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