chore: Аннотации к типам

This commit is contained in:
origami11@yandex.ru 2025-10-30 12:59:36 +03:00
parent 5e8958969f
commit f964472e62
28 changed files with 140 additions and 36 deletions

View file

@ -3,7 +3,9 @@
/**
* Формат для композиции изображений
*/
namespace ctiso\Tools;
use ctiso\Tools\Drawing;
use GdImage;
@ -27,7 +29,7 @@ class TemplateImage
'' => 'arial.ttf',
'dejavu' => 'DejaVuCondensedSerif.ttf',
'dejavubd' => 'DejaVuCondensedSerifBold.ttf',
'dejavuz' =>'DejaVuCondensedSerifBoldItalic.ttf',
'dejavuz' => 'DejaVuCondensedSerifBoldItalic.ttf',
'dejavui' => 'DejaVuCondensedSerifItalic.ttf',
'miriad' => 'MyriadPro-Cond.ttf',
'miriadbd' => 'MyriadPro-BoldCond.ttf'
@ -47,7 +49,7 @@ class TemplateImage
public string $resource;
public string $filename;
function __construct (?array $template = null)
function __construct(?array $template = null)
{
if ($template) {
$this->data = $template;
@ -70,9 +72,13 @@ class TemplateImage
$this->base = $path;
}
/**
* @param string $name
* @param mixed $value
*/
function set(string $name, $value): void
{
$this->context['['.$name.']'] = $value;
$this->context['[' . $name . ']'] = $value;
}
function setImage(string $name): void
@ -107,7 +113,7 @@ class TemplateImage
function getFontFile(string $name): string
{
if(array_key_exists(strtolower($name), self::$listfonts)) {
if (array_key_exists(strtolower($name), self::$listfonts)) {
return $this->base . self::$listfonts[$name];
}
return $this->base . 'arial.ttf';
@ -115,15 +121,15 @@ class TemplateImage
function fontSuffix(array $style): string
{
if($style[0] && $style[1]) return "z";
if ($style[0] && $style[1]) return "z";
if($style[0]) return "bd";
if($style[1]) return "i";
if ($style[0]) return "bd";
if ($style[1]) return "i";
return "";
}
function imageText(string $text, object $value)
function imageText(string $text, object $value): void
{
$text = strtr($text, $this->context);
$size = $value->fontSize;
@ -140,15 +146,26 @@ class TemplateImage
if ($value->valign[0]) {
$valign = Drawing::ALIGN_TOP;
} elseif ($value->valign[1]) {
} elseif ($value->valign[1]) {
$valign = Drawing::ALIGN_CENTER;
} else {
$valign = Drawing::ALIGN_BOTTOM;
}
Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text,
$value->width, $value->height,
$align, $valign);
Drawing::imagettftextbox(
$this->image,
$size,
0,
$value->left,
$value->top,
$color,
$fontfile,
$text,
$value->width,
$value->height,
$align,
$valign
);
}
/**
@ -171,12 +188,13 @@ class TemplateImage
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// imagecopyresized($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// imagecopyresized($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
$this->image = $image_p;
}
function prepare(): void {
if($this->_prepare) {
function prepare(): void
{
if ($this->_prepare) {
$this->_prepare = false;
foreach ($this->data as $value) {
$this->imageText($value->text, $value); // break;