myPdf.class.php 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  1. <?php
  2. /**
  3. * HTML2PDF Librairy - myPdf class
  4. *
  5. * HTML => PDF convertor
  6. * distributed under the LGPL License
  7. *
  8. * @author Laurent MINGUET <webmaster@html2pdf.fr>
  9. * @version 4.03
  10. */
  11. require_once(dirname(__FILE__).'/tcpdfConfig.php');
  12. require_once(dirname(__FILE__).'/../_tcpdf_'.HTML2PDF_USED_TCPDF_VERSION.'/tcpdf.php');
  13. class HTML2PDF_myPdf extends TCPDF
  14. {
  15. protected $_footerParam = array();
  16. protected $_transf = array();
  17. protected $_myLastPageGroup = null;
  18. protected $_myLastPageGroupNb = 0;
  19. // used to make a radius with bezier : (4/3 * (sqrt(2) - 1))
  20. const MY_ARC = 0.5522847498;
  21. // nb of segment to build a arc with bezier curv
  22. const ARC_NB_SEGMENT = 8;
  23. /**
  24. * class constructor
  25. *
  26. * @param string $orientation page orientation, same as TCPDF
  27. * @param string $unit User measure unit, same as TCPDF
  28. * @param mixed $format The format used for pages, same as TCPDF
  29. * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  30. * @param String $encoding charset encoding; default is UTF-8
  31. * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  32. * @access public
  33. */
  34. public function __construct(
  35. $orientation='P',
  36. $unit='mm',
  37. $format='A4',
  38. $unicode=true,
  39. $encoding='UTF-8',
  40. $diskcache=false)
  41. {
  42. // call the parent constructor
  43. parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache);
  44. // init the specific parameters used by HTML2PDF
  45. $this->SetCreator(PDF_CREATOR);
  46. $this->SetAutoPageBreak(false, 0);
  47. $this->linestyleCap = '2 J';
  48. $this->setPrintHeader(false);
  49. $this->jpeg_quality = 90;
  50. // prepare the automatic footer
  51. $this->SetMyFooter();
  52. $this->cMargin = 0;
  53. }
  54. /**
  55. * Set the parameters for the automatic footer
  56. *
  57. * @param boolean $page display the page number
  58. * @param boolean $date display the date
  59. * @param boolean $hour display the hour
  60. * @param boolean $form display a warning abour forms
  61. * @access public
  62. */
  63. public function SetMyFooter($page = false, $date = false, $hour = false, $form = false)
  64. {
  65. $page = ($page ? true : false);
  66. $date = ($date ? true : false);
  67. $hour = ($hour ? true : false);
  68. $form = ($form ? true : false);
  69. $this->_footerParam = array('page' => $page, 'date' => $date, 'hour' => $hour, 'form' => $form);
  70. }
  71. /**
  72. * This function is call automatically by TCPDF at the end of a page
  73. * It takes no parameters
  74. *
  75. * @access public
  76. */
  77. public function Footer()
  78. {
  79. // prepare the text from the tranlated text
  80. $txt = '';
  81. if ($this->_footerParam['form']) {
  82. $txt = (HTML2PDF_locale::get('pdf05'));
  83. }
  84. if ($this->_footerParam['date'] && $this->_footerParam['hour']) {
  85. $txt.= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf03'));
  86. }
  87. if ($this->_footerParam['date'] && !$this->_footerParam['hour']) {
  88. $txt.= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf01'));
  89. }
  90. if (!$this->_footerParam['date'] && $this->_footerParam['hour']) {
  91. $txt.= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf02'));
  92. }
  93. if ($this->_footerParam['page']) {
  94. $txt.= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf04'));
  95. }
  96. if (strlen($txt)>0) {
  97. // replace some values
  98. $toReplace = array(
  99. '[[date_d]]' => date('d'),
  100. '[[date_m]]' => date('m'),
  101. '[[date_y]]' => date('Y'),
  102. '[[date_h]]' => date('H'),
  103. '[[date_i]]' => date('i'),
  104. '[[date_s]]' => date('s'),
  105. '[[page_cu]]' => $this->getMyNumPage(),
  106. '[[page_nb]]' => $this->getMyAliasNbPages(),
  107. );
  108. $txt = str_replace(array_keys($toReplace), array_values($toReplace), $txt);
  109. // draw the footer
  110. parent::SetY(-11);
  111. $this->SetFont('helvetica', 'I', 8);
  112. $this->Cell(0, 10, $txt, 0, 0, 'R');
  113. }
  114. }
  115. /**
  116. * after cloning a object, we does not want to clone all the front informations
  117. * because it take a lot a time and a lot of memory => we use reference
  118. *
  119. * @param &HTML2PDF_myPdf object
  120. * @access public
  121. */
  122. public function cloneFontFrom(&$pdf)
  123. {
  124. $this->fonts = &$pdf->getFonts();
  125. $this->FontFiles = &$pdf->getFontFiles();
  126. $this->diffs = &$pdf->getDiffs();
  127. $this->fontlist = &$pdf->getFontList();
  128. $this->numfonts = &$pdf->getNumFonts();
  129. $this->fontkeys = &$pdf->getFontKeys();
  130. $this->font_obj_ids = &$pdf->getFontObjIds();
  131. $this->annotation_fonts = &$pdf->getAnnotFonts();
  132. }
  133. /**
  134. * multiple public accessor for some private attributs
  135. * used only by cloneFontFrom
  136. *
  137. * @return &array
  138. * @access public
  139. */
  140. public function &getFonts()
  141. {
  142. return $this->fonts;
  143. }
  144. public function &getFontFiles()
  145. {
  146. return $this->FontFiles;
  147. }
  148. public function &getDiffs()
  149. {
  150. return $this->diffs;
  151. }
  152. public function &getFontList()
  153. {
  154. return $this->fontlist;
  155. }
  156. public function &getNumFonts()
  157. {
  158. return $this->numfonts;
  159. }
  160. public function &getFontKeys()
  161. {
  162. return $this->fontkeys;
  163. }
  164. public function &getFontObjIds()
  165. {
  166. return $this->font_obj_ids;
  167. }
  168. public function &getAnnotFonts()
  169. {
  170. return $this->annotation_fonts;
  171. }
  172. /**
  173. * Verify that a Font is already loaded
  174. *
  175. * @param string Font Key
  176. * @return boolean
  177. * @access public
  178. */
  179. public function isLoadedFont($fontKey)
  180. {
  181. if (isset($this->fonts[$fontKey])) {
  182. return true;
  183. }
  184. if (isset($this->CoreFonts[$fontKey])) {
  185. return true;
  186. }
  187. return false;
  188. }
  189. /**
  190. * Get the Word Spacing
  191. *
  192. * @access public
  193. * @return float word spacing
  194. */
  195. public function getWordSpacing()
  196. {
  197. return $this->ws;
  198. }
  199. /**
  200. * set the Word Spacing
  201. *
  202. * @param float word spacing
  203. * @access public
  204. */
  205. public function setWordSpacing($ws=0.)
  206. {
  207. $this->ws = $ws;
  208. $this->_out(sprintf('%.3F Tw', $ws*$this->k));
  209. }
  210. /**
  211. * start to use a rectangular Cliping Path with radius corners
  212. *
  213. * @param float $x (top left corner)
  214. * @param float $y (top left corner)
  215. * @param float $w (x+w = botom rigth corner)
  216. * @param float $h (y+h = botom rigth corner)
  217. * @param array $cornerTL radius of the Top Left corner
  218. * @param array $cornerTR radius of the Top Right corner
  219. * @param array $cornerBL radius of the Bottom Left corner
  220. * @param array $cornerBR radius of the Bottom Right corner
  221. * @access public
  222. */
  223. public function clippingPathStart(
  224. $x = null,
  225. $y = null,
  226. $w = null,
  227. $h = null,
  228. $cornerTL=null,
  229. $cornerTR=null,
  230. $cornerBL=null,
  231. $cornerBR=null)
  232. {
  233. // init the path
  234. $path = '';
  235. // if we have the position and the size of the rectangle, we can proceed
  236. if ($x!==null && $y!==null && $w!==null && $h!==null) {
  237. // the positions of the rectangle's corners
  238. $x1 = $x*$this->k;
  239. $y1 = ($this->h-$y)*$this->k;
  240. $x2 = ($x+$w)*$this->k;
  241. $y2 = ($this->h-$y)*$this->k;
  242. $x3 = ($x+$w)*$this->k;
  243. $y3 = ($this->h-$y-$h)*$this->k;
  244. $x4 = $x*$this->k;
  245. $y4 = ($this->h-$y-$h)*$this->k;
  246. // if we have at least one radius corner, then we proceed to a specific path, else it is just a rectangle
  247. if ($cornerTL || $cornerTR || $cornerBL || $cornerBR) {
  248. // prepare the radius values
  249. if ($cornerTL) {
  250. $cornerTL[0] = $cornerTL[0]*$this->k;
  251. $cornerTL[1] =-$cornerTL[1]*$this->k;
  252. }
  253. if ($cornerTR) {
  254. $cornerTR[0] = $cornerTR[0]*$this->k;
  255. $cornerTR[1] =-$cornerTR[1]*$this->k;
  256. }
  257. if ($cornerBL) {
  258. $cornerBL[0] = $cornerBL[0]*$this->k;
  259. $cornerBL[1] =-$cornerBL[1]*$this->k;
  260. }
  261. if ($cornerBR) {
  262. $cornerBR[0] = $cornerBR[0]*$this->k;
  263. $cornerBR[1] =-$cornerBR[1]*$this->k;
  264. }
  265. // if TL radius then specific start else (X1,Y1)
  266. if ($cornerTL) {
  267. $path.= sprintf('%.2F %.2F m ', $x1+$cornerTL[0], $y1);
  268. } else {
  269. $path.= sprintf('%.2F %.2F m ', $x1, $y1);
  270. }
  271. // if TR radius then line + arc, else line to (X2,Y2)
  272. if ($cornerTR) {
  273. $xt1 = ($x2-$cornerTR[0])+$cornerTR[0]*self::MY_ARC;
  274. $yt1 = ($y2+$cornerTR[1])-$cornerTR[1];
  275. $xt2 = ($x2-$cornerTR[0])+$cornerTR[0];
  276. $yt2 = ($y2+$cornerTR[1])-$cornerTR[1]*self::MY_ARC;
  277. $path.= sprintf('%.2F %.2F l ', $x2-$cornerTR[0], $y2);
  278. $path.= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x2, $y2+$cornerTR[1]);
  279. } else {
  280. $path.= sprintf('%.2F %.2F l ', $x2, $y2);
  281. }
  282. // if BR radius then line + arc, else line to (X3, Y3)
  283. if ($cornerBR) {
  284. $xt1 = ($x3-$cornerBR[0])+$cornerBR[0];
  285. $yt1 = ($y3-$cornerBR[1])+$cornerBR[1]*self::MY_ARC;
  286. $xt2 = ($x3-$cornerBR[0])+$cornerBR[0]*self::MY_ARC;
  287. $yt2 = ($y3-$cornerBR[1])+$cornerBR[1];
  288. $path.= sprintf('%.2F %.2F l ', $x3, $y3-$cornerBR[1]);
  289. $path.= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x3-$cornerBR[0], $y3);
  290. } else {
  291. $path.= sprintf('%.2F %.2F l ', $x3, $y3);
  292. }
  293. // if BL radius then line + arc, else line to (X4, Y4)
  294. if ($cornerBL) {
  295. $xt1 = ($x4+$cornerBL[0])-$cornerBL[0]*self::MY_ARC;
  296. $yt1 = ($y4-$cornerBL[1])+$cornerBL[1];
  297. $xt2 = ($x4+$cornerBL[0])-$cornerBL[0];
  298. $yt2 = ($y4-$cornerBL[1])+$cornerBL[1]*self::MY_ARC;
  299. $path.= sprintf('%.2F %.2F l ', $x4+$cornerBL[0], $y4);
  300. $path.= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x4, $y4-$cornerBL[1]);
  301. } else {
  302. $path.= sprintf('%.2F %.2F l ', $x4, $y4);
  303. }
  304. // if RL radius then line + arc
  305. if ($cornerTL) {
  306. $xt1 = ($x1+$cornerTL[0])-$cornerTL[0];
  307. $yt1 = ($y1+$cornerTL[1])-$cornerTL[1]*self::MY_ARC;
  308. $xt2 = ($x1+$cornerTL[0])-$cornerTL[0]*self::MY_ARC;
  309. $yt2 = ($y1+$cornerTL[1])-$cornerTL[1];
  310. $path.= sprintf('%.2F %.2F l ', $x1, $y1+$cornerTL[1]);
  311. $path.= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x1+$cornerTL[0], $y1);
  312. }
  313. } else {
  314. $path.= sprintf('%.2F %.2F m ', $x1, $y1);
  315. $path.= sprintf('%.2F %.2F l ', $x2, $y2);
  316. $path.= sprintf('%.2F %.2F l ', $x3, $y3);
  317. $path.= sprintf('%.2F %.2F l ', $x4, $y4);
  318. }
  319. // close the path
  320. $path.= ' h W n';
  321. }
  322. // using the path as a clipping path
  323. $this->_out('q '.$path.' ');
  324. }
  325. /**
  326. * stop to use the Cliping Path
  327. *
  328. * @access public
  329. */
  330. public function clippingPathStop()
  331. {
  332. $this->_out(' Q');
  333. }
  334. /**
  335. * draw a filled corner of a border with a external and a internal radius
  336. * /--------+ ext2
  337. * / |
  338. * / /-------+ int2
  339. * / /
  340. * | /
  341. * | |
  342. * | |
  343. * ext1 +-+ int1 + cen
  344. *
  345. * @param float $ext1X
  346. * @param float $ext1Y
  347. * @param float $ext2X
  348. * @param float $ext2Y
  349. * @param float $int1X
  350. * @param float $int1Y
  351. * @param float $int2X
  352. * @param float $int2Y
  353. * @param float $cenX
  354. * @param float $cenY
  355. * @access public
  356. */
  357. public function drawCurve($ext1X, $ext1Y, $ext2X, $ext2Y, $int1X, $int1Y, $int2X, $int2Y, $cenX, $cenY)
  358. {
  359. // prepare the coordinates
  360. $ext1X = $ext1X*$this->k;
  361. $ext2X = $ext2X*$this->k;
  362. $int1X = $int1X*$this->k;
  363. $int2X = $int2X*$this->k;
  364. $cenX = $cenX*$this->k;
  365. $ext1Y = ($this->h-$ext1Y)*$this->k;
  366. $ext2Y = ($this->h-$ext2Y)*$this->k;
  367. $int1Y = ($this->h-$int1Y)*$this->k;
  368. $int2Y = ($this->h-$int2Y)*$this->k;
  369. $cenY = ($this->h-$cenY) *$this->k;
  370. // init the curve
  371. $path = '';
  372. if ($ext1X-$cenX!=0) {
  373. $xt1 = $cenX+($ext1X-$cenX);
  374. $yt1 = $cenY+($ext2Y-$cenY)*self::MY_ARC;
  375. $xt2 = $cenX+($ext1X-$cenX)*self::MY_ARC;
  376. $yt2 = $cenY+($ext2Y-$cenY);
  377. } else {
  378. $xt1 = $cenX+($ext2X-$cenX)*self::MY_ARC;
  379. $yt1 = $cenY+($ext1Y-$cenY);
  380. $xt2 = $cenX+($ext2X-$cenX);
  381. $yt2 = $cenY+($ext1Y-$cenY)*self::MY_ARC;
  382. }
  383. $path.= sprintf('%.2F %.2F m ', $ext1X, $ext1Y);
  384. $path.= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $ext2X, $ext2Y);
  385. if ($int1X-$cenX!=0) {
  386. $xt1 = $cenX+($int1X-$cenX)*self::MY_ARC;
  387. $yt1 = $cenY+($int2Y-$cenY);
  388. $xt2 = $cenX+($int1X-$cenX);
  389. $yt2 = $cenY+($int2Y-$cenY)*self::MY_ARC;
  390. } else {
  391. $xt1 = $cenX+($int2X-$cenX);
  392. $yt1 = $cenY+($int1Y-$cenY)*self::MY_ARC;
  393. $xt2 = $cenX+($int2X-$cenX)*self::MY_ARC;
  394. $yt2 = $cenY+($int1Y-$cenY);
  395. }
  396. $path.= sprintf('%.2F %.2F l ', $int2X, $int2Y);
  397. $path.= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $int1X, $int1Y);
  398. // draw the curve
  399. $this->_out($path . 'f');
  400. }
  401. /**
  402. * draw a filled corner of a border with only a external radius
  403. * /--+ ext2
  404. * / |
  405. * / |
  406. * / |
  407. * | |
  408. * | |
  409. * | |
  410. * ext1 +-----+ int + cen
  411. *
  412. * @param float $ext1X
  413. * @param float $ext1Y
  414. * @param float $ext2X
  415. * @param float $ext2Y
  416. * @param float $intX
  417. * @param float $intY
  418. * @param float $cenX
  419. * @param float $cenY
  420. * @access public
  421. */
  422. public function drawCorner($ext1X, $ext1Y, $ext2X, $ext2Y, $intX, $intY, $cenX, $cenY)
  423. {
  424. // prepare the coordinates
  425. $ext1X = $ext1X*$this->k;
  426. $ext2X = $ext2X*$this->k;
  427. $intX = $intX*$this->k;
  428. $cenX = $cenX*$this->k;
  429. $ext1Y = ($this->h-$ext1Y)*$this->k;
  430. $ext2Y = ($this->h-$ext2Y)*$this->k;
  431. $intY = ($this->h-$intY)*$this->k;
  432. $cenY = ($this->h-$cenY)*$this->k;
  433. // init the curve
  434. $path = '';
  435. if ($ext1X-$cenX!=0) {
  436. $xt1 = $cenX+($ext1X-$cenX);
  437. $yt1 = $cenY+($ext2Y-$cenY)*self::MY_ARC;
  438. $xt2 = $cenX+($ext1X-$cenX)*self::MY_ARC;
  439. $yt2 = $cenY+($ext2Y-$cenY);
  440. } else {
  441. $xt1 = $cenX+($ext2X-$cenX)*self::MY_ARC;
  442. $yt1 = $cenY+($ext1Y-$cenY);
  443. $xt2 = $cenX+($ext2X-$cenX);
  444. $yt2 = $cenY+($ext1Y-$cenY)*self::MY_ARC;
  445. }
  446. $path.= sprintf('%.2F %.2F m ', $ext1X, $ext1Y);
  447. $path.= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $ext2X, $ext2Y);
  448. $path.= sprintf('%.2F %.2F l ', $intX, $intY);
  449. $path.= sprintf('%.2F %.2F l ', $ext1X, $ext1Y);
  450. // draw the curve
  451. $this->_out($path . 'f');
  452. }
  453. /**
  454. * Start a transformation
  455. *
  456. * @access public
  457. */
  458. public function startTransform()
  459. {
  460. $this->_out('q');
  461. }
  462. /**
  463. * Stop a transformation
  464. *
  465. * @access public
  466. */
  467. public function stopTransform()
  468. {
  469. $this->_out('Q');
  470. }
  471. /**
  472. * add a Translate transformation
  473. *
  474. * @param float $Tx
  475. * @param float $Ty
  476. * @access public
  477. */
  478. public function setTranslate($xT, $yT)
  479. {
  480. // Matrix for Translate
  481. $tm[0]=1;
  482. $tm[1]=0;
  483. $tm[2]=0;
  484. $tm[3]=1;
  485. $tm[4]=$xT*$this->k;
  486. $tm[5]=-$yT*$this->k;
  487. // apply the Transform Matric
  488. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
  489. }
  490. /**
  491. * add a Rotate transformation
  492. *
  493. * @param float $angle
  494. * @param float $Cx
  495. * @param float $Cy
  496. * @access public
  497. */
  498. public function setRotation($angle, $xC=null, $yC=null)
  499. {
  500. // if no center, rotate around the current posiition
  501. if($xC === null) $xC=$this->x;
  502. if($yC === null) $yC=$this->y;
  503. // prepare the coordinate
  504. $yC=($this->h-$yC)*$this->k;
  505. $xC*=$this->k;
  506. // Matrix for Rotate
  507. $tm[0]=cos(deg2rad($angle));
  508. $tm[1]=sin(deg2rad($angle));
  509. $tm[2]=-$tm[1];
  510. $tm[3]=$tm[0];
  511. $tm[4]=$xC+$tm[1]*$yC-$tm[0]*$xC;
  512. $tm[5]=$yC-$tm[0]*$yC-$tm[1]*$xC;
  513. // apply the Transform Matric
  514. $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
  515. }
  516. /**
  517. * we redifine the original SetX method, because we don't want the automatic treatment.
  518. * It is HTML2PDF that make the treatment
  519. *
  520. * @param float $x
  521. * @param boolean $rtloff NOT USED
  522. * @access public
  523. */
  524. public function SetX($x, $rtloff=false)
  525. {
  526. $this->x=$x;
  527. }
  528. /**
  529. * we redifine the original SetY method, because we don't want the automatic treatment.
  530. * It is HTML2PDF that make the treatment
  531. *
  532. * @param float $y
  533. * @param boolean $resetx Reset the X position
  534. * @param boolean $rtloff NOT USED
  535. * @access public
  536. */
  537. public function SetY($y, $resetx=true, $rtloff=false)
  538. {
  539. if ($resetx)
  540. $this->x=$this->lMargin;
  541. $this->y=$y;
  542. }
  543. /**
  544. * we redifine the original SetXY method, because we don't want the automatic treatment.
  545. * It is HTML2PDF that make the treatment
  546. *
  547. * @param integer $x
  548. * @param integer $y
  549. * @param boolean $rtloff NOT USED
  550. * @access public
  551. */
  552. public function SetXY($x, $y, $rtloff=false)
  553. {
  554. $this->x=$x;
  555. $this->y=$y;
  556. }
  557. /**
  558. * multiple public accessor because HTML2PDF need to use TCPDF without being a extend of it
  559. *
  560. * @param mixed
  561. * @return mixed
  562. * @access public
  563. */
  564. public function getK()
  565. {
  566. return $this->k;
  567. }
  568. public function getW()
  569. {
  570. return $this->w;
  571. }
  572. public function getH()
  573. {
  574. return $this->h;
  575. }
  576. public function getlMargin()
  577. {
  578. return $this->lMargin;
  579. }
  580. public function getrMargin()
  581. {
  582. return $this->rMargin;
  583. }
  584. public function gettMargin()
  585. {
  586. return $this->tMargin;
  587. }
  588. public function getbMargin()
  589. {
  590. return $this->bMargin;
  591. }
  592. public function setbMargin($v)
  593. {
  594. $this->bMargin=$v;
  595. }
  596. /**
  597. * SVG - Convert a SVG Style in PDF Style
  598. *
  599. * @param array $styles SVG Style
  600. * @return string PDF style
  601. * @access public
  602. */
  603. public function svgSetStyle($styles)
  604. {
  605. // init the PDF style
  606. $style = '';
  607. // Style : fill
  608. if ($styles['fill']) {
  609. $this->setFillColorArray($styles['fill']);
  610. $style.= 'F';
  611. }
  612. // Style : stroke
  613. if ($styles['stroke'] && $styles['stroke-width']) {
  614. $this->SetDrawColorArray($styles['stroke']);
  615. $this->SetLineWidth($styles['stroke-width']);
  616. $style.= 'D';
  617. }
  618. // Style : opacity
  619. if ($styles['fill-opacity']) {
  620. $this->SetAlpha($styles['fill-opacity']);
  621. }
  622. return $style;
  623. }
  624. /**
  625. * SVG - make a Rectangle
  626. *
  627. * @param float $x
  628. * @param float $y
  629. * @param float $w
  630. * @param float $h
  631. * @param string $style PDF Style
  632. * @access public
  633. */
  634. public function svgRect($x, $y, $w, $h, $style)
  635. {
  636. // prepare the 4 corners
  637. $x1=$x;
  638. $x2=$x+$w;
  639. $x3=$x+$w;
  640. $x4=$x;
  641. $y1=$y;
  642. $y2=$y;
  643. $y3=$y+$h;
  644. $y4=$y+$h;
  645. // get the Closing operator from the PDF Style
  646. if($style=='F') $op='f';
  647. elseif($style=='FD' || $style=='DF') $op='B';
  648. else $op='S';
  649. // drawing
  650. $this->_Point($x1, $y1, true);
  651. $this->_Line($x2, $y2, true);
  652. $this->_Line($x3, $y3, true);
  653. $this->_Line($x4, $y4, true);
  654. $this->_Line($x1, $y1, true);
  655. $this->_out($op);
  656. }
  657. /**
  658. * SVG - make a Line
  659. *
  660. * @param float $x1
  661. * @param float $y1
  662. * @param float $x2
  663. * @param float $y2
  664. * @access public
  665. */
  666. public function svgLine($x1, $y1, $x2, $y2)
  667. {
  668. // get the Closing operator
  669. $op='S';
  670. // drawing
  671. $this->_Point($x1, $y1, true);
  672. $this->_Line($x2, $y2, true);
  673. $this->_out($op);
  674. }
  675. /**
  676. * SVG - make a Ellipse
  677. *
  678. * @param float $x0 x Center
  679. * @param float $y0 y Center
  680. * @param float $rx x radius
  681. * @param float $ry y radius
  682. * @param string $style PDF Style
  683. * @access public
  684. */
  685. public function svgEllipse($x0, $y0, $rx, $ry, $style)
  686. {
  687. // get the Closing operator from the PDF Style
  688. if($style=='F') $op='f';
  689. elseif($style=='FD' || $style=='DF') $op='B';
  690. else $op='S';
  691. // drawing
  692. $this->_Arc($x0, $y0, $rx, $ry, 0, 2*M_PI, true, true, true);
  693. $this->_out($op);
  694. }
  695. /**
  696. * SVG - make a Advanced Polygone
  697. *
  698. * @param array $actions list of actions
  699. * @param string $style PDF Style
  700. * @access public
  701. */
  702. public function svgPolygone($actions, $style)
  703. {
  704. // get the Closing operator from the PDF Style
  705. if($style=='F') $op='f';
  706. elseif($style=='FD' || $style=='DF') $op='B';
  707. else $op='S';
  708. // To save the First action and the last point
  709. $first = array('', 0, 0);
  710. $last = array(0, 0, 0, 0);
  711. foreach ($actions as $action) {
  712. switch($action[0])
  713. {
  714. // Start the Path
  715. case 'M':
  716. case 'm':
  717. $first = $action;
  718. $x = $action[1]; $y = $action[2]; $xc = $x; $yc = $y;
  719. $this->_Point($x, $y, true);
  720. break;
  721. // Close the Path
  722. case 'Z':
  723. case 'z':
  724. $x = $first[1]; $y = $first[2]; $xc = $x; $yc = $y;
  725. $this->_Line($x, $y, true);
  726. break;
  727. // Make a Line (new point)
  728. case 'L':
  729. $x = $action[1]; $y = $action[2]; $xc = $x; $yc = $y;
  730. $this->_Line($x, $y, true);
  731. break;
  732. // Make a Line (vector from last point)
  733. case 'l':
  734. $x = $last[0]+$action[1]; $y = $last[1]+$action[2]; $xc = $x; $yc = $y;
  735. $this->_Line($x, $y, true);
  736. break;
  737. // Make a Horizontal Line (new point)
  738. case 'H':
  739. $x = $action[1]; $y = $last[1]; $xc = $x; $yc = $y;
  740. $this->_Line($x, $y, true);
  741. break;
  742. // Make a Horisontal Line (vector from last point)
  743. case 'h':
  744. $x = $last[0]+$action[1]; $y = $last[1]; $xc = $x; $yc = $y;
  745. $this->_Line($x, $y, true);
  746. break;
  747. // Make a Vertical Line (new point)
  748. case 'V':
  749. $x = $last[0]; $y = $action[1]; $xc = $x; $yc = $y;
  750. $this->_Line($x, $y, true);
  751. break;
  752. // Make a Vertical Line (vector from last point)
  753. case 'v':
  754. $x = $last[0]; $y = $last[1]+$action[1]; $xc = $x; $yc = $y;
  755. $this->_Line($x, $y, true);
  756. break;
  757. // Make a Arc (new point)
  758. case 'A':
  759. $rx = $action[1]; // rx
  760. $ry = $action[2]; // ry
  761. $a = $action[3]; // deviation angle of the axis X
  762. $l = $action[4]; // large-arc-flag
  763. $s = $action[5]; // sweep-flag
  764. $x1 = $last[0]; // begin x
  765. $y1 = $last[1]; // begin y
  766. $x2 = $action[6]; // final x
  767. $y2 = $action[7]; // final y
  768. $this->_Arc2($x1, $y1, $x2, $y2, $rx, $ry, $a, $l, $s, true);
  769. $x = $x2; $y = $y2; $xc = $x; $yc = $y;
  770. break;
  771. // Make a Arc (vector from last point)
  772. case 'a':
  773. $rx = $action[1]; // rx
  774. $ry = $action[2]; // ry
  775. $a = $action[3]; // deviation angle of the axis X
  776. $l = $action[4]; // large-arc-flag
  777. $s = $action[5]; // sweep-flag
  778. $x1 = $last[0]; // begin x
  779. $y1 = $last[1]; // begin y
  780. $x2 = $last[0]+$action[6]; // final x
  781. $y2 = $last[1]+$action[7]; // final y
  782. $this->_Arc2($x1, $y1, $x2, $y2, $rx, $ry, $a, $l, $s, true);
  783. $x = $x2; $y = $y2; $xc = $x; $yc = $y;
  784. break;
  785. // Make a Bezier Curve (new point)
  786. case 'C':
  787. $x1 = $action[1];
  788. $y1 = $action[2];
  789. $x2 = $action[3];
  790. $y2 = $action[4];
  791. $xf = $action[5];
  792. $yf = $action[6];
  793. $this->_Curve($x1, $y1, $x2, $y2, $xf, $yf, true);
  794. $x = $xf; $y = $yf; $xc = $x2; $yc = $y2;
  795. break;
  796. // Make a Bezier Curve (vector from last point)
  797. case 'c':
  798. $x1 = $last[0]+$action[1];
  799. $y1 = $last[1]+$action[2];
  800. $x2 = $last[0]+$action[3];
  801. $y2 = $last[1]+$action[4];
  802. $xf = $last[0]+$action[5];
  803. $yf = $last[1]+$action[6];
  804. $this->_Curve($x1, $y1, $x2, $y2, $xf, $yf, true);
  805. $x = $xf; $y = $yf; $xc = $x2; $yc = $y2;
  806. break;
  807. // Unknown Path
  808. default:
  809. throw new HTML2PDF_exception(0, 'SVG Path Error : ['.$action[0].'] unkown');
  810. }
  811. // save the last point
  812. $last = array($x, $y, $xc, $yc);
  813. }
  814. // finish the path
  815. $this->_out($op);
  816. }
  817. /**
  818. * SVG - go to a point
  819. *
  820. * @param float $x
  821. * @param float $y
  822. * @param boolean $trans apply transformation
  823. * @access protected
  824. */
  825. protected function _Point($x, $y, $trans = false)
  826. {
  827. if ($trans) $this->ptTransform($x, $y);
  828. $this->_out(sprintf('%.2F %.2F m', $x, $y));
  829. }
  830. /**
  831. * SVG - make a line from the last point to (x,y)
  832. *
  833. * @param float $x
  834. * @param float $y
  835. * @param boolean $trans apply transformation
  836. * @access protected
  837. */
  838. protected function _Line($x, $y, $trans = false)
  839. {
  840. if ($trans) $this->ptTransform($x, $y);
  841. $this->_out(sprintf('%.2F %.2F l', $x, $y));
  842. }
  843. /**
  844. * SVG - make a bezier curve from the last point to (xf,yf), with the 2 direction points (x1,y1) and (x2,y2)
  845. *
  846. * @param float $x1
  847. * @param float $y1
  848. * @param float $x2
  849. * @param float $y2
  850. * @param float $xf
  851. * @param float $yf
  852. * @param boolean $trans apply transformation
  853. * @access protected
  854. */
  855. protected function _Curve($x1, $y1, $x2, $y2, $xf, $yf, $trans = false)
  856. {
  857. if ($trans) {
  858. $this->ptTransform($x1, $y1);
  859. $this->ptTransform($x2, $y2);
  860. $this->ptTransform($xf, $yf);
  861. }
  862. $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', $x1, $y1, $x2, $y2, $xf, $yf));
  863. }
  864. /**
  865. * SVG - make a arc with Center, Radius, from angleBegin to angleEnd
  866. *
  867. * @param float $xc
  868. * @param float $yc
  869. * @param float $rx
  870. * @param float $ry
  871. * @param float $angleBegin in radians
  872. * @param float $angleEng in radians
  873. * @param boolean $direction
  874. * @param boolean $drawFirst, true => add the first point
  875. * @param boolean $trans apply transformation
  876. * @access protected
  877. */
  878. protected function _Arc(
  879. $xc,
  880. $yc,
  881. $rx,
  882. $ry,
  883. $angleBegin,
  884. $angleEnd,
  885. $direction = true,
  886. $drawFirst = true,
  887. $trans=false)
  888. {
  889. // if we want the no trigo direction : add 2PI to the begin angle, to invert the direction
  890. if (!$direction) $angleBegin+= M_PI*2.;
  891. // cut in segment to convert in berize curv
  892. $dt = ($angleEnd - $angleBegin)/self::ARC_NB_SEGMENT;
  893. $dtm = $dt/3;
  894. // center of the arc
  895. $x0 = $xc; $y0 = $yc;
  896. // calculing the first point
  897. $t1 = $angleBegin;
  898. $a0 = $x0 + ($rx * cos($t1));
  899. $b0 = $y0 + ($ry * sin($t1));
  900. $c0 = -$rx * sin($t1);
  901. $d0 = $ry * cos($t1);
  902. // if drawFirst => draw the first point
  903. if ($drawFirst) $this->_Point($a0, $b0, $trans);
  904. // foreach segment
  905. for ($i = 1; $i <= self::ARC_NB_SEGMENT; $i++) {
  906. // calculing the next point
  907. $t1 = ($i * $dt)+$angleBegin;
  908. $a1 = $x0 + ($rx * cos($t1));
  909. $b1 = $y0 + ($ry * sin($t1));
  910. $c1 = -$rx * sin($t1);
  911. $d1 = $ry * cos($t1);
  912. // make the bezier curv
  913. $this->_Curve(
  914. $a0 + ($c0 * $dtm), $b0 + ($d0 * $dtm),
  915. $a1 - ($c1 * $dtm), $b1 - ($d1 * $dtm),
  916. $a1, $b1,
  917. $trans
  918. );
  919. // save the point
  920. $a0 = $a1;
  921. $b0 = $b1;
  922. $c0 = $c1;
  923. $d0 = $d1;
  924. }
  925. }
  926. /**
  927. * SVG - make a arc from Pt1 to Pt2, with Radius
  928. *
  929. * @param float $x1
  930. * @param float $y1
  931. * @param float $x2
  932. * @param float $y2
  933. * @param float $rx
  934. * @param float $ry
  935. * @param float $angle deviation angle of the axis X
  936. * @param boolean $l large-arc-flag
  937. * @param boolean $s sweep-flag
  938. * @param boolean $trans apply transformation
  939. * @access protected
  940. */
  941. protected function _Arc2($x1, $y1, $x2, $y2, $rx, $ry, $angle=0., $l=0, $s=0, $trans = false)
  942. {
  943. // array to stock the parameters
  944. $v = array();
  945. // the original values
  946. $v['x1'] = $x1;
  947. $v['y1'] = $y1;
  948. $v['x2'] = $x2;
  949. $v['y2'] = $y2;
  950. $v['rx'] = $rx;
  951. $v['ry'] = $ry;
  952. // rotate with the deviation angle of the axis X
  953. $v['xr1'] = $v['x1']*cos($angle) - $v['y1']*sin($angle);
  954. $v['yr1'] = $v['x1']*sin($angle) + $v['y1']*cos($angle);
  955. $v['xr2'] = $v['x2']*cos($angle) - $v['y2']*sin($angle);
  956. $v['yr2'] = $v['x2']*sin($angle) + $v['y2']*cos($angle);
  957. // the normalized vector
  958. $v['Xr1'] = $v['xr1']/$v['rx'];
  959. $v['Yr1'] = $v['yr1']/$v['ry'];
  960. $v['Xr2'] = $v['xr2']/$v['rx'];
  961. $v['Yr2'] = $v['yr2']/$v['ry'];
  962. $v['dXr'] = $v['Xr2']-$v['Xr1'];
  963. $v['dYr'] = $v['Yr2']-$v['Yr1'];
  964. $v['D'] = $v['dXr']*$v['dXr'] + $v['dYr']*$v['dYr'];
  965. // if |vector| is Null, or if |vector| > 2 : impossible to make a arc => Line
  966. if ($v['D']==0 || $v['D']>4) {
  967. $this->_Line($x2, $y2, $trans);
  968. return false;
  969. }
  970. // convert paramters for make a arc with Center, Radius, from angleBegin to angleEnd
  971. $v['s1'] = array();
  972. $v['s1']['t'] = sqrt((4.-$v['D'])/$v['D']);
  973. $v['s1']['Xr'] = ($v['Xr1']+$v['Xr2'])/2. + $v['s1']['t']*($v['Yr2']-$v['Yr1'])/2.;
  974. $v['s1']['Yr'] = ($v['Yr1']+$v['Yr2'])/2. + $v['s1']['t']*($v['Xr1']-$v['Xr2'])/2.;
  975. $v['s1']['xr'] = $v['s1']['Xr']*$v['rx'];
  976. $v['s1']['yr'] = $v['s1']['Yr']*$v['ry'];
  977. $v['s1']['x'] = $v['s1']['xr']*cos($angle)+$v['s1']['yr']*sin($angle);
  978. $v['s1']['y'] =-$v['s1']['xr']*sin($angle)+$v['s1']['yr']*cos($angle);
  979. $v['s1']['a1'] = atan2($v['y1']-$v['s1']['y'], $v['x1']-$v['s1']['x']);
  980. $v['s1']['a2'] = atan2($v['y2']-$v['s1']['y'], $v['x2']-$v['s1']['x']);
  981. if ($v['s1']['a1']>$v['s1']['a2']) $v['s1']['a1']-=2*M_PI;
  982. $v['s2'] = array();
  983. $v['s2']['t'] = -$v['s1']['t'];
  984. $v['s2']['Xr'] = ($v['Xr1']+$v['Xr2'])/2. + $v['s2']['t']*($v['Yr2']-$v['Yr1'])/2.;
  985. $v['s2']['Yr'] = ($v['Yr1']+$v['Yr2'])/2. + $v['s2']['t']*($v['Xr1']-$v['Xr2'])/2.;
  986. $v['s2']['xr'] = $v['s2']['Xr']*$v['rx'];
  987. $v['s2']['yr'] = $v['s2']['Yr']*$v['ry'];
  988. $v['s2']['x'] = $v['s2']['xr']*cos($angle)+$v['s2']['yr']*sin($angle);
  989. $v['s2']['y'] =-$v['s2']['xr']*sin($angle)+$v['s2']['yr']*cos($angle);
  990. $v['s2']['a1'] = atan2($v['y1']-$v['s2']['y'], $v['x1']-$v['s2']['x']);
  991. $v['s2']['a2'] = atan2($v['y2']-$v['s2']['y'], $v['x2']-$v['s2']['x']);
  992. if ($v['s2']['a1']>$v['s2']['a2']) $v['s2']['a1']-=2*M_PI;
  993. if (!$l) {
  994. if ($s) {
  995. $xc = $v['s2']['x'];
  996. $yc = $v['s2']['y'];
  997. $a1 = $v['s2']['a1'];
  998. $a2 = $v['s2']['a2'];
  999. $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, true, false, $trans);
  1000. } else {
  1001. $xc = $v['s1']['x'];
  1002. $yc = $v['s1']['y'];
  1003. $a1 = $v['s1']['a1'];
  1004. $a2 = $v['s1']['a2'];
  1005. $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, false, false, $trans);
  1006. }
  1007. } else {
  1008. if ($s) {
  1009. $xc = $v['s1']['x'];
  1010. $yc = $v['s1']['y'];
  1011. $a1 = $v['s1']['a1'];
  1012. $a2 = $v['s1']['a2'];
  1013. $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, true, false, $trans);
  1014. } else {
  1015. $xc = $v['s2']['x'];
  1016. $yc = $v['s2']['y'];
  1017. $a1 = $v['s2']['a1'];
  1018. $a2 = $v['s2']['a2'];
  1019. $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, false, false, $trans);
  1020. }
  1021. }
  1022. }
  1023. /**
  1024. * SVG - transform the point (reference)
  1025. *
  1026. * @param float &$x
  1027. * @param float &$y
  1028. * @param boolean $trans true => convert into PDF unit
  1029. * @return boolean
  1030. * @access public
  1031. */
  1032. public function ptTransform(&$x, &$y, $trans=true)
  1033. {
  1034. // load the last Transfomation Matrix
  1035. $nb = count($this->_transf);
  1036. if ($nb) $m = $this->_transf[$nb-1];
  1037. else $m = array(1,0,0,1,0,0);
  1038. // apply the Transformation Matrix
  1039. list($x,$y) = array(($x*$m[0]+$y*$m[2]+$m[4]),($x*$m[1]+$y*$m[3]+$m[5]));
  1040. // if true => convert into PDF unit
  1041. if ($trans) {
  1042. $x = $x*$this->k;
  1043. $y = ($this->h-$y)*$this->k;
  1044. }
  1045. return true;
  1046. }
  1047. /**
  1048. * SVG - add a transformation Matric
  1049. *
  1050. * @param array $n matrix
  1051. * @access public
  1052. */
  1053. public function doTransform($n = null)
  1054. {
  1055. // get the last Transformation Matrix
  1056. $nb = count($this->_transf);
  1057. if ($nb) $m = $this->_transf[$nb-1];
  1058. else $m = array(1,0,0,1,0,0);
  1059. // if no transform, get the Identity Matrix
  1060. if (!$n) $n = array(1,0,0,1,0,0);
  1061. // create the new Transformation Matrix
  1062. $this->_transf[] = array(
  1063. $m[0]*$n[0]+$m[2]*$n[1],
  1064. $m[1]*$n[0]+$m[3]*$n[1],
  1065. $m[0]*$n[2]+$m[2]*$n[3],
  1066. $m[1]*$n[2]+$m[3]*$n[3],
  1067. $m[0]*$n[4]+$m[2]*$n[5]+$m[4],
  1068. $m[1]*$n[4]+$m[3]*$n[5]+$m[5]
  1069. );
  1070. }
  1071. /**
  1072. * SVG - remove a transformation Matric
  1073. *
  1074. * @access public
  1075. */
  1076. public function undoTransform()
  1077. {
  1078. array_pop($this->_transf);
  1079. }
  1080. /**
  1081. * Convert a HTML2PDF barcode in a TCPDF barcode
  1082. *
  1083. * @param string $code code to print
  1084. * @param string $type type of barcode (see tcpdf/barcodes.php for supported formats)
  1085. * @param int $x x position in user units
  1086. * @param int $y y position in user units
  1087. * @param int $w width in user units
  1088. * @param int $h height in user units
  1089. * @param int $labelFontsize of the Test Label. If false : no Label
  1090. * @param array $color color of the foreground
  1091. * @access public
  1092. */
  1093. public function myBarcode($code, $type, $x, $y, $w, $h, $labelFontsize, $color)
  1094. {
  1095. // the style of the barcode
  1096. $style = array(
  1097. 'position' => 'S',
  1098. 'text' => ($labelFontsize ? true : false),
  1099. 'fgcolor' => $color,
  1100. 'bgcolor' => false,
  1101. );
  1102. // build the barcode
  1103. $this->write1DBarcode($code, $type, $x, $y, $w, $h, '', $style, 'N');
  1104. // it Label => add the FontSize to the height
  1105. if ($labelFontsize) $h+= ($labelFontsize);
  1106. // return the size of the barcode
  1107. return array($w, $h);
  1108. }
  1109. /**
  1110. * create a automatic Index on a page
  1111. *
  1112. * @param html2pdf $obj parent object
  1113. * @param string $titre Title of the Index Page
  1114. * @param integer $sizeTitle Font size for hthe Title
  1115. * @param integer $sizeBookmark Font size for the bookmarks
  1116. * @param boolean $bookmarkTitle Bookmark the Title
  1117. * @param boolean $displayPage Display the page number for each bookmark
  1118. * @param integer $page draw the automatic Index on a specific Page. if null => add a page at the end
  1119. * @param string $fontName FontName to use
  1120. * @access public
  1121. */
  1122. public function createIndex(
  1123. &$obj,
  1124. $titre = 'Index',
  1125. $sizeTitle = 20,
  1126. $sizeBookmark = 15,
  1127. $bookmarkTitle = true,
  1128. $displayPage = true,
  1129. $page = null,
  1130. $fontName = 'helvetica')
  1131. {
  1132. // bookmark the Title if wanted
  1133. if ($bookmarkTitle) $this->Bookmark($titre, 0, -1);
  1134. // display the Title with the good Font size
  1135. $this->SetFont($fontName, '', $sizeTitle);
  1136. $this->Cell(0, 5, $titre, 0, 1, 'C');
  1137. // set the good Font size for the bookmarks
  1138. $this->SetFont($fontName, '', $sizeBookmark);
  1139. $this->Ln(10);
  1140. // get the number of bookmarks
  1141. $size=sizeof($this->outlines);
  1142. // get the size of the "P. xx" cell
  1143. $pageCellSize=$this->GetStringWidth('p. '.$this->outlines[$size-1]['p'])+2;
  1144. // Foreach bookmark
  1145. for ($i=0;$i<$size;$i++) {
  1146. // if we need a new page => add a new page
  1147. if ($this->getY()+$this->FontSize>=($this->h - $this->bMargin)) {
  1148. $obj->_INDEX_NewPage($page);
  1149. $this->SetFont($fontName, '', $sizeBookmark);
  1150. }
  1151. // Offset of the current level
  1152. $level=$this->outlines[$i]['l'];
  1153. if($level>0) $this->Cell($level*8);
  1154. // Caption (cut to fit on the width page)
  1155. $str=$this->outlines[$i]['t'];
  1156. $strsize=$this->GetStringWidth($str);
  1157. $availableSize=$this->w-$this->lMargin-$this->rMargin-$pageCellSize-($level*8)-4;
  1158. while ($strsize>=$availableSize) {
  1159. $str=substr($str, 0, -1);
  1160. $strsize=$this->GetStringWidth($str);
  1161. }
  1162. // if we want to display the page nmber
  1163. if ($displayPage) {
  1164. // display the Bookmark Caption
  1165. $this->Cell($strsize+2, $this->FontSize+2, $str);
  1166. //Filling dots
  1167. $w=$this->w-$this->lMargin-$this->rMargin-$pageCellSize-($level*8)-($strsize+2);
  1168. $nb=$w/$this->GetStringWidth('.');
  1169. $dots=str_repeat('.', $nb);
  1170. $this->Cell($w, $this->FontSize+2, $dots, 0, 0, 'R');
  1171. //Page number
  1172. $this->Cell($pageCellSize, $this->FontSize+2, 'p. '.$this->outlines[$i]['p'], 0, 1, 'R');
  1173. } else {
  1174. // display the Bookmark Caption
  1175. $this->Cell($strsize+2, $this->FontSize+2, $str, 0, 1);
  1176. }
  1177. }
  1178. }
  1179. /**
  1180. * Returns the string alias used for the total number of pages.
  1181. *
  1182. * @access public
  1183. * @return string;
  1184. * @see TCPDF::getAliasNbPages(), TCPDF::getPageGroupAlias()
  1185. */
  1186. public function getMyAliasNbPages()
  1187. {
  1188. if ($this->_myLastPageGroupNb==0) {
  1189. return $this->getAliasNbPages();
  1190. } else {
  1191. $old = $this->currpagegroup;
  1192. $this->currpagegroup = '{nb'.$this->_myLastPageGroupNb.'}';
  1193. $new = $this->getPageGroupAlias();
  1194. $this->currpagegroup = $old;
  1195. return $new;
  1196. }
  1197. }
  1198. /**
  1199. * Returns the current page number.
  1200. *
  1201. * @access public
  1202. * @param integer $page
  1203. * @return integer;
  1204. */
  1205. public function getMyNumPage($page=null)
  1206. {
  1207. if ($page===null) {
  1208. $page = $this->page;
  1209. }
  1210. if ($this->_myLastPageGroupNb==0) {
  1211. return $page;
  1212. } else {
  1213. return $page-$this->_myLastPageGroup;
  1214. }
  1215. }
  1216. /**
  1217. * Start a new group of pages
  1218. *
  1219. * @access public
  1220. * @return integer;
  1221. * @see tcpdf::startPageGroup
  1222. */
  1223. public function myStartPageGroup()
  1224. {
  1225. $this->_myLastPageGroup = $this->page-1;
  1226. $this->_myLastPageGroupNb++;
  1227. }
  1228. /**
  1229. * get $_myLastPageGroup;
  1230. *
  1231. * @access public
  1232. * @return integer $_myLastPageGroup;
  1233. */
  1234. public function getMyLastPageGroup()
  1235. {
  1236. return $this->_myLastPageGroup;
  1237. }
  1238. /**
  1239. * set $_myLastPageGroup;
  1240. *
  1241. * @access public
  1242. * @param integer $myLastPageGroup;
  1243. */
  1244. public function setMyLastPageGroup($myLastPageGroup)
  1245. {
  1246. $this->_myLastPageGroup = $myLastPageGroup;
  1247. }
  1248. /**
  1249. * get $_myLastPageGroupNb;
  1250. *
  1251. * @access public
  1252. * @return integer $_myLastPageGroupNb;
  1253. */
  1254. public function getMyLastPageGroupNb()
  1255. {
  1256. return $this->_myLastPageGroupNb;
  1257. }
  1258. /**
  1259. * set $_myLastPageGroupNb;
  1260. *
  1261. * @access public
  1262. * @param integer $myLastPageGroupNb;
  1263. */
  1264. public function setMyLastPageGroupNb($myLastPageGroupNb)
  1265. {
  1266. $this->_myLastPageGroupNb = $myLastPageGroupNb;
  1267. }
  1268. }