Skip to content

Commit

Permalink
1.2.3: #6
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed Aug 18, 2020
1 parent d89f24d commit f028e9d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 57 deletions.
12 changes: 2 additions & 10 deletions Fonts/Png.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace Df\GoogleFont\Fonts;
use Df\GoogleFont\Font\Variant\Preview\Params;
abstract class Png extends \Df\Core\OLegacy {
/** @see \Df\GoogleFont\Fonts\Sprite */
abstract class Png extends \Df\Core\O {
/**
* 2015-12-08
* @used-by \Df\GoogleFont\Fonts\Png::image()
Expand Down Expand Up @@ -146,15 +147,6 @@ private function path() {return dfc($this, function() {return
$this->fs()->absolute($this->pathRelativeA())
;});}

/**
* 2015-12-08
* @override
* @see \Df\Core\OLegacy::_construct()
*/
protected function _construct() {
parent::_construct();
$this->_prop(self::$P__PARAMS, Params::class);
}
/** @var string */
protected static $P__PARAMS = 'params';
}
60 changes: 14 additions & 46 deletions Fonts/Sprite.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Df\GoogleFont\Font\Variant\Preview;
use Df\GoogleFont\Font\Variant\Preview\Params;
use Df\GoogleFont\Fonts;
class Sprite extends Png {
final class Sprite extends Png {
/**
* 2015-12-08
* Возвращает координаты левого верхнего угла изображения шрифта в общей картинке-спрайте.
Expand All @@ -17,9 +17,7 @@ class Sprite extends Png {
* @param Preview $preview
* @return int[]
*/
function datumPoint(Preview $preview) {
return dfa($this->datumPoints(), $preview->getId());
}
function datumPoint(Preview $preview) {return dfa($this->datumPoints(), $preview->getId());}

/**
* 2015-12-08
Expand All @@ -29,23 +27,17 @@ function datumPoint(Preview $preview) {
* @param resource $image
*/
protected function draw($image) {
/** @var int $x */
$x = 0;
/** @var int $y */
$y = 0;
$x = 0; /** @var int $x */
$y = 0; /** @var int $y */
$this->_datumPoints = [];
df_assert_nef(imagefill($image, 0, 0, $this->colorAllocateAlpha($image, $this->bgColor())));
// http://stackoverflow.com/a/1397584/254475
imagealphablending($image, true);
foreach ($this->previews() as $preview) {
/** @var Preview $preview */
foreach ($this->previews() as $preview) { /** @var Preview $preview */
try {
/** @var resource $previewImage */
$previewImage = df_assert_nef(imagecreatefromstring($preview->contents()));
$previewImage = df_assert_nef(imagecreatefromstring($preview->contents())); /** @var resource $previewImage */
try {
df_assert_nef(imagecopy(
$image, $previewImage, $x, $y, 0, 0, $preview->width(), $preview->height()
));
df_assert_nef(imagecopy($image, $previewImage, $x, $y, 0, 0, $preview->width(), $preview->height()));
$this->_datumPoints[$preview->getId()] = [$x, $y];
}
finally {
Expand All @@ -65,9 +57,8 @@ protected function draw($image) {
}

/**
* 2015-12-08
* 2015-12-08 Высота спрайта
* @override
* Высота спрайта.
* @see \Df\GoogleFont\Fonts\Png::height()
* @used-by \Df\GoogleFont\Fonts\Png::image()
* @return int
Expand All @@ -87,25 +78,19 @@ protected function height() {
* Поэтому добавляем место для ещё одого ряда снизу,
* чтобы последнему ряду уж наверняка хватило места.
*/
$this->{__METHOD__} =
ceil($this->square() / $this->width())
+ $this->previewHeight() + $this->marginY()
;
$this->{__METHOD__} = ceil($this->square() / $this->width()) + $this->previewHeight() + $this->marginY();
}
return $this->{__METHOD__};
}

/**
* 2015-12-08
* Кэшировать результат нельзя!
* 2015-12-08 Кэшировать результат нельзя!
* @override
* @see \Df\GoogleFont\Fonts\Png::needToCreate()
* @used-by \Df\GoogleFont\Fonts\Png::createIfNeeded()
* @return bool
*/
protected function needToCreate() {
return !file_exists($this->pathToDatumPoints()) || parent::needToCreate();
}
protected function needToCreate() {return !file_exists($this->pathToDatumPoints()) || parent::needToCreate();}

/**
* 2015-12-08
Expand All @@ -114,9 +99,7 @@ protected function needToCreate() {
* @used-by \Df\GoogleFont\Fonts\Png::path()
* @return string[]
*/
protected function pathRelativeA() {
return [$this->pathRelativeBase(), $this->fs()->namePng(['i'])];
}
protected function pathRelativeA() {return [$this->pathRelativeBase(), $this->fs()->namePng(['i'])];}

/**
* 2015-12-08
Expand Down Expand Up @@ -239,24 +222,11 @@ private function previewWidth() {return $this->params()->width();}
*/
private function square() {
if (!isset($this->{__METHOD__})) {
$this->{__METHOD__} =
($this->previewHeight() + $this->marginY())
* $this->previewWidth()
* count($this->previews())
;
$this->{__METHOD__} = ($this->previewHeight() + $this->marginY()) * $this->previewWidth() * count($this->previews());
}
return $this->{__METHOD__};
}

/**
* 2015-12-08
* @override
* @see \Df\GoogleFont\Fonts\Png::_construct()
*/
protected function _construct() {
parent::_construct();
$this->_prop(self::$P__FONTS, Fonts::class);
}
/** @var string */
private static $P__FONTS = 'fonts';

Expand All @@ -273,7 +243,5 @@ protected function _construct() {
* @param Params $params
* @return \Df\GoogleFont\Fonts\Sprite
*/
static function i(Fonts $fonts, Params $params) {return new self([
self::$P__FONTS => $fonts, self::$P__PARAMS => $params
]);}
static function i(Fonts $fonts, Params $params) {return new self([self::$P__FONTS => $fonts, self::$P__PARAMS => $params]);}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mage2pro/google-font"
,"version": "1.2.2"
,"version": "1.2.3"
,"description": "Google Font API."
,"type": "magento2-module"
,"homepage": "https://github.com/mage2pro/google-font"
Expand Down

0 comments on commit f028e9d

Please sign in to comment.