2013-03-17 14:03:01 +00:00
< ? php
//============================================================+
// File name : tcpdf_static.php
2013-09-14 19:02:50 +00:00
// Version : 1.0.002
2013-03-17 14:03:01 +00:00
// Begin : 2002-08-03
2013-09-14 19:02:50 +00:00
// Last Update : 2013-09-14
2013-04-22 19:23:46 +00:00
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
2013-05-14 20:28:42 +00:00
// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
2013-03-17 14:03:01 +00:00
// -------------------------------------------------------------------
// Copyright (C) 2002-2013 Nicola Asuni - Tecnick.com LTD
//
// This file is part of TCPDF software library.
//
// TCPDF is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// TCPDF is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the License
// along with TCPDF. If not, see
// <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
//
// See LICENSE.TXT file for more information.
// -------------------------------------------------------------------
//
// Description :
// Static methods used by the TCPDF class.
//
//============================================================+
/**
* @ file
* This is a PHP class that contains static methods for the TCPDF class .< br >
* @ package com . tecnick . tcpdf
* @ author Nicola Asuni
2013-09-14 19:02:50 +00:00
* @ version 1.0 . 002
2013-03-17 14:03:01 +00:00
*/
/**
* @ class TCPDF_STATIC
* Static methods used by the TCPDF class .
* @ package com . tecnick . tcpdf
* @ brief PHP class for generating PDF documents without requiring external extensions .
2013-09-14 19:02:50 +00:00
* @ version 1.0 . 002
2013-03-17 14:03:01 +00:00
* @ author Nicola Asuni - info @ tecnick . com
*/
class TCPDF_STATIC {
/**
* Current TCPDF version .
* @ private static
*/
2014-01-26 14:35:08 +00:00
private static $tcpdf_version = '6.0.057' ;
2013-03-17 14:03:01 +00:00
/**
* String alias for total number of pages .
* @ public static
*/
public static $alias_tot_pages = '{:ptp:}' ;
/**
* String alias for page number .
* @ public static
*/
public static $alias_num_page = '{:pnp:}' ;
/**
* String alias for total number of pages in a single group .
* @ public static
*/
public static $alias_group_tot_pages = '{:ptg:}' ;
/**
* String alias for group page number .
* @ public static
*/
public static $alias_group_num_page = '{:png:}' ;
/**
* String alias for right shift compensation used to correctly align page numbers on the right .
* @ public static
*/
public static $alias_right_shift = '{rsc:' ;
/**
* Encryption padding string .
* @ public static
*/
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 " ;
/**
* ByteRange placemark used during digital signature process .
* @ since 4.6 . 02 8 ( 2009 - 08 - 25 )
* @ public static
*/
public static $byterange_string = '/ByteRange[0 ********** ********** **********]' ;
/**
* Array page boxes names
* @ public static
*/
public static $pageboxes = array ( 'MediaBox' , 'CropBox' , 'BleedBox' , 'TrimBox' , 'ArtBox' );
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
* Return the current TCPDF version .
* @ return TCPDF version string
* @ since 5.9 . 012 ( 2010 - 11 - 10 )
* @ public static
*/
public static function getTCPDFVersion () {
return self :: $tcpdf_version ;
}
/**
* Return the current TCPDF producer .
* @ return TCPDF producer string
* @ since 6.0 . 000 ( 2013 - 03 - 16 )
* @ public static
*/
public static function getTCPDFProducer () {
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 " ;
}
/**
* Sets the current active configuration setting of magic_quotes_runtime ( if the set_magic_quotes_runtime function exist )
* @ param $mqr ( boolean ) FALSE for off , TRUE for on .
* @ since 4.6 . 025 ( 2009 - 08 - 17 )
* @ public static
*/
public static function set_mqr ( $mqr ) {
if ( ! defined ( 'PHP_VERSION_ID' )) {
$version = PHP_VERSION ;
define ( 'PHP_VERSION_ID' , (( $version { 0 } * 10000 ) + ( $version { 2 } * 100 ) + $version { 4 }));
}
if ( PHP_VERSION_ID < 50300 ) {
@ set_magic_quotes_runtime ( $mqr );
}
}
/**
* Gets the current active configuration setting of magic_quotes_runtime ( if the get_magic_quotes_runtime function exist )
* @ return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn ' t exist , 1 otherwise .
* @ since 4.6 . 025 ( 2009 - 08 - 17 )
* @ public static
*/
public static function get_mqr () {
if ( ! defined ( 'PHP_VERSION_ID' )) {
$version = PHP_VERSION ;
define ( 'PHP_VERSION_ID' , (( $version { 0 } * 10000 ) + ( $version { 2 } * 100 ) + $version { 4 }));
}
if ( PHP_VERSION_ID < 50300 ) {
return @ get_magic_quotes_runtime ();
}
return 0 ;
}
/**
* Get page dimensions from format name .
* @ param $format ( mixed ) The format name . It can be : < ul >
* < li >< b > ISO 216 A Series + 2 SIS 014711 extensions </ b ></ li >
* < li > A0 ( 841 x1189 mm ; 33.11 x46 . 81 in ) </ li >
* < li > A1 ( 594 x841 mm ; 23.39 x33 . 11 in ) </ li >
* < li > A2 ( 420 x594 mm ; 16.54 x23 . 39 in ) </ li >
* < li > A3 ( 297 x420 mm ; 11.69 x16 . 54 in ) </ li >
* < li > A4 ( 210 x297 mm ; 8.27 x11 . 69 in ) </ li >
* < li > A5 ( 148 x210 mm ; 5.83 x8 . 27 in ) </ li >
* < li > A6 ( 105 x148 mm ; 4.13 x5 . 83 in ) </ li >
* < li > A7 ( 74 x105 mm ; 2.91 x4 . 13 in ) </ li >
* < li > A8 ( 52 x74 mm ; 2.05 x2 . 91 in ) </ li >
* < li > A9 ( 37 x52 mm ; 1.46 x2 . 05 in ) </ li >
* < li > A10 ( 26 x37 mm ; 1.02 x1 . 46 in ) </ li >
* < li > A11 ( 18 x26 mm ; 0.71 x1 . 02 in ) </ li >
* < li > A12 ( 13 x18 mm ; 0.51 x0 . 71 in ) </ li >
* < li >< b > ISO 216 B Series + 2 SIS 014711 extensions </ b ></ li >
* < li > B0 ( 1000 x1414 mm ; 39.37 x55 . 67 in ) </ li >
* < li > B1 ( 707 x1000 mm ; 27.83 x39 . 37 in ) </ li >
* < li > B2 ( 500 x707 mm ; 19.69 x27 . 83 in ) </ li >
* < li > B3 ( 353 x500 mm ; 13.90 x19 . 69 in ) </ li >
* < li > B4 ( 250 x353 mm ; 9.84 x13 . 90 in ) </ li >
* < li > B5 ( 176 x250 mm ; 6.93 x9 . 84 in ) </ li >
* < li > B6 ( 125 x176 mm ; 4.92 x6 . 93 in ) </ li >
* < li > B7 ( 88 x125 mm ; 3.46 x4 . 92 in ) </ li >
* < li > B8 ( 62 x88 mm ; 2.44 x3 . 46 in ) </ li >
* < li > B9 ( 44 x62 mm ; 1.73 x2 . 44 in ) </ li >
* < li > B10 ( 31 x44 mm ; 1.22 x1 . 73 in ) </ li >
* < li > B11 ( 22 x31 mm ; 0.87 x1 . 22 in ) </ li >
* < li > B12 ( 15 x22 mm ; 0.59 x0 . 87 in ) </ li >
* < li >< b > ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION </ b ></ li >
* < li > C0 ( 917 x1297 mm ; 36.10 x51 . 06 in ) </ li >
* < li > C1 ( 648 x917 mm ; 25.51 x36 . 10 in ) </ li >
* < li > C2 ( 458 x648 mm ; 18.03 x25 . 51 in ) </ li >
* < li > C3 ( 324 x458 mm ; 12.76 x18 . 03 in ) </ li >
* < li > C4 ( 229 x324 mm ; 9.02 x12 . 76 in ) </ li >
* < li > C5 ( 162 x229 mm ; 6.38 x9 . 02 in ) </ li >
* < li > C6 ( 114 x162 mm ; 4.49 x6 . 38 in ) </ li >
* < li > C7 ( 81 x114 mm ; 3.19 x4 . 49 in ) </ li >
* < li > C8 ( 57 x81 mm ; 2.24 x3 . 19 in ) </ li >
* < li > C9 ( 40 x57 mm ; 1.57 x2 . 24 in ) </ li >
* < li > C10 ( 28 x40 mm ; 1.10 x1 . 57 in ) </ li >
* < li > C11 ( 20 x28 mm ; 0.79 x1 . 10 in ) </ li >
* < li > C12 ( 14 x20 mm ; 0.55 x0 . 79 in ) </ li >
* < li > C76 ( 81 x162 mm ; 3.19 x6 . 38 in ) </ li >
* < li > DL ( 110 x220 mm ; 4.33 x8 . 66 in ) </ li >
* < li >< b > SIS 014711 E Series </ b ></ li >
* < li > E0 ( 879 x1241 mm ; 34.61 x48 . 86 in ) </ li >
* < li > E1 ( 620 x879 mm ; 24.41 x34 . 61 in ) </ li >
* < li > E2 ( 440 x620 mm ; 17.32 x24 . 41 in ) </ li >
* < li > E3 ( 310 x440 mm ; 12.20 x17 . 32 in ) </ li >
* < li > E4 ( 220 x310 mm ; 8.66 x12 . 20 in ) </ li >
* < li > E5 ( 155 x220 mm ; 6.10 x8 . 66 in ) </ li >
* < li > E6 ( 110 x155 mm ; 4.33 x6 . 10 in ) </ li >
* < li > E7 ( 78 x110 mm ; 3.07 x4 . 33 in ) </ li >
* < li > E8 ( 55 x78 mm ; 2.17 x3 . 07 in ) </ li >
* < li > E9 ( 39 x55 mm ; 1.54 x2 . 17 in ) </ li >
* < li > E10 ( 27 x39 mm ; 1.06 x1 . 54 in ) </ li >
* < li > E11 ( 19 x27 mm ; 0.75 x1 . 06 in ) </ li >
* < li > E12 ( 13 x19 mm ; 0.51 x0 . 75 in ) </ li >
* < li >< b > SIS 014711 G Series </ b ></ li >
* < li > G0 ( 958 x1354 mm ; 37.72 x53 . 31 in ) </ li >
* < li > G1 ( 677 x958 mm ; 26.65 x37 . 72 in ) </ li >
* < li > G2 ( 479 x677 mm ; 18.86 x26 . 65 in ) </ li >
* < li > G3 ( 338 x479 mm ; 13.31 x18 . 86 in ) </ li >
* < li > G4 ( 239 x338 mm ; 9.41 x13 . 31 in ) </ li >
* < li > G5 ( 169 x239 mm ; 6.65 x9 . 41 in ) </ li >
* < li > G6 ( 119 x169 mm ; 4.69 x6 . 65 in ) </ li >
* < li > G7 ( 84 x119 mm ; 3.31 x4 . 69 in ) </ li >
* < li > G8 ( 59 x84 mm ; 2.32 x3 . 31 in ) </ li >
* < li > G9 ( 42 x59 mm ; 1.65 x2 . 32 in ) </ li >
* < li > G10 ( 29 x42 mm ; 1.14 x1 . 65 in ) </ li >
* < li > G11 ( 21 x29 mm ; 0.83 x1 . 14 in ) </ li >
* < li > G12 ( 14 x21 mm ; 0.55 x0 . 83 in ) </ li >
* < li >< b > ISO Press </ b ></ li >
* < li > RA0 ( 860 x1220 mm ; 33.86 x48 . 03 in ) </ li >
* < li > RA1 ( 610 x860 mm ; 24.02 x33 . 86 in ) </ li >
* < li > RA2 ( 430 x610 mm ; 16.93 x24 . 02 in ) </ li >
* < li > RA3 ( 305 x430 mm ; 12.01 x16 . 93 in ) </ li >
* < li > RA4 ( 215 x305 mm ; 8.46 x12 . 01 in ) </ li >
* < li > SRA0 ( 900 x1280 mm ; 35.43 x50 . 39 in ) </ li >
* < li > SRA1 ( 640 x900 mm ; 25.20 x35 . 43 in ) </ li >
* < li > SRA2 ( 450 x640 mm ; 17.72 x25 . 20 in ) </ li >
* < li > SRA3 ( 320 x450 mm ; 12.60 x17 . 72 in ) </ li >
* < li > SRA4 ( 225 x320 mm ; 8.86 x12 . 60 in ) </ li >
* < li >< b > German DIN 476 </ b ></ li >
* < li > 4 A0 ( 1682 x2378 mm ; 66.22 x93 . 62 in ) </ li >
* < li > 2 A0 ( 1189 x1682 mm ; 46.81 x66 . 22 in ) </ li >
* < li >< b > Variations on the ISO Standard </ b ></ li >
* < li > A2_EXTRA ( 445 x619 mm ; 17.52 x24 . 37 in ) </ li >
* < li > A3 + ( 329 x483 mm ; 12.95 x19 . 02 in ) </ li >
* < li > A3_EXTRA ( 322 x445 mm ; 12.68 x17 . 52 in ) </ li >
* < li > A3_SUPER ( 305 x508 mm ; 12.01 x20 . 00 in ) </ li >
* < li > SUPER_A3 ( 305 x487 mm ; 12.01 x19 . 17 in ) </ li >
* < li > A4_EXTRA ( 235 x322 mm ; 9.25 x12 . 68 in ) </ li >
* < li > A4_SUPER ( 229 x322 mm ; 9.02 x12 . 68 in ) </ li >
* < li > SUPER_A4 ( 227 x356 mm ; 8.94 x14 . 02 in ) </ li >
* < li > A4_LONG ( 210 x348 mm ; 8.27 x13 . 70 in ) </ li >
* < li > F4 ( 210 x330 mm ; 8.27 x12 . 99 in ) </ li >
* < li > SO_B5_EXTRA ( 202 x276 mm ; 7.95 x10 . 87 in ) </ li >
* < li > A5_EXTRA ( 173 x235 mm ; 6.81 x9 . 25 in ) </ li >
* < li >< b > ANSI Series </ b ></ li >
* < li > ANSI_E ( 864 x1118 mm ; 34.00 x44 . 00 in ) </ li >
* < li > ANSI_D ( 559 x864 mm ; 22.00 x34 . 00 in ) </ li >
* < li > ANSI_C ( 432 x559 mm ; 17.00 x22 . 00 in ) </ li >
* < li > ANSI_B ( 279 x432 mm ; 11.00 x17 . 00 in ) </ li >
* < li > ANSI_A ( 216 x279 mm ; 8.50 x11 . 00 in ) </ li >
* < li >< b > Traditional 'Loose' North American Paper Sizes </ b ></ li >
* < li > LEDGER , USLEDGER ( 432 x279 mm ; 17.00 x11 . 00 in ) </ li >
* < li > TABLOID , USTABLOID , BIBLE , ORGANIZERK ( 279 x432 mm ; 11.00 x17 . 00 in ) </ li >
* < li > LETTER , USLETTER , ORGANIZERM ( 216 x279 mm ; 8.50 x11 . 00 in ) </ li >
* < li > LEGAL , USLEGAL ( 216 x356 mm ; 8.50 x14 . 00 in ) </ li >
* < li > GLETTER , GOVERNMENTLETTER ( 203 x267 mm ; 8.00 x10 . 50 in ) </ li >
* < li > JLEGAL , JUNIORLEGAL ( 203 x127 mm ; 8.00 x5 . 00 in ) </ li >
* < li >< b > Other North American Paper Sizes </ b ></ li >
* < li > QUADDEMY ( 889 x1143 mm ; 35.00 x45 . 00 in ) </ li >
* < li > SUPER_B ( 330 x483 mm ; 13.00 x19 . 00 in ) </ li >
* < li > QUARTO ( 229 x279 mm ; 9.00 x11 . 00 in ) </ li >
* < li > FOLIO , GOVERNMENTLEGAL ( 216 x330 mm ; 8.50 x13 . 00 in ) </ li >
* < li > EXECUTIVE , MONARCH ( 184 x267 mm ; 7.25 x10 . 50 in ) </ li >
* < li > MEMO , STATEMENT , ORGANIZERL ( 140 x216 mm ; 5.50 x8 . 50 in ) </ li >
* < li > FOOLSCAP ( 210 x330 mm ; 8.27 x13 . 00 in ) </ li >
* < li > COMPACT ( 108 x171 mm ; 4.25 x6 . 75 in ) </ li >
* < li > ORGANIZERJ ( 70 x127 mm ; 2.75 x5 . 00 in ) </ li >
* < li >< b > Canadian standard CAN 2 - 9.60 M </ b ></ li >
* < li > P1 ( 560 x860 mm ; 22.05 x33 . 86 in ) </ li >
* < li > P2 ( 430 x560 mm ; 16.93 x22 . 05 in ) </ li >
* < li > P3 ( 280 x430 mm ; 11.02 x16 . 93 in ) </ li >
* < li > P4 ( 215 x280 mm ; 8.46 x11 . 02 in ) </ li >
* < li > P5 ( 140 x215 mm ; 5.51 x8 . 46 in ) </ li >
* < li > P6 ( 107 x140 mm ; 4.21 x5 . 51 in ) </ li >
* < li >< b > North American Architectural Sizes </ b ></ li >
* < li > ARCH_E ( 914 x1219 mm ; 36.00 x48 . 00 in ) </ li >
* < li > ARCH_E1 ( 762 x1067 mm ; 30.00 x42 . 00 in ) </ li >
* < li > ARCH_D ( 610 x914 mm ; 24.00 x36 . 00 in ) </ li >
* < li > ARCH_C , BROADSHEET ( 457 x610 mm ; 18.00 x24 . 00 in ) </ li >
* < li > ARCH_B ( 305 x457 mm ; 12.00 x18 . 00 in ) </ li >
* < li > ARCH_A ( 229 x305 mm ; 9.00 x12 . 00 in ) </ li >
* < li >< b > Announcement Envelopes </ b ></ li >
* < li > ANNENV_A2 ( 111 x146 mm ; 4.37 x5 . 75 in ) </ li >
* < li > ANNENV_A6 ( 121 x165 mm ; 4.75 x6 . 50 in ) </ li >
* < li > ANNENV_A7 ( 133 x184 mm ; 5.25 x7 . 25 in ) </ li >
* < li > ANNENV_A8 ( 140 x206 mm ; 5.50 x8 . 12 in ) </ li >
* < li > ANNENV_A10 ( 159 x244 mm ; 6.25 x9 . 62 in ) </ li >
* < li > ANNENV_SLIM ( 98 x225 mm ; 3.87 x8 . 87 in ) </ li >
* < li >< b > Commercial Envelopes </ b ></ li >
* < li > COMMENV_N6_1 / 4 ( 89 x152 mm ; 3.50 x6 . 00 in ) </ li >
* < li > COMMENV_N6_3 / 4 ( 92 x165 mm ; 3.62 x6 . 50 in ) </ li >
* < li > COMMENV_N8 ( 98 x191 mm ; 3.87 x7 . 50 in ) </ li >
* < li > COMMENV_N9 ( 98 x225 mm ; 3.87 x8 . 87 in ) </ li >
* < li > COMMENV_N10 ( 105 x241 mm ; 4.12 x9 . 50 in ) </ li >
* < li > COMMENV_N11 ( 114 x263 mm ; 4.50 x10 . 37 in ) </ li >
* < li > COMMENV_N12 ( 121 x279 mm ; 4.75 x11 . 00 in ) </ li >
* < li > COMMENV_N14 ( 127 x292 mm ; 5.00 x11 . 50 in ) </ li >
* < li >< b > Catalogue Envelopes </ b ></ li >
* < li > CATENV_N1 ( 152 x229 mm ; 6.00 x9 . 00 in ) </ li >
* < li > CATENV_N1_3 / 4 ( 165 x241 mm ; 6.50 x9 . 50 in ) </ li >
* < li > CATENV_N2 ( 165 x254 mm ; 6.50 x10 . 00 in ) </ li >
* < li > CATENV_N3 ( 178 x254 mm ; 7.00 x10 . 00 in ) </ li >
* < li > CATENV_N6 ( 191 x267 mm ; 7.50 x10 . 50 in ) </ li >
* < li > CATENV_N7 ( 203 x279 mm ; 8.00 x11 . 00 in ) </ li >
* < li > CATENV_N8 ( 210 x286 mm ; 8.25 x11 . 25 in ) </ li >
* < li > CATENV_N9_1 / 2 ( 216 x267 mm ; 8.50 x10 . 50 in ) </ li >
* < li > CATENV_N9_3 / 4 ( 222 x286 mm ; 8.75 x11 . 25 in ) </ li >
* < li > CATENV_N10_1 / 2 ( 229 x305 mm ; 9.00 x12 . 00 in ) </ li >
* < li > CATENV_N12_1 / 2 ( 241 x318 mm ; 9.50 x12 . 50 in ) </ li >
* < li > CATENV_N13_1 / 2 ( 254 x330 mm ; 10.00 x13 . 00 in ) </ li >
* < li > CATENV_N14_1 / 4 ( 286 x311 mm ; 11.25 x12 . 25 in ) </ li >
* < li > CATENV_N14_1 / 2 ( 292 x368 mm ; 11.50 x14 . 50 in ) </ li >
* < li >< b > Japanese ( JIS P 013 8 - 61 ) Standard B - Series </ b ></ li >
* < li > JIS_B0 ( 1030 x1456 mm ; 40.55 x57 . 32 in ) </ li >
* < li > JIS_B1 ( 728 x1030 mm ; 28.66 x40 . 55 in ) </ li >
* < li > JIS_B2 ( 515 x728 mm ; 20.28 x28 . 66 in ) </ li >
* < li > JIS_B3 ( 364 x515 mm ; 14.33 x20 . 28 in ) </ li >
* < li > JIS_B4 ( 257 x364 mm ; 10.12 x14 . 33 in ) </ li >
* < li > JIS_B5 ( 182 x257 mm ; 7.17 x10 . 12 in ) </ li >
* < li > JIS_B6 ( 128 x182 mm ; 5.04 x7 . 17 in ) </ li >
* < li > JIS_B7 ( 91 x128 mm ; 3.58 x5 . 04 in ) </ li >
* < li > JIS_B8 ( 64 x91 mm ; 2.52 x3 . 58 in ) </ li >
* < li > JIS_B9 ( 45 x64 mm ; 1.77 x2 . 52 in ) </ li >
* < li > JIS_B10 ( 32 x45 mm ; 1.26 x1 . 77 in ) </ li >
* < li > JIS_B11 ( 22 x32 mm ; 0.87 x1 . 26 in ) </ li >
* < li > JIS_B12 ( 16 x22 mm ; 0.63 x0 . 87 in ) </ li >
* < li >< b > PA Series </ b ></ li >
* < li > PA0 ( 840 x1120 mm ; 33.07 x44 . 09 in ) </ li >
* < li > PA1 ( 560 x840 mm ; 22.05 x33 . 07 in ) </ li >
* < li > PA2 ( 420 x560 mm ; 16.54 x22 . 05 in ) </ li >
* < li > PA3 ( 280 x420 mm ; 11.02 x16 . 54 in ) </ li >
* < li > PA4 ( 210 x280 mm ; 8.27 x11 . 02 in ) </ li >
* < li > PA5 ( 140 x210 mm ; 5.51 x8 . 27 in ) </ li >
* < li > PA6 ( 105 x140 mm ; 4.13 x5 . 51 in ) </ li >
* < li > PA7 ( 70 x105 mm ; 2.76 x4 . 13 in ) </ li >
* < li > PA8 ( 52 x70 mm ; 2.05 x2 . 76 in ) </ li >
* < li > PA9 ( 35 x52 mm ; 1.38 x2 . 05 in ) </ li >
* < li > PA10 ( 26 x35 mm ; 1.02 x1 . 38 in ) </ li >
* < li >< b > Standard Photographic Print Sizes </ b ></ li >
* < li > PASSPORT_PHOTO ( 35 x45 mm ; 1.38 x1 . 77 in ) </ li >
* < li > E ( 82 x120 mm ; 3.25 x4 . 72 in ) </ li >
* < li > 3 R , L ( 89 x127 mm ; 3.50 x5 . 00 in ) </ li >
* < li > 4 R , KG ( 102 x152 mm ; 4.02 x5 . 98 in ) </ li >
* < li > 4 D ( 120 x152 mm ; 4.72 x5 . 98 in ) </ li >
* < li > 5 R , 2 L ( 127 x178 mm ; 5.00 x7 . 01 in ) </ li >
* < li > 6 R , 8 P ( 152 x203 mm ; 5.98 x7 . 99 in ) </ li >
* < li > 8 R , 6 P ( 203 x254 mm ; 7.99 x10 . 00 in ) </ li >
* < li > S8R , 6 PW ( 203 x305 mm ; 7.99 x12 . 01 in ) </ li >
* < li > 10 R , 4 P ( 254 x305 mm ; 10.00 x12 . 01 in ) </ li >
* < li > S10R , 4 PW ( 254 x381 mm ; 10.00 x15 . 00 in ) </ li >
* < li > 11 R ( 279 x356 mm ; 10.98 x14 . 02 in ) </ li >
* < li > S11R ( 279 x432 mm ; 10.98 x17 . 01 in ) </ li >
* < li > 12 R ( 305 x381 mm ; 12.01 x15 . 00 in ) </ li >
* < li > S12R ( 305 x456 mm ; 12.01 x17 . 95 in ) </ li >
* < li >< b > Common Newspaper Sizes </ b ></ li >
* < li > NEWSPAPER_BROADSHEET ( 750 x600 mm ; 29.53 x23 . 62 in ) </ li >
* < li > NEWSPAPER_BERLINER ( 470 x315 mm ; 18.50 x12 . 40 in ) </ li >
* < li > NEWSPAPER_COMPACT , NEWSPAPER_TABLOID ( 430 x280 mm ; 16.93 x11 . 02 in ) </ li >
* < li >< b > Business Cards </ b ></ li >
* < li > CREDIT_CARD , BUSINESS_CARD , BUSINESS_CARD_ISO7810 ( 54 x86 mm ; 2.13 x3 . 37 in ) </ li >
* < li > BUSINESS_CARD_ISO216 ( 52 x74 mm ; 2.05 x2 . 91 in ) </ li >
* < li > BUSINESS_CARD_IT , BUSINESS_CARD_UK , BUSINESS_CARD_FR , BUSINESS_CARD_DE , BUSINESS_CARD_ES ( 55 x85 mm ; 2.17 x3 . 35 in ) </ li >
* < li > BUSINESS_CARD_US , BUSINESS_CARD_CA ( 51 x89 mm ; 2.01 x3 . 50 in ) </ li >
* < li > BUSINESS_CARD_JP ( 55 x91 mm ; 2.17 x3 . 58 in ) </ li >
* < li > BUSINESS_CARD_HK ( 54 x90 mm ; 2.13 x3 . 54 in ) </ li >
* < li > BUSINESS_CARD_AU , BUSINESS_CARD_DK , BUSINESS_CARD_SE ( 55 x90 mm ; 2.17 x3 . 54 in ) </ li >
* < li > BUSINESS_CARD_RU , BUSINESS_CARD_CZ , BUSINESS_CARD_FI , BUSINESS_CARD_HU , BUSINESS_CARD_IL ( 50 x90 mm ; 1.97 x3 . 54 in ) </ li >
* < li >< b > Billboards </ b ></ li >
* < li > 4 SHEET ( 1016 x1524 mm ; 40.00 x60 . 00 in ) </ li >
* < li > 6 SHEET ( 1200 x1800 mm ; 47.24 x70 . 87 in ) </ li >
* < li > 12 SHEET ( 3048 x1524 mm ; 120.00 x60 . 00 in ) </ li >
* < li > 16 SHEET ( 2032 x3048 mm ; 80.00 x120 . 00 in ) </ li >
* < li > 32 SHEET ( 4064 x3048 mm ; 160.00 x120 . 00 in ) </ li >
* < li > 48 SHEET ( 6096 x3048 mm ; 240.00 x120 . 00 in ) </ li >
* < li > 64 SHEET ( 8128 x3048 mm ; 320.00 x120 . 00 in ) </ li >
* < li > 96 SHEET ( 12192 x3048 mm ; 480.00 x120 . 00 in ) </ li >
* < li >< b > Old Imperial English ( some are still used in USA ) </ b ></ li >
* < li > EN_EMPEROR ( 1219 x1829 mm ; 48.00 x72 . 00 in ) </ li >
* < li > EN_ANTIQUARIAN ( 787 x1346 mm ; 31.00 x53 . 00 in ) </ li >
* < li > EN_GRAND_EAGLE ( 730 x1067 mm ; 28.75 x42 . 00 in ) </ li >
* < li > EN_DOUBLE_ELEPHANT ( 679 x1016 mm ; 26.75 x40 . 00 in ) </ li >
* < li > EN_ATLAS ( 660 x864 mm ; 26.00 x34 . 00 in ) </ li >
* < li > EN_COLOMBIER ( 597 x876 mm ; 23.50 x34 . 50 in ) </ li >
* < li > EN_ELEPHANT ( 584 x711 mm ; 23.00 x28 . 00 in ) </ li >
* < li > EN_DOUBLE_DEMY ( 572 x902 mm ; 22.50 x35 . 50 in ) </ li >
* < li > EN_IMPERIAL ( 559 x762 mm ; 22.00 x30 . 00 in ) </ li >
* < li > EN_PRINCESS ( 546 x711 mm ; 21.50 x28 . 00 in ) </ li >
* < li > EN_CARTRIDGE ( 533 x660 mm ; 21.00 x26 . 00 in ) </ li >
* < li > EN_DOUBLE_LARGE_POST ( 533 x838 mm ; 21.00 x33 . 00 in ) </ li >
* < li > EN_ROYAL ( 508 x635 mm ; 20.00 x25 . 00 in ) </ li >
* < li > EN_SHEET , EN_HALF_POST ( 495 x597 mm ; 19.50 x23 . 50 in ) </ li >
* < li > EN_SUPER_ROYAL ( 483 x686 mm ; 19.00 x27 . 00 in ) </ li >
* < li > EN_DOUBLE_POST ( 483 x775 mm ; 19.00 x30 . 50 in ) </ li >
* < li > EN_MEDIUM ( 445 x584 mm ; 17.50 x23 . 00 in ) </ li >
* < li > EN_DEMY ( 445 x572 mm ; 17.50 x22 . 50 in ) </ li >
* < li > EN_LARGE_POST ( 419 x533 mm ; 16.50 x21 . 00 in ) </ li >
* < li > EN_COPY_DRAUGHT ( 406 x508 mm ; 16.00 x20 . 00 in ) </ li >
* < li > EN_POST ( 394 x489 mm ; 15.50 x19 . 25 in ) </ li >
* < li > EN_CROWN ( 381 x508 mm ; 15.00 x20 . 00 in ) </ li >
* < li > EN_PINCHED_POST ( 375 x470 mm ; 14.75 x18 . 50 in ) </ li >
* < li > EN_BRIEF ( 343 x406 mm ; 13.50 x16 . 00 in ) </ li >
* < li > EN_FOOLSCAP ( 343 x432 mm ; 13.50 x17 . 00 in ) </ li >
* < li > EN_SMALL_FOOLSCAP ( 337 x419 mm ; 13.25 x16 . 50 in ) </ li >
* < li > EN_POTT ( 318 x381 mm ; 12.50 x15 . 00 in ) </ li >
* < li >< b > Old Imperial Belgian </ b ></ li >
* < li > BE_GRAND_AIGLE ( 700 x1040 mm ; 27.56 x40 . 94 in ) </ li >
* < li > BE_COLOMBIER ( 620 x850 mm ; 24.41 x33 . 46 in ) </ li >
* < li > BE_DOUBLE_CARRE ( 620 x920 mm ; 24.41 x36 . 22 in ) </ li >
* < li > BE_ELEPHANT ( 616 x770 mm ; 24.25 x30 . 31 in ) </ li >
* < li > BE_PETIT_AIGLE ( 600 x840 mm ; 23.62 x33 . 07 in ) </ li >
* < li > BE_GRAND_JESUS ( 550 x730 mm ; 21.65 x28 . 74 in ) </ li >
* < li > BE_JESUS ( 540 x730 mm ; 21.26 x28 . 74 in ) </ li >
* < li > BE_RAISIN ( 500 x650 mm ; 19.69 x25 . 59 in ) </ li >
* < li > BE_GRAND_MEDIAN ( 460 x605 mm ; 18.11 x23 . 82 in ) </ li >
* < li > BE_DOUBLE_POSTE ( 435 x565 mm ; 17.13 x22 . 24 in ) </ li >
* < li > BE_COQUILLE ( 430 x560 mm ; 16.93 x22 . 05 in ) </ li >
* < li > BE_PETIT_MEDIAN ( 415 x530 mm ; 16.34 x20 . 87 in ) </ li >
* < li > BE_RUCHE ( 360 x460 mm ; 14.17 x18 . 11 in ) </ li >
* < li > BE_PROPATRIA ( 345 x430 mm ; 13.58 x16 . 93 in ) </ li >
* < li > BE_LYS ( 317 x397 mm ; 12.48 x15 . 63 in ) </ li >
* < li > BE_POT ( 307 x384 mm ; 12.09 x15 . 12 in ) </ li >
* < li > BE_ROSETTE ( 270 x347 mm ; 10.63 x13 . 66 in ) </ li >
* < li >< b > Old Imperial French </ b ></ li >
* < li > FR_UNIVERS ( 1000 x1300 mm ; 39.37 x51 . 18 in ) </ li >
* < li > FR_DOUBLE_COLOMBIER ( 900 x1260 mm ; 35.43 x49 . 61 in ) </ li >
* < li > FR_GRANDE_MONDE ( 900 x1260 mm ; 35.43 x49 . 61 in ) </ li >
* < li > FR_DOUBLE_SOLEIL ( 800 x1200 mm ; 31.50 x47 . 24 in ) </ li >
* < li > FR_DOUBLE_JESUS ( 760 x1120 mm ; 29.92 x44 . 09 in ) </ li >
* < li > FR_GRAND_AIGLE ( 750 x1060 mm ; 29.53 x41 . 73 in ) </ li >
* < li > FR_PETIT_AIGLE ( 700 x940 mm ; 27.56 x37 . 01 in ) </ li >
* < li > FR_DOUBLE_RAISIN ( 650 x1000 mm ; 25.59 x39 . 37 in ) </ li >
* < li > FR_JOURNAL ( 650 x940 mm ; 25.59 x37 . 01 in ) </ li >
* < li > FR_COLOMBIER_AFFICHE ( 630 x900 mm ; 24.80 x35 . 43 in ) </ li >
* < li > FR_DOUBLE_CAVALIER ( 620 x920 mm ; 24.41 x36 . 22 in ) </ li >
* < li > FR_CLOCHE ( 600 x800 mm ; 23.62 x31 . 50 in ) </ li >
* < li > FR_SOLEIL ( 600 x800 mm ; 23.62 x31 . 50 in ) </ li >
* < li > FR_DOUBLE_CARRE ( 560 x900 mm ; 22.05 x35 . 43 in ) </ li >
* < li > FR_DOUBLE_COQUILLE ( 560 x880 mm ; 22.05 x34 . 65 in ) </ li >
* < li > FR_JESUS ( 560 x760 mm ; 22.05 x29 . 92 in ) </ li >
* < li > FR_RAISIN ( 500 x650 mm ; 19.69 x25 . 59 in ) </ li >
* < li > FR_CAVALIER ( 460 x620 mm ; 18.11 x24 . 41 in ) </ li >
* < li > FR_DOUBLE_COURONNE ( 460 x720 mm ; 18.11 x28 . 35 in ) </ li >
* < li > FR_CARRE ( 450 x560 mm ; 17.72 x22 . 05 in ) </ li >
* < li > FR_COQUILLE ( 440 x560 mm ; 17.32 x22 . 05 in ) </ li >
* < li > FR_DOUBLE_TELLIERE ( 440 x680 mm ; 17.32 x26 . 77 in ) </ li >
* < li > FR_DOUBLE_CLOCHE ( 400 x600 mm ; 15.75 x23 . 62 in ) </ li >
* < li > FR_DOUBLE_POT ( 400 x620 mm ; 15.75 x24 . 41 in ) </ li >
* < li > FR_ECU ( 400 x520 mm ; 15.75 x20 . 47 in ) </ li >
* < li > FR_COURONNE ( 360 x460 mm ; 14.17 x18 . 11 in ) </ li >
* < li > FR_TELLIERE ( 340 x440 mm ; 13.39 x17 . 32 in ) </ li >
* < li > FR_POT ( 310 x400 mm ; 12.20 x15 . 75 in ) </ li >
* </ ul >
* @ return array containing page width and height in points
* @ since 5.0 . 010 ( 2010 - 05 - 17 )
* @ public static
*/
public static function getPageSizeFromFormat ( $format ) {
// Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 25.4 mm)
switch ( strtoupper ( $format )) {
// ISO 216 A Series + 2 SIS 014711 extensions
case 'A0' : { $pf = array ( 2383.937 , 3370.394 ); break ;}
case 'A1' : { $pf = array ( 1683.780 , 2383.937 ); break ;}
case 'A2' : { $pf = array ( 1190.551 , 1683.780 ); break ;}
case 'A3' : { $pf = array ( 841.890 , 1190.551 ); break ;}
case 'A4' : { $pf = array ( 595.276 , 841.890 ); break ;}
case 'A5' : { $pf = array ( 419.528 , 595.276 ); break ;}
case 'A6' : { $pf = array ( 297.638 , 419.528 ); break ;}
case 'A7' : { $pf = array ( 209.764 , 297.638 ); break ;}
case 'A8' : { $pf = array ( 147.402 , 209.764 ); break ;}
case 'A9' : { $pf = array ( 104.882 , 147.402 ); break ;}
case 'A10' : { $pf = array ( 73.701 , 104.882 ); break ;}
case 'A11' : { $pf = array ( 51.024 , 73.701 ); break ;}
case 'A12' : { $pf = array ( 36.850 , 51.024 ); break ;}
// ISO 216 B Series + 2 SIS 014711 extensions
case 'B0' : { $pf = array ( 2834.646 , 4008.189 ); break ;}
case 'B1' : { $pf = array ( 2004.094 , 2834.646 ); break ;}
case 'B2' : { $pf = array ( 1417.323 , 2004.094 ); break ;}
case 'B3' : { $pf = array ( 1000.630 , 1417.323 ); break ;}
case 'B4' : { $pf = array ( 708.661 , 1000.630 ); break ;}
case 'B5' : { $pf = array ( 498.898 , 708.661 ); break ;}
case 'B6' : { $pf = array ( 354.331 , 498.898 ); break ;}
case 'B7' : { $pf = array ( 249.449 , 354.331 ); break ;}
case 'B8' : { $pf = array ( 175.748 , 249.449 ); break ;}
case 'B9' : { $pf = array ( 124.724 , 175.748 ); break ;}
case 'B10' : { $pf = array ( 87.874 , 124.724 ); break ;}
case 'B11' : { $pf = array ( 62.362 , 87.874 ); break ;}
case 'B12' : { $pf = array ( 42.520 , 62.362 ); break ;}
// ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION
case 'C0' : { $pf = array ( 2599.370 , 3676.535 ); break ;}
case 'C1' : { $pf = array ( 1836.850 , 2599.370 ); break ;}
case 'C2' : { $pf = array ( 1298.268 , 1836.850 ); break ;}
case 'C3' : { $pf = array ( 918.425 , 1298.268 ); break ;}
case 'C4' : { $pf = array ( 649.134 , 918.425 ); break ;}
case 'C5' : { $pf = array ( 459.213 , 649.134 ); break ;}
case 'C6' : { $pf = array ( 323.150 , 459.213 ); break ;}
case 'C7' : { $pf = array ( 229.606 , 323.150 ); break ;}
case 'C8' : { $pf = array ( 161.575 , 229.606 ); break ;}
case 'C9' : { $pf = array ( 113.386 , 161.575 ); break ;}
case 'C10' : { $pf = array ( 79.370 , 113.386 ); break ;}
case 'C11' : { $pf = array ( 56.693 , 79.370 ); break ;}
case 'C12' : { $pf = array ( 39.685 , 56.693 ); break ;}
case 'C76' : { $pf = array ( 229.606 , 459.213 ); break ;}
case 'DL' : { $pf = array ( 311.811 , 623.622 ); break ;}
// SIS 014711 E Series
case 'E0' : { $pf = array ( 2491.654 , 3517.795 ); break ;}
case 'E1' : { $pf = array ( 1757.480 , 2491.654 ); break ;}
case 'E2' : { $pf = array ( 1247.244 , 1757.480 ); break ;}
case 'E3' : { $pf = array ( 878.740 , 1247.244 ); break ;}
case 'E4' : { $pf = array ( 623.622 , 878.740 ); break ;}
case 'E5' : { $pf = array ( 439.370 , 623.622 ); break ;}
case 'E6' : { $pf = array ( 311.811 , 439.370 ); break ;}
case 'E7' : { $pf = array ( 221.102 , 311.811 ); break ;}
case 'E8' : { $pf = array ( 155.906 , 221.102 ); break ;}
case 'E9' : { $pf = array ( 110.551 , 155.906 ); break ;}
case 'E10' : { $pf = array ( 76.535 , 110.551 ); break ;}
case 'E11' : { $pf = array ( 53.858 , 76.535 ); break ;}
case 'E12' : { $pf = array ( 36.850 , 53.858 ); break ;}
// SIS 014711 G Series
case 'G0' : { $pf = array ( 2715.591 , 3838.110 ); break ;}
case 'G1' : { $pf = array ( 1919.055 , 2715.591 ); break ;}
case 'G2' : { $pf = array ( 1357.795 , 1919.055 ); break ;}
case 'G3' : { $pf = array ( 958.110 , 1357.795 ); break ;}
case 'G4' : { $pf = array ( 677.480 , 958.110 ); break ;}
case 'G5' : { $pf = array ( 479.055 , 677.480 ); break ;}
case 'G6' : { $pf = array ( 337.323 , 479.055 ); break ;}
case 'G7' : { $pf = array ( 238.110 , 337.323 ); break ;}
case 'G8' : { $pf = array ( 167.244 , 238.110 ); break ;}
case 'G9' : { $pf = array ( 119.055 , 167.244 ); break ;}
case 'G10' : { $pf = array ( 82.205 , 119.055 ); break ;}
case 'G11' : { $pf = array ( 59.528 , 82.205 ); break ;}
case 'G12' : { $pf = array ( 39.685 , 59.528 ); break ;}
// ISO Press
case 'RA0' : { $pf = array ( 2437.795 , 3458.268 ); break ;}
case 'RA1' : { $pf = array ( 1729.134 , 2437.795 ); break ;}
case 'RA2' : { $pf = array ( 1218.898 , 1729.134 ); break ;}
case 'RA3' : { $pf = array ( 864.567 , 1218.898 ); break ;}
case 'RA4' : { $pf = array ( 609.449 , 864.567 ); break ;}
case 'SRA0' : { $pf = array ( 2551.181 , 3628.346 ); break ;}
case 'SRA1' : { $pf = array ( 1814.173 , 2551.181 ); break ;}
case 'SRA2' : { $pf = array ( 1275.591 , 1814.173 ); break ;}
case 'SRA3' : { $pf = array ( 907.087 , 1275.591 ); break ;}
case 'SRA4' : { $pf = array ( 637.795 , 907.087 ); break ;}
// German DIN 476
case '4A0' : { $pf = array ( 4767.874 , 6740.787 ); break ;}
case '2A0' : { $pf = array ( 3370.394 , 4767.874 ); break ;}
// Variations on the ISO Standard
case 'A2_EXTRA' : { $pf = array ( 1261.417 , 1754.646 ); break ;}
case 'A3+' : { $pf = array ( 932.598 , 1369.134 ); break ;}
case 'A3_EXTRA' : { $pf = array ( 912.756 , 1261.417 ); break ;}
case 'A3_SUPER' : { $pf = array ( 864.567 , 1440.000 ); break ;}
case 'SUPER_A3' : { $pf = array ( 864.567 , 1380.472 ); break ;}
case 'A4_EXTRA' : { $pf = array ( 666.142 , 912.756 ); break ;}
case 'A4_SUPER' : { $pf = array ( 649.134 , 912.756 ); break ;}
case 'SUPER_A4' : { $pf = array ( 643.465 , 1009.134 ); break ;}
case 'A4_LONG' : { $pf = array ( 595.276 , 986.457 ); break ;}
case 'F4' : { $pf = array ( 595.276 , 935.433 ); break ;}
case 'SO_B5_EXTRA' : { $pf = array ( 572.598 , 782.362 ); break ;}
case 'A5_EXTRA' : { $pf = array ( 490.394 , 666.142 ); break ;}
// ANSI Series
case 'ANSI_E' : { $pf = array ( 2448.000 , 3168.000 ); break ;}
case 'ANSI_D' : { $pf = array ( 1584.000 , 2448.000 ); break ;}
case 'ANSI_C' : { $pf = array ( 1224.000 , 1584.000 ); break ;}
case 'ANSI_B' : { $pf = array ( 792.000 , 1224.000 ); break ;}
case 'ANSI_A' : { $pf = array ( 612.000 , 792.000 ); break ;}
// Traditional 'Loose' North American Paper Sizes
case 'USLEDGER' :
case 'LEDGER' : { $pf = array ( 1224.000 , 792.000 ); break ;}
case 'ORGANIZERK' :
case 'BIBLE' :
case 'USTABLOID' :
case 'TABLOID' : { $pf = array ( 792.000 , 1224.000 ); break ;}
case 'ORGANIZERM' :
case 'USLETTER' :
case 'LETTER' : { $pf = array ( 612.000 , 792.000 ); break ;}
case 'USLEGAL' :
case 'LEGAL' : { $pf = array ( 612.000 , 1008.000 ); break ;}
case 'GOVERNMENTLETTER' :
case 'GLETTER' : { $pf = array ( 576.000 , 756.000 ); break ;}
case 'JUNIORLEGAL' :
case 'JLEGAL' : { $pf = array ( 576.000 , 360.000 ); break ;}
// Other North American Paper Sizes
case 'QUADDEMY' : { $pf = array ( 2520.000 , 3240.000 ); break ;}
case 'SUPER_B' : { $pf = array ( 936.000 , 1368.000 ); break ;}
case 'QUARTO' : { $pf = array ( 648.000 , 792.000 ); break ;}
case 'GOVERNMENTLEGAL' :
case 'FOLIO' : { $pf = array ( 612.000 , 936.000 ); break ;}
case 'MONARCH' :
case 'EXECUTIVE' : { $pf = array ( 522.000 , 756.000 ); break ;}
case 'ORGANIZERL' :
case 'STATEMENT' :
case 'MEMO' : { $pf = array ( 396.000 , 612.000 ); break ;}
case 'FOOLSCAP' : { $pf = array ( 595.440 , 936.000 ); break ;}
case 'COMPACT' : { $pf = array ( 306.000 , 486.000 ); break ;}
case 'ORGANIZERJ' : { $pf = array ( 198.000 , 360.000 ); break ;}
// Canadian standard CAN 2-9.60M
case 'P1' : { $pf = array ( 1587.402 , 2437.795 ); break ;}
case 'P2' : { $pf = array ( 1218.898 , 1587.402 ); break ;}
case 'P3' : { $pf = array ( 793.701 , 1218.898 ); break ;}
case 'P4' : { $pf = array ( 609.449 , 793.701 ); break ;}
case 'P5' : { $pf = array ( 396.850 , 609.449 ); break ;}
case 'P6' : { $pf = array ( 303.307 , 396.850 ); break ;}
// North American Architectural Sizes
case 'ARCH_E' : { $pf = array ( 2592.000 , 3456.000 ); break ;}
case 'ARCH_E1' : { $pf = array ( 2160.000 , 3024.000 ); break ;}
case 'ARCH_D' : { $pf = array ( 1728.000 , 2592.000 ); break ;}
case 'BROADSHEET' :
case 'ARCH_C' : { $pf = array ( 1296.000 , 1728.000 ); break ;}
case 'ARCH_B' : { $pf = array ( 864.000 , 1296.000 ); break ;}
case 'ARCH_A' : { $pf = array ( 648.000 , 864.000 ); break ;}
// --- North American Envelope Sizes ---
// - Announcement Envelopes
case 'ANNENV_A2' : { $pf = array ( 314.640 , 414.000 ); break ;}
case 'ANNENV_A6' : { $pf = array ( 342.000 , 468.000 ); break ;}
case 'ANNENV_A7' : { $pf = array ( 378.000 , 522.000 ); break ;}
case 'ANNENV_A8' : { $pf = array ( 396.000 , 584.640 ); break ;}
case 'ANNENV_A10' : { $pf = array ( 450.000 , 692.640 ); break ;}
case 'ANNENV_SLIM' : { $pf = array ( 278.640 , 638.640 ); break ;}
// - Commercial Envelopes
case 'COMMENV_N6_1/4' : { $pf = array ( 252.000 , 432.000 ); break ;}
case 'COMMENV_N6_3/4' : { $pf = array ( 260.640 , 468.000 ); break ;}
case 'COMMENV_N8' : { $pf = array ( 278.640 , 540.000 ); break ;}
case 'COMMENV_N9' : { $pf = array ( 278.640 , 638.640 ); break ;}
case 'COMMENV_N10' : { $pf = array ( 296.640 , 684.000 ); break ;}
case 'COMMENV_N11' : { $pf = array ( 324.000 , 746.640 ); break ;}
case 'COMMENV_N12' : { $pf = array ( 342.000 , 792.000 ); break ;}
case 'COMMENV_N14' : { $pf = array ( 360.000 , 828.000 ); break ;}
// - Catalogue Envelopes
case 'CATENV_N1' : { $pf = array ( 432.000 , 648.000 ); break ;}
case 'CATENV_N1_3/4' : { $pf = array ( 468.000 , 684.000 ); break ;}
case 'CATENV_N2' : { $pf = array ( 468.000 , 720.000 ); break ;}
case 'CATENV_N3' : { $pf = array ( 504.000 , 720.000 ); break ;}
case 'CATENV_N6' : { $pf = array ( 540.000 , 756.000 ); break ;}
case 'CATENV_N7' : { $pf = array ( 576.000 , 792.000 ); break ;}
case 'CATENV_N8' : { $pf = array ( 594.000 , 810.000 ); break ;}
case 'CATENV_N9_1/2' : { $pf = array ( 612.000 , 756.000 ); break ;}
case 'CATENV_N9_3/4' : { $pf = array ( 630.000 , 810.000 ); break ;}
case 'CATENV_N10_1/2' : { $pf = array ( 648.000 , 864.000 ); break ;}
case 'CATENV_N12_1/2' : { $pf = array ( 684.000 , 900.000 ); break ;}
case 'CATENV_N13_1/2' : { $pf = array ( 720.000 , 936.000 ); break ;}
case 'CATENV_N14_1/4' : { $pf = array ( 810.000 , 882.000 ); break ;}
case 'CATENV_N14_1/2' : { $pf = array ( 828.000 , 1044.000 ); break ;}
// Japanese (JIS P 0138-61) Standard B-Series
case 'JIS_B0' : { $pf = array ( 2919.685 , 4127.244 ); break ;}
case 'JIS_B1' : { $pf = array ( 2063.622 , 2919.685 ); break ;}
case 'JIS_B2' : { $pf = array ( 1459.843 , 2063.622 ); break ;}
case 'JIS_B3' : { $pf = array ( 1031.811 , 1459.843 ); break ;}
case 'JIS_B4' : { $pf = array ( 728.504 , 1031.811 ); break ;}
case 'JIS_B5' : { $pf = array ( 515.906 , 728.504 ); break ;}
case 'JIS_B6' : { $pf = array ( 362.835 , 515.906 ); break ;}
case 'JIS_B7' : { $pf = array ( 257.953 , 362.835 ); break ;}
case 'JIS_B8' : { $pf = array ( 181.417 , 257.953 ); break ;}
case 'JIS_B9' : { $pf = array ( 127.559 , 181.417 ); break ;}
case 'JIS_B10' : { $pf = array ( 90.709 , 127.559 ); break ;}
case 'JIS_B11' : { $pf = array ( 62.362 , 90.709 ); break ;}
case 'JIS_B12' : { $pf = array ( 45.354 , 62.362 ); break ;}
// PA Series
case 'PA0' : { $pf = array ( 2381.102 , 3174.803 ,); break ;}
case 'PA1' : { $pf = array ( 1587.402 , 2381.102 ); break ;}
case 'PA2' : { $pf = array ( 1190.551 , 1587.402 ); break ;}
case 'PA3' : { $pf = array ( 793.701 , 1190.551 ); break ;}
case 'PA4' : { $pf = array ( 595.276 , 793.701 ); break ;}
case 'PA5' : { $pf = array ( 396.850 , 595.276 ); break ;}
case 'PA6' : { $pf = array ( 297.638 , 396.850 ); break ;}
case 'PA7' : { $pf = array ( 198.425 , 297.638 ); break ;}
case 'PA8' : { $pf = array ( 147.402 , 198.425 ); break ;}
case 'PA9' : { $pf = array ( 99.213 , 147.402 ); break ;}
case 'PA10' : { $pf = array ( 73.701 , 99.213 ); break ;}
// Standard Photographic Print Sizes
case 'PASSPORT_PHOTO' : { $pf = array ( 99.213 , 127.559 ); break ;}
case 'E' : { $pf = array ( 233.858 , 340.157 ); break ;}
case 'L' :
case '3R' : { $pf = array ( 252.283 , 360.000 ); break ;}
case 'KG' :
case '4R' : { $pf = array ( 289.134 , 430.866 ); break ;}
case '4D' : { $pf = array ( 340.157 , 430.866 ); break ;}
case '2L' :
case '5R' : { $pf = array ( 360.000 , 504.567 ); break ;}
case '8P' :
case '6R' : { $pf = array ( 430.866 , 575.433 ); break ;}
case '6P' :
case '8R' : { $pf = array ( 575.433 , 720.000 ); break ;}
case '6PW' :
case 'S8R' : { $pf = array ( 575.433 , 864.567 ); break ;}
case '4P' :
case '10R' : { $pf = array ( 720.000 , 864.567 ); break ;}
case '4PW' :
case 'S10R' : { $pf = array ( 720.000 , 1080.000 ); break ;}
case '11R' : { $pf = array ( 790.866 , 1009.134 ); break ;}
case 'S11R' : { $pf = array ( 790.866 , 1224.567 ); break ;}
case '12R' : { $pf = array ( 864.567 , 1080.000 ); break ;}
case 'S12R' : { $pf = array ( 864.567 , 1292.598 ); break ;}
// Common Newspaper Sizes
case 'NEWSPAPER_BROADSHEET' : { $pf = array ( 2125.984 , 1700.787 ); break ;}
case 'NEWSPAPER_BERLINER' : { $pf = array ( 1332.283 , 892.913 ); break ;}
case 'NEWSPAPER_TABLOID' :
case 'NEWSPAPER_COMPACT' : { $pf = array ( 1218.898 , 793.701 ); break ;}
// Business Cards
case 'CREDIT_CARD' :
case 'BUSINESS_CARD' :
case 'BUSINESS_CARD_ISO7810' : { $pf = array ( 153.014 , 242.646 ); break ;}
case 'BUSINESS_CARD_ISO216' : { $pf = array ( 147.402 , 209.764 ); break ;}
case 'BUSINESS_CARD_IT' :
case 'BUSINESS_CARD_UK' :
case 'BUSINESS_CARD_FR' :
case 'BUSINESS_CARD_DE' :
case 'BUSINESS_CARD_ES' : { $pf = array ( 155.906 , 240.945 ); break ;}
case 'BUSINESS_CARD_CA' :
case 'BUSINESS_CARD_US' : { $pf = array ( 144.567 , 252.283 ); break ;}
case 'BUSINESS_CARD_JP' : { $pf = array ( 155.906 , 257.953 ); break ;}
case 'BUSINESS_CARD_HK' : { $pf = array ( 153.071 , 255.118 ); break ;}
case 'BUSINESS_CARD_AU' :
case 'BUSINESS_CARD_DK' :
case 'BUSINESS_CARD_SE' : { $pf = array ( 155.906 , 255.118 ); break ;}
case 'BUSINESS_CARD_RU' :
case 'BUSINESS_CARD_CZ' :
case 'BUSINESS_CARD_FI' :
case 'BUSINESS_CARD_HU' :
case 'BUSINESS_CARD_IL' : { $pf = array ( 141.732 , 255.118 ); break ;}
// Billboards
case '4SHEET' : { $pf = array ( 2880.000 , 4320.000 ); break ;}
case '6SHEET' : { $pf = array ( 3401.575 , 5102.362 ); break ;}
case '12SHEET' : { $pf = array ( 8640.000 , 4320.000 ); break ;}
case '16SHEET' : { $pf = array ( 5760.000 , 8640.000 ); break ;}
case '32SHEET' : { $pf = array ( 11520.000 , 8640.000 ); break ;}
case '48SHEET' : { $pf = array ( 17280.000 , 8640.000 ); break ;}
case '64SHEET' : { $pf = array ( 23040.000 , 8640.000 ); break ;}
case '96SHEET' : { $pf = array ( 34560.000 , 8640.000 ); break ;}
// Old European Sizes
// - Old Imperial English Sizes
case 'EN_EMPEROR' : { $pf = array ( 3456.000 , 5184.000 ); break ;}
case 'EN_ANTIQUARIAN' : { $pf = array ( 2232.000 , 3816.000 ); break ;}
case 'EN_GRAND_EAGLE' : { $pf = array ( 2070.000 , 3024.000 ); break ;}
case 'EN_DOUBLE_ELEPHANT' : { $pf = array ( 1926.000 , 2880.000 ); break ;}
case 'EN_ATLAS' : { $pf = array ( 1872.000 , 2448.000 ); break ;}
case 'EN_COLOMBIER' : { $pf = array ( 1692.000 , 2484.000 ); break ;}
case 'EN_ELEPHANT' : { $pf = array ( 1656.000 , 2016.000 ); break ;}
case 'EN_DOUBLE_DEMY' : { $pf = array ( 1620.000 , 2556.000 ); break ;}
case 'EN_IMPERIAL' : { $pf = array ( 1584.000 , 2160.000 ); break ;}
case 'EN_PRINCESS' : { $pf = array ( 1548.000 , 2016.000 ); break ;}
case 'EN_CARTRIDGE' : { $pf = array ( 1512.000 , 1872.000 ); break ;}
case 'EN_DOUBLE_LARGE_POST' : { $pf = array ( 1512.000 , 2376.000 ); break ;}
case 'EN_ROYAL' : { $pf = array ( 1440.000 , 1800.000 ); break ;}
case 'EN_SHEET' :
case 'EN_HALF_POST' : { $pf = array ( 1404.000 , 1692.000 ); break ;}
case 'EN_SUPER_ROYAL' : { $pf = array ( 1368.000 , 1944.000 ); break ;}
case 'EN_DOUBLE_POST' : { $pf = array ( 1368.000 , 2196.000 ); break ;}
case 'EN_MEDIUM' : { $pf = array ( 1260.000 , 1656.000 ); break ;}
case 'EN_DEMY' : { $pf = array ( 1260.000 , 1620.000 ); break ;}
case 'EN_LARGE_POST' : { $pf = array ( 1188.000 , 1512.000 ); break ;}
case 'EN_COPY_DRAUGHT' : { $pf = array ( 1152.000 , 1440.000 ); break ;}
case 'EN_POST' : { $pf = array ( 1116.000 , 1386.000 ); break ;}
case 'EN_CROWN' : { $pf = array ( 1080.000 , 1440.000 ); break ;}
case 'EN_PINCHED_POST' : { $pf = array ( 1062.000 , 1332.000 ); break ;}
case 'EN_BRIEF' : { $pf = array ( 972.000 , 1152.000 ); break ;}
case 'EN_FOOLSCAP' : { $pf = array ( 972.000 , 1224.000 ); break ;}
case 'EN_SMALL_FOOLSCAP' : { $pf = array ( 954.000 , 1188.000 ); break ;}
case 'EN_POTT' : { $pf = array ( 900.000 , 1080.000 ); break ;}
// - Old Imperial Belgian Sizes
case 'BE_GRAND_AIGLE' : { $pf = array ( 1984.252 , 2948.031 ); break ;}
case 'BE_COLOMBIER' : { $pf = array ( 1757.480 , 2409.449 ); break ;}
case 'BE_DOUBLE_CARRE' : { $pf = array ( 1757.480 , 2607.874 ); break ;}
case 'BE_ELEPHANT' : { $pf = array ( 1746.142 , 2182.677 ); break ;}
case 'BE_PETIT_AIGLE' : { $pf = array ( 1700.787 , 2381.102 ); break ;}
case 'BE_GRAND_JESUS' : { $pf = array ( 1559.055 , 2069.291 ); break ;}
case 'BE_JESUS' : { $pf = array ( 1530.709 , 2069.291 ); break ;}
case 'BE_RAISIN' : { $pf = array ( 1417.323 , 1842.520 ); break ;}
case 'BE_GRAND_MEDIAN' : { $pf = array ( 1303.937 , 1714.961 ); break ;}
case 'BE_DOUBLE_POSTE' : { $pf = array ( 1233.071 , 1601.575 ); break ;}
case 'BE_COQUILLE' : { $pf = array ( 1218.898 , 1587.402 ); break ;}
case 'BE_PETIT_MEDIAN' : { $pf = array ( 1176.378 , 1502.362 ); break ;}
case 'BE_RUCHE' : { $pf = array ( 1020.472 , 1303.937 ); break ;}
case 'BE_PROPATRIA' : { $pf = array ( 977.953 , 1218.898 ); break ;}
case 'BE_LYS' : { $pf = array ( 898.583 , 1125.354 ); break ;}
case 'BE_POT' : { $pf = array ( 870.236 , 1088.504 ); break ;}
case 'BE_ROSETTE' : { $pf = array ( 765.354 , 983.622 ); break ;}
// - Old Imperial French Sizes
case 'FR_UNIVERS' : { $pf = array ( 2834.646 , 3685.039 ); break ;}
case 'FR_DOUBLE_COLOMBIER' : { $pf = array ( 2551.181 , 3571.654 ); break ;}
case 'FR_GRANDE_MONDE' : { $pf = array ( 2551.181 , 3571.654 ); break ;}
case 'FR_DOUBLE_SOLEIL' : { $pf = array ( 2267.717 , 3401.575 ); break ;}
case 'FR_DOUBLE_JESUS' : { $pf = array ( 2154.331 , 3174.803 ); break ;}
case 'FR_GRAND_AIGLE' : { $pf = array ( 2125.984 , 3004.724 ); break ;}
case 'FR_PETIT_AIGLE' : { $pf = array ( 1984.252 , 2664.567 ); break ;}
case 'FR_DOUBLE_RAISIN' : { $pf = array ( 1842.520 , 2834.646 ); break ;}
case 'FR_JOURNAL' : { $pf = array ( 1842.520 , 2664.567 ); break ;}
case 'FR_COLOMBIER_AFFICHE' : { $pf = array ( 1785.827 , 2551.181 ); break ;}
case 'FR_DOUBLE_CAVALIER' : { $pf = array ( 1757.480 , 2607.874 ); break ;}
case 'FR_CLOCHE' : { $pf = array ( 1700.787 , 2267.717 ); break ;}
case 'FR_SOLEIL' : { $pf = array ( 1700.787 , 2267.717 ); break ;}
case 'FR_DOUBLE_CARRE' : { $pf = array ( 1587.402 , 2551.181 ); break ;}
case 'FR_DOUBLE_COQUILLE' : { $pf = array ( 1587.402 , 2494.488 ); break ;}
case 'FR_JESUS' : { $pf = array ( 1587.402 , 2154.331 ); break ;}
case 'FR_RAISIN' : { $pf = array ( 1417.323 , 1842.520 ); break ;}
case 'FR_CAVALIER' : { $pf = array ( 1303.937 , 1757.480 ); break ;}
case 'FR_DOUBLE_COURONNE' : { $pf = array ( 1303.937 , 2040.945 ); break ;}
case 'FR_CARRE' : { $pf = array ( 1275.591 , 1587.402 ); break ;}
case 'FR_COQUILLE' : { $pf = array ( 1247.244 , 1587.402 ); break ;}
case 'FR_DOUBLE_TELLIERE' : { $pf = array ( 1247.244 , 1927.559 ); break ;}
case 'FR_DOUBLE_CLOCHE' : { $pf = array ( 1133.858 , 1700.787 ); break ;}
case 'FR_DOUBLE_POT' : { $pf = array ( 1133.858 , 1757.480 ); break ;}
case 'FR_ECU' : { $pf = array ( 1133.858 , 1474.016 ); break ;}
case 'FR_COURONNE' : { $pf = array ( 1020.472 , 1303.937 ); break ;}
case 'FR_TELLIERE' : { $pf = array ( 963.780 , 1247.244 ); break ;}
case 'FR_POT' : { $pf = array ( 878.740 , 1133.858 ); break ;}
// DEFAULT ISO A4
default : { $pf = array ( 595.276 , 841.890 ); break ;}
}
return $pf ;
}
/**
* Set page boundaries .
* @ param $page ( int ) page number
* @ 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 >
* @ param $llx ( float ) lower - left x coordinate in user units .
* @ param $lly ( float ) lower - left y coordinate in user units .
* @ param $urx ( float ) upper - right x coordinate in user units .
* @ param $ury ( float ) upper - right y coordinate in user units .
* @ param $points ( boolean ) If true uses user units as unit of measure , otherwise uses PDF points .
2013-03-17 14:11:58 +00:00
* @ param $k ( float ) Scale factor ( number of points in user unit ) .
2013-03-17 14:03:01 +00:00
* @ param $pagedim ( array ) Array of page dimensions .
* @ return pagedim array of page dimensions .
* @ since 5.0 . 010 ( 2010 - 05 - 17 )
* @ public static
*/
public static function setPageBoxes ( $page , $type , $llx , $lly , $urx , $ury , $points = false , $k , $pagedim = array ()) {
if ( ! isset ( $pagedim [ $page ])) {
// initialize array
$pagedim [ $page ] = array ();
}
if ( ! in_array ( $type , self :: $pageboxes )) {
return ;
}
if ( $points ) {
$k = 1 ;
}
$pagedim [ $page ][ $type ][ 'llx' ] = ( $llx * $k );
$pagedim [ $page ][ $type ][ 'lly' ] = ( $lly * $k );
$pagedim [ $page ][ $type ][ 'urx' ] = ( $urx * $k );
$pagedim [ $page ][ $type ][ 'ury' ] = ( $ury * $k );
return $pagedim ;
}
/**
* Swap X and Y coordinates of page boxes ( change page boxes orientation ) .
* @ param $page ( int ) page number
* @ param $pagedim ( array ) Array of page dimensions .
* @ return pagedim array of page dimensions .
* @ since 5.0 . 010 ( 2010 - 05 - 17 )
* @ public static
*/
public static function swapPageBoxCoordinates ( $page , $pagedim ) {
foreach ( self :: $pageboxes as $type ) {
// swap X and Y coordinates
if ( isset ( $pagedim [ $page ][ $type ])) {
$tmp = $pagedim [ $page ][ $type ][ 'llx' ];
$pagedim [ $page ][ $type ][ 'llx' ] = $pagedim [ $page ][ $type ][ 'lly' ];
$pagedim [ $page ][ $type ][ 'lly' ] = $tmp ;
$tmp = $pagedim [ $page ][ $type ][ 'urx' ];
$pagedim [ $page ][ $type ][ 'urx' ] = $pagedim [ $page ][ $type ][ 'ury' ];
$pagedim [ $page ][ $type ][ 'ury' ] = $tmp ;
}
}
return $pagedim ;
}
/**
* Get the canonical page layout mode .
* @ 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 >
* @ return ( string ) Canonical page layout name .
* @ public static
*/
public static function getPageLayoutMode ( $layout = 'SinglePage' ) {
switch ( $layout ) {
case 'default' :
case 'single' :
case 'SinglePage' : {
$layout_mode = 'SinglePage' ;
break ;
}
case 'continuous' :
case 'OneColumn' : {
$layout_mode = 'OneColumn' ;
break ;
}
case 'two' :
case 'TwoColumnLeft' : {
$layout_mode = 'TwoColumnLeft' ;
break ;
}
case 'TwoColumnRight' : {
$layout_mode = 'TwoColumnRight' ;
break ;
}
case 'TwoPageLeft' : {
$layout_mode = 'TwoPageLeft' ;
break ;
}
case 'TwoPageRight' : {
$layout_mode = 'TwoPageRight' ;
break ;
}
default : {
$layout_mode = 'SinglePage' ;
}
}
return $layout_mode ;
}
/**
* Get the canonical page layout mode .
* @ 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 >
* @ return ( string ) Canonical page mode name .
* @ public static
*/
public static function getPageMode ( $mode = 'UseNone' ) {
switch ( $mode ) {
case 'UseNone' : {
$page_mode = 'UseNone' ;
break ;
}
case 'UseOutlines' : {
$page_mode = 'UseOutlines' ;
break ;
}
case 'UseThumbs' : {
$page_mode = 'UseThumbs' ;
break ;
}
case 'FullScreen' : {
$page_mode = 'FullScreen' ;
break ;
}
case 'UseOC' : {
$page_mode = 'UseOC' ;
break ;
}
case '' : {
$page_mode = 'UseAttachments' ;
break ;
}
default : {
$page_mode = 'UseNone' ;
}
}
return $page_mode ;
}
/**
* Check if the URL exist .
* @ param $url ( string ) URL to check .
* @ return Boolean true if the URl exist , false otherwise .
* @ since 5.9 . 204 ( 2013 - 01 - 28 )
* @ public static
*/
public static function isValidURL ( $url ) {
$headers = @ get_headers ( $url );
return ( strpos ( $headers [ 0 ], '200' ) !== false );
}
/**
* Removes SHY characters from text .
* Unicode Data :< ul >
* < li > Name : SOFT HYPHEN , commonly abbreviated as SHY </ li >
* < li > HTML Entity ( decimal ) : " &#173; " </ li >
* < li > HTML Entity ( hex ) : " &#xad; " </ li >
* < li > HTML Entity ( named ) : " &shy; " </ li >
* < li > How to type in Microsoft Windows : [ Alt + 00 AD ] or [ Alt 0173 ] </ li >
* < li > UTF - 8 ( hex ) : 0xC2 0xAD ( c2ad ) </ li >
* < li > UTF - 8 character : chr ( 194 ) . chr ( 173 ) </ li >
* </ ul >
* @ param $txt ( string ) input string
* @ param $unicode ( boolean ) True if we are in unicode mode , false otherwise .
* @ return string without SHY characters .
* @ since ( 4.5 . 01 9 ) 2009 - 02 - 28
* @ public static
*/
public static function removeSHY ( $txt = '' , $unicode = true ) {
$txt = preg_replace ( '/([\\xc2]{1}[\\xad]{1})/' , '' , $txt );
if ( ! $unicode ) {
$txt = preg_replace ( '/([\\xad]{1})/' , '' , $txt );
}
return $txt ;
}
/**
* Get the border mode accounting for multicell position ( opens bottom side of multicell crossing pages )
* @ 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 )))
* @ param $position ( string ) multicell position : 'start' , 'middle' , 'end'
* @ param $opencell ( boolean ) True when the cell is left open at the page bottom , false otherwise .
* @ return border mode array
* @ since 4.4 . 002 ( 2008 - 12 - 09 )
* @ public static
*/
public static function getBorderMode ( $brd , $position = 'start' , $opencell = true ) {
if (( ! $opencell ) OR empty ( $brd )) {
return $brd ;
}
if ( $brd == 1 ) {
$brd = 'LTRB' ;
}
if ( is_string ( $brd )) {
// convert string to array
$slen = strlen ( $brd );
$newbrd = array ();
for ( $i = 0 ; $i < $slen ; ++ $i ) {
$newbrd [ $brd [ $i ]] = array ( 'cap' => 'square' , 'join' => 'miter' );
}
$brd = $newbrd ;
}
foreach ( $brd as $border => $style ) {
switch ( $position ) {
case 'start' : {
if ( strpos ( $border , 'B' ) !== false ) {
// remove bottom line
$newkey = str_replace ( 'B' , '' , $border );
if ( strlen ( $newkey ) > 0 ) {
$brd [ $newkey ] = $style ;
}
unset ( $brd [ $border ]);
}
break ;
}
case 'middle' : {
if ( strpos ( $border , 'B' ) !== false ) {
// remove bottom line
$newkey = str_replace ( 'B' , '' , $border );
if ( strlen ( $newkey ) > 0 ) {
$brd [ $newkey ] = $style ;
}
unset ( $brd [ $border ]);
$border = $newkey ;
}
if ( strpos ( $border , 'T' ) !== false ) {
// remove bottom line
$newkey = str_replace ( 'T' , '' , $border );
if ( strlen ( $newkey ) > 0 ) {
$brd [ $newkey ] = $style ;
}
unset ( $brd [ $border ]);
}
break ;
}
case 'end' : {
if ( strpos ( $border , 'T' ) !== false ) {
// remove bottom line
$newkey = str_replace ( 'T' , '' , $border );
if ( strlen ( $newkey ) > 0 ) {
$brd [ $newkey ] = $style ;
}
unset ( $brd [ $border ]);
}
break ;
}
}
}
return $brd ;
}
/**
* Determine whether a string is empty .
* @ param $str ( string ) string to be checked
* @ return boolean true if string is empty
* @ since 4.5 . 044 ( 2009 - 04 - 16 )
* @ public static
*/
public static function empty_string ( $str ) {
return ( is_null ( $str ) OR ( is_string ( $str ) AND ( strlen ( $str ) == 0 )));
}
/**
* Returns a temporary filename for caching object on filesystem .
2013-10-20 12:37:51 +00:00
* @ param $type ( string ) Type of file ( name of the subdir on the tcpdf cache folder ) .
2013-03-17 14:03:01 +00:00
* @ return string filename .
* @ since 4.5 . 000 ( 2008 - 12 - 31 )
* @ public static
*/
2013-10-20 12:37:51 +00:00
public static function getObjFilename ( $type = 'tmp' ) {
return tempnam ( K_PATH_CACHE , '__tcpdf_' . $type . '_' . md5 ( getmypid () . uniqid ( '' , true ) . rand () . microtime ( true )) . '_' );
2013-03-17 14:03:01 +00:00
}
/**
* Add " \" before " \ " , " ( " and " ) "
* @ param $s ( string ) string to escape .
* @ return string escaped string .
* @ public static
*/
public static function _escape ( $s ) {
// the chr(13) substitution fixes the Bugs item #1421290.
return strtr ( $s , array ( ')' => '\\)' , '(' => '\\(' , '\\' => '\\\\' , chr ( 13 ) => '\r' ));
}
/**
* Escape some special characters ( & lt ; & gt ; & amp ;) for XML output .
* @ param $str ( string ) Input string to convert .
* @ return converted string
* @ since 5.9 . 121 ( 2011 - 09 - 28 )
* @ public static
*/
public static function _escapeXML ( $str ) {
$replaceTable = array ( " \0 " => '' , '&' => '&' , '<' => '<' , '>' => '>' );
$str = strtr ( $str , $replaceTable );
return $str ;
}
/**
* Creates a copy of a class object
* @ param $object ( object ) class object to be cloned
* @ return cloned object
* @ since 4.5 . 02 9 ( 2009 - 03 - 19 )
* @ public static
*/
public static function objclone ( $object ) {
if (( $object instanceof Imagick ) AND ( version_compare ( phpversion ( 'imagick' ), '3.0.1' ) !== 1 )) {
// on the versions after 3.0.1 the clone() method was deprecated in favour of clone keyword
return @ $object -> clone ();
}
return @ clone ( $object );
}
/**
* Ouput input data and compress it if possible .
* @ param $data ( string ) Data to output .
* @ param $length ( int ) Data length in bytes .
* @ since 5.9 . 086
* @ public static
*/
public static function sendOutputData ( $data , $length ) {
if ( ! isset ( $_SERVER [ 'HTTP_ACCEPT_ENCODING' ]) OR empty ( $_SERVER [ 'HTTP_ACCEPT_ENCODING' ])) {
// the content length may vary if the server is using compression
header ( 'Content-Length: ' . $length );
}
echo $data ;
}
/**
* Replace page number aliases with number .
* @ param $page ( string ) Page content .
* @ param $replace ( array ) Array of replacements ( array keys are replacement strings , values are alias arrays ) .
* @ param $diff ( int ) If passed , this will be set to the total char number difference between alias and replacements .
* @ return replaced page content and updated $diff parameter as array .
* @ public static
*/
public static function replacePageNumAliases ( $page , $replace , $diff = 0 ) {
foreach ( $replace as $rep ) {
foreach ( $rep [ 3 ] as $a ) {
if ( strpos ( $page , $a ) !== false ) {
$page = str_replace ( $a , $rep [ 0 ], $page );
$diff += ( $rep [ 2 ] - $rep [ 1 ]);
}
}
}
return array ( $page , $diff );
}
/**
* Returns timestamp in seconds from formatted date - time .
* @ param $date ( string ) Formatted date - time .
* @ return int seconds .
* @ since 5.9 . 152 ( 2012 - 03 - 23 )
* @ public static
*/
public static function getTimestamp ( $date ) {
if (( $date [ 0 ] == 'D' ) AND ( $date [ 1 ] == ':' )) {
// remove date prefix if present
$date = substr ( $date , 2 );
}
return strtotime ( $date );
}
/**
* Returns a formatted date - time .
* @ param $time ( int ) Time in seconds .
* @ return string escaped date string .
* @ since 5.9 . 152 ( 2012 - 03 - 23 )
* @ public static
*/
public static function getFormattedDate ( $time ) {
return substr_replace ( date ( 'YmdHisO' , intval ( $time )), '\'' , ( 0 - 2 ), 0 ) . '\'' ;
}
/**
* Get ULONG from string ( Big Endian 32 - bit unsigned integer ) .
* @ param $str ( string ) string from where to extract value
* @ param $offset ( int ) point from where to read the data
* @ return int 32 bit value
* @ author Nicola Asuni
* @ since 5.2 . 000 ( 2010 - 06 - 02 )
* @ public static
*/
public static function _getULONG ( $str , $offset ) {
$v = unpack ( 'Ni' , substr ( $str , $offset , 4 ));
return $v [ 'i' ];
}
/**
* Get USHORT from string ( Big Endian 16 - bit unsigned integer ) .
* @ param $str ( string ) string from where to extract value
* @ param $offset ( int ) point from where to read the data
* @ return int 16 bit value
* @ author Nicola Asuni
* @ since 5.2 . 000 ( 2010 - 06 - 02 )
* @ public static
*/
public static function _getUSHORT ( $str , $offset ) {
$v = unpack ( 'ni' , substr ( $str , $offset , 2 ));
return $v [ 'i' ];
}
/**
* Get SHORT from string ( Big Endian 16 - bit signed integer ) .
* @ param $str ( string ) String from where to extract value .
* @ param $offset ( int ) Point from where to read the data .
* @ return int 16 bit value
* @ author Nicola Asuni
* @ since 5.2 . 000 ( 2010 - 06 - 02 )
* @ public static
*/
public static function _getSHORT ( $str , $offset ) {
$v = unpack ( 'si' , substr ( $str , $offset , 2 ));
return $v [ 'i' ];
}
/**
* Get FWORD from string ( Big Endian 16 - bit signed integer ) .
* @ param $str ( string ) String from where to extract value .
* @ param $offset ( int ) Point from where to read the data .
* @ return int 16 bit value
* @ author Nicola Asuni
* @ since 5.9 . 123 ( 2011 - 09 - 30 )
* @ public static
*/
public static function _getFWORD ( $str , $offset ) {
$v = self :: _getUSHORT ( $str , $offset );
if ( $v > 0x7fff ) {
$v -= 0x10000 ;
}
return $v ;
}
/**
* Get UFWORD from string ( Big Endian 16 - bit unsigned integer ) .
* @ param $str ( string ) string from where to extract value
* @ param $offset ( int ) point from where to read the data
* @ return int 16 bit value
* @ author Nicola Asuni
* @ since 5.9 . 123 ( 2011 - 09 - 30 )
* @ public static
*/
public static function _getUFWORD ( $str , $offset ) {
$v = self :: _getUSHORT ( $str , $offset );
return $v ;
}
/**
* Get FIXED from string ( 32 - bit signed fixed - point number ( 16.16 ) .
* @ param $str ( string ) string from where to extract value
* @ param $offset ( int ) point from where to read the data
* @ return int 16 bit value
* @ author Nicola Asuni
* @ since 5.9 . 123 ( 2011 - 09 - 30 )
* @ public static
*/
public static function _getFIXED ( $str , $offset ) {
// mantissa
$m = self :: _getFWORD ( $str , $offset );
// fraction
$f = self :: _getUSHORT ( $str , ( $offset + 2 ));
$v = floatval ( '' . $m . '.' . $f . '' );
return $v ;
}
/**
* Get BYTE from string ( 8 - bit unsigned integer ) .
* @ param $str ( string ) String from where to extract value .
* @ param $offset ( int ) Point from where to read the data .
* @ return int 8 bit value
* @ author Nicola Asuni
* @ since 5.2 . 000 ( 2010 - 06 - 02 )
* @ public static
*/
public static function _getBYTE ( $str , $offset ) {
$v = unpack ( 'Ci' , substr ( $str , $offset , 1 ));
return $v [ 'i' ];
}
/**
* Binary - safe and URL - safe file read .
* 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 .
* @ param $handle ( resource )
* @ param $length ( int )
* @ return Returns the read string or FALSE in case of error .
* @ author Nicola Asuni
* @ since 4.5 . 027 ( 2009 - 03 - 16 )
* @ public static
*/
public static function rfread ( $handle , $length ) {
$data = fread ( $handle , $length );
if ( $data === false ) {
return false ;
}
$rest = ( $length - strlen ( $data ));
if ( $rest > 0 ) {
$data .= self :: rfread ( $handle , $rest );
}
return $data ;
}
/**
* Read a 4 - byte ( 32 bit ) integer from file .
* @ param $f ( string ) file name .
* @ return 4 - byte integer
* @ public static
*/
public static function _freadint ( $f ) {
$a = unpack ( 'Ni' , fread ( $f , 4 ));
return $a [ 'i' ];
}
/**
* Returns a string containing random data to be used as a seed for encryption methods .
* @ param $seed ( string ) starting seed value
* @ return string containing random data
* @ author Nicola Asuni
* @ since 5.9 . 006 ( 2010 - 10 - 19 )
* @ public static
*/
public static function getRandomSeed ( $seed = '' ) {
$seed .= microtime ();
if ( function_exists ( 'openssl_random_pseudo_bytes' ) AND ( strtoupper ( substr ( PHP_OS , 0 , 3 )) !== 'WIN' )) {
// this is not used on windows systems because it is very slow for a know bug
$seed .= openssl_random_pseudo_bytes ( 512 );
} else {
for ( $i = 0 ; $i < 23 ; ++ $i ) {
$seed .= uniqid ( '' , true );
}
}
$seed .= uniqid ( '' , true );
$seed .= rand ();
$seed .= getmypid ();
$seed .= __FILE__ ;
if ( isset ( $_SERVER [ 'REMOTE_ADDR' ])) {
$seed .= $_SERVER [ 'REMOTE_ADDR' ];
}
if ( isset ( $_SERVER [ 'HTTP_USER_AGENT' ])) {
$seed .= $_SERVER [ 'HTTP_USER_AGENT' ];
}
if ( isset ( $_SERVER [ 'HTTP_ACCEPT' ])) {
$seed .= $_SERVER [ 'HTTP_ACCEPT' ];
}
if ( isset ( $_SERVER [ 'HTTP_ACCEPT_ENCODING' ])) {
$seed .= $_SERVER [ 'HTTP_ACCEPT_ENCODING' ];
}
if ( isset ( $_SERVER [ 'HTTP_ACCEPT_LANGUAGE' ])) {
$seed .= $_SERVER [ 'HTTP_ACCEPT_LANGUAGE' ];
}
if ( isset ( $_SERVER [ 'HTTP_ACCEPT_CHARSET' ])) {
$seed .= $_SERVER [ 'HTTP_ACCEPT_CHARSET' ];
}
$seed .= rand ();
$seed .= uniqid ( '' , true );
$seed .= microtime ();
return $seed ;
}
/**
* Encrypts a string using MD5 and returns it ' s value as a binary string .
* @ param $str ( string ) input string
* @ return String MD5 encrypted binary string
* @ since 2.0 . 000 ( 2008 - 01 - 02 )
* @ public static
*/
public static function _md5_16 ( $str ) {
return pack ( 'H*' , md5 ( $str ));
}
/**
* Returns the input text exrypted using AES algorithm and the specified key .
* This method requires mcrypt .
* @ param $key ( string ) encryption key
* @ param $text ( String ) input text to be encrypted
* @ return String encrypted text
* @ author Nicola Asuni
* @ since 5.0 . 005 ( 2010 - 05 - 11 )
* @ public static
*/
public static function _AES ( $key , $text ) {
// padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0)
$padding = 16 - ( strlen ( $text ) % 16 );
$text .= str_repeat ( chr ( $padding ), $padding );
$iv = mcrypt_create_iv ( mcrypt_get_iv_size ( MCRYPT_RIJNDAEL_128 , MCRYPT_MODE_CBC ), MCRYPT_RAND );
$text = mcrypt_encrypt ( MCRYPT_RIJNDAEL_128 , $key , $text , MCRYPT_MODE_CBC , $iv );
$text = $iv . $text ;
return $text ;
}
/**
* Returns the input text encrypted using RC4 algorithm and the specified key .
* RC4 is the standard encryption algorithm used in PDF format
2013-03-17 14:11:58 +00:00
* @ param $key ( string ) Encryption key .
* @ param $text ( String ) Input text to be encrypted .
* @ param $last_enc_key ( String ) Reference to last RC4 key encrypted .
* @ param $last_enc_key_c ( String ) Reference to last RC4 computed key .
2013-03-17 14:03:01 +00:00
* @ return String encrypted text
* @ since 2.0 . 000 ( 2008 - 01 - 02 )
* @ author Klemen Vodopivec , Nicola Asuni
* @ public static
*/
public static function _RC4 ( $key , $text , & $last_enc_key , & $last_enc_key_c ) {
2013-09-14 19:02:50 +00:00
if ( function_exists ( 'mcrypt_encrypt' ) AND ( $out = @ mcrypt_encrypt ( MCRYPT_ARCFOUR , $key , $text , MCRYPT_MODE_STREAM , '' ))) {
2013-03-17 14:03:01 +00:00
// try to use mcrypt function if exist
return $out ;
}
if ( $last_enc_key != $key ) {
$k = str_repeat ( $key , (( 256 / strlen ( $key )) + 1 ));
$rc4 = range ( 0 , 255 );
$j = 0 ;
for ( $i = 0 ; $i < 256 ; ++ $i ) {
$t = $rc4 [ $i ];
$j = ( $j + $t + ord ( $k [ $i ])) % 256 ;
$rc4 [ $i ] = $rc4 [ $j ];
$rc4 [ $j ] = $t ;
}
$last_enc_key = $key ;
$last_enc_key_c = $rc4 ;
} else {
$rc4 = $last_enc_key_c ;
}
$len = strlen ( $text );
$a = 0 ;
$b = 0 ;
$out = '' ;
for ( $i = 0 ; $i < $len ; ++ $i ) {
$a = ( $a + 1 ) % 256 ;
$t = $rc4 [ $a ];
$b = ( $b + $t ) % 256 ;
$rc4 [ $a ] = $rc4 [ $b ];
$rc4 [ $b ] = $t ;
$k = $rc4 [( $rc4 [ $a ] + $rc4 [ $b ]) % 256 ];
$out .= chr ( ord ( $text [ $i ]) ^ $k );
}
return $out ;
}
/**
* Return the premission code used on encryption ( P value ) .
* @ param $permissions ( Array ) the set of permissions ( specify the ones you want to block ) .
* @ param $mode ( int ) encryption strength : 0 = RC4 40 bit ; 1 = RC4 128 bit ; 2 = AES 128 bit ; 3 = AES 256 bit .
* @ since 5.0 . 005 ( 2010 - 05 - 12 )
* @ author Nicola Asuni
* @ public static
*/
public static function getUserPermissionCode ( $permissions , $mode = 0 ) {
$options = array (
'owner' => 2 , // bit 2 -- inverted logic: cleared by default
'print' => 4 , // bit 3
'modify' => 8 , // bit 4
'copy' => 16 , // bit 5
'annot-forms' => 32 , // bit 6
'fill-forms' => 256 , // bit 9
'extract' => 512 , // bit 10
'assemble' => 1024 , // bit 11
'print-high' => 2048 // bit 12
);
$protection = 2147422012 ; // 32 bit: (01111111 11111111 00001111 00111100)
foreach ( $permissions as $permission ) {
if ( isset ( $options [ $permission ])) {
if (( $mode > 0 ) OR ( $options [ $permission ] <= 32 )) {
// set only valid permissions
if ( $options [ $permission ] == 2 ) {
// the logic for bit 2 is inverted (cleared by default)
$protection += $options [ $permission ];
} else {
$protection -= $options [ $permission ];
}
}
}
}
return $protection ;
}
/**
* Convert hexadecimal string to string
* @ param $bs ( string ) byte - string to convert
* @ return String
* @ since 5.0 . 005 ( 2010 - 05 - 12 )
* @ author Nicola Asuni
* @ public static
*/
public static function convertHexStringToString ( $bs ) {
$string = '' ; // string to be returned
$bslength = strlen ( $bs );
if (( $bslength % 2 ) != 0 ) {
// padding
$bs .= '0' ;
++ $bslength ;
}
for ( $i = 0 ; $i < $bslength ; $i += 2 ) {
$string .= chr ( hexdec ( $bs [ $i ] . $bs [( $i + 1 )]));
}
return $string ;
}
/**
* Convert string to hexadecimal string ( byte string )
* @ param $s ( string ) string to convert
* @ return byte string
* @ since 5.0 . 010 ( 2010 - 05 - 17 )
* @ author Nicola Asuni
* @ public static
*/
public static function convertStringToHexString ( $s ) {
$bs = '' ;
$chars = preg_split ( '//' , $s , - 1 , PREG_SPLIT_NO_EMPTY );
foreach ( $chars as $c ) {
$bs .= sprintf ( '%02s' , dechex ( ord ( $c )));
}
return $bs ;
}
/**
* Convert encryption P value to a string of bytes , low - order byte first .
* @ param $protection ( string ) 32 bit encryption permission value ( P value )
* @ return String
* @ since 5.0 . 005 ( 2010 - 05 - 12 )
* @ author Nicola Asuni
* @ public static
*/
public static function getEncPermissionsString ( $protection ) {
$binprot = sprintf ( '%032b' , $protection );
$str = chr ( bindec ( substr ( $binprot , 24 , 8 )));
$str .= chr ( bindec ( substr ( $binprot , 16 , 8 )));
$str .= chr ( bindec ( substr ( $binprot , 8 , 8 )));
$str .= chr ( bindec ( substr ( $binprot , 0 , 8 )));
return $str ;
}
/**
* Encode a name object .
* @ param $name ( string ) Name object to encode .
* @ return ( string ) Encoded name object .
* @ author Nicola Asuni
* @ since 5.9 . 097 ( 2011 - 06 - 23 )
* @ public static
*/
public static function encodeNameObject ( $name ) {
$escname = '' ;
$length = strlen ( $name );
for ( $i = 0 ; $i < $length ; ++ $i ) {
$chr = $name [ $i ];
if ( preg_match ( '/[0-9a-zA-Z]/' , $chr ) == 1 ) {
$escname .= $chr ;
} else {
$escname .= sprintf ( '#%02X' , ord ( $chr ));
}
}
return $escname ;
}
/**
* Convert JavaScript form fields properties array to Annotation Properties array .
* @ param $prop ( array ) javascript field properties . Possible values are described on official Javascript for Acrobat API reference .
* @ param $spot_colors ( array ) Reference to spot colors array .
* @ param $rtl ( boolean ) True if in Right - To - Left text direction mode , false otherwise .
* @ return array of annotation properties
* @ author Nicola Asuni
* @ since 4.8 . 000 ( 2009 - 09 - 06 )
* @ public static
*/
public static function getAnnotOptFromJSProp ( $prop , & $spot_colors , $rtl = false ) {
if ( isset ( $prop [ 'aopt' ]) AND is_array ( $prop [ 'aopt' ])) {
// the annotation options area lready defined
return $prop [ 'aopt' ];
}
$opt = array (); // value to be returned
// alignment: Controls how the text is laid out within the text field.
if ( isset ( $prop [ 'alignment' ])) {
switch ( $prop [ 'alignment' ]) {
case 'left' : {
$opt [ 'q' ] = 0 ;
break ;
}
case 'center' : {
$opt [ 'q' ] = 1 ;
break ;
}
case 'right' : {
$opt [ 'q' ] = 2 ;
break ;
}
default : {
$opt [ 'q' ] = ( $rtl ) ? 2 : 0 ;
break ;
}
}
}
// lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle.
if ( isset ( $prop [ 'lineWidth' ])) {
$linewidth = intval ( $prop [ 'lineWidth' ]);
} else {
$linewidth = 1 ;
}
// borderStyle: The border style for a field.
if ( isset ( $prop [ 'borderStyle' ])) {
switch ( $prop [ 'borderStyle' ]) {
case 'border.d' :
case 'dashed' : {
$opt [ 'border' ] = array ( 0 , 0 , $linewidth , array ( 3 , 2 ));
$opt [ 'bs' ] = array ( 'w' => $linewidth , 's' => 'D' , 'd' => array ( 3 , 2 ));
break ;
}
case 'border.b' :
case 'beveled' : {
$opt [ 'border' ] = array ( 0 , 0 , $linewidth );
$opt [ 'bs' ] = array ( 'w' => $linewidth , 's' => 'B' );
break ;
}
case 'border.i' :
case 'inset' : {
$opt [ 'border' ] = array ( 0 , 0 , $linewidth );
$opt [ 'bs' ] = array ( 'w' => $linewidth , 's' => 'I' );
break ;
}
case 'border.u' :
case 'underline' : {
$opt [ 'border' ] = array ( 0 , 0 , $linewidth );
$opt [ 'bs' ] = array ( 'w' => $linewidth , 's' => 'U' );
break ;
}
case 'border.s' :
case 'solid' : {
$opt [ 'border' ] = array ( 0 , 0 , $linewidth );
$opt [ 'bs' ] = array ( 'w' => $linewidth , 's' => 'S' );
break ;
}
default : {
break ;
}
}
}
if ( isset ( $prop [ 'border' ]) AND is_array ( $prop [ 'border' ])) {
$opt [ 'border' ] = $prop [ 'border' ];
}
if ( ! isset ( $opt [ 'mk' ])) {
$opt [ 'mk' ] = array ();
}
if ( ! isset ( $opt [ 'mk' ][ 'if' ])) {
$opt [ 'mk' ][ 'if' ] = array ();
}
$opt [ 'mk' ][ 'if' ][ 'a' ] = array ( 0.5 , 0.5 );
// buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon.
if ( isset ( $prop [ 'buttonAlignX' ])) {
$opt [ 'mk' ][ 'if' ][ 'a' ][ 0 ] = $prop [ 'buttonAlignX' ];
}
// buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon.
if ( isset ( $prop [ 'buttonAlignY' ])) {
$opt [ 'mk' ][ 'if' ][ 'a' ][ 1 ] = $prop [ 'buttonAlignY' ];
}
// buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field.
if ( isset ( $prop [ 'buttonFitBounds' ]) AND ( $prop [ 'buttonFitBounds' ] == 'true' )) {
$opt [ 'mk' ][ 'if' ][ 'fb' ] = true ;
}
// buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face.
if ( isset ( $prop [ 'buttonScaleHow' ])) {
switch ( $prop [ 'buttonScaleHow' ]) {
case 'scaleHow.proportional' : {
$opt [ 'mk' ][ 'if' ][ 's' ] = 'P' ;
break ;
}
case 'scaleHow.anamorphic' : {
$opt [ 'mk' ][ 'if' ][ 's' ] = 'A' ;
break ;
}
}
}
// buttonScaleWhen: Controls when an icon is scaled to fit inside the button face.
if ( isset ( $prop [ 'buttonScaleWhen' ])) {
switch ( $prop [ 'buttonScaleWhen' ]) {
case 'scaleWhen.always' : {
$opt [ 'mk' ][ 'if' ][ 'sw' ] = 'A' ;
break ;
}
case 'scaleWhen.never' : {
$opt [ 'mk' ][ 'if' ][ 'sw' ] = 'N' ;
break ;
}
case 'scaleWhen.tooBig' : {
$opt [ 'mk' ][ 'if' ][ 'sw' ] = 'B' ;
break ;
}
case 'scaleWhen.tooSmall' : {
$opt [ 'mk' ][ 'if' ][ 'sw' ] = 'S' ;
break ;
}
}
}
// buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face.
if ( isset ( $prop [ 'buttonPosition' ])) {
switch ( $prop [ 'buttonPosition' ]) {
case 0 :
case 'position.textOnly' : {
$opt [ 'mk' ][ 'tp' ] = 0 ;
break ;
}
case 1 :
case 'position.iconOnly' : {
$opt [ 'mk' ][ 'tp' ] = 1 ;
break ;
}
case 2 :
case 'position.iconTextV' : {
$opt [ 'mk' ][ 'tp' ] = 2 ;
break ;
}
case 3 :
case 'position.textIconV' : {
$opt [ 'mk' ][ 'tp' ] = 3 ;
break ;
}
case 4 :
case 'position.iconTextH' : {
$opt [ 'mk' ][ 'tp' ] = 4 ;
break ;
}
case 5 :
case 'position.textIconH' : {
$opt [ 'mk' ][ 'tp' ] = 5 ;
break ;
}
case 6 :
case 'position.overlay' : {
$opt [ 'mk' ][ 'tp' ] = 6 ;
break ;
}
}
}
// fillColor: Specifies the background color for a field.
if ( isset ( $prop [ 'fillColor' ])) {
if ( is_array ( $prop [ 'fillColor' ])) {
$opt [ 'mk' ][ 'bg' ] = $prop [ 'fillColor' ];
} else {
$opt [ 'mk' ][ 'bg' ] = TCPDF_COLORS :: convertHTMLColorToDec ( $prop [ 'fillColor' ], $spot_colors );
}
}
// 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.
if ( isset ( $prop [ 'strokeColor' ])) {
if ( is_array ( $prop [ 'strokeColor' ])) {
$opt [ 'mk' ][ 'bc' ] = $prop [ 'strokeColor' ];
} else {
$opt [ 'mk' ][ 'bc' ] = TCPDF_COLORS :: convertHTMLColorToDec ( $prop [ 'strokeColor' ], $spot_colors );
}
}
// rotation: The rotation of a widget in counterclockwise increments.
if ( isset ( $prop [ 'rotation' ])) {
$opt [ 'mk' ][ 'r' ] = $prop [ 'rotation' ];
}
// charLimit: Limits the number of characters that a user can type into a text field.
if ( isset ( $prop [ 'charLimit' ])) {
$opt [ 'maxlen' ] = intval ( $prop [ 'charLimit' ]);
}
if ( ! isset ( $ff )) {
$ff = 0 ; // default value
}
// readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
if ( isset ( $prop [ 'readonly' ]) AND ( $prop [ 'readonly' ] == 'true' )) {
$ff += 1 << 0 ;
}
// required: Specifies whether a field requires a value.
if ( isset ( $prop [ 'required' ]) AND ( $prop [ 'required' ] == 'true' )) {
$ff += 1 << 1 ;
}
// multiline: Controls how text is wrapped within the field.
if ( isset ( $prop [ 'multiline' ]) AND ( $prop [ 'multiline' ] == 'true' )) {
$ff += 1 << 12 ;
}
// password: Specifies whether the field should display asterisks when data is entered in the field.
if ( isset ( $prop [ 'password' ]) AND ( $prop [ 'password' ] == 'true' )) {
$ff += 1 << 13 ;
}
// NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect.
if ( isset ( $prop [ 'NoToggleToOff' ]) AND ( $prop [ 'NoToggleToOff' ] == 'true' )) {
$ff += 1 << 14 ;
}
// Radio: If set, the field is a set of radio buttons.
if ( isset ( $prop [ 'Radio' ]) AND ( $prop [ 'Radio' ] == 'true' )) {
$ff += 1 << 15 ;
}
// Pushbutton: If set, the field is a pushbutton that does not retain a permanent value.
if ( isset ( $prop [ 'Pushbutton' ]) AND ( $prop [ 'Pushbutton' ] == 'true' )) {
$ff += 1 << 16 ;
}
// Combo: If set, the field is a combo box; if clear, the field is a list box.
if ( isset ( $prop [ 'Combo' ]) AND ( $prop [ 'Combo' ] == 'true' )) {
$ff += 1 << 17 ;
}
// editable: Controls whether a combo box is editable.
if ( isset ( $prop [ 'editable' ]) AND ( $prop [ 'editable' ] == 'true' )) {
$ff += 1 << 18 ;
}
// Sort: If set, the field's option items shall be sorted alphabetically.
if ( isset ( $prop [ 'Sort' ]) AND ( $prop [ 'Sort' ] == 'true' )) {
$ff += 1 << 19 ;
}
// fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection).
if ( isset ( $prop [ 'fileSelect' ]) AND ( $prop [ 'fileSelect' ] == 'true' )) {
$ff += 1 << 20 ;
}
// multipleSelection: If true, indicates that a list box allows a multiple selection of items.
if ( isset ( $prop [ 'multipleSelection' ]) AND ( $prop [ 'multipleSelection' ] == 'true' )) {
$ff += 1 << 21 ;
}
// doNotSpellCheck: If true, spell checking is not performed on this editable text field.
if ( isset ( $prop [ 'doNotSpellCheck' ]) AND ( $prop [ 'doNotSpellCheck' ] == 'true' )) {
$ff += 1 << 22 ;
}
// doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field.
if ( isset ( $prop [ 'doNotScroll' ]) AND ( $prop [ 'doNotScroll' ] == 'true' )) {
$ff += 1 << 23 ;
}
// 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.
if ( isset ( $prop [ 'comb' ]) AND ( $prop [ 'comb' ] == 'true' )) {
$ff += 1 << 24 ;
}
// 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.
if ( isset ( $prop [ 'radiosInUnison' ]) AND ( $prop [ 'radiosInUnison' ] == 'true' )) {
$ff += 1 << 25 ;
}
// richText: If true, the field allows rich text formatting.
if ( isset ( $prop [ 'richText' ]) AND ( $prop [ 'richText' ] == 'true' )) {
$ff += 1 << 25 ;
}
// commitOnSelChange: Controls whether a field value is committed after a selection change.
if ( isset ( $prop [ 'commitOnSelChange' ]) AND ( $prop [ 'commitOnSelChange' ] == 'true' )) {
$ff += 1 << 26 ;
}
$opt [ 'ff' ] = $ff ;
// defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset.
if ( isset ( $prop [ 'defaultValue' ])) {
$opt [ 'dv' ] = $prop [ 'defaultValue' ];
}
$f = 4 ; // default value for annotation flags
// readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
if ( isset ( $prop [ 'readonly' ]) AND ( $prop [ 'readonly' ] == 'true' )) {
$f += 1 << 6 ;
}
// display: Controls whether the field is hidden or visible on screen and in print.
if ( isset ( $prop [ 'display' ])) {
if ( $prop [ 'display' ] == 'display.visible' ) {
//
} elseif ( $prop [ 'display' ] == 'display.hidden' ) {
$f += 1 << 1 ;
} elseif ( $prop [ 'display' ] == 'display.noPrint' ) {
$f -= 1 << 2 ;
} elseif ( $prop [ 'display' ] == 'display.noView' ) {
$f += 1 << 5 ;
}
}
$opt [ 'f' ] = $f ;
// currentValueIndices: Reads and writes single or multiple values of a list box or combo box.
if ( isset ( $prop [ 'currentValueIndices' ]) AND is_array ( $prop [ 'currentValueIndices' ])) {
$opt [ 'i' ] = $prop [ 'currentValueIndices' ];
}
// value: The value of the field data that the user has entered.
if ( isset ( $prop [ 'value' ])) {
if ( is_array ( $prop [ 'value' ])) {
$opt [ 'opt' ] = array ();
foreach ( $prop [ 'value' ] AS $key => $optval ) {
// exportValues: An array of strings representing the export values for the field.
if ( isset ( $prop [ 'exportValues' ][ $key ])) {
$opt [ 'opt' ][ $key ] = array ( $prop [ 'exportValues' ][ $key ], $prop [ 'value' ][ $key ]);
} else {
$opt [ 'opt' ][ $key ] = $prop [ 'value' ][ $key ];
}
}
} else {
$opt [ 'v' ] = $prop [ 'value' ];
}
}
// richValue: This property specifies the text contents and formatting of a rich text field.
if ( isset ( $prop [ 'richValue' ])) {
$opt [ 'rv' ] = $prop [ 'richValue' ];
}
// submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded).
if ( isset ( $prop [ 'submitName' ])) {
$opt [ 'tm' ] = $prop [ 'submitName' ];
}
// name: Fully qualified field name.
if ( isset ( $prop [ 'name' ])) {
$opt [ 't' ] = $prop [ 'name' ];
}
// userName: The user name (short description string) of the field.
if ( isset ( $prop [ 'userName' ])) {
$opt [ 'tu' ] = $prop [ 'userName' ];
}
// highlight: Defines how a button reacts when a user clicks it.
if ( isset ( $prop [ 'highlight' ])) {
switch ( $prop [ 'highlight' ]) {
case 'none' :
case 'highlight.n' : {
$opt [ 'h' ] = 'N' ;
break ;
}
case 'invert' :
case 'highlight.i' : {
$opt [ 'h' ] = 'i' ;
break ;
}
case 'push' :
case 'highlight.p' : {
$opt [ 'h' ] = 'P' ;
break ;
}
case 'outline' :
case 'highlight.o' : {
$opt [ 'h' ] = 'O' ;
break ;
}
}
}
// Unsupported options:
// - calcOrderIndex: Changes the calculation order of fields in the document.
// - delay: Delays the redrawing of a field's appearance.
// - defaultStyle: This property defines the default style attributes for the form field.
// - style: Allows the user to set the glyph style of a check box or radio button.
// - textColor, textFont, textSize
return $opt ;
}
/**
* Format the page numbers .
* This method can be overriden for custom formats .
* @ param $num ( int ) page number
* @ since 4.2 . 005 ( 2008 - 11 - 06 )
* @ public static
*/
public static function formatPageNumber ( $num ) {
return number_format (( float ) $num , 0 , '' , '.' );
}
/**
* Format the page numbers on the Table Of Content .
* This method can be overriden for custom formats .
* @ param $num ( int ) page number
* @ since 4.5 . 001 ( 2009 - 01 - 04 )
* @ see addTOC (), addHTMLTOC ()
* @ public static
*/
public static function formatTOCPageNumber ( $num ) {
return number_format (( float ) $num , 0 , '' , '.' );
}
/**
* Extracts the CSS properties from a CSS string .
* @ param $cssdata ( string ) string containing CSS definitions .
* @ return An array where the keys are the CSS selectors and the values are the CSS properties .
* @ author Nicola Asuni
* @ since 5.1 . 000 ( 2010 - 05 - 25 )
* @ public static
*/
public static function extractCSSproperties ( $cssdata ) {
if ( empty ( $cssdata )) {
return array ();
}
// remove comments
$cssdata = preg_replace ( '/\/\*[^\*]*\*\//' , '' , $cssdata );
// remove newlines and multiple spaces
$cssdata = preg_replace ( '/[\s]+/' , ' ' , $cssdata );
// remove some spaces
$cssdata = preg_replace ( '/[\s]*([;:\{\}]{1})[\s]*/' , '\\1' , $cssdata );
// remove empty blocks
$cssdata = preg_replace ( '/([^\}\{]+)\{\}/' , '' , $cssdata );
// replace media type parenthesis
$cssdata = preg_replace ( '/@media[\s]+([^\{]*)\{/i' , '@media \\1§' , $cssdata );
$cssdata = preg_replace ( '/\}\}/si' , '}§' , $cssdata );
// trim string
$cssdata = trim ( $cssdata );
// find media blocks (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
$cssblocks = array ();
$matches = array ();
if ( preg_match_all ( '/@media[\s]+([^\§]*)§([^§]*)§/i' , $cssdata , $matches ) > 0 ) {
foreach ( $matches [ 1 ] as $key => $type ) {
$cssblocks [ $type ] = $matches [ 2 ][ $key ];
}
// remove media blocks
$cssdata = preg_replace ( '/@media[\s]+([^\§]*)§([^§]*)§/i' , '' , $cssdata );
}
// keep 'all' and 'print' media, other media types are discarded
if ( isset ( $cssblocks [ 'all' ]) AND ! empty ( $cssblocks [ 'all' ])) {
$cssdata .= $cssblocks [ 'all' ];
}
if ( isset ( $cssblocks [ 'print' ]) AND ! empty ( $cssblocks [ 'print' ])) {
$cssdata .= $cssblocks [ 'print' ];
}
// reset css blocks array
$cssblocks = array ();
$matches = array ();
// explode css data string into array
if ( substr ( $cssdata , - 1 ) == '}' ) {
// remove last parethesis
$cssdata = substr ( $cssdata , 0 , - 1 );
}
$matches = explode ( '}' , $cssdata );
foreach ( $matches as $key => $block ) {
// index 0 contains the CSS selector, index 1 contains CSS properties
$cssblocks [ $key ] = explode ( '{' , $block );
if ( ! isset ( $cssblocks [ $key ][ 1 ])) {
// remove empty definitions
unset ( $cssblocks [ $key ]);
}
}
// split groups of selectors (comma-separated list of selectors)
foreach ( $cssblocks as $key => $block ) {
if ( strpos ( $block [ 0 ], ',' ) > 0 ) {
$selectors = explode ( ',' , $block [ 0 ]);
foreach ( $selectors as $sel ) {
$cssblocks [] = array ( 0 => trim ( $sel ), 1 => $block [ 1 ]);
}
unset ( $cssblocks [ $key ]);
}
}
// covert array to selector => properties
$cssdata = array ();
foreach ( $cssblocks as $block ) {
$selector = $block [ 0 ];
// calculate selector's specificity
$matches = array ();
$a = 0 ; // the declaration is not from is a 'style' attribute
$b = intval ( preg_match_all ( '/[\#]/' , $selector , $matches )); // number of ID attributes
$c = intval ( preg_match_all ( '/[\[\.]/' , $selector , $matches )); // number of other attributes
$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
$d = intval ( preg_match_all ( '/[\>\+\~\s]{1}[a-zA-Z0-9]+/' , ' ' . $selector , $matches )); // number of element names
$d += intval ( preg_match_all ( '/[\:][\:]/' , $selector , $matches )); // number of pseudo-elements
$specificity = $a . $b . $c . $d ;
// add specificity to the beginning of the selector
$cssdata [ $specificity . ' ' . $selector ] = $block [ 1 ];
}
// sort selectors alphabetically to account for specificity
ksort ( $cssdata , SORT_STRING );
// return array
return $cssdata ;
}
/**
* Cleanup HTML code ( requires HTML Tidy library ) .
* @ param $html ( string ) htmlcode to fix
* @ param $default_css ( string ) CSS commands to add
* @ param $tagvs ( array ) parameters for setHtmlVSpace method
* @ param $tidy_options ( array ) options for tidy_parse_string function
* @ param $tagvspaces ( array ) Array of vertical spaces for tags .
* @ return string XHTML code cleaned up
* @ author Nicola Asuni
* @ since 5.9 . 017 ( 2010 - 11 - 16 )
* @ see setHtmlVSpace ()
* @ public static
*/
public static function fixHTMLCode ( $html , $default_css = '' , $tagvs = '' , $tidy_options = '' , & $tagvspaces ) {
// configure parameters for HTML Tidy
if ( $tidy_options === '' ) {
$tidy_options = array (
'clean' => 1 ,
'drop-empty-paras' => 0 ,
'drop-proprietary-attributes' => 1 ,
'fix-backslash' => 1 ,
'hide-comments' => 1 ,
'join-styles' => 1 ,
'lower-literals' => 1 ,
'merge-divs' => 1 ,
'merge-spans' => 1 ,
'output-xhtml' => 1 ,
'word-2000' => 1 ,
'wrap' => 0 ,
'output-bom' => 0 ,
//'char-encoding' => 'utf8',
//'input-encoding' => 'utf8',
//'output-encoding' => 'utf8'
);
}
// clean up the HTML code
$tidy = tidy_parse_string ( $html , $tidy_options );
// fix the HTML
$tidy -> cleanRepair ();
// get the CSS part
$tidy_head = tidy_get_head ( $tidy );
$css = $tidy_head -> value ;
$css = preg_replace ( '/<style([^>]+)>/ims' , '<style>' , $css );
$css = preg_replace ( '/<\/style>(.*)<style>/ims' , " \n " , $css );
$css = str_replace ( '/*<![CDATA[*/' , '' , $css );
$css = str_replace ( '/*]]>*/' , '' , $css );
preg_match ( '/<style>(.*)<\/style>/ims' , $css , $matches );
if ( isset ( $matches [ 1 ])) {
$css = strtolower ( $matches [ 1 ]);
} else {
$css = '' ;
}
// include default css
$css = '<style>' . $default_css . $css . '</style>' ;
// get the body part
$tidy_body = tidy_get_body ( $tidy );
$html = $tidy_body -> value ;
// fix some self-closing tags
$html = str_replace ( '<br>' , '<br />' , $html );
// remove some empty tag blocks
$html = preg_replace ( '/<div([^\>]*)><\/div>/' , '' , $html );
$html = preg_replace ( '/<p([^\>]*)><\/p>/' , '' , $html );
if ( $tagvs !== '' ) {
// set vertical space for some XHTML tags
$tagvspaces = $tagvs ;
}
// return the cleaned XHTML code + CSS
return $css . $html ;
}
/**
* Returns true if the CSS selector is valid for the selected HTML tag
* @ param $dom ( array ) array of HTML tags and properties
* @ param $key ( int ) key of the current HTML tag
* @ param $selector ( string ) CSS selector string
* @ return true if the selector is valid , false otherwise
* @ since 5.1 . 000 ( 2010 - 05 - 25 )
* @ public static
*/
public static function isValidCSSSelectorForTag ( $dom , $key , $selector ) {
$valid = false ; // value to be returned
$tag = $dom [ $key ][ 'value' ];
$class = array ();
if ( isset ( $dom [ $key ][ 'attribute' ][ 'class' ]) AND ! empty ( $dom [ $key ][ 'attribute' ][ 'class' ])) {
$class = explode ( ' ' , strtolower ( $dom [ $key ][ 'attribute' ][ 'class' ]));
}
$id = '' ;
if ( isset ( $dom [ $key ][ 'attribute' ][ 'id' ]) AND ! empty ( $dom [ $key ][ 'attribute' ][ 'id' ])) {
$id = strtolower ( $dom [ $key ][ 'attribute' ][ 'id' ]);
}
$selector = preg_replace ( '/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si' , '\\1*.\\3' , $selector );
$matches = array ();
if ( preg_match_all ( '/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si' , $selector , $matches , PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE ) > 0 ) {
$parentop = array_pop ( $matches [ 1 ]);
$operator = $parentop [ 0 ];
$offset = $parentop [ 1 ];
$lasttag = array_pop ( $matches [ 2 ]);
$lasttag = strtolower ( trim ( $lasttag [ 0 ]));
if (( $lasttag == '*' ) OR ( $lasttag == $tag )) {
// the last element on selector is our tag or 'any tag'
$attrib = array_pop ( $matches [ 3 ]);
$attrib = strtolower ( trim ( $attrib [ 0 ]));
if ( ! empty ( $attrib )) {
// check if matches class, id, attribute, pseudo-class or pseudo-element
switch ( $attrib { 0 }) {
case '.' : { // class
if ( in_array ( substr ( $attrib , 1 ), $class )) {
$valid = true ;
}
break ;
}
case '#' : { // ID
if ( substr ( $attrib , 1 ) == $id ) {
$valid = true ;
}
break ;
}
case '[' : { // attribute
$attrmatch = array ();
if ( preg_match ( '/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i' , $attrib , $attrmatch ) > 0 ) {
$att = strtolower ( $attrmatch [ 1 ]);
$val = $attrmatch [ 3 ];
if ( isset ( $dom [ $key ][ 'attribute' ][ $att ])) {
switch ( $attrmatch [ 2 ]) {
case '=' : {
if ( $dom [ $key ][ 'attribute' ][ $att ] == $val ) {
$valid = true ;
}
break ;
}
case '~=' : {
if ( in_array ( $val , explode ( ' ' , $dom [ $key ][ 'attribute' ][ $att ]))) {
$valid = true ;
}
break ;
}
case '^=' : {
if ( $val == substr ( $dom [ $key ][ 'attribute' ][ $att ], 0 , strlen ( $val ))) {
$valid = true ;
}
break ;
}
case '$=' : {
if ( $val == substr ( $dom [ $key ][ 'attribute' ][ $att ], - strlen ( $val ))) {
$valid = true ;
}
break ;
}
case '*=' : {
if ( strpos ( $dom [ $key ][ 'attribute' ][ $att ], $val ) !== false ) {
$valid = true ;
}
break ;
}
case '|=' : {
if ( $dom [ $key ][ 'attribute' ][ $att ] == $val ) {
$valid = true ;
} elseif ( preg_match ( '/' . $val . '[\-]{1}/i' , $dom [ $key ][ 'attribute' ][ $att ]) > 0 ) {
$valid = true ;
}
break ;
}
default : {
$valid = true ;
}
}
}
}
break ;
}
case ':' : { // pseudo-class or pseudo-element
if ( $attrib { 1 } == ':' ) { // pseudo-element
// pseudo-elements are not supported!
// (::first-line, ::first-letter, ::before, ::after)
} else { // pseudo-class
// pseudo-classes are not supported!
// (: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)
}
break ;
}
} // end of switch
} else {
$valid = true ;
}
if ( $valid AND ( $offset > 0 )) {
$valid = false ;
// check remaining selector part
$selector = substr ( $selector , 0 , $offset );
switch ( $operator ) {
case ' ' : { // descendant of an element
while ( $dom [ $key ][ 'parent' ] > 0 ) {
if ( self :: isValidCSSSelectorForTag ( $dom , $dom [ $key ][ 'parent' ], $selector )) {
$valid = true ;
break ;
} else {
$key = $dom [ $key ][ 'parent' ];
}
}
break ;
}
case '>' : { // child of an element
$valid = self :: isValidCSSSelectorForTag ( $dom , $dom [ $key ][ 'parent' ], $selector );
break ;
}
case '+' : { // immediately preceded by an element
for ( $i = ( $key - 1 ); $i > $dom [ $key ][ 'parent' ]; -- $i ) {
if ( $dom [ $i ][ 'tag' ] AND $dom [ $i ][ 'opening' ]) {
$valid = self :: isValidCSSSelectorForTag ( $dom , $i , $selector );
break ;
}
}
break ;
}
case '~' : { // preceded by an element
for ( $i = ( $key - 1 ); $i > $dom [ $key ][ 'parent' ]; -- $i ) {
if ( $dom [ $i ][ 'tag' ] AND $dom [ $i ][ 'opening' ]) {
if ( self :: isValidCSSSelectorForTag ( $dom , $i , $selector )) {
break ;
}
}
}
break ;
}
}
}
}
}
return $valid ;
}
/**
* Returns the styles array that apply for the selected HTML tag .
* @ param $dom ( array ) array of HTML tags and properties
* @ param $key ( int ) key of the current HTML tag
* @ param $css ( array ) array of CSS properties
* @ return array containing CSS properties
* @ since 5.1 . 000 ( 2010 - 05 - 25 )
* @ public static
*/
public static function getCSSdataArray ( $dom , $key , $css ) {
$cssarray = array (); // style to be returned
// get parent CSS selectors
$selectors = array ();
if ( isset ( $dom [( $dom [ $key ][ 'parent' ])][ 'csssel' ])) {
$selectors = $dom [( $dom [ $key ][ 'parent' ])][ 'csssel' ];
}
// get all styles that apply
foreach ( $css as $selector => $style ) {
$pos = strpos ( $selector , ' ' );
// get specificity
$specificity = substr ( $selector , 0 , $pos );
// remove specificity
$selector = substr ( $selector , $pos );
// check if this selector apply to current tag
if ( self :: isValidCSSSelectorForTag ( $dom , $key , $selector )) {
if ( ! in_array ( $selector , $selectors )) {
// add style if not already added on parent selector
$cssarray [] = array ( 'k' => $selector , 's' => $specificity , 'c' => $style );
$selectors [] = $selector ;
}
}
}
if ( isset ( $dom [ $key ][ 'attribute' ][ 'style' ])) {
// attach inline style (latest properties have high priority)
$cssarray [] = array ( 'k' => '' , 's' => '1000' , 'c' => $dom [ $key ][ 'attribute' ][ 'style' ]);
}
// order the css array to account for specificity
$cssordered = array ();
foreach ( $cssarray as $key => $val ) {
$skey = sprintf ( '%04d' , $key );
$cssordered [ $val [ 's' ] . '_' . $skey ] = $val ;
}
// sort selectors alphabetically to account for specificity
ksort ( $cssordered , SORT_STRING );
return array ( $selectors , $cssordered );
}
/**
* Compact CSS data array into single string .
* @ param $css ( array ) array of CSS properties
* @ return string containing merged CSS properties
* @ since 5.9 . 070 ( 2011 - 04 - 19 )
* @ public static
*/
public static function getTagStyleFromCSSarray ( $css ) {
$tagstyle = '' ; // value to be returned
foreach ( $css as $style ) {
// split single css commands
$csscmds = explode ( ';' , $style [ 'c' ]);
foreach ( $csscmds as $cmd ) {
if ( ! empty ( $cmd )) {
$pos = strpos ( $cmd , ':' );
if ( $pos !== false ) {
$cmd = substr ( $cmd , 0 , ( $pos + 1 ));
if ( strpos ( $tagstyle , $cmd ) !== false ) {
// remove duplicate commands (last commands have high priority)
$tagstyle = preg_replace ( '/' . $cmd . '[^;]+/i' , '' , $tagstyle );
}
}
}
}
$tagstyle .= ';' . $style [ 'c' ];
}
// remove multiple semicolons
$tagstyle = preg_replace ( '/[;]+/' , ';' , $tagstyle );
return $tagstyle ;
}
/**
* Returns the Roman representation of an integer number
* @ param $number ( int ) number to convert
* @ return string roman representation of the specified number
* @ since 4.4 . 004 ( 2008 - 12 - 10 )
* @ public static
*/
public static function intToRoman ( $number ) {
$roman = '' ;
while ( $number >= 1000 ) {
$roman .= 'M' ;
$number -= 1000 ;
}
while ( $number >= 900 ) {
$roman .= 'CM' ;
$number -= 900 ;
}
while ( $number >= 500 ) {
$roman .= 'D' ;
$number -= 500 ;
}
while ( $number >= 400 ) {
$roman .= 'CD' ;
$number -= 400 ;
}
while ( $number >= 100 ) {
$roman .= 'C' ;
$number -= 100 ;
}
while ( $number >= 90 ) {
$roman .= 'XC' ;
$number -= 90 ;
}
while ( $number >= 50 ) {
$roman .= 'L' ;
$number -= 50 ;
}
while ( $number >= 40 ) {
$roman .= 'XL' ;
$number -= 40 ;
}
while ( $number >= 10 ) {
$roman .= 'X' ;
$number -= 10 ;
}
while ( $number >= 9 ) {
$roman .= 'IX' ;
$number -= 9 ;
}
while ( $number >= 5 ) {
$roman .= 'V' ;
$number -= 5 ;
}
while ( $number >= 4 ) {
$roman .= 'IV' ;
$number -= 4 ;
}
while ( $number >= 1 ) {
$roman .= 'I' ;
-- $number ;
}
return $roman ;
}
/**
* Find position of last occurrence of a substring in a string
* @ param $haystack ( string ) The string to search in .
* @ param $needle ( string ) substring to search .
* @ param $offset ( int ) May be specified to begin searching an arbitrary number of characters into the string .
* @ return Returns the position where the needle exists . Returns FALSE if the needle was not found .
* @ since 4.8 . 03 8 ( 2010 - 03 - 13 )
* @ public static
*/
public static function revstrpos ( $haystack , $needle , $offset = 0 ) {
$length = strlen ( $haystack );
$offset = ( $offset > 0 ) ? ( $length - $offset ) : abs ( $offset );
$pos = strpos ( strrev ( $haystack ), strrev ( $needle ), $offset );
return ( $pos === false ) ? false : ( $length - $pos - strlen ( $needle ));
}
/**
* Serialize an array of parameters to be used with TCPDF tag in HTML code .
* @ param $pararray ( array ) parameters array
* @ return sting containing serialized data
* @ since 4.9 . 006 ( 2010 - 04 - 02 )
* @ public static
*/
public static function serializeTCPDFtagParameters ( $pararray ) {
return urlencode ( serialize ( $pararray ));
}
/**
* Returns an array of hyphenation patterns .
* @ 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 /
* @ return array of hyphenation patterns
* @ author Nicola Asuni
* @ since 4.9 . 012 ( 2010 - 04 - 12 )
* @ public static
*/
public static function getHyphenPatternsFromTEX ( $file ) {
// TEX patterns are available at:
// http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
$data = file_get_contents ( $file );
$patterns = array ();
// remove comments
$data = preg_replace ( '/\%[^\n]*/' , '' , $data );
// extract the patterns part
preg_match ( '/\\\\patterns\{([^\}]*)\}/i' , $data , $matches );
$data = trim ( substr ( $matches [ 0 ], 10 , - 1 ));
// extract each pattern
$patterns_array = preg_split ( '/[\s]+/' , $data );
// create new language array of patterns
$patterns = array ();
foreach ( $patterns_array as $val ) {
if ( ! TCPDF_STATIC :: empty_string ( $val )) {
$val = trim ( $val );
$val = str_replace ( '\'' , '\\\'' , $val );
$key = preg_replace ( '/[0-9]+/' , '' , $val );
$patterns [ $key ] = $val ;
}
}
return $patterns ;
}
/**
* Get the Path - Painting Operators .
* @ param $style ( string ) Style of rendering . Possible values are :
* < ul >
* < li > S or D : Stroke the path .</ li >
* < li > s or d : Close and stroke the path .</ li >
* < li > f or F : Fill the path , using the nonzero winding number rule to determine the region to fill .</ li >
* < li > f * or F *: Fill the path , using the even - odd rule to determine the region to fill .</ li >
* < 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 >
* < 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 >
* < 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 >
* < 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 >
* < li > CNZ : Clipping mode using the even - odd rule to determine which regions lie inside the clipping path .</ li >
* < li > CEO : Clipping mode using the nonzero winding number rule to determine which regions lie inside the clipping path </ li >
* < li > n : End the path object without filling or stroking it .</ li >
* </ ul >
* @ param $default ( string ) default style
* @ author Nicola Asuni
* @ since 5.0 . 000 ( 2010 - 04 - 30 )
* @ public static
*/
public static function getPathPaintOperator ( $style , $default = 'S' ) {
$op = '' ;
switch ( $style ) {
case 'S' :
case 'D' : {
$op = 'S' ;
break ;
}
case 's' :
case 'd' : {
$op = 's' ;
break ;
}
case 'f' :
case 'F' : {
$op = 'f' ;
break ;
}
case 'f*' :
case 'F*' : {
$op = 'f*' ;
break ;
}
case 'B' :
case 'FD' :
case 'DF' : {
$op = 'B' ;
break ;
}
case 'B*' :
case 'F*D' :
case 'DF*' : {
$op = 'B*' ;
break ;
}
case 'b' :
case 'fd' :
case 'df' : {
$op = 'b' ;
break ;
}
case 'b*' :
case 'f*d' :
case 'df*' : {
$op = 'b*' ;
break ;
}
case 'CNZ' : {
$op = 'W n' ;
break ;
}
case 'CEO' : {
$op = 'W* n' ;
break ;
}
case 'n' : {
$op = 'n' ;
break ;
}
default : {
if ( ! empty ( $default )) {
$op = self :: getPathPaintOperator ( $default , '' );
} else {
$op = '' ;
}
}
}
return $op ;
}
/**
* Get the product of two SVG tranformation matrices
* @ param $ta ( array ) first SVG tranformation matrix
* @ param $tb ( array ) second SVG tranformation matrix
* @ return transformation array
* @ author Nicola Asuni
* @ since 5.0 . 000 ( 2010 - 05 - 02 )
* @ public static
*/
public static function getTransformationMatrixProduct ( $ta , $tb ) {
$tm = array ();
$tm [ 0 ] = ( $ta [ 0 ] * $tb [ 0 ]) + ( $ta [ 2 ] * $tb [ 1 ]);
$tm [ 1 ] = ( $ta [ 1 ] * $tb [ 0 ]) + ( $ta [ 3 ] * $tb [ 1 ]);
$tm [ 2 ] = ( $ta [ 0 ] * $tb [ 2 ]) + ( $ta [ 2 ] * $tb [ 3 ]);
$tm [ 3 ] = ( $ta [ 1 ] * $tb [ 2 ]) + ( $ta [ 3 ] * $tb [ 3 ]);
$tm [ 4 ] = ( $ta [ 0 ] * $tb [ 4 ]) + ( $ta [ 2 ] * $tb [ 5 ]) + $ta [ 4 ];
$tm [ 5 ] = ( $ta [ 1 ] * $tb [ 4 ]) + ( $ta [ 3 ] * $tb [ 5 ]) + $ta [ 5 ];
return $tm ;
}
/**
* Get the tranformation matrix from SVG transform attribute
* @ param $attribute ( string ) transformation
* @ return array of transformations
* @ author Nicola Asuni
* @ since 5.0 . 000 ( 2010 - 05 - 02 )
* @ public static
*/
public static function getSVGTransformMatrix ( $attribute ) {
// identity matrix
$tm = array ( 1 , 0 , 0 , 1 , 0 , 0 );
$transform = array ();
if ( preg_match_all ( '/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si' , $attribute , $transform , PREG_SET_ORDER ) > 0 ) {
foreach ( $transform as $key => $data ) {
if ( ! empty ( $data [ 2 ])) {
$a = 1 ;
$b = 0 ;
$c = 0 ;
$d = 1 ;
$e = 0 ;
$f = 0 ;
$regs = array ();
switch ( $data [ 1 ]) {
case 'matrix' : {
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 )) {
$a = $regs [ 1 ];
$b = $regs [ 2 ];
$c = $regs [ 3 ];
$d = $regs [ 4 ];
$e = $regs [ 5 ];
$f = $regs [ 6 ];
}
break ;
}
case 'translate' : {
if ( preg_match ( '/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si' , $data [ 2 ], $regs )) {
$e = $regs [ 1 ];
$f = $regs [ 2 ];
} elseif ( preg_match ( '/([a-z0-9\-\.]+)/si' , $data [ 2 ], $regs )) {
$e = $regs [ 1 ];
}
break ;
}
case 'scale' : {
if ( preg_match ( '/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si' , $data [ 2 ], $regs )) {
$a = $regs [ 1 ];
$d = $regs [ 2 ];
} elseif ( preg_match ( '/([a-z0-9\-\.]+)/si' , $data [ 2 ], $regs )) {
$a = $regs [ 1 ];
$d = $a ;
}
break ;
}
case 'rotate' : {
if ( preg_match ( '/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si' , $data [ 2 ], $regs )) {
$ang = deg2rad ( $regs [ 1 ]);
$x = $regs [ 2 ];
$y = $regs [ 3 ];
$a = cos ( $ang );
$b = sin ( $ang );
$c = - $b ;
$d = $a ;
$e = ( $x * ( 1 - $a )) - ( $y * $c );
$f = ( $y * ( 1 - $d )) - ( $x * $b );
} elseif ( preg_match ( '/([0-9\-\.]+)/si' , $data [ 2 ], $regs )) {
$ang = deg2rad ( $regs [ 1 ]);
$a = cos ( $ang );
$b = sin ( $ang );
$c = - $b ;
$d = $a ;
$e = 0 ;
$f = 0 ;
}
break ;
}
case 'skewX' : {
if ( preg_match ( '/([0-9\-\.]+)/si' , $data [ 2 ], $regs )) {
$c = tan ( deg2rad ( $regs [ 1 ]));
}
break ;
}
case 'skewY' : {
if ( preg_match ( '/([0-9\-\.]+)/si' , $data [ 2 ], $regs )) {
$b = tan ( deg2rad ( $regs [ 1 ]));
}
break ;
}
}
$tm = self :: getTransformationMatrixProduct ( $tm , array ( $a , $b , $c , $d , $e , $f ));
}
}
}
return $tm ;
}
/**
* Returns the angle in radiants between two vectors
* @ param $x1 ( int ) X coordinate of first vector point
* @ param $y1 ( int ) Y coordinate of first vector point
* @ param $x2 ( int ) X coordinate of second vector point
* @ param $y2 ( int ) Y coordinate of second vector point
* @ author Nicola Asuni
* @ since 5.0 . 000 ( 2010 - 05 - 04 )
* @ public static
*/
public static function getVectorsAngle ( $x1 , $y1 , $x2 , $y2 ) {
$dprod = ( $x1 * $x2 ) + ( $y1 * $y2 );
$dist1 = sqrt (( $x1 * $x1 ) + ( $y1 * $y1 ));
$dist2 = sqrt (( $x2 * $x2 ) + ( $y2 * $y2 ));
$angle = acos ( $dprod / ( $dist1 * $dist2 ));
if ( is_nan ( $angle )) {
$angle = M_PI ;
}
if ((( $x1 * $y2 ) - ( $x2 * $y1 )) < 0 ) {
$angle *= - 1 ;
}
return $angle ;
}
2013-07-18 19:45:24 +00:00
/**
* Split string by a regular expression .
* This is a wrapper for the preg_split function to avoid the bug : https :// bugs . php . net / bug . php ? id = 45850
* @ param $pattern ( string ) The regular expression pattern to search for without the modifiers , as a string .
* @ param $modifiers ( string ) The modifiers part of the pattern ,
* @ param $subject ( string ) The input string .
* @ 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 .
* @ param $flags ( int ) The flags as specified on the preg_split PHP function .
* @ return Returns an array containing substrings of subject split along boundaries matched by pattern . modifier
* @ author Nicola Asuni
2013-08-05 19:34:06 +00:00
* @ since 6.0 . 023
2013-07-18 19:45:24 +00:00
* @ public static
*/
public static function pregSplit ( $pattern , $modifiers , $subject , $limit = NULL , $flags = NULL ) {
// the bug only happens on PHP 5.2 when using the u modifier
if (( strpos ( $modifiers , 'u' ) === FALSE ) OR ( count ( preg_split ( '//u' , " \n \t " , - 1 , PREG_SPLIT_NO_EMPTY )) == 2 )) {
return preg_split ( $pattern . $modifiers , $subject , $limit , $flags );
}
// preg_split is bugged - try alternative solution
$ret = array ();
while (( $nl = strpos ( $subject , " \n " )) !== FALSE ) {
$ret = array_merge ( $ret , preg_split ( $pattern . $modifiers , substr ( $subject , 0 , $nl ), $limit , $flags ));
$ret [] = " \n " ;
$subject = substr ( $subject , ( $nl + 1 ));
}
2013-09-04 18:32:13 +00:00
if ( strlen ( $subject ) > 0 ) {
2013-07-18 19:45:24 +00:00
$ret = array_merge ( $ret , preg_split ( $pattern . $modifiers , $subject , $limit , $flags ));
}
return $ret ;
}
2013-09-04 18:32:13 +00:00
/**
* Reads entire file into a string .
* The file can be also an URL .
* @ param $file ( string ) Name of the file or URL to read .
* @ return The function returns the read data or FALSE on failure .
* @ author Nicola Asuni
* @ since 6.0 . 025
* @ public static
*/
public static function fileGetContents ( $file ) {
// array of possible alternative paths/URLs
$alt = array ( $file );
// replace URL relative path with full real server path
if (( strlen ( $file ) > 1 )
AND ( $file [ 0 ] == '/' )
AND ( $file [ 1 ] != '/' )
AND ! empty ( $_SERVER [ 'DOCUMENT_ROOT' ])
AND ( $_SERVER [ 'DOCUMENT_ROOT' ] != '/' )) {
$findroot = strpos ( $file , $_SERVER [ 'DOCUMENT_ROOT' ]);
if (( $findroot === false ) OR ( $findroot > 1 )) {
if ( substr ( $_SERVER [ 'DOCUMENT_ROOT' ], - 1 ) == '/' ) {
$tmp = substr ( $_SERVER [ 'DOCUMENT_ROOT' ], 0 , - 1 ) . $file ;
} else {
$tmp = $_SERVER [ 'DOCUMENT_ROOT' ] . $file ;
}
$alt [] = htmlspecialchars_decode ( urldecode ( $tmp ));
}
}
// URL mode
$url = $file ;
// check for missing protocol
if ( preg_match ( '%^/{2}%' , $url )) {
if ( preg_match ( '%^([^:]+:)//%i' , K_PATH_URL , $match )) {
$url = $match [ 1 ] . str_replace ( ' ' , '%20' , $url );
$alt [] = $url ;
}
}
$urldata = @ parse_url ( $url );
if ( ! isset ( $urldata [ 'query' ]) OR ( strlen ( $urldata [ 'query' ]) <= 0 )) {
if ( strpos ( $url , K_PATH_URL ) === 0 ) {
// convert URL to full server path
$tmp = str_replace ( K_PATH_URL , K_PATH_MAIN , $url );
$tmp = htmlspecialchars_decode ( urldecode ( $tmp ));
$alt [] = $tmp ;
}
}
foreach ( $alt as $f ) {
$ret = @ file_get_contents ( $f );
if (( $ret === FALSE )
AND ! ini_get ( 'allow_url_fopen' )
AND function_exists ( 'curl_init' )
AND preg_match ( '%^(https?|ftp)://%' , $f )) {
// try to get remote file data using cURL
$cs = curl_init (); // curl session
curl_setopt ( $cs , CURLOPT_URL , $file );
curl_setopt ( $cs , CURLOPT_BINARYTRANSFER , true );
curl_setopt ( $cs , CURLOPT_FAILONERROR , true );
curl_setopt ( $cs , CURLOPT_RETURNTRANSFER , true );
if (( ini_get ( 'open_basedir' ) == '' ) AND ( ! ini_get ( 'safe_mode' ))) {
curl_setopt ( $cs , CURLOPT_FOLLOWLOCATION , true );
}
curl_setopt ( $cs , CURLOPT_CONNECTTIMEOUT , 5 );
curl_setopt ( $cs , CURLOPT_TIMEOUT , 30 );
curl_setopt ( $cs , CURLOPT_SSL_VERIFYPEER , false );
curl_setopt ( $cs , CURLOPT_SSL_VERIFYHOST , false );
curl_setopt ( $cs , CURLOPT_USERAGENT , 'TCPDF' );
$ret = curl_exec ( $cs );
curl_close ( $cs );
}
if ( $ret !== FALSE ) {
break ;
}
}
return $ret ;
}
2013-03-17 14:03:01 +00:00
} // END OF TCPDF_STATIC CLASS
//============================================================+
// END OF FILE
//============================================================+