tcpdf_static.php 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf_static.php
  4. // Version : 1.1.4
  5. // Begin : 2002-08-03
  6. // Last Update : 2019-11-01
  7. // Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
  8. // License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
  9. // -------------------------------------------------------------------
  10. // Copyright (C) 2002-2021 Nicola Asuni - Tecnick.com LTD
  11. //
  12. // This file is part of TCPDF software library.
  13. //
  14. // TCPDF is free software: you can redistribute it and/or modify it
  15. // under the terms of the GNU Lesser General Public License as
  16. // published by the Free Software Foundation, either version 3 of the
  17. // License, or (at your option) any later version.
  18. //
  19. // TCPDF is distributed in the hope that it will be useful, but
  20. // WITHOUT ANY WARRANTY; without even the implied warranty of
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. // See the GNU Lesser General Public License for more details.
  23. //
  24. // You should have received a copy of the License
  25. // along with TCPDF. If not, see
  26. // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
  27. //
  28. // See LICENSE.TXT file for more information.
  29. // -------------------------------------------------------------------
  30. //
  31. // Description :
  32. // Static methods used by the TCPDF class.
  33. //
  34. //============================================================+
  35. /**
  36. * @file
  37. * This is a PHP class that contains static methods for the TCPDF class.<br>
  38. * @package com.tecnick.tcpdf
  39. * @author Nicola Asuni
  40. * @version 1.1.2
  41. */
  42. /**
  43. * @class TCPDF_STATIC
  44. * Static methods used by the TCPDF class.
  45. * @package com.tecnick.tcpdf
  46. * @brief PHP class for generating PDF documents without requiring external extensions.
  47. * @version 1.1.1
  48. * @author Nicola Asuni - info@tecnick.com
  49. */
  50. class TCPDF_STATIC {
  51. /**
  52. * Current TCPDF version.
  53. * @private static
  54. */
  55. private static $tcpdf_version = '6.4.4';
  56. /**
  57. * String alias for total number of pages.
  58. * @public static
  59. */
  60. public static $alias_tot_pages = '{:ptp:}';
  61. /**
  62. * String alias for page number.
  63. * @public static
  64. */
  65. public static $alias_num_page = '{:pnp:}';
  66. /**
  67. * String alias for total number of pages in a single group.
  68. * @public static
  69. */
  70. public static $alias_group_tot_pages = '{:ptg:}';
  71. /**
  72. * String alias for group page number.
  73. * @public static
  74. */
  75. public static $alias_group_num_page = '{:png:}';
  76. /**
  77. * String alias for right shift compensation used to correctly align page numbers on the right.
  78. * @public static
  79. */
  80. public static $alias_right_shift = '{rsc:';
  81. /**
  82. * Encryption padding string.
  83. * @public static
  84. */
  85. public static $enc_padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  86. /**
  87. * ByteRange placemark used during digital signature process.
  88. * @since 4.6.028 (2009-08-25)
  89. * @public static
  90. */
  91. public static $byterange_string = '/ByteRange[0 ********** ********** **********]';
  92. /**
  93. * Array page boxes names
  94. * @public static
  95. */
  96. public static $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  97. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  98. /**
  99. * Return the current TCPDF version.
  100. * @return string TCPDF version string
  101. * @since 5.9.012 (2010-11-10)
  102. * @public static
  103. */
  104. public static function getTCPDFVersion() {
  105. return self::$tcpdf_version;
  106. }
  107. /**
  108. * Return the current TCPDF producer.
  109. * @return string TCPDF producer string
  110. * @since 6.0.000 (2013-03-16)
  111. * @public static
  112. */
  113. public static function getTCPDFProducer() {
  114. return "\x54\x43\x50\x44\x46\x20".self::getTCPDFVersion()."\x20\x28\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
  115. }
  116. /**
  117. * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
  118. * @param boolean $mqr FALSE for off, TRUE for on.
  119. * @since 4.6.025 (2009-08-17)
  120. * @public static
  121. */
  122. public static function set_mqr($mqr) {
  123. if (!defined('PHP_VERSION_ID')) {
  124. $version = PHP_VERSION;
  125. define('PHP_VERSION_ID', (($version[0] * 10000) + ($version[2] * 100) + $version[4]));
  126. }
  127. if (PHP_VERSION_ID < 50300) {
  128. @set_magic_quotes_runtime($mqr);
  129. }
  130. }
  131. /**
  132. * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
  133. * @return int Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
  134. * @since 4.6.025 (2009-08-17)
  135. * @public static
  136. */
  137. public static function get_mqr() {
  138. if (!defined('PHP_VERSION_ID')) {
  139. $version = PHP_VERSION;
  140. define('PHP_VERSION_ID', (($version[0] * 10000) + ($version[2] * 100) + $version[4]));
  141. }
  142. if (PHP_VERSION_ID < 50300) {
  143. return @get_magic_quotes_runtime();
  144. }
  145. return 0;
  146. }
  147. /**
  148. * Check if the URL exist.
  149. * @param string $url URL to check.
  150. * @return boolean true if the URl exist, false otherwise.
  151. * @since 5.9.204 (2013-01-28)
  152. * @public static
  153. */
  154. public static function isValidURL($url) {
  155. $headers = @get_headers($url);
  156. if ($headers === false) {
  157. return false;
  158. }
  159. return (strpos($headers[0], '200') !== false);
  160. }
  161. /**
  162. * Removes SHY characters from text.
  163. * Unicode Data:<ul>
  164. * <li>Name : SOFT HYPHEN, commonly abbreviated as SHY</li>
  165. * <li>HTML Entity (decimal): "&amp;#173;"</li>
  166. * <li>HTML Entity (hex): "&amp;#xad;"</li>
  167. * <li>HTML Entity (named): "&amp;shy;"</li>
  168. * <li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li>
  169. * <li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li>
  170. * <li>UTF-8 character: chr(194).chr(173)</li>
  171. * </ul>
  172. * @param string $txt input string
  173. * @param boolean $unicode True if we are in unicode mode, false otherwise.
  174. * @return string without SHY characters.
  175. * @since (4.5.019) 2009-02-28
  176. * @public static
  177. */
  178. public static function removeSHY($txt='', $unicode=true) {
  179. $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
  180. if (!$unicode) {
  181. $txt = preg_replace('/([\\xad]{1})/', '', $txt);
  182. }
  183. return $txt;
  184. }
  185. /**
  186. * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
  187. * @param string|array|int $brd Indicates if borders must be drawn around the cell block. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  188. * @param string $position multicell position: 'start', 'middle', 'end'
  189. * @param boolean $opencell True when the cell is left open at the page bottom, false otherwise.
  190. * @return array border mode array
  191. * @since 4.4.002 (2008-12-09)
  192. * @public static
  193. */
  194. public static function getBorderMode($brd, $position='start', $opencell=true) {
  195. if ((!$opencell) OR empty($brd)) {
  196. return $brd;
  197. }
  198. if ($brd == 1) {
  199. $brd = 'LTRB';
  200. }
  201. if (is_string($brd)) {
  202. // convert string to array
  203. $slen = strlen($brd);
  204. $newbrd = array();
  205. for ($i = 0; $i < $slen; ++$i) {
  206. $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
  207. }
  208. $brd = $newbrd;
  209. }
  210. foreach ($brd as $border => $style) {
  211. switch ($position) {
  212. case 'start': {
  213. if (strpos($border, 'B') !== false) {
  214. // remove bottom line
  215. $newkey = str_replace('B', '', $border);
  216. if (strlen($newkey) > 0) {
  217. $brd[$newkey] = $style;
  218. }
  219. unset($brd[$border]);
  220. }
  221. break;
  222. }
  223. case 'middle': {
  224. if (strpos($border, 'B') !== false) {
  225. // remove bottom line
  226. $newkey = str_replace('B', '', $border);
  227. if (strlen($newkey) > 0) {
  228. $brd[$newkey] = $style;
  229. }
  230. unset($brd[$border]);
  231. $border = $newkey;
  232. }
  233. if (strpos($border, 'T') !== false) {
  234. // remove bottom line
  235. $newkey = str_replace('T', '', $border);
  236. if (strlen($newkey) > 0) {
  237. $brd[$newkey] = $style;
  238. }
  239. unset($brd[$border]);
  240. }
  241. break;
  242. }
  243. case 'end': {
  244. if (strpos($border, 'T') !== false) {
  245. // remove bottom line
  246. $newkey = str_replace('T', '', $border);
  247. if (strlen($newkey) > 0) {
  248. $brd[$newkey] = $style;
  249. }
  250. unset($brd[$border]);
  251. }
  252. break;
  253. }
  254. }
  255. }
  256. return $brd;
  257. }
  258. /**
  259. * Determine whether a string is empty.
  260. * @param string $str string to be checked
  261. * @return bool true if string is empty
  262. * @since 4.5.044 (2009-04-16)
  263. * @public static
  264. */
  265. public static function empty_string($str) {
  266. return (is_null($str) OR (is_string($str) AND (strlen($str) == 0)));
  267. }
  268. /**
  269. * Returns a temporary filename for caching object on filesystem.
  270. * @param string $type Type of file (name of the subdir on the tcpdf cache folder).
  271. * @param string $file_id TCPDF file_id.
  272. * @return string filename.
  273. * @since 4.5.000 (2008-12-31)
  274. * @public static
  275. */
  276. public static function getObjFilename($type='tmp', $file_id='') {
  277. return tempnam(K_PATH_CACHE, '__tcpdf_'.$file_id.'_'.$type.'_'.md5(TCPDF_STATIC::getRandomSeed()).'_');
  278. }
  279. /**
  280. * Add "\" before "\", "(" and ")"
  281. * @param string $s string to escape.
  282. * @return string escaped string.
  283. * @public static
  284. */
  285. public static function _escape($s) {
  286. // the chr(13) substitution fixes the Bugs item #1421290.
  287. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
  288. }
  289. /**
  290. * Escape some special characters (&lt; &gt; &amp;) for XML output.
  291. * @param string $str Input string to convert.
  292. * @return string converted string
  293. * @since 5.9.121 (2011-09-28)
  294. * @public static
  295. */
  296. public static function _escapeXML($str) {
  297. $replaceTable = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
  298. $str = strtr($str, $replaceTable);
  299. return $str;
  300. }
  301. /**
  302. * Creates a copy of a class object
  303. * @param object $object class object to be cloned
  304. * @return object cloned object
  305. * @since 4.5.029 (2009-03-19)
  306. * @public static
  307. */
  308. public static function objclone($object) {
  309. if (($object instanceof Imagick) AND (version_compare(phpversion('imagick'), '3.0.1') !== 1)) {
  310. // on the versions after 3.0.1 the clone() method was deprecated in favour of clone keyword
  311. return @$object->clone();
  312. }
  313. return @clone($object);
  314. }
  315. /**
  316. * Output input data and compress it if possible.
  317. * @param string $data Data to output.
  318. * @param int $length Data length in bytes.
  319. * @since 5.9.086
  320. * @public static
  321. */
  322. public static function sendOutputData($data, $length) {
  323. if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  324. // the content length may vary if the server is using compression
  325. header('Content-Length: '.$length);
  326. }
  327. echo $data;
  328. }
  329. /**
  330. * Replace page number aliases with number.
  331. * @param string $page Page content.
  332. * @param array $replace Array of replacements (array keys are replacement strings, values are alias arrays).
  333. * @param int $diff If passed, this will be set to the total char number difference between alias and replacements.
  334. * @return array replaced page content and updated $diff parameter as array.
  335. * @public static
  336. */
  337. public static function replacePageNumAliases($page, $replace, $diff=0) {
  338. foreach ($replace as $rep) {
  339. foreach ($rep[3] as $a) {
  340. if (strpos($page, $a) !== false) {
  341. $page = str_replace($a, $rep[0], $page);
  342. $diff += ($rep[2] - $rep[1]);
  343. }
  344. }
  345. }
  346. return array($page, $diff);
  347. }
  348. /**
  349. * Returns timestamp in seconds from formatted date-time.
  350. * @param string $date Formatted date-time.
  351. * @return int seconds.
  352. * @since 5.9.152 (2012-03-23)
  353. * @public static
  354. */
  355. public static function getTimestamp($date) {
  356. if (($date[0] == 'D') AND ($date[1] == ':')) {
  357. // remove date prefix if present
  358. $date = substr($date, 2);
  359. }
  360. return strtotime($date);
  361. }
  362. /**
  363. * Returns a formatted date-time.
  364. * @param int $time Time in seconds.
  365. * @return string escaped date string.
  366. * @since 5.9.152 (2012-03-23)
  367. * @public static
  368. */
  369. public static function getFormattedDate($time) {
  370. return substr_replace(date('YmdHisO', intval($time)), '\'', (0 - 2), 0).'\'';
  371. }
  372. /**
  373. * Returns a string containing random data to be used as a seed for encryption methods.
  374. * @param string $seed starting seed value
  375. * @return string containing random data
  376. * @author Nicola Asuni
  377. * @since 5.9.006 (2010-10-19)
  378. * @public static
  379. */
  380. public static function getRandomSeed($seed='') {
  381. $rnd = uniqid(rand().microtime(true), true);
  382. if (function_exists('posix_getpid')) {
  383. $rnd .= posix_getpid();
  384. }
  385. if (function_exists('openssl_random_pseudo_bytes') AND (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) {
  386. // this is not used on windows systems because it is very slow for a know bug
  387. $rnd .= openssl_random_pseudo_bytes(512);
  388. } else {
  389. for ($i = 0; $i < 23; ++$i) {
  390. $rnd .= uniqid('', true);
  391. }
  392. }
  393. return $rnd.$seed.__FILE__.serialize($_SERVER).microtime(true);
  394. }
  395. /**
  396. * Encrypts a string using MD5 and returns it's value as a binary string.
  397. * @param string $str input string
  398. * @return string MD5 encrypted binary string
  399. * @since 2.0.000 (2008-01-02)
  400. * @public static
  401. */
  402. public static function _md5_16($str) {
  403. return pack('H*', md5($str));
  404. }
  405. /**
  406. * Returns the input text encrypted using AES algorithm and the specified key.
  407. * This method requires openssl or mcrypt. Text is padded to 16bytes blocks
  408. * @param string $key encryption key
  409. * @param string $text input text to be encrypted
  410. * @return string encrypted text
  411. * @author Nicola Asuni
  412. * @since 5.0.005 (2010-05-11)
  413. * @public static
  414. */
  415. public static function _AES($key, $text) {
  416. // padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0)
  417. $padding = 16 - (strlen($text) % 16);
  418. $text .= str_repeat(chr($padding), $padding);
  419. if (extension_loaded('openssl')) {
  420. $algo = 'aes-256-cbc';
  421. if (strlen($key) == 16) {
  422. $algo = 'aes-128-cbc';
  423. }
  424. $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($algo));
  425. $text = openssl_encrypt($text, $algo, $key, OPENSSL_RAW_DATA, $iv);
  426. return $iv.substr($text, 0, -16);
  427. }
  428. $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
  429. $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
  430. $text = $iv.$text;
  431. return $text;
  432. }
  433. /**
  434. * Returns the input text encrypted using AES algorithm and the specified key.
  435. * This method requires openssl or mcrypt. Text is not padded
  436. * @param string $key encryption key
  437. * @param string $text input text to be encrypted
  438. * @return string encrypted text
  439. * @author Nicola Asuni
  440. * @since TODO
  441. * @public static
  442. */
  443. public static function _AESnopad($key, $text) {
  444. if (extension_loaded('openssl')) {
  445. $algo = 'aes-256-cbc';
  446. if (strlen($key) == 16) {
  447. $algo = 'aes-128-cbc';
  448. }
  449. $iv = str_repeat("\x00", openssl_cipher_iv_length($algo));
  450. $text = openssl_encrypt($text, $algo, $key, OPENSSL_RAW_DATA, $iv);
  451. return substr($text, 0, -16);
  452. }
  453. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
  454. $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
  455. return $text;
  456. }
  457. /**
  458. * Returns the input text encrypted using RC4 algorithm and the specified key.
  459. * RC4 is the standard encryption algorithm used in PDF format
  460. * @param string $key Encryption key.
  461. * @param string $text Input text to be encrypted.
  462. * @param string $last_enc_key Reference to last RC4 key encrypted.
  463. * @param string $last_enc_key_c Reference to last RC4 computed key.
  464. * @return string encrypted text
  465. * @since 2.0.000 (2008-01-02)
  466. * @author Klemen Vodopivec, Nicola Asuni
  467. * @public static
  468. */
  469. public static function _RC4($key, $text, &$last_enc_key, &$last_enc_key_c) {
  470. if (function_exists('mcrypt_encrypt') AND ($out = @mcrypt_encrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, ''))) {
  471. // try to use mcrypt function if exist
  472. return $out;
  473. }
  474. if ($last_enc_key != $key) {
  475. $k = str_repeat($key, (int) ((256 / strlen($key)) + 1));
  476. $rc4 = range(0, 255);
  477. $j = 0;
  478. for ($i = 0; $i < 256; ++$i) {
  479. $t = $rc4[$i];
  480. $j = ($j + $t + ord($k[$i])) % 256;
  481. $rc4[$i] = $rc4[$j];
  482. $rc4[$j] = $t;
  483. }
  484. $last_enc_key = $key;
  485. $last_enc_key_c = $rc4;
  486. } else {
  487. $rc4 = $last_enc_key_c;
  488. }
  489. $len = strlen($text);
  490. $a = 0;
  491. $b = 0;
  492. $out = '';
  493. for ($i = 0; $i < $len; ++$i) {
  494. $a = ($a + 1) % 256;
  495. $t = $rc4[$a];
  496. $b = ($b + $t) % 256;
  497. $rc4[$a] = $rc4[$b];
  498. $rc4[$b] = $t;
  499. $k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
  500. $out .= chr(ord($text[$i]) ^ $k);
  501. }
  502. return $out;
  503. }
  504. /**
  505. * Return the permission code used on encryption (P value).
  506. * @param array $permissions the set of permissions (specify the ones you want to block).
  507. * @param int $mode encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  508. * @since 5.0.005 (2010-05-12)
  509. * @author Nicola Asuni
  510. * @public static
  511. */
  512. public static function getUserPermissionCode($permissions, $mode=0) {
  513. $options = array(
  514. 'owner' => 2, // bit 2 -- inverted logic: cleared by default
  515. 'print' => 4, // bit 3
  516. 'modify' => 8, // bit 4
  517. 'copy' => 16, // bit 5
  518. 'annot-forms' => 32, // bit 6
  519. 'fill-forms' => 256, // bit 9
  520. 'extract' => 512, // bit 10
  521. 'assemble' => 1024,// bit 11
  522. 'print-high' => 2048 // bit 12
  523. );
  524. $protection = 2147422012; // 32 bit: (01111111 11111111 00001111 00111100)
  525. foreach ($permissions as $permission) {
  526. if (isset($options[$permission])) {
  527. if (($mode > 0) OR ($options[$permission] <= 32)) {
  528. // set only valid permissions
  529. if ($options[$permission] == 2) {
  530. // the logic for bit 2 is inverted (cleared by default)
  531. $protection += $options[$permission];
  532. } else {
  533. $protection -= $options[$permission];
  534. }
  535. }
  536. }
  537. }
  538. return $protection;
  539. }
  540. /**
  541. * Convert hexadecimal string to string
  542. * @param string $bs byte-string to convert
  543. * @return string
  544. * @since 5.0.005 (2010-05-12)
  545. * @author Nicola Asuni
  546. * @public static
  547. */
  548. public static function convertHexStringToString($bs) {
  549. $string = ''; // string to be returned
  550. $bslength = strlen($bs);
  551. if (($bslength % 2) != 0) {
  552. // padding
  553. $bs .= '0';
  554. ++$bslength;
  555. }
  556. for ($i = 0; $i < $bslength; $i += 2) {
  557. $string .= chr(hexdec($bs[$i].$bs[($i + 1)]));
  558. }
  559. return $string;
  560. }
  561. /**
  562. * Convert string to hexadecimal string (byte string)
  563. * @param string $s string to convert
  564. * @return string byte string
  565. * @since 5.0.010 (2010-05-17)
  566. * @author Nicola Asuni
  567. * @public static
  568. */
  569. public static function convertStringToHexString($s) {
  570. $bs = '';
  571. $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY);
  572. foreach ($chars as $c) {
  573. $bs .= sprintf('%02s', dechex(ord($c)));
  574. }
  575. return $bs;
  576. }
  577. /**
  578. * Convert encryption P value to a string of bytes, low-order byte first.
  579. * @param string $protection 32bit encryption permission value (P value)
  580. * @return string
  581. * @since 5.0.005 (2010-05-12)
  582. * @author Nicola Asuni
  583. * @public static
  584. */
  585. public static function getEncPermissionsString($protection) {
  586. $binprot = sprintf('%032b', $protection);
  587. $str = chr(bindec(substr($binprot, 24, 8)));
  588. $str .= chr(bindec(substr($binprot, 16, 8)));
  589. $str .= chr(bindec(substr($binprot, 8, 8)));
  590. $str .= chr(bindec(substr($binprot, 0, 8)));
  591. return $str;
  592. }
  593. /**
  594. * Encode a name object.
  595. * @param string $name Name object to encode.
  596. * @return string Encoded name object.
  597. * @author Nicola Asuni
  598. * @since 5.9.097 (2011-06-23)
  599. * @public static
  600. */
  601. public static function encodeNameObject($name) {
  602. $escname = '';
  603. $length = strlen($name);
  604. for ($i = 0; $i < $length; ++$i) {
  605. $chr = $name[$i];
  606. if (preg_match('/[0-9a-zA-Z#_=-]/', $chr) == 1) {
  607. $escname .= $chr;
  608. } else {
  609. $escname .= sprintf('#%02X', ord($chr));
  610. }
  611. }
  612. return $escname;
  613. }
  614. /**
  615. * Convert JavaScript form fields properties array to Annotation Properties array.
  616. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  617. * @param array $spot_colors Reference to spot colors array.
  618. * @param boolean $rtl True if in Right-To-Left text direction mode, false otherwise.
  619. * @return array of annotation properties
  620. * @author Nicola Asuni
  621. * @since 4.8.000 (2009-09-06)
  622. * @public static
  623. */
  624. public static function getAnnotOptFromJSProp($prop, &$spot_colors, $rtl=false) {
  625. if (isset($prop['aopt']) AND is_array($prop['aopt'])) {
  626. // the annotation options are already defined
  627. return $prop['aopt'];
  628. }
  629. $opt = array(); // value to be returned
  630. // alignment: Controls how the text is laid out within the text field.
  631. if (isset($prop['alignment'])) {
  632. switch ($prop['alignment']) {
  633. case 'left': {
  634. $opt['q'] = 0;
  635. break;
  636. }
  637. case 'center': {
  638. $opt['q'] = 1;
  639. break;
  640. }
  641. case 'right': {
  642. $opt['q'] = 2;
  643. break;
  644. }
  645. default: {
  646. $opt['q'] = ($rtl)?2:0;
  647. break;
  648. }
  649. }
  650. }
  651. // lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle.
  652. if (isset($prop['lineWidth'])) {
  653. $linewidth = intval($prop['lineWidth']);
  654. } else {
  655. $linewidth = 1;
  656. }
  657. // borderStyle: The border style for a field.
  658. if (isset($prop['borderStyle'])) {
  659. switch ($prop['borderStyle']) {
  660. case 'border.d':
  661. case 'dashed': {
  662. $opt['border'] = array(0, 0, $linewidth, array(3, 2));
  663. $opt['bs'] = array('w'=>$linewidth, 's'=>'D', 'd'=>array(3, 2));
  664. break;
  665. }
  666. case 'border.b':
  667. case 'beveled': {
  668. $opt['border'] = array(0, 0, $linewidth);
  669. $opt['bs'] = array('w'=>$linewidth, 's'=>'B');
  670. break;
  671. }
  672. case 'border.i':
  673. case 'inset': {
  674. $opt['border'] = array(0, 0, $linewidth);
  675. $opt['bs'] = array('w'=>$linewidth, 's'=>'I');
  676. break;
  677. }
  678. case 'border.u':
  679. case 'underline': {
  680. $opt['border'] = array(0, 0, $linewidth);
  681. $opt['bs'] = array('w'=>$linewidth, 's'=>'U');
  682. break;
  683. }
  684. case 'border.s':
  685. case 'solid': {
  686. $opt['border'] = array(0, 0, $linewidth);
  687. $opt['bs'] = array('w'=>$linewidth, 's'=>'S');
  688. break;
  689. }
  690. default: {
  691. break;
  692. }
  693. }
  694. }
  695. if (isset($prop['border']) AND is_array($prop['border'])) {
  696. $opt['border'] = $prop['border'];
  697. }
  698. if (!isset($opt['mk'])) {
  699. $opt['mk'] = array();
  700. }
  701. if (!isset($opt['mk']['if'])) {
  702. $opt['mk']['if'] = array();
  703. }
  704. $opt['mk']['if']['a'] = array(0.5, 0.5);
  705. // buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon.
  706. if (isset($prop['buttonAlignX'])) {
  707. $opt['mk']['if']['a'][0] = $prop['buttonAlignX'];
  708. }
  709. // buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon.
  710. if (isset($prop['buttonAlignY'])) {
  711. $opt['mk']['if']['a'][1] = $prop['buttonAlignY'];
  712. }
  713. // buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field.
  714. if (isset($prop['buttonFitBounds']) AND ($prop['buttonFitBounds'] == 'true')) {
  715. $opt['mk']['if']['fb'] = true;
  716. }
  717. // buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face.
  718. if (isset($prop['buttonScaleHow'])) {
  719. switch ($prop['buttonScaleHow']) {
  720. case 'scaleHow.proportional': {
  721. $opt['mk']['if']['s'] = 'P';
  722. break;
  723. }
  724. case 'scaleHow.anamorphic': {
  725. $opt['mk']['if']['s'] = 'A';
  726. break;
  727. }
  728. }
  729. }
  730. // buttonScaleWhen: Controls when an icon is scaled to fit inside the button face.
  731. if (isset($prop['buttonScaleWhen'])) {
  732. switch ($prop['buttonScaleWhen']) {
  733. case 'scaleWhen.always': {
  734. $opt['mk']['if']['sw'] = 'A';
  735. break;
  736. }
  737. case 'scaleWhen.never': {
  738. $opt['mk']['if']['sw'] = 'N';
  739. break;
  740. }
  741. case 'scaleWhen.tooBig': {
  742. $opt['mk']['if']['sw'] = 'B';
  743. break;
  744. }
  745. case 'scaleWhen.tooSmall': {
  746. $opt['mk']['if']['sw'] = 'S';
  747. break;
  748. }
  749. }
  750. }
  751. // buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face.
  752. if (isset($prop['buttonPosition'])) {
  753. switch ($prop['buttonPosition']) {
  754. case 0:
  755. case 'position.textOnly': {
  756. $opt['mk']['tp'] = 0;
  757. break;
  758. }
  759. case 1:
  760. case 'position.iconOnly': {
  761. $opt['mk']['tp'] = 1;
  762. break;
  763. }
  764. case 2:
  765. case 'position.iconTextV': {
  766. $opt['mk']['tp'] = 2;
  767. break;
  768. }
  769. case 3:
  770. case 'position.textIconV': {
  771. $opt['mk']['tp'] = 3;
  772. break;
  773. }
  774. case 4:
  775. case 'position.iconTextH': {
  776. $opt['mk']['tp'] = 4;
  777. break;
  778. }
  779. case 5:
  780. case 'position.textIconH': {
  781. $opt['mk']['tp'] = 5;
  782. break;
  783. }
  784. case 6:
  785. case 'position.overlay': {
  786. $opt['mk']['tp'] = 6;
  787. break;
  788. }
  789. }
  790. }
  791. // fillColor: Specifies the background color for a field.
  792. if (isset($prop['fillColor'])) {
  793. if (is_array($prop['fillColor'])) {
  794. $opt['mk']['bg'] = $prop['fillColor'];
  795. } else {
  796. $opt['mk']['bg'] = TCPDF_COLORS::convertHTMLColorToDec($prop['fillColor'], $spot_colors);
  797. }
  798. }
  799. // strokeColor: Specifies the stroke color for a field that is used to stroke the rectangle of the field with a line as large as the line width.
  800. if (isset($prop['strokeColor'])) {
  801. if (is_array($prop['strokeColor'])) {
  802. $opt['mk']['bc'] = $prop['strokeColor'];
  803. } else {
  804. $opt['mk']['bc'] = TCPDF_COLORS::convertHTMLColorToDec($prop['strokeColor'], $spot_colors);
  805. }
  806. }
  807. // rotation: The rotation of a widget in counterclockwise increments.
  808. if (isset($prop['rotation'])) {
  809. $opt['mk']['r'] = $prop['rotation'];
  810. }
  811. // charLimit: Limits the number of characters that a user can type into a text field.
  812. if (isset($prop['charLimit'])) {
  813. $opt['maxlen'] = intval($prop['charLimit']);
  814. }
  815. if (!isset($ff)) {
  816. $ff = 0; // default value
  817. }
  818. // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
  819. if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
  820. $ff += 1 << 0;
  821. }
  822. // required: Specifies whether a field requires a value.
  823. if (isset($prop['required']) AND ($prop['required'] == 'true')) {
  824. $ff += 1 << 1;
  825. }
  826. // multiline: Controls how text is wrapped within the field.
  827. if (isset($prop['multiline']) AND ($prop['multiline'] == 'true')) {
  828. $ff += 1 << 12;
  829. }
  830. // password: Specifies whether the field should display asterisks when data is entered in the field.
  831. if (isset($prop['password']) AND ($prop['password'] == 'true')) {
  832. $ff += 1 << 13;
  833. }
  834. // NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect.
  835. if (isset($prop['NoToggleToOff']) AND ($prop['NoToggleToOff'] == 'true')) {
  836. $ff += 1 << 14;
  837. }
  838. // Radio: If set, the field is a set of radio buttons.
  839. if (isset($prop['Radio']) AND ($prop['Radio'] == 'true')) {
  840. $ff += 1 << 15;
  841. }
  842. // Pushbutton: If set, the field is a pushbutton that does not retain a permanent value.
  843. if (isset($prop['Pushbutton']) AND ($prop['Pushbutton'] == 'true')) {
  844. $ff += 1 << 16;
  845. }
  846. // Combo: If set, the field is a combo box; if clear, the field is a list box.
  847. if (isset($prop['Combo']) AND ($prop['Combo'] == 'true')) {
  848. $ff += 1 << 17;
  849. }
  850. // editable: Controls whether a combo box is editable.
  851. if (isset($prop['editable']) AND ($prop['editable'] == 'true')) {
  852. $ff += 1 << 18;
  853. }
  854. // Sort: If set, the field's option items shall be sorted alphabetically.
  855. if (isset($prop['Sort']) AND ($prop['Sort'] == 'true')) {
  856. $ff += 1 << 19;
  857. }
  858. // fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection).
  859. if (isset($prop['fileSelect']) AND ($prop['fileSelect'] == 'true')) {
  860. $ff += 1 << 20;
  861. }
  862. // multipleSelection: If true, indicates that a list box allows a multiple selection of items.
  863. if (isset($prop['multipleSelection']) AND ($prop['multipleSelection'] == 'true')) {
  864. $ff += 1 << 21;
  865. }
  866. // doNotSpellCheck: If true, spell checking is not performed on this editable text field.
  867. if (isset($prop['doNotSpellCheck']) AND ($prop['doNotSpellCheck'] == 'true')) {
  868. $ff += 1 << 22;
  869. }
  870. // doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field.
  871. if (isset($prop['doNotScroll']) AND ($prop['doNotScroll'] == 'true')) {
  872. $ff += 1 << 23;
  873. }
  874. // comb: If set to true, the field background is drawn as series of boxes (one for each character in the value of the field) and each character of the content is drawn within those boxes. The number of boxes drawn is determined from the charLimit property. It applies only to text fields. The setter will also raise if any of the following field properties are also set multiline, password, and fileSelect. A side-effect of setting this property is that the doNotScroll property is also set.
  875. if (isset($prop['comb']) AND ($prop['comb'] == 'true')) {
  876. $ff += 1 << 24;
  877. }
  878. // radiosInUnison: If false, even if a group of radio buttons have the same name and export value, they behave in a mutually exclusive fashion, like HTML radio buttons.
  879. if (isset($prop['radiosInUnison']) AND ($prop['radiosInUnison'] == 'true')) {
  880. $ff += 1 << 25;
  881. }
  882. // richText: If true, the field allows rich text formatting.
  883. if (isset($prop['richText']) AND ($prop['richText'] == 'true')) {
  884. $ff += 1 << 25;
  885. }
  886. // commitOnSelChange: Controls whether a field value is committed after a selection change.
  887. if (isset($prop['commitOnSelChange']) AND ($prop['commitOnSelChange'] == 'true')) {
  888. $ff += 1 << 26;
  889. }
  890. $opt['ff'] = $ff;
  891. // defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset.
  892. if (isset($prop['defaultValue'])) {
  893. $opt['dv'] = $prop['defaultValue'];
  894. }
  895. $f = 4; // default value for annotation flags
  896. // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
  897. if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
  898. $f += 1 << 6;
  899. }
  900. // display: Controls whether the field is hidden or visible on screen and in print.
  901. if (isset($prop['display'])) {
  902. if ($prop['display'] == 'display.visible') {
  903. //
  904. } elseif ($prop['display'] == 'display.hidden') {
  905. $f += 1 << 1;
  906. } elseif ($prop['display'] == 'display.noPrint') {
  907. $f -= 1 << 2;
  908. } elseif ($prop['display'] == 'display.noView') {
  909. $f += 1 << 5;
  910. }
  911. }
  912. $opt['f'] = $f;
  913. // currentValueIndices: Reads and writes single or multiple values of a list box or combo box.
  914. if (isset($prop['currentValueIndices']) AND is_array($prop['currentValueIndices'])) {
  915. $opt['i'] = $prop['currentValueIndices'];
  916. }
  917. // value: The value of the field data that the user has entered.
  918. if (isset($prop['value'])) {
  919. if (is_array($prop['value'])) {
  920. $opt['opt'] = array();
  921. foreach ($prop['value'] AS $key => $optval) {
  922. // exportValues: An array of strings representing the export values for the field.
  923. if (isset($prop['exportValues'][$key])) {
  924. $opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]);
  925. } else {
  926. $opt['opt'][$key] = $prop['value'][$key];
  927. }
  928. }
  929. } else {
  930. $opt['v'] = $prop['value'];
  931. }
  932. }
  933. // richValue: This property specifies the text contents and formatting of a rich text field.
  934. if (isset($prop['richValue'])) {
  935. $opt['rv'] = $prop['richValue'];
  936. }
  937. // submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded).
  938. if (isset($prop['submitName'])) {
  939. $opt['tm'] = $prop['submitName'];
  940. }
  941. // name: Fully qualified field name.
  942. if (isset($prop['name'])) {
  943. $opt['t'] = $prop['name'];
  944. }
  945. // userName: The user name (short description string) of the field.
  946. if (isset($prop['userName'])) {
  947. $opt['tu'] = $prop['userName'];
  948. }
  949. // highlight: Defines how a button reacts when a user clicks it.
  950. if (isset($prop['highlight'])) {
  951. switch ($prop['highlight']) {
  952. case 'none':
  953. case 'highlight.n': {
  954. $opt['h'] = 'N';
  955. break;
  956. }
  957. case 'invert':
  958. case 'highlight.i': {
  959. $opt['h'] = 'i';
  960. break;
  961. }
  962. case 'push':
  963. case 'highlight.p': {
  964. $opt['h'] = 'P';
  965. break;
  966. }
  967. case 'outline':
  968. case 'highlight.o': {
  969. $opt['h'] = 'O';
  970. break;
  971. }
  972. }
  973. }
  974. // Unsupported options:
  975. // - calcOrderIndex: Changes the calculation order of fields in the document.
  976. // - delay: Delays the redrawing of a field's appearance.
  977. // - defaultStyle: This property defines the default style attributes for the form field.
  978. // - style: Allows the user to set the glyph style of a check box or radio button.
  979. // - textColor, textFont, textSize
  980. return $opt;
  981. }
  982. /**
  983. * Format the page numbers.
  984. * This method can be overridden for custom formats.
  985. * @param int $num page number
  986. * @return string
  987. * @since 4.2.005 (2008-11-06)
  988. * @public static
  989. */
  990. public static function formatPageNumber($num) {
  991. return number_format((float)$num, 0, '', '.');
  992. }
  993. /**
  994. * Format the page numbers on the Table Of Content.
  995. * This method can be overridden for custom formats.
  996. * @param int $num page number
  997. * @return string
  998. * @since 4.5.001 (2009-01-04)
  999. * @see addTOC(), addHTMLTOC()
  1000. * @public static
  1001. */
  1002. public static function formatTOCPageNumber($num) {
  1003. return number_format((float)$num, 0, '', '.');
  1004. }
  1005. /**
  1006. * Extracts the CSS properties from a CSS string.
  1007. * @param string $cssdata string containing CSS definitions.
  1008. * @return array An array where the keys are the CSS selectors and the values are the CSS properties.
  1009. * @author Nicola Asuni
  1010. * @since 5.1.000 (2010-05-25)
  1011. * @public static
  1012. */
  1013. public static function extractCSSproperties($cssdata) {
  1014. if (empty($cssdata)) {
  1015. return array();
  1016. }
  1017. // remove comments
  1018. $cssdata = preg_replace('/\/\*[^\*]*\*\//', '', $cssdata);
  1019. // remove newlines and multiple spaces
  1020. $cssdata = preg_replace('/[\s]+/', ' ', $cssdata);
  1021. // remove some spaces
  1022. $cssdata = preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata);
  1023. // remove empty blocks
  1024. $cssdata = preg_replace('/([^\}\{]+)\{\}/', '', $cssdata);
  1025. // replace media type parenthesis
  1026. $cssdata = preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1§', $cssdata);
  1027. $cssdata = preg_replace('/\}\}/si', '}§', $cssdata);
  1028. // trim string
  1029. $cssdata = trim($cssdata);
  1030. // find media blocks (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  1031. $cssblocks = array();
  1032. $matches = array();
  1033. if (preg_match_all('/@media[\s]+([^\§]*)§([^§]*)§/i', $cssdata, $matches) > 0) {
  1034. foreach ($matches[1] as $key => $type) {
  1035. $cssblocks[$type] = $matches[2][$key];
  1036. }
  1037. // remove media blocks
  1038. $cssdata = preg_replace('/@media[\s]+([^\§]*)§([^§]*)§/i', '', $cssdata);
  1039. }
  1040. // keep 'all' and 'print' media, other media types are discarded
  1041. if (isset($cssblocks['all']) AND !empty($cssblocks['all'])) {
  1042. $cssdata .= $cssblocks['all'];
  1043. }
  1044. if (isset($cssblocks['print']) AND !empty($cssblocks['print'])) {
  1045. $cssdata .= $cssblocks['print'];
  1046. }
  1047. // reset css blocks array
  1048. $cssblocks = array();
  1049. $matches = array();
  1050. // explode css data string into array
  1051. if (substr($cssdata, -1) == '}') {
  1052. // remove last parethesis
  1053. $cssdata = substr($cssdata, 0, -1);
  1054. }
  1055. $matches = explode('}', $cssdata);
  1056. foreach ($matches as $key => $block) {
  1057. // index 0 contains the CSS selector, index 1 contains CSS properties
  1058. $cssblocks[$key] = explode('{', $block);
  1059. if (!isset($cssblocks[$key][1])) {
  1060. // remove empty definitions
  1061. unset($cssblocks[$key]);
  1062. }
  1063. }
  1064. // split groups of selectors (comma-separated list of selectors)
  1065. foreach ($cssblocks as $key => $block) {
  1066. if (strpos($block[0], ',') > 0) {
  1067. $selectors = explode(',', $block[0]);
  1068. foreach ($selectors as $sel) {
  1069. $cssblocks[] = array(0 => trim($sel), 1 => $block[1]);
  1070. }
  1071. unset($cssblocks[$key]);
  1072. }
  1073. }
  1074. // covert array to selector => properties
  1075. $cssdata = array();
  1076. foreach ($cssblocks as $block) {
  1077. $selector = $block[0];
  1078. // calculate selector's specificity
  1079. $matches = array();
  1080. $a = 0; // the declaration is not from is a 'style' attribute
  1081. $b = intval(preg_match_all('/[\#]/', $selector, $matches)); // number of ID attributes
  1082. $c = intval(preg_match_all('/[\[\.]/', $selector, $matches)); // number of other attributes
  1083. $c += intval(preg_match_all('/[\:]link|visited|hover|active|focus|target|lang|enabled|disabled|checked|indeterminate|root|nth|first|last|only|empty|contains|not/i', $selector, $matches)); // number of pseudo-classes
  1084. $d = intval(preg_match_all('/[\>\+\~\s]{1}[a-zA-Z0-9]+/', ' '.$selector, $matches)); // number of element names
  1085. $d += intval(preg_match_all('/[\:][\:]/', $selector, $matches)); // number of pseudo-elements
  1086. $specificity = $a.$b.$c.$d;
  1087. // add specificity to the beginning of the selector
  1088. $cssdata[$specificity.' '.$selector] = $block[1];
  1089. }
  1090. // sort selectors alphabetically to account for specificity
  1091. ksort($cssdata, SORT_STRING);
  1092. // return array
  1093. return $cssdata;
  1094. }
  1095. /**
  1096. * Cleanup HTML code (requires HTML Tidy library).
  1097. * @param string $html htmlcode to fix
  1098. * @param string $default_css CSS commands to add
  1099. * @param array|null $tagvs parameters for setHtmlVSpace method
  1100. * @param array|null $tidy_options options for tidy_parse_string function
  1101. * @param array $tagvspaces Array of vertical spaces for tags.
  1102. * @return string XHTML code cleaned up
  1103. * @author Nicola Asuni
  1104. * @since 5.9.017 (2010-11-16)
  1105. * @see setHtmlVSpace()
  1106. * @public static
  1107. */
  1108. public static function fixHTMLCode($html, $default_css, $tagvs, $tidy_options, &$tagvspaces) {
  1109. // configure parameters for HTML Tidy
  1110. if (TCPDF_STATIC::empty_string($tidy_options)) {
  1111. $tidy_options = array (
  1112. 'clean' => 1,
  1113. 'drop-empty-paras' => 0,
  1114. 'drop-proprietary-attributes' => 1,
  1115. 'fix-backslash' => 1,
  1116. 'hide-comments' => 1,
  1117. 'join-styles' => 1,
  1118. 'lower-literals' => 1,
  1119. 'merge-divs' => 1,
  1120. 'merge-spans' => 1,
  1121. 'output-xhtml' => 1,
  1122. 'word-2000' => 1,
  1123. 'wrap' => 0,
  1124. 'output-bom' => 0,
  1125. //'char-encoding' => 'utf8',
  1126. //'input-encoding' => 'utf8',
  1127. //'output-encoding' => 'utf8'
  1128. );
  1129. }
  1130. // clean up the HTML code
  1131. $tidy = tidy_parse_string($html, $tidy_options);
  1132. // fix the HTML
  1133. $tidy->cleanRepair();
  1134. // get the CSS part
  1135. $tidy_head = tidy_get_head($tidy);
  1136. $css = $tidy_head->value;
  1137. $css = preg_replace('/<style([^>]+)>/ims', '<style>', $css);
  1138. $css = preg_replace('/<\/style>(.*)<style>/ims', "\n", $css);
  1139. $css = str_replace('/*<![CDATA[*/', '', $css);
  1140. $css = str_replace('/*]]>*/', '', $css);
  1141. preg_match('/<style>(.*)<\/style>/ims', $css, $matches);
  1142. if (isset($matches[1])) {
  1143. $css = strtolower($matches[1]);
  1144. } else {
  1145. $css = '';
  1146. }
  1147. // include default css
  1148. $css = '<style>'.$default_css.$css.'</style>';
  1149. // get the body part
  1150. $tidy_body = tidy_get_body($tidy);
  1151. $html = $tidy_body->value;
  1152. // fix some self-closing tags
  1153. $html = str_replace('<br>', '<br />', $html);
  1154. // remove some empty tag blocks
  1155. $html = preg_replace('/<div([^\>]*)><\/div>/', '', $html);
  1156. $html = preg_replace('/<p([^\>]*)><\/p>/', '', $html);
  1157. if (!TCPDF_STATIC::empty_string($tagvs)) {
  1158. // set vertical space for some XHTML tags
  1159. $tagvspaces = $tagvs;
  1160. }
  1161. // return the cleaned XHTML code + CSS
  1162. return $css.$html;
  1163. }
  1164. /**
  1165. * Returns true if the CSS selector is valid for the selected HTML tag
  1166. * @param array $dom array of HTML tags and properties
  1167. * @param int $key key of the current HTML tag
  1168. * @param string $selector CSS selector string
  1169. * @return true if the selector is valid, false otherwise
  1170. * @since 5.1.000 (2010-05-25)
  1171. * @public static
  1172. */
  1173. public static function isValidCSSSelectorForTag($dom, $key, $selector) {
  1174. $valid = false; // value to be returned
  1175. $tag = $dom[$key]['value'];
  1176. $class = array();
  1177. if (isset($dom[$key]['attribute']['class']) AND !empty($dom[$key]['attribute']['class'])) {
  1178. $class = explode(' ', strtolower($dom[$key]['attribute']['class']));
  1179. }
  1180. $id = '';
  1181. if (isset($dom[$key]['attribute']['id']) AND !empty($dom[$key]['attribute']['id'])) {
  1182. $id = strtolower($dom[$key]['attribute']['id']);
  1183. }
  1184. $selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector);
  1185. $matches = array();
  1186. if (preg_match_all('/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si', $selector, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) > 0) {
  1187. $parentop = array_pop($matches[1]);
  1188. $operator = $parentop[0];
  1189. $offset = $parentop[1];
  1190. $lasttag = array_pop($matches[2]);
  1191. $lasttag = strtolower(trim($lasttag[0]));
  1192. if (($lasttag == '*') OR ($lasttag == $tag)) {
  1193. // the last element on selector is our tag or 'any tag'
  1194. $attrib = array_pop($matches[3]);
  1195. $attrib = strtolower(trim($attrib[0]));
  1196. if (!empty($attrib)) {
  1197. // check if matches class, id, attribute, pseudo-class or pseudo-element
  1198. switch ($attrib[0]) {
  1199. case '.': { // class
  1200. if (in_array(substr($attrib, 1), $class)) {
  1201. $valid = true;
  1202. }
  1203. break;
  1204. }
  1205. case '#': { // ID
  1206. if (substr($attrib, 1) == $id) {
  1207. $valid = true;
  1208. }
  1209. break;
  1210. }
  1211. case '[': { // attribute
  1212. $attrmatch = array();
  1213. if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) {
  1214. $att = strtolower($attrmatch[1]);
  1215. $val = $attrmatch[3];
  1216. if (isset($dom[$key]['attribute'][$att])) {
  1217. switch ($attrmatch[2]) {
  1218. case '=': {
  1219. if ($dom[$key]['attribute'][$att] == $val) {
  1220. $valid = true;
  1221. }
  1222. break;
  1223. }
  1224. case '~=': {
  1225. if (in_array($val, explode(' ', $dom[$key]['attribute'][$att]))) {
  1226. $valid = true;
  1227. }
  1228. break;
  1229. }
  1230. case '^=': {
  1231. if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val))) {
  1232. $valid = true;
  1233. }
  1234. break;
  1235. }
  1236. case '$=': {
  1237. if ($val == substr($dom[$key]['attribute'][$att], -strlen($val))) {
  1238. $valid = true;
  1239. }
  1240. break;
  1241. }
  1242. case '*=': {
  1243. if (strpos($dom[$key]['attribute'][$att], $val) !== false) {
  1244. $valid = true;
  1245. }
  1246. break;
  1247. }
  1248. case '|=': {
  1249. if ($dom[$key]['attribute'][$att] == $val) {
  1250. $valid = true;
  1251. } elseif (preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) {
  1252. $valid = true;
  1253. }
  1254. break;
  1255. }
  1256. default: {
  1257. $valid = true;
  1258. }
  1259. }
  1260. }
  1261. }
  1262. break;
  1263. }
  1264. case ':': { // pseudo-class or pseudo-element
  1265. if ($attrib[1] == ':') { // pseudo-element
  1266. // pseudo-elements are not supported!
  1267. // (::first-line, ::first-letter, ::before, ::after)
  1268. } else { // pseudo-class
  1269. // pseudo-classes are not supported!
  1270. // (:root, :nth-child(n), :nth-last-child(n), :nth-of-type(n), :nth-last-of-type(n), :first-child, :last-child, :first-of-type, :last-of-type, :only-child, :only-of-type, :empty, :link, :visited, :active, :hover, :focus, :target, :lang(fr), :enabled, :disabled, :checked)
  1271. }
  1272. break;
  1273. }
  1274. } // end of switch
  1275. } else {
  1276. $valid = true;
  1277. }
  1278. if ($valid AND ($offset > 0)) {
  1279. $valid = false;
  1280. // check remaining selector part
  1281. $selector = substr($selector, 0, $offset);
  1282. switch ($operator) {
  1283. case ' ': { // descendant of an element
  1284. while ($dom[$key]['parent'] > 0) {
  1285. if (self::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector)) {
  1286. $valid = true;
  1287. break;
  1288. } else {
  1289. $key = $dom[$key]['parent'];
  1290. }
  1291. }
  1292. break;
  1293. }
  1294. case '>': { // child of an element
  1295. $valid = self::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector);
  1296. break;
  1297. }
  1298. case '+': { // immediately preceded by an element
  1299. for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
  1300. if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
  1301. $valid = self::isValidCSSSelectorForTag($dom, $i, $selector);
  1302. break;
  1303. }
  1304. }
  1305. break;
  1306. }
  1307. case '~': { // preceded by an element
  1308. for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
  1309. if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
  1310. if (self::isValidCSSSelectorForTag($dom, $i, $selector)) {
  1311. break;
  1312. }
  1313. }
  1314. }
  1315. break;
  1316. }
  1317. }
  1318. }
  1319. }
  1320. }
  1321. return $valid;
  1322. }
  1323. /**
  1324. * Returns the styles array that apply for the selected HTML tag.
  1325. * @param array $dom array of HTML tags and properties
  1326. * @param int $key key of the current HTML tag
  1327. * @param array $css array of CSS properties
  1328. * @return array containing CSS properties
  1329. * @since 5.1.000 (2010-05-25)
  1330. * @public static
  1331. */
  1332. public static function getCSSdataArray($dom, $key, $css) {
  1333. $cssarray = array(); // style to be returned
  1334. // get parent CSS selectors
  1335. $selectors = array();
  1336. if (isset($dom[($dom[$key]['parent'])]['csssel'])) {
  1337. $selectors = $dom[($dom[$key]['parent'])]['csssel'];
  1338. }
  1339. // get all styles that apply
  1340. foreach($css as $selector => $style) {
  1341. $pos = strpos($selector, ' ');
  1342. // get specificity
  1343. $specificity = substr($selector, 0, $pos);
  1344. // remove specificity
  1345. $selector = substr($selector, $pos);
  1346. // check if this selector apply to current tag
  1347. if (self::isValidCSSSelectorForTag($dom, $key, $selector)) {
  1348. if (!in_array($selector, $selectors)) {
  1349. // add style if not already added on parent selector
  1350. $cssarray[] = array('k' => $selector, 's' => $specificity, 'c' => $style);
  1351. $selectors[] = $selector;
  1352. }
  1353. }
  1354. }
  1355. if (isset($dom[$key]['attribute']['style'])) {
  1356. // attach inline style (latest properties have high priority)
  1357. $cssarray[] = array('k' => '', 's' => '1000', 'c' => $dom[$key]['attribute']['style']);
  1358. }
  1359. // order the css array to account for specificity
  1360. $cssordered = array();
  1361. foreach ($cssarray as $key => $val) {
  1362. $skey = sprintf('%04d', $key);
  1363. $cssordered[$val['s'].'_'.$skey] = $val;
  1364. }
  1365. // sort selectors alphabetically to account for specificity
  1366. ksort($cssordered, SORT_STRING);
  1367. return array($selectors, $cssordered);
  1368. }
  1369. /**
  1370. * Compact CSS data array into single string.
  1371. * @param array $css array of CSS properties
  1372. * @return string containing merged CSS properties
  1373. * @since 5.9.070 (2011-04-19)
  1374. * @public static
  1375. */
  1376. public static function getTagStyleFromCSSarray($css) {
  1377. $tagstyle = ''; // value to be returned
  1378. foreach ($css as $style) {
  1379. // split single css commands
  1380. $csscmds = explode(';', $style['c']);
  1381. foreach ($csscmds as $cmd) {
  1382. if (!empty($cmd)) {
  1383. $pos = strpos($cmd, ':');
  1384. if ($pos !== false) {
  1385. $cmd = substr($cmd, 0, ($pos + 1));
  1386. if (strpos($tagstyle, $cmd) !== false) {
  1387. // remove duplicate commands (last commands have high priority)
  1388. $tagstyle = preg_replace('/'.$cmd.'[^;]+/i', '', $tagstyle);
  1389. }
  1390. }
  1391. }
  1392. }
  1393. $tagstyle .= ';'.$style['c'];
  1394. }
  1395. // remove multiple semicolons
  1396. $tagstyle = preg_replace('/[;]+/', ';', $tagstyle);
  1397. return $tagstyle;
  1398. }
  1399. /**
  1400. * Returns the Roman representation of an integer number
  1401. * @param int $number number to convert
  1402. * @return string roman representation of the specified number
  1403. * @since 4.4.004 (2008-12-10)
  1404. * @public static
  1405. */
  1406. public static function intToRoman($number) {
  1407. $roman = '';
  1408. if ($number >= 4000) {
  1409. // do not represent numbers above 4000 in Roman numerals
  1410. return strval($number);
  1411. }
  1412. while ($number >= 1000) {
  1413. $roman .= 'M';
  1414. $number -= 1000;
  1415. }
  1416. while ($number >= 900) {
  1417. $roman .= 'CM';
  1418. $number -= 900;
  1419. }
  1420. while ($number >= 500) {
  1421. $roman .= 'D';
  1422. $number -= 500;
  1423. }
  1424. while ($number >= 400) {
  1425. $roman .= 'CD';
  1426. $number -= 400;
  1427. }
  1428. while ($number >= 100) {
  1429. $roman .= 'C';
  1430. $number -= 100;
  1431. }
  1432. while ($number >= 90) {
  1433. $roman .= 'XC';
  1434. $number -= 90;
  1435. }
  1436. while ($number >= 50) {
  1437. $roman .= 'L';
  1438. $number -= 50;
  1439. }
  1440. while ($number >= 40) {
  1441. $roman .= 'XL';
  1442. $number -= 40;
  1443. }
  1444. while ($number >= 10) {
  1445. $roman .= 'X';
  1446. $number -= 10;
  1447. }
  1448. while ($number >= 9) {
  1449. $roman .= 'IX';
  1450. $number -= 9;
  1451. }
  1452. while ($number >= 5) {
  1453. $roman .= 'V';
  1454. $number -= 5;
  1455. }
  1456. while ($number >= 4) {
  1457. $roman .= 'IV';
  1458. $number -= 4;
  1459. }
  1460. while ($number >= 1) {
  1461. $roman .= 'I';
  1462. --$number;
  1463. }
  1464. return $roman;
  1465. }
  1466. /**
  1467. * Find position of last occurrence of a substring in a string
  1468. * @param string $haystack The string to search in.
  1469. * @param string $needle substring to search.
  1470. * @param int $offset May be specified to begin searching an arbitrary number of characters into the string.
  1471. * @return int|false Returns the position where the needle exists. Returns FALSE if the needle was not found.
  1472. * @since 4.8.038 (2010-03-13)
  1473. * @public static
  1474. */
  1475. public static function revstrpos($haystack, $needle, $offset = 0) {
  1476. $length = strlen($haystack);
  1477. $offset = ($offset > 0)?($length - $offset):abs($offset);
  1478. $pos = strpos(strrev($haystack), strrev($needle), $offset);
  1479. return ($pos === false)?false:($length - $pos - strlen($needle));
  1480. }
  1481. /**
  1482. * Returns an array of hyphenation patterns.
  1483. * @param string $file TEX file containing hypenation patterns. TEX patterns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
  1484. * @return array of hyphenation patterns
  1485. * @author Nicola Asuni
  1486. * @since 4.9.012 (2010-04-12)
  1487. * @public static
  1488. */
  1489. public static function getHyphenPatternsFromTEX($file) {
  1490. // TEX patterns are available at:
  1491. // http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
  1492. $data = file_get_contents($file);
  1493. $patterns = array();
  1494. // remove comments
  1495. $data = preg_replace('/\%[^\n]*/', '', $data);
  1496. // extract the patterns part
  1497. preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches);
  1498. $data = trim(substr($matches[0], 10, -1));
  1499. // extract each pattern
  1500. $patterns_array = preg_split('/[\s]+/', $data);
  1501. // create new language array of patterns
  1502. $patterns = array();
  1503. foreach($patterns_array as $val) {
  1504. if (!TCPDF_STATIC::empty_string($val)) {
  1505. $val = trim($val);
  1506. $val = str_replace('\'', '\\\'', $val);
  1507. $key = preg_replace('/[0-9]+/', '', $val);
  1508. $patterns[$key] = $val;
  1509. }
  1510. }
  1511. return $patterns;
  1512. }
  1513. /**
  1514. * Get the Path-Painting Operators.
  1515. * @param string $style Style of rendering. Possible values are:
  1516. * <ul>
  1517. * <li>S or D: Stroke the path.</li>
  1518. * <li>s or d: Close and stroke the path.</li>
  1519. * <li>f or F: Fill the path, using the nonzero winding number rule to determine the region to fill.</li>
  1520. * <li>f* or F*: Fill the path, using the even-odd rule to determine the region to fill.</li>
  1521. * <li>B or FD or DF: Fill and then stroke the path, using the nonzero winding number rule to determine the region to fill.</li>
  1522. * <li>B* or F*D or DF*: Fill and then stroke the path, using the even-odd rule to determine the region to fill.</li>
  1523. * <li>b or fd or df: Close, fill, and then stroke the path, using the nonzero winding number rule to determine the region to fill.</li>
  1524. * <li>b or f*d or df*: Close, fill, and then stroke the path, using the even-odd rule to determine the region to fill.</li>
  1525. * <li>CNZ: Clipping mode using the even-odd rule to determine which regions lie inside the clipping path.</li>
  1526. * <li>CEO: Clipping mode using the nonzero winding number rule to determine which regions lie inside the clipping path</li>
  1527. * <li>n: End the path object without filling or stroking it.</li>
  1528. * </ul>
  1529. * @param string $default default style
  1530. * @return string
  1531. * @author Nicola Asuni
  1532. * @since 5.0.000 (2010-04-30)
  1533. * @public static
  1534. */
  1535. public static function getPathPaintOperator($style, $default='S') {
  1536. $op = '';
  1537. switch($style) {
  1538. case 'S':
  1539. case 'D': {
  1540. $op = 'S';
  1541. break;
  1542. }
  1543. case 's':
  1544. case 'd': {
  1545. $op = 's';
  1546. break;
  1547. }
  1548. case 'f':
  1549. case 'F': {
  1550. $op = 'f';
  1551. break;
  1552. }
  1553. case 'f*':
  1554. case 'F*': {
  1555. $op = 'f*';
  1556. break;
  1557. }
  1558. case 'B':
  1559. case 'FD':
  1560. case 'DF': {
  1561. $op = 'B';
  1562. break;
  1563. }
  1564. case 'B*':
  1565. case 'F*D':
  1566. case 'DF*': {
  1567. $op = 'B*';
  1568. break;
  1569. }
  1570. case 'b':
  1571. case 'fd':
  1572. case 'df': {
  1573. $op = 'b';
  1574. break;
  1575. }
  1576. case 'b*':
  1577. case 'f*d':
  1578. case 'df*': {
  1579. $op = 'b*';
  1580. break;
  1581. }
  1582. case 'CNZ': {
  1583. $op = 'W n';
  1584. break;
  1585. }
  1586. case 'CEO': {
  1587. $op = 'W* n';
  1588. break;
  1589. }
  1590. case 'n': {
  1591. $op = 'n';
  1592. break;
  1593. }
  1594. default: {
  1595. if (!empty($default)) {
  1596. $op = self::getPathPaintOperator($default, '');
  1597. } else {
  1598. $op = '';
  1599. }
  1600. }
  1601. }
  1602. return $op;
  1603. }
  1604. /**
  1605. * Get the product of two SVG tranformation matrices
  1606. * @param array $ta first SVG tranformation matrix
  1607. * @param array $tb second SVG tranformation matrix
  1608. * @return array transformation array
  1609. * @author Nicola Asuni
  1610. * @since 5.0.000 (2010-05-02)
  1611. * @public static
  1612. */
  1613. public static function getTransformationMatrixProduct($ta, $tb) {
  1614. $tm = array();
  1615. $tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]);
  1616. $tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]);
  1617. $tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]);
  1618. $tm[3] = ($ta[1] * $tb[2]) + ($ta[3] * $tb[3]);
  1619. $tm[4] = ($ta[0] * $tb[4]) + ($ta[2] * $tb[5]) + $ta[4];
  1620. $tm[5] = ($ta[1] * $tb[4]) + ($ta[3] * $tb[5]) + $ta[5];
  1621. return $tm;
  1622. }
  1623. /**
  1624. * Get the tranformation matrix from SVG transform attribute
  1625. * @param string $attribute transformation
  1626. * @return array of transformations
  1627. * @author Nicola Asuni
  1628. * @since 5.0.000 (2010-05-02)
  1629. * @public static
  1630. */
  1631. public static function getSVGTransformMatrix($attribute) {
  1632. // identity matrix
  1633. $tm = array(1, 0, 0, 1, 0, 0);
  1634. $transform = array();
  1635. if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0) {
  1636. foreach ($transform as $key => $data) {
  1637. if (!empty($data[2])) {
  1638. $a = 1;
  1639. $b = 0;
  1640. $c = 0;
  1641. $d = 1;
  1642. $e = 0;
  1643. $f = 0;
  1644. $regs = array();
  1645. switch ($data[1]) {
  1646. case 'matrix': {
  1647. if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  1648. $a = $regs[1];
  1649. $b = $regs[2];
  1650. $c = $regs[3];
  1651. $d = $regs[4];
  1652. $e = $regs[5];
  1653. $f = $regs[6];
  1654. }
  1655. break;
  1656. }
  1657. case 'translate': {
  1658. if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  1659. $e = $regs[1];
  1660. $f = $regs[2];
  1661. } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  1662. $e = $regs[1];
  1663. }
  1664. break;
  1665. }
  1666. case 'scale': {
  1667. if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  1668. $a = $regs[1];
  1669. $d = $regs[2];
  1670. } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  1671. $a = $regs[1];
  1672. $d = $a;
  1673. }
  1674. break;
  1675. }
  1676. case 'rotate': {
  1677. if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  1678. $ang = deg2rad($regs[1]);
  1679. $x = $regs[2];
  1680. $y = $regs[3];
  1681. $a = cos($ang);
  1682. $b = sin($ang);
  1683. $c = -$b;
  1684. $d = $a;
  1685. $e = ($x * (1 - $a)) - ($y * $c);
  1686. $f = ($y * (1 - $d)) - ($x * $b);
  1687. } elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
  1688. $ang = deg2rad($regs[1]);
  1689. $a = cos($ang);
  1690. $b = sin($ang);
  1691. $c = -$b;
  1692. $d = $a;
  1693. $e = 0;
  1694. $f = 0;
  1695. }
  1696. break;
  1697. }
  1698. case 'skewX': {
  1699. if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
  1700. $c = tan(deg2rad($regs[1]));
  1701. }
  1702. break;
  1703. }
  1704. case 'skewY': {
  1705. if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
  1706. $b = tan(deg2rad($regs[1]));
  1707. }
  1708. break;
  1709. }
  1710. }
  1711. $tm = self::getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f));
  1712. }
  1713. }
  1714. }
  1715. return $tm;
  1716. }
  1717. /**
  1718. * Returns the angle in radiants between two vectors
  1719. * @param int $x1 X coordinate of first vector point
  1720. * @param int $y1 Y coordinate of first vector point
  1721. * @param int $x2 X coordinate of second vector point
  1722. * @param int $y2 Y coordinate of second vector point
  1723. * @author Nicola Asuni
  1724. * @since 5.0.000 (2010-05-04)
  1725. * @public static
  1726. */
  1727. public static function getVectorsAngle($x1, $y1, $x2, $y2) {
  1728. $dprod = ($x1 * $x2) + ($y1 * $y2);
  1729. $dist1 = sqrt(($x1 * $x1) + ($y1 * $y1));
  1730. $dist2 = sqrt(($x2 * $x2) + ($y2 * $y2));
  1731. $angle = acos($dprod / ($dist1 * $dist2));
  1732. if (is_nan($angle)) {
  1733. $angle = M_PI;
  1734. }
  1735. if ((($x1 * $y2) - ($x2 * $y1)) < 0) {
  1736. $angle *= -1;
  1737. }
  1738. return $angle;
  1739. }
  1740. /**
  1741. * Split string by a regular expression.
  1742. * This is a wrapper for the preg_split function to avoid the bug: https://bugs.php.net/bug.php?id=45850
  1743. * @param string $pattern The regular expression pattern to search for without the modifiers, as a string.
  1744. * @param string $modifiers The modifiers part of the pattern,
  1745. * @param string $subject The input string.
  1746. * @param int $limit If specified, then only substrings up to limit are returned with the rest of the string being placed in the last substring. A limit of -1, 0 or NULL means "no limit" and, as is standard across PHP, you can use NULL to skip to the flags parameter.
  1747. * @param int $flags The flags as specified on the preg_split PHP function.
  1748. * @return array Returns an array containing substrings of subject split along boundaries matched by pattern.modifier
  1749. * @author Nicola Asuni
  1750. * @since 6.0.023
  1751. * @public static
  1752. */
  1753. public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $flags=NULL) {
  1754. // PHP 8.1 deprecates nulls for $limit and $flags
  1755. $limit = $limit === null ? -1 : $limit;
  1756. $flags = $flags === null ? 0 : $flags;
  1757. // the bug only happens on PHP 5.2 when using the u modifier
  1758. if ((strpos($modifiers, 'u') === FALSE) OR (count(preg_split('//u', "\n\t", -1, PREG_SPLIT_NO_EMPTY)) == 2)) {
  1759. return preg_split($pattern.$modifiers, $subject, $limit, $flags);
  1760. }
  1761. // preg_split is bugged - try alternative solution
  1762. $ret = array();
  1763. while (($nl = strpos($subject, "\n")) !== FALSE) {
  1764. $ret = array_merge($ret, preg_split($pattern.$modifiers, substr($subject, 0, $nl), $limit, $flags));
  1765. $ret[] = "\n";
  1766. $subject = substr($subject, ($nl + 1));
  1767. }
  1768. if (strlen($subject) > 0) {
  1769. $ret = array_merge($ret, preg_split($pattern.$modifiers, $subject, $limit, $flags));
  1770. }
  1771. return $ret;
  1772. }
  1773. /**
  1774. * Wrapper to use fopen only with local files
  1775. * @param string $filename Name of the file to open
  1776. * @param string $mode
  1777. * @return resource|false Returns a file pointer resource on success, or FALSE on error.
  1778. * @public static
  1779. */
  1780. public static function fopenLocal($filename, $mode) {
  1781. if (strpos($filename, '://') === false) {
  1782. $filename = 'file://'.$filename;
  1783. } elseif (stream_is_local($filename) !== true) {
  1784. return false;
  1785. }
  1786. return fopen($filename, $mode);
  1787. }
  1788. /**
  1789. * Check if the URL exist.
  1790. * @param string $url URL to check.
  1791. * @return bool Returns TRUE if the URL exists; FALSE otherwise.
  1792. * @public static
  1793. * @since 6.2.25
  1794. */
  1795. public static function url_exists($url) {
  1796. $crs = curl_init();
  1797. // encode query params in URL to get right response form the server
  1798. $url = self::encodeUrlQuery($url);
  1799. curl_setopt($crs, CURLOPT_URL, $url);
  1800. curl_setopt($crs, CURLOPT_NOBODY, true);
  1801. curl_setopt($crs, CURLOPT_FAILONERROR, true);
  1802. if ((ini_get('open_basedir') == '') && (!ini_get('safe_mode'))) {
  1803. curl_setopt($crs, CURLOPT_FOLLOWLOCATION, true);
  1804. }
  1805. curl_setopt($crs, CURLOPT_CONNECTTIMEOUT, 5);
  1806. curl_setopt($crs, CURLOPT_TIMEOUT, 30);
  1807. curl_setopt($crs, CURLOPT_SSL_VERIFYPEER, false);
  1808. curl_setopt($crs, CURLOPT_SSL_VERIFYHOST, false);
  1809. curl_setopt($crs, CURLOPT_USERAGENT, 'tc-lib-file');
  1810. curl_setopt($crs, CURLOPT_MAXREDIRS, 5);
  1811. if (defined('CURLOPT_PROTOCOLS')) {
  1812. curl_setopt($crs, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP | CURLPROTO_FTP | CURLPROTO_FTPS);
  1813. }
  1814. curl_exec($crs);
  1815. $code = curl_getinfo($crs, CURLINFO_HTTP_CODE);
  1816. curl_close($crs);
  1817. return ($code == 200);
  1818. }
  1819. /**
  1820. * Encode query params in URL
  1821. *
  1822. * @param string $url
  1823. * @return string
  1824. * @since 6.3.3 (2019-11-01)
  1825. * @public static
  1826. */
  1827. public static function encodeUrlQuery($url) {
  1828. $urlData = parse_url($url);
  1829. if (isset($urlData['query']) && $urlData['query']) {
  1830. $urlQueryData = array();
  1831. parse_str(urldecode($urlData['query']), $urlQueryData);
  1832. $updatedUrl = $urlData['scheme'] . '://' . $urlData['host'] . $urlData['path'] . '?' . http_build_query($urlQueryData);
  1833. } else {
  1834. $updatedUrl = $url;
  1835. }
  1836. return $updatedUrl;
  1837. }
  1838. /**
  1839. * Wrapper for file_exists.
  1840. * Checks whether a file or directory exists.
  1841. * Only allows some protocols and local files.
  1842. * @param string $filename Path to the file or directory.
  1843. * @return bool Returns TRUE if the file or directory specified by filename exists; FALSE otherwise.
  1844. * @public static
  1845. */
  1846. public static function file_exists($filename) {
  1847. if (preg_match('|^https?://|', $filename) == 1) {
  1848. return self::url_exists($filename);
  1849. }
  1850. if (strpos($filename, '://')) {
  1851. return false; // only support http and https wrappers for security reasons
  1852. }
  1853. return @file_exists($filename);
  1854. }
  1855. /**
  1856. * Reads entire file into a string.
  1857. * The file can be also an URL.
  1858. * @param string $file Name of the file or URL to read.
  1859. * @return string|false The function returns the read data or FALSE on failure.
  1860. * @author Nicola Asuni
  1861. * @since 6.0.025
  1862. * @public static
  1863. */
  1864. public static function fileGetContents($file) {
  1865. $alt = array($file);
  1866. //
  1867. if ((strlen($file) > 1)
  1868. && ($file[0] === '/')
  1869. && ($file[1] !== '/')
  1870. && !empty($_SERVER['DOCUMENT_ROOT'])
  1871. && ($_SERVER['DOCUMENT_ROOT'] !== '/')
  1872. ) {
  1873. $findroot = strpos($file, $_SERVER['DOCUMENT_ROOT']);
  1874. if (($findroot === false) || ($findroot > 1)) {
  1875. $alt[] = htmlspecialchars_decode(urldecode($_SERVER['DOCUMENT_ROOT'].$file));
  1876. }
  1877. }
  1878. //
  1879. $protocol = 'http';
  1880. if (!empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) {
  1881. $protocol .= 's';
  1882. }
  1883. //
  1884. $url = $file;
  1885. if (preg_match('%^//%', $url) && !empty($_SERVER['HTTP_HOST'])) {
  1886. $url = $protocol.':'.str_replace(' ', '%20', $url);
  1887. }
  1888. $url = htmlspecialchars_decode($url);
  1889. $alt[] = $url;
  1890. //
  1891. if (preg_match('%^(https?)://%', $url)
  1892. && empty($_SERVER['HTTP_HOST'])
  1893. && empty($_SERVER['DOCUMENT_ROOT'])
  1894. ) {
  1895. $urldata = parse_url($url);
  1896. if (empty($urldata['query'])) {
  1897. $host = $protocol.'://'.$_SERVER['HTTP_HOST'];
  1898. if (strpos($url, $host) === 0) {
  1899. // convert URL to full server path
  1900. $tmp = str_replace($host, $_SERVER['DOCUMENT_ROOT'], $url);
  1901. $alt[] = htmlspecialchars_decode(urldecode($tmp));
  1902. }
  1903. }
  1904. }
  1905. //
  1906. if (isset($_SERVER['SCRIPT_URI'])
  1907. && !preg_match('%^(https?|ftp)://%', $file)
  1908. && !preg_match('%^//%', $file)
  1909. ) {
  1910. $urldata = @parse_url($_SERVER['SCRIPT_URI']);
  1911. $alt[] = $urldata['scheme'].'://'.$urldata['host'].(($file[0] == '/') ? '' : '/').$file;
  1912. }
  1913. //
  1914. $alt = array_unique($alt);
  1915. foreach ($alt as $path) {
  1916. if (!self::file_exists($path)) {
  1917. continue;
  1918. }
  1919. $ret = @file_get_contents($path);
  1920. if ( $ret != false ) {
  1921. return $ret;
  1922. }
  1923. // try to use CURL for URLs
  1924. if (!ini_get('allow_url_fopen')
  1925. && function_exists('curl_init')
  1926. && preg_match('%^(https?|ftp)://%', $path)
  1927. ) {
  1928. // try to get remote file data using cURL
  1929. $crs = curl_init();
  1930. curl_setopt($crs, CURLOPT_URL, $path);
  1931. curl_setopt($crs, CURLOPT_BINARYTRANSFER, true);
  1932. curl_setopt($crs, CURLOPT_FAILONERROR, true);
  1933. curl_setopt($crs, CURLOPT_RETURNTRANSFER, true);
  1934. if ((ini_get('open_basedir') == '') && (!ini_get('safe_mode'))) {
  1935. curl_setopt($crs, CURLOPT_FOLLOWLOCATION, true);
  1936. }
  1937. curl_setopt($crs, CURLOPT_CONNECTTIMEOUT, 5);
  1938. curl_setopt($crs, CURLOPT_TIMEOUT, 30);
  1939. curl_setopt($crs, CURLOPT_SSL_VERIFYPEER, false);
  1940. curl_setopt($crs, CURLOPT_SSL_VERIFYHOST, false);
  1941. curl_setopt($crs, CURLOPT_USERAGENT, 'tc-lib-file');
  1942. curl_setopt($crs, CURLOPT_MAXREDIRS, 5);
  1943. if (defined('CURLOPT_PROTOCOLS')) {
  1944. curl_setopt($crs, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP | CURLPROTO_FTP | CURLPROTO_FTPS);
  1945. }
  1946. $ret = curl_exec($crs);
  1947. curl_close($crs);
  1948. if ($ret !== false) {
  1949. return $ret;
  1950. }
  1951. }
  1952. }
  1953. return false;
  1954. }
  1955. /**
  1956. * Get ULONG from string (Big Endian 32-bit unsigned integer).
  1957. * @param string $str string from where to extract value
  1958. * @param int $offset point from where to read the data
  1959. * @return int 32 bit value
  1960. * @author Nicola Asuni
  1961. * @since 5.2.000 (2010-06-02)
  1962. * @public static
  1963. */
  1964. public static function _getULONG($str, $offset) {
  1965. $v = unpack('Ni', substr($str, $offset, 4));
  1966. return $v['i'];
  1967. }
  1968. /**
  1969. * Get USHORT from string (Big Endian 16-bit unsigned integer).
  1970. * @param string $str string from where to extract value
  1971. * @param int $offset point from where to read the data
  1972. * @return int 16 bit value
  1973. * @author Nicola Asuni
  1974. * @since 5.2.000 (2010-06-02)
  1975. * @public static
  1976. */
  1977. public static function _getUSHORT($str, $offset) {
  1978. $v = unpack('ni', substr($str, $offset, 2));
  1979. return $v['i'];
  1980. }
  1981. /**
  1982. * Get SHORT from string (Big Endian 16-bit signed integer).
  1983. * @param string $str String from where to extract value.
  1984. * @param int $offset Point from where to read the data.
  1985. * @return int 16 bit value
  1986. * @author Nicola Asuni
  1987. * @since 5.2.000 (2010-06-02)
  1988. * @public static
  1989. */
  1990. public static function _getSHORT($str, $offset) {
  1991. $v = unpack('si', substr($str, $offset, 2));
  1992. return $v['i'];
  1993. }
  1994. /**
  1995. * Get FWORD from string (Big Endian 16-bit signed integer).
  1996. * @param string $str String from where to extract value.
  1997. * @param int $offset Point from where to read the data.
  1998. * @return int 16 bit value
  1999. * @author Nicola Asuni
  2000. * @since 5.9.123 (2011-09-30)
  2001. * @public static
  2002. */
  2003. public static function _getFWORD($str, $offset) {
  2004. $v = self::_getUSHORT($str, $offset);
  2005. if ($v > 0x7fff) {
  2006. $v -= 0x10000;
  2007. }
  2008. return $v;
  2009. }
  2010. /**
  2011. * Get UFWORD from string (Big Endian 16-bit unsigned integer).
  2012. * @param string $str string from where to extract value
  2013. * @param int $offset point from where to read the data
  2014. * @return int 16 bit value
  2015. * @author Nicola Asuni
  2016. * @since 5.9.123 (2011-09-30)
  2017. * @public static
  2018. */
  2019. public static function _getUFWORD($str, $offset) {
  2020. $v = self::_getUSHORT($str, $offset);
  2021. return $v;
  2022. }
  2023. /**
  2024. * Get FIXED from string (32-bit signed fixed-point number (16.16).
  2025. * @param string $str string from where to extract value
  2026. * @param int $offset point from where to read the data
  2027. * @return int 16 bit value
  2028. * @author Nicola Asuni
  2029. * @since 5.9.123 (2011-09-30)
  2030. * @public static
  2031. */
  2032. public static function _getFIXED($str, $offset) {
  2033. // mantissa
  2034. $m = self::_getFWORD($str, $offset);
  2035. // fraction
  2036. $f = self::_getUSHORT($str, ($offset + 2));
  2037. $v = floatval(''.$m.'.'.$f.'');
  2038. return $v;
  2039. }
  2040. /**
  2041. * Get BYTE from string (8-bit unsigned integer).
  2042. * @param string $str String from where to extract value.
  2043. * @param int $offset Point from where to read the data.
  2044. * @return int 8 bit value
  2045. * @author Nicola Asuni
  2046. * @since 5.2.000 (2010-06-02)
  2047. * @public static
  2048. */
  2049. public static function _getBYTE($str, $offset) {
  2050. $v = unpack('Ci', substr($str, $offset, 1));
  2051. return $v['i'];
  2052. }
  2053. /**
  2054. * Binary-safe and URL-safe file read.
  2055. * Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached.
  2056. * @param resource $handle
  2057. * @param int $length
  2058. * @return string|false Returns the read string or FALSE in case of error.
  2059. * @author Nicola Asuni
  2060. * @since 4.5.027 (2009-03-16)
  2061. * @public static
  2062. */
  2063. public static function rfread($handle, $length) {
  2064. $data = fread($handle, $length);
  2065. if ($data === false) {
  2066. return false;
  2067. }
  2068. $rest = ($length - strlen($data));
  2069. if (($rest > 0) && !feof($handle)) {
  2070. $data .= self::rfread($handle, $rest);
  2071. }
  2072. return $data;
  2073. }
  2074. /**
  2075. * Read a 4-byte (32 bit) integer from file.
  2076. * @param resource $f file resource.
  2077. * @return int 4-byte integer
  2078. * @public static
  2079. */
  2080. public static function _freadint($f) {
  2081. $a = unpack('Ni', fread($f, 4));
  2082. return $a['i'];
  2083. }
  2084. /**
  2085. * Array of page formats
  2086. * measures are calculated in this way: (inches * 72) or (millimeters * 72 / 25.4)
  2087. * @public static
  2088. *
  2089. * @var array<string,float[]>
  2090. */
  2091. public static $page_formats = array(
  2092. // ISO 216 A Series + 2 SIS 014711 extensions
  2093. 'A0' => array( 2383.937, 3370.394), // = ( 841 x 1189 ) mm = ( 33.11 x 46.81 ) in
  2094. 'A1' => array( 1683.780, 2383.937), // = ( 594 x 841 ) mm = ( 23.39 x 33.11 ) in
  2095. 'A2' => array( 1190.551, 1683.780), // = ( 420 x 594 ) mm = ( 16.54 x 23.39 ) in
  2096. 'A3' => array( 841.890, 1190.551), // = ( 297 x 420 ) mm = ( 11.69 x 16.54 ) in
  2097. 'A4' => array( 595.276, 841.890), // = ( 210 x 297 ) mm = ( 8.27 x 11.69 ) in
  2098. 'A5' => array( 419.528, 595.276), // = ( 148 x 210 ) mm = ( 5.83 x 8.27 ) in
  2099. 'A6' => array( 297.638, 419.528), // = ( 105 x 148 ) mm = ( 4.13 x 5.83 ) in
  2100. 'A7' => array( 209.764, 297.638), // = ( 74 x 105 ) mm = ( 2.91 x 4.13 ) in
  2101. 'A8' => array( 147.402, 209.764), // = ( 52 x 74 ) mm = ( 2.05 x 2.91 ) in
  2102. 'A9' => array( 104.882, 147.402), // = ( 37 x 52 ) mm = ( 1.46 x 2.05 ) in
  2103. 'A10' => array( 73.701, 104.882), // = ( 26 x 37 ) mm = ( 1.02 x 1.46 ) in
  2104. 'A11' => array( 51.024, 73.701), // = ( 18 x 26 ) mm = ( 0.71 x 1.02 ) in
  2105. 'A12' => array( 36.850, 51.024), // = ( 13 x 18 ) mm = ( 0.51 x 0.71 ) in
  2106. // ISO 216 B Series + 2 SIS 014711 extensions
  2107. 'B0' => array( 2834.646, 4008.189), // = ( 1000 x 1414 ) mm = ( 39.37 x 55.67 ) in
  2108. 'B1' => array( 2004.094, 2834.646), // = ( 707 x 1000 ) mm = ( 27.83 x 39.37 ) in
  2109. 'B2' => array( 1417.323, 2004.094), // = ( 500 x 707 ) mm = ( 19.69 x 27.83 ) in
  2110. 'B3' => array( 1000.630, 1417.323), // = ( 353 x 500 ) mm = ( 13.90 x 19.69 ) in
  2111. 'B4' => array( 708.661, 1000.630), // = ( 250 x 353 ) mm = ( 9.84 x 13.90 ) in
  2112. 'B5' => array( 498.898, 708.661), // = ( 176 x 250 ) mm = ( 6.93 x 9.84 ) in
  2113. 'B6' => array( 354.331, 498.898), // = ( 125 x 176 ) mm = ( 4.92 x 6.93 ) in
  2114. 'B7' => array( 249.449, 354.331), // = ( 88 x 125 ) mm = ( 3.46 x 4.92 ) in
  2115. 'B8' => array( 175.748, 249.449), // = ( 62 x 88 ) mm = ( 2.44 x 3.46 ) in
  2116. 'B9' => array( 124.724, 175.748), // = ( 44 x 62 ) mm = ( 1.73 x 2.44 ) in
  2117. 'B10' => array( 87.874, 124.724), // = ( 31 x 44 ) mm = ( 1.22 x 1.73 ) in
  2118. 'B11' => array( 62.362, 87.874), // = ( 22 x 31 ) mm = ( 0.87 x 1.22 ) in
  2119. 'B12' => array( 42.520, 62.362), // = ( 15 x 22 ) mm = ( 0.59 x 0.87 ) in
  2120. // ISO 216 C Series + 2 SIS 014711 extensions + 5 EXTENSION
  2121. 'C0' => array( 2599.370, 3676.535), // = ( 917 x 1297 ) mm = ( 36.10 x 51.06 ) in
  2122. 'C1' => array( 1836.850, 2599.370), // = ( 648 x 917 ) mm = ( 25.51 x 36.10 ) in
  2123. 'C2' => array( 1298.268, 1836.850), // = ( 458 x 648 ) mm = ( 18.03 x 25.51 ) in
  2124. 'C3' => array( 918.425, 1298.268), // = ( 324 x 458 ) mm = ( 12.76 x 18.03 ) in
  2125. 'C4' => array( 649.134, 918.425), // = ( 229 x 324 ) mm = ( 9.02 x 12.76 ) in
  2126. 'C5' => array( 459.213, 649.134), // = ( 162 x 229 ) mm = ( 6.38 x 9.02 ) in
  2127. 'C6' => array( 323.150, 459.213), // = ( 114 x 162 ) mm = ( 4.49 x 6.38 ) in
  2128. 'C7' => array( 229.606, 323.150), // = ( 81 x 114 ) mm = ( 3.19 x 4.49 ) in
  2129. 'C8' => array( 161.575, 229.606), // = ( 57 x 81 ) mm = ( 2.24 x 3.19 ) in
  2130. 'C9' => array( 113.386, 161.575), // = ( 40 x 57 ) mm = ( 1.57 x 2.24 ) in
  2131. 'C10' => array( 79.370, 113.386), // = ( 28 x 40 ) mm = ( 1.10 x 1.57 ) in
  2132. 'C11' => array( 56.693, 79.370), // = ( 20 x 28 ) mm = ( 0.79 x 1.10 ) in
  2133. 'C12' => array( 39.685, 56.693), // = ( 14 x 20 ) mm = ( 0.55 x 0.79 ) in
  2134. 'C76' => array( 229.606, 459.213), // = ( 81 x 162 ) mm = ( 3.19 x 6.38 ) in
  2135. 'DL' => array( 311.811, 623.622), // = ( 110 x 220 ) mm = ( 4.33 x 8.66 ) in
  2136. 'DLE' => array( 323.150, 637.795), // = ( 114 x 225 ) mm = ( 4.49 x 8.86 ) in
  2137. 'DLX' => array( 340.158, 666.142), // = ( 120 x 235 ) mm = ( 4.72 x 9.25 ) in
  2138. 'DLP' => array( 280.630, 595.276), // = ( 99 x 210 ) mm = ( 3.90 x 8.27 ) in (1/3 A4)
  2139. // SIS 014711 E Series
  2140. 'E0' => array( 2491.654, 3517.795), // = ( 879 x 1241 ) mm = ( 34.61 x 48.86 ) in
  2141. 'E1' => array( 1757.480, 2491.654), // = ( 620 x 879 ) mm = ( 24.41 x 34.61 ) in
  2142. 'E2' => array( 1247.244, 1757.480), // = ( 440 x 620 ) mm = ( 17.32 x 24.41 ) in
  2143. 'E3' => array( 878.740, 1247.244), // = ( 310 x 440 ) mm = ( 12.20 x 17.32 ) in
  2144. 'E4' => array( 623.622, 878.740), // = ( 220 x 310 ) mm = ( 8.66 x 12.20 ) in
  2145. 'E5' => array( 439.370, 623.622), // = ( 155 x 220 ) mm = ( 6.10 x 8.66 ) in
  2146. 'E6' => array( 311.811, 439.370), // = ( 110 x 155 ) mm = ( 4.33 x 6.10 ) in
  2147. 'E7' => array( 221.102, 311.811), // = ( 78 x 110 ) mm = ( 3.07 x 4.33 ) in
  2148. 'E8' => array( 155.906, 221.102), // = ( 55 x 78 ) mm = ( 2.17 x 3.07 ) in
  2149. 'E9' => array( 110.551, 155.906), // = ( 39 x 55 ) mm = ( 1.54 x 2.17 ) in
  2150. 'E10' => array( 76.535, 110.551), // = ( 27 x 39 ) mm = ( 1.06 x 1.54 ) in
  2151. 'E11' => array( 53.858, 76.535), // = ( 19 x 27 ) mm = ( 0.75 x 1.06 ) in
  2152. 'E12' => array( 36.850, 53.858), // = ( 13 x 19 ) mm = ( 0.51 x 0.75 ) in
  2153. // SIS 014711 G Series
  2154. 'G0' => array( 2715.591, 3838.110), // = ( 958 x 1354 ) mm = ( 37.72 x 53.31 ) in
  2155. 'G1' => array( 1919.055, 2715.591), // = ( 677 x 958 ) mm = ( 26.65 x 37.72 ) in
  2156. 'G2' => array( 1357.795, 1919.055), // = ( 479 x 677 ) mm = ( 18.86 x 26.65 ) in
  2157. 'G3' => array( 958.110, 1357.795), // = ( 338 x 479 ) mm = ( 13.31 x 18.86 ) in
  2158. 'G4' => array( 677.480, 958.110), // = ( 239 x 338 ) mm = ( 9.41 x 13.31 ) in
  2159. 'G5' => array( 479.055, 677.480), // = ( 169 x 239 ) mm = ( 6.65 x 9.41 ) in
  2160. 'G6' => array( 337.323, 479.055), // = ( 119 x 169 ) mm = ( 4.69 x 6.65 ) in
  2161. 'G7' => array( 238.110, 337.323), // = ( 84 x 119 ) mm = ( 3.31 x 4.69 ) in
  2162. 'G8' => array( 167.244, 238.110), // = ( 59 x 84 ) mm = ( 2.32 x 3.31 ) in
  2163. 'G9' => array( 119.055, 167.244), // = ( 42 x 59 ) mm = ( 1.65 x 2.32 ) in
  2164. 'G10' => array( 82.205, 119.055), // = ( 29 x 42 ) mm = ( 1.14 x 1.65 ) in
  2165. 'G11' => array( 59.528, 82.205), // = ( 21 x 29 ) mm = ( 0.83 x 1.14 ) in
  2166. 'G12' => array( 39.685, 59.528), // = ( 14 x 21 ) mm = ( 0.55 x 0.83 ) in
  2167. // ISO Press
  2168. 'RA0' => array( 2437.795, 3458.268), // = ( 860 x 1220 ) mm = ( 33.86 x 48.03 ) in
  2169. 'RA1' => array( 1729.134, 2437.795), // = ( 610 x 860 ) mm = ( 24.02 x 33.86 ) in
  2170. 'RA2' => array( 1218.898, 1729.134), // = ( 430 x 610 ) mm = ( 16.93 x 24.02 ) in
  2171. 'RA3' => array( 864.567, 1218.898), // = ( 305 x 430 ) mm = ( 12.01 x 16.93 ) in
  2172. 'RA4' => array( 609.449, 864.567), // = ( 215 x 305 ) mm = ( 8.46 x 12.01 ) in
  2173. 'SRA0' => array( 2551.181, 3628.346), // = ( 900 x 1280 ) mm = ( 35.43 x 50.39 ) in
  2174. 'SRA1' => array( 1814.173, 2551.181), // = ( 640 x 900 ) mm = ( 25.20 x 35.43 ) in
  2175. 'SRA2' => array( 1275.591, 1814.173), // = ( 450 x 640 ) mm = ( 17.72 x 25.20 ) in
  2176. 'SRA3' => array( 907.087, 1275.591), // = ( 320 x 450 ) mm = ( 12.60 x 17.72 ) in
  2177. 'SRA4' => array( 637.795, 907.087), // = ( 225 x 320 ) mm = ( 8.86 x 12.60 ) in
  2178. // German DIN 476
  2179. '4A0' => array( 4767.874, 6740.787), // = ( 1682 x 2378 ) mm = ( 66.22 x 93.62 ) in
  2180. '2A0' => array( 3370.394, 4767.874), // = ( 1189 x 1682 ) mm = ( 46.81 x 66.22 ) in
  2181. // Variations on the ISO Standard
  2182. 'A2_EXTRA' => array( 1261.417, 1754.646), // = ( 445 x 619 ) mm = ( 17.52 x 24.37 ) in
  2183. 'A3+' => array( 932.598, 1369.134), // = ( 329 x 483 ) mm = ( 12.95 x 19.02 ) in
  2184. 'A3_EXTRA' => array( 912.756, 1261.417), // = ( 322 x 445 ) mm = ( 12.68 x 17.52 ) in
  2185. 'A3_SUPER' => array( 864.567, 1440.000), // = ( 305 x 508 ) mm = ( 12.01 x 20.00 ) in
  2186. 'SUPER_A3' => array( 864.567, 1380.472), // = ( 305 x 487 ) mm = ( 12.01 x 19.17 ) in
  2187. 'A4_EXTRA' => array( 666.142, 912.756), // = ( 235 x 322 ) mm = ( 9.25 x 12.68 ) in
  2188. 'A4_SUPER' => array( 649.134, 912.756), // = ( 229 x 322 ) mm = ( 9.02 x 12.68 ) in
  2189. 'SUPER_A4' => array( 643.465, 1009.134), // = ( 227 x 356 ) mm = ( 8.94 x 14.02 ) in
  2190. 'A4_LONG' => array( 595.276, 986.457), // = ( 210 x 348 ) mm = ( 8.27 x 13.70 ) in
  2191. 'F4' => array( 595.276, 935.433), // = ( 210 x 330 ) mm = ( 8.27 x 12.99 ) in
  2192. 'SO_B5_EXTRA' => array( 572.598, 782.362), // = ( 202 x 276 ) mm = ( 7.95 x 10.87 ) in
  2193. 'A5_EXTRA' => array( 490.394, 666.142), // = ( 173 x 235 ) mm = ( 6.81 x 9.25 ) in
  2194. // ANSI Series
  2195. 'ANSI_E' => array( 2448.000, 3168.000), // = ( 864 x 1118 ) mm = ( 34.00 x 44.00 ) in
  2196. 'ANSI_D' => array( 1584.000, 2448.000), // = ( 559 x 864 ) mm = ( 22.00 x 34.00 ) in
  2197. 'ANSI_C' => array( 1224.000, 1584.000), // = ( 432 x 559 ) mm = ( 17.00 x 22.00 ) in
  2198. 'ANSI_B' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
  2199. 'ANSI_A' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
  2200. // Traditional 'Loose' North American Paper Sizes
  2201. 'USLEDGER' => array( 1224.000, 792.000), // = ( 432 x 279 ) mm = ( 17.00 x 11.00 ) in
  2202. 'LEDGER' => array( 1224.000, 792.000), // = ( 432 x 279 ) mm = ( 17.00 x 11.00 ) in
  2203. 'ORGANIZERK' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
  2204. 'BIBLE' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
  2205. 'USTABLOID' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
  2206. 'TABLOID' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
  2207. 'ORGANIZERM' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
  2208. 'USLETTER' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
  2209. 'LETTER' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
  2210. 'USLEGAL' => array( 612.000, 1008.000), // = ( 216 x 356 ) mm = ( 8.50 x 14.00 ) in
  2211. 'LEGAL' => array( 612.000, 1008.000), // = ( 216 x 356 ) mm = ( 8.50 x 14.00 ) in
  2212. 'GOVERNMENTLETTER' => array( 576.000, 756.000), // = ( 203 x 267 ) mm = ( 8.00 x 10.50 ) in
  2213. 'GLETTER' => array( 576.000, 756.000), // = ( 203 x 267 ) mm = ( 8.00 x 10.50 ) in
  2214. 'JUNIORLEGAL' => array( 576.000, 360.000), // = ( 203 x 127 ) mm = ( 8.00 x 5.00 ) in
  2215. 'JLEGAL' => array( 576.000, 360.000), // = ( 203 x 127 ) mm = ( 8.00 x 5.00 ) in
  2216. // Other North American Paper Sizes
  2217. 'QUADDEMY' => array( 2520.000, 3240.000), // = ( 889 x 1143 ) mm = ( 35.00 x 45.00 ) in
  2218. 'SUPER_B' => array( 936.000, 1368.000), // = ( 330 x 483 ) mm = ( 13.00 x 19.00 ) in
  2219. 'QUARTO' => array( 648.000, 792.000), // = ( 229 x 279 ) mm = ( 9.00 x 11.00 ) in
  2220. 'GOVERNMENTLEGAL' => array( 612.000, 936.000), // = ( 216 x 330 ) mm = ( 8.50 x 13.00 ) in
  2221. 'FOLIO' => array( 612.000, 936.000), // = ( 216 x 330 ) mm = ( 8.50 x 13.00 ) in
  2222. 'MONARCH' => array( 522.000, 756.000), // = ( 184 x 267 ) mm = ( 7.25 x 10.50 ) in
  2223. 'EXECUTIVE' => array( 522.000, 756.000), // = ( 184 x 267 ) mm = ( 7.25 x 10.50 ) in
  2224. 'ORGANIZERL' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in
  2225. 'STATEMENT' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in
  2226. 'MEMO' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in
  2227. 'FOOLSCAP' => array( 595.440, 936.000), // = ( 210 x 330 ) mm = ( 8.27 x 13.00 ) in
  2228. 'COMPACT' => array( 306.000, 486.000), // = ( 108 x 171 ) mm = ( 4.25 x 6.75 ) in
  2229. 'ORGANIZERJ' => array( 198.000, 360.000), // = ( 70 x 127 ) mm = ( 2.75 x 5.00 ) in
  2230. // Canadian standard CAN 2-9.60M
  2231. 'P1' => array( 1587.402, 2437.795), // = ( 560 x 860 ) mm = ( 22.05 x 33.86 ) in
  2232. 'P2' => array( 1218.898, 1587.402), // = ( 430 x 560 ) mm = ( 16.93 x 22.05 ) in
  2233. 'P3' => array( 793.701, 1218.898), // = ( 280 x 430 ) mm = ( 11.02 x 16.93 ) in
  2234. 'P4' => array( 609.449, 793.701), // = ( 215 x 280 ) mm = ( 8.46 x 11.02 ) in
  2235. 'P5' => array( 396.850, 609.449), // = ( 140 x 215 ) mm = ( 5.51 x 8.46 ) in
  2236. 'P6' => array( 303.307, 396.850), // = ( 107 x 140 ) mm = ( 4.21 x 5.51 ) in
  2237. // North American Architectural Sizes
  2238. 'ARCH_E' => array( 2592.000, 3456.000), // = ( 914 x 1219 ) mm = ( 36.00 x 48.00 ) in
  2239. 'ARCH_E1' => array( 2160.000, 3024.000), // = ( 762 x 1067 ) mm = ( 30.00 x 42.00 ) in
  2240. 'ARCH_D' => array( 1728.000, 2592.000), // = ( 610 x 914 ) mm = ( 24.00 x 36.00 ) in
  2241. 'BROADSHEET' => array( 1296.000, 1728.000), // = ( 457 x 610 ) mm = ( 18.00 x 24.00 ) in
  2242. 'ARCH_C' => array( 1296.000, 1728.000), // = ( 457 x 610 ) mm = ( 18.00 x 24.00 ) in
  2243. 'ARCH_B' => array( 864.000, 1296.000), // = ( 305 x 457 ) mm = ( 12.00 x 18.00 ) in
  2244. 'ARCH_A' => array( 648.000, 864.000), // = ( 229 x 305 ) mm = ( 9.00 x 12.00 ) in
  2245. // -- North American Envelope Sizes
  2246. // - Announcement Envelopes
  2247. 'ANNENV_A2' => array( 314.640, 414.000), // = ( 111 x 146 ) mm = ( 4.37 x 5.75 ) in
  2248. 'ANNENV_A6' => array( 342.000, 468.000), // = ( 121 x 165 ) mm = ( 4.75 x 6.50 ) in
  2249. 'ANNENV_A7' => array( 378.000, 522.000), // = ( 133 x 184 ) mm = ( 5.25 x 7.25 ) in
  2250. 'ANNENV_A8' => array( 396.000, 584.640), // = ( 140 x 206 ) mm = ( 5.50 x 8.12 ) in
  2251. 'ANNENV_A10' => array( 450.000, 692.640), // = ( 159 x 244 ) mm = ( 6.25 x 9.62 ) in
  2252. 'ANNENV_SLIM' => array( 278.640, 638.640), // = ( 98 x 225 ) mm = ( 3.87 x 8.87 ) in
  2253. // - Commercial Envelopes
  2254. 'COMMENV_N6_1/4' => array( 252.000, 432.000), // = ( 89 x 152 ) mm = ( 3.50 x 6.00 ) in
  2255. 'COMMENV_N6_3/4' => array( 260.640, 468.000), // = ( 92 x 165 ) mm = ( 3.62 x 6.50 ) in
  2256. 'COMMENV_N8' => array( 278.640, 540.000), // = ( 98 x 191 ) mm = ( 3.87 x 7.50 ) in
  2257. 'COMMENV_N9' => array( 278.640, 638.640), // = ( 98 x 225 ) mm = ( 3.87 x 8.87 ) in
  2258. 'COMMENV_N10' => array( 296.640, 684.000), // = ( 105 x 241 ) mm = ( 4.12 x 9.50 ) in
  2259. 'COMMENV_N11' => array( 324.000, 746.640), // = ( 114 x 263 ) mm = ( 4.50 x 10.37 ) in
  2260. 'COMMENV_N12' => array( 342.000, 792.000), // = ( 121 x 279 ) mm = ( 4.75 x 11.00 ) in
  2261. 'COMMENV_N14' => array( 360.000, 828.000), // = ( 127 x 292 ) mm = ( 5.00 x 11.50 ) in
  2262. // - Catalogue Envelopes
  2263. 'CATENV_N1' => array( 432.000, 648.000), // = ( 152 x 229 ) mm = ( 6.00 x 9.00 ) in
  2264. 'CATENV_N1_3/4' => array( 468.000, 684.000), // = ( 165 x 241 ) mm = ( 6.50 x 9.50 ) in
  2265. 'CATENV_N2' => array( 468.000, 720.000), // = ( 165 x 254 ) mm = ( 6.50 x 10.00 ) in
  2266. 'CATENV_N3' => array( 504.000, 720.000), // = ( 178 x 254 ) mm = ( 7.00 x 10.00 ) in
  2267. 'CATENV_N6' => array( 540.000, 756.000), // = ( 191 x 267 ) mm = ( 7.50 x 10.50 ) in
  2268. 'CATENV_N7' => array( 576.000, 792.000), // = ( 203 x 279 ) mm = ( 8.00 x 11.00 ) in
  2269. 'CATENV_N8' => array( 594.000, 810.000), // = ( 210 x 286 ) mm = ( 8.25 x 11.25 ) in
  2270. 'CATENV_N9_1/2' => array( 612.000, 756.000), // = ( 216 x 267 ) mm = ( 8.50 x 10.50 ) in
  2271. 'CATENV_N9_3/4' => array( 630.000, 810.000), // = ( 222 x 286 ) mm = ( 8.75 x 11.25 ) in
  2272. 'CATENV_N10_1/2' => array( 648.000, 864.000), // = ( 229 x 305 ) mm = ( 9.00 x 12.00 ) in
  2273. 'CATENV_N12_1/2' => array( 684.000, 900.000), // = ( 241 x 318 ) mm = ( 9.50 x 12.50 ) in
  2274. 'CATENV_N13_1/2' => array( 720.000, 936.000), // = ( 254 x 330 ) mm = ( 10.00 x 13.00 ) in
  2275. 'CATENV_N14_1/4' => array( 810.000, 882.000), // = ( 286 x 311 ) mm = ( 11.25 x 12.25 ) in
  2276. 'CATENV_N14_1/2' => array( 828.000, 1044.000), // = ( 292 x 368 ) mm = ( 11.50 x 14.50 ) in
  2277. // Japanese (JIS P 0138-61) Standard B-Series
  2278. 'JIS_B0' => array( 2919.685, 4127.244), // = ( 1030 x 1456 ) mm = ( 40.55 x 57.32 ) in
  2279. 'JIS_B1' => array( 2063.622, 2919.685), // = ( 728 x 1030 ) mm = ( 28.66 x 40.55 ) in
  2280. 'JIS_B2' => array( 1459.843, 2063.622), // = ( 515 x 728 ) mm = ( 20.28 x 28.66 ) in
  2281. 'JIS_B3' => array( 1031.811, 1459.843), // = ( 364 x 515 ) mm = ( 14.33 x 20.28 ) in
  2282. 'JIS_B4' => array( 728.504, 1031.811), // = ( 257 x 364 ) mm = ( 10.12 x 14.33 ) in
  2283. 'JIS_B5' => array( 515.906, 728.504), // = ( 182 x 257 ) mm = ( 7.17 x 10.12 ) in
  2284. 'JIS_B6' => array( 362.835, 515.906), // = ( 128 x 182 ) mm = ( 5.04 x 7.17 ) in
  2285. 'JIS_B7' => array( 257.953, 362.835), // = ( 91 x 128 ) mm = ( 3.58 x 5.04 ) in
  2286. 'JIS_B8' => array( 181.417, 257.953), // = ( 64 x 91 ) mm = ( 2.52 x 3.58 ) in
  2287. 'JIS_B9' => array( 127.559, 181.417), // = ( 45 x 64 ) mm = ( 1.77 x 2.52 ) in
  2288. 'JIS_B10' => array( 90.709, 127.559), // = ( 32 x 45 ) mm = ( 1.26 x 1.77 ) in
  2289. 'JIS_B11' => array( 62.362, 90.709), // = ( 22 x 32 ) mm = ( 0.87 x 1.26 ) in
  2290. 'JIS_B12' => array( 45.354, 62.362), // = ( 16 x 22 ) mm = ( 0.63 x 0.87 ) in
  2291. // PA Series
  2292. 'PA0' => array( 2381.102, 3174.803), // = ( 840 x 1120 ) mm = ( 33.07 x 44.09 ) in
  2293. 'PA1' => array( 1587.402, 2381.102), // = ( 560 x 840 ) mm = ( 22.05 x 33.07 ) in
  2294. 'PA2' => array( 1190.551, 1587.402), // = ( 420 x 560 ) mm = ( 16.54 x 22.05 ) in
  2295. 'PA3' => array( 793.701, 1190.551), // = ( 280 x 420 ) mm = ( 11.02 x 16.54 ) in
  2296. 'PA4' => array( 595.276, 793.701), // = ( 210 x 280 ) mm = ( 8.27 x 11.02 ) in
  2297. 'PA5' => array( 396.850, 595.276), // = ( 140 x 210 ) mm = ( 5.51 x 8.27 ) in
  2298. 'PA6' => array( 297.638, 396.850), // = ( 105 x 140 ) mm = ( 4.13 x 5.51 ) in
  2299. 'PA7' => array( 198.425, 297.638), // = ( 70 x 105 ) mm = ( 2.76 x 4.13 ) in
  2300. 'PA8' => array( 147.402, 198.425), // = ( 52 x 70 ) mm = ( 2.05 x 2.76 ) in
  2301. 'PA9' => array( 99.213, 147.402), // = ( 35 x 52 ) mm = ( 1.38 x 2.05 ) in
  2302. 'PA10' => array( 73.701, 99.213), // = ( 26 x 35 ) mm = ( 1.02 x 1.38 ) in
  2303. // Standard Photographic Print Sizes
  2304. 'PASSPORT_PHOTO' => array( 99.213, 127.559), // = ( 35 x 45 ) mm = ( 1.38 x 1.77 ) in
  2305. 'E' => array( 233.858, 340.157), // = ( 82 x 120 ) mm = ( 3.25 x 4.72 ) in
  2306. 'L' => array( 252.283, 360.000), // = ( 89 x 127 ) mm = ( 3.50 x 5.00 ) in
  2307. '3R' => array( 252.283, 360.000), // = ( 89 x 127 ) mm = ( 3.50 x 5.00 ) in
  2308. 'KG' => array( 289.134, 430.866), // = ( 102 x 152 ) mm = ( 4.02 x 5.98 ) in
  2309. '4R' => array( 289.134, 430.866), // = ( 102 x 152 ) mm = ( 4.02 x 5.98 ) in
  2310. '4D' => array( 340.157, 430.866), // = ( 120 x 152 ) mm = ( 4.72 x 5.98 ) in
  2311. '2L' => array( 360.000, 504.567), // = ( 127 x 178 ) mm = ( 5.00 x 7.01 ) in
  2312. '5R' => array( 360.000, 504.567), // = ( 127 x 178 ) mm = ( 5.00 x 7.01 ) in
  2313. '8P' => array( 430.866, 575.433), // = ( 152 x 203 ) mm = ( 5.98 x 7.99 ) in
  2314. '6R' => array( 430.866, 575.433), // = ( 152 x 203 ) mm = ( 5.98 x 7.99 ) in
  2315. '6P' => array( 575.433, 720.000), // = ( 203 x 254 ) mm = ( 7.99 x 10.00 ) in
  2316. '8R' => array( 575.433, 720.000), // = ( 203 x 254 ) mm = ( 7.99 x 10.00 ) in
  2317. '6PW' => array( 575.433, 864.567), // = ( 203 x 305 ) mm = ( 7.99 x 12.01 ) in
  2318. 'S8R' => array( 575.433, 864.567), // = ( 203 x 305 ) mm = ( 7.99 x 12.01 ) in
  2319. '4P' => array( 720.000, 864.567), // = ( 254 x 305 ) mm = ( 10.00 x 12.01 ) in
  2320. '10R' => array( 720.000, 864.567), // = ( 254 x 305 ) mm = ( 10.00 x 12.01 ) in
  2321. '4PW' => array( 720.000, 1080.000), // = ( 254 x 381 ) mm = ( 10.00 x 15.00 ) in
  2322. 'S10R' => array( 720.000, 1080.000), // = ( 254 x 381 ) mm = ( 10.00 x 15.00 ) in
  2323. '11R' => array( 790.866, 1009.134), // = ( 279 x 356 ) mm = ( 10.98 x 14.02 ) in
  2324. 'S11R' => array( 790.866, 1224.567), // = ( 279 x 432 ) mm = ( 10.98 x 17.01 ) in
  2325. '12R' => array( 864.567, 1080.000), // = ( 305 x 381 ) mm = ( 12.01 x 15.00 ) in
  2326. 'S12R' => array( 864.567, 1292.598), // = ( 305 x 456 ) mm = ( 12.01 x 17.95 ) in
  2327. // Common Newspaper Sizes
  2328. 'NEWSPAPER_BROADSHEET' => array( 2125.984, 1700.787), // = ( 750 x 600 ) mm = ( 29.53 x 23.62 ) in
  2329. 'NEWSPAPER_BERLINER' => array( 1332.283, 892.913), // = ( 470 x 315 ) mm = ( 18.50 x 12.40 ) in
  2330. 'NEWSPAPER_TABLOID' => array( 1218.898, 793.701), // = ( 430 x 280 ) mm = ( 16.93 x 11.02 ) in
  2331. 'NEWSPAPER_COMPACT' => array( 1218.898, 793.701), // = ( 430 x 280 ) mm = ( 16.93 x 11.02 ) in
  2332. // Business Cards
  2333. 'CREDIT_CARD' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in
  2334. 'BUSINESS_CARD' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in
  2335. 'BUSINESS_CARD_ISO7810' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in
  2336. 'BUSINESS_CARD_ISO216' => array( 147.402, 209.764), // = ( 52 x 74 ) mm = ( 2.05 x 2.91 ) in
  2337. 'BUSINESS_CARD_IT' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
  2338. 'BUSINESS_CARD_UK' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
  2339. 'BUSINESS_CARD_FR' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
  2340. 'BUSINESS_CARD_DE' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
  2341. 'BUSINESS_CARD_ES' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
  2342. 'BUSINESS_CARD_CA' => array( 144.567, 252.283), // = ( 51 x 89 ) mm = ( 2.01 x 3.50 ) in
  2343. 'BUSINESS_CARD_US' => array( 144.567, 252.283), // = ( 51 x 89 ) mm = ( 2.01 x 3.50 ) in
  2344. 'BUSINESS_CARD_JP' => array( 155.906, 257.953), // = ( 55 x 91 ) mm = ( 2.17 x 3.58 ) in
  2345. 'BUSINESS_CARD_HK' => array( 153.071, 255.118), // = ( 54 x 90 ) mm = ( 2.13 x 3.54 ) in
  2346. 'BUSINESS_CARD_AU' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in
  2347. 'BUSINESS_CARD_DK' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in
  2348. 'BUSINESS_CARD_SE' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in
  2349. 'BUSINESS_CARD_RU' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
  2350. 'BUSINESS_CARD_CZ' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
  2351. 'BUSINESS_CARD_FI' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
  2352. 'BUSINESS_CARD_HU' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
  2353. 'BUSINESS_CARD_IL' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
  2354. // Billboards
  2355. '4SHEET' => array( 2880.000, 4320.000), // = ( 1016 x 1524 ) mm = ( 40.00 x 60.00 ) in
  2356. '6SHEET' => array( 3401.575, 5102.362), // = ( 1200 x 1800 ) mm = ( 47.24 x 70.87 ) in
  2357. '12SHEET' => array( 8640.000, 4320.000), // = ( 3048 x 1524 ) mm = (120.00 x 60.00 ) in
  2358. '16SHEET' => array( 5760.000, 8640.000), // = ( 2032 x 3048 ) mm = ( 80.00 x 120.00) in
  2359. '32SHEET' => array(11520.000, 8640.000), // = ( 4064 x 3048 ) mm = (160.00 x 120.00) in
  2360. '48SHEET' => array(17280.000, 8640.000), // = ( 6096 x 3048 ) mm = (240.00 x 120.00) in
  2361. '64SHEET' => array(23040.000, 8640.000), // = ( 8128 x 3048 ) mm = (320.00 x 120.00) in
  2362. '96SHEET' => array(34560.000, 8640.000), // = (12192 x 3048 ) mm = (480.00 x 120.00) in
  2363. // -- Old European Sizes
  2364. // - Old Imperial English Sizes
  2365. 'EN_EMPEROR' => array( 3456.000, 5184.000), // = ( 1219 x 1829 ) mm = ( 48.00 x 72.00 ) in
  2366. 'EN_ANTIQUARIAN' => array( 2232.000, 3816.000), // = ( 787 x 1346 ) mm = ( 31.00 x 53.00 ) in
  2367. 'EN_GRAND_EAGLE' => array( 2070.000, 3024.000), // = ( 730 x 1067 ) mm = ( 28.75 x 42.00 ) in
  2368. 'EN_DOUBLE_ELEPHANT' => array( 1926.000, 2880.000), // = ( 679 x 1016 ) mm = ( 26.75 x 40.00 ) in
  2369. 'EN_ATLAS' => array( 1872.000, 2448.000), // = ( 660 x 864 ) mm = ( 26.00 x 34.00 ) in
  2370. 'EN_COLOMBIER' => array( 1692.000, 2484.000), // = ( 597 x 876 ) mm = ( 23.50 x 34.50 ) in
  2371. 'EN_ELEPHANT' => array( 1656.000, 2016.000), // = ( 584 x 711 ) mm = ( 23.00 x 28.00 ) in
  2372. 'EN_DOUBLE_DEMY' => array( 1620.000, 2556.000), // = ( 572 x 902 ) mm = ( 22.50 x 35.50 ) in
  2373. 'EN_IMPERIAL' => array( 1584.000, 2160.000), // = ( 559 x 762 ) mm = ( 22.00 x 30.00 ) in
  2374. 'EN_PRINCESS' => array( 1548.000, 2016.000), // = ( 546 x 711 ) mm = ( 21.50 x 28.00 ) in
  2375. 'EN_CARTRIDGE' => array( 1512.000, 1872.000), // = ( 533 x 660 ) mm = ( 21.00 x 26.00 ) in
  2376. 'EN_DOUBLE_LARGE_POST' => array( 1512.000, 2376.000), // = ( 533 x 838 ) mm = ( 21.00 x 33.00 ) in
  2377. 'EN_ROYAL' => array( 1440.000, 1800.000), // = ( 508 x 635 ) mm = ( 20.00 x 25.00 ) in
  2378. 'EN_SHEET' => array( 1404.000, 1692.000), // = ( 495 x 597 ) mm = ( 19.50 x 23.50 ) in
  2379. 'EN_HALF_POST' => array( 1404.000, 1692.000), // = ( 495 x 597 ) mm = ( 19.50 x 23.50 ) in
  2380. 'EN_SUPER_ROYAL' => array( 1368.000, 1944.000), // = ( 483 x 686 ) mm = ( 19.00 x 27.00 ) in
  2381. 'EN_DOUBLE_POST' => array( 1368.000, 2196.000), // = ( 483 x 775 ) mm = ( 19.00 x 30.50 ) in
  2382. 'EN_MEDIUM' => array( 1260.000, 1656.000), // = ( 445 x 584 ) mm = ( 17.50 x 23.00 ) in
  2383. 'EN_DEMY' => array( 1260.000, 1620.000), // = ( 445 x 572 ) mm = ( 17.50 x 22.50 ) in
  2384. 'EN_LARGE_POST' => array( 1188.000, 1512.000), // = ( 419 x 533 ) mm = ( 16.50 x 21.00 ) in
  2385. 'EN_COPY_DRAUGHT' => array( 1152.000, 1440.000), // = ( 406 x 508 ) mm = ( 16.00 x 20.00 ) in
  2386. 'EN_POST' => array( 1116.000, 1386.000), // = ( 394 x 489 ) mm = ( 15.50 x 19.25 ) in
  2387. 'EN_CROWN' => array( 1080.000, 1440.000), // = ( 381 x 508 ) mm = ( 15.00 x 20.00 ) in
  2388. 'EN_PINCHED_POST' => array( 1062.000, 1332.000), // = ( 375 x 470 ) mm = ( 14.75 x 18.50 ) in
  2389. 'EN_BRIEF' => array( 972.000, 1152.000), // = ( 343 x 406 ) mm = ( 13.50 x 16.00 ) in
  2390. 'EN_FOOLSCAP' => array( 972.000, 1224.000), // = ( 343 x 432 ) mm = ( 13.50 x 17.00 ) in
  2391. 'EN_SMALL_FOOLSCAP' => array( 954.000, 1188.000), // = ( 337 x 419 ) mm = ( 13.25 x 16.50 ) in
  2392. 'EN_POTT' => array( 900.000, 1080.000), // = ( 318 x 381 ) mm = ( 12.50 x 15.00 ) in
  2393. // - Old Imperial Belgian Sizes
  2394. 'BE_GRAND_AIGLE' => array( 1984.252, 2948.031), // = ( 700 x 1040 ) mm = ( 27.56 x 40.94 ) in
  2395. 'BE_COLOMBIER' => array( 1757.480, 2409.449), // = ( 620 x 850 ) mm = ( 24.41 x 33.46 ) in
  2396. 'BE_DOUBLE_CARRE' => array( 1757.480, 2607.874), // = ( 620 x 920 ) mm = ( 24.41 x 36.22 ) in
  2397. 'BE_ELEPHANT' => array( 1746.142, 2182.677), // = ( 616 x 770 ) mm = ( 24.25 x 30.31 ) in
  2398. 'BE_PETIT_AIGLE' => array( 1700.787, 2381.102), // = ( 600 x 840 ) mm = ( 23.62 x 33.07 ) in
  2399. 'BE_GRAND_JESUS' => array( 1559.055, 2069.291), // = ( 550 x 730 ) mm = ( 21.65 x 28.74 ) in
  2400. 'BE_JESUS' => array( 1530.709, 2069.291), // = ( 540 x 730 ) mm = ( 21.26 x 28.74 ) in
  2401. 'BE_RAISIN' => array( 1417.323, 1842.520), // = ( 500 x 650 ) mm = ( 19.69 x 25.59 ) in
  2402. 'BE_GRAND_MEDIAN' => array( 1303.937, 1714.961), // = ( 460 x 605 ) mm = ( 18.11 x 23.82 ) in
  2403. 'BE_DOUBLE_POSTE' => array( 1233.071, 1601.575), // = ( 435 x 565 ) mm = ( 17.13 x 22.24 ) in
  2404. 'BE_COQUILLE' => array( 1218.898, 1587.402), // = ( 430 x 560 ) mm = ( 16.93 x 22.05 ) in
  2405. 'BE_PETIT_MEDIAN' => array( 1176.378, 1502.362), // = ( 415 x 530 ) mm = ( 16.34 x 20.87 ) in
  2406. 'BE_RUCHE' => array( 1020.472, 1303.937), // = ( 360 x 460 ) mm = ( 14.17 x 18.11 ) in
  2407. 'BE_PROPATRIA' => array( 977.953, 1218.898), // = ( 345 x 430 ) mm = ( 13.58 x 16.93 ) in
  2408. 'BE_LYS' => array( 898.583, 1125.354), // = ( 317 x 397 ) mm = ( 12.48 x 15.63 ) in
  2409. 'BE_POT' => array( 870.236, 1088.504), // = ( 307 x 384 ) mm = ( 12.09 x 15.12 ) in
  2410. 'BE_ROSETTE' => array( 765.354, 983.622), // = ( 270 x 347 ) mm = ( 10.63 x 13.66 ) in
  2411. // - Old Imperial French Sizes
  2412. 'FR_UNIVERS' => array( 2834.646, 3685.039), // = ( 1000 x 1300 ) mm = ( 39.37 x 51.18 ) in
  2413. 'FR_DOUBLE_COLOMBIER' => array( 2551.181, 3571.654), // = ( 900 x 1260 ) mm = ( 35.43 x 49.61 ) in
  2414. 'FR_GRANDE_MONDE' => array( 2551.181, 3571.654), // = ( 900 x 1260 ) mm = ( 35.43 x 49.61 ) in
  2415. 'FR_DOUBLE_SOLEIL' => array( 2267.717, 3401.575), // = ( 800 x 1200 ) mm = ( 31.50 x 47.24 ) in
  2416. 'FR_DOUBLE_JESUS' => array( 2154.331, 3174.803), // = ( 760 x 1120 ) mm = ( 29.92 x 44.09 ) in
  2417. 'FR_GRAND_AIGLE' => array( 2125.984, 3004.724), // = ( 750 x 1060 ) mm = ( 29.53 x 41.73 ) in
  2418. 'FR_PETIT_AIGLE' => array( 1984.252, 2664.567), // = ( 700 x 940 ) mm = ( 27.56 x 37.01 ) in
  2419. 'FR_DOUBLE_RAISIN' => array( 1842.520, 2834.646), // = ( 650 x 1000 ) mm = ( 25.59 x 39.37 ) in
  2420. 'FR_JOURNAL' => array( 1842.520, 2664.567), // = ( 650 x 940 ) mm = ( 25.59 x 37.01 ) in
  2421. 'FR_COLOMBIER_AFFICHE' => array( 1785.827, 2551.181), // = ( 630 x 900 ) mm = ( 24.80 x 35.43 ) in
  2422. 'FR_DOUBLE_CAVALIER' => array( 1757.480, 2607.874), // = ( 620 x 920 ) mm = ( 24.41 x 36.22 ) in
  2423. 'FR_CLOCHE' => array( 1700.787, 2267.717), // = ( 600 x 800 ) mm = ( 23.62 x 31.50 ) in
  2424. 'FR_SOLEIL' => array( 1700.787, 2267.717), // = ( 600 x 800 ) mm = ( 23.62 x 31.50 ) in
  2425. 'FR_DOUBLE_CARRE' => array( 1587.402, 2551.181), // = ( 560 x 900 ) mm = ( 22.05 x 35.43 ) in
  2426. 'FR_DOUBLE_COQUILLE' => array( 1587.402, 2494.488), // = ( 560 x 880 ) mm = ( 22.05 x 34.65 ) in
  2427. 'FR_JESUS' => array( 1587.402, 2154.331), // = ( 560 x 760 ) mm = ( 22.05 x 29.92 ) in
  2428. 'FR_RAISIN' => array( 1417.323, 1842.520), // = ( 500 x 650 ) mm = ( 19.69 x 25.59 ) in
  2429. 'FR_CAVALIER' => array( 1303.937, 1757.480), // = ( 460 x 620 ) mm = ( 18.11 x 24.41 ) in
  2430. 'FR_DOUBLE_COURONNE' => array( 1303.937, 2040.945), // = ( 460 x 720 ) mm = ( 18.11 x 28.35 ) in
  2431. 'FR_CARRE' => array( 1275.591, 1587.402), // = ( 450 x 560 ) mm = ( 17.72 x 22.05 ) in
  2432. 'FR_COQUILLE' => array( 1247.244, 1587.402), // = ( 440 x 560 ) mm = ( 17.32 x 22.05 ) in
  2433. 'FR_DOUBLE_TELLIERE' => array( 1247.244, 1927.559), // = ( 440 x 680 ) mm = ( 17.32 x 26.77 ) in
  2434. 'FR_DOUBLE_CLOCHE' => array( 1133.858, 1700.787), // = ( 400 x 600 ) mm = ( 15.75 x 23.62 ) in
  2435. 'FR_DOUBLE_POT' => array( 1133.858, 1757.480), // = ( 400 x 620 ) mm = ( 15.75 x 24.41 ) in
  2436. 'FR_ECU' => array( 1133.858, 1474.016), // = ( 400 x 520 ) mm = ( 15.75 x 20.47 ) in
  2437. 'FR_COURONNE' => array( 1020.472, 1303.937), // = ( 360 x 460 ) mm = ( 14.17 x 18.11 ) in
  2438. 'FR_TELLIERE' => array( 963.780, 1247.244), // = ( 340 x 440 ) mm = ( 13.39 x 17.32 ) in
  2439. 'FR_POT' => array( 878.740, 1133.858), // = ( 310 x 400 ) mm = ( 12.20 x 15.75 ) in
  2440. );
  2441. /**
  2442. * Get page dimensions from format name.
  2443. * @param mixed $format The format name @see self::$page_format<ul>
  2444. * @return array containing page width and height in points
  2445. * @since 5.0.010 (2010-05-17)
  2446. * @public static
  2447. */
  2448. public static function getPageSizeFromFormat($format) {
  2449. if (isset(self::$page_formats[$format])) {
  2450. return self::$page_formats[$format];
  2451. }
  2452. return self::$page_formats['A4'];
  2453. }
  2454. /**
  2455. * Set page boundaries.
  2456. * @param int $page page number
  2457. * @param string $type valid values are: <ul><li>'MediaBox' : the boundaries of the physical medium on which the page shall be displayed or printed;</li><li>'CropBox' : the visible region of default user space;</li><li>'BleedBox' : the region to which the contents of the page shall be clipped when output in a production environment;</li><li>'TrimBox' : the intended dimensions of the finished page after trimming;</li><li>'ArtBox' : the page's meaningful content (including potential white space).</li></ul>
  2458. * @param float $llx lower-left x coordinate in user units.
  2459. * @param float $lly lower-left y coordinate in user units.
  2460. * @param float $urx upper-right x coordinate in user units.
  2461. * @param float $ury upper-right y coordinate in user units.
  2462. * @param boolean $points If true uses user units as unit of measure, otherwise uses PDF points.
  2463. * @param float $k Scale factor (number of points in user unit).
  2464. * @param array $pagedim Array of page dimensions.
  2465. * @return array pagedim array of page dimensions.
  2466. * @since 5.0.010 (2010-05-17)
  2467. * @public static
  2468. */
  2469. public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points, $k, $pagedim=array()) {
  2470. if (!isset($pagedim[$page])) {
  2471. // initialize array
  2472. $pagedim[$page] = array();
  2473. }
  2474. if (!in_array($type, self::$pageboxes)) {
  2475. return;
  2476. }
  2477. if ($points) {
  2478. $k = 1;
  2479. }
  2480. $pagedim[$page][$type]['llx'] = ($llx * $k);
  2481. $pagedim[$page][$type]['lly'] = ($lly * $k);
  2482. $pagedim[$page][$type]['urx'] = ($urx * $k);
  2483. $pagedim[$page][$type]['ury'] = ($ury * $k);
  2484. return $pagedim;
  2485. }
  2486. /**
  2487. * Swap X and Y coordinates of page boxes (change page boxes orientation).
  2488. * @param int $page page number
  2489. * @param array $pagedim Array of page dimensions.
  2490. * @return array pagedim array of page dimensions.
  2491. * @since 5.0.010 (2010-05-17)
  2492. * @public static
  2493. */
  2494. public static function swapPageBoxCoordinates($page, $pagedim) {
  2495. foreach (self::$pageboxes as $type) {
  2496. // swap X and Y coordinates
  2497. if (isset($pagedim[$page][$type])) {
  2498. $tmp = $pagedim[$page][$type]['llx'];
  2499. $pagedim[$page][$type]['llx'] = $pagedim[$page][$type]['lly'];
  2500. $pagedim[$page][$type]['lly'] = $tmp;
  2501. $tmp = $pagedim[$page][$type]['urx'];
  2502. $pagedim[$page][$type]['urx'] = $pagedim[$page][$type]['ury'];
  2503. $pagedim[$page][$type]['ury'] = $tmp;
  2504. }
  2505. }
  2506. return $pagedim;
  2507. }
  2508. /**
  2509. * Get the canonical page layout mode.
  2510. * @param string $layout The page layout. Possible values are:<ul><li>SinglePage Display one page at a time</li><li>OneColumn Display the pages in one column</li><li>TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left</li><li>TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right</li><li>TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left</li><li>TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right</li></ul>
  2511. * @return string Canonical page layout name.
  2512. * @public static
  2513. */
  2514. public static function getPageLayoutMode($layout='SinglePage') {
  2515. switch ($layout) {
  2516. case 'default':
  2517. case 'single':
  2518. case 'SinglePage': {
  2519. $layout_mode = 'SinglePage';
  2520. break;
  2521. }
  2522. case 'continuous':
  2523. case 'OneColumn': {
  2524. $layout_mode = 'OneColumn';
  2525. break;
  2526. }
  2527. case 'two':
  2528. case 'TwoColumnLeft': {
  2529. $layout_mode = 'TwoColumnLeft';
  2530. break;
  2531. }
  2532. case 'TwoColumnRight': {
  2533. $layout_mode = 'TwoColumnRight';
  2534. break;
  2535. }
  2536. case 'TwoPageLeft': {
  2537. $layout_mode = 'TwoPageLeft';
  2538. break;
  2539. }
  2540. case 'TwoPageRight': {
  2541. $layout_mode = 'TwoPageRight';
  2542. break;
  2543. }
  2544. default: {
  2545. $layout_mode = 'SinglePage';
  2546. }
  2547. }
  2548. return $layout_mode;
  2549. }
  2550. /**
  2551. * Get the canonical page layout mode.
  2552. * @param string $mode A name object specifying how the document should be displayed when opened:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible</li><li>UseOC (PDF 1.5) Optional content group panel visible</li><li>UseAttachments (PDF 1.6) Attachments panel visible</li></ul>
  2553. * @return string Canonical page mode name.
  2554. * @public static
  2555. */
  2556. public static function getPageMode($mode='UseNone') {
  2557. switch ($mode) {
  2558. case 'UseNone': {
  2559. $page_mode = 'UseNone';
  2560. break;
  2561. }
  2562. case 'UseOutlines': {
  2563. $page_mode = 'UseOutlines';
  2564. break;
  2565. }
  2566. case 'UseThumbs': {
  2567. $page_mode = 'UseThumbs';
  2568. break;
  2569. }
  2570. case 'FullScreen': {
  2571. $page_mode = 'FullScreen';
  2572. break;
  2573. }
  2574. case 'UseOC': {
  2575. $page_mode = 'UseOC';
  2576. break;
  2577. }
  2578. case '': {
  2579. $page_mode = 'UseAttachments';
  2580. break;
  2581. }
  2582. default: {
  2583. $page_mode = 'UseNone';
  2584. }
  2585. }
  2586. return $page_mode;
  2587. }
  2588. } // END OF TCPDF_STATIC CLASS
  2589. //============================================================+
  2590. // END OF FILE
  2591. //============================================================+