Abstract.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  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. require_once 'Zend/Pdf/Canvas/Interface.php';
  22. /** Internally used classes */
  23. require_once 'Zend/Pdf/Element.php';
  24. require_once 'Zend/Pdf/Element/Array.php';
  25. require_once 'Zend/Pdf/Element/String/Binary.php';
  26. require_once 'Zend/Pdf/Element/Boolean.php';
  27. require_once 'Zend/Pdf/Element/Dictionary.php';
  28. require_once 'Zend/Pdf/Element/Name.php';
  29. require_once 'Zend/Pdf/Element/Null.php';
  30. require_once 'Zend/Pdf/Element/Numeric.php';
  31. require_once 'Zend/Pdf/Element/String.php';
  32. /**
  33. * Canvas is an abstract rectangle drawing area which can be dropped into
  34. * page object at specified place.
  35. *
  36. * @package Zend_Pdf
  37. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. abstract class Zend_Pdf_Canvas_Abstract implements Zend_Pdf_Canvas_Interface
  41. {
  42. /**
  43. * Drawing instructions
  44. *
  45. * @var string
  46. */
  47. protected $_contents = '';
  48. /**
  49. * Current font
  50. *
  51. * @var Zend_Pdf_Resource_Font
  52. */
  53. protected $_font = null;
  54. /**
  55. * Current font size
  56. *
  57. * @var float
  58. */
  59. protected $_fontSize;
  60. /**
  61. * Current style
  62. *
  63. * @var Zend_Pdf_Style
  64. */
  65. protected $_style = null;
  66. /**
  67. * Counter for the "Save" operations
  68. *
  69. * @var integer
  70. */
  71. protected $_saveCount = 0;
  72. /**
  73. * Add procedureSet to the Page description
  74. *
  75. * @param string $procSetName
  76. */
  77. abstract protected function _addProcSet($procSetName);
  78. /**
  79. * Attach resource to the canvas
  80. *
  81. * Method returns a name of the resource which can be used
  82. * as a resource reference within drawing instructions stream
  83. * Allowed types: 'ExtGState', 'ColorSpace', 'Pattern', 'Shading',
  84. * 'XObject', 'Font', 'Properties'
  85. *
  86. * @param string $type
  87. * @param Zend_Pdf_Resource $resource
  88. * @return string
  89. */
  90. abstract protected function _attachResource($type, Zend_Pdf_Resource $resource);
  91. /**
  92. * Draw a canvas at the specified location
  93. *
  94. * If upper right corner is not specified then canvas heght and width
  95. * are used.
  96. *
  97. * @param Zend_Pdf_Canvas_Interface $canvas
  98. * @param float $x1
  99. * @param float $y1
  100. * @param float $x2
  101. * @param float $y2
  102. * @return Zend_Pdf_Canvas_Interface
  103. */
  104. public function drawCanvas(Zend_Pdf_Canvas_Interface $canvas, $x1, $y1, $x2 = null, $y2 = null)
  105. {
  106. $this->saveGS();
  107. $this->translate($x1, $y1);
  108. if ($x2 === null) {
  109. $with = $canvas->getWidth();
  110. } else {
  111. $with = $x2 - $x1;
  112. }
  113. if ($y2 === null) {
  114. $height = $canvas->getHeight();
  115. } else {
  116. $height = $y2 - $y1;
  117. }
  118. $this->clipRectangle(0, 0, $with, $height);
  119. if ($x2 !== null || $y2 !== null) {
  120. // Drawn canvas has to be scaled.
  121. if ($x2 !== null) {
  122. $xScale = $with/$canvas->getWidth();
  123. } else {
  124. $xScale = 1;
  125. }
  126. if ($y2 !== null) {
  127. $yScale = $height/$canvas->getHeight();
  128. } else {
  129. $yScale = 1;
  130. }
  131. $this->scale($xScale, $yScale);
  132. }
  133. $contentsToDraw = $canvas->getContents();
  134. /** @todo implementation */
  135. $this->restoreGS();
  136. return $this;
  137. }
  138. /**
  139. * Set fill color.
  140. *
  141. * @param Zend_Pdf_Color $color
  142. * @return Zend_Pdf_Canvas_Interface
  143. */
  144. public function setFillColor(Zend_Pdf_Color $color)
  145. {
  146. $this->_addProcSet('PDF');
  147. $this->_contents .= $color->instructions(false);
  148. return $this;
  149. }
  150. /**
  151. * Set line color.
  152. *
  153. * @param Zend_Pdf_Color $color
  154. * @return Zend_Pdf_Canvas_Interface
  155. */
  156. public function setLineColor(Zend_Pdf_Color $color)
  157. {
  158. $this->_addProcSet('PDF');
  159. $this->_contents .= $color->instructions(true);
  160. return $this;
  161. }
  162. /**
  163. * Set line width.
  164. *
  165. * @param float $width
  166. * @return Zend_Pdf_Canvas_Interface
  167. */
  168. public function setLineWidth($width)
  169. {
  170. $this->_addProcSet('PDF');
  171. $widthObj = new Zend_Pdf_Element_Numeric($width);
  172. $this->_contents .= $widthObj->toString() . " w\n";
  173. return $this;
  174. }
  175. /**
  176. * Set line dashing pattern
  177. *
  178. * Pattern is an array of floats: array(on_length, off_length, on_length, off_length, ...)
  179. * or Zend_Pdf_Page::LINE_DASHING_SOLID constant
  180. * Phase is shift from the beginning of line.
  181. *
  182. * @param mixed $pattern
  183. * @param array $phase
  184. * @return Zend_Pdf_Canvas_Interface
  185. */
  186. public function setLineDashingPattern($pattern, $phase = 0)
  187. {
  188. $this->_addProcSet('PDF');
  189. require_once 'Zend/Pdf/Page.php';
  190. if ($pattern === Zend_Pdf_Page::LINE_DASHING_SOLID) {
  191. $pattern = array();
  192. $phase = 0;
  193. }
  194. $dashPattern = new Zend_Pdf_Element_Array();
  195. $phaseEleemnt = new Zend_Pdf_Element_Numeric($phase);
  196. foreach ($pattern as $dashItem) {
  197. $dashElement = new Zend_Pdf_Element_Numeric($dashItem);
  198. $dashPattern->items[] = $dashElement;
  199. }
  200. $this->_contents .= $dashPattern->toString() . ' '
  201. . $phaseEleemnt->toString() . " d\n";
  202. return $this;
  203. }
  204. /**
  205. * Set current font.
  206. *
  207. * @param Zend_Pdf_Resource_Font $font
  208. * @param float $fontSize
  209. * @return Zend_Pdf_Canvas_Interface
  210. */
  211. public function setFont(Zend_Pdf_Resource_Font $font, $fontSize)
  212. {
  213. $this->_addProcSet('Text');
  214. $fontName = $this->_attachResource('Font', $font);
  215. $this->_font = $font;
  216. $this->_fontSize = $fontSize;
  217. $fontNameObj = new Zend_Pdf_Element_Name($fontName);
  218. $fontSizeObj = new Zend_Pdf_Element_Numeric($fontSize);
  219. $this->_contents .= $fontNameObj->toString() . ' ' . $fontSizeObj->toString() . " Tf\n";
  220. return $this;
  221. }
  222. /**
  223. * Set the style to use for future drawing operations on this page
  224. *
  225. * @param Zend_Pdf_Style $style
  226. * @return Zend_Pdf_Canvas_Interface
  227. */
  228. public function setStyle(Zend_Pdf_Style $style)
  229. {
  230. $this->_addProcSet('Text');
  231. $this->_addProcSet('PDF');
  232. if ($style->getFont() !== null) {
  233. $this->setFont($style->getFont(), $style->getFontSize());
  234. }
  235. $this->_contents .= $style->instructions($this->_dictionary->Resources);
  236. $this->_style = $style;
  237. return $this;
  238. }
  239. /**
  240. * Get current font.
  241. *
  242. * @return Zend_Pdf_Resource_Font $font
  243. */
  244. public function getFont()
  245. {
  246. return $this->_font;
  247. }
  248. /**
  249. * Get current font size
  250. *
  251. * @return float $fontSize
  252. */
  253. public function getFontSize()
  254. {
  255. return $this->_fontSize;
  256. }
  257. /**
  258. * Return the style, applied to the page.
  259. *
  260. * @return Zend_Pdf_Style
  261. */
  262. public function getStyle()
  263. {
  264. return $this->_style;
  265. }
  266. /**
  267. * Save the graphics state of this page.
  268. * This takes a snapshot of the currently applied style, position, clipping area and
  269. * any rotation/translation/scaling that has been applied.
  270. *
  271. * @todo check for the open paths
  272. * @throws Zend_Pdf_Exception - if a save is performed with an open path
  273. * @return Zend_Pdf_Canvas_Interface
  274. */
  275. public function saveGS()
  276. {
  277. $this->_saveCount++;
  278. $this->_addProcSet('PDF');
  279. $this->_contents .= " q\n";
  280. return $this;
  281. }
  282. /**
  283. * Restore the graphics state that was saved with the last call to saveGS().
  284. *
  285. * @throws Zend_Pdf_Exception - if there is no previously saved state
  286. * @return Zend_Pdf_Canvas_Interface
  287. */
  288. public function restoreGS()
  289. {
  290. if ($this->_saveCount-- <= 0) {
  291. require_once 'Zend/Pdf/Exception.php';
  292. throw new Zend_Pdf_Exception('Restoring graphics state which is not saved');
  293. }
  294. $this->_contents .= " Q\n";
  295. return $this;
  296. }
  297. /**
  298. * Set the transparancy
  299. *
  300. * $alpha == 0 - transparent
  301. * $alpha == 1 - opaque
  302. *
  303. * Transparency modes, supported by PDF:
  304. * Normal (default), Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight,
  305. * SoftLight, Difference, Exclusion
  306. *
  307. * @param float $alpha
  308. * @param string $mode
  309. * @return Zend_Pdf_Canvas_Interface
  310. */
  311. public function setAlpha($alpha, $mode = 'Normal')
  312. {
  313. $this->_addProcSet('Text');
  314. $this->_addProcSet('PDF');
  315. $graphicsState = new Zend_Pdf_Resource_GraphicsState();
  316. $graphicsState->setAlpha($alpha, $mode);
  317. $gStateName = $this->_attachResource('ExtGState', $graphicsState);
  318. $gStateNameObject = new Zend_Pdf_Element_Name($gStateName);
  319. $this->_contents .= $gStateNameObject->toString() . " gs\n";
  320. return $this;
  321. }
  322. /**
  323. * Intersect current clipping area with a circle.
  324. *
  325. * @param float $x
  326. * @param float $y
  327. * @param float $radius
  328. * @param float $startAngle
  329. * @param float $endAngle
  330. * @return Zend_Pdf_Canvas_Interface
  331. */
  332. public function clipCircle($x, $y, $radius, $startAngle = null, $endAngle = null)
  333. {
  334. $this->clipEllipse($x - $radius, $y - $radius,
  335. $x + $radius, $y + $radius,
  336. $startAngle, $endAngle);
  337. return $this;
  338. }
  339. /**
  340. * Intersect current clipping area with a polygon.
  341. *
  342. * Method signatures:
  343. * drawEllipse($x1, $y1, $x2, $y2);
  344. * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
  345. *
  346. * @todo process special cases with $x2-$x1 == 0 or $y2-$y1 == 0
  347. *
  348. * @param float $x1
  349. * @param float $y1
  350. * @param float $x2
  351. * @param float $y2
  352. * @param float $startAngle
  353. * @param float $endAngle
  354. * @return Zend_Pdf_Canvas_Interface
  355. */
  356. public function clipEllipse($x1, $y1, $x2, $y2, $startAngle = null, $endAngle = null)
  357. {
  358. $this->_addProcSet('PDF');
  359. if ($x2 < $x1) {
  360. $temp = $x1;
  361. $x1 = $x2;
  362. $x2 = $temp;
  363. }
  364. if ($y2 < $y1) {
  365. $temp = $y1;
  366. $y1 = $y2;
  367. $y2 = $temp;
  368. }
  369. $x = ($x1 + $x2)/2.;
  370. $y = ($y1 + $y2)/2.;
  371. $xC = new Zend_Pdf_Element_Numeric($x);
  372. $yC = new Zend_Pdf_Element_Numeric($y);
  373. if ($startAngle !== null) {
  374. if ($startAngle != 0) { $startAngle = fmod($startAngle, M_PI*2); }
  375. if ($endAngle != 0) { $endAngle = fmod($endAngle, M_PI*2); }
  376. if ($startAngle > $endAngle) {
  377. $endAngle += M_PI*2;
  378. }
  379. $clipPath = $xC->toString() . ' ' . $yC->toString() . " m\n";
  380. $clipSectors = (int)ceil(($endAngle - $startAngle)/M_PI_4);
  381. $clipRadius = max($x2 - $x1, $y2 - $y1);
  382. for($count = 0; $count <= $clipSectors; $count++) {
  383. $pAngle = $startAngle + ($endAngle - $startAngle)*$count/(float)$clipSectors;
  384. $pX = new Zend_Pdf_Element_Numeric($x + cos($pAngle)*$clipRadius);
  385. $pY = new Zend_Pdf_Element_Numeric($y + sin($pAngle)*$clipRadius);
  386. $clipPath .= $pX->toString() . ' ' . $pY->toString() . " l\n";
  387. }
  388. $this->_contents .= $clipPath . "h\nW\nn\n";
  389. }
  390. $xLeft = new Zend_Pdf_Element_Numeric($x1);
  391. $xRight = new Zend_Pdf_Element_Numeric($x2);
  392. $yUp = new Zend_Pdf_Element_Numeric($y2);
  393. $yDown = new Zend_Pdf_Element_Numeric($y1);
  394. $xDelta = 2*(M_SQRT2 - 1)*($x2 - $x1)/3.;
  395. $yDelta = 2*(M_SQRT2 - 1)*($y2 - $y1)/3.;
  396. $xr = new Zend_Pdf_Element_Numeric($x + $xDelta);
  397. $xl = new Zend_Pdf_Element_Numeric($x - $xDelta);
  398. $yu = new Zend_Pdf_Element_Numeric($y + $yDelta);
  399. $yd = new Zend_Pdf_Element_Numeric($y - $yDelta);
  400. $this->_contents .= $xC->toString() . ' ' . $yUp->toString() . " m\n"
  401. . $xr->toString() . ' ' . $yUp->toString() . ' '
  402. . $xRight->toString() . ' ' . $yu->toString() . ' '
  403. . $xRight->toString() . ' ' . $yC->toString() . " c\n"
  404. . $xRight->toString() . ' ' . $yd->toString() . ' '
  405. . $xr->toString() . ' ' . $yDown->toString() . ' '
  406. . $xC->toString() . ' ' . $yDown->toString() . " c\n"
  407. . $xl->toString() . ' ' . $yDown->toString() . ' '
  408. . $xLeft->toString() . ' ' . $yd->toString() . ' '
  409. . $xLeft->toString() . ' ' . $yC->toString() . " c\n"
  410. . $xLeft->toString() . ' ' . $yu->toString() . ' '
  411. . $xl->toString() . ' ' . $yUp->toString() . ' '
  412. . $xC->toString() . ' ' . $yUp->toString() . " c\n"
  413. . "h\nW\nn\n";
  414. return $this;
  415. }
  416. /**
  417. * Intersect current clipping area with a polygon.
  418. *
  419. * @param array $x - array of float (the X co-ordinates of the vertices)
  420. * @param array $y - array of float (the Y co-ordinates of the vertices)
  421. * @param integer $fillMethod
  422. * @return Zend_Pdf_Canvas_Interface
  423. */
  424. public function clipPolygon($x, $y, $fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING)
  425. {
  426. $this->_addProcSet('PDF');
  427. $firstPoint = true;
  428. foreach ($x as $id => $xVal) {
  429. $xObj = new Zend_Pdf_Element_Numeric($xVal);
  430. $yObj = new Zend_Pdf_Element_Numeric($y[$id]);
  431. if ($firstPoint) {
  432. $path = $xObj->toString() . ' ' . $yObj->toString() . " m\n";
  433. $firstPoint = false;
  434. } else {
  435. $path .= $xObj->toString() . ' ' . $yObj->toString() . " l\n";
  436. }
  437. }
  438. $this->_contents .= $path;
  439. if ($fillMethod == Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING) {
  440. $this->_contents .= " h\n W\nn\n";
  441. } else {
  442. // Even-Odd fill method.
  443. $this->_contents .= " h\n W*\nn\n";
  444. }
  445. return $this;
  446. }
  447. /**
  448. * Intersect current clipping area with a rectangle.
  449. *
  450. * @param float $x1
  451. * @param float $y1
  452. * @param float $x2
  453. * @param float $y2
  454. * @return Zend_Pdf_Canvas_Interface
  455. */
  456. public function clipRectangle($x1, $y1, $x2, $y2)
  457. {
  458. $this->_addProcSet('PDF');
  459. $x1Obj = new Zend_Pdf_Element_Numeric($x1);
  460. $y1Obj = new Zend_Pdf_Element_Numeric($y1);
  461. $widthObj = new Zend_Pdf_Element_Numeric($x2 - $x1);
  462. $height2Obj = new Zend_Pdf_Element_Numeric($y2 - $y1);
  463. $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
  464. . $widthObj->toString() . ' ' . $height2Obj->toString() . " re\n"
  465. . " W\nn\n";
  466. return $this;
  467. }
  468. // ------------------------------------------------------------------------------------------
  469. /**
  470. * Draw a circle centered on x, y with a radius of radius.
  471. *
  472. * Method signatures:
  473. * drawCircle($x, $y, $radius);
  474. * drawCircle($x, $y, $radius, $fillType);
  475. * drawCircle($x, $y, $radius, $startAngle, $endAngle);
  476. * drawCircle($x, $y, $radius, $startAngle, $endAngle, $fillType);
  477. *
  478. *
  479. * It's not a really circle, because PDF supports only cubic Bezier curves.
  480. * But _very_ good approximation.
  481. * It differs from a real circle on a maximum 0.00026 radiuses
  482. * (at PI/8, 3*PI/8, 5*PI/8, 7*PI/8, 9*PI/8, 11*PI/8, 13*PI/8 and 15*PI/8 angles).
  483. * At 0, PI/4, PI/2, 3*PI/4, PI, 5*PI/4, 3*PI/2 and 7*PI/4 it's exactly a tangent to a circle.
  484. *
  485. * @param float $x
  486. * @param float $y
  487. * @param float $radius
  488. * @param mixed $param4
  489. * @param mixed $param5
  490. * @param mixed $param6
  491. * @return Zend_Pdf_Canvas_Interface
  492. */
  493. public function drawCircle($x, $y, $radius, $param4 = null, $param5 = null, $param6 = null)
  494. {
  495. $this->drawEllipse($x - $radius, $y - $radius,
  496. $x + $radius, $y + $radius,
  497. $param4, $param5, $param6);
  498. return $this;
  499. }
  500. /**
  501. * Draw an ellipse inside the specified rectangle.
  502. *
  503. * Method signatures:
  504. * drawEllipse($x1, $y1, $x2, $y2);
  505. * drawEllipse($x1, $y1, $x2, $y2, $fillType);
  506. * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
  507. * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle, $fillType);
  508. *
  509. * @todo process special cases with $x2-$x1 == 0 or $y2-$y1 == 0
  510. *
  511. * @param float $x1
  512. * @param float $y1
  513. * @param float $x2
  514. * @param float $y2
  515. * @param mixed $param5
  516. * @param mixed $param6
  517. * @param mixed $param7
  518. * @return Zend_Pdf_Canvas_Interface
  519. */
  520. public function drawEllipse($x1, $y1, $x2, $y2, $param5 = null, $param6 = null, $param7 = null)
  521. {
  522. if ($param5 === null) {
  523. // drawEllipse($x1, $y1, $x2, $y2);
  524. $startAngle = null;
  525. $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE;
  526. } else if ($param6 === null) {
  527. // drawEllipse($x1, $y1, $x2, $y2, $fillType);
  528. $startAngle = null;
  529. $fillType = $param5;
  530. } else {
  531. // drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
  532. // drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle, $fillType);
  533. $startAngle = $param5;
  534. $endAngle = $param6;
  535. if ($param7 === null) {
  536. $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE;
  537. } else {
  538. $fillType = $param7;
  539. }
  540. }
  541. $this->_addProcSet('PDF');
  542. if ($x2 < $x1) {
  543. $temp = $x1;
  544. $x1 = $x2;
  545. $x2 = $temp;
  546. }
  547. if ($y2 < $y1) {
  548. $temp = $y1;
  549. $y1 = $y2;
  550. $y2 = $temp;
  551. }
  552. $x = ($x1 + $x2)/2.;
  553. $y = ($y1 + $y2)/2.;
  554. $xC = new Zend_Pdf_Element_Numeric($x);
  555. $yC = new Zend_Pdf_Element_Numeric($y);
  556. if ($startAngle !== null) {
  557. if ($startAngle != 0) { $startAngle = fmod($startAngle, M_PI*2); }
  558. if ($endAngle != 0) { $endAngle = fmod($endAngle, M_PI*2); }
  559. if ($startAngle > $endAngle) {
  560. $endAngle += M_PI*2;
  561. }
  562. $clipPath = $xC->toString() . ' ' . $yC->toString() . " m\n";
  563. $clipSectors = (int)ceil(($endAngle - $startAngle)/M_PI_4);
  564. $clipRadius = max($x2 - $x1, $y2 - $y1);
  565. for($count = 0; $count <= $clipSectors; $count++) {
  566. $pAngle = $startAngle + ($endAngle - $startAngle)*$count/(float)$clipSectors;
  567. $pX = new Zend_Pdf_Element_Numeric($x + cos($pAngle)*$clipRadius);
  568. $pY = new Zend_Pdf_Element_Numeric($y + sin($pAngle)*$clipRadius);
  569. $clipPath .= $pX->toString() . ' ' . $pY->toString() . " l\n";
  570. }
  571. $this->_contents .= "q\n" . $clipPath . "h\nW\nn\n";
  572. }
  573. $xLeft = new Zend_Pdf_Element_Numeric($x1);
  574. $xRight = new Zend_Pdf_Element_Numeric($x2);
  575. $yUp = new Zend_Pdf_Element_Numeric($y2);
  576. $yDown = new Zend_Pdf_Element_Numeric($y1);
  577. $xDelta = 2*(M_SQRT2 - 1)*($x2 - $x1)/3.;
  578. $yDelta = 2*(M_SQRT2 - 1)*($y2 - $y1)/3.;
  579. $xr = new Zend_Pdf_Element_Numeric($x + $xDelta);
  580. $xl = new Zend_Pdf_Element_Numeric($x - $xDelta);
  581. $yu = new Zend_Pdf_Element_Numeric($y + $yDelta);
  582. $yd = new Zend_Pdf_Element_Numeric($y - $yDelta);
  583. $this->_contents .= $xC->toString() . ' ' . $yUp->toString() . " m\n"
  584. . $xr->toString() . ' ' . $yUp->toString() . ' '
  585. . $xRight->toString() . ' ' . $yu->toString() . ' '
  586. . $xRight->toString() . ' ' . $yC->toString() . " c\n"
  587. . $xRight->toString() . ' ' . $yd->toString() . ' '
  588. . $xr->toString() . ' ' . $yDown->toString() . ' '
  589. . $xC->toString() . ' ' . $yDown->toString() . " c\n"
  590. . $xl->toString() . ' ' . $yDown->toString() . ' '
  591. . $xLeft->toString() . ' ' . $yd->toString() . ' '
  592. . $xLeft->toString() . ' ' . $yC->toString() . " c\n"
  593. . $xLeft->toString() . ' ' . $yu->toString() . ' '
  594. . $xl->toString() . ' ' . $yUp->toString() . ' '
  595. . $xC->toString() . ' ' . $yUp->toString() . " c\n";
  596. switch ($fillType) {
  597. case Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE:
  598. $this->_contents .= " B*\n";
  599. break;
  600. case Zend_Pdf_Page::SHAPE_DRAW_FILL:
  601. $this->_contents .= " f*\n";
  602. break;
  603. case Zend_Pdf_Page::SHAPE_DRAW_STROKE:
  604. $this->_contents .= " S\n";
  605. break;
  606. }
  607. if ($startAngle !== null) {
  608. $this->_contents .= "Q\n";
  609. }
  610. return $this;
  611. }
  612. /**
  613. * Draw an image at the specified position on the page.
  614. *
  615. * @param Zend_Pdf_Image $image
  616. * @param float $x1
  617. * @param float $y1
  618. * @param float $x2
  619. * @param float $y2
  620. * @return Zend_Pdf_Canvas_Interface
  621. */
  622. public function drawImage(Zend_Pdf_Resource_Image $image, $x1, $y1, $x2, $y2)
  623. {
  624. $this->_addProcSet('PDF');
  625. $imageName = $this->_attachResource('XObject', $image);
  626. $imageNameObj = new Zend_Pdf_Element_Name($imageName);
  627. $x1Obj = new Zend_Pdf_Element_Numeric($x1);
  628. $y1Obj = new Zend_Pdf_Element_Numeric($y1);
  629. $widthObj = new Zend_Pdf_Element_Numeric($x2 - $x1);
  630. $heightObj = new Zend_Pdf_Element_Numeric($y2 - $y1);
  631. $this->_contents .= "q\n"
  632. . '1 0 0 1 ' . $x1Obj->toString() . ' ' . $y1Obj->toString() . " cm\n"
  633. . $widthObj->toString() . ' 0 0 ' . $heightObj->toString() . " 0 0 cm\n"
  634. . $imageNameObj->toString() . " Do\n"
  635. . "Q\n";
  636. return $this;
  637. }
  638. /**
  639. * Draw a LayoutBox at the specified position on the page.
  640. *
  641. * @internal (not implemented now)
  642. *
  643. * @param Zend_Pdf_Element_LayoutBox $box
  644. * @param float $x
  645. * @param float $y
  646. * @return Zend_Pdf_Canvas_Interface
  647. */
  648. public function drawLayoutBox($box, $x, $y)
  649. {
  650. /** @todo implementation */
  651. return $this;
  652. }
  653. /**
  654. * Draw a line from x1,y1 to x2,y2.
  655. *
  656. * @param float $x1
  657. * @param float $y1
  658. * @param float $x2
  659. * @param float $y2
  660. * @return Zend_Pdf_Canvas_Interface
  661. */
  662. public function drawLine($x1, $y1, $x2, $y2)
  663. {
  664. $this->_addProcSet('PDF');
  665. $x1Obj = new Zend_Pdf_Element_Numeric($x1);
  666. $y1Obj = new Zend_Pdf_Element_Numeric($y1);
  667. $x2Obj = new Zend_Pdf_Element_Numeric($x2);
  668. $y2Obj = new Zend_Pdf_Element_Numeric($y2);
  669. $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " m\n"
  670. . $x2Obj->toString() . ' ' . $y2Obj->toString() . " l\n S\n";
  671. return $this;
  672. }
  673. /**
  674. * Draw a polygon.
  675. *
  676. * If $fillType is Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE or
  677. * Zend_Pdf_Page::SHAPE_DRAW_FILL, then polygon is automatically closed.
  678. * See detailed description of these methods in a PDF documentation
  679. * (section 4.4.2 Path painting Operators, Filling)
  680. *
  681. * @param array $x - array of float (the X co-ordinates of the vertices)
  682. * @param array $y - array of float (the Y co-ordinates of the vertices)
  683. * @param integer $fillType
  684. * @param integer $fillMethod
  685. * @return Zend_Pdf_Canvas_Interface
  686. */
  687. public function drawPolygon($x, $y,
  688. $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE,
  689. $fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING)
  690. {
  691. $this->_addProcSet('PDF');
  692. $firstPoint = true;
  693. foreach ($x as $id => $xVal) {
  694. $xObj = new Zend_Pdf_Element_Numeric($xVal);
  695. $yObj = new Zend_Pdf_Element_Numeric($y[$id]);
  696. if ($firstPoint) {
  697. $path = $xObj->toString() . ' ' . $yObj->toString() . " m\n";
  698. $firstPoint = false;
  699. } else {
  700. $path .= $xObj->toString() . ' ' . $yObj->toString() . " l\n";
  701. }
  702. }
  703. $this->_contents .= $path;
  704. switch ($fillType) {
  705. case Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE:
  706. if ($fillMethod == Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING) {
  707. $this->_contents .= " b\n";
  708. } else {
  709. // Even-Odd fill method.
  710. $this->_contents .= " b*\n";
  711. }
  712. break;
  713. case Zend_Pdf_Page::SHAPE_DRAW_FILL:
  714. if ($fillMethod == Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING) {
  715. $this->_contents .= " h\n f\n";
  716. } else {
  717. // Even-Odd fill method.
  718. $this->_contents .= " h\n f*\n";
  719. }
  720. break;
  721. case Zend_Pdf_Page::SHAPE_DRAW_STROKE:
  722. $this->_contents .= " S\n";
  723. break;
  724. }
  725. return $this;
  726. }
  727. /**
  728. * Draw a rectangle.
  729. *
  730. * Fill types:
  731. * Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE - fill rectangle and stroke (default)
  732. * Zend_Pdf_Page::SHAPE_DRAW_STROKE - stroke rectangle
  733. * Zend_Pdf_Page::SHAPE_DRAW_FILL - fill rectangle
  734. *
  735. * @param float $x1
  736. * @param float $y1
  737. * @param float $x2
  738. * @param float $y2
  739. * @param integer $fillType
  740. * @return Zend_Pdf_Canvas_Interface
  741. */
  742. public function drawRectangle($x1, $y1, $x2, $y2, $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE)
  743. {
  744. $this->_addProcSet('PDF');
  745. $x1Obj = new Zend_Pdf_Element_Numeric($x1);
  746. $y1Obj = new Zend_Pdf_Element_Numeric($y1);
  747. $widthObj = new Zend_Pdf_Element_Numeric($x2 - $x1);
  748. $height2Obj = new Zend_Pdf_Element_Numeric($y2 - $y1);
  749. $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
  750. . $widthObj->toString() . ' ' . $height2Obj->toString() . " re\n";
  751. switch ($fillType) {
  752. case Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE:
  753. $this->_contents .= " B*\n";
  754. break;
  755. case Zend_Pdf_Page::SHAPE_DRAW_FILL:
  756. $this->_contents .= " f*\n";
  757. break;
  758. case Zend_Pdf_Page::SHAPE_DRAW_STROKE:
  759. $this->_contents .= " S\n";
  760. break;
  761. }
  762. return $this;
  763. }
  764. /**
  765. * Draw a rounded rectangle.
  766. *
  767. * Fill types:
  768. * Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE - fill rectangle and stroke (default)
  769. * Zend_Pdf_Page::SHAPE_DRAW_STROKE - stroke rectangle
  770. * Zend_Pdf_Page::SHAPE_DRAW_FILL - fill rectangle
  771. *
  772. * radius is an integer representing radius of the four corners, or an array
  773. * of four integers representing the radius starting at top left, going
  774. * clockwise
  775. *
  776. * @param float $x1
  777. * @param float $y1
  778. * @param float $x2
  779. * @param float $y2
  780. * @param integer|array $radius
  781. * @param integer $fillType
  782. * @return Zend_Pdf_Canvas_Interface
  783. */
  784. public function drawRoundedRectangle($x1, $y1, $x2, $y2, $radius,
  785. $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE)
  786. {
  787. $this->_addProcSet('PDF');
  788. if(!is_array($radius)) {
  789. $radius = array($radius, $radius, $radius, $radius);
  790. } else {
  791. for ($i = 0; $i < 4; $i++) {
  792. if(!isset($radius[$i])) {
  793. $radius[$i] = 0;
  794. }
  795. }
  796. }
  797. $topLeftX = $x1;
  798. $topLeftY = $y2;
  799. $topRightX = $x2;
  800. $topRightY = $y2;
  801. $bottomRightX = $x2;
  802. $bottomRightY = $y1;
  803. $bottomLeftX = $x1;
  804. $bottomLeftY = $y1;
  805. //draw top side
  806. $x1Obj = new Zend_Pdf_Element_Numeric($topLeftX + $radius[0]);
  807. $y1Obj = new Zend_Pdf_Element_Numeric($topLeftY);
  808. $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " m\n";
  809. $x1Obj = new Zend_Pdf_Element_Numeric($topRightX - $radius[1]);
  810. $y1Obj = new Zend_Pdf_Element_Numeric($topRightY);
  811. $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
  812. //draw top right corner if needed
  813. if ($radius[1] != 0) {
  814. $x1Obj = new Zend_Pdf_Element_Numeric($topRightX);
  815. $y1Obj = new Zend_Pdf_Element_Numeric($topRightY);
  816. $x2Obj = new Zend_Pdf_Element_Numeric($topRightX);
  817. $y2Obj = new Zend_Pdf_Element_Numeric($topRightY);
  818. $x3Obj = new Zend_Pdf_Element_Numeric($topRightX);
  819. $y3Obj = new Zend_Pdf_Element_Numeric($topRightY - $radius[1]);
  820. $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
  821. . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' '
  822. . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' '
  823. . " c\n";
  824. }
  825. //draw right side
  826. $x1Obj = new Zend_Pdf_Element_Numeric($bottomRightX);
  827. $y1Obj = new Zend_Pdf_Element_Numeric($bottomRightY + $radius[2]);
  828. $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
  829. //draw bottom right corner if needed
  830. if ($radius[2] != 0) {
  831. $x1Obj = new Zend_Pdf_Element_Numeric($bottomRightX);
  832. $y1Obj = new Zend_Pdf_Element_Numeric($bottomRightY);
  833. $x2Obj = new Zend_Pdf_Element_Numeric($bottomRightX);
  834. $y2Obj = new Zend_Pdf_Element_Numeric($bottomRightY);
  835. $x3Obj = new Zend_Pdf_Element_Numeric($bottomRightX - $radius[2]);
  836. $y3Obj = new Zend_Pdf_Element_Numeric($bottomRightY);
  837. $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
  838. . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' '
  839. . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' '
  840. . " c\n";
  841. }
  842. //draw bottom side
  843. $x1Obj = new Zend_Pdf_Element_Numeric($bottomLeftX + $radius[3]);
  844. $y1Obj = new Zend_Pdf_Element_Numeric($bottomLeftY);
  845. $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
  846. //draw bottom left corner if needed
  847. if ($radius[3] != 0) {
  848. $x1Obj = new Zend_Pdf_Element_Numeric($bottomLeftX);
  849. $y1Obj = new Zend_Pdf_Element_Numeric($bottomLeftY);
  850. $x2Obj = new Zend_Pdf_Element_Numeric($bottomLeftX);
  851. $y2Obj = new Zend_Pdf_Element_Numeric($bottomLeftY);
  852. $x3Obj = new Zend_Pdf_Element_Numeric($bottomLeftX);
  853. $y3Obj = new Zend_Pdf_Element_Numeric($bottomLeftY + $radius[3]);
  854. $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
  855. . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' '
  856. . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' '
  857. . " c\n";
  858. }
  859. //draw left side
  860. $x1Obj = new Zend_Pdf_Element_Numeric($topLeftX);
  861. $y1Obj = new Zend_Pdf_Element_Numeric($topLeftY - $radius[0]);
  862. $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . " l\n";
  863. //draw top left corner if needed
  864. if ($radius[0] != 0) {
  865. $x1Obj = new Zend_Pdf_Element_Numeric($topLeftX);
  866. $y1Obj = new Zend_Pdf_Element_Numeric($topLeftY);
  867. $x2Obj = new Zend_Pdf_Element_Numeric($topLeftX);
  868. $y2Obj = new Zend_Pdf_Element_Numeric($topLeftY);
  869. $x3Obj = new Zend_Pdf_Element_Numeric($topLeftX + $radius[0]);
  870. $y3Obj = new Zend_Pdf_Element_Numeric($topLeftY);
  871. $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' '
  872. . $x2Obj->toString() . ' ' . $y2Obj->toString() . ' '
  873. . $x3Obj->toString() . ' ' . $y3Obj->toString() . ' '
  874. . " c\n";
  875. }
  876. switch ($fillType) {
  877. case Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE:
  878. $this->_contents .= " B*\n";
  879. break;
  880. case Zend_Pdf_Page::SHAPE_DRAW_FILL:
  881. $this->_contents .= " f*\n";
  882. break;
  883. case Zend_Pdf_Page::SHAPE_DRAW_STROKE:
  884. $this->_contents .= " S\n";
  885. break;
  886. }
  887. return $this;
  888. }
  889. /**
  890. * Draw a line of text at the specified position.
  891. *
  892. * @param string $text
  893. * @param float $x
  894. * @param float $y
  895. * @param string $charEncoding (optional) Character encoding of source text.
  896. * Defaults to current locale.
  897. * @throws Zend_Pdf_Exception
  898. * @return Zend_Pdf_Canvas_Interface
  899. */
  900. public function drawText($text, $x, $y, $charEncoding = '')
  901. {
  902. if ($this->_font === null) {
  903. require_once 'Zend/Pdf/Exception.php';
  904. throw new Zend_Pdf_Exception('Font has not been set');
  905. }
  906. $this->_addProcSet('Text');
  907. $textObj = new Zend_Pdf_Element_String($this->_font->encodeString($text, $charEncoding));
  908. $xObj = new Zend_Pdf_Element_Numeric($x);
  909. $yObj = new Zend_Pdf_Element_Numeric($y);
  910. $this->_contents .= "BT\n"
  911. . $xObj->toString() . ' ' . $yObj->toString() . " Td\n"
  912. . $textObj->toString() . " Tj\n"
  913. . "ET\n";
  914. return $this;
  915. }
  916. /**
  917. * Close the path by drawing a straight line back to it's beginning.
  918. *
  919. * @internal (needs implementation)
  920. *
  921. * @throws Zend_Pdf_Exception - if a path hasn't been started with pathMove()
  922. * @return Zend_Pdf_Canvas_Interface
  923. */
  924. public function pathClose()
  925. {
  926. /** @todo implementation */
  927. return $this;
  928. }
  929. /**
  930. * Continue the open path in a straight line to the specified position.
  931. *
  932. * @internal (needs implementation)
  933. *
  934. * @param float $x - the X co-ordinate to move to
  935. * @param float $y - the Y co-ordinate to move to
  936. * @return Zend_Pdf_Canvas_Interface
  937. */
  938. public function pathLine($x, $y)
  939. {
  940. /** @todo implementation */
  941. return $this;
  942. }
  943. /**
  944. * Start a new path at the specified position. If a path has already been started,
  945. * move the cursor without drawing a line.
  946. *
  947. * @internal (needs implementation)
  948. *
  949. * @param float $x - the X co-ordinate to move to
  950. * @param float $y - the Y co-ordinate to move to
  951. * @return Zend_Pdf_Canvas_Interface
  952. */
  953. public function pathMove($x, $y)
  954. {
  955. /** @todo implementation */
  956. return $this;
  957. }
  958. /**
  959. * Rotate the page.
  960. *
  961. * @param float $x - the X co-ordinate of rotation point
  962. * @param float $y - the Y co-ordinate of rotation point
  963. * @param float $angle - rotation angle
  964. * @return Zend_Pdf_Canvas_Interface
  965. */
  966. public function rotate($x, $y, $angle)
  967. {
  968. $cos = new Zend_Pdf_Element_Numeric(cos($angle));
  969. $sin = new Zend_Pdf_Element_Numeric(sin($angle));
  970. $mSin = new Zend_Pdf_Element_Numeric(-$sin->value);
  971. $xObj = new Zend_Pdf_Element_Numeric($x);
  972. $yObj = new Zend_Pdf_Element_Numeric($y);
  973. $mXObj = new Zend_Pdf_Element_Numeric(-$x);
  974. $mYObj = new Zend_Pdf_Element_Numeric(-$y);
  975. $this->_addProcSet('PDF');
  976. $this->_contents .= '1 0 0 1 ' . $xObj->toString() . ' ' . $yObj->toString() . " cm\n"
  977. . $cos->toString() . ' ' . $sin->toString() . ' ' . $mSin->toString() . ' ' . $cos->toString() . " 0 0 cm\n"
  978. . '1 0 0 1 ' . $mXObj->toString() . ' ' . $mYObj->toString() . " cm\n";
  979. return $this;
  980. }
  981. /**
  982. * Scale coordination system.
  983. *
  984. * @param float $xScale - X dimention scale factor
  985. * @param float $yScale - Y dimention scale factor
  986. * @return Zend_Pdf_Canvas_Interface
  987. */
  988. public function scale($xScale, $yScale)
  989. {
  990. $xScaleObj = new Zend_Pdf_Element_Numeric($xScale);
  991. $yScaleObj = new Zend_Pdf_Element_Numeric($yScale);
  992. $this->_addProcSet('PDF');
  993. $this->_contents .= $xScaleObj->toString() . ' 0 0 ' . $yScaleObj->toString() . " 0 0 cm\n";
  994. return $this;
  995. }
  996. /**
  997. * Translate coordination system.
  998. *
  999. * @param float $xShift - X coordinate shift
  1000. * @param float $yShift - Y coordinate shift
  1001. * @return Zend_Pdf_Canvas_Interface
  1002. */
  1003. public function translate($xShift, $yShift)
  1004. {
  1005. $xShiftObj = new Zend_Pdf_Element_Numeric($xShift);
  1006. $yShiftObj = new Zend_Pdf_Element_Numeric($yShift);
  1007. $this->_addProcSet('PDF');
  1008. $this->_contents .= '1 0 0 1 ' . $xShiftObj->toString() . ' ' . $yShiftObj->toString() . " cm\n";
  1009. return $this;
  1010. }
  1011. /**
  1012. * Translate coordination system.
  1013. *
  1014. * @param float $x - the X co-ordinate of axis skew point
  1015. * @param float $y - the Y co-ordinate of axis skew point
  1016. * @param float $xAngle - X axis skew angle
  1017. * @param float $yAngle - Y axis skew angle
  1018. * @return Zend_Pdf_Canvas_Interface
  1019. */
  1020. public function skew($x, $y, $xAngle, $yAngle)
  1021. {
  1022. $tanXObj = new Zend_Pdf_Element_Numeric(tan($xAngle));
  1023. $tanYObj = new Zend_Pdf_Element_Numeric(-tan($yAngle));
  1024. $xObj = new Zend_Pdf_Element_Numeric($x);
  1025. $yObj = new Zend_Pdf_Element_Numeric($y);
  1026. $mXObj = new Zend_Pdf_Element_Numeric(-$x);
  1027. $mYObj = new Zend_Pdf_Element_Numeric(-$y);
  1028. $this->_addProcSet('PDF');
  1029. $this->_contents .= '1 0 0 1 ' . $xObj->toString() . ' ' . $yObj->toString() . " cm\n"
  1030. . '1 ' . $tanXObj->toString() . ' ' . $tanYObj->toString() . " 1 0 0 cm\n"
  1031. . '1 0 0 1 ' . $mXObj->toString() . ' ' . $mYObj->toString() . " cm\n";
  1032. return $this;
  1033. }
  1034. /**
  1035. * Writes the raw data to the page's content stream.
  1036. *
  1037. * Be sure to consult the PDF reference to ensure your syntax is correct. No
  1038. * attempt is made to ensure the validity of the stream data.
  1039. *
  1040. * @param string $data
  1041. * @param string $procSet (optional) Name of ProcSet to add.
  1042. * @return Zend_Pdf_Canvas_Interface
  1043. */
  1044. public function rawWrite($data, $procSet = null)
  1045. {
  1046. if (! empty($procSet)) {
  1047. $this->_addProcSet($procSet);
  1048. }
  1049. $this->_contents .= $data;
  1050. return $this;
  1051. }
  1052. }