Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
TextWatermark.php
1<?php
10
11use Bitrix\Main;
12
14{
15 protected
20 $copyright = false,
22
29 public function __construct($text, $font, Color $color = null)
30 {
31 parent::__construct();
32
33 $this->text = $text;
34 $this->font = $font;
35
36 if($color !== null)
37 {
38 $this->color = $color;
39 }
40 else
41 {
42 $this->color = new Color();
43 }
44 }
45
49 public function getText()
50 {
51 return ($this->copyright? chr(169)." " : "").$this->text;
52 }
53
57 public function getUtfText()
58 {
59 $text = $this->getText();
60
61 $culture = Main\Context::getCurrent()->getCulture();
62 if($culture)
63 {
64 $text = Main\Text\Encoding::convertEncoding($text, $culture->getCharset(), "UTF-8");
65 }
66
67 return $text;
68 }
69
74 public function setText($text)
75 {
76 $this->text = $text;
77 return $this;
78 }
79
83 public function getWidth()
84 {
85 return $this->width;
86 }
87
92 public function setWidth($width)
93 {
94 $this->width = (int)$width;
95 return $this;
96 }
97
101 public function getFont()
102 {
103 return $this->font;
104 }
105
110 public function setFont($font)
111 {
112 $this->font = $font;
113 return $this;
114 }
115
119 public function getColor(): Color
120 {
121 return $this->color;
122 }
123
128 public function setColor(Color $color)
129 {
130 $this->color = $color;
131 return $this;
132 }
133
137 public function isCopyright()
138 {
139 return $this->copyright;
140 }
141
146 public function setCopyright($copyright)
147 {
148 $this->copyright = (bool)$copyright;
149 return $this;
150 }
151
155 public function getRatio()
156 {
157 if($this->ratio === null)
158 {
159 if($this->size == static::SIZE_BIG)
160 {
161 return 7;
162 }
163 if($this->size == static::SIZE_SMALL)
164 {
165 return 2;
166 }
167 //static::SIZE_MEDIUM
168 return 4;
169 }
170 return $this->ratio;
171 }
172
177 public function getFontSize($width)
178 {
179 $length = mb_strlen($this->getText());
180
181 $fontSize = $width * ($this->getRatio() / 100.0);
182
183 if(($fontSize * $length * 0.7) > $width)
184 {
185 $fontSize = $width / ($length * 0.7);
186 }
187
188 return $fontSize;
189 }
190}
__construct($text, $font, Color $color=null)