File indexing completed on 2025-01-26 05:29:15
0001 <?php 0002 0003 namespace Intervention\Image; 0004 0005 abstract class AbstractFont 0006 { 0007 /** 0008 * Text to be written 0009 * 0010 * @var String 0011 */ 0012 public $text; 0013 0014 /** 0015 * Text size in pixels 0016 * 0017 * @var int 0018 */ 0019 public $size = 12; 0020 0021 /** 0022 * Color of the text 0023 * 0024 * @var mixed 0025 */ 0026 public $color = '000000'; 0027 0028 /** 0029 * Rotation angle of the text 0030 * 0031 * @var int 0032 */ 0033 public $angle = 0; 0034 0035 /** 0036 * Horizontal alignment of the text 0037 * 0038 * @var String 0039 */ 0040 public $align; 0041 0042 /** 0043 * Vertical alignment of the text 0044 * 0045 * @var String 0046 */ 0047 public $valign; 0048 0049 /** 0050 * Path to TTF or GD library internal font file of the text 0051 * 0052 * @var mixed 0053 */ 0054 public $file; 0055 0056 /** 0057 * Draws font to given image on given position 0058 * 0059 * @param Image $image 0060 * @param int $posx 0061 * @param int $posy 0062 * @return boolean 0063 */ 0064 abstract public function applyToImage(Image $image, $posx = 0, $posy = 0); 0065 0066 /** 0067 * Calculates bounding box of current font setting 0068 * 0069 * @return array 0070 */ 0071 abstract public function getBoxSize(); 0072 0073 /** 0074 * Create a new instance of Font 0075 * 0076 * @param Strinf $text Text to be written 0077 */ 0078 public function __construct($text = null) 0079 { 0080 $this->text = $text; 0081 } 0082 0083 /** 0084 * Set text to be written 0085 * 0086 * @param String $text 0087 * @return void 0088 */ 0089 public function text($text) 0090 { 0091 $this->text = $text; 0092 0093 return $this; 0094 } 0095 0096 /** 0097 * Get text to be written 0098 * 0099 * @return String 0100 */ 0101 public function getText() 0102 { 0103 return $this->text; 0104 } 0105 0106 /** 0107 * Set font size in pixels 0108 * 0109 * @param int $size 0110 * @return void 0111 */ 0112 public function size($size) 0113 { 0114 $this->size = $size; 0115 0116 return $this; 0117 } 0118 0119 /** 0120 * Get font size in pixels 0121 * 0122 * @return int 0123 */ 0124 public function getSize() 0125 { 0126 return $this->size; 0127 } 0128 0129 /** 0130 * Set color of text to be written 0131 * 0132 * @param mixed $color 0133 * @return void 0134 */ 0135 public function color($color) 0136 { 0137 $this->color = $color; 0138 0139 return $this; 0140 } 0141 0142 /** 0143 * Get color of text 0144 * 0145 * @return mixed 0146 */ 0147 public function getColor() 0148 { 0149 return $this->color; 0150 } 0151 0152 /** 0153 * Set rotation angle of text 0154 * 0155 * @param int $angle 0156 * @return void 0157 */ 0158 public function angle($angle) 0159 { 0160 $this->angle = $angle; 0161 0162 return $this; 0163 } 0164 0165 /** 0166 * Get rotation angle of text 0167 * 0168 * @return int 0169 */ 0170 public function getAngle() 0171 { 0172 return $this->angle; 0173 } 0174 0175 /** 0176 * Set horizontal text alignment 0177 * 0178 * @param string $align 0179 * @return void 0180 */ 0181 public function align($align) 0182 { 0183 $this->align = $align; 0184 0185 return $this; 0186 } 0187 0188 /** 0189 * Get horizontal text alignment 0190 * 0191 * @return string 0192 */ 0193 public function getAlign() 0194 { 0195 return $this->align; 0196 } 0197 0198 /** 0199 * Set vertical text alignment 0200 * 0201 * @param string $valign 0202 * @return void 0203 */ 0204 public function valign($valign) 0205 { 0206 $this->valign = $valign; 0207 0208 return $this; 0209 } 0210 0211 /** 0212 * Get vertical text alignment 0213 * 0214 * @return string 0215 */ 0216 public function getValign() 0217 { 0218 return $this->valign; 0219 } 0220 0221 /** 0222 * Set path to font file 0223 * 0224 * @param string $file 0225 * @return void 0226 */ 0227 public function file($file) 0228 { 0229 $this->file = $file; 0230 0231 return $this; 0232 } 0233 0234 /** 0235 * Get path to font file 0236 * 0237 * @return string 0238 */ 0239 public function getFile() 0240 { 0241 return $this->file; 0242 } 0243 0244 /** 0245 * Checks if current font has access to an applicable font file 0246 * 0247 * @return boolean 0248 */ 0249 protected function hasApplicableFontFile() 0250 { 0251 if (is_string($this->file)) { 0252 return file_exists($this->file); 0253 } 0254 0255 return false; 0256 } 0257 0258 /** 0259 * Counts lines of text to be written 0260 * 0261 * @return int 0262 */ 0263 public function countLines() 0264 { 0265 return count(explode(PHP_EOL, $this->text)); 0266 } 0267 }