/framework/vendor/zend/Zend/Pdf/Style.php
PHP | 295 lines | 109 code | 41 blank | 145 comment | 6 complexity | 3b49dcbc11bc825b72713443e16ae54a MD5 | raw file
1<?php 2/** 3 * Zend Framework 4 * 5 * LICENSE 6 * 7 * This source file is subject to the new BSD license that is bundled 8 * with this package in the file LICENSE.txt. 9 * It is also available through the world-wide-web at this URL: 10 * http://framework.zend.com/license/new-bsd 11 * If you did not receive a copy of the license and are unable to 12 * obtain it through the world-wide-web, please send an email 13 * to license@zend.com so we can send you a copy immediately. 14 * 15 * @category Zend 16 * @package Zend_Pdf 17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 18 * @license http://framework.zend.com/license/new-bsd New BSD License 19 * @version $Id: Style.php 20096 2010-01-06 02:05:09Z bkarwin $ 20 */ 21 22 23/** 24 * Style object. 25 * Style object doesn't directly correspond to any PDF file object. 26 * It's utility class, used as a container for style information. 27 * It's used by Zend_Pdf_Page class in draw operations. 28 * 29 * @package Zend_Pdf 30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 31 * @license http://framework.zend.com/license/new-bsd New BSD License 32 */ 33class Zend_Pdf_Style 34{ 35 /** 36 * Fill color. 37 * Used to fill geometric shapes or text. 38 * 39 * @var Zend_Pdf_Color|null 40 */ 41 private $_fillColor = null; 42 43 /** 44 * Line color. 45 * Current color, used for lines and font outlines. 46 * 47 * @var Zend_Pdf_Color|null 48 */ 49 50 private $_color; 51 52 /** 53 * Line width. 54 * 55 * @var Zend_Pdf_Element_Numeric 56 */ 57 private $_lineWidth; 58 59 /** 60 * Array which describes line dashing pattern. 61 * It's array of numeric: 62 * array($on_length, $off_length, $on_length, $off_length, ...) 63 * 64 * @var array 65 */ 66 private $_lineDashingPattern; 67 68 /** 69 * Line dashing phase 70 * 71 * @var float 72 */ 73 private $_lineDashingPhase; 74 75 /** 76 * Current font 77 * 78 * @var Zend_Pdf_Resource_Font 79 */ 80 private $_font; 81 82 /** 83 * Font size 84 * 85 * @var float 86 */ 87 private $_fontSize; 88 89 90 91 /** 92 * Create style. 93 * 94 * @param Zend_Pdf_Style $anotherStyle 95 */ 96 public function __construct($anotherStyle = null) 97 { 98 if ($anotherStyle !== null) { 99 $this->_fillColor = $anotherStyle->_fillColor; 100 $this->_color = $anotherStyle->_color; 101 $this->_lineWidth = $anotherStyle->_lineWidth; 102 $this->_lineDashingPattern = $anotherStyle->_lineDashingPattern; 103 $this->_lineDashingPhase = $anotherStyle->_lineDashingPhase; 104 $this->_font = $anotherStyle->_font; 105 $this->_fontSize = $anotherStyle->_fontSize; 106 } 107 } 108 109 110 /** 111 * Set fill color. 112 * 113 * @param Zend_Pdf_Color $color 114 */ 115 public function setFillColor(Zend_Pdf_Color $color) 116 { 117 $this->_fillColor = $color; 118 } 119 120 /** 121 * Set line color. 122 * 123 * @param Zend_Pdf_Color $color 124 */ 125 public function setLineColor(Zend_Pdf_Color $color) 126 { 127 $this->_color = $color; 128 } 129 130 /** 131 * Set line width. 132 * 133 * @param float $width 134 */ 135 public function setLineWidth($width) 136 { 137 require_once 'Zend/Pdf/Element/Numeric.php'; 138 $this->_lineWidth = new Zend_Pdf_Element_Numeric($width); 139 } 140 141 142 /** 143 * Set line dashing pattern 144 * 145 * @param array $pattern 146 * @param float $phase 147 */ 148 public function setLineDashingPattern($pattern, $phase = 0) 149 { 150 require_once 'Zend/Pdf/Page.php'; 151 if ($pattern === Zend_Pdf_Page::LINE_DASHING_SOLID) { 152 $pattern = array(); 153 $phase = 0; 154 } 155 156 require_once 'Zend/Pdf/Element/Numeric.php'; 157 $this->_lineDashingPattern = $pattern; 158 $this->_lineDashingPhase = new Zend_Pdf_Element_Numeric($phase); 159 } 160 161 162 /** 163 * Set current font. 164 * 165 * @param Zend_Pdf_Resource_Font $font 166 * @param float $fontSize 167 */ 168 public function setFont(Zend_Pdf_Resource_Font $font, $fontSize) 169 { 170 $this->_font = $font; 171 $this->_fontSize = $fontSize; 172 } 173 174 /** 175 * Modify current font size 176 * 177 * @param float $fontSize 178 */ 179 public function setFontSize($fontSize) 180 { 181 $this->_fontSize = $fontSize; 182 } 183 184 /** 185 * Get fill color. 186 * 187 * @return Zend_Pdf_Color|null 188 */ 189 public function getFillColor() 190 { 191 return $this->_fillColor; 192 } 193 194 /** 195 * Get line color. 196 * 197 * @return Zend_Pdf_Color|null 198 */ 199 public function getLineColor() 200 { 201 return $this->_color; 202 } 203 204 /** 205 * Get line width. 206 * 207 * @return float 208 */ 209 public function getLineWidth() 210 { 211 return $this->_lineWidth->value; 212 } 213 214 /** 215 * Get line dashing pattern 216 * 217 * @return array 218 */ 219 public function getLineDashingPattern() 220 { 221 return $this->_lineDashingPattern; 222 } 223 224 225 /** 226 * Get current font. 227 * 228 * @return Zend_Pdf_Resource_Font $font 229 */ 230 public function getFont() 231 { 232 return $this->_font; 233 } 234 235 /** 236 * Get current font size 237 * 238 * @return float $fontSize 239 */ 240 public function getFontSize() 241 { 242 return $this->_fontSize; 243 } 244 245 /** 246 * Get line dashing phase 247 * 248 * @return float 249 */ 250 public function getLineDashingPhase() 251 { 252 return $this->_lineDashingPhase->value; 253 } 254 255 256 /** 257 * Dump style to a string, which can be directly inserted into content stream 258 * 259 * @return string 260 */ 261 public function instructions() 262 { 263 $instructions = ''; 264 265 if ($this->_fillColor !== null) { 266 $instructions .= $this->_fillColor->instructions(false); 267 } 268 269 if ($this->_color !== null) { 270 $instructions .= $this->_color->instructions(true); 271 } 272 273 if ($this->_lineWidth !== null) { 274 $instructions .= $this->_lineWidth->toString() . " w\n"; 275 } 276 277 if ($this->_lineDashingPattern !== null) { 278 require_once 'Zend/Pdf/Element/Array.php'; 279 $dashPattern = new Zend_Pdf_Element_Array(); 280 281 require_once 'Zend/Pdf/Element/Numeric.php'; 282 foreach ($this->_lineDashingPattern as $dashItem) { 283 $dashElement = new Zend_Pdf_Element_Numeric($dashItem); 284 $dashPattern->items[] = $dashElement; 285 } 286 287 $instructions .= $dashPattern->toString() . ' ' 288 . $this->_lineDashingPhase->toString() . " d\n"; 289 } 290 291 return $instructions; 292 } 293 294} 295