File indexing completed on 2025-01-19 05:21:24
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Pdf 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 0023 /** 0024 * Style object. 0025 * Style object doesn't directly correspond to any PDF file object. 0026 * It's utility class, used as a container for style information. 0027 * It's used by Zend_Pdf_Page class in draw operations. 0028 * 0029 * @package Zend_Pdf 0030 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0031 * @license http://framework.zend.com/license/new-bsd New BSD License 0032 */ 0033 class Zend_Pdf_Style 0034 { 0035 /** 0036 * Fill color. 0037 * Used to fill geometric shapes or text. 0038 * 0039 * @var Zend_Pdf_Color|null 0040 */ 0041 private $_fillColor = null; 0042 0043 /** 0044 * Line color. 0045 * Current color, used for lines and font outlines. 0046 * 0047 * @var Zend_Pdf_Color|null 0048 */ 0049 0050 private $_color; 0051 0052 /** 0053 * Line width. 0054 * 0055 * @var Zend_Pdf_Element_Numeric 0056 */ 0057 private $_lineWidth; 0058 0059 /** 0060 * Array which describes line dashing pattern. 0061 * It's array of numeric: 0062 * array($on_length, $off_length, $on_length, $off_length, ...) 0063 * 0064 * @var array 0065 */ 0066 private $_lineDashingPattern; 0067 0068 /** 0069 * Line dashing phase 0070 * 0071 * @var float 0072 */ 0073 private $_lineDashingPhase; 0074 0075 /** 0076 * Current font 0077 * 0078 * @var Zend_Pdf_Resource_Font 0079 */ 0080 private $_font; 0081 0082 /** 0083 * Font size 0084 * 0085 * @var float 0086 */ 0087 private $_fontSize; 0088 0089 0090 0091 /** 0092 * Create style. 0093 * 0094 * @param Zend_Pdf_Style $anotherStyle 0095 */ 0096 public function __construct($anotherStyle = null) 0097 { 0098 if ($anotherStyle !== null) { 0099 $this->_fillColor = $anotherStyle->_fillColor; 0100 $this->_color = $anotherStyle->_color; 0101 $this->_lineWidth = $anotherStyle->_lineWidth; 0102 $this->_lineDashingPattern = $anotherStyle->_lineDashingPattern; 0103 $this->_lineDashingPhase = $anotherStyle->_lineDashingPhase; 0104 $this->_font = $anotherStyle->_font; 0105 $this->_fontSize = $anotherStyle->_fontSize; 0106 } 0107 } 0108 0109 0110 /** 0111 * Set fill color. 0112 * 0113 * @param Zend_Pdf_Color $color 0114 */ 0115 public function setFillColor(Zend_Pdf_Color $color) 0116 { 0117 $this->_fillColor = $color; 0118 } 0119 0120 /** 0121 * Set line color. 0122 * 0123 * @param Zend_Pdf_Color $color 0124 */ 0125 public function setLineColor(Zend_Pdf_Color $color) 0126 { 0127 $this->_color = $color; 0128 } 0129 0130 /** 0131 * Set line width. 0132 * 0133 * @param float $width 0134 */ 0135 public function setLineWidth($width) 0136 { 0137 // require_once 'Zend/Pdf/Element/Numeric.php'; 0138 $this->_lineWidth = new Zend_Pdf_Element_Numeric($width); 0139 } 0140 0141 0142 /** 0143 * Set line dashing pattern 0144 * 0145 * @param array $pattern 0146 * @param float $phase 0147 */ 0148 public function setLineDashingPattern($pattern, $phase = 0) 0149 { 0150 // require_once 'Zend/Pdf/Page.php'; 0151 if ($pattern === Zend_Pdf_Page::LINE_DASHING_SOLID) { 0152 $pattern = array(); 0153 $phase = 0; 0154 } 0155 0156 // require_once 'Zend/Pdf/Element/Numeric.php'; 0157 $this->_lineDashingPattern = $pattern; 0158 $this->_lineDashingPhase = new Zend_Pdf_Element_Numeric($phase); 0159 } 0160 0161 0162 /** 0163 * Set current font. 0164 * 0165 * @param Zend_Pdf_Resource_Font $font 0166 * @param float $fontSize 0167 */ 0168 public function setFont(Zend_Pdf_Resource_Font $font, $fontSize) 0169 { 0170 $this->_font = $font; 0171 $this->_fontSize = $fontSize; 0172 } 0173 0174 /** 0175 * Modify current font size 0176 * 0177 * @param float $fontSize 0178 */ 0179 public function setFontSize($fontSize) 0180 { 0181 $this->_fontSize = $fontSize; 0182 } 0183 0184 /** 0185 * Get fill color. 0186 * 0187 * @return Zend_Pdf_Color|null 0188 */ 0189 public function getFillColor() 0190 { 0191 return $this->_fillColor; 0192 } 0193 0194 /** 0195 * Get line color. 0196 * 0197 * @return Zend_Pdf_Color|null 0198 */ 0199 public function getLineColor() 0200 { 0201 return $this->_color; 0202 } 0203 0204 /** 0205 * Get line width. 0206 * 0207 * @return float 0208 */ 0209 public function getLineWidth() 0210 { 0211 return $this->_lineWidth->value; 0212 } 0213 0214 /** 0215 * Get line dashing pattern 0216 * 0217 * @return array 0218 */ 0219 public function getLineDashingPattern() 0220 { 0221 return $this->_lineDashingPattern; 0222 } 0223 0224 0225 /** 0226 * Get current font. 0227 * 0228 * @return Zend_Pdf_Resource_Font $font 0229 */ 0230 public function getFont() 0231 { 0232 return $this->_font; 0233 } 0234 0235 /** 0236 * Get current font size 0237 * 0238 * @return float $fontSize 0239 */ 0240 public function getFontSize() 0241 { 0242 return $this->_fontSize; 0243 } 0244 0245 /** 0246 * Get line dashing phase 0247 * 0248 * @return float 0249 */ 0250 public function getLineDashingPhase() 0251 { 0252 return $this->_lineDashingPhase->value; 0253 } 0254 0255 0256 /** 0257 * Dump style to a string, which can be directly inserted into content stream 0258 * 0259 * @return string 0260 */ 0261 public function instructions() 0262 { 0263 $instructions = ''; 0264 0265 if ($this->_fillColor !== null) { 0266 $instructions .= $this->_fillColor->instructions(false); 0267 } 0268 0269 if ($this->_color !== null) { 0270 $instructions .= $this->_color->instructions(true); 0271 } 0272 0273 if ($this->_lineWidth !== null) { 0274 $instructions .= $this->_lineWidth->toString() . " w\n"; 0275 } 0276 0277 if ($this->_lineDashingPattern !== null) { 0278 // require_once 'Zend/Pdf/Element/Array.php'; 0279 $dashPattern = new Zend_Pdf_Element_Array(); 0280 0281 // require_once 'Zend/Pdf/Element/Numeric.php'; 0282 foreach ($this->_lineDashingPattern as $dashItem) { 0283 $dashElement = new Zend_Pdf_Element_Numeric($dashItem); 0284 $dashPattern->items[] = $dashElement; 0285 } 0286 0287 $instructions .= $dashPattern->toString() . ' ' 0288 . $this->_lineDashingPhase->toString() . " d\n"; 0289 } 0290 0291 return $instructions; 0292 } 0293 0294 }