GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 2.8 ( 7accb9...ab4929 )
by Thorsten
15:19
created
phpmyfaq/inc/libs/tcpdf/include/barcodes/pdf417.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -734,8 +734,8 @@  discard block
 block discarded – undo
734 734
 
735 735
 	/**
736 736
 	 * Returns the error correction level (0-8) to be used
737
-	 * @param $ecl (int) error correction level
738
-	 * @param $numcw (int) number of data codewords
737
+	 * @param integer $ecl (int) error correction level
738
+	 * @param integer $numcw (int) number of data codewords
739 739
 	 * @return int error correction level
740 740
 	 * @protected
741 741
 	 */
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
 	/**
774 774
 	 * Returns the error correction codewords
775 775
 	 * @param $cw (array) array of codewords including Symbol Lenght Descriptor and pad
776
-	 * @param $ecl (int) error correction level 0-8
776
+	 * @param integer $ecl (int) error correction level 0-8
777 777
 	 * @return array of error correction codewords
778 778
 	 * @protected
779 779
 	 */
Please login to merge, or discard this patch.
Indentation   +901 added lines, -901 removed lines patch added patch discarded remove patch
@@ -56,27 +56,27 @@  discard block
 block discarded – undo
56 56
 // definitions
57 57
 if (!defined('PDF417DEFS')) {
58 58
 
59
-	/**
60
-	 * Indicate that definitions for this class are set
61
-	 */
62
-	define('PDF417DEFS', true);
59
+    /**
60
+     * Indicate that definitions for this class are set
61
+     */
62
+    define('PDF417DEFS', true);
63 63
 
64
-	// -----------------------------------------------------
64
+    // -----------------------------------------------------
65 65
 
66
-	/**
67
-	 * Row height respect X dimension of single module
68
-	 */
69
-	define('ROWHEIGHT', 4);
66
+    /**
67
+     * Row height respect X dimension of single module
68
+     */
69
+    define('ROWHEIGHT', 4);
70 70
 
71
-	/**
72
-	 * Horizontal quiet zone in modules
73
-	 */
74
-	define('QUIETH', 2);
71
+    /**
72
+     * Horizontal quiet zone in modules
73
+     */
74
+    define('QUIETH', 2);
75 75
 
76
-	/**
77
-	 * Vertical quiet zone in modules
78
-	 */
79
-	define('QUIETV', 2);
76
+    /**
77
+     * Vertical quiet zone in modules
78
+     */
79
+    define('QUIETV', 2);
80 80
 
81 81
 } // end of definitions
82 82
 
@@ -92,902 +92,902 @@  discard block
 block discarded – undo
92 92
  */
93 93
 class PDF417 {
94 94
 
95
-	/**
96
-	 * Barcode array to be returned which is readable by TCPDF.
97
-	 * @protected
98
-	 */
99
-	protected $barcode_array = array();
95
+    /**
96
+     * Barcode array to be returned which is readable by TCPDF.
97
+     * @protected
98
+     */
99
+    protected $barcode_array = array();
100 100
 
101
-	/**
102
-	 * Start pattern.
103
-	 * @protected
104
-	 */
105
-	protected $start_pattern = '11111111010101000';
101
+    /**
102
+     * Start pattern.
103
+     * @protected
104
+     */
105
+    protected $start_pattern = '11111111010101000';
106 106
 
107
-	/**
108
-	 * Stop pattern.
109
-	 * @protected
110
-	 */
111
-	protected $stop_pattern = '111111101000101001';
107
+    /**
108
+     * Stop pattern.
109
+     * @protected
110
+     */
111
+    protected $stop_pattern = '111111101000101001';
112 112
 
113
-	/**
114
-	 * Array of text Compaction Sub-Modes (values 0xFB - 0xFF are used for submode changers).
115
-	 * @protected
116
-	 */
117
-	protected $textsubmodes = array(
118
-		array(0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x20,0xFD,0xFE,0xFF), // Alpha
119
-		array(0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x20,0xFD,0xFE,0xFF), // Lower
120
-		array(0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x26,0x0d,0x09,0x2c,0x3a,0x23,0x2d,0x2e,0x24,0x2f,0x2b,0x25,0x2a,0x3d,0x5e,0xFB,0x20,0xFD,0xFE,0xFF), // Mixed
121
-		array(0x3b,0x3c,0x3e,0x40,0x5b,0x5c,0x5d,0x5f,0x60,0x7e,0x21,0x0d,0x09,0x2c,0x3a,0x0a,0x2d,0x2e,0x24,0x2f,0x22,0x7c,0x2a,0x28,0x29,0x3f,0x7b,0x7d,0x27,0xFF) // Puntuaction
122
-	);
113
+    /**
114
+     * Array of text Compaction Sub-Modes (values 0xFB - 0xFF are used for submode changers).
115
+     * @protected
116
+     */
117
+    protected $textsubmodes = array(
118
+        array(0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x20,0xFD,0xFE,0xFF), // Alpha
119
+        array(0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x20,0xFD,0xFE,0xFF), // Lower
120
+        array(0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x26,0x0d,0x09,0x2c,0x3a,0x23,0x2d,0x2e,0x24,0x2f,0x2b,0x25,0x2a,0x3d,0x5e,0xFB,0x20,0xFD,0xFE,0xFF), // Mixed
121
+        array(0x3b,0x3c,0x3e,0x40,0x5b,0x5c,0x5d,0x5f,0x60,0x7e,0x21,0x0d,0x09,0x2c,0x3a,0x0a,0x2d,0x2e,0x24,0x2f,0x22,0x7c,0x2a,0x28,0x29,0x3f,0x7b,0x7d,0x27,0xFF) // Puntuaction
122
+    );
123 123
 
124
-	/**
125
-	 * Array of switching codes for Text Compaction Sub-Modes.
126
-	 * @protected
127
-	 */
128
-	protected $textlatch = array(
129
-		'01' => array(27), '02' => array(28), '03' => array(28,25), //
130
-		'10' => array(28,28), '12' => array(28), '13' => array(28,25), //
131
-		'20' => array(28), '21' => array(27), '23' => array(25), //
132
-		'30' => array(29), '31' => array(29,27), '32' => array(29,28) //
133
-	);
124
+    /**
125
+     * Array of switching codes for Text Compaction Sub-Modes.
126
+     * @protected
127
+     */
128
+    protected $textlatch = array(
129
+        '01' => array(27), '02' => array(28), '03' => array(28,25), //
130
+        '10' => array(28,28), '12' => array(28), '13' => array(28,25), //
131
+        '20' => array(28), '21' => array(27), '23' => array(25), //
132
+        '30' => array(29), '31' => array(29,27), '32' => array(29,28) //
133
+    );
134 134
 
135
-	/**
136
-	 * Clusters of codewords (0, 3, 6)<br/>
137
-	 * Values are hex equivalents of binary representation of bars (1 = bar, 0 = space).<br/>
138
-	 * The codewords numbered from 900 to 928 have special meaning, some enable to switch between modes in order to optimise the code:<ul>
139
-	 * <li>900 : Switch to "Text" mode</li>
140
-	 * <li>901 : Switch to "Byte" mode</li>
141
-	 * <li>902 : Switch to "Numeric" mode</li>
142
-	 * <li>903 - 912 : Reserved</li>
143
-	 * <li>913 : Switch to "Octet" only for the next codeword</li>
144
-	 * <li>914 - 920 : Reserved</li>
145
-	 * <li>921 : Initialization</li>
146
-	 * <li>922 : Terminator codeword for Macro PDF control block</li>
147
-	 * <li>923 : Sequence tag to identify the beginning of optional fields in the Macro PDF control block</li>
148
-	 * <li>924 : Switch to "Byte" mode (If the total number of byte is multiple of 6)</li>
149
-	 * <li>925 : Identifier for a user defined Extended Channel Interpretation (ECI)</li>
150
-	 * <li>926 : Identifier for a general purpose ECI format</li>
151
-	 * <li>927 : Identifier for an ECI of a character set or code page</li>
152
-	 * <li>928 : Macro marker codeword to indicate the beginning of a Macro PDF Control Block</li>
153
-	 * </ul>
154
-	 * @protected
155
-	 */
156
-	protected $clusters = array(
157
-		array( // cluster 0 -----------------------------------------------------------------------
158
-			0x1d5c0,0x1eaf0,0x1f57c,0x1d4e0,0x1ea78,0x1f53e,0x1a8c0,0x1d470,0x1a860,0x15040, //  10
159
-			0x1a830,0x15020,0x1adc0,0x1d6f0,0x1eb7c,0x1ace0,0x1d678,0x1eb3e,0x158c0,0x1ac70, //  20
160
-			0x15860,0x15dc0,0x1aef0,0x1d77c,0x15ce0,0x1ae78,0x1d73e,0x15c70,0x1ae3c,0x15ef0, //  30
161
-			0x1af7c,0x15e78,0x1af3e,0x15f7c,0x1f5fa,0x1d2e0,0x1e978,0x1f4be,0x1a4c0,0x1d270, //  40
162
-			0x1e93c,0x1a460,0x1d238,0x14840,0x1a430,0x1d21c,0x14820,0x1a418,0x14810,0x1a6e0, //  50
163
-			0x1d378,0x1e9be,0x14cc0,0x1a670,0x1d33c,0x14c60,0x1a638,0x1d31e,0x14c30,0x1a61c, //  60
164
-			0x14ee0,0x1a778,0x1d3be,0x14e70,0x1a73c,0x14e38,0x1a71e,0x14f78,0x1a7be,0x14f3c, //  70
165
-			0x14f1e,0x1a2c0,0x1d170,0x1e8bc,0x1a260,0x1d138,0x1e89e,0x14440,0x1a230,0x1d11c, //  80
166
-			0x14420,0x1a218,0x14410,0x14408,0x146c0,0x1a370,0x1d1bc,0x14660,0x1a338,0x1d19e, //  90
167
-			0x14630,0x1a31c,0x14618,0x1460c,0x14770,0x1a3bc,0x14738,0x1a39e,0x1471c,0x147bc, // 100
168
-			0x1a160,0x1d0b8,0x1e85e,0x14240,0x1a130,0x1d09c,0x14220,0x1a118,0x1d08e,0x14210, // 110
169
-			0x1a10c,0x14208,0x1a106,0x14360,0x1a1b8,0x1d0de,0x14330,0x1a19c,0x14318,0x1a18e, // 120
170
-			0x1430c,0x14306,0x1a1de,0x1438e,0x14140,0x1a0b0,0x1d05c,0x14120,0x1a098,0x1d04e, // 130
171
-			0x14110,0x1a08c,0x14108,0x1a086,0x14104,0x141b0,0x14198,0x1418c,0x140a0,0x1d02e, // 140
172
-			0x1a04c,0x1a046,0x14082,0x1cae0,0x1e578,0x1f2be,0x194c0,0x1ca70,0x1e53c,0x19460, // 150
173
-			0x1ca38,0x1e51e,0x12840,0x19430,0x12820,0x196e0,0x1cb78,0x1e5be,0x12cc0,0x19670, // 160
174
-			0x1cb3c,0x12c60,0x19638,0x12c30,0x12c18,0x12ee0,0x19778,0x1cbbe,0x12e70,0x1973c, // 170
175
-			0x12e38,0x12e1c,0x12f78,0x197be,0x12f3c,0x12fbe,0x1dac0,0x1ed70,0x1f6bc,0x1da60, // 180
176
-			0x1ed38,0x1f69e,0x1b440,0x1da30,0x1ed1c,0x1b420,0x1da18,0x1ed0e,0x1b410,0x1da0c, // 190
177
-			0x192c0,0x1c970,0x1e4bc,0x1b6c0,0x19260,0x1c938,0x1e49e,0x1b660,0x1db38,0x1ed9e, // 200
178
-			0x16c40,0x12420,0x19218,0x1c90e,0x16c20,0x1b618,0x16c10,0x126c0,0x19370,0x1c9bc, // 210
179
-			0x16ec0,0x12660,0x19338,0x1c99e,0x16e60,0x1b738,0x1db9e,0x16e30,0x12618,0x16e18, // 220
180
-			0x12770,0x193bc,0x16f70,0x12738,0x1939e,0x16f38,0x1b79e,0x16f1c,0x127bc,0x16fbc, // 230
181
-			0x1279e,0x16f9e,0x1d960,0x1ecb8,0x1f65e,0x1b240,0x1d930,0x1ec9c,0x1b220,0x1d918, // 240
182
-			0x1ec8e,0x1b210,0x1d90c,0x1b208,0x1b204,0x19160,0x1c8b8,0x1e45e,0x1b360,0x19130, // 250
183
-			0x1c89c,0x16640,0x12220,0x1d99c,0x1c88e,0x16620,0x12210,0x1910c,0x16610,0x1b30c, // 260
184
-			0x19106,0x12204,0x12360,0x191b8,0x1c8de,0x16760,0x12330,0x1919c,0x16730,0x1b39c, // 270
185
-			0x1918e,0x16718,0x1230c,0x12306,0x123b8,0x191de,0x167b8,0x1239c,0x1679c,0x1238e, // 280
186
-			0x1678e,0x167de,0x1b140,0x1d8b0,0x1ec5c,0x1b120,0x1d898,0x1ec4e,0x1b110,0x1d88c, // 290
187
-			0x1b108,0x1d886,0x1b104,0x1b102,0x12140,0x190b0,0x1c85c,0x16340,0x12120,0x19098, // 300
188
-			0x1c84e,0x16320,0x1b198,0x1d8ce,0x16310,0x12108,0x19086,0x16308,0x1b186,0x16304, // 310
189
-			0x121b0,0x190dc,0x163b0,0x12198,0x190ce,0x16398,0x1b1ce,0x1638c,0x12186,0x16386, // 320
190
-			0x163dc,0x163ce,0x1b0a0,0x1d858,0x1ec2e,0x1b090,0x1d84c,0x1b088,0x1d846,0x1b084, // 330
191
-			0x1b082,0x120a0,0x19058,0x1c82e,0x161a0,0x12090,0x1904c,0x16190,0x1b0cc,0x19046, // 340
192
-			0x16188,0x12084,0x16184,0x12082,0x120d8,0x161d8,0x161cc,0x161c6,0x1d82c,0x1d826, // 350
193
-			0x1b042,0x1902c,0x12048,0x160c8,0x160c4,0x160c2,0x18ac0,0x1c570,0x1e2bc,0x18a60, // 360
194
-			0x1c538,0x11440,0x18a30,0x1c51c,0x11420,0x18a18,0x11410,0x11408,0x116c0,0x18b70, // 370
195
-			0x1c5bc,0x11660,0x18b38,0x1c59e,0x11630,0x18b1c,0x11618,0x1160c,0x11770,0x18bbc, // 380
196
-			0x11738,0x18b9e,0x1171c,0x117bc,0x1179e,0x1cd60,0x1e6b8,0x1f35e,0x19a40,0x1cd30, // 390
197
-			0x1e69c,0x19a20,0x1cd18,0x1e68e,0x19a10,0x1cd0c,0x19a08,0x1cd06,0x18960,0x1c4b8, // 400
198
-			0x1e25e,0x19b60,0x18930,0x1c49c,0x13640,0x11220,0x1cd9c,0x1c48e,0x13620,0x19b18, // 410
199
-			0x1890c,0x13610,0x11208,0x13608,0x11360,0x189b8,0x1c4de,0x13760,0x11330,0x1cdde, // 420
200
-			0x13730,0x19b9c,0x1898e,0x13718,0x1130c,0x1370c,0x113b8,0x189de,0x137b8,0x1139c, // 430
201
-			0x1379c,0x1138e,0x113de,0x137de,0x1dd40,0x1eeb0,0x1f75c,0x1dd20,0x1ee98,0x1f74e, // 440
202
-			0x1dd10,0x1ee8c,0x1dd08,0x1ee86,0x1dd04,0x19940,0x1ccb0,0x1e65c,0x1bb40,0x19920, // 450
203
-			0x1eedc,0x1e64e,0x1bb20,0x1dd98,0x1eece,0x1bb10,0x19908,0x1cc86,0x1bb08,0x1dd86, // 460
204
-			0x19902,0x11140,0x188b0,0x1c45c,0x13340,0x11120,0x18898,0x1c44e,0x17740,0x13320, // 470
205
-			0x19998,0x1ccce,0x17720,0x1bb98,0x1ddce,0x18886,0x17710,0x13308,0x19986,0x17708, // 480
206
-			0x11102,0x111b0,0x188dc,0x133b0,0x11198,0x188ce,0x177b0,0x13398,0x199ce,0x17798, // 490
207
-			0x1bbce,0x11186,0x13386,0x111dc,0x133dc,0x111ce,0x177dc,0x133ce,0x1dca0,0x1ee58, // 500
208
-			0x1f72e,0x1dc90,0x1ee4c,0x1dc88,0x1ee46,0x1dc84,0x1dc82,0x198a0,0x1cc58,0x1e62e, // 510
209
-			0x1b9a0,0x19890,0x1ee6e,0x1b990,0x1dccc,0x1cc46,0x1b988,0x19884,0x1b984,0x19882, // 520
210
-			0x1b982,0x110a0,0x18858,0x1c42e,0x131a0,0x11090,0x1884c,0x173a0,0x13190,0x198cc, // 530
211
-			0x18846,0x17390,0x1b9cc,0x11084,0x17388,0x13184,0x11082,0x13182,0x110d8,0x1886e, // 540
212
-			0x131d8,0x110cc,0x173d8,0x131cc,0x110c6,0x173cc,0x131c6,0x110ee,0x173ee,0x1dc50, // 550
213
-			0x1ee2c,0x1dc48,0x1ee26,0x1dc44,0x1dc42,0x19850,0x1cc2c,0x1b8d0,0x19848,0x1cc26, // 560
214
-			0x1b8c8,0x1dc66,0x1b8c4,0x19842,0x1b8c2,0x11050,0x1882c,0x130d0,0x11048,0x18826, // 570
215
-			0x171d0,0x130c8,0x19866,0x171c8,0x1b8e6,0x11042,0x171c4,0x130c2,0x171c2,0x130ec, // 580
216
-			0x171ec,0x171e6,0x1ee16,0x1dc22,0x1cc16,0x19824,0x19822,0x11028,0x13068,0x170e8, // 590
217
-			0x11022,0x13062,0x18560,0x10a40,0x18530,0x10a20,0x18518,0x1c28e,0x10a10,0x1850c, // 600
218
-			0x10a08,0x18506,0x10b60,0x185b8,0x1c2de,0x10b30,0x1859c,0x10b18,0x1858e,0x10b0c, // 610
219
-			0x10b06,0x10bb8,0x185de,0x10b9c,0x10b8e,0x10bde,0x18d40,0x1c6b0,0x1e35c,0x18d20, // 620
220
-			0x1c698,0x18d10,0x1c68c,0x18d08,0x1c686,0x18d04,0x10940,0x184b0,0x1c25c,0x11b40, // 630
221
-			0x10920,0x1c6dc,0x1c24e,0x11b20,0x18d98,0x1c6ce,0x11b10,0x10908,0x18486,0x11b08, // 640
222
-			0x18d86,0x10902,0x109b0,0x184dc,0x11bb0,0x10998,0x184ce,0x11b98,0x18dce,0x11b8c, // 650
223
-			0x10986,0x109dc,0x11bdc,0x109ce,0x11bce,0x1cea0,0x1e758,0x1f3ae,0x1ce90,0x1e74c, // 660
224
-			0x1ce88,0x1e746,0x1ce84,0x1ce82,0x18ca0,0x1c658,0x19da0,0x18c90,0x1c64c,0x19d90, // 670
225
-			0x1cecc,0x1c646,0x19d88,0x18c84,0x19d84,0x18c82,0x19d82,0x108a0,0x18458,0x119a0, // 680
226
-			0x10890,0x1c66e,0x13ba0,0x11990,0x18ccc,0x18446,0x13b90,0x19dcc,0x10884,0x13b88, // 690
227
-			0x11984,0x10882,0x11982,0x108d8,0x1846e,0x119d8,0x108cc,0x13bd8,0x119cc,0x108c6, // 700
228
-			0x13bcc,0x119c6,0x108ee,0x119ee,0x13bee,0x1ef50,0x1f7ac,0x1ef48,0x1f7a6,0x1ef44, // 710
229
-			0x1ef42,0x1ce50,0x1e72c,0x1ded0,0x1ef6c,0x1e726,0x1dec8,0x1ef66,0x1dec4,0x1ce42, // 720
230
-			0x1dec2,0x18c50,0x1c62c,0x19cd0,0x18c48,0x1c626,0x1bdd0,0x19cc8,0x1ce66,0x1bdc8, // 730
231
-			0x1dee6,0x18c42,0x1bdc4,0x19cc2,0x1bdc2,0x10850,0x1842c,0x118d0,0x10848,0x18426, // 740
232
-			0x139d0,0x118c8,0x18c66,0x17bd0,0x139c8,0x19ce6,0x10842,0x17bc8,0x1bde6,0x118c2, // 750
233
-			0x17bc4,0x1086c,0x118ec,0x10866,0x139ec,0x118e6,0x17bec,0x139e6,0x17be6,0x1ef28, // 760
234
-			0x1f796,0x1ef24,0x1ef22,0x1ce28,0x1e716,0x1de68,0x1ef36,0x1de64,0x1ce22,0x1de62, // 770
235
-			0x18c28,0x1c616,0x19c68,0x18c24,0x1bce8,0x19c64,0x18c22,0x1bce4,0x19c62,0x1bce2, // 780
236
-			0x10828,0x18416,0x11868,0x18c36,0x138e8,0x11864,0x10822,0x179e8,0x138e4,0x11862, // 790
237
-			0x179e4,0x138e2,0x179e2,0x11876,0x179f6,0x1ef12,0x1de34,0x1de32,0x19c34,0x1bc74, // 800
238
-			0x1bc72,0x11834,0x13874,0x178f4,0x178f2,0x10540,0x10520,0x18298,0x10510,0x10508, // 810
239
-			0x10504,0x105b0,0x10598,0x1058c,0x10586,0x105dc,0x105ce,0x186a0,0x18690,0x1c34c, // 820
240
-			0x18688,0x1c346,0x18684,0x18682,0x104a0,0x18258,0x10da0,0x186d8,0x1824c,0x10d90, // 830
241
-			0x186cc,0x10d88,0x186c6,0x10d84,0x10482,0x10d82,0x104d8,0x1826e,0x10dd8,0x186ee, // 840
242
-			0x10dcc,0x104c6,0x10dc6,0x104ee,0x10dee,0x1c750,0x1c748,0x1c744,0x1c742,0x18650, // 850
243
-			0x18ed0,0x1c76c,0x1c326,0x18ec8,0x1c766,0x18ec4,0x18642,0x18ec2,0x10450,0x10cd0, // 860
244
-			0x10448,0x18226,0x11dd0,0x10cc8,0x10444,0x11dc8,0x10cc4,0x10442,0x11dc4,0x10cc2, // 870
245
-			0x1046c,0x10cec,0x10466,0x11dec,0x10ce6,0x11de6,0x1e7a8,0x1e7a4,0x1e7a2,0x1c728, // 880
246
-			0x1cf68,0x1e7b6,0x1cf64,0x1c722,0x1cf62,0x18628,0x1c316,0x18e68,0x1c736,0x19ee8, // 890
247
-			0x18e64,0x18622,0x19ee4,0x18e62,0x19ee2,0x10428,0x18216,0x10c68,0x18636,0x11ce8, // 900
248
-			0x10c64,0x10422,0x13de8,0x11ce4,0x10c62,0x13de4,0x11ce2,0x10436,0x10c76,0x11cf6, // 910
249
-			0x13df6,0x1f7d4,0x1f7d2,0x1e794,0x1efb4,0x1e792,0x1efb2,0x1c714,0x1cf34,0x1c712, // 920
250
-			0x1df74,0x1cf32,0x1df72,0x18614,0x18e34,0x18612,0x19e74,0x18e32,0x1bef4),        // 929
251
-		array( // cluster 3 -----------------------------------------------------------------------
252
-			0x1f560,0x1fab8,0x1ea40,0x1f530,0x1fa9c,0x1ea20,0x1f518,0x1fa8e,0x1ea10,0x1f50c, //  10
253
-			0x1ea08,0x1f506,0x1ea04,0x1eb60,0x1f5b8,0x1fade,0x1d640,0x1eb30,0x1f59c,0x1d620, //  20
254
-			0x1eb18,0x1f58e,0x1d610,0x1eb0c,0x1d608,0x1eb06,0x1d604,0x1d760,0x1ebb8,0x1f5de, //  30
255
-			0x1ae40,0x1d730,0x1eb9c,0x1ae20,0x1d718,0x1eb8e,0x1ae10,0x1d70c,0x1ae08,0x1d706, //  40
256
-			0x1ae04,0x1af60,0x1d7b8,0x1ebde,0x15e40,0x1af30,0x1d79c,0x15e20,0x1af18,0x1d78e, //  50
257
-			0x15e10,0x1af0c,0x15e08,0x1af06,0x15f60,0x1afb8,0x1d7de,0x15f30,0x1af9c,0x15f18, //  60
258
-			0x1af8e,0x15f0c,0x15fb8,0x1afde,0x15f9c,0x15f8e,0x1e940,0x1f4b0,0x1fa5c,0x1e920, //  70
259
-			0x1f498,0x1fa4e,0x1e910,0x1f48c,0x1e908,0x1f486,0x1e904,0x1e902,0x1d340,0x1e9b0, //  80
260
-			0x1f4dc,0x1d320,0x1e998,0x1f4ce,0x1d310,0x1e98c,0x1d308,0x1e986,0x1d304,0x1d302, //  90
261
-			0x1a740,0x1d3b0,0x1e9dc,0x1a720,0x1d398,0x1e9ce,0x1a710,0x1d38c,0x1a708,0x1d386, // 100
262
-			0x1a704,0x1a702,0x14f40,0x1a7b0,0x1d3dc,0x14f20,0x1a798,0x1d3ce,0x14f10,0x1a78c, // 110
263
-			0x14f08,0x1a786,0x14f04,0x14fb0,0x1a7dc,0x14f98,0x1a7ce,0x14f8c,0x14f86,0x14fdc, // 120
264
-			0x14fce,0x1e8a0,0x1f458,0x1fa2e,0x1e890,0x1f44c,0x1e888,0x1f446,0x1e884,0x1e882, // 130
265
-			0x1d1a0,0x1e8d8,0x1f46e,0x1d190,0x1e8cc,0x1d188,0x1e8c6,0x1d184,0x1d182,0x1a3a0, // 140
266
-			0x1d1d8,0x1e8ee,0x1a390,0x1d1cc,0x1a388,0x1d1c6,0x1a384,0x1a382,0x147a0,0x1a3d8, // 150
267
-			0x1d1ee,0x14790,0x1a3cc,0x14788,0x1a3c6,0x14784,0x14782,0x147d8,0x1a3ee,0x147cc, // 160
268
-			0x147c6,0x147ee,0x1e850,0x1f42c,0x1e848,0x1f426,0x1e844,0x1e842,0x1d0d0,0x1e86c, // 170
269
-			0x1d0c8,0x1e866,0x1d0c4,0x1d0c2,0x1a1d0,0x1d0ec,0x1a1c8,0x1d0e6,0x1a1c4,0x1a1c2, // 180
270
-			0x143d0,0x1a1ec,0x143c8,0x1a1e6,0x143c4,0x143c2,0x143ec,0x143e6,0x1e828,0x1f416, // 190
271
-			0x1e824,0x1e822,0x1d068,0x1e836,0x1d064,0x1d062,0x1a0e8,0x1d076,0x1a0e4,0x1a0e2, // 200
272
-			0x141e8,0x1a0f6,0x141e4,0x141e2,0x1e814,0x1e812,0x1d034,0x1d032,0x1a074,0x1a072, // 210
273
-			0x1e540,0x1f2b0,0x1f95c,0x1e520,0x1f298,0x1f94e,0x1e510,0x1f28c,0x1e508,0x1f286, // 220
274
-			0x1e504,0x1e502,0x1cb40,0x1e5b0,0x1f2dc,0x1cb20,0x1e598,0x1f2ce,0x1cb10,0x1e58c, // 230
275
-			0x1cb08,0x1e586,0x1cb04,0x1cb02,0x19740,0x1cbb0,0x1e5dc,0x19720,0x1cb98,0x1e5ce, // 240
276
-			0x19710,0x1cb8c,0x19708,0x1cb86,0x19704,0x19702,0x12f40,0x197b0,0x1cbdc,0x12f20, // 250
277
-			0x19798,0x1cbce,0x12f10,0x1978c,0x12f08,0x19786,0x12f04,0x12fb0,0x197dc,0x12f98, // 260
278
-			0x197ce,0x12f8c,0x12f86,0x12fdc,0x12fce,0x1f6a0,0x1fb58,0x16bf0,0x1f690,0x1fb4c, // 270
279
-			0x169f8,0x1f688,0x1fb46,0x168fc,0x1f684,0x1f682,0x1e4a0,0x1f258,0x1f92e,0x1eda0, // 280
280
-			0x1e490,0x1fb6e,0x1ed90,0x1f6cc,0x1f246,0x1ed88,0x1e484,0x1ed84,0x1e482,0x1ed82, // 290
281
-			0x1c9a0,0x1e4d8,0x1f26e,0x1dba0,0x1c990,0x1e4cc,0x1db90,0x1edcc,0x1e4c6,0x1db88, // 300
282
-			0x1c984,0x1db84,0x1c982,0x1db82,0x193a0,0x1c9d8,0x1e4ee,0x1b7a0,0x19390,0x1c9cc, // 310
283
-			0x1b790,0x1dbcc,0x1c9c6,0x1b788,0x19384,0x1b784,0x19382,0x1b782,0x127a0,0x193d8, // 320
284
-			0x1c9ee,0x16fa0,0x12790,0x193cc,0x16f90,0x1b7cc,0x193c6,0x16f88,0x12784,0x16f84, // 330
285
-			0x12782,0x127d8,0x193ee,0x16fd8,0x127cc,0x16fcc,0x127c6,0x16fc6,0x127ee,0x1f650, // 340
286
-			0x1fb2c,0x165f8,0x1f648,0x1fb26,0x164fc,0x1f644,0x1647e,0x1f642,0x1e450,0x1f22c, // 350
287
-			0x1ecd0,0x1e448,0x1f226,0x1ecc8,0x1f666,0x1ecc4,0x1e442,0x1ecc2,0x1c8d0,0x1e46c, // 360
288
-			0x1d9d0,0x1c8c8,0x1e466,0x1d9c8,0x1ece6,0x1d9c4,0x1c8c2,0x1d9c2,0x191d0,0x1c8ec, // 370
289
-			0x1b3d0,0x191c8,0x1c8e6,0x1b3c8,0x1d9e6,0x1b3c4,0x191c2,0x1b3c2,0x123d0,0x191ec, // 380
290
-			0x167d0,0x123c8,0x191e6,0x167c8,0x1b3e6,0x167c4,0x123c2,0x167c2,0x123ec,0x167ec, // 390
291
-			0x123e6,0x167e6,0x1f628,0x1fb16,0x162fc,0x1f624,0x1627e,0x1f622,0x1e428,0x1f216, // 400
292
-			0x1ec68,0x1f636,0x1ec64,0x1e422,0x1ec62,0x1c868,0x1e436,0x1d8e8,0x1c864,0x1d8e4, // 410
293
-			0x1c862,0x1d8e2,0x190e8,0x1c876,0x1b1e8,0x1d8f6,0x1b1e4,0x190e2,0x1b1e2,0x121e8, // 420
294
-			0x190f6,0x163e8,0x121e4,0x163e4,0x121e2,0x163e2,0x121f6,0x163f6,0x1f614,0x1617e, // 430
295
-			0x1f612,0x1e414,0x1ec34,0x1e412,0x1ec32,0x1c834,0x1d874,0x1c832,0x1d872,0x19074, // 440
296
-			0x1b0f4,0x19072,0x1b0f2,0x120f4,0x161f4,0x120f2,0x161f2,0x1f60a,0x1e40a,0x1ec1a, // 450
297
-			0x1c81a,0x1d83a,0x1903a,0x1b07a,0x1e2a0,0x1f158,0x1f8ae,0x1e290,0x1f14c,0x1e288, // 460
298
-			0x1f146,0x1e284,0x1e282,0x1c5a0,0x1e2d8,0x1f16e,0x1c590,0x1e2cc,0x1c588,0x1e2c6, // 470
299
-			0x1c584,0x1c582,0x18ba0,0x1c5d8,0x1e2ee,0x18b90,0x1c5cc,0x18b88,0x1c5c6,0x18b84, // 480
300
-			0x18b82,0x117a0,0x18bd8,0x1c5ee,0x11790,0x18bcc,0x11788,0x18bc6,0x11784,0x11782, // 490
301
-			0x117d8,0x18bee,0x117cc,0x117c6,0x117ee,0x1f350,0x1f9ac,0x135f8,0x1f348,0x1f9a6, // 500
302
-			0x134fc,0x1f344,0x1347e,0x1f342,0x1e250,0x1f12c,0x1e6d0,0x1e248,0x1f126,0x1e6c8, // 510
303
-			0x1f366,0x1e6c4,0x1e242,0x1e6c2,0x1c4d0,0x1e26c,0x1cdd0,0x1c4c8,0x1e266,0x1cdc8, // 520
304
-			0x1e6e6,0x1cdc4,0x1c4c2,0x1cdc2,0x189d0,0x1c4ec,0x19bd0,0x189c8,0x1c4e6,0x19bc8, // 530
305
-			0x1cde6,0x19bc4,0x189c2,0x19bc2,0x113d0,0x189ec,0x137d0,0x113c8,0x189e6,0x137c8, // 540
306
-			0x19be6,0x137c4,0x113c2,0x137c2,0x113ec,0x137ec,0x113e6,0x137e6,0x1fba8,0x175f0, // 550
307
-			0x1bafc,0x1fba4,0x174f8,0x1ba7e,0x1fba2,0x1747c,0x1743e,0x1f328,0x1f996,0x132fc, // 560
308
-			0x1f768,0x1fbb6,0x176fc,0x1327e,0x1f764,0x1f322,0x1767e,0x1f762,0x1e228,0x1f116, // 570
309
-			0x1e668,0x1e224,0x1eee8,0x1f776,0x1e222,0x1eee4,0x1e662,0x1eee2,0x1c468,0x1e236, // 580
310
-			0x1cce8,0x1c464,0x1dde8,0x1cce4,0x1c462,0x1dde4,0x1cce2,0x1dde2,0x188e8,0x1c476, // 590
311
-			0x199e8,0x188e4,0x1bbe8,0x199e4,0x188e2,0x1bbe4,0x199e2,0x1bbe2,0x111e8,0x188f6, // 600
312
-			0x133e8,0x111e4,0x177e8,0x133e4,0x111e2,0x177e4,0x133e2,0x177e2,0x111f6,0x133f6, // 610
313
-			0x1fb94,0x172f8,0x1b97e,0x1fb92,0x1727c,0x1723e,0x1f314,0x1317e,0x1f734,0x1f312, // 620
314
-			0x1737e,0x1f732,0x1e214,0x1e634,0x1e212,0x1ee74,0x1e632,0x1ee72,0x1c434,0x1cc74, // 630
315
-			0x1c432,0x1dcf4,0x1cc72,0x1dcf2,0x18874,0x198f4,0x18872,0x1b9f4,0x198f2,0x1b9f2, // 640
316
-			0x110f4,0x131f4,0x110f2,0x173f4,0x131f2,0x173f2,0x1fb8a,0x1717c,0x1713e,0x1f30a, // 650
317
-			0x1f71a,0x1e20a,0x1e61a,0x1ee3a,0x1c41a,0x1cc3a,0x1dc7a,0x1883a,0x1987a,0x1b8fa, // 660
318
-			0x1107a,0x130fa,0x171fa,0x170be,0x1e150,0x1f0ac,0x1e148,0x1f0a6,0x1e144,0x1e142, // 670
319
-			0x1c2d0,0x1e16c,0x1c2c8,0x1e166,0x1c2c4,0x1c2c2,0x185d0,0x1c2ec,0x185c8,0x1c2e6, // 680
320
-			0x185c4,0x185c2,0x10bd0,0x185ec,0x10bc8,0x185e6,0x10bc4,0x10bc2,0x10bec,0x10be6, // 690
321
-			0x1f1a8,0x1f8d6,0x11afc,0x1f1a4,0x11a7e,0x1f1a2,0x1e128,0x1f096,0x1e368,0x1e124, // 700
322
-			0x1e364,0x1e122,0x1e362,0x1c268,0x1e136,0x1c6e8,0x1c264,0x1c6e4,0x1c262,0x1c6e2, // 710
323
-			0x184e8,0x1c276,0x18de8,0x184e4,0x18de4,0x184e2,0x18de2,0x109e8,0x184f6,0x11be8, // 720
324
-			0x109e4,0x11be4,0x109e2,0x11be2,0x109f6,0x11bf6,0x1f9d4,0x13af8,0x19d7e,0x1f9d2, // 730
325
-			0x13a7c,0x13a3e,0x1f194,0x1197e,0x1f3b4,0x1f192,0x13b7e,0x1f3b2,0x1e114,0x1e334, // 740
326
-			0x1e112,0x1e774,0x1e332,0x1e772,0x1c234,0x1c674,0x1c232,0x1cef4,0x1c672,0x1cef2, // 750
327
-			0x18474,0x18cf4,0x18472,0x19df4,0x18cf2,0x19df2,0x108f4,0x119f4,0x108f2,0x13bf4, // 760
328
-			0x119f2,0x13bf2,0x17af0,0x1bd7c,0x17a78,0x1bd3e,0x17a3c,0x17a1e,0x1f9ca,0x1397c, // 770
329
-			0x1fbda,0x17b7c,0x1393e,0x17b3e,0x1f18a,0x1f39a,0x1f7ba,0x1e10a,0x1e31a,0x1e73a, // 780
330
-			0x1ef7a,0x1c21a,0x1c63a,0x1ce7a,0x1defa,0x1843a,0x18c7a,0x19cfa,0x1bdfa,0x1087a, // 790
331
-			0x118fa,0x139fa,0x17978,0x1bcbe,0x1793c,0x1791e,0x138be,0x179be,0x178bc,0x1789e, // 800
332
-			0x1785e,0x1e0a8,0x1e0a4,0x1e0a2,0x1c168,0x1e0b6,0x1c164,0x1c162,0x182e8,0x1c176, // 810
333
-			0x182e4,0x182e2,0x105e8,0x182f6,0x105e4,0x105e2,0x105f6,0x1f0d4,0x10d7e,0x1f0d2, // 820
334
-			0x1e094,0x1e1b4,0x1e092,0x1e1b2,0x1c134,0x1c374,0x1c132,0x1c372,0x18274,0x186f4, // 830
335
-			0x18272,0x186f2,0x104f4,0x10df4,0x104f2,0x10df2,0x1f8ea,0x11d7c,0x11d3e,0x1f0ca, // 840
336
-			0x1f1da,0x1e08a,0x1e19a,0x1e3ba,0x1c11a,0x1c33a,0x1c77a,0x1823a,0x1867a,0x18efa, // 850
337
-			0x1047a,0x10cfa,0x11dfa,0x13d78,0x19ebe,0x13d3c,0x13d1e,0x11cbe,0x13dbe,0x17d70, // 860
338
-			0x1bebc,0x17d38,0x1be9e,0x17d1c,0x17d0e,0x13cbc,0x17dbc,0x13c9e,0x17d9e,0x17cb8, // 870
339
-			0x1be5e,0x17c9c,0x17c8e,0x13c5e,0x17cde,0x17c5c,0x17c4e,0x17c2e,0x1c0b4,0x1c0b2, // 880
340
-			0x18174,0x18172,0x102f4,0x102f2,0x1e0da,0x1c09a,0x1c1ba,0x1813a,0x1837a,0x1027a, // 890
341
-			0x106fa,0x10ebe,0x11ebc,0x11e9e,0x13eb8,0x19f5e,0x13e9c,0x13e8e,0x11e5e,0x13ede, // 900
342
-			0x17eb0,0x1bf5c,0x17e98,0x1bf4e,0x17e8c,0x17e86,0x13e5c,0x17edc,0x13e4e,0x17ece, // 910
343
-			0x17e58,0x1bf2e,0x17e4c,0x17e46,0x13e2e,0x17e6e,0x17e2c,0x17e26,0x10f5e,0x11f5c, // 920
344
-			0x11f4e,0x13f58,0x19fae,0x13f4c,0x13f46,0x11f2e,0x13f6e,0x13f2c,0x13f26),        // 929
345
-		array( // cluster 6 -----------------------------------------------------------------------
346
-			0x1abe0,0x1d5f8,0x153c0,0x1a9f0,0x1d4fc,0x151e0,0x1a8f8,0x1d47e,0x150f0,0x1a87c, //  10
347
-			0x15078,0x1fad0,0x15be0,0x1adf8,0x1fac8,0x159f0,0x1acfc,0x1fac4,0x158f8,0x1ac7e, //  20
348
-			0x1fac2,0x1587c,0x1f5d0,0x1faec,0x15df8,0x1f5c8,0x1fae6,0x15cfc,0x1f5c4,0x15c7e, //  30
349
-			0x1f5c2,0x1ebd0,0x1f5ec,0x1ebc8,0x1f5e6,0x1ebc4,0x1ebc2,0x1d7d0,0x1ebec,0x1d7c8, //  40
350
-			0x1ebe6,0x1d7c4,0x1d7c2,0x1afd0,0x1d7ec,0x1afc8,0x1d7e6,0x1afc4,0x14bc0,0x1a5f0, //  50
351
-			0x1d2fc,0x149e0,0x1a4f8,0x1d27e,0x148f0,0x1a47c,0x14878,0x1a43e,0x1483c,0x1fa68, //  60
352
-			0x14df0,0x1a6fc,0x1fa64,0x14cf8,0x1a67e,0x1fa62,0x14c7c,0x14c3e,0x1f4e8,0x1fa76, //  70
353
-			0x14efc,0x1f4e4,0x14e7e,0x1f4e2,0x1e9e8,0x1f4f6,0x1e9e4,0x1e9e2,0x1d3e8,0x1e9f6, //  80
354
-			0x1d3e4,0x1d3e2,0x1a7e8,0x1d3f6,0x1a7e4,0x1a7e2,0x145e0,0x1a2f8,0x1d17e,0x144f0, //  90
355
-			0x1a27c,0x14478,0x1a23e,0x1443c,0x1441e,0x1fa34,0x146f8,0x1a37e,0x1fa32,0x1467c, // 100
356
-			0x1463e,0x1f474,0x1477e,0x1f472,0x1e8f4,0x1e8f2,0x1d1f4,0x1d1f2,0x1a3f4,0x1a3f2, // 110
357
-			0x142f0,0x1a17c,0x14278,0x1a13e,0x1423c,0x1421e,0x1fa1a,0x1437c,0x1433e,0x1f43a, // 120
358
-			0x1e87a,0x1d0fa,0x14178,0x1a0be,0x1413c,0x1411e,0x141be,0x140bc,0x1409e,0x12bc0, // 130
359
-			0x195f0,0x1cafc,0x129e0,0x194f8,0x1ca7e,0x128f0,0x1947c,0x12878,0x1943e,0x1283c, // 140
360
-			0x1f968,0x12df0,0x196fc,0x1f964,0x12cf8,0x1967e,0x1f962,0x12c7c,0x12c3e,0x1f2e8, // 150
361
-			0x1f976,0x12efc,0x1f2e4,0x12e7e,0x1f2e2,0x1e5e8,0x1f2f6,0x1e5e4,0x1e5e2,0x1cbe8, // 160
362
-			0x1e5f6,0x1cbe4,0x1cbe2,0x197e8,0x1cbf6,0x197e4,0x197e2,0x1b5e0,0x1daf8,0x1ed7e, // 170
363
-			0x169c0,0x1b4f0,0x1da7c,0x168e0,0x1b478,0x1da3e,0x16870,0x1b43c,0x16838,0x1b41e, // 180
364
-			0x1681c,0x125e0,0x192f8,0x1c97e,0x16de0,0x124f0,0x1927c,0x16cf0,0x1b67c,0x1923e, // 190
365
-			0x16c78,0x1243c,0x16c3c,0x1241e,0x16c1e,0x1f934,0x126f8,0x1937e,0x1fb74,0x1f932, // 200
366
-			0x16ef8,0x1267c,0x1fb72,0x16e7c,0x1263e,0x16e3e,0x1f274,0x1277e,0x1f6f4,0x1f272, // 210
367
-			0x16f7e,0x1f6f2,0x1e4f4,0x1edf4,0x1e4f2,0x1edf2,0x1c9f4,0x1dbf4,0x1c9f2,0x1dbf2, // 220
368
-			0x193f4,0x193f2,0x165c0,0x1b2f0,0x1d97c,0x164e0,0x1b278,0x1d93e,0x16470,0x1b23c, // 230
369
-			0x16438,0x1b21e,0x1641c,0x1640e,0x122f0,0x1917c,0x166f0,0x12278,0x1913e,0x16678, // 240
370
-			0x1b33e,0x1663c,0x1221e,0x1661e,0x1f91a,0x1237c,0x1fb3a,0x1677c,0x1233e,0x1673e, // 250
371
-			0x1f23a,0x1f67a,0x1e47a,0x1ecfa,0x1c8fa,0x1d9fa,0x191fa,0x162e0,0x1b178,0x1d8be, // 260
372
-			0x16270,0x1b13c,0x16238,0x1b11e,0x1621c,0x1620e,0x12178,0x190be,0x16378,0x1213c, // 270
373
-			0x1633c,0x1211e,0x1631e,0x121be,0x163be,0x16170,0x1b0bc,0x16138,0x1b09e,0x1611c, // 280
374
-			0x1610e,0x120bc,0x161bc,0x1209e,0x1619e,0x160b8,0x1b05e,0x1609c,0x1608e,0x1205e, // 290
375
-			0x160de,0x1605c,0x1604e,0x115e0,0x18af8,0x1c57e,0x114f0,0x18a7c,0x11478,0x18a3e, // 300
376
-			0x1143c,0x1141e,0x1f8b4,0x116f8,0x18b7e,0x1f8b2,0x1167c,0x1163e,0x1f174,0x1177e, // 310
377
-			0x1f172,0x1e2f4,0x1e2f2,0x1c5f4,0x1c5f2,0x18bf4,0x18bf2,0x135c0,0x19af0,0x1cd7c, // 320
378
-			0x134e0,0x19a78,0x1cd3e,0x13470,0x19a3c,0x13438,0x19a1e,0x1341c,0x1340e,0x112f0, // 330
379
-			0x1897c,0x136f0,0x11278,0x1893e,0x13678,0x19b3e,0x1363c,0x1121e,0x1361e,0x1f89a, // 340
380
-			0x1137c,0x1f9ba,0x1377c,0x1133e,0x1373e,0x1f13a,0x1f37a,0x1e27a,0x1e6fa,0x1c4fa, // 350
381
-			0x1cdfa,0x189fa,0x1bae0,0x1dd78,0x1eebe,0x174c0,0x1ba70,0x1dd3c,0x17460,0x1ba38, // 360
382
-			0x1dd1e,0x17430,0x1ba1c,0x17418,0x1ba0e,0x1740c,0x132e0,0x19978,0x1ccbe,0x176e0, // 370
383
-			0x13270,0x1993c,0x17670,0x1bb3c,0x1991e,0x17638,0x1321c,0x1761c,0x1320e,0x1760e, // 380
384
-			0x11178,0x188be,0x13378,0x1113c,0x17778,0x1333c,0x1111e,0x1773c,0x1331e,0x1771e, // 390
385
-			0x111be,0x133be,0x177be,0x172c0,0x1b970,0x1dcbc,0x17260,0x1b938,0x1dc9e,0x17230, // 400
386
-			0x1b91c,0x17218,0x1b90e,0x1720c,0x17206,0x13170,0x198bc,0x17370,0x13138,0x1989e, // 410
387
-			0x17338,0x1b99e,0x1731c,0x1310e,0x1730e,0x110bc,0x131bc,0x1109e,0x173bc,0x1319e, // 420
388
-			0x1739e,0x17160,0x1b8b8,0x1dc5e,0x17130,0x1b89c,0x17118,0x1b88e,0x1710c,0x17106, // 430
389
-			0x130b8,0x1985e,0x171b8,0x1309c,0x1719c,0x1308e,0x1718e,0x1105e,0x130de,0x171de, // 440
390
-			0x170b0,0x1b85c,0x17098,0x1b84e,0x1708c,0x17086,0x1305c,0x170dc,0x1304e,0x170ce, // 450
391
-			0x17058,0x1b82e,0x1704c,0x17046,0x1302e,0x1706e,0x1702c,0x17026,0x10af0,0x1857c, // 460
392
-			0x10a78,0x1853e,0x10a3c,0x10a1e,0x10b7c,0x10b3e,0x1f0ba,0x1e17a,0x1c2fa,0x185fa, // 470
393
-			0x11ae0,0x18d78,0x1c6be,0x11a70,0x18d3c,0x11a38,0x18d1e,0x11a1c,0x11a0e,0x10978, // 480
394
-			0x184be,0x11b78,0x1093c,0x11b3c,0x1091e,0x11b1e,0x109be,0x11bbe,0x13ac0,0x19d70, // 490
395
-			0x1cebc,0x13a60,0x19d38,0x1ce9e,0x13a30,0x19d1c,0x13a18,0x19d0e,0x13a0c,0x13a06, // 500
396
-			0x11970,0x18cbc,0x13b70,0x11938,0x18c9e,0x13b38,0x1191c,0x13b1c,0x1190e,0x13b0e, // 510
397
-			0x108bc,0x119bc,0x1089e,0x13bbc,0x1199e,0x13b9e,0x1bd60,0x1deb8,0x1ef5e,0x17a40, // 520
398
-			0x1bd30,0x1de9c,0x17a20,0x1bd18,0x1de8e,0x17a10,0x1bd0c,0x17a08,0x1bd06,0x17a04, // 530
399
-			0x13960,0x19cb8,0x1ce5e,0x17b60,0x13930,0x19c9c,0x17b30,0x1bd9c,0x19c8e,0x17b18, // 540
400
-			0x1390c,0x17b0c,0x13906,0x17b06,0x118b8,0x18c5e,0x139b8,0x1189c,0x17bb8,0x1399c, // 550
401
-			0x1188e,0x17b9c,0x1398e,0x17b8e,0x1085e,0x118de,0x139de,0x17bde,0x17940,0x1bcb0, // 560
402
-			0x1de5c,0x17920,0x1bc98,0x1de4e,0x17910,0x1bc8c,0x17908,0x1bc86,0x17904,0x17902, // 570
403
-			0x138b0,0x19c5c,0x179b0,0x13898,0x19c4e,0x17998,0x1bcce,0x1798c,0x13886,0x17986, // 580
404
-			0x1185c,0x138dc,0x1184e,0x179dc,0x138ce,0x179ce,0x178a0,0x1bc58,0x1de2e,0x17890, // 590
405
-			0x1bc4c,0x17888,0x1bc46,0x17884,0x17882,0x13858,0x19c2e,0x178d8,0x1384c,0x178cc, // 600
406
-			0x13846,0x178c6,0x1182e,0x1386e,0x178ee,0x17850,0x1bc2c,0x17848,0x1bc26,0x17844, // 610
407
-			0x17842,0x1382c,0x1786c,0x13826,0x17866,0x17828,0x1bc16,0x17824,0x17822,0x13816, // 620
408
-			0x17836,0x10578,0x182be,0x1053c,0x1051e,0x105be,0x10d70,0x186bc,0x10d38,0x1869e, // 630
409
-			0x10d1c,0x10d0e,0x104bc,0x10dbc,0x1049e,0x10d9e,0x11d60,0x18eb8,0x1c75e,0x11d30, // 640
410
-			0x18e9c,0x11d18,0x18e8e,0x11d0c,0x11d06,0x10cb8,0x1865e,0x11db8,0x10c9c,0x11d9c, // 650
411
-			0x10c8e,0x11d8e,0x1045e,0x10cde,0x11dde,0x13d40,0x19eb0,0x1cf5c,0x13d20,0x19e98, // 660
412
-			0x1cf4e,0x13d10,0x19e8c,0x13d08,0x19e86,0x13d04,0x13d02,0x11cb0,0x18e5c,0x13db0, // 670
413
-			0x11c98,0x18e4e,0x13d98,0x19ece,0x13d8c,0x11c86,0x13d86,0x10c5c,0x11cdc,0x10c4e, // 680
414
-			0x13ddc,0x11cce,0x13dce,0x1bea0,0x1df58,0x1efae,0x1be90,0x1df4c,0x1be88,0x1df46, // 690
415
-			0x1be84,0x1be82,0x13ca0,0x19e58,0x1cf2e,0x17da0,0x13c90,0x19e4c,0x17d90,0x1becc, // 700
416
-			0x19e46,0x17d88,0x13c84,0x17d84,0x13c82,0x17d82,0x11c58,0x18e2e,0x13cd8,0x11c4c, // 710
417
-			0x17dd8,0x13ccc,0x11c46,0x17dcc,0x13cc6,0x17dc6,0x10c2e,0x11c6e,0x13cee,0x17dee, // 720
418
-			0x1be50,0x1df2c,0x1be48,0x1df26,0x1be44,0x1be42,0x13c50,0x19e2c,0x17cd0,0x13c48, // 730
419
-			0x19e26,0x17cc8,0x1be66,0x17cc4,0x13c42,0x17cc2,0x11c2c,0x13c6c,0x11c26,0x17cec, // 740
420
-			0x13c66,0x17ce6,0x1be28,0x1df16,0x1be24,0x1be22,0x13c28,0x19e16,0x17c68,0x13c24, // 750
421
-			0x17c64,0x13c22,0x17c62,0x11c16,0x13c36,0x17c76,0x1be14,0x1be12,0x13c14,0x17c34, // 760
422
-			0x13c12,0x17c32,0x102bc,0x1029e,0x106b8,0x1835e,0x1069c,0x1068e,0x1025e,0x106de, // 770
423
-			0x10eb0,0x1875c,0x10e98,0x1874e,0x10e8c,0x10e86,0x1065c,0x10edc,0x1064e,0x10ece, // 780
424
-			0x11ea0,0x18f58,0x1c7ae,0x11e90,0x18f4c,0x11e88,0x18f46,0x11e84,0x11e82,0x10e58, // 790
425
-			0x1872e,0x11ed8,0x18f6e,0x11ecc,0x10e46,0x11ec6,0x1062e,0x10e6e,0x11eee,0x19f50, // 800
426
-			0x1cfac,0x19f48,0x1cfa6,0x19f44,0x19f42,0x11e50,0x18f2c,0x13ed0,0x19f6c,0x18f26, // 810
427
-			0x13ec8,0x11e44,0x13ec4,0x11e42,0x13ec2,0x10e2c,0x11e6c,0x10e26,0x13eec,0x11e66, // 820
428
-			0x13ee6,0x1dfa8,0x1efd6,0x1dfa4,0x1dfa2,0x19f28,0x1cf96,0x1bf68,0x19f24,0x1bf64, // 830
429
-			0x19f22,0x1bf62,0x11e28,0x18f16,0x13e68,0x11e24,0x17ee8,0x13e64,0x11e22,0x17ee4, // 840
430
-			0x13e62,0x17ee2,0x10e16,0x11e36,0x13e76,0x17ef6,0x1df94,0x1df92,0x19f14,0x1bf34, // 850
431
-			0x19f12,0x1bf32,0x11e14,0x13e34,0x11e12,0x17e74,0x13e32,0x17e72,0x1df8a,0x19f0a, // 860
432
-			0x1bf1a,0x11e0a,0x13e1a,0x17e3a,0x1035c,0x1034e,0x10758,0x183ae,0x1074c,0x10746, // 870
433
-			0x1032e,0x1076e,0x10f50,0x187ac,0x10f48,0x187a6,0x10f44,0x10f42,0x1072c,0x10f6c, // 880
434
-			0x10726,0x10f66,0x18fa8,0x1c7d6,0x18fa4,0x18fa2,0x10f28,0x18796,0x11f68,0x18fb6, // 890
435
-			0x11f64,0x10f22,0x11f62,0x10716,0x10f36,0x11f76,0x1cfd4,0x1cfd2,0x18f94,0x19fb4, // 900
436
-			0x18f92,0x19fb2,0x10f14,0x11f34,0x10f12,0x13f74,0x11f32,0x13f72,0x1cfca,0x18f8a, // 910
437
-			0x19f9a,0x10f0a,0x11f1a,0x13f3a,0x103ac,0x103a6,0x107a8,0x183d6,0x107a4,0x107a2, // 920
438
-			0x10396,0x107b6,0x187d4,0x187d2,0x10794,0x10fb4,0x10792,0x10fb2,0x1c7ea)         // 929
439
-	); // end of $clusters array
135
+    /**
136
+     * Clusters of codewords (0, 3, 6)<br/>
137
+     * Values are hex equivalents of binary representation of bars (1 = bar, 0 = space).<br/>
138
+     * The codewords numbered from 900 to 928 have special meaning, some enable to switch between modes in order to optimise the code:<ul>
139
+     * <li>900 : Switch to "Text" mode</li>
140
+     * <li>901 : Switch to "Byte" mode</li>
141
+     * <li>902 : Switch to "Numeric" mode</li>
142
+     * <li>903 - 912 : Reserved</li>
143
+     * <li>913 : Switch to "Octet" only for the next codeword</li>
144
+     * <li>914 - 920 : Reserved</li>
145
+     * <li>921 : Initialization</li>
146
+     * <li>922 : Terminator codeword for Macro PDF control block</li>
147
+     * <li>923 : Sequence tag to identify the beginning of optional fields in the Macro PDF control block</li>
148
+     * <li>924 : Switch to "Byte" mode (If the total number of byte is multiple of 6)</li>
149
+     * <li>925 : Identifier for a user defined Extended Channel Interpretation (ECI)</li>
150
+     * <li>926 : Identifier for a general purpose ECI format</li>
151
+     * <li>927 : Identifier for an ECI of a character set or code page</li>
152
+     * <li>928 : Macro marker codeword to indicate the beginning of a Macro PDF Control Block</li>
153
+     * </ul>
154
+     * @protected
155
+     */
156
+    protected $clusters = array(
157
+        array( // cluster 0 -----------------------------------------------------------------------
158
+            0x1d5c0,0x1eaf0,0x1f57c,0x1d4e0,0x1ea78,0x1f53e,0x1a8c0,0x1d470,0x1a860,0x15040, //  10
159
+            0x1a830,0x15020,0x1adc0,0x1d6f0,0x1eb7c,0x1ace0,0x1d678,0x1eb3e,0x158c0,0x1ac70, //  20
160
+            0x15860,0x15dc0,0x1aef0,0x1d77c,0x15ce0,0x1ae78,0x1d73e,0x15c70,0x1ae3c,0x15ef0, //  30
161
+            0x1af7c,0x15e78,0x1af3e,0x15f7c,0x1f5fa,0x1d2e0,0x1e978,0x1f4be,0x1a4c0,0x1d270, //  40
162
+            0x1e93c,0x1a460,0x1d238,0x14840,0x1a430,0x1d21c,0x14820,0x1a418,0x14810,0x1a6e0, //  50
163
+            0x1d378,0x1e9be,0x14cc0,0x1a670,0x1d33c,0x14c60,0x1a638,0x1d31e,0x14c30,0x1a61c, //  60
164
+            0x14ee0,0x1a778,0x1d3be,0x14e70,0x1a73c,0x14e38,0x1a71e,0x14f78,0x1a7be,0x14f3c, //  70
165
+            0x14f1e,0x1a2c0,0x1d170,0x1e8bc,0x1a260,0x1d138,0x1e89e,0x14440,0x1a230,0x1d11c, //  80
166
+            0x14420,0x1a218,0x14410,0x14408,0x146c0,0x1a370,0x1d1bc,0x14660,0x1a338,0x1d19e, //  90
167
+            0x14630,0x1a31c,0x14618,0x1460c,0x14770,0x1a3bc,0x14738,0x1a39e,0x1471c,0x147bc, // 100
168
+            0x1a160,0x1d0b8,0x1e85e,0x14240,0x1a130,0x1d09c,0x14220,0x1a118,0x1d08e,0x14210, // 110
169
+            0x1a10c,0x14208,0x1a106,0x14360,0x1a1b8,0x1d0de,0x14330,0x1a19c,0x14318,0x1a18e, // 120
170
+            0x1430c,0x14306,0x1a1de,0x1438e,0x14140,0x1a0b0,0x1d05c,0x14120,0x1a098,0x1d04e, // 130
171
+            0x14110,0x1a08c,0x14108,0x1a086,0x14104,0x141b0,0x14198,0x1418c,0x140a0,0x1d02e, // 140
172
+            0x1a04c,0x1a046,0x14082,0x1cae0,0x1e578,0x1f2be,0x194c0,0x1ca70,0x1e53c,0x19460, // 150
173
+            0x1ca38,0x1e51e,0x12840,0x19430,0x12820,0x196e0,0x1cb78,0x1e5be,0x12cc0,0x19670, // 160
174
+            0x1cb3c,0x12c60,0x19638,0x12c30,0x12c18,0x12ee0,0x19778,0x1cbbe,0x12e70,0x1973c, // 170
175
+            0x12e38,0x12e1c,0x12f78,0x197be,0x12f3c,0x12fbe,0x1dac0,0x1ed70,0x1f6bc,0x1da60, // 180
176
+            0x1ed38,0x1f69e,0x1b440,0x1da30,0x1ed1c,0x1b420,0x1da18,0x1ed0e,0x1b410,0x1da0c, // 190
177
+            0x192c0,0x1c970,0x1e4bc,0x1b6c0,0x19260,0x1c938,0x1e49e,0x1b660,0x1db38,0x1ed9e, // 200
178
+            0x16c40,0x12420,0x19218,0x1c90e,0x16c20,0x1b618,0x16c10,0x126c0,0x19370,0x1c9bc, // 210
179
+            0x16ec0,0x12660,0x19338,0x1c99e,0x16e60,0x1b738,0x1db9e,0x16e30,0x12618,0x16e18, // 220
180
+            0x12770,0x193bc,0x16f70,0x12738,0x1939e,0x16f38,0x1b79e,0x16f1c,0x127bc,0x16fbc, // 230
181
+            0x1279e,0x16f9e,0x1d960,0x1ecb8,0x1f65e,0x1b240,0x1d930,0x1ec9c,0x1b220,0x1d918, // 240
182
+            0x1ec8e,0x1b210,0x1d90c,0x1b208,0x1b204,0x19160,0x1c8b8,0x1e45e,0x1b360,0x19130, // 250
183
+            0x1c89c,0x16640,0x12220,0x1d99c,0x1c88e,0x16620,0x12210,0x1910c,0x16610,0x1b30c, // 260
184
+            0x19106,0x12204,0x12360,0x191b8,0x1c8de,0x16760,0x12330,0x1919c,0x16730,0x1b39c, // 270
185
+            0x1918e,0x16718,0x1230c,0x12306,0x123b8,0x191de,0x167b8,0x1239c,0x1679c,0x1238e, // 280
186
+            0x1678e,0x167de,0x1b140,0x1d8b0,0x1ec5c,0x1b120,0x1d898,0x1ec4e,0x1b110,0x1d88c, // 290
187
+            0x1b108,0x1d886,0x1b104,0x1b102,0x12140,0x190b0,0x1c85c,0x16340,0x12120,0x19098, // 300
188
+            0x1c84e,0x16320,0x1b198,0x1d8ce,0x16310,0x12108,0x19086,0x16308,0x1b186,0x16304, // 310
189
+            0x121b0,0x190dc,0x163b0,0x12198,0x190ce,0x16398,0x1b1ce,0x1638c,0x12186,0x16386, // 320
190
+            0x163dc,0x163ce,0x1b0a0,0x1d858,0x1ec2e,0x1b090,0x1d84c,0x1b088,0x1d846,0x1b084, // 330
191
+            0x1b082,0x120a0,0x19058,0x1c82e,0x161a0,0x12090,0x1904c,0x16190,0x1b0cc,0x19046, // 340
192
+            0x16188,0x12084,0x16184,0x12082,0x120d8,0x161d8,0x161cc,0x161c6,0x1d82c,0x1d826, // 350
193
+            0x1b042,0x1902c,0x12048,0x160c8,0x160c4,0x160c2,0x18ac0,0x1c570,0x1e2bc,0x18a60, // 360
194
+            0x1c538,0x11440,0x18a30,0x1c51c,0x11420,0x18a18,0x11410,0x11408,0x116c0,0x18b70, // 370
195
+            0x1c5bc,0x11660,0x18b38,0x1c59e,0x11630,0x18b1c,0x11618,0x1160c,0x11770,0x18bbc, // 380
196
+            0x11738,0x18b9e,0x1171c,0x117bc,0x1179e,0x1cd60,0x1e6b8,0x1f35e,0x19a40,0x1cd30, // 390
197
+            0x1e69c,0x19a20,0x1cd18,0x1e68e,0x19a10,0x1cd0c,0x19a08,0x1cd06,0x18960,0x1c4b8, // 400
198
+            0x1e25e,0x19b60,0x18930,0x1c49c,0x13640,0x11220,0x1cd9c,0x1c48e,0x13620,0x19b18, // 410
199
+            0x1890c,0x13610,0x11208,0x13608,0x11360,0x189b8,0x1c4de,0x13760,0x11330,0x1cdde, // 420
200
+            0x13730,0x19b9c,0x1898e,0x13718,0x1130c,0x1370c,0x113b8,0x189de,0x137b8,0x1139c, // 430
201
+            0x1379c,0x1138e,0x113de,0x137de,0x1dd40,0x1eeb0,0x1f75c,0x1dd20,0x1ee98,0x1f74e, // 440
202
+            0x1dd10,0x1ee8c,0x1dd08,0x1ee86,0x1dd04,0x19940,0x1ccb0,0x1e65c,0x1bb40,0x19920, // 450
203
+            0x1eedc,0x1e64e,0x1bb20,0x1dd98,0x1eece,0x1bb10,0x19908,0x1cc86,0x1bb08,0x1dd86, // 460
204
+            0x19902,0x11140,0x188b0,0x1c45c,0x13340,0x11120,0x18898,0x1c44e,0x17740,0x13320, // 470
205
+            0x19998,0x1ccce,0x17720,0x1bb98,0x1ddce,0x18886,0x17710,0x13308,0x19986,0x17708, // 480
206
+            0x11102,0x111b0,0x188dc,0x133b0,0x11198,0x188ce,0x177b0,0x13398,0x199ce,0x17798, // 490
207
+            0x1bbce,0x11186,0x13386,0x111dc,0x133dc,0x111ce,0x177dc,0x133ce,0x1dca0,0x1ee58, // 500
208
+            0x1f72e,0x1dc90,0x1ee4c,0x1dc88,0x1ee46,0x1dc84,0x1dc82,0x198a0,0x1cc58,0x1e62e, // 510
209
+            0x1b9a0,0x19890,0x1ee6e,0x1b990,0x1dccc,0x1cc46,0x1b988,0x19884,0x1b984,0x19882, // 520
210
+            0x1b982,0x110a0,0x18858,0x1c42e,0x131a0,0x11090,0x1884c,0x173a0,0x13190,0x198cc, // 530
211
+            0x18846,0x17390,0x1b9cc,0x11084,0x17388,0x13184,0x11082,0x13182,0x110d8,0x1886e, // 540
212
+            0x131d8,0x110cc,0x173d8,0x131cc,0x110c6,0x173cc,0x131c6,0x110ee,0x173ee,0x1dc50, // 550
213
+            0x1ee2c,0x1dc48,0x1ee26,0x1dc44,0x1dc42,0x19850,0x1cc2c,0x1b8d0,0x19848,0x1cc26, // 560
214
+            0x1b8c8,0x1dc66,0x1b8c4,0x19842,0x1b8c2,0x11050,0x1882c,0x130d0,0x11048,0x18826, // 570
215
+            0x171d0,0x130c8,0x19866,0x171c8,0x1b8e6,0x11042,0x171c4,0x130c2,0x171c2,0x130ec, // 580
216
+            0x171ec,0x171e6,0x1ee16,0x1dc22,0x1cc16,0x19824,0x19822,0x11028,0x13068,0x170e8, // 590
217
+            0x11022,0x13062,0x18560,0x10a40,0x18530,0x10a20,0x18518,0x1c28e,0x10a10,0x1850c, // 600
218
+            0x10a08,0x18506,0x10b60,0x185b8,0x1c2de,0x10b30,0x1859c,0x10b18,0x1858e,0x10b0c, // 610
219
+            0x10b06,0x10bb8,0x185de,0x10b9c,0x10b8e,0x10bde,0x18d40,0x1c6b0,0x1e35c,0x18d20, // 620
220
+            0x1c698,0x18d10,0x1c68c,0x18d08,0x1c686,0x18d04,0x10940,0x184b0,0x1c25c,0x11b40, // 630
221
+            0x10920,0x1c6dc,0x1c24e,0x11b20,0x18d98,0x1c6ce,0x11b10,0x10908,0x18486,0x11b08, // 640
222
+            0x18d86,0x10902,0x109b0,0x184dc,0x11bb0,0x10998,0x184ce,0x11b98,0x18dce,0x11b8c, // 650
223
+            0x10986,0x109dc,0x11bdc,0x109ce,0x11bce,0x1cea0,0x1e758,0x1f3ae,0x1ce90,0x1e74c, // 660
224
+            0x1ce88,0x1e746,0x1ce84,0x1ce82,0x18ca0,0x1c658,0x19da0,0x18c90,0x1c64c,0x19d90, // 670
225
+            0x1cecc,0x1c646,0x19d88,0x18c84,0x19d84,0x18c82,0x19d82,0x108a0,0x18458,0x119a0, // 680
226
+            0x10890,0x1c66e,0x13ba0,0x11990,0x18ccc,0x18446,0x13b90,0x19dcc,0x10884,0x13b88, // 690
227
+            0x11984,0x10882,0x11982,0x108d8,0x1846e,0x119d8,0x108cc,0x13bd8,0x119cc,0x108c6, // 700
228
+            0x13bcc,0x119c6,0x108ee,0x119ee,0x13bee,0x1ef50,0x1f7ac,0x1ef48,0x1f7a6,0x1ef44, // 710
229
+            0x1ef42,0x1ce50,0x1e72c,0x1ded0,0x1ef6c,0x1e726,0x1dec8,0x1ef66,0x1dec4,0x1ce42, // 720
230
+            0x1dec2,0x18c50,0x1c62c,0x19cd0,0x18c48,0x1c626,0x1bdd0,0x19cc8,0x1ce66,0x1bdc8, // 730
231
+            0x1dee6,0x18c42,0x1bdc4,0x19cc2,0x1bdc2,0x10850,0x1842c,0x118d0,0x10848,0x18426, // 740
232
+            0x139d0,0x118c8,0x18c66,0x17bd0,0x139c8,0x19ce6,0x10842,0x17bc8,0x1bde6,0x118c2, // 750
233
+            0x17bc4,0x1086c,0x118ec,0x10866,0x139ec,0x118e6,0x17bec,0x139e6,0x17be6,0x1ef28, // 760
234
+            0x1f796,0x1ef24,0x1ef22,0x1ce28,0x1e716,0x1de68,0x1ef36,0x1de64,0x1ce22,0x1de62, // 770
235
+            0x18c28,0x1c616,0x19c68,0x18c24,0x1bce8,0x19c64,0x18c22,0x1bce4,0x19c62,0x1bce2, // 780
236
+            0x10828,0x18416,0x11868,0x18c36,0x138e8,0x11864,0x10822,0x179e8,0x138e4,0x11862, // 790
237
+            0x179e4,0x138e2,0x179e2,0x11876,0x179f6,0x1ef12,0x1de34,0x1de32,0x19c34,0x1bc74, // 800
238
+            0x1bc72,0x11834,0x13874,0x178f4,0x178f2,0x10540,0x10520,0x18298,0x10510,0x10508, // 810
239
+            0x10504,0x105b0,0x10598,0x1058c,0x10586,0x105dc,0x105ce,0x186a0,0x18690,0x1c34c, // 820
240
+            0x18688,0x1c346,0x18684,0x18682,0x104a0,0x18258,0x10da0,0x186d8,0x1824c,0x10d90, // 830
241
+            0x186cc,0x10d88,0x186c6,0x10d84,0x10482,0x10d82,0x104d8,0x1826e,0x10dd8,0x186ee, // 840
242
+            0x10dcc,0x104c6,0x10dc6,0x104ee,0x10dee,0x1c750,0x1c748,0x1c744,0x1c742,0x18650, // 850
243
+            0x18ed0,0x1c76c,0x1c326,0x18ec8,0x1c766,0x18ec4,0x18642,0x18ec2,0x10450,0x10cd0, // 860
244
+            0x10448,0x18226,0x11dd0,0x10cc8,0x10444,0x11dc8,0x10cc4,0x10442,0x11dc4,0x10cc2, // 870
245
+            0x1046c,0x10cec,0x10466,0x11dec,0x10ce6,0x11de6,0x1e7a8,0x1e7a4,0x1e7a2,0x1c728, // 880
246
+            0x1cf68,0x1e7b6,0x1cf64,0x1c722,0x1cf62,0x18628,0x1c316,0x18e68,0x1c736,0x19ee8, // 890
247
+            0x18e64,0x18622,0x19ee4,0x18e62,0x19ee2,0x10428,0x18216,0x10c68,0x18636,0x11ce8, // 900
248
+            0x10c64,0x10422,0x13de8,0x11ce4,0x10c62,0x13de4,0x11ce2,0x10436,0x10c76,0x11cf6, // 910
249
+            0x13df6,0x1f7d4,0x1f7d2,0x1e794,0x1efb4,0x1e792,0x1efb2,0x1c714,0x1cf34,0x1c712, // 920
250
+            0x1df74,0x1cf32,0x1df72,0x18614,0x18e34,0x18612,0x19e74,0x18e32,0x1bef4),        // 929
251
+        array( // cluster 3 -----------------------------------------------------------------------
252
+            0x1f560,0x1fab8,0x1ea40,0x1f530,0x1fa9c,0x1ea20,0x1f518,0x1fa8e,0x1ea10,0x1f50c, //  10
253
+            0x1ea08,0x1f506,0x1ea04,0x1eb60,0x1f5b8,0x1fade,0x1d640,0x1eb30,0x1f59c,0x1d620, //  20
254
+            0x1eb18,0x1f58e,0x1d610,0x1eb0c,0x1d608,0x1eb06,0x1d604,0x1d760,0x1ebb8,0x1f5de, //  30
255
+            0x1ae40,0x1d730,0x1eb9c,0x1ae20,0x1d718,0x1eb8e,0x1ae10,0x1d70c,0x1ae08,0x1d706, //  40
256
+            0x1ae04,0x1af60,0x1d7b8,0x1ebde,0x15e40,0x1af30,0x1d79c,0x15e20,0x1af18,0x1d78e, //  50
257
+            0x15e10,0x1af0c,0x15e08,0x1af06,0x15f60,0x1afb8,0x1d7de,0x15f30,0x1af9c,0x15f18, //  60
258
+            0x1af8e,0x15f0c,0x15fb8,0x1afde,0x15f9c,0x15f8e,0x1e940,0x1f4b0,0x1fa5c,0x1e920, //  70
259
+            0x1f498,0x1fa4e,0x1e910,0x1f48c,0x1e908,0x1f486,0x1e904,0x1e902,0x1d340,0x1e9b0, //  80
260
+            0x1f4dc,0x1d320,0x1e998,0x1f4ce,0x1d310,0x1e98c,0x1d308,0x1e986,0x1d304,0x1d302, //  90
261
+            0x1a740,0x1d3b0,0x1e9dc,0x1a720,0x1d398,0x1e9ce,0x1a710,0x1d38c,0x1a708,0x1d386, // 100
262
+            0x1a704,0x1a702,0x14f40,0x1a7b0,0x1d3dc,0x14f20,0x1a798,0x1d3ce,0x14f10,0x1a78c, // 110
263
+            0x14f08,0x1a786,0x14f04,0x14fb0,0x1a7dc,0x14f98,0x1a7ce,0x14f8c,0x14f86,0x14fdc, // 120
264
+            0x14fce,0x1e8a0,0x1f458,0x1fa2e,0x1e890,0x1f44c,0x1e888,0x1f446,0x1e884,0x1e882, // 130
265
+            0x1d1a0,0x1e8d8,0x1f46e,0x1d190,0x1e8cc,0x1d188,0x1e8c6,0x1d184,0x1d182,0x1a3a0, // 140
266
+            0x1d1d8,0x1e8ee,0x1a390,0x1d1cc,0x1a388,0x1d1c6,0x1a384,0x1a382,0x147a0,0x1a3d8, // 150
267
+            0x1d1ee,0x14790,0x1a3cc,0x14788,0x1a3c6,0x14784,0x14782,0x147d8,0x1a3ee,0x147cc, // 160
268
+            0x147c6,0x147ee,0x1e850,0x1f42c,0x1e848,0x1f426,0x1e844,0x1e842,0x1d0d0,0x1e86c, // 170
269
+            0x1d0c8,0x1e866,0x1d0c4,0x1d0c2,0x1a1d0,0x1d0ec,0x1a1c8,0x1d0e6,0x1a1c4,0x1a1c2, // 180
270
+            0x143d0,0x1a1ec,0x143c8,0x1a1e6,0x143c4,0x143c2,0x143ec,0x143e6,0x1e828,0x1f416, // 190
271
+            0x1e824,0x1e822,0x1d068,0x1e836,0x1d064,0x1d062,0x1a0e8,0x1d076,0x1a0e4,0x1a0e2, // 200
272
+            0x141e8,0x1a0f6,0x141e4,0x141e2,0x1e814,0x1e812,0x1d034,0x1d032,0x1a074,0x1a072, // 210
273
+            0x1e540,0x1f2b0,0x1f95c,0x1e520,0x1f298,0x1f94e,0x1e510,0x1f28c,0x1e508,0x1f286, // 220
274
+            0x1e504,0x1e502,0x1cb40,0x1e5b0,0x1f2dc,0x1cb20,0x1e598,0x1f2ce,0x1cb10,0x1e58c, // 230
275
+            0x1cb08,0x1e586,0x1cb04,0x1cb02,0x19740,0x1cbb0,0x1e5dc,0x19720,0x1cb98,0x1e5ce, // 240
276
+            0x19710,0x1cb8c,0x19708,0x1cb86,0x19704,0x19702,0x12f40,0x197b0,0x1cbdc,0x12f20, // 250
277
+            0x19798,0x1cbce,0x12f10,0x1978c,0x12f08,0x19786,0x12f04,0x12fb0,0x197dc,0x12f98, // 260
278
+            0x197ce,0x12f8c,0x12f86,0x12fdc,0x12fce,0x1f6a0,0x1fb58,0x16bf0,0x1f690,0x1fb4c, // 270
279
+            0x169f8,0x1f688,0x1fb46,0x168fc,0x1f684,0x1f682,0x1e4a0,0x1f258,0x1f92e,0x1eda0, // 280
280
+            0x1e490,0x1fb6e,0x1ed90,0x1f6cc,0x1f246,0x1ed88,0x1e484,0x1ed84,0x1e482,0x1ed82, // 290
281
+            0x1c9a0,0x1e4d8,0x1f26e,0x1dba0,0x1c990,0x1e4cc,0x1db90,0x1edcc,0x1e4c6,0x1db88, // 300
282
+            0x1c984,0x1db84,0x1c982,0x1db82,0x193a0,0x1c9d8,0x1e4ee,0x1b7a0,0x19390,0x1c9cc, // 310
283
+            0x1b790,0x1dbcc,0x1c9c6,0x1b788,0x19384,0x1b784,0x19382,0x1b782,0x127a0,0x193d8, // 320
284
+            0x1c9ee,0x16fa0,0x12790,0x193cc,0x16f90,0x1b7cc,0x193c6,0x16f88,0x12784,0x16f84, // 330
285
+            0x12782,0x127d8,0x193ee,0x16fd8,0x127cc,0x16fcc,0x127c6,0x16fc6,0x127ee,0x1f650, // 340
286
+            0x1fb2c,0x165f8,0x1f648,0x1fb26,0x164fc,0x1f644,0x1647e,0x1f642,0x1e450,0x1f22c, // 350
287
+            0x1ecd0,0x1e448,0x1f226,0x1ecc8,0x1f666,0x1ecc4,0x1e442,0x1ecc2,0x1c8d0,0x1e46c, // 360
288
+            0x1d9d0,0x1c8c8,0x1e466,0x1d9c8,0x1ece6,0x1d9c4,0x1c8c2,0x1d9c2,0x191d0,0x1c8ec, // 370
289
+            0x1b3d0,0x191c8,0x1c8e6,0x1b3c8,0x1d9e6,0x1b3c4,0x191c2,0x1b3c2,0x123d0,0x191ec, // 380
290
+            0x167d0,0x123c8,0x191e6,0x167c8,0x1b3e6,0x167c4,0x123c2,0x167c2,0x123ec,0x167ec, // 390
291
+            0x123e6,0x167e6,0x1f628,0x1fb16,0x162fc,0x1f624,0x1627e,0x1f622,0x1e428,0x1f216, // 400
292
+            0x1ec68,0x1f636,0x1ec64,0x1e422,0x1ec62,0x1c868,0x1e436,0x1d8e8,0x1c864,0x1d8e4, // 410
293
+            0x1c862,0x1d8e2,0x190e8,0x1c876,0x1b1e8,0x1d8f6,0x1b1e4,0x190e2,0x1b1e2,0x121e8, // 420
294
+            0x190f6,0x163e8,0x121e4,0x163e4,0x121e2,0x163e2,0x121f6,0x163f6,0x1f614,0x1617e, // 430
295
+            0x1f612,0x1e414,0x1ec34,0x1e412,0x1ec32,0x1c834,0x1d874,0x1c832,0x1d872,0x19074, // 440
296
+            0x1b0f4,0x19072,0x1b0f2,0x120f4,0x161f4,0x120f2,0x161f2,0x1f60a,0x1e40a,0x1ec1a, // 450
297
+            0x1c81a,0x1d83a,0x1903a,0x1b07a,0x1e2a0,0x1f158,0x1f8ae,0x1e290,0x1f14c,0x1e288, // 460
298
+            0x1f146,0x1e284,0x1e282,0x1c5a0,0x1e2d8,0x1f16e,0x1c590,0x1e2cc,0x1c588,0x1e2c6, // 470
299
+            0x1c584,0x1c582,0x18ba0,0x1c5d8,0x1e2ee,0x18b90,0x1c5cc,0x18b88,0x1c5c6,0x18b84, // 480
300
+            0x18b82,0x117a0,0x18bd8,0x1c5ee,0x11790,0x18bcc,0x11788,0x18bc6,0x11784,0x11782, // 490
301
+            0x117d8,0x18bee,0x117cc,0x117c6,0x117ee,0x1f350,0x1f9ac,0x135f8,0x1f348,0x1f9a6, // 500
302
+            0x134fc,0x1f344,0x1347e,0x1f342,0x1e250,0x1f12c,0x1e6d0,0x1e248,0x1f126,0x1e6c8, // 510
303
+            0x1f366,0x1e6c4,0x1e242,0x1e6c2,0x1c4d0,0x1e26c,0x1cdd0,0x1c4c8,0x1e266,0x1cdc8, // 520
304
+            0x1e6e6,0x1cdc4,0x1c4c2,0x1cdc2,0x189d0,0x1c4ec,0x19bd0,0x189c8,0x1c4e6,0x19bc8, // 530
305
+            0x1cde6,0x19bc4,0x189c2,0x19bc2,0x113d0,0x189ec,0x137d0,0x113c8,0x189e6,0x137c8, // 540
306
+            0x19be6,0x137c4,0x113c2,0x137c2,0x113ec,0x137ec,0x113e6,0x137e6,0x1fba8,0x175f0, // 550
307
+            0x1bafc,0x1fba4,0x174f8,0x1ba7e,0x1fba2,0x1747c,0x1743e,0x1f328,0x1f996,0x132fc, // 560
308
+            0x1f768,0x1fbb6,0x176fc,0x1327e,0x1f764,0x1f322,0x1767e,0x1f762,0x1e228,0x1f116, // 570
309
+            0x1e668,0x1e224,0x1eee8,0x1f776,0x1e222,0x1eee4,0x1e662,0x1eee2,0x1c468,0x1e236, // 580
310
+            0x1cce8,0x1c464,0x1dde8,0x1cce4,0x1c462,0x1dde4,0x1cce2,0x1dde2,0x188e8,0x1c476, // 590
311
+            0x199e8,0x188e4,0x1bbe8,0x199e4,0x188e2,0x1bbe4,0x199e2,0x1bbe2,0x111e8,0x188f6, // 600
312
+            0x133e8,0x111e4,0x177e8,0x133e4,0x111e2,0x177e4,0x133e2,0x177e2,0x111f6,0x133f6, // 610
313
+            0x1fb94,0x172f8,0x1b97e,0x1fb92,0x1727c,0x1723e,0x1f314,0x1317e,0x1f734,0x1f312, // 620
314
+            0x1737e,0x1f732,0x1e214,0x1e634,0x1e212,0x1ee74,0x1e632,0x1ee72,0x1c434,0x1cc74, // 630
315
+            0x1c432,0x1dcf4,0x1cc72,0x1dcf2,0x18874,0x198f4,0x18872,0x1b9f4,0x198f2,0x1b9f2, // 640
316
+            0x110f4,0x131f4,0x110f2,0x173f4,0x131f2,0x173f2,0x1fb8a,0x1717c,0x1713e,0x1f30a, // 650
317
+            0x1f71a,0x1e20a,0x1e61a,0x1ee3a,0x1c41a,0x1cc3a,0x1dc7a,0x1883a,0x1987a,0x1b8fa, // 660
318
+            0x1107a,0x130fa,0x171fa,0x170be,0x1e150,0x1f0ac,0x1e148,0x1f0a6,0x1e144,0x1e142, // 670
319
+            0x1c2d0,0x1e16c,0x1c2c8,0x1e166,0x1c2c4,0x1c2c2,0x185d0,0x1c2ec,0x185c8,0x1c2e6, // 680
320
+            0x185c4,0x185c2,0x10bd0,0x185ec,0x10bc8,0x185e6,0x10bc4,0x10bc2,0x10bec,0x10be6, // 690
321
+            0x1f1a8,0x1f8d6,0x11afc,0x1f1a4,0x11a7e,0x1f1a2,0x1e128,0x1f096,0x1e368,0x1e124, // 700
322
+            0x1e364,0x1e122,0x1e362,0x1c268,0x1e136,0x1c6e8,0x1c264,0x1c6e4,0x1c262,0x1c6e2, // 710
323
+            0x184e8,0x1c276,0x18de8,0x184e4,0x18de4,0x184e2,0x18de2,0x109e8,0x184f6,0x11be8, // 720
324
+            0x109e4,0x11be4,0x109e2,0x11be2,0x109f6,0x11bf6,0x1f9d4,0x13af8,0x19d7e,0x1f9d2, // 730
325
+            0x13a7c,0x13a3e,0x1f194,0x1197e,0x1f3b4,0x1f192,0x13b7e,0x1f3b2,0x1e114,0x1e334, // 740
326
+            0x1e112,0x1e774,0x1e332,0x1e772,0x1c234,0x1c674,0x1c232,0x1cef4,0x1c672,0x1cef2, // 750
327
+            0x18474,0x18cf4,0x18472,0x19df4,0x18cf2,0x19df2,0x108f4,0x119f4,0x108f2,0x13bf4, // 760
328
+            0x119f2,0x13bf2,0x17af0,0x1bd7c,0x17a78,0x1bd3e,0x17a3c,0x17a1e,0x1f9ca,0x1397c, // 770
329
+            0x1fbda,0x17b7c,0x1393e,0x17b3e,0x1f18a,0x1f39a,0x1f7ba,0x1e10a,0x1e31a,0x1e73a, // 780
330
+            0x1ef7a,0x1c21a,0x1c63a,0x1ce7a,0x1defa,0x1843a,0x18c7a,0x19cfa,0x1bdfa,0x1087a, // 790
331
+            0x118fa,0x139fa,0x17978,0x1bcbe,0x1793c,0x1791e,0x138be,0x179be,0x178bc,0x1789e, // 800
332
+            0x1785e,0x1e0a8,0x1e0a4,0x1e0a2,0x1c168,0x1e0b6,0x1c164,0x1c162,0x182e8,0x1c176, // 810
333
+            0x182e4,0x182e2,0x105e8,0x182f6,0x105e4,0x105e2,0x105f6,0x1f0d4,0x10d7e,0x1f0d2, // 820
334
+            0x1e094,0x1e1b4,0x1e092,0x1e1b2,0x1c134,0x1c374,0x1c132,0x1c372,0x18274,0x186f4, // 830
335
+            0x18272,0x186f2,0x104f4,0x10df4,0x104f2,0x10df2,0x1f8ea,0x11d7c,0x11d3e,0x1f0ca, // 840
336
+            0x1f1da,0x1e08a,0x1e19a,0x1e3ba,0x1c11a,0x1c33a,0x1c77a,0x1823a,0x1867a,0x18efa, // 850
337
+            0x1047a,0x10cfa,0x11dfa,0x13d78,0x19ebe,0x13d3c,0x13d1e,0x11cbe,0x13dbe,0x17d70, // 860
338
+            0x1bebc,0x17d38,0x1be9e,0x17d1c,0x17d0e,0x13cbc,0x17dbc,0x13c9e,0x17d9e,0x17cb8, // 870
339
+            0x1be5e,0x17c9c,0x17c8e,0x13c5e,0x17cde,0x17c5c,0x17c4e,0x17c2e,0x1c0b4,0x1c0b2, // 880
340
+            0x18174,0x18172,0x102f4,0x102f2,0x1e0da,0x1c09a,0x1c1ba,0x1813a,0x1837a,0x1027a, // 890
341
+            0x106fa,0x10ebe,0x11ebc,0x11e9e,0x13eb8,0x19f5e,0x13e9c,0x13e8e,0x11e5e,0x13ede, // 900
342
+            0x17eb0,0x1bf5c,0x17e98,0x1bf4e,0x17e8c,0x17e86,0x13e5c,0x17edc,0x13e4e,0x17ece, // 910
343
+            0x17e58,0x1bf2e,0x17e4c,0x17e46,0x13e2e,0x17e6e,0x17e2c,0x17e26,0x10f5e,0x11f5c, // 920
344
+            0x11f4e,0x13f58,0x19fae,0x13f4c,0x13f46,0x11f2e,0x13f6e,0x13f2c,0x13f26),        // 929
345
+        array( // cluster 6 -----------------------------------------------------------------------
346
+            0x1abe0,0x1d5f8,0x153c0,0x1a9f0,0x1d4fc,0x151e0,0x1a8f8,0x1d47e,0x150f0,0x1a87c, //  10
347
+            0x15078,0x1fad0,0x15be0,0x1adf8,0x1fac8,0x159f0,0x1acfc,0x1fac4,0x158f8,0x1ac7e, //  20
348
+            0x1fac2,0x1587c,0x1f5d0,0x1faec,0x15df8,0x1f5c8,0x1fae6,0x15cfc,0x1f5c4,0x15c7e, //  30
349
+            0x1f5c2,0x1ebd0,0x1f5ec,0x1ebc8,0x1f5e6,0x1ebc4,0x1ebc2,0x1d7d0,0x1ebec,0x1d7c8, //  40
350
+            0x1ebe6,0x1d7c4,0x1d7c2,0x1afd0,0x1d7ec,0x1afc8,0x1d7e6,0x1afc4,0x14bc0,0x1a5f0, //  50
351
+            0x1d2fc,0x149e0,0x1a4f8,0x1d27e,0x148f0,0x1a47c,0x14878,0x1a43e,0x1483c,0x1fa68, //  60
352
+            0x14df0,0x1a6fc,0x1fa64,0x14cf8,0x1a67e,0x1fa62,0x14c7c,0x14c3e,0x1f4e8,0x1fa76, //  70
353
+            0x14efc,0x1f4e4,0x14e7e,0x1f4e2,0x1e9e8,0x1f4f6,0x1e9e4,0x1e9e2,0x1d3e8,0x1e9f6, //  80
354
+            0x1d3e4,0x1d3e2,0x1a7e8,0x1d3f6,0x1a7e4,0x1a7e2,0x145e0,0x1a2f8,0x1d17e,0x144f0, //  90
355
+            0x1a27c,0x14478,0x1a23e,0x1443c,0x1441e,0x1fa34,0x146f8,0x1a37e,0x1fa32,0x1467c, // 100
356
+            0x1463e,0x1f474,0x1477e,0x1f472,0x1e8f4,0x1e8f2,0x1d1f4,0x1d1f2,0x1a3f4,0x1a3f2, // 110
357
+            0x142f0,0x1a17c,0x14278,0x1a13e,0x1423c,0x1421e,0x1fa1a,0x1437c,0x1433e,0x1f43a, // 120
358
+            0x1e87a,0x1d0fa,0x14178,0x1a0be,0x1413c,0x1411e,0x141be,0x140bc,0x1409e,0x12bc0, // 130
359
+            0x195f0,0x1cafc,0x129e0,0x194f8,0x1ca7e,0x128f0,0x1947c,0x12878,0x1943e,0x1283c, // 140
360
+            0x1f968,0x12df0,0x196fc,0x1f964,0x12cf8,0x1967e,0x1f962,0x12c7c,0x12c3e,0x1f2e8, // 150
361
+            0x1f976,0x12efc,0x1f2e4,0x12e7e,0x1f2e2,0x1e5e8,0x1f2f6,0x1e5e4,0x1e5e2,0x1cbe8, // 160
362
+            0x1e5f6,0x1cbe4,0x1cbe2,0x197e8,0x1cbf6,0x197e4,0x197e2,0x1b5e0,0x1daf8,0x1ed7e, // 170
363
+            0x169c0,0x1b4f0,0x1da7c,0x168e0,0x1b478,0x1da3e,0x16870,0x1b43c,0x16838,0x1b41e, // 180
364
+            0x1681c,0x125e0,0x192f8,0x1c97e,0x16de0,0x124f0,0x1927c,0x16cf0,0x1b67c,0x1923e, // 190
365
+            0x16c78,0x1243c,0x16c3c,0x1241e,0x16c1e,0x1f934,0x126f8,0x1937e,0x1fb74,0x1f932, // 200
366
+            0x16ef8,0x1267c,0x1fb72,0x16e7c,0x1263e,0x16e3e,0x1f274,0x1277e,0x1f6f4,0x1f272, // 210
367
+            0x16f7e,0x1f6f2,0x1e4f4,0x1edf4,0x1e4f2,0x1edf2,0x1c9f4,0x1dbf4,0x1c9f2,0x1dbf2, // 220
368
+            0x193f4,0x193f2,0x165c0,0x1b2f0,0x1d97c,0x164e0,0x1b278,0x1d93e,0x16470,0x1b23c, // 230
369
+            0x16438,0x1b21e,0x1641c,0x1640e,0x122f0,0x1917c,0x166f0,0x12278,0x1913e,0x16678, // 240
370
+            0x1b33e,0x1663c,0x1221e,0x1661e,0x1f91a,0x1237c,0x1fb3a,0x1677c,0x1233e,0x1673e, // 250
371
+            0x1f23a,0x1f67a,0x1e47a,0x1ecfa,0x1c8fa,0x1d9fa,0x191fa,0x162e0,0x1b178,0x1d8be, // 260
372
+            0x16270,0x1b13c,0x16238,0x1b11e,0x1621c,0x1620e,0x12178,0x190be,0x16378,0x1213c, // 270
373
+            0x1633c,0x1211e,0x1631e,0x121be,0x163be,0x16170,0x1b0bc,0x16138,0x1b09e,0x1611c, // 280
374
+            0x1610e,0x120bc,0x161bc,0x1209e,0x1619e,0x160b8,0x1b05e,0x1609c,0x1608e,0x1205e, // 290
375
+            0x160de,0x1605c,0x1604e,0x115e0,0x18af8,0x1c57e,0x114f0,0x18a7c,0x11478,0x18a3e, // 300
376
+            0x1143c,0x1141e,0x1f8b4,0x116f8,0x18b7e,0x1f8b2,0x1167c,0x1163e,0x1f174,0x1177e, // 310
377
+            0x1f172,0x1e2f4,0x1e2f2,0x1c5f4,0x1c5f2,0x18bf4,0x18bf2,0x135c0,0x19af0,0x1cd7c, // 320
378
+            0x134e0,0x19a78,0x1cd3e,0x13470,0x19a3c,0x13438,0x19a1e,0x1341c,0x1340e,0x112f0, // 330
379
+            0x1897c,0x136f0,0x11278,0x1893e,0x13678,0x19b3e,0x1363c,0x1121e,0x1361e,0x1f89a, // 340
380
+            0x1137c,0x1f9ba,0x1377c,0x1133e,0x1373e,0x1f13a,0x1f37a,0x1e27a,0x1e6fa,0x1c4fa, // 350
381
+            0x1cdfa,0x189fa,0x1bae0,0x1dd78,0x1eebe,0x174c0,0x1ba70,0x1dd3c,0x17460,0x1ba38, // 360
382
+            0x1dd1e,0x17430,0x1ba1c,0x17418,0x1ba0e,0x1740c,0x132e0,0x19978,0x1ccbe,0x176e0, // 370
383
+            0x13270,0x1993c,0x17670,0x1bb3c,0x1991e,0x17638,0x1321c,0x1761c,0x1320e,0x1760e, // 380
384
+            0x11178,0x188be,0x13378,0x1113c,0x17778,0x1333c,0x1111e,0x1773c,0x1331e,0x1771e, // 390
385
+            0x111be,0x133be,0x177be,0x172c0,0x1b970,0x1dcbc,0x17260,0x1b938,0x1dc9e,0x17230, // 400
386
+            0x1b91c,0x17218,0x1b90e,0x1720c,0x17206,0x13170,0x198bc,0x17370,0x13138,0x1989e, // 410
387
+            0x17338,0x1b99e,0x1731c,0x1310e,0x1730e,0x110bc,0x131bc,0x1109e,0x173bc,0x1319e, // 420
388
+            0x1739e,0x17160,0x1b8b8,0x1dc5e,0x17130,0x1b89c,0x17118,0x1b88e,0x1710c,0x17106, // 430
389
+            0x130b8,0x1985e,0x171b8,0x1309c,0x1719c,0x1308e,0x1718e,0x1105e,0x130de,0x171de, // 440
390
+            0x170b0,0x1b85c,0x17098,0x1b84e,0x1708c,0x17086,0x1305c,0x170dc,0x1304e,0x170ce, // 450
391
+            0x17058,0x1b82e,0x1704c,0x17046,0x1302e,0x1706e,0x1702c,0x17026,0x10af0,0x1857c, // 460
392
+            0x10a78,0x1853e,0x10a3c,0x10a1e,0x10b7c,0x10b3e,0x1f0ba,0x1e17a,0x1c2fa,0x185fa, // 470
393
+            0x11ae0,0x18d78,0x1c6be,0x11a70,0x18d3c,0x11a38,0x18d1e,0x11a1c,0x11a0e,0x10978, // 480
394
+            0x184be,0x11b78,0x1093c,0x11b3c,0x1091e,0x11b1e,0x109be,0x11bbe,0x13ac0,0x19d70, // 490
395
+            0x1cebc,0x13a60,0x19d38,0x1ce9e,0x13a30,0x19d1c,0x13a18,0x19d0e,0x13a0c,0x13a06, // 500
396
+            0x11970,0x18cbc,0x13b70,0x11938,0x18c9e,0x13b38,0x1191c,0x13b1c,0x1190e,0x13b0e, // 510
397
+            0x108bc,0x119bc,0x1089e,0x13bbc,0x1199e,0x13b9e,0x1bd60,0x1deb8,0x1ef5e,0x17a40, // 520
398
+            0x1bd30,0x1de9c,0x17a20,0x1bd18,0x1de8e,0x17a10,0x1bd0c,0x17a08,0x1bd06,0x17a04, // 530
399
+            0x13960,0x19cb8,0x1ce5e,0x17b60,0x13930,0x19c9c,0x17b30,0x1bd9c,0x19c8e,0x17b18, // 540
400
+            0x1390c,0x17b0c,0x13906,0x17b06,0x118b8,0x18c5e,0x139b8,0x1189c,0x17bb8,0x1399c, // 550
401
+            0x1188e,0x17b9c,0x1398e,0x17b8e,0x1085e,0x118de,0x139de,0x17bde,0x17940,0x1bcb0, // 560
402
+            0x1de5c,0x17920,0x1bc98,0x1de4e,0x17910,0x1bc8c,0x17908,0x1bc86,0x17904,0x17902, // 570
403
+            0x138b0,0x19c5c,0x179b0,0x13898,0x19c4e,0x17998,0x1bcce,0x1798c,0x13886,0x17986, // 580
404
+            0x1185c,0x138dc,0x1184e,0x179dc,0x138ce,0x179ce,0x178a0,0x1bc58,0x1de2e,0x17890, // 590
405
+            0x1bc4c,0x17888,0x1bc46,0x17884,0x17882,0x13858,0x19c2e,0x178d8,0x1384c,0x178cc, // 600
406
+            0x13846,0x178c6,0x1182e,0x1386e,0x178ee,0x17850,0x1bc2c,0x17848,0x1bc26,0x17844, // 610
407
+            0x17842,0x1382c,0x1786c,0x13826,0x17866,0x17828,0x1bc16,0x17824,0x17822,0x13816, // 620
408
+            0x17836,0x10578,0x182be,0x1053c,0x1051e,0x105be,0x10d70,0x186bc,0x10d38,0x1869e, // 630
409
+            0x10d1c,0x10d0e,0x104bc,0x10dbc,0x1049e,0x10d9e,0x11d60,0x18eb8,0x1c75e,0x11d30, // 640
410
+            0x18e9c,0x11d18,0x18e8e,0x11d0c,0x11d06,0x10cb8,0x1865e,0x11db8,0x10c9c,0x11d9c, // 650
411
+            0x10c8e,0x11d8e,0x1045e,0x10cde,0x11dde,0x13d40,0x19eb0,0x1cf5c,0x13d20,0x19e98, // 660
412
+            0x1cf4e,0x13d10,0x19e8c,0x13d08,0x19e86,0x13d04,0x13d02,0x11cb0,0x18e5c,0x13db0, // 670
413
+            0x11c98,0x18e4e,0x13d98,0x19ece,0x13d8c,0x11c86,0x13d86,0x10c5c,0x11cdc,0x10c4e, // 680
414
+            0x13ddc,0x11cce,0x13dce,0x1bea0,0x1df58,0x1efae,0x1be90,0x1df4c,0x1be88,0x1df46, // 690
415
+            0x1be84,0x1be82,0x13ca0,0x19e58,0x1cf2e,0x17da0,0x13c90,0x19e4c,0x17d90,0x1becc, // 700
416
+            0x19e46,0x17d88,0x13c84,0x17d84,0x13c82,0x17d82,0x11c58,0x18e2e,0x13cd8,0x11c4c, // 710
417
+            0x17dd8,0x13ccc,0x11c46,0x17dcc,0x13cc6,0x17dc6,0x10c2e,0x11c6e,0x13cee,0x17dee, // 720
418
+            0x1be50,0x1df2c,0x1be48,0x1df26,0x1be44,0x1be42,0x13c50,0x19e2c,0x17cd0,0x13c48, // 730
419
+            0x19e26,0x17cc8,0x1be66,0x17cc4,0x13c42,0x17cc2,0x11c2c,0x13c6c,0x11c26,0x17cec, // 740
420
+            0x13c66,0x17ce6,0x1be28,0x1df16,0x1be24,0x1be22,0x13c28,0x19e16,0x17c68,0x13c24, // 750
421
+            0x17c64,0x13c22,0x17c62,0x11c16,0x13c36,0x17c76,0x1be14,0x1be12,0x13c14,0x17c34, // 760
422
+            0x13c12,0x17c32,0x102bc,0x1029e,0x106b8,0x1835e,0x1069c,0x1068e,0x1025e,0x106de, // 770
423
+            0x10eb0,0x1875c,0x10e98,0x1874e,0x10e8c,0x10e86,0x1065c,0x10edc,0x1064e,0x10ece, // 780
424
+            0x11ea0,0x18f58,0x1c7ae,0x11e90,0x18f4c,0x11e88,0x18f46,0x11e84,0x11e82,0x10e58, // 790
425
+            0x1872e,0x11ed8,0x18f6e,0x11ecc,0x10e46,0x11ec6,0x1062e,0x10e6e,0x11eee,0x19f50, // 800
426
+            0x1cfac,0x19f48,0x1cfa6,0x19f44,0x19f42,0x11e50,0x18f2c,0x13ed0,0x19f6c,0x18f26, // 810
427
+            0x13ec8,0x11e44,0x13ec4,0x11e42,0x13ec2,0x10e2c,0x11e6c,0x10e26,0x13eec,0x11e66, // 820
428
+            0x13ee6,0x1dfa8,0x1efd6,0x1dfa4,0x1dfa2,0x19f28,0x1cf96,0x1bf68,0x19f24,0x1bf64, // 830
429
+            0x19f22,0x1bf62,0x11e28,0x18f16,0x13e68,0x11e24,0x17ee8,0x13e64,0x11e22,0x17ee4, // 840
430
+            0x13e62,0x17ee2,0x10e16,0x11e36,0x13e76,0x17ef6,0x1df94,0x1df92,0x19f14,0x1bf34, // 850
431
+            0x19f12,0x1bf32,0x11e14,0x13e34,0x11e12,0x17e74,0x13e32,0x17e72,0x1df8a,0x19f0a, // 860
432
+            0x1bf1a,0x11e0a,0x13e1a,0x17e3a,0x1035c,0x1034e,0x10758,0x183ae,0x1074c,0x10746, // 870
433
+            0x1032e,0x1076e,0x10f50,0x187ac,0x10f48,0x187a6,0x10f44,0x10f42,0x1072c,0x10f6c, // 880
434
+            0x10726,0x10f66,0x18fa8,0x1c7d6,0x18fa4,0x18fa2,0x10f28,0x18796,0x11f68,0x18fb6, // 890
435
+            0x11f64,0x10f22,0x11f62,0x10716,0x10f36,0x11f76,0x1cfd4,0x1cfd2,0x18f94,0x19fb4, // 900
436
+            0x18f92,0x19fb2,0x10f14,0x11f34,0x10f12,0x13f74,0x11f32,0x13f72,0x1cfca,0x18f8a, // 910
437
+            0x19f9a,0x10f0a,0x11f1a,0x13f3a,0x103ac,0x103a6,0x107a8,0x183d6,0x107a4,0x107a2, // 920
438
+            0x10396,0x107b6,0x187d4,0x187d2,0x10794,0x10fb4,0x10792,0x10fb2,0x1c7ea)         // 929
439
+    ); // end of $clusters array
440 440
 
441
-	/**
442
-	 * Array of factors of the Reed-Solomon polynomial equations used for error correction; one sub array for each correction level (0-8).
443
-	 * @protected
444
-	 */
445
-	protected $rsfactors = array(
446
-		array( // ECL 0 (2 factors) -------------------------------------------------------------------------------
447
-			0x01b,0x395),                                                                                    //   2
448
-		array( // ECL 1 (4 factors) -------------------------------------------------------------------------------
449
-			0x20a,0x238,0x2d3,0x329),                                                                        //   4
450
-		array( // ECL 2 (8 factors) -------------------------------------------------------------------------------
451
-			0x0ed,0x134,0x1b4,0x11c,0x286,0x28d,0x1ac,0x17b),                                                //   8
452
-		array( // ECL 3 (16 factors) ------------------------------------------------------------------------------
453
-			0x112,0x232,0x0e8,0x2f3,0x257,0x20c,0x321,0x084,0x127,0x074,0x1ba,0x1ac,0x127,0x02a,0x0b0,0x041),//  16
454
-		array( // ECL 4 (32 factors) ------------------------------------------------------------------------------
455
-			0x169,0x23f,0x39a,0x20d,0x0b0,0x24a,0x280,0x141,0x218,0x2e6,0x2a5,0x2e6,0x2af,0x11c,0x0c1,0x205, //  16
456
-			0x111,0x1ee,0x107,0x093,0x251,0x320,0x23b,0x140,0x323,0x085,0x0e7,0x186,0x2ad,0x14a,0x03f,0x19a),//  32
457
-		array( // ECL 5 (64 factors) ------------------------------------------------------------------------------
458
-			0x21b,0x1a6,0x006,0x05d,0x35e,0x303,0x1c5,0x06a,0x262,0x11f,0x06b,0x1f9,0x2dd,0x36d,0x17d,0x264, //  16
459
-			0x2d3,0x1dc,0x1ce,0x0ac,0x1ae,0x261,0x35a,0x336,0x21f,0x178,0x1ff,0x190,0x2a0,0x2fa,0x11b,0x0b8, //  32
460
-			0x1b8,0x023,0x207,0x01f,0x1cc,0x252,0x0e1,0x217,0x205,0x160,0x25d,0x09e,0x28b,0x0c9,0x1e8,0x1f6, //  48
461
-			0x288,0x2dd,0x2cd,0x053,0x194,0x061,0x118,0x303,0x348,0x275,0x004,0x17d,0x34b,0x26f,0x108,0x21f),//  64
462
-		array( // ECL 6 (128 factors) -----------------------------------------------------------------------------
463
-			0x209,0x136,0x360,0x223,0x35a,0x244,0x128,0x17b,0x035,0x30b,0x381,0x1bc,0x190,0x39d,0x2ed,0x19f, //  16
464
-			0x336,0x05d,0x0d9,0x0d0,0x3a0,0x0f4,0x247,0x26c,0x0f6,0x094,0x1bf,0x277,0x124,0x38c,0x1ea,0x2c0, //  32
465
-			0x204,0x102,0x1c9,0x38b,0x252,0x2d3,0x2a2,0x124,0x110,0x060,0x2ac,0x1b0,0x2ae,0x25e,0x35c,0x239, //  48
466
-			0x0c1,0x0db,0x081,0x0ba,0x0ec,0x11f,0x0c0,0x307,0x116,0x0ad,0x028,0x17b,0x2c8,0x1cf,0x286,0x308, //  64
467
-			0x0ab,0x1eb,0x129,0x2fb,0x09c,0x2dc,0x05f,0x10e,0x1bf,0x05a,0x1fb,0x030,0x0e4,0x335,0x328,0x382, //  80
468
-			0x310,0x297,0x273,0x17a,0x17e,0x106,0x17c,0x25a,0x2f2,0x150,0x059,0x266,0x057,0x1b0,0x29e,0x268, //  96
469
-			0x09d,0x176,0x0f2,0x2d6,0x258,0x10d,0x177,0x382,0x34d,0x1c6,0x162,0x082,0x32e,0x24b,0x324,0x022, // 112
470
-			0x0d3,0x14a,0x21b,0x129,0x33b,0x361,0x025,0x205,0x342,0x13b,0x226,0x056,0x321,0x004,0x06c,0x21b),// 128
471
-		array( // ECL 7 (256 factors) -----------------------------------------------------------------------------
472
-			0x20c,0x37e,0x04b,0x2fe,0x372,0x359,0x04a,0x0cc,0x052,0x24a,0x2c4,0x0fa,0x389,0x312,0x08a,0x2d0, //  16
473
-			0x35a,0x0c2,0x137,0x391,0x113,0x0be,0x177,0x352,0x1b6,0x2dd,0x0c2,0x118,0x0c9,0x118,0x33c,0x2f5, //  32
474
-			0x2c6,0x32e,0x397,0x059,0x044,0x239,0x00b,0x0cc,0x31c,0x25d,0x21c,0x391,0x321,0x2bc,0x31f,0x089, //  48
475
-			0x1b7,0x1a2,0x250,0x29c,0x161,0x35b,0x172,0x2b6,0x145,0x0f0,0x0d8,0x101,0x11c,0x225,0x0d1,0x374, //  64
476
-			0x13b,0x046,0x149,0x319,0x1ea,0x112,0x36d,0x0a2,0x2ed,0x32c,0x2ac,0x1cd,0x14e,0x178,0x351,0x209, //  80
477
-			0x133,0x123,0x323,0x2c8,0x013,0x166,0x18f,0x38c,0x067,0x1ff,0x033,0x008,0x205,0x0e1,0x121,0x1d6, //  96
478
-			0x27d,0x2db,0x042,0x0ff,0x395,0x10d,0x1cf,0x33e,0x2da,0x1b1,0x350,0x249,0x088,0x21a,0x38a,0x05a, // 112
479
-			0x002,0x122,0x2e7,0x0c7,0x28f,0x387,0x149,0x031,0x322,0x244,0x163,0x24c,0x0bc,0x1ce,0x00a,0x086, // 128
480
-			0x274,0x140,0x1df,0x082,0x2e3,0x047,0x107,0x13e,0x176,0x259,0x0c0,0x25d,0x08e,0x2a1,0x2af,0x0ea, // 144
481
-			0x2d2,0x180,0x0b1,0x2f0,0x25f,0x280,0x1c7,0x0c1,0x2b1,0x2c3,0x325,0x281,0x030,0x03c,0x2dc,0x26d, // 160
482
-			0x37f,0x220,0x105,0x354,0x28f,0x135,0x2b9,0x2f3,0x2f4,0x03c,0x0e7,0x305,0x1b2,0x1a5,0x2d6,0x210, // 176
483
-			0x1f7,0x076,0x031,0x31b,0x020,0x090,0x1f4,0x0ee,0x344,0x18a,0x118,0x236,0x13f,0x009,0x287,0x226, // 192
484
-			0x049,0x392,0x156,0x07e,0x020,0x2a9,0x14b,0x318,0x26c,0x03c,0x261,0x1b9,0x0b4,0x317,0x37d,0x2f2, // 208
485
-			0x25d,0x17f,0x0e4,0x2ed,0x2f8,0x0d5,0x036,0x129,0x086,0x036,0x342,0x12b,0x39a,0x0bf,0x38e,0x214, // 224
486
-			0x261,0x33d,0x0bd,0x014,0x0a7,0x01d,0x368,0x1c1,0x053,0x192,0x029,0x290,0x1f9,0x243,0x1e1,0x0ad, // 240
487
-			0x194,0x0fb,0x2b0,0x05f,0x1f1,0x22b,0x282,0x21f,0x133,0x09f,0x39c,0x22e,0x288,0x037,0x1f1,0x00a),// 256
488
-		array( // ECL 8 (512 factors) -----------------------------------------------------------------------------
489
-			0x160,0x04d,0x175,0x1f8,0x023,0x257,0x1ac,0x0cf,0x199,0x23e,0x076,0x1f2,0x11d,0x17c,0x15e,0x1ec, //  16
490
-			0x0c5,0x109,0x398,0x09b,0x392,0x12b,0x0e5,0x283,0x126,0x367,0x132,0x058,0x057,0x0c1,0x160,0x30d, //  32
491
-			0x34e,0x04b,0x147,0x208,0x1b3,0x21f,0x0cb,0x29a,0x0f9,0x15a,0x30d,0x26d,0x280,0x10c,0x31a,0x216, //  48
492
-			0x21b,0x30d,0x198,0x186,0x284,0x066,0x1dc,0x1f3,0x122,0x278,0x221,0x025,0x35a,0x394,0x228,0x029, //  64
493
-			0x21e,0x121,0x07a,0x110,0x17f,0x320,0x1e5,0x062,0x2f0,0x1d8,0x2f9,0x06b,0x310,0x35c,0x292,0x2e5, //  80
494
-			0x122,0x0cc,0x2a9,0x197,0x357,0x055,0x063,0x03e,0x1e2,0x0b4,0x014,0x129,0x1c3,0x251,0x391,0x08e, //  96
495
-			0x328,0x2ac,0x11f,0x218,0x231,0x04c,0x28d,0x383,0x2d9,0x237,0x2e8,0x186,0x201,0x0c0,0x204,0x102, // 112
496
-			0x0f0,0x206,0x31a,0x18b,0x300,0x350,0x033,0x262,0x180,0x0a8,0x0be,0x33a,0x148,0x254,0x312,0x12f, // 128
497
-			0x23a,0x17d,0x19f,0x281,0x09c,0x0ed,0x097,0x1ad,0x213,0x0cf,0x2a4,0x2c6,0x059,0x0a8,0x130,0x192, // 144
498
-			0x028,0x2c4,0x23f,0x0a2,0x360,0x0e5,0x041,0x35d,0x349,0x200,0x0a4,0x1dd,0x0dd,0x05c,0x166,0x311, // 160
499
-			0x120,0x165,0x352,0x344,0x33b,0x2e0,0x2c3,0x05e,0x008,0x1ee,0x072,0x209,0x002,0x1f3,0x353,0x21f, // 176
500
-			0x098,0x2d9,0x303,0x05f,0x0f8,0x169,0x242,0x143,0x358,0x31d,0x121,0x033,0x2ac,0x1d2,0x215,0x334, // 192
501
-			0x29d,0x02d,0x386,0x1c4,0x0a7,0x156,0x0f4,0x0ad,0x023,0x1cf,0x28b,0x033,0x2bb,0x24f,0x1c4,0x242, // 208
502
-			0x025,0x07c,0x12a,0x14c,0x228,0x02b,0x1ab,0x077,0x296,0x309,0x1db,0x352,0x2fc,0x16c,0x242,0x38f, // 224
503
-			0x11b,0x2c7,0x1d8,0x1a4,0x0f5,0x120,0x252,0x18a,0x1ff,0x147,0x24d,0x309,0x2bb,0x2b0,0x02b,0x198, // 240
504
-			0x34a,0x17f,0x2d1,0x209,0x230,0x284,0x2ca,0x22f,0x03e,0x091,0x369,0x297,0x2c9,0x09f,0x2a0,0x2d9, // 256
505
-			0x270,0x03b,0x0c1,0x1a1,0x09e,0x0d1,0x233,0x234,0x157,0x2b5,0x06d,0x260,0x233,0x16d,0x0b5,0x304, // 272
506
-			0x2a5,0x136,0x0f8,0x161,0x2c4,0x19a,0x243,0x366,0x269,0x349,0x278,0x35c,0x121,0x218,0x023,0x309, // 288
507
-			0x26a,0x24a,0x1a8,0x341,0x04d,0x255,0x15a,0x10d,0x2f5,0x278,0x2b7,0x2ef,0x14b,0x0f7,0x0b8,0x02d, // 304
508
-			0x313,0x2a8,0x012,0x042,0x197,0x171,0x036,0x1ec,0x0e4,0x265,0x33e,0x39a,0x1b5,0x207,0x284,0x389, // 320
509
-			0x315,0x1a4,0x131,0x1b9,0x0cf,0x12c,0x37c,0x33b,0x08d,0x219,0x17d,0x296,0x201,0x038,0x0fc,0x155, // 336
510
-			0x0f2,0x31d,0x346,0x345,0x2d0,0x0e0,0x133,0x277,0x03d,0x057,0x230,0x136,0x2f4,0x299,0x18d,0x328, // 352
511
-			0x353,0x135,0x1d9,0x31b,0x17a,0x01f,0x287,0x393,0x1cb,0x326,0x24e,0x2db,0x1a9,0x0d8,0x224,0x0f9, // 368
512
-			0x141,0x371,0x2bb,0x217,0x2a1,0x30e,0x0d2,0x32f,0x389,0x12f,0x34b,0x39a,0x119,0x049,0x1d5,0x317, // 384
513
-			0x294,0x0a2,0x1f2,0x134,0x09b,0x1a6,0x38b,0x331,0x0bb,0x03e,0x010,0x1a9,0x217,0x150,0x11e,0x1b5, // 400
514
-			0x177,0x111,0x262,0x128,0x0b7,0x39b,0x074,0x29b,0x2ef,0x161,0x03e,0x16e,0x2b3,0x17b,0x2af,0x34a, // 416
515
-			0x025,0x165,0x2d0,0x2e6,0x14a,0x005,0x027,0x39b,0x137,0x1a8,0x0f2,0x2ed,0x141,0x036,0x29d,0x13c, // 432
516
-			0x156,0x12b,0x216,0x069,0x29b,0x1e8,0x280,0x2a0,0x240,0x21c,0x13c,0x1e6,0x2d1,0x262,0x02e,0x290, // 448
517
-			0x1bf,0x0ab,0x268,0x1d0,0x0be,0x213,0x129,0x141,0x2fa,0x2f0,0x215,0x0af,0x086,0x00e,0x17d,0x1b1, // 464
518
-			0x2cd,0x02d,0x06f,0x014,0x254,0x11c,0x2e0,0x08a,0x286,0x19b,0x36d,0x29d,0x08d,0x397,0x02d,0x30c, // 480
519
-			0x197,0x0a4,0x14c,0x383,0x0a5,0x2d6,0x258,0x145,0x1f2,0x28f,0x165,0x2f0,0x300,0x0df,0x351,0x287, // 496
520
-			0x03f,0x136,0x35f,0x0fb,0x16e,0x130,0x11a,0x2e2,0x2a3,0x19a,0x185,0x0f4,0x01f,0x079,0x12f,0x107) // 512
521
-	);
441
+    /**
442
+     * Array of factors of the Reed-Solomon polynomial equations used for error correction; one sub array for each correction level (0-8).
443
+     * @protected
444
+     */
445
+    protected $rsfactors = array(
446
+        array( // ECL 0 (2 factors) -------------------------------------------------------------------------------
447
+            0x01b,0x395),                                                                                    //   2
448
+        array( // ECL 1 (4 factors) -------------------------------------------------------------------------------
449
+            0x20a,0x238,0x2d3,0x329),                                                                        //   4
450
+        array( // ECL 2 (8 factors) -------------------------------------------------------------------------------
451
+            0x0ed,0x134,0x1b4,0x11c,0x286,0x28d,0x1ac,0x17b),                                                //   8
452
+        array( // ECL 3 (16 factors) ------------------------------------------------------------------------------
453
+            0x112,0x232,0x0e8,0x2f3,0x257,0x20c,0x321,0x084,0x127,0x074,0x1ba,0x1ac,0x127,0x02a,0x0b0,0x041),//  16
454
+        array( // ECL 4 (32 factors) ------------------------------------------------------------------------------
455
+            0x169,0x23f,0x39a,0x20d,0x0b0,0x24a,0x280,0x141,0x218,0x2e6,0x2a5,0x2e6,0x2af,0x11c,0x0c1,0x205, //  16
456
+            0x111,0x1ee,0x107,0x093,0x251,0x320,0x23b,0x140,0x323,0x085,0x0e7,0x186,0x2ad,0x14a,0x03f,0x19a),//  32
457
+        array( // ECL 5 (64 factors) ------------------------------------------------------------------------------
458
+            0x21b,0x1a6,0x006,0x05d,0x35e,0x303,0x1c5,0x06a,0x262,0x11f,0x06b,0x1f9,0x2dd,0x36d,0x17d,0x264, //  16
459
+            0x2d3,0x1dc,0x1ce,0x0ac,0x1ae,0x261,0x35a,0x336,0x21f,0x178,0x1ff,0x190,0x2a0,0x2fa,0x11b,0x0b8, //  32
460
+            0x1b8,0x023,0x207,0x01f,0x1cc,0x252,0x0e1,0x217,0x205,0x160,0x25d,0x09e,0x28b,0x0c9,0x1e8,0x1f6, //  48
461
+            0x288,0x2dd,0x2cd,0x053,0x194,0x061,0x118,0x303,0x348,0x275,0x004,0x17d,0x34b,0x26f,0x108,0x21f),//  64
462
+        array( // ECL 6 (128 factors) -----------------------------------------------------------------------------
463
+            0x209,0x136,0x360,0x223,0x35a,0x244,0x128,0x17b,0x035,0x30b,0x381,0x1bc,0x190,0x39d,0x2ed,0x19f, //  16
464
+            0x336,0x05d,0x0d9,0x0d0,0x3a0,0x0f4,0x247,0x26c,0x0f6,0x094,0x1bf,0x277,0x124,0x38c,0x1ea,0x2c0, //  32
465
+            0x204,0x102,0x1c9,0x38b,0x252,0x2d3,0x2a2,0x124,0x110,0x060,0x2ac,0x1b0,0x2ae,0x25e,0x35c,0x239, //  48
466
+            0x0c1,0x0db,0x081,0x0ba,0x0ec,0x11f,0x0c0,0x307,0x116,0x0ad,0x028,0x17b,0x2c8,0x1cf,0x286,0x308, //  64
467
+            0x0ab,0x1eb,0x129,0x2fb,0x09c,0x2dc,0x05f,0x10e,0x1bf,0x05a,0x1fb,0x030,0x0e4,0x335,0x328,0x382, //  80
468
+            0x310,0x297,0x273,0x17a,0x17e,0x106,0x17c,0x25a,0x2f2,0x150,0x059,0x266,0x057,0x1b0,0x29e,0x268, //  96
469
+            0x09d,0x176,0x0f2,0x2d6,0x258,0x10d,0x177,0x382,0x34d,0x1c6,0x162,0x082,0x32e,0x24b,0x324,0x022, // 112
470
+            0x0d3,0x14a,0x21b,0x129,0x33b,0x361,0x025,0x205,0x342,0x13b,0x226,0x056,0x321,0x004,0x06c,0x21b),// 128
471
+        array( // ECL 7 (256 factors) -----------------------------------------------------------------------------
472
+            0x20c,0x37e,0x04b,0x2fe,0x372,0x359,0x04a,0x0cc,0x052,0x24a,0x2c4,0x0fa,0x389,0x312,0x08a,0x2d0, //  16
473
+            0x35a,0x0c2,0x137,0x391,0x113,0x0be,0x177,0x352,0x1b6,0x2dd,0x0c2,0x118,0x0c9,0x118,0x33c,0x2f5, //  32
474
+            0x2c6,0x32e,0x397,0x059,0x044,0x239,0x00b,0x0cc,0x31c,0x25d,0x21c,0x391,0x321,0x2bc,0x31f,0x089, //  48
475
+            0x1b7,0x1a2,0x250,0x29c,0x161,0x35b,0x172,0x2b6,0x145,0x0f0,0x0d8,0x101,0x11c,0x225,0x0d1,0x374, //  64
476
+            0x13b,0x046,0x149,0x319,0x1ea,0x112,0x36d,0x0a2,0x2ed,0x32c,0x2ac,0x1cd,0x14e,0x178,0x351,0x209, //  80
477
+            0x133,0x123,0x323,0x2c8,0x013,0x166,0x18f,0x38c,0x067,0x1ff,0x033,0x008,0x205,0x0e1,0x121,0x1d6, //  96
478
+            0x27d,0x2db,0x042,0x0ff,0x395,0x10d,0x1cf,0x33e,0x2da,0x1b1,0x350,0x249,0x088,0x21a,0x38a,0x05a, // 112
479
+            0x002,0x122,0x2e7,0x0c7,0x28f,0x387,0x149,0x031,0x322,0x244,0x163,0x24c,0x0bc,0x1ce,0x00a,0x086, // 128
480
+            0x274,0x140,0x1df,0x082,0x2e3,0x047,0x107,0x13e,0x176,0x259,0x0c0,0x25d,0x08e,0x2a1,0x2af,0x0ea, // 144
481
+            0x2d2,0x180,0x0b1,0x2f0,0x25f,0x280,0x1c7,0x0c1,0x2b1,0x2c3,0x325,0x281,0x030,0x03c,0x2dc,0x26d, // 160
482
+            0x37f,0x220,0x105,0x354,0x28f,0x135,0x2b9,0x2f3,0x2f4,0x03c,0x0e7,0x305,0x1b2,0x1a5,0x2d6,0x210, // 176
483
+            0x1f7,0x076,0x031,0x31b,0x020,0x090,0x1f4,0x0ee,0x344,0x18a,0x118,0x236,0x13f,0x009,0x287,0x226, // 192
484
+            0x049,0x392,0x156,0x07e,0x020,0x2a9,0x14b,0x318,0x26c,0x03c,0x261,0x1b9,0x0b4,0x317,0x37d,0x2f2, // 208
485
+            0x25d,0x17f,0x0e4,0x2ed,0x2f8,0x0d5,0x036,0x129,0x086,0x036,0x342,0x12b,0x39a,0x0bf,0x38e,0x214, // 224
486
+            0x261,0x33d,0x0bd,0x014,0x0a7,0x01d,0x368,0x1c1,0x053,0x192,0x029,0x290,0x1f9,0x243,0x1e1,0x0ad, // 240
487
+            0x194,0x0fb,0x2b0,0x05f,0x1f1,0x22b,0x282,0x21f,0x133,0x09f,0x39c,0x22e,0x288,0x037,0x1f1,0x00a),// 256
488
+        array( // ECL 8 (512 factors) -----------------------------------------------------------------------------
489
+            0x160,0x04d,0x175,0x1f8,0x023,0x257,0x1ac,0x0cf,0x199,0x23e,0x076,0x1f2,0x11d,0x17c,0x15e,0x1ec, //  16
490
+            0x0c5,0x109,0x398,0x09b,0x392,0x12b,0x0e5,0x283,0x126,0x367,0x132,0x058,0x057,0x0c1,0x160,0x30d, //  32
491
+            0x34e,0x04b,0x147,0x208,0x1b3,0x21f,0x0cb,0x29a,0x0f9,0x15a,0x30d,0x26d,0x280,0x10c,0x31a,0x216, //  48
492
+            0x21b,0x30d,0x198,0x186,0x284,0x066,0x1dc,0x1f3,0x122,0x278,0x221,0x025,0x35a,0x394,0x228,0x029, //  64
493
+            0x21e,0x121,0x07a,0x110,0x17f,0x320,0x1e5,0x062,0x2f0,0x1d8,0x2f9,0x06b,0x310,0x35c,0x292,0x2e5, //  80
494
+            0x122,0x0cc,0x2a9,0x197,0x357,0x055,0x063,0x03e,0x1e2,0x0b4,0x014,0x129,0x1c3,0x251,0x391,0x08e, //  96
495
+            0x328,0x2ac,0x11f,0x218,0x231,0x04c,0x28d,0x383,0x2d9,0x237,0x2e8,0x186,0x201,0x0c0,0x204,0x102, // 112
496
+            0x0f0,0x206,0x31a,0x18b,0x300,0x350,0x033,0x262,0x180,0x0a8,0x0be,0x33a,0x148,0x254,0x312,0x12f, // 128
497
+            0x23a,0x17d,0x19f,0x281,0x09c,0x0ed,0x097,0x1ad,0x213,0x0cf,0x2a4,0x2c6,0x059,0x0a8,0x130,0x192, // 144
498
+            0x028,0x2c4,0x23f,0x0a2,0x360,0x0e5,0x041,0x35d,0x349,0x200,0x0a4,0x1dd,0x0dd,0x05c,0x166,0x311, // 160
499
+            0x120,0x165,0x352,0x344,0x33b,0x2e0,0x2c3,0x05e,0x008,0x1ee,0x072,0x209,0x002,0x1f3,0x353,0x21f, // 176
500
+            0x098,0x2d9,0x303,0x05f,0x0f8,0x169,0x242,0x143,0x358,0x31d,0x121,0x033,0x2ac,0x1d2,0x215,0x334, // 192
501
+            0x29d,0x02d,0x386,0x1c4,0x0a7,0x156,0x0f4,0x0ad,0x023,0x1cf,0x28b,0x033,0x2bb,0x24f,0x1c4,0x242, // 208
502
+            0x025,0x07c,0x12a,0x14c,0x228,0x02b,0x1ab,0x077,0x296,0x309,0x1db,0x352,0x2fc,0x16c,0x242,0x38f, // 224
503
+            0x11b,0x2c7,0x1d8,0x1a4,0x0f5,0x120,0x252,0x18a,0x1ff,0x147,0x24d,0x309,0x2bb,0x2b0,0x02b,0x198, // 240
504
+            0x34a,0x17f,0x2d1,0x209,0x230,0x284,0x2ca,0x22f,0x03e,0x091,0x369,0x297,0x2c9,0x09f,0x2a0,0x2d9, // 256
505
+            0x270,0x03b,0x0c1,0x1a1,0x09e,0x0d1,0x233,0x234,0x157,0x2b5,0x06d,0x260,0x233,0x16d,0x0b5,0x304, // 272
506
+            0x2a5,0x136,0x0f8,0x161,0x2c4,0x19a,0x243,0x366,0x269,0x349,0x278,0x35c,0x121,0x218,0x023,0x309, // 288
507
+            0x26a,0x24a,0x1a8,0x341,0x04d,0x255,0x15a,0x10d,0x2f5,0x278,0x2b7,0x2ef,0x14b,0x0f7,0x0b8,0x02d, // 304
508
+            0x313,0x2a8,0x012,0x042,0x197,0x171,0x036,0x1ec,0x0e4,0x265,0x33e,0x39a,0x1b5,0x207,0x284,0x389, // 320
509
+            0x315,0x1a4,0x131,0x1b9,0x0cf,0x12c,0x37c,0x33b,0x08d,0x219,0x17d,0x296,0x201,0x038,0x0fc,0x155, // 336
510
+            0x0f2,0x31d,0x346,0x345,0x2d0,0x0e0,0x133,0x277,0x03d,0x057,0x230,0x136,0x2f4,0x299,0x18d,0x328, // 352
511
+            0x353,0x135,0x1d9,0x31b,0x17a,0x01f,0x287,0x393,0x1cb,0x326,0x24e,0x2db,0x1a9,0x0d8,0x224,0x0f9, // 368
512
+            0x141,0x371,0x2bb,0x217,0x2a1,0x30e,0x0d2,0x32f,0x389,0x12f,0x34b,0x39a,0x119,0x049,0x1d5,0x317, // 384
513
+            0x294,0x0a2,0x1f2,0x134,0x09b,0x1a6,0x38b,0x331,0x0bb,0x03e,0x010,0x1a9,0x217,0x150,0x11e,0x1b5, // 400
514
+            0x177,0x111,0x262,0x128,0x0b7,0x39b,0x074,0x29b,0x2ef,0x161,0x03e,0x16e,0x2b3,0x17b,0x2af,0x34a, // 416
515
+            0x025,0x165,0x2d0,0x2e6,0x14a,0x005,0x027,0x39b,0x137,0x1a8,0x0f2,0x2ed,0x141,0x036,0x29d,0x13c, // 432
516
+            0x156,0x12b,0x216,0x069,0x29b,0x1e8,0x280,0x2a0,0x240,0x21c,0x13c,0x1e6,0x2d1,0x262,0x02e,0x290, // 448
517
+            0x1bf,0x0ab,0x268,0x1d0,0x0be,0x213,0x129,0x141,0x2fa,0x2f0,0x215,0x0af,0x086,0x00e,0x17d,0x1b1, // 464
518
+            0x2cd,0x02d,0x06f,0x014,0x254,0x11c,0x2e0,0x08a,0x286,0x19b,0x36d,0x29d,0x08d,0x397,0x02d,0x30c, // 480
519
+            0x197,0x0a4,0x14c,0x383,0x0a5,0x2d6,0x258,0x145,0x1f2,0x28f,0x165,0x2f0,0x300,0x0df,0x351,0x287, // 496
520
+            0x03f,0x136,0x35f,0x0fb,0x16e,0x130,0x11a,0x2e2,0x2a3,0x19a,0x185,0x0f4,0x01f,0x079,0x12f,0x107) // 512
521
+    );
522 522
 
523
-	/**
524
-	 * This is the class constructor.
525
-	 * Creates a PDF417 object
526
-	 * @param $code (string) code to represent using PDF417
527
-	 * @param $ecl (int) error correction level (0-8); default -1 = automatic correction level
528
-	 * @param $aspectratio (float) the width to height of the symbol (excluding quiet zones)
529
-	 * @param $macro (array) information for macro block
530
-	 * @public
531
-	 */
532
-	public function __construct($code, $ecl=-1, $aspectratio=2, $macro=array()) {
533
-		$barcode_array = array();
534
-		if ((is_null($code)) OR ($code == '\0') OR ($code == '')) {
535
-			return false;
536
-		}
537
-		// get the input sequence array
538
-		$sequence = $this->getInputSequences($code);
539
-		$codewords = array(); // array of code-words
540
-		foreach($sequence as $seq) {
541
-			$cw = $this->getCompaction($seq[0], $seq[1], true);
542
-			$codewords = array_merge($codewords, $cw);
543
-		}
544
-		if ($codewords[0] == 900) {
545
-			// Text Alpha is the default mode, so remove the first code
546
-			array_shift($codewords);
547
-		}
548
-		// count number of codewords
549
-		$numcw = count($codewords);
550
-		if ($numcw > 925) {
551
-			// reached maximum data codeword capacity
552
-			return false;
553
-		}
554
-		// build macro control block codewords
555
-		if (!empty($macro)) {
556
-			$macrocw = array();
557
-			// beginning of macro control block
558
-			$macrocw[] = 928;
559
-			// segment index
560
-			$cw = $this->getCompaction(902, sprintf('%05d', $macro['segment_index']), false);
561
-			$macrocw = array_merge($macrocw, $cw);
562
-			// file ID
563
-			$cw = $this->getCompaction(900, $macro['file_id'], false);
564
-			$macrocw = array_merge($macrocw, $cw);
565
-			// optional fields
566
-			$optmodes = array(900,902,902,900,900,902,902);
567
-			$optsize = array(-1,2,4,-1,-1,-1,2);
568
-			foreach ($optmodes as $k => $omode) {
569
-				if (isset($macro['option_'.$k])) {
570
-					$macrocw[] = 923;
571
-					$macrocw[] = $k;
572
-					if ($optsize[$k] == 2) {
573
-						$macro['option_'.$k] = sprintf('%05d', $macro['option_'.$k]);
574
-					} elseif ($optsize[$k] == 4) {
575
-						$macro['option_'.$k] = sprintf('%010d', $macro['option_'.$k]);
576
-					}
577
-					$cw = $this->getCompaction($omode, $macro['option_'.$k], false);
578
-					$macrocw = array_merge($macrocw, $cw);
579
-				}
580
-			}
581
-			if ($macro['segment_index'] == ($macro['segment_total'] - 1)) {
582
-				// end of control block
583
-				$macrocw[] = 922;
584
-			}
585
-			// update total codewords
586
-			$numcw += count($macrocw);
587
-		}
588
-		// set error correction level
589
-		$ecl = $this->getErrorCorrectionLevel($ecl, $numcw);
590
-		// number of codewords for error correction
591
-		$errsize = (2 << $ecl);
592
-		// calculate number of columns (number of codewords per row) and rows
593
-		$nce = ($numcw + $errsize + 1);
594
-		$cols = round((sqrt(4761 + (68 * $aspectratio * ROWHEIGHT * $nce)) - 69) / 34);
595
-		// adjust cols
596
-		if ($cols < 1) {
597
-			$cols = 1;
598
-		} elseif ($cols > 30) {
599
-			$cols = 30;
600
-		}
601
-		$rows = ceil($nce / $cols);
602
-		$size = ($cols * $rows);
603
-		// adjust rows
604
-		if (($rows < 3) OR ($rows > 90)) {
605
-			if ($rows < 3) {
606
-				$rows = 3;
607
-			} elseif ($rows > 90) {
608
-				$rows = 90;
609
-			}
610
-			$cols = ceil($size / $rows);
611
-			$size = ($cols * $rows);
612
-		}
613
-		if ($size > 928) {
614
-			// set dimensions to get maximum capacity
615
-			if (abs($aspectratio - (17 * 29 / 32)) < abs($aspectratio - (17 * 16 / 58))) {
616
-				$cols = 29;
617
-				$rows = 32;
618
-			} else {
619
-				$cols = 16;
620
-				$rows = 58;
621
-			}
622
-			$size = 928;
623
-		}
624
-		// calculate padding
625
-		$pad = ($size - $nce);
626
-		if ($pad > 0) {
627
-			if (($size - $rows) == $nce) {
628
-				--$rows;
629
-				$size -= $rows;
630
-			} else {
631
-				// add pading
632
-				$codewords = array_merge($codewords, array_fill(0, $pad, 900));
633
-			}
634
-		}
635
-		if (!empty($macro)) {
636
-			// add macro section
637
-			$codewords = array_merge($codewords, $macrocw);
638
-		}
639
-		// Symbol Lenght Descriptor (number of data codewords including Symbol Lenght Descriptor and pad codewords)
640
-		$sld = $size - $errsize;
641
-		// add symbol length description
642
-		array_unshift($codewords, $sld);
643
-		// calculate error correction
644
-		$ecw = $this->getErrorCorrection($codewords, $ecl);
645
-		// add error correction codewords
646
-		$codewords = array_merge($codewords, $ecw);
647
-		// add horizontal quiet zones to start and stop patterns
648
-		$pstart = str_repeat('0', QUIETH).$this->start_pattern;
649
-		$pstop = $this->stop_pattern.str_repeat('0', QUIETH);
650
-		$barcode_array['num_rows'] = ($rows * ROWHEIGHT) + (2 * QUIETV);
651
-		$barcode_array['num_cols'] = (($cols + 2) * 17) + 35 + (2 * QUIETH);
652
-		$barcode_array['bcode'] = array();
653
-		// build rows for vertical quiet zone
654
-		if (QUIETV > 0) {
655
-			$empty_row = array_fill(0, $barcode_array['num_cols'], 0);
656
-			for ($i = 0; $i < QUIETV; ++$i) {
657
-				// add vertical quiet rows
658
-				$barcode_array['bcode'][] = $empty_row;
659
-			}
660
-		}
661
-		$k = 0; // codeword index
662
-		$cid = 0; // initial cluster
663
-		// for each row
664
-		for ($r = 0; $r < $rows; ++$r) {
665
-			// row start code
666
-			$row = $pstart;
667
-			switch ($cid) {
668
-				case 0: {
669
-					$L = ((30 * intval($r / 3)) + intval(($rows - 1) / 3));
670
-					break;
671
-				}
672
-				case 1: {
673
-					$L = ((30 * intval($r / 3)) + ($ecl * 3) + (($rows - 1) % 3));
674
-					break;
675
-				}
676
-				case 2: {
677
-					$L = ((30 * intval($r / 3)) + ($cols - 1));
678
-					break;
679
-				}
680
-			}
681
-			// left row indicator
682
-			$row .= sprintf('%17b', $this->clusters[$cid][$L]);
683
-			// for each column
684
-			for ($c = 0; $c < $cols; ++$c) {
685
-				$row .= sprintf('%17b', $this->clusters[$cid][$codewords[$k]]);
686
-				++$k;
687
-			}
688
-			switch ($cid) {
689
-				case 0: {
690
-					$L = ((30 * intval($r / 3)) + ($cols - 1));
691
-					break;
692
-				}
693
-				case 1: {
694
-					$L = ((30 * intval($r / 3)) + intval(($rows - 1) / 3));
695
-					break;
696
-				}
697
-				case 2: {
698
-					$L = ((30 * intval($r / 3)) + ($ecl * 3) + (($rows - 1) % 3));
699
-					break;
700
-				}
701
-			}
702
-			// right row indicator
703
-			$row .= sprintf('%17b', $this->clusters[$cid][$L]);
704
-			// row stop code
705
-			$row .= $pstop;
706
-			// convert the string to array
707
-			$arow = preg_split('//', $row, -1, PREG_SPLIT_NO_EMPTY);
708
-			// duplicate row to get the desired height
709
-			for ($h = 0; $h < ROWHEIGHT; ++$h) {
710
-				$barcode_array['bcode'][] = $arow;
711
-			}
712
-			++$cid;
713
-			if ($cid > 2) {
714
-				$cid = 0;
715
-			}
716
-		}
717
-		if (QUIETV > 0) {
718
-			for ($i = 0; $i < QUIETV; ++$i) {
719
-				// add vertical quiet rows
720
-				$barcode_array['bcode'][] = $empty_row;
721
-			}
722
-		}
723
-		$this->barcode_array = $barcode_array;
724
-	}
523
+    /**
524
+     * This is the class constructor.
525
+     * Creates a PDF417 object
526
+     * @param $code (string) code to represent using PDF417
527
+     * @param $ecl (int) error correction level (0-8); default -1 = automatic correction level
528
+     * @param $aspectratio (float) the width to height of the symbol (excluding quiet zones)
529
+     * @param $macro (array) information for macro block
530
+     * @public
531
+     */
532
+    public function __construct($code, $ecl=-1, $aspectratio=2, $macro=array()) {
533
+        $barcode_array = array();
534
+        if ((is_null($code)) OR ($code == '\0') OR ($code == '')) {
535
+            return false;
536
+        }
537
+        // get the input sequence array
538
+        $sequence = $this->getInputSequences($code);
539
+        $codewords = array(); // array of code-words
540
+        foreach($sequence as $seq) {
541
+            $cw = $this->getCompaction($seq[0], $seq[1], true);
542
+            $codewords = array_merge($codewords, $cw);
543
+        }
544
+        if ($codewords[0] == 900) {
545
+            // Text Alpha is the default mode, so remove the first code
546
+            array_shift($codewords);
547
+        }
548
+        // count number of codewords
549
+        $numcw = count($codewords);
550
+        if ($numcw > 925) {
551
+            // reached maximum data codeword capacity
552
+            return false;
553
+        }
554
+        // build macro control block codewords
555
+        if (!empty($macro)) {
556
+            $macrocw = array();
557
+            // beginning of macro control block
558
+            $macrocw[] = 928;
559
+            // segment index
560
+            $cw = $this->getCompaction(902, sprintf('%05d', $macro['segment_index']), false);
561
+            $macrocw = array_merge($macrocw, $cw);
562
+            // file ID
563
+            $cw = $this->getCompaction(900, $macro['file_id'], false);
564
+            $macrocw = array_merge($macrocw, $cw);
565
+            // optional fields
566
+            $optmodes = array(900,902,902,900,900,902,902);
567
+            $optsize = array(-1,2,4,-1,-1,-1,2);
568
+            foreach ($optmodes as $k => $omode) {
569
+                if (isset($macro['option_'.$k])) {
570
+                    $macrocw[] = 923;
571
+                    $macrocw[] = $k;
572
+                    if ($optsize[$k] == 2) {
573
+                        $macro['option_'.$k] = sprintf('%05d', $macro['option_'.$k]);
574
+                    } elseif ($optsize[$k] == 4) {
575
+                        $macro['option_'.$k] = sprintf('%010d', $macro['option_'.$k]);
576
+                    }
577
+                    $cw = $this->getCompaction($omode, $macro['option_'.$k], false);
578
+                    $macrocw = array_merge($macrocw, $cw);
579
+                }
580
+            }
581
+            if ($macro['segment_index'] == ($macro['segment_total'] - 1)) {
582
+                // end of control block
583
+                $macrocw[] = 922;
584
+            }
585
+            // update total codewords
586
+            $numcw += count($macrocw);
587
+        }
588
+        // set error correction level
589
+        $ecl = $this->getErrorCorrectionLevel($ecl, $numcw);
590
+        // number of codewords for error correction
591
+        $errsize = (2 << $ecl);
592
+        // calculate number of columns (number of codewords per row) and rows
593
+        $nce = ($numcw + $errsize + 1);
594
+        $cols = round((sqrt(4761 + (68 * $aspectratio * ROWHEIGHT * $nce)) - 69) / 34);
595
+        // adjust cols
596
+        if ($cols < 1) {
597
+            $cols = 1;
598
+        } elseif ($cols > 30) {
599
+            $cols = 30;
600
+        }
601
+        $rows = ceil($nce / $cols);
602
+        $size = ($cols * $rows);
603
+        // adjust rows
604
+        if (($rows < 3) OR ($rows > 90)) {
605
+            if ($rows < 3) {
606
+                $rows = 3;
607
+            } elseif ($rows > 90) {
608
+                $rows = 90;
609
+            }
610
+            $cols = ceil($size / $rows);
611
+            $size = ($cols * $rows);
612
+        }
613
+        if ($size > 928) {
614
+            // set dimensions to get maximum capacity
615
+            if (abs($aspectratio - (17 * 29 / 32)) < abs($aspectratio - (17 * 16 / 58))) {
616
+                $cols = 29;
617
+                $rows = 32;
618
+            } else {
619
+                $cols = 16;
620
+                $rows = 58;
621
+            }
622
+            $size = 928;
623
+        }
624
+        // calculate padding
625
+        $pad = ($size - $nce);
626
+        if ($pad > 0) {
627
+            if (($size - $rows) == $nce) {
628
+                --$rows;
629
+                $size -= $rows;
630
+            } else {
631
+                // add pading
632
+                $codewords = array_merge($codewords, array_fill(0, $pad, 900));
633
+            }
634
+        }
635
+        if (!empty($macro)) {
636
+            // add macro section
637
+            $codewords = array_merge($codewords, $macrocw);
638
+        }
639
+        // Symbol Lenght Descriptor (number of data codewords including Symbol Lenght Descriptor and pad codewords)
640
+        $sld = $size - $errsize;
641
+        // add symbol length description
642
+        array_unshift($codewords, $sld);
643
+        // calculate error correction
644
+        $ecw = $this->getErrorCorrection($codewords, $ecl);
645
+        // add error correction codewords
646
+        $codewords = array_merge($codewords, $ecw);
647
+        // add horizontal quiet zones to start and stop patterns
648
+        $pstart = str_repeat('0', QUIETH).$this->start_pattern;
649
+        $pstop = $this->stop_pattern.str_repeat('0', QUIETH);
650
+        $barcode_array['num_rows'] = ($rows * ROWHEIGHT) + (2 * QUIETV);
651
+        $barcode_array['num_cols'] = (($cols + 2) * 17) + 35 + (2 * QUIETH);
652
+        $barcode_array['bcode'] = array();
653
+        // build rows for vertical quiet zone
654
+        if (QUIETV > 0) {
655
+            $empty_row = array_fill(0, $barcode_array['num_cols'], 0);
656
+            for ($i = 0; $i < QUIETV; ++$i) {
657
+                // add vertical quiet rows
658
+                $barcode_array['bcode'][] = $empty_row;
659
+            }
660
+        }
661
+        $k = 0; // codeword index
662
+        $cid = 0; // initial cluster
663
+        // for each row
664
+        for ($r = 0; $r < $rows; ++$r) {
665
+            // row start code
666
+            $row = $pstart;
667
+            switch ($cid) {
668
+                case 0: {
669
+                    $L = ((30 * intval($r / 3)) + intval(($rows - 1) / 3));
670
+                    break;
671
+                }
672
+                case 1: {
673
+                    $L = ((30 * intval($r / 3)) + ($ecl * 3) + (($rows - 1) % 3));
674
+                    break;
675
+                }
676
+                case 2: {
677
+                    $L = ((30 * intval($r / 3)) + ($cols - 1));
678
+                    break;
679
+                }
680
+            }
681
+            // left row indicator
682
+            $row .= sprintf('%17b', $this->clusters[$cid][$L]);
683
+            // for each column
684
+            for ($c = 0; $c < $cols; ++$c) {
685
+                $row .= sprintf('%17b', $this->clusters[$cid][$codewords[$k]]);
686
+                ++$k;
687
+            }
688
+            switch ($cid) {
689
+                case 0: {
690
+                    $L = ((30 * intval($r / 3)) + ($cols - 1));
691
+                    break;
692
+                }
693
+                case 1: {
694
+                    $L = ((30 * intval($r / 3)) + intval(($rows - 1) / 3));
695
+                    break;
696
+                }
697
+                case 2: {
698
+                    $L = ((30 * intval($r / 3)) + ($ecl * 3) + (($rows - 1) % 3));
699
+                    break;
700
+                }
701
+            }
702
+            // right row indicator
703
+            $row .= sprintf('%17b', $this->clusters[$cid][$L]);
704
+            // row stop code
705
+            $row .= $pstop;
706
+            // convert the string to array
707
+            $arow = preg_split('//', $row, -1, PREG_SPLIT_NO_EMPTY);
708
+            // duplicate row to get the desired height
709
+            for ($h = 0; $h < ROWHEIGHT; ++$h) {
710
+                $barcode_array['bcode'][] = $arow;
711
+            }
712
+            ++$cid;
713
+            if ($cid > 2) {
714
+                $cid = 0;
715
+            }
716
+        }
717
+        if (QUIETV > 0) {
718
+            for ($i = 0; $i < QUIETV; ++$i) {
719
+                // add vertical quiet rows
720
+                $barcode_array['bcode'][] = $empty_row;
721
+            }
722
+        }
723
+        $this->barcode_array = $barcode_array;
724
+    }
725 725
 
726
-	/**
727
-	 * Returns a barcode array which is readable by TCPDF
728
-	 * @return array barcode array readable by TCPDF;
729
-	 * @public
730
-	 */
731
-	public function getBarcodeArray() {
732
-		return $this->barcode_array;
733
-	}
726
+    /**
727
+     * Returns a barcode array which is readable by TCPDF
728
+     * @return array barcode array readable by TCPDF;
729
+     * @public
730
+     */
731
+    public function getBarcodeArray() {
732
+        return $this->barcode_array;
733
+    }
734 734
 
735
-	/**
736
-	 * Returns the error correction level (0-8) to be used
737
-	 * @param $ecl (int) error correction level
738
-	 * @param $numcw (int) number of data codewords
739
-	 * @return int error correction level
740
-	 * @protected
741
-	 */
742
-	protected function getErrorCorrectionLevel($ecl, $numcw) {
743
-		// get maximum correction level
744
-		$maxecl = 8; // starting error level
745
-		$maxerrsize = (928 - $numcw); // available codewords for error
746
-		while ($maxecl > 0) {
747
-			$errsize = (2 << $ecl);
748
-			if ($maxerrsize >= $errsize) {
749
-				break;
750
-			}
751
-			--$maxecl;
752
-		}
753
-		// check for automatic levels
754
-		if (($ecl < 0) OR ($ecl > 8)) {
755
-			if ($numcw < 41) {
756
-				$ecl = 2;
757
-			} elseif ($numcw < 161) {
758
-				$ecl = 3;
759
-			} elseif ($numcw < 321) {
760
-				$ecl = 4;
761
-			} elseif ($numcw < 864) {
762
-				$ecl = 5;
763
-			} else {
764
-				$ecl = $maxecl;
765
-			}
766
-		}
767
-		if ($ecl > $maxecl) {
768
-			$ecl = $maxecl;
769
-		}
770
-		return $ecl;
771
-	}
735
+    /**
736
+     * Returns the error correction level (0-8) to be used
737
+     * @param $ecl (int) error correction level
738
+     * @param $numcw (int) number of data codewords
739
+     * @return int error correction level
740
+     * @protected
741
+     */
742
+    protected function getErrorCorrectionLevel($ecl, $numcw) {
743
+        // get maximum correction level
744
+        $maxecl = 8; // starting error level
745
+        $maxerrsize = (928 - $numcw); // available codewords for error
746
+        while ($maxecl > 0) {
747
+            $errsize = (2 << $ecl);
748
+            if ($maxerrsize >= $errsize) {
749
+                break;
750
+            }
751
+            --$maxecl;
752
+        }
753
+        // check for automatic levels
754
+        if (($ecl < 0) OR ($ecl > 8)) {
755
+            if ($numcw < 41) {
756
+                $ecl = 2;
757
+            } elseif ($numcw < 161) {
758
+                $ecl = 3;
759
+            } elseif ($numcw < 321) {
760
+                $ecl = 4;
761
+            } elseif ($numcw < 864) {
762
+                $ecl = 5;
763
+            } else {
764
+                $ecl = $maxecl;
765
+            }
766
+        }
767
+        if ($ecl > $maxecl) {
768
+            $ecl = $maxecl;
769
+        }
770
+        return $ecl;
771
+    }
772 772
 
773
-	/**
774
-	 * Returns the error correction codewords
775
-	 * @param $cw (array) array of codewords including Symbol Lenght Descriptor and pad
776
-	 * @param $ecl (int) error correction level 0-8
777
-	 * @return array of error correction codewords
778
-	 * @protected
779
-	 */
780
-	protected function getErrorCorrection($cw, $ecl) {
781
-		// get error correction coefficients
782
-		$ecc = $this->rsfactors[$ecl];
783
-		// number of error correction factors
784
-		$eclsize = (2 << $ecl);
785
-		// maximum index for $rsfactors[$ecl]
786
-		$eclmaxid = ($eclsize - 1);
787
-		// initialize array of error correction codewords
788
-		$ecw = array_fill(0, $eclsize, 0);
789
-		// for each data codeword
790
-		foreach($cw as $k => $d) {
791
-			$t1 = ($d + $ecw[$eclmaxid]) % 929;
792
-			for ($j = $eclmaxid; $j > 0; --$j) {
793
-				$t2 = ($t1 * $ecc[$j]) % 929;
794
-				$t3 = 929 - $t2;
795
-				$ecw[$j] = ($ecw[($j - 1)] + $t3) % 929;
796
-			}
797
-			$t2 = ($t1 * $ecc[0]) % 929;
798
-			$t3 = 929 - $t2;
799
-			$ecw[0] = $t3 % 929;
800
-		}
801
-		foreach($ecw as $j => $e) {
802
-			if ($e != 0) {
803
-				$ecw[$j] = 929 - $e;
804
-			}
805
-		}
806
-		$ecw = array_reverse($ecw);
807
-		return $ecw;
808
-	}
773
+    /**
774
+     * Returns the error correction codewords
775
+     * @param $cw (array) array of codewords including Symbol Lenght Descriptor and pad
776
+     * @param $ecl (int) error correction level 0-8
777
+     * @return array of error correction codewords
778
+     * @protected
779
+     */
780
+    protected function getErrorCorrection($cw, $ecl) {
781
+        // get error correction coefficients
782
+        $ecc = $this->rsfactors[$ecl];
783
+        // number of error correction factors
784
+        $eclsize = (2 << $ecl);
785
+        // maximum index for $rsfactors[$ecl]
786
+        $eclmaxid = ($eclsize - 1);
787
+        // initialize array of error correction codewords
788
+        $ecw = array_fill(0, $eclsize, 0);
789
+        // for each data codeword
790
+        foreach($cw as $k => $d) {
791
+            $t1 = ($d + $ecw[$eclmaxid]) % 929;
792
+            for ($j = $eclmaxid; $j > 0; --$j) {
793
+                $t2 = ($t1 * $ecc[$j]) % 929;
794
+                $t3 = 929 - $t2;
795
+                $ecw[$j] = ($ecw[($j - 1)] + $t3) % 929;
796
+            }
797
+            $t2 = ($t1 * $ecc[0]) % 929;
798
+            $t3 = 929 - $t2;
799
+            $ecw[0] = $t3 % 929;
800
+        }
801
+        foreach($ecw as $j => $e) {
802
+            if ($e != 0) {
803
+                $ecw[$j] = 929 - $e;
804
+            }
805
+        }
806
+        $ecw = array_reverse($ecw);
807
+        return $ecw;
808
+    }
809 809
 
810
-	/**
811
-	 * Create array of sequences from input
812
-	 * @param $code (string) code
813
-	 * @return bidimensional array containing characters and classification
814
-	 * @protected
815
-	 */
816
-	protected function getInputSequences($code) {
817
-		$sequence_array = array(); // array to be returned
818
-		$numseq = array();
819
-		// get numeric sequences
820
-		preg_match_all('/([0-9]{13,44})/', $code, $numseq, PREG_OFFSET_CAPTURE);
821
-		$numseq[1][] = array('', strlen($code));
822
-		$offset = 0;
823
-		foreach($numseq[1] as $seq) {
824
-			$seqlen = strlen($seq[0]);
825
-			if ($seq[1] > 0) {
826
-				// extract text sequence before the number sequence
827
-				$prevseq = substr($code, $offset, ($seq[1] - $offset));
828
-				$textseq = array();
829
-				// get text sequences
830
-				preg_match_all('/([\x09\x0a\x0d\x20-\x7e]{5,})/', $prevseq, $textseq, PREG_OFFSET_CAPTURE);
831
-				$textseq[1][] = array('', strlen($prevseq));
832
-				$txtoffset = 0;
833
-				foreach($textseq[1] as $txtseq) {
834
-					$txtseqlen = strlen($txtseq[0]);
835
-					if ($txtseq[1] > 0) {
836
-						// extract byte sequence before the text sequence
837
-						$prevtxtseq = substr($prevseq, $txtoffset, ($txtseq[1] - $txtoffset));
838
-						if (strlen($prevtxtseq) > 0) {
839
-							// add BYTE sequence
840
-							if ((strlen($prevtxtseq) == 1) AND ((count($sequence_array) > 0) AND ($sequence_array[(count($sequence_array) - 1)][0] == 900))) {
841
-								$sequence_array[] = array(913, $prevtxtseq);
842
-							} elseif ((strlen($prevtxtseq) % 6) == 0) {
843
-								$sequence_array[] = array(924, $prevtxtseq);
844
-							} else {
845
-								$sequence_array[] = array(901, $prevtxtseq);
846
-							}
847
-						}
848
-					}
849
-					if ($txtseqlen > 0) {
850
-						// add numeric sequence
851
-						$sequence_array[] = array(900, $txtseq[0]);
852
-					}
853
-					$txtoffset = $txtseq[1] + $txtseqlen;
854
-				}
855
-			}
856
-			if ($seqlen > 0) {
857
-				// add numeric sequence
858
-				$sequence_array[] = array(902, $seq[0]);
859
-			}
860
-			$offset = $seq[1] + $seqlen;
861
-		}
862
-		return $sequence_array;
863
-	}
810
+    /**
811
+     * Create array of sequences from input
812
+     * @param $code (string) code
813
+     * @return bidimensional array containing characters and classification
814
+     * @protected
815
+     */
816
+    protected function getInputSequences($code) {
817
+        $sequence_array = array(); // array to be returned
818
+        $numseq = array();
819
+        // get numeric sequences
820
+        preg_match_all('/([0-9]{13,44})/', $code, $numseq, PREG_OFFSET_CAPTURE);
821
+        $numseq[1][] = array('', strlen($code));
822
+        $offset = 0;
823
+        foreach($numseq[1] as $seq) {
824
+            $seqlen = strlen($seq[0]);
825
+            if ($seq[1] > 0) {
826
+                // extract text sequence before the number sequence
827
+                $prevseq = substr($code, $offset, ($seq[1] - $offset));
828
+                $textseq = array();
829
+                // get text sequences
830
+                preg_match_all('/([\x09\x0a\x0d\x20-\x7e]{5,})/', $prevseq, $textseq, PREG_OFFSET_CAPTURE);
831
+                $textseq[1][] = array('', strlen($prevseq));
832
+                $txtoffset = 0;
833
+                foreach($textseq[1] as $txtseq) {
834
+                    $txtseqlen = strlen($txtseq[0]);
835
+                    if ($txtseq[1] > 0) {
836
+                        // extract byte sequence before the text sequence
837
+                        $prevtxtseq = substr($prevseq, $txtoffset, ($txtseq[1] - $txtoffset));
838
+                        if (strlen($prevtxtseq) > 0) {
839
+                            // add BYTE sequence
840
+                            if ((strlen($prevtxtseq) == 1) AND ((count($sequence_array) > 0) AND ($sequence_array[(count($sequence_array) - 1)][0] == 900))) {
841
+                                $sequence_array[] = array(913, $prevtxtseq);
842
+                            } elseif ((strlen($prevtxtseq) % 6) == 0) {
843
+                                $sequence_array[] = array(924, $prevtxtseq);
844
+                            } else {
845
+                                $sequence_array[] = array(901, $prevtxtseq);
846
+                            }
847
+                        }
848
+                    }
849
+                    if ($txtseqlen > 0) {
850
+                        // add numeric sequence
851
+                        $sequence_array[] = array(900, $txtseq[0]);
852
+                    }
853
+                    $txtoffset = $txtseq[1] + $txtseqlen;
854
+                }
855
+            }
856
+            if ($seqlen > 0) {
857
+                // add numeric sequence
858
+                $sequence_array[] = array(902, $seq[0]);
859
+            }
860
+            $offset = $seq[1] + $seqlen;
861
+        }
862
+        return $sequence_array;
863
+    }
864 864
 
865
-	/**
866
-	 * Compact data by mode.
867
-	 * @param $mode (int) compaction mode number
868
-	 * @param $code (string) data to compact
869
-	 * @param $addmode (boolean) if true add the mode codeword at first position
870
-	 * @return array of codewords
871
-	 * @protected
872
-	 */
873
-	protected function getCompaction($mode, $code, $addmode=true) {
874
-		$cw = array(); // array of codewords to return
875
-		switch($mode) {
876
-			case 900: { // Text Compaction mode latch
877
-				$submode = 0; // default Alpha sub-mode
878
-				$txtarr = array(); // array of characters and sub-mode switching characters
879
-				$codelen = strlen($code);
880
-				for ($i = 0; $i < $codelen; ++$i) {
881
-					$chval = ord($code{$i});
882
-					if (($k = array_search($chval, $this->textsubmodes[$submode])) !== false) {
883
-						// we are on the same sub-mode
884
-						$txtarr[] = $k;
885
-					} else {
886
-						// the sub-mode is changed
887
-						for ($s = 0; $s < 4; ++$s) {
888
-							// search new sub-mode
889
-							if (($s != $submode) AND (($k = array_search($chval, $this->textsubmodes[$s])) !== false)) {
890
-								// $s is the new submode
891
-								if (((($i + 1) == $codelen) OR ((($i + 1) < $codelen) AND (array_search(ord($code{($i + 1)}), $this->textsubmodes[$submode]) !== false))) AND (($s == 3) OR (($s == 0) AND ($submode == 1)))) {
892
-									// shift (temporary change only for this char)
893
-									if ($s == 3) {
894
-										// shift to puntuaction
895
-										$txtarr[] = 29;
896
-									} else {
897
-										// shift from lower to alpha
898
-										$txtarr[] = 27;
899
-									}
900
-								} else {
901
-									// latch
902
-									$txtarr	= array_merge($txtarr, $this->textlatch[''.$submode.$s]);
903
-									// set new submode
904
-									$submode = $s;
905
-								}
906
-								// add characted code to array
907
-								$txtarr[] = $k;
908
-								break;
909
-							}
910
-						}
911
-					}
912
-				}
913
-				$txtarrlen = count($txtarr);
914
-				if (($txtarrlen % 2) != 0) {
915
-					// add padding
916
-					$txtarr[] = 29;
917
-					++$txtarrlen;
918
-				}
919
-				// calculate codewords
920
-				for ($i = 0; $i < $txtarrlen; $i += 2) {
921
-					$cw[] = (30 * $txtarr[$i]) + $txtarr[($i + 1)];
922
-				}
923
-				break;
924
-			}
925
-			case 901:
926
-			case 924: { // Byte Compaction mode latch
927
-				while (($codelen = strlen($code)) > 0) {
928
-					if ($codelen > 6) {
929
-						$rest = substr($code, 6);
930
-						$code = substr($code, 0, 6);
931
-						$sublen = 6;
932
-					} else {
933
-						$rest = '';
934
-						$sublen = strlen($code);
935
-					}
936
-					if ($sublen == 6) {
937
-						$t = bcmul(''.ord($code[0]), '1099511627776');
938
-						$t = bcadd($t, bcmul(''.ord($code[1]), '4294967296'));
939
-						$t = bcadd($t, bcmul(''.ord($code[2]), '16777216'));
940
-						$t = bcadd($t, bcmul(''.ord($code[3]), '65536'));
941
-						$t = bcadd($t, bcmul(''.ord($code[4]), '256'));
942
-						$t = bcadd($t, ''.ord($code[5]));
943
-						// tmp array for the 6 bytes block
944
-						$cw6 = array();
945
-						do {
946
-							$d = bcmod($t, '900');
947
-							$t = bcdiv($t, '900');
948
-							// prepend the value to the beginning of the array
949
-							array_unshift($cw6, $d);
950
-						} while ($t != '0');
951
-						// append the result array at the end
952
-						$cw = array_merge($cw, $cw6);
953
-					} else {
954
-						for ($i = 0; $i < $sublen; ++$i) {
955
-							$cw[] = ord($code{$i});
956
-						}
957
-					}
958
-					$code = $rest;
959
-				}
960
-				break;
961
-			}
962
-			case 902: { // Numeric Compaction mode latch
963
-				while (($codelen = strlen($code)) > 0) {
964
-					if ($codelen > 44) {
965
-						$rest = substr($code, 44);
966
-						$code = substr($code, 0, 44);
967
-					} else {
968
-						$rest = '';
969
-					}
970
-					$t = '1'.$code;
971
-					do {
972
-						$d = bcmod($t, '900');
973
-						$t = bcdiv($t, '900');
974
-						array_unshift($cw, $d);
975
-					} while ($t != '0');
976
-					$code = $rest;
977
-				}
978
-				break;
979
-			}
980
-			case 913: { // Byte Compaction mode shift
981
-				$cw[] = ord($code);
982
-				break;
983
-			}
984
-		}
985
-		if ($addmode) {
986
-			// add the compaction mode codeword at the beginning
987
-			array_unshift($cw, $mode);
988
-		}
989
-		return $cw;
990
-	}
865
+    /**
866
+     * Compact data by mode.
867
+     * @param $mode (int) compaction mode number
868
+     * @param $code (string) data to compact
869
+     * @param $addmode (boolean) if true add the mode codeword at first position
870
+     * @return array of codewords
871
+     * @protected
872
+     */
873
+    protected function getCompaction($mode, $code, $addmode=true) {
874
+        $cw = array(); // array of codewords to return
875
+        switch($mode) {
876
+            case 900: { // Text Compaction mode latch
877
+                $submode = 0; // default Alpha sub-mode
878
+                $txtarr = array(); // array of characters and sub-mode switching characters
879
+                $codelen = strlen($code);
880
+                for ($i = 0; $i < $codelen; ++$i) {
881
+                    $chval = ord($code{$i});
882
+                    if (($k = array_search($chval, $this->textsubmodes[$submode])) !== false) {
883
+                        // we are on the same sub-mode
884
+                        $txtarr[] = $k;
885
+                    } else {
886
+                        // the sub-mode is changed
887
+                        for ($s = 0; $s < 4; ++$s) {
888
+                            // search new sub-mode
889
+                            if (($s != $submode) AND (($k = array_search($chval, $this->textsubmodes[$s])) !== false)) {
890
+                                // $s is the new submode
891
+                                if (((($i + 1) == $codelen) OR ((($i + 1) < $codelen) AND (array_search(ord($code{($i + 1)}), $this->textsubmodes[$submode]) !== false))) AND (($s == 3) OR (($s == 0) AND ($submode == 1)))) {
892
+                                    // shift (temporary change only for this char)
893
+                                    if ($s == 3) {
894
+                                        // shift to puntuaction
895
+                                        $txtarr[] = 29;
896
+                                    } else {
897
+                                        // shift from lower to alpha
898
+                                        $txtarr[] = 27;
899
+                                    }
900
+                                } else {
901
+                                    // latch
902
+                                    $txtarr	= array_merge($txtarr, $this->textlatch[''.$submode.$s]);
903
+                                    // set new submode
904
+                                    $submode = $s;
905
+                                }
906
+                                // add characted code to array
907
+                                $txtarr[] = $k;
908
+                                break;
909
+                            }
910
+                        }
911
+                    }
912
+                }
913
+                $txtarrlen = count($txtarr);
914
+                if (($txtarrlen % 2) != 0) {
915
+                    // add padding
916
+                    $txtarr[] = 29;
917
+                    ++$txtarrlen;
918
+                }
919
+                // calculate codewords
920
+                for ($i = 0; $i < $txtarrlen; $i += 2) {
921
+                    $cw[] = (30 * $txtarr[$i]) + $txtarr[($i + 1)];
922
+                }
923
+                break;
924
+            }
925
+            case 901:
926
+            case 924: { // Byte Compaction mode latch
927
+                while (($codelen = strlen($code)) > 0) {
928
+                    if ($codelen > 6) {
929
+                        $rest = substr($code, 6);
930
+                        $code = substr($code, 0, 6);
931
+                        $sublen = 6;
932
+                    } else {
933
+                        $rest = '';
934
+                        $sublen = strlen($code);
935
+                    }
936
+                    if ($sublen == 6) {
937
+                        $t = bcmul(''.ord($code[0]), '1099511627776');
938
+                        $t = bcadd($t, bcmul(''.ord($code[1]), '4294967296'));
939
+                        $t = bcadd($t, bcmul(''.ord($code[2]), '16777216'));
940
+                        $t = bcadd($t, bcmul(''.ord($code[3]), '65536'));
941
+                        $t = bcadd($t, bcmul(''.ord($code[4]), '256'));
942
+                        $t = bcadd($t, ''.ord($code[5]));
943
+                        // tmp array for the 6 bytes block
944
+                        $cw6 = array();
945
+                        do {
946
+                            $d = bcmod($t, '900');
947
+                            $t = bcdiv($t, '900');
948
+                            // prepend the value to the beginning of the array
949
+                            array_unshift($cw6, $d);
950
+                        } while ($t != '0');
951
+                        // append the result array at the end
952
+                        $cw = array_merge($cw, $cw6);
953
+                    } else {
954
+                        for ($i = 0; $i < $sublen; ++$i) {
955
+                            $cw[] = ord($code{$i});
956
+                        }
957
+                    }
958
+                    $code = $rest;
959
+                }
960
+                break;
961
+            }
962
+            case 902: { // Numeric Compaction mode latch
963
+                while (($codelen = strlen($code)) > 0) {
964
+                    if ($codelen > 44) {
965
+                        $rest = substr($code, 44);
966
+                        $code = substr($code, 0, 44);
967
+                    } else {
968
+                        $rest = '';
969
+                    }
970
+                    $t = '1'.$code;
971
+                    do {
972
+                        $d = bcmod($t, '900');
973
+                        $t = bcdiv($t, '900');
974
+                        array_unshift($cw, $d);
975
+                    } while ($t != '0');
976
+                    $code = $rest;
977
+                }
978
+                break;
979
+            }
980
+            case 913: { // Byte Compaction mode shift
981
+                $cw[] = ord($code);
982
+                break;
983
+            }
984
+        }
985
+        if ($addmode) {
986
+            // add the compaction mode codeword at the beginning
987
+            array_unshift($cw, $mode);
988
+        }
989
+        return $cw;
990
+    }
991 991
 
992 992
 } // end PDF417 class
993 993
 
Please login to merge, or discard this patch.
Spacing   +385 added lines, -385 removed lines patch added patch discarded remove patch
@@ -115,10 +115,10 @@  discard block
 block discarded – undo
115 115
 	 * @protected
116 116
 	 */
117 117
 	protected $textsubmodes = array(
118
-		array(0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x20,0xFD,0xFE,0xFF), // Alpha
119
-		array(0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x20,0xFD,0xFE,0xFF), // Lower
120
-		array(0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x26,0x0d,0x09,0x2c,0x3a,0x23,0x2d,0x2e,0x24,0x2f,0x2b,0x25,0x2a,0x3d,0x5e,0xFB,0x20,0xFD,0xFE,0xFF), // Mixed
121
-		array(0x3b,0x3c,0x3e,0x40,0x5b,0x5c,0x5d,0x5f,0x60,0x7e,0x21,0x0d,0x09,0x2c,0x3a,0x0a,0x2d,0x2e,0x24,0x2f,0x22,0x7c,0x2a,0x28,0x29,0x3f,0x7b,0x7d,0x27,0xFF) // Puntuaction
118
+		array(0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x20, 0xFD, 0xFE, 0xFF), // Alpha
119
+		array(0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x20, 0xFD, 0xFE, 0xFF), // Lower
120
+		array(0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x26, 0x0d, 0x09, 0x2c, 0x3a, 0x23, 0x2d, 0x2e, 0x24, 0x2f, 0x2b, 0x25, 0x2a, 0x3d, 0x5e, 0xFB, 0x20, 0xFD, 0xFE, 0xFF), // Mixed
121
+		array(0x3b, 0x3c, 0x3e, 0x40, 0x5b, 0x5c, 0x5d, 0x5f, 0x60, 0x7e, 0x21, 0x0d, 0x09, 0x2c, 0x3a, 0x0a, 0x2d, 0x2e, 0x24, 0x2f, 0x22, 0x7c, 0x2a, 0x28, 0x29, 0x3f, 0x7b, 0x7d, 0x27, 0xFF) // Puntuaction
122 122
 	);
123 123
 
124 124
 	/**
@@ -126,10 +126,10 @@  discard block
 block discarded – undo
126 126
 	 * @protected
127 127
 	 */
128 128
 	protected $textlatch = array(
129
-		'01' => array(27), '02' => array(28), '03' => array(28,25), //
130
-		'10' => array(28,28), '12' => array(28), '13' => array(28,25), //
129
+		'01' => array(27), '02' => array(28), '03' => array(28, 25), //
130
+		'10' => array(28, 28), '12' => array(28), '13' => array(28, 25), //
131 131
 		'20' => array(28), '21' => array(27), '23' => array(25), //
132
-		'30' => array(29), '31' => array(29,27), '32' => array(29,28) //
132
+		'30' => array(29), '31' => array(29, 27), '32' => array(29, 28) //
133 133
 	);
134 134
 
135 135
 	/**
@@ -155,287 +155,287 @@  discard block
 block discarded – undo
155 155
 	 */
156 156
 	protected $clusters = array(
157 157
 		array( // cluster 0 -----------------------------------------------------------------------
158
-			0x1d5c0,0x1eaf0,0x1f57c,0x1d4e0,0x1ea78,0x1f53e,0x1a8c0,0x1d470,0x1a860,0x15040, //  10
159
-			0x1a830,0x15020,0x1adc0,0x1d6f0,0x1eb7c,0x1ace0,0x1d678,0x1eb3e,0x158c0,0x1ac70, //  20
160
-			0x15860,0x15dc0,0x1aef0,0x1d77c,0x15ce0,0x1ae78,0x1d73e,0x15c70,0x1ae3c,0x15ef0, //  30
161
-			0x1af7c,0x15e78,0x1af3e,0x15f7c,0x1f5fa,0x1d2e0,0x1e978,0x1f4be,0x1a4c0,0x1d270, //  40
162
-			0x1e93c,0x1a460,0x1d238,0x14840,0x1a430,0x1d21c,0x14820,0x1a418,0x14810,0x1a6e0, //  50
163
-			0x1d378,0x1e9be,0x14cc0,0x1a670,0x1d33c,0x14c60,0x1a638,0x1d31e,0x14c30,0x1a61c, //  60
164
-			0x14ee0,0x1a778,0x1d3be,0x14e70,0x1a73c,0x14e38,0x1a71e,0x14f78,0x1a7be,0x14f3c, //  70
165
-			0x14f1e,0x1a2c0,0x1d170,0x1e8bc,0x1a260,0x1d138,0x1e89e,0x14440,0x1a230,0x1d11c, //  80
166
-			0x14420,0x1a218,0x14410,0x14408,0x146c0,0x1a370,0x1d1bc,0x14660,0x1a338,0x1d19e, //  90
167
-			0x14630,0x1a31c,0x14618,0x1460c,0x14770,0x1a3bc,0x14738,0x1a39e,0x1471c,0x147bc, // 100
168
-			0x1a160,0x1d0b8,0x1e85e,0x14240,0x1a130,0x1d09c,0x14220,0x1a118,0x1d08e,0x14210, // 110
169
-			0x1a10c,0x14208,0x1a106,0x14360,0x1a1b8,0x1d0de,0x14330,0x1a19c,0x14318,0x1a18e, // 120
170
-			0x1430c,0x14306,0x1a1de,0x1438e,0x14140,0x1a0b0,0x1d05c,0x14120,0x1a098,0x1d04e, // 130
171
-			0x14110,0x1a08c,0x14108,0x1a086,0x14104,0x141b0,0x14198,0x1418c,0x140a0,0x1d02e, // 140
172
-			0x1a04c,0x1a046,0x14082,0x1cae0,0x1e578,0x1f2be,0x194c0,0x1ca70,0x1e53c,0x19460, // 150
173
-			0x1ca38,0x1e51e,0x12840,0x19430,0x12820,0x196e0,0x1cb78,0x1e5be,0x12cc0,0x19670, // 160
174
-			0x1cb3c,0x12c60,0x19638,0x12c30,0x12c18,0x12ee0,0x19778,0x1cbbe,0x12e70,0x1973c, // 170
175
-			0x12e38,0x12e1c,0x12f78,0x197be,0x12f3c,0x12fbe,0x1dac0,0x1ed70,0x1f6bc,0x1da60, // 180
176
-			0x1ed38,0x1f69e,0x1b440,0x1da30,0x1ed1c,0x1b420,0x1da18,0x1ed0e,0x1b410,0x1da0c, // 190
177
-			0x192c0,0x1c970,0x1e4bc,0x1b6c0,0x19260,0x1c938,0x1e49e,0x1b660,0x1db38,0x1ed9e, // 200
178
-			0x16c40,0x12420,0x19218,0x1c90e,0x16c20,0x1b618,0x16c10,0x126c0,0x19370,0x1c9bc, // 210
179
-			0x16ec0,0x12660,0x19338,0x1c99e,0x16e60,0x1b738,0x1db9e,0x16e30,0x12618,0x16e18, // 220
180
-			0x12770,0x193bc,0x16f70,0x12738,0x1939e,0x16f38,0x1b79e,0x16f1c,0x127bc,0x16fbc, // 230
181
-			0x1279e,0x16f9e,0x1d960,0x1ecb8,0x1f65e,0x1b240,0x1d930,0x1ec9c,0x1b220,0x1d918, // 240
182
-			0x1ec8e,0x1b210,0x1d90c,0x1b208,0x1b204,0x19160,0x1c8b8,0x1e45e,0x1b360,0x19130, // 250
183
-			0x1c89c,0x16640,0x12220,0x1d99c,0x1c88e,0x16620,0x12210,0x1910c,0x16610,0x1b30c, // 260
184
-			0x19106,0x12204,0x12360,0x191b8,0x1c8de,0x16760,0x12330,0x1919c,0x16730,0x1b39c, // 270
185
-			0x1918e,0x16718,0x1230c,0x12306,0x123b8,0x191de,0x167b8,0x1239c,0x1679c,0x1238e, // 280
186
-			0x1678e,0x167de,0x1b140,0x1d8b0,0x1ec5c,0x1b120,0x1d898,0x1ec4e,0x1b110,0x1d88c, // 290
187
-			0x1b108,0x1d886,0x1b104,0x1b102,0x12140,0x190b0,0x1c85c,0x16340,0x12120,0x19098, // 300
188
-			0x1c84e,0x16320,0x1b198,0x1d8ce,0x16310,0x12108,0x19086,0x16308,0x1b186,0x16304, // 310
189
-			0x121b0,0x190dc,0x163b0,0x12198,0x190ce,0x16398,0x1b1ce,0x1638c,0x12186,0x16386, // 320
190
-			0x163dc,0x163ce,0x1b0a0,0x1d858,0x1ec2e,0x1b090,0x1d84c,0x1b088,0x1d846,0x1b084, // 330
191
-			0x1b082,0x120a0,0x19058,0x1c82e,0x161a0,0x12090,0x1904c,0x16190,0x1b0cc,0x19046, // 340
192
-			0x16188,0x12084,0x16184,0x12082,0x120d8,0x161d8,0x161cc,0x161c6,0x1d82c,0x1d826, // 350
193
-			0x1b042,0x1902c,0x12048,0x160c8,0x160c4,0x160c2,0x18ac0,0x1c570,0x1e2bc,0x18a60, // 360
194
-			0x1c538,0x11440,0x18a30,0x1c51c,0x11420,0x18a18,0x11410,0x11408,0x116c0,0x18b70, // 370
195
-			0x1c5bc,0x11660,0x18b38,0x1c59e,0x11630,0x18b1c,0x11618,0x1160c,0x11770,0x18bbc, // 380
196
-			0x11738,0x18b9e,0x1171c,0x117bc,0x1179e,0x1cd60,0x1e6b8,0x1f35e,0x19a40,0x1cd30, // 390
197
-			0x1e69c,0x19a20,0x1cd18,0x1e68e,0x19a10,0x1cd0c,0x19a08,0x1cd06,0x18960,0x1c4b8, // 400
198
-			0x1e25e,0x19b60,0x18930,0x1c49c,0x13640,0x11220,0x1cd9c,0x1c48e,0x13620,0x19b18, // 410
199
-			0x1890c,0x13610,0x11208,0x13608,0x11360,0x189b8,0x1c4de,0x13760,0x11330,0x1cdde, // 420
200
-			0x13730,0x19b9c,0x1898e,0x13718,0x1130c,0x1370c,0x113b8,0x189de,0x137b8,0x1139c, // 430
201
-			0x1379c,0x1138e,0x113de,0x137de,0x1dd40,0x1eeb0,0x1f75c,0x1dd20,0x1ee98,0x1f74e, // 440
202
-			0x1dd10,0x1ee8c,0x1dd08,0x1ee86,0x1dd04,0x19940,0x1ccb0,0x1e65c,0x1bb40,0x19920, // 450
203
-			0x1eedc,0x1e64e,0x1bb20,0x1dd98,0x1eece,0x1bb10,0x19908,0x1cc86,0x1bb08,0x1dd86, // 460
204
-			0x19902,0x11140,0x188b0,0x1c45c,0x13340,0x11120,0x18898,0x1c44e,0x17740,0x13320, // 470
205
-			0x19998,0x1ccce,0x17720,0x1bb98,0x1ddce,0x18886,0x17710,0x13308,0x19986,0x17708, // 480
206
-			0x11102,0x111b0,0x188dc,0x133b0,0x11198,0x188ce,0x177b0,0x13398,0x199ce,0x17798, // 490
207
-			0x1bbce,0x11186,0x13386,0x111dc,0x133dc,0x111ce,0x177dc,0x133ce,0x1dca0,0x1ee58, // 500
208
-			0x1f72e,0x1dc90,0x1ee4c,0x1dc88,0x1ee46,0x1dc84,0x1dc82,0x198a0,0x1cc58,0x1e62e, // 510
209
-			0x1b9a0,0x19890,0x1ee6e,0x1b990,0x1dccc,0x1cc46,0x1b988,0x19884,0x1b984,0x19882, // 520
210
-			0x1b982,0x110a0,0x18858,0x1c42e,0x131a0,0x11090,0x1884c,0x173a0,0x13190,0x198cc, // 530
211
-			0x18846,0x17390,0x1b9cc,0x11084,0x17388,0x13184,0x11082,0x13182,0x110d8,0x1886e, // 540
212
-			0x131d8,0x110cc,0x173d8,0x131cc,0x110c6,0x173cc,0x131c6,0x110ee,0x173ee,0x1dc50, // 550
213
-			0x1ee2c,0x1dc48,0x1ee26,0x1dc44,0x1dc42,0x19850,0x1cc2c,0x1b8d0,0x19848,0x1cc26, // 560
214
-			0x1b8c8,0x1dc66,0x1b8c4,0x19842,0x1b8c2,0x11050,0x1882c,0x130d0,0x11048,0x18826, // 570
215
-			0x171d0,0x130c8,0x19866,0x171c8,0x1b8e6,0x11042,0x171c4,0x130c2,0x171c2,0x130ec, // 580
216
-			0x171ec,0x171e6,0x1ee16,0x1dc22,0x1cc16,0x19824,0x19822,0x11028,0x13068,0x170e8, // 590
217
-			0x11022,0x13062,0x18560,0x10a40,0x18530,0x10a20,0x18518,0x1c28e,0x10a10,0x1850c, // 600
218
-			0x10a08,0x18506,0x10b60,0x185b8,0x1c2de,0x10b30,0x1859c,0x10b18,0x1858e,0x10b0c, // 610
219
-			0x10b06,0x10bb8,0x185de,0x10b9c,0x10b8e,0x10bde,0x18d40,0x1c6b0,0x1e35c,0x18d20, // 620
220
-			0x1c698,0x18d10,0x1c68c,0x18d08,0x1c686,0x18d04,0x10940,0x184b0,0x1c25c,0x11b40, // 630
221
-			0x10920,0x1c6dc,0x1c24e,0x11b20,0x18d98,0x1c6ce,0x11b10,0x10908,0x18486,0x11b08, // 640
222
-			0x18d86,0x10902,0x109b0,0x184dc,0x11bb0,0x10998,0x184ce,0x11b98,0x18dce,0x11b8c, // 650
223
-			0x10986,0x109dc,0x11bdc,0x109ce,0x11bce,0x1cea0,0x1e758,0x1f3ae,0x1ce90,0x1e74c, // 660
224
-			0x1ce88,0x1e746,0x1ce84,0x1ce82,0x18ca0,0x1c658,0x19da0,0x18c90,0x1c64c,0x19d90, // 670
225
-			0x1cecc,0x1c646,0x19d88,0x18c84,0x19d84,0x18c82,0x19d82,0x108a0,0x18458,0x119a0, // 680
226
-			0x10890,0x1c66e,0x13ba0,0x11990,0x18ccc,0x18446,0x13b90,0x19dcc,0x10884,0x13b88, // 690
227
-			0x11984,0x10882,0x11982,0x108d8,0x1846e,0x119d8,0x108cc,0x13bd8,0x119cc,0x108c6, // 700
228
-			0x13bcc,0x119c6,0x108ee,0x119ee,0x13bee,0x1ef50,0x1f7ac,0x1ef48,0x1f7a6,0x1ef44, // 710
229
-			0x1ef42,0x1ce50,0x1e72c,0x1ded0,0x1ef6c,0x1e726,0x1dec8,0x1ef66,0x1dec4,0x1ce42, // 720
230
-			0x1dec2,0x18c50,0x1c62c,0x19cd0,0x18c48,0x1c626,0x1bdd0,0x19cc8,0x1ce66,0x1bdc8, // 730
231
-			0x1dee6,0x18c42,0x1bdc4,0x19cc2,0x1bdc2,0x10850,0x1842c,0x118d0,0x10848,0x18426, // 740
232
-			0x139d0,0x118c8,0x18c66,0x17bd0,0x139c8,0x19ce6,0x10842,0x17bc8,0x1bde6,0x118c2, // 750
233
-			0x17bc4,0x1086c,0x118ec,0x10866,0x139ec,0x118e6,0x17bec,0x139e6,0x17be6,0x1ef28, // 760
234
-			0x1f796,0x1ef24,0x1ef22,0x1ce28,0x1e716,0x1de68,0x1ef36,0x1de64,0x1ce22,0x1de62, // 770
235
-			0x18c28,0x1c616,0x19c68,0x18c24,0x1bce8,0x19c64,0x18c22,0x1bce4,0x19c62,0x1bce2, // 780
236
-			0x10828,0x18416,0x11868,0x18c36,0x138e8,0x11864,0x10822,0x179e8,0x138e4,0x11862, // 790
237
-			0x179e4,0x138e2,0x179e2,0x11876,0x179f6,0x1ef12,0x1de34,0x1de32,0x19c34,0x1bc74, // 800
238
-			0x1bc72,0x11834,0x13874,0x178f4,0x178f2,0x10540,0x10520,0x18298,0x10510,0x10508, // 810
239
-			0x10504,0x105b0,0x10598,0x1058c,0x10586,0x105dc,0x105ce,0x186a0,0x18690,0x1c34c, // 820
240
-			0x18688,0x1c346,0x18684,0x18682,0x104a0,0x18258,0x10da0,0x186d8,0x1824c,0x10d90, // 830
241
-			0x186cc,0x10d88,0x186c6,0x10d84,0x10482,0x10d82,0x104d8,0x1826e,0x10dd8,0x186ee, // 840
242
-			0x10dcc,0x104c6,0x10dc6,0x104ee,0x10dee,0x1c750,0x1c748,0x1c744,0x1c742,0x18650, // 850
243
-			0x18ed0,0x1c76c,0x1c326,0x18ec8,0x1c766,0x18ec4,0x18642,0x18ec2,0x10450,0x10cd0, // 860
244
-			0x10448,0x18226,0x11dd0,0x10cc8,0x10444,0x11dc8,0x10cc4,0x10442,0x11dc4,0x10cc2, // 870
245
-			0x1046c,0x10cec,0x10466,0x11dec,0x10ce6,0x11de6,0x1e7a8,0x1e7a4,0x1e7a2,0x1c728, // 880
246
-			0x1cf68,0x1e7b6,0x1cf64,0x1c722,0x1cf62,0x18628,0x1c316,0x18e68,0x1c736,0x19ee8, // 890
247
-			0x18e64,0x18622,0x19ee4,0x18e62,0x19ee2,0x10428,0x18216,0x10c68,0x18636,0x11ce8, // 900
248
-			0x10c64,0x10422,0x13de8,0x11ce4,0x10c62,0x13de4,0x11ce2,0x10436,0x10c76,0x11cf6, // 910
249
-			0x13df6,0x1f7d4,0x1f7d2,0x1e794,0x1efb4,0x1e792,0x1efb2,0x1c714,0x1cf34,0x1c712, // 920
250
-			0x1df74,0x1cf32,0x1df72,0x18614,0x18e34,0x18612,0x19e74,0x18e32,0x1bef4),        // 929
158
+			0x1d5c0, 0x1eaf0, 0x1f57c, 0x1d4e0, 0x1ea78, 0x1f53e, 0x1a8c0, 0x1d470, 0x1a860, 0x15040, //  10
159
+			0x1a830, 0x15020, 0x1adc0, 0x1d6f0, 0x1eb7c, 0x1ace0, 0x1d678, 0x1eb3e, 0x158c0, 0x1ac70, //  20
160
+			0x15860, 0x15dc0, 0x1aef0, 0x1d77c, 0x15ce0, 0x1ae78, 0x1d73e, 0x15c70, 0x1ae3c, 0x15ef0, //  30
161
+			0x1af7c, 0x15e78, 0x1af3e, 0x15f7c, 0x1f5fa, 0x1d2e0, 0x1e978, 0x1f4be, 0x1a4c0, 0x1d270, //  40
162
+			0x1e93c, 0x1a460, 0x1d238, 0x14840, 0x1a430, 0x1d21c, 0x14820, 0x1a418, 0x14810, 0x1a6e0, //  50
163
+			0x1d378, 0x1e9be, 0x14cc0, 0x1a670, 0x1d33c, 0x14c60, 0x1a638, 0x1d31e, 0x14c30, 0x1a61c, //  60
164
+			0x14ee0, 0x1a778, 0x1d3be, 0x14e70, 0x1a73c, 0x14e38, 0x1a71e, 0x14f78, 0x1a7be, 0x14f3c, //  70
165
+			0x14f1e, 0x1a2c0, 0x1d170, 0x1e8bc, 0x1a260, 0x1d138, 0x1e89e, 0x14440, 0x1a230, 0x1d11c, //  80
166
+			0x14420, 0x1a218, 0x14410, 0x14408, 0x146c0, 0x1a370, 0x1d1bc, 0x14660, 0x1a338, 0x1d19e, //  90
167
+			0x14630, 0x1a31c, 0x14618, 0x1460c, 0x14770, 0x1a3bc, 0x14738, 0x1a39e, 0x1471c, 0x147bc, // 100
168
+			0x1a160, 0x1d0b8, 0x1e85e, 0x14240, 0x1a130, 0x1d09c, 0x14220, 0x1a118, 0x1d08e, 0x14210, // 110
169
+			0x1a10c, 0x14208, 0x1a106, 0x14360, 0x1a1b8, 0x1d0de, 0x14330, 0x1a19c, 0x14318, 0x1a18e, // 120
170
+			0x1430c, 0x14306, 0x1a1de, 0x1438e, 0x14140, 0x1a0b0, 0x1d05c, 0x14120, 0x1a098, 0x1d04e, // 130
171
+			0x14110, 0x1a08c, 0x14108, 0x1a086, 0x14104, 0x141b0, 0x14198, 0x1418c, 0x140a0, 0x1d02e, // 140
172
+			0x1a04c, 0x1a046, 0x14082, 0x1cae0, 0x1e578, 0x1f2be, 0x194c0, 0x1ca70, 0x1e53c, 0x19460, // 150
173
+			0x1ca38, 0x1e51e, 0x12840, 0x19430, 0x12820, 0x196e0, 0x1cb78, 0x1e5be, 0x12cc0, 0x19670, // 160
174
+			0x1cb3c, 0x12c60, 0x19638, 0x12c30, 0x12c18, 0x12ee0, 0x19778, 0x1cbbe, 0x12e70, 0x1973c, // 170
175
+			0x12e38, 0x12e1c, 0x12f78, 0x197be, 0x12f3c, 0x12fbe, 0x1dac0, 0x1ed70, 0x1f6bc, 0x1da60, // 180
176
+			0x1ed38, 0x1f69e, 0x1b440, 0x1da30, 0x1ed1c, 0x1b420, 0x1da18, 0x1ed0e, 0x1b410, 0x1da0c, // 190
177
+			0x192c0, 0x1c970, 0x1e4bc, 0x1b6c0, 0x19260, 0x1c938, 0x1e49e, 0x1b660, 0x1db38, 0x1ed9e, // 200
178
+			0x16c40, 0x12420, 0x19218, 0x1c90e, 0x16c20, 0x1b618, 0x16c10, 0x126c0, 0x19370, 0x1c9bc, // 210
179
+			0x16ec0, 0x12660, 0x19338, 0x1c99e, 0x16e60, 0x1b738, 0x1db9e, 0x16e30, 0x12618, 0x16e18, // 220
180
+			0x12770, 0x193bc, 0x16f70, 0x12738, 0x1939e, 0x16f38, 0x1b79e, 0x16f1c, 0x127bc, 0x16fbc, // 230
181
+			0x1279e, 0x16f9e, 0x1d960, 0x1ecb8, 0x1f65e, 0x1b240, 0x1d930, 0x1ec9c, 0x1b220, 0x1d918, // 240
182
+			0x1ec8e, 0x1b210, 0x1d90c, 0x1b208, 0x1b204, 0x19160, 0x1c8b8, 0x1e45e, 0x1b360, 0x19130, // 250
183
+			0x1c89c, 0x16640, 0x12220, 0x1d99c, 0x1c88e, 0x16620, 0x12210, 0x1910c, 0x16610, 0x1b30c, // 260
184
+			0x19106, 0x12204, 0x12360, 0x191b8, 0x1c8de, 0x16760, 0x12330, 0x1919c, 0x16730, 0x1b39c, // 270
185
+			0x1918e, 0x16718, 0x1230c, 0x12306, 0x123b8, 0x191de, 0x167b8, 0x1239c, 0x1679c, 0x1238e, // 280
186
+			0x1678e, 0x167de, 0x1b140, 0x1d8b0, 0x1ec5c, 0x1b120, 0x1d898, 0x1ec4e, 0x1b110, 0x1d88c, // 290
187
+			0x1b108, 0x1d886, 0x1b104, 0x1b102, 0x12140, 0x190b0, 0x1c85c, 0x16340, 0x12120, 0x19098, // 300
188
+			0x1c84e, 0x16320, 0x1b198, 0x1d8ce, 0x16310, 0x12108, 0x19086, 0x16308, 0x1b186, 0x16304, // 310
189
+			0x121b0, 0x190dc, 0x163b0, 0x12198, 0x190ce, 0x16398, 0x1b1ce, 0x1638c, 0x12186, 0x16386, // 320
190
+			0x163dc, 0x163ce, 0x1b0a0, 0x1d858, 0x1ec2e, 0x1b090, 0x1d84c, 0x1b088, 0x1d846, 0x1b084, // 330
191
+			0x1b082, 0x120a0, 0x19058, 0x1c82e, 0x161a0, 0x12090, 0x1904c, 0x16190, 0x1b0cc, 0x19046, // 340
192
+			0x16188, 0x12084, 0x16184, 0x12082, 0x120d8, 0x161d8, 0x161cc, 0x161c6, 0x1d82c, 0x1d826, // 350
193
+			0x1b042, 0x1902c, 0x12048, 0x160c8, 0x160c4, 0x160c2, 0x18ac0, 0x1c570, 0x1e2bc, 0x18a60, // 360
194
+			0x1c538, 0x11440, 0x18a30, 0x1c51c, 0x11420, 0x18a18, 0x11410, 0x11408, 0x116c0, 0x18b70, // 370
195
+			0x1c5bc, 0x11660, 0x18b38, 0x1c59e, 0x11630, 0x18b1c, 0x11618, 0x1160c, 0x11770, 0x18bbc, // 380
196
+			0x11738, 0x18b9e, 0x1171c, 0x117bc, 0x1179e, 0x1cd60, 0x1e6b8, 0x1f35e, 0x19a40, 0x1cd30, // 390
197
+			0x1e69c, 0x19a20, 0x1cd18, 0x1e68e, 0x19a10, 0x1cd0c, 0x19a08, 0x1cd06, 0x18960, 0x1c4b8, // 400
198
+			0x1e25e, 0x19b60, 0x18930, 0x1c49c, 0x13640, 0x11220, 0x1cd9c, 0x1c48e, 0x13620, 0x19b18, // 410
199
+			0x1890c, 0x13610, 0x11208, 0x13608, 0x11360, 0x189b8, 0x1c4de, 0x13760, 0x11330, 0x1cdde, // 420
200
+			0x13730, 0x19b9c, 0x1898e, 0x13718, 0x1130c, 0x1370c, 0x113b8, 0x189de, 0x137b8, 0x1139c, // 430
201
+			0x1379c, 0x1138e, 0x113de, 0x137de, 0x1dd40, 0x1eeb0, 0x1f75c, 0x1dd20, 0x1ee98, 0x1f74e, // 440
202
+			0x1dd10, 0x1ee8c, 0x1dd08, 0x1ee86, 0x1dd04, 0x19940, 0x1ccb0, 0x1e65c, 0x1bb40, 0x19920, // 450
203
+			0x1eedc, 0x1e64e, 0x1bb20, 0x1dd98, 0x1eece, 0x1bb10, 0x19908, 0x1cc86, 0x1bb08, 0x1dd86, // 460
204
+			0x19902, 0x11140, 0x188b0, 0x1c45c, 0x13340, 0x11120, 0x18898, 0x1c44e, 0x17740, 0x13320, // 470
205
+			0x19998, 0x1ccce, 0x17720, 0x1bb98, 0x1ddce, 0x18886, 0x17710, 0x13308, 0x19986, 0x17708, // 480
206
+			0x11102, 0x111b0, 0x188dc, 0x133b0, 0x11198, 0x188ce, 0x177b0, 0x13398, 0x199ce, 0x17798, // 490
207
+			0x1bbce, 0x11186, 0x13386, 0x111dc, 0x133dc, 0x111ce, 0x177dc, 0x133ce, 0x1dca0, 0x1ee58, // 500
208
+			0x1f72e, 0x1dc90, 0x1ee4c, 0x1dc88, 0x1ee46, 0x1dc84, 0x1dc82, 0x198a0, 0x1cc58, 0x1e62e, // 510
209
+			0x1b9a0, 0x19890, 0x1ee6e, 0x1b990, 0x1dccc, 0x1cc46, 0x1b988, 0x19884, 0x1b984, 0x19882, // 520
210
+			0x1b982, 0x110a0, 0x18858, 0x1c42e, 0x131a0, 0x11090, 0x1884c, 0x173a0, 0x13190, 0x198cc, // 530
211
+			0x18846, 0x17390, 0x1b9cc, 0x11084, 0x17388, 0x13184, 0x11082, 0x13182, 0x110d8, 0x1886e, // 540
212
+			0x131d8, 0x110cc, 0x173d8, 0x131cc, 0x110c6, 0x173cc, 0x131c6, 0x110ee, 0x173ee, 0x1dc50, // 550
213
+			0x1ee2c, 0x1dc48, 0x1ee26, 0x1dc44, 0x1dc42, 0x19850, 0x1cc2c, 0x1b8d0, 0x19848, 0x1cc26, // 560
214
+			0x1b8c8, 0x1dc66, 0x1b8c4, 0x19842, 0x1b8c2, 0x11050, 0x1882c, 0x130d0, 0x11048, 0x18826, // 570
215
+			0x171d0, 0x130c8, 0x19866, 0x171c8, 0x1b8e6, 0x11042, 0x171c4, 0x130c2, 0x171c2, 0x130ec, // 580
216
+			0x171ec, 0x171e6, 0x1ee16, 0x1dc22, 0x1cc16, 0x19824, 0x19822, 0x11028, 0x13068, 0x170e8, // 590
217
+			0x11022, 0x13062, 0x18560, 0x10a40, 0x18530, 0x10a20, 0x18518, 0x1c28e, 0x10a10, 0x1850c, // 600
218
+			0x10a08, 0x18506, 0x10b60, 0x185b8, 0x1c2de, 0x10b30, 0x1859c, 0x10b18, 0x1858e, 0x10b0c, // 610
219
+			0x10b06, 0x10bb8, 0x185de, 0x10b9c, 0x10b8e, 0x10bde, 0x18d40, 0x1c6b0, 0x1e35c, 0x18d20, // 620
220
+			0x1c698, 0x18d10, 0x1c68c, 0x18d08, 0x1c686, 0x18d04, 0x10940, 0x184b0, 0x1c25c, 0x11b40, // 630
221
+			0x10920, 0x1c6dc, 0x1c24e, 0x11b20, 0x18d98, 0x1c6ce, 0x11b10, 0x10908, 0x18486, 0x11b08, // 640
222
+			0x18d86, 0x10902, 0x109b0, 0x184dc, 0x11bb0, 0x10998, 0x184ce, 0x11b98, 0x18dce, 0x11b8c, // 650
223
+			0x10986, 0x109dc, 0x11bdc, 0x109ce, 0x11bce, 0x1cea0, 0x1e758, 0x1f3ae, 0x1ce90, 0x1e74c, // 660
224
+			0x1ce88, 0x1e746, 0x1ce84, 0x1ce82, 0x18ca0, 0x1c658, 0x19da0, 0x18c90, 0x1c64c, 0x19d90, // 670
225
+			0x1cecc, 0x1c646, 0x19d88, 0x18c84, 0x19d84, 0x18c82, 0x19d82, 0x108a0, 0x18458, 0x119a0, // 680
226
+			0x10890, 0x1c66e, 0x13ba0, 0x11990, 0x18ccc, 0x18446, 0x13b90, 0x19dcc, 0x10884, 0x13b88, // 690
227
+			0x11984, 0x10882, 0x11982, 0x108d8, 0x1846e, 0x119d8, 0x108cc, 0x13bd8, 0x119cc, 0x108c6, // 700
228
+			0x13bcc, 0x119c6, 0x108ee, 0x119ee, 0x13bee, 0x1ef50, 0x1f7ac, 0x1ef48, 0x1f7a6, 0x1ef44, // 710
229
+			0x1ef42, 0x1ce50, 0x1e72c, 0x1ded0, 0x1ef6c, 0x1e726, 0x1dec8, 0x1ef66, 0x1dec4, 0x1ce42, // 720
230
+			0x1dec2, 0x18c50, 0x1c62c, 0x19cd0, 0x18c48, 0x1c626, 0x1bdd0, 0x19cc8, 0x1ce66, 0x1bdc8, // 730
231
+			0x1dee6, 0x18c42, 0x1bdc4, 0x19cc2, 0x1bdc2, 0x10850, 0x1842c, 0x118d0, 0x10848, 0x18426, // 740
232
+			0x139d0, 0x118c8, 0x18c66, 0x17bd0, 0x139c8, 0x19ce6, 0x10842, 0x17bc8, 0x1bde6, 0x118c2, // 750
233
+			0x17bc4, 0x1086c, 0x118ec, 0x10866, 0x139ec, 0x118e6, 0x17bec, 0x139e6, 0x17be6, 0x1ef28, // 760
234
+			0x1f796, 0x1ef24, 0x1ef22, 0x1ce28, 0x1e716, 0x1de68, 0x1ef36, 0x1de64, 0x1ce22, 0x1de62, // 770
235
+			0x18c28, 0x1c616, 0x19c68, 0x18c24, 0x1bce8, 0x19c64, 0x18c22, 0x1bce4, 0x19c62, 0x1bce2, // 780
236
+			0x10828, 0x18416, 0x11868, 0x18c36, 0x138e8, 0x11864, 0x10822, 0x179e8, 0x138e4, 0x11862, // 790
237
+			0x179e4, 0x138e2, 0x179e2, 0x11876, 0x179f6, 0x1ef12, 0x1de34, 0x1de32, 0x19c34, 0x1bc74, // 800
238
+			0x1bc72, 0x11834, 0x13874, 0x178f4, 0x178f2, 0x10540, 0x10520, 0x18298, 0x10510, 0x10508, // 810
239
+			0x10504, 0x105b0, 0x10598, 0x1058c, 0x10586, 0x105dc, 0x105ce, 0x186a0, 0x18690, 0x1c34c, // 820
240
+			0x18688, 0x1c346, 0x18684, 0x18682, 0x104a0, 0x18258, 0x10da0, 0x186d8, 0x1824c, 0x10d90, // 830
241
+			0x186cc, 0x10d88, 0x186c6, 0x10d84, 0x10482, 0x10d82, 0x104d8, 0x1826e, 0x10dd8, 0x186ee, // 840
242
+			0x10dcc, 0x104c6, 0x10dc6, 0x104ee, 0x10dee, 0x1c750, 0x1c748, 0x1c744, 0x1c742, 0x18650, // 850
243
+			0x18ed0, 0x1c76c, 0x1c326, 0x18ec8, 0x1c766, 0x18ec4, 0x18642, 0x18ec2, 0x10450, 0x10cd0, // 860
244
+			0x10448, 0x18226, 0x11dd0, 0x10cc8, 0x10444, 0x11dc8, 0x10cc4, 0x10442, 0x11dc4, 0x10cc2, // 870
245
+			0x1046c, 0x10cec, 0x10466, 0x11dec, 0x10ce6, 0x11de6, 0x1e7a8, 0x1e7a4, 0x1e7a2, 0x1c728, // 880
246
+			0x1cf68, 0x1e7b6, 0x1cf64, 0x1c722, 0x1cf62, 0x18628, 0x1c316, 0x18e68, 0x1c736, 0x19ee8, // 890
247
+			0x18e64, 0x18622, 0x19ee4, 0x18e62, 0x19ee2, 0x10428, 0x18216, 0x10c68, 0x18636, 0x11ce8, // 900
248
+			0x10c64, 0x10422, 0x13de8, 0x11ce4, 0x10c62, 0x13de4, 0x11ce2, 0x10436, 0x10c76, 0x11cf6, // 910
249
+			0x13df6, 0x1f7d4, 0x1f7d2, 0x1e794, 0x1efb4, 0x1e792, 0x1efb2, 0x1c714, 0x1cf34, 0x1c712, // 920
250
+			0x1df74, 0x1cf32, 0x1df72, 0x18614, 0x18e34, 0x18612, 0x19e74, 0x18e32, 0x1bef4), // 929
251 251
 		array( // cluster 3 -----------------------------------------------------------------------
252
-			0x1f560,0x1fab8,0x1ea40,0x1f530,0x1fa9c,0x1ea20,0x1f518,0x1fa8e,0x1ea10,0x1f50c, //  10
253
-			0x1ea08,0x1f506,0x1ea04,0x1eb60,0x1f5b8,0x1fade,0x1d640,0x1eb30,0x1f59c,0x1d620, //  20
254
-			0x1eb18,0x1f58e,0x1d610,0x1eb0c,0x1d608,0x1eb06,0x1d604,0x1d760,0x1ebb8,0x1f5de, //  30
255
-			0x1ae40,0x1d730,0x1eb9c,0x1ae20,0x1d718,0x1eb8e,0x1ae10,0x1d70c,0x1ae08,0x1d706, //  40
256
-			0x1ae04,0x1af60,0x1d7b8,0x1ebde,0x15e40,0x1af30,0x1d79c,0x15e20,0x1af18,0x1d78e, //  50
257
-			0x15e10,0x1af0c,0x15e08,0x1af06,0x15f60,0x1afb8,0x1d7de,0x15f30,0x1af9c,0x15f18, //  60
258
-			0x1af8e,0x15f0c,0x15fb8,0x1afde,0x15f9c,0x15f8e,0x1e940,0x1f4b0,0x1fa5c,0x1e920, //  70
259
-			0x1f498,0x1fa4e,0x1e910,0x1f48c,0x1e908,0x1f486,0x1e904,0x1e902,0x1d340,0x1e9b0, //  80
260
-			0x1f4dc,0x1d320,0x1e998,0x1f4ce,0x1d310,0x1e98c,0x1d308,0x1e986,0x1d304,0x1d302, //  90
261
-			0x1a740,0x1d3b0,0x1e9dc,0x1a720,0x1d398,0x1e9ce,0x1a710,0x1d38c,0x1a708,0x1d386, // 100
262
-			0x1a704,0x1a702,0x14f40,0x1a7b0,0x1d3dc,0x14f20,0x1a798,0x1d3ce,0x14f10,0x1a78c, // 110
263
-			0x14f08,0x1a786,0x14f04,0x14fb0,0x1a7dc,0x14f98,0x1a7ce,0x14f8c,0x14f86,0x14fdc, // 120
264
-			0x14fce,0x1e8a0,0x1f458,0x1fa2e,0x1e890,0x1f44c,0x1e888,0x1f446,0x1e884,0x1e882, // 130
265
-			0x1d1a0,0x1e8d8,0x1f46e,0x1d190,0x1e8cc,0x1d188,0x1e8c6,0x1d184,0x1d182,0x1a3a0, // 140
266
-			0x1d1d8,0x1e8ee,0x1a390,0x1d1cc,0x1a388,0x1d1c6,0x1a384,0x1a382,0x147a0,0x1a3d8, // 150
267
-			0x1d1ee,0x14790,0x1a3cc,0x14788,0x1a3c6,0x14784,0x14782,0x147d8,0x1a3ee,0x147cc, // 160
268
-			0x147c6,0x147ee,0x1e850,0x1f42c,0x1e848,0x1f426,0x1e844,0x1e842,0x1d0d0,0x1e86c, // 170
269
-			0x1d0c8,0x1e866,0x1d0c4,0x1d0c2,0x1a1d0,0x1d0ec,0x1a1c8,0x1d0e6,0x1a1c4,0x1a1c2, // 180
270
-			0x143d0,0x1a1ec,0x143c8,0x1a1e6,0x143c4,0x143c2,0x143ec,0x143e6,0x1e828,0x1f416, // 190
271
-			0x1e824,0x1e822,0x1d068,0x1e836,0x1d064,0x1d062,0x1a0e8,0x1d076,0x1a0e4,0x1a0e2, // 200
272
-			0x141e8,0x1a0f6,0x141e4,0x141e2,0x1e814,0x1e812,0x1d034,0x1d032,0x1a074,0x1a072, // 210
273
-			0x1e540,0x1f2b0,0x1f95c,0x1e520,0x1f298,0x1f94e,0x1e510,0x1f28c,0x1e508,0x1f286, // 220
274
-			0x1e504,0x1e502,0x1cb40,0x1e5b0,0x1f2dc,0x1cb20,0x1e598,0x1f2ce,0x1cb10,0x1e58c, // 230
275
-			0x1cb08,0x1e586,0x1cb04,0x1cb02,0x19740,0x1cbb0,0x1e5dc,0x19720,0x1cb98,0x1e5ce, // 240
276
-			0x19710,0x1cb8c,0x19708,0x1cb86,0x19704,0x19702,0x12f40,0x197b0,0x1cbdc,0x12f20, // 250
277
-			0x19798,0x1cbce,0x12f10,0x1978c,0x12f08,0x19786,0x12f04,0x12fb0,0x197dc,0x12f98, // 260
278
-			0x197ce,0x12f8c,0x12f86,0x12fdc,0x12fce,0x1f6a0,0x1fb58,0x16bf0,0x1f690,0x1fb4c, // 270
279
-			0x169f8,0x1f688,0x1fb46,0x168fc,0x1f684,0x1f682,0x1e4a0,0x1f258,0x1f92e,0x1eda0, // 280
280
-			0x1e490,0x1fb6e,0x1ed90,0x1f6cc,0x1f246,0x1ed88,0x1e484,0x1ed84,0x1e482,0x1ed82, // 290
281
-			0x1c9a0,0x1e4d8,0x1f26e,0x1dba0,0x1c990,0x1e4cc,0x1db90,0x1edcc,0x1e4c6,0x1db88, // 300
282
-			0x1c984,0x1db84,0x1c982,0x1db82,0x193a0,0x1c9d8,0x1e4ee,0x1b7a0,0x19390,0x1c9cc, // 310
283
-			0x1b790,0x1dbcc,0x1c9c6,0x1b788,0x19384,0x1b784,0x19382,0x1b782,0x127a0,0x193d8, // 320
284
-			0x1c9ee,0x16fa0,0x12790,0x193cc,0x16f90,0x1b7cc,0x193c6,0x16f88,0x12784,0x16f84, // 330
285
-			0x12782,0x127d8,0x193ee,0x16fd8,0x127cc,0x16fcc,0x127c6,0x16fc6,0x127ee,0x1f650, // 340
286
-			0x1fb2c,0x165f8,0x1f648,0x1fb26,0x164fc,0x1f644,0x1647e,0x1f642,0x1e450,0x1f22c, // 350
287
-			0x1ecd0,0x1e448,0x1f226,0x1ecc8,0x1f666,0x1ecc4,0x1e442,0x1ecc2,0x1c8d0,0x1e46c, // 360
288
-			0x1d9d0,0x1c8c8,0x1e466,0x1d9c8,0x1ece6,0x1d9c4,0x1c8c2,0x1d9c2,0x191d0,0x1c8ec, // 370
289
-			0x1b3d0,0x191c8,0x1c8e6,0x1b3c8,0x1d9e6,0x1b3c4,0x191c2,0x1b3c2,0x123d0,0x191ec, // 380
290
-			0x167d0,0x123c8,0x191e6,0x167c8,0x1b3e6,0x167c4,0x123c2,0x167c2,0x123ec,0x167ec, // 390
291
-			0x123e6,0x167e6,0x1f628,0x1fb16,0x162fc,0x1f624,0x1627e,0x1f622,0x1e428,0x1f216, // 400
292
-			0x1ec68,0x1f636,0x1ec64,0x1e422,0x1ec62,0x1c868,0x1e436,0x1d8e8,0x1c864,0x1d8e4, // 410
293
-			0x1c862,0x1d8e2,0x190e8,0x1c876,0x1b1e8,0x1d8f6,0x1b1e4,0x190e2,0x1b1e2,0x121e8, // 420
294
-			0x190f6,0x163e8,0x121e4,0x163e4,0x121e2,0x163e2,0x121f6,0x163f6,0x1f614,0x1617e, // 430
295
-			0x1f612,0x1e414,0x1ec34,0x1e412,0x1ec32,0x1c834,0x1d874,0x1c832,0x1d872,0x19074, // 440
296
-			0x1b0f4,0x19072,0x1b0f2,0x120f4,0x161f4,0x120f2,0x161f2,0x1f60a,0x1e40a,0x1ec1a, // 450
297
-			0x1c81a,0x1d83a,0x1903a,0x1b07a,0x1e2a0,0x1f158,0x1f8ae,0x1e290,0x1f14c,0x1e288, // 460
298
-			0x1f146,0x1e284,0x1e282,0x1c5a0,0x1e2d8,0x1f16e,0x1c590,0x1e2cc,0x1c588,0x1e2c6, // 470
299
-			0x1c584,0x1c582,0x18ba0,0x1c5d8,0x1e2ee,0x18b90,0x1c5cc,0x18b88,0x1c5c6,0x18b84, // 480
300
-			0x18b82,0x117a0,0x18bd8,0x1c5ee,0x11790,0x18bcc,0x11788,0x18bc6,0x11784,0x11782, // 490
301
-			0x117d8,0x18bee,0x117cc,0x117c6,0x117ee,0x1f350,0x1f9ac,0x135f8,0x1f348,0x1f9a6, // 500
302
-			0x134fc,0x1f344,0x1347e,0x1f342,0x1e250,0x1f12c,0x1e6d0,0x1e248,0x1f126,0x1e6c8, // 510
303
-			0x1f366,0x1e6c4,0x1e242,0x1e6c2,0x1c4d0,0x1e26c,0x1cdd0,0x1c4c8,0x1e266,0x1cdc8, // 520
304
-			0x1e6e6,0x1cdc4,0x1c4c2,0x1cdc2,0x189d0,0x1c4ec,0x19bd0,0x189c8,0x1c4e6,0x19bc8, // 530
305
-			0x1cde6,0x19bc4,0x189c2,0x19bc2,0x113d0,0x189ec,0x137d0,0x113c8,0x189e6,0x137c8, // 540
306
-			0x19be6,0x137c4,0x113c2,0x137c2,0x113ec,0x137ec,0x113e6,0x137e6,0x1fba8,0x175f0, // 550
307
-			0x1bafc,0x1fba4,0x174f8,0x1ba7e,0x1fba2,0x1747c,0x1743e,0x1f328,0x1f996,0x132fc, // 560
308
-			0x1f768,0x1fbb6,0x176fc,0x1327e,0x1f764,0x1f322,0x1767e,0x1f762,0x1e228,0x1f116, // 570
309
-			0x1e668,0x1e224,0x1eee8,0x1f776,0x1e222,0x1eee4,0x1e662,0x1eee2,0x1c468,0x1e236, // 580
310
-			0x1cce8,0x1c464,0x1dde8,0x1cce4,0x1c462,0x1dde4,0x1cce2,0x1dde2,0x188e8,0x1c476, // 590
311
-			0x199e8,0x188e4,0x1bbe8,0x199e4,0x188e2,0x1bbe4,0x199e2,0x1bbe2,0x111e8,0x188f6, // 600
312
-			0x133e8,0x111e4,0x177e8,0x133e4,0x111e2,0x177e4,0x133e2,0x177e2,0x111f6,0x133f6, // 610
313
-			0x1fb94,0x172f8,0x1b97e,0x1fb92,0x1727c,0x1723e,0x1f314,0x1317e,0x1f734,0x1f312, // 620
314
-			0x1737e,0x1f732,0x1e214,0x1e634,0x1e212,0x1ee74,0x1e632,0x1ee72,0x1c434,0x1cc74, // 630
315
-			0x1c432,0x1dcf4,0x1cc72,0x1dcf2,0x18874,0x198f4,0x18872,0x1b9f4,0x198f2,0x1b9f2, // 640
316
-			0x110f4,0x131f4,0x110f2,0x173f4,0x131f2,0x173f2,0x1fb8a,0x1717c,0x1713e,0x1f30a, // 650
317
-			0x1f71a,0x1e20a,0x1e61a,0x1ee3a,0x1c41a,0x1cc3a,0x1dc7a,0x1883a,0x1987a,0x1b8fa, // 660
318
-			0x1107a,0x130fa,0x171fa,0x170be,0x1e150,0x1f0ac,0x1e148,0x1f0a6,0x1e144,0x1e142, // 670
319
-			0x1c2d0,0x1e16c,0x1c2c8,0x1e166,0x1c2c4,0x1c2c2,0x185d0,0x1c2ec,0x185c8,0x1c2e6, // 680
320
-			0x185c4,0x185c2,0x10bd0,0x185ec,0x10bc8,0x185e6,0x10bc4,0x10bc2,0x10bec,0x10be6, // 690
321
-			0x1f1a8,0x1f8d6,0x11afc,0x1f1a4,0x11a7e,0x1f1a2,0x1e128,0x1f096,0x1e368,0x1e124, // 700
322
-			0x1e364,0x1e122,0x1e362,0x1c268,0x1e136,0x1c6e8,0x1c264,0x1c6e4,0x1c262,0x1c6e2, // 710
323
-			0x184e8,0x1c276,0x18de8,0x184e4,0x18de4,0x184e2,0x18de2,0x109e8,0x184f6,0x11be8, // 720
324
-			0x109e4,0x11be4,0x109e2,0x11be2,0x109f6,0x11bf6,0x1f9d4,0x13af8,0x19d7e,0x1f9d2, // 730
325
-			0x13a7c,0x13a3e,0x1f194,0x1197e,0x1f3b4,0x1f192,0x13b7e,0x1f3b2,0x1e114,0x1e334, // 740
326
-			0x1e112,0x1e774,0x1e332,0x1e772,0x1c234,0x1c674,0x1c232,0x1cef4,0x1c672,0x1cef2, // 750
327
-			0x18474,0x18cf4,0x18472,0x19df4,0x18cf2,0x19df2,0x108f4,0x119f4,0x108f2,0x13bf4, // 760
328
-			0x119f2,0x13bf2,0x17af0,0x1bd7c,0x17a78,0x1bd3e,0x17a3c,0x17a1e,0x1f9ca,0x1397c, // 770
329
-			0x1fbda,0x17b7c,0x1393e,0x17b3e,0x1f18a,0x1f39a,0x1f7ba,0x1e10a,0x1e31a,0x1e73a, // 780
330
-			0x1ef7a,0x1c21a,0x1c63a,0x1ce7a,0x1defa,0x1843a,0x18c7a,0x19cfa,0x1bdfa,0x1087a, // 790
331
-			0x118fa,0x139fa,0x17978,0x1bcbe,0x1793c,0x1791e,0x138be,0x179be,0x178bc,0x1789e, // 800
332
-			0x1785e,0x1e0a8,0x1e0a4,0x1e0a2,0x1c168,0x1e0b6,0x1c164,0x1c162,0x182e8,0x1c176, // 810
333
-			0x182e4,0x182e2,0x105e8,0x182f6,0x105e4,0x105e2,0x105f6,0x1f0d4,0x10d7e,0x1f0d2, // 820
334
-			0x1e094,0x1e1b4,0x1e092,0x1e1b2,0x1c134,0x1c374,0x1c132,0x1c372,0x18274,0x186f4, // 830
335
-			0x18272,0x186f2,0x104f4,0x10df4,0x104f2,0x10df2,0x1f8ea,0x11d7c,0x11d3e,0x1f0ca, // 840
336
-			0x1f1da,0x1e08a,0x1e19a,0x1e3ba,0x1c11a,0x1c33a,0x1c77a,0x1823a,0x1867a,0x18efa, // 850
337
-			0x1047a,0x10cfa,0x11dfa,0x13d78,0x19ebe,0x13d3c,0x13d1e,0x11cbe,0x13dbe,0x17d70, // 860
338
-			0x1bebc,0x17d38,0x1be9e,0x17d1c,0x17d0e,0x13cbc,0x17dbc,0x13c9e,0x17d9e,0x17cb8, // 870
339
-			0x1be5e,0x17c9c,0x17c8e,0x13c5e,0x17cde,0x17c5c,0x17c4e,0x17c2e,0x1c0b4,0x1c0b2, // 880
340
-			0x18174,0x18172,0x102f4,0x102f2,0x1e0da,0x1c09a,0x1c1ba,0x1813a,0x1837a,0x1027a, // 890
341
-			0x106fa,0x10ebe,0x11ebc,0x11e9e,0x13eb8,0x19f5e,0x13e9c,0x13e8e,0x11e5e,0x13ede, // 900
342
-			0x17eb0,0x1bf5c,0x17e98,0x1bf4e,0x17e8c,0x17e86,0x13e5c,0x17edc,0x13e4e,0x17ece, // 910
343
-			0x17e58,0x1bf2e,0x17e4c,0x17e46,0x13e2e,0x17e6e,0x17e2c,0x17e26,0x10f5e,0x11f5c, // 920
344
-			0x11f4e,0x13f58,0x19fae,0x13f4c,0x13f46,0x11f2e,0x13f6e,0x13f2c,0x13f26),        // 929
252
+			0x1f560, 0x1fab8, 0x1ea40, 0x1f530, 0x1fa9c, 0x1ea20, 0x1f518, 0x1fa8e, 0x1ea10, 0x1f50c, //  10
253
+			0x1ea08, 0x1f506, 0x1ea04, 0x1eb60, 0x1f5b8, 0x1fade, 0x1d640, 0x1eb30, 0x1f59c, 0x1d620, //  20
254
+			0x1eb18, 0x1f58e, 0x1d610, 0x1eb0c, 0x1d608, 0x1eb06, 0x1d604, 0x1d760, 0x1ebb8, 0x1f5de, //  30
255
+			0x1ae40, 0x1d730, 0x1eb9c, 0x1ae20, 0x1d718, 0x1eb8e, 0x1ae10, 0x1d70c, 0x1ae08, 0x1d706, //  40
256
+			0x1ae04, 0x1af60, 0x1d7b8, 0x1ebde, 0x15e40, 0x1af30, 0x1d79c, 0x15e20, 0x1af18, 0x1d78e, //  50
257
+			0x15e10, 0x1af0c, 0x15e08, 0x1af06, 0x15f60, 0x1afb8, 0x1d7de, 0x15f30, 0x1af9c, 0x15f18, //  60
258
+			0x1af8e, 0x15f0c, 0x15fb8, 0x1afde, 0x15f9c, 0x15f8e, 0x1e940, 0x1f4b0, 0x1fa5c, 0x1e920, //  70
259
+			0x1f498, 0x1fa4e, 0x1e910, 0x1f48c, 0x1e908, 0x1f486, 0x1e904, 0x1e902, 0x1d340, 0x1e9b0, //  80
260
+			0x1f4dc, 0x1d320, 0x1e998, 0x1f4ce, 0x1d310, 0x1e98c, 0x1d308, 0x1e986, 0x1d304, 0x1d302, //  90
261
+			0x1a740, 0x1d3b0, 0x1e9dc, 0x1a720, 0x1d398, 0x1e9ce, 0x1a710, 0x1d38c, 0x1a708, 0x1d386, // 100
262
+			0x1a704, 0x1a702, 0x14f40, 0x1a7b0, 0x1d3dc, 0x14f20, 0x1a798, 0x1d3ce, 0x14f10, 0x1a78c, // 110
263
+			0x14f08, 0x1a786, 0x14f04, 0x14fb0, 0x1a7dc, 0x14f98, 0x1a7ce, 0x14f8c, 0x14f86, 0x14fdc, // 120
264
+			0x14fce, 0x1e8a0, 0x1f458, 0x1fa2e, 0x1e890, 0x1f44c, 0x1e888, 0x1f446, 0x1e884, 0x1e882, // 130
265
+			0x1d1a0, 0x1e8d8, 0x1f46e, 0x1d190, 0x1e8cc, 0x1d188, 0x1e8c6, 0x1d184, 0x1d182, 0x1a3a0, // 140
266
+			0x1d1d8, 0x1e8ee, 0x1a390, 0x1d1cc, 0x1a388, 0x1d1c6, 0x1a384, 0x1a382, 0x147a0, 0x1a3d8, // 150
267
+			0x1d1ee, 0x14790, 0x1a3cc, 0x14788, 0x1a3c6, 0x14784, 0x14782, 0x147d8, 0x1a3ee, 0x147cc, // 160
268
+			0x147c6, 0x147ee, 0x1e850, 0x1f42c, 0x1e848, 0x1f426, 0x1e844, 0x1e842, 0x1d0d0, 0x1e86c, // 170
269
+			0x1d0c8, 0x1e866, 0x1d0c4, 0x1d0c2, 0x1a1d0, 0x1d0ec, 0x1a1c8, 0x1d0e6, 0x1a1c4, 0x1a1c2, // 180
270
+			0x143d0, 0x1a1ec, 0x143c8, 0x1a1e6, 0x143c4, 0x143c2, 0x143ec, 0x143e6, 0x1e828, 0x1f416, // 190
271
+			0x1e824, 0x1e822, 0x1d068, 0x1e836, 0x1d064, 0x1d062, 0x1a0e8, 0x1d076, 0x1a0e4, 0x1a0e2, // 200
272
+			0x141e8, 0x1a0f6, 0x141e4, 0x141e2, 0x1e814, 0x1e812, 0x1d034, 0x1d032, 0x1a074, 0x1a072, // 210
273
+			0x1e540, 0x1f2b0, 0x1f95c, 0x1e520, 0x1f298, 0x1f94e, 0x1e510, 0x1f28c, 0x1e508, 0x1f286, // 220
274
+			0x1e504, 0x1e502, 0x1cb40, 0x1e5b0, 0x1f2dc, 0x1cb20, 0x1e598, 0x1f2ce, 0x1cb10, 0x1e58c, // 230
275
+			0x1cb08, 0x1e586, 0x1cb04, 0x1cb02, 0x19740, 0x1cbb0, 0x1e5dc, 0x19720, 0x1cb98, 0x1e5ce, // 240
276
+			0x19710, 0x1cb8c, 0x19708, 0x1cb86, 0x19704, 0x19702, 0x12f40, 0x197b0, 0x1cbdc, 0x12f20, // 250
277
+			0x19798, 0x1cbce, 0x12f10, 0x1978c, 0x12f08, 0x19786, 0x12f04, 0x12fb0, 0x197dc, 0x12f98, // 260
278
+			0x197ce, 0x12f8c, 0x12f86, 0x12fdc, 0x12fce, 0x1f6a0, 0x1fb58, 0x16bf0, 0x1f690, 0x1fb4c, // 270
279
+			0x169f8, 0x1f688, 0x1fb46, 0x168fc, 0x1f684, 0x1f682, 0x1e4a0, 0x1f258, 0x1f92e, 0x1eda0, // 280
280
+			0x1e490, 0x1fb6e, 0x1ed90, 0x1f6cc, 0x1f246, 0x1ed88, 0x1e484, 0x1ed84, 0x1e482, 0x1ed82, // 290
281
+			0x1c9a0, 0x1e4d8, 0x1f26e, 0x1dba0, 0x1c990, 0x1e4cc, 0x1db90, 0x1edcc, 0x1e4c6, 0x1db88, // 300
282
+			0x1c984, 0x1db84, 0x1c982, 0x1db82, 0x193a0, 0x1c9d8, 0x1e4ee, 0x1b7a0, 0x19390, 0x1c9cc, // 310
283
+			0x1b790, 0x1dbcc, 0x1c9c6, 0x1b788, 0x19384, 0x1b784, 0x19382, 0x1b782, 0x127a0, 0x193d8, // 320
284
+			0x1c9ee, 0x16fa0, 0x12790, 0x193cc, 0x16f90, 0x1b7cc, 0x193c6, 0x16f88, 0x12784, 0x16f84, // 330
285
+			0x12782, 0x127d8, 0x193ee, 0x16fd8, 0x127cc, 0x16fcc, 0x127c6, 0x16fc6, 0x127ee, 0x1f650, // 340
286
+			0x1fb2c, 0x165f8, 0x1f648, 0x1fb26, 0x164fc, 0x1f644, 0x1647e, 0x1f642, 0x1e450, 0x1f22c, // 350
287
+			0x1ecd0, 0x1e448, 0x1f226, 0x1ecc8, 0x1f666, 0x1ecc4, 0x1e442, 0x1ecc2, 0x1c8d0, 0x1e46c, // 360
288
+			0x1d9d0, 0x1c8c8, 0x1e466, 0x1d9c8, 0x1ece6, 0x1d9c4, 0x1c8c2, 0x1d9c2, 0x191d0, 0x1c8ec, // 370
289
+			0x1b3d0, 0x191c8, 0x1c8e6, 0x1b3c8, 0x1d9e6, 0x1b3c4, 0x191c2, 0x1b3c2, 0x123d0, 0x191ec, // 380
290
+			0x167d0, 0x123c8, 0x191e6, 0x167c8, 0x1b3e6, 0x167c4, 0x123c2, 0x167c2, 0x123ec, 0x167ec, // 390
291
+			0x123e6, 0x167e6, 0x1f628, 0x1fb16, 0x162fc, 0x1f624, 0x1627e, 0x1f622, 0x1e428, 0x1f216, // 400
292
+			0x1ec68, 0x1f636, 0x1ec64, 0x1e422, 0x1ec62, 0x1c868, 0x1e436, 0x1d8e8, 0x1c864, 0x1d8e4, // 410
293
+			0x1c862, 0x1d8e2, 0x190e8, 0x1c876, 0x1b1e8, 0x1d8f6, 0x1b1e4, 0x190e2, 0x1b1e2, 0x121e8, // 420
294
+			0x190f6, 0x163e8, 0x121e4, 0x163e4, 0x121e2, 0x163e2, 0x121f6, 0x163f6, 0x1f614, 0x1617e, // 430
295
+			0x1f612, 0x1e414, 0x1ec34, 0x1e412, 0x1ec32, 0x1c834, 0x1d874, 0x1c832, 0x1d872, 0x19074, // 440
296
+			0x1b0f4, 0x19072, 0x1b0f2, 0x120f4, 0x161f4, 0x120f2, 0x161f2, 0x1f60a, 0x1e40a, 0x1ec1a, // 450
297
+			0x1c81a, 0x1d83a, 0x1903a, 0x1b07a, 0x1e2a0, 0x1f158, 0x1f8ae, 0x1e290, 0x1f14c, 0x1e288, // 460
298
+			0x1f146, 0x1e284, 0x1e282, 0x1c5a0, 0x1e2d8, 0x1f16e, 0x1c590, 0x1e2cc, 0x1c588, 0x1e2c6, // 470
299
+			0x1c584, 0x1c582, 0x18ba0, 0x1c5d8, 0x1e2ee, 0x18b90, 0x1c5cc, 0x18b88, 0x1c5c6, 0x18b84, // 480
300
+			0x18b82, 0x117a0, 0x18bd8, 0x1c5ee, 0x11790, 0x18bcc, 0x11788, 0x18bc6, 0x11784, 0x11782, // 490
301
+			0x117d8, 0x18bee, 0x117cc, 0x117c6, 0x117ee, 0x1f350, 0x1f9ac, 0x135f8, 0x1f348, 0x1f9a6, // 500
302
+			0x134fc, 0x1f344, 0x1347e, 0x1f342, 0x1e250, 0x1f12c, 0x1e6d0, 0x1e248, 0x1f126, 0x1e6c8, // 510
303
+			0x1f366, 0x1e6c4, 0x1e242, 0x1e6c2, 0x1c4d0, 0x1e26c, 0x1cdd0, 0x1c4c8, 0x1e266, 0x1cdc8, // 520
304
+			0x1e6e6, 0x1cdc4, 0x1c4c2, 0x1cdc2, 0x189d0, 0x1c4ec, 0x19bd0, 0x189c8, 0x1c4e6, 0x19bc8, // 530
305
+			0x1cde6, 0x19bc4, 0x189c2, 0x19bc2, 0x113d0, 0x189ec, 0x137d0, 0x113c8, 0x189e6, 0x137c8, // 540
306
+			0x19be6, 0x137c4, 0x113c2, 0x137c2, 0x113ec, 0x137ec, 0x113e6, 0x137e6, 0x1fba8, 0x175f0, // 550
307
+			0x1bafc, 0x1fba4, 0x174f8, 0x1ba7e, 0x1fba2, 0x1747c, 0x1743e, 0x1f328, 0x1f996, 0x132fc, // 560
308
+			0x1f768, 0x1fbb6, 0x176fc, 0x1327e, 0x1f764, 0x1f322, 0x1767e, 0x1f762, 0x1e228, 0x1f116, // 570
309
+			0x1e668, 0x1e224, 0x1eee8, 0x1f776, 0x1e222, 0x1eee4, 0x1e662, 0x1eee2, 0x1c468, 0x1e236, // 580
310
+			0x1cce8, 0x1c464, 0x1dde8, 0x1cce4, 0x1c462, 0x1dde4, 0x1cce2, 0x1dde2, 0x188e8, 0x1c476, // 590
311
+			0x199e8, 0x188e4, 0x1bbe8, 0x199e4, 0x188e2, 0x1bbe4, 0x199e2, 0x1bbe2, 0x111e8, 0x188f6, // 600
312
+			0x133e8, 0x111e4, 0x177e8, 0x133e4, 0x111e2, 0x177e4, 0x133e2, 0x177e2, 0x111f6, 0x133f6, // 610
313
+			0x1fb94, 0x172f8, 0x1b97e, 0x1fb92, 0x1727c, 0x1723e, 0x1f314, 0x1317e, 0x1f734, 0x1f312, // 620
314
+			0x1737e, 0x1f732, 0x1e214, 0x1e634, 0x1e212, 0x1ee74, 0x1e632, 0x1ee72, 0x1c434, 0x1cc74, // 630
315
+			0x1c432, 0x1dcf4, 0x1cc72, 0x1dcf2, 0x18874, 0x198f4, 0x18872, 0x1b9f4, 0x198f2, 0x1b9f2, // 640
316
+			0x110f4, 0x131f4, 0x110f2, 0x173f4, 0x131f2, 0x173f2, 0x1fb8a, 0x1717c, 0x1713e, 0x1f30a, // 650
317
+			0x1f71a, 0x1e20a, 0x1e61a, 0x1ee3a, 0x1c41a, 0x1cc3a, 0x1dc7a, 0x1883a, 0x1987a, 0x1b8fa, // 660
318
+			0x1107a, 0x130fa, 0x171fa, 0x170be, 0x1e150, 0x1f0ac, 0x1e148, 0x1f0a6, 0x1e144, 0x1e142, // 670
319
+			0x1c2d0, 0x1e16c, 0x1c2c8, 0x1e166, 0x1c2c4, 0x1c2c2, 0x185d0, 0x1c2ec, 0x185c8, 0x1c2e6, // 680
320
+			0x185c4, 0x185c2, 0x10bd0, 0x185ec, 0x10bc8, 0x185e6, 0x10bc4, 0x10bc2, 0x10bec, 0x10be6, // 690
321
+			0x1f1a8, 0x1f8d6, 0x11afc, 0x1f1a4, 0x11a7e, 0x1f1a2, 0x1e128, 0x1f096, 0x1e368, 0x1e124, // 700
322
+			0x1e364, 0x1e122, 0x1e362, 0x1c268, 0x1e136, 0x1c6e8, 0x1c264, 0x1c6e4, 0x1c262, 0x1c6e2, // 710
323
+			0x184e8, 0x1c276, 0x18de8, 0x184e4, 0x18de4, 0x184e2, 0x18de2, 0x109e8, 0x184f6, 0x11be8, // 720
324
+			0x109e4, 0x11be4, 0x109e2, 0x11be2, 0x109f6, 0x11bf6, 0x1f9d4, 0x13af8, 0x19d7e, 0x1f9d2, // 730
325
+			0x13a7c, 0x13a3e, 0x1f194, 0x1197e, 0x1f3b4, 0x1f192, 0x13b7e, 0x1f3b2, 0x1e114, 0x1e334, // 740
326
+			0x1e112, 0x1e774, 0x1e332, 0x1e772, 0x1c234, 0x1c674, 0x1c232, 0x1cef4, 0x1c672, 0x1cef2, // 750
327
+			0x18474, 0x18cf4, 0x18472, 0x19df4, 0x18cf2, 0x19df2, 0x108f4, 0x119f4, 0x108f2, 0x13bf4, // 760
328
+			0x119f2, 0x13bf2, 0x17af0, 0x1bd7c, 0x17a78, 0x1bd3e, 0x17a3c, 0x17a1e, 0x1f9ca, 0x1397c, // 770
329
+			0x1fbda, 0x17b7c, 0x1393e, 0x17b3e, 0x1f18a, 0x1f39a, 0x1f7ba, 0x1e10a, 0x1e31a, 0x1e73a, // 780
330
+			0x1ef7a, 0x1c21a, 0x1c63a, 0x1ce7a, 0x1defa, 0x1843a, 0x18c7a, 0x19cfa, 0x1bdfa, 0x1087a, // 790
331
+			0x118fa, 0x139fa, 0x17978, 0x1bcbe, 0x1793c, 0x1791e, 0x138be, 0x179be, 0x178bc, 0x1789e, // 800
332
+			0x1785e, 0x1e0a8, 0x1e0a4, 0x1e0a2, 0x1c168, 0x1e0b6, 0x1c164, 0x1c162, 0x182e8, 0x1c176, // 810
333
+			0x182e4, 0x182e2, 0x105e8, 0x182f6, 0x105e4, 0x105e2, 0x105f6, 0x1f0d4, 0x10d7e, 0x1f0d2, // 820
334
+			0x1e094, 0x1e1b4, 0x1e092, 0x1e1b2, 0x1c134, 0x1c374, 0x1c132, 0x1c372, 0x18274, 0x186f4, // 830
335
+			0x18272, 0x186f2, 0x104f4, 0x10df4, 0x104f2, 0x10df2, 0x1f8ea, 0x11d7c, 0x11d3e, 0x1f0ca, // 840
336
+			0x1f1da, 0x1e08a, 0x1e19a, 0x1e3ba, 0x1c11a, 0x1c33a, 0x1c77a, 0x1823a, 0x1867a, 0x18efa, // 850
337
+			0x1047a, 0x10cfa, 0x11dfa, 0x13d78, 0x19ebe, 0x13d3c, 0x13d1e, 0x11cbe, 0x13dbe, 0x17d70, // 860
338
+			0x1bebc, 0x17d38, 0x1be9e, 0x17d1c, 0x17d0e, 0x13cbc, 0x17dbc, 0x13c9e, 0x17d9e, 0x17cb8, // 870
339
+			0x1be5e, 0x17c9c, 0x17c8e, 0x13c5e, 0x17cde, 0x17c5c, 0x17c4e, 0x17c2e, 0x1c0b4, 0x1c0b2, // 880
340
+			0x18174, 0x18172, 0x102f4, 0x102f2, 0x1e0da, 0x1c09a, 0x1c1ba, 0x1813a, 0x1837a, 0x1027a, // 890
341
+			0x106fa, 0x10ebe, 0x11ebc, 0x11e9e, 0x13eb8, 0x19f5e, 0x13e9c, 0x13e8e, 0x11e5e, 0x13ede, // 900
342
+			0x17eb0, 0x1bf5c, 0x17e98, 0x1bf4e, 0x17e8c, 0x17e86, 0x13e5c, 0x17edc, 0x13e4e, 0x17ece, // 910
343
+			0x17e58, 0x1bf2e, 0x17e4c, 0x17e46, 0x13e2e, 0x17e6e, 0x17e2c, 0x17e26, 0x10f5e, 0x11f5c, // 920
344
+			0x11f4e, 0x13f58, 0x19fae, 0x13f4c, 0x13f46, 0x11f2e, 0x13f6e, 0x13f2c, 0x13f26), // 929
345 345
 		array( // cluster 6 -----------------------------------------------------------------------
346
-			0x1abe0,0x1d5f8,0x153c0,0x1a9f0,0x1d4fc,0x151e0,0x1a8f8,0x1d47e,0x150f0,0x1a87c, //  10
347
-			0x15078,0x1fad0,0x15be0,0x1adf8,0x1fac8,0x159f0,0x1acfc,0x1fac4,0x158f8,0x1ac7e, //  20
348
-			0x1fac2,0x1587c,0x1f5d0,0x1faec,0x15df8,0x1f5c8,0x1fae6,0x15cfc,0x1f5c4,0x15c7e, //  30
349
-			0x1f5c2,0x1ebd0,0x1f5ec,0x1ebc8,0x1f5e6,0x1ebc4,0x1ebc2,0x1d7d0,0x1ebec,0x1d7c8, //  40
350
-			0x1ebe6,0x1d7c4,0x1d7c2,0x1afd0,0x1d7ec,0x1afc8,0x1d7e6,0x1afc4,0x14bc0,0x1a5f0, //  50
351
-			0x1d2fc,0x149e0,0x1a4f8,0x1d27e,0x148f0,0x1a47c,0x14878,0x1a43e,0x1483c,0x1fa68, //  60
352
-			0x14df0,0x1a6fc,0x1fa64,0x14cf8,0x1a67e,0x1fa62,0x14c7c,0x14c3e,0x1f4e8,0x1fa76, //  70
353
-			0x14efc,0x1f4e4,0x14e7e,0x1f4e2,0x1e9e8,0x1f4f6,0x1e9e4,0x1e9e2,0x1d3e8,0x1e9f6, //  80
354
-			0x1d3e4,0x1d3e2,0x1a7e8,0x1d3f6,0x1a7e4,0x1a7e2,0x145e0,0x1a2f8,0x1d17e,0x144f0, //  90
355
-			0x1a27c,0x14478,0x1a23e,0x1443c,0x1441e,0x1fa34,0x146f8,0x1a37e,0x1fa32,0x1467c, // 100
356
-			0x1463e,0x1f474,0x1477e,0x1f472,0x1e8f4,0x1e8f2,0x1d1f4,0x1d1f2,0x1a3f4,0x1a3f2, // 110
357
-			0x142f0,0x1a17c,0x14278,0x1a13e,0x1423c,0x1421e,0x1fa1a,0x1437c,0x1433e,0x1f43a, // 120
358
-			0x1e87a,0x1d0fa,0x14178,0x1a0be,0x1413c,0x1411e,0x141be,0x140bc,0x1409e,0x12bc0, // 130
359
-			0x195f0,0x1cafc,0x129e0,0x194f8,0x1ca7e,0x128f0,0x1947c,0x12878,0x1943e,0x1283c, // 140
360
-			0x1f968,0x12df0,0x196fc,0x1f964,0x12cf8,0x1967e,0x1f962,0x12c7c,0x12c3e,0x1f2e8, // 150
361
-			0x1f976,0x12efc,0x1f2e4,0x12e7e,0x1f2e2,0x1e5e8,0x1f2f6,0x1e5e4,0x1e5e2,0x1cbe8, // 160
362
-			0x1e5f6,0x1cbe4,0x1cbe2,0x197e8,0x1cbf6,0x197e4,0x197e2,0x1b5e0,0x1daf8,0x1ed7e, // 170
363
-			0x169c0,0x1b4f0,0x1da7c,0x168e0,0x1b478,0x1da3e,0x16870,0x1b43c,0x16838,0x1b41e, // 180
364
-			0x1681c,0x125e0,0x192f8,0x1c97e,0x16de0,0x124f0,0x1927c,0x16cf0,0x1b67c,0x1923e, // 190
365
-			0x16c78,0x1243c,0x16c3c,0x1241e,0x16c1e,0x1f934,0x126f8,0x1937e,0x1fb74,0x1f932, // 200
366
-			0x16ef8,0x1267c,0x1fb72,0x16e7c,0x1263e,0x16e3e,0x1f274,0x1277e,0x1f6f4,0x1f272, // 210
367
-			0x16f7e,0x1f6f2,0x1e4f4,0x1edf4,0x1e4f2,0x1edf2,0x1c9f4,0x1dbf4,0x1c9f2,0x1dbf2, // 220
368
-			0x193f4,0x193f2,0x165c0,0x1b2f0,0x1d97c,0x164e0,0x1b278,0x1d93e,0x16470,0x1b23c, // 230
369
-			0x16438,0x1b21e,0x1641c,0x1640e,0x122f0,0x1917c,0x166f0,0x12278,0x1913e,0x16678, // 240
370
-			0x1b33e,0x1663c,0x1221e,0x1661e,0x1f91a,0x1237c,0x1fb3a,0x1677c,0x1233e,0x1673e, // 250
371
-			0x1f23a,0x1f67a,0x1e47a,0x1ecfa,0x1c8fa,0x1d9fa,0x191fa,0x162e0,0x1b178,0x1d8be, // 260
372
-			0x16270,0x1b13c,0x16238,0x1b11e,0x1621c,0x1620e,0x12178,0x190be,0x16378,0x1213c, // 270
373
-			0x1633c,0x1211e,0x1631e,0x121be,0x163be,0x16170,0x1b0bc,0x16138,0x1b09e,0x1611c, // 280
374
-			0x1610e,0x120bc,0x161bc,0x1209e,0x1619e,0x160b8,0x1b05e,0x1609c,0x1608e,0x1205e, // 290
375
-			0x160de,0x1605c,0x1604e,0x115e0,0x18af8,0x1c57e,0x114f0,0x18a7c,0x11478,0x18a3e, // 300
376
-			0x1143c,0x1141e,0x1f8b4,0x116f8,0x18b7e,0x1f8b2,0x1167c,0x1163e,0x1f174,0x1177e, // 310
377
-			0x1f172,0x1e2f4,0x1e2f2,0x1c5f4,0x1c5f2,0x18bf4,0x18bf2,0x135c0,0x19af0,0x1cd7c, // 320
378
-			0x134e0,0x19a78,0x1cd3e,0x13470,0x19a3c,0x13438,0x19a1e,0x1341c,0x1340e,0x112f0, // 330
379
-			0x1897c,0x136f0,0x11278,0x1893e,0x13678,0x19b3e,0x1363c,0x1121e,0x1361e,0x1f89a, // 340
380
-			0x1137c,0x1f9ba,0x1377c,0x1133e,0x1373e,0x1f13a,0x1f37a,0x1e27a,0x1e6fa,0x1c4fa, // 350
381
-			0x1cdfa,0x189fa,0x1bae0,0x1dd78,0x1eebe,0x174c0,0x1ba70,0x1dd3c,0x17460,0x1ba38, // 360
382
-			0x1dd1e,0x17430,0x1ba1c,0x17418,0x1ba0e,0x1740c,0x132e0,0x19978,0x1ccbe,0x176e0, // 370
383
-			0x13270,0x1993c,0x17670,0x1bb3c,0x1991e,0x17638,0x1321c,0x1761c,0x1320e,0x1760e, // 380
384
-			0x11178,0x188be,0x13378,0x1113c,0x17778,0x1333c,0x1111e,0x1773c,0x1331e,0x1771e, // 390
385
-			0x111be,0x133be,0x177be,0x172c0,0x1b970,0x1dcbc,0x17260,0x1b938,0x1dc9e,0x17230, // 400
386
-			0x1b91c,0x17218,0x1b90e,0x1720c,0x17206,0x13170,0x198bc,0x17370,0x13138,0x1989e, // 410
387
-			0x17338,0x1b99e,0x1731c,0x1310e,0x1730e,0x110bc,0x131bc,0x1109e,0x173bc,0x1319e, // 420
388
-			0x1739e,0x17160,0x1b8b8,0x1dc5e,0x17130,0x1b89c,0x17118,0x1b88e,0x1710c,0x17106, // 430
389
-			0x130b8,0x1985e,0x171b8,0x1309c,0x1719c,0x1308e,0x1718e,0x1105e,0x130de,0x171de, // 440
390
-			0x170b0,0x1b85c,0x17098,0x1b84e,0x1708c,0x17086,0x1305c,0x170dc,0x1304e,0x170ce, // 450
391
-			0x17058,0x1b82e,0x1704c,0x17046,0x1302e,0x1706e,0x1702c,0x17026,0x10af0,0x1857c, // 460
392
-			0x10a78,0x1853e,0x10a3c,0x10a1e,0x10b7c,0x10b3e,0x1f0ba,0x1e17a,0x1c2fa,0x185fa, // 470
393
-			0x11ae0,0x18d78,0x1c6be,0x11a70,0x18d3c,0x11a38,0x18d1e,0x11a1c,0x11a0e,0x10978, // 480
394
-			0x184be,0x11b78,0x1093c,0x11b3c,0x1091e,0x11b1e,0x109be,0x11bbe,0x13ac0,0x19d70, // 490
395
-			0x1cebc,0x13a60,0x19d38,0x1ce9e,0x13a30,0x19d1c,0x13a18,0x19d0e,0x13a0c,0x13a06, // 500
396
-			0x11970,0x18cbc,0x13b70,0x11938,0x18c9e,0x13b38,0x1191c,0x13b1c,0x1190e,0x13b0e, // 510
397
-			0x108bc,0x119bc,0x1089e,0x13bbc,0x1199e,0x13b9e,0x1bd60,0x1deb8,0x1ef5e,0x17a40, // 520
398
-			0x1bd30,0x1de9c,0x17a20,0x1bd18,0x1de8e,0x17a10,0x1bd0c,0x17a08,0x1bd06,0x17a04, // 530
399
-			0x13960,0x19cb8,0x1ce5e,0x17b60,0x13930,0x19c9c,0x17b30,0x1bd9c,0x19c8e,0x17b18, // 540
400
-			0x1390c,0x17b0c,0x13906,0x17b06,0x118b8,0x18c5e,0x139b8,0x1189c,0x17bb8,0x1399c, // 550
401
-			0x1188e,0x17b9c,0x1398e,0x17b8e,0x1085e,0x118de,0x139de,0x17bde,0x17940,0x1bcb0, // 560
402
-			0x1de5c,0x17920,0x1bc98,0x1de4e,0x17910,0x1bc8c,0x17908,0x1bc86,0x17904,0x17902, // 570
403
-			0x138b0,0x19c5c,0x179b0,0x13898,0x19c4e,0x17998,0x1bcce,0x1798c,0x13886,0x17986, // 580
404
-			0x1185c,0x138dc,0x1184e,0x179dc,0x138ce,0x179ce,0x178a0,0x1bc58,0x1de2e,0x17890, // 590
405
-			0x1bc4c,0x17888,0x1bc46,0x17884,0x17882,0x13858,0x19c2e,0x178d8,0x1384c,0x178cc, // 600
406
-			0x13846,0x178c6,0x1182e,0x1386e,0x178ee,0x17850,0x1bc2c,0x17848,0x1bc26,0x17844, // 610
407
-			0x17842,0x1382c,0x1786c,0x13826,0x17866,0x17828,0x1bc16,0x17824,0x17822,0x13816, // 620
408
-			0x17836,0x10578,0x182be,0x1053c,0x1051e,0x105be,0x10d70,0x186bc,0x10d38,0x1869e, // 630
409
-			0x10d1c,0x10d0e,0x104bc,0x10dbc,0x1049e,0x10d9e,0x11d60,0x18eb8,0x1c75e,0x11d30, // 640
410
-			0x18e9c,0x11d18,0x18e8e,0x11d0c,0x11d06,0x10cb8,0x1865e,0x11db8,0x10c9c,0x11d9c, // 650
411
-			0x10c8e,0x11d8e,0x1045e,0x10cde,0x11dde,0x13d40,0x19eb0,0x1cf5c,0x13d20,0x19e98, // 660
412
-			0x1cf4e,0x13d10,0x19e8c,0x13d08,0x19e86,0x13d04,0x13d02,0x11cb0,0x18e5c,0x13db0, // 670
413
-			0x11c98,0x18e4e,0x13d98,0x19ece,0x13d8c,0x11c86,0x13d86,0x10c5c,0x11cdc,0x10c4e, // 680
414
-			0x13ddc,0x11cce,0x13dce,0x1bea0,0x1df58,0x1efae,0x1be90,0x1df4c,0x1be88,0x1df46, // 690
415
-			0x1be84,0x1be82,0x13ca0,0x19e58,0x1cf2e,0x17da0,0x13c90,0x19e4c,0x17d90,0x1becc, // 700
416
-			0x19e46,0x17d88,0x13c84,0x17d84,0x13c82,0x17d82,0x11c58,0x18e2e,0x13cd8,0x11c4c, // 710
417
-			0x17dd8,0x13ccc,0x11c46,0x17dcc,0x13cc6,0x17dc6,0x10c2e,0x11c6e,0x13cee,0x17dee, // 720
418
-			0x1be50,0x1df2c,0x1be48,0x1df26,0x1be44,0x1be42,0x13c50,0x19e2c,0x17cd0,0x13c48, // 730
419
-			0x19e26,0x17cc8,0x1be66,0x17cc4,0x13c42,0x17cc2,0x11c2c,0x13c6c,0x11c26,0x17cec, // 740
420
-			0x13c66,0x17ce6,0x1be28,0x1df16,0x1be24,0x1be22,0x13c28,0x19e16,0x17c68,0x13c24, // 750
421
-			0x17c64,0x13c22,0x17c62,0x11c16,0x13c36,0x17c76,0x1be14,0x1be12,0x13c14,0x17c34, // 760
422
-			0x13c12,0x17c32,0x102bc,0x1029e,0x106b8,0x1835e,0x1069c,0x1068e,0x1025e,0x106de, // 770
423
-			0x10eb0,0x1875c,0x10e98,0x1874e,0x10e8c,0x10e86,0x1065c,0x10edc,0x1064e,0x10ece, // 780
424
-			0x11ea0,0x18f58,0x1c7ae,0x11e90,0x18f4c,0x11e88,0x18f46,0x11e84,0x11e82,0x10e58, // 790
425
-			0x1872e,0x11ed8,0x18f6e,0x11ecc,0x10e46,0x11ec6,0x1062e,0x10e6e,0x11eee,0x19f50, // 800
426
-			0x1cfac,0x19f48,0x1cfa6,0x19f44,0x19f42,0x11e50,0x18f2c,0x13ed0,0x19f6c,0x18f26, // 810
427
-			0x13ec8,0x11e44,0x13ec4,0x11e42,0x13ec2,0x10e2c,0x11e6c,0x10e26,0x13eec,0x11e66, // 820
428
-			0x13ee6,0x1dfa8,0x1efd6,0x1dfa4,0x1dfa2,0x19f28,0x1cf96,0x1bf68,0x19f24,0x1bf64, // 830
429
-			0x19f22,0x1bf62,0x11e28,0x18f16,0x13e68,0x11e24,0x17ee8,0x13e64,0x11e22,0x17ee4, // 840
430
-			0x13e62,0x17ee2,0x10e16,0x11e36,0x13e76,0x17ef6,0x1df94,0x1df92,0x19f14,0x1bf34, // 850
431
-			0x19f12,0x1bf32,0x11e14,0x13e34,0x11e12,0x17e74,0x13e32,0x17e72,0x1df8a,0x19f0a, // 860
432
-			0x1bf1a,0x11e0a,0x13e1a,0x17e3a,0x1035c,0x1034e,0x10758,0x183ae,0x1074c,0x10746, // 870
433
-			0x1032e,0x1076e,0x10f50,0x187ac,0x10f48,0x187a6,0x10f44,0x10f42,0x1072c,0x10f6c, // 880
434
-			0x10726,0x10f66,0x18fa8,0x1c7d6,0x18fa4,0x18fa2,0x10f28,0x18796,0x11f68,0x18fb6, // 890
435
-			0x11f64,0x10f22,0x11f62,0x10716,0x10f36,0x11f76,0x1cfd4,0x1cfd2,0x18f94,0x19fb4, // 900
436
-			0x18f92,0x19fb2,0x10f14,0x11f34,0x10f12,0x13f74,0x11f32,0x13f72,0x1cfca,0x18f8a, // 910
437
-			0x19f9a,0x10f0a,0x11f1a,0x13f3a,0x103ac,0x103a6,0x107a8,0x183d6,0x107a4,0x107a2, // 920
438
-			0x10396,0x107b6,0x187d4,0x187d2,0x10794,0x10fb4,0x10792,0x10fb2,0x1c7ea)         // 929
346
+			0x1abe0, 0x1d5f8, 0x153c0, 0x1a9f0, 0x1d4fc, 0x151e0, 0x1a8f8, 0x1d47e, 0x150f0, 0x1a87c, //  10
347
+			0x15078, 0x1fad0, 0x15be0, 0x1adf8, 0x1fac8, 0x159f0, 0x1acfc, 0x1fac4, 0x158f8, 0x1ac7e, //  20
348
+			0x1fac2, 0x1587c, 0x1f5d0, 0x1faec, 0x15df8, 0x1f5c8, 0x1fae6, 0x15cfc, 0x1f5c4, 0x15c7e, //  30
349
+			0x1f5c2, 0x1ebd0, 0x1f5ec, 0x1ebc8, 0x1f5e6, 0x1ebc4, 0x1ebc2, 0x1d7d0, 0x1ebec, 0x1d7c8, //  40
350
+			0x1ebe6, 0x1d7c4, 0x1d7c2, 0x1afd0, 0x1d7ec, 0x1afc8, 0x1d7e6, 0x1afc4, 0x14bc0, 0x1a5f0, //  50
351
+			0x1d2fc, 0x149e0, 0x1a4f8, 0x1d27e, 0x148f0, 0x1a47c, 0x14878, 0x1a43e, 0x1483c, 0x1fa68, //  60
352
+			0x14df0, 0x1a6fc, 0x1fa64, 0x14cf8, 0x1a67e, 0x1fa62, 0x14c7c, 0x14c3e, 0x1f4e8, 0x1fa76, //  70
353
+			0x14efc, 0x1f4e4, 0x14e7e, 0x1f4e2, 0x1e9e8, 0x1f4f6, 0x1e9e4, 0x1e9e2, 0x1d3e8, 0x1e9f6, //  80
354
+			0x1d3e4, 0x1d3e2, 0x1a7e8, 0x1d3f6, 0x1a7e4, 0x1a7e2, 0x145e0, 0x1a2f8, 0x1d17e, 0x144f0, //  90
355
+			0x1a27c, 0x14478, 0x1a23e, 0x1443c, 0x1441e, 0x1fa34, 0x146f8, 0x1a37e, 0x1fa32, 0x1467c, // 100
356
+			0x1463e, 0x1f474, 0x1477e, 0x1f472, 0x1e8f4, 0x1e8f2, 0x1d1f4, 0x1d1f2, 0x1a3f4, 0x1a3f2, // 110
357
+			0x142f0, 0x1a17c, 0x14278, 0x1a13e, 0x1423c, 0x1421e, 0x1fa1a, 0x1437c, 0x1433e, 0x1f43a, // 120
358
+			0x1e87a, 0x1d0fa, 0x14178, 0x1a0be, 0x1413c, 0x1411e, 0x141be, 0x140bc, 0x1409e, 0x12bc0, // 130
359
+			0x195f0, 0x1cafc, 0x129e0, 0x194f8, 0x1ca7e, 0x128f0, 0x1947c, 0x12878, 0x1943e, 0x1283c, // 140
360
+			0x1f968, 0x12df0, 0x196fc, 0x1f964, 0x12cf8, 0x1967e, 0x1f962, 0x12c7c, 0x12c3e, 0x1f2e8, // 150
361
+			0x1f976, 0x12efc, 0x1f2e4, 0x12e7e, 0x1f2e2, 0x1e5e8, 0x1f2f6, 0x1e5e4, 0x1e5e2, 0x1cbe8, // 160
362
+			0x1e5f6, 0x1cbe4, 0x1cbe2, 0x197e8, 0x1cbf6, 0x197e4, 0x197e2, 0x1b5e0, 0x1daf8, 0x1ed7e, // 170
363
+			0x169c0, 0x1b4f0, 0x1da7c, 0x168e0, 0x1b478, 0x1da3e, 0x16870, 0x1b43c, 0x16838, 0x1b41e, // 180
364
+			0x1681c, 0x125e0, 0x192f8, 0x1c97e, 0x16de0, 0x124f0, 0x1927c, 0x16cf0, 0x1b67c, 0x1923e, // 190
365
+			0x16c78, 0x1243c, 0x16c3c, 0x1241e, 0x16c1e, 0x1f934, 0x126f8, 0x1937e, 0x1fb74, 0x1f932, // 200
366
+			0x16ef8, 0x1267c, 0x1fb72, 0x16e7c, 0x1263e, 0x16e3e, 0x1f274, 0x1277e, 0x1f6f4, 0x1f272, // 210
367
+			0x16f7e, 0x1f6f2, 0x1e4f4, 0x1edf4, 0x1e4f2, 0x1edf2, 0x1c9f4, 0x1dbf4, 0x1c9f2, 0x1dbf2, // 220
368
+			0x193f4, 0x193f2, 0x165c0, 0x1b2f0, 0x1d97c, 0x164e0, 0x1b278, 0x1d93e, 0x16470, 0x1b23c, // 230
369
+			0x16438, 0x1b21e, 0x1641c, 0x1640e, 0x122f0, 0x1917c, 0x166f0, 0x12278, 0x1913e, 0x16678, // 240
370
+			0x1b33e, 0x1663c, 0x1221e, 0x1661e, 0x1f91a, 0x1237c, 0x1fb3a, 0x1677c, 0x1233e, 0x1673e, // 250
371
+			0x1f23a, 0x1f67a, 0x1e47a, 0x1ecfa, 0x1c8fa, 0x1d9fa, 0x191fa, 0x162e0, 0x1b178, 0x1d8be, // 260
372
+			0x16270, 0x1b13c, 0x16238, 0x1b11e, 0x1621c, 0x1620e, 0x12178, 0x190be, 0x16378, 0x1213c, // 270
373
+			0x1633c, 0x1211e, 0x1631e, 0x121be, 0x163be, 0x16170, 0x1b0bc, 0x16138, 0x1b09e, 0x1611c, // 280
374
+			0x1610e, 0x120bc, 0x161bc, 0x1209e, 0x1619e, 0x160b8, 0x1b05e, 0x1609c, 0x1608e, 0x1205e, // 290
375
+			0x160de, 0x1605c, 0x1604e, 0x115e0, 0x18af8, 0x1c57e, 0x114f0, 0x18a7c, 0x11478, 0x18a3e, // 300
376
+			0x1143c, 0x1141e, 0x1f8b4, 0x116f8, 0x18b7e, 0x1f8b2, 0x1167c, 0x1163e, 0x1f174, 0x1177e, // 310
377
+			0x1f172, 0x1e2f4, 0x1e2f2, 0x1c5f4, 0x1c5f2, 0x18bf4, 0x18bf2, 0x135c0, 0x19af0, 0x1cd7c, // 320
378
+			0x134e0, 0x19a78, 0x1cd3e, 0x13470, 0x19a3c, 0x13438, 0x19a1e, 0x1341c, 0x1340e, 0x112f0, // 330
379
+			0x1897c, 0x136f0, 0x11278, 0x1893e, 0x13678, 0x19b3e, 0x1363c, 0x1121e, 0x1361e, 0x1f89a, // 340
380
+			0x1137c, 0x1f9ba, 0x1377c, 0x1133e, 0x1373e, 0x1f13a, 0x1f37a, 0x1e27a, 0x1e6fa, 0x1c4fa, // 350
381
+			0x1cdfa, 0x189fa, 0x1bae0, 0x1dd78, 0x1eebe, 0x174c0, 0x1ba70, 0x1dd3c, 0x17460, 0x1ba38, // 360
382
+			0x1dd1e, 0x17430, 0x1ba1c, 0x17418, 0x1ba0e, 0x1740c, 0x132e0, 0x19978, 0x1ccbe, 0x176e0, // 370
383
+			0x13270, 0x1993c, 0x17670, 0x1bb3c, 0x1991e, 0x17638, 0x1321c, 0x1761c, 0x1320e, 0x1760e, // 380
384
+			0x11178, 0x188be, 0x13378, 0x1113c, 0x17778, 0x1333c, 0x1111e, 0x1773c, 0x1331e, 0x1771e, // 390
385
+			0x111be, 0x133be, 0x177be, 0x172c0, 0x1b970, 0x1dcbc, 0x17260, 0x1b938, 0x1dc9e, 0x17230, // 400
386
+			0x1b91c, 0x17218, 0x1b90e, 0x1720c, 0x17206, 0x13170, 0x198bc, 0x17370, 0x13138, 0x1989e, // 410
387
+			0x17338, 0x1b99e, 0x1731c, 0x1310e, 0x1730e, 0x110bc, 0x131bc, 0x1109e, 0x173bc, 0x1319e, // 420
388
+			0x1739e, 0x17160, 0x1b8b8, 0x1dc5e, 0x17130, 0x1b89c, 0x17118, 0x1b88e, 0x1710c, 0x17106, // 430
389
+			0x130b8, 0x1985e, 0x171b8, 0x1309c, 0x1719c, 0x1308e, 0x1718e, 0x1105e, 0x130de, 0x171de, // 440
390
+			0x170b0, 0x1b85c, 0x17098, 0x1b84e, 0x1708c, 0x17086, 0x1305c, 0x170dc, 0x1304e, 0x170ce, // 450
391
+			0x17058, 0x1b82e, 0x1704c, 0x17046, 0x1302e, 0x1706e, 0x1702c, 0x17026, 0x10af0, 0x1857c, // 460
392
+			0x10a78, 0x1853e, 0x10a3c, 0x10a1e, 0x10b7c, 0x10b3e, 0x1f0ba, 0x1e17a, 0x1c2fa, 0x185fa, // 470
393
+			0x11ae0, 0x18d78, 0x1c6be, 0x11a70, 0x18d3c, 0x11a38, 0x18d1e, 0x11a1c, 0x11a0e, 0x10978, // 480
394
+			0x184be, 0x11b78, 0x1093c, 0x11b3c, 0x1091e, 0x11b1e, 0x109be, 0x11bbe, 0x13ac0, 0x19d70, // 490
395
+			0x1cebc, 0x13a60, 0x19d38, 0x1ce9e, 0x13a30, 0x19d1c, 0x13a18, 0x19d0e, 0x13a0c, 0x13a06, // 500
396
+			0x11970, 0x18cbc, 0x13b70, 0x11938, 0x18c9e, 0x13b38, 0x1191c, 0x13b1c, 0x1190e, 0x13b0e, // 510
397
+			0x108bc, 0x119bc, 0x1089e, 0x13bbc, 0x1199e, 0x13b9e, 0x1bd60, 0x1deb8, 0x1ef5e, 0x17a40, // 520
398
+			0x1bd30, 0x1de9c, 0x17a20, 0x1bd18, 0x1de8e, 0x17a10, 0x1bd0c, 0x17a08, 0x1bd06, 0x17a04, // 530
399
+			0x13960, 0x19cb8, 0x1ce5e, 0x17b60, 0x13930, 0x19c9c, 0x17b30, 0x1bd9c, 0x19c8e, 0x17b18, // 540
400
+			0x1390c, 0x17b0c, 0x13906, 0x17b06, 0x118b8, 0x18c5e, 0x139b8, 0x1189c, 0x17bb8, 0x1399c, // 550
401
+			0x1188e, 0x17b9c, 0x1398e, 0x17b8e, 0x1085e, 0x118de, 0x139de, 0x17bde, 0x17940, 0x1bcb0, // 560
402
+			0x1de5c, 0x17920, 0x1bc98, 0x1de4e, 0x17910, 0x1bc8c, 0x17908, 0x1bc86, 0x17904, 0x17902, // 570
403
+			0x138b0, 0x19c5c, 0x179b0, 0x13898, 0x19c4e, 0x17998, 0x1bcce, 0x1798c, 0x13886, 0x17986, // 580
404
+			0x1185c, 0x138dc, 0x1184e, 0x179dc, 0x138ce, 0x179ce, 0x178a0, 0x1bc58, 0x1de2e, 0x17890, // 590
405
+			0x1bc4c, 0x17888, 0x1bc46, 0x17884, 0x17882, 0x13858, 0x19c2e, 0x178d8, 0x1384c, 0x178cc, // 600
406
+			0x13846, 0x178c6, 0x1182e, 0x1386e, 0x178ee, 0x17850, 0x1bc2c, 0x17848, 0x1bc26, 0x17844, // 610
407
+			0x17842, 0x1382c, 0x1786c, 0x13826, 0x17866, 0x17828, 0x1bc16, 0x17824, 0x17822, 0x13816, // 620
408
+			0x17836, 0x10578, 0x182be, 0x1053c, 0x1051e, 0x105be, 0x10d70, 0x186bc, 0x10d38, 0x1869e, // 630
409
+			0x10d1c, 0x10d0e, 0x104bc, 0x10dbc, 0x1049e, 0x10d9e, 0x11d60, 0x18eb8, 0x1c75e, 0x11d30, // 640
410
+			0x18e9c, 0x11d18, 0x18e8e, 0x11d0c, 0x11d06, 0x10cb8, 0x1865e, 0x11db8, 0x10c9c, 0x11d9c, // 650
411
+			0x10c8e, 0x11d8e, 0x1045e, 0x10cde, 0x11dde, 0x13d40, 0x19eb0, 0x1cf5c, 0x13d20, 0x19e98, // 660
412
+			0x1cf4e, 0x13d10, 0x19e8c, 0x13d08, 0x19e86, 0x13d04, 0x13d02, 0x11cb0, 0x18e5c, 0x13db0, // 670
413
+			0x11c98, 0x18e4e, 0x13d98, 0x19ece, 0x13d8c, 0x11c86, 0x13d86, 0x10c5c, 0x11cdc, 0x10c4e, // 680
414
+			0x13ddc, 0x11cce, 0x13dce, 0x1bea0, 0x1df58, 0x1efae, 0x1be90, 0x1df4c, 0x1be88, 0x1df46, // 690
415
+			0x1be84, 0x1be82, 0x13ca0, 0x19e58, 0x1cf2e, 0x17da0, 0x13c90, 0x19e4c, 0x17d90, 0x1becc, // 700
416
+			0x19e46, 0x17d88, 0x13c84, 0x17d84, 0x13c82, 0x17d82, 0x11c58, 0x18e2e, 0x13cd8, 0x11c4c, // 710
417
+			0x17dd8, 0x13ccc, 0x11c46, 0x17dcc, 0x13cc6, 0x17dc6, 0x10c2e, 0x11c6e, 0x13cee, 0x17dee, // 720
418
+			0x1be50, 0x1df2c, 0x1be48, 0x1df26, 0x1be44, 0x1be42, 0x13c50, 0x19e2c, 0x17cd0, 0x13c48, // 730
419
+			0x19e26, 0x17cc8, 0x1be66, 0x17cc4, 0x13c42, 0x17cc2, 0x11c2c, 0x13c6c, 0x11c26, 0x17cec, // 740
420
+			0x13c66, 0x17ce6, 0x1be28, 0x1df16, 0x1be24, 0x1be22, 0x13c28, 0x19e16, 0x17c68, 0x13c24, // 750
421
+			0x17c64, 0x13c22, 0x17c62, 0x11c16, 0x13c36, 0x17c76, 0x1be14, 0x1be12, 0x13c14, 0x17c34, // 760
422
+			0x13c12, 0x17c32, 0x102bc, 0x1029e, 0x106b8, 0x1835e, 0x1069c, 0x1068e, 0x1025e, 0x106de, // 770
423
+			0x10eb0, 0x1875c, 0x10e98, 0x1874e, 0x10e8c, 0x10e86, 0x1065c, 0x10edc, 0x1064e, 0x10ece, // 780
424
+			0x11ea0, 0x18f58, 0x1c7ae, 0x11e90, 0x18f4c, 0x11e88, 0x18f46, 0x11e84, 0x11e82, 0x10e58, // 790
425
+			0x1872e, 0x11ed8, 0x18f6e, 0x11ecc, 0x10e46, 0x11ec6, 0x1062e, 0x10e6e, 0x11eee, 0x19f50, // 800
426
+			0x1cfac, 0x19f48, 0x1cfa6, 0x19f44, 0x19f42, 0x11e50, 0x18f2c, 0x13ed0, 0x19f6c, 0x18f26, // 810
427
+			0x13ec8, 0x11e44, 0x13ec4, 0x11e42, 0x13ec2, 0x10e2c, 0x11e6c, 0x10e26, 0x13eec, 0x11e66, // 820
428
+			0x13ee6, 0x1dfa8, 0x1efd6, 0x1dfa4, 0x1dfa2, 0x19f28, 0x1cf96, 0x1bf68, 0x19f24, 0x1bf64, // 830
429
+			0x19f22, 0x1bf62, 0x11e28, 0x18f16, 0x13e68, 0x11e24, 0x17ee8, 0x13e64, 0x11e22, 0x17ee4, // 840
430
+			0x13e62, 0x17ee2, 0x10e16, 0x11e36, 0x13e76, 0x17ef6, 0x1df94, 0x1df92, 0x19f14, 0x1bf34, // 850
431
+			0x19f12, 0x1bf32, 0x11e14, 0x13e34, 0x11e12, 0x17e74, 0x13e32, 0x17e72, 0x1df8a, 0x19f0a, // 860
432
+			0x1bf1a, 0x11e0a, 0x13e1a, 0x17e3a, 0x1035c, 0x1034e, 0x10758, 0x183ae, 0x1074c, 0x10746, // 870
433
+			0x1032e, 0x1076e, 0x10f50, 0x187ac, 0x10f48, 0x187a6, 0x10f44, 0x10f42, 0x1072c, 0x10f6c, // 880
434
+			0x10726, 0x10f66, 0x18fa8, 0x1c7d6, 0x18fa4, 0x18fa2, 0x10f28, 0x18796, 0x11f68, 0x18fb6, // 890
435
+			0x11f64, 0x10f22, 0x11f62, 0x10716, 0x10f36, 0x11f76, 0x1cfd4, 0x1cfd2, 0x18f94, 0x19fb4, // 900
436
+			0x18f92, 0x19fb2, 0x10f14, 0x11f34, 0x10f12, 0x13f74, 0x11f32, 0x13f72, 0x1cfca, 0x18f8a, // 910
437
+			0x19f9a, 0x10f0a, 0x11f1a, 0x13f3a, 0x103ac, 0x103a6, 0x107a8, 0x183d6, 0x107a4, 0x107a2, // 920
438
+			0x10396, 0x107b6, 0x187d4, 0x187d2, 0x10794, 0x10fb4, 0x10792, 0x10fb2, 0x1c7ea)         // 929
439 439
 	); // end of $clusters array
440 440
 
441 441
 	/**
@@ -444,80 +444,80 @@  discard block
 block discarded – undo
444 444
 	 */
445 445
 	protected $rsfactors = array(
446 446
 		array( // ECL 0 (2 factors) -------------------------------------------------------------------------------
447
-			0x01b,0x395),                                                                                    //   2
447
+			0x01b, 0x395), //   2
448 448
 		array( // ECL 1 (4 factors) -------------------------------------------------------------------------------
449
-			0x20a,0x238,0x2d3,0x329),                                                                        //   4
449
+			0x20a, 0x238, 0x2d3, 0x329), //   4
450 450
 		array( // ECL 2 (8 factors) -------------------------------------------------------------------------------
451
-			0x0ed,0x134,0x1b4,0x11c,0x286,0x28d,0x1ac,0x17b),                                                //   8
451
+			0x0ed, 0x134, 0x1b4, 0x11c, 0x286, 0x28d, 0x1ac, 0x17b), //   8
452 452
 		array( // ECL 3 (16 factors) ------------------------------------------------------------------------------
453
-			0x112,0x232,0x0e8,0x2f3,0x257,0x20c,0x321,0x084,0x127,0x074,0x1ba,0x1ac,0x127,0x02a,0x0b0,0x041),//  16
453
+			0x112, 0x232, 0x0e8, 0x2f3, 0x257, 0x20c, 0x321, 0x084, 0x127, 0x074, 0x1ba, 0x1ac, 0x127, 0x02a, 0x0b0, 0x041), //  16
454 454
 		array( // ECL 4 (32 factors) ------------------------------------------------------------------------------
455
-			0x169,0x23f,0x39a,0x20d,0x0b0,0x24a,0x280,0x141,0x218,0x2e6,0x2a5,0x2e6,0x2af,0x11c,0x0c1,0x205, //  16
456
-			0x111,0x1ee,0x107,0x093,0x251,0x320,0x23b,0x140,0x323,0x085,0x0e7,0x186,0x2ad,0x14a,0x03f,0x19a),//  32
455
+			0x169, 0x23f, 0x39a, 0x20d, 0x0b0, 0x24a, 0x280, 0x141, 0x218, 0x2e6, 0x2a5, 0x2e6, 0x2af, 0x11c, 0x0c1, 0x205, //  16
456
+			0x111, 0x1ee, 0x107, 0x093, 0x251, 0x320, 0x23b, 0x140, 0x323, 0x085, 0x0e7, 0x186, 0x2ad, 0x14a, 0x03f, 0x19a), //  32
457 457
 		array( // ECL 5 (64 factors) ------------------------------------------------------------------------------
458
-			0x21b,0x1a6,0x006,0x05d,0x35e,0x303,0x1c5,0x06a,0x262,0x11f,0x06b,0x1f9,0x2dd,0x36d,0x17d,0x264, //  16
459
-			0x2d3,0x1dc,0x1ce,0x0ac,0x1ae,0x261,0x35a,0x336,0x21f,0x178,0x1ff,0x190,0x2a0,0x2fa,0x11b,0x0b8, //  32
460
-			0x1b8,0x023,0x207,0x01f,0x1cc,0x252,0x0e1,0x217,0x205,0x160,0x25d,0x09e,0x28b,0x0c9,0x1e8,0x1f6, //  48
461
-			0x288,0x2dd,0x2cd,0x053,0x194,0x061,0x118,0x303,0x348,0x275,0x004,0x17d,0x34b,0x26f,0x108,0x21f),//  64
458
+			0x21b, 0x1a6, 0x006, 0x05d, 0x35e, 0x303, 0x1c5, 0x06a, 0x262, 0x11f, 0x06b, 0x1f9, 0x2dd, 0x36d, 0x17d, 0x264, //  16
459
+			0x2d3, 0x1dc, 0x1ce, 0x0ac, 0x1ae, 0x261, 0x35a, 0x336, 0x21f, 0x178, 0x1ff, 0x190, 0x2a0, 0x2fa, 0x11b, 0x0b8, //  32
460
+			0x1b8, 0x023, 0x207, 0x01f, 0x1cc, 0x252, 0x0e1, 0x217, 0x205, 0x160, 0x25d, 0x09e, 0x28b, 0x0c9, 0x1e8, 0x1f6, //  48
461
+			0x288, 0x2dd, 0x2cd, 0x053, 0x194, 0x061, 0x118, 0x303, 0x348, 0x275, 0x004, 0x17d, 0x34b, 0x26f, 0x108, 0x21f), //  64
462 462
 		array( // ECL 6 (128 factors) -----------------------------------------------------------------------------
463
-			0x209,0x136,0x360,0x223,0x35a,0x244,0x128,0x17b,0x035,0x30b,0x381,0x1bc,0x190,0x39d,0x2ed,0x19f, //  16
464
-			0x336,0x05d,0x0d9,0x0d0,0x3a0,0x0f4,0x247,0x26c,0x0f6,0x094,0x1bf,0x277,0x124,0x38c,0x1ea,0x2c0, //  32
465
-			0x204,0x102,0x1c9,0x38b,0x252,0x2d3,0x2a2,0x124,0x110,0x060,0x2ac,0x1b0,0x2ae,0x25e,0x35c,0x239, //  48
466
-			0x0c1,0x0db,0x081,0x0ba,0x0ec,0x11f,0x0c0,0x307,0x116,0x0ad,0x028,0x17b,0x2c8,0x1cf,0x286,0x308, //  64
467
-			0x0ab,0x1eb,0x129,0x2fb,0x09c,0x2dc,0x05f,0x10e,0x1bf,0x05a,0x1fb,0x030,0x0e4,0x335,0x328,0x382, //  80
468
-			0x310,0x297,0x273,0x17a,0x17e,0x106,0x17c,0x25a,0x2f2,0x150,0x059,0x266,0x057,0x1b0,0x29e,0x268, //  96
469
-			0x09d,0x176,0x0f2,0x2d6,0x258,0x10d,0x177,0x382,0x34d,0x1c6,0x162,0x082,0x32e,0x24b,0x324,0x022, // 112
470
-			0x0d3,0x14a,0x21b,0x129,0x33b,0x361,0x025,0x205,0x342,0x13b,0x226,0x056,0x321,0x004,0x06c,0x21b),// 128
463
+			0x209, 0x136, 0x360, 0x223, 0x35a, 0x244, 0x128, 0x17b, 0x035, 0x30b, 0x381, 0x1bc, 0x190, 0x39d, 0x2ed, 0x19f, //  16
464
+			0x336, 0x05d, 0x0d9, 0x0d0, 0x3a0, 0x0f4, 0x247, 0x26c, 0x0f6, 0x094, 0x1bf, 0x277, 0x124, 0x38c, 0x1ea, 0x2c0, //  32
465
+			0x204, 0x102, 0x1c9, 0x38b, 0x252, 0x2d3, 0x2a2, 0x124, 0x110, 0x060, 0x2ac, 0x1b0, 0x2ae, 0x25e, 0x35c, 0x239, //  48
466
+			0x0c1, 0x0db, 0x081, 0x0ba, 0x0ec, 0x11f, 0x0c0, 0x307, 0x116, 0x0ad, 0x028, 0x17b, 0x2c8, 0x1cf, 0x286, 0x308, //  64
467
+			0x0ab, 0x1eb, 0x129, 0x2fb, 0x09c, 0x2dc, 0x05f, 0x10e, 0x1bf, 0x05a, 0x1fb, 0x030, 0x0e4, 0x335, 0x328, 0x382, //  80
468
+			0x310, 0x297, 0x273, 0x17a, 0x17e, 0x106, 0x17c, 0x25a, 0x2f2, 0x150, 0x059, 0x266, 0x057, 0x1b0, 0x29e, 0x268, //  96
469
+			0x09d, 0x176, 0x0f2, 0x2d6, 0x258, 0x10d, 0x177, 0x382, 0x34d, 0x1c6, 0x162, 0x082, 0x32e, 0x24b, 0x324, 0x022, // 112
470
+			0x0d3, 0x14a, 0x21b, 0x129, 0x33b, 0x361, 0x025, 0x205, 0x342, 0x13b, 0x226, 0x056, 0x321, 0x004, 0x06c, 0x21b), // 128
471 471
 		array( // ECL 7 (256 factors) -----------------------------------------------------------------------------
472
-			0x20c,0x37e,0x04b,0x2fe,0x372,0x359,0x04a,0x0cc,0x052,0x24a,0x2c4,0x0fa,0x389,0x312,0x08a,0x2d0, //  16
473
-			0x35a,0x0c2,0x137,0x391,0x113,0x0be,0x177,0x352,0x1b6,0x2dd,0x0c2,0x118,0x0c9,0x118,0x33c,0x2f5, //  32
474
-			0x2c6,0x32e,0x397,0x059,0x044,0x239,0x00b,0x0cc,0x31c,0x25d,0x21c,0x391,0x321,0x2bc,0x31f,0x089, //  48
475
-			0x1b7,0x1a2,0x250,0x29c,0x161,0x35b,0x172,0x2b6,0x145,0x0f0,0x0d8,0x101,0x11c,0x225,0x0d1,0x374, //  64
476
-			0x13b,0x046,0x149,0x319,0x1ea,0x112,0x36d,0x0a2,0x2ed,0x32c,0x2ac,0x1cd,0x14e,0x178,0x351,0x209, //  80
477
-			0x133,0x123,0x323,0x2c8,0x013,0x166,0x18f,0x38c,0x067,0x1ff,0x033,0x008,0x205,0x0e1,0x121,0x1d6, //  96
478
-			0x27d,0x2db,0x042,0x0ff,0x395,0x10d,0x1cf,0x33e,0x2da,0x1b1,0x350,0x249,0x088,0x21a,0x38a,0x05a, // 112
479
-			0x002,0x122,0x2e7,0x0c7,0x28f,0x387,0x149,0x031,0x322,0x244,0x163,0x24c,0x0bc,0x1ce,0x00a,0x086, // 128
480
-			0x274,0x140,0x1df,0x082,0x2e3,0x047,0x107,0x13e,0x176,0x259,0x0c0,0x25d,0x08e,0x2a1,0x2af,0x0ea, // 144
481
-			0x2d2,0x180,0x0b1,0x2f0,0x25f,0x280,0x1c7,0x0c1,0x2b1,0x2c3,0x325,0x281,0x030,0x03c,0x2dc,0x26d, // 160
482
-			0x37f,0x220,0x105,0x354,0x28f,0x135,0x2b9,0x2f3,0x2f4,0x03c,0x0e7,0x305,0x1b2,0x1a5,0x2d6,0x210, // 176
483
-			0x1f7,0x076,0x031,0x31b,0x020,0x090,0x1f4,0x0ee,0x344,0x18a,0x118,0x236,0x13f,0x009,0x287,0x226, // 192
484
-			0x049,0x392,0x156,0x07e,0x020,0x2a9,0x14b,0x318,0x26c,0x03c,0x261,0x1b9,0x0b4,0x317,0x37d,0x2f2, // 208
485
-			0x25d,0x17f,0x0e4,0x2ed,0x2f8,0x0d5,0x036,0x129,0x086,0x036,0x342,0x12b,0x39a,0x0bf,0x38e,0x214, // 224
486
-			0x261,0x33d,0x0bd,0x014,0x0a7,0x01d,0x368,0x1c1,0x053,0x192,0x029,0x290,0x1f9,0x243,0x1e1,0x0ad, // 240
487
-			0x194,0x0fb,0x2b0,0x05f,0x1f1,0x22b,0x282,0x21f,0x133,0x09f,0x39c,0x22e,0x288,0x037,0x1f1,0x00a),// 256
472
+			0x20c, 0x37e, 0x04b, 0x2fe, 0x372, 0x359, 0x04a, 0x0cc, 0x052, 0x24a, 0x2c4, 0x0fa, 0x389, 0x312, 0x08a, 0x2d0, //  16
473
+			0x35a, 0x0c2, 0x137, 0x391, 0x113, 0x0be, 0x177, 0x352, 0x1b6, 0x2dd, 0x0c2, 0x118, 0x0c9, 0x118, 0x33c, 0x2f5, //  32
474
+			0x2c6, 0x32e, 0x397, 0x059, 0x044, 0x239, 0x00b, 0x0cc, 0x31c, 0x25d, 0x21c, 0x391, 0x321, 0x2bc, 0x31f, 0x089, //  48
475
+			0x1b7, 0x1a2, 0x250, 0x29c, 0x161, 0x35b, 0x172, 0x2b6, 0x145, 0x0f0, 0x0d8, 0x101, 0x11c, 0x225, 0x0d1, 0x374, //  64
476
+			0x13b, 0x046, 0x149, 0x319, 0x1ea, 0x112, 0x36d, 0x0a2, 0x2ed, 0x32c, 0x2ac, 0x1cd, 0x14e, 0x178, 0x351, 0x209, //  80
477
+			0x133, 0x123, 0x323, 0x2c8, 0x013, 0x166, 0x18f, 0x38c, 0x067, 0x1ff, 0x033, 0x008, 0x205, 0x0e1, 0x121, 0x1d6, //  96
478
+			0x27d, 0x2db, 0x042, 0x0ff, 0x395, 0x10d, 0x1cf, 0x33e, 0x2da, 0x1b1, 0x350, 0x249, 0x088, 0x21a, 0x38a, 0x05a, // 112
479
+			0x002, 0x122, 0x2e7, 0x0c7, 0x28f, 0x387, 0x149, 0x031, 0x322, 0x244, 0x163, 0x24c, 0x0bc, 0x1ce, 0x00a, 0x086, // 128
480
+			0x274, 0x140, 0x1df, 0x082, 0x2e3, 0x047, 0x107, 0x13e, 0x176, 0x259, 0x0c0, 0x25d, 0x08e, 0x2a1, 0x2af, 0x0ea, // 144
481
+			0x2d2, 0x180, 0x0b1, 0x2f0, 0x25f, 0x280, 0x1c7, 0x0c1, 0x2b1, 0x2c3, 0x325, 0x281, 0x030, 0x03c, 0x2dc, 0x26d, // 160
482
+			0x37f, 0x220, 0x105, 0x354, 0x28f, 0x135, 0x2b9, 0x2f3, 0x2f4, 0x03c, 0x0e7, 0x305, 0x1b2, 0x1a5, 0x2d6, 0x210, // 176
483
+			0x1f7, 0x076, 0x031, 0x31b, 0x020, 0x090, 0x1f4, 0x0ee, 0x344, 0x18a, 0x118, 0x236, 0x13f, 0x009, 0x287, 0x226, // 192
484
+			0x049, 0x392, 0x156, 0x07e, 0x020, 0x2a9, 0x14b, 0x318, 0x26c, 0x03c, 0x261, 0x1b9, 0x0b4, 0x317, 0x37d, 0x2f2, // 208
485
+			0x25d, 0x17f, 0x0e4, 0x2ed, 0x2f8, 0x0d5, 0x036, 0x129, 0x086, 0x036, 0x342, 0x12b, 0x39a, 0x0bf, 0x38e, 0x214, // 224
486
+			0x261, 0x33d, 0x0bd, 0x014, 0x0a7, 0x01d, 0x368, 0x1c1, 0x053, 0x192, 0x029, 0x290, 0x1f9, 0x243, 0x1e1, 0x0ad, // 240
487
+			0x194, 0x0fb, 0x2b0, 0x05f, 0x1f1, 0x22b, 0x282, 0x21f, 0x133, 0x09f, 0x39c, 0x22e, 0x288, 0x037, 0x1f1, 0x00a), // 256
488 488
 		array( // ECL 8 (512 factors) -----------------------------------------------------------------------------
489
-			0x160,0x04d,0x175,0x1f8,0x023,0x257,0x1ac,0x0cf,0x199,0x23e,0x076,0x1f2,0x11d,0x17c,0x15e,0x1ec, //  16
490
-			0x0c5,0x109,0x398,0x09b,0x392,0x12b,0x0e5,0x283,0x126,0x367,0x132,0x058,0x057,0x0c1,0x160,0x30d, //  32
491
-			0x34e,0x04b,0x147,0x208,0x1b3,0x21f,0x0cb,0x29a,0x0f9,0x15a,0x30d,0x26d,0x280,0x10c,0x31a,0x216, //  48
492
-			0x21b,0x30d,0x198,0x186,0x284,0x066,0x1dc,0x1f3,0x122,0x278,0x221,0x025,0x35a,0x394,0x228,0x029, //  64
493
-			0x21e,0x121,0x07a,0x110,0x17f,0x320,0x1e5,0x062,0x2f0,0x1d8,0x2f9,0x06b,0x310,0x35c,0x292,0x2e5, //  80
494
-			0x122,0x0cc,0x2a9,0x197,0x357,0x055,0x063,0x03e,0x1e2,0x0b4,0x014,0x129,0x1c3,0x251,0x391,0x08e, //  96
495
-			0x328,0x2ac,0x11f,0x218,0x231,0x04c,0x28d,0x383,0x2d9,0x237,0x2e8,0x186,0x201,0x0c0,0x204,0x102, // 112
496
-			0x0f0,0x206,0x31a,0x18b,0x300,0x350,0x033,0x262,0x180,0x0a8,0x0be,0x33a,0x148,0x254,0x312,0x12f, // 128
497
-			0x23a,0x17d,0x19f,0x281,0x09c,0x0ed,0x097,0x1ad,0x213,0x0cf,0x2a4,0x2c6,0x059,0x0a8,0x130,0x192, // 144
498
-			0x028,0x2c4,0x23f,0x0a2,0x360,0x0e5,0x041,0x35d,0x349,0x200,0x0a4,0x1dd,0x0dd,0x05c,0x166,0x311, // 160
499
-			0x120,0x165,0x352,0x344,0x33b,0x2e0,0x2c3,0x05e,0x008,0x1ee,0x072,0x209,0x002,0x1f3,0x353,0x21f, // 176
500
-			0x098,0x2d9,0x303,0x05f,0x0f8,0x169,0x242,0x143,0x358,0x31d,0x121,0x033,0x2ac,0x1d2,0x215,0x334, // 192
501
-			0x29d,0x02d,0x386,0x1c4,0x0a7,0x156,0x0f4,0x0ad,0x023,0x1cf,0x28b,0x033,0x2bb,0x24f,0x1c4,0x242, // 208
502
-			0x025,0x07c,0x12a,0x14c,0x228,0x02b,0x1ab,0x077,0x296,0x309,0x1db,0x352,0x2fc,0x16c,0x242,0x38f, // 224
503
-			0x11b,0x2c7,0x1d8,0x1a4,0x0f5,0x120,0x252,0x18a,0x1ff,0x147,0x24d,0x309,0x2bb,0x2b0,0x02b,0x198, // 240
504
-			0x34a,0x17f,0x2d1,0x209,0x230,0x284,0x2ca,0x22f,0x03e,0x091,0x369,0x297,0x2c9,0x09f,0x2a0,0x2d9, // 256
505
-			0x270,0x03b,0x0c1,0x1a1,0x09e,0x0d1,0x233,0x234,0x157,0x2b5,0x06d,0x260,0x233,0x16d,0x0b5,0x304, // 272
506
-			0x2a5,0x136,0x0f8,0x161,0x2c4,0x19a,0x243,0x366,0x269,0x349,0x278,0x35c,0x121,0x218,0x023,0x309, // 288
507
-			0x26a,0x24a,0x1a8,0x341,0x04d,0x255,0x15a,0x10d,0x2f5,0x278,0x2b7,0x2ef,0x14b,0x0f7,0x0b8,0x02d, // 304
508
-			0x313,0x2a8,0x012,0x042,0x197,0x171,0x036,0x1ec,0x0e4,0x265,0x33e,0x39a,0x1b5,0x207,0x284,0x389, // 320
509
-			0x315,0x1a4,0x131,0x1b9,0x0cf,0x12c,0x37c,0x33b,0x08d,0x219,0x17d,0x296,0x201,0x038,0x0fc,0x155, // 336
510
-			0x0f2,0x31d,0x346,0x345,0x2d0,0x0e0,0x133,0x277,0x03d,0x057,0x230,0x136,0x2f4,0x299,0x18d,0x328, // 352
511
-			0x353,0x135,0x1d9,0x31b,0x17a,0x01f,0x287,0x393,0x1cb,0x326,0x24e,0x2db,0x1a9,0x0d8,0x224,0x0f9, // 368
512
-			0x141,0x371,0x2bb,0x217,0x2a1,0x30e,0x0d2,0x32f,0x389,0x12f,0x34b,0x39a,0x119,0x049,0x1d5,0x317, // 384
513
-			0x294,0x0a2,0x1f2,0x134,0x09b,0x1a6,0x38b,0x331,0x0bb,0x03e,0x010,0x1a9,0x217,0x150,0x11e,0x1b5, // 400
514
-			0x177,0x111,0x262,0x128,0x0b7,0x39b,0x074,0x29b,0x2ef,0x161,0x03e,0x16e,0x2b3,0x17b,0x2af,0x34a, // 416
515
-			0x025,0x165,0x2d0,0x2e6,0x14a,0x005,0x027,0x39b,0x137,0x1a8,0x0f2,0x2ed,0x141,0x036,0x29d,0x13c, // 432
516
-			0x156,0x12b,0x216,0x069,0x29b,0x1e8,0x280,0x2a0,0x240,0x21c,0x13c,0x1e6,0x2d1,0x262,0x02e,0x290, // 448
517
-			0x1bf,0x0ab,0x268,0x1d0,0x0be,0x213,0x129,0x141,0x2fa,0x2f0,0x215,0x0af,0x086,0x00e,0x17d,0x1b1, // 464
518
-			0x2cd,0x02d,0x06f,0x014,0x254,0x11c,0x2e0,0x08a,0x286,0x19b,0x36d,0x29d,0x08d,0x397,0x02d,0x30c, // 480
519
-			0x197,0x0a4,0x14c,0x383,0x0a5,0x2d6,0x258,0x145,0x1f2,0x28f,0x165,0x2f0,0x300,0x0df,0x351,0x287, // 496
520
-			0x03f,0x136,0x35f,0x0fb,0x16e,0x130,0x11a,0x2e2,0x2a3,0x19a,0x185,0x0f4,0x01f,0x079,0x12f,0x107) // 512
489
+			0x160, 0x04d, 0x175, 0x1f8, 0x023, 0x257, 0x1ac, 0x0cf, 0x199, 0x23e, 0x076, 0x1f2, 0x11d, 0x17c, 0x15e, 0x1ec, //  16
490
+			0x0c5, 0x109, 0x398, 0x09b, 0x392, 0x12b, 0x0e5, 0x283, 0x126, 0x367, 0x132, 0x058, 0x057, 0x0c1, 0x160, 0x30d, //  32
491
+			0x34e, 0x04b, 0x147, 0x208, 0x1b3, 0x21f, 0x0cb, 0x29a, 0x0f9, 0x15a, 0x30d, 0x26d, 0x280, 0x10c, 0x31a, 0x216, //  48
492
+			0x21b, 0x30d, 0x198, 0x186, 0x284, 0x066, 0x1dc, 0x1f3, 0x122, 0x278, 0x221, 0x025, 0x35a, 0x394, 0x228, 0x029, //  64
493
+			0x21e, 0x121, 0x07a, 0x110, 0x17f, 0x320, 0x1e5, 0x062, 0x2f0, 0x1d8, 0x2f9, 0x06b, 0x310, 0x35c, 0x292, 0x2e5, //  80
494
+			0x122, 0x0cc, 0x2a9, 0x197, 0x357, 0x055, 0x063, 0x03e, 0x1e2, 0x0b4, 0x014, 0x129, 0x1c3, 0x251, 0x391, 0x08e, //  96
495
+			0x328, 0x2ac, 0x11f, 0x218, 0x231, 0x04c, 0x28d, 0x383, 0x2d9, 0x237, 0x2e8, 0x186, 0x201, 0x0c0, 0x204, 0x102, // 112
496
+			0x0f0, 0x206, 0x31a, 0x18b, 0x300, 0x350, 0x033, 0x262, 0x180, 0x0a8, 0x0be, 0x33a, 0x148, 0x254, 0x312, 0x12f, // 128
497
+			0x23a, 0x17d, 0x19f, 0x281, 0x09c, 0x0ed, 0x097, 0x1ad, 0x213, 0x0cf, 0x2a4, 0x2c6, 0x059, 0x0a8, 0x130, 0x192, // 144
498
+			0x028, 0x2c4, 0x23f, 0x0a2, 0x360, 0x0e5, 0x041, 0x35d, 0x349, 0x200, 0x0a4, 0x1dd, 0x0dd, 0x05c, 0x166, 0x311, // 160
499
+			0x120, 0x165, 0x352, 0x344, 0x33b, 0x2e0, 0x2c3, 0x05e, 0x008, 0x1ee, 0x072, 0x209, 0x002, 0x1f3, 0x353, 0x21f, // 176
500
+			0x098, 0x2d9, 0x303, 0x05f, 0x0f8, 0x169, 0x242, 0x143, 0x358, 0x31d, 0x121, 0x033, 0x2ac, 0x1d2, 0x215, 0x334, // 192
501
+			0x29d, 0x02d, 0x386, 0x1c4, 0x0a7, 0x156, 0x0f4, 0x0ad, 0x023, 0x1cf, 0x28b, 0x033, 0x2bb, 0x24f, 0x1c4, 0x242, // 208
502
+			0x025, 0x07c, 0x12a, 0x14c, 0x228, 0x02b, 0x1ab, 0x077, 0x296, 0x309, 0x1db, 0x352, 0x2fc, 0x16c, 0x242, 0x38f, // 224
503
+			0x11b, 0x2c7, 0x1d8, 0x1a4, 0x0f5, 0x120, 0x252, 0x18a, 0x1ff, 0x147, 0x24d, 0x309, 0x2bb, 0x2b0, 0x02b, 0x198, // 240
504
+			0x34a, 0x17f, 0x2d1, 0x209, 0x230, 0x284, 0x2ca, 0x22f, 0x03e, 0x091, 0x369, 0x297, 0x2c9, 0x09f, 0x2a0, 0x2d9, // 256
505
+			0x270, 0x03b, 0x0c1, 0x1a1, 0x09e, 0x0d1, 0x233, 0x234, 0x157, 0x2b5, 0x06d, 0x260, 0x233, 0x16d, 0x0b5, 0x304, // 272
506
+			0x2a5, 0x136, 0x0f8, 0x161, 0x2c4, 0x19a, 0x243, 0x366, 0x269, 0x349, 0x278, 0x35c, 0x121, 0x218, 0x023, 0x309, // 288
507
+			0x26a, 0x24a, 0x1a8, 0x341, 0x04d, 0x255, 0x15a, 0x10d, 0x2f5, 0x278, 0x2b7, 0x2ef, 0x14b, 0x0f7, 0x0b8, 0x02d, // 304
508
+			0x313, 0x2a8, 0x012, 0x042, 0x197, 0x171, 0x036, 0x1ec, 0x0e4, 0x265, 0x33e, 0x39a, 0x1b5, 0x207, 0x284, 0x389, // 320
509
+			0x315, 0x1a4, 0x131, 0x1b9, 0x0cf, 0x12c, 0x37c, 0x33b, 0x08d, 0x219, 0x17d, 0x296, 0x201, 0x038, 0x0fc, 0x155, // 336
510
+			0x0f2, 0x31d, 0x346, 0x345, 0x2d0, 0x0e0, 0x133, 0x277, 0x03d, 0x057, 0x230, 0x136, 0x2f4, 0x299, 0x18d, 0x328, // 352
511
+			0x353, 0x135, 0x1d9, 0x31b, 0x17a, 0x01f, 0x287, 0x393, 0x1cb, 0x326, 0x24e, 0x2db, 0x1a9, 0x0d8, 0x224, 0x0f9, // 368
512
+			0x141, 0x371, 0x2bb, 0x217, 0x2a1, 0x30e, 0x0d2, 0x32f, 0x389, 0x12f, 0x34b, 0x39a, 0x119, 0x049, 0x1d5, 0x317, // 384
513
+			0x294, 0x0a2, 0x1f2, 0x134, 0x09b, 0x1a6, 0x38b, 0x331, 0x0bb, 0x03e, 0x010, 0x1a9, 0x217, 0x150, 0x11e, 0x1b5, // 400
514
+			0x177, 0x111, 0x262, 0x128, 0x0b7, 0x39b, 0x074, 0x29b, 0x2ef, 0x161, 0x03e, 0x16e, 0x2b3, 0x17b, 0x2af, 0x34a, // 416
515
+			0x025, 0x165, 0x2d0, 0x2e6, 0x14a, 0x005, 0x027, 0x39b, 0x137, 0x1a8, 0x0f2, 0x2ed, 0x141, 0x036, 0x29d, 0x13c, // 432
516
+			0x156, 0x12b, 0x216, 0x069, 0x29b, 0x1e8, 0x280, 0x2a0, 0x240, 0x21c, 0x13c, 0x1e6, 0x2d1, 0x262, 0x02e, 0x290, // 448
517
+			0x1bf, 0x0ab, 0x268, 0x1d0, 0x0be, 0x213, 0x129, 0x141, 0x2fa, 0x2f0, 0x215, 0x0af, 0x086, 0x00e, 0x17d, 0x1b1, // 464
518
+			0x2cd, 0x02d, 0x06f, 0x014, 0x254, 0x11c, 0x2e0, 0x08a, 0x286, 0x19b, 0x36d, 0x29d, 0x08d, 0x397, 0x02d, 0x30c, // 480
519
+			0x197, 0x0a4, 0x14c, 0x383, 0x0a5, 0x2d6, 0x258, 0x145, 0x1f2, 0x28f, 0x165, 0x2f0, 0x300, 0x0df, 0x351, 0x287, // 496
520
+			0x03f, 0x136, 0x35f, 0x0fb, 0x16e, 0x130, 0x11a, 0x2e2, 0x2a3, 0x19a, 0x185, 0x0f4, 0x01f, 0x079, 0x12f, 0x107) // 512
521 521
 	);
522 522
 
523 523
 	/**
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 	 * @param $macro (array) information for macro block
530 530
 	 * @public
531 531
 	 */
532
-	public function __construct($code, $ecl=-1, $aspectratio=2, $macro=array()) {
532
+	public function __construct($code, $ecl = -1, $aspectratio = 2, $macro = array()) {
533 533
 		$barcode_array = array();
534 534
 		if ((is_null($code)) OR ($code == '\0') OR ($code == '')) {
535 535
 			return false;
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
 		// get the input sequence array
538 538
 		$sequence = $this->getInputSequences($code);
539 539
 		$codewords = array(); // array of code-words
540
-		foreach($sequence as $seq) {
540
+		foreach ($sequence as $seq) {
541 541
 			$cw = $this->getCompaction($seq[0], $seq[1], true);
542 542
 			$codewords = array_merge($codewords, $cw);
543 543
 		}
@@ -563,8 +563,8 @@  discard block
 block discarded – undo
563 563
 			$cw = $this->getCompaction(900, $macro['file_id'], false);
564 564
 			$macrocw = array_merge($macrocw, $cw);
565 565
 			// optional fields
566
-			$optmodes = array(900,902,902,900,900,902,902);
567
-			$optsize = array(-1,2,4,-1,-1,-1,2);
566
+			$optmodes = array(900, 902, 902, 900, 900, 902, 902);
567
+			$optsize = array(-1, 2, 4, -1, -1, -1, 2);
568 568
 			foreach ($optmodes as $k => $omode) {
569 569
 				if (isset($macro['option_'.$k])) {
570 570
 					$macrocw[] = 923;
@@ -591,15 +591,15 @@  discard block
 block discarded – undo
591 591
 		$errsize = (2 << $ecl);
592 592
 		// calculate number of columns (number of codewords per row) and rows
593 593
 		$nce = ($numcw + $errsize + 1);
594
-		$cols = round((sqrt(4761 + (68 * $aspectratio * ROWHEIGHT * $nce)) - 69) / 34);
594
+		$cols = round((sqrt(4761 + (68*$aspectratio*ROWHEIGHT*$nce)) - 69)/34);
595 595
 		// adjust cols
596 596
 		if ($cols < 1) {
597 597
 			$cols = 1;
598 598
 		} elseif ($cols > 30) {
599 599
 			$cols = 30;
600 600
 		}
601
-		$rows = ceil($nce / $cols);
602
-		$size = ($cols * $rows);
601
+		$rows = ceil($nce/$cols);
602
+		$size = ($cols*$rows);
603 603
 		// adjust rows
604 604
 		if (($rows < 3) OR ($rows > 90)) {
605 605
 			if ($rows < 3) {
@@ -607,12 +607,12 @@  discard block
 block discarded – undo
607 607
 			} elseif ($rows > 90) {
608 608
 				$rows = 90;
609 609
 			}
610
-			$cols = ceil($size / $rows);
611
-			$size = ($cols * $rows);
610
+			$cols = ceil($size/$rows);
611
+			$size = ($cols*$rows);
612 612
 		}
613 613
 		if ($size > 928) {
614 614
 			// set dimensions to get maximum capacity
615
-			if (abs($aspectratio - (17 * 29 / 32)) < abs($aspectratio - (17 * 16 / 58))) {
615
+			if (abs($aspectratio - (17*29/32)) < abs($aspectratio - (17*16/58))) {
616 616
 				$cols = 29;
617 617
 				$rows = 32;
618 618
 			} else {
@@ -647,8 +647,8 @@  discard block
 block discarded – undo
647 647
 		// add horizontal quiet zones to start and stop patterns
648 648
 		$pstart = str_repeat('0', QUIETH).$this->start_pattern;
649 649
 		$pstop = $this->stop_pattern.str_repeat('0', QUIETH);
650
-		$barcode_array['num_rows'] = ($rows * ROWHEIGHT) + (2 * QUIETV);
651
-		$barcode_array['num_cols'] = (($cols + 2) * 17) + 35 + (2 * QUIETH);
650
+		$barcode_array['num_rows'] = ($rows*ROWHEIGHT) + (2*QUIETV);
651
+		$barcode_array['num_cols'] = (($cols + 2)*17) + 35 + (2*QUIETH);
652 652
 		$barcode_array['bcode'] = array();
653 653
 		// build rows for vertical quiet zone
654 654
 		if (QUIETV > 0) {
@@ -666,15 +666,15 @@  discard block
 block discarded – undo
666 666
 			$row = $pstart;
667 667
 			switch ($cid) {
668 668
 				case 0: {
669
-					$L = ((30 * intval($r / 3)) + intval(($rows - 1) / 3));
669
+					$L = ((30*intval($r/3)) + intval(($rows - 1)/3));
670 670
 					break;
671 671
 				}
672 672
 				case 1: {
673
-					$L = ((30 * intval($r / 3)) + ($ecl * 3) + (($rows - 1) % 3));
673
+					$L = ((30*intval($r/3)) + ($ecl*3) + (($rows - 1)%3));
674 674
 					break;
675 675
 				}
676 676
 				case 2: {
677
-					$L = ((30 * intval($r / 3)) + ($cols - 1));
677
+					$L = ((30*intval($r/3)) + ($cols - 1));
678 678
 					break;
679 679
 				}
680 680
 			}
@@ -687,15 +687,15 @@  discard block
 block discarded – undo
687 687
 			}
688 688
 			switch ($cid) {
689 689
 				case 0: {
690
-					$L = ((30 * intval($r / 3)) + ($cols - 1));
690
+					$L = ((30*intval($r/3)) + ($cols - 1));
691 691
 					break;
692 692
 				}
693 693
 				case 1: {
694
-					$L = ((30 * intval($r / 3)) + intval(($rows - 1) / 3));
694
+					$L = ((30*intval($r/3)) + intval(($rows - 1)/3));
695 695
 					break;
696 696
 				}
697 697
 				case 2: {
698
-					$L = ((30 * intval($r / 3)) + ($ecl * 3) + (($rows - 1) % 3));
698
+					$L = ((30*intval($r/3)) + ($ecl*3) + (($rows - 1)%3));
699 699
 					break;
700 700
 				}
701 701
 			}
@@ -787,18 +787,18 @@  discard block
 block discarded – undo
787 787
 		// initialize array of error correction codewords
788 788
 		$ecw = array_fill(0, $eclsize, 0);
789 789
 		// for each data codeword
790
-		foreach($cw as $k => $d) {
791
-			$t1 = ($d + $ecw[$eclmaxid]) % 929;
790
+		foreach ($cw as $k => $d) {
791
+			$t1 = ($d + $ecw[$eclmaxid])%929;
792 792
 			for ($j = $eclmaxid; $j > 0; --$j) {
793
-				$t2 = ($t1 * $ecc[$j]) % 929;
793
+				$t2 = ($t1*$ecc[$j])%929;
794 794
 				$t3 = 929 - $t2;
795
-				$ecw[$j] = ($ecw[($j - 1)] + $t3) % 929;
795
+				$ecw[$j] = ($ecw[($j - 1)] + $t3)%929;
796 796
 			}
797
-			$t2 = ($t1 * $ecc[0]) % 929;
797
+			$t2 = ($t1*$ecc[0])%929;
798 798
 			$t3 = 929 - $t2;
799
-			$ecw[0] = $t3 % 929;
799
+			$ecw[0] = $t3%929;
800 800
 		}
801
-		foreach($ecw as $j => $e) {
801
+		foreach ($ecw as $j => $e) {
802 802
 			if ($e != 0) {
803 803
 				$ecw[$j] = 929 - $e;
804 804
 			}
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
 		preg_match_all('/([0-9]{13,44})/', $code, $numseq, PREG_OFFSET_CAPTURE);
821 821
 		$numseq[1][] = array('', strlen($code));
822 822
 		$offset = 0;
823
-		foreach($numseq[1] as $seq) {
823
+		foreach ($numseq[1] as $seq) {
824 824
 			$seqlen = strlen($seq[0]);
825 825
 			if ($seq[1] > 0) {
826 826
 				// extract text sequence before the number sequence
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
 				preg_match_all('/([\x09\x0a\x0d\x20-\x7e]{5,})/', $prevseq, $textseq, PREG_OFFSET_CAPTURE);
831 831
 				$textseq[1][] = array('', strlen($prevseq));
832 832
 				$txtoffset = 0;
833
-				foreach($textseq[1] as $txtseq) {
833
+				foreach ($textseq[1] as $txtseq) {
834 834
 					$txtseqlen = strlen($txtseq[0]);
835 835
 					if ($txtseq[1] > 0) {
836 836
 						// extract byte sequence before the text sequence
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
 							// add BYTE sequence
840 840
 							if ((strlen($prevtxtseq) == 1) AND ((count($sequence_array) > 0) AND ($sequence_array[(count($sequence_array) - 1)][0] == 900))) {
841 841
 								$sequence_array[] = array(913, $prevtxtseq);
842
-							} elseif ((strlen($prevtxtseq) % 6) == 0) {
842
+							} elseif ((strlen($prevtxtseq)%6) == 0) {
843 843
 								$sequence_array[] = array(924, $prevtxtseq);
844 844
 							} else {
845 845
 								$sequence_array[] = array(901, $prevtxtseq);
@@ -870,9 +870,9 @@  discard block
 block discarded – undo
870 870
 	 * @return array of codewords
871 871
 	 * @protected
872 872
 	 */
873
-	protected function getCompaction($mode, $code, $addmode=true) {
873
+	protected function getCompaction($mode, $code, $addmode = true) {
874 874
 		$cw = array(); // array of codewords to return
875
-		switch($mode) {
875
+		switch ($mode) {
876 876
 			case 900: { // Text Compaction mode latch
877 877
 				$submode = 0; // default Alpha sub-mode
878 878
 				$txtarr = array(); // array of characters and sub-mode switching characters
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
 									}
900 900
 								} else {
901 901
 									// latch
902
-									$txtarr	= array_merge($txtarr, $this->textlatch[''.$submode.$s]);
902
+									$txtarr = array_merge($txtarr, $this->textlatch[''.$submode.$s]);
903 903
 									// set new submode
904 904
 									$submode = $s;
905 905
 								}
@@ -911,14 +911,14 @@  discard block
 block discarded – undo
911 911
 					}
912 912
 				}
913 913
 				$txtarrlen = count($txtarr);
914
-				if (($txtarrlen % 2) != 0) {
914
+				if (($txtarrlen%2) != 0) {
915 915
 					// add padding
916 916
 					$txtarr[] = 29;
917 917
 					++$txtarrlen;
918 918
 				}
919 919
 				// calculate codewords
920 920
 				for ($i = 0; $i < $txtarrlen; $i += 2) {
921
-					$cw[] = (30 * $txtarr[$i]) + $txtarr[($i + 1)];
921
+					$cw[] = (30*$txtarr[$i]) + $txtarr[($i + 1)];
922 922
 				}
923 923
 				break;
924 924
 			}
Please login to merge, or discard this patch.
phpmyfaq/inc/libs/tcpdf/include/barcodes/qrcode.php 3 patches
Doc Comments   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 	 * Convert a string to an array (needed for PHP4 compatibility)
256 256
 	 * @param $string (string) The input string.
257 257
 	 * @param $split_length (int) Maximum length of the chunk.
258
-	 * @return  If the optional split_length  parameter is specified, the returned array will be broken down into chunks with each being split_length  in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element.
258
+	 * @return  string[] the optional split_length  parameter is specified, the returned array will be broken down into chunks with each being split_length  in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element.
259 259
 	 */
260 260
 	function str_split($string, $split_length=1) {
261 261
 		if ((strlen($string) > $split_length) OR (!$split_length)) {
@@ -715,7 +715,7 @@  discard block
 block discarded – undo
715 715
 
716 716
 	/**
717 717
 	 * Encode mask
718
-	 * @param $mask (int) masking mode
718
+	 * @param integer $mask (int) masking mode
719 719
 	 */
720 720
 	protected function encodeMask($mask) {
721 721
 		$spec = array(0, 0, 0, 0, 0);
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
 	/**
790 790
 	 * Get frame value at specified position
791 791
 	 * @param $at (array) x,y position
792
-	 * @return value at specified position
792
+	 * @return integer at specified position
793 793
 	 */
794 794
 	protected function getFrameAt($at) {
795 795
 		return ord($this->frame[$at['y']][$at['x']]);
@@ -1105,7 +1105,7 @@  discard block
 block discarded – undo
1105 1105
 
1106 1106
 	/**
1107 1107
 	 * makeMask
1108
-	 * @param $width (int)
1108
+	 * @param integer $width (int)
1109 1109
 	 * @param $frame (array)
1110 1110
 	 * @param $maskNo (int)
1111 1111
 	 * @param $level (int)
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
 
1121 1121
 	/**
1122 1122
 	 * calcN1N3
1123
-	 * @param $length (int)
1123
+	 * @param integer $length (int)
1124 1124
 	 * @return int demerit
1125 1125
 	 */
1126 1126
 	 protected function calcN1N3($length) {
@@ -1211,7 +1211,7 @@  discard block
 block discarded – undo
1211 1211
 
1212 1212
 	/**
1213 1213
 	 * mask
1214
-	 * @param $width (int)
1214
+	 * @param integer $width (int)
1215 1215
 	 * @param $frame (array)
1216 1216
 	 * @param $level (int)
1217 1217
 	 * @return array best mask
@@ -1254,7 +1254,7 @@  discard block
 block discarded – undo
1254 1254
 
1255 1255
 	/**
1256 1256
 	 * Return true if the character at specified position is a number
1257
-	 * @param $str (string) string
1257
+	 * @param string $str (string) string
1258 1258
 	 * @param $pos (int) characted position
1259 1259
 	 * @return boolean true of false
1260 1260
 	 */
@@ -1267,7 +1267,7 @@  discard block
 block discarded – undo
1267 1267
 
1268 1268
 	/**
1269 1269
 	 * Return true if the character at specified position is an alphanumeric character
1270
-	 * @param $str (string) string
1270
+	 * @param string $str (string) string
1271 1271
 	 * @param $pos (int) characted position
1272 1272
 	 * @return boolean true of false
1273 1273
 	 */
@@ -1634,7 +1634,7 @@  discard block
 block discarded – undo
1634 1634
 	/**
1635 1635
 	 * encodeBitStream
1636 1636
 	 * @param $inputitem (array)
1637
-	 * @param $version (int)
1637
+	 * @param integer $version (int)
1638 1638
 	 * @return array input item
1639 1639
 	 */
1640 1640
 	 protected function encodeBitStream($inputitem, $version) {
@@ -1686,9 +1686,9 @@  discard block
 block discarded – undo
1686 1686
 	 * Append data to an input object.
1687 1687
 	 * The data is copied and appended to the input object.
1688 1688
 	 * @param $items (arrray) input items
1689
-	 * @param $mode (int) encoding mode.
1690
-	 * @param $size (int) size of data (byte).
1691
-	 * @param $data (array) array of input data.
1689
+	 * @param integer $mode (int) encoding mode.
1690
+	 * @param integer $size (int) size of data (byte).
1691
+	 * @param string[] $data (array) array of input data.
1692 1692
 	 * @return items
1693 1693
 	 *
1694 1694
 	 */
@@ -1755,7 +1755,7 @@  discard block
 block discarded – undo
1755 1755
 
1756 1756
 	/**
1757 1757
 	 * Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19).
1758
-	 * @param $c (int) character value
1758
+	 * @param integer $c (int) character value
1759 1759
 	 * @return value
1760 1760
 	 */
1761 1761
 	protected function lookAnTable($c) {
@@ -1885,7 +1885,7 @@  discard block
 block discarded – undo
1885 1885
 	/**
1886 1886
 	 * estimateBitStreamSize
1887 1887
 	 * @param $items (array)
1888
-	 * @param $version (int)
1888
+	 * @param integer $version (int)
1889 1889
 	 * @return int bits
1890 1890
 	 */
1891 1891
 	 protected function estimateBitStreamSize($items, $version) {
@@ -2265,7 +2265,7 @@  discard block
 block discarded – undo
2265 2265
 	 * @param $srctab (array)
2266 2266
 	 * @param $x (int) X position
2267 2267
 	 * @param $y (int) Y position
2268
-	 * @param $repl (string) value to replace
2268
+	 * @param string $repl (string) value to replace
2269 2269
 	 * @param $replLen (int) length of the repl string
2270 2270
 	 * @return array srctab
2271 2271
 	 */
@@ -2296,7 +2296,7 @@  discard block
 block discarded – undo
2296 2296
 
2297 2297
 	/**
2298 2298
 	 * Return the width of the symbol for the version.
2299
-	 * @param $version (int) version
2299
+	 * @param integer $version (int) version
2300 2300
 	 * @return int width
2301 2301
 	 */
2302 2302
 	protected function getWidth($version) {
@@ -2305,7 +2305,7 @@  discard block
 block discarded – undo
2305 2305
 
2306 2306
 	/**
2307 2307
 	 * Return the numer of remainder bits.
2308
-	 * @param $version (int) version
2308
+	 * @param integer $version (int) version
2309 2309
 	 * @return int number of remainder bits
2310 2310
 	 */
2311 2311
 	protected function getRemainder($version) {
@@ -2314,7 +2314,7 @@  discard block
 block discarded – undo
2314 2314
 
2315 2315
 	/**
2316 2316
 	 * Return a version number that satisfies the input code length.
2317
-	 * @param $size (int) input code length (bytes)
2317
+	 * @param integer $size (int) input code length (bytes)
2318 2318
 	 * @param $level (int) error correction level
2319 2319
 	 * @return int version number
2320 2320
 	 */
@@ -2376,9 +2376,9 @@  discard block
 block discarded – undo
2376 2376
 
2377 2377
 	/**
2378 2378
 	 * Return an array of ECC specification.
2379
-	 * @param $version (int) version
2379
+	 * @param integer $version (int) version
2380 2380
 	 * @param $level (int) error correction level
2381
-	 * @param $spec (array) an array of ECC specification contains as following: {# of type1 blocks, # of data code, # of ecc code, # of type2 blocks, # of data code}
2381
+	 * @param integer[] $spec (array) an array of ECC specification contains as following: {# of type1 blocks, # of data code, # of ecc code, # of type2 blocks, # of data code}
2382 2382
 	 * @return array spec
2383 2383
 	 */
2384 2384
 	protected function getEccSpec($version, $level, $spec) {
@@ -2588,7 +2588,7 @@  discard block
 block discarded – undo
2588 2588
 
2589 2589
 	/**
2590 2590
 	 * Set new frame for the specified version.
2591
-	 * @param $version (int) version
2591
+	 * @param integer $version (int) version
2592 2592
 	 * @return Array of unsigned char.
2593 2593
 	 */
2594 2594
 	protected function newFrame($version) {
@@ -2670,7 +2670,7 @@  discard block
 block discarded – undo
2670 2670
 	/**
2671 2671
 	 * Return data length
2672 2672
 	 * @param $spec (array)
2673
-	 * @return int value
2673
+	 * @return double value
2674 2674
 	 */
2675 2675
 	 protected function rsDataLength($spec) {
2676 2676
 		return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);
@@ -2691,12 +2691,12 @@  discard block
 block discarded – undo
2691 2691
 
2692 2692
 	/**
2693 2693
 	 * Initialize a Reed-Solomon codec and add it to existing rsitems
2694
-	 * @param $symsize (int) symbol size, bits
2695
-	 * @param $gfpoly (int)  Field generator polynomial coefficients
2696
-	 * @param $fcr (int)  first root of RS code generator polynomial, index form
2697
-	 * @param $prim (int)  primitive element to generate polynomial roots
2698
-	 * @param $nroots (int) RS code generator polynomial degree (number of roots)
2699
-	 * @param $pad (int)  padding bytes at front of shortened block
2694
+	 * @param integer $symsize (int) symbol size, bits
2695
+	 * @param integer $gfpoly (int)  Field generator polynomial coefficients
2696
+	 * @param integer $fcr (int)  first root of RS code generator polynomial, index form
2697
+	 * @param integer $prim (int)  primitive element to generate polynomial roots
2698
+	 * @param integer $nroots (int) RS code generator polynomial degree (number of roots)
2699
+	 * @param integer $pad (int)  padding bytes at front of shortened block
2700 2700
 	 * @return array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>.
2701 2701
 	 */
2702 2702
 	 protected function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) {
Please login to merge, or discard this patch.
Indentation   +2710 added lines, -2710 removed lines patch added patch discarded remove patch
@@ -82,168 +82,168 @@  discard block
 block discarded – undo
82 82
 // definitions
83 83
 if (!defined('QRCODEDEFS')) {
84 84
 
85
-	/**
86
-	 * Indicate that definitions for this class are set
87
-	 */
88
-	define('QRCODEDEFS', true);
89
-
90
-	// -----------------------------------------------------
91
-
92
-	// Encoding modes (characters which can be encoded in QRcode)
93
-
94
-	/**
95
-	 * Encoding mode
96
-	 */
97
-	define('QR_MODE_NL', -1);
98
-
99
-	/**
100
-	 * Encoding mode numeric (0-9). 3 characters are encoded to 10bit length. In theory, 7089 characters or less can be stored in a QRcode.
101
-	 */
102
-	define('QR_MODE_NM', 0);
103
-
104
-	/**
105
-	 * Encoding mode alphanumeric (0-9A-Z $%*+-./:) 45characters. 2 characters are encoded to 11bit length. In theory, 4296 characters or less can be stored in a QRcode.
106
-	 */
107
-	define('QR_MODE_AN', 1);
108
-
109
-	/**
110
-	 * Encoding mode 8bit byte data. In theory, 2953 characters or less can be stored in a QRcode.
111
-	 */
112
-	define('QR_MODE_8B', 2);
113
-
114
-	/**
115
-	 * Encoding mode KANJI. A KANJI character (multibyte character) is encoded to 13bit length. In theory, 1817 characters or less can be stored in a QRcode.
116
-	 */
117
-	define('QR_MODE_KJ', 3);
118
-
119
-	/**
120
-	 * Encoding mode STRUCTURED (currently unsupported)
121
-	 */
122
-	define('QR_MODE_ST', 4);
123
-
124
-	// -----------------------------------------------------
125
-
126
-	// Levels of error correction.
127
-	// QRcode has a function of an error correcting for miss reading that white is black.
128
-	// Error correcting is defined in 4 level as below.
129
-
130
-	/**
131
-	 * Error correction level L : About 7% or less errors can be corrected.
132
-	 */
133
-	define('QR_ECLEVEL_L', 0);
134
-
135
-	/**
136
-	 * Error correction level M : About 15% or less errors can be corrected.
137
-	 */
138
-	define('QR_ECLEVEL_M', 1);
139
-
140
-	/**
141
-	 * Error correction level Q : About 25% or less errors can be corrected.
142
-	 */
143
-	define('QR_ECLEVEL_Q', 2);
144
-
145
-	/**
146
-	 * Error correction level H : About 30% or less errors can be corrected.
147
-	 */
148
-	define('QR_ECLEVEL_H', 3);
149
-
150
-	// -----------------------------------------------------
151
-
152
-	// Version. Size of QRcode is defined as version.
153
-	// Version is from 1 to 40.
154
-	// Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases.
155
-	// So version 40 is 177*177 matrix.
156
-
157
-	/**
158
-	 * Maximum QR Code version.
159
-	 */
160
-	define('QRSPEC_VERSION_MAX', 40);
161
-
162
-	/**
163
-	 * Maximum matrix size for maximum version (version 40 is 177*177 matrix).
164
-	 */
85
+    /**
86
+     * Indicate that definitions for this class are set
87
+     */
88
+    define('QRCODEDEFS', true);
89
+
90
+    // -----------------------------------------------------
91
+
92
+    // Encoding modes (characters which can be encoded in QRcode)
93
+
94
+    /**
95
+     * Encoding mode
96
+     */
97
+    define('QR_MODE_NL', -1);
98
+
99
+    /**
100
+     * Encoding mode numeric (0-9). 3 characters are encoded to 10bit length. In theory, 7089 characters or less can be stored in a QRcode.
101
+     */
102
+    define('QR_MODE_NM', 0);
103
+
104
+    /**
105
+     * Encoding mode alphanumeric (0-9A-Z $%*+-./:) 45characters. 2 characters are encoded to 11bit length. In theory, 4296 characters or less can be stored in a QRcode.
106
+     */
107
+    define('QR_MODE_AN', 1);
108
+
109
+    /**
110
+     * Encoding mode 8bit byte data. In theory, 2953 characters or less can be stored in a QRcode.
111
+     */
112
+    define('QR_MODE_8B', 2);
113
+
114
+    /**
115
+     * Encoding mode KANJI. A KANJI character (multibyte character) is encoded to 13bit length. In theory, 1817 characters or less can be stored in a QRcode.
116
+     */
117
+    define('QR_MODE_KJ', 3);
118
+
119
+    /**
120
+     * Encoding mode STRUCTURED (currently unsupported)
121
+     */
122
+    define('QR_MODE_ST', 4);
123
+
124
+    // -----------------------------------------------------
125
+
126
+    // Levels of error correction.
127
+    // QRcode has a function of an error correcting for miss reading that white is black.
128
+    // Error correcting is defined in 4 level as below.
129
+
130
+    /**
131
+     * Error correction level L : About 7% or less errors can be corrected.
132
+     */
133
+    define('QR_ECLEVEL_L', 0);
134
+
135
+    /**
136
+     * Error correction level M : About 15% or less errors can be corrected.
137
+     */
138
+    define('QR_ECLEVEL_M', 1);
139
+
140
+    /**
141
+     * Error correction level Q : About 25% or less errors can be corrected.
142
+     */
143
+    define('QR_ECLEVEL_Q', 2);
144
+
145
+    /**
146
+     * Error correction level H : About 30% or less errors can be corrected.
147
+     */
148
+    define('QR_ECLEVEL_H', 3);
149
+
150
+    // -----------------------------------------------------
151
+
152
+    // Version. Size of QRcode is defined as version.
153
+    // Version is from 1 to 40.
154
+    // Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases.
155
+    // So version 40 is 177*177 matrix.
156
+
157
+    /**
158
+     * Maximum QR Code version.
159
+     */
160
+    define('QRSPEC_VERSION_MAX', 40);
161
+
162
+    /**
163
+     * Maximum matrix size for maximum version (version 40 is 177*177 matrix).
164
+     */
165 165
     define('QRSPEC_WIDTH_MAX', 177);
166 166
 
167
-	// -----------------------------------------------------
167
+    // -----------------------------------------------------
168 168
 
169
-	/**
170
-	 * Matrix index to get width from $capacity array.
171
-	 */
169
+    /**
170
+     * Matrix index to get width from $capacity array.
171
+     */
172 172
     define('QRCAP_WIDTH',    0);
173 173
 
174 174
     /**
175
-	 * Matrix index to get number of words from $capacity array.
176
-	 */
175
+     * Matrix index to get number of words from $capacity array.
176
+     */
177 177
     define('QRCAP_WORDS',    1);
178 178
 
179 179
     /**
180
-	 * Matrix index to get remainder from $capacity array.
181
-	 */
180
+     * Matrix index to get remainder from $capacity array.
181
+     */
182 182
     define('QRCAP_REMINDER', 2);
183 183
 
184 184
     /**
185
-	 * Matrix index to get error correction level from $capacity array.
186
-	 */
185
+     * Matrix index to get error correction level from $capacity array.
186
+     */
187 187
     define('QRCAP_EC',       3);
188 188
 
189
-	// -----------------------------------------------------
189
+    // -----------------------------------------------------
190 190
 
191
-	// Structure (currently usupported)
191
+    // Structure (currently usupported)
192 192
 
193
-	/**
194
-	 * Number of header bits for structured mode
195
-	 */
193
+    /**
194
+     * Number of header bits for structured mode
195
+     */
196 196
     define('STRUCTURE_HEADER_BITS',  20);
197 197
 
198 198
     /**
199
-	 * Max number of symbols for structured mode
200
-	 */
199
+     * Max number of symbols for structured mode
200
+     */
201 201
     define('MAX_STRUCTURED_SYMBOLS', 16);
202 202
 
203
-	// -----------------------------------------------------
203
+    // -----------------------------------------------------
204 204
 
205 205
     // Masks
206 206
 
207 207
     /**
208
-	 * Down point base value for case 1 mask pattern (concatenation of same color in a line or a column)
209
-	 */
208
+     * Down point base value for case 1 mask pattern (concatenation of same color in a line or a column)
209
+     */
210 210
     define('N1',  3);
211 211
 
212 212
     /**
213
-	 * Down point base value for case 2 mask pattern (module block of same color)
214
-	 */
215
-	define('N2',  3);
213
+     * Down point base value for case 2 mask pattern (module block of same color)
214
+     */
215
+    define('N2',  3);
216 216
 
217 217
     /**
218
-	 * Down point base value for case 3 mask pattern (1:1:3:1:1(dark:bright:dark:bright:dark)pattern in a line or a column)
219
-	 */
220
-	define('N3', 40);
218
+     * Down point base value for case 3 mask pattern (1:1:3:1:1(dark:bright:dark:bright:dark)pattern in a line or a column)
219
+     */
220
+    define('N3', 40);
221 221
 
222 222
     /**
223
-	 * Down point base value for case 4 mask pattern (ration of dark modules in whole)
224
-	 */
225
-	define('N4', 10);
223
+     * Down point base value for case 4 mask pattern (ration of dark modules in whole)
224
+     */
225
+    define('N4', 10);
226 226
 
227
-	// -----------------------------------------------------
227
+    // -----------------------------------------------------
228 228
 
229
-	// Optimization settings
229
+    // Optimization settings
230 230
 
231
-	/**
232
-	 * if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code
233
-	 */
234
-	define('QR_FIND_BEST_MASK', true);
231
+    /**
232
+     * if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code
233
+     */
234
+    define('QR_FIND_BEST_MASK', true);
235 235
 
236
-	/**
237
-	 * if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
238
-	 */
239
-	define('QR_FIND_FROM_RANDOM', 2);
236
+    /**
237
+     * if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
238
+     */
239
+    define('QR_FIND_FROM_RANDOM', 2);
240 240
 
241
-	/**
242
-	 * when QR_FIND_BEST_MASK === false
243
-	 */
244
-	define('QR_DEFAULT_MASK', 2);
241
+    /**
242
+     * when QR_FIND_BEST_MASK === false
243
+     */
244
+    define('QR_DEFAULT_MASK', 2);
245 245
 
246
-	// -----------------------------------------------------
246
+    // -----------------------------------------------------
247 247
 
248 248
 } // end of definitions
249 249
 
@@ -251,24 +251,24 @@  discard block
 block discarded – undo
251 251
 
252 252
 // for compatibility with PHP4
253 253
 if (!function_exists('str_split')) {
254
-	/**
255
-	 * Convert a string to an array (needed for PHP4 compatibility)
256
-	 * @param $string (string) The input string.
257
-	 * @param $split_length (int) Maximum length of the chunk.
258
-	 * @return  If the optional split_length  parameter is specified, the returned array will be broken down into chunks with each being split_length  in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element.
259
-	 */
260
-	function str_split($string, $split_length=1) {
261
-		if ((strlen($string) > $split_length) OR (!$split_length)) {
262
-			do {
263
-				$c = strlen($string);
264
-				$parts[] = substr($string, 0, $split_length);
265
-				$string = substr($string, $split_length);
266
-			} while ($string !== false);
267
-		} else {
268
-			$parts = array($string);
269
-		}
270
-		return $parts;
271
-	}
254
+    /**
255
+     * Convert a string to an array (needed for PHP4 compatibility)
256
+     * @param $string (string) The input string.
257
+     * @param $split_length (int) Maximum length of the chunk.
258
+     * @return  If the optional split_length  parameter is specified, the returned array will be broken down into chunks with each being split_length  in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element.
259
+     */
260
+    function str_split($string, $split_length=1) {
261
+        if ((strlen($string) > $split_length) OR (!$split_length)) {
262
+            do {
263
+                $c = strlen($string);
264
+                $parts[] = substr($string, 0, $split_length);
265
+                $string = substr($string, $split_length);
266
+            } while ($string !== false);
267
+        } else {
268
+            $parts = array($string);
269
+        }
270
+        return $parts;
271
+    }
272 272
 }
273 273
 
274 274
 // #####################################################
@@ -290,2574 +290,2574 @@  discard block
 block discarded – undo
290 290
  */
291 291
 class QRcode {
292 292
 
293
-	/**
294
-	 * Barcode array to be returned which is readable by TCPDF.
295
-	 * @protected
296
-	 */
297
-	protected $barcode_array = array();
298
-
299
-	/**
300
-	 * QR code version. Size of QRcode is defined as version. Version is from 1 to 40. Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases. So version 40 is 177*177 matrix.
301
-	 * @protected
302
-	 */
303
-	protected $version = 0;
304
-
305
-	/**
306
-	 * Levels of error correction. See definitions for possible values.
307
-	 * @protected
308
-	 */
309
-	protected $level = QR_ECLEVEL_L;
310
-
311
-	/**
312
-	 * Encoding mode.
313
-	 * @protected
314
-	 */
315
-	protected $hint = QR_MODE_8B;
316
-
317
-	/**
318
-	 * Boolean flag, if true the input string will be converted to uppercase.
319
-	 * @protected
320
-	 */
321
-	protected $casesensitive = true;
322
-
323
-	/**
324
-	 * Structured QR code (not supported yet).
325
-	 * @protected
326
-	 */
327
-	protected $structured = 0;
328
-
329
-	/**
330
-	 * Mask data.
331
-	 * @protected
332
-	 */
333
-	protected $data;
334
-
335
-	// FrameFiller
336
-
337
-	/**
338
-	 * Width.
339
-	 * @protected
340
-	 */
341
-	protected $width;
342
-
343
-	/**
344
-	 * Frame.
345
-	 * @protected
346
-	 */
347
-	protected $frame;
348
-
349
-	/**
350
-	 * X position of bit.
351
-	 * @protected
352
-	 */
353
-	protected $x;
354
-
355
-	/**
356
-	 * Y position of bit.
357
-	 * @protected
358
-	 */
359
-	protected $y;
360
-
361
-	/**
362
-	 * Direction.
363
-	 * @protected
364
-	 */
365
-	protected $dir;
366
-
367
-	/**
368
-	 * Single bit value.
369
-	 * @protected
370
-	 */
371
-	protected $bit;
372
-
373
-	// ---- QRrawcode ----
374
-
375
-	/**
376
-	 * Data code.
377
-	 * @protected
378
-	 */
379
-	protected $datacode = array();
380
-
381
-	/**
382
-	 * Error correction code.
383
-	 * @protected
384
-	 */
385
-	protected $ecccode = array();
386
-
387
-	/**
388
-	 * Blocks.
389
-	 * @protected
390
-	 */
391
-	protected $blocks;
392
-
393
-	/**
394
-	 * Reed-Solomon blocks.
395
-	 * @protected
396
-	 */
397
-	protected $rsblocks = array(); //of RSblock
398
-
399
-	/**
400
-	 * Counter.
401
-	 * @protected
402
-	 */
403
-	protected $count;
404
-
405
-	/**
406
-	 * Data length.
407
-	 * @protected
408
-	 */
409
-	protected $dataLength;
410
-
411
-	/**
412
-	 * Error correction length.
413
-	 * @protected
414
-	 */
415
-	protected $eccLength;
416
-
417
-	/**
418
-	 * Value b1.
419
-	 * @protected
420
-	 */
421
-	protected $b1;
422
-
423
-	// ---- QRmask ----
424
-
425
-	/**
426
-	 * Run length.
427
-	 * @protected
428
-	 */
429
-	protected $runLength = array();
430
-
431
-	// ---- QRsplit ----
432
-
433
-	/**
434
-	 * Input data string.
435
-	 * @protected
436
-	 */
437
-	protected $dataStr = '';
438
-
439
-	/**
440
-	 * Input items.
441
-	 * @protected
442
-	 */
443
-	protected $items;
444
-
445
-	// Reed-Solomon items
446
-
447
-	/**
448
-	 * Reed-Solomon items.
449
-	 * @protected
450
-	 */
451
-	protected $rsitems = array();
452
-
453
-	/**
454
-	 * Array of frames.
455
-	 * @protected
456
-	 */
457
-	protected $frames = array();
458
-
459
-	/**
460
-	 * Alphabet-numeric convesion table.
461
-	 * @protected
462
-	 */
463
-	protected $anTable = array(
464
-		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //
465
-		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //
466
-		36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, //
467
-		 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 44, -1, -1, -1, -1, -1, //
468
-		-1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, //
469
-		25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, //
470
-		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //
471
-		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1  //
472
-		);
473
-
474
-	/**
475
-	 * Array Table of the capacity of symbols.
476
-	 * See Table 1 (pp.13) and Table 12-16 (pp.30-36), JIS X0510:2004.
477
-	 * @protected
478
-	 */
479
-	protected $capacity = array(
480
-		array(  0,    0, 0, array(   0,    0,    0,    0)), //
481
-		array( 21,   26, 0, array(   7,   10,   13,   17)), //  1
482
-		array( 25,   44, 7, array(  10,   16,   22,   28)), //
483
-		array( 29,   70, 7, array(  15,   26,   36,   44)), //
484
-		array( 33,  100, 7, array(  20,   36,   52,   64)), //
485
-		array( 37,  134, 7, array(  26,   48,   72,   88)), //  5
486
-		array( 41,  172, 7, array(  36,   64,   96,  112)), //
487
-		array( 45,  196, 0, array(  40,   72,  108,  130)), //
488
-		array( 49,  242, 0, array(  48,   88,  132,  156)), //
489
-		array( 53,  292, 0, array(  60,  110,  160,  192)), //
490
-		array( 57,  346, 0, array(  72,  130,  192,  224)), // 10
491
-		array( 61,  404, 0, array(  80,  150,  224,  264)), //
492
-		array( 65,  466, 0, array(  96,  176,  260,  308)), //
493
-		array( 69,  532, 0, array( 104,  198,  288,  352)), //
494
-		array( 73,  581, 3, array( 120,  216,  320,  384)), //
495
-		array( 77,  655, 3, array( 132,  240,  360,  432)), // 15
496
-		array( 81,  733, 3, array( 144,  280,  408,  480)), //
497
-		array( 85,  815, 3, array( 168,  308,  448,  532)), //
498
-		array( 89,  901, 3, array( 180,  338,  504,  588)), //
499
-		array( 93,  991, 3, array( 196,  364,  546,  650)), //
500
-		array( 97, 1085, 3, array( 224,  416,  600,  700)), // 20
501
-		array(101, 1156, 4, array( 224,  442,  644,  750)), //
502
-		array(105, 1258, 4, array( 252,  476,  690,  816)), //
503
-		array(109, 1364, 4, array( 270,  504,  750,  900)), //
504
-		array(113, 1474, 4, array( 300,  560,  810,  960)), //
505
-		array(117, 1588, 4, array( 312,  588,  870, 1050)), // 25
506
-		array(121, 1706, 4, array( 336,  644,  952, 1110)), //
507
-		array(125, 1828, 4, array( 360,  700, 1020, 1200)), //
508
-		array(129, 1921, 3, array( 390,  728, 1050, 1260)), //
509
-		array(133, 2051, 3, array( 420,  784, 1140, 1350)), //
510
-		array(137, 2185, 3, array( 450,  812, 1200, 1440)), // 30
511
-		array(141, 2323, 3, array( 480,  868, 1290, 1530)), //
512
-		array(145, 2465, 3, array( 510,  924, 1350, 1620)), //
513
-		array(149, 2611, 3, array( 540,  980, 1440, 1710)), //
514
-		array(153, 2761, 3, array( 570, 1036, 1530, 1800)), //
515
-		array(157, 2876, 0, array( 570, 1064, 1590, 1890)), // 35
516
-		array(161, 3034, 0, array( 600, 1120, 1680, 1980)), //
517
-		array(165, 3196, 0, array( 630, 1204, 1770, 2100)), //
518
-		array(169, 3362, 0, array( 660, 1260, 1860, 2220)), //
519
-		array(173, 3532, 0, array( 720, 1316, 1950, 2310)), //
520
-		array(177, 3706, 0, array( 750, 1372, 2040, 2430))  // 40
521
-	);
522
-
523
-	/**
524
-	 * Array Length indicator.
525
-	 * @protected
526
-	 */
527
-	protected $lengthTableBits = array(
528
-		array(10, 12, 14),
529
-		array( 9, 11, 13),
530
-		array( 8, 16, 16),
531
-		array( 8, 10, 12)
532
-	);
533
-
534
-	/**
535
-	 * Array Table of the error correction code (Reed-Solomon block).
536
-	 * See Table 12-16 (pp.30-36), JIS X0510:2004.
537
-	 * @protected
538
-	 */
539
-	protected $eccTable = array(
540
-		array(array( 0,  0), array( 0,  0), array( 0,  0), array( 0,  0)), //
541
-		array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)), //  1
542
-		array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)), //
543
-		array(array( 1,  0), array( 1,  0), array( 2,  0), array( 2,  0)), //
544
-		array(array( 1,  0), array( 2,  0), array( 2,  0), array( 4,  0)), //
545
-		array(array( 1,  0), array( 2,  0), array( 2,  2), array( 2,  2)), //  5
546
-		array(array( 2,  0), array( 4,  0), array( 4,  0), array( 4,  0)), //
547
-		array(array( 2,  0), array( 4,  0), array( 2,  4), array( 4,  1)), //
548
-		array(array( 2,  0), array( 2,  2), array( 4,  2), array( 4,  2)), //
549
-		array(array( 2,  0), array( 3,  2), array( 4,  4), array( 4,  4)), //
550
-		array(array( 2,  2), array( 4,  1), array( 6,  2), array( 6,  2)), // 10
551
-		array(array( 4,  0), array( 1,  4), array( 4,  4), array( 3,  8)), //
552
-		array(array( 2,  2), array( 6,  2), array( 4,  6), array( 7,  4)), //
553
-		array(array( 4,  0), array( 8,  1), array( 8,  4), array(12,  4)), //
554
-		array(array( 3,  1), array( 4,  5), array(11,  5), array(11,  5)), //
555
-		array(array( 5,  1), array( 5,  5), array( 5,  7), array(11,  7)), // 15
556
-		array(array( 5,  1), array( 7,  3), array(15,  2), array( 3, 13)), //
557
-		array(array( 1,  5), array(10,  1), array( 1, 15), array( 2, 17)), //
558
-		array(array( 5,  1), array( 9,  4), array(17,  1), array( 2, 19)), //
559
-		array(array( 3,  4), array( 3, 11), array(17,  4), array( 9, 16)), //
560
-		array(array( 3,  5), array( 3, 13), array(15,  5), array(15, 10)), // 20
561
-		array(array( 4,  4), array(17,  0), array(17,  6), array(19,  6)), //
562
-		array(array( 2,  7), array(17,  0), array( 7, 16), array(34,  0)), //
563
-		array(array( 4,  5), array( 4, 14), array(11, 14), array(16, 14)), //
564
-		array(array( 6,  4), array( 6, 14), array(11, 16), array(30,  2)), //
565
-		array(array( 8,  4), array( 8, 13), array( 7, 22), array(22, 13)), // 25
566
-		array(array(10,  2), array(19,  4), array(28,  6), array(33,  4)), //
567
-		array(array( 8,  4), array(22,  3), array( 8, 26), array(12, 28)), //
568
-		array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), //
569
-		array(array( 7,  7), array(21,  7), array( 1, 37), array(19, 26)), //
570
-		array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), // 30
571
-		array(array(13,  3), array( 2, 29), array(42,  1), array(23, 28)), //
572
-		array(array(17,  0), array(10, 23), array(10, 35), array(19, 35)), //
573
-		array(array(17,  1), array(14, 21), array(29, 19), array(11, 46)), //
574
-		array(array(13,  6), array(14, 23), array(44,  7), array(59,  1)), //
575
-		array(array(12,  7), array(12, 26), array(39, 14), array(22, 41)), // 35
576
-		array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), //
577
-		array(array(17,  4), array(29, 14), array(49, 10), array(24, 46)), //
578
-		array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), //
579
-		array(array(20,  4), array(40,  7), array(43, 22), array(10, 67)), //
580
-		array(array(19,  6), array(18, 31), array(34, 34), array(20, 61))  // 40
581
-	);
582
-
583
-	/**
584
-	 * Array Positions of alignment patterns.
585
-	 * This array includes only the second and the third position of the alignment patterns. Rest of them can be calculated from the distance between them.
586
-	 * See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
587
-	 * @protected
588
-	 */
589
-	protected $alignmentPattern = array(
590
-		array( 0,  0),
591
-		array( 0,  0), array(18,  0), array(22,  0), array(26,  0), array(30,  0), //  1- 5
592
-		array(34,  0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), //  6-10
593
-		array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), // 11-15
594
-		array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), // 16-20
595
-		array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), // 21-25
596
-		array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), // 26-30
597
-		array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), // 31-35
598
-		array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58)  // 35-40
599
-	);
600
-
601
-	/**
602
-	 * Array Version information pattern (BCH coded).
603
-	 * See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
604
-	 * size: [QRSPEC_VERSION_MAX - 6]
605
-	 * @protected
606
-	 */
607
-	protected $versionPattern = array(
608
-		0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, //
609
-		0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9, //
610
-		0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75, //
611
-		0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64, //
612
-		0x27541, 0x28c69
613
-	);
614
-
615
-	/**
616
-	 * Array Format information
617
-	 * @protected
618
-	 */
619
-	protected $formatInfo = array(
620
-		array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976), //
621
-		array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0), //
622
-		array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed), //
623
-		array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b)  //
624
-	);
625
-
626
-
627
-	// -------------------------------------------------
628
-	// -------------------------------------------------
629
-
630
-
631
-	/**
632
-	 * This is the class constructor.
633
-	 * Creates a QRcode object
634
-	 * @param $code (string) code to represent using QRcode
635
-	 * @param $eclevel (string) error level: <ul><li>L : About 7% or less errors can be corrected.</li><li>M : About 15% or less errors can be corrected.</li><li>Q : About 25% or less errors can be corrected.</li><li>H : About 30% or less errors can be corrected.</li></ul>
636
-	 * @public
637
-	 * @since 1.0.000
638
-	 */
639
-	public function __construct($code, $eclevel = 'L') {
640
-		$barcode_array = array();
641
-		if ((is_null($code)) OR ($code == '\0') OR ($code == '')) {
642
-			return false;
643
-		}
644
-		// set error correction level
645
-		$this->level = array_search($eclevel, array('L', 'M', 'Q', 'H'));
646
-		if ($this->level === false) {
647
-			$this->level = QR_ECLEVEL_L;
648
-		}
649
-		if (($this->hint != QR_MODE_8B) AND ($this->hint != QR_MODE_KJ)) {
650
-			return false;
651
-		}
652
-		if (($this->version < 0) OR ($this->version > QRSPEC_VERSION_MAX)) {
653
-			return false;
654
-		}
655
-		$this->items = array();
656
-		$this->encodeString($code);
657
-		if (is_null($this->data)) {
658
-			return false;
659
-		}
660
-		$qrTab = $this->binarize($this->data);
661
-		$size = count($qrTab);
662
-		$barcode_array['num_rows'] = $size;
663
-		$barcode_array['num_cols'] = $size;
664
-		$barcode_array['bcode'] = array();
665
-		foreach ($qrTab as $line) {
666
-			$arrAdd = array();
667
-			foreach (str_split($line) as $char) {
668
-				$arrAdd[] = ($char=='1')?1:0;
669
-			}
670
-			$barcode_array['bcode'][] = $arrAdd;
671
-		}
672
-		$this->barcode_array = $barcode_array;
673
-	}
674
-
675
-	/**
676
-	 * Returns a barcode array which is readable by TCPDF
677
-	 * @return array barcode array readable by TCPDF;
678
-	 * @public
679
-	 */
680
-	public function getBarcodeArray() {
681
-		return $this->barcode_array;
682
-	}
683
-
684
-	/**
685
-	 * Convert the frame in binary form
686
-	 * @param $frame (array) array to binarize
687
-	 * @return array frame in binary form
688
-	 */
689
-	protected function binarize($frame) {
690
-		$len = count($frame);
691
-		// the frame is square (width = height)
692
-		foreach ($frame as &$frameLine) {
693
-			for ($i=0; $i<$len; $i++) {
694
-				$frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
695
-			}
696
-		}
697
-		return $frame;
698
-	}
699
-
700
-	/**
701
-	 * Encode the input string to QR code
702
-	 * @param $string (string) input string to encode
703
-	 */
704
-	protected function encodeString($string) {
705
-		$this->dataStr = $string;
706
-		if (!$this->casesensitive) {
707
-			$this->toUpper();
708
-		}
709
-		$ret = $this->splitString();
710
-		if ($ret < 0) {
711
-			return NULL;
712
-		}
713
-		$this->encodeMask(-1);
714
-	}
715
-
716
-	/**
717
-	 * Encode mask
718
-	 * @param $mask (int) masking mode
719
-	 */
720
-	protected function encodeMask($mask) {
721
-		$spec = array(0, 0, 0, 0, 0);
722
-		$this->datacode = $this->getByteStream($this->items);
723
-		if (is_null($this->datacode)) {
724
-			return NULL;
725
-		}
726
-		$spec = $this->getEccSpec($this->version, $this->level, $spec);
727
-		$this->b1 = $this->rsBlockNum1($spec);
728
-		$this->dataLength = $this->rsDataLength($spec);
729
-		$this->eccLength = $this->rsEccLength($spec);
730
-		$this->ecccode = array_fill(0, $this->eccLength, 0);
731
-		$this->blocks = $this->rsBlockNum($spec);
732
-		$ret = $this->init($spec);
733
-		if ($ret < 0) {
734
-			return NULL;
735
-		}
736
-		$this->count = 0;
737
-		$this->width = $this->getWidth($this->version);
738
-		$this->frame = $this->newFrame($this->version);
739
-		$this->x = $this->width - 1;
740
-		$this->y = $this->width - 1;
741
-		$this->dir = -1;
742
-		$this->bit = -1;
743
-		// inteleaved data and ecc codes
744
-		for ($i=0; $i < ($this->dataLength + $this->eccLength); $i++) {
745
-			$code = $this->getCode();
746
-			$bit = 0x80;
747
-			for ($j=0; $j<8; $j++) {
748
-				$addr = $this->getNextPosition();
749
-				$this->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
750
-				$bit = $bit >> 1;
751
-			}
752
-		}
753
-		// remainder bits
754
-		$j = $this->getRemainder($this->version);
755
-		for ($i=0; $i<$j; $i++) {
756
-			$addr = $this->getNextPosition();
757
-			$this->setFrameAt($addr, 0x02);
758
-		}
759
-		// masking
760
-		$this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
761
-		if ($mask < 0) {
762
-			if (QR_FIND_BEST_MASK) {
763
-				$masked = $this->mask($this->width, $this->frame, $this->level);
764
-			} else {
765
-				$masked = $this->makeMask($this->width, $this->frame, (intval(QR_DEFAULT_MASK) % 8), $this->level);
766
-			}
767
-		} else {
768
-			$masked = $this->makeMask($this->width, $this->frame, $mask, $this->level);
769
-		}
770
-		if ($masked == NULL) {
771
-			return NULL;
772
-		}
773
-		$this->data = $masked;
774
-	}
775
-
776
-	// - - - - - - - - - - - - - - - - - - - - - - - - -
777
-
778
-	// FrameFiller
779
-
780
-	/**
781
-	 * Set frame value at specified position
782
-	 * @param $at (array) x,y position
783
-	 * @param $val (int) value of the character to set
784
-	 */
785
-	protected function setFrameAt($at, $val) {
786
-		$this->frame[$at['y']][$at['x']] = chr($val);
787
-	}
788
-
789
-	/**
790
-	 * Get frame value at specified position
791
-	 * @param $at (array) x,y position
792
-	 * @return value at specified position
793
-	 */
794
-	protected function getFrameAt($at) {
795
-		return ord($this->frame[$at['y']][$at['x']]);
796
-	}
797
-
798
-	/**
799
-	 * Return the next frame position
800
-	 * @return array of x,y coordinates
801
-	 */
802
-	protected function getNextPosition() {
803
-		do {
804
-			if ($this->bit == -1) {
805
-				$this->bit = 0;
806
-				return array('x'=>$this->x, 'y'=>$this->y);
807
-			}
808
-			$x = $this->x;
809
-			$y = $this->y;
810
-			$w = $this->width;
811
-			if ($this->bit == 0) {
812
-				$x--;
813
-				$this->bit++;
814
-			} else {
815
-				$x++;
816
-				$y += $this->dir;
817
-				$this->bit--;
818
-			}
819
-			if ($this->dir < 0) {
820
-				if ($y < 0) {
821
-					$y = 0;
822
-					$x -= 2;
823
-					$this->dir = 1;
824
-					if ($x == 6) {
825
-						$x--;
826
-						$y = 9;
827
-					}
828
-				}
829
-			} else {
830
-				if ($y == $w) {
831
-					$y = $w - 1;
832
-					$x -= 2;
833
-					$this->dir = -1;
834
-					if ($x == 6) {
835
-						$x--;
836
-						$y -= 8;
837
-					}
838
-				}
839
-			}
840
-			if (($x < 0) OR ($y < 0)) {
841
-				return NULL;
842
-			}
843
-			$this->x = $x;
844
-			$this->y = $y;
845
-		} while(ord($this->frame[$y][$x]) & 0x80);
846
-		return array('x'=>$x, 'y'=>$y);
847
-	}
848
-
849
-	// - - - - - - - - - - - - - - - - - - - - - - - - -
850
-
851
-	// QRrawcode
852
-
853
-	/**
854
-	 * Initialize code.
855
-	 * @param $spec (array) array of ECC specification
856
-	 * @return 0 in case of success, -1 in case of error
857
-	 */
858
-	protected function init($spec) {
859
-		$dl = $this->rsDataCodes1($spec);
860
-		$el = $this->rsEccCodes1($spec);
861
-		$rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
862
-		$blockNo = 0;
863
-		$dataPos = 0;
864
-		$eccPos = 0;
865
-		$endfor = $this->rsBlockNum1($spec);
866
-		for ($i=0; $i < $endfor; ++$i) {
867
-			$ecc = array_slice($this->ecccode, $eccPos);
868
-			$this->rsblocks[$blockNo] = array();
869
-			$this->rsblocks[$blockNo]['dataLength'] = $dl;
870
-			$this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos);
871
-			$this->rsblocks[$blockNo]['eccLength'] = $el;
872
-			$ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc);
873
-			$this->rsblocks[$blockNo]['ecc'] = $ecc;
874
-			$this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
875
-			$dataPos += $dl;
876
-			$eccPos += $el;
877
-			$blockNo++;
878
-		}
879
-		if ($this->rsBlockNum2($spec) == 0) {
880
-			return 0;
881
-		}
882
-		$dl = $this->rsDataCodes2($spec);
883
-		$el = $this->rsEccCodes2($spec);
884
-		$rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
885
-		if ($rs == NULL) {
886
-			return -1;
887
-		}
888
-		$endfor = $this->rsBlockNum2($spec);
889
-		for ($i=0; $i < $endfor; ++$i) {
890
-			$ecc = array_slice($this->ecccode, $eccPos);
891
-			$this->rsblocks[$blockNo] = array();
892
-			$this->rsblocks[$blockNo]['dataLength'] = $dl;
893
-			$this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos);
894
-			$this->rsblocks[$blockNo]['eccLength'] = $el;
895
-			$ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc);
896
-			$this->rsblocks[$blockNo]['ecc'] = $ecc;
897
-			$this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc);
898
-			$dataPos += $dl;
899
-			$eccPos += $el;
900
-			$blockNo++;
901
-		}
902
-		return 0;
903
-	}
904
-
905
-	/**
906
-	 * Return Reed-Solomon block code.
907
-	 * @return array rsblocks
908
-	 */
909
-	protected function getCode() {
910
-		if ($this->count < $this->dataLength) {
911
-			$row = $this->count % $this->blocks;
912
-			$col = $this->count / $this->blocks;
913
-			if ($col >= $this->rsblocks[0]['dataLength']) {
914
-				$row += $this->b1;
915
-			}
916
-			$ret = $this->rsblocks[$row]['data'][$col];
917
-		} elseif ($this->count < $this->dataLength + $this->eccLength) {
918
-			$row = ($this->count - $this->dataLength) % $this->blocks;
919
-			$col = ($this->count - $this->dataLength) / $this->blocks;
920
-			$ret = $this->rsblocks[$row]['ecc'][$col];
921
-		} else {
922
-			return 0;
923
-		}
924
-		$this->count++;
925
-		return $ret;
926
-	}
927
-
928
-	// - - - - - - - - - - - - - - - - - - - - - - - - -
929
-
930
-	// QRmask
931
-
932
-	/**
933
-	 * Write Format Information on frame and returns the number of black bits
934
-	 * @param $width (int) frame width
935
-	 * @param $frame (array) frame
936
-	 * @param $mask (array) masking mode
937
-	 * @param $level (int) error correction level
938
-	 * @return int blacks
939
-	 */
940
-	 protected function writeFormatInformation($width, &$frame, $mask, $level) {
941
-		$blacks = 0;
942
-		$format =  $this->getFormatInfo($mask, $level);
943
-		for ($i=0; $i<8; ++$i) {
944
-			if ($format & 1) {
945
-				$blacks += 2;
946
-				$v = 0x85;
947
-			} else {
948
-				$v = 0x84;
949
-			}
950
-			$frame[8][$width - 1 - $i] = chr($v);
951
-			if ($i < 6) {
952
-				$frame[$i][8] = chr($v);
953
-			} else {
954
-				$frame[$i + 1][8] = chr($v);
955
-			}
956
-			$format = $format >> 1;
957
-		}
958
-		for ($i=0; $i<7; ++$i) {
959
-		if ($format & 1) {
960
-			$blacks += 2;
961
-			$v = 0x85;
962
-		} else {
963
-			$v = 0x84;
964
-		}
965
-		$frame[$width - 7 + $i][8] = chr($v);
966
-		if ($i == 0) {
967
-			$frame[8][7] = chr($v);
968
-		} else {
969
-			$frame[8][6 - $i] = chr($v);
970
-		}
971
-		$format = $format >> 1;
972
-		}
973
-		return $blacks;
974
-	}
975
-
976
-	/**
977
-	 * mask0
978
-	 * @param $x (int) X position
979
-	 * @param $y (int) Y position
980
-	 * @return int mask
981
-	 */
982
-	 protected function mask0($x, $y) {
983
-		return ($x + $y) & 1;
984
-	}
985
-
986
-	/**
987
-	 * mask1
988
-	 * @param $x (int) X position
989
-	 * @param $y (int) Y position
990
-	 * @return int mask
991
-	 */
992
-	 protected function mask1($x, $y) {
993
-		return ($y & 1);
994
-	}
995
-
996
-	/**
997
-	 * mask2
998
-	 * @param $x (int) X position
999
-	 * @param $y (int) Y position
1000
-	 * @return int mask
1001
-	 */
1002
-	 protected function mask2($x, $y) {
1003
-		return ($x % 3);
1004
-	}
1005
-
1006
-	/**
1007
-	 * mask3
1008
-	 * @param $x (int) X position
1009
-	 * @param $y (int) Y position
1010
-	 * @return int mask
1011
-	 */
1012
-	 protected function mask3($x, $y) {
1013
-		return ($x + $y) % 3;
1014
-	}
1015
-
1016
-	/**
1017
-	 * mask4
1018
-	 * @param $x (int) X position
1019
-	 * @param $y (int) Y position
1020
-	 * @return int mask
1021
-	 */
1022
-	 protected function mask4($x, $y) {
1023
-		return (((int)($y / 2)) + ((int)($x / 3))) & 1;
1024
-	}
1025
-
1026
-	/**
1027
-	 * mask5
1028
-	 * @param $x (int) X position
1029
-	 * @param $y (int) Y position
1030
-	 * @return int mask
1031
-	 */
1032
-	 protected function mask5($x, $y) {
1033
-		return (($x * $y) & 1) + ($x * $y) % 3;
1034
-	}
1035
-
1036
-	/**
1037
-	 * mask6
1038
-	 * @param $x (int) X position
1039
-	 * @param $y (int) Y position
1040
-	 * @return int mask
1041
-	 */
1042
-	 protected function mask6($x, $y) {
1043
-		return ((($x * $y) & 1) + ($x * $y) % 3) & 1;
1044
-	}
1045
-
1046
-	/**
1047
-	 * mask7
1048
-	 * @param $x (int) X position
1049
-	 * @param $y (int) Y position
1050
-	 * @return int mask
1051
-	 */
1052
-	 protected function mask7($x, $y) {
1053
-		return ((($x * $y) % 3) + (($x + $y) & 1)) & 1;
1054
-	}
1055
-
1056
-	/**
1057
-	 * Return bitmask
1058
-	 * @param $maskNo (int) mask number
1059
-	 * @param $width (int) width
1060
-	 * @param $frame (array) frame
1061
-	 * @return array bitmask
1062
-	 */
1063
-	protected function generateMaskNo($maskNo, $width, $frame) {
1064
-		$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
1065
-		for ($y=0; $y<$width; ++$y) {
1066
-			for ($x=0; $x<$width; ++$x) {
1067
-				if (ord($frame[$y][$x]) & 0x80) {
1068
-					$bitMask[$y][$x] = 0;
1069
-				} else {
1070
-					$maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
1071
-					$bitMask[$y][$x] = ($maskFunc == 0)?1:0;
1072
-				}
1073
-			}
1074
-		}
1075
-		return $bitMask;
1076
-	}
1077
-
1078
-	/**
1079
-	 * makeMaskNo
1080
-	 * @param $maskNo (int)
1081
-	 * @param $width (int)
1082
-	 * @param $s (int)
1083
-	 * @param $d (int)
1084
-	 * @param $maskGenOnly (boolean)
1085
-	 * @return int b
1086
-	 */
1087
-	 protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false) {
1088
-		$b = 0;
1089
-		$bitMask = array();
1090
-		$bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
1091
-		if ($maskGenOnly) {
1092
-			return;
1093
-		}
1094
-		$d = $s;
1095
-		for ($y=0; $y<$width; ++$y) {
1096
-			for ($x=0; $x<$width; ++$x) {
1097
-				if ($bitMask[$y][$x] == 1) {
1098
-					$d[$y][$x] = chr(ord($s[$y][$x]) ^ ((int)($bitMask[$y][$x])));
1099
-				}
1100
-				$b += (int)(ord($d[$y][$x]) & 1);
1101
-			}
1102
-		}
1103
-		return $b;
1104
-	}
1105
-
1106
-	/**
1107
-	 * makeMask
1108
-	 * @param $width (int)
1109
-	 * @param $frame (array)
1110
-	 * @param $maskNo (int)
1111
-	 * @param $level (int)
1112
-	 * @return array mask
1113
-	 */
1114
-	 protected function makeMask($width, $frame, $maskNo, $level) {
1115
-		$masked = array_fill(0, $width, str_repeat("\0", $width));
1116
-		$this->makeMaskNo($maskNo, $width, $frame, $masked);
1117
-		$this->writeFormatInformation($width, $masked, $maskNo, $level);
1118
-		return $masked;
1119
-	}
1120
-
1121
-	/**
1122
-	 * calcN1N3
1123
-	 * @param $length (int)
1124
-	 * @return int demerit
1125
-	 */
1126
-	 protected function calcN1N3($length) {
1127
-		$demerit = 0;
1128
-		for ($i=0; $i<$length; ++$i) {
1129
-			if ($this->runLength[$i] >= 5) {
1130
-				$demerit += (N1 + ($this->runLength[$i] - 5));
1131
-			}
1132
-			if ($i & 1) {
1133
-				if (($i >= 3) AND ($i < ($length-2)) AND ($this->runLength[$i] % 3 == 0)) {
1134
-					$fact = (int)($this->runLength[$i] / 3);
1135
-					if (($this->runLength[$i-2] == $fact)
1136
-						AND ($this->runLength[$i-1] == $fact)
1137
-						AND ($this->runLength[$i+1] == $fact)
1138
-						AND ($this->runLength[$i+2] == $fact)) {
1139
-						if (($this->runLength[$i-3] < 0) OR ($this->runLength[$i-3] >= (4 * $fact))) {
1140
-							$demerit += N3;
1141
-						} elseif ((($i+3) >= $length) OR ($this->runLength[$i+3] >= (4 * $fact))) {
1142
-							$demerit += N3;
1143
-						}
1144
-					}
1145
-				}
1146
-			}
1147
-		}
1148
-		return $demerit;
1149
-	}
1150
-
1151
-	/**
1152
-	 * evaluateSymbol
1153
-	 * @param $width (int)
1154
-	 * @param $frame (array)
1155
-	 * @return int demerit
1156
-	 */
1157
-	 protected function evaluateSymbol($width, $frame) {
1158
-		$head = 0;
1159
-		$demerit = 0;
1160
-		for ($y=0; $y<$width; ++$y) {
1161
-			$head = 0;
1162
-			$this->runLength[0] = 1;
1163
-			$frameY = $frame[$y];
1164
-			if ($y > 0) {
1165
-				$frameYM = $frame[$y-1];
1166
-			}
1167
-			for ($x=0; $x<$width; ++$x) {
1168
-				if (($x > 0) AND ($y > 0)) {
1169
-					$b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
1170
-					$w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
1171
-					if (($b22 | ($w22 ^ 1)) & 1) {
1172
-						$demerit += N2;
1173
-					}
1174
-				}
1175
-				if (($x == 0) AND (ord($frameY[$x]) & 1)) {
1176
-					$this->runLength[0] = -1;
1177
-					$head = 1;
1178
-					$this->runLength[$head] = 1;
1179
-				} elseif ($x > 0) {
1180
-					if ((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
1181
-						$head++;
1182
-						$this->runLength[$head] = 1;
1183
-					} else {
1184
-						$this->runLength[$head]++;
1185
-					}
1186
-				}
1187
-			}
1188
-			$demerit += $this->calcN1N3($head+1);
1189
-		}
1190
-		for ($x=0; $x<$width; ++$x) {
1191
-			$head = 0;
1192
-			$this->runLength[0] = 1;
1193
-			for ($y=0; $y<$width; ++$y) {
1194
-				if (($y == 0) AND (ord($frame[$y][$x]) & 1)) {
1195
-					$this->runLength[0] = -1;
1196
-					$head = 1;
1197
-					$this->runLength[$head] = 1;
1198
-				} elseif ($y > 0) {
1199
-					if ((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
1200
-						$head++;
1201
-						$this->runLength[$head] = 1;
1202
-					} else {
1203
-						$this->runLength[$head]++;
1204
-					}
1205
-				}
1206
-			}
1207
-			$demerit += $this->calcN1N3($head+1);
1208
-		}
1209
-		return $demerit;
1210
-	}
1211
-
1212
-	/**
1213
-	 * mask
1214
-	 * @param $width (int)
1215
-	 * @param $frame (array)
1216
-	 * @param $level (int)
1217
-	 * @return array best mask
1218
-	 */
1219
-	 protected function mask($width, $frame, $level) {
1220
-		$minDemerit = PHP_INT_MAX;
1221
-		$bestMaskNum = 0;
1222
-		$bestMask = array();
1223
-		$checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7);
1224
-		if (QR_FIND_FROM_RANDOM !== false) {
1225
-			$howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9);
1226
-			for ($i = 0; $i <  $howManuOut; ++$i) {
1227
-				$remPos = rand (0, count($checked_masks)-1);
1228
-				unset($checked_masks[$remPos]);
1229
-				$checked_masks = array_values($checked_masks);
1230
-			}
1231
-		}
1232
-		$bestMask = $frame;
1233
-		foreach ($checked_masks as $i) {
1234
-			$mask = array_fill(0, $width, str_repeat("\0", $width));
1235
-			$demerit = 0;
1236
-			$blacks = 0;
1237
-			$blacks  = $this->makeMaskNo($i, $width, $frame, $mask);
1238
-			$blacks += $this->writeFormatInformation($width, $mask, $i, $level);
1239
-			$blacks  = (int)(100 * $blacks / ($width * $width));
1240
-			$demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
1241
-			$demerit += $this->evaluateSymbol($width, $mask);
1242
-			if ($demerit < $minDemerit) {
1243
-				$minDemerit = $demerit;
1244
-				$bestMask = $mask;
1245
-				$bestMaskNum = $i;
1246
-			}
1247
-		}
1248
-		return $bestMask;
1249
-	}
1250
-
1251
-	// - - - - - - - - - - - - - - - - - - - - - - - - -
1252
-
1253
-	// QRsplit
1254
-
1255
-	/**
1256
-	 * Return true if the character at specified position is a number
1257
-	 * @param $str (string) string
1258
-	 * @param $pos (int) characted position
1259
-	 * @return boolean true of false
1260
-	 */
1261
-	 protected function isdigitat($str, $pos) {
1262
-		if ($pos >= strlen($str)) {
1263
-			return false;
1264
-		}
1265
-		return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
1266
-	}
1267
-
1268
-	/**
1269
-	 * Return true if the character at specified position is an alphanumeric character
1270
-	 * @param $str (string) string
1271
-	 * @param $pos (int) characted position
1272
-	 * @return boolean true of false
1273
-	 */
1274
-	 protected function isalnumat($str, $pos) {
1275
-		if ($pos >= strlen($str)) {
1276
-			return false;
1277
-		}
1278
-		return ($this->lookAnTable(ord($str[$pos])) >= 0);
1279
-	}
1280
-
1281
-	/**
1282
-	 * identifyMode
1283
-	 * @param $pos (int)
1284
-	 * @return int mode
1285
-	 */
1286
-	 protected function identifyMode($pos) {
1287
-		if ($pos >= strlen($this->dataStr)) {
1288
-			return QR_MODE_NL;
1289
-		}
1290
-		$c = $this->dataStr[$pos];
1291
-		if ($this->isdigitat($this->dataStr, $pos)) {
1292
-			return QR_MODE_NM;
1293
-		} elseif ($this->isalnumat($this->dataStr, $pos)) {
1294
-			return QR_MODE_AN;
1295
-		} elseif ($this->hint == QR_MODE_KJ) {
1296
-			if ($pos+1 < strlen($this->dataStr)) {
1297
-				$d = $this->dataStr[$pos+1];
1298
-				$word = (ord($c) << 8) | ord($d);
1299
-				if (($word >= 0x8140 && $word <= 0x9ffc) OR ($word >= 0xe040 && $word <= 0xebbf)) {
1300
-					return QR_MODE_KJ;
1301
-				}
1302
-			}
1303
-		}
1304
-		return QR_MODE_8B;
1305
-	}
1306
-
1307
-	/**
1308
-	 * eatNum
1309
-	 * @return int run
1310
-	 */
1311
-	 protected function eatNum() {
1312
-		$ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
1313
-		$p = 0;
1314
-		while($this->isdigitat($this->dataStr, $p)) {
1315
-			$p++;
1316
-		}
1317
-		$run = $p;
1318
-		$mode = $this->identifyMode($p);
1319
-		if ($mode == QR_MODE_8B) {
1320
-			$dif = $this->estimateBitsModeNum($run) + 4 + $ln
1321
-			+ $this->estimateBitsMode8(1)         // + 4 + l8
1322
-			- $this->estimateBitsMode8($run + 1); // - 4 - l8
1323
-			if ($dif > 0) {
1324
-				return $this->eat8();
1325
-			}
1326
-		}
1327
-		if ($mode == QR_MODE_AN) {
1328
-			$dif = $this->estimateBitsModeNum($run) + 4 + $ln
1329
-			+ $this->estimateBitsModeAn(1)        // + 4 + la
1330
-			- $this->estimateBitsModeAn($run + 1);// - 4 - la
1331
-			if ($dif > 0) {
1332
-				return $this->eatAn();
1333
-			}
1334
-		}
1335
-		$this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, str_split($this->dataStr));
1336
-		return $run;
1337
-	}
1338
-
1339
-	/**
1340
-	 * eatAn
1341
-	 * @return int run
1342
-	 */
1343
-	 protected function eatAn() {
1344
-		$la = $this->lengthIndicator(QR_MODE_AN,  $this->version);
1345
-		$ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
1346
-		$p =1 ;
1347
-		while($this->isalnumat($this->dataStr, $p)) {
1348
-			if ($this->isdigitat($this->dataStr, $p)) {
1349
-				$q = $p;
1350
-				while($this->isdigitat($this->dataStr, $q)) {
1351
-					$q++;
1352
-				}
1353
-				$dif = $this->estimateBitsModeAn($p) // + 4 + la
1354
-				+ $this->estimateBitsModeNum($q - $p) + 4 + $ln
1355
-				- $this->estimateBitsModeAn($q); // - 4 - la
1356
-				if ($dif < 0) {
1357
-					break;
1358
-				} else {
1359
-					$p = $q;
1360
-				}
1361
-			} else {
1362
-				$p++;
1363
-			}
1364
-		}
1365
-		$run = $p;
1366
-		if (!$this->isalnumat($this->dataStr, $p)) {
1367
-			$dif = $this->estimateBitsModeAn($run) + 4 + $la
1368
-			+ $this->estimateBitsMode8(1) // + 4 + l8
1369
-			- $this->estimateBitsMode8($run + 1); // - 4 - l8
1370
-			if ($dif > 0) {
1371
-				return $this->eat8();
1372
-			}
1373
-		}
1374
-		$this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, str_split($this->dataStr));
1375
-		return $run;
1376
-	}
1377
-
1378
-	/**
1379
-	 * eatKanji
1380
-	 * @return int run
1381
-	 */
1382
-	 protected function eatKanji() {
1383
-		$p = 0;
1384
-		while($this->identifyMode($p) == QR_MODE_KJ) {
1385
-			$p += 2;
1386
-		}
1387
-		$this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, str_split($this->dataStr));
1388
-		return $run;
1389
-	}
1390
-
1391
-	/**
1392
-	 * eat8
1393
-	 * @return int run
1394
-	 */
1395
-	 protected function eat8() {
1396
-		$la = $this->lengthIndicator(QR_MODE_AN, $this->version);
1397
-		$ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
1398
-		$p = 1;
1399
-		$dataStrLen = strlen($this->dataStr);
1400
-		while($p < $dataStrLen) {
1401
-			$mode = $this->identifyMode($p);
1402
-			if ($mode == QR_MODE_KJ) {
1403
-				break;
1404
-			}
1405
-			if ($mode == QR_MODE_NM) {
1406
-				$q = $p;
1407
-				while($this->isdigitat($this->dataStr, $q)) {
1408
-					$q++;
1409
-				}
1410
-				$dif = $this->estimateBitsMode8($p) // + 4 + l8
1411
-				+ $this->estimateBitsModeNum($q - $p) + 4 + $ln
1412
-				- $this->estimateBitsMode8($q); // - 4 - l8
1413
-				if ($dif < 0) {
1414
-					break;
1415
-				} else {
1416
-					$p = $q;
1417
-				}
1418
-			} elseif ($mode == QR_MODE_AN) {
1419
-				$q = $p;
1420
-				while($this->isalnumat($this->dataStr, $q)) {
1421
-					$q++;
1422
-				}
1423
-				$dif = $this->estimateBitsMode8($p)  // + 4 + l8
1424
-				+ $this->estimateBitsModeAn($q - $p) + 4 + $la
1425
-				- $this->estimateBitsMode8($q); // - 4 - l8
1426
-				if ($dif < 0) {
1427
-					break;
1428
-				} else {
1429
-					$p = $q;
1430
-				}
1431
-			} else {
1432
-				$p++;
1433
-			}
1434
-		}
1435
-		$run = $p;
1436
-		$this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, str_split($this->dataStr));
1437
-		return $run;
1438
-	}
1439
-
1440
-	/**
1441
-	 * splitString
1442
-	 * @return (int)
1443
-	 */
1444
-	 protected function splitString() {
1445
-		while (strlen($this->dataStr) > 0) {
1446
-			$mode = $this->identifyMode(0);
1447
-			switch ($mode) {
1448
-				case QR_MODE_NM: {
1449
-					$length = $this->eatNum();
1450
-					break;
1451
-				}
1452
-				case QR_MODE_AN: {
1453
-					$length = $this->eatAn();
1454
-					break;
1455
-				}
1456
-				case QR_MODE_KJ: {
1457
-					if ($hint == QR_MODE_KJ) {
1458
-						$length = $this->eatKanji();
1459
-					} else {
1460
-						$length = $this->eat8();
1461
-					}
1462
-					break;
1463
-				}
1464
-				default: {
1465
-					$length = $this->eat8();
1466
-					break;
1467
-				}
1468
-			}
1469
-			if ($length == 0) {
1470
-				return 0;
1471
-			}
1472
-			if ($length < 0) {
1473
-				return -1;
1474
-			}
1475
-			$this->dataStr = substr($this->dataStr, $length);
1476
-		}
1477
-		return 0;
1478
-	}
1479
-
1480
-	/**
1481
-	 * toUpper
1482
-	 */
1483
-	 protected function toUpper() {
1484
-		$stringLen = strlen($this->dataStr);
1485
-		$p = 0;
1486
-		while ($p < $stringLen) {
1487
-			$mode = $this->identifyMode(substr($this->dataStr, $p), $this->hint);
1488
-			if ($mode == QR_MODE_KJ) {
1489
-				$p += 2;
1490
-			} else {
1491
-				if ((ord($this->dataStr[$p]) >= ord('a')) AND (ord($this->dataStr[$p]) <= ord('z'))) {
1492
-					$this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32);
1493
-				}
1494
-				$p++;
1495
-			}
1496
-		}
1497
-		return $this->dataStr;
1498
-	}
1499
-
1500
-	// - - - - - - - - - - - - - - - - - - - - - - - - -
1501
-
1502
-	// QRinputItem
1503
-
1504
-	/**
1505
-	 * newInputItem
1506
-	 * @param $mode (int)
1507
-	 * @param $size (int)
1508
-	 * @param $data (array)
1509
-	 * @param $bstream (array)
1510
-	 * @return array input item
1511
-	 */
1512
-	 protected function newInputItem($mode, $size, $data, $bstream=null) {
1513
-		$setData = array_slice($data, 0, $size);
1514
-		if (count($setData) < $size) {
1515
-			$setData = array_merge($setData, array_fill(0, ($size - count($setData)), 0));
1516
-		}
1517
-		if (!$this->check($mode, $size, $setData)) {
1518
-			return NULL;
1519
-		}
1520
-		$inputitem = array();
1521
-		$inputitem['mode'] = $mode;
1522
-		$inputitem['size'] = $size;
1523
-		$inputitem['data'] = $setData;
1524
-		$inputitem['bstream'] = $bstream;
1525
-		return $inputitem;
1526
-	}
1527
-
1528
-	/**
1529
-	 * encodeModeNum
1530
-	 * @param $inputitem (array)
1531
-	 * @param $version (int)
1532
-	 * @return array input item
1533
-	 */
1534
-	 protected function encodeModeNum($inputitem, $version) {
1535
-		$words = (int)($inputitem['size'] / 3);
1536
-		$inputitem['bstream'] = array();
1537
-		$val = 0x1;
1538
-		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val);
1539
-		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_NM, $version), $inputitem['size']);
1540
-		for ($i=0; $i < $words; ++$i) {
1541
-			$val  = (ord($inputitem['data'][$i*3  ]) - ord('0')) * 100;
1542
-			$val += (ord($inputitem['data'][$i*3+1]) - ord('0')) * 10;
1543
-			$val += (ord($inputitem['data'][$i*3+2]) - ord('0'));
1544
-			$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 10, $val);
1545
-		}
1546
-		if ($inputitem['size'] - $words * 3 == 1) {
1547
-			$val = ord($inputitem['data'][$words*3]) - ord('0');
1548
-			$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val);
1549
-		} elseif (($inputitem['size'] - ($words * 3)) == 2) {
1550
-			$val  = (ord($inputitem['data'][$words*3  ]) - ord('0')) * 10;
1551
-			$val += (ord($inputitem['data'][$words*3+1]) - ord('0'));
1552
-			$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 7, $val);
1553
-		}
1554
-		return $inputitem;
1555
-	}
1556
-
1557
-	/**
1558
-	 * encodeModeAn
1559
-	 * @param $inputitem (array)
1560
-	 * @param $version (int)
1561
-	 * @return array input item
1562
-	 */
1563
-	 protected function encodeModeAn($inputitem, $version) {
1564
-		$words = (int)($inputitem['size'] / 2);
1565
-		$inputitem['bstream'] = array();
1566
-		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x02);
1567
-		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_AN, $version), $inputitem['size']);
1568
-		for ($i=0; $i < $words; ++$i) {
1569
-			$val  = (int)($this->lookAnTable(ord($inputitem['data'][$i*2])) * 45);
1570
-			$val += (int)($this->lookAnTable(ord($inputitem['data'][($i*2)+1])));
1571
-			$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 11, $val);
1572
-		}
1573
-		if ($inputitem['size'] & 1) {
1574
-			$val = $this->lookAnTable(ord($inputitem['data'][($words * 2)]));
1575
-			$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 6, $val);
1576
-		}
1577
-		return $inputitem;
1578
-	}
1579
-
1580
-	/**
1581
-	 * encodeMode8
1582
-	 * @param $inputitem (array)
1583
-	 * @param $version (int)
1584
-	 * @return array input item
1585
-	 */
1586
-	 protected function encodeMode8($inputitem, $version) {
1587
-		$inputitem['bstream'] = array();
1588
-		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x4);
1589
-		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_8B, $version), $inputitem['size']);
1590
-		for ($i=0; $i < $inputitem['size']; ++$i) {
1591
-			$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][$i]));
1592
-		}
1593
-		return $inputitem;
1594
-	}
1595
-
1596
-	/**
1597
-	 * encodeModeKanji
1598
-	 * @param $inputitem (array)
1599
-	 * @param $version (int)
1600
-	 * @return array input item
1601
-	 */
1602
-	 protected function encodeModeKanji($inputitem, $version) {
1603
-		$inputitem['bstream'] = array();
1604
-		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x8);
1605
-		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_KJ, $version), (int)($inputitem['size'] / 2));
1606
-		for ($i=0; $i<$inputitem['size']; $i+=2) {
1607
-			$val = (ord($inputitem['data'][$i]) << 8) | ord($inputitem['data'][$i+1]);
1608
-			if ($val <= 0x9ffc) {
1609
-				$val -= 0x8140;
1610
-			} else {
1611
-				$val -= 0xc140;
1612
-			}
1613
-			$h = ($val >> 8) * 0xc0;
1614
-			$val = ($val & 0xff) + $h;
1615
-			$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 13, $val);
1616
-		}
1617
-		return $inputitem;
1618
-	}
1619
-
1620
-	/**
1621
-	 * encodeModeStructure
1622
-	 * @param $inputitem (array)
1623
-	 * @return array input item
1624
-	 */
1625
-	 protected function encodeModeStructure($inputitem) {
1626
-		$inputitem['bstream'] = array();
1627
-		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x03);
1628
-		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][1]) - 1);
1629
-		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][0]) - 1);
1630
-		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][2]));
1631
-		return $inputitem;
1632
-	}
1633
-
1634
-	/**
1635
-	 * encodeBitStream
1636
-	 * @param $inputitem (array)
1637
-	 * @param $version (int)
1638
-	 * @return array input item
1639
-	 */
1640
-	 protected function encodeBitStream($inputitem, $version) {
1641
-		$inputitem['bstream'] = array();
1642
-		$words = $this->maximumWords($inputitem['mode'], $version);
1643
-		if ($inputitem['size'] > $words) {
1644
-			$st1 = $this->newInputItem($inputitem['mode'], $words, $inputitem['data']);
1645
-			$st2 = $this->newInputItem($inputitem['mode'], $inputitem['size'] - $words, array_slice($inputitem['data'], $words));
1646
-			$st1 = $this->encodeBitStream($st1, $version);
1647
-			$st2 = $this->encodeBitStream($st2, $version);
1648
-			$inputitem['bstream'] = array();
1649
-			$inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st1['bstream']);
1650
-			$inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st2['bstream']);
1651
-		} else {
1652
-			switch($inputitem['mode']) {
1653
-				case QR_MODE_NM: {
1654
-					$inputitem = $this->encodeModeNum($inputitem, $version);
1655
-					break;
1656
-				}
1657
-				case QR_MODE_AN: {
1658
-					$inputitem = $this->encodeModeAn($inputitem, $version);
1659
-					break;
1660
-				}
1661
-				case QR_MODE_8B: {
1662
-					$inputitem = $this->encodeMode8($inputitem, $version);
1663
-					break;
1664
-				}
1665
-				case QR_MODE_KJ: {
1666
-					$inputitem = $this->encodeModeKanji($inputitem, $version);
1667
-					break;
1668
-				}
1669
-				case QR_MODE_ST: {
1670
-					$inputitem = $this->encodeModeStructure($inputitem);
1671
-					break;
1672
-				}
1673
-				default: {
1674
-					break;
1675
-				}
1676
-			}
1677
-		}
1678
-		return $inputitem;
1679
-	}
1680
-
1681
-	// - - - - - - - - - - - - - - - - - - - - - - - - -
1682
-
1683
-	// QRinput
1684
-
1685
-	/**
1686
-	 * Append data to an input object.
1687
-	 * The data is copied and appended to the input object.
1688
-	 * @param $items (arrray) input items
1689
-	 * @param $mode (int) encoding mode.
1690
-	 * @param $size (int) size of data (byte).
1691
-	 * @param $data (array) array of input data.
1692
-	 * @return items
1693
-	 *
1694
-	 */
1695
-	protected function appendNewInputItem($items, $mode, $size, $data) {
1696
-		$newitem = $this->newInputItem($mode, $size, $data);
1697
-		if (!empty($newitem)) {
1698
-			$items[] = $newitem;
1699
-		}
1700
-		return $items;
1701
-	}
1702
-
1703
-	/**
1704
-	 * insertStructuredAppendHeader
1705
-	 * @param $items (array)
1706
-	 * @param $size (int)
1707
-	 * @param $index (int)
1708
-	 * @param $parity (int)
1709
-	 * @return array items
1710
-	 */
1711
-	 protected function insertStructuredAppendHeader($items, $size, $index, $parity) {
1712
-		if ($size > MAX_STRUCTURED_SYMBOLS) {
1713
-			return -1;
1714
-		}
1715
-		if (($index <= 0) OR ($index > MAX_STRUCTURED_SYMBOLS)) {
1716
-			return -1;
1717
-		}
1718
-		$buf = array($size, $index, $parity);
1719
-		$entry = $this->newInputItem(QR_MODE_ST, 3, buf);
1720
-		array_unshift($items, $entry);
1721
-		return $items;
1722
-	}
1723
-
1724
-	/**
1725
-	 * calcParity
1726
-	 * @param $items (array)
1727
-	 * @return int parity
1728
-	 */
1729
-	 protected function calcParity($items) {
1730
-		$parity = 0;
1731
-		foreach ($items as $item) {
1732
-			if ($item['mode'] != QR_MODE_ST) {
1733
-				for ($i=$item['size']-1; $i>=0; --$i) {
1734
-					$parity ^= $item['data'][$i];
1735
-				}
1736
-			}
1737
-		}
1738
-		return $parity;
1739
-	}
1740
-
1741
-	/**
1742
-	 * checkModeNum
1743
-	 * @param $size (int)
1744
-	 * @param $data (array)
1745
-	 * @return boolean true or false
1746
-	 */
1747
-	 protected function checkModeNum($size, $data) {
1748
-		for ($i=0; $i<$size; ++$i) {
1749
-			if ((ord($data[$i]) < ord('0')) OR (ord($data[$i]) > ord('9'))){
1750
-				return false;
1751
-			}
1752
-		}
1753
-		return true;
1754
-	}
1755
-
1756
-	/**
1757
-	 * Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19).
1758
-	 * @param $c (int) character value
1759
-	 * @return value
1760
-	 */
1761
-	protected function lookAnTable($c) {
1762
-		return (($c > 127)?-1:$this->anTable[$c]);
1763
-	}
1764
-
1765
-	/**
1766
-	 * checkModeAn
1767
-	 * @param $size (int)
1768
-	 * @param $data (array)
1769
-	 * @return boolean true or false
1770
-	 */
1771
-	 protected function checkModeAn($size, $data) {
1772
-		for ($i=0; $i<$size; ++$i) {
1773
-			if ($this->lookAnTable(ord($data[$i])) == -1) {
1774
-				return false;
1775
-			}
1776
-		}
1777
-		return true;
1778
-	}
1779
-
1780
-	/**
1781
-	 * estimateBitsModeNum
1782
-	 * @param $size (int)
1783
-	 * @return int number of bits
1784
-	 */
1785
-	 protected function estimateBitsModeNum($size) {
1786
-		$w = (int)($size / 3);
1787
-		$bits = ($w * 10);
1788
-		switch($size - ($w * 3)) {
1789
-			case 1: {
1790
-				$bits += 4;
1791
-				break;
1792
-			}
1793
-			case 2: {
1794
-				$bits += 7;
1795
-				break;
1796
-			}
1797
-		}
1798
-		return $bits;
1799
-	}
1800
-
1801
-	/**
1802
-	 * estimateBitsModeAn
1803
-	 * @param $size (int)
1804
-	 * @return int number of bits
1805
-	 */
1806
-	 protected function estimateBitsModeAn($size) {
1807
-		$bits = (int)($size * 5.5); // (size / 2 ) * 11
1808
-		if ($size & 1) {
1809
-			$bits += 6;
1810
-		}
1811
-		return $bits;
1812
-	}
1813
-
1814
-	/**
1815
-	 * estimateBitsMode8
1816
-	 * @param $size (int)
1817
-	 * @return int number of bits
1818
-	 */
1819
-	 protected function estimateBitsMode8($size) {
1820
-		return (int)($size * 8);
1821
-	}
1822
-
1823
-	/**
1824
-	 * estimateBitsModeKanji
1825
-	 * @param $size (int)
1826
-	 * @return int number of bits
1827
-	 */
1828
-	 protected function estimateBitsModeKanji($size) {
1829
-		return (int)($size * 6.5); // (size / 2 ) * 13
1830
-	}
1831
-
1832
-	/**
1833
-	 * checkModeKanji
1834
-	 * @param $size (int)
1835
-	 * @param $data (array)
1836
-	 * @return boolean true or false
1837
-	 */
1838
-	 protected function checkModeKanji($size, $data) {
1839
-		if ($size & 1) {
1840
-			return false;
1841
-		}
1842
-		for ($i=0; $i<$size; $i+=2) {
1843
-			$val = (ord($data[$i]) << 8) | ord($data[$i+1]);
1844
-			if (($val < 0x8140) OR (($val > 0x9ffc) AND ($val < 0xe040)) OR ($val > 0xebbf)) {
1845
-				return false;
1846
-			}
1847
-		}
1848
-		return true;
1849
-	}
1850
-
1851
-	/**
1852
-	 * Validate the input data.
1853
-	 * @param $mode (int) encoding mode.
1854
-	 * @param $size (int) size of data (byte).
1855
-	 * @param $data (array) data to validate
1856
-	 * @return boolean true in case of valid data, false otherwise
1857
-	 */
1858
-	protected function check($mode, $size, $data) {
1859
-		if ($size <= 0) {
1860
-			return false;
1861
-		}
1862
-		switch($mode) {
1863
-			case QR_MODE_NM: {
1864
-				return $this->checkModeNum($size, $data);
1865
-			}
1866
-			case QR_MODE_AN: {
1867
-				return $this->checkModeAn($size, $data);
1868
-			}
1869
-			case QR_MODE_KJ: {
1870
-				return $this->checkModeKanji($size, $data);
1871
-			}
1872
-			case QR_MODE_8B: {
1873
-				return true;
1874
-			}
1875
-			case QR_MODE_ST: {
1876
-				return true;
1877
-			}
1878
-			default: {
1879
-				break;
1880
-			}
1881
-		}
1882
-		return false;
1883
-	}
1884
-
1885
-	/**
1886
-	 * estimateBitStreamSize
1887
-	 * @param $items (array)
1888
-	 * @param $version (int)
1889
-	 * @return int bits
1890
-	 */
1891
-	 protected function estimateBitStreamSize($items, $version) {
1892
-		$bits = 0;
1893
-		if ($version == 0) {
1894
-			$version = 1;
1895
-		}
1896
-		foreach ($items as $item) {
1897
-			switch($item['mode']) {
1898
-				case QR_MODE_NM: {
1899
-					$bits = $this->estimateBitsModeNum($item['size']);
1900
-					break;
1901
-				}
1902
-				case QR_MODE_AN: {
1903
-					$bits = $this->estimateBitsModeAn($item['size']);
1904
-					break;
1905
-				}
1906
-				case QR_MODE_8B: {
1907
-					$bits = $this->estimateBitsMode8($item['size']);
1908
-					break;
1909
-				}
1910
-				case QR_MODE_KJ: {
1911
-					$bits = $this->estimateBitsModeKanji($item['size']);
1912
-					break;
1913
-				}
1914
-				case QR_MODE_ST: {
1915
-					return STRUCTURE_HEADER_BITS;
1916
-				}
1917
-				default: {
1918
-					return 0;
1919
-				}
1920
-			}
1921
-			$l = $this->lengthIndicator($item['mode'], $version);
1922
-			$m = 1 << $l;
1923
-			$num = (int)(($item['size'] + $m - 1) / $m);
1924
-			$bits += $num * (4 + $l);
1925
-		}
1926
-		return $bits;
1927
-	}
1928
-
1929
-	/**
1930
-	 * estimateVersion
1931
-	 * @param $items (array)
1932
-	 * @return int version
1933
-	 */
1934
-	 protected function estimateVersion($items) {
1935
-		$version = 0;
1936
-		$prev = 0;
1937
-		do {
1938
-			$prev = $version;
1939
-			$bits = $this->estimateBitStreamSize($items, $prev);
1940
-			$version = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level);
1941
-			if ($version < 0) {
1942
-				return -1;
1943
-			}
1944
-		} while ($version > $prev);
1945
-		return $version;
1946
-	}
1947
-
1948
-	/**
1949
-	 * lengthOfCode
1950
-	 * @param $mode (int)
1951
-	 * @param $version (int)
1952
-	 * @param $bits (int)
1953
-	 * @return int size
1954
-	 */
1955
-	 protected function lengthOfCode($mode, $version, $bits) {
1956
-		$payload = $bits - 4 - $this->lengthIndicator($mode, $version);
1957
-		switch($mode) {
1958
-			case QR_MODE_NM: {
1959
-				$chunks = (int)($payload / 10);
1960
-				$remain = $payload - $chunks * 10;
1961
-				$size = $chunks * 3;
1962
-				if ($remain >= 7) {
1963
-					$size += 2;
1964
-				} elseif ($remain >= 4) {
1965
-					$size += 1;
1966
-				}
1967
-				break;
1968
-			}
1969
-			case QR_MODE_AN: {
1970
-				$chunks = (int)($payload / 11);
1971
-				$remain = $payload - $chunks * 11;
1972
-				$size = $chunks * 2;
1973
-				if ($remain >= 6) {
1974
-					++$size;
1975
-				}
1976
-				break;
1977
-			}
1978
-			case QR_MODE_8B: {
1979
-				$size = (int)($payload / 8);
1980
-				break;
1981
-			}
1982
-			case QR_MODE_KJ: {
1983
-				$size = (int)(($payload / 13) * 2);
1984
-				break;
1985
-			}
1986
-			case QR_MODE_ST: {
1987
-				$size = (int)($payload / 8);
1988
-				break;
1989
-			}
1990
-			default: {
1991
-				$size = 0;
1992
-				break;
1993
-			}
1994
-		}
1995
-		$maxsize = $this->maximumWords($mode, $version);
1996
-		if ($size < 0) {
1997
-			$size = 0;
1998
-		}
1999
-		if ($size > $maxsize) {
2000
-			$size = $maxsize;
2001
-		}
2002
-		return $size;
2003
-	}
2004
-
2005
-	/**
2006
-	 * createBitStream
2007
-	 * @param $items (array)
2008
-	 * @return array of items and total bits
2009
-	 */
2010
-	 protected function createBitStream($items) {
2011
-		$total = 0;
2012
-		foreach ($items as $key => $item) {
2013
-			$items[$key] = $this->encodeBitStream($item, $this->version);
2014
-			$bits = count($items[$key]['bstream']);
2015
-			$total += $bits;
2016
-		}
2017
-		return array($items, $total);
2018
-	}
2019
-
2020
-	/**
2021
-	 * convertData
2022
-	 * @param $items (array)
2023
-	 * @return array items
2024
-	 */
2025
-	 protected function convertData($items) {
2026
-		$ver = $this->estimateVersion($items);
2027
-		if ($ver > $this->version) {
2028
-			$this->version = $ver;
2029
-		}
2030
-		while (true) {
2031
-			$cbs = $this->createBitStream($items);
2032
-			$items = $cbs[0];
2033
-			$bits = $cbs[1];
2034
-			if ($bits < 0) {
2035
-				return -1;
2036
-			}
2037
-			$ver = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level);
2038
-			if ($ver < 0) {
2039
-				return -1;
2040
-			} elseif ($ver > $this->version) {
2041
-				$this->version = $ver;
2042
-			} else {
2043
-				break;
2044
-			}
2045
-		}
2046
-		return $items;
2047
-	}
2048
-
2049
-	/**
2050
-	 * Append Padding Bit to bitstream
2051
-	 * @param $bstream (array)
2052
-	 * @return array bitstream
2053
-	 */
2054
-	 protected function appendPaddingBit($bstream) {
2055
-	 	if (is_null($bstream)) {
2056
-	 		return null;
2057
-	 	}
2058
-		$bits = count($bstream);
2059
-		$maxwords = $this->getDataLength($this->version, $this->level);
2060
-		$maxbits = $maxwords * 8;
2061
-		if ($maxbits == $bits) {
2062
-			return $bstream;
2063
-		}
2064
-		if ($maxbits - $bits < 5) {
2065
-			return $this->appendNum($bstream, $maxbits - $bits, 0);
2066
-		}
2067
-		$bits += 4;
2068
-		$words = (int)(($bits + 7) / 8);
2069
-		$padding = array();
2070
-		$padding = $this->appendNum($padding, $words * 8 - $bits + 4, 0);
2071
-		$padlen = $maxwords - $words;
2072
-		if ($padlen > 0) {
2073
-			$padbuf = array();
2074
-			for ($i=0; $i<$padlen; ++$i) {
2075
-				$padbuf[$i] = ($i&1)?0x11:0xec;
2076
-			}
2077
-			$padding = $this->appendBytes($padding, $padlen, $padbuf);
2078
-		}
2079
-		return $this->appendBitstream($bstream, $padding);
2080
-	}
2081
-
2082
-	/**
2083
-	 * mergeBitStream
2084
-	 * @param $items (array) items
2085
-	 * @return array bitstream
2086
-	 */
2087
-	 protected function mergeBitStream($items) {
2088
-		$items = $this->convertData($items);
2089
-		if (!is_array($items)) {
2090
-			return null;
2091
-		}
2092
-		$bstream = array();
2093
-		foreach ($items as $item) {
2094
-			$bstream = $this->appendBitstream($bstream, $item['bstream']);
2095
-		}
2096
-		return $bstream;
2097
-	}
2098
-
2099
-	/**
2100
-	 * Returns a stream of bits.
2101
-	 * @param $items (int)
2102
-	 * @return array padded merged byte stream
2103
-	 */
2104
-	protected function getBitStream($items) {
2105
-		$bstream = $this->mergeBitStream($items);
2106
-		return $this->appendPaddingBit($bstream);
2107
-	}
2108
-
2109
-	/**
2110
-	 * Pack all bit streams padding bits into a byte array.
2111
-	 * @param $items (int)
2112
-	 * @return array padded merged byte stream
2113
-	 */
2114
-	protected function getByteStream($items) {
2115
-		$bstream = $this->getBitStream($items);
2116
-		return $this->bitstreamToByte($bstream);
2117
-	}
2118
-
2119
-	// - - - - - - - - - - - - - - - - - - - - - - - - -
2120
-
2121
-	// QRbitstream
2122
-
2123
-	/**
2124
-	 * Return an array with zeros
2125
-	 * @param $setLength (int) array size
2126
-	 * @return array
2127
-	 */
2128
-	 protected function allocate($setLength) {
2129
-		return array_fill(0, $setLength, 0);
2130
-	}
2131
-
2132
-	/**
2133
-	 * Return new bitstream from number
2134
-	 * @param $bits (int) number of bits
2135
-	 * @param $num (int) number
2136
-	 * @return array bitstream
2137
-	 */
2138
-	 protected function newFromNum($bits, $num) {
2139
-		$bstream = $this->allocate($bits);
2140
-		$mask = 1 << ($bits - 1);
2141
-		for ($i=0; $i<$bits; ++$i) {
2142
-			if ($num & $mask) {
2143
-				$bstream[$i] = 1;
2144
-			} else {
2145
-				$bstream[$i] = 0;
2146
-			}
2147
-			$mask = $mask >> 1;
2148
-		}
2149
-		return $bstream;
2150
-	}
2151
-
2152
-	/**
2153
-	 * Return new bitstream from bytes
2154
-	 * @param $size (int) size
2155
-	 * @param $data (array) bytes
2156
-	 * @return array bitstream
2157
-	 */
2158
-	 protected function newFromBytes($size, $data) {
2159
-		$bstream = $this->allocate($size * 8);
2160
-		$p=0;
2161
-		for ($i=0; $i<$size; ++$i) {
2162
-			$mask = 0x80;
2163
-			for ($j=0; $j<8; ++$j) {
2164
-				if ($data[$i] & $mask) {
2165
-					$bstream[$p] = 1;
2166
-				} else {
2167
-					$bstream[$p] = 0;
2168
-				}
2169
-				$p++;
2170
-				$mask = $mask >> 1;
2171
-			}
2172
-		}
2173
-		return $bstream;
2174
-	}
2175
-
2176
-	/**
2177
-	 * Append one bitstream to another
2178
-	 * @param $bitstream (array) original bitstream
2179
-	 * @param $append (array) bitstream to append
2180
-	 * @return array bitstream
2181
-	 */
2182
-	 protected function appendBitstream($bitstream, $append) {
2183
-		if ((!is_array($append)) OR (count($append) == 0)) {
2184
-			return $bitstream;
2185
-		}
2186
-		if (count($bitstream) == 0) {
2187
-			return $append;
2188
-		}
2189
-		return array_values(array_merge($bitstream, $append));
2190
-	}
2191
-
2192
-	/**
2193
-	 * Append one bitstream created from number to another
2194
-	 * @param $bitstream (array) original bitstream
2195
-	 * @param $bits (int) number of bits
2196
-	 * @param $num (int) number
2197
-	 * @return array bitstream
2198
-	 */
2199
-	 protected function appendNum($bitstream, $bits, $num) {
2200
-		if ($bits == 0) {
2201
-			return 0;
2202
-		}
2203
-		$b = $this->newFromNum($bits, $num);
2204
-		return $this->appendBitstream($bitstream, $b);
2205
-	}
2206
-
2207
-	/**
2208
-	 * Append one bitstream created from bytes to another
2209
-	 * @param $bitstream (array) original bitstream
2210
-	 * @param $size (int) size
2211
-	 * @param $data (array) bytes
2212
-	 * @return array bitstream
2213
-	 */
2214
-	 protected function appendBytes($bitstream, $size, $data) {
2215
-		if ($size == 0) {
2216
-			return 0;
2217
-		}
2218
-		$b = $this->newFromBytes($size, $data);
2219
-		return $this->appendBitstream($bitstream, $b);
2220
-	}
2221
-
2222
-	/**
2223
-	 * Convert bitstream to bytes
2224
-	 * @param $bstream (array) original bitstream
2225
-	 * @return array of bytes
2226
-	 */
2227
-	 protected function bitstreamToByte($bstream) {
2228
-		if (is_null($bstream)) {
2229
-	 		return null;
2230
-	 	}
2231
-		$size = count($bstream);
2232
-		if ($size == 0) {
2233
-			return array();
2234
-		}
2235
-		$data = array_fill(0, (int)(($size + 7) / 8), 0);
2236
-		$bytes = (int)($size / 8);
2237
-		$p = 0;
2238
-		for ($i=0; $i<$bytes; $i++) {
2239
-			$v = 0;
2240
-			for ($j=0; $j<8; $j++) {
2241
-				$v = $v << 1;
2242
-				$v |= $bstream[$p];
2243
-				$p++;
2244
-			}
2245
-			$data[$i] = $v;
2246
-		}
2247
-		if ($size & 7) {
2248
-			$v = 0;
2249
-			for ($j=0; $j<($size & 7); $j++) {
2250
-				$v = $v << 1;
2251
-				$v |= $bstream[$p];
2252
-				$p++;
2253
-			}
2254
-			$data[$bytes] = $v;
2255
-		}
2256
-		return $data;
2257
-	}
2258
-
2259
-	// - - - - - - - - - - - - - - - - - - - - - - - - -
2260
-
2261
-	// QRspec
2262
-
2263
-	/**
2264
-	 * Replace a value on the array at the specified position
2265
-	 * @param $srctab (array)
2266
-	 * @param $x (int) X position
2267
-	 * @param $y (int) Y position
2268
-	 * @param $repl (string) value to replace
2269
-	 * @param $replLen (int) length of the repl string
2270
-	 * @return array srctab
2271
-	 */
2272
-	 protected function qrstrset($srctab, $x, $y, $repl, $replLen=false) {
2273
-		$srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
2274
-		return $srctab;
2275
-	}
2276
-
2277
-	/**
2278
-	 * Return maximum data code length (bytes) for the version.
2279
-	 * @param $version (int) version
2280
-	 * @param $level (int) error correction level
2281
-	 * @return int maximum size (bytes)
2282
-	 */
2283
-	protected function getDataLength($version, $level) {
2284
-		return $this->capacity[$version][QRCAP_WORDS] - $this->capacity[$version][QRCAP_EC][$level];
2285
-	}
2286
-
2287
-	/**
2288
-	 * Return maximum error correction code length (bytes) for the version.
2289
-	 * @param $version (int) version
2290
-	 * @param $level (int) error correction level
2291
-	 * @return int ECC size (bytes)
2292
-	 */
2293
-	protected function getECCLength($version, $level){
2294
-		return $this->capacity[$version][QRCAP_EC][$level];
2295
-	}
2296
-
2297
-	/**
2298
-	 * Return the width of the symbol for the version.
2299
-	 * @param $version (int) version
2300
-	 * @return int width
2301
-	 */
2302
-	protected function getWidth($version) {
2303
-		return $this->capacity[$version][QRCAP_WIDTH];
2304
-	}
2305
-
2306
-	/**
2307
-	 * Return the numer of remainder bits.
2308
-	 * @param $version (int) version
2309
-	 * @return int number of remainder bits
2310
-	 */
2311
-	protected function getRemainder($version) {
2312
-		return $this->capacity[$version][QRCAP_REMINDER];
2313
-	}
2314
-
2315
-	/**
2316
-	 * Return a version number that satisfies the input code length.
2317
-	 * @param $size (int) input code length (bytes)
2318
-	 * @param $level (int) error correction level
2319
-	 * @return int version number
2320
-	 */
2321
-	protected function getMinimumVersion($size, $level) {
2322
-		for ($i = 1; $i <= QRSPEC_VERSION_MAX; ++$i) {
2323
-			$words = ($this->capacity[$i][QRCAP_WORDS] - $this->capacity[$i][QRCAP_EC][$level]);
2324
-			if ($words >= $size) {
2325
-				return $i;
2326
-			}
2327
-		}
2328
-		// the size of input data is greater than QR capacity, try to lover the error correction mode
2329
-		return -1;
2330
-	}
2331
-
2332
-	/**
2333
-	 * Return the size of length indicator for the mode and version.
2334
-	 * @param $mode (int) encoding mode
2335
-	 * @param $version (int) version
2336
-	 * @return int the size of the appropriate length indicator (bits).
2337
-	 */
2338
-	protected function lengthIndicator($mode, $version) {
2339
-		if ($mode == QR_MODE_ST) {
2340
-			return 0;
2341
-		}
2342
-		if ($version <= 9) {
2343
-			$l = 0;
2344
-		} elseif ($version <= 26) {
2345
-			$l = 1;
2346
-		} else {
2347
-			$l = 2;
2348
-		}
2349
-		return $this->lengthTableBits[$mode][$l];
2350
-	}
2351
-
2352
-	/**
2353
-	 * Return the maximum length for the mode and version.
2354
-	 * @param $mode (int) encoding mode
2355
-	 * @param $version (int) version
2356
-	 * @return int the maximum length (bytes)
2357
-	 */
2358
-	protected function maximumWords($mode, $version) {
2359
-		if ($mode == QR_MODE_ST) {
2360
-			return 3;
2361
-		}
2362
-		if ($version <= 9) {
2363
-			$l = 0;
2364
-		} else if ($version <= 26) {
2365
-			$l = 1;
2366
-		} else {
2367
-			$l = 2;
2368
-		}
2369
-		$bits = $this->lengthTableBits[$mode][$l];
2370
-		$words = (1 << $bits) - 1;
2371
-		if ($mode == QR_MODE_KJ) {
2372
-			$words *= 2; // the number of bytes is required
2373
-		}
2374
-		return $words;
2375
-	}
2376
-
2377
-	/**
2378
-	 * Return an array of ECC specification.
2379
-	 * @param $version (int) version
2380
-	 * @param $level (int) error correction level
2381
-	 * @param $spec (array) an array of ECC specification contains as following: {# of type1 blocks, # of data code, # of ecc code, # of type2 blocks, # of data code}
2382
-	 * @return array spec
2383
-	 */
2384
-	protected function getEccSpec($version, $level, $spec) {
2385
-		if (count($spec) < 5) {
2386
-			$spec = array(0, 0, 0, 0, 0);
2387
-		}
2388
-		$b1 = $this->eccTable[$version][$level][0];
2389
-		$b2 = $this->eccTable[$version][$level][1];
2390
-		$data = $this->getDataLength($version, $level);
2391
-		$ecc = $this->getECCLength($version, $level);
2392
-		if ($b2 == 0) {
2393
-			$spec[0] = $b1;
2394
-			$spec[1] = (int)($data / $b1);
2395
-			$spec[2] = (int)($ecc / $b1);
2396
-			$spec[3] = 0;
2397
-			$spec[4] = 0;
2398
-		} else {
2399
-			$spec[0] = $b1;
2400
-			$spec[1] = (int)($data / ($b1 + $b2));
2401
-			$spec[2] = (int)($ecc  / ($b1 + $b2));
2402
-			$spec[3] = $b2;
2403
-			$spec[4] = $spec[1] + 1;
2404
-		}
2405
-		return $spec;
2406
-	}
2407
-
2408
-	/**
2409
-	 * Put an alignment marker.
2410
-	 * @param $frame (array) frame
2411
-	 * @param $ox (int) X center coordinate of the pattern
2412
-	 * @param $oy (int) Y center coordinate of the pattern
2413
-	 * @return array frame
2414
-	 */
2415
-	protected function putAlignmentMarker($frame, $ox, $oy) {
2416
-		$finder = array(
2417
-			"\xa1\xa1\xa1\xa1\xa1",
2418
-			"\xa1\xa0\xa0\xa0\xa1",
2419
-			"\xa1\xa0\xa1\xa0\xa1",
2420
-			"\xa1\xa0\xa0\xa0\xa1",
2421
-			"\xa1\xa1\xa1\xa1\xa1"
2422
-			);
2423
-		$yStart = $oy - 2;
2424
-		$xStart = $ox - 2;
2425
-		for ($y=0; $y < 5; $y++) {
2426
-			$frame = $this->qrstrset($frame, $xStart, $yStart+$y, $finder[$y]);
2427
-		}
2428
-		return $frame;
2429
-	}
2430
-
2431
-	/**
2432
-	 * Put an alignment pattern.
2433
-	 * @param $version (int) version
2434
-	 * @param $frame (array) frame
2435
-	 * @param $width (int) width
2436
-	 * @return array frame
2437
-	 */
2438
-	 protected function putAlignmentPattern($version, $frame, $width) {
2439
-		if ($version < 2) {
2440
-			return $frame;
2441
-		}
2442
-		$d = $this->alignmentPattern[$version][1] - $this->alignmentPattern[$version][0];
2443
-		if ($d < 0) {
2444
-			$w = 2;
2445
-		} else {
2446
-			$w = (int)(($width - $this->alignmentPattern[$version][0]) / $d + 2);
2447
-		}
2448
-		if ($w * $w - 3 == 1) {
2449
-			$x = $this->alignmentPattern[$version][0];
2450
-			$y = $this->alignmentPattern[$version][0];
2451
-			$frame = $this->putAlignmentMarker($frame, $x, $y);
2452
-			return $frame;
2453
-		}
2454
-		$cx = $this->alignmentPattern[$version][0];
2455
-		$wo = $w - 1;
2456
-		for ($x=1; $x < $wo; ++$x) {
2457
-			$frame = $this->putAlignmentMarker($frame, 6, $cx);
2458
-			$frame = $this->putAlignmentMarker($frame, $cx,  6);
2459
-			$cx += $d;
2460
-		}
2461
-		$cy = $this->alignmentPattern[$version][0];
2462
-		for ($y=0; $y < $wo; ++$y) {
2463
-			$cx = $this->alignmentPattern[$version][0];
2464
-			for ($x=0; $x < $wo; ++$x) {
2465
-				$frame = $this->putAlignmentMarker($frame, $cx, $cy);
2466
-				$cx += $d;
2467
-			}
2468
-			$cy += $d;
2469
-		}
2470
-		return $frame;
2471
-	}
2472
-
2473
-	/**
2474
-	 * Return BCH encoded version information pattern that is used for the symbol of version 7 or greater. Use lower 18 bits.
2475
-	 * @param $version (int) version
2476
-	 * @return BCH encoded version information pattern
2477
-	 */
2478
-	protected function getVersionPattern($version) {
2479
-		if (($version < 7) OR ($version > QRSPEC_VERSION_MAX)) {
2480
-			return 0;
2481
-		}
2482
-		return $this->versionPattern[($version - 7)];
2483
-	}
2484
-
2485
-	/**
2486
-	 * Return BCH encoded format information pattern.
2487
-	 * @param $mask (array)
2488
-	 * @param $level (int) error correction level
2489
-	 * @return BCH encoded format information pattern
2490
-	 */
2491
-	protected function getFormatInfo($mask, $level) {
2492
-		if (($mask < 0) OR ($mask > 7)) {
2493
-			return 0;
2494
-		}
2495
-		if (($level < 0) OR ($level > 3)) {
2496
-			return 0;
2497
-		}
2498
-		return $this->formatInfo[$level][$mask];
2499
-	}
2500
-
2501
-	/**
2502
-	 * Put a finder pattern.
2503
-	 * @param $frame (array) frame
2504
-	 * @param $ox (int) X center coordinate of the pattern
2505
-	 * @param $oy (int) Y center coordinate of the pattern
2506
-	 * @return array frame
2507
-	 */
2508
-	protected function putFinderPattern($frame, $ox, $oy) {
2509
-		$finder = array(
2510
-		"\xc1\xc1\xc1\xc1\xc1\xc1\xc1",
2511
-		"\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
2512
-		"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
2513
-		"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
2514
-		"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
2515
-		"\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
2516
-		"\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
2517
-		);
2518
-		for ($y=0; $y < 7; $y++) {
2519
-			$frame = $this->qrstrset($frame, $ox, ($oy + $y), $finder[$y]);
2520
-		}
2521
-		return $frame;
2522
-	}
2523
-
2524
-	/**
2525
-	 * Return a copy of initialized frame.
2526
-	 * @param $version (int) version
2527
-	 * @return Array of unsigned char.
2528
-	 */
2529
-	protected function createFrame($version) {
2530
-		$width = $this->capacity[$version][QRCAP_WIDTH];
2531
-		$frameLine = str_repeat ("\0", $width);
2532
-		$frame = array_fill(0, $width, $frameLine);
2533
-		// Finder pattern
2534
-		$frame = $this->putFinderPattern($frame, 0, 0);
2535
-		$frame = $this->putFinderPattern($frame, $width - 7, 0);
2536
-		$frame = $this->putFinderPattern($frame, 0, $width - 7);
2537
-		// Separator
2538
-		$yOffset = $width - 7;
2539
-		for ($y=0; $y < 7; ++$y) {
2540
-			$frame[$y][7] = "\xc0";
2541
-			$frame[$y][$width - 8] = "\xc0";
2542
-			$frame[$yOffset][7] = "\xc0";
2543
-			++$yOffset;
2544
-		}
2545
-		$setPattern = str_repeat("\xc0", 8);
2546
-		$frame = $this->qrstrset($frame, 0, 7, $setPattern);
2547
-		$frame = $this->qrstrset($frame, $width-8, 7, $setPattern);
2548
-		$frame = $this->qrstrset($frame, 0, $width - 8, $setPattern);
2549
-		// Format info
2550
-		$setPattern = str_repeat("\x84", 9);
2551
-		$frame = $this->qrstrset($frame, 0, 8, $setPattern);
2552
-		$frame = $this->qrstrset($frame, $width - 8, 8, $setPattern, 8);
2553
-		$yOffset = $width - 8;
2554
-		for ($y=0; $y < 8; ++$y,++$yOffset) {
2555
-			$frame[$y][8] = "\x84";
2556
-			$frame[$yOffset][8] = "\x84";
2557
-		}
2558
-		// Timing pattern
2559
-		$wo = $width - 15;
2560
-		for ($i=1; $i < $wo; ++$i) {
2561
-			$frame[6][7+$i] = chr(0x90 | ($i & 1));
2562
-			$frame[7+$i][6] = chr(0x90 | ($i & 1));
2563
-		}
2564
-		// Alignment pattern
2565
-		$frame = $this->putAlignmentPattern($version, $frame, $width);
2566
-		// Version information
2567
-		if ($version >= 7) {
2568
-			$vinf = $this->getVersionPattern($version);
2569
-			$v = $vinf;
2570
-			for ($x=0; $x<6; ++$x) {
2571
-				for ($y=0; $y<3; ++$y) {
2572
-					$frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
2573
-					$v = $v >> 1;
2574
-				}
2575
-			}
2576
-			$v = $vinf;
2577
-			for ($y=0; $y<6; ++$y) {
2578
-				for ($x=0; $x<3; ++$x) {
2579
-					$frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
2580
-					$v = $v >> 1;
2581
-				}
2582
-			}
2583
-		}
2584
-		// and a little bit...
2585
-		$frame[$width - 8][8] = "\x81";
2586
-		return $frame;
2587
-	}
2588
-
2589
-	/**
2590
-	 * Set new frame for the specified version.
2591
-	 * @param $version (int) version
2592
-	 * @return Array of unsigned char.
2593
-	 */
2594
-	protected function newFrame($version) {
2595
-		if (($version < 1) OR ($version > QRSPEC_VERSION_MAX)) {
2596
-			return NULL;
2597
-		}
2598
-		if (!isset($this->frames[$version])) {
2599
-			$this->frames[$version] = $this->createFrame($version);
2600
-		}
2601
-		if (is_null($this->frames[$version])) {
2602
-			return NULL;
2603
-		}
2604
-		return $this->frames[$version];
2605
-	}
2606
-
2607
-	/**
2608
-	 * Return block number 0
2609
-	 * @param $spec (array)
2610
-	 * @return int value
2611
-	 */
2612
-	 protected function rsBlockNum($spec) {
2613
-		return ($spec[0] + $spec[3]);
2614
-	}
2615
-
2616
-	/**
2617
-	* Return block number 1
2618
-	 * @param $spec (array)
2619
-	 * @return int value
2620
-	 */
2621
-	 protected function rsBlockNum1($spec) {
2622
-		return $spec[0];
2623
-	}
2624
-
2625
-	/**
2626
-	 * Return data codes 1
2627
-	 * @param $spec (array)
2628
-	 * @return int value
2629
-	 */
2630
-	 protected function rsDataCodes1($spec) {
2631
-		return $spec[1];
2632
-	}
2633
-
2634
-	/**
2635
-	 * Return ecc codes 1
2636
-	 * @param $spec (array)
2637
-	 * @return int value
2638
-	 */
2639
-	 protected function rsEccCodes1($spec) {
2640
-		return $spec[2];
2641
-	}
2642
-
2643
-	/**
2644
-	 * Return block number 2
2645
-	 * @param $spec (array)
2646
-	 * @return int value
2647
-	 */
2648
-	 protected function rsBlockNum2($spec) {
2649
-		return $spec[3];
2650
-	}
2651
-
2652
-	/**
2653
-	 * Return data codes 2
2654
-	 * @param $spec (array)
2655
-	 * @return int value
2656
-	 */
2657
-	 protected function rsDataCodes2($spec) {
2658
-		return $spec[4];
2659
-	}
2660
-
2661
-	/**
2662
-	 * Return ecc codes 2
2663
-	 * @param $spec (array)
2664
-	 * @return int value
2665
-	 */
2666
-	 protected function rsEccCodes2($spec) {
2667
-		return $spec[2];
2668
-	}
2669
-
2670
-	/**
2671
-	 * Return data length
2672
-	 * @param $spec (array)
2673
-	 * @return int value
2674
-	 */
2675
-	 protected function rsDataLength($spec) {
2676
-		return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);
2677
-	}
2678
-
2679
-	/**
2680
-	 * Return ecc length
2681
-	 * @param $spec (array)
2682
-	 * @return int value
2683
-	 */
2684
-	 protected function rsEccLength($spec) {
2685
-		return ($spec[0] + $spec[3]) * $spec[2];
2686
-	}
2687
-
2688
-	// - - - - - - - - - - - - - - - - - - - - - - - - -
2689
-
2690
-	// QRrs
2691
-
2692
-	/**
2693
-	 * Initialize a Reed-Solomon codec and add it to existing rsitems
2694
-	 * @param $symsize (int) symbol size, bits
2695
-	 * @param $gfpoly (int)  Field generator polynomial coefficients
2696
-	 * @param $fcr (int)  first root of RS code generator polynomial, index form
2697
-	 * @param $prim (int)  primitive element to generate polynomial roots
2698
-	 * @param $nroots (int) RS code generator polynomial degree (number of roots)
2699
-	 * @param $pad (int)  padding bytes at front of shortened block
2700
-	 * @return array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>.
2701
-	 */
2702
-	 protected function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) {
2703
-		foreach ($this->rsitems as $rs) {
2704
-			if (($rs['pad'] != $pad) OR ($rs['nroots'] != $nroots) OR ($rs['mm'] != $symsize)
2705
-				OR ($rs['gfpoly'] != $gfpoly) OR ($rs['fcr'] != $fcr) OR ($rs['prim'] != $prim)) {
2706
-				continue;
2707
-			}
2708
-			return $rs;
2709
-		}
2710
-		$rs = $this->init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad);
2711
-		array_unshift($this->rsitems, $rs);
2712
-		return $rs;
2713
-	}
2714
-
2715
-	// - - - - - - - - - - - - - - - - - - - - - - - - -
2716
-
2717
-	// QRrsItem
2718
-
2719
-	/**
2720
-	 * modnn
2721
-	 * @param $rs (array) RS values
2722
-	 * @param $x (int) X position
2723
-	 * @return int X osition
2724
-	 */
2725
-	 protected function modnn($rs, $x) {
2726
-		while ($x >= $rs['nn']) {
2727
-			$x -= $rs['nn'];
2728
-			$x = ($x >> $rs['mm']) + ($x & $rs['nn']);
2729
-		}
2730
-		return $x;
2731
-	}
2732
-
2733
-	/**
2734
-	 * Initialize a Reed-Solomon codec and returns an array of values.
2735
-	 * @param $symsize (int) symbol size, bits
2736
-	 * @param $gfpoly (int)  Field generator polynomial coefficients
2737
-	 * @param $fcr (int)  first root of RS code generator polynomial, index form
2738
-	 * @param $prim (int)  primitive element to generate polynomial roots
2739
-	 * @param $nroots (int) RS code generator polynomial degree (number of roots)
2740
-	 * @param $pad (int)  padding bytes at front of shortened block
2741
-	 * @return array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>.
2742
-	 */
2743
-	protected function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) {
2744
-		// Based on Reed solomon encoder by Phil Karn, KA9Q (GNU-LGPLv2)
2745
-		$rs = null;
2746
-		// Check parameter ranges
2747
-		if (($symsize < 0) OR ($symsize > 8)) {
2748
-			return $rs;
2749
-		}
2750
-		if (($fcr < 0) OR ($fcr >= (1<<$symsize))) {
2751
-			return $rs;
2752
-		}
2753
-		if (($prim <= 0) OR ($prim >= (1<<$symsize))) {
2754
-			return $rs;
2755
-		}
2756
-		if (($nroots < 0) OR ($nroots >= (1<<$symsize))) {
2757
-			return $rs;
2758
-		}
2759
-		if (($pad < 0) OR ($pad >= ((1<<$symsize) -1 - $nroots))) {
2760
-			return $rs;
2761
-		}
2762
-		$rs = array();
2763
-		$rs['mm'] = $symsize;
2764
-		$rs['nn'] = (1 << $symsize) - 1;
2765
-		$rs['pad'] = $pad;
2766
-		$rs['alpha_to'] = array_fill(0, ($rs['nn'] + 1), 0);
2767
-		$rs['index_of'] = array_fill(0, ($rs['nn'] + 1), 0);
2768
-		// PHP style macro replacement ;)
2769
-		$NN =& $rs['nn'];
2770
-		$A0 =& $NN;
2771
-		// Generate Galois field lookup tables
2772
-		$rs['index_of'][0] = $A0; // log(zero) = -inf
2773
-		$rs['alpha_to'][$A0] = 0; // alpha**-inf = 0
2774
-		$sr = 1;
2775
-		for ($i=0; $i<$rs['nn']; ++$i) {
2776
-			$rs['index_of'][$sr] = $i;
2777
-			$rs['alpha_to'][$i] = $sr;
2778
-			$sr <<= 1;
2779
-			if ($sr & (1 << $symsize)) {
2780
-				$sr ^= $gfpoly;
2781
-			}
2782
-			$sr &= $rs['nn'];
2783
-		}
2784
-		if ($sr != 1) {
2785
-			// field generator polynomial is not primitive!
2786
-			return NULL;
2787
-		}
2788
-		// Form RS code generator polynomial from its roots
2789
-		$rs['genpoly'] = array_fill(0, ($nroots + 1), 0);
2790
-		$rs['fcr'] = $fcr;
2791
-		$rs['prim'] = $prim;
2792
-		$rs['nroots'] = $nroots;
2793
-		$rs['gfpoly'] = $gfpoly;
2794
-		// Find prim-th root of 1, used in decoding
2795
-		for ($iprim=1; ($iprim % $prim) != 0; $iprim += $rs['nn']) {
2796
-			; // intentional empty-body loop!
2797
-		}
2798
-		$rs['iprim'] = (int)($iprim / $prim);
2799
-		$rs['genpoly'][0] = 1;
2800
-		for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
2801
-			$rs['genpoly'][$i+1] = 1;
2802
-			// Multiply rs->genpoly[] by  @**(root + x)
2803
-			for ($j = $i; $j > 0; --$j) {
2804
-				if ($rs['genpoly'][$j] != 0) {
2805
-					$rs['genpoly'][$j] = $rs['genpoly'][$j-1] ^ $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][$j]] + $root)];
2806
-				} else {
2807
-					$rs['genpoly'][$j] = $rs['genpoly'][$j-1];
2808
-				}
2809
-			}
2810
-			// rs->genpoly[0] can never be zero
2811
-			$rs['genpoly'][0] = $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][0]] + $root)];
2812
-		}
2813
-		// convert rs->genpoly[] to index form for quicker encoding
2814
-		for ($i = 0; $i <= $nroots; ++$i) {
2815
-			$rs['genpoly'][$i] = $rs['index_of'][$rs['genpoly'][$i]];
2816
-		}
2817
-		return $rs;
2818
-	}
2819
-
2820
-	/**
2821
-	 * Encode a Reed-Solomon codec and returns the parity array
2822
-	 * @param $rs (array) RS values
2823
-	 * @param $data (array) data
2824
-	 * @param $parity (array) parity
2825
-	 * @return parity array
2826
-	 */
2827
-	 protected function encode_rs_char($rs, $data, $parity) {
2828
-		$MM       =& $rs['mm']; // bits per symbol
2829
-		$NN       =& $rs['nn']; // the total number of symbols in a RS block
2830
-		$ALPHA_TO =& $rs['alpha_to']; // the address of an array of NN elements to convert Galois field elements in index (log) form to polynomial form
2831
-		$INDEX_OF =& $rs['index_of']; // the address of an array of NN elements to convert Galois field elements in polynomial form to index (log) form
2832
-		$GENPOLY  =& $rs['genpoly']; // an array of NROOTS+1 elements containing the generator polynomial in index form
2833
-		$NROOTS   =& $rs['nroots']; // the number of roots in the RS code generator polynomial, which is the same as the number of parity symbols in a block
2834
-		$FCR      =& $rs['fcr']; // first consecutive root, index form
2835
-		$PRIM     =& $rs['prim']; // primitive element, index form
2836
-		$IPRIM    =& $rs['iprim']; // prim-th root of 1, index form
2837
-		$PAD      =& $rs['pad']; // the number of pad symbols in a block
2838
-		$A0       =& $NN;
2839
-		$parity = array_fill(0, $NROOTS, 0);
2840
-		for ($i=0; $i < ($NN - $NROOTS - $PAD); $i++) {
2841
-			$feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
2842
-			if ($feedback != $A0) {
2843
-				// feedback term is non-zero
2844
-				// This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
2845
-				// always be for the polynomials constructed by init_rs()
2846
-				$feedback = $this->modnn($rs, $NN - $GENPOLY[$NROOTS] + $feedback);
2847
-				for ($j=1; $j < $NROOTS; ++$j) {
2848
-				$parity[$j] ^= $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[($NROOTS - $j)])];
2849
-				}
2850
-			}
2851
-			// Shift
2852
-			array_shift($parity);
2853
-			if ($feedback != $A0) {
2854
-				array_push($parity, $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[0])]);
2855
-			} else {
2856
-				array_push($parity, 0);
2857
-			}
2858
-		}
2859
-		return $parity;
2860
-	}
293
+    /**
294
+     * Barcode array to be returned which is readable by TCPDF.
295
+     * @protected
296
+     */
297
+    protected $barcode_array = array();
298
+
299
+    /**
300
+     * QR code version. Size of QRcode is defined as version. Version is from 1 to 40. Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases. So version 40 is 177*177 matrix.
301
+     * @protected
302
+     */
303
+    protected $version = 0;
304
+
305
+    /**
306
+     * Levels of error correction. See definitions for possible values.
307
+     * @protected
308
+     */
309
+    protected $level = QR_ECLEVEL_L;
310
+
311
+    /**
312
+     * Encoding mode.
313
+     * @protected
314
+     */
315
+    protected $hint = QR_MODE_8B;
316
+
317
+    /**
318
+     * Boolean flag, if true the input string will be converted to uppercase.
319
+     * @protected
320
+     */
321
+    protected $casesensitive = true;
322
+
323
+    /**
324
+     * Structured QR code (not supported yet).
325
+     * @protected
326
+     */
327
+    protected $structured = 0;
328
+
329
+    /**
330
+     * Mask data.
331
+     * @protected
332
+     */
333
+    protected $data;
334
+
335
+    // FrameFiller
336
+
337
+    /**
338
+     * Width.
339
+     * @protected
340
+     */
341
+    protected $width;
342
+
343
+    /**
344
+     * Frame.
345
+     * @protected
346
+     */
347
+    protected $frame;
348
+
349
+    /**
350
+     * X position of bit.
351
+     * @protected
352
+     */
353
+    protected $x;
354
+
355
+    /**
356
+     * Y position of bit.
357
+     * @protected
358
+     */
359
+    protected $y;
360
+
361
+    /**
362
+     * Direction.
363
+     * @protected
364
+     */
365
+    protected $dir;
366
+
367
+    /**
368
+     * Single bit value.
369
+     * @protected
370
+     */
371
+    protected $bit;
372
+
373
+    // ---- QRrawcode ----
374
+
375
+    /**
376
+     * Data code.
377
+     * @protected
378
+     */
379
+    protected $datacode = array();
380
+
381
+    /**
382
+     * Error correction code.
383
+     * @protected
384
+     */
385
+    protected $ecccode = array();
386
+
387
+    /**
388
+     * Blocks.
389
+     * @protected
390
+     */
391
+    protected $blocks;
392
+
393
+    /**
394
+     * Reed-Solomon blocks.
395
+     * @protected
396
+     */
397
+    protected $rsblocks = array(); //of RSblock
398
+
399
+    /**
400
+     * Counter.
401
+     * @protected
402
+     */
403
+    protected $count;
404
+
405
+    /**
406
+     * Data length.
407
+     * @protected
408
+     */
409
+    protected $dataLength;
410
+
411
+    /**
412
+     * Error correction length.
413
+     * @protected
414
+     */
415
+    protected $eccLength;
416
+
417
+    /**
418
+     * Value b1.
419
+     * @protected
420
+     */
421
+    protected $b1;
422
+
423
+    // ---- QRmask ----
424
+
425
+    /**
426
+     * Run length.
427
+     * @protected
428
+     */
429
+    protected $runLength = array();
430
+
431
+    // ---- QRsplit ----
432
+
433
+    /**
434
+     * Input data string.
435
+     * @protected
436
+     */
437
+    protected $dataStr = '';
438
+
439
+    /**
440
+     * Input items.
441
+     * @protected
442
+     */
443
+    protected $items;
444
+
445
+    // Reed-Solomon items
446
+
447
+    /**
448
+     * Reed-Solomon items.
449
+     * @protected
450
+     */
451
+    protected $rsitems = array();
452
+
453
+    /**
454
+     * Array of frames.
455
+     * @protected
456
+     */
457
+    protected $frames = array();
458
+
459
+    /**
460
+     * Alphabet-numeric convesion table.
461
+     * @protected
462
+     */
463
+    protected $anTable = array(
464
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //
465
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //
466
+        36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, //
467
+            0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 44, -1, -1, -1, -1, -1, //
468
+        -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, //
469
+        25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, //
470
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //
471
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1  //
472
+        );
473
+
474
+    /**
475
+     * Array Table of the capacity of symbols.
476
+     * See Table 1 (pp.13) and Table 12-16 (pp.30-36), JIS X0510:2004.
477
+     * @protected
478
+     */
479
+    protected $capacity = array(
480
+        array(  0,    0, 0, array(   0,    0,    0,    0)), //
481
+        array( 21,   26, 0, array(   7,   10,   13,   17)), //  1
482
+        array( 25,   44, 7, array(  10,   16,   22,   28)), //
483
+        array( 29,   70, 7, array(  15,   26,   36,   44)), //
484
+        array( 33,  100, 7, array(  20,   36,   52,   64)), //
485
+        array( 37,  134, 7, array(  26,   48,   72,   88)), //  5
486
+        array( 41,  172, 7, array(  36,   64,   96,  112)), //
487
+        array( 45,  196, 0, array(  40,   72,  108,  130)), //
488
+        array( 49,  242, 0, array(  48,   88,  132,  156)), //
489
+        array( 53,  292, 0, array(  60,  110,  160,  192)), //
490
+        array( 57,  346, 0, array(  72,  130,  192,  224)), // 10
491
+        array( 61,  404, 0, array(  80,  150,  224,  264)), //
492
+        array( 65,  466, 0, array(  96,  176,  260,  308)), //
493
+        array( 69,  532, 0, array( 104,  198,  288,  352)), //
494
+        array( 73,  581, 3, array( 120,  216,  320,  384)), //
495
+        array( 77,  655, 3, array( 132,  240,  360,  432)), // 15
496
+        array( 81,  733, 3, array( 144,  280,  408,  480)), //
497
+        array( 85,  815, 3, array( 168,  308,  448,  532)), //
498
+        array( 89,  901, 3, array( 180,  338,  504,  588)), //
499
+        array( 93,  991, 3, array( 196,  364,  546,  650)), //
500
+        array( 97, 1085, 3, array( 224,  416,  600,  700)), // 20
501
+        array(101, 1156, 4, array( 224,  442,  644,  750)), //
502
+        array(105, 1258, 4, array( 252,  476,  690,  816)), //
503
+        array(109, 1364, 4, array( 270,  504,  750,  900)), //
504
+        array(113, 1474, 4, array( 300,  560,  810,  960)), //
505
+        array(117, 1588, 4, array( 312,  588,  870, 1050)), // 25
506
+        array(121, 1706, 4, array( 336,  644,  952, 1110)), //
507
+        array(125, 1828, 4, array( 360,  700, 1020, 1200)), //
508
+        array(129, 1921, 3, array( 390,  728, 1050, 1260)), //
509
+        array(133, 2051, 3, array( 420,  784, 1140, 1350)), //
510
+        array(137, 2185, 3, array( 450,  812, 1200, 1440)), // 30
511
+        array(141, 2323, 3, array( 480,  868, 1290, 1530)), //
512
+        array(145, 2465, 3, array( 510,  924, 1350, 1620)), //
513
+        array(149, 2611, 3, array( 540,  980, 1440, 1710)), //
514
+        array(153, 2761, 3, array( 570, 1036, 1530, 1800)), //
515
+        array(157, 2876, 0, array( 570, 1064, 1590, 1890)), // 35
516
+        array(161, 3034, 0, array( 600, 1120, 1680, 1980)), //
517
+        array(165, 3196, 0, array( 630, 1204, 1770, 2100)), //
518
+        array(169, 3362, 0, array( 660, 1260, 1860, 2220)), //
519
+        array(173, 3532, 0, array( 720, 1316, 1950, 2310)), //
520
+        array(177, 3706, 0, array( 750, 1372, 2040, 2430))  // 40
521
+    );
522
+
523
+    /**
524
+     * Array Length indicator.
525
+     * @protected
526
+     */
527
+    protected $lengthTableBits = array(
528
+        array(10, 12, 14),
529
+        array( 9, 11, 13),
530
+        array( 8, 16, 16),
531
+        array( 8, 10, 12)
532
+    );
533
+
534
+    /**
535
+     * Array Table of the error correction code (Reed-Solomon block).
536
+     * See Table 12-16 (pp.30-36), JIS X0510:2004.
537
+     * @protected
538
+     */
539
+    protected $eccTable = array(
540
+        array(array( 0,  0), array( 0,  0), array( 0,  0), array( 0,  0)), //
541
+        array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)), //  1
542
+        array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)), //
543
+        array(array( 1,  0), array( 1,  0), array( 2,  0), array( 2,  0)), //
544
+        array(array( 1,  0), array( 2,  0), array( 2,  0), array( 4,  0)), //
545
+        array(array( 1,  0), array( 2,  0), array( 2,  2), array( 2,  2)), //  5
546
+        array(array( 2,  0), array( 4,  0), array( 4,  0), array( 4,  0)), //
547
+        array(array( 2,  0), array( 4,  0), array( 2,  4), array( 4,  1)), //
548
+        array(array( 2,  0), array( 2,  2), array( 4,  2), array( 4,  2)), //
549
+        array(array( 2,  0), array( 3,  2), array( 4,  4), array( 4,  4)), //
550
+        array(array( 2,  2), array( 4,  1), array( 6,  2), array( 6,  2)), // 10
551
+        array(array( 4,  0), array( 1,  4), array( 4,  4), array( 3,  8)), //
552
+        array(array( 2,  2), array( 6,  2), array( 4,  6), array( 7,  4)), //
553
+        array(array( 4,  0), array( 8,  1), array( 8,  4), array(12,  4)), //
554
+        array(array( 3,  1), array( 4,  5), array(11,  5), array(11,  5)), //
555
+        array(array( 5,  1), array( 5,  5), array( 5,  7), array(11,  7)), // 15
556
+        array(array( 5,  1), array( 7,  3), array(15,  2), array( 3, 13)), //
557
+        array(array( 1,  5), array(10,  1), array( 1, 15), array( 2, 17)), //
558
+        array(array( 5,  1), array( 9,  4), array(17,  1), array( 2, 19)), //
559
+        array(array( 3,  4), array( 3, 11), array(17,  4), array( 9, 16)), //
560
+        array(array( 3,  5), array( 3, 13), array(15,  5), array(15, 10)), // 20
561
+        array(array( 4,  4), array(17,  0), array(17,  6), array(19,  6)), //
562
+        array(array( 2,  7), array(17,  0), array( 7, 16), array(34,  0)), //
563
+        array(array( 4,  5), array( 4, 14), array(11, 14), array(16, 14)), //
564
+        array(array( 6,  4), array( 6, 14), array(11, 16), array(30,  2)), //
565
+        array(array( 8,  4), array( 8, 13), array( 7, 22), array(22, 13)), // 25
566
+        array(array(10,  2), array(19,  4), array(28,  6), array(33,  4)), //
567
+        array(array( 8,  4), array(22,  3), array( 8, 26), array(12, 28)), //
568
+        array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), //
569
+        array(array( 7,  7), array(21,  7), array( 1, 37), array(19, 26)), //
570
+        array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), // 30
571
+        array(array(13,  3), array( 2, 29), array(42,  1), array(23, 28)), //
572
+        array(array(17,  0), array(10, 23), array(10, 35), array(19, 35)), //
573
+        array(array(17,  1), array(14, 21), array(29, 19), array(11, 46)), //
574
+        array(array(13,  6), array(14, 23), array(44,  7), array(59,  1)), //
575
+        array(array(12,  7), array(12, 26), array(39, 14), array(22, 41)), // 35
576
+        array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), //
577
+        array(array(17,  4), array(29, 14), array(49, 10), array(24, 46)), //
578
+        array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), //
579
+        array(array(20,  4), array(40,  7), array(43, 22), array(10, 67)), //
580
+        array(array(19,  6), array(18, 31), array(34, 34), array(20, 61))  // 40
581
+    );
582
+
583
+    /**
584
+     * Array Positions of alignment patterns.
585
+     * This array includes only the second and the third position of the alignment patterns. Rest of them can be calculated from the distance between them.
586
+     * See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
587
+     * @protected
588
+     */
589
+    protected $alignmentPattern = array(
590
+        array( 0,  0),
591
+        array( 0,  0), array(18,  0), array(22,  0), array(26,  0), array(30,  0), //  1- 5
592
+        array(34,  0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), //  6-10
593
+        array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), // 11-15
594
+        array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), // 16-20
595
+        array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), // 21-25
596
+        array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), // 26-30
597
+        array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), // 31-35
598
+        array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58)  // 35-40
599
+    );
600
+
601
+    /**
602
+     * Array Version information pattern (BCH coded).
603
+     * See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
604
+     * size: [QRSPEC_VERSION_MAX - 6]
605
+     * @protected
606
+     */
607
+    protected $versionPattern = array(
608
+        0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, //
609
+        0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9, //
610
+        0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75, //
611
+        0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64, //
612
+        0x27541, 0x28c69
613
+    );
614
+
615
+    /**
616
+     * Array Format information
617
+     * @protected
618
+     */
619
+    protected $formatInfo = array(
620
+        array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976), //
621
+        array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0), //
622
+        array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed), //
623
+        array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b)  //
624
+    );
625
+
626
+
627
+    // -------------------------------------------------
628
+    // -------------------------------------------------
629
+
630
+
631
+    /**
632
+     * This is the class constructor.
633
+     * Creates a QRcode object
634
+     * @param $code (string) code to represent using QRcode
635
+     * @param $eclevel (string) error level: <ul><li>L : About 7% or less errors can be corrected.</li><li>M : About 15% or less errors can be corrected.</li><li>Q : About 25% or less errors can be corrected.</li><li>H : About 30% or less errors can be corrected.</li></ul>
636
+     * @public
637
+     * @since 1.0.000
638
+     */
639
+    public function __construct($code, $eclevel = 'L') {
640
+        $barcode_array = array();
641
+        if ((is_null($code)) OR ($code == '\0') OR ($code == '')) {
642
+            return false;
643
+        }
644
+        // set error correction level
645
+        $this->level = array_search($eclevel, array('L', 'M', 'Q', 'H'));
646
+        if ($this->level === false) {
647
+            $this->level = QR_ECLEVEL_L;
648
+        }
649
+        if (($this->hint != QR_MODE_8B) AND ($this->hint != QR_MODE_KJ)) {
650
+            return false;
651
+        }
652
+        if (($this->version < 0) OR ($this->version > QRSPEC_VERSION_MAX)) {
653
+            return false;
654
+        }
655
+        $this->items = array();
656
+        $this->encodeString($code);
657
+        if (is_null($this->data)) {
658
+            return false;
659
+        }
660
+        $qrTab = $this->binarize($this->data);
661
+        $size = count($qrTab);
662
+        $barcode_array['num_rows'] = $size;
663
+        $barcode_array['num_cols'] = $size;
664
+        $barcode_array['bcode'] = array();
665
+        foreach ($qrTab as $line) {
666
+            $arrAdd = array();
667
+            foreach (str_split($line) as $char) {
668
+                $arrAdd[] = ($char=='1')?1:0;
669
+            }
670
+            $barcode_array['bcode'][] = $arrAdd;
671
+        }
672
+        $this->barcode_array = $barcode_array;
673
+    }
674
+
675
+    /**
676
+     * Returns a barcode array which is readable by TCPDF
677
+     * @return array barcode array readable by TCPDF;
678
+     * @public
679
+     */
680
+    public function getBarcodeArray() {
681
+        return $this->barcode_array;
682
+    }
683
+
684
+    /**
685
+     * Convert the frame in binary form
686
+     * @param $frame (array) array to binarize
687
+     * @return array frame in binary form
688
+     */
689
+    protected function binarize($frame) {
690
+        $len = count($frame);
691
+        // the frame is square (width = height)
692
+        foreach ($frame as &$frameLine) {
693
+            for ($i=0; $i<$len; $i++) {
694
+                $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
695
+            }
696
+        }
697
+        return $frame;
698
+    }
699
+
700
+    /**
701
+     * Encode the input string to QR code
702
+     * @param $string (string) input string to encode
703
+     */
704
+    protected function encodeString($string) {
705
+        $this->dataStr = $string;
706
+        if (!$this->casesensitive) {
707
+            $this->toUpper();
708
+        }
709
+        $ret = $this->splitString();
710
+        if ($ret < 0) {
711
+            return NULL;
712
+        }
713
+        $this->encodeMask(-1);
714
+    }
715
+
716
+    /**
717
+     * Encode mask
718
+     * @param $mask (int) masking mode
719
+     */
720
+    protected function encodeMask($mask) {
721
+        $spec = array(0, 0, 0, 0, 0);
722
+        $this->datacode = $this->getByteStream($this->items);
723
+        if (is_null($this->datacode)) {
724
+            return NULL;
725
+        }
726
+        $spec = $this->getEccSpec($this->version, $this->level, $spec);
727
+        $this->b1 = $this->rsBlockNum1($spec);
728
+        $this->dataLength = $this->rsDataLength($spec);
729
+        $this->eccLength = $this->rsEccLength($spec);
730
+        $this->ecccode = array_fill(0, $this->eccLength, 0);
731
+        $this->blocks = $this->rsBlockNum($spec);
732
+        $ret = $this->init($spec);
733
+        if ($ret < 0) {
734
+            return NULL;
735
+        }
736
+        $this->count = 0;
737
+        $this->width = $this->getWidth($this->version);
738
+        $this->frame = $this->newFrame($this->version);
739
+        $this->x = $this->width - 1;
740
+        $this->y = $this->width - 1;
741
+        $this->dir = -1;
742
+        $this->bit = -1;
743
+        // inteleaved data and ecc codes
744
+        for ($i=0; $i < ($this->dataLength + $this->eccLength); $i++) {
745
+            $code = $this->getCode();
746
+            $bit = 0x80;
747
+            for ($j=0; $j<8; $j++) {
748
+                $addr = $this->getNextPosition();
749
+                $this->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
750
+                $bit = $bit >> 1;
751
+            }
752
+        }
753
+        // remainder bits
754
+        $j = $this->getRemainder($this->version);
755
+        for ($i=0; $i<$j; $i++) {
756
+            $addr = $this->getNextPosition();
757
+            $this->setFrameAt($addr, 0x02);
758
+        }
759
+        // masking
760
+        $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
761
+        if ($mask < 0) {
762
+            if (QR_FIND_BEST_MASK) {
763
+                $masked = $this->mask($this->width, $this->frame, $this->level);
764
+            } else {
765
+                $masked = $this->makeMask($this->width, $this->frame, (intval(QR_DEFAULT_MASK) % 8), $this->level);
766
+            }
767
+        } else {
768
+            $masked = $this->makeMask($this->width, $this->frame, $mask, $this->level);
769
+        }
770
+        if ($masked == NULL) {
771
+            return NULL;
772
+        }
773
+        $this->data = $masked;
774
+    }
775
+
776
+    // - - - - - - - - - - - - - - - - - - - - - - - - -
777
+
778
+    // FrameFiller
779
+
780
+    /**
781
+     * Set frame value at specified position
782
+     * @param $at (array) x,y position
783
+     * @param $val (int) value of the character to set
784
+     */
785
+    protected function setFrameAt($at, $val) {
786
+        $this->frame[$at['y']][$at['x']] = chr($val);
787
+    }
788
+
789
+    /**
790
+     * Get frame value at specified position
791
+     * @param $at (array) x,y position
792
+     * @return value at specified position
793
+     */
794
+    protected function getFrameAt($at) {
795
+        return ord($this->frame[$at['y']][$at['x']]);
796
+    }
797
+
798
+    /**
799
+     * Return the next frame position
800
+     * @return array of x,y coordinates
801
+     */
802
+    protected function getNextPosition() {
803
+        do {
804
+            if ($this->bit == -1) {
805
+                $this->bit = 0;
806
+                return array('x'=>$this->x, 'y'=>$this->y);
807
+            }
808
+            $x = $this->x;
809
+            $y = $this->y;
810
+            $w = $this->width;
811
+            if ($this->bit == 0) {
812
+                $x--;
813
+                $this->bit++;
814
+            } else {
815
+                $x++;
816
+                $y += $this->dir;
817
+                $this->bit--;
818
+            }
819
+            if ($this->dir < 0) {
820
+                if ($y < 0) {
821
+                    $y = 0;
822
+                    $x -= 2;
823
+                    $this->dir = 1;
824
+                    if ($x == 6) {
825
+                        $x--;
826
+                        $y = 9;
827
+                    }
828
+                }
829
+            } else {
830
+                if ($y == $w) {
831
+                    $y = $w - 1;
832
+                    $x -= 2;
833
+                    $this->dir = -1;
834
+                    if ($x == 6) {
835
+                        $x--;
836
+                        $y -= 8;
837
+                    }
838
+                }
839
+            }
840
+            if (($x < 0) OR ($y < 0)) {
841
+                return NULL;
842
+            }
843
+            $this->x = $x;
844
+            $this->y = $y;
845
+        } while(ord($this->frame[$y][$x]) & 0x80);
846
+        return array('x'=>$x, 'y'=>$y);
847
+    }
848
+
849
+    // - - - - - - - - - - - - - - - - - - - - - - - - -
850
+
851
+    // QRrawcode
852
+
853
+    /**
854
+     * Initialize code.
855
+     * @param $spec (array) array of ECC specification
856
+     * @return 0 in case of success, -1 in case of error
857
+     */
858
+    protected function init($spec) {
859
+        $dl = $this->rsDataCodes1($spec);
860
+        $el = $this->rsEccCodes1($spec);
861
+        $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
862
+        $blockNo = 0;
863
+        $dataPos = 0;
864
+        $eccPos = 0;
865
+        $endfor = $this->rsBlockNum1($spec);
866
+        for ($i=0; $i < $endfor; ++$i) {
867
+            $ecc = array_slice($this->ecccode, $eccPos);
868
+            $this->rsblocks[$blockNo] = array();
869
+            $this->rsblocks[$blockNo]['dataLength'] = $dl;
870
+            $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos);
871
+            $this->rsblocks[$blockNo]['eccLength'] = $el;
872
+            $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc);
873
+            $this->rsblocks[$blockNo]['ecc'] = $ecc;
874
+            $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
875
+            $dataPos += $dl;
876
+            $eccPos += $el;
877
+            $blockNo++;
878
+        }
879
+        if ($this->rsBlockNum2($spec) == 0) {
880
+            return 0;
881
+        }
882
+        $dl = $this->rsDataCodes2($spec);
883
+        $el = $this->rsEccCodes2($spec);
884
+        $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
885
+        if ($rs == NULL) {
886
+            return -1;
887
+        }
888
+        $endfor = $this->rsBlockNum2($spec);
889
+        for ($i=0; $i < $endfor; ++$i) {
890
+            $ecc = array_slice($this->ecccode, $eccPos);
891
+            $this->rsblocks[$blockNo] = array();
892
+            $this->rsblocks[$blockNo]['dataLength'] = $dl;
893
+            $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos);
894
+            $this->rsblocks[$blockNo]['eccLength'] = $el;
895
+            $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc);
896
+            $this->rsblocks[$blockNo]['ecc'] = $ecc;
897
+            $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc);
898
+            $dataPos += $dl;
899
+            $eccPos += $el;
900
+            $blockNo++;
901
+        }
902
+        return 0;
903
+    }
904
+
905
+    /**
906
+     * Return Reed-Solomon block code.
907
+     * @return array rsblocks
908
+     */
909
+    protected function getCode() {
910
+        if ($this->count < $this->dataLength) {
911
+            $row = $this->count % $this->blocks;
912
+            $col = $this->count / $this->blocks;
913
+            if ($col >= $this->rsblocks[0]['dataLength']) {
914
+                $row += $this->b1;
915
+            }
916
+            $ret = $this->rsblocks[$row]['data'][$col];
917
+        } elseif ($this->count < $this->dataLength + $this->eccLength) {
918
+            $row = ($this->count - $this->dataLength) % $this->blocks;
919
+            $col = ($this->count - $this->dataLength) / $this->blocks;
920
+            $ret = $this->rsblocks[$row]['ecc'][$col];
921
+        } else {
922
+            return 0;
923
+        }
924
+        $this->count++;
925
+        return $ret;
926
+    }
927
+
928
+    // - - - - - - - - - - - - - - - - - - - - - - - - -
929
+
930
+    // QRmask
931
+
932
+    /**
933
+     * Write Format Information on frame and returns the number of black bits
934
+     * @param $width (int) frame width
935
+     * @param $frame (array) frame
936
+     * @param $mask (array) masking mode
937
+     * @param $level (int) error correction level
938
+     * @return int blacks
939
+     */
940
+        protected function writeFormatInformation($width, &$frame, $mask, $level) {
941
+        $blacks = 0;
942
+        $format =  $this->getFormatInfo($mask, $level);
943
+        for ($i=0; $i<8; ++$i) {
944
+            if ($format & 1) {
945
+                $blacks += 2;
946
+                $v = 0x85;
947
+            } else {
948
+                $v = 0x84;
949
+            }
950
+            $frame[8][$width - 1 - $i] = chr($v);
951
+            if ($i < 6) {
952
+                $frame[$i][8] = chr($v);
953
+            } else {
954
+                $frame[$i + 1][8] = chr($v);
955
+            }
956
+            $format = $format >> 1;
957
+        }
958
+        for ($i=0; $i<7; ++$i) {
959
+        if ($format & 1) {
960
+            $blacks += 2;
961
+            $v = 0x85;
962
+        } else {
963
+            $v = 0x84;
964
+        }
965
+        $frame[$width - 7 + $i][8] = chr($v);
966
+        if ($i == 0) {
967
+            $frame[8][7] = chr($v);
968
+        } else {
969
+            $frame[8][6 - $i] = chr($v);
970
+        }
971
+        $format = $format >> 1;
972
+        }
973
+        return $blacks;
974
+    }
975
+
976
+    /**
977
+     * mask0
978
+     * @param $x (int) X position
979
+     * @param $y (int) Y position
980
+     * @return int mask
981
+     */
982
+        protected function mask0($x, $y) {
983
+        return ($x + $y) & 1;
984
+    }
985
+
986
+    /**
987
+     * mask1
988
+     * @param $x (int) X position
989
+     * @param $y (int) Y position
990
+     * @return int mask
991
+     */
992
+        protected function mask1($x, $y) {
993
+        return ($y & 1);
994
+    }
995
+
996
+    /**
997
+     * mask2
998
+     * @param $x (int) X position
999
+     * @param $y (int) Y position
1000
+     * @return int mask
1001
+     */
1002
+        protected function mask2($x, $y) {
1003
+        return ($x % 3);
1004
+    }
1005
+
1006
+    /**
1007
+     * mask3
1008
+     * @param $x (int) X position
1009
+     * @param $y (int) Y position
1010
+     * @return int mask
1011
+     */
1012
+        protected function mask3($x, $y) {
1013
+        return ($x + $y) % 3;
1014
+    }
1015
+
1016
+    /**
1017
+     * mask4
1018
+     * @param $x (int) X position
1019
+     * @param $y (int) Y position
1020
+     * @return int mask
1021
+     */
1022
+        protected function mask4($x, $y) {
1023
+        return (((int)($y / 2)) + ((int)($x / 3))) & 1;
1024
+    }
1025
+
1026
+    /**
1027
+     * mask5
1028
+     * @param $x (int) X position
1029
+     * @param $y (int) Y position
1030
+     * @return int mask
1031
+     */
1032
+        protected function mask5($x, $y) {
1033
+        return (($x * $y) & 1) + ($x * $y) % 3;
1034
+    }
1035
+
1036
+    /**
1037
+     * mask6
1038
+     * @param $x (int) X position
1039
+     * @param $y (int) Y position
1040
+     * @return int mask
1041
+     */
1042
+        protected function mask6($x, $y) {
1043
+        return ((($x * $y) & 1) + ($x * $y) % 3) & 1;
1044
+    }
1045
+
1046
+    /**
1047
+     * mask7
1048
+     * @param $x (int) X position
1049
+     * @param $y (int) Y position
1050
+     * @return int mask
1051
+     */
1052
+        protected function mask7($x, $y) {
1053
+        return ((($x * $y) % 3) + (($x + $y) & 1)) & 1;
1054
+    }
1055
+
1056
+    /**
1057
+     * Return bitmask
1058
+     * @param $maskNo (int) mask number
1059
+     * @param $width (int) width
1060
+     * @param $frame (array) frame
1061
+     * @return array bitmask
1062
+     */
1063
+    protected function generateMaskNo($maskNo, $width, $frame) {
1064
+        $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
1065
+        for ($y=0; $y<$width; ++$y) {
1066
+            for ($x=0; $x<$width; ++$x) {
1067
+                if (ord($frame[$y][$x]) & 0x80) {
1068
+                    $bitMask[$y][$x] = 0;
1069
+                } else {
1070
+                    $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
1071
+                    $bitMask[$y][$x] = ($maskFunc == 0)?1:0;
1072
+                }
1073
+            }
1074
+        }
1075
+        return $bitMask;
1076
+    }
1077
+
1078
+    /**
1079
+     * makeMaskNo
1080
+     * @param $maskNo (int)
1081
+     * @param $width (int)
1082
+     * @param $s (int)
1083
+     * @param $d (int)
1084
+     * @param $maskGenOnly (boolean)
1085
+     * @return int b
1086
+     */
1087
+        protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false) {
1088
+        $b = 0;
1089
+        $bitMask = array();
1090
+        $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
1091
+        if ($maskGenOnly) {
1092
+            return;
1093
+        }
1094
+        $d = $s;
1095
+        for ($y=0; $y<$width; ++$y) {
1096
+            for ($x=0; $x<$width; ++$x) {
1097
+                if ($bitMask[$y][$x] == 1) {
1098
+                    $d[$y][$x] = chr(ord($s[$y][$x]) ^ ((int)($bitMask[$y][$x])));
1099
+                }
1100
+                $b += (int)(ord($d[$y][$x]) & 1);
1101
+            }
1102
+        }
1103
+        return $b;
1104
+    }
1105
+
1106
+    /**
1107
+     * makeMask
1108
+     * @param $width (int)
1109
+     * @param $frame (array)
1110
+     * @param $maskNo (int)
1111
+     * @param $level (int)
1112
+     * @return array mask
1113
+     */
1114
+        protected function makeMask($width, $frame, $maskNo, $level) {
1115
+        $masked = array_fill(0, $width, str_repeat("\0", $width));
1116
+        $this->makeMaskNo($maskNo, $width, $frame, $masked);
1117
+        $this->writeFormatInformation($width, $masked, $maskNo, $level);
1118
+        return $masked;
1119
+    }
1120
+
1121
+    /**
1122
+     * calcN1N3
1123
+     * @param $length (int)
1124
+     * @return int demerit
1125
+     */
1126
+        protected function calcN1N3($length) {
1127
+        $demerit = 0;
1128
+        for ($i=0; $i<$length; ++$i) {
1129
+            if ($this->runLength[$i] >= 5) {
1130
+                $demerit += (N1 + ($this->runLength[$i] - 5));
1131
+            }
1132
+            if ($i & 1) {
1133
+                if (($i >= 3) AND ($i < ($length-2)) AND ($this->runLength[$i] % 3 == 0)) {
1134
+                    $fact = (int)($this->runLength[$i] / 3);
1135
+                    if (($this->runLength[$i-2] == $fact)
1136
+                        AND ($this->runLength[$i-1] == $fact)
1137
+                        AND ($this->runLength[$i+1] == $fact)
1138
+                        AND ($this->runLength[$i+2] == $fact)) {
1139
+                        if (($this->runLength[$i-3] < 0) OR ($this->runLength[$i-3] >= (4 * $fact))) {
1140
+                            $demerit += N3;
1141
+                        } elseif ((($i+3) >= $length) OR ($this->runLength[$i+3] >= (4 * $fact))) {
1142
+                            $demerit += N3;
1143
+                        }
1144
+                    }
1145
+                }
1146
+            }
1147
+        }
1148
+        return $demerit;
1149
+    }
1150
+
1151
+    /**
1152
+     * evaluateSymbol
1153
+     * @param $width (int)
1154
+     * @param $frame (array)
1155
+     * @return int demerit
1156
+     */
1157
+        protected function evaluateSymbol($width, $frame) {
1158
+        $head = 0;
1159
+        $demerit = 0;
1160
+        for ($y=0; $y<$width; ++$y) {
1161
+            $head = 0;
1162
+            $this->runLength[0] = 1;
1163
+            $frameY = $frame[$y];
1164
+            if ($y > 0) {
1165
+                $frameYM = $frame[$y-1];
1166
+            }
1167
+            for ($x=0; $x<$width; ++$x) {
1168
+                if (($x > 0) AND ($y > 0)) {
1169
+                    $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
1170
+                    $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
1171
+                    if (($b22 | ($w22 ^ 1)) & 1) {
1172
+                        $demerit += N2;
1173
+                    }
1174
+                }
1175
+                if (($x == 0) AND (ord($frameY[$x]) & 1)) {
1176
+                    $this->runLength[0] = -1;
1177
+                    $head = 1;
1178
+                    $this->runLength[$head] = 1;
1179
+                } elseif ($x > 0) {
1180
+                    if ((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
1181
+                        $head++;
1182
+                        $this->runLength[$head] = 1;
1183
+                    } else {
1184
+                        $this->runLength[$head]++;
1185
+                    }
1186
+                }
1187
+            }
1188
+            $demerit += $this->calcN1N3($head+1);
1189
+        }
1190
+        for ($x=0; $x<$width; ++$x) {
1191
+            $head = 0;
1192
+            $this->runLength[0] = 1;
1193
+            for ($y=0; $y<$width; ++$y) {
1194
+                if (($y == 0) AND (ord($frame[$y][$x]) & 1)) {
1195
+                    $this->runLength[0] = -1;
1196
+                    $head = 1;
1197
+                    $this->runLength[$head] = 1;
1198
+                } elseif ($y > 0) {
1199
+                    if ((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
1200
+                        $head++;
1201
+                        $this->runLength[$head] = 1;
1202
+                    } else {
1203
+                        $this->runLength[$head]++;
1204
+                    }
1205
+                }
1206
+            }
1207
+            $demerit += $this->calcN1N3($head+1);
1208
+        }
1209
+        return $demerit;
1210
+    }
1211
+
1212
+    /**
1213
+     * mask
1214
+     * @param $width (int)
1215
+     * @param $frame (array)
1216
+     * @param $level (int)
1217
+     * @return array best mask
1218
+     */
1219
+        protected function mask($width, $frame, $level) {
1220
+        $minDemerit = PHP_INT_MAX;
1221
+        $bestMaskNum = 0;
1222
+        $bestMask = array();
1223
+        $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7);
1224
+        if (QR_FIND_FROM_RANDOM !== false) {
1225
+            $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9);
1226
+            for ($i = 0; $i <  $howManuOut; ++$i) {
1227
+                $remPos = rand (0, count($checked_masks)-1);
1228
+                unset($checked_masks[$remPos]);
1229
+                $checked_masks = array_values($checked_masks);
1230
+            }
1231
+        }
1232
+        $bestMask = $frame;
1233
+        foreach ($checked_masks as $i) {
1234
+            $mask = array_fill(0, $width, str_repeat("\0", $width));
1235
+            $demerit = 0;
1236
+            $blacks = 0;
1237
+            $blacks  = $this->makeMaskNo($i, $width, $frame, $mask);
1238
+            $blacks += $this->writeFormatInformation($width, $mask, $i, $level);
1239
+            $blacks  = (int)(100 * $blacks / ($width * $width));
1240
+            $demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
1241
+            $demerit += $this->evaluateSymbol($width, $mask);
1242
+            if ($demerit < $minDemerit) {
1243
+                $minDemerit = $demerit;
1244
+                $bestMask = $mask;
1245
+                $bestMaskNum = $i;
1246
+            }
1247
+        }
1248
+        return $bestMask;
1249
+    }
1250
+
1251
+    // - - - - - - - - - - - - - - - - - - - - - - - - -
1252
+
1253
+    // QRsplit
1254
+
1255
+    /**
1256
+     * Return true if the character at specified position is a number
1257
+     * @param $str (string) string
1258
+     * @param $pos (int) characted position
1259
+     * @return boolean true of false
1260
+     */
1261
+        protected function isdigitat($str, $pos) {
1262
+        if ($pos >= strlen($str)) {
1263
+            return false;
1264
+        }
1265
+        return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
1266
+    }
1267
+
1268
+    /**
1269
+     * Return true if the character at specified position is an alphanumeric character
1270
+     * @param $str (string) string
1271
+     * @param $pos (int) characted position
1272
+     * @return boolean true of false
1273
+     */
1274
+        protected function isalnumat($str, $pos) {
1275
+        if ($pos >= strlen($str)) {
1276
+            return false;
1277
+        }
1278
+        return ($this->lookAnTable(ord($str[$pos])) >= 0);
1279
+    }
1280
+
1281
+    /**
1282
+     * identifyMode
1283
+     * @param $pos (int)
1284
+     * @return int mode
1285
+     */
1286
+        protected function identifyMode($pos) {
1287
+        if ($pos >= strlen($this->dataStr)) {
1288
+            return QR_MODE_NL;
1289
+        }
1290
+        $c = $this->dataStr[$pos];
1291
+        if ($this->isdigitat($this->dataStr, $pos)) {
1292
+            return QR_MODE_NM;
1293
+        } elseif ($this->isalnumat($this->dataStr, $pos)) {
1294
+            return QR_MODE_AN;
1295
+        } elseif ($this->hint == QR_MODE_KJ) {
1296
+            if ($pos+1 < strlen($this->dataStr)) {
1297
+                $d = $this->dataStr[$pos+1];
1298
+                $word = (ord($c) << 8) | ord($d);
1299
+                if (($word >= 0x8140 && $word <= 0x9ffc) OR ($word >= 0xe040 && $word <= 0xebbf)) {
1300
+                    return QR_MODE_KJ;
1301
+                }
1302
+            }
1303
+        }
1304
+        return QR_MODE_8B;
1305
+    }
1306
+
1307
+    /**
1308
+     * eatNum
1309
+     * @return int run
1310
+     */
1311
+        protected function eatNum() {
1312
+        $ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
1313
+        $p = 0;
1314
+        while($this->isdigitat($this->dataStr, $p)) {
1315
+            $p++;
1316
+        }
1317
+        $run = $p;
1318
+        $mode = $this->identifyMode($p);
1319
+        if ($mode == QR_MODE_8B) {
1320
+            $dif = $this->estimateBitsModeNum($run) + 4 + $ln
1321
+            + $this->estimateBitsMode8(1)         // + 4 + l8
1322
+            - $this->estimateBitsMode8($run + 1); // - 4 - l8
1323
+            if ($dif > 0) {
1324
+                return $this->eat8();
1325
+            }
1326
+        }
1327
+        if ($mode == QR_MODE_AN) {
1328
+            $dif = $this->estimateBitsModeNum($run) + 4 + $ln
1329
+            + $this->estimateBitsModeAn(1)        // + 4 + la
1330
+            - $this->estimateBitsModeAn($run + 1);// - 4 - la
1331
+            if ($dif > 0) {
1332
+                return $this->eatAn();
1333
+            }
1334
+        }
1335
+        $this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, str_split($this->dataStr));
1336
+        return $run;
1337
+    }
1338
+
1339
+    /**
1340
+     * eatAn
1341
+     * @return int run
1342
+     */
1343
+        protected function eatAn() {
1344
+        $la = $this->lengthIndicator(QR_MODE_AN,  $this->version);
1345
+        $ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
1346
+        $p =1 ;
1347
+        while($this->isalnumat($this->dataStr, $p)) {
1348
+            if ($this->isdigitat($this->dataStr, $p)) {
1349
+                $q = $p;
1350
+                while($this->isdigitat($this->dataStr, $q)) {
1351
+                    $q++;
1352
+                }
1353
+                $dif = $this->estimateBitsModeAn($p) // + 4 + la
1354
+                + $this->estimateBitsModeNum($q - $p) + 4 + $ln
1355
+                - $this->estimateBitsModeAn($q); // - 4 - la
1356
+                if ($dif < 0) {
1357
+                    break;
1358
+                } else {
1359
+                    $p = $q;
1360
+                }
1361
+            } else {
1362
+                $p++;
1363
+            }
1364
+        }
1365
+        $run = $p;
1366
+        if (!$this->isalnumat($this->dataStr, $p)) {
1367
+            $dif = $this->estimateBitsModeAn($run) + 4 + $la
1368
+            + $this->estimateBitsMode8(1) // + 4 + l8
1369
+            - $this->estimateBitsMode8($run + 1); // - 4 - l8
1370
+            if ($dif > 0) {
1371
+                return $this->eat8();
1372
+            }
1373
+        }
1374
+        $this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, str_split($this->dataStr));
1375
+        return $run;
1376
+    }
1377
+
1378
+    /**
1379
+     * eatKanji
1380
+     * @return int run
1381
+     */
1382
+        protected function eatKanji() {
1383
+        $p = 0;
1384
+        while($this->identifyMode($p) == QR_MODE_KJ) {
1385
+            $p += 2;
1386
+        }
1387
+        $this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, str_split($this->dataStr));
1388
+        return $run;
1389
+    }
1390
+
1391
+    /**
1392
+     * eat8
1393
+     * @return int run
1394
+     */
1395
+        protected function eat8() {
1396
+        $la = $this->lengthIndicator(QR_MODE_AN, $this->version);
1397
+        $ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
1398
+        $p = 1;
1399
+        $dataStrLen = strlen($this->dataStr);
1400
+        while($p < $dataStrLen) {
1401
+            $mode = $this->identifyMode($p);
1402
+            if ($mode == QR_MODE_KJ) {
1403
+                break;
1404
+            }
1405
+            if ($mode == QR_MODE_NM) {
1406
+                $q = $p;
1407
+                while($this->isdigitat($this->dataStr, $q)) {
1408
+                    $q++;
1409
+                }
1410
+                $dif = $this->estimateBitsMode8($p) // + 4 + l8
1411
+                + $this->estimateBitsModeNum($q - $p) + 4 + $ln
1412
+                - $this->estimateBitsMode8($q); // - 4 - l8
1413
+                if ($dif < 0) {
1414
+                    break;
1415
+                } else {
1416
+                    $p = $q;
1417
+                }
1418
+            } elseif ($mode == QR_MODE_AN) {
1419
+                $q = $p;
1420
+                while($this->isalnumat($this->dataStr, $q)) {
1421
+                    $q++;
1422
+                }
1423
+                $dif = $this->estimateBitsMode8($p)  // + 4 + l8
1424
+                + $this->estimateBitsModeAn($q - $p) + 4 + $la
1425
+                - $this->estimateBitsMode8($q); // - 4 - l8
1426
+                if ($dif < 0) {
1427
+                    break;
1428
+                } else {
1429
+                    $p = $q;
1430
+                }
1431
+            } else {
1432
+                $p++;
1433
+            }
1434
+        }
1435
+        $run = $p;
1436
+        $this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, str_split($this->dataStr));
1437
+        return $run;
1438
+    }
1439
+
1440
+    /**
1441
+     * splitString
1442
+     * @return (int)
1443
+     */
1444
+        protected function splitString() {
1445
+        while (strlen($this->dataStr) > 0) {
1446
+            $mode = $this->identifyMode(0);
1447
+            switch ($mode) {
1448
+                case QR_MODE_NM: {
1449
+                    $length = $this->eatNum();
1450
+                    break;
1451
+                }
1452
+                case QR_MODE_AN: {
1453
+                    $length = $this->eatAn();
1454
+                    break;
1455
+                }
1456
+                case QR_MODE_KJ: {
1457
+                    if ($hint == QR_MODE_KJ) {
1458
+                        $length = $this->eatKanji();
1459
+                    } else {
1460
+                        $length = $this->eat8();
1461
+                    }
1462
+                    break;
1463
+                }
1464
+                default: {
1465
+                    $length = $this->eat8();
1466
+                    break;
1467
+                }
1468
+            }
1469
+            if ($length == 0) {
1470
+                return 0;
1471
+            }
1472
+            if ($length < 0) {
1473
+                return -1;
1474
+            }
1475
+            $this->dataStr = substr($this->dataStr, $length);
1476
+        }
1477
+        return 0;
1478
+    }
1479
+
1480
+    /**
1481
+     * toUpper
1482
+     */
1483
+        protected function toUpper() {
1484
+        $stringLen = strlen($this->dataStr);
1485
+        $p = 0;
1486
+        while ($p < $stringLen) {
1487
+            $mode = $this->identifyMode(substr($this->dataStr, $p), $this->hint);
1488
+            if ($mode == QR_MODE_KJ) {
1489
+                $p += 2;
1490
+            } else {
1491
+                if ((ord($this->dataStr[$p]) >= ord('a')) AND (ord($this->dataStr[$p]) <= ord('z'))) {
1492
+                    $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32);
1493
+                }
1494
+                $p++;
1495
+            }
1496
+        }
1497
+        return $this->dataStr;
1498
+    }
1499
+
1500
+    // - - - - - - - - - - - - - - - - - - - - - - - - -
1501
+
1502
+    // QRinputItem
1503
+
1504
+    /**
1505
+     * newInputItem
1506
+     * @param $mode (int)
1507
+     * @param $size (int)
1508
+     * @param $data (array)
1509
+     * @param $bstream (array)
1510
+     * @return array input item
1511
+     */
1512
+        protected function newInputItem($mode, $size, $data, $bstream=null) {
1513
+        $setData = array_slice($data, 0, $size);
1514
+        if (count($setData) < $size) {
1515
+            $setData = array_merge($setData, array_fill(0, ($size - count($setData)), 0));
1516
+        }
1517
+        if (!$this->check($mode, $size, $setData)) {
1518
+            return NULL;
1519
+        }
1520
+        $inputitem = array();
1521
+        $inputitem['mode'] = $mode;
1522
+        $inputitem['size'] = $size;
1523
+        $inputitem['data'] = $setData;
1524
+        $inputitem['bstream'] = $bstream;
1525
+        return $inputitem;
1526
+    }
1527
+
1528
+    /**
1529
+     * encodeModeNum
1530
+     * @param $inputitem (array)
1531
+     * @param $version (int)
1532
+     * @return array input item
1533
+     */
1534
+        protected function encodeModeNum($inputitem, $version) {
1535
+        $words = (int)($inputitem['size'] / 3);
1536
+        $inputitem['bstream'] = array();
1537
+        $val = 0x1;
1538
+        $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val);
1539
+        $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_NM, $version), $inputitem['size']);
1540
+        for ($i=0; $i < $words; ++$i) {
1541
+            $val  = (ord($inputitem['data'][$i*3  ]) - ord('0')) * 100;
1542
+            $val += (ord($inputitem['data'][$i*3+1]) - ord('0')) * 10;
1543
+            $val += (ord($inputitem['data'][$i*3+2]) - ord('0'));
1544
+            $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 10, $val);
1545
+        }
1546
+        if ($inputitem['size'] - $words * 3 == 1) {
1547
+            $val = ord($inputitem['data'][$words*3]) - ord('0');
1548
+            $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val);
1549
+        } elseif (($inputitem['size'] - ($words * 3)) == 2) {
1550
+            $val  = (ord($inputitem['data'][$words*3  ]) - ord('0')) * 10;
1551
+            $val += (ord($inputitem['data'][$words*3+1]) - ord('0'));
1552
+            $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 7, $val);
1553
+        }
1554
+        return $inputitem;
1555
+    }
1556
+
1557
+    /**
1558
+     * encodeModeAn
1559
+     * @param $inputitem (array)
1560
+     * @param $version (int)
1561
+     * @return array input item
1562
+     */
1563
+        protected function encodeModeAn($inputitem, $version) {
1564
+        $words = (int)($inputitem['size'] / 2);
1565
+        $inputitem['bstream'] = array();
1566
+        $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x02);
1567
+        $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_AN, $version), $inputitem['size']);
1568
+        for ($i=0; $i < $words; ++$i) {
1569
+            $val  = (int)($this->lookAnTable(ord($inputitem['data'][$i*2])) * 45);
1570
+            $val += (int)($this->lookAnTable(ord($inputitem['data'][($i*2)+1])));
1571
+            $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 11, $val);
1572
+        }
1573
+        if ($inputitem['size'] & 1) {
1574
+            $val = $this->lookAnTable(ord($inputitem['data'][($words * 2)]));
1575
+            $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 6, $val);
1576
+        }
1577
+        return $inputitem;
1578
+    }
1579
+
1580
+    /**
1581
+     * encodeMode8
1582
+     * @param $inputitem (array)
1583
+     * @param $version (int)
1584
+     * @return array input item
1585
+     */
1586
+        protected function encodeMode8($inputitem, $version) {
1587
+        $inputitem['bstream'] = array();
1588
+        $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x4);
1589
+        $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_8B, $version), $inputitem['size']);
1590
+        for ($i=0; $i < $inputitem['size']; ++$i) {
1591
+            $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][$i]));
1592
+        }
1593
+        return $inputitem;
1594
+    }
1595
+
1596
+    /**
1597
+     * encodeModeKanji
1598
+     * @param $inputitem (array)
1599
+     * @param $version (int)
1600
+     * @return array input item
1601
+     */
1602
+        protected function encodeModeKanji($inputitem, $version) {
1603
+        $inputitem['bstream'] = array();
1604
+        $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x8);
1605
+        $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_KJ, $version), (int)($inputitem['size'] / 2));
1606
+        for ($i=0; $i<$inputitem['size']; $i+=2) {
1607
+            $val = (ord($inputitem['data'][$i]) << 8) | ord($inputitem['data'][$i+1]);
1608
+            if ($val <= 0x9ffc) {
1609
+                $val -= 0x8140;
1610
+            } else {
1611
+                $val -= 0xc140;
1612
+            }
1613
+            $h = ($val >> 8) * 0xc0;
1614
+            $val = ($val & 0xff) + $h;
1615
+            $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 13, $val);
1616
+        }
1617
+        return $inputitem;
1618
+    }
1619
+
1620
+    /**
1621
+     * encodeModeStructure
1622
+     * @param $inputitem (array)
1623
+     * @return array input item
1624
+     */
1625
+        protected function encodeModeStructure($inputitem) {
1626
+        $inputitem['bstream'] = array();
1627
+        $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x03);
1628
+        $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][1]) - 1);
1629
+        $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][0]) - 1);
1630
+        $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][2]));
1631
+        return $inputitem;
1632
+    }
1633
+
1634
+    /**
1635
+     * encodeBitStream
1636
+     * @param $inputitem (array)
1637
+     * @param $version (int)
1638
+     * @return array input item
1639
+     */
1640
+        protected function encodeBitStream($inputitem, $version) {
1641
+        $inputitem['bstream'] = array();
1642
+        $words = $this->maximumWords($inputitem['mode'], $version);
1643
+        if ($inputitem['size'] > $words) {
1644
+            $st1 = $this->newInputItem($inputitem['mode'], $words, $inputitem['data']);
1645
+            $st2 = $this->newInputItem($inputitem['mode'], $inputitem['size'] - $words, array_slice($inputitem['data'], $words));
1646
+            $st1 = $this->encodeBitStream($st1, $version);
1647
+            $st2 = $this->encodeBitStream($st2, $version);
1648
+            $inputitem['bstream'] = array();
1649
+            $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st1['bstream']);
1650
+            $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st2['bstream']);
1651
+        } else {
1652
+            switch($inputitem['mode']) {
1653
+                case QR_MODE_NM: {
1654
+                    $inputitem = $this->encodeModeNum($inputitem, $version);
1655
+                    break;
1656
+                }
1657
+                case QR_MODE_AN: {
1658
+                    $inputitem = $this->encodeModeAn($inputitem, $version);
1659
+                    break;
1660
+                }
1661
+                case QR_MODE_8B: {
1662
+                    $inputitem = $this->encodeMode8($inputitem, $version);
1663
+                    break;
1664
+                }
1665
+                case QR_MODE_KJ: {
1666
+                    $inputitem = $this->encodeModeKanji($inputitem, $version);
1667
+                    break;
1668
+                }
1669
+                case QR_MODE_ST: {
1670
+                    $inputitem = $this->encodeModeStructure($inputitem);
1671
+                    break;
1672
+                }
1673
+                default: {
1674
+                    break;
1675
+                }
1676
+            }
1677
+        }
1678
+        return $inputitem;
1679
+    }
1680
+
1681
+    // - - - - - - - - - - - - - - - - - - - - - - - - -
1682
+
1683
+    // QRinput
1684
+
1685
+    /**
1686
+     * Append data to an input object.
1687
+     * The data is copied and appended to the input object.
1688
+     * @param $items (arrray) input items
1689
+     * @param $mode (int) encoding mode.
1690
+     * @param $size (int) size of data (byte).
1691
+     * @param $data (array) array of input data.
1692
+     * @return items
1693
+     *
1694
+     */
1695
+    protected function appendNewInputItem($items, $mode, $size, $data) {
1696
+        $newitem = $this->newInputItem($mode, $size, $data);
1697
+        if (!empty($newitem)) {
1698
+            $items[] = $newitem;
1699
+        }
1700
+        return $items;
1701
+    }
1702
+
1703
+    /**
1704
+     * insertStructuredAppendHeader
1705
+     * @param $items (array)
1706
+     * @param $size (int)
1707
+     * @param $index (int)
1708
+     * @param $parity (int)
1709
+     * @return array items
1710
+     */
1711
+        protected function insertStructuredAppendHeader($items, $size, $index, $parity) {
1712
+        if ($size > MAX_STRUCTURED_SYMBOLS) {
1713
+            return -1;
1714
+        }
1715
+        if (($index <= 0) OR ($index > MAX_STRUCTURED_SYMBOLS)) {
1716
+            return -1;
1717
+        }
1718
+        $buf = array($size, $index, $parity);
1719
+        $entry = $this->newInputItem(QR_MODE_ST, 3, buf);
1720
+        array_unshift($items, $entry);
1721
+        return $items;
1722
+    }
1723
+
1724
+    /**
1725
+     * calcParity
1726
+     * @param $items (array)
1727
+     * @return int parity
1728
+     */
1729
+        protected function calcParity($items) {
1730
+        $parity = 0;
1731
+        foreach ($items as $item) {
1732
+            if ($item['mode'] != QR_MODE_ST) {
1733
+                for ($i=$item['size']-1; $i>=0; --$i) {
1734
+                    $parity ^= $item['data'][$i];
1735
+                }
1736
+            }
1737
+        }
1738
+        return $parity;
1739
+    }
1740
+
1741
+    /**
1742
+     * checkModeNum
1743
+     * @param $size (int)
1744
+     * @param $data (array)
1745
+     * @return boolean true or false
1746
+     */
1747
+        protected function checkModeNum($size, $data) {
1748
+        for ($i=0; $i<$size; ++$i) {
1749
+            if ((ord($data[$i]) < ord('0')) OR (ord($data[$i]) > ord('9'))){
1750
+                return false;
1751
+            }
1752
+        }
1753
+        return true;
1754
+    }
1755
+
1756
+    /**
1757
+     * Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19).
1758
+     * @param $c (int) character value
1759
+     * @return value
1760
+     */
1761
+    protected function lookAnTable($c) {
1762
+        return (($c > 127)?-1:$this->anTable[$c]);
1763
+    }
1764
+
1765
+    /**
1766
+     * checkModeAn
1767
+     * @param $size (int)
1768
+     * @param $data (array)
1769
+     * @return boolean true or false
1770
+     */
1771
+        protected function checkModeAn($size, $data) {
1772
+        for ($i=0; $i<$size; ++$i) {
1773
+            if ($this->lookAnTable(ord($data[$i])) == -1) {
1774
+                return false;
1775
+            }
1776
+        }
1777
+        return true;
1778
+    }
1779
+
1780
+    /**
1781
+     * estimateBitsModeNum
1782
+     * @param $size (int)
1783
+     * @return int number of bits
1784
+     */
1785
+        protected function estimateBitsModeNum($size) {
1786
+        $w = (int)($size / 3);
1787
+        $bits = ($w * 10);
1788
+        switch($size - ($w * 3)) {
1789
+            case 1: {
1790
+                $bits += 4;
1791
+                break;
1792
+            }
1793
+            case 2: {
1794
+                $bits += 7;
1795
+                break;
1796
+            }
1797
+        }
1798
+        return $bits;
1799
+    }
1800
+
1801
+    /**
1802
+     * estimateBitsModeAn
1803
+     * @param $size (int)
1804
+     * @return int number of bits
1805
+     */
1806
+        protected function estimateBitsModeAn($size) {
1807
+        $bits = (int)($size * 5.5); // (size / 2 ) * 11
1808
+        if ($size & 1) {
1809
+            $bits += 6;
1810
+        }
1811
+        return $bits;
1812
+    }
1813
+
1814
+    /**
1815
+     * estimateBitsMode8
1816
+     * @param $size (int)
1817
+     * @return int number of bits
1818
+     */
1819
+        protected function estimateBitsMode8($size) {
1820
+        return (int)($size * 8);
1821
+    }
1822
+
1823
+    /**
1824
+     * estimateBitsModeKanji
1825
+     * @param $size (int)
1826
+     * @return int number of bits
1827
+     */
1828
+        protected function estimateBitsModeKanji($size) {
1829
+        return (int)($size * 6.5); // (size / 2 ) * 13
1830
+    }
1831
+
1832
+    /**
1833
+     * checkModeKanji
1834
+     * @param $size (int)
1835
+     * @param $data (array)
1836
+     * @return boolean true or false
1837
+     */
1838
+        protected function checkModeKanji($size, $data) {
1839
+        if ($size & 1) {
1840
+            return false;
1841
+        }
1842
+        for ($i=0; $i<$size; $i+=2) {
1843
+            $val = (ord($data[$i]) << 8) | ord($data[$i+1]);
1844
+            if (($val < 0x8140) OR (($val > 0x9ffc) AND ($val < 0xe040)) OR ($val > 0xebbf)) {
1845
+                return false;
1846
+            }
1847
+        }
1848
+        return true;
1849
+    }
1850
+
1851
+    /**
1852
+     * Validate the input data.
1853
+     * @param $mode (int) encoding mode.
1854
+     * @param $size (int) size of data (byte).
1855
+     * @param $data (array) data to validate
1856
+     * @return boolean true in case of valid data, false otherwise
1857
+     */
1858
+    protected function check($mode, $size, $data) {
1859
+        if ($size <= 0) {
1860
+            return false;
1861
+        }
1862
+        switch($mode) {
1863
+            case QR_MODE_NM: {
1864
+                return $this->checkModeNum($size, $data);
1865
+            }
1866
+            case QR_MODE_AN: {
1867
+                return $this->checkModeAn($size, $data);
1868
+            }
1869
+            case QR_MODE_KJ: {
1870
+                return $this->checkModeKanji($size, $data);
1871
+            }
1872
+            case QR_MODE_8B: {
1873
+                return true;
1874
+            }
1875
+            case QR_MODE_ST: {
1876
+                return true;
1877
+            }
1878
+            default: {
1879
+                break;
1880
+            }
1881
+        }
1882
+        return false;
1883
+    }
1884
+
1885
+    /**
1886
+     * estimateBitStreamSize
1887
+     * @param $items (array)
1888
+     * @param $version (int)
1889
+     * @return int bits
1890
+     */
1891
+        protected function estimateBitStreamSize($items, $version) {
1892
+        $bits = 0;
1893
+        if ($version == 0) {
1894
+            $version = 1;
1895
+        }
1896
+        foreach ($items as $item) {
1897
+            switch($item['mode']) {
1898
+                case QR_MODE_NM: {
1899
+                    $bits = $this->estimateBitsModeNum($item['size']);
1900
+                    break;
1901
+                }
1902
+                case QR_MODE_AN: {
1903
+                    $bits = $this->estimateBitsModeAn($item['size']);
1904
+                    break;
1905
+                }
1906
+                case QR_MODE_8B: {
1907
+                    $bits = $this->estimateBitsMode8($item['size']);
1908
+                    break;
1909
+                }
1910
+                case QR_MODE_KJ: {
1911
+                    $bits = $this->estimateBitsModeKanji($item['size']);
1912
+                    break;
1913
+                }
1914
+                case QR_MODE_ST: {
1915
+                    return STRUCTURE_HEADER_BITS;
1916
+                }
1917
+                default: {
1918
+                    return 0;
1919
+                }
1920
+            }
1921
+            $l = $this->lengthIndicator($item['mode'], $version);
1922
+            $m = 1 << $l;
1923
+            $num = (int)(($item['size'] + $m - 1) / $m);
1924
+            $bits += $num * (4 + $l);
1925
+        }
1926
+        return $bits;
1927
+    }
1928
+
1929
+    /**
1930
+     * estimateVersion
1931
+     * @param $items (array)
1932
+     * @return int version
1933
+     */
1934
+        protected function estimateVersion($items) {
1935
+        $version = 0;
1936
+        $prev = 0;
1937
+        do {
1938
+            $prev = $version;
1939
+            $bits = $this->estimateBitStreamSize($items, $prev);
1940
+            $version = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level);
1941
+            if ($version < 0) {
1942
+                return -1;
1943
+            }
1944
+        } while ($version > $prev);
1945
+        return $version;
1946
+    }
1947
+
1948
+    /**
1949
+     * lengthOfCode
1950
+     * @param $mode (int)
1951
+     * @param $version (int)
1952
+     * @param $bits (int)
1953
+     * @return int size
1954
+     */
1955
+        protected function lengthOfCode($mode, $version, $bits) {
1956
+        $payload = $bits - 4 - $this->lengthIndicator($mode, $version);
1957
+        switch($mode) {
1958
+            case QR_MODE_NM: {
1959
+                $chunks = (int)($payload / 10);
1960
+                $remain = $payload - $chunks * 10;
1961
+                $size = $chunks * 3;
1962
+                if ($remain >= 7) {
1963
+                    $size += 2;
1964
+                } elseif ($remain >= 4) {
1965
+                    $size += 1;
1966
+                }
1967
+                break;
1968
+            }
1969
+            case QR_MODE_AN: {
1970
+                $chunks = (int)($payload / 11);
1971
+                $remain = $payload - $chunks * 11;
1972
+                $size = $chunks * 2;
1973
+                if ($remain >= 6) {
1974
+                    ++$size;
1975
+                }
1976
+                break;
1977
+            }
1978
+            case QR_MODE_8B: {
1979
+                $size = (int)($payload / 8);
1980
+                break;
1981
+            }
1982
+            case QR_MODE_KJ: {
1983
+                $size = (int)(($payload / 13) * 2);
1984
+                break;
1985
+            }
1986
+            case QR_MODE_ST: {
1987
+                $size = (int)($payload / 8);
1988
+                break;
1989
+            }
1990
+            default: {
1991
+                $size = 0;
1992
+                break;
1993
+            }
1994
+        }
1995
+        $maxsize = $this->maximumWords($mode, $version);
1996
+        if ($size < 0) {
1997
+            $size = 0;
1998
+        }
1999
+        if ($size > $maxsize) {
2000
+            $size = $maxsize;
2001
+        }
2002
+        return $size;
2003
+    }
2004
+
2005
+    /**
2006
+     * createBitStream
2007
+     * @param $items (array)
2008
+     * @return array of items and total bits
2009
+     */
2010
+        protected function createBitStream($items) {
2011
+        $total = 0;
2012
+        foreach ($items as $key => $item) {
2013
+            $items[$key] = $this->encodeBitStream($item, $this->version);
2014
+            $bits = count($items[$key]['bstream']);
2015
+            $total += $bits;
2016
+        }
2017
+        return array($items, $total);
2018
+    }
2019
+
2020
+    /**
2021
+     * convertData
2022
+     * @param $items (array)
2023
+     * @return array items
2024
+     */
2025
+        protected function convertData($items) {
2026
+        $ver = $this->estimateVersion($items);
2027
+        if ($ver > $this->version) {
2028
+            $this->version = $ver;
2029
+        }
2030
+        while (true) {
2031
+            $cbs = $this->createBitStream($items);
2032
+            $items = $cbs[0];
2033
+            $bits = $cbs[1];
2034
+            if ($bits < 0) {
2035
+                return -1;
2036
+            }
2037
+            $ver = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level);
2038
+            if ($ver < 0) {
2039
+                return -1;
2040
+            } elseif ($ver > $this->version) {
2041
+                $this->version = $ver;
2042
+            } else {
2043
+                break;
2044
+            }
2045
+        }
2046
+        return $items;
2047
+    }
2048
+
2049
+    /**
2050
+     * Append Padding Bit to bitstream
2051
+     * @param $bstream (array)
2052
+     * @return array bitstream
2053
+     */
2054
+        protected function appendPaddingBit($bstream) {
2055
+            if (is_null($bstream)) {
2056
+                return null;
2057
+            }
2058
+        $bits = count($bstream);
2059
+        $maxwords = $this->getDataLength($this->version, $this->level);
2060
+        $maxbits = $maxwords * 8;
2061
+        if ($maxbits == $bits) {
2062
+            return $bstream;
2063
+        }
2064
+        if ($maxbits - $bits < 5) {
2065
+            return $this->appendNum($bstream, $maxbits - $bits, 0);
2066
+        }
2067
+        $bits += 4;
2068
+        $words = (int)(($bits + 7) / 8);
2069
+        $padding = array();
2070
+        $padding = $this->appendNum($padding, $words * 8 - $bits + 4, 0);
2071
+        $padlen = $maxwords - $words;
2072
+        if ($padlen > 0) {
2073
+            $padbuf = array();
2074
+            for ($i=0; $i<$padlen; ++$i) {
2075
+                $padbuf[$i] = ($i&1)?0x11:0xec;
2076
+            }
2077
+            $padding = $this->appendBytes($padding, $padlen, $padbuf);
2078
+        }
2079
+        return $this->appendBitstream($bstream, $padding);
2080
+    }
2081
+
2082
+    /**
2083
+     * mergeBitStream
2084
+     * @param $items (array) items
2085
+     * @return array bitstream
2086
+     */
2087
+        protected function mergeBitStream($items) {
2088
+        $items = $this->convertData($items);
2089
+        if (!is_array($items)) {
2090
+            return null;
2091
+        }
2092
+        $bstream = array();
2093
+        foreach ($items as $item) {
2094
+            $bstream = $this->appendBitstream($bstream, $item['bstream']);
2095
+        }
2096
+        return $bstream;
2097
+    }
2098
+
2099
+    /**
2100
+     * Returns a stream of bits.
2101
+     * @param $items (int)
2102
+     * @return array padded merged byte stream
2103
+     */
2104
+    protected function getBitStream($items) {
2105
+        $bstream = $this->mergeBitStream($items);
2106
+        return $this->appendPaddingBit($bstream);
2107
+    }
2108
+
2109
+    /**
2110
+     * Pack all bit streams padding bits into a byte array.
2111
+     * @param $items (int)
2112
+     * @return array padded merged byte stream
2113
+     */
2114
+    protected function getByteStream($items) {
2115
+        $bstream = $this->getBitStream($items);
2116
+        return $this->bitstreamToByte($bstream);
2117
+    }
2118
+
2119
+    // - - - - - - - - - - - - - - - - - - - - - - - - -
2120
+
2121
+    // QRbitstream
2122
+
2123
+    /**
2124
+     * Return an array with zeros
2125
+     * @param $setLength (int) array size
2126
+     * @return array
2127
+     */
2128
+        protected function allocate($setLength) {
2129
+        return array_fill(0, $setLength, 0);
2130
+    }
2131
+
2132
+    /**
2133
+     * Return new bitstream from number
2134
+     * @param $bits (int) number of bits
2135
+     * @param $num (int) number
2136
+     * @return array bitstream
2137
+     */
2138
+        protected function newFromNum($bits, $num) {
2139
+        $bstream = $this->allocate($bits);
2140
+        $mask = 1 << ($bits - 1);
2141
+        for ($i=0; $i<$bits; ++$i) {
2142
+            if ($num & $mask) {
2143
+                $bstream[$i] = 1;
2144
+            } else {
2145
+                $bstream[$i] = 0;
2146
+            }
2147
+            $mask = $mask >> 1;
2148
+        }
2149
+        return $bstream;
2150
+    }
2151
+
2152
+    /**
2153
+     * Return new bitstream from bytes
2154
+     * @param $size (int) size
2155
+     * @param $data (array) bytes
2156
+     * @return array bitstream
2157
+     */
2158
+        protected function newFromBytes($size, $data) {
2159
+        $bstream = $this->allocate($size * 8);
2160
+        $p=0;
2161
+        for ($i=0; $i<$size; ++$i) {
2162
+            $mask = 0x80;
2163
+            for ($j=0; $j<8; ++$j) {
2164
+                if ($data[$i] & $mask) {
2165
+                    $bstream[$p] = 1;
2166
+                } else {
2167
+                    $bstream[$p] = 0;
2168
+                }
2169
+                $p++;
2170
+                $mask = $mask >> 1;
2171
+            }
2172
+        }
2173
+        return $bstream;
2174
+    }
2175
+
2176
+    /**
2177
+     * Append one bitstream to another
2178
+     * @param $bitstream (array) original bitstream
2179
+     * @param $append (array) bitstream to append
2180
+     * @return array bitstream
2181
+     */
2182
+        protected function appendBitstream($bitstream, $append) {
2183
+        if ((!is_array($append)) OR (count($append) == 0)) {
2184
+            return $bitstream;
2185
+        }
2186
+        if (count($bitstream) == 0) {
2187
+            return $append;
2188
+        }
2189
+        return array_values(array_merge($bitstream, $append));
2190
+    }
2191
+
2192
+    /**
2193
+     * Append one bitstream created from number to another
2194
+     * @param $bitstream (array) original bitstream
2195
+     * @param $bits (int) number of bits
2196
+     * @param $num (int) number
2197
+     * @return array bitstream
2198
+     */
2199
+        protected function appendNum($bitstream, $bits, $num) {
2200
+        if ($bits == 0) {
2201
+            return 0;
2202
+        }
2203
+        $b = $this->newFromNum($bits, $num);
2204
+        return $this->appendBitstream($bitstream, $b);
2205
+    }
2206
+
2207
+    /**
2208
+     * Append one bitstream created from bytes to another
2209
+     * @param $bitstream (array) original bitstream
2210
+     * @param $size (int) size
2211
+     * @param $data (array) bytes
2212
+     * @return array bitstream
2213
+     */
2214
+        protected function appendBytes($bitstream, $size, $data) {
2215
+        if ($size == 0) {
2216
+            return 0;
2217
+        }
2218
+        $b = $this->newFromBytes($size, $data);
2219
+        return $this->appendBitstream($bitstream, $b);
2220
+    }
2221
+
2222
+    /**
2223
+     * Convert bitstream to bytes
2224
+     * @param $bstream (array) original bitstream
2225
+     * @return array of bytes
2226
+     */
2227
+        protected function bitstreamToByte($bstream) {
2228
+        if (is_null($bstream)) {
2229
+                return null;
2230
+            }
2231
+        $size = count($bstream);
2232
+        if ($size == 0) {
2233
+            return array();
2234
+        }
2235
+        $data = array_fill(0, (int)(($size + 7) / 8), 0);
2236
+        $bytes = (int)($size / 8);
2237
+        $p = 0;
2238
+        for ($i=0; $i<$bytes; $i++) {
2239
+            $v = 0;
2240
+            for ($j=0; $j<8; $j++) {
2241
+                $v = $v << 1;
2242
+                $v |= $bstream[$p];
2243
+                $p++;
2244
+            }
2245
+            $data[$i] = $v;
2246
+        }
2247
+        if ($size & 7) {
2248
+            $v = 0;
2249
+            for ($j=0; $j<($size & 7); $j++) {
2250
+                $v = $v << 1;
2251
+                $v |= $bstream[$p];
2252
+                $p++;
2253
+            }
2254
+            $data[$bytes] = $v;
2255
+        }
2256
+        return $data;
2257
+    }
2258
+
2259
+    // - - - - - - - - - - - - - - - - - - - - - - - - -
2260
+
2261
+    // QRspec
2262
+
2263
+    /**
2264
+     * Replace a value on the array at the specified position
2265
+     * @param $srctab (array)
2266
+     * @param $x (int) X position
2267
+     * @param $y (int) Y position
2268
+     * @param $repl (string) value to replace
2269
+     * @param $replLen (int) length of the repl string
2270
+     * @return array srctab
2271
+     */
2272
+        protected function qrstrset($srctab, $x, $y, $repl, $replLen=false) {
2273
+        $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
2274
+        return $srctab;
2275
+    }
2276
+
2277
+    /**
2278
+     * Return maximum data code length (bytes) for the version.
2279
+     * @param $version (int) version
2280
+     * @param $level (int) error correction level
2281
+     * @return int maximum size (bytes)
2282
+     */
2283
+    protected function getDataLength($version, $level) {
2284
+        return $this->capacity[$version][QRCAP_WORDS] - $this->capacity[$version][QRCAP_EC][$level];
2285
+    }
2286
+
2287
+    /**
2288
+     * Return maximum error correction code length (bytes) for the version.
2289
+     * @param $version (int) version
2290
+     * @param $level (int) error correction level
2291
+     * @return int ECC size (bytes)
2292
+     */
2293
+    protected function getECCLength($version, $level){
2294
+        return $this->capacity[$version][QRCAP_EC][$level];
2295
+    }
2296
+
2297
+    /**
2298
+     * Return the width of the symbol for the version.
2299
+     * @param $version (int) version
2300
+     * @return int width
2301
+     */
2302
+    protected function getWidth($version) {
2303
+        return $this->capacity[$version][QRCAP_WIDTH];
2304
+    }
2305
+
2306
+    /**
2307
+     * Return the numer of remainder bits.
2308
+     * @param $version (int) version
2309
+     * @return int number of remainder bits
2310
+     */
2311
+    protected function getRemainder($version) {
2312
+        return $this->capacity[$version][QRCAP_REMINDER];
2313
+    }
2314
+
2315
+    /**
2316
+     * Return a version number that satisfies the input code length.
2317
+     * @param $size (int) input code length (bytes)
2318
+     * @param $level (int) error correction level
2319
+     * @return int version number
2320
+     */
2321
+    protected function getMinimumVersion($size, $level) {
2322
+        for ($i = 1; $i <= QRSPEC_VERSION_MAX; ++$i) {
2323
+            $words = ($this->capacity[$i][QRCAP_WORDS] - $this->capacity[$i][QRCAP_EC][$level]);
2324
+            if ($words >= $size) {
2325
+                return $i;
2326
+            }
2327
+        }
2328
+        // the size of input data is greater than QR capacity, try to lover the error correction mode
2329
+        return -1;
2330
+    }
2331
+
2332
+    /**
2333
+     * Return the size of length indicator for the mode and version.
2334
+     * @param $mode (int) encoding mode
2335
+     * @param $version (int) version
2336
+     * @return int the size of the appropriate length indicator (bits).
2337
+     */
2338
+    protected function lengthIndicator($mode, $version) {
2339
+        if ($mode == QR_MODE_ST) {
2340
+            return 0;
2341
+        }
2342
+        if ($version <= 9) {
2343
+            $l = 0;
2344
+        } elseif ($version <= 26) {
2345
+            $l = 1;
2346
+        } else {
2347
+            $l = 2;
2348
+        }
2349
+        return $this->lengthTableBits[$mode][$l];
2350
+    }
2351
+
2352
+    /**
2353
+     * Return the maximum length for the mode and version.
2354
+     * @param $mode (int) encoding mode
2355
+     * @param $version (int) version
2356
+     * @return int the maximum length (bytes)
2357
+     */
2358
+    protected function maximumWords($mode, $version) {
2359
+        if ($mode == QR_MODE_ST) {
2360
+            return 3;
2361
+        }
2362
+        if ($version <= 9) {
2363
+            $l = 0;
2364
+        } else if ($version <= 26) {
2365
+            $l = 1;
2366
+        } else {
2367
+            $l = 2;
2368
+        }
2369
+        $bits = $this->lengthTableBits[$mode][$l];
2370
+        $words = (1 << $bits) - 1;
2371
+        if ($mode == QR_MODE_KJ) {
2372
+            $words *= 2; // the number of bytes is required
2373
+        }
2374
+        return $words;
2375
+    }
2376
+
2377
+    /**
2378
+     * Return an array of ECC specification.
2379
+     * @param $version (int) version
2380
+     * @param $level (int) error correction level
2381
+     * @param $spec (array) an array of ECC specification contains as following: {# of type1 blocks, # of data code, # of ecc code, # of type2 blocks, # of data code}
2382
+     * @return array spec
2383
+     */
2384
+    protected function getEccSpec($version, $level, $spec) {
2385
+        if (count($spec) < 5) {
2386
+            $spec = array(0, 0, 0, 0, 0);
2387
+        }
2388
+        $b1 = $this->eccTable[$version][$level][0];
2389
+        $b2 = $this->eccTable[$version][$level][1];
2390
+        $data = $this->getDataLength($version, $level);
2391
+        $ecc = $this->getECCLength($version, $level);
2392
+        if ($b2 == 0) {
2393
+            $spec[0] = $b1;
2394
+            $spec[1] = (int)($data / $b1);
2395
+            $spec[2] = (int)($ecc / $b1);
2396
+            $spec[3] = 0;
2397
+            $spec[4] = 0;
2398
+        } else {
2399
+            $spec[0] = $b1;
2400
+            $spec[1] = (int)($data / ($b1 + $b2));
2401
+            $spec[2] = (int)($ecc  / ($b1 + $b2));
2402
+            $spec[3] = $b2;
2403
+            $spec[4] = $spec[1] + 1;
2404
+        }
2405
+        return $spec;
2406
+    }
2407
+
2408
+    /**
2409
+     * Put an alignment marker.
2410
+     * @param $frame (array) frame
2411
+     * @param $ox (int) X center coordinate of the pattern
2412
+     * @param $oy (int) Y center coordinate of the pattern
2413
+     * @return array frame
2414
+     */
2415
+    protected function putAlignmentMarker($frame, $ox, $oy) {
2416
+        $finder = array(
2417
+            "\xa1\xa1\xa1\xa1\xa1",
2418
+            "\xa1\xa0\xa0\xa0\xa1",
2419
+            "\xa1\xa0\xa1\xa0\xa1",
2420
+            "\xa1\xa0\xa0\xa0\xa1",
2421
+            "\xa1\xa1\xa1\xa1\xa1"
2422
+            );
2423
+        $yStart = $oy - 2;
2424
+        $xStart = $ox - 2;
2425
+        for ($y=0; $y < 5; $y++) {
2426
+            $frame = $this->qrstrset($frame, $xStart, $yStart+$y, $finder[$y]);
2427
+        }
2428
+        return $frame;
2429
+    }
2430
+
2431
+    /**
2432
+     * Put an alignment pattern.
2433
+     * @param $version (int) version
2434
+     * @param $frame (array) frame
2435
+     * @param $width (int) width
2436
+     * @return array frame
2437
+     */
2438
+        protected function putAlignmentPattern($version, $frame, $width) {
2439
+        if ($version < 2) {
2440
+            return $frame;
2441
+        }
2442
+        $d = $this->alignmentPattern[$version][1] - $this->alignmentPattern[$version][0];
2443
+        if ($d < 0) {
2444
+            $w = 2;
2445
+        } else {
2446
+            $w = (int)(($width - $this->alignmentPattern[$version][0]) / $d + 2);
2447
+        }
2448
+        if ($w * $w - 3 == 1) {
2449
+            $x = $this->alignmentPattern[$version][0];
2450
+            $y = $this->alignmentPattern[$version][0];
2451
+            $frame = $this->putAlignmentMarker($frame, $x, $y);
2452
+            return $frame;
2453
+        }
2454
+        $cx = $this->alignmentPattern[$version][0];
2455
+        $wo = $w - 1;
2456
+        for ($x=1; $x < $wo; ++$x) {
2457
+            $frame = $this->putAlignmentMarker($frame, 6, $cx);
2458
+            $frame = $this->putAlignmentMarker($frame, $cx,  6);
2459
+            $cx += $d;
2460
+        }
2461
+        $cy = $this->alignmentPattern[$version][0];
2462
+        for ($y=0; $y < $wo; ++$y) {
2463
+            $cx = $this->alignmentPattern[$version][0];
2464
+            for ($x=0; $x < $wo; ++$x) {
2465
+                $frame = $this->putAlignmentMarker($frame, $cx, $cy);
2466
+                $cx += $d;
2467
+            }
2468
+            $cy += $d;
2469
+        }
2470
+        return $frame;
2471
+    }
2472
+
2473
+    /**
2474
+     * Return BCH encoded version information pattern that is used for the symbol of version 7 or greater. Use lower 18 bits.
2475
+     * @param $version (int) version
2476
+     * @return BCH encoded version information pattern
2477
+     */
2478
+    protected function getVersionPattern($version) {
2479
+        if (($version < 7) OR ($version > QRSPEC_VERSION_MAX)) {
2480
+            return 0;
2481
+        }
2482
+        return $this->versionPattern[($version - 7)];
2483
+    }
2484
+
2485
+    /**
2486
+     * Return BCH encoded format information pattern.
2487
+     * @param $mask (array)
2488
+     * @param $level (int) error correction level
2489
+     * @return BCH encoded format information pattern
2490
+     */
2491
+    protected function getFormatInfo($mask, $level) {
2492
+        if (($mask < 0) OR ($mask > 7)) {
2493
+            return 0;
2494
+        }
2495
+        if (($level < 0) OR ($level > 3)) {
2496
+            return 0;
2497
+        }
2498
+        return $this->formatInfo[$level][$mask];
2499
+    }
2500
+
2501
+    /**
2502
+     * Put a finder pattern.
2503
+     * @param $frame (array) frame
2504
+     * @param $ox (int) X center coordinate of the pattern
2505
+     * @param $oy (int) Y center coordinate of the pattern
2506
+     * @return array frame
2507
+     */
2508
+    protected function putFinderPattern($frame, $ox, $oy) {
2509
+        $finder = array(
2510
+        "\xc1\xc1\xc1\xc1\xc1\xc1\xc1",
2511
+        "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
2512
+        "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
2513
+        "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
2514
+        "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
2515
+        "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
2516
+        "\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
2517
+        );
2518
+        for ($y=0; $y < 7; $y++) {
2519
+            $frame = $this->qrstrset($frame, $ox, ($oy + $y), $finder[$y]);
2520
+        }
2521
+        return $frame;
2522
+    }
2523
+
2524
+    /**
2525
+     * Return a copy of initialized frame.
2526
+     * @param $version (int) version
2527
+     * @return Array of unsigned char.
2528
+     */
2529
+    protected function createFrame($version) {
2530
+        $width = $this->capacity[$version][QRCAP_WIDTH];
2531
+        $frameLine = str_repeat ("\0", $width);
2532
+        $frame = array_fill(0, $width, $frameLine);
2533
+        // Finder pattern
2534
+        $frame = $this->putFinderPattern($frame, 0, 0);
2535
+        $frame = $this->putFinderPattern($frame, $width - 7, 0);
2536
+        $frame = $this->putFinderPattern($frame, 0, $width - 7);
2537
+        // Separator
2538
+        $yOffset = $width - 7;
2539
+        for ($y=0; $y < 7; ++$y) {
2540
+            $frame[$y][7] = "\xc0";
2541
+            $frame[$y][$width - 8] = "\xc0";
2542
+            $frame[$yOffset][7] = "\xc0";
2543
+            ++$yOffset;
2544
+        }
2545
+        $setPattern = str_repeat("\xc0", 8);
2546
+        $frame = $this->qrstrset($frame, 0, 7, $setPattern);
2547
+        $frame = $this->qrstrset($frame, $width-8, 7, $setPattern);
2548
+        $frame = $this->qrstrset($frame, 0, $width - 8, $setPattern);
2549
+        // Format info
2550
+        $setPattern = str_repeat("\x84", 9);
2551
+        $frame = $this->qrstrset($frame, 0, 8, $setPattern);
2552
+        $frame = $this->qrstrset($frame, $width - 8, 8, $setPattern, 8);
2553
+        $yOffset = $width - 8;
2554
+        for ($y=0; $y < 8; ++$y,++$yOffset) {
2555
+            $frame[$y][8] = "\x84";
2556
+            $frame[$yOffset][8] = "\x84";
2557
+        }
2558
+        // Timing pattern
2559
+        $wo = $width - 15;
2560
+        for ($i=1; $i < $wo; ++$i) {
2561
+            $frame[6][7+$i] = chr(0x90 | ($i & 1));
2562
+            $frame[7+$i][6] = chr(0x90 | ($i & 1));
2563
+        }
2564
+        // Alignment pattern
2565
+        $frame = $this->putAlignmentPattern($version, $frame, $width);
2566
+        // Version information
2567
+        if ($version >= 7) {
2568
+            $vinf = $this->getVersionPattern($version);
2569
+            $v = $vinf;
2570
+            for ($x=0; $x<6; ++$x) {
2571
+                for ($y=0; $y<3; ++$y) {
2572
+                    $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
2573
+                    $v = $v >> 1;
2574
+                }
2575
+            }
2576
+            $v = $vinf;
2577
+            for ($y=0; $y<6; ++$y) {
2578
+                for ($x=0; $x<3; ++$x) {
2579
+                    $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
2580
+                    $v = $v >> 1;
2581
+                }
2582
+            }
2583
+        }
2584
+        // and a little bit...
2585
+        $frame[$width - 8][8] = "\x81";
2586
+        return $frame;
2587
+    }
2588
+
2589
+    /**
2590
+     * Set new frame for the specified version.
2591
+     * @param $version (int) version
2592
+     * @return Array of unsigned char.
2593
+     */
2594
+    protected function newFrame($version) {
2595
+        if (($version < 1) OR ($version > QRSPEC_VERSION_MAX)) {
2596
+            return NULL;
2597
+        }
2598
+        if (!isset($this->frames[$version])) {
2599
+            $this->frames[$version] = $this->createFrame($version);
2600
+        }
2601
+        if (is_null($this->frames[$version])) {
2602
+            return NULL;
2603
+        }
2604
+        return $this->frames[$version];
2605
+    }
2606
+
2607
+    /**
2608
+     * Return block number 0
2609
+     * @param $spec (array)
2610
+     * @return int value
2611
+     */
2612
+        protected function rsBlockNum($spec) {
2613
+        return ($spec[0] + $spec[3]);
2614
+    }
2615
+
2616
+    /**
2617
+     * Return block number 1
2618
+     * @param $spec (array)
2619
+     * @return int value
2620
+     */
2621
+        protected function rsBlockNum1($spec) {
2622
+        return $spec[0];
2623
+    }
2624
+
2625
+    /**
2626
+     * Return data codes 1
2627
+     * @param $spec (array)
2628
+     * @return int value
2629
+     */
2630
+        protected function rsDataCodes1($spec) {
2631
+        return $spec[1];
2632
+    }
2633
+
2634
+    /**
2635
+     * Return ecc codes 1
2636
+     * @param $spec (array)
2637
+     * @return int value
2638
+     */
2639
+        protected function rsEccCodes1($spec) {
2640
+        return $spec[2];
2641
+    }
2642
+
2643
+    /**
2644
+     * Return block number 2
2645
+     * @param $spec (array)
2646
+     * @return int value
2647
+     */
2648
+        protected function rsBlockNum2($spec) {
2649
+        return $spec[3];
2650
+    }
2651
+
2652
+    /**
2653
+     * Return data codes 2
2654
+     * @param $spec (array)
2655
+     * @return int value
2656
+     */
2657
+        protected function rsDataCodes2($spec) {
2658
+        return $spec[4];
2659
+    }
2660
+
2661
+    /**
2662
+     * Return ecc codes 2
2663
+     * @param $spec (array)
2664
+     * @return int value
2665
+     */
2666
+        protected function rsEccCodes2($spec) {
2667
+        return $spec[2];
2668
+    }
2669
+
2670
+    /**
2671
+     * Return data length
2672
+     * @param $spec (array)
2673
+     * @return int value
2674
+     */
2675
+        protected function rsDataLength($spec) {
2676
+        return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);
2677
+    }
2678
+
2679
+    /**
2680
+     * Return ecc length
2681
+     * @param $spec (array)
2682
+     * @return int value
2683
+     */
2684
+        protected function rsEccLength($spec) {
2685
+        return ($spec[0] + $spec[3]) * $spec[2];
2686
+    }
2687
+
2688
+    // - - - - - - - - - - - - - - - - - - - - - - - - -
2689
+
2690
+    // QRrs
2691
+
2692
+    /**
2693
+     * Initialize a Reed-Solomon codec and add it to existing rsitems
2694
+     * @param $symsize (int) symbol size, bits
2695
+     * @param $gfpoly (int)  Field generator polynomial coefficients
2696
+     * @param $fcr (int)  first root of RS code generator polynomial, index form
2697
+     * @param $prim (int)  primitive element to generate polynomial roots
2698
+     * @param $nroots (int) RS code generator polynomial degree (number of roots)
2699
+     * @param $pad (int)  padding bytes at front of shortened block
2700
+     * @return array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>.
2701
+     */
2702
+        protected function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) {
2703
+        foreach ($this->rsitems as $rs) {
2704
+            if (($rs['pad'] != $pad) OR ($rs['nroots'] != $nroots) OR ($rs['mm'] != $symsize)
2705
+                OR ($rs['gfpoly'] != $gfpoly) OR ($rs['fcr'] != $fcr) OR ($rs['prim'] != $prim)) {
2706
+                continue;
2707
+            }
2708
+            return $rs;
2709
+        }
2710
+        $rs = $this->init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad);
2711
+        array_unshift($this->rsitems, $rs);
2712
+        return $rs;
2713
+    }
2714
+
2715
+    // - - - - - - - - - - - - - - - - - - - - - - - - -
2716
+
2717
+    // QRrsItem
2718
+
2719
+    /**
2720
+     * modnn
2721
+     * @param $rs (array) RS values
2722
+     * @param $x (int) X position
2723
+     * @return int X osition
2724
+     */
2725
+        protected function modnn($rs, $x) {
2726
+        while ($x >= $rs['nn']) {
2727
+            $x -= $rs['nn'];
2728
+            $x = ($x >> $rs['mm']) + ($x & $rs['nn']);
2729
+        }
2730
+        return $x;
2731
+    }
2732
+
2733
+    /**
2734
+     * Initialize a Reed-Solomon codec and returns an array of values.
2735
+     * @param $symsize (int) symbol size, bits
2736
+     * @param $gfpoly (int)  Field generator polynomial coefficients
2737
+     * @param $fcr (int)  first root of RS code generator polynomial, index form
2738
+     * @param $prim (int)  primitive element to generate polynomial roots
2739
+     * @param $nroots (int) RS code generator polynomial degree (number of roots)
2740
+     * @param $pad (int)  padding bytes at front of shortened block
2741
+     * @return array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>.
2742
+     */
2743
+    protected function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) {
2744
+        // Based on Reed solomon encoder by Phil Karn, KA9Q (GNU-LGPLv2)
2745
+        $rs = null;
2746
+        // Check parameter ranges
2747
+        if (($symsize < 0) OR ($symsize > 8)) {
2748
+            return $rs;
2749
+        }
2750
+        if (($fcr < 0) OR ($fcr >= (1<<$symsize))) {
2751
+            return $rs;
2752
+        }
2753
+        if (($prim <= 0) OR ($prim >= (1<<$symsize))) {
2754
+            return $rs;
2755
+        }
2756
+        if (($nroots < 0) OR ($nroots >= (1<<$symsize))) {
2757
+            return $rs;
2758
+        }
2759
+        if (($pad < 0) OR ($pad >= ((1<<$symsize) -1 - $nroots))) {
2760
+            return $rs;
2761
+        }
2762
+        $rs = array();
2763
+        $rs['mm'] = $symsize;
2764
+        $rs['nn'] = (1 << $symsize) - 1;
2765
+        $rs['pad'] = $pad;
2766
+        $rs['alpha_to'] = array_fill(0, ($rs['nn'] + 1), 0);
2767
+        $rs['index_of'] = array_fill(0, ($rs['nn'] + 1), 0);
2768
+        // PHP style macro replacement ;)
2769
+        $NN =& $rs['nn'];
2770
+        $A0 =& $NN;
2771
+        // Generate Galois field lookup tables
2772
+        $rs['index_of'][0] = $A0; // log(zero) = -inf
2773
+        $rs['alpha_to'][$A0] = 0; // alpha**-inf = 0
2774
+        $sr = 1;
2775
+        for ($i=0; $i<$rs['nn']; ++$i) {
2776
+            $rs['index_of'][$sr] = $i;
2777
+            $rs['alpha_to'][$i] = $sr;
2778
+            $sr <<= 1;
2779
+            if ($sr & (1 << $symsize)) {
2780
+                $sr ^= $gfpoly;
2781
+            }
2782
+            $sr &= $rs['nn'];
2783
+        }
2784
+        if ($sr != 1) {
2785
+            // field generator polynomial is not primitive!
2786
+            return NULL;
2787
+        }
2788
+        // Form RS code generator polynomial from its roots
2789
+        $rs['genpoly'] = array_fill(0, ($nroots + 1), 0);
2790
+        $rs['fcr'] = $fcr;
2791
+        $rs['prim'] = $prim;
2792
+        $rs['nroots'] = $nroots;
2793
+        $rs['gfpoly'] = $gfpoly;
2794
+        // Find prim-th root of 1, used in decoding
2795
+        for ($iprim=1; ($iprim % $prim) != 0; $iprim += $rs['nn']) {
2796
+            ; // intentional empty-body loop!
2797
+        }
2798
+        $rs['iprim'] = (int)($iprim / $prim);
2799
+        $rs['genpoly'][0] = 1;
2800
+        for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
2801
+            $rs['genpoly'][$i+1] = 1;
2802
+            // Multiply rs->genpoly[] by  @**(root + x)
2803
+            for ($j = $i; $j > 0; --$j) {
2804
+                if ($rs['genpoly'][$j] != 0) {
2805
+                    $rs['genpoly'][$j] = $rs['genpoly'][$j-1] ^ $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][$j]] + $root)];
2806
+                } else {
2807
+                    $rs['genpoly'][$j] = $rs['genpoly'][$j-1];
2808
+                }
2809
+            }
2810
+            // rs->genpoly[0] can never be zero
2811
+            $rs['genpoly'][0] = $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][0]] + $root)];
2812
+        }
2813
+        // convert rs->genpoly[] to index form for quicker encoding
2814
+        for ($i = 0; $i <= $nroots; ++$i) {
2815
+            $rs['genpoly'][$i] = $rs['index_of'][$rs['genpoly'][$i]];
2816
+        }
2817
+        return $rs;
2818
+    }
2819
+
2820
+    /**
2821
+     * Encode a Reed-Solomon codec and returns the parity array
2822
+     * @param $rs (array) RS values
2823
+     * @param $data (array) data
2824
+     * @param $parity (array) parity
2825
+     * @return parity array
2826
+     */
2827
+        protected function encode_rs_char($rs, $data, $parity) {
2828
+        $MM       =& $rs['mm']; // bits per symbol
2829
+        $NN       =& $rs['nn']; // the total number of symbols in a RS block
2830
+        $ALPHA_TO =& $rs['alpha_to']; // the address of an array of NN elements to convert Galois field elements in index (log) form to polynomial form
2831
+        $INDEX_OF =& $rs['index_of']; // the address of an array of NN elements to convert Galois field elements in polynomial form to index (log) form
2832
+        $GENPOLY  =& $rs['genpoly']; // an array of NROOTS+1 elements containing the generator polynomial in index form
2833
+        $NROOTS   =& $rs['nroots']; // the number of roots in the RS code generator polynomial, which is the same as the number of parity symbols in a block
2834
+        $FCR      =& $rs['fcr']; // first consecutive root, index form
2835
+        $PRIM     =& $rs['prim']; // primitive element, index form
2836
+        $IPRIM    =& $rs['iprim']; // prim-th root of 1, index form
2837
+        $PAD      =& $rs['pad']; // the number of pad symbols in a block
2838
+        $A0       =& $NN;
2839
+        $parity = array_fill(0, $NROOTS, 0);
2840
+        for ($i=0; $i < ($NN - $NROOTS - $PAD); $i++) {
2841
+            $feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
2842
+            if ($feedback != $A0) {
2843
+                // feedback term is non-zero
2844
+                // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
2845
+                // always be for the polynomials constructed by init_rs()
2846
+                $feedback = $this->modnn($rs, $NN - $GENPOLY[$NROOTS] + $feedback);
2847
+                for ($j=1; $j < $NROOTS; ++$j) {
2848
+                $parity[$j] ^= $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[($NROOTS - $j)])];
2849
+                }
2850
+            }
2851
+            // Shift
2852
+            array_shift($parity);
2853
+            if ($feedback != $A0) {
2854
+                array_push($parity, $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[0])]);
2855
+            } else {
2856
+                array_push($parity, 0);
2857
+            }
2858
+        }
2859
+        return $parity;
2860
+    }
2861 2861
 
2862 2862
 } // end QRcode class
2863 2863
 
Please login to merge, or discard this patch.
Spacing   +286 added lines, -286 removed lines patch added patch discarded remove patch
@@ -169,12 +169,12 @@  discard block
 block discarded – undo
169 169
 	/**
170 170
 	 * Matrix index to get width from $capacity array.
171 171
 	 */
172
-    define('QRCAP_WIDTH',    0);
172
+    define('QRCAP_WIDTH', 0);
173 173
 
174 174
     /**
175 175
 	 * Matrix index to get number of words from $capacity array.
176 176
 	 */
177
-    define('QRCAP_WORDS',    1);
177
+    define('QRCAP_WORDS', 1);
178 178
 
179 179
     /**
180 180
 	 * Matrix index to get remainder from $capacity array.
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
     /**
185 185
 	 * Matrix index to get error correction level from $capacity array.
186 186
 	 */
187
-    define('QRCAP_EC',       3);
187
+    define('QRCAP_EC', 3);
188 188
 
189 189
 	// -----------------------------------------------------
190 190
 
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 	/**
194 194
 	 * Number of header bits for structured mode
195 195
 	 */
196
-    define('STRUCTURE_HEADER_BITS',  20);
196
+    define('STRUCTURE_HEADER_BITS', 20);
197 197
 
198 198
     /**
199 199
 	 * Max number of symbols for structured mode
@@ -207,12 +207,12 @@  discard block
 block discarded – undo
207 207
     /**
208 208
 	 * Down point base value for case 1 mask pattern (concatenation of same color in a line or a column)
209 209
 	 */
210
-    define('N1',  3);
210
+    define('N1', 3);
211 211
 
212 212
     /**
213 213
 	 * Down point base value for case 2 mask pattern (module block of same color)
214 214
 	 */
215
-	define('N2',  3);
215
+	define('N2', 3);
216 216
 
217 217
     /**
218 218
 	 * Down point base value for case 3 mask pattern (1:1:3:1:1(dark:bright:dark:bright:dark)pattern in a line or a column)
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 	 * @param $split_length (int) Maximum length of the chunk.
258 258
 	 * @return  If the optional split_length  parameter is specified, the returned array will be broken down into chunks with each being split_length  in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element.
259 259
 	 */
260
-	function str_split($string, $split_length=1) {
260
+	function str_split($string, $split_length = 1) {
261 261
 		if ((strlen($string) > $split_length) OR (!$split_length)) {
262 262
 			do {
263 263
 				$c = strlen($string);
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //
465 465
 		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //
466 466
 		36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, //
467
-		 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 44, -1, -1, -1, -1, -1, //
467
+		 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, //
468 468
 		-1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, //
469 469
 		25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, //
470 470
 		-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //
@@ -477,47 +477,47 @@  discard block
 block discarded – undo
477 477
 	 * @protected
478 478
 	 */
479 479
 	protected $capacity = array(
480
-		array(  0,    0, 0, array(   0,    0,    0,    0)), //
481
-		array( 21,   26, 0, array(   7,   10,   13,   17)), //  1
482
-		array( 25,   44, 7, array(  10,   16,   22,   28)), //
483
-		array( 29,   70, 7, array(  15,   26,   36,   44)), //
484
-		array( 33,  100, 7, array(  20,   36,   52,   64)), //
485
-		array( 37,  134, 7, array(  26,   48,   72,   88)), //  5
486
-		array( 41,  172, 7, array(  36,   64,   96,  112)), //
487
-		array( 45,  196, 0, array(  40,   72,  108,  130)), //
488
-		array( 49,  242, 0, array(  48,   88,  132,  156)), //
489
-		array( 53,  292, 0, array(  60,  110,  160,  192)), //
490
-		array( 57,  346, 0, array(  72,  130,  192,  224)), // 10
491
-		array( 61,  404, 0, array(  80,  150,  224,  264)), //
492
-		array( 65,  466, 0, array(  96,  176,  260,  308)), //
493
-		array( 69,  532, 0, array( 104,  198,  288,  352)), //
494
-		array( 73,  581, 3, array( 120,  216,  320,  384)), //
495
-		array( 77,  655, 3, array( 132,  240,  360,  432)), // 15
496
-		array( 81,  733, 3, array( 144,  280,  408,  480)), //
497
-		array( 85,  815, 3, array( 168,  308,  448,  532)), //
498
-		array( 89,  901, 3, array( 180,  338,  504,  588)), //
499
-		array( 93,  991, 3, array( 196,  364,  546,  650)), //
500
-		array( 97, 1085, 3, array( 224,  416,  600,  700)), // 20
501
-		array(101, 1156, 4, array( 224,  442,  644,  750)), //
502
-		array(105, 1258, 4, array( 252,  476,  690,  816)), //
503
-		array(109, 1364, 4, array( 270,  504,  750,  900)), //
504
-		array(113, 1474, 4, array( 300,  560,  810,  960)), //
505
-		array(117, 1588, 4, array( 312,  588,  870, 1050)), // 25
506
-		array(121, 1706, 4, array( 336,  644,  952, 1110)), //
507
-		array(125, 1828, 4, array( 360,  700, 1020, 1200)), //
508
-		array(129, 1921, 3, array( 390,  728, 1050, 1260)), //
509
-		array(133, 2051, 3, array( 420,  784, 1140, 1350)), //
510
-		array(137, 2185, 3, array( 450,  812, 1200, 1440)), // 30
511
-		array(141, 2323, 3, array( 480,  868, 1290, 1530)), //
512
-		array(145, 2465, 3, array( 510,  924, 1350, 1620)), //
513
-		array(149, 2611, 3, array( 540,  980, 1440, 1710)), //
514
-		array(153, 2761, 3, array( 570, 1036, 1530, 1800)), //
515
-		array(157, 2876, 0, array( 570, 1064, 1590, 1890)), // 35
516
-		array(161, 3034, 0, array( 600, 1120, 1680, 1980)), //
517
-		array(165, 3196, 0, array( 630, 1204, 1770, 2100)), //
518
-		array(169, 3362, 0, array( 660, 1260, 1860, 2220)), //
519
-		array(173, 3532, 0, array( 720, 1316, 1950, 2310)), //
520
-		array(177, 3706, 0, array( 750, 1372, 2040, 2430))  // 40
480
+		array(0, 0, 0, array(0, 0, 0, 0)), //
481
+		array(21, 26, 0, array(7, 10, 13, 17)), //  1
482
+		array(25, 44, 7, array(10, 16, 22, 28)), //
483
+		array(29, 70, 7, array(15, 26, 36, 44)), //
484
+		array(33, 100, 7, array(20, 36, 52, 64)), //
485
+		array(37, 134, 7, array(26, 48, 72, 88)), //  5
486
+		array(41, 172, 7, array(36, 64, 96, 112)), //
487
+		array(45, 196, 0, array(40, 72, 108, 130)), //
488
+		array(49, 242, 0, array(48, 88, 132, 156)), //
489
+		array(53, 292, 0, array(60, 110, 160, 192)), //
490
+		array(57, 346, 0, array(72, 130, 192, 224)), // 10
491
+		array(61, 404, 0, array(80, 150, 224, 264)), //
492
+		array(65, 466, 0, array(96, 176, 260, 308)), //
493
+		array(69, 532, 0, array(104, 198, 288, 352)), //
494
+		array(73, 581, 3, array(120, 216, 320, 384)), //
495
+		array(77, 655, 3, array(132, 240, 360, 432)), // 15
496
+		array(81, 733, 3, array(144, 280, 408, 480)), //
497
+		array(85, 815, 3, array(168, 308, 448, 532)), //
498
+		array(89, 901, 3, array(180, 338, 504, 588)), //
499
+		array(93, 991, 3, array(196, 364, 546, 650)), //
500
+		array(97, 1085, 3, array(224, 416, 600, 700)), // 20
501
+		array(101, 1156, 4, array(224, 442, 644, 750)), //
502
+		array(105, 1258, 4, array(252, 476, 690, 816)), //
503
+		array(109, 1364, 4, array(270, 504, 750, 900)), //
504
+		array(113, 1474, 4, array(300, 560, 810, 960)), //
505
+		array(117, 1588, 4, array(312, 588, 870, 1050)), // 25
506
+		array(121, 1706, 4, array(336, 644, 952, 1110)), //
507
+		array(125, 1828, 4, array(360, 700, 1020, 1200)), //
508
+		array(129, 1921, 3, array(390, 728, 1050, 1260)), //
509
+		array(133, 2051, 3, array(420, 784, 1140, 1350)), //
510
+		array(137, 2185, 3, array(450, 812, 1200, 1440)), // 30
511
+		array(141, 2323, 3, array(480, 868, 1290, 1530)), //
512
+		array(145, 2465, 3, array(510, 924, 1350, 1620)), //
513
+		array(149, 2611, 3, array(540, 980, 1440, 1710)), //
514
+		array(153, 2761, 3, array(570, 1036, 1530, 1800)), //
515
+		array(157, 2876, 0, array(570, 1064, 1590, 1890)), // 35
516
+		array(161, 3034, 0, array(600, 1120, 1680, 1980)), //
517
+		array(165, 3196, 0, array(630, 1204, 1770, 2100)), //
518
+		array(169, 3362, 0, array(660, 1260, 1860, 2220)), //
519
+		array(173, 3532, 0, array(720, 1316, 1950, 2310)), //
520
+		array(177, 3706, 0, array(750, 1372, 2040, 2430))  // 40
521 521
 	);
522 522
 
523 523
 	/**
@@ -526,9 +526,9 @@  discard block
 block discarded – undo
526 526
 	 */
527 527
 	protected $lengthTableBits = array(
528 528
 		array(10, 12, 14),
529
-		array( 9, 11, 13),
530
-		array( 8, 16, 16),
531
-		array( 8, 10, 12)
529
+		array(9, 11, 13),
530
+		array(8, 16, 16),
531
+		array(8, 10, 12)
532 532
 	);
533 533
 
534 534
 	/**
@@ -537,47 +537,47 @@  discard block
 block discarded – undo
537 537
 	 * @protected
538 538
 	 */
539 539
 	protected $eccTable = array(
540
-		array(array( 0,  0), array( 0,  0), array( 0,  0), array( 0,  0)), //
541
-		array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)), //  1
542
-		array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)), //
543
-		array(array( 1,  0), array( 1,  0), array( 2,  0), array( 2,  0)), //
544
-		array(array( 1,  0), array( 2,  0), array( 2,  0), array( 4,  0)), //
545
-		array(array( 1,  0), array( 2,  0), array( 2,  2), array( 2,  2)), //  5
546
-		array(array( 2,  0), array( 4,  0), array( 4,  0), array( 4,  0)), //
547
-		array(array( 2,  0), array( 4,  0), array( 2,  4), array( 4,  1)), //
548
-		array(array( 2,  0), array( 2,  2), array( 4,  2), array( 4,  2)), //
549
-		array(array( 2,  0), array( 3,  2), array( 4,  4), array( 4,  4)), //
550
-		array(array( 2,  2), array( 4,  1), array( 6,  2), array( 6,  2)), // 10
551
-		array(array( 4,  0), array( 1,  4), array( 4,  4), array( 3,  8)), //
552
-		array(array( 2,  2), array( 6,  2), array( 4,  6), array( 7,  4)), //
553
-		array(array( 4,  0), array( 8,  1), array( 8,  4), array(12,  4)), //
554
-		array(array( 3,  1), array( 4,  5), array(11,  5), array(11,  5)), //
555
-		array(array( 5,  1), array( 5,  5), array( 5,  7), array(11,  7)), // 15
556
-		array(array( 5,  1), array( 7,  3), array(15,  2), array( 3, 13)), //
557
-		array(array( 1,  5), array(10,  1), array( 1, 15), array( 2, 17)), //
558
-		array(array( 5,  1), array( 9,  4), array(17,  1), array( 2, 19)), //
559
-		array(array( 3,  4), array( 3, 11), array(17,  4), array( 9, 16)), //
560
-		array(array( 3,  5), array( 3, 13), array(15,  5), array(15, 10)), // 20
561
-		array(array( 4,  4), array(17,  0), array(17,  6), array(19,  6)), //
562
-		array(array( 2,  7), array(17,  0), array( 7, 16), array(34,  0)), //
563
-		array(array( 4,  5), array( 4, 14), array(11, 14), array(16, 14)), //
564
-		array(array( 6,  4), array( 6, 14), array(11, 16), array(30,  2)), //
565
-		array(array( 8,  4), array( 8, 13), array( 7, 22), array(22, 13)), // 25
566
-		array(array(10,  2), array(19,  4), array(28,  6), array(33,  4)), //
567
-		array(array( 8,  4), array(22,  3), array( 8, 26), array(12, 28)), //
568
-		array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), //
569
-		array(array( 7,  7), array(21,  7), array( 1, 37), array(19, 26)), //
570
-		array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), // 30
571
-		array(array(13,  3), array( 2, 29), array(42,  1), array(23, 28)), //
572
-		array(array(17,  0), array(10, 23), array(10, 35), array(19, 35)), //
573
-		array(array(17,  1), array(14, 21), array(29, 19), array(11, 46)), //
574
-		array(array(13,  6), array(14, 23), array(44,  7), array(59,  1)), //
575
-		array(array(12,  7), array(12, 26), array(39, 14), array(22, 41)), // 35
576
-		array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), //
577
-		array(array(17,  4), array(29, 14), array(49, 10), array(24, 46)), //
578
-		array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), //
579
-		array(array(20,  4), array(40,  7), array(43, 22), array(10, 67)), //
580
-		array(array(19,  6), array(18, 31), array(34, 34), array(20, 61))  // 40
540
+		array(array(0, 0), array(0, 0), array(0, 0), array(0, 0)), //
541
+		array(array(1, 0), array(1, 0), array(1, 0), array(1, 0)), //  1
542
+		array(array(1, 0), array(1, 0), array(1, 0), array(1, 0)), //
543
+		array(array(1, 0), array(1, 0), array(2, 0), array(2, 0)), //
544
+		array(array(1, 0), array(2, 0), array(2, 0), array(4, 0)), //
545
+		array(array(1, 0), array(2, 0), array(2, 2), array(2, 2)), //  5
546
+		array(array(2, 0), array(4, 0), array(4, 0), array(4, 0)), //
547
+		array(array(2, 0), array(4, 0), array(2, 4), array(4, 1)), //
548
+		array(array(2, 0), array(2, 2), array(4, 2), array(4, 2)), //
549
+		array(array(2, 0), array(3, 2), array(4, 4), array(4, 4)), //
550
+		array(array(2, 2), array(4, 1), array(6, 2), array(6, 2)), // 10
551
+		array(array(4, 0), array(1, 4), array(4, 4), array(3, 8)), //
552
+		array(array(2, 2), array(6, 2), array(4, 6), array(7, 4)), //
553
+		array(array(4, 0), array(8, 1), array(8, 4), array(12, 4)), //
554
+		array(array(3, 1), array(4, 5), array(11, 5), array(11, 5)), //
555
+		array(array(5, 1), array(5, 5), array(5, 7), array(11, 7)), // 15
556
+		array(array(5, 1), array(7, 3), array(15, 2), array(3, 13)), //
557
+		array(array(1, 5), array(10, 1), array(1, 15), array(2, 17)), //
558
+		array(array(5, 1), array(9, 4), array(17, 1), array(2, 19)), //
559
+		array(array(3, 4), array(3, 11), array(17, 4), array(9, 16)), //
560
+		array(array(3, 5), array(3, 13), array(15, 5), array(15, 10)), // 20
561
+		array(array(4, 4), array(17, 0), array(17, 6), array(19, 6)), //
562
+		array(array(2, 7), array(17, 0), array(7, 16), array(34, 0)), //
563
+		array(array(4, 5), array(4, 14), array(11, 14), array(16, 14)), //
564
+		array(array(6, 4), array(6, 14), array(11, 16), array(30, 2)), //
565
+		array(array(8, 4), array(8, 13), array(7, 22), array(22, 13)), // 25
566
+		array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), //
567
+		array(array(8, 4), array(22, 3), array(8, 26), array(12, 28)), //
568
+		array(array(3, 10), array(3, 23), array(4, 31), array(11, 31)), //
569
+		array(array(7, 7), array(21, 7), array(1, 37), array(19, 26)), //
570
+		array(array(5, 10), array(19, 10), array(15, 25), array(23, 25)), // 30
571
+		array(array(13, 3), array(2, 29), array(42, 1), array(23, 28)), //
572
+		array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), //
573
+		array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), //
574
+		array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), //
575
+		array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), // 35
576
+		array(array(6, 14), array(6, 34), array(46, 10), array(2, 64)), //
577
+		array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), //
578
+		array(array(4, 18), array(13, 32), array(48, 14), array(42, 32)), //
579
+		array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), //
580
+		array(array(19, 6), array(18, 31), array(34, 34), array(20, 61))  // 40
581 581
 	);
582 582
 
583 583
 	/**
@@ -587,9 +587,9 @@  discard block
 block discarded – undo
587 587
 	 * @protected
588 588
 	 */
589 589
 	protected $alignmentPattern = array(
590
-		array( 0,  0),
591
-		array( 0,  0), array(18,  0), array(22,  0), array(26,  0), array(30,  0), //  1- 5
592
-		array(34,  0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), //  6-10
590
+		array(0, 0),
591
+		array(0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), //  1- 5
592
+		array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), //  6-10
593 593
 		array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), // 11-15
594 594
 		array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), // 16-20
595 595
 		array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), // 21-25
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
 		foreach ($qrTab as $line) {
666 666
 			$arrAdd = array();
667 667
 			foreach (str_split($line) as $char) {
668
-				$arrAdd[] = ($char=='1')?1:0;
668
+				$arrAdd[] = ($char == '1') ? 1 : 0;
669 669
 			}
670 670
 			$barcode_array['bcode'][] = $arrAdd;
671 671
 		}
@@ -690,8 +690,8 @@  discard block
 block discarded – undo
690 690
 		$len = count($frame);
691 691
 		// the frame is square (width = height)
692 692
 		foreach ($frame as &$frameLine) {
693
-			for ($i=0; $i<$len; $i++) {
694
-				$frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
693
+			for ($i = 0; $i < $len; $i++) {
694
+				$frameLine[$i] = (ord($frameLine[$i]) & 1) ? '1' : '0';
695 695
 			}
696 696
 		}
697 697
 		return $frame;
@@ -741,10 +741,10 @@  discard block
 block discarded – undo
741 741
 		$this->dir = -1;
742 742
 		$this->bit = -1;
743 743
 		// inteleaved data and ecc codes
744
-		for ($i=0; $i < ($this->dataLength + $this->eccLength); $i++) {
744
+		for ($i = 0; $i < ($this->dataLength + $this->eccLength); $i++) {
745 745
 			$code = $this->getCode();
746 746
 			$bit = 0x80;
747
-			for ($j=0; $j<8; $j++) {
747
+			for ($j = 0; $j < 8; $j++) {
748 748
 				$addr = $this->getNextPosition();
749 749
 				$this->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
750 750
 				$bit = $bit >> 1;
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
 		}
753 753
 		// remainder bits
754 754
 		$j = $this->getRemainder($this->version);
755
-		for ($i=0; $i<$j; $i++) {
755
+		for ($i = 0; $i < $j; $i++) {
756 756
 			$addr = $this->getNextPosition();
757 757
 			$this->setFrameAt($addr, 0x02);
758 758
 		}
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 			if (QR_FIND_BEST_MASK) {
763 763
 				$masked = $this->mask($this->width, $this->frame, $this->level);
764 764
 			} else {
765
-				$masked = $this->makeMask($this->width, $this->frame, (intval(QR_DEFAULT_MASK) % 8), $this->level);
765
+				$masked = $this->makeMask($this->width, $this->frame, (intval(QR_DEFAULT_MASK)%8), $this->level);
766 766
 			}
767 767
 		} else {
768 768
 			$masked = $this->makeMask($this->width, $this->frame, $mask, $this->level);
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 			}
843 843
 			$this->x = $x;
844 844
 			$this->y = $y;
845
-		} while(ord($this->frame[$y][$x]) & 0x80);
845
+		} while (ord($this->frame[$y][$x]) & 0x80);
846 846
 		return array('x'=>$x, 'y'=>$y);
847 847
 	}
848 848
 
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
 		$dataPos = 0;
864 864
 		$eccPos = 0;
865 865
 		$endfor = $this->rsBlockNum1($spec);
866
-		for ($i=0; $i < $endfor; ++$i) {
866
+		for ($i = 0; $i < $endfor; ++$i) {
867 867
 			$ecc = array_slice($this->ecccode, $eccPos);
868 868
 			$this->rsblocks[$blockNo] = array();
869 869
 			$this->rsblocks[$blockNo]['dataLength'] = $dl;
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
 			$this->rsblocks[$blockNo]['eccLength'] = $el;
872 872
 			$ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc);
873 873
 			$this->rsblocks[$blockNo]['ecc'] = $ecc;
874
-			$this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
874
+			$this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc);
875 875
 			$dataPos += $dl;
876 876
 			$eccPos += $el;
877 877
 			$blockNo++;
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
 			return -1;
887 887
 		}
888 888
 		$endfor = $this->rsBlockNum2($spec);
889
-		for ($i=0; $i < $endfor; ++$i) {
889
+		for ($i = 0; $i < $endfor; ++$i) {
890 890
 			$ecc = array_slice($this->ecccode, $eccPos);
891 891
 			$this->rsblocks[$blockNo] = array();
892 892
 			$this->rsblocks[$blockNo]['dataLength'] = $dl;
@@ -908,15 +908,15 @@  discard block
 block discarded – undo
908 908
 	 */
909 909
 	protected function getCode() {
910 910
 		if ($this->count < $this->dataLength) {
911
-			$row = $this->count % $this->blocks;
912
-			$col = $this->count / $this->blocks;
911
+			$row = $this->count%$this->blocks;
912
+			$col = $this->count/$this->blocks;
913 913
 			if ($col >= $this->rsblocks[0]['dataLength']) {
914 914
 				$row += $this->b1;
915 915
 			}
916 916
 			$ret = $this->rsblocks[$row]['data'][$col];
917 917
 		} elseif ($this->count < $this->dataLength + $this->eccLength) {
918
-			$row = ($this->count - $this->dataLength) % $this->blocks;
919
-			$col = ($this->count - $this->dataLength) / $this->blocks;
918
+			$row = ($this->count - $this->dataLength)%$this->blocks;
919
+			$col = ($this->count - $this->dataLength)/$this->blocks;
920 920
 			$ret = $this->rsblocks[$row]['ecc'][$col];
921 921
 		} else {
922 922
 			return 0;
@@ -939,8 +939,8 @@  discard block
 block discarded – undo
939 939
 	 */
940 940
 	 protected function writeFormatInformation($width, &$frame, $mask, $level) {
941 941
 		$blacks = 0;
942
-		$format =  $this->getFormatInfo($mask, $level);
943
-		for ($i=0; $i<8; ++$i) {
942
+		$format = $this->getFormatInfo($mask, $level);
943
+		for ($i = 0; $i < 8; ++$i) {
944 944
 			if ($format & 1) {
945 945
 				$blacks += 2;
946 946
 				$v = 0x85;
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
 			}
956 956
 			$format = $format >> 1;
957 957
 		}
958
-		for ($i=0; $i<7; ++$i) {
958
+		for ($i = 0; $i < 7; ++$i) {
959 959
 		if ($format & 1) {
960 960
 			$blacks += 2;
961 961
 			$v = 0x85;
@@ -1000,7 +1000,7 @@  discard block
 block discarded – undo
1000 1000
 	 * @return int mask
1001 1001
 	 */
1002 1002
 	 protected function mask2($x, $y) {
1003
-		return ($x % 3);
1003
+		return ($x%3);
1004 1004
 	}
1005 1005
 
1006 1006
 	/**
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
 	 * @return int mask
1011 1011
 	 */
1012 1012
 	 protected function mask3($x, $y) {
1013
-		return ($x + $y) % 3;
1013
+		return ($x + $y)%3;
1014 1014
 	}
1015 1015
 
1016 1016
 	/**
@@ -1020,7 +1020,7 @@  discard block
 block discarded – undo
1020 1020
 	 * @return int mask
1021 1021
 	 */
1022 1022
 	 protected function mask4($x, $y) {
1023
-		return (((int)($y / 2)) + ((int)($x / 3))) & 1;
1023
+		return (((int)($y/2)) + ((int)($x/3))) & 1;
1024 1024
 	}
1025 1025
 
1026 1026
 	/**
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
 	 * @return int mask
1031 1031
 	 */
1032 1032
 	 protected function mask5($x, $y) {
1033
-		return (($x * $y) & 1) + ($x * $y) % 3;
1033
+		return (($x*$y) & 1) + ($x*$y)%3;
1034 1034
 	}
1035 1035
 
1036 1036
 	/**
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
 	 * @return int mask
1041 1041
 	 */
1042 1042
 	 protected function mask6($x, $y) {
1043
-		return ((($x * $y) & 1) + ($x * $y) % 3) & 1;
1043
+		return ((($x*$y) & 1) + ($x*$y)%3) & 1;
1044 1044
 	}
1045 1045
 
1046 1046
 	/**
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
 	 * @return int mask
1051 1051
 	 */
1052 1052
 	 protected function mask7($x, $y) {
1053
-		return ((($x * $y) % 3) + (($x + $y) & 1)) & 1;
1053
+		return ((($x*$y)%3) + (($x + $y) & 1)) & 1;
1054 1054
 	}
1055 1055
 
1056 1056
 	/**
@@ -1062,13 +1062,13 @@  discard block
 block discarded – undo
1062 1062
 	 */
1063 1063
 	protected function generateMaskNo($maskNo, $width, $frame) {
1064 1064
 		$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
1065
-		for ($y=0; $y<$width; ++$y) {
1066
-			for ($x=0; $x<$width; ++$x) {
1065
+		for ($y = 0; $y < $width; ++$y) {
1066
+			for ($x = 0; $x < $width; ++$x) {
1067 1067
 				if (ord($frame[$y][$x]) & 0x80) {
1068 1068
 					$bitMask[$y][$x] = 0;
1069 1069
 				} else {
1070 1070
 					$maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
1071
-					$bitMask[$y][$x] = ($maskFunc == 0)?1:0;
1071
+					$bitMask[$y][$x] = ($maskFunc == 0) ? 1 : 0;
1072 1072
 				}
1073 1073
 			}
1074 1074
 		}
@@ -1084,7 +1084,7 @@  discard block
 block discarded – undo
1084 1084
 	 * @param $maskGenOnly (boolean)
1085 1085
 	 * @return int b
1086 1086
 	 */
1087
-	 protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false) {
1087
+	 protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false) {
1088 1088
 		$b = 0;
1089 1089
 		$bitMask = array();
1090 1090
 		$bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
@@ -1092,8 +1092,8 @@  discard block
 block discarded – undo
1092 1092
 			return;
1093 1093
 		}
1094 1094
 		$d = $s;
1095
-		for ($y=0; $y<$width; ++$y) {
1096
-			for ($x=0; $x<$width; ++$x) {
1095
+		for ($y = 0; $y < $width; ++$y) {
1096
+			for ($x = 0; $x < $width; ++$x) {
1097 1097
 				if ($bitMask[$y][$x] == 1) {
1098 1098
 					$d[$y][$x] = chr(ord($s[$y][$x]) ^ ((int)($bitMask[$y][$x])));
1099 1099
 				}
@@ -1125,20 +1125,20 @@  discard block
 block discarded – undo
1125 1125
 	 */
1126 1126
 	 protected function calcN1N3($length) {
1127 1127
 		$demerit = 0;
1128
-		for ($i=0; $i<$length; ++$i) {
1128
+		for ($i = 0; $i < $length; ++$i) {
1129 1129
 			if ($this->runLength[$i] >= 5) {
1130 1130
 				$demerit += (N1 + ($this->runLength[$i] - 5));
1131 1131
 			}
1132 1132
 			if ($i & 1) {
1133
-				if (($i >= 3) AND ($i < ($length-2)) AND ($this->runLength[$i] % 3 == 0)) {
1134
-					$fact = (int)($this->runLength[$i] / 3);
1135
-					if (($this->runLength[$i-2] == $fact)
1136
-						AND ($this->runLength[$i-1] == $fact)
1137
-						AND ($this->runLength[$i+1] == $fact)
1138
-						AND ($this->runLength[$i+2] == $fact)) {
1139
-						if (($this->runLength[$i-3] < 0) OR ($this->runLength[$i-3] >= (4 * $fact))) {
1133
+				if (($i >= 3) AND ($i < ($length - 2)) AND ($this->runLength[$i]%3 == 0)) {
1134
+					$fact = (int)($this->runLength[$i]/3);
1135
+					if (($this->runLength[$i - 2] == $fact)
1136
+						AND ($this->runLength[$i - 1] == $fact)
1137
+						AND ($this->runLength[$i + 1] == $fact)
1138
+						AND ($this->runLength[$i + 2] == $fact)) {
1139
+						if (($this->runLength[$i - 3] < 0) OR ($this->runLength[$i - 3] >= (4*$fact))) {
1140 1140
 							$demerit += N3;
1141
-						} elseif ((($i+3) >= $length) OR ($this->runLength[$i+3] >= (4 * $fact))) {
1141
+						} elseif ((($i + 3) >= $length) OR ($this->runLength[$i + 3] >= (4*$fact))) {
1142 1142
 							$demerit += N3;
1143 1143
 						}
1144 1144
 					}
@@ -1157,17 +1157,17 @@  discard block
 block discarded – undo
1157 1157
 	 protected function evaluateSymbol($width, $frame) {
1158 1158
 		$head = 0;
1159 1159
 		$demerit = 0;
1160
-		for ($y=0; $y<$width; ++$y) {
1160
+		for ($y = 0; $y < $width; ++$y) {
1161 1161
 			$head = 0;
1162 1162
 			$this->runLength[0] = 1;
1163 1163
 			$frameY = $frame[$y];
1164 1164
 			if ($y > 0) {
1165
-				$frameYM = $frame[$y-1];
1165
+				$frameYM = $frame[$y - 1];
1166 1166
 			}
1167
-			for ($x=0; $x<$width; ++$x) {
1167
+			for ($x = 0; $x < $width; ++$x) {
1168 1168
 				if (($x > 0) AND ($y > 0)) {
1169
-					$b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
1170
-					$w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
1169
+					$b22 = ord($frameY[$x]) & ord($frameY[$x - 1]) & ord($frameYM[$x]) & ord($frameYM[$x - 1]);
1170
+					$w22 = ord($frameY[$x]) | ord($frameY[$x - 1]) | ord($frameYM[$x]) | ord($frameYM[$x - 1]);
1171 1171
 					if (($b22 | ($w22 ^ 1)) & 1) {
1172 1172
 						$demerit += N2;
1173 1173
 					}
@@ -1177,7 +1177,7 @@  discard block
 block discarded – undo
1177 1177
 					$head = 1;
1178 1178
 					$this->runLength[$head] = 1;
1179 1179
 				} elseif ($x > 0) {
1180
-					if ((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
1180
+					if ((ord($frameY[$x]) ^ ord($frameY[$x - 1])) & 1) {
1181 1181
 						$head++;
1182 1182
 						$this->runLength[$head] = 1;
1183 1183
 					} else {
@@ -1185,18 +1185,18 @@  discard block
 block discarded – undo
1185 1185
 					}
1186 1186
 				}
1187 1187
 			}
1188
-			$demerit += $this->calcN1N3($head+1);
1188
+			$demerit += $this->calcN1N3($head + 1);
1189 1189
 		}
1190
-		for ($x=0; $x<$width; ++$x) {
1190
+		for ($x = 0; $x < $width; ++$x) {
1191 1191
 			$head = 0;
1192 1192
 			$this->runLength[0] = 1;
1193
-			for ($y=0; $y<$width; ++$y) {
1193
+			for ($y = 0; $y < $width; ++$y) {
1194 1194
 				if (($y == 0) AND (ord($frame[$y][$x]) & 1)) {
1195 1195
 					$this->runLength[0] = -1;
1196 1196
 					$head = 1;
1197 1197
 					$this->runLength[$head] = 1;
1198 1198
 				} elseif ($y > 0) {
1199
-					if ((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
1199
+					if ((ord($frame[$y][$x]) ^ ord($frame[$y - 1][$x])) & 1) {
1200 1200
 						$head++;
1201 1201
 						$this->runLength[$head] = 1;
1202 1202
 					} else {
@@ -1204,7 +1204,7 @@  discard block
 block discarded – undo
1204 1204
 					}
1205 1205
 				}
1206 1206
 			}
1207
-			$demerit += $this->calcN1N3($head+1);
1207
+			$demerit += $this->calcN1N3($head + 1);
1208 1208
 		}
1209 1209
 		return $demerit;
1210 1210
 	}
@@ -1222,9 +1222,9 @@  discard block
 block discarded – undo
1222 1222
 		$bestMask = array();
1223 1223
 		$checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7);
1224 1224
 		if (QR_FIND_FROM_RANDOM !== false) {
1225
-			$howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9);
1226
-			for ($i = 0; $i <  $howManuOut; ++$i) {
1227
-				$remPos = rand (0, count($checked_masks)-1);
1225
+			$howManuOut = 8 - (QR_FIND_FROM_RANDOM%9);
1226
+			for ($i = 0; $i < $howManuOut; ++$i) {
1227
+				$remPos = rand(0, count($checked_masks) - 1);
1228 1228
 				unset($checked_masks[$remPos]);
1229 1229
 				$checked_masks = array_values($checked_masks);
1230 1230
 			}
@@ -1236,8 +1236,8 @@  discard block
 block discarded – undo
1236 1236
 			$blacks = 0;
1237 1237
 			$blacks  = $this->makeMaskNo($i, $width, $frame, $mask);
1238 1238
 			$blacks += $this->writeFormatInformation($width, $mask, $i, $level);
1239
-			$blacks  = (int)(100 * $blacks / ($width * $width));
1240
-			$demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
1239
+			$blacks  = (int)(100*$blacks/($width*$width));
1240
+			$demerit = (int)((int)(abs($blacks - 50)/5)*N4);
1241 1241
 			$demerit += $this->evaluateSymbol($width, $mask);
1242 1242
 			if ($demerit < $minDemerit) {
1243 1243
 				$minDemerit = $demerit;
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
 		if ($pos >= strlen($str)) {
1263 1263
 			return false;
1264 1264
 		}
1265
-		return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
1265
+		return ((ord($str[$pos]) >= ord('0')) && (ord($str[$pos]) <= ord('9')));
1266 1266
 	}
1267 1267
 
1268 1268
 	/**
@@ -1293,8 +1293,8 @@  discard block
 block discarded – undo
1293 1293
 		} elseif ($this->isalnumat($this->dataStr, $pos)) {
1294 1294
 			return QR_MODE_AN;
1295 1295
 		} elseif ($this->hint == QR_MODE_KJ) {
1296
-			if ($pos+1 < strlen($this->dataStr)) {
1297
-				$d = $this->dataStr[$pos+1];
1296
+			if ($pos + 1 < strlen($this->dataStr)) {
1297
+				$d = $this->dataStr[$pos + 1];
1298 1298
 				$word = (ord($c) << 8) | ord($d);
1299 1299
 				if (($word >= 0x8140 && $word <= 0x9ffc) OR ($word >= 0xe040 && $word <= 0xebbf)) {
1300 1300
 					return QR_MODE_KJ;
@@ -1311,7 +1311,7 @@  discard block
 block discarded – undo
1311 1311
 	 protected function eatNum() {
1312 1312
 		$ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
1313 1313
 		$p = 0;
1314
-		while($this->isdigitat($this->dataStr, $p)) {
1314
+		while ($this->isdigitat($this->dataStr, $p)) {
1315 1315
 			$p++;
1316 1316
 		}
1317 1317
 		$run = $p;
@@ -1327,7 +1327,7 @@  discard block
 block discarded – undo
1327 1327
 		if ($mode == QR_MODE_AN) {
1328 1328
 			$dif = $this->estimateBitsModeNum($run) + 4 + $ln
1329 1329
 			+ $this->estimateBitsModeAn(1)        // + 4 + la
1330
-			- $this->estimateBitsModeAn($run + 1);// - 4 - la
1330
+			- $this->estimateBitsModeAn($run + 1); // - 4 - la
1331 1331
 			if ($dif > 0) {
1332 1332
 				return $this->eatAn();
1333 1333
 			}
@@ -1341,13 +1341,13 @@  discard block
 block discarded – undo
1341 1341
 	 * @return int run
1342 1342
 	 */
1343 1343
 	 protected function eatAn() {
1344
-		$la = $this->lengthIndicator(QR_MODE_AN,  $this->version);
1344
+		$la = $this->lengthIndicator(QR_MODE_AN, $this->version);
1345 1345
 		$ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
1346
-		$p =1 ;
1347
-		while($this->isalnumat($this->dataStr, $p)) {
1346
+		$p = 1;
1347
+		while ($this->isalnumat($this->dataStr, $p)) {
1348 1348
 			if ($this->isdigitat($this->dataStr, $p)) {
1349 1349
 				$q = $p;
1350
-				while($this->isdigitat($this->dataStr, $q)) {
1350
+				while ($this->isdigitat($this->dataStr, $q)) {
1351 1351
 					$q++;
1352 1352
 				}
1353 1353
 				$dif = $this->estimateBitsModeAn($p) // + 4 + la
@@ -1381,7 +1381,7 @@  discard block
 block discarded – undo
1381 1381
 	 */
1382 1382
 	 protected function eatKanji() {
1383 1383
 		$p = 0;
1384
-		while($this->identifyMode($p) == QR_MODE_KJ) {
1384
+		while ($this->identifyMode($p) == QR_MODE_KJ) {
1385 1385
 			$p += 2;
1386 1386
 		}
1387 1387
 		$this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, str_split($this->dataStr));
@@ -1397,14 +1397,14 @@  discard block
 block discarded – undo
1397 1397
 		$ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
1398 1398
 		$p = 1;
1399 1399
 		$dataStrLen = strlen($this->dataStr);
1400
-		while($p < $dataStrLen) {
1400
+		while ($p < $dataStrLen) {
1401 1401
 			$mode = $this->identifyMode($p);
1402 1402
 			if ($mode == QR_MODE_KJ) {
1403 1403
 				break;
1404 1404
 			}
1405 1405
 			if ($mode == QR_MODE_NM) {
1406 1406
 				$q = $p;
1407
-				while($this->isdigitat($this->dataStr, $q)) {
1407
+				while ($this->isdigitat($this->dataStr, $q)) {
1408 1408
 					$q++;
1409 1409
 				}
1410 1410
 				$dif = $this->estimateBitsMode8($p) // + 4 + l8
@@ -1417,7 +1417,7 @@  discard block
 block discarded – undo
1417 1417
 				}
1418 1418
 			} elseif ($mode == QR_MODE_AN) {
1419 1419
 				$q = $p;
1420
-				while($this->isalnumat($this->dataStr, $q)) {
1420
+				while ($this->isalnumat($this->dataStr, $q)) {
1421 1421
 					$q++;
1422 1422
 				}
1423 1423
 				$dif = $this->estimateBitsMode8($p)  // + 4 + l8
@@ -1509,7 +1509,7 @@  discard block
 block discarded – undo
1509 1509
 	 * @param $bstream (array)
1510 1510
 	 * @return array input item
1511 1511
 	 */
1512
-	 protected function newInputItem($mode, $size, $data, $bstream=null) {
1512
+	 protected function newInputItem($mode, $size, $data, $bstream = null) {
1513 1513
 		$setData = array_slice($data, 0, $size);
1514 1514
 		if (count($setData) < $size) {
1515 1515
 			$setData = array_merge($setData, array_fill(0, ($size - count($setData)), 0));
@@ -1532,23 +1532,23 @@  discard block
 block discarded – undo
1532 1532
 	 * @return array input item
1533 1533
 	 */
1534 1534
 	 protected function encodeModeNum($inputitem, $version) {
1535
-		$words = (int)($inputitem['size'] / 3);
1535
+		$words = (int)($inputitem['size']/3);
1536 1536
 		$inputitem['bstream'] = array();
1537 1537
 		$val = 0x1;
1538 1538
 		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val);
1539 1539
 		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_NM, $version), $inputitem['size']);
1540
-		for ($i=0; $i < $words; ++$i) {
1541
-			$val  = (ord($inputitem['data'][$i*3  ]) - ord('0')) * 100;
1542
-			$val += (ord($inputitem['data'][$i*3+1]) - ord('0')) * 10;
1543
-			$val += (ord($inputitem['data'][$i*3+2]) - ord('0'));
1540
+		for ($i = 0; $i < $words; ++$i) {
1541
+			$val  = (ord($inputitem['data'][$i*3]) - ord('0'))*100;
1542
+			$val += (ord($inputitem['data'][$i*3 + 1]) - ord('0'))*10;
1543
+			$val += (ord($inputitem['data'][$i*3 + 2]) - ord('0'));
1544 1544
 			$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 10, $val);
1545 1545
 		}
1546
-		if ($inputitem['size'] - $words * 3 == 1) {
1546
+		if ($inputitem['size'] - $words*3 == 1) {
1547 1547
 			$val = ord($inputitem['data'][$words*3]) - ord('0');
1548 1548
 			$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val);
1549
-		} elseif (($inputitem['size'] - ($words * 3)) == 2) {
1550
-			$val  = (ord($inputitem['data'][$words*3  ]) - ord('0')) * 10;
1551
-			$val += (ord($inputitem['data'][$words*3+1]) - ord('0'));
1549
+		} elseif (($inputitem['size'] - ($words*3)) == 2) {
1550
+			$val  = (ord($inputitem['data'][$words*3]) - ord('0'))*10;
1551
+			$val += (ord($inputitem['data'][$words*3 + 1]) - ord('0'));
1552 1552
 			$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 7, $val);
1553 1553
 		}
1554 1554
 		return $inputitem;
@@ -1561,17 +1561,17 @@  discard block
 block discarded – undo
1561 1561
 	 * @return array input item
1562 1562
 	 */
1563 1563
 	 protected function encodeModeAn($inputitem, $version) {
1564
-		$words = (int)($inputitem['size'] / 2);
1564
+		$words = (int)($inputitem['size']/2);
1565 1565
 		$inputitem['bstream'] = array();
1566 1566
 		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x02);
1567 1567
 		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_AN, $version), $inputitem['size']);
1568
-		for ($i=0; $i < $words; ++$i) {
1569
-			$val  = (int)($this->lookAnTable(ord($inputitem['data'][$i*2])) * 45);
1570
-			$val += (int)($this->lookAnTable(ord($inputitem['data'][($i*2)+1])));
1568
+		for ($i = 0; $i < $words; ++$i) {
1569
+			$val  = (int)($this->lookAnTable(ord($inputitem['data'][$i*2]))*45);
1570
+			$val += (int)($this->lookAnTable(ord($inputitem['data'][($i*2) + 1])));
1571 1571
 			$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 11, $val);
1572 1572
 		}
1573 1573
 		if ($inputitem['size'] & 1) {
1574
-			$val = $this->lookAnTable(ord($inputitem['data'][($words * 2)]));
1574
+			$val = $this->lookAnTable(ord($inputitem['data'][($words*2)]));
1575 1575
 			$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 6, $val);
1576 1576
 		}
1577 1577
 		return $inputitem;
@@ -1587,7 +1587,7 @@  discard block
 block discarded – undo
1587 1587
 		$inputitem['bstream'] = array();
1588 1588
 		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x4);
1589 1589
 		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_8B, $version), $inputitem['size']);
1590
-		for ($i=0; $i < $inputitem['size']; ++$i) {
1590
+		for ($i = 0; $i < $inputitem['size']; ++$i) {
1591 1591
 			$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][$i]));
1592 1592
 		}
1593 1593
 		return $inputitem;
@@ -1602,15 +1602,15 @@  discard block
 block discarded – undo
1602 1602
 	 protected function encodeModeKanji($inputitem, $version) {
1603 1603
 		$inputitem['bstream'] = array();
1604 1604
 		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x8);
1605
-		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_KJ, $version), (int)($inputitem['size'] / 2));
1606
-		for ($i=0; $i<$inputitem['size']; $i+=2) {
1607
-			$val = (ord($inputitem['data'][$i]) << 8) | ord($inputitem['data'][$i+1]);
1605
+		$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_KJ, $version), (int)($inputitem['size']/2));
1606
+		for ($i = 0; $i < $inputitem['size']; $i += 2) {
1607
+			$val = (ord($inputitem['data'][$i]) << 8) | ord($inputitem['data'][$i + 1]);
1608 1608
 			if ($val <= 0x9ffc) {
1609 1609
 				$val -= 0x8140;
1610 1610
 			} else {
1611 1611
 				$val -= 0xc140;
1612 1612
 			}
1613
-			$h = ($val >> 8) * 0xc0;
1613
+			$h = ($val >> 8)*0xc0;
1614 1614
 			$val = ($val & 0xff) + $h;
1615 1615
 			$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 13, $val);
1616 1616
 		}
@@ -1649,7 +1649,7 @@  discard block
 block discarded – undo
1649 1649
 			$inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st1['bstream']);
1650 1650
 			$inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st2['bstream']);
1651 1651
 		} else {
1652
-			switch($inputitem['mode']) {
1652
+			switch ($inputitem['mode']) {
1653 1653
 				case QR_MODE_NM: {
1654 1654
 					$inputitem = $this->encodeModeNum($inputitem, $version);
1655 1655
 					break;
@@ -1730,7 +1730,7 @@  discard block
 block discarded – undo
1730 1730
 		$parity = 0;
1731 1731
 		foreach ($items as $item) {
1732 1732
 			if ($item['mode'] != QR_MODE_ST) {
1733
-				for ($i=$item['size']-1; $i>=0; --$i) {
1733
+				for ($i = $item['size'] - 1; $i >= 0; --$i) {
1734 1734
 					$parity ^= $item['data'][$i];
1735 1735
 				}
1736 1736
 			}
@@ -1745,8 +1745,8 @@  discard block
 block discarded – undo
1745 1745
 	 * @return boolean true or false
1746 1746
 	 */
1747 1747
 	 protected function checkModeNum($size, $data) {
1748
-		for ($i=0; $i<$size; ++$i) {
1749
-			if ((ord($data[$i]) < ord('0')) OR (ord($data[$i]) > ord('9'))){
1748
+		for ($i = 0; $i < $size; ++$i) {
1749
+			if ((ord($data[$i]) < ord('0')) OR (ord($data[$i]) > ord('9'))) {
1750 1750
 				return false;
1751 1751
 			}
1752 1752
 		}
@@ -1759,7 +1759,7 @@  discard block
 block discarded – undo
1759 1759
 	 * @return value
1760 1760
 	 */
1761 1761
 	protected function lookAnTable($c) {
1762
-		return (($c > 127)?-1:$this->anTable[$c]);
1762
+		return (($c > 127) ?-1 : $this->anTable[$c]);
1763 1763
 	}
1764 1764
 
1765 1765
 	/**
@@ -1769,7 +1769,7 @@  discard block
 block discarded – undo
1769 1769
 	 * @return boolean true or false
1770 1770
 	 */
1771 1771
 	 protected function checkModeAn($size, $data) {
1772
-		for ($i=0; $i<$size; ++$i) {
1772
+		for ($i = 0; $i < $size; ++$i) {
1773 1773
 			if ($this->lookAnTable(ord($data[$i])) == -1) {
1774 1774
 				return false;
1775 1775
 			}
@@ -1783,9 +1783,9 @@  discard block
 block discarded – undo
1783 1783
 	 * @return int number of bits
1784 1784
 	 */
1785 1785
 	 protected function estimateBitsModeNum($size) {
1786
-		$w = (int)($size / 3);
1787
-		$bits = ($w * 10);
1788
-		switch($size - ($w * 3)) {
1786
+		$w = (int)($size/3);
1787
+		$bits = ($w*10);
1788
+		switch ($size - ($w*3)) {
1789 1789
 			case 1: {
1790 1790
 				$bits += 4;
1791 1791
 				break;
@@ -1804,7 +1804,7 @@  discard block
 block discarded – undo
1804 1804
 	 * @return int number of bits
1805 1805
 	 */
1806 1806
 	 protected function estimateBitsModeAn($size) {
1807
-		$bits = (int)($size * 5.5); // (size / 2 ) * 11
1807
+		$bits = (int)($size*5.5); // (size / 2 ) * 11
1808 1808
 		if ($size & 1) {
1809 1809
 			$bits += 6;
1810 1810
 		}
@@ -1817,7 +1817,7 @@  discard block
 block discarded – undo
1817 1817
 	 * @return int number of bits
1818 1818
 	 */
1819 1819
 	 protected function estimateBitsMode8($size) {
1820
-		return (int)($size * 8);
1820
+		return (int)($size*8);
1821 1821
 	}
1822 1822
 
1823 1823
 	/**
@@ -1826,7 +1826,7 @@  discard block
 block discarded – undo
1826 1826
 	 * @return int number of bits
1827 1827
 	 */
1828 1828
 	 protected function estimateBitsModeKanji($size) {
1829
-		return (int)($size * 6.5); // (size / 2 ) * 13
1829
+		return (int)($size*6.5); // (size / 2 ) * 13
1830 1830
 	}
1831 1831
 
1832 1832
 	/**
@@ -1839,8 +1839,8 @@  discard block
 block discarded – undo
1839 1839
 		if ($size & 1) {
1840 1840
 			return false;
1841 1841
 		}
1842
-		for ($i=0; $i<$size; $i+=2) {
1843
-			$val = (ord($data[$i]) << 8) | ord($data[$i+1]);
1842
+		for ($i = 0; $i < $size; $i += 2) {
1843
+			$val = (ord($data[$i]) << 8) | ord($data[$i + 1]);
1844 1844
 			if (($val < 0x8140) OR (($val > 0x9ffc) AND ($val < 0xe040)) OR ($val > 0xebbf)) {
1845 1845
 				return false;
1846 1846
 			}
@@ -1859,7 +1859,7 @@  discard block
 block discarded – undo
1859 1859
 		if ($size <= 0) {
1860 1860
 			return false;
1861 1861
 		}
1862
-		switch($mode) {
1862
+		switch ($mode) {
1863 1863
 			case QR_MODE_NM: {
1864 1864
 				return $this->checkModeNum($size, $data);
1865 1865
 			}
@@ -1894,7 +1894,7 @@  discard block
 block discarded – undo
1894 1894
 			$version = 1;
1895 1895
 		}
1896 1896
 		foreach ($items as $item) {
1897
-			switch($item['mode']) {
1897
+			switch ($item['mode']) {
1898 1898
 				case QR_MODE_NM: {
1899 1899
 					$bits = $this->estimateBitsModeNum($item['size']);
1900 1900
 					break;
@@ -1920,8 +1920,8 @@  discard block
 block discarded – undo
1920 1920
 			}
1921 1921
 			$l = $this->lengthIndicator($item['mode'], $version);
1922 1922
 			$m = 1 << $l;
1923
-			$num = (int)(($item['size'] + $m - 1) / $m);
1924
-			$bits += $num * (4 + $l);
1923
+			$num = (int)(($item['size'] + $m - 1)/$m);
1924
+			$bits += $num*(4 + $l);
1925 1925
 		}
1926 1926
 		return $bits;
1927 1927
 	}
@@ -1937,7 +1937,7 @@  discard block
 block discarded – undo
1937 1937
 		do {
1938 1938
 			$prev = $version;
1939 1939
 			$bits = $this->estimateBitStreamSize($items, $prev);
1940
-			$version = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level);
1940
+			$version = $this->getMinimumVersion((int)(($bits + 7)/8), $this->level);
1941 1941
 			if ($version < 0) {
1942 1942
 				return -1;
1943 1943
 			}
@@ -1954,11 +1954,11 @@  discard block
 block discarded – undo
1954 1954
 	 */
1955 1955
 	 protected function lengthOfCode($mode, $version, $bits) {
1956 1956
 		$payload = $bits - 4 - $this->lengthIndicator($mode, $version);
1957
-		switch($mode) {
1957
+		switch ($mode) {
1958 1958
 			case QR_MODE_NM: {
1959
-				$chunks = (int)($payload / 10);
1960
-				$remain = $payload - $chunks * 10;
1961
-				$size = $chunks * 3;
1959
+				$chunks = (int)($payload/10);
1960
+				$remain = $payload - $chunks*10;
1961
+				$size = $chunks*3;
1962 1962
 				if ($remain >= 7) {
1963 1963
 					$size += 2;
1964 1964
 				} elseif ($remain >= 4) {
@@ -1967,24 +1967,24 @@  discard block
 block discarded – undo
1967 1967
 				break;
1968 1968
 			}
1969 1969
 			case QR_MODE_AN: {
1970
-				$chunks = (int)($payload / 11);
1971
-				$remain = $payload - $chunks * 11;
1972
-				$size = $chunks * 2;
1970
+				$chunks = (int)($payload/11);
1971
+				$remain = $payload - $chunks*11;
1972
+				$size = $chunks*2;
1973 1973
 				if ($remain >= 6) {
1974 1974
 					++$size;
1975 1975
 				}
1976 1976
 				break;
1977 1977
 			}
1978 1978
 			case QR_MODE_8B: {
1979
-				$size = (int)($payload / 8);
1979
+				$size = (int)($payload/8);
1980 1980
 				break;
1981 1981
 			}
1982 1982
 			case QR_MODE_KJ: {
1983
-				$size = (int)(($payload / 13) * 2);
1983
+				$size = (int)(($payload/13)*2);
1984 1984
 				break;
1985 1985
 			}
1986 1986
 			case QR_MODE_ST: {
1987
-				$size = (int)($payload / 8);
1987
+				$size = (int)($payload/8);
1988 1988
 				break;
1989 1989
 			}
1990 1990
 			default: {
@@ -2034,7 +2034,7 @@  discard block
 block discarded – undo
2034 2034
 			if ($bits < 0) {
2035 2035
 				return -1;
2036 2036
 			}
2037
-			$ver = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level);
2037
+			$ver = $this->getMinimumVersion((int)(($bits + 7)/8), $this->level);
2038 2038
 			if ($ver < 0) {
2039 2039
 				return -1;
2040 2040
 			} elseif ($ver > $this->version) {
@@ -2057,7 +2057,7 @@  discard block
 block discarded – undo
2057 2057
 	 	}
2058 2058
 		$bits = count($bstream);
2059 2059
 		$maxwords = $this->getDataLength($this->version, $this->level);
2060
-		$maxbits = $maxwords * 8;
2060
+		$maxbits = $maxwords*8;
2061 2061
 		if ($maxbits == $bits) {
2062 2062
 			return $bstream;
2063 2063
 		}
@@ -2065,14 +2065,14 @@  discard block
 block discarded – undo
2065 2065
 			return $this->appendNum($bstream, $maxbits - $bits, 0);
2066 2066
 		}
2067 2067
 		$bits += 4;
2068
-		$words = (int)(($bits + 7) / 8);
2068
+		$words = (int)(($bits + 7)/8);
2069 2069
 		$padding = array();
2070
-		$padding = $this->appendNum($padding, $words * 8 - $bits + 4, 0);
2070
+		$padding = $this->appendNum($padding, $words*8 - $bits + 4, 0);
2071 2071
 		$padlen = $maxwords - $words;
2072 2072
 		if ($padlen > 0) {
2073 2073
 			$padbuf = array();
2074
-			for ($i=0; $i<$padlen; ++$i) {
2075
-				$padbuf[$i] = ($i&1)?0x11:0xec;
2074
+			for ($i = 0; $i < $padlen; ++$i) {
2075
+				$padbuf[$i] = ($i & 1) ? 0x11 : 0xec;
2076 2076
 			}
2077 2077
 			$padding = $this->appendBytes($padding, $padlen, $padbuf);
2078 2078
 		}
@@ -2138,7 +2138,7 @@  discard block
 block discarded – undo
2138 2138
 	 protected function newFromNum($bits, $num) {
2139 2139
 		$bstream = $this->allocate($bits);
2140 2140
 		$mask = 1 << ($bits - 1);
2141
-		for ($i=0; $i<$bits; ++$i) {
2141
+		for ($i = 0; $i < $bits; ++$i) {
2142 2142
 			if ($num & $mask) {
2143 2143
 				$bstream[$i] = 1;
2144 2144
 			} else {
@@ -2156,11 +2156,11 @@  discard block
 block discarded – undo
2156 2156
 	 * @return array bitstream
2157 2157
 	 */
2158 2158
 	 protected function newFromBytes($size, $data) {
2159
-		$bstream = $this->allocate($size * 8);
2160
-		$p=0;
2161
-		for ($i=0; $i<$size; ++$i) {
2159
+		$bstream = $this->allocate($size*8);
2160
+		$p = 0;
2161
+		for ($i = 0; $i < $size; ++$i) {
2162 2162
 			$mask = 0x80;
2163
-			for ($j=0; $j<8; ++$j) {
2163
+			for ($j = 0; $j < 8; ++$j) {
2164 2164
 				if ($data[$i] & $mask) {
2165 2165
 					$bstream[$p] = 1;
2166 2166
 				} else {
@@ -2232,12 +2232,12 @@  discard block
 block discarded – undo
2232 2232
 		if ($size == 0) {
2233 2233
 			return array();
2234 2234
 		}
2235
-		$data = array_fill(0, (int)(($size + 7) / 8), 0);
2236
-		$bytes = (int)($size / 8);
2235
+		$data = array_fill(0, (int)(($size + 7)/8), 0);
2236
+		$bytes = (int)($size/8);
2237 2237
 		$p = 0;
2238
-		for ($i=0; $i<$bytes; $i++) {
2238
+		for ($i = 0; $i < $bytes; $i++) {
2239 2239
 			$v = 0;
2240
-			for ($j=0; $j<8; $j++) {
2240
+			for ($j = 0; $j < 8; $j++) {
2241 2241
 				$v = $v << 1;
2242 2242
 				$v |= $bstream[$p];
2243 2243
 				$p++;
@@ -2246,7 +2246,7 @@  discard block
 block discarded – undo
2246 2246
 		}
2247 2247
 		if ($size & 7) {
2248 2248
 			$v = 0;
2249
-			for ($j=0; $j<($size & 7); $j++) {
2249
+			for ($j = 0; $j < ($size & 7); $j++) {
2250 2250
 				$v = $v << 1;
2251 2251
 				$v |= $bstream[$p];
2252 2252
 				$p++;
@@ -2269,8 +2269,8 @@  discard block
 block discarded – undo
2269 2269
 	 * @param $replLen (int) length of the repl string
2270 2270
 	 * @return array srctab
2271 2271
 	 */
2272
-	 protected function qrstrset($srctab, $x, $y, $repl, $replLen=false) {
2273
-		$srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
2272
+	 protected function qrstrset($srctab, $x, $y, $repl, $replLen = false) {
2273
+		$srctab[$y] = substr_replace($srctab[$y], ($replLen !== false) ? substr($repl, 0, $replLen) : $repl, $x, ($replLen !== false) ? $replLen : strlen($repl));
2274 2274
 		return $srctab;
2275 2275
 	}
2276 2276
 
@@ -2290,7 +2290,7 @@  discard block
 block discarded – undo
2290 2290
 	 * @param $level (int) error correction level
2291 2291
 	 * @return int ECC size (bytes)
2292 2292
 	 */
2293
-	protected function getECCLength($version, $level){
2293
+	protected function getECCLength($version, $level) {
2294 2294
 		return $this->capacity[$version][QRCAP_EC][$level];
2295 2295
 	}
2296 2296
 
@@ -2391,14 +2391,14 @@  discard block
 block discarded – undo
2391 2391
 		$ecc = $this->getECCLength($version, $level);
2392 2392
 		if ($b2 == 0) {
2393 2393
 			$spec[0] = $b1;
2394
-			$spec[1] = (int)($data / $b1);
2395
-			$spec[2] = (int)($ecc / $b1);
2394
+			$spec[1] = (int)($data/$b1);
2395
+			$spec[2] = (int)($ecc/$b1);
2396 2396
 			$spec[3] = 0;
2397 2397
 			$spec[4] = 0;
2398 2398
 		} else {
2399 2399
 			$spec[0] = $b1;
2400
-			$spec[1] = (int)($data / ($b1 + $b2));
2401
-			$spec[2] = (int)($ecc  / ($b1 + $b2));
2400
+			$spec[1] = (int)($data/($b1 + $b2));
2401
+			$spec[2] = (int)($ecc/($b1 + $b2));
2402 2402
 			$spec[3] = $b2;
2403 2403
 			$spec[4] = $spec[1] + 1;
2404 2404
 		}
@@ -2422,8 +2422,8 @@  discard block
 block discarded – undo
2422 2422
 			);
2423 2423
 		$yStart = $oy - 2;
2424 2424
 		$xStart = $ox - 2;
2425
-		for ($y=0; $y < 5; $y++) {
2426
-			$frame = $this->qrstrset($frame, $xStart, $yStart+$y, $finder[$y]);
2425
+		for ($y = 0; $y < 5; $y++) {
2426
+			$frame = $this->qrstrset($frame, $xStart, $yStart + $y, $finder[$y]);
2427 2427
 		}
2428 2428
 		return $frame;
2429 2429
 	}
@@ -2443,9 +2443,9 @@  discard block
 block discarded – undo
2443 2443
 		if ($d < 0) {
2444 2444
 			$w = 2;
2445 2445
 		} else {
2446
-			$w = (int)(($width - $this->alignmentPattern[$version][0]) / $d + 2);
2446
+			$w = (int)(($width - $this->alignmentPattern[$version][0])/$d + 2);
2447 2447
 		}
2448
-		if ($w * $w - 3 == 1) {
2448
+		if ($w*$w - 3 == 1) {
2449 2449
 			$x = $this->alignmentPattern[$version][0];
2450 2450
 			$y = $this->alignmentPattern[$version][0];
2451 2451
 			$frame = $this->putAlignmentMarker($frame, $x, $y);
@@ -2453,15 +2453,15 @@  discard block
 block discarded – undo
2453 2453
 		}
2454 2454
 		$cx = $this->alignmentPattern[$version][0];
2455 2455
 		$wo = $w - 1;
2456
-		for ($x=1; $x < $wo; ++$x) {
2456
+		for ($x = 1; $x < $wo; ++$x) {
2457 2457
 			$frame = $this->putAlignmentMarker($frame, 6, $cx);
2458
-			$frame = $this->putAlignmentMarker($frame, $cx,  6);
2458
+			$frame = $this->putAlignmentMarker($frame, $cx, 6);
2459 2459
 			$cx += $d;
2460 2460
 		}
2461 2461
 		$cy = $this->alignmentPattern[$version][0];
2462
-		for ($y=0; $y < $wo; ++$y) {
2462
+		for ($y = 0; $y < $wo; ++$y) {
2463 2463
 			$cx = $this->alignmentPattern[$version][0];
2464
-			for ($x=0; $x < $wo; ++$x) {
2464
+			for ($x = 0; $x < $wo; ++$x) {
2465 2465
 				$frame = $this->putAlignmentMarker($frame, $cx, $cy);
2466 2466
 				$cx += $d;
2467 2467
 			}
@@ -2515,7 +2515,7 @@  discard block
 block discarded – undo
2515 2515
 		"\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
2516 2516
 		"\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
2517 2517
 		);
2518
-		for ($y=0; $y < 7; $y++) {
2518
+		for ($y = 0; $y < 7; $y++) {
2519 2519
 			$frame = $this->qrstrset($frame, $ox, ($oy + $y), $finder[$y]);
2520 2520
 		}
2521 2521
 		return $frame;
@@ -2528,7 +2528,7 @@  discard block
 block discarded – undo
2528 2528
 	 */
2529 2529
 	protected function createFrame($version) {
2530 2530
 		$width = $this->capacity[$version][QRCAP_WIDTH];
2531
-		$frameLine = str_repeat ("\0", $width);
2531
+		$frameLine = str_repeat("\0", $width);
2532 2532
 		$frame = array_fill(0, $width, $frameLine);
2533 2533
 		// Finder pattern
2534 2534
 		$frame = $this->putFinderPattern($frame, 0, 0);
@@ -2536,7 +2536,7 @@  discard block
 block discarded – undo
2536 2536
 		$frame = $this->putFinderPattern($frame, 0, $width - 7);
2537 2537
 		// Separator
2538 2538
 		$yOffset = $width - 7;
2539
-		for ($y=0; $y < 7; ++$y) {
2539
+		for ($y = 0; $y < 7; ++$y) {
2540 2540
 			$frame[$y][7] = "\xc0";
2541 2541
 			$frame[$y][$width - 8] = "\xc0";
2542 2542
 			$frame[$yOffset][7] = "\xc0";
@@ -2544,22 +2544,22 @@  discard block
 block discarded – undo
2544 2544
 		}
2545 2545
 		$setPattern = str_repeat("\xc0", 8);
2546 2546
 		$frame = $this->qrstrset($frame, 0, 7, $setPattern);
2547
-		$frame = $this->qrstrset($frame, $width-8, 7, $setPattern);
2547
+		$frame = $this->qrstrset($frame, $width - 8, 7, $setPattern);
2548 2548
 		$frame = $this->qrstrset($frame, 0, $width - 8, $setPattern);
2549 2549
 		// Format info
2550 2550
 		$setPattern = str_repeat("\x84", 9);
2551 2551
 		$frame = $this->qrstrset($frame, 0, 8, $setPattern);
2552 2552
 		$frame = $this->qrstrset($frame, $width - 8, 8, $setPattern, 8);
2553 2553
 		$yOffset = $width - 8;
2554
-		for ($y=0; $y < 8; ++$y,++$yOffset) {
2554
+		for ($y = 0; $y < 8; ++$y, ++$yOffset) {
2555 2555
 			$frame[$y][8] = "\x84";
2556 2556
 			$frame[$yOffset][8] = "\x84";
2557 2557
 		}
2558 2558
 		// Timing pattern
2559 2559
 		$wo = $width - 15;
2560
-		for ($i=1; $i < $wo; ++$i) {
2561
-			$frame[6][7+$i] = chr(0x90 | ($i & 1));
2562
-			$frame[7+$i][6] = chr(0x90 | ($i & 1));
2560
+		for ($i = 1; $i < $wo; ++$i) {
2561
+			$frame[6][7 + $i] = chr(0x90 | ($i & 1));
2562
+			$frame[7 + $i][6] = chr(0x90 | ($i & 1));
2563 2563
 		}
2564 2564
 		// Alignment pattern
2565 2565
 		$frame = $this->putAlignmentPattern($version, $frame, $width);
@@ -2567,16 +2567,16 @@  discard block
 block discarded – undo
2567 2567
 		if ($version >= 7) {
2568 2568
 			$vinf = $this->getVersionPattern($version);
2569 2569
 			$v = $vinf;
2570
-			for ($x=0; $x<6; ++$x) {
2571
-				for ($y=0; $y<3; ++$y) {
2572
-					$frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
2570
+			for ($x = 0; $x < 6; ++$x) {
2571
+				for ($y = 0; $y < 3; ++$y) {
2572
+					$frame[($width - 11) + $y][$x] = chr(0x88 | ($v & 1));
2573 2573
 					$v = $v >> 1;
2574 2574
 				}
2575 2575
 			}
2576 2576
 			$v = $vinf;
2577
-			for ($y=0; $y<6; ++$y) {
2578
-				for ($x=0; $x<3; ++$x) {
2579
-					$frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
2577
+			for ($y = 0; $y < 6; ++$y) {
2578
+				for ($x = 0; $x < 3; ++$x) {
2579
+					$frame[$y][$x + ($width - 11)] = chr(0x88 | ($v & 1));
2580 2580
 					$v = $v >> 1;
2581 2581
 				}
2582 2582
 			}
@@ -2673,7 +2673,7 @@  discard block
 block discarded – undo
2673 2673
 	 * @return int value
2674 2674
 	 */
2675 2675
 	 protected function rsDataLength($spec) {
2676
-		return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);
2676
+		return ($spec[0]*$spec[1]) + ($spec[3]*$spec[4]);
2677 2677
 	}
2678 2678
 
2679 2679
 	/**
@@ -2682,7 +2682,7 @@  discard block
 block discarded – undo
2682 2682
 	 * @return int value
2683 2683
 	 */
2684 2684
 	 protected function rsEccLength($spec) {
2685
-		return ($spec[0] + $spec[3]) * $spec[2];
2685
+		return ($spec[0] + $spec[3])*$spec[2];
2686 2686
 	}
2687 2687
 
2688 2688
 	// - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -2747,16 +2747,16 @@  discard block
 block discarded – undo
2747 2747
 		if (($symsize < 0) OR ($symsize > 8)) {
2748 2748
 			return $rs;
2749 2749
 		}
2750
-		if (($fcr < 0) OR ($fcr >= (1<<$symsize))) {
2750
+		if (($fcr < 0) OR ($fcr >= (1 << $symsize))) {
2751 2751
 			return $rs;
2752 2752
 		}
2753
-		if (($prim <= 0) OR ($prim >= (1<<$symsize))) {
2753
+		if (($prim <= 0) OR ($prim >= (1 << $symsize))) {
2754 2754
 			return $rs;
2755 2755
 		}
2756
-		if (($nroots < 0) OR ($nroots >= (1<<$symsize))) {
2756
+		if (($nroots < 0) OR ($nroots >= (1 << $symsize))) {
2757 2757
 			return $rs;
2758 2758
 		}
2759
-		if (($pad < 0) OR ($pad >= ((1<<$symsize) -1 - $nroots))) {
2759
+		if (($pad < 0) OR ($pad >= ((1 << $symsize) - 1 - $nroots))) {
2760 2760
 			return $rs;
2761 2761
 		}
2762 2762
 		$rs = array();
@@ -2766,13 +2766,13 @@  discard block
 block discarded – undo
2766 2766
 		$rs['alpha_to'] = array_fill(0, ($rs['nn'] + 1), 0);
2767 2767
 		$rs['index_of'] = array_fill(0, ($rs['nn'] + 1), 0);
2768 2768
 		// PHP style macro replacement ;)
2769
-		$NN =& $rs['nn'];
2770
-		$A0 =& $NN;
2769
+		$NN = & $rs['nn'];
2770
+		$A0 = & $NN;
2771 2771
 		// Generate Galois field lookup tables
2772 2772
 		$rs['index_of'][0] = $A0; // log(zero) = -inf
2773 2773
 		$rs['alpha_to'][$A0] = 0; // alpha**-inf = 0
2774 2774
 		$sr = 1;
2775
-		for ($i=0; $i<$rs['nn']; ++$i) {
2775
+		for ($i = 0; $i < $rs['nn']; ++$i) {
2776 2776
 			$rs['index_of'][$sr] = $i;
2777 2777
 			$rs['alpha_to'][$i] = $sr;
2778 2778
 			$sr <<= 1;
@@ -2792,19 +2792,19 @@  discard block
 block discarded – undo
2792 2792
 		$rs['nroots'] = $nroots;
2793 2793
 		$rs['gfpoly'] = $gfpoly;
2794 2794
 		// Find prim-th root of 1, used in decoding
2795
-		for ($iprim=1; ($iprim % $prim) != 0; $iprim += $rs['nn']) {
2795
+		for ($iprim = 1; ($iprim%$prim) != 0; $iprim += $rs['nn']) {
2796 2796
 			; // intentional empty-body loop!
2797 2797
 		}
2798
-		$rs['iprim'] = (int)($iprim / $prim);
2798
+		$rs['iprim'] = (int)($iprim/$prim);
2799 2799
 		$rs['genpoly'][0] = 1;
2800
-		for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
2801
-			$rs['genpoly'][$i+1] = 1;
2800
+		for ($i = 0, $root = $fcr*$prim; $i < $nroots; $i++, $root += $prim) {
2801
+			$rs['genpoly'][$i + 1] = 1;
2802 2802
 			// Multiply rs->genpoly[] by  @**(root + x)
2803 2803
 			for ($j = $i; $j > 0; --$j) {
2804 2804
 				if ($rs['genpoly'][$j] != 0) {
2805
-					$rs['genpoly'][$j] = $rs['genpoly'][$j-1] ^ $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][$j]] + $root)];
2805
+					$rs['genpoly'][$j] = $rs['genpoly'][$j - 1] ^ $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][$j]] + $root)];
2806 2806
 				} else {
2807
-					$rs['genpoly'][$j] = $rs['genpoly'][$j-1];
2807
+					$rs['genpoly'][$j] = $rs['genpoly'][$j - 1];
2808 2808
 				}
2809 2809
 			}
2810 2810
 			// rs->genpoly[0] can never be zero
@@ -2825,26 +2825,26 @@  discard block
 block discarded – undo
2825 2825
 	 * @return parity array
2826 2826
 	 */
2827 2827
 	 protected function encode_rs_char($rs, $data, $parity) {
2828
-		$MM       =& $rs['mm']; // bits per symbol
2829
-		$NN       =& $rs['nn']; // the total number of symbols in a RS block
2830
-		$ALPHA_TO =& $rs['alpha_to']; // the address of an array of NN elements to convert Galois field elements in index (log) form to polynomial form
2831
-		$INDEX_OF =& $rs['index_of']; // the address of an array of NN elements to convert Galois field elements in polynomial form to index (log) form
2832
-		$GENPOLY  =& $rs['genpoly']; // an array of NROOTS+1 elements containing the generator polynomial in index form
2833
-		$NROOTS   =& $rs['nroots']; // the number of roots in the RS code generator polynomial, which is the same as the number of parity symbols in a block
2834
-		$FCR      =& $rs['fcr']; // first consecutive root, index form
2835
-		$PRIM     =& $rs['prim']; // primitive element, index form
2836
-		$IPRIM    =& $rs['iprim']; // prim-th root of 1, index form
2837
-		$PAD      =& $rs['pad']; // the number of pad symbols in a block
2838
-		$A0       =& $NN;
2828
+		$MM       = & $rs['mm']; // bits per symbol
2829
+		$NN       = & $rs['nn']; // the total number of symbols in a RS block
2830
+		$ALPHA_TO = & $rs['alpha_to']; // the address of an array of NN elements to convert Galois field elements in index (log) form to polynomial form
2831
+		$INDEX_OF = & $rs['index_of']; // the address of an array of NN elements to convert Galois field elements in polynomial form to index (log) form
2832
+		$GENPOLY  = & $rs['genpoly']; // an array of NROOTS+1 elements containing the generator polynomial in index form
2833
+		$NROOTS   = & $rs['nroots']; // the number of roots in the RS code generator polynomial, which is the same as the number of parity symbols in a block
2834
+		$FCR      = & $rs['fcr']; // first consecutive root, index form
2835
+		$PRIM     = & $rs['prim']; // primitive element, index form
2836
+		$IPRIM    = & $rs['iprim']; // prim-th root of 1, index form
2837
+		$PAD      = & $rs['pad']; // the number of pad symbols in a block
2838
+		$A0       = & $NN;
2839 2839
 		$parity = array_fill(0, $NROOTS, 0);
2840
-		for ($i=0; $i < ($NN - $NROOTS - $PAD); $i++) {
2840
+		for ($i = 0; $i < ($NN - $NROOTS - $PAD); $i++) {
2841 2841
 			$feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
2842 2842
 			if ($feedback != $A0) {
2843 2843
 				// feedback term is non-zero
2844 2844
 				// This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
2845 2845
 				// always be for the polynomials constructed by init_rs()
2846 2846
 				$feedback = $this->modnn($rs, $NN - $GENPOLY[$NROOTS] + $feedback);
2847
-				for ($j=1; $j < $NROOTS; ++$j) {
2847
+				for ($j = 1; $j < $NROOTS; ++$j) {
2848 2848
 				$parity[$j] ^= $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[($NROOTS - $j)])];
2849 2849
 				}
2850 2850
 			}
Please login to merge, or discard this patch.
phpmyfaq/inc/libs/tcpdf/include/tcpdf_colors.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -240,7 +240,7 @@
 block discarded – undo
240 240
 
241 241
 	/**
242 242
 	 * Return the Spot color array.
243
-	 * @param $name (string) Name of the spot color.
243
+	 * @param string $name (string) Name of the spot color.
244 244
 	 * @param $spotc (array) Reference to an array of spot colors.
245 245
 	 * @return (array) Spot color array or false if not defined.
246 246
 	 * @since 5.9.125 (2011-10-03)
Please login to merge, or discard this patch.
Indentation   +399 added lines, -399 removed lines patch added patch discarded remove patch
@@ -47,412 +47,412 @@
 block discarded – undo
47 47
  */
48 48
 class TCPDF_COLORS {
49 49
 
50
-	/**
51
-	 * Array of WEB safe colors
52
-	 * @public static
53
-	 */
54
-	public static $webcolor = array (
55
-		'aliceblue' => 'f0f8ff',
56
-		'antiquewhite' => 'faebd7',
57
-		'aqua' => '00ffff',
58
-		'aquamarine' => '7fffd4',
59
-		'azure' => 'f0ffff',
60
-		'beige' => 'f5f5dc',
61
-		'bisque' => 'ffe4c4',
62
-		'black' => '000000',
63
-		'blanchedalmond' => 'ffebcd',
64
-		'blue' => '0000ff',
65
-		'blueviolet' => '8a2be2',
66
-		'brown' => 'a52a2a',
67
-		'burlywood' => 'deb887',
68
-		'cadetblue' => '5f9ea0',
69
-		'chartreuse' => '7fff00',
70
-		'chocolate' => 'd2691e',
71
-		'coral' => 'ff7f50',
72
-		'cornflowerblue' => '6495ed',
73
-		'cornsilk' => 'fff8dc',
74
-		'crimson' => 'dc143c',
75
-		'cyan' => '00ffff',
76
-		'darkblue' => '00008b',
77
-		'darkcyan' => '008b8b',
78
-		'darkgoldenrod' => 'b8860b',
79
-		'dkgray' => 'a9a9a9',
80
-		'darkgray' => 'a9a9a9',
81
-		'darkgrey' => 'a9a9a9',
82
-		'darkgreen' => '006400',
83
-		'darkkhaki' => 'bdb76b',
84
-		'darkmagenta' => '8b008b',
85
-		'darkolivegreen' => '556b2f',
86
-		'darkorange' => 'ff8c00',
87
-		'darkorchid' => '9932cc',
88
-		'darkred' => '8b0000',
89
-		'darksalmon' => 'e9967a',
90
-		'darkseagreen' => '8fbc8f',
91
-		'darkslateblue' => '483d8b',
92
-		'darkslategray' => '2f4f4f',
93
-		'darkslategrey' => '2f4f4f',
94
-		'darkturquoise' => '00ced1',
95
-		'darkviolet' => '9400d3',
96
-		'deeppink' => 'ff1493',
97
-		'deepskyblue' => '00bfff',
98
-		'dimgray' => '696969',
99
-		'dimgrey' => '696969',
100
-		'dodgerblue' => '1e90ff',
101
-		'firebrick' => 'b22222',
102
-		'floralwhite' => 'fffaf0',
103
-		'forestgreen' => '228b22',
104
-		'fuchsia' => 'ff00ff',
105
-		'gainsboro' => 'dcdcdc',
106
-		'ghostwhite' => 'f8f8ff',
107
-		'gold' => 'ffd700',
108
-		'goldenrod' => 'daa520',
109
-		'gray' => '808080',
110
-		'grey' => '808080',
111
-		'green' => '008000',
112
-		'greenyellow' => 'adff2f',
113
-		'honeydew' => 'f0fff0',
114
-		'hotpink' => 'ff69b4',
115
-		'indianred' => 'cd5c5c',
116
-		'indigo' => '4b0082',
117
-		'ivory' => 'fffff0',
118
-		'khaki' => 'f0e68c',
119
-		'lavender' => 'e6e6fa',
120
-		'lavenderblush' => 'fff0f5',
121
-		'lawngreen' => '7cfc00',
122
-		'lemonchiffon' => 'fffacd',
123
-		'lightblue' => 'add8e6',
124
-		'lightcoral' => 'f08080',
125
-		'lightcyan' => 'e0ffff',
126
-		'lightgoldenrodyellow' => 'fafad2',
127
-		'ltgray' => 'd3d3d3',
128
-		'lightgray' => 'd3d3d3',
129
-		'lightgrey' => 'd3d3d3',
130
-		'lightgreen' => '90ee90',
131
-		'lightpink' => 'ffb6c1',
132
-		'lightsalmon' => 'ffa07a',
133
-		'lightseagreen' => '20b2aa',
134
-		'lightskyblue' => '87cefa',
135
-		'lightslategray' => '778899',
136
-		'lightslategrey' => '778899',
137
-		'lightsteelblue' => 'b0c4de',
138
-		'lightyellow' => 'ffffe0',
139
-		'lime' => '00ff00',
140
-		'limegreen' => '32cd32',
141
-		'linen' => 'faf0e6',
142
-		'magenta' => 'ff00ff',
143
-		'maroon' => '800000',
144
-		'mediumaquamarine' => '66cdaa',
145
-		'mediumblue' => '0000cd',
146
-		'mediumorchid' => 'ba55d3',
147
-		'mediumpurple' => '9370d8',
148
-		'mediumseagreen' => '3cb371',
149
-		'mediumslateblue' => '7b68ee',
150
-		'mediumspringgreen' => '00fa9a',
151
-		'mediumturquoise' => '48d1cc',
152
-		'mediumvioletred' => 'c71585',
153
-		'midnightblue' => '191970',
154
-		'mintcream' => 'f5fffa',
155
-		'mistyrose' => 'ffe4e1',
156
-		'moccasin' => 'ffe4b5',
157
-		'navajowhite' => 'ffdead',
158
-		'navy' => '000080',
159
-		'oldlace' => 'fdf5e6',
160
-		'olive' => '808000',
161
-		'olivedrab' => '6b8e23',
162
-		'orange' => 'ffa500',
163
-		'orangered' => 'ff4500',
164
-		'orchid' => 'da70d6',
165
-		'palegoldenrod' => 'eee8aa',
166
-		'palegreen' => '98fb98',
167
-		'paleturquoise' => 'afeeee',
168
-		'palevioletred' => 'd87093',
169
-		'papayawhip' => 'ffefd5',
170
-		'peachpuff' => 'ffdab9',
171
-		'peru' => 'cd853f',
172
-		'pink' => 'ffc0cb',
173
-		'plum' => 'dda0dd',
174
-		'powderblue' => 'b0e0e6',
175
-		'purple' => '800080',
176
-		'red' => 'ff0000',
177
-		'rosybrown' => 'bc8f8f',
178
-		'royalblue' => '4169e1',
179
-		'saddlebrown' => '8b4513',
180
-		'salmon' => 'fa8072',
181
-		'sandybrown' => 'f4a460',
182
-		'seagreen' => '2e8b57',
183
-		'seashell' => 'fff5ee',
184
-		'sienna' => 'a0522d',
185
-		'silver' => 'c0c0c0',
186
-		'skyblue' => '87ceeb',
187
-		'slateblue' => '6a5acd',
188
-		'slategray' => '708090',
189
-		'slategrey' => '708090',
190
-		'snow' => 'fffafa',
191
-		'springgreen' => '00ff7f',
192
-		'steelblue' => '4682b4',
193
-		'tan' => 'd2b48c',
194
-		'teal' => '008080',
195
-		'thistle' => 'd8bfd8',
196
-		'tomato' => 'ff6347',
197
-		'turquoise' => '40e0d0',
198
-		'violet' => 'ee82ee',
199
-		'wheat' => 'f5deb3',
200
-		'white' => 'ffffff',
201
-		'whitesmoke' => 'f5f5f5',
202
-		'yellow' => 'ffff00',
203
-		'yellowgreen' => '9acd32'
204
-	); // end of web colors
50
+    /**
51
+     * Array of WEB safe colors
52
+     * @public static
53
+     */
54
+    public static $webcolor = array (
55
+        'aliceblue' => 'f0f8ff',
56
+        'antiquewhite' => 'faebd7',
57
+        'aqua' => '00ffff',
58
+        'aquamarine' => '7fffd4',
59
+        'azure' => 'f0ffff',
60
+        'beige' => 'f5f5dc',
61
+        'bisque' => 'ffe4c4',
62
+        'black' => '000000',
63
+        'blanchedalmond' => 'ffebcd',
64
+        'blue' => '0000ff',
65
+        'blueviolet' => '8a2be2',
66
+        'brown' => 'a52a2a',
67
+        'burlywood' => 'deb887',
68
+        'cadetblue' => '5f9ea0',
69
+        'chartreuse' => '7fff00',
70
+        'chocolate' => 'd2691e',
71
+        'coral' => 'ff7f50',
72
+        'cornflowerblue' => '6495ed',
73
+        'cornsilk' => 'fff8dc',
74
+        'crimson' => 'dc143c',
75
+        'cyan' => '00ffff',
76
+        'darkblue' => '00008b',
77
+        'darkcyan' => '008b8b',
78
+        'darkgoldenrod' => 'b8860b',
79
+        'dkgray' => 'a9a9a9',
80
+        'darkgray' => 'a9a9a9',
81
+        'darkgrey' => 'a9a9a9',
82
+        'darkgreen' => '006400',
83
+        'darkkhaki' => 'bdb76b',
84
+        'darkmagenta' => '8b008b',
85
+        'darkolivegreen' => '556b2f',
86
+        'darkorange' => 'ff8c00',
87
+        'darkorchid' => '9932cc',
88
+        'darkred' => '8b0000',
89
+        'darksalmon' => 'e9967a',
90
+        'darkseagreen' => '8fbc8f',
91
+        'darkslateblue' => '483d8b',
92
+        'darkslategray' => '2f4f4f',
93
+        'darkslategrey' => '2f4f4f',
94
+        'darkturquoise' => '00ced1',
95
+        'darkviolet' => '9400d3',
96
+        'deeppink' => 'ff1493',
97
+        'deepskyblue' => '00bfff',
98
+        'dimgray' => '696969',
99
+        'dimgrey' => '696969',
100
+        'dodgerblue' => '1e90ff',
101
+        'firebrick' => 'b22222',
102
+        'floralwhite' => 'fffaf0',
103
+        'forestgreen' => '228b22',
104
+        'fuchsia' => 'ff00ff',
105
+        'gainsboro' => 'dcdcdc',
106
+        'ghostwhite' => 'f8f8ff',
107
+        'gold' => 'ffd700',
108
+        'goldenrod' => 'daa520',
109
+        'gray' => '808080',
110
+        'grey' => '808080',
111
+        'green' => '008000',
112
+        'greenyellow' => 'adff2f',
113
+        'honeydew' => 'f0fff0',
114
+        'hotpink' => 'ff69b4',
115
+        'indianred' => 'cd5c5c',
116
+        'indigo' => '4b0082',
117
+        'ivory' => 'fffff0',
118
+        'khaki' => 'f0e68c',
119
+        'lavender' => 'e6e6fa',
120
+        'lavenderblush' => 'fff0f5',
121
+        'lawngreen' => '7cfc00',
122
+        'lemonchiffon' => 'fffacd',
123
+        'lightblue' => 'add8e6',
124
+        'lightcoral' => 'f08080',
125
+        'lightcyan' => 'e0ffff',
126
+        'lightgoldenrodyellow' => 'fafad2',
127
+        'ltgray' => 'd3d3d3',
128
+        'lightgray' => 'd3d3d3',
129
+        'lightgrey' => 'd3d3d3',
130
+        'lightgreen' => '90ee90',
131
+        'lightpink' => 'ffb6c1',
132
+        'lightsalmon' => 'ffa07a',
133
+        'lightseagreen' => '20b2aa',
134
+        'lightskyblue' => '87cefa',
135
+        'lightslategray' => '778899',
136
+        'lightslategrey' => '778899',
137
+        'lightsteelblue' => 'b0c4de',
138
+        'lightyellow' => 'ffffe0',
139
+        'lime' => '00ff00',
140
+        'limegreen' => '32cd32',
141
+        'linen' => 'faf0e6',
142
+        'magenta' => 'ff00ff',
143
+        'maroon' => '800000',
144
+        'mediumaquamarine' => '66cdaa',
145
+        'mediumblue' => '0000cd',
146
+        'mediumorchid' => 'ba55d3',
147
+        'mediumpurple' => '9370d8',
148
+        'mediumseagreen' => '3cb371',
149
+        'mediumslateblue' => '7b68ee',
150
+        'mediumspringgreen' => '00fa9a',
151
+        'mediumturquoise' => '48d1cc',
152
+        'mediumvioletred' => 'c71585',
153
+        'midnightblue' => '191970',
154
+        'mintcream' => 'f5fffa',
155
+        'mistyrose' => 'ffe4e1',
156
+        'moccasin' => 'ffe4b5',
157
+        'navajowhite' => 'ffdead',
158
+        'navy' => '000080',
159
+        'oldlace' => 'fdf5e6',
160
+        'olive' => '808000',
161
+        'olivedrab' => '6b8e23',
162
+        'orange' => 'ffa500',
163
+        'orangered' => 'ff4500',
164
+        'orchid' => 'da70d6',
165
+        'palegoldenrod' => 'eee8aa',
166
+        'palegreen' => '98fb98',
167
+        'paleturquoise' => 'afeeee',
168
+        'palevioletred' => 'd87093',
169
+        'papayawhip' => 'ffefd5',
170
+        'peachpuff' => 'ffdab9',
171
+        'peru' => 'cd853f',
172
+        'pink' => 'ffc0cb',
173
+        'plum' => 'dda0dd',
174
+        'powderblue' => 'b0e0e6',
175
+        'purple' => '800080',
176
+        'red' => 'ff0000',
177
+        'rosybrown' => 'bc8f8f',
178
+        'royalblue' => '4169e1',
179
+        'saddlebrown' => '8b4513',
180
+        'salmon' => 'fa8072',
181
+        'sandybrown' => 'f4a460',
182
+        'seagreen' => '2e8b57',
183
+        'seashell' => 'fff5ee',
184
+        'sienna' => 'a0522d',
185
+        'silver' => 'c0c0c0',
186
+        'skyblue' => '87ceeb',
187
+        'slateblue' => '6a5acd',
188
+        'slategray' => '708090',
189
+        'slategrey' => '708090',
190
+        'snow' => 'fffafa',
191
+        'springgreen' => '00ff7f',
192
+        'steelblue' => '4682b4',
193
+        'tan' => 'd2b48c',
194
+        'teal' => '008080',
195
+        'thistle' => 'd8bfd8',
196
+        'tomato' => 'ff6347',
197
+        'turquoise' => '40e0d0',
198
+        'violet' => 'ee82ee',
199
+        'wheat' => 'f5deb3',
200
+        'white' => 'ffffff',
201
+        'whitesmoke' => 'f5f5f5',
202
+        'yellow' => 'ffff00',
203
+        'yellowgreen' => '9acd32'
204
+    ); // end of web colors
205 205
 
206
-	/**
207
-	 * Array of valid JavaScript color names
208
-	 * @public static
209
-	 */
210
-	public static $jscolor = array ('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray');
206
+    /**
207
+     * Array of valid JavaScript color names
208
+     * @public static
209
+     */
210
+    public static $jscolor = array ('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray');
211 211
 
212
-	/**
213
-	 * Array of Spot colors (C,M,Y,K,name)
214
-	 * Color keys must be in lowercase and without spaces.
215
-	 * As long as no open standard for spot colours exists, you have to buy a colour book by one of the colour manufacturers and insert the values and names of spot colours directly.
216
-	 * Common industry standard spot colors are: ANPA-COLOR, DIC, FOCOLTONE, GCMI, HKS, PANTONE, TOYO, TRUMATCH.
217
-	 * @public static
218
-	 */
219
-	public static $spotcolor = array (
220
-		// special registration colors
221
-		'none'    => array(  0,   0,   0,   0, 'None'),
222
-		'all'     => array(100, 100, 100, 100, 'All'),
223
-		// standard CMYK colors
224
-		'cyan'    => array(100,   0,   0,   0, 'Cyan'),
225
-		'magenta' => array(  0, 100,   0,   0, 'Magenta'),
226
-		'yellow'  => array(  0,   0, 100,   0, 'Yellow'),
227
-		'key'     => array(  0,   0,   0, 100, 'Key'),
228
-		// alias
229
-		'white'   => array(  0,   0,   0,   0, 'White'),
230
-		'black'   => array(  0,   0,   0, 100, 'Black'),
231
-		// standard RGB colors
232
-		'red'     => array(  0, 100, 100,   0, 'Red'),
233
-		'green'   => array(100,   0, 100,   0, 'Green'),
234
-		'blue'    => array(100, 100,   0,   0, 'Blue'),
235
-		// Add here standard spot colors or dynamically define them with AddSpotColor()
236
-		// ...
237
-	); // end of spot colors
212
+    /**
213
+     * Array of Spot colors (C,M,Y,K,name)
214
+     * Color keys must be in lowercase and without spaces.
215
+     * As long as no open standard for spot colours exists, you have to buy a colour book by one of the colour manufacturers and insert the values and names of spot colours directly.
216
+     * Common industry standard spot colors are: ANPA-COLOR, DIC, FOCOLTONE, GCMI, HKS, PANTONE, TOYO, TRUMATCH.
217
+     * @public static
218
+     */
219
+    public static $spotcolor = array (
220
+        // special registration colors
221
+        'none'    => array(  0,   0,   0,   0, 'None'),
222
+        'all'     => array(100, 100, 100, 100, 'All'),
223
+        // standard CMYK colors
224
+        'cyan'    => array(100,   0,   0,   0, 'Cyan'),
225
+        'magenta' => array(  0, 100,   0,   0, 'Magenta'),
226
+        'yellow'  => array(  0,   0, 100,   0, 'Yellow'),
227
+        'key'     => array(  0,   0,   0, 100, 'Key'),
228
+        // alias
229
+        'white'   => array(  0,   0,   0,   0, 'White'),
230
+        'black'   => array(  0,   0,   0, 100, 'Black'),
231
+        // standard RGB colors
232
+        'red'     => array(  0, 100, 100,   0, 'Red'),
233
+        'green'   => array(100,   0, 100,   0, 'Green'),
234
+        'blue'    => array(100, 100,   0,   0, 'Blue'),
235
+        // Add here standard spot colors or dynamically define them with AddSpotColor()
236
+        // ...
237
+    ); // end of spot colors
238 238
 
239
-	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
239
+    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
240 240
 
241
-	/**
242
-	 * Return the Spot color array.
243
-	 * @param $name (string) Name of the spot color.
244
-	 * @param $spotc (array) Reference to an array of spot colors.
245
-	 * @return (array) Spot color array or false if not defined.
246
-	 * @since 5.9.125 (2011-10-03)
247
-	 * @public static
248
-	 */
249
-	public static function getSpotColor($name, &$spotc) {
250
-		if (isset($spotc[$name])) {
251
-			return $spotc[$name];
252
-		}
253
-		$color = preg_replace('/[\s]*/', '', $name); // remove extra spaces
254
-		$color = strtolower($color);
255
-		if (isset(self::$spotcolor[$color])) {
256
-			if (!isset($spotc[$name])) {
257
-				$i = (1 + count($spotc));
258
-				$spotc[$name] = array('C' => self::$spotcolor[$color][0], 'M' => self::$spotcolor[$color][1], 'Y' => self::$spotcolor[$color][2], 'K' => self::$spotcolor[$color][3], 'name' => self::$spotcolor[$color][4], 'i' => $i);
259
-			}
260
-			return $spotc[self::$spotcolor[$color][4]];
261
-		}
262
-		return false;
263
-	}
241
+    /**
242
+     * Return the Spot color array.
243
+     * @param $name (string) Name of the spot color.
244
+     * @param $spotc (array) Reference to an array of spot colors.
245
+     * @return (array) Spot color array or false if not defined.
246
+     * @since 5.9.125 (2011-10-03)
247
+     * @public static
248
+     */
249
+    public static function getSpotColor($name, &$spotc) {
250
+        if (isset($spotc[$name])) {
251
+            return $spotc[$name];
252
+        }
253
+        $color = preg_replace('/[\s]*/', '', $name); // remove extra spaces
254
+        $color = strtolower($color);
255
+        if (isset(self::$spotcolor[$color])) {
256
+            if (!isset($spotc[$name])) {
257
+                $i = (1 + count($spotc));
258
+                $spotc[$name] = array('C' => self::$spotcolor[$color][0], 'M' => self::$spotcolor[$color][1], 'Y' => self::$spotcolor[$color][2], 'K' => self::$spotcolor[$color][3], 'name' => self::$spotcolor[$color][4], 'i' => $i);
259
+            }
260
+            return $spotc[self::$spotcolor[$color][4]];
261
+        }
262
+        return false;
263
+    }
264 264
 
265
-	/**
266
-	 * Returns an array (RGB or CMYK) from an html color name, or a six-digit (i.e. #3FE5AA), or three-digit (i.e. #7FF) hexadecimal color, or a javascript color array, or javascript color name.
267
-	 * @param $hcolor (string) HTML color.
268
-	 * @param $spotc (array) Reference to an array of spot colors.
269
-	 * @param $defcol (array) Color to return in case of error.
270
-	 * @return array RGB or CMYK color, or false in case of error.
271
-	 * @public static
272
-	 */
273
-	public static function convertHTMLColorToDec($hcolor, &$spotc, $defcol=array('R'=>128,'G'=>128,'B'=>128)) {
274
-		$color = preg_replace('/[\s]*/', '', $hcolor); // remove extra spaces
275
-		$color = strtolower($color);
276
-		// check for javascript color array syntax
277
-		if (strpos($color, '[') !== false) {
278
-			if (preg_match('/[\[][\"\'](t|g|rgb|cmyk)[\"\'][\,]?([0-9\.]*)[\,]?([0-9\.]*)[\,]?([0-9\.]*)[\,]?([0-9\.]*)[\]]/', $color, $m) > 0) {
279
-				$returncolor = array();
280
-				switch ($m[1]) {
281
-					case 'cmyk': {
282
-						// RGB
283
-						$returncolor['C'] = max(0, min(100, (floatval($m[2]) * 100)));
284
-						$returncolor['M'] = max(0, min(100, (floatval($m[3]) * 100)));
285
-						$returncolor['Y'] = max(0, min(100, (floatval($m[4]) * 100)));
286
-						$returncolor['K'] = max(0, min(100, (floatval($m[5]) * 100)));
287
-						break;
288
-					}
289
-					case 'rgb': {
290
-						// RGB
291
-						$returncolor['R'] = max(0, min(255, (floatval($m[2]) * 255)));
292
-						$returncolor['G'] = max(0, min(255, (floatval($m[3]) * 255)));
293
-						$returncolor['B'] = max(0, min(255, (floatval($m[4]) * 255)));
294
-						break;
295
-					}
296
-					case 'g': {
297
-						// grayscale
298
-						$returncolor['G'] = max(0, min(255, (floatval($m[2]) * 255)));
299
-						break;
300
-					}
301
-					case 't':
302
-					default: {
303
-						// transparent (empty array)
304
-						break;
305
-					}
306
-				}
307
-				return $returncolor;
308
-			}
309
-		} elseif ((substr($color, 0, 4) != 'cmyk') AND (substr($color, 0, 3) != 'rgb') AND (($dotpos = strpos($color, '.')) !== false)) {
310
-			// remove class parent (i.e.: color.red)
311
-			$color = substr($color, ($dotpos + 1));
312
-			if ($color == 'transparent') {
313
-				// transparent (empty array)
314
-				return array();
315
-			}
316
-		}
317
-		if (strlen($color) == 0) {
318
-			return $defcol;
319
-		}
320
-		// RGB ARRAY
321
-		if (substr($color, 0, 3) == 'rgb') {
322
-			$codes = substr($color, 4);
323
-			$codes = str_replace(')', '', $codes);
324
-			$returncolor = explode(',', $codes);
325
-			foreach ($returncolor as $key => $val) {
326
-				if (strpos($val, '%') > 0) {
327
-					// percentage
328
-					$returncolor[$key] = (255 * intval($val) / 100);
329
-				} else {
330
-					$returncolor[$key] = intval($val);
331
-				}
332
-				// normalize value
333
-				$returncolor[$key] = max(0, min(255, $returncolor[$key]));
334
-			}
335
-			return $returncolor;
336
-		}
337
-		// CMYK ARRAY
338
-		if (substr($color, 0, 4) == 'cmyk') {
339
-			$codes = substr($color, 5);
340
-			$codes = str_replace(')', '', $codes);
341
-			$returncolor = explode(',', $codes);
342
-			foreach ($returncolor as $key => $val) {
343
-				if (strpos($val, '%') !== false) {
344
-					// percentage
345
-					$returncolor[$key] = (100 * intval($val) / 100);
346
-				} else {
347
-					$returncolor[$key] = intval($val);
348
-				}
349
-				// normalize value
350
-				$returncolor[$key] = max(0, min(100, $returncolor[$key]));
351
-			}
352
-			return $returncolor;
353
-		}
354
-		if ($color[0] != '#') {
355
-			// COLOR NAME
356
-			if (isset(self::$webcolor[$color])) {
357
-				// web color
358
-				$color_code = self::$webcolor[$color];
359
-			} else {
360
-				// spot color
361
-				$returncolor = self::getSpotColor($color, $spotc);
362
-				if ($returncolor === false) {
363
-					$returncolor = $defcol;
364
-				}
365
-				return $returncolor;
366
-			}
367
-		} else {
368
-			$color_code = substr($color, 1);
369
-		}
370
-		// HEXADECIMAL REPRESENTATION
371
-		switch (strlen($color_code)) {
372
-			case 3: {
373
-				// 3-digit RGB hexadecimal representation
374
-				$r = substr($color_code, 0, 1);
375
-				$g = substr($color_code, 1, 1);
376
-				$b = substr($color_code, 2, 1);
377
-				$returncolor = array();
378
-				$returncolor['R'] = max(0, min(255, hexdec($r.$r)));
379
-				$returncolor['G'] = max(0, min(255, hexdec($g.$g)));
380
-				$returncolor['B'] = max(0, min(255, hexdec($b.$b)));
381
-				break;
382
-			}
383
-			case 6: {
384
-				// 6-digit RGB hexadecimal representation
385
-				$returncolor = array();
386
-				$returncolor['R'] = max(0, min(255, hexdec(substr($color_code, 0, 2))));
387
-				$returncolor['G'] = max(0, min(255, hexdec(substr($color_code, 2, 2))));
388
-				$returncolor['B'] = max(0, min(255, hexdec(substr($color_code, 4, 2))));
389
-				break;
390
-			}
391
-			case 8: {
392
-				// 8-digit CMYK hexadecimal representation
393
-				$returncolor = array();
394
-				$returncolor['C'] = max(0, min(100, round(hexdec(substr($color_code, 0, 2)) / 2.55)));
395
-				$returncolor['M'] = max(0, min(100, round(hexdec(substr($color_code, 2, 2)) / 2.55)));
396
-				$returncolor['Y'] = max(0, min(100, round(hexdec(substr($color_code, 4, 2)) / 2.55)));
397
-				$returncolor['K'] = max(0, min(100, round(hexdec(substr($color_code, 6, 2)) / 2.55)));
398
-				break;
399
-			}
400
-			default: {
401
-				$returncolor = $defcol;
402
-				break;
403
-			}
404
-		}
405
-		return $returncolor;
406
-	}
265
+    /**
266
+     * Returns an array (RGB or CMYK) from an html color name, or a six-digit (i.e. #3FE5AA), or three-digit (i.e. #7FF) hexadecimal color, or a javascript color array, or javascript color name.
267
+     * @param $hcolor (string) HTML color.
268
+     * @param $spotc (array) Reference to an array of spot colors.
269
+     * @param $defcol (array) Color to return in case of error.
270
+     * @return array RGB or CMYK color, or false in case of error.
271
+     * @public static
272
+     */
273
+    public static function convertHTMLColorToDec($hcolor, &$spotc, $defcol=array('R'=>128,'G'=>128,'B'=>128)) {
274
+        $color = preg_replace('/[\s]*/', '', $hcolor); // remove extra spaces
275
+        $color = strtolower($color);
276
+        // check for javascript color array syntax
277
+        if (strpos($color, '[') !== false) {
278
+            if (preg_match('/[\[][\"\'](t|g|rgb|cmyk)[\"\'][\,]?([0-9\.]*)[\,]?([0-9\.]*)[\,]?([0-9\.]*)[\,]?([0-9\.]*)[\]]/', $color, $m) > 0) {
279
+                $returncolor = array();
280
+                switch ($m[1]) {
281
+                    case 'cmyk': {
282
+                        // RGB
283
+                        $returncolor['C'] = max(0, min(100, (floatval($m[2]) * 100)));
284
+                        $returncolor['M'] = max(0, min(100, (floatval($m[3]) * 100)));
285
+                        $returncolor['Y'] = max(0, min(100, (floatval($m[4]) * 100)));
286
+                        $returncolor['K'] = max(0, min(100, (floatval($m[5]) * 100)));
287
+                        break;
288
+                    }
289
+                    case 'rgb': {
290
+                        // RGB
291
+                        $returncolor['R'] = max(0, min(255, (floatval($m[2]) * 255)));
292
+                        $returncolor['G'] = max(0, min(255, (floatval($m[3]) * 255)));
293
+                        $returncolor['B'] = max(0, min(255, (floatval($m[4]) * 255)));
294
+                        break;
295
+                    }
296
+                    case 'g': {
297
+                        // grayscale
298
+                        $returncolor['G'] = max(0, min(255, (floatval($m[2]) * 255)));
299
+                        break;
300
+                    }
301
+                    case 't':
302
+                    default: {
303
+                        // transparent (empty array)
304
+                        break;
305
+                    }
306
+                }
307
+                return $returncolor;
308
+            }
309
+        } elseif ((substr($color, 0, 4) != 'cmyk') AND (substr($color, 0, 3) != 'rgb') AND (($dotpos = strpos($color, '.')) !== false)) {
310
+            // remove class parent (i.e.: color.red)
311
+            $color = substr($color, ($dotpos + 1));
312
+            if ($color == 'transparent') {
313
+                // transparent (empty array)
314
+                return array();
315
+            }
316
+        }
317
+        if (strlen($color) == 0) {
318
+            return $defcol;
319
+        }
320
+        // RGB ARRAY
321
+        if (substr($color, 0, 3) == 'rgb') {
322
+            $codes = substr($color, 4);
323
+            $codes = str_replace(')', '', $codes);
324
+            $returncolor = explode(',', $codes);
325
+            foreach ($returncolor as $key => $val) {
326
+                if (strpos($val, '%') > 0) {
327
+                    // percentage
328
+                    $returncolor[$key] = (255 * intval($val) / 100);
329
+                } else {
330
+                    $returncolor[$key] = intval($val);
331
+                }
332
+                // normalize value
333
+                $returncolor[$key] = max(0, min(255, $returncolor[$key]));
334
+            }
335
+            return $returncolor;
336
+        }
337
+        // CMYK ARRAY
338
+        if (substr($color, 0, 4) == 'cmyk') {
339
+            $codes = substr($color, 5);
340
+            $codes = str_replace(')', '', $codes);
341
+            $returncolor = explode(',', $codes);
342
+            foreach ($returncolor as $key => $val) {
343
+                if (strpos($val, '%') !== false) {
344
+                    // percentage
345
+                    $returncolor[$key] = (100 * intval($val) / 100);
346
+                } else {
347
+                    $returncolor[$key] = intval($val);
348
+                }
349
+                // normalize value
350
+                $returncolor[$key] = max(0, min(100, $returncolor[$key]));
351
+            }
352
+            return $returncolor;
353
+        }
354
+        if ($color[0] != '#') {
355
+            // COLOR NAME
356
+            if (isset(self::$webcolor[$color])) {
357
+                // web color
358
+                $color_code = self::$webcolor[$color];
359
+            } else {
360
+                // spot color
361
+                $returncolor = self::getSpotColor($color, $spotc);
362
+                if ($returncolor === false) {
363
+                    $returncolor = $defcol;
364
+                }
365
+                return $returncolor;
366
+            }
367
+        } else {
368
+            $color_code = substr($color, 1);
369
+        }
370
+        // HEXADECIMAL REPRESENTATION
371
+        switch (strlen($color_code)) {
372
+            case 3: {
373
+                // 3-digit RGB hexadecimal representation
374
+                $r = substr($color_code, 0, 1);
375
+                $g = substr($color_code, 1, 1);
376
+                $b = substr($color_code, 2, 1);
377
+                $returncolor = array();
378
+                $returncolor['R'] = max(0, min(255, hexdec($r.$r)));
379
+                $returncolor['G'] = max(0, min(255, hexdec($g.$g)));
380
+                $returncolor['B'] = max(0, min(255, hexdec($b.$b)));
381
+                break;
382
+            }
383
+            case 6: {
384
+                // 6-digit RGB hexadecimal representation
385
+                $returncolor = array();
386
+                $returncolor['R'] = max(0, min(255, hexdec(substr($color_code, 0, 2))));
387
+                $returncolor['G'] = max(0, min(255, hexdec(substr($color_code, 2, 2))));
388
+                $returncolor['B'] = max(0, min(255, hexdec(substr($color_code, 4, 2))));
389
+                break;
390
+            }
391
+            case 8: {
392
+                // 8-digit CMYK hexadecimal representation
393
+                $returncolor = array();
394
+                $returncolor['C'] = max(0, min(100, round(hexdec(substr($color_code, 0, 2)) / 2.55)));
395
+                $returncolor['M'] = max(0, min(100, round(hexdec(substr($color_code, 2, 2)) / 2.55)));
396
+                $returncolor['Y'] = max(0, min(100, round(hexdec(substr($color_code, 4, 2)) / 2.55)));
397
+                $returncolor['K'] = max(0, min(100, round(hexdec(substr($color_code, 6, 2)) / 2.55)));
398
+                break;
399
+            }
400
+            default: {
401
+                $returncolor = $defcol;
402
+                break;
403
+            }
404
+        }
405
+        return $returncolor;
406
+    }
407 407
 
408
-	/**
409
-	 * Convert a color array into a string representation.
410
-	 * @param $c (array) Array of colors.
411
-	 * @return (string) The color array representation.
412
-	 * @since 5.9.137 (2011-12-01)
413
-	 * @public static
414
-	 */
415
-	public static function getColorStringFromArray($c) {
416
-		$c = array_values($c);
417
-		$color = '[';
418
-		switch (count($c)) {
419
-			case 4: {
420
-				// CMYK
421
-				$color .= sprintf('%F %F %F %F', (max(0, min(100, floatval($c[0]))) / 100), (max(0, min(100, floatval($c[1]))) / 100), (max(0, min(100, floatval($c[2]))) / 100), (max(0, min(100, floatval($c[3]))) / 100));
422
-				break;
423
-			}
424
-			case 3: {
425
-				// RGB
426
-				$color .= sprintf('%F %F %F', (max(0, min(255, floatval($c[0]))) / 255), (max(0, min(255, floatval($c[1]))) / 255), (max(0, min(255, floatval($c[2]))) / 255));
427
-				break;
428
-			}
429
-			case 1: {
430
-				// grayscale
431
-				$color .= sprintf('%F', (max(0, min(255, floatval($c[0]))) / 255));
432
-				break;
433
-			}
434
-		}
435
-		$color .= ']';
436
-		return $color;
437
-	}
408
+    /**
409
+     * Convert a color array into a string representation.
410
+     * @param $c (array) Array of colors.
411
+     * @return (string) The color array representation.
412
+     * @since 5.9.137 (2011-12-01)
413
+     * @public static
414
+     */
415
+    public static function getColorStringFromArray($c) {
416
+        $c = array_values($c);
417
+        $color = '[';
418
+        switch (count($c)) {
419
+            case 4: {
420
+                // CMYK
421
+                $color .= sprintf('%F %F %F %F', (max(0, min(100, floatval($c[0]))) / 100), (max(0, min(100, floatval($c[1]))) / 100), (max(0, min(100, floatval($c[2]))) / 100), (max(0, min(100, floatval($c[3]))) / 100));
422
+                break;
423
+            }
424
+            case 3: {
425
+                // RGB
426
+                $color .= sprintf('%F %F %F', (max(0, min(255, floatval($c[0]))) / 255), (max(0, min(255, floatval($c[1]))) / 255), (max(0, min(255, floatval($c[2]))) / 255));
427
+                break;
428
+            }
429
+            case 1: {
430
+                // grayscale
431
+                $color .= sprintf('%F', (max(0, min(255, floatval($c[0]))) / 255));
432
+                break;
433
+            }
434
+        }
435
+        $color .= ']';
436
+        return $color;
437
+    }
438 438
 
439
-	/**
440
-	 * Convert color to javascript color.
441
-	 * @param $color (string) color name or "#RRGGBB"
442
-	 * @protected
443
-	 * @since 2.1.002 (2008-02-12)
444
-	 * @public static
445
-	 */
446
-	public static function _JScolor($color) {
447
-		if (substr($color, 0, 1) == '#') {
448
-			return sprintf("['RGB',%F,%F,%F]", (hexdec(substr($color, 1, 2)) / 255), (hexdec(substr($color, 3, 2)) / 255), (hexdec(substr($color, 5, 2)) / 255));
449
-		}
450
-		if (!in_array($color, self::$jscolor)) {
451
-			// default transparent color
452
-			$color = $jscolor[0];
453
-		}
454
-		return 'color.'.$color;
455
-	}
439
+    /**
440
+     * Convert color to javascript color.
441
+     * @param $color (string) color name or "#RRGGBB"
442
+     * @protected
443
+     * @since 2.1.002 (2008-02-12)
444
+     * @public static
445
+     */
446
+    public static function _JScolor($color) {
447
+        if (substr($color, 0, 1) == '#') {
448
+            return sprintf("['RGB',%F,%F,%F]", (hexdec(substr($color, 1, 2)) / 255), (hexdec(substr($color, 3, 2)) / 255), (hexdec(substr($color, 5, 2)) / 255));
449
+        }
450
+        if (!in_array($color, self::$jscolor)) {
451
+            // default transparent color
452
+            $color = $jscolor[0];
453
+        }
454
+        return 'color.'.$color;
455
+    }
456 456
 
457 457
 
458 458
 } // END OF TCPDF_COLORS CLASS
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * Array of WEB safe colors
52 52
 	 * @public static
53 53
 	 */
54
-	public static $webcolor = array (
54
+	public static $webcolor = array(
55 55
 		'aliceblue' => 'f0f8ff',
56 56
 		'antiquewhite' => 'faebd7',
57 57
 		'aqua' => '00ffff',
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	 * Array of valid JavaScript color names
208 208
 	 * @public static
209 209
 	 */
210
-	public static $jscolor = array ('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray');
210
+	public static $jscolor = array('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray');
211 211
 
212 212
 	/**
213 213
 	 * Array of Spot colors (C,M,Y,K,name)
@@ -216,22 +216,22 @@  discard block
 block discarded – undo
216 216
 	 * Common industry standard spot colors are: ANPA-COLOR, DIC, FOCOLTONE, GCMI, HKS, PANTONE, TOYO, TRUMATCH.
217 217
 	 * @public static
218 218
 	 */
219
-	public static $spotcolor = array (
219
+	public static $spotcolor = array(
220 220
 		// special registration colors
221
-		'none'    => array(  0,   0,   0,   0, 'None'),
221
+		'none'    => array(0, 0, 0, 0, 'None'),
222 222
 		'all'     => array(100, 100, 100, 100, 'All'),
223 223
 		// standard CMYK colors
224
-		'cyan'    => array(100,   0,   0,   0, 'Cyan'),
225
-		'magenta' => array(  0, 100,   0,   0, 'Magenta'),
226
-		'yellow'  => array(  0,   0, 100,   0, 'Yellow'),
227
-		'key'     => array(  0,   0,   0, 100, 'Key'),
224
+		'cyan'    => array(100, 0, 0, 0, 'Cyan'),
225
+		'magenta' => array(0, 100, 0, 0, 'Magenta'),
226
+		'yellow'  => array(0, 0, 100, 0, 'Yellow'),
227
+		'key'     => array(0, 0, 0, 100, 'Key'),
228 228
 		// alias
229
-		'white'   => array(  0,   0,   0,   0, 'White'),
230
-		'black'   => array(  0,   0,   0, 100, 'Black'),
229
+		'white'   => array(0, 0, 0, 0, 'White'),
230
+		'black'   => array(0, 0, 0, 100, 'Black'),
231 231
 		// standard RGB colors
232
-		'red'     => array(  0, 100, 100,   0, 'Red'),
233
-		'green'   => array(100,   0, 100,   0, 'Green'),
234
-		'blue'    => array(100, 100,   0,   0, 'Blue'),
232
+		'red'     => array(0, 100, 100, 0, 'Red'),
233
+		'green'   => array(100, 0, 100, 0, 'Green'),
234
+		'blue'    => array(100, 100, 0, 0, 'Blue'),
235 235
 		// Add here standard spot colors or dynamically define them with AddSpotColor()
236 236
 		// ...
237 237
 	); // end of spot colors
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	 * @return array RGB or CMYK color, or false in case of error.
271 271
 	 * @public static
272 272
 	 */
273
-	public static function convertHTMLColorToDec($hcolor, &$spotc, $defcol=array('R'=>128,'G'=>128,'B'=>128)) {
273
+	public static function convertHTMLColorToDec($hcolor, &$spotc, $defcol = array('R'=>128, 'G'=>128, 'B'=>128)) {
274 274
 		$color = preg_replace('/[\s]*/', '', $hcolor); // remove extra spaces
275 275
 		$color = strtolower($color);
276 276
 		// check for javascript color array syntax
@@ -280,22 +280,22 @@  discard block
 block discarded – undo
280 280
 				switch ($m[1]) {
281 281
 					case 'cmyk': {
282 282
 						// RGB
283
-						$returncolor['C'] = max(0, min(100, (floatval($m[2]) * 100)));
284
-						$returncolor['M'] = max(0, min(100, (floatval($m[3]) * 100)));
285
-						$returncolor['Y'] = max(0, min(100, (floatval($m[4]) * 100)));
286
-						$returncolor['K'] = max(0, min(100, (floatval($m[5]) * 100)));
283
+						$returncolor['C'] = max(0, min(100, (floatval($m[2])*100)));
284
+						$returncolor['M'] = max(0, min(100, (floatval($m[3])*100)));
285
+						$returncolor['Y'] = max(0, min(100, (floatval($m[4])*100)));
286
+						$returncolor['K'] = max(0, min(100, (floatval($m[5])*100)));
287 287
 						break;
288 288
 					}
289 289
 					case 'rgb': {
290 290
 						// RGB
291
-						$returncolor['R'] = max(0, min(255, (floatval($m[2]) * 255)));
292
-						$returncolor['G'] = max(0, min(255, (floatval($m[3]) * 255)));
293
-						$returncolor['B'] = max(0, min(255, (floatval($m[4]) * 255)));
291
+						$returncolor['R'] = max(0, min(255, (floatval($m[2])*255)));
292
+						$returncolor['G'] = max(0, min(255, (floatval($m[3])*255)));
293
+						$returncolor['B'] = max(0, min(255, (floatval($m[4])*255)));
294 294
 						break;
295 295
 					}
296 296
 					case 'g': {
297 297
 						// grayscale
298
-						$returncolor['G'] = max(0, min(255, (floatval($m[2]) * 255)));
298
+						$returncolor['G'] = max(0, min(255, (floatval($m[2])*255)));
299 299
 						break;
300 300
 					}
301 301
 					case 't':
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 			foreach ($returncolor as $key => $val) {
326 326
 				if (strpos($val, '%') > 0) {
327 327
 					// percentage
328
-					$returncolor[$key] = (255 * intval($val) / 100);
328
+					$returncolor[$key] = (255*intval($val)/100);
329 329
 				} else {
330 330
 					$returncolor[$key] = intval($val);
331 331
 				}
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 			foreach ($returncolor as $key => $val) {
343 343
 				if (strpos($val, '%') !== false) {
344 344
 					// percentage
345
-					$returncolor[$key] = (100 * intval($val) / 100);
345
+					$returncolor[$key] = (100*intval($val)/100);
346 346
 				} else {
347 347
 					$returncolor[$key] = intval($val);
348 348
 				}
@@ -391,10 +391,10 @@  discard block
 block discarded – undo
391 391
 			case 8: {
392 392
 				// 8-digit CMYK hexadecimal representation
393 393
 				$returncolor = array();
394
-				$returncolor['C'] = max(0, min(100, round(hexdec(substr($color_code, 0, 2)) / 2.55)));
395
-				$returncolor['M'] = max(0, min(100, round(hexdec(substr($color_code, 2, 2)) / 2.55)));
396
-				$returncolor['Y'] = max(0, min(100, round(hexdec(substr($color_code, 4, 2)) / 2.55)));
397
-				$returncolor['K'] = max(0, min(100, round(hexdec(substr($color_code, 6, 2)) / 2.55)));
394
+				$returncolor['C'] = max(0, min(100, round(hexdec(substr($color_code, 0, 2))/2.55)));
395
+				$returncolor['M'] = max(0, min(100, round(hexdec(substr($color_code, 2, 2))/2.55)));
396
+				$returncolor['Y'] = max(0, min(100, round(hexdec(substr($color_code, 4, 2))/2.55)));
397
+				$returncolor['K'] = max(0, min(100, round(hexdec(substr($color_code, 6, 2))/2.55)));
398 398
 				break;
399 399
 			}
400 400
 			default: {
@@ -418,17 +418,17 @@  discard block
 block discarded – undo
418 418
 		switch (count($c)) {
419 419
 			case 4: {
420 420
 				// CMYK
421
-				$color .= sprintf('%F %F %F %F', (max(0, min(100, floatval($c[0]))) / 100), (max(0, min(100, floatval($c[1]))) / 100), (max(0, min(100, floatval($c[2]))) / 100), (max(0, min(100, floatval($c[3]))) / 100));
421
+				$color .= sprintf('%F %F %F %F', (max(0, min(100, floatval($c[0])))/100), (max(0, min(100, floatval($c[1])))/100), (max(0, min(100, floatval($c[2])))/100), (max(0, min(100, floatval($c[3])))/100));
422 422
 				break;
423 423
 			}
424 424
 			case 3: {
425 425
 				// RGB
426
-				$color .= sprintf('%F %F %F', (max(0, min(255, floatval($c[0]))) / 255), (max(0, min(255, floatval($c[1]))) / 255), (max(0, min(255, floatval($c[2]))) / 255));
426
+				$color .= sprintf('%F %F %F', (max(0, min(255, floatval($c[0])))/255), (max(0, min(255, floatval($c[1])))/255), (max(0, min(255, floatval($c[2])))/255));
427 427
 				break;
428 428
 			}
429 429
 			case 1: {
430 430
 				// grayscale
431
-				$color .= sprintf('%F', (max(0, min(255, floatval($c[0]))) / 255));
431
+				$color .= sprintf('%F', (max(0, min(255, floatval($c[0])))/255));
432 432
 				break;
433 433
 			}
434 434
 		}
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 	 */
446 446
 	public static function _JScolor($color) {
447 447
 		if (substr($color, 0, 1) == '#') {
448
-			return sprintf("['RGB',%F,%F,%F]", (hexdec(substr($color, 1, 2)) / 255), (hexdec(substr($color, 3, 2)) / 255), (hexdec(substr($color, 5, 2)) / 255));
448
+			return sprintf("['RGB',%F,%F,%F]", (hexdec(substr($color, 1, 2))/255), (hexdec(substr($color, 3, 2))/255), (hexdec(substr($color, 5, 2))/255));
449 449
 		}
450 450
 		if (!in_array($color, self::$jscolor)) {
451 451
 			// default transparent color
Please login to merge, or discard this patch.
phpmyfaq/inc/libs/tcpdf/include/tcpdf_filters.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	 * ASCIIHexDecode
144 144
 	 * Decodes data encoded in an ASCII hexadecimal representation, reproducing the original binary data.
145 145
 	 * @param $data (string) Data to decode.
146
-	 * @return Decoded data string.
146
+	 * @return string data string.
147 147
 	 * @since 1.0.000 (2011-05-23)
148 148
 	 * @public static
149 149
 	 */
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 * ASCII85Decode
184 184
 	 * Decodes data encoded in an ASCII base-85 representation, reproducing the original binary data.
185 185
 	 * @param $data (string) Data to decode.
186
-	 * @return Decoded data string.
186
+	 * @return string data string.
187 187
 	 * @since 1.0.000 (2011-05-23)
188 188
 	 * @public static
189 189
 	 */
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * LZWDecode
268 268
 	 * Decompresses data encoded using the LZW (Lempel-Ziv-Welch) adaptive compression method, reproducing the original text or binary data.
269 269
 	 * @param $data (string) Data to decode.
270
-	 * @return Decoded data string.
270
+	 * @return string data string.
271 271
 	 * @since 1.0.000 (2011-05-23)
272 272
 	 * @public static
273 273
 	 */
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
 
467 467
 	/**
468 468
 	 * Throw an exception.
469
-	 * @param $msg (string) The error message
469
+	 * @param string $msg (string) The error message
470 470
 	 * @since 1.0.000 (2011-05-23)
471 471
 	 * @public static
472 472
 	 */
Please login to merge, or discard this patch.
Indentation   +405 added lines, -405 removed lines patch added patch discarded remove patch
@@ -50,429 +50,429 @@
 block discarded – undo
50 50
  */
51 51
 class TCPDF_FILTERS {
52 52
 
53
-	/**
54
-	 * Define a list of available filter decoders.
55
-	 * @private static
56
-	 */
57
-	private static $available_filters = array('ASCIIHexDecode', 'ASCII85Decode', 'LZWDecode', 'FlateDecode', 'RunLengthDecode');
53
+    /**
54
+     * Define a list of available filter decoders.
55
+     * @private static
56
+     */
57
+    private static $available_filters = array('ASCIIHexDecode', 'ASCII85Decode', 'LZWDecode', 'FlateDecode', 'RunLengthDecode');
58 58
 
59 59
 // -----------------------------------------------------------------------------
60 60
 
61
-	/**
62
-	 * Get a list of available decoding filters.
63
-	 * @return (array) Array of available filter decoders.
64
-	 * @since 1.0.000 (2011-05-23)
65
-	 * @public static
66
-	 */
67
-	public static function getAvailableFilters() {
68
-		return self::$available_filters;
69
-	}
61
+    /**
62
+     * Get a list of available decoding filters.
63
+     * @return (array) Array of available filter decoders.
64
+     * @since 1.0.000 (2011-05-23)
65
+     * @public static
66
+     */
67
+    public static function getAvailableFilters() {
68
+        return self::$available_filters;
69
+    }
70 70
 
71
-	/**
72
-	 * Decode data using the specified filter type.
73
-	 * @param $filter (string) Filter name.
74
-	 * @param $data (string) Data to decode.
75
-	 * @return Decoded data string.
76
-	 * @since 1.0.000 (2011-05-23)
77
-	 * @public static
78
-	 */
79
-	public static function decodeFilter($filter, $data) {
80
-		switch ($filter) {
81
-			case 'ASCIIHexDecode': {
82
-				return self::decodeFilterASCIIHexDecode($data);
83
-				break;
84
-			}
85
-			case 'ASCII85Decode': {
86
-				return self::decodeFilterASCII85Decode($data);
87
-				break;
88
-			}
89
-			case 'LZWDecode': {
90
-				return self::decodeFilterLZWDecode($data);
91
-				break;
92
-			}
93
-			case 'FlateDecode': {
94
-				return self::decodeFilterFlateDecode($data);
95
-				break;
96
-			}
97
-			case 'RunLengthDecode': {
98
-				return self::decodeFilterRunLengthDecode($data);
99
-				break;
100
-			}
101
-			case 'CCITTFaxDecode': {
102
-				return self::decodeFilterCCITTFaxDecode($data);
103
-				break;
104
-			}
105
-			case 'JBIG2Decode': {
106
-				return self::decodeFilterJBIG2Decode($data);
107
-				break;
108
-			}
109
-			case 'DCTDecode': {
110
-				return self::decodeFilterDCTDecode($data);
111
-				break;
112
-			}
113
-			case 'JPXDecode': {
114
-				return self::decodeFilterJPXDecode($data);
115
-				break;
116
-			}
117
-			case 'Crypt': {
118
-				return self::decodeFilterCrypt($data);
119
-				break;
120
-			}
121
-			default: {
122
-				return self::decodeFilterStandard($data);
123
-				break;
124
-			}
125
-		}
126
-	}
71
+    /**
72
+     * Decode data using the specified filter type.
73
+     * @param $filter (string) Filter name.
74
+     * @param $data (string) Data to decode.
75
+     * @return Decoded data string.
76
+     * @since 1.0.000 (2011-05-23)
77
+     * @public static
78
+     */
79
+    public static function decodeFilter($filter, $data) {
80
+        switch ($filter) {
81
+            case 'ASCIIHexDecode': {
82
+                return self::decodeFilterASCIIHexDecode($data);
83
+                break;
84
+            }
85
+            case 'ASCII85Decode': {
86
+                return self::decodeFilterASCII85Decode($data);
87
+                break;
88
+            }
89
+            case 'LZWDecode': {
90
+                return self::decodeFilterLZWDecode($data);
91
+                break;
92
+            }
93
+            case 'FlateDecode': {
94
+                return self::decodeFilterFlateDecode($data);
95
+                break;
96
+            }
97
+            case 'RunLengthDecode': {
98
+                return self::decodeFilterRunLengthDecode($data);
99
+                break;
100
+            }
101
+            case 'CCITTFaxDecode': {
102
+                return self::decodeFilterCCITTFaxDecode($data);
103
+                break;
104
+            }
105
+            case 'JBIG2Decode': {
106
+                return self::decodeFilterJBIG2Decode($data);
107
+                break;
108
+            }
109
+            case 'DCTDecode': {
110
+                return self::decodeFilterDCTDecode($data);
111
+                break;
112
+            }
113
+            case 'JPXDecode': {
114
+                return self::decodeFilterJPXDecode($data);
115
+                break;
116
+            }
117
+            case 'Crypt': {
118
+                return self::decodeFilterCrypt($data);
119
+                break;
120
+            }
121
+            default: {
122
+                return self::decodeFilterStandard($data);
123
+                break;
124
+            }
125
+        }
126
+    }
127 127
 
128
-	// --- FILTERS (PDF 32000-2008 - 7.4 Filters) ------------------------------
128
+    // --- FILTERS (PDF 32000-2008 - 7.4 Filters) ------------------------------
129 129
 
130
-	/**
131
-	 * Standard
132
-	 * Default decoding filter (leaves data unchanged).
133
-	 * @param $data (string) Data to decode.
134
-	 * @return Decoded data string.
135
-	 * @since 1.0.000 (2011-05-23)
136
-	 * @public static
137
-	 */
138
-	public static function decodeFilterStandard($data) {
139
-		return $data;
140
-	}
130
+    /**
131
+     * Standard
132
+     * Default decoding filter (leaves data unchanged).
133
+     * @param $data (string) Data to decode.
134
+     * @return Decoded data string.
135
+     * @since 1.0.000 (2011-05-23)
136
+     * @public static
137
+     */
138
+    public static function decodeFilterStandard($data) {
139
+        return $data;
140
+    }
141 141
 
142
-	/**
143
-	 * ASCIIHexDecode
144
-	 * Decodes data encoded in an ASCII hexadecimal representation, reproducing the original binary data.
145
-	 * @param $data (string) Data to decode.
146
-	 * @return Decoded data string.
147
-	 * @since 1.0.000 (2011-05-23)
148
-	 * @public static
149
-	 */
150
-	public static function decodeFilterASCIIHexDecode($data) {
151
-		// intialize string to return
152
-		$decoded = '';
153
-		// all white-space characters shall be ignored
154
-		$data = preg_replace('/[\s]/', '', $data);
155
-		// check for EOD character: GREATER-THAN SIGN (3Eh)
156
-		$eod = strpos($data, '>');
157
-		if ($eod !== false) {
158
-			// remove EOD and extra data (if any)
159
-			$data = substr($data, 0, $eod);
160
-			$eod = true;
161
-		}
162
-		// get data length
163
-		$data_length = strlen($data);
164
-		if (($data_length % 2) != 0) {
165
-			// odd number of hexadecimal digits
166
-			if ($eod) {
167
-				// EOD shall behave as if a 0 (zero) followed the last digit
168
-				$data = substr($data, 0, -1).'0'.substr($data, -1);
169
-			} else {
170
-				self::Error('decodeFilterASCIIHexDecode: invalid code');
171
-			}
172
-		}
173
-		// check for invalid characters
174
-		if (preg_match('/[^a-fA-F\d]/', $data) > 0) {
175
-			self::Error('decodeFilterASCIIHexDecode: invalid code');
176
-		}
177
-		// get one byte of binary data for each pair of ASCII hexadecimal digits
178
-		$decoded = pack('H*', $data);
179
-		return $decoded;
180
-	}
142
+    /**
143
+     * ASCIIHexDecode
144
+     * Decodes data encoded in an ASCII hexadecimal representation, reproducing the original binary data.
145
+     * @param $data (string) Data to decode.
146
+     * @return Decoded data string.
147
+     * @since 1.0.000 (2011-05-23)
148
+     * @public static
149
+     */
150
+    public static function decodeFilterASCIIHexDecode($data) {
151
+        // intialize string to return
152
+        $decoded = '';
153
+        // all white-space characters shall be ignored
154
+        $data = preg_replace('/[\s]/', '', $data);
155
+        // check for EOD character: GREATER-THAN SIGN (3Eh)
156
+        $eod = strpos($data, '>');
157
+        if ($eod !== false) {
158
+            // remove EOD and extra data (if any)
159
+            $data = substr($data, 0, $eod);
160
+            $eod = true;
161
+        }
162
+        // get data length
163
+        $data_length = strlen($data);
164
+        if (($data_length % 2) != 0) {
165
+            // odd number of hexadecimal digits
166
+            if ($eod) {
167
+                // EOD shall behave as if a 0 (zero) followed the last digit
168
+                $data = substr($data, 0, -1).'0'.substr($data, -1);
169
+            } else {
170
+                self::Error('decodeFilterASCIIHexDecode: invalid code');
171
+            }
172
+        }
173
+        // check for invalid characters
174
+        if (preg_match('/[^a-fA-F\d]/', $data) > 0) {
175
+            self::Error('decodeFilterASCIIHexDecode: invalid code');
176
+        }
177
+        // get one byte of binary data for each pair of ASCII hexadecimal digits
178
+        $decoded = pack('H*', $data);
179
+        return $decoded;
180
+    }
181 181
 
182
-	/**
183
-	 * ASCII85Decode
184
-	 * Decodes data encoded in an ASCII base-85 representation, reproducing the original binary data.
185
-	 * @param $data (string) Data to decode.
186
-	 * @return Decoded data string.
187
-	 * @since 1.0.000 (2011-05-23)
188
-	 * @public static
189
-	 */
190
-	public static function decodeFilterASCII85Decode($data) {
191
-		// intialize string to return
192
-		$decoded = '';
193
-		// all white-space characters shall be ignored
194
-		$data = preg_replace('/[\s]/', '', $data);
195
-		// remove start sequence 2-character sequence <~ (3Ch)(7Eh)
196
-		if (strpos($data, '<~') !== false) {
197
-			// remove EOD and extra data (if any)
198
-			$data = substr($data, 2);
199
-		}
200
-		// check for EOD: 2-character sequence ~> (7Eh)(3Eh)
201
-		$eod = strpos($data, '~>');
202
-		if ($eod !== false) {
203
-			// remove EOD and extra data (if any)
204
-			$data = substr($data, 0, $eod);
205
-		}
206
-		// data length
207
-		$data_length = strlen($data);
208
-		// check for invalid characters
209
-		if (preg_match('/[^\x21-\x75,\x74]/', $data) > 0) {
210
-			self::Error('decodeFilterASCII85Decode: invalid code');
211
-		}
212
-		// z sequence
213
-		$zseq = chr(0).chr(0).chr(0).chr(0);
214
-		// position inside a group of 4 bytes (0-3)
215
-		$group_pos = 0;
216
-		$tuple = 0;
217
-		$pow85 = array((85*85*85*85), (85*85*85), (85*85), 85, 1);
218
-		$last_pos = ($data_length - 1);
219
-		// for each byte
220
-		for ($i = 0; $i < $data_length; ++$i) {
221
-			// get char value
222
-			$char = ord($data[$i]);
223
-			if ($char == 122) { // 'z'
224
-				if ($group_pos == 0) {
225
-					$decoded .= $zseq;
226
-				} else {
227
-					self::Error('decodeFilterASCII85Decode: invalid code');
228
-				}
229
-			} else {
230
-				// the value represented by a group of 5 characters should never be greater than 2^32 - 1
231
-				$tuple += (($char - 33) * $pow85[$group_pos]);
232
-				if ($group_pos == 4) {
233
-					$decoded .= chr($tuple >> 24).chr($tuple >> 16).chr($tuple >> 8).chr($tuple);
234
-					$tuple = 0;
235
-					$group_pos = 0;
236
-				} else {
237
-					++$group_pos;
238
-				}
239
-			}
240
-		}
241
-		if ($group_pos > 1) {
242
-			$tuple += $pow85[($group_pos - 1)];
243
-		}
244
-		// last tuple (if any)
245
-		switch ($group_pos) {
246
-			case 4: {
247
-				$decoded .= chr($tuple >> 24).chr($tuple >> 16).chr($tuple >> 8);
248
-				break;
249
-			}
250
-			case 3: {
251
-				$decoded .= chr($tuple >> 24).chr($tuple >> 16);
252
-				break;
253
-			}
254
-			case 2: {
255
-				$decoded .= chr($tuple >> 24);
256
-				break;
257
-			}
258
-			case 1: {
259
-				self::Error('decodeFilterASCII85Decode: invalid code');
260
-				break;
261
-			}
262
-		}
263
-		return $decoded;
264
-	}
182
+    /**
183
+     * ASCII85Decode
184
+     * Decodes data encoded in an ASCII base-85 representation, reproducing the original binary data.
185
+     * @param $data (string) Data to decode.
186
+     * @return Decoded data string.
187
+     * @since 1.0.000 (2011-05-23)
188
+     * @public static
189
+     */
190
+    public static function decodeFilterASCII85Decode($data) {
191
+        // intialize string to return
192
+        $decoded = '';
193
+        // all white-space characters shall be ignored
194
+        $data = preg_replace('/[\s]/', '', $data);
195
+        // remove start sequence 2-character sequence <~ (3Ch)(7Eh)
196
+        if (strpos($data, '<~') !== false) {
197
+            // remove EOD and extra data (if any)
198
+            $data = substr($data, 2);
199
+        }
200
+        // check for EOD: 2-character sequence ~> (7Eh)(3Eh)
201
+        $eod = strpos($data, '~>');
202
+        if ($eod !== false) {
203
+            // remove EOD and extra data (if any)
204
+            $data = substr($data, 0, $eod);
205
+        }
206
+        // data length
207
+        $data_length = strlen($data);
208
+        // check for invalid characters
209
+        if (preg_match('/[^\x21-\x75,\x74]/', $data) > 0) {
210
+            self::Error('decodeFilterASCII85Decode: invalid code');
211
+        }
212
+        // z sequence
213
+        $zseq = chr(0).chr(0).chr(0).chr(0);
214
+        // position inside a group of 4 bytes (0-3)
215
+        $group_pos = 0;
216
+        $tuple = 0;
217
+        $pow85 = array((85*85*85*85), (85*85*85), (85*85), 85, 1);
218
+        $last_pos = ($data_length - 1);
219
+        // for each byte
220
+        for ($i = 0; $i < $data_length; ++$i) {
221
+            // get char value
222
+            $char = ord($data[$i]);
223
+            if ($char == 122) { // 'z'
224
+                if ($group_pos == 0) {
225
+                    $decoded .= $zseq;
226
+                } else {
227
+                    self::Error('decodeFilterASCII85Decode: invalid code');
228
+                }
229
+            } else {
230
+                // the value represented by a group of 5 characters should never be greater than 2^32 - 1
231
+                $tuple += (($char - 33) * $pow85[$group_pos]);
232
+                if ($group_pos == 4) {
233
+                    $decoded .= chr($tuple >> 24).chr($tuple >> 16).chr($tuple >> 8).chr($tuple);
234
+                    $tuple = 0;
235
+                    $group_pos = 0;
236
+                } else {
237
+                    ++$group_pos;
238
+                }
239
+            }
240
+        }
241
+        if ($group_pos > 1) {
242
+            $tuple += $pow85[($group_pos - 1)];
243
+        }
244
+        // last tuple (if any)
245
+        switch ($group_pos) {
246
+            case 4: {
247
+                $decoded .= chr($tuple >> 24).chr($tuple >> 16).chr($tuple >> 8);
248
+                break;
249
+            }
250
+            case 3: {
251
+                $decoded .= chr($tuple >> 24).chr($tuple >> 16);
252
+                break;
253
+            }
254
+            case 2: {
255
+                $decoded .= chr($tuple >> 24);
256
+                break;
257
+            }
258
+            case 1: {
259
+                self::Error('decodeFilterASCII85Decode: invalid code');
260
+                break;
261
+            }
262
+        }
263
+        return $decoded;
264
+    }
265 265
 
266
-	/**
267
-	 * LZWDecode
268
-	 * Decompresses data encoded using the LZW (Lempel-Ziv-Welch) adaptive compression method, reproducing the original text or binary data.
269
-	 * @param $data (string) Data to decode.
270
-	 * @return Decoded data string.
271
-	 * @since 1.0.000 (2011-05-23)
272
-	 * @public static
273
-	 */
274
-	public static function decodeFilterLZWDecode($data) {
275
-		// intialize string to return
276
-		$decoded = '';
277
-		// data length
278
-		$data_length = strlen($data);
279
-		// convert string to binary string
280
-		$bitstring = '';
281
-		for ($i = 0; $i < $data_length; ++$i) {
282
-			$bitstring .= sprintf('%08b', ord($data{$i}));
283
-		}
284
-		// get the number of bits
285
-		$data_length = strlen($bitstring);
286
-		// initialize code length in bits
287
-		$bitlen = 9;
288
-		// initialize dictionary index
289
-		$dix = 258;
290
-		// initialize the dictionary (with the first 256 entries).
291
-		$dictionary = array();
292
-		for ($i = 0; $i < 256; ++$i) {
293
-			$dictionary[$i] = chr($i);
294
-		}
295
-		// previous val
296
-		$prev_index = 0;
297
-		// while we encounter EOD marker (257), read code_length bits
298
-		while (($data_length > 0) AND (($index = bindec(substr($bitstring, 0, $bitlen))) != 257)) {
299
-			// remove read bits from string
300
-			$bitstring = substr($bitstring, $bitlen);
301
-			// update number of bits
302
-			$data_length -= $bitlen;
303
-			if ($index == 256) { // clear-table marker
304
-				// reset code length in bits
305
-				$bitlen = 9;
306
-				// reset dictionary index
307
-				$dix = 258;
308
-				$prev_index = 256;
309
-				// reset the dictionary (with the first 256 entries).
310
-				$dictionary = array();
311
-				for ($i = 0; $i < 256; ++$i) {
312
-					$dictionary[$i] = chr($i);
313
-				}
314
-			} elseif ($prev_index == 256) {
315
-				// first entry
316
-				$decoded .= $dictionary[$index];
317
-				$prev_index = $index;
318
-			} else {
319
-				// check if index exist in the dictionary
320
-				if ($index < $dix) {
321
-					// index exist on dictionary
322
-					$decoded .= $dictionary[$index];
323
-					$dic_val = $dictionary[$prev_index].$dictionary[$index][0];
324
-					// store current index
325
-					$prev_index = $index;
326
-				} else {
327
-					// index do not exist on dictionary
328
-					$dic_val = $dictionary[$prev_index].$dictionary[$prev_index][0];
329
-					$decoded .= $dic_val;
330
-				}
331
-				// update dictionary
332
-				$dictionary[$dix] = $dic_val;
333
-				++$dix;
334
-				// change bit length by case
335
-				if ($dix == 2047) {
336
-					$bitlen = 12;
337
-				} elseif ($dix == 1023) {
338
-					$bitlen = 11;
339
-				} elseif ($dix == 511) {
340
-					$bitlen = 10;
341
-				}
342
-			}
343
-		}
344
-		return $decoded;
345
-	}
266
+    /**
267
+     * LZWDecode
268
+     * Decompresses data encoded using the LZW (Lempel-Ziv-Welch) adaptive compression method, reproducing the original text or binary data.
269
+     * @param $data (string) Data to decode.
270
+     * @return Decoded data string.
271
+     * @since 1.0.000 (2011-05-23)
272
+     * @public static
273
+     */
274
+    public static function decodeFilterLZWDecode($data) {
275
+        // intialize string to return
276
+        $decoded = '';
277
+        // data length
278
+        $data_length = strlen($data);
279
+        // convert string to binary string
280
+        $bitstring = '';
281
+        for ($i = 0; $i < $data_length; ++$i) {
282
+            $bitstring .= sprintf('%08b', ord($data{$i}));
283
+        }
284
+        // get the number of bits
285
+        $data_length = strlen($bitstring);
286
+        // initialize code length in bits
287
+        $bitlen = 9;
288
+        // initialize dictionary index
289
+        $dix = 258;
290
+        // initialize the dictionary (with the first 256 entries).
291
+        $dictionary = array();
292
+        for ($i = 0; $i < 256; ++$i) {
293
+            $dictionary[$i] = chr($i);
294
+        }
295
+        // previous val
296
+        $prev_index = 0;
297
+        // while we encounter EOD marker (257), read code_length bits
298
+        while (($data_length > 0) AND (($index = bindec(substr($bitstring, 0, $bitlen))) != 257)) {
299
+            // remove read bits from string
300
+            $bitstring = substr($bitstring, $bitlen);
301
+            // update number of bits
302
+            $data_length -= $bitlen;
303
+            if ($index == 256) { // clear-table marker
304
+                // reset code length in bits
305
+                $bitlen = 9;
306
+                // reset dictionary index
307
+                $dix = 258;
308
+                $prev_index = 256;
309
+                // reset the dictionary (with the first 256 entries).
310
+                $dictionary = array();
311
+                for ($i = 0; $i < 256; ++$i) {
312
+                    $dictionary[$i] = chr($i);
313
+                }
314
+            } elseif ($prev_index == 256) {
315
+                // first entry
316
+                $decoded .= $dictionary[$index];
317
+                $prev_index = $index;
318
+            } else {
319
+                // check if index exist in the dictionary
320
+                if ($index < $dix) {
321
+                    // index exist on dictionary
322
+                    $decoded .= $dictionary[$index];
323
+                    $dic_val = $dictionary[$prev_index].$dictionary[$index][0];
324
+                    // store current index
325
+                    $prev_index = $index;
326
+                } else {
327
+                    // index do not exist on dictionary
328
+                    $dic_val = $dictionary[$prev_index].$dictionary[$prev_index][0];
329
+                    $decoded .= $dic_val;
330
+                }
331
+                // update dictionary
332
+                $dictionary[$dix] = $dic_val;
333
+                ++$dix;
334
+                // change bit length by case
335
+                if ($dix == 2047) {
336
+                    $bitlen = 12;
337
+                } elseif ($dix == 1023) {
338
+                    $bitlen = 11;
339
+                } elseif ($dix == 511) {
340
+                    $bitlen = 10;
341
+                }
342
+            }
343
+        }
344
+        return $decoded;
345
+    }
346 346
 
347
-	/**
348
-	 * FlateDecode
349
-	 * Decompresses data encoded using the zlib/deflate compression method, reproducing the original text or binary data.
350
-	 * @param $data (string) Data to decode.
351
-	 * @return Decoded data string.
352
-	 * @since 1.0.000 (2011-05-23)
353
-	 * @public static
354
-	 */
355
-	public static function decodeFilterFlateDecode($data) {
356
-		// intialize string to return
357
-		$decoded = @gzuncompress($data);
358
-		if ($decoded === false) {
359
-			self::Error('decodeFilterFlateDecode: invalid code');
360
-		}
361
-		return $decoded;
362
-	}
347
+    /**
348
+     * FlateDecode
349
+     * Decompresses data encoded using the zlib/deflate compression method, reproducing the original text or binary data.
350
+     * @param $data (string) Data to decode.
351
+     * @return Decoded data string.
352
+     * @since 1.0.000 (2011-05-23)
353
+     * @public static
354
+     */
355
+    public static function decodeFilterFlateDecode($data) {
356
+        // intialize string to return
357
+        $decoded = @gzuncompress($data);
358
+        if ($decoded === false) {
359
+            self::Error('decodeFilterFlateDecode: invalid code');
360
+        }
361
+        return $decoded;
362
+    }
363 363
 
364
-	/**
365
-	 * RunLengthDecode
366
-	 * Decompresses data encoded using a byte-oriented run-length encoding algorithm.
367
-	 * @param $data (string) Data to decode.
368
-	 * @since 1.0.000 (2011-05-23)
369
-	 * @public static
370
-	 */
371
-	public static function decodeFilterRunLengthDecode($data) {
372
-		// intialize string to return
373
-		$decoded = '';
374
-		// data length
375
-		$data_length = strlen($data);
376
-		$i = 0;
377
-		while($i < $data_length) {
378
-			// get current byte value
379
-			$byte = ord($data{$i});
380
-			if ($byte == 128) {
381
-				// a length value of 128 denote EOD
382
-				break;
383
-			} elseif ($byte < 128) {
384
-				// if the length byte is in the range 0 to 127
385
-				// the following length + 1 (1 to 128) bytes shall be copied literally during decompression
386
-				$decoded .= substr($data, ($i + 1), ($byte + 1));
387
-				// move to next block
388
-				$i += ($byte + 2);
389
-			} else {
390
-				// if length is in the range 129 to 255,
391
-				// the following single byte shall be copied 257 - length (2 to 128) times during decompression
392
-				$decoded .= str_repeat($data{($i + 1)}, (257 - $byte));
393
-				// move to next block
394
-				$i += 2;
395
-			}
396
-		}
397
-		return $decoded;
398
-	}
364
+    /**
365
+     * RunLengthDecode
366
+     * Decompresses data encoded using a byte-oriented run-length encoding algorithm.
367
+     * @param $data (string) Data to decode.
368
+     * @since 1.0.000 (2011-05-23)
369
+     * @public static
370
+     */
371
+    public static function decodeFilterRunLengthDecode($data) {
372
+        // intialize string to return
373
+        $decoded = '';
374
+        // data length
375
+        $data_length = strlen($data);
376
+        $i = 0;
377
+        while($i < $data_length) {
378
+            // get current byte value
379
+            $byte = ord($data{$i});
380
+            if ($byte == 128) {
381
+                // a length value of 128 denote EOD
382
+                break;
383
+            } elseif ($byte < 128) {
384
+                // if the length byte is in the range 0 to 127
385
+                // the following length + 1 (1 to 128) bytes shall be copied literally during decompression
386
+                $decoded .= substr($data, ($i + 1), ($byte + 1));
387
+                // move to next block
388
+                $i += ($byte + 2);
389
+            } else {
390
+                // if length is in the range 129 to 255,
391
+                // the following single byte shall be copied 257 - length (2 to 128) times during decompression
392
+                $decoded .= str_repeat($data{($i + 1)}, (257 - $byte));
393
+                // move to next block
394
+                $i += 2;
395
+            }
396
+        }
397
+        return $decoded;
398
+    }
399 399
 
400
-	/**
401
-	 * CCITTFaxDecode (NOT IMPLEMETED - RETURN AN EXCEPTION)
402
-	 * Decompresses data encoded using the CCITT facsimile standard, reproducing the original data (typically monochrome image data at 1 bit per pixel).
403
-	 * @param $data (string) Data to decode.
404
-	 * @return Decoded data string.
405
-	 * @since 1.0.000 (2011-05-23)
406
-	 * @public static
407
-	 */
408
-	public static function decodeFilterCCITTFaxDecode($data) {
409
-		self::Error('~decodeFilterCCITTFaxDecode: this method has not been yet implemented');
410
-		//return $data;
411
-	}
400
+    /**
401
+     * CCITTFaxDecode (NOT IMPLEMETED - RETURN AN EXCEPTION)
402
+     * Decompresses data encoded using the CCITT facsimile standard, reproducing the original data (typically monochrome image data at 1 bit per pixel).
403
+     * @param $data (string) Data to decode.
404
+     * @return Decoded data string.
405
+     * @since 1.0.000 (2011-05-23)
406
+     * @public static
407
+     */
408
+    public static function decodeFilterCCITTFaxDecode($data) {
409
+        self::Error('~decodeFilterCCITTFaxDecode: this method has not been yet implemented');
410
+        //return $data;
411
+    }
412 412
 
413
-	/**
414
-	 * JBIG2Decode (NOT IMPLEMETED - RETURN AN EXCEPTION)
415
-	 * Decompresses data encoded using the JBIG2 standard, reproducing the original monochrome (1 bit per pixel) image data (or an approximation of that data).
416
-	 * @param $data (string) Data to decode.
417
-	 * @return Decoded data string.
418
-	 * @since 1.0.000 (2011-05-23)
419
-	 * @public static
420
-	 */
421
-	public static function decodeFilterJBIG2Decode($data) {
422
-		self::Error('~decodeFilterJBIG2Decode: this method has not been yet implemented');
423
-		//return $data;
424
-	}
413
+    /**
414
+     * JBIG2Decode (NOT IMPLEMETED - RETURN AN EXCEPTION)
415
+     * Decompresses data encoded using the JBIG2 standard, reproducing the original monochrome (1 bit per pixel) image data (or an approximation of that data).
416
+     * @param $data (string) Data to decode.
417
+     * @return Decoded data string.
418
+     * @since 1.0.000 (2011-05-23)
419
+     * @public static
420
+     */
421
+    public static function decodeFilterJBIG2Decode($data) {
422
+        self::Error('~decodeFilterJBIG2Decode: this method has not been yet implemented');
423
+        //return $data;
424
+    }
425 425
 
426
-	/**
427
-	 * DCTDecode (NOT IMPLEMETED - RETURN AN EXCEPTION)
428
-	 * Decompresses data encoded using a DCT (discrete cosine transform) technique based on the JPEG standard, reproducing image sample data that approximates the original data.
429
-	 * @param $data (string) Data to decode.
430
-	 * @return Decoded data string.
431
-	 * @since 1.0.000 (2011-05-23)
432
-	 * @public static
433
-	 */
434
-	public static function decodeFilterDCTDecode($data) {
435
-		self::Error('~decodeFilterDCTDecode: this method has not been yet implemented');
436
-		//return $data;
437
-	}
426
+    /**
427
+     * DCTDecode (NOT IMPLEMETED - RETURN AN EXCEPTION)
428
+     * Decompresses data encoded using a DCT (discrete cosine transform) technique based on the JPEG standard, reproducing image sample data that approximates the original data.
429
+     * @param $data (string) Data to decode.
430
+     * @return Decoded data string.
431
+     * @since 1.0.000 (2011-05-23)
432
+     * @public static
433
+     */
434
+    public static function decodeFilterDCTDecode($data) {
435
+        self::Error('~decodeFilterDCTDecode: this method has not been yet implemented');
436
+        //return $data;
437
+    }
438 438
 
439
-	/**
440
-	 * JPXDecode (NOT IMPLEMETED - RETURN AN EXCEPTION)
441
-	 * Decompresses data encoded using the wavelet-based JPEG2000 standard, reproducing the original image data.
442
-	 * @param $data (string) Data to decode.
443
-	 * @return Decoded data string.
444
-	 * @since 1.0.000 (2011-05-23)
445
-	 * @public static
446
-	 */
447
-	public static function decodeFilterJPXDecode($data) {
448
-		self::Error('~decodeFilterJPXDecode: this method has not been yet implemented');
449
-		//return $data;
450
-	}
439
+    /**
440
+     * JPXDecode (NOT IMPLEMETED - RETURN AN EXCEPTION)
441
+     * Decompresses data encoded using the wavelet-based JPEG2000 standard, reproducing the original image data.
442
+     * @param $data (string) Data to decode.
443
+     * @return Decoded data string.
444
+     * @since 1.0.000 (2011-05-23)
445
+     * @public static
446
+     */
447
+    public static function decodeFilterJPXDecode($data) {
448
+        self::Error('~decodeFilterJPXDecode: this method has not been yet implemented');
449
+        //return $data;
450
+    }
451 451
 
452
-	/**
453
-	 * Crypt (NOT IMPLEMETED - RETURN AN EXCEPTION)
454
-	 * Decrypts data encrypted by a security handler, reproducing the data as it was before encryption.
455
-	 * @param $data (string) Data to decode.
456
-	 * @return Decoded data string.
457
-	 * @since 1.0.000 (2011-05-23)
458
-	 * @public static
459
-	 */
460
-	public static function decodeFilterCrypt($data) {
461
-		self::Error('~decodeFilterCrypt: this method has not been yet implemented');
462
-		//return $data;
463
-	}
452
+    /**
453
+     * Crypt (NOT IMPLEMETED - RETURN AN EXCEPTION)
454
+     * Decrypts data encrypted by a security handler, reproducing the data as it was before encryption.
455
+     * @param $data (string) Data to decode.
456
+     * @return Decoded data string.
457
+     * @since 1.0.000 (2011-05-23)
458
+     * @public static
459
+     */
460
+    public static function decodeFilterCrypt($data) {
461
+        self::Error('~decodeFilterCrypt: this method has not been yet implemented');
462
+        //return $data;
463
+    }
464 464
 
465
-	// --- END FILTERS SECTION -------------------------------------------------
465
+    // --- END FILTERS SECTION -------------------------------------------------
466 466
 
467
-	/**
468
-	 * Throw an exception.
469
-	 * @param $msg (string) The error message
470
-	 * @since 1.0.000 (2011-05-23)
471
-	 * @public static
472
-	 */
473
-	public static function Error($msg) {
474
-		throw new Exception('TCPDF_PARSER ERROR: '.$msg);
475
-	}
467
+    /**
468
+     * Throw an exception.
469
+     * @param $msg (string) The error message
470
+     * @since 1.0.000 (2011-05-23)
471
+     * @public static
472
+     */
473
+    public static function Error($msg) {
474
+        throw new Exception('TCPDF_PARSER ERROR: '.$msg);
475
+    }
476 476
 
477 477
 } // END OF TCPDF_FILTERS CLASS
478 478
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 		}
162 162
 		// get data length
163 163
 		$data_length = strlen($data);
164
-		if (($data_length % 2) != 0) {
164
+		if (($data_length%2) != 0) {
165 165
 			// odd number of hexadecimal digits
166 166
 			if ($eod) {
167 167
 				// EOD shall behave as if a 0 (zero) followed the last digit
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 				}
229 229
 			} else {
230 230
 				// the value represented by a group of 5 characters should never be greater than 2^32 - 1
231
-				$tuple += (($char - 33) * $pow85[$group_pos]);
231
+				$tuple += (($char - 33)*$pow85[$group_pos]);
232 232
 				if ($group_pos == 4) {
233 233
 					$decoded .= chr($tuple >> 24).chr($tuple >> 16).chr($tuple >> 8).chr($tuple);
234 234
 					$tuple = 0;
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 		// data length
375 375
 		$data_length = strlen($data);
376 376
 		$i = 0;
377
-		while($i < $data_length) {
377
+		while ($i < $data_length) {
378 378
 			// get current byte value
379 379
 			$byte = ord($data{$i});
380 380
 			if ($byte == 128) {
Please login to merge, or discard this patch.
phpmyfaq/inc/libs/tcpdf/include/tcpdf_fonts.php 3 patches
Doc Comments   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1381,7 +1381,7 @@  discard block
 block discarded – undo
1381 1381
 	 * Outputs font widths
1382 1382
 	 * @param $font (array) font data
1383 1383
 	 * @param $cidoffset (int) offset for CID values
1384
-	 * @return PDF command string for font widths
1384
+	 * @return string command string for font widths
1385 1385
 	 * @author Nicola Asuni
1386 1386
 	 * @since 4.4.000 (2008-12-07)
1387 1387
 	 * @public static
@@ -1486,7 +1486,7 @@  discard block
 block discarded – undo
1486 1486
 	 * Returns the unicode caracter specified by the value
1487 1487
 	 * @param $c (int) UTF-8 value
1488 1488
 	 * @param $unicode (boolean) True if we are in unicode mode, false otherwise.
1489
-	 * @return Returns the specified character.
1489
+	 * @return string the specified character.
1490 1490
 	 * @since 2.3.000 (2008-03-05)
1491 1491
 	 * @public static
1492 1492
 	 */
@@ -1513,7 +1513,7 @@  discard block
 block discarded – undo
1513 1513
 	/**
1514 1514
 	 * Returns the unicode caracter specified by UTF-8 value
1515 1515
 	 * @param $c (int) UTF-8 value
1516
-	 * @return Returns the specified character.
1516
+	 * @return string the specified character.
1517 1517
 	 * @public static
1518 1518
 	 */
1519 1519
 	public static function unichrUnicode($c) {
@@ -1523,7 +1523,7 @@  discard block
 block discarded – undo
1523 1523
 	/**
1524 1524
 	 * Returns the unicode caracter specified by ASCII value
1525 1525
 	 * @param $c (int) UTF-8 value
1526
-	 * @return Returns the specified character.
1526
+	 * @return string the specified character.
1527 1527
 	 * @public static
1528 1528
 	 */
1529 1529
 	public static function unichrASCII($c) {
@@ -1615,7 +1615,7 @@  discard block
 block discarded – undo
1615 1615
 	 * @param $start (int) the starting element of $strarr.
1616 1616
 	 * @param $end (int) first element that will not be returned.
1617 1617
 	 * @param $unicode (boolean) True if we are in unicode mode, false otherwise.
1618
-	 * @return Return part of a string
1618
+	 * @return string part of a string
1619 1619
 	 * @public static
1620 1620
 	 */
1621 1621
 	public static function UTF8ArrSubString($strarr, $start='', $end='', $unicode=true) {
@@ -1637,7 +1637,7 @@  discard block
 block discarded – undo
1637 1637
 	 * @param $uniarr (string) The input array of characters.
1638 1638
 	 * @param $start (int) the starting element of $strarr.
1639 1639
 	 * @param $end (int) first element that will not be returned.
1640
-	 * @return Return part of a string
1640
+	 * @return string part of a string
1641 1641
 	 * @since 4.5.037 (2009-04-07)
1642 1642
 	 * @public static
1643 1643
 	 */
@@ -1657,8 +1657,8 @@  discard block
 block discarded – undo
1657 1657
 
1658 1658
 	/**
1659 1659
 	 * Update the CIDToGIDMap string with a new value.
1660
-	 * @param $map (string) CIDToGIDMap.
1661
-	 * @param $cid (int) CID value.
1660
+	 * @param string $map (string) CIDToGIDMap.
1661
+	 * @param integer $cid (int) CID value.
1662 1662
 	 * @param $gid (int) GID value.
1663 1663
 	 * @return (string) CIDToGIDMap.
1664 1664
 	 * @author Nicola Asuni
@@ -1741,7 +1741,7 @@  discard block
 block discarded – undo
1741 1741
 	/**
1742 1742
 	 * Converts UTF-8 characters array to array of Latin1 string<br>
1743 1743
 	 * @param $unicode (array) array containing UTF-8 unicode values
1744
-	 * @return array
1744
+	 * @return string
1745 1745
 	 * @author Nicola Asuni
1746 1746
 	 * @since 4.8.023 (2010-01-15)
1747 1747
 	 * @public static
Please login to merge, or discard this patch.
Indentation   +2481 added lines, -2481 removed lines patch added patch discarded remove patch
@@ -47,2534 +47,2534 @@
 block discarded – undo
47 47
  */
48 48
 class TCPDF_FONTS {
49 49
 
50
-	/**
51
-	 * Static cache used for speed up uniord performances
52
-	 * @protected
53
-	 */
54
-	protected static $cache_uniord = array();
50
+    /**
51
+     * Static cache used for speed up uniord performances
52
+     * @protected
53
+     */
54
+    protected static $cache_uniord = array();
55 55
 
56
-	/**
57
-	 * Convert and add the selected TrueType or Type1 font to the fonts folder (that must be writeable).
58
-	 * @param $fontfile (string) Font file (full path).
59
-	 * @param $fonttype (string) Font type. Leave empty for autodetect mode. Valid values are: TrueTypeUnicode, TrueType, Type1, CID0JP = CID-0 Japanese, CID0KR = CID-0 Korean, CID0CS = CID-0 Chinese Simplified, CID0CT = CID-0 Chinese Traditional.
60
-	 * @param $enc (string) Name of the encoding table to use. Leave empty for default mode. Omit this parameter for TrueType Unicode and symbolic fonts like Symbol or ZapfDingBats.
61
-	 * @param $flags (int) Unsigned 32-bit integer containing flags specifying various characteristics of the font (PDF32000:2008 - 9.8.2 Font Descriptor Flags): +1 for fixed font; +4 for symbol or +32 for non-symbol; +64 for italic. Fixed and Italic mode are generally autodetected so you have to set it to 32 = non-symbolic font (default) or 4 = symbolic font.
62
-	 * @param $outpath (string) Output path for generated font files (must be writeable by the web server). Leave empty for default font folder.
63
-	 * @param $platid (int) Platform ID for CMAP table to extract (when building a Unicode font for Windows this value should be 3, for Macintosh should be 1).
64
-	 * @param $encid (int) Encoding ID for CMAP table to extract (when building a Unicode font for Windows this value should be 1, for Macintosh should be 0). When Platform ID is 3, legal values for Encoding ID are: 0=Symbol, 1=Unicode, 2=ShiftJIS, 3=PRC, 4=Big5, 5=Wansung, 6=Johab, 7=Reserved, 8=Reserved, 9=Reserved, 10=UCS-4.
65
-	 * @param $addcbbox (boolean) If true includes the character bounding box information on the php font file.
66
-	 * @param $link (boolean) If true link to system font instead of copying the font data (not transportable) - Note: do not work with Type1 fonts.
67
-	 * @return (string) TCPDF font name or boolean false in case of error.
68
-	 * @author Nicola Asuni
69
-	 * @since 5.9.123 (2010-09-30)
70
-	 * @public static
71
-	 */
72
-	public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1, $addcbbox=false, $link=false) {
73
-		if (!file_exists($fontfile)) {
74
-			// Could not find file
75
-			return false;
76
-		}
77
-		// font metrics
78
-		$fmetric = array();
79
-		// build new font name for TCPDF compatibility
80
-		$font_path_parts = pathinfo($fontfile);
81
-		if (!isset($font_path_parts['filename'])) {
82
-			$font_path_parts['filename'] = substr($font_path_parts['basename'], 0, -(strlen($font_path_parts['extension']) + 1));
83
-		}
84
-		$font_name = strtolower($font_path_parts['filename']);
85
-		$font_name = preg_replace('/[^a-z0-9_]/', '', $font_name);
86
-		$search  = array('bold', 'oblique', 'italic', 'regular');
87
-		$replace = array('b', 'i', 'i', '');
88
-		$font_name = str_replace($search, $replace, $font_name);
89
-		if (empty($font_name)) {
90
-			// set generic name
91
-			$font_name = 'tcpdffont';
92
-		}
93
-		// set output path
94
-		if (empty($outpath)) {
95
-			$outpath = self::_getfontpath();
96
-		}
97
-		// check if this font already exist
98
-		if (@file_exists($outpath.$font_name.'.php')) {
99
-			// this font already exist (delete it from fonts folder to rebuild it)
100
-			return $font_name;
101
-		}
102
-		$fmetric['file'] = $font_name;
103
-		$fmetric['ctg'] = $font_name.'.ctg.z';
104
-		// get font data
105
-		$font = file_get_contents($fontfile);
106
-		$fmetric['originalsize'] = strlen($font);
107
-		// autodetect font type
108
-		if (empty($fonttype)) {
109
-			if (TCPDF_STATIC::_getULONG($font, 0) == 0x10000) {
110
-				// True Type (Unicode or not)
111
-				$fonttype = 'TrueTypeUnicode';
112
-			} elseif (substr($font, 0, 4) == 'OTTO') {
113
-				// Open Type (Unicode or not)
114
-				//Unsupported font format: OpenType with CFF data
115
-				return false;
116
-			} else {
117
-				// Type 1
118
-				$fonttype = 'Type1';
119
-			}
120
-		}
121
-		// set font type
122
-		switch ($fonttype) {
123
-			case 'CID0CT':
124
-			case 'CID0CS':
125
-			case 'CID0KR':
126
-			case 'CID0JP': {
127
-				$fmetric['type'] = 'cidfont0';
128
-				break;
129
-			}
130
-			case 'Type1': {
131
-				$fmetric['type'] = 'Type1';
132
-				if (empty($enc) AND (($flags & 4) == 0)) {
133
-					$enc = 'cp1252';
134
-				}
135
-				break;
136
-			}
137
-			case 'TrueType': {
138
-				$fmetric['type'] = 'TrueType';
139
-				break;
140
-			}
141
-			case 'TrueTypeUnicode':
142
-			default: {
143
-				$fmetric['type'] = 'TrueTypeUnicode';
144
-				break;
145
-			}
146
-		}
147
-		// set encoding maps (if any)
148
-		$fmetric['enc'] = preg_replace('/[^A-Za-z0-9_\-]/', '', $enc);
149
-		$fmetric['diff'] = '';
150
-		if (($fmetric['type'] == 'TrueType') OR ($fmetric['type'] == 'Type1')) {
151
-			if (!empty($enc) AND ($enc != 'cp1252') AND isset(TCPDF_FONT_DATA::$encmap[$enc])) {
152
-				// build differences from reference encoding
153
-				$enc_ref = TCPDF_FONT_DATA::$encmap['cp1252'];
154
-				$enc_target = TCPDF_FONT_DATA::$encmap[$enc];
155
-				$last = 0;
156
-				for ($i = 32; $i <= 255; ++$i) {
157
-					if ($enc_target != $enc_ref[$i]) {
158
-						if ($i != ($last + 1)) {
159
-							$fmetric['diff'] .= $i.' ';
160
-						}
161
-						$last = $i;
162
-						$fmetric['diff'] .= '/'.$enc_target[$i].' ';
163
-					}
164
-				}
165
-			}
166
-		}
167
-		// parse the font by type
168
-		if ($fmetric['type'] == 'Type1') {
169
-			// ---------- TYPE 1 ----------
170
-			// read first segment
171
-			$a = unpack('Cmarker/Ctype/Vsize', substr($font, 0, 6));
172
-			if ($a['marker'] != 128) {
173
-				// Font file is not a valid binary Type1
174
-				return false;
175
-			}
176
-			$fmetric['size1'] = $a['size'];
177
-			$data = substr($font, 6, $fmetric['size1']);
178
-			// read second segment
179
-			$a = unpack('Cmarker/Ctype/Vsize', substr($font, (6 + $fmetric['size1']), 6));
180
-			if ($a['marker'] != 128) {
181
-				// Font file is not a valid binary Type1
182
-				return false;
183
-			}
184
-			$fmetric['size2'] = $a['size'];
185
-			$encrypted = substr($font, (12 + $fmetric['size1']), $fmetric['size2']);
186
-			$data .= $encrypted;
187
-			// store compressed font
188
-			$fmetric['file'] .= '.z';
189
-			$fp = fopen($outpath.$fmetric['file'], 'wb');
190
-			fwrite($fp, gzcompress($data));
191
-			fclose($fp);
192
-			// get font info
193
-			$fmetric['Flags'] = $flags;
194
-			preg_match ('#/FullName[\s]*\(([^\)]*)#', $font, $matches);
195
-			$fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $matches[1]);
196
-			preg_match('#/FontBBox[\s]*{([^}]*)#', $font, $matches);
197
-			$fmetric['bbox'] = trim($matches[1]);
198
-			$bv = explode(' ', $fmetric['bbox']);
199
-			$fmetric['Ascent'] = intval($bv[3]);
200
-			$fmetric['Descent'] = intval($bv[1]);
201
-			preg_match('#/ItalicAngle[\s]*([0-9\+\-]*)#', $font, $matches);
202
-			$fmetric['italicAngle'] = intval($matches[1]);
203
-			if ($fmetric['italicAngle'] != 0) {
204
-				$fmetric['Flags'] |= 64;
205
-			}
206
-			preg_match('#/UnderlinePosition[\s]*([0-9\+\-]*)#', $font, $matches);
207
-			$fmetric['underlinePosition'] = intval($matches[1]);
208
-			preg_match('#/UnderlineThickness[\s]*([0-9\+\-]*)#', $font, $matches);
209
-			$fmetric['underlineThickness'] = intval($matches[1]);
210
-			preg_match('#/isFixedPitch[\s]*([^\s]*)#', $font, $matches);
211
-			if ($matches[1] == 'true') {
212
-				$fmetric['Flags'] |= 1;
213
-			}
214
-			// get internal map
215
-			$imap = array();
216
-			if (preg_match_all('#dup[\s]([0-9]+)[\s]*/([^\s]*)[\s]put#sU', $font, $fmap, PREG_SET_ORDER) > 0) {
217
-				foreach ($fmap as $v) {
218
-					$imap[$v[2]] = $v[1];
219
-				}
220
-			}
221
-			// decrypt eexec encrypted part
222
-			$r = 55665; // eexec encryption constant
223
-			$c1 = 52845;
224
-			$c2 = 22719;
225
-			$elen = strlen($encrypted);
226
-			$eplain = '';
227
-			for ($i = 0; $i < $elen; ++$i) {
228
-				$chr = ord($encrypted[$i]);
229
-				$eplain .= chr($chr ^ ($r >> 8));
230
-				$r = ((($chr + $r) * $c1 + $c2) % 65536);
231
-			}
232
-			if (preg_match('#/ForceBold[\s]*([^\s]*)#', $eplain, $matches) > 0) {
233
-				if ($matches[1] == 'true') {
234
-					$fmetric['Flags'] |= 0x40000;
235
-				}
236
-			}
237
-			if (preg_match('#/StdVW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
238
-				$fmetric['StemV'] = intval($matches[1]);
239
-			} else {
240
-				$fmetric['StemV'] = 70;
241
-			}
242
-			if (preg_match('#/StdHW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
243
-				$fmetric['StemH'] = intval($matches[1]);
244
-			} else {
245
-				$fmetric['StemH'] = 30;
246
-			}
247
-			if (preg_match('#/BlueValues[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
248
-				$bv = explode(' ', $matches[1]);
249
-				if (count($bv) >= 6) {
250
-					$v1 = intval($bv[2]);
251
-					$v2 = intval($bv[4]);
252
-					if ($v1 <= $v2) {
253
-						$fmetric['XHeight'] = $v1;
254
-						$fmetric['CapHeight'] = $v2;
255
-					} else {
256
-						$fmetric['XHeight'] = $v2;
257
-						$fmetric['CapHeight'] = $v1;
258
-					}
259
-				} else {
260
-					$fmetric['XHeight'] = 450;
261
-					$fmetric['CapHeight'] = 700;
262
-				}
263
-			} else {
264
-				$fmetric['XHeight'] = 450;
265
-				$fmetric['CapHeight'] = 700;
266
-			}
267
-			// get the number of random bytes at the beginning of charstrings
268
-			if (preg_match('#/lenIV[\s]*([0-9]*)#', $eplain, $matches) > 0) {
269
-				$lenIV = intval($matches[1]);
270
-			} else {
271
-				$lenIV = 4;
272
-			}
273
-			$fmetric['Leading'] = 0;
274
-			// get charstring data
275
-			$eplain = substr($eplain, (strpos($eplain, '/CharStrings') + 1));
276
-			preg_match_all('#/([A-Za-z0-9\.]*)[\s][0-9]+[\s]RD[\s](.*)[\s]ND#sU', $eplain, $matches, PREG_SET_ORDER);
277
-			if (!empty($enc) AND isset(TCPDF_FONT_DATA::$encmap[$enc])) {
278
-				$enc_map = TCPDF_FONT_DATA::$encmap[$enc];
279
-			} else {
280
-				$enc_map = false;
281
-			}
282
-			$fmetric['cw'] = '';
283
-			$fmetric['MaxWidth'] = 0;
284
-			$cwidths = array();
285
-			foreach ($matches as $k => $v) {
286
-				$cid = 0;
287
-				if (isset($imap[$v[1]])) {
288
-					$cid = $imap[$v[1]];
289
-				} elseif ($enc_map !== false) {
290
-					$cid = array_search($v[1], $enc_map);
291
-					if ($cid === false) {
292
-						$cid = 0;
293
-					} elseif ($cid > 1000) {
294
-						$cid -= 1000;
295
-					}
296
-				}
297
-				// decrypt charstring encrypted part
298
-				$r = 4330; // charstring encryption constant
299
-				$c1 = 52845;
300
-				$c2 = 22719;
301
-				$cd = $v[2];
302
-				$clen = strlen($cd);
303
-				$ccom = array();
304
-				for ($i = 0; $i < $clen; ++$i) {
305
-					$chr = ord($cd[$i]);
306
-					$ccom[] = ($chr ^ ($r >> 8));
307
-					$r = ((($chr + $r) * $c1 + $c2) % 65536);
308
-				}
309
-				// decode numbers
310
-				$cdec = array();
311
-				$ck = 0;
312
-				$i = $lenIV;
313
-				while ($i < $clen) {
314
-					if ($ccom[$i] < 32) {
315
-						$cdec[$ck] = $ccom[$i];
316
-						if (($ck > 0) AND ($cdec[$ck] == 13)) {
317
-							// hsbw command: update width
318
-							$cwidths[$cid] = $cdec[($ck - 1)];
319
-						}
320
-						++$i;
321
-					} elseif (($ccom[$i] >= 32) AND ($ccom[$i] <= 246)) {
322
-						$cdec[$ck] = ($ccom[$i] - 139);
323
-						++$i;
324
-					} elseif (($ccom[$i] >= 247) AND ($ccom[$i] <= 250)) {
325
-						$cdec[$ck] = ((($ccom[$i] - 247) * 256) + $ccom[($i + 1)] + 108);
326
-						$i += 2;
327
-					} elseif (($ccom[$i] >= 251) AND ($ccom[$i] <= 254)) {
328
-						$cdec[$ck] = ((-($ccom[$i] - 251) * 256) - $ccom[($i + 1)] - 108);
329
-						$i += 2;
330
-					} elseif ($ccom[$i] == 255) {
331
-						$sval = chr($ccom[($i + 1)]).chr($ccom[($i + 2)]).chr($ccom[($i + 3)]).chr($ccom[($i + 4)]);
332
-						$vsval = unpack('li', $sval);
333
-						$cdec[$ck] = $vsval['i'];
334
-						$i += 5;
335
-					}
336
-					++$ck;
337
-				}
338
-			} // end for each matches
339
-			$fmetric['MissingWidth'] = $cwidths[0];
340
-			$fmetric['MaxWidth'] = $fmetric['MissingWidth'];
341
-			$fmetric['AvgWidth'] = 0;
342
-			// set chars widths
343
-			for ($cid = 0; $cid <= 255; ++$cid) {
344
-				if (isset($cwidths[$cid])) {
345
-					if ($cwidths[$cid] > $fmetric['MaxWidth']) {
346
-						$fmetric['MaxWidth'] = $cwidths[$cid];
347
-					}
348
-					$fmetric['AvgWidth'] += $cwidths[$cid];
349
-					$fmetric['cw'] .= ','.$cid.'=>'.$cwidths[$cid];
350
-				} else {
351
-					$fmetric['cw'] .= ','.$cid.'=>'.$fmetric['MissingWidth'];
352
-				}
353
-			}
354
-			$fmetric['AvgWidth'] = round($fmetric['AvgWidth'] / count($cwidths));
355
-		} else {
356
-			// ---------- TRUE TYPE ----------
357
-			if ($fmetric['type'] != 'cidfont0') {
358
-				if ($link) {
359
-					// creates a symbolic link to the existing font
360
-					symlink($fontfile, $outpath.$fmetric['file']);
361
-				} else {
362
-					// store compressed font
363
-					$fmetric['file'] .= '.z';
364
-					$fp = fopen($outpath.$fmetric['file'], 'wb');
365
-					fwrite($fp, gzcompress($font));
366
-					fclose($fp);
367
-				}
368
-			}
369
-			$offset = 0; // offset position of the font data
370
-			if (TCPDF_STATIC::_getULONG($font, $offset) != 0x10000) {
371
-				// sfnt version must be 0x00010000 for TrueType version 1.0.
372
-				return false;
373
-			}
374
-			$offset += 4;
375
-			// get number of tables
376
-			$numTables = TCPDF_STATIC::_getUSHORT($font, $offset);
377
-			$offset += 2;
378
-			// skip searchRange, entrySelector and rangeShift
379
-			$offset += 6;
380
-			// tables array
381
-			$table = array();
382
-			// ---------- get tables ----------
383
-			for ($i = 0; $i < $numTables; ++$i) {
384
-				// get table info
385
-				$tag = substr($font, $offset, 4);
386
-				$offset += 4;
387
-				$table[$tag] = array();
388
-				$table[$tag]['checkSum'] = TCPDF_STATIC::_getULONG($font, $offset);
389
-				$offset += 4;
390
-				$table[$tag]['offset'] = TCPDF_STATIC::_getULONG($font, $offset);
391
-				$offset += 4;
392
-				$table[$tag]['length'] = TCPDF_STATIC::_getULONG($font, $offset);
393
-				$offset += 4;
394
-			}
395
-			// check magicNumber
396
-			$offset = $table['head']['offset'] + 12;
397
-			if (TCPDF_STATIC::_getULONG($font, $offset) != 0x5F0F3CF5) {
398
-				// magicNumber must be 0x5F0F3CF5
399
-				return false;
400
-			}
401
-			$offset += 4;
402
-			$offset += 2; // skip flags
403
-			// get FUnits
404
-			$fmetric['unitsPerEm'] = TCPDF_STATIC::_getUSHORT($font, $offset);
405
-			$offset += 2;
406
-			// units ratio constant
407
-			$urk = (1000 / $fmetric['unitsPerEm']);
408
-			$offset += 16; // skip created, modified
409
-			$xMin = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
410
-			$offset += 2;
411
-			$yMin = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
412
-			$offset += 2;
413
-			$xMax = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
414
-			$offset += 2;
415
-			$yMax = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
416
-			$offset += 2;
417
-			$fmetric['bbox'] = ''.$xMin.' '.$yMin.' '.$xMax.' '.$yMax.'';
418
-			$macStyle = TCPDF_STATIC::_getUSHORT($font, $offset);
419
-			$offset += 2;
420
-			// PDF font flags
421
-			$fmetric['Flags'] = $flags;
422
-			if (($macStyle & 2) == 2) {
423
-				// italic flag
424
-				$fmetric['Flags'] |= 64;
425
-			}
426
-			// get offset mode (indexToLocFormat : 0 = short, 1 = long)
427
-			$offset = $table['head']['offset'] + 50;
428
-			$short_offset = (TCPDF_STATIC::_getSHORT($font, $offset) == 0);
429
-			$offset += 2;
430
-			// get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table
431
-			$indexToLoc = array();
432
-			$offset = $table['loca']['offset'];
433
-			if ($short_offset) {
434
-				// short version
435
-				$tot_num_glyphs = floor($table['loca']['length'] / 2); // numGlyphs + 1
436
-				for ($i = 0; $i < $tot_num_glyphs; ++$i) {
437
-					$indexToLoc[$i] = TCPDF_STATIC::_getUSHORT($font, $offset) * 2;
438
-					$offset += 2;
439
-				}
440
-			} else {
441
-				// long version
442
-				$tot_num_glyphs = floor($table['loca']['length'] / 4); // numGlyphs + 1
443
-				for ($i = 0; $i < $tot_num_glyphs; ++$i) {
444
-					$indexToLoc[$i] = TCPDF_STATIC::_getULONG($font, $offset);
445
-					$offset += 4;
446
-				}
447
-			}
448
-			// get glyphs indexes of chars from cmap table
449
-			$offset = $table['cmap']['offset'] + 2;
450
-			$numEncodingTables = TCPDF_STATIC::_getUSHORT($font, $offset);
451
-			$offset += 2;
452
-			$encodingTables = array();
453
-			for ($i = 0; $i < $numEncodingTables; ++$i) {
454
-				$encodingTables[$i]['platformID'] = TCPDF_STATIC::_getUSHORT($font, $offset);
455
-				$offset += 2;
456
-				$encodingTables[$i]['encodingID'] = TCPDF_STATIC::_getUSHORT($font, $offset);
457
-				$offset += 2;
458
-				$encodingTables[$i]['offset'] = TCPDF_STATIC::_getULONG($font, $offset);
459
-				$offset += 4;
460
-			}
461
-			// ---------- get os/2 metrics ----------
462
-			$offset = $table['OS/2']['offset'];
463
-			$offset += 2; // skip version
464
-			// xAvgCharWidth
465
-			$fmetric['AvgWidth'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
466
-			$offset += 2;
467
-			// usWeightClass
468
-			$usWeightClass = round(TCPDF_STATIC::_getUFWORD($font, $offset) * $urk);
469
-			// estimate StemV and StemH (400 = usWeightClass for Normal - Regular font)
470
-			$fmetric['StemV'] = round((70 * $usWeightClass) / 400);
471
-			$fmetric['StemH'] = round((30 * $usWeightClass) / 400);
472
-			$offset += 2;
473
-			$offset += 2; // usWidthClass
474
-			$fsType = TCPDF_STATIC::_getSHORT($font, $offset);
475
-			$offset += 2;
476
-			if ($fsType == 2) {
477
-				// This Font cannot be modified, embedded or exchanged in any manner without first obtaining permission of the legal owner.
478
-				return false;
479
-			}
480
-			// ---------- get font name ----------
481
-			$fmetric['name'] = '';
482
-			$offset = $table['name']['offset'];
483
-			$offset += 2; // skip Format selector (=0).
484
-			// Number of NameRecords that follow n.
485
-			$numNameRecords = TCPDF_STATIC::_getUSHORT($font, $offset);
486
-			$offset += 2;
487
-			// Offset to start of string storage (from start of table).
488
-			$stringStorageOffset = TCPDF_STATIC::_getUSHORT($font, $offset);
489
-			$offset += 2;
490
-			for ($i = 0; $i < $numNameRecords; ++$i) {
491
-				$offset += 6; // skip Platform ID, Platform-specific encoding ID, Language ID.
492
-				// Name ID.
493
-				$nameID = TCPDF_STATIC::_getUSHORT($font, $offset);
494
-				$offset += 2;
495
-				if ($nameID == 6) {
496
-					// String length (in bytes).
497
-					$stringLength = TCPDF_STATIC::_getUSHORT($font, $offset);
498
-					$offset += 2;
499
-					// String offset from start of storage area (in bytes).
500
-					$stringOffset = TCPDF_STATIC::_getUSHORT($font, $offset);
501
-					$offset += 2;
502
-					$offset = ($table['name']['offset'] + $stringStorageOffset + $stringOffset);
503
-					$fmetric['name'] = substr($font, $offset, $stringLength);
504
-					$fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $fmetric['name']);
505
-					break;
506
-				} else {
507
-					$offset += 4; // skip String length, String offset
508
-				}
509
-			}
510
-			if (empty($fmetric['name'])) {
511
-				$fmetric['name'] = $font_name;
512
-			}
513
-			// ---------- get post data ----------
514
-			$offset = $table['post']['offset'];
515
-			$offset += 4; // skip Format Type
516
-			$fmetric['italicAngle'] = TCPDF_STATIC::_getFIXED($font, $offset);
517
-			$offset += 4;
518
-			$fmetric['underlinePosition'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
519
-			$offset += 2;
520
-			$fmetric['underlineThickness'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
521
-			$offset += 2;
522
-			$isFixedPitch = (TCPDF_STATIC::_getULONG($font, $offset) == 0) ? false : true;
523
-			$offset += 2;
524
-			if ($isFixedPitch) {
525
-				$fmetric['Flags'] |= 1;
526
-			}
527
-			// ---------- get hhea data ----------
528
-			$offset = $table['hhea']['offset'];
529
-			$offset += 4; // skip Table version number
530
-			// Ascender
531
-			$fmetric['Ascent'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
532
-			$offset += 2;
533
-			// Descender
534
-			$fmetric['Descent'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
535
-			$offset += 2;
536
-			// LineGap
537
-			$fmetric['Leading'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
538
-			$offset += 2;
539
-			// advanceWidthMax
540
-			$fmetric['MaxWidth'] = round(TCPDF_STATIC::_getUFWORD($font, $offset) * $urk);
541
-			$offset += 2;
542
-			$offset += 22; // skip some values
543
-			// get the number of hMetric entries in hmtx table
544
-			$numberOfHMetrics = TCPDF_STATIC::_getUSHORT($font, $offset);
545
-			// ---------- get maxp data ----------
546
-			$offset = $table['maxp']['offset'];
547
-			$offset += 4; // skip Table version number
548
-			// get the the number of glyphs in the font.
549
-			$numGlyphs = TCPDF_STATIC::_getUSHORT($font, $offset);
550
-			// ---------- get CIDToGIDMap ----------
551
-			$ctg = array();
552
-			foreach ($encodingTables as $enctable) {
553
-				// get only specified Platform ID and Encoding ID
554
-				if (($enctable['platformID'] == $platid) AND ($enctable['encodingID'] == $encid)) {
555
-					$offset = $table['cmap']['offset'] + $enctable['offset'];
556
-					$format = TCPDF_STATIC::_getUSHORT($font, $offset);
557
-					$offset += 2;
558
-					switch ($format) {
559
-						case 0: { // Format 0: Byte encoding table
560
-							$offset += 4; // skip length and version/language
561
-							for ($c = 0; $c < 256; ++$c) {
562
-								$g = TCPDF_STATIC::_getBYTE($font, $offset);
563
-								$ctg[$c] = $g;
564
-								++$offset;
565
-							}
566
-							break;
567
-						}
568
-						case 2: { // Format 2: High-byte mapping through table
569
-							$offset += 4; // skip length and version/language
570
-							$numSubHeaders = 0;
571
-							for ($i = 0; $i < 256; ++$i) {
572
-								// Array that maps high bytes to subHeaders: value is subHeader index * 8.
573
-								$subHeaderKeys[$i] = (TCPDF_STATIC::_getUSHORT($font, $offset) / 8);
574
-								$offset += 2;
575
-								if ($numSubHeaders < $subHeaderKeys[$i]) {
576
-									$numSubHeaders = $subHeaderKeys[$i];
577
-								}
578
-							}
579
-							// the number of subHeaders is equal to the max of subHeaderKeys + 1
580
-							++$numSubHeaders;
581
-							// read subHeader structures
582
-							$subHeaders = array();
583
-							$numGlyphIndexArray = 0;
584
-							for ($k = 0; $k < $numSubHeaders; ++$k) {
585
-								$subHeaders[$k]['firstCode'] = TCPDF_STATIC::_getUSHORT($font, $offset);
586
-								$offset += 2;
587
-								$subHeaders[$k]['entryCount'] = TCPDF_STATIC::_getUSHORT($font, $offset);
588
-								$offset += 2;
589
-								$subHeaders[$k]['idDelta'] = TCPDF_STATIC::_getUSHORT($font, $offset);
590
-								$offset += 2;
591
-								$subHeaders[$k]['idRangeOffset'] = TCPDF_STATIC::_getUSHORT($font, $offset);
592
-								$offset += 2;
593
-								$subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1) * 8));
594
-								$subHeaders[$k]['idRangeOffset'] /= 2;
595
-								$numGlyphIndexArray += $subHeaders[$k]['entryCount'];
596
-							}
597
-							for ($k = 0; $k < $numGlyphIndexArray; ++$k) {
598
-								$glyphIndexArray[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
599
-								$offset += 2;
600
-							}
601
-							for ($i = 0; $i < 256; ++$i) {
602
-								$k = $subHeaderKeys[$i];
603
-								if ($k == 0) {
604
-									// one byte code
605
-									$c = $i;
606
-									$g = $glyphIndexArray[0];
607
-									$ctg[$c] = $g;
608
-								} else {
609
-									// two bytes code
610
-									$start_byte = $subHeaders[$k]['firstCode'];
611
-									$end_byte = $start_byte + $subHeaders[$k]['entryCount'];
612
-									for ($j = $start_byte; $j < $end_byte; ++$j) {
613
-										// combine high and low bytes
614
-										$c = (($i << 8) + $j);
615
-										$idRangeOffset = ($subHeaders[$k]['idRangeOffset'] + $j - $subHeaders[$k]['firstCode']);
616
-										$g = ($glyphIndexArray[$idRangeOffset] + $subHeaders[$k]['idDelta']) % 65536;
617
-										if ($g < 0) {
618
-											$g = 0;
619
-										}
620
-										$ctg[$c] = $g;
621
-									}
622
-								}
623
-							}
624
-							break;
625
-						}
626
-						case 4: { // Format 4: Segment mapping to delta values
627
-							$length = TCPDF_STATIC::_getUSHORT($font, $offset);
628
-							$offset += 2;
629
-							$offset += 2; // skip version/language
630
-							$segCount = floor(TCPDF_STATIC::_getUSHORT($font, $offset) / 2);
631
-							$offset += 2;
632
-							$offset += 6; // skip searchRange, entrySelector, rangeShift
633
-							$endCount = array(); // array of end character codes for each segment
634
-							for ($k = 0; $k < $segCount; ++$k) {
635
-								$endCount[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
636
-								$offset += 2;
637
-							}
638
-							$offset += 2; // skip reservedPad
639
-							$startCount = array(); // array of start character codes for each segment
640
-							for ($k = 0; $k < $segCount; ++$k) {
641
-								$startCount[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
642
-								$offset += 2;
643
-							}
644
-							$idDelta = array(); // delta for all character codes in segment
645
-							for ($k = 0; $k < $segCount; ++$k) {
646
-								$idDelta[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
647
-								$offset += 2;
648
-							}
649
-							$idRangeOffset = array(); // Offsets into glyphIdArray or 0
650
-							for ($k = 0; $k < $segCount; ++$k) {
651
-								$idRangeOffset[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
652
-								$offset += 2;
653
-							}
654
-							$gidlen = (floor($length / 2) - 8 - (4 * $segCount));
655
-							$glyphIdArray = array(); // glyph index array
656
-							for ($k = 0; $k < $gidlen; ++$k) {
657
-								$glyphIdArray[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
658
-								$offset += 2;
659
-							}
660
-							for ($k = 0; $k < $segCount; ++$k) {
661
-								for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) {
662
-									if ($idRangeOffset[$k] == 0) {
663
-										$g = ($idDelta[$k] + $c) % 65536;
664
-									} else {
665
-										$gid = (floor($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k));
666
-										$g = ($glyphIdArray[$gid] + $idDelta[$k]) % 65536;
667
-									}
668
-									if ($g < 0) {
669
-										$g = 0;
670
-									}
671
-									$ctg[$c] = $g;
672
-								}
673
-							}
674
-							break;
675
-						}
676
-						case 6: { // Format 6: Trimmed table mapping
677
-							$offset += 4; // skip length and version/language
678
-							$firstCode = TCPDF_STATIC::_getUSHORT($font, $offset);
679
-							$offset += 2;
680
-							$entryCount = TCPDF_STATIC::_getUSHORT($font, $offset);
681
-							$offset += 2;
682
-							for ($k = 0; $k < $entryCount; ++$k) {
683
-								$c = ($k + $firstCode);
684
-								$g = TCPDF_STATIC::_getUSHORT($font, $offset);
685
-								$offset += 2;
686
-								$ctg[$c] = $g;
687
-							}
688
-							break;
689
-						}
690
-						case 8: { // Format 8: Mixed 16-bit and 32-bit coverage
691
-							$offset += 10; // skip reserved, length and version/language
692
-							for ($k = 0; $k < 8192; ++$k) {
693
-								$is32[$k] = TCPDF_STATIC::_getBYTE($font, $offset);
694
-								++$offset;
695
-							}
696
-							$nGroups = TCPDF_STATIC::_getULONG($font, $offset);
697
-							$offset += 4;
698
-							for ($i = 0; $i < $nGroups; ++$i) {
699
-								$startCharCode = TCPDF_STATIC::_getULONG($font, $offset);
700
-								$offset += 4;
701
-								$endCharCode = TCPDF_STATIC::_getULONG($font, $offset);
702
-								$offset += 4;
703
-								$startGlyphID = TCPDF_STATIC::_getULONG($font, $offset);
704
-								$offset += 4;
705
-								for ($k = $startCharCode; $k <= $endCharCode; ++$k) {
706
-									$is32idx = floor($c / 8);
707
-									if ((isset($is32[$is32idx])) AND (($is32[$is32idx] & (1 << (7 - ($c % 8)))) == 0)) {
708
-										$c = $k;
709
-									} else {
710
-										// 32 bit format
711
-										// convert to decimal (http://www.unicode.org/faq//utf_bom.html#utf16-4)
712
-										//LEAD_OFFSET = (0xD800 - (0x10000 >> 10)) = 55232
713
-										//SURROGATE_OFFSET = (0x10000 - (0xD800 << 10) - 0xDC00) = -56613888
714
-										$c = ((55232 + ($k >> 10)) << 10) + (0xDC00 + ($k & 0x3FF)) -56613888;
715
-									}
716
-									$ctg[$c] = 0;
717
-									++$startGlyphID;
718
-								}
719
-							}
720
-							break;
721
-						}
722
-						case 10: { // Format 10: Trimmed array
723
-							$offset += 10; // skip reserved, length and version/language
724
-							$startCharCode = TCPDF_STATIC::_getULONG($font, $offset);
725
-							$offset += 4;
726
-							$numChars = TCPDF_STATIC::_getULONG($font, $offset);
727
-							$offset += 4;
728
-							for ($k = 0; $k < $numChars; ++$k) {
729
-								$c = ($k + $startCharCode);
730
-								$g = TCPDF_STATIC::_getUSHORT($font, $offset);
731
-								$ctg[$c] = $g;
732
-								$offset += 2;
733
-							}
734
-							break;
735
-						}
736
-						case 12: { // Format 12: Segmented coverage
737
-							$offset += 10; // skip length and version/language
738
-							$nGroups = TCPDF_STATIC::_getULONG($font, $offset);
739
-							$offset += 4;
740
-							for ($k = 0; $k < $nGroups; ++$k) {
741
-								$startCharCode = TCPDF_STATIC::_getULONG($font, $offset);
742
-								$offset += 4;
743
-								$endCharCode = TCPDF_STATIC::_getULONG($font, $offset);
744
-								$offset += 4;
745
-								$startGlyphCode = TCPDF_STATIC::_getULONG($font, $offset);
746
-								$offset += 4;
747
-								for ($c = $startCharCode; $c <= $endCharCode; ++$c) {
748
-									$ctg[$c] = $startGlyphCode;
749
-									++$startGlyphCode;
750
-								}
751
-							}
752
-							break;
753
-						}
754
-						case 13: { // Format 13: Many-to-one range mappings
755
-							// to be implemented ...
756
-							break;
757
-						}
758
-						case 14: { // Format 14: Unicode Variation Sequences
759
-							// to be implemented ...
760
-							break;
761
-						}
762
-					}
763
-				}
764
-			}
765
-			if (!isset($ctg[0])) {
766
-				$ctg[0] = 0;
767
-			}
768
-			// get xHeight (height of x)
769
-			$offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[120]] + 4);
770
-			$yMin = TCPDF_STATIC::_getFWORD($font, $offset);
771
-			$offset += 4;
772
-			$yMax = TCPDF_STATIC::_getFWORD($font, $offset);
773
-			$offset += 2;
774
-			$fmetric['XHeight'] = round(($yMax - $yMin) * $urk);
775
-			// get CapHeight (height of H)
776
-			$offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[72]] + 4);
777
-			$yMin = TCPDF_STATIC::_getFWORD($font, $offset);
778
-			$offset += 4;
779
-			$yMax = TCPDF_STATIC::_getFWORD($font, $offset);
780
-			$offset += 2;
781
-			$fmetric['CapHeight'] = round(($yMax - $yMin) * $urk);
782
-			// ceate widths array
783
-			$cw = array();
784
-			$offset = $table['hmtx']['offset'];
785
-			for ($i = 0 ; $i < $numberOfHMetrics; ++$i) {
786
-				$cw[$i] = round(TCPDF_STATIC::_getUFWORD($font, $offset) * $urk);
787
-				$offset += 4; // skip lsb
788
-			}
789
-			if ($numberOfHMetrics < $numGlyphs) {
790
-				// fill missing widths with the last value
791
-				$cw = array_pad($cw, $numGlyphs, $cw[($numberOfHMetrics - 1)]);
792
-			}
793
-			$fmetric['MissingWidth'] = $cw[0];
794
-			$fmetric['cw'] = '';
795
-			$fmetric['cbbox'] = '';
796
-			for ($cid = 0; $cid <= 65535; ++$cid) {
797
-				if (isset($ctg[$cid])) {
798
-					if (isset($cw[$ctg[$cid]])) {
799
-						$fmetric['cw'] .= ','.$cid.'=>'.$cw[$ctg[$cid]];
800
-					}
801
-					if ($addcbbox AND isset($indexToLoc[$ctg[$cid]])) {
802
-						$offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[$cid]]);
803
-						$xMin = round(TCPDF_STATIC::_getFWORD($font, $offset + 2) * $urk);
804
-						$yMin = round(TCPDF_STATIC::_getFWORD($font, $offset + 4) * $urk);
805
-						$xMax = round(TCPDF_STATIC::_getFWORD($font, $offset + 6) * $urk);
806
-						$yMax = round(TCPDF_STATIC::_getFWORD($font, $offset + 8) * $urk);
807
-						$fmetric['cbbox'] .= ','.$cid.'=>array('.$xMin.','.$yMin.','.$xMax.','.$yMax.')';
808
-					}
809
-				}
810
-			}
811
-		} // end of true type
812
-		if (($fmetric['type'] == 'TrueTypeUnicode') AND (count($ctg) == 256)) {
813
-			$fmetric['type'] == 'TrueType';
814
-		}
815
-		// ---------- create php font file ----------
816
-		$pfile = '<'.'?'.'php'."\n";
817
-		$pfile .= '// TCPDF FONT FILE DESCRIPTION'."\n";
818
-		$pfile .= '$type=\''.$fmetric['type'].'\';'."\n";
819
-		$pfile .= '$name=\''.$fmetric['name'].'\';'."\n";
820
-		$pfile .= '$up='.$fmetric['underlinePosition'].';'."\n";
821
-		$pfile .= '$ut='.$fmetric['underlineThickness'].';'."\n";
822
-		if ($fmetric['MissingWidth'] > 0) {
823
-			$pfile .= '$dw='.$fmetric['MissingWidth'].';'."\n";
824
-		} else {
825
-			$pfile .= '$dw='.$fmetric['AvgWidth'].';'."\n";
826
-		}
827
-		$pfile .= '$diff=\''.$fmetric['diff'].'\';'."\n";
828
-		if ($fmetric['type'] == 'Type1') {
829
-			// Type 1
830
-			$pfile .= '$enc=\''.$fmetric['enc'].'\';'."\n";
831
-			$pfile .= '$file=\''.$fmetric['file'].'\';'."\n";
832
-			$pfile .= '$size1='.$fmetric['size1'].';'."\n";
833
-			$pfile .= '$size2='.$fmetric['size2'].';'."\n";
834
-		} else {
835
-			$pfile .= '$originalsize='.$fmetric['originalsize'].';'."\n";
836
-			if ($fmetric['type'] == 'cidfont0') {
837
-				// CID-0
838
-				switch ($fonttype) {
839
-					case 'CID0JP': {
840
-						$pfile .= '// Japanese'."\n";
841
-						$pfile .= '$enc=\'UniJIS-UTF16-H\';'."\n";
842
-						$pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'Japan1\',\'Supplement\'=>5);'."\n";
843
-						$pfile .= 'include(dirname(__FILE__).\'/uni2cid_aj16.php\');'."\n";
844
-						break;
845
-					}
846
-					case 'CID0KR': {
847
-						$pfile .= '// Korean'."\n";
848
-						$pfile .= '$enc=\'UniKS-UTF16-H\';'."\n";
849
-						$pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'Korea1\',\'Supplement\'=>0);'."\n";
850
-						$pfile .= 'include(dirname(__FILE__).\'/uni2cid_ak12.php\');'."\n";
851
-						break;
852
-					}
853
-					case 'CID0CS': {
854
-						$pfile .= '// Chinese Simplified'."\n";
855
-						$pfile .= '$enc=\'UniGB-UTF16-H\';'."\n";
856
-						$pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'GB1\',\'Supplement\'=>2);'."\n";
857
-						$pfile .= 'include(dirname(__FILE__).\'/uni2cid_ag15.php\');'."\n";
858
-						break;
859
-					}
860
-					case 'CID0CT':
861
-					default: {
862
-						$pfile .= '// Chinese Traditional'."\n";
863
-						$pfile .= '$enc=\'UniCNS-UTF16-H\';'."\n";
864
-						$pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'CNS1\',\'Supplement\'=>0);'."\n";
865
-						$pfile .= 'include(dirname(__FILE__).\'/uni2cid_aj16.php\');'."\n";
866
-						break;
867
-					}
868
-				}
869
-			} else {
870
-				// TrueType
871
-				$pfile .= '$enc=\''.$fmetric['enc'].'\';'."\n";
872
-				$pfile .= '$file=\''.$fmetric['file'].'\';'."\n";
873
-				$pfile .= '$ctg=\''.$fmetric['ctg'].'\';'."\n";
874
-				// create CIDToGIDMap
875
-				$cidtogidmap = str_pad('', 131072, "\x00"); // (256 * 256 * 2) = 131072
876
-				foreach ($ctg as $cid => $gid) {
877
-					$cidtogidmap = self::updateCIDtoGIDmap($cidtogidmap, $cid, $ctg[$cid]);
878
-				}
879
-				// store compressed CIDToGIDMap
880
-				$fp = fopen($outpath.$fmetric['ctg'], 'wb');
881
-				fwrite($fp, gzcompress($cidtogidmap));
882
-				fclose($fp);
883
-			}
884
-		}
885
-		$pfile .= '$desc=array(';
886
-		$pfile .= '\'Flags\'=>'.$fmetric['Flags'].',';
887
-		$pfile .= '\'FontBBox\'=>\'['.$fmetric['bbox'].']\',';
888
-		$pfile .= '\'ItalicAngle\'=>'.$fmetric['italicAngle'].',';
889
-		$pfile .= '\'Ascent\'=>'.$fmetric['Ascent'].',';
890
-		$pfile .= '\'Descent\'=>'.$fmetric['Descent'].',';
891
-		$pfile .= '\'Leading\'=>'.$fmetric['Leading'].',';
892
-		$pfile .= '\'CapHeight\'=>'.$fmetric['CapHeight'].',';
893
-		$pfile .= '\'XHeight\'=>'.$fmetric['XHeight'].',';
894
-		$pfile .= '\'StemV\'=>'.$fmetric['StemV'].',';
895
-		$pfile .= '\'StemH\'=>'.$fmetric['StemH'].',';
896
-		$pfile .= '\'AvgWidth\'=>'.$fmetric['AvgWidth'].',';
897
-		$pfile .= '\'MaxWidth\'=>'.$fmetric['MaxWidth'].',';
898
-		$pfile .= '\'MissingWidth\'=>'.$fmetric['MissingWidth'].'';
899
-		$pfile .= ');'."\n";
900
-		if (!empty($fmetric['cbbox'])) {
901
-			$pfile .= '$cbbox=array('.substr($fmetric['cbbox'], 1).');'."\n";
902
-		}
903
-		$pfile .= '$cw=array('.substr($fmetric['cw'], 1).');'."\n";
904
-		$pfile .= '// --- EOF ---'."\n";
905
-		// store file
906
-		$fp = fopen($outpath.$font_name.'.php', 'w');
907
-		fwrite($fp, $pfile);
908
-		fclose($fp);
909
-		// return TCPDF font name
910
-		return $font_name;
911
-	}
56
+    /**
57
+     * Convert and add the selected TrueType or Type1 font to the fonts folder (that must be writeable).
58
+     * @param $fontfile (string) Font file (full path).
59
+     * @param $fonttype (string) Font type. Leave empty for autodetect mode. Valid values are: TrueTypeUnicode, TrueType, Type1, CID0JP = CID-0 Japanese, CID0KR = CID-0 Korean, CID0CS = CID-0 Chinese Simplified, CID0CT = CID-0 Chinese Traditional.
60
+     * @param $enc (string) Name of the encoding table to use. Leave empty for default mode. Omit this parameter for TrueType Unicode and symbolic fonts like Symbol or ZapfDingBats.
61
+     * @param $flags (int) Unsigned 32-bit integer containing flags specifying various characteristics of the font (PDF32000:2008 - 9.8.2 Font Descriptor Flags): +1 for fixed font; +4 for symbol or +32 for non-symbol; +64 for italic. Fixed and Italic mode are generally autodetected so you have to set it to 32 = non-symbolic font (default) or 4 = symbolic font.
62
+     * @param $outpath (string) Output path for generated font files (must be writeable by the web server). Leave empty for default font folder.
63
+     * @param $platid (int) Platform ID for CMAP table to extract (when building a Unicode font for Windows this value should be 3, for Macintosh should be 1).
64
+     * @param $encid (int) Encoding ID for CMAP table to extract (when building a Unicode font for Windows this value should be 1, for Macintosh should be 0). When Platform ID is 3, legal values for Encoding ID are: 0=Symbol, 1=Unicode, 2=ShiftJIS, 3=PRC, 4=Big5, 5=Wansung, 6=Johab, 7=Reserved, 8=Reserved, 9=Reserved, 10=UCS-4.
65
+     * @param $addcbbox (boolean) If true includes the character bounding box information on the php font file.
66
+     * @param $link (boolean) If true link to system font instead of copying the font data (not transportable) - Note: do not work with Type1 fonts.
67
+     * @return (string) TCPDF font name or boolean false in case of error.
68
+     * @author Nicola Asuni
69
+     * @since 5.9.123 (2010-09-30)
70
+     * @public static
71
+     */
72
+    public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1, $addcbbox=false, $link=false) {
73
+        if (!file_exists($fontfile)) {
74
+            // Could not find file
75
+            return false;
76
+        }
77
+        // font metrics
78
+        $fmetric = array();
79
+        // build new font name for TCPDF compatibility
80
+        $font_path_parts = pathinfo($fontfile);
81
+        if (!isset($font_path_parts['filename'])) {
82
+            $font_path_parts['filename'] = substr($font_path_parts['basename'], 0, -(strlen($font_path_parts['extension']) + 1));
83
+        }
84
+        $font_name = strtolower($font_path_parts['filename']);
85
+        $font_name = preg_replace('/[^a-z0-9_]/', '', $font_name);
86
+        $search  = array('bold', 'oblique', 'italic', 'regular');
87
+        $replace = array('b', 'i', 'i', '');
88
+        $font_name = str_replace($search, $replace, $font_name);
89
+        if (empty($font_name)) {
90
+            // set generic name
91
+            $font_name = 'tcpdffont';
92
+        }
93
+        // set output path
94
+        if (empty($outpath)) {
95
+            $outpath = self::_getfontpath();
96
+        }
97
+        // check if this font already exist
98
+        if (@file_exists($outpath.$font_name.'.php')) {
99
+            // this font already exist (delete it from fonts folder to rebuild it)
100
+            return $font_name;
101
+        }
102
+        $fmetric['file'] = $font_name;
103
+        $fmetric['ctg'] = $font_name.'.ctg.z';
104
+        // get font data
105
+        $font = file_get_contents($fontfile);
106
+        $fmetric['originalsize'] = strlen($font);
107
+        // autodetect font type
108
+        if (empty($fonttype)) {
109
+            if (TCPDF_STATIC::_getULONG($font, 0) == 0x10000) {
110
+                // True Type (Unicode or not)
111
+                $fonttype = 'TrueTypeUnicode';
112
+            } elseif (substr($font, 0, 4) == 'OTTO') {
113
+                // Open Type (Unicode or not)
114
+                //Unsupported font format: OpenType with CFF data
115
+                return false;
116
+            } else {
117
+                // Type 1
118
+                $fonttype = 'Type1';
119
+            }
120
+        }
121
+        // set font type
122
+        switch ($fonttype) {
123
+            case 'CID0CT':
124
+            case 'CID0CS':
125
+            case 'CID0KR':
126
+            case 'CID0JP': {
127
+                $fmetric['type'] = 'cidfont0';
128
+                break;
129
+            }
130
+            case 'Type1': {
131
+                $fmetric['type'] = 'Type1';
132
+                if (empty($enc) AND (($flags & 4) == 0)) {
133
+                    $enc = 'cp1252';
134
+                }
135
+                break;
136
+            }
137
+            case 'TrueType': {
138
+                $fmetric['type'] = 'TrueType';
139
+                break;
140
+            }
141
+            case 'TrueTypeUnicode':
142
+            default: {
143
+                $fmetric['type'] = 'TrueTypeUnicode';
144
+                break;
145
+            }
146
+        }
147
+        // set encoding maps (if any)
148
+        $fmetric['enc'] = preg_replace('/[^A-Za-z0-9_\-]/', '', $enc);
149
+        $fmetric['diff'] = '';
150
+        if (($fmetric['type'] == 'TrueType') OR ($fmetric['type'] == 'Type1')) {
151
+            if (!empty($enc) AND ($enc != 'cp1252') AND isset(TCPDF_FONT_DATA::$encmap[$enc])) {
152
+                // build differences from reference encoding
153
+                $enc_ref = TCPDF_FONT_DATA::$encmap['cp1252'];
154
+                $enc_target = TCPDF_FONT_DATA::$encmap[$enc];
155
+                $last = 0;
156
+                for ($i = 32; $i <= 255; ++$i) {
157
+                    if ($enc_target != $enc_ref[$i]) {
158
+                        if ($i != ($last + 1)) {
159
+                            $fmetric['diff'] .= $i.' ';
160
+                        }
161
+                        $last = $i;
162
+                        $fmetric['diff'] .= '/'.$enc_target[$i].' ';
163
+                    }
164
+                }
165
+            }
166
+        }
167
+        // parse the font by type
168
+        if ($fmetric['type'] == 'Type1') {
169
+            // ---------- TYPE 1 ----------
170
+            // read first segment
171
+            $a = unpack('Cmarker/Ctype/Vsize', substr($font, 0, 6));
172
+            if ($a['marker'] != 128) {
173
+                // Font file is not a valid binary Type1
174
+                return false;
175
+            }
176
+            $fmetric['size1'] = $a['size'];
177
+            $data = substr($font, 6, $fmetric['size1']);
178
+            // read second segment
179
+            $a = unpack('Cmarker/Ctype/Vsize', substr($font, (6 + $fmetric['size1']), 6));
180
+            if ($a['marker'] != 128) {
181
+                // Font file is not a valid binary Type1
182
+                return false;
183
+            }
184
+            $fmetric['size2'] = $a['size'];
185
+            $encrypted = substr($font, (12 + $fmetric['size1']), $fmetric['size2']);
186
+            $data .= $encrypted;
187
+            // store compressed font
188
+            $fmetric['file'] .= '.z';
189
+            $fp = fopen($outpath.$fmetric['file'], 'wb');
190
+            fwrite($fp, gzcompress($data));
191
+            fclose($fp);
192
+            // get font info
193
+            $fmetric['Flags'] = $flags;
194
+            preg_match ('#/FullName[\s]*\(([^\)]*)#', $font, $matches);
195
+            $fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $matches[1]);
196
+            preg_match('#/FontBBox[\s]*{([^}]*)#', $font, $matches);
197
+            $fmetric['bbox'] = trim($matches[1]);
198
+            $bv = explode(' ', $fmetric['bbox']);
199
+            $fmetric['Ascent'] = intval($bv[3]);
200
+            $fmetric['Descent'] = intval($bv[1]);
201
+            preg_match('#/ItalicAngle[\s]*([0-9\+\-]*)#', $font, $matches);
202
+            $fmetric['italicAngle'] = intval($matches[1]);
203
+            if ($fmetric['italicAngle'] != 0) {
204
+                $fmetric['Flags'] |= 64;
205
+            }
206
+            preg_match('#/UnderlinePosition[\s]*([0-9\+\-]*)#', $font, $matches);
207
+            $fmetric['underlinePosition'] = intval($matches[1]);
208
+            preg_match('#/UnderlineThickness[\s]*([0-9\+\-]*)#', $font, $matches);
209
+            $fmetric['underlineThickness'] = intval($matches[1]);
210
+            preg_match('#/isFixedPitch[\s]*([^\s]*)#', $font, $matches);
211
+            if ($matches[1] == 'true') {
212
+                $fmetric['Flags'] |= 1;
213
+            }
214
+            // get internal map
215
+            $imap = array();
216
+            if (preg_match_all('#dup[\s]([0-9]+)[\s]*/([^\s]*)[\s]put#sU', $font, $fmap, PREG_SET_ORDER) > 0) {
217
+                foreach ($fmap as $v) {
218
+                    $imap[$v[2]] = $v[1];
219
+                }
220
+            }
221
+            // decrypt eexec encrypted part
222
+            $r = 55665; // eexec encryption constant
223
+            $c1 = 52845;
224
+            $c2 = 22719;
225
+            $elen = strlen($encrypted);
226
+            $eplain = '';
227
+            for ($i = 0; $i < $elen; ++$i) {
228
+                $chr = ord($encrypted[$i]);
229
+                $eplain .= chr($chr ^ ($r >> 8));
230
+                $r = ((($chr + $r) * $c1 + $c2) % 65536);
231
+            }
232
+            if (preg_match('#/ForceBold[\s]*([^\s]*)#', $eplain, $matches) > 0) {
233
+                if ($matches[1] == 'true') {
234
+                    $fmetric['Flags'] |= 0x40000;
235
+                }
236
+            }
237
+            if (preg_match('#/StdVW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
238
+                $fmetric['StemV'] = intval($matches[1]);
239
+            } else {
240
+                $fmetric['StemV'] = 70;
241
+            }
242
+            if (preg_match('#/StdHW[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
243
+                $fmetric['StemH'] = intval($matches[1]);
244
+            } else {
245
+                $fmetric['StemH'] = 30;
246
+            }
247
+            if (preg_match('#/BlueValues[\s]*\[([^\]]*)#', $eplain, $matches) > 0) {
248
+                $bv = explode(' ', $matches[1]);
249
+                if (count($bv) >= 6) {
250
+                    $v1 = intval($bv[2]);
251
+                    $v2 = intval($bv[4]);
252
+                    if ($v1 <= $v2) {
253
+                        $fmetric['XHeight'] = $v1;
254
+                        $fmetric['CapHeight'] = $v2;
255
+                    } else {
256
+                        $fmetric['XHeight'] = $v2;
257
+                        $fmetric['CapHeight'] = $v1;
258
+                    }
259
+                } else {
260
+                    $fmetric['XHeight'] = 450;
261
+                    $fmetric['CapHeight'] = 700;
262
+                }
263
+            } else {
264
+                $fmetric['XHeight'] = 450;
265
+                $fmetric['CapHeight'] = 700;
266
+            }
267
+            // get the number of random bytes at the beginning of charstrings
268
+            if (preg_match('#/lenIV[\s]*([0-9]*)#', $eplain, $matches) > 0) {
269
+                $lenIV = intval($matches[1]);
270
+            } else {
271
+                $lenIV = 4;
272
+            }
273
+            $fmetric['Leading'] = 0;
274
+            // get charstring data
275
+            $eplain = substr($eplain, (strpos($eplain, '/CharStrings') + 1));
276
+            preg_match_all('#/([A-Za-z0-9\.]*)[\s][0-9]+[\s]RD[\s](.*)[\s]ND#sU', $eplain, $matches, PREG_SET_ORDER);
277
+            if (!empty($enc) AND isset(TCPDF_FONT_DATA::$encmap[$enc])) {
278
+                $enc_map = TCPDF_FONT_DATA::$encmap[$enc];
279
+            } else {
280
+                $enc_map = false;
281
+            }
282
+            $fmetric['cw'] = '';
283
+            $fmetric['MaxWidth'] = 0;
284
+            $cwidths = array();
285
+            foreach ($matches as $k => $v) {
286
+                $cid = 0;
287
+                if (isset($imap[$v[1]])) {
288
+                    $cid = $imap[$v[1]];
289
+                } elseif ($enc_map !== false) {
290
+                    $cid = array_search($v[1], $enc_map);
291
+                    if ($cid === false) {
292
+                        $cid = 0;
293
+                    } elseif ($cid > 1000) {
294
+                        $cid -= 1000;
295
+                    }
296
+                }
297
+                // decrypt charstring encrypted part
298
+                $r = 4330; // charstring encryption constant
299
+                $c1 = 52845;
300
+                $c2 = 22719;
301
+                $cd = $v[2];
302
+                $clen = strlen($cd);
303
+                $ccom = array();
304
+                for ($i = 0; $i < $clen; ++$i) {
305
+                    $chr = ord($cd[$i]);
306
+                    $ccom[] = ($chr ^ ($r >> 8));
307
+                    $r = ((($chr + $r) * $c1 + $c2) % 65536);
308
+                }
309
+                // decode numbers
310
+                $cdec = array();
311
+                $ck = 0;
312
+                $i = $lenIV;
313
+                while ($i < $clen) {
314
+                    if ($ccom[$i] < 32) {
315
+                        $cdec[$ck] = $ccom[$i];
316
+                        if (($ck > 0) AND ($cdec[$ck] == 13)) {
317
+                            // hsbw command: update width
318
+                            $cwidths[$cid] = $cdec[($ck - 1)];
319
+                        }
320
+                        ++$i;
321
+                    } elseif (($ccom[$i] >= 32) AND ($ccom[$i] <= 246)) {
322
+                        $cdec[$ck] = ($ccom[$i] - 139);
323
+                        ++$i;
324
+                    } elseif (($ccom[$i] >= 247) AND ($ccom[$i] <= 250)) {
325
+                        $cdec[$ck] = ((($ccom[$i] - 247) * 256) + $ccom[($i + 1)] + 108);
326
+                        $i += 2;
327
+                    } elseif (($ccom[$i] >= 251) AND ($ccom[$i] <= 254)) {
328
+                        $cdec[$ck] = ((-($ccom[$i] - 251) * 256) - $ccom[($i + 1)] - 108);
329
+                        $i += 2;
330
+                    } elseif ($ccom[$i] == 255) {
331
+                        $sval = chr($ccom[($i + 1)]).chr($ccom[($i + 2)]).chr($ccom[($i + 3)]).chr($ccom[($i + 4)]);
332
+                        $vsval = unpack('li', $sval);
333
+                        $cdec[$ck] = $vsval['i'];
334
+                        $i += 5;
335
+                    }
336
+                    ++$ck;
337
+                }
338
+            } // end for each matches
339
+            $fmetric['MissingWidth'] = $cwidths[0];
340
+            $fmetric['MaxWidth'] = $fmetric['MissingWidth'];
341
+            $fmetric['AvgWidth'] = 0;
342
+            // set chars widths
343
+            for ($cid = 0; $cid <= 255; ++$cid) {
344
+                if (isset($cwidths[$cid])) {
345
+                    if ($cwidths[$cid] > $fmetric['MaxWidth']) {
346
+                        $fmetric['MaxWidth'] = $cwidths[$cid];
347
+                    }
348
+                    $fmetric['AvgWidth'] += $cwidths[$cid];
349
+                    $fmetric['cw'] .= ','.$cid.'=>'.$cwidths[$cid];
350
+                } else {
351
+                    $fmetric['cw'] .= ','.$cid.'=>'.$fmetric['MissingWidth'];
352
+                }
353
+            }
354
+            $fmetric['AvgWidth'] = round($fmetric['AvgWidth'] / count($cwidths));
355
+        } else {
356
+            // ---------- TRUE TYPE ----------
357
+            if ($fmetric['type'] != 'cidfont0') {
358
+                if ($link) {
359
+                    // creates a symbolic link to the existing font
360
+                    symlink($fontfile, $outpath.$fmetric['file']);
361
+                } else {
362
+                    // store compressed font
363
+                    $fmetric['file'] .= '.z';
364
+                    $fp = fopen($outpath.$fmetric['file'], 'wb');
365
+                    fwrite($fp, gzcompress($font));
366
+                    fclose($fp);
367
+                }
368
+            }
369
+            $offset = 0; // offset position of the font data
370
+            if (TCPDF_STATIC::_getULONG($font, $offset) != 0x10000) {
371
+                // sfnt version must be 0x00010000 for TrueType version 1.0.
372
+                return false;
373
+            }
374
+            $offset += 4;
375
+            // get number of tables
376
+            $numTables = TCPDF_STATIC::_getUSHORT($font, $offset);
377
+            $offset += 2;
378
+            // skip searchRange, entrySelector and rangeShift
379
+            $offset += 6;
380
+            // tables array
381
+            $table = array();
382
+            // ---------- get tables ----------
383
+            for ($i = 0; $i < $numTables; ++$i) {
384
+                // get table info
385
+                $tag = substr($font, $offset, 4);
386
+                $offset += 4;
387
+                $table[$tag] = array();
388
+                $table[$tag]['checkSum'] = TCPDF_STATIC::_getULONG($font, $offset);
389
+                $offset += 4;
390
+                $table[$tag]['offset'] = TCPDF_STATIC::_getULONG($font, $offset);
391
+                $offset += 4;
392
+                $table[$tag]['length'] = TCPDF_STATIC::_getULONG($font, $offset);
393
+                $offset += 4;
394
+            }
395
+            // check magicNumber
396
+            $offset = $table['head']['offset'] + 12;
397
+            if (TCPDF_STATIC::_getULONG($font, $offset) != 0x5F0F3CF5) {
398
+                // magicNumber must be 0x5F0F3CF5
399
+                return false;
400
+            }
401
+            $offset += 4;
402
+            $offset += 2; // skip flags
403
+            // get FUnits
404
+            $fmetric['unitsPerEm'] = TCPDF_STATIC::_getUSHORT($font, $offset);
405
+            $offset += 2;
406
+            // units ratio constant
407
+            $urk = (1000 / $fmetric['unitsPerEm']);
408
+            $offset += 16; // skip created, modified
409
+            $xMin = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
410
+            $offset += 2;
411
+            $yMin = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
412
+            $offset += 2;
413
+            $xMax = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
414
+            $offset += 2;
415
+            $yMax = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
416
+            $offset += 2;
417
+            $fmetric['bbox'] = ''.$xMin.' '.$yMin.' '.$xMax.' '.$yMax.'';
418
+            $macStyle = TCPDF_STATIC::_getUSHORT($font, $offset);
419
+            $offset += 2;
420
+            // PDF font flags
421
+            $fmetric['Flags'] = $flags;
422
+            if (($macStyle & 2) == 2) {
423
+                // italic flag
424
+                $fmetric['Flags'] |= 64;
425
+            }
426
+            // get offset mode (indexToLocFormat : 0 = short, 1 = long)
427
+            $offset = $table['head']['offset'] + 50;
428
+            $short_offset = (TCPDF_STATIC::_getSHORT($font, $offset) == 0);
429
+            $offset += 2;
430
+            // get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table
431
+            $indexToLoc = array();
432
+            $offset = $table['loca']['offset'];
433
+            if ($short_offset) {
434
+                // short version
435
+                $tot_num_glyphs = floor($table['loca']['length'] / 2); // numGlyphs + 1
436
+                for ($i = 0; $i < $tot_num_glyphs; ++$i) {
437
+                    $indexToLoc[$i] = TCPDF_STATIC::_getUSHORT($font, $offset) * 2;
438
+                    $offset += 2;
439
+                }
440
+            } else {
441
+                // long version
442
+                $tot_num_glyphs = floor($table['loca']['length'] / 4); // numGlyphs + 1
443
+                for ($i = 0; $i < $tot_num_glyphs; ++$i) {
444
+                    $indexToLoc[$i] = TCPDF_STATIC::_getULONG($font, $offset);
445
+                    $offset += 4;
446
+                }
447
+            }
448
+            // get glyphs indexes of chars from cmap table
449
+            $offset = $table['cmap']['offset'] + 2;
450
+            $numEncodingTables = TCPDF_STATIC::_getUSHORT($font, $offset);
451
+            $offset += 2;
452
+            $encodingTables = array();
453
+            for ($i = 0; $i < $numEncodingTables; ++$i) {
454
+                $encodingTables[$i]['platformID'] = TCPDF_STATIC::_getUSHORT($font, $offset);
455
+                $offset += 2;
456
+                $encodingTables[$i]['encodingID'] = TCPDF_STATIC::_getUSHORT($font, $offset);
457
+                $offset += 2;
458
+                $encodingTables[$i]['offset'] = TCPDF_STATIC::_getULONG($font, $offset);
459
+                $offset += 4;
460
+            }
461
+            // ---------- get os/2 metrics ----------
462
+            $offset = $table['OS/2']['offset'];
463
+            $offset += 2; // skip version
464
+            // xAvgCharWidth
465
+            $fmetric['AvgWidth'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
466
+            $offset += 2;
467
+            // usWeightClass
468
+            $usWeightClass = round(TCPDF_STATIC::_getUFWORD($font, $offset) * $urk);
469
+            // estimate StemV and StemH (400 = usWeightClass for Normal - Regular font)
470
+            $fmetric['StemV'] = round((70 * $usWeightClass) / 400);
471
+            $fmetric['StemH'] = round((30 * $usWeightClass) / 400);
472
+            $offset += 2;
473
+            $offset += 2; // usWidthClass
474
+            $fsType = TCPDF_STATIC::_getSHORT($font, $offset);
475
+            $offset += 2;
476
+            if ($fsType == 2) {
477
+                // This Font cannot be modified, embedded or exchanged in any manner without first obtaining permission of the legal owner.
478
+                return false;
479
+            }
480
+            // ---------- get font name ----------
481
+            $fmetric['name'] = '';
482
+            $offset = $table['name']['offset'];
483
+            $offset += 2; // skip Format selector (=0).
484
+            // Number of NameRecords that follow n.
485
+            $numNameRecords = TCPDF_STATIC::_getUSHORT($font, $offset);
486
+            $offset += 2;
487
+            // Offset to start of string storage (from start of table).
488
+            $stringStorageOffset = TCPDF_STATIC::_getUSHORT($font, $offset);
489
+            $offset += 2;
490
+            for ($i = 0; $i < $numNameRecords; ++$i) {
491
+                $offset += 6; // skip Platform ID, Platform-specific encoding ID, Language ID.
492
+                // Name ID.
493
+                $nameID = TCPDF_STATIC::_getUSHORT($font, $offset);
494
+                $offset += 2;
495
+                if ($nameID == 6) {
496
+                    // String length (in bytes).
497
+                    $stringLength = TCPDF_STATIC::_getUSHORT($font, $offset);
498
+                    $offset += 2;
499
+                    // String offset from start of storage area (in bytes).
500
+                    $stringOffset = TCPDF_STATIC::_getUSHORT($font, $offset);
501
+                    $offset += 2;
502
+                    $offset = ($table['name']['offset'] + $stringStorageOffset + $stringOffset);
503
+                    $fmetric['name'] = substr($font, $offset, $stringLength);
504
+                    $fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $fmetric['name']);
505
+                    break;
506
+                } else {
507
+                    $offset += 4; // skip String length, String offset
508
+                }
509
+            }
510
+            if (empty($fmetric['name'])) {
511
+                $fmetric['name'] = $font_name;
512
+            }
513
+            // ---------- get post data ----------
514
+            $offset = $table['post']['offset'];
515
+            $offset += 4; // skip Format Type
516
+            $fmetric['italicAngle'] = TCPDF_STATIC::_getFIXED($font, $offset);
517
+            $offset += 4;
518
+            $fmetric['underlinePosition'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
519
+            $offset += 2;
520
+            $fmetric['underlineThickness'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
521
+            $offset += 2;
522
+            $isFixedPitch = (TCPDF_STATIC::_getULONG($font, $offset) == 0) ? false : true;
523
+            $offset += 2;
524
+            if ($isFixedPitch) {
525
+                $fmetric['Flags'] |= 1;
526
+            }
527
+            // ---------- get hhea data ----------
528
+            $offset = $table['hhea']['offset'];
529
+            $offset += 4; // skip Table version number
530
+            // Ascender
531
+            $fmetric['Ascent'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
532
+            $offset += 2;
533
+            // Descender
534
+            $fmetric['Descent'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
535
+            $offset += 2;
536
+            // LineGap
537
+            $fmetric['Leading'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
538
+            $offset += 2;
539
+            // advanceWidthMax
540
+            $fmetric['MaxWidth'] = round(TCPDF_STATIC::_getUFWORD($font, $offset) * $urk);
541
+            $offset += 2;
542
+            $offset += 22; // skip some values
543
+            // get the number of hMetric entries in hmtx table
544
+            $numberOfHMetrics = TCPDF_STATIC::_getUSHORT($font, $offset);
545
+            // ---------- get maxp data ----------
546
+            $offset = $table['maxp']['offset'];
547
+            $offset += 4; // skip Table version number
548
+            // get the the number of glyphs in the font.
549
+            $numGlyphs = TCPDF_STATIC::_getUSHORT($font, $offset);
550
+            // ---------- get CIDToGIDMap ----------
551
+            $ctg = array();
552
+            foreach ($encodingTables as $enctable) {
553
+                // get only specified Platform ID and Encoding ID
554
+                if (($enctable['platformID'] == $platid) AND ($enctable['encodingID'] == $encid)) {
555
+                    $offset = $table['cmap']['offset'] + $enctable['offset'];
556
+                    $format = TCPDF_STATIC::_getUSHORT($font, $offset);
557
+                    $offset += 2;
558
+                    switch ($format) {
559
+                        case 0: { // Format 0: Byte encoding table
560
+                            $offset += 4; // skip length and version/language
561
+                            for ($c = 0; $c < 256; ++$c) {
562
+                                $g = TCPDF_STATIC::_getBYTE($font, $offset);
563
+                                $ctg[$c] = $g;
564
+                                ++$offset;
565
+                            }
566
+                            break;
567
+                        }
568
+                        case 2: { // Format 2: High-byte mapping through table
569
+                            $offset += 4; // skip length and version/language
570
+                            $numSubHeaders = 0;
571
+                            for ($i = 0; $i < 256; ++$i) {
572
+                                // Array that maps high bytes to subHeaders: value is subHeader index * 8.
573
+                                $subHeaderKeys[$i] = (TCPDF_STATIC::_getUSHORT($font, $offset) / 8);
574
+                                $offset += 2;
575
+                                if ($numSubHeaders < $subHeaderKeys[$i]) {
576
+                                    $numSubHeaders = $subHeaderKeys[$i];
577
+                                }
578
+                            }
579
+                            // the number of subHeaders is equal to the max of subHeaderKeys + 1
580
+                            ++$numSubHeaders;
581
+                            // read subHeader structures
582
+                            $subHeaders = array();
583
+                            $numGlyphIndexArray = 0;
584
+                            for ($k = 0; $k < $numSubHeaders; ++$k) {
585
+                                $subHeaders[$k]['firstCode'] = TCPDF_STATIC::_getUSHORT($font, $offset);
586
+                                $offset += 2;
587
+                                $subHeaders[$k]['entryCount'] = TCPDF_STATIC::_getUSHORT($font, $offset);
588
+                                $offset += 2;
589
+                                $subHeaders[$k]['idDelta'] = TCPDF_STATIC::_getUSHORT($font, $offset);
590
+                                $offset += 2;
591
+                                $subHeaders[$k]['idRangeOffset'] = TCPDF_STATIC::_getUSHORT($font, $offset);
592
+                                $offset += 2;
593
+                                $subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1) * 8));
594
+                                $subHeaders[$k]['idRangeOffset'] /= 2;
595
+                                $numGlyphIndexArray += $subHeaders[$k]['entryCount'];
596
+                            }
597
+                            for ($k = 0; $k < $numGlyphIndexArray; ++$k) {
598
+                                $glyphIndexArray[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
599
+                                $offset += 2;
600
+                            }
601
+                            for ($i = 0; $i < 256; ++$i) {
602
+                                $k = $subHeaderKeys[$i];
603
+                                if ($k == 0) {
604
+                                    // one byte code
605
+                                    $c = $i;
606
+                                    $g = $glyphIndexArray[0];
607
+                                    $ctg[$c] = $g;
608
+                                } else {
609
+                                    // two bytes code
610
+                                    $start_byte = $subHeaders[$k]['firstCode'];
611
+                                    $end_byte = $start_byte + $subHeaders[$k]['entryCount'];
612
+                                    for ($j = $start_byte; $j < $end_byte; ++$j) {
613
+                                        // combine high and low bytes
614
+                                        $c = (($i << 8) + $j);
615
+                                        $idRangeOffset = ($subHeaders[$k]['idRangeOffset'] + $j - $subHeaders[$k]['firstCode']);
616
+                                        $g = ($glyphIndexArray[$idRangeOffset] + $subHeaders[$k]['idDelta']) % 65536;
617
+                                        if ($g < 0) {
618
+                                            $g = 0;
619
+                                        }
620
+                                        $ctg[$c] = $g;
621
+                                    }
622
+                                }
623
+                            }
624
+                            break;
625
+                        }
626
+                        case 4: { // Format 4: Segment mapping to delta values
627
+                            $length = TCPDF_STATIC::_getUSHORT($font, $offset);
628
+                            $offset += 2;
629
+                            $offset += 2; // skip version/language
630
+                            $segCount = floor(TCPDF_STATIC::_getUSHORT($font, $offset) / 2);
631
+                            $offset += 2;
632
+                            $offset += 6; // skip searchRange, entrySelector, rangeShift
633
+                            $endCount = array(); // array of end character codes for each segment
634
+                            for ($k = 0; $k < $segCount; ++$k) {
635
+                                $endCount[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
636
+                                $offset += 2;
637
+                            }
638
+                            $offset += 2; // skip reservedPad
639
+                            $startCount = array(); // array of start character codes for each segment
640
+                            for ($k = 0; $k < $segCount; ++$k) {
641
+                                $startCount[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
642
+                                $offset += 2;
643
+                            }
644
+                            $idDelta = array(); // delta for all character codes in segment
645
+                            for ($k = 0; $k < $segCount; ++$k) {
646
+                                $idDelta[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
647
+                                $offset += 2;
648
+                            }
649
+                            $idRangeOffset = array(); // Offsets into glyphIdArray or 0
650
+                            for ($k = 0; $k < $segCount; ++$k) {
651
+                                $idRangeOffset[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
652
+                                $offset += 2;
653
+                            }
654
+                            $gidlen = (floor($length / 2) - 8 - (4 * $segCount));
655
+                            $glyphIdArray = array(); // glyph index array
656
+                            for ($k = 0; $k < $gidlen; ++$k) {
657
+                                $glyphIdArray[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
658
+                                $offset += 2;
659
+                            }
660
+                            for ($k = 0; $k < $segCount; ++$k) {
661
+                                for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) {
662
+                                    if ($idRangeOffset[$k] == 0) {
663
+                                        $g = ($idDelta[$k] + $c) % 65536;
664
+                                    } else {
665
+                                        $gid = (floor($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k));
666
+                                        $g = ($glyphIdArray[$gid] + $idDelta[$k]) % 65536;
667
+                                    }
668
+                                    if ($g < 0) {
669
+                                        $g = 0;
670
+                                    }
671
+                                    $ctg[$c] = $g;
672
+                                }
673
+                            }
674
+                            break;
675
+                        }
676
+                        case 6: { // Format 6: Trimmed table mapping
677
+                            $offset += 4; // skip length and version/language
678
+                            $firstCode = TCPDF_STATIC::_getUSHORT($font, $offset);
679
+                            $offset += 2;
680
+                            $entryCount = TCPDF_STATIC::_getUSHORT($font, $offset);
681
+                            $offset += 2;
682
+                            for ($k = 0; $k < $entryCount; ++$k) {
683
+                                $c = ($k + $firstCode);
684
+                                $g = TCPDF_STATIC::_getUSHORT($font, $offset);
685
+                                $offset += 2;
686
+                                $ctg[$c] = $g;
687
+                            }
688
+                            break;
689
+                        }
690
+                        case 8: { // Format 8: Mixed 16-bit and 32-bit coverage
691
+                            $offset += 10; // skip reserved, length and version/language
692
+                            for ($k = 0; $k < 8192; ++$k) {
693
+                                $is32[$k] = TCPDF_STATIC::_getBYTE($font, $offset);
694
+                                ++$offset;
695
+                            }
696
+                            $nGroups = TCPDF_STATIC::_getULONG($font, $offset);
697
+                            $offset += 4;
698
+                            for ($i = 0; $i < $nGroups; ++$i) {
699
+                                $startCharCode = TCPDF_STATIC::_getULONG($font, $offset);
700
+                                $offset += 4;
701
+                                $endCharCode = TCPDF_STATIC::_getULONG($font, $offset);
702
+                                $offset += 4;
703
+                                $startGlyphID = TCPDF_STATIC::_getULONG($font, $offset);
704
+                                $offset += 4;
705
+                                for ($k = $startCharCode; $k <= $endCharCode; ++$k) {
706
+                                    $is32idx = floor($c / 8);
707
+                                    if ((isset($is32[$is32idx])) AND (($is32[$is32idx] & (1 << (7 - ($c % 8)))) == 0)) {
708
+                                        $c = $k;
709
+                                    } else {
710
+                                        // 32 bit format
711
+                                        // convert to decimal (http://www.unicode.org/faq//utf_bom.html#utf16-4)
712
+                                        //LEAD_OFFSET = (0xD800 - (0x10000 >> 10)) = 55232
713
+                                        //SURROGATE_OFFSET = (0x10000 - (0xD800 << 10) - 0xDC00) = -56613888
714
+                                        $c = ((55232 + ($k >> 10)) << 10) + (0xDC00 + ($k & 0x3FF)) -56613888;
715
+                                    }
716
+                                    $ctg[$c] = 0;
717
+                                    ++$startGlyphID;
718
+                                }
719
+                            }
720
+                            break;
721
+                        }
722
+                        case 10: { // Format 10: Trimmed array
723
+                            $offset += 10; // skip reserved, length and version/language
724
+                            $startCharCode = TCPDF_STATIC::_getULONG($font, $offset);
725
+                            $offset += 4;
726
+                            $numChars = TCPDF_STATIC::_getULONG($font, $offset);
727
+                            $offset += 4;
728
+                            for ($k = 0; $k < $numChars; ++$k) {
729
+                                $c = ($k + $startCharCode);
730
+                                $g = TCPDF_STATIC::_getUSHORT($font, $offset);
731
+                                $ctg[$c] = $g;
732
+                                $offset += 2;
733
+                            }
734
+                            break;
735
+                        }
736
+                        case 12: { // Format 12: Segmented coverage
737
+                            $offset += 10; // skip length and version/language
738
+                            $nGroups = TCPDF_STATIC::_getULONG($font, $offset);
739
+                            $offset += 4;
740
+                            for ($k = 0; $k < $nGroups; ++$k) {
741
+                                $startCharCode = TCPDF_STATIC::_getULONG($font, $offset);
742
+                                $offset += 4;
743
+                                $endCharCode = TCPDF_STATIC::_getULONG($font, $offset);
744
+                                $offset += 4;
745
+                                $startGlyphCode = TCPDF_STATIC::_getULONG($font, $offset);
746
+                                $offset += 4;
747
+                                for ($c = $startCharCode; $c <= $endCharCode; ++$c) {
748
+                                    $ctg[$c] = $startGlyphCode;
749
+                                    ++$startGlyphCode;
750
+                                }
751
+                            }
752
+                            break;
753
+                        }
754
+                        case 13: { // Format 13: Many-to-one range mappings
755
+                            // to be implemented ...
756
+                            break;
757
+                        }
758
+                        case 14: { // Format 14: Unicode Variation Sequences
759
+                            // to be implemented ...
760
+                            break;
761
+                        }
762
+                    }
763
+                }
764
+            }
765
+            if (!isset($ctg[0])) {
766
+                $ctg[0] = 0;
767
+            }
768
+            // get xHeight (height of x)
769
+            $offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[120]] + 4);
770
+            $yMin = TCPDF_STATIC::_getFWORD($font, $offset);
771
+            $offset += 4;
772
+            $yMax = TCPDF_STATIC::_getFWORD($font, $offset);
773
+            $offset += 2;
774
+            $fmetric['XHeight'] = round(($yMax - $yMin) * $urk);
775
+            // get CapHeight (height of H)
776
+            $offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[72]] + 4);
777
+            $yMin = TCPDF_STATIC::_getFWORD($font, $offset);
778
+            $offset += 4;
779
+            $yMax = TCPDF_STATIC::_getFWORD($font, $offset);
780
+            $offset += 2;
781
+            $fmetric['CapHeight'] = round(($yMax - $yMin) * $urk);
782
+            // ceate widths array
783
+            $cw = array();
784
+            $offset = $table['hmtx']['offset'];
785
+            for ($i = 0 ; $i < $numberOfHMetrics; ++$i) {
786
+                $cw[$i] = round(TCPDF_STATIC::_getUFWORD($font, $offset) * $urk);
787
+                $offset += 4; // skip lsb
788
+            }
789
+            if ($numberOfHMetrics < $numGlyphs) {
790
+                // fill missing widths with the last value
791
+                $cw = array_pad($cw, $numGlyphs, $cw[($numberOfHMetrics - 1)]);
792
+            }
793
+            $fmetric['MissingWidth'] = $cw[0];
794
+            $fmetric['cw'] = '';
795
+            $fmetric['cbbox'] = '';
796
+            for ($cid = 0; $cid <= 65535; ++$cid) {
797
+                if (isset($ctg[$cid])) {
798
+                    if (isset($cw[$ctg[$cid]])) {
799
+                        $fmetric['cw'] .= ','.$cid.'=>'.$cw[$ctg[$cid]];
800
+                    }
801
+                    if ($addcbbox AND isset($indexToLoc[$ctg[$cid]])) {
802
+                        $offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[$cid]]);
803
+                        $xMin = round(TCPDF_STATIC::_getFWORD($font, $offset + 2) * $urk);
804
+                        $yMin = round(TCPDF_STATIC::_getFWORD($font, $offset + 4) * $urk);
805
+                        $xMax = round(TCPDF_STATIC::_getFWORD($font, $offset + 6) * $urk);
806
+                        $yMax = round(TCPDF_STATIC::_getFWORD($font, $offset + 8) * $urk);
807
+                        $fmetric['cbbox'] .= ','.$cid.'=>array('.$xMin.','.$yMin.','.$xMax.','.$yMax.')';
808
+                    }
809
+                }
810
+            }
811
+        } // end of true type
812
+        if (($fmetric['type'] == 'TrueTypeUnicode') AND (count($ctg) == 256)) {
813
+            $fmetric['type'] == 'TrueType';
814
+        }
815
+        // ---------- create php font file ----------
816
+        $pfile = '<'.'?'.'php'."\n";
817
+        $pfile .= '// TCPDF FONT FILE DESCRIPTION'."\n";
818
+        $pfile .= '$type=\''.$fmetric['type'].'\';'."\n";
819
+        $pfile .= '$name=\''.$fmetric['name'].'\';'."\n";
820
+        $pfile .= '$up='.$fmetric['underlinePosition'].';'."\n";
821
+        $pfile .= '$ut='.$fmetric['underlineThickness'].';'."\n";
822
+        if ($fmetric['MissingWidth'] > 0) {
823
+            $pfile .= '$dw='.$fmetric['MissingWidth'].';'."\n";
824
+        } else {
825
+            $pfile .= '$dw='.$fmetric['AvgWidth'].';'."\n";
826
+        }
827
+        $pfile .= '$diff=\''.$fmetric['diff'].'\';'."\n";
828
+        if ($fmetric['type'] == 'Type1') {
829
+            // Type 1
830
+            $pfile .= '$enc=\''.$fmetric['enc'].'\';'."\n";
831
+            $pfile .= '$file=\''.$fmetric['file'].'\';'."\n";
832
+            $pfile .= '$size1='.$fmetric['size1'].';'."\n";
833
+            $pfile .= '$size2='.$fmetric['size2'].';'."\n";
834
+        } else {
835
+            $pfile .= '$originalsize='.$fmetric['originalsize'].';'."\n";
836
+            if ($fmetric['type'] == 'cidfont0') {
837
+                // CID-0
838
+                switch ($fonttype) {
839
+                    case 'CID0JP': {
840
+                        $pfile .= '// Japanese'."\n";
841
+                        $pfile .= '$enc=\'UniJIS-UTF16-H\';'."\n";
842
+                        $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'Japan1\',\'Supplement\'=>5);'."\n";
843
+                        $pfile .= 'include(dirname(__FILE__).\'/uni2cid_aj16.php\');'."\n";
844
+                        break;
845
+                    }
846
+                    case 'CID0KR': {
847
+                        $pfile .= '// Korean'."\n";
848
+                        $pfile .= '$enc=\'UniKS-UTF16-H\';'."\n";
849
+                        $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'Korea1\',\'Supplement\'=>0);'."\n";
850
+                        $pfile .= 'include(dirname(__FILE__).\'/uni2cid_ak12.php\');'."\n";
851
+                        break;
852
+                    }
853
+                    case 'CID0CS': {
854
+                        $pfile .= '// Chinese Simplified'."\n";
855
+                        $pfile .= '$enc=\'UniGB-UTF16-H\';'."\n";
856
+                        $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'GB1\',\'Supplement\'=>2);'."\n";
857
+                        $pfile .= 'include(dirname(__FILE__).\'/uni2cid_ag15.php\');'."\n";
858
+                        break;
859
+                    }
860
+                    case 'CID0CT':
861
+                    default: {
862
+                        $pfile .= '// Chinese Traditional'."\n";
863
+                        $pfile .= '$enc=\'UniCNS-UTF16-H\';'."\n";
864
+                        $pfile .= '$cidinfo=array(\'Registry\'=>\'Adobe\', \'Ordering\'=>\'CNS1\',\'Supplement\'=>0);'."\n";
865
+                        $pfile .= 'include(dirname(__FILE__).\'/uni2cid_aj16.php\');'."\n";
866
+                        break;
867
+                    }
868
+                }
869
+            } else {
870
+                // TrueType
871
+                $pfile .= '$enc=\''.$fmetric['enc'].'\';'."\n";
872
+                $pfile .= '$file=\''.$fmetric['file'].'\';'."\n";
873
+                $pfile .= '$ctg=\''.$fmetric['ctg'].'\';'."\n";
874
+                // create CIDToGIDMap
875
+                $cidtogidmap = str_pad('', 131072, "\x00"); // (256 * 256 * 2) = 131072
876
+                foreach ($ctg as $cid => $gid) {
877
+                    $cidtogidmap = self::updateCIDtoGIDmap($cidtogidmap, $cid, $ctg[$cid]);
878
+                }
879
+                // store compressed CIDToGIDMap
880
+                $fp = fopen($outpath.$fmetric['ctg'], 'wb');
881
+                fwrite($fp, gzcompress($cidtogidmap));
882
+                fclose($fp);
883
+            }
884
+        }
885
+        $pfile .= '$desc=array(';
886
+        $pfile .= '\'Flags\'=>'.$fmetric['Flags'].',';
887
+        $pfile .= '\'FontBBox\'=>\'['.$fmetric['bbox'].']\',';
888
+        $pfile .= '\'ItalicAngle\'=>'.$fmetric['italicAngle'].',';
889
+        $pfile .= '\'Ascent\'=>'.$fmetric['Ascent'].',';
890
+        $pfile .= '\'Descent\'=>'.$fmetric['Descent'].',';
891
+        $pfile .= '\'Leading\'=>'.$fmetric['Leading'].',';
892
+        $pfile .= '\'CapHeight\'=>'.$fmetric['CapHeight'].',';
893
+        $pfile .= '\'XHeight\'=>'.$fmetric['XHeight'].',';
894
+        $pfile .= '\'StemV\'=>'.$fmetric['StemV'].',';
895
+        $pfile .= '\'StemH\'=>'.$fmetric['StemH'].',';
896
+        $pfile .= '\'AvgWidth\'=>'.$fmetric['AvgWidth'].',';
897
+        $pfile .= '\'MaxWidth\'=>'.$fmetric['MaxWidth'].',';
898
+        $pfile .= '\'MissingWidth\'=>'.$fmetric['MissingWidth'].'';
899
+        $pfile .= ');'."\n";
900
+        if (!empty($fmetric['cbbox'])) {
901
+            $pfile .= '$cbbox=array('.substr($fmetric['cbbox'], 1).');'."\n";
902
+        }
903
+        $pfile .= '$cw=array('.substr($fmetric['cw'], 1).');'."\n";
904
+        $pfile .= '// --- EOF ---'."\n";
905
+        // store file
906
+        $fp = fopen($outpath.$font_name.'.php', 'w');
907
+        fwrite($fp, $pfile);
908
+        fclose($fp);
909
+        // return TCPDF font name
910
+        return $font_name;
911
+    }
912 912
 
913
-	/**
914
-	 * Returs the checksum of a TTF table.
915
-	 * @param $table (string) table to check
916
-	 * @param $length (int) length of table in bytes
917
-	 * @return int checksum
918
-	 * @author Nicola Asuni
919
-	 * @since 5.2.000 (2010-06-02)
920
-	 * @public static
921
-	 */
922
-	public static function _getTTFtableChecksum($table, $length) {
923
-		$sum = 0;
924
-		$tlen = ($length / 4);
925
-		$offset = 0;
926
-		for ($i = 0; $i < $tlen; ++$i) {
927
-			$v = unpack('Ni', substr($table, $offset, 4));
928
-			$sum += $v['i'];
929
-			$offset += 4;
930
-		}
931
-		$sum = unpack('Ni', pack('N', $sum));
932
-		return $sum['i'];
933
-	}
913
+    /**
914
+     * Returs the checksum of a TTF table.
915
+     * @param $table (string) table to check
916
+     * @param $length (int) length of table in bytes
917
+     * @return int checksum
918
+     * @author Nicola Asuni
919
+     * @since 5.2.000 (2010-06-02)
920
+     * @public static
921
+     */
922
+    public static function _getTTFtableChecksum($table, $length) {
923
+        $sum = 0;
924
+        $tlen = ($length / 4);
925
+        $offset = 0;
926
+        for ($i = 0; $i < $tlen; ++$i) {
927
+            $v = unpack('Ni', substr($table, $offset, 4));
928
+            $sum += $v['i'];
929
+            $offset += 4;
930
+        }
931
+        $sum = unpack('Ni', pack('N', $sum));
932
+        return $sum['i'];
933
+    }
934 934
 
935
-	/**
936
-	 * Returns a subset of the TrueType font data without the unused glyphs.
937
-	 * @param $font (string) TrueType font data.
938
-	 * @param $subsetchars (array) Array of used characters (the glyphs to keep).
939
-	 * @return (string) A subset of TrueType font data without the unused glyphs.
940
-	 * @author Nicola Asuni
941
-	 * @since 5.2.000 (2010-06-02)
942
-	 * @public static
943
-	 */
944
-	public static function _getTrueTypeFontSubset($font, $subsetchars) {
945
-		ksort($subsetchars);
946
-		$offset = 0; // offset position of the font data
947
-		if (TCPDF_STATIC::_getULONG($font, $offset) != 0x10000) {
948
-			// sfnt version must be 0x00010000 for TrueType version 1.0.
949
-			return $font;
950
-		}
951
-		$offset += 4;
952
-		// get number of tables
953
-		$numTables = TCPDF_STATIC::_getUSHORT($font, $offset);
954
-		$offset += 2;
955
-		// skip searchRange, entrySelector and rangeShift
956
-		$offset += 6;
957
-		// tables array
958
-		$table = array();
959
-		// for each table
960
-		for ($i = 0; $i < $numTables; ++$i) {
961
-			// get table info
962
-			$tag = substr($font, $offset, 4);
963
-			$offset += 4;
964
-			$table[$tag] = array();
965
-			$table[$tag]['checkSum'] = TCPDF_STATIC::_getULONG($font, $offset);
966
-			$offset += 4;
967
-			$table[$tag]['offset'] = TCPDF_STATIC::_getULONG($font, $offset);
968
-			$offset += 4;
969
-			$table[$tag]['length'] = TCPDF_STATIC::_getULONG($font, $offset);
970
-			$offset += 4;
971
-		}
972
-		// check magicNumber
973
-		$offset = $table['head']['offset'] + 12;
974
-		if (TCPDF_STATIC::_getULONG($font, $offset) != 0x5F0F3CF5) {
975
-			// magicNumber must be 0x5F0F3CF5
976
-			return $font;
977
-		}
978
-		$offset += 4;
979
-		// get offset mode (indexToLocFormat : 0 = short, 1 = long)
980
-		$offset = $table['head']['offset'] + 50;
981
-		$short_offset = (TCPDF_STATIC::_getSHORT($font, $offset) == 0);
982
-		$offset += 2;
983
-		// get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table
984
-		$indexToLoc = array();
985
-		$offset = $table['loca']['offset'];
986
-		if ($short_offset) {
987
-			// short version
988
-			$tot_num_glyphs = floor($table['loca']['length'] / 2); // numGlyphs + 1
989
-			for ($i = 0; $i < $tot_num_glyphs; ++$i) {
990
-				$indexToLoc[$i] = TCPDF_STATIC::_getUSHORT($font, $offset) * 2;
991
-				$offset += 2;
992
-			}
993
-		} else {
994
-			// long version
995
-			$tot_num_glyphs = ($table['loca']['length'] / 4); // numGlyphs + 1
996
-			for ($i = 0; $i < $tot_num_glyphs; ++$i) {
997
-				$indexToLoc[$i] = TCPDF_STATIC::_getULONG($font, $offset);
998
-				$offset += 4;
999
-			}
1000
-		}
1001
-		// get glyphs indexes of chars from cmap table
1002
-		$subsetglyphs = array(); // glyph IDs on key
1003
-		$subsetglyphs[0] = true; // character codes that do not correspond to any glyph in the font should be mapped to glyph index 0
1004
-		$offset = $table['cmap']['offset'] + 2;
1005
-		$numEncodingTables = TCPDF_STATIC::_getUSHORT($font, $offset);
1006
-		$offset += 2;
1007
-		$encodingTables = array();
1008
-		for ($i = 0; $i < $numEncodingTables; ++$i) {
1009
-			$encodingTables[$i]['platformID'] = TCPDF_STATIC::_getUSHORT($font, $offset);
1010
-			$offset += 2;
1011
-			$encodingTables[$i]['encodingID'] = TCPDF_STATIC::_getUSHORT($font, $offset);
1012
-			$offset += 2;
1013
-			$encodingTables[$i]['offset'] = TCPDF_STATIC::_getULONG($font, $offset);
1014
-			$offset += 4;
1015
-		}
1016
-		foreach ($encodingTables as $enctable) {
1017
-			// get all platforms and encodings
1018
-			$offset = $table['cmap']['offset'] + $enctable['offset'];
1019
-			$format = TCPDF_STATIC::_getUSHORT($font, $offset);
1020
-			$offset += 2;
1021
-			switch ($format) {
1022
-				case 0: { // Format 0: Byte encoding table
1023
-					$offset += 4; // skip length and version/language
1024
-					for ($c = 0; $c < 256; ++$c) {
1025
-						if (isset($subsetchars[$c])) {
1026
-							$g = TCPDF_STATIC::_getBYTE($font, $offset);
1027
-							$subsetglyphs[$g] = true;
1028
-						}
1029
-						++$offset;
1030
-					}
1031
-					break;
1032
-				}
1033
-				case 2: { // Format 2: High-byte mapping through table
1034
-					$offset += 4; // skip length and version/language
1035
-					$numSubHeaders = 0;
1036
-					for ($i = 0; $i < 256; ++$i) {
1037
-						// Array that maps high bytes to subHeaders: value is subHeader index * 8.
1038
-						$subHeaderKeys[$i] = (TCPDF_STATIC::_getUSHORT($font, $offset) / 8);
1039
-						$offset += 2;
1040
-						if ($numSubHeaders < $subHeaderKeys[$i]) {
1041
-							$numSubHeaders = $subHeaderKeys[$i];
1042
-						}
1043
-					}
1044
-					// the number of subHeaders is equal to the max of subHeaderKeys + 1
1045
-					++$numSubHeaders;
1046
-					// read subHeader structures
1047
-					$subHeaders = array();
1048
-					$numGlyphIndexArray = 0;
1049
-					for ($k = 0; $k < $numSubHeaders; ++$k) {
1050
-						$subHeaders[$k]['firstCode'] = TCPDF_STATIC::_getUSHORT($font, $offset);
1051
-						$offset += 2;
1052
-						$subHeaders[$k]['entryCount'] = TCPDF_STATIC::_getUSHORT($font, $offset);
1053
-						$offset += 2;
1054
-						$subHeaders[$k]['idDelta'] = TCPDF_STATIC::_getUSHORT($font, $offset);
1055
-						$offset += 2;
1056
-						$subHeaders[$k]['idRangeOffset'] = TCPDF_STATIC::_getUSHORT($font, $offset);
1057
-						$offset += 2;
1058
-						$subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1) * 8));
1059
-						$subHeaders[$k]['idRangeOffset'] /= 2;
1060
-						$numGlyphIndexArray += $subHeaders[$k]['entryCount'];
1061
-					}
1062
-					for ($k = 0; $k < $numGlyphIndexArray; ++$k) {
1063
-						$glyphIndexArray[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
1064
-						$offset += 2;
1065
-					}
1066
-					for ($i = 0; $i < 256; ++$i) {
1067
-						$k = $subHeaderKeys[$i];
1068
-						if ($k == 0) {
1069
-							// one byte code
1070
-							$c = $i;
1071
-							if (isset($subsetchars[$c])) {
1072
-								$g = $glyphIndexArray[0];
1073
-								$subsetglyphs[$g] = true;
1074
-							}
1075
-						} else {
1076
-							// two bytes code
1077
-							$start_byte = $subHeaders[$k]['firstCode'];
1078
-							$end_byte = $start_byte + $subHeaders[$k]['entryCount'];
1079
-							for ($j = $start_byte; $j < $end_byte; ++$j) {
1080
-								// combine high and low bytes
1081
-								$c = (($i << 8) + $j);
1082
-								if (isset($subsetchars[$c])) {
1083
-									$idRangeOffset = ($subHeaders[$k]['idRangeOffset'] + $j - $subHeaders[$k]['firstCode']);
1084
-									$g = ($glyphIndexArray[$idRangeOffset] + $subHeaders[$k]['idDelta']) % 65536;
1085
-									if ($g < 0) {
1086
-										$g = 0;
1087
-									}
1088
-									$subsetglyphs[$g] = true;
1089
-								}
1090
-							}
1091
-						}
1092
-					}
1093
-					break;
1094
-				}
1095
-				case 4: { // Format 4: Segment mapping to delta values
1096
-					$length = TCPDF_STATIC::_getUSHORT($font, $offset);
1097
-					$offset += 2;
1098
-					$offset += 2; // skip version/language
1099
-					$segCount = floor(TCPDF_STATIC::_getUSHORT($font, $offset) / 2);
1100
-					$offset += 2;
1101
-					$offset += 6; // skip searchRange, entrySelector, rangeShift
1102
-					$endCount = array(); // array of end character codes for each segment
1103
-					for ($k = 0; $k < $segCount; ++$k) {
1104
-						$endCount[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
1105
-						$offset += 2;
1106
-					}
1107
-					$offset += 2; // skip reservedPad
1108
-					$startCount = array(); // array of start character codes for each segment
1109
-					for ($k = 0; $k < $segCount; ++$k) {
1110
-						$startCount[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
1111
-						$offset += 2;
1112
-					}
1113
-					$idDelta = array(); // delta for all character codes in segment
1114
-					for ($k = 0; $k < $segCount; ++$k) {
1115
-						$idDelta[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
1116
-						$offset += 2;
1117
-					}
1118
-					$idRangeOffset = array(); // Offsets into glyphIdArray or 0
1119
-					for ($k = 0; $k < $segCount; ++$k) {
1120
-						$idRangeOffset[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
1121
-						$offset += 2;
1122
-					}
1123
-					$gidlen = (floor($length / 2) - 8 - (4 * $segCount));
1124
-					$glyphIdArray = array(); // glyph index array
1125
-					for ($k = 0; $k < $gidlen; ++$k) {
1126
-						$glyphIdArray[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
1127
-						$offset += 2;
1128
-					}
1129
-					for ($k = 0; $k < $segCount; ++$k) {
1130
-						for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) {
1131
-							if (isset($subsetchars[$c])) {
1132
-								if ($idRangeOffset[$k] == 0) {
1133
-									$g = ($idDelta[$k] + $c) % 65536;
1134
-								} else {
1135
-									$gid = (floor($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k));
1136
-									$g = ($glyphIdArray[$gid] + $idDelta[$k]) % 65536;
1137
-								}
1138
-								if ($g < 0) {
1139
-									$g = 0;
1140
-								}
1141
-								$subsetglyphs[$g] = true;
1142
-							}
1143
-						}
1144
-					}	
1145
-					break;
1146
-				}
1147
-				case 6: { // Format 6: Trimmed table mapping
1148
-					$offset += 4; // skip length and version/language
1149
-					$firstCode = TCPDF_STATIC::_getUSHORT($font, $offset);
1150
-					$offset += 2;
1151
-					$entryCount = TCPDF_STATIC::_getUSHORT($font, $offset);
1152
-					$offset += 2;
1153
-					for ($k = 0; $k < $entryCount; ++$k) {
1154
-						$c = ($k + $firstCode);
1155
-						if (isset($subsetchars[$c])) {
1156
-							$g = TCPDF_STATIC::_getUSHORT($font, $offset);
1157
-							$subsetglyphs[$g] = true;
1158
-						}
1159
-						$offset += 2;
1160
-					}
1161
-					break;
1162
-				}
1163
-				case 8: { // Format 8: Mixed 16-bit and 32-bit coverage
1164
-					$offset += 10; // skip reserved, length and version/language
1165
-					for ($k = 0; $k < 8192; ++$k) {
1166
-						$is32[$k] = TCPDF_STATIC::_getBYTE($font, $offset);
1167
-						++$offset;
1168
-					}
1169
-					$nGroups = TCPDF_STATIC::_getULONG($font, $offset);
1170
-					$offset += 4;
1171
-					for ($i = 0; $i < $nGroups; ++$i) {
1172
-						$startCharCode = TCPDF_STATIC::_getULONG($font, $offset);
1173
-						$offset += 4;
1174
-						$endCharCode = TCPDF_STATIC::_getULONG($font, $offset);
1175
-						$offset += 4;
1176
-						$startGlyphID = TCPDF_STATIC::_getULONG($font, $offset);
1177
-						$offset += 4;
1178
-						for ($k = $startCharCode; $k <= $endCharCode; ++$k) {
1179
-							$is32idx = floor($c / 8);
1180
-							if ((isset($is32[$is32idx])) AND (($is32[$is32idx] & (1 << (7 - ($c % 8)))) == 0)) {
1181
-								$c = $k;
1182
-							} else {
1183
-								// 32 bit format
1184
-								// convert to decimal (http://www.unicode.org/faq//utf_bom.html#utf16-4)
1185
-								//LEAD_OFFSET = (0xD800 - (0x10000 >> 10)) = 55232
1186
-								//SURROGATE_OFFSET = (0x10000 - (0xD800 << 10) - 0xDC00) = -56613888
1187
-								$c = ((55232 + ($k >> 10)) << 10) + (0xDC00 + ($k & 0x3FF)) -56613888;
1188
-							}
1189
-							if (isset($subsetchars[$c])) {
1190
-								$subsetglyphs[$startGlyphID] = true;
1191
-							}
1192
-							++$startGlyphID;
1193
-						}
1194
-					}
1195
-					break;
1196
-				}
1197
-				case 10: { // Format 10: Trimmed array
1198
-					$offset += 10; // skip reserved, length and version/language
1199
-					$startCharCode = TCPDF_STATIC::_getULONG($font, $offset);
1200
-					$offset += 4;
1201
-					$numChars = TCPDF_STATIC::_getULONG($font, $offset);
1202
-					$offset += 4;
1203
-					for ($k = 0; $k < $numChars; ++$k) {
1204
-						$c = ($k + $startCharCode);
1205
-						if (isset($subsetchars[$c])) {
1206
-							$g = TCPDF_STATIC::_getUSHORT($font, $offset);
1207
-							$subsetglyphs[$g] = true;
1208
-						}
1209
-						$offset += 2;
1210
-					}
1211
-					break;
1212
-				}
1213
-				case 12: { // Format 12: Segmented coverage
1214
-					$offset += 10; // skip length and version/language
1215
-					$nGroups = TCPDF_STATIC::_getULONG($font, $offset);
1216
-					$offset += 4;
1217
-					for ($k = 0; $k < $nGroups; ++$k) {
1218
-						$startCharCode = TCPDF_STATIC::_getULONG($font, $offset);
1219
-						$offset += 4;
1220
-						$endCharCode = TCPDF_STATIC::_getULONG($font, $offset);
1221
-						$offset += 4;
1222
-						$startGlyphCode = TCPDF_STATIC::_getULONG($font, $offset);
1223
-						$offset += 4;
1224
-						for ($c = $startCharCode; $c <= $endCharCode; ++$c) {
1225
-							if (isset($subsetchars[$c])) {
1226
-								$subsetglyphs[$startGlyphCode] = true;
1227
-							}
1228
-							++$startGlyphCode;
1229
-						}
1230
-					}
1231
-					break;
1232
-				}
1233
-				case 13: { // Format 13: Many-to-one range mappings
1234
-					// to be implemented ...
1235
-					break;
1236
-				}
1237
-				case 14: { // Format 14: Unicode Variation Sequences
1238
-					// to be implemented ...
1239
-					break;
1240
-				}
1241
-			}
1242
-		}
1243
-		// include all parts of composite glyphs
1244
-		$new_sga = $subsetglyphs;
1245
-		while (!empty($new_sga)) {
1246
-			$sga = $new_sga;
1247
-			$new_sga = array();
1248
-			foreach ($sga as $key => $val) {
1249
-				if (isset($indexToLoc[$key])) {
1250
-					$offset = ($table['glyf']['offset'] + $indexToLoc[$key]);
1251
-					$numberOfContours = TCPDF_STATIC::_getSHORT($font, $offset);
1252
-					$offset += 2;
1253
-					if ($numberOfContours < 0) { // composite glyph
1254
-						$offset += 8; // skip xMin, yMin, xMax, yMax
1255
-						do {
1256
-							$flags = TCPDF_STATIC::_getUSHORT($font, $offset);
1257
-							$offset += 2;
1258
-							$glyphIndex = TCPDF_STATIC::_getUSHORT($font, $offset);
1259
-							$offset += 2;
1260
-							if (!isset($subsetglyphs[$glyphIndex])) {
1261
-								// add missing glyphs
1262
-								$new_sga[$glyphIndex] = true;
1263
-							}
1264
-							// skip some bytes by case
1265
-							if ($flags & 1) {
1266
-								$offset += 4;
1267
-							} else {
1268
-								$offset += 2;
1269
-							}
1270
-							if ($flags & 8) {
1271
-								$offset += 2;
1272
-							} elseif ($flags & 64) {
1273
-								$offset += 4;
1274
-							} elseif ($flags & 128) {
1275
-								$offset += 8;
1276
-							}
1277
-						} while ($flags & 32);
1278
-					}
1279
-				}
1280
-			}
1281
-			$subsetglyphs += $new_sga;
1282
-		}
1283
-		// sort glyphs by key (and remove duplicates)
1284
-		ksort($subsetglyphs);
1285
-		// build new glyf and loca tables
1286
-		$glyf = '';
1287
-		$loca = '';
1288
-		$offset = 0;
1289
-		$glyf_offset = $table['glyf']['offset'];
1290
-		for ($i = 0; $i < $tot_num_glyphs; ++$i) {
1291
-			if (isset($subsetglyphs[$i])) {
1292
-				$length = ($indexToLoc[($i + 1)] - $indexToLoc[$i]);
1293
-				$glyf .= substr($font, ($glyf_offset + $indexToLoc[$i]), $length);
1294
-			} else {
1295
-				$length = 0;
1296
-			}
1297
-			if ($short_offset) {
1298
-				$loca .= pack('n', floor($offset / 2));
1299
-			} else {
1300
-				$loca .= pack('N', $offset);
1301
-			}
1302
-			$offset += $length;
1303
-		}
1304
-		// array of table names to preserve (loca and glyf tables will be added later)
1305
-		// the cmap table is not needed and shall not be present, since the mapping from character codes to glyph descriptions is provided separately
1306
-		$table_names = array ('head', 'hhea', 'hmtx', 'maxp', 'cvt ', 'fpgm', 'prep'); // minimum required table names
1307
-		// get the tables to preserve
1308
-		$offset = 12;
1309
-		foreach ($table as $tag => $val) {
1310
-			if (in_array($tag, $table_names)) {
1311
-				$table[$tag]['data'] = substr($font, $table[$tag]['offset'], $table[$tag]['length']);
1312
-				if ($tag == 'head') {
1313
-					// set the checkSumAdjustment to 0
1314
-					$table[$tag]['data'] = substr($table[$tag]['data'], 0, 8)."\x0\x0\x0\x0".substr($table[$tag]['data'], 12);
1315
-				}
1316
-				$pad = 4 - ($table[$tag]['length'] % 4);
1317
-				if ($pad != 4) {
1318
-					// the length of a table must be a multiple of four bytes
1319
-					$table[$tag]['length'] += $pad;
1320
-					$table[$tag]['data'] .= str_repeat("\x0", $pad);
1321
-				}
1322
-				$table[$tag]['offset'] = $offset;
1323
-				$offset += $table[$tag]['length'];
1324
-				// check sum is not changed (so keep the following line commented)
1325
-				//$table[$tag]['checkSum'] = self::_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length']);
1326
-			} else {
1327
-				unset($table[$tag]);
1328
-			}
1329
-		}
1330
-		// add loca
1331
-		$table['loca']['data'] = $loca;
1332
-		$table['loca']['length'] = strlen($loca);
1333
-		$pad = 4 - ($table['loca']['length'] % 4);
1334
-		if ($pad != 4) {
1335
-			// the length of a table must be a multiple of four bytes
1336
-			$table['loca']['length'] += $pad;
1337
-			$table['loca']['data'] .= str_repeat("\x0", $pad);
1338
-		}
1339
-		$table['loca']['offset'] = $offset;
1340
-		$table['loca']['checkSum'] = self::_getTTFtableChecksum($table['loca']['data'], $table['loca']['length']);
1341
-		$offset += $table['loca']['length'];
1342
-		// add glyf
1343
-		$table['glyf']['data'] = $glyf;
1344
-		$table['glyf']['length'] = strlen($glyf);
1345
-		$pad = 4 - ($table['glyf']['length'] % 4);
1346
-		if ($pad != 4) {
1347
-			// the length of a table must be a multiple of four bytes
1348
-			$table['glyf']['length'] += $pad;
1349
-			$table['glyf']['data'] .= str_repeat("\x0", $pad);
1350
-		}
1351
-		$table['glyf']['offset'] = $offset;
1352
-		$table['glyf']['checkSum'] = self::_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length']);
1353
-		// rebuild font
1354
-		$font = '';
1355
-		$font .= pack('N', 0x10000); // sfnt version
1356
-		$numTables = count($table);
1357
-		$font .= pack('n', $numTables); // numTables
1358
-		$entrySelector = floor(log($numTables, 2));
1359
-		$searchRange = pow(2, $entrySelector) * 16;
1360
-		$rangeShift = ($numTables * 16) - $searchRange;
1361
-		$font .= pack('n', $searchRange); // searchRange
1362
-		$font .= pack('n', $entrySelector); // entrySelector
1363
-		$font .= pack('n', $rangeShift); // rangeShift
1364
-		$offset = ($numTables * 16);
1365
-		foreach ($table as $tag => $data) {
1366
-			$font .= $tag; // tag
1367
-			$font .= pack('N', $data['checkSum']); // checkSum
1368
-			$font .= pack('N', ($data['offset'] + $offset)); // offset
1369
-			$font .= pack('N', $data['length']); // length
1370
-		}
1371
-		foreach ($table as $data) {
1372
-			$font .= $data['data'];
1373
-		}
1374
-		// set checkSumAdjustment on head table
1375
-		$checkSumAdjustment = 0xB1B0AFBA - self::_getTTFtableChecksum($font, strlen($font));
1376
-		$font = substr($font, 0, $table['head']['offset'] + 8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + 12);
1377
-		return $font;
1378
-	}
935
+    /**
936
+     * Returns a subset of the TrueType font data without the unused glyphs.
937
+     * @param $font (string) TrueType font data.
938
+     * @param $subsetchars (array) Array of used characters (the glyphs to keep).
939
+     * @return (string) A subset of TrueType font data without the unused glyphs.
940
+     * @author Nicola Asuni
941
+     * @since 5.2.000 (2010-06-02)
942
+     * @public static
943
+     */
944
+    public static function _getTrueTypeFontSubset($font, $subsetchars) {
945
+        ksort($subsetchars);
946
+        $offset = 0; // offset position of the font data
947
+        if (TCPDF_STATIC::_getULONG($font, $offset) != 0x10000) {
948
+            // sfnt version must be 0x00010000 for TrueType version 1.0.
949
+            return $font;
950
+        }
951
+        $offset += 4;
952
+        // get number of tables
953
+        $numTables = TCPDF_STATIC::_getUSHORT($font, $offset);
954
+        $offset += 2;
955
+        // skip searchRange, entrySelector and rangeShift
956
+        $offset += 6;
957
+        // tables array
958
+        $table = array();
959
+        // for each table
960
+        for ($i = 0; $i < $numTables; ++$i) {
961
+            // get table info
962
+            $tag = substr($font, $offset, 4);
963
+            $offset += 4;
964
+            $table[$tag] = array();
965
+            $table[$tag]['checkSum'] = TCPDF_STATIC::_getULONG($font, $offset);
966
+            $offset += 4;
967
+            $table[$tag]['offset'] = TCPDF_STATIC::_getULONG($font, $offset);
968
+            $offset += 4;
969
+            $table[$tag]['length'] = TCPDF_STATIC::_getULONG($font, $offset);
970
+            $offset += 4;
971
+        }
972
+        // check magicNumber
973
+        $offset = $table['head']['offset'] + 12;
974
+        if (TCPDF_STATIC::_getULONG($font, $offset) != 0x5F0F3CF5) {
975
+            // magicNumber must be 0x5F0F3CF5
976
+            return $font;
977
+        }
978
+        $offset += 4;
979
+        // get offset mode (indexToLocFormat : 0 = short, 1 = long)
980
+        $offset = $table['head']['offset'] + 50;
981
+        $short_offset = (TCPDF_STATIC::_getSHORT($font, $offset) == 0);
982
+        $offset += 2;
983
+        // get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table
984
+        $indexToLoc = array();
985
+        $offset = $table['loca']['offset'];
986
+        if ($short_offset) {
987
+            // short version
988
+            $tot_num_glyphs = floor($table['loca']['length'] / 2); // numGlyphs + 1
989
+            for ($i = 0; $i < $tot_num_glyphs; ++$i) {
990
+                $indexToLoc[$i] = TCPDF_STATIC::_getUSHORT($font, $offset) * 2;
991
+                $offset += 2;
992
+            }
993
+        } else {
994
+            // long version
995
+            $tot_num_glyphs = ($table['loca']['length'] / 4); // numGlyphs + 1
996
+            for ($i = 0; $i < $tot_num_glyphs; ++$i) {
997
+                $indexToLoc[$i] = TCPDF_STATIC::_getULONG($font, $offset);
998
+                $offset += 4;
999
+            }
1000
+        }
1001
+        // get glyphs indexes of chars from cmap table
1002
+        $subsetglyphs = array(); // glyph IDs on key
1003
+        $subsetglyphs[0] = true; // character codes that do not correspond to any glyph in the font should be mapped to glyph index 0
1004
+        $offset = $table['cmap']['offset'] + 2;
1005
+        $numEncodingTables = TCPDF_STATIC::_getUSHORT($font, $offset);
1006
+        $offset += 2;
1007
+        $encodingTables = array();
1008
+        for ($i = 0; $i < $numEncodingTables; ++$i) {
1009
+            $encodingTables[$i]['platformID'] = TCPDF_STATIC::_getUSHORT($font, $offset);
1010
+            $offset += 2;
1011
+            $encodingTables[$i]['encodingID'] = TCPDF_STATIC::_getUSHORT($font, $offset);
1012
+            $offset += 2;
1013
+            $encodingTables[$i]['offset'] = TCPDF_STATIC::_getULONG($font, $offset);
1014
+            $offset += 4;
1015
+        }
1016
+        foreach ($encodingTables as $enctable) {
1017
+            // get all platforms and encodings
1018
+            $offset = $table['cmap']['offset'] + $enctable['offset'];
1019
+            $format = TCPDF_STATIC::_getUSHORT($font, $offset);
1020
+            $offset += 2;
1021
+            switch ($format) {
1022
+                case 0: { // Format 0: Byte encoding table
1023
+                    $offset += 4; // skip length and version/language
1024
+                    for ($c = 0; $c < 256; ++$c) {
1025
+                        if (isset($subsetchars[$c])) {
1026
+                            $g = TCPDF_STATIC::_getBYTE($font, $offset);
1027
+                            $subsetglyphs[$g] = true;
1028
+                        }
1029
+                        ++$offset;
1030
+                    }
1031
+                    break;
1032
+                }
1033
+                case 2: { // Format 2: High-byte mapping through table
1034
+                    $offset += 4; // skip length and version/language
1035
+                    $numSubHeaders = 0;
1036
+                    for ($i = 0; $i < 256; ++$i) {
1037
+                        // Array that maps high bytes to subHeaders: value is subHeader index * 8.
1038
+                        $subHeaderKeys[$i] = (TCPDF_STATIC::_getUSHORT($font, $offset) / 8);
1039
+                        $offset += 2;
1040
+                        if ($numSubHeaders < $subHeaderKeys[$i]) {
1041
+                            $numSubHeaders = $subHeaderKeys[$i];
1042
+                        }
1043
+                    }
1044
+                    // the number of subHeaders is equal to the max of subHeaderKeys + 1
1045
+                    ++$numSubHeaders;
1046
+                    // read subHeader structures
1047
+                    $subHeaders = array();
1048
+                    $numGlyphIndexArray = 0;
1049
+                    for ($k = 0; $k < $numSubHeaders; ++$k) {
1050
+                        $subHeaders[$k]['firstCode'] = TCPDF_STATIC::_getUSHORT($font, $offset);
1051
+                        $offset += 2;
1052
+                        $subHeaders[$k]['entryCount'] = TCPDF_STATIC::_getUSHORT($font, $offset);
1053
+                        $offset += 2;
1054
+                        $subHeaders[$k]['idDelta'] = TCPDF_STATIC::_getUSHORT($font, $offset);
1055
+                        $offset += 2;
1056
+                        $subHeaders[$k]['idRangeOffset'] = TCPDF_STATIC::_getUSHORT($font, $offset);
1057
+                        $offset += 2;
1058
+                        $subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1) * 8));
1059
+                        $subHeaders[$k]['idRangeOffset'] /= 2;
1060
+                        $numGlyphIndexArray += $subHeaders[$k]['entryCount'];
1061
+                    }
1062
+                    for ($k = 0; $k < $numGlyphIndexArray; ++$k) {
1063
+                        $glyphIndexArray[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
1064
+                        $offset += 2;
1065
+                    }
1066
+                    for ($i = 0; $i < 256; ++$i) {
1067
+                        $k = $subHeaderKeys[$i];
1068
+                        if ($k == 0) {
1069
+                            // one byte code
1070
+                            $c = $i;
1071
+                            if (isset($subsetchars[$c])) {
1072
+                                $g = $glyphIndexArray[0];
1073
+                                $subsetglyphs[$g] = true;
1074
+                            }
1075
+                        } else {
1076
+                            // two bytes code
1077
+                            $start_byte = $subHeaders[$k]['firstCode'];
1078
+                            $end_byte = $start_byte + $subHeaders[$k]['entryCount'];
1079
+                            for ($j = $start_byte; $j < $end_byte; ++$j) {
1080
+                                // combine high and low bytes
1081
+                                $c = (($i << 8) + $j);
1082
+                                if (isset($subsetchars[$c])) {
1083
+                                    $idRangeOffset = ($subHeaders[$k]['idRangeOffset'] + $j - $subHeaders[$k]['firstCode']);
1084
+                                    $g = ($glyphIndexArray[$idRangeOffset] + $subHeaders[$k]['idDelta']) % 65536;
1085
+                                    if ($g < 0) {
1086
+                                        $g = 0;
1087
+                                    }
1088
+                                    $subsetglyphs[$g] = true;
1089
+                                }
1090
+                            }
1091
+                        }
1092
+                    }
1093
+                    break;
1094
+                }
1095
+                case 4: { // Format 4: Segment mapping to delta values
1096
+                    $length = TCPDF_STATIC::_getUSHORT($font, $offset);
1097
+                    $offset += 2;
1098
+                    $offset += 2; // skip version/language
1099
+                    $segCount = floor(TCPDF_STATIC::_getUSHORT($font, $offset) / 2);
1100
+                    $offset += 2;
1101
+                    $offset += 6; // skip searchRange, entrySelector, rangeShift
1102
+                    $endCount = array(); // array of end character codes for each segment
1103
+                    for ($k = 0; $k < $segCount; ++$k) {
1104
+                        $endCount[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
1105
+                        $offset += 2;
1106
+                    }
1107
+                    $offset += 2; // skip reservedPad
1108
+                    $startCount = array(); // array of start character codes for each segment
1109
+                    for ($k = 0; $k < $segCount; ++$k) {
1110
+                        $startCount[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
1111
+                        $offset += 2;
1112
+                    }
1113
+                    $idDelta = array(); // delta for all character codes in segment
1114
+                    for ($k = 0; $k < $segCount; ++$k) {
1115
+                        $idDelta[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
1116
+                        $offset += 2;
1117
+                    }
1118
+                    $idRangeOffset = array(); // Offsets into glyphIdArray or 0
1119
+                    for ($k = 0; $k < $segCount; ++$k) {
1120
+                        $idRangeOffset[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
1121
+                        $offset += 2;
1122
+                    }
1123
+                    $gidlen = (floor($length / 2) - 8 - (4 * $segCount));
1124
+                    $glyphIdArray = array(); // glyph index array
1125
+                    for ($k = 0; $k < $gidlen; ++$k) {
1126
+                        $glyphIdArray[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
1127
+                        $offset += 2;
1128
+                    }
1129
+                    for ($k = 0; $k < $segCount; ++$k) {
1130
+                        for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) {
1131
+                            if (isset($subsetchars[$c])) {
1132
+                                if ($idRangeOffset[$k] == 0) {
1133
+                                    $g = ($idDelta[$k] + $c) % 65536;
1134
+                                } else {
1135
+                                    $gid = (floor($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k));
1136
+                                    $g = ($glyphIdArray[$gid] + $idDelta[$k]) % 65536;
1137
+                                }
1138
+                                if ($g < 0) {
1139
+                                    $g = 0;
1140
+                                }
1141
+                                $subsetglyphs[$g] = true;
1142
+                            }
1143
+                        }
1144
+                    }	
1145
+                    break;
1146
+                }
1147
+                case 6: { // Format 6: Trimmed table mapping
1148
+                    $offset += 4; // skip length and version/language
1149
+                    $firstCode = TCPDF_STATIC::_getUSHORT($font, $offset);
1150
+                    $offset += 2;
1151
+                    $entryCount = TCPDF_STATIC::_getUSHORT($font, $offset);
1152
+                    $offset += 2;
1153
+                    for ($k = 0; $k < $entryCount; ++$k) {
1154
+                        $c = ($k + $firstCode);
1155
+                        if (isset($subsetchars[$c])) {
1156
+                            $g = TCPDF_STATIC::_getUSHORT($font, $offset);
1157
+                            $subsetglyphs[$g] = true;
1158
+                        }
1159
+                        $offset += 2;
1160
+                    }
1161
+                    break;
1162
+                }
1163
+                case 8: { // Format 8: Mixed 16-bit and 32-bit coverage
1164
+                    $offset += 10; // skip reserved, length and version/language
1165
+                    for ($k = 0; $k < 8192; ++$k) {
1166
+                        $is32[$k] = TCPDF_STATIC::_getBYTE($font, $offset);
1167
+                        ++$offset;
1168
+                    }
1169
+                    $nGroups = TCPDF_STATIC::_getULONG($font, $offset);
1170
+                    $offset += 4;
1171
+                    for ($i = 0; $i < $nGroups; ++$i) {
1172
+                        $startCharCode = TCPDF_STATIC::_getULONG($font, $offset);
1173
+                        $offset += 4;
1174
+                        $endCharCode = TCPDF_STATIC::_getULONG($font, $offset);
1175
+                        $offset += 4;
1176
+                        $startGlyphID = TCPDF_STATIC::_getULONG($font, $offset);
1177
+                        $offset += 4;
1178
+                        for ($k = $startCharCode; $k <= $endCharCode; ++$k) {
1179
+                            $is32idx = floor($c / 8);
1180
+                            if ((isset($is32[$is32idx])) AND (($is32[$is32idx] & (1 << (7 - ($c % 8)))) == 0)) {
1181
+                                $c = $k;
1182
+                            } else {
1183
+                                // 32 bit format
1184
+                                // convert to decimal (http://www.unicode.org/faq//utf_bom.html#utf16-4)
1185
+                                //LEAD_OFFSET = (0xD800 - (0x10000 >> 10)) = 55232
1186
+                                //SURROGATE_OFFSET = (0x10000 - (0xD800 << 10) - 0xDC00) = -56613888
1187
+                                $c = ((55232 + ($k >> 10)) << 10) + (0xDC00 + ($k & 0x3FF)) -56613888;
1188
+                            }
1189
+                            if (isset($subsetchars[$c])) {
1190
+                                $subsetglyphs[$startGlyphID] = true;
1191
+                            }
1192
+                            ++$startGlyphID;
1193
+                        }
1194
+                    }
1195
+                    break;
1196
+                }
1197
+                case 10: { // Format 10: Trimmed array
1198
+                    $offset += 10; // skip reserved, length and version/language
1199
+                    $startCharCode = TCPDF_STATIC::_getULONG($font, $offset);
1200
+                    $offset += 4;
1201
+                    $numChars = TCPDF_STATIC::_getULONG($font, $offset);
1202
+                    $offset += 4;
1203
+                    for ($k = 0; $k < $numChars; ++$k) {
1204
+                        $c = ($k + $startCharCode);
1205
+                        if (isset($subsetchars[$c])) {
1206
+                            $g = TCPDF_STATIC::_getUSHORT($font, $offset);
1207
+                            $subsetglyphs[$g] = true;
1208
+                        }
1209
+                        $offset += 2;
1210
+                    }
1211
+                    break;
1212
+                }
1213
+                case 12: { // Format 12: Segmented coverage
1214
+                    $offset += 10; // skip length and version/language
1215
+                    $nGroups = TCPDF_STATIC::_getULONG($font, $offset);
1216
+                    $offset += 4;
1217
+                    for ($k = 0; $k < $nGroups; ++$k) {
1218
+                        $startCharCode = TCPDF_STATIC::_getULONG($font, $offset);
1219
+                        $offset += 4;
1220
+                        $endCharCode = TCPDF_STATIC::_getULONG($font, $offset);
1221
+                        $offset += 4;
1222
+                        $startGlyphCode = TCPDF_STATIC::_getULONG($font, $offset);
1223
+                        $offset += 4;
1224
+                        for ($c = $startCharCode; $c <= $endCharCode; ++$c) {
1225
+                            if (isset($subsetchars[$c])) {
1226
+                                $subsetglyphs[$startGlyphCode] = true;
1227
+                            }
1228
+                            ++$startGlyphCode;
1229
+                        }
1230
+                    }
1231
+                    break;
1232
+                }
1233
+                case 13: { // Format 13: Many-to-one range mappings
1234
+                    // to be implemented ...
1235
+                    break;
1236
+                }
1237
+                case 14: { // Format 14: Unicode Variation Sequences
1238
+                    // to be implemented ...
1239
+                    break;
1240
+                }
1241
+            }
1242
+        }
1243
+        // include all parts of composite glyphs
1244
+        $new_sga = $subsetglyphs;
1245
+        while (!empty($new_sga)) {
1246
+            $sga = $new_sga;
1247
+            $new_sga = array();
1248
+            foreach ($sga as $key => $val) {
1249
+                if (isset($indexToLoc[$key])) {
1250
+                    $offset = ($table['glyf']['offset'] + $indexToLoc[$key]);
1251
+                    $numberOfContours = TCPDF_STATIC::_getSHORT($font, $offset);
1252
+                    $offset += 2;
1253
+                    if ($numberOfContours < 0) { // composite glyph
1254
+                        $offset += 8; // skip xMin, yMin, xMax, yMax
1255
+                        do {
1256
+                            $flags = TCPDF_STATIC::_getUSHORT($font, $offset);
1257
+                            $offset += 2;
1258
+                            $glyphIndex = TCPDF_STATIC::_getUSHORT($font, $offset);
1259
+                            $offset += 2;
1260
+                            if (!isset($subsetglyphs[$glyphIndex])) {
1261
+                                // add missing glyphs
1262
+                                $new_sga[$glyphIndex] = true;
1263
+                            }
1264
+                            // skip some bytes by case
1265
+                            if ($flags & 1) {
1266
+                                $offset += 4;
1267
+                            } else {
1268
+                                $offset += 2;
1269
+                            }
1270
+                            if ($flags & 8) {
1271
+                                $offset += 2;
1272
+                            } elseif ($flags & 64) {
1273
+                                $offset += 4;
1274
+                            } elseif ($flags & 128) {
1275
+                                $offset += 8;
1276
+                            }
1277
+                        } while ($flags & 32);
1278
+                    }
1279
+                }
1280
+            }
1281
+            $subsetglyphs += $new_sga;
1282
+        }
1283
+        // sort glyphs by key (and remove duplicates)
1284
+        ksort($subsetglyphs);
1285
+        // build new glyf and loca tables
1286
+        $glyf = '';
1287
+        $loca = '';
1288
+        $offset = 0;
1289
+        $glyf_offset = $table['glyf']['offset'];
1290
+        for ($i = 0; $i < $tot_num_glyphs; ++$i) {
1291
+            if (isset($subsetglyphs[$i])) {
1292
+                $length = ($indexToLoc[($i + 1)] - $indexToLoc[$i]);
1293
+                $glyf .= substr($font, ($glyf_offset + $indexToLoc[$i]), $length);
1294
+            } else {
1295
+                $length = 0;
1296
+            }
1297
+            if ($short_offset) {
1298
+                $loca .= pack('n', floor($offset / 2));
1299
+            } else {
1300
+                $loca .= pack('N', $offset);
1301
+            }
1302
+            $offset += $length;
1303
+        }
1304
+        // array of table names to preserve (loca and glyf tables will be added later)
1305
+        // the cmap table is not needed and shall not be present, since the mapping from character codes to glyph descriptions is provided separately
1306
+        $table_names = array ('head', 'hhea', 'hmtx', 'maxp', 'cvt ', 'fpgm', 'prep'); // minimum required table names
1307
+        // get the tables to preserve
1308
+        $offset = 12;
1309
+        foreach ($table as $tag => $val) {
1310
+            if (in_array($tag, $table_names)) {
1311
+                $table[$tag]['data'] = substr($font, $table[$tag]['offset'], $table[$tag]['length']);
1312
+                if ($tag == 'head') {
1313
+                    // set the checkSumAdjustment to 0
1314
+                    $table[$tag]['data'] = substr($table[$tag]['data'], 0, 8)."\x0\x0\x0\x0".substr($table[$tag]['data'], 12);
1315
+                }
1316
+                $pad = 4 - ($table[$tag]['length'] % 4);
1317
+                if ($pad != 4) {
1318
+                    // the length of a table must be a multiple of four bytes
1319
+                    $table[$tag]['length'] += $pad;
1320
+                    $table[$tag]['data'] .= str_repeat("\x0", $pad);
1321
+                }
1322
+                $table[$tag]['offset'] = $offset;
1323
+                $offset += $table[$tag]['length'];
1324
+                // check sum is not changed (so keep the following line commented)
1325
+                //$table[$tag]['checkSum'] = self::_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length']);
1326
+            } else {
1327
+                unset($table[$tag]);
1328
+            }
1329
+        }
1330
+        // add loca
1331
+        $table['loca']['data'] = $loca;
1332
+        $table['loca']['length'] = strlen($loca);
1333
+        $pad = 4 - ($table['loca']['length'] % 4);
1334
+        if ($pad != 4) {
1335
+            // the length of a table must be a multiple of four bytes
1336
+            $table['loca']['length'] += $pad;
1337
+            $table['loca']['data'] .= str_repeat("\x0", $pad);
1338
+        }
1339
+        $table['loca']['offset'] = $offset;
1340
+        $table['loca']['checkSum'] = self::_getTTFtableChecksum($table['loca']['data'], $table['loca']['length']);
1341
+        $offset += $table['loca']['length'];
1342
+        // add glyf
1343
+        $table['glyf']['data'] = $glyf;
1344
+        $table['glyf']['length'] = strlen($glyf);
1345
+        $pad = 4 - ($table['glyf']['length'] % 4);
1346
+        if ($pad != 4) {
1347
+            // the length of a table must be a multiple of four bytes
1348
+            $table['glyf']['length'] += $pad;
1349
+            $table['glyf']['data'] .= str_repeat("\x0", $pad);
1350
+        }
1351
+        $table['glyf']['offset'] = $offset;
1352
+        $table['glyf']['checkSum'] = self::_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length']);
1353
+        // rebuild font
1354
+        $font = '';
1355
+        $font .= pack('N', 0x10000); // sfnt version
1356
+        $numTables = count($table);
1357
+        $font .= pack('n', $numTables); // numTables
1358
+        $entrySelector = floor(log($numTables, 2));
1359
+        $searchRange = pow(2, $entrySelector) * 16;
1360
+        $rangeShift = ($numTables * 16) - $searchRange;
1361
+        $font .= pack('n', $searchRange); // searchRange
1362
+        $font .= pack('n', $entrySelector); // entrySelector
1363
+        $font .= pack('n', $rangeShift); // rangeShift
1364
+        $offset = ($numTables * 16);
1365
+        foreach ($table as $tag => $data) {
1366
+            $font .= $tag; // tag
1367
+            $font .= pack('N', $data['checkSum']); // checkSum
1368
+            $font .= pack('N', ($data['offset'] + $offset)); // offset
1369
+            $font .= pack('N', $data['length']); // length
1370
+        }
1371
+        foreach ($table as $data) {
1372
+            $font .= $data['data'];
1373
+        }
1374
+        // set checkSumAdjustment on head table
1375
+        $checkSumAdjustment = 0xB1B0AFBA - self::_getTTFtableChecksum($font, strlen($font));
1376
+        $font = substr($font, 0, $table['head']['offset'] + 8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] + 12);
1377
+        return $font;
1378
+    }
1379 1379
 
1380
-	/**
1381
-	 * Outputs font widths
1382
-	 * @param $font (array) font data
1383
-	 * @param $cidoffset (int) offset for CID values
1384
-	 * @return PDF command string for font widths
1385
-	 * @author Nicola Asuni
1386
-	 * @since 4.4.000 (2008-12-07)
1387
-	 * @public static
1388
-	 */
1389
-	public static function _putfontwidths($font, $cidoffset=0) {
1390
-		ksort($font['cw']);
1391
-		$rangeid = 0;
1392
-		$range = array();
1393
-		$prevcid = -2;
1394
-		$prevwidth = -1;
1395
-		$interval = false;
1396
-		// for each character
1397
-		foreach ($font['cw'] as $cid => $width) {
1398
-			$cid -= $cidoffset;
1399
-			if ($font['subset'] AND (!isset($font['subsetchars'][$cid]))) {
1400
-				// ignore the unused characters (font subsetting)
1401
-				continue;
1402
-			}
1403
-			if ($width != $font['dw']) {
1404
-				if ($cid == ($prevcid + 1)) {
1405
-					// consecutive CID
1406
-					if ($width == $prevwidth) {
1407
-						if ($width == $range[$rangeid][0]) {
1408
-							$range[$rangeid][] = $width;
1409
-						} else {
1410
-							array_pop($range[$rangeid]);
1411
-							// new range
1412
-							$rangeid = $prevcid;
1413
-							$range[$rangeid] = array();
1414
-							$range[$rangeid][] = $prevwidth;
1415
-							$range[$rangeid][] = $width;
1416
-						}
1417
-						$interval = true;
1418
-						$range[$rangeid]['interval'] = true;
1419
-					} else {
1420
-						if ($interval) {
1421
-							// new range
1422
-							$rangeid = $cid;
1423
-							$range[$rangeid] = array();
1424
-							$range[$rangeid][] = $width;
1425
-						} else {
1426
-							$range[$rangeid][] = $width;
1427
-						}
1428
-						$interval = false;
1429
-					}
1430
-				} else {
1431
-					// new range
1432
-					$rangeid = $cid;
1433
-					$range[$rangeid] = array();
1434
-					$range[$rangeid][] = $width;
1435
-					$interval = false;
1436
-				}
1437
-				$prevcid = $cid;
1438
-				$prevwidth = $width;
1439
-			}
1440
-		}
1441
-		// optimize ranges
1442
-		$prevk = -1;
1443
-		$nextk = -1;
1444
-		$prevint = false;
1445
-		foreach ($range as $k => $ws) {
1446
-			$cws = count($ws);
1447
-			if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) {
1448
-				if (isset($range[$k]['interval'])) {
1449
-					unset($range[$k]['interval']);
1450
-				}
1451
-				$range[$prevk] = array_merge($range[$prevk], $range[$k]);
1452
-				unset($range[$k]);
1453
-			} else {
1454
-				$prevk = $k;
1455
-			}
1456
-			$nextk = $k + $cws;
1457
-			if (isset($ws['interval'])) {
1458
-				if ($cws > 3) {
1459
-					$prevint = true;
1460
-				} else {
1461
-					$prevint = false;
1462
-				}
1463
-				if (isset($range[$k]['interval'])) {
1464
-					unset($range[$k]['interval']);
1465
-				}
1466
-				--$nextk;
1467
-			} else {
1468
-				$prevint = false;
1469
-			}
1470
-		}
1471
-		// output data
1472
-		$w = '';
1473
-		foreach ($range as $k => $ws) {
1474
-			if (count(array_count_values($ws)) == 1) {
1475
-				// interval mode is more compact
1476
-				$w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0];
1477
-			} else {
1478
-				// range mode
1479
-				$w .= ' '.$k.' [ '.implode(' ', $ws).' ]';
1480
-			}
1481
-		}
1482
-		return '/W ['.$w.' ]';
1483
-	}
1380
+    /**
1381
+     * Outputs font widths
1382
+     * @param $font (array) font data
1383
+     * @param $cidoffset (int) offset for CID values
1384
+     * @return PDF command string for font widths
1385
+     * @author Nicola Asuni
1386
+     * @since 4.4.000 (2008-12-07)
1387
+     * @public static
1388
+     */
1389
+    public static function _putfontwidths($font, $cidoffset=0) {
1390
+        ksort($font['cw']);
1391
+        $rangeid = 0;
1392
+        $range = array();
1393
+        $prevcid = -2;
1394
+        $prevwidth = -1;
1395
+        $interval = false;
1396
+        // for each character
1397
+        foreach ($font['cw'] as $cid => $width) {
1398
+            $cid -= $cidoffset;
1399
+            if ($font['subset'] AND (!isset($font['subsetchars'][$cid]))) {
1400
+                // ignore the unused characters (font subsetting)
1401
+                continue;
1402
+            }
1403
+            if ($width != $font['dw']) {
1404
+                if ($cid == ($prevcid + 1)) {
1405
+                    // consecutive CID
1406
+                    if ($width == $prevwidth) {
1407
+                        if ($width == $range[$rangeid][0]) {
1408
+                            $range[$rangeid][] = $width;
1409
+                        } else {
1410
+                            array_pop($range[$rangeid]);
1411
+                            // new range
1412
+                            $rangeid = $prevcid;
1413
+                            $range[$rangeid] = array();
1414
+                            $range[$rangeid][] = $prevwidth;
1415
+                            $range[$rangeid][] = $width;
1416
+                        }
1417
+                        $interval = true;
1418
+                        $range[$rangeid]['interval'] = true;
1419
+                    } else {
1420
+                        if ($interval) {
1421
+                            // new range
1422
+                            $rangeid = $cid;
1423
+                            $range[$rangeid] = array();
1424
+                            $range[$rangeid][] = $width;
1425
+                        } else {
1426
+                            $range[$rangeid][] = $width;
1427
+                        }
1428
+                        $interval = false;
1429
+                    }
1430
+                } else {
1431
+                    // new range
1432
+                    $rangeid = $cid;
1433
+                    $range[$rangeid] = array();
1434
+                    $range[$rangeid][] = $width;
1435
+                    $interval = false;
1436
+                }
1437
+                $prevcid = $cid;
1438
+                $prevwidth = $width;
1439
+            }
1440
+        }
1441
+        // optimize ranges
1442
+        $prevk = -1;
1443
+        $nextk = -1;
1444
+        $prevint = false;
1445
+        foreach ($range as $k => $ws) {
1446
+            $cws = count($ws);
1447
+            if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) {
1448
+                if (isset($range[$k]['interval'])) {
1449
+                    unset($range[$k]['interval']);
1450
+                }
1451
+                $range[$prevk] = array_merge($range[$prevk], $range[$k]);
1452
+                unset($range[$k]);
1453
+            } else {
1454
+                $prevk = $k;
1455
+            }
1456
+            $nextk = $k + $cws;
1457
+            if (isset($ws['interval'])) {
1458
+                if ($cws > 3) {
1459
+                    $prevint = true;
1460
+                } else {
1461
+                    $prevint = false;
1462
+                }
1463
+                if (isset($range[$k]['interval'])) {
1464
+                    unset($range[$k]['interval']);
1465
+                }
1466
+                --$nextk;
1467
+            } else {
1468
+                $prevint = false;
1469
+            }
1470
+        }
1471
+        // output data
1472
+        $w = '';
1473
+        foreach ($range as $k => $ws) {
1474
+            if (count(array_count_values($ws)) == 1) {
1475
+                // interval mode is more compact
1476
+                $w .= ' '.$k.' '.($k + count($ws) - 1).' '.$ws[0];
1477
+            } else {
1478
+                // range mode
1479
+                $w .= ' '.$k.' [ '.implode(' ', $ws).' ]';
1480
+            }
1481
+        }
1482
+        return '/W ['.$w.' ]';
1483
+    }
1484 1484
 
1485
-	/**
1486
-	 * Returns the unicode caracter specified by the value
1487
-	 * @param $c (int) UTF-8 value
1488
-	 * @param $unicode (boolean) True if we are in unicode mode, false otherwise.
1489
-	 * @return Returns the specified character.
1490
-	 * @since 2.3.000 (2008-03-05)
1491
-	 * @public static
1492
-	 */
1493
-	public static function unichr($c, $unicode=true) {
1494
-		if (!$unicode) {
1495
-			return chr($c);
1496
-		} elseif ($c <= 0x7F) {
1497
-			// one byte
1498
-			return chr($c);
1499
-		} elseif ($c <= 0x7FF) {
1500
-			// two bytes
1501
-			return chr(0xC0 | $c >> 6).chr(0x80 | $c & 0x3F);
1502
-		} elseif ($c <= 0xFFFF) {
1503
-			// three bytes
1504
-			return chr(0xE0 | $c >> 12).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
1505
-		} elseif ($c <= 0x10FFFF) {
1506
-			// four bytes
1507
-			return chr(0xF0 | $c >> 18).chr(0x80 | $c >> 12 & 0x3F).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
1508
-		} else {
1509
-			return '';
1510
-		}
1511
-	}
1485
+    /**
1486
+     * Returns the unicode caracter specified by the value
1487
+     * @param $c (int) UTF-8 value
1488
+     * @param $unicode (boolean) True if we are in unicode mode, false otherwise.
1489
+     * @return Returns the specified character.
1490
+     * @since 2.3.000 (2008-03-05)
1491
+     * @public static
1492
+     */
1493
+    public static function unichr($c, $unicode=true) {
1494
+        if (!$unicode) {
1495
+            return chr($c);
1496
+        } elseif ($c <= 0x7F) {
1497
+            // one byte
1498
+            return chr($c);
1499
+        } elseif ($c <= 0x7FF) {
1500
+            // two bytes
1501
+            return chr(0xC0 | $c >> 6).chr(0x80 | $c & 0x3F);
1502
+        } elseif ($c <= 0xFFFF) {
1503
+            // three bytes
1504
+            return chr(0xE0 | $c >> 12).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
1505
+        } elseif ($c <= 0x10FFFF) {
1506
+            // four bytes
1507
+            return chr(0xF0 | $c >> 18).chr(0x80 | $c >> 12 & 0x3F).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
1508
+        } else {
1509
+            return '';
1510
+        }
1511
+    }
1512 1512
 
1513
-	/**
1514
-	 * Returns the unicode caracter specified by UTF-8 value
1515
-	 * @param $c (int) UTF-8 value
1516
-	 * @return Returns the specified character.
1517
-	 * @public static
1518
-	 */
1519
-	public static function unichrUnicode($c) {
1520
-		return self::unichr($c, true);
1521
-	}
1513
+    /**
1514
+     * Returns the unicode caracter specified by UTF-8 value
1515
+     * @param $c (int) UTF-8 value
1516
+     * @return Returns the specified character.
1517
+     * @public static
1518
+     */
1519
+    public static function unichrUnicode($c) {
1520
+        return self::unichr($c, true);
1521
+    }
1522 1522
 
1523
-	/**
1524
-	 * Returns the unicode caracter specified by ASCII value
1525
-	 * @param $c (int) UTF-8 value
1526
-	 * @return Returns the specified character.
1527
-	 * @public static
1528
-	 */
1529
-	public static function unichrASCII($c) {
1530
-		return self::unichr($c, false);
1531
-	}
1523
+    /**
1524
+     * Returns the unicode caracter specified by ASCII value
1525
+     * @param $c (int) UTF-8 value
1526
+     * @return Returns the specified character.
1527
+     * @public static
1528
+     */
1529
+    public static function unichrASCII($c) {
1530
+        return self::unichr($c, false);
1531
+    }
1532 1532
 
1533
-	/**
1534
-	 * Converts array of UTF-8 characters to UTF16-BE string.<br>
1535
-	 * Based on: http://www.faqs.org/rfcs/rfc2781.html
1536
-	 * <pre>
1537
-	 *   Encoding UTF-16:
1538
-	 *
1539
-	 *   Encoding of a single character from an ISO 10646 character value to
1540
-	 *    UTF-16 proceeds as follows. Let U be the character number, no greater
1541
-	 *    than 0x10FFFF.
1542
-	 *
1543
-	 *    1) If U < 0x10000, encode U as a 16-bit unsigned integer and
1544
-	 *       terminate.
1545
-	 *
1546
-	 *    2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
1547
-	 *       U' must be less than or equal to 0xFFFFF. That is, U' can be
1548
-	 *       represented in 20 bits.
1549
-	 *
1550
-	 *    3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
1551
-	 *       0xDC00, respectively. These integers each have 10 bits free to
1552
-	 *       encode the character value, for a total of 20 bits.
1553
-	 *
1554
-	 *    4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
1555
-	 *       bits of W1 and the 10 low-order bits of U' to the 10 low-order
1556
-	 *       bits of W2. Terminate.
1557
-	 *
1558
-	 *    Graphically, steps 2 through 4 look like:
1559
-	 *    U' = yyyyyyyyyyxxxxxxxxxx
1560
-	 *    W1 = 110110yyyyyyyyyy
1561
-	 *    W2 = 110111xxxxxxxxxx
1562
-	 * </pre>
1563
-	 * @param $unicode (array) array containing UTF-8 unicode values
1564
-	 * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF)
1565
-	 * @return string
1566
-	 * @protected
1567
-	 * @author Nicola Asuni
1568
-	 * @since 2.1.000 (2008-01-08)
1569
-	 * @public static
1570
-	 */
1571
-	public static function arrUTF8ToUTF16BE($unicode, $setbom=false) {
1572
-		$outstr = ''; // string to be returned
1573
-		if ($setbom) {
1574
-			$outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
1575
-		}
1576
-		foreach ($unicode as $char) {
1577
-			if ($char == 0x200b) {
1578
-				// skip Unicode Character 'ZERO WIDTH SPACE' (DEC:8203, U+200B)
1579
-			} elseif ($char == 0xFFFD) {
1580
-				$outstr .= "\xFF\xFD"; // replacement character
1581
-			} elseif ($char < 0x10000) {
1582
-				$outstr .= chr($char >> 0x08);
1583
-				$outstr .= chr($char & 0xFF);
1584
-			} else {
1585
-				$char -= 0x10000;
1586
-				$w1 = 0xD800 | ($char >> 0x0a);
1587
-				$w2 = 0xDC00 | ($char & 0x3FF);
1588
-				$outstr .= chr($w1 >> 0x08);
1589
-				$outstr .= chr($w1 & 0xFF);
1590
-				$outstr .= chr($w2 >> 0x08);
1591
-				$outstr .= chr($w2 & 0xFF);
1592
-			}
1593
-		}
1594
-		return $outstr;
1595
-	}
1533
+    /**
1534
+     * Converts array of UTF-8 characters to UTF16-BE string.<br>
1535
+     * Based on: http://www.faqs.org/rfcs/rfc2781.html
1536
+     * <pre>
1537
+     *   Encoding UTF-16:
1538
+     *
1539
+     *   Encoding of a single character from an ISO 10646 character value to
1540
+     *    UTF-16 proceeds as follows. Let U be the character number, no greater
1541
+     *    than 0x10FFFF.
1542
+     *
1543
+     *    1) If U < 0x10000, encode U as a 16-bit unsigned integer and
1544
+     *       terminate.
1545
+     *
1546
+     *    2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
1547
+     *       U' must be less than or equal to 0xFFFFF. That is, U' can be
1548
+     *       represented in 20 bits.
1549
+     *
1550
+     *    3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
1551
+     *       0xDC00, respectively. These integers each have 10 bits free to
1552
+     *       encode the character value, for a total of 20 bits.
1553
+     *
1554
+     *    4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
1555
+     *       bits of W1 and the 10 low-order bits of U' to the 10 low-order
1556
+     *       bits of W2. Terminate.
1557
+     *
1558
+     *    Graphically, steps 2 through 4 look like:
1559
+     *    U' = yyyyyyyyyyxxxxxxxxxx
1560
+     *    W1 = 110110yyyyyyyyyy
1561
+     *    W2 = 110111xxxxxxxxxx
1562
+     * </pre>
1563
+     * @param $unicode (array) array containing UTF-8 unicode values
1564
+     * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF)
1565
+     * @return string
1566
+     * @protected
1567
+     * @author Nicola Asuni
1568
+     * @since 2.1.000 (2008-01-08)
1569
+     * @public static
1570
+     */
1571
+    public static function arrUTF8ToUTF16BE($unicode, $setbom=false) {
1572
+        $outstr = ''; // string to be returned
1573
+        if ($setbom) {
1574
+            $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
1575
+        }
1576
+        foreach ($unicode as $char) {
1577
+            if ($char == 0x200b) {
1578
+                // skip Unicode Character 'ZERO WIDTH SPACE' (DEC:8203, U+200B)
1579
+            } elseif ($char == 0xFFFD) {
1580
+                $outstr .= "\xFF\xFD"; // replacement character
1581
+            } elseif ($char < 0x10000) {
1582
+                $outstr .= chr($char >> 0x08);
1583
+                $outstr .= chr($char & 0xFF);
1584
+            } else {
1585
+                $char -= 0x10000;
1586
+                $w1 = 0xD800 | ($char >> 0x0a);
1587
+                $w2 = 0xDC00 | ($char & 0x3FF);
1588
+                $outstr .= chr($w1 >> 0x08);
1589
+                $outstr .= chr($w1 & 0xFF);
1590
+                $outstr .= chr($w2 >> 0x08);
1591
+                $outstr .= chr($w2 & 0xFF);
1592
+            }
1593
+        }
1594
+        return $outstr;
1595
+    }
1596 1596
 
1597
-	/**
1598
-	 * Convert an array of UTF8 values to array of unicode characters
1599
-	 * @param $ta (array) The input array of UTF8 values.
1600
-	 * @param $isunicode (boolean) True for Unicode mode, false otherwise.
1601
-	 * @return Return array of unicode characters
1602
-	 * @since 4.5.037 (2009-04-07)
1603
-	 * @public static
1604
-	 */
1605
-	public static function UTF8ArrayToUniArray($ta, $isunicode=true) {
1606
-		if ($isunicode) {
1607
-			return array_map(array('TCPDF_FONTS', 'unichrUnicode'), $ta);
1608
-		}
1609
-		return array_map(array('TCPDF_FONTS', 'unichrASCII'), $ta);
1610
-	}
1597
+    /**
1598
+     * Convert an array of UTF8 values to array of unicode characters
1599
+     * @param $ta (array) The input array of UTF8 values.
1600
+     * @param $isunicode (boolean) True for Unicode mode, false otherwise.
1601
+     * @return Return array of unicode characters
1602
+     * @since 4.5.037 (2009-04-07)
1603
+     * @public static
1604
+     */
1605
+    public static function UTF8ArrayToUniArray($ta, $isunicode=true) {
1606
+        if ($isunicode) {
1607
+            return array_map(array('TCPDF_FONTS', 'unichrUnicode'), $ta);
1608
+        }
1609
+        return array_map(array('TCPDF_FONTS', 'unichrASCII'), $ta);
1610
+    }
1611 1611
 
1612
-	/**
1613
-	 * Extract a slice of the $strarr array and return it as string.
1614
-	 * @param $strarr (string) The input array of characters.
1615
-	 * @param $start (int) the starting element of $strarr.
1616
-	 * @param $end (int) first element that will not be returned.
1617
-	 * @param $unicode (boolean) True if we are in unicode mode, false otherwise.
1618
-	 * @return Return part of a string
1619
-	 * @public static
1620
-	 */
1621
-	public static function UTF8ArrSubString($strarr, $start='', $end='', $unicode=true) {
1622
-		if (strlen($start) == 0) {
1623
-			$start = 0;
1624
-		}
1625
-		if (strlen($end) == 0) {
1626
-			$end = count($strarr);
1627
-		}
1628
-		$string = '';
1629
-		for ($i = $start; $i < $end; ++$i) {
1630
-			$string .= self::unichr($strarr[$i], $unicode);
1631
-		}
1632
-		return $string;
1633
-	}
1612
+    /**
1613
+     * Extract a slice of the $strarr array and return it as string.
1614
+     * @param $strarr (string) The input array of characters.
1615
+     * @param $start (int) the starting element of $strarr.
1616
+     * @param $end (int) first element that will not be returned.
1617
+     * @param $unicode (boolean) True if we are in unicode mode, false otherwise.
1618
+     * @return Return part of a string
1619
+     * @public static
1620
+     */
1621
+    public static function UTF8ArrSubString($strarr, $start='', $end='', $unicode=true) {
1622
+        if (strlen($start) == 0) {
1623
+            $start = 0;
1624
+        }
1625
+        if (strlen($end) == 0) {
1626
+            $end = count($strarr);
1627
+        }
1628
+        $string = '';
1629
+        for ($i = $start; $i < $end; ++$i) {
1630
+            $string .= self::unichr($strarr[$i], $unicode);
1631
+        }
1632
+        return $string;
1633
+    }
1634 1634
 
1635
-	/**
1636
-	 * Extract a slice of the $uniarr array and return it as string.
1637
-	 * @param $uniarr (string) The input array of characters.
1638
-	 * @param $start (int) the starting element of $strarr.
1639
-	 * @param $end (int) first element that will not be returned.
1640
-	 * @return Return part of a string
1641
-	 * @since 4.5.037 (2009-04-07)
1642
-	 * @public static
1643
-	 */
1644
-	public static function UniArrSubString($uniarr, $start='', $end='') {
1645
-		if (strlen($start) == 0) {
1646
-			$start = 0;
1647
-		}
1648
-		if (strlen($end) == 0) {
1649
-			$end = count($uniarr);
1650
-		}
1651
-		$string = '';
1652
-		for ($i=$start; $i < $end; ++$i) {
1653
-			$string .= $uniarr[$i];
1654
-		}
1655
-		return $string;
1656
-	}
1635
+    /**
1636
+     * Extract a slice of the $uniarr array and return it as string.
1637
+     * @param $uniarr (string) The input array of characters.
1638
+     * @param $start (int) the starting element of $strarr.
1639
+     * @param $end (int) first element that will not be returned.
1640
+     * @return Return part of a string
1641
+     * @since 4.5.037 (2009-04-07)
1642
+     * @public static
1643
+     */
1644
+    public static function UniArrSubString($uniarr, $start='', $end='') {
1645
+        if (strlen($start) == 0) {
1646
+            $start = 0;
1647
+        }
1648
+        if (strlen($end) == 0) {
1649
+            $end = count($uniarr);
1650
+        }
1651
+        $string = '';
1652
+        for ($i=$start; $i < $end; ++$i) {
1653
+            $string .= $uniarr[$i];
1654
+        }
1655
+        return $string;
1656
+    }
1657 1657
 
1658
-	/**
1659
-	 * Update the CIDToGIDMap string with a new value.
1660
-	 * @param $map (string) CIDToGIDMap.
1661
-	 * @param $cid (int) CID value.
1662
-	 * @param $gid (int) GID value.
1663
-	 * @return (string) CIDToGIDMap.
1664
-	 * @author Nicola Asuni
1665
-	 * @since 5.9.123 (2011-09-29)
1666
-	 * @public static
1667
-	 */
1668
-	public static function updateCIDtoGIDmap($map, $cid, $gid) {
1669
-		if (($cid >= 0) AND ($cid <= 0xFFFF) AND ($gid >= 0)) {
1670
-			if ($gid > 0xFFFF) {
1671
-				$gid -= 0x10000;
1672
-			}
1673
-			$map[($cid * 2)] = chr($gid >> 8);
1674
-			$map[(($cid * 2) + 1)] = chr($gid & 0xFF);
1675
-		}
1676
-		return $map;
1677
-	}
1658
+    /**
1659
+     * Update the CIDToGIDMap string with a new value.
1660
+     * @param $map (string) CIDToGIDMap.
1661
+     * @param $cid (int) CID value.
1662
+     * @param $gid (int) GID value.
1663
+     * @return (string) CIDToGIDMap.
1664
+     * @author Nicola Asuni
1665
+     * @since 5.9.123 (2011-09-29)
1666
+     * @public static
1667
+     */
1668
+    public static function updateCIDtoGIDmap($map, $cid, $gid) {
1669
+        if (($cid >= 0) AND ($cid <= 0xFFFF) AND ($gid >= 0)) {
1670
+            if ($gid > 0xFFFF) {
1671
+                $gid -= 0x10000;
1672
+            }
1673
+            $map[($cid * 2)] = chr($gid >> 8);
1674
+            $map[(($cid * 2) + 1)] = chr($gid & 0xFF);
1675
+        }
1676
+        return $map;
1677
+    }
1678 1678
 
1679
-	/**
1680
-	 * Return fonts path
1681
-	 * @return string
1682
-	 * @public static
1683
-	 */
1684
-	public static function _getfontpath() {
1685
-		if (!defined('K_PATH_FONTS') AND is_dir($fdir = realpath(dirname(__FILE__).'/../fonts'))) {
1686
-			if (substr($fdir, -1) != '/') {
1687
-				$fdir .= '/';
1688
-			}
1689
-			define('K_PATH_FONTS', $fdir);
1690
-		}
1691
-		return defined('K_PATH_FONTS') ? K_PATH_FONTS : '';
1692
-	}
1679
+    /**
1680
+     * Return fonts path
1681
+     * @return string
1682
+     * @public static
1683
+     */
1684
+    public static function _getfontpath() {
1685
+        if (!defined('K_PATH_FONTS') AND is_dir($fdir = realpath(dirname(__FILE__).'/../fonts'))) {
1686
+            if (substr($fdir, -1) != '/') {
1687
+                $fdir .= '/';
1688
+            }
1689
+            define('K_PATH_FONTS', $fdir);
1690
+        }
1691
+        return defined('K_PATH_FONTS') ? K_PATH_FONTS : '';
1692
+    }
1693 1693
 
1694
-	/**
1695
-	 * Return font full path
1696
-	 * @param $file (string) Font file name.
1697
-	 * @param $fontdir (string) Font directory (set to false fto search on default directories)
1698
-	 * @return string Font full path or empty string
1699
-	 * @author Nicola Asuni
1700
-	 * @since 6.0.025
1701
-	 * @public static
1702
-	 */
1703
-	public static function getFontFullPath($file, $fontdir=false) {
1704
-		$fontfile = '';
1705
-		// search files on various directories
1706
-		if (($fontdir !== false) AND @file_exists($fontdir.$file)) {
1707
-			$fontfile = $fontdir.$file;
1708
-		} elseif (@file_exists(self::_getfontpath().$file)) {
1709
-			$fontfile = self::_getfontpath().$file;
1710
-		} elseif (@file_exists($file)) {
1711
-			$fontfile = $file;
1712
-		}
1713
-		return $fontfile;
1714
-	}
1694
+    /**
1695
+     * Return font full path
1696
+     * @param $file (string) Font file name.
1697
+     * @param $fontdir (string) Font directory (set to false fto search on default directories)
1698
+     * @return string Font full path or empty string
1699
+     * @author Nicola Asuni
1700
+     * @since 6.0.025
1701
+     * @public static
1702
+     */
1703
+    public static function getFontFullPath($file, $fontdir=false) {
1704
+        $fontfile = '';
1705
+        // search files on various directories
1706
+        if (($fontdir !== false) AND @file_exists($fontdir.$file)) {
1707
+            $fontfile = $fontdir.$file;
1708
+        } elseif (@file_exists(self::_getfontpath().$file)) {
1709
+            $fontfile = self::_getfontpath().$file;
1710
+        } elseif (@file_exists($file)) {
1711
+            $fontfile = $file;
1712
+        }
1713
+        return $fontfile;
1714
+    }
1715 1715
 
1716
-	/**
1717
-	 * Converts UTF-8 characters array to array of Latin1 characters array<br>
1718
-	 * @param $unicode (array) array containing UTF-8 unicode values
1719
-	 * @return array
1720
-	 * @author Nicola Asuni
1721
-	 * @since 4.8.023 (2010-01-15)
1722
-	 * @public static
1723
-	 */
1724
-	public static function UTF8ArrToLatin1Arr($unicode) {
1725
-		$outarr = array(); // array to be returned
1726
-		foreach ($unicode as $char) {
1727
-			if ($char < 256) {
1728
-				$outarr[] = $char;
1729
-			} elseif (array_key_exists($char, TCPDF_FONT_DATA::$uni_utf8tolatin)) {
1730
-				// map from UTF-8
1731
-				$outarr[] = TCPDF_FONT_DATA::$uni_utf8tolatin[$char];
1732
-			} elseif ($char == 0xFFFD) {
1733
-				// skip
1734
-			} else {
1735
-				$outarr[] = 63; // '?' character
1736
-			}
1737
-		}
1738
-		return $outarr;
1739
-	}
1716
+    /**
1717
+     * Converts UTF-8 characters array to array of Latin1 characters array<br>
1718
+     * @param $unicode (array) array containing UTF-8 unicode values
1719
+     * @return array
1720
+     * @author Nicola Asuni
1721
+     * @since 4.8.023 (2010-01-15)
1722
+     * @public static
1723
+     */
1724
+    public static function UTF8ArrToLatin1Arr($unicode) {
1725
+        $outarr = array(); // array to be returned
1726
+        foreach ($unicode as $char) {
1727
+            if ($char < 256) {
1728
+                $outarr[] = $char;
1729
+            } elseif (array_key_exists($char, TCPDF_FONT_DATA::$uni_utf8tolatin)) {
1730
+                // map from UTF-8
1731
+                $outarr[] = TCPDF_FONT_DATA::$uni_utf8tolatin[$char];
1732
+            } elseif ($char == 0xFFFD) {
1733
+                // skip
1734
+            } else {
1735
+                $outarr[] = 63; // '?' character
1736
+            }
1737
+        }
1738
+        return $outarr;
1739
+    }
1740 1740
 
1741
-	/**
1742
-	 * Converts UTF-8 characters array to array of Latin1 string<br>
1743
-	 * @param $unicode (array) array containing UTF-8 unicode values
1744
-	 * @return array
1745
-	 * @author Nicola Asuni
1746
-	 * @since 4.8.023 (2010-01-15)
1747
-	 * @public static
1748
-	 */
1749
-	public static function UTF8ArrToLatin1($unicode) {
1750
-		$outstr = ''; // string to be returned
1751
-		foreach ($unicode as $char) {
1752
-			if ($char < 256) {
1753
-				$outstr .= chr($char);
1754
-			} elseif (array_key_exists($char, TCPDF_FONT_DATA::$uni_utf8tolatin)) {
1755
-				// map from UTF-8
1756
-				$outstr .= chr(TCPDF_FONT_DATA::$uni_utf8tolatin[$char]);
1757
-			} elseif ($char == 0xFFFD) {
1758
-				// skip
1759
-			} else {
1760
-				$outstr .= '?';
1761
-			}
1762
-		}
1763
-		return $outstr;
1764
-	}
1741
+    /**
1742
+     * Converts UTF-8 characters array to array of Latin1 string<br>
1743
+     * @param $unicode (array) array containing UTF-8 unicode values
1744
+     * @return array
1745
+     * @author Nicola Asuni
1746
+     * @since 4.8.023 (2010-01-15)
1747
+     * @public static
1748
+     */
1749
+    public static function UTF8ArrToLatin1($unicode) {
1750
+        $outstr = ''; // string to be returned
1751
+        foreach ($unicode as $char) {
1752
+            if ($char < 256) {
1753
+                $outstr .= chr($char);
1754
+            } elseif (array_key_exists($char, TCPDF_FONT_DATA::$uni_utf8tolatin)) {
1755
+                // map from UTF-8
1756
+                $outstr .= chr(TCPDF_FONT_DATA::$uni_utf8tolatin[$char]);
1757
+            } elseif ($char == 0xFFFD) {
1758
+                // skip
1759
+            } else {
1760
+                $outstr .= '?';
1761
+            }
1762
+        }
1763
+        return $outstr;
1764
+    }
1765 1765
 
1766
-	/**
1767
-	 * Converts UTF-8 character to integer value.<br>
1768
-	 * Uses the getUniord() method if the value is not cached.
1769
-	 * @param $uch (string) character string to process.
1770
-	 * @return integer Unicode value
1771
-	 * @public static
1772
-	 */
1773
-	public static function uniord($uch) {
1774
-		if (!isset(self::$cache_uniord[$uch])) {
1775
-			self::$cache_uniord[$uch] = self::getUniord($uch);
1776
-		}
1777
-		return self::$cache_uniord[$uch];
1778
-	}
1766
+    /**
1767
+     * Converts UTF-8 character to integer value.<br>
1768
+     * Uses the getUniord() method if the value is not cached.
1769
+     * @param $uch (string) character string to process.
1770
+     * @return integer Unicode value
1771
+     * @public static
1772
+     */
1773
+    public static function uniord($uch) {
1774
+        if (!isset(self::$cache_uniord[$uch])) {
1775
+            self::$cache_uniord[$uch] = self::getUniord($uch);
1776
+        }
1777
+        return self::$cache_uniord[$uch];
1778
+    }
1779 1779
 
1780
-	/**
1781
-	 * Converts UTF-8 character to integer value.<br>
1782
-	 * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
1783
-	 * Based on: http://www.faqs.org/rfcs/rfc3629.html
1784
-	 * <pre>
1785
-	 *    Char. number range  |        UTF-8 octet sequence
1786
-	 *       (hexadecimal)    |              (binary)
1787
-	 *    --------------------+-----------------------------------------------
1788
-	 *    0000 0000-0000 007F | 0xxxxxxx
1789
-	 *    0000 0080-0000 07FF | 110xxxxx 10xxxxxx
1790
-	 *    0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
1791
-	 *    0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
1792
-	 *    ---------------------------------------------------------------------
1793
-	 *
1794
-	 *   ABFN notation:
1795
-	 *   ---------------------------------------------------------------------
1796
-	 *   UTF8-octets = *( UTF8-char )
1797
-	 *   UTF8-char   = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
1798
-	 *   UTF8-1      = %x00-7F
1799
-	 *   UTF8-2      = %xC2-DF UTF8-tail
1800
-	 *
1801
-	 *   UTF8-3      = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
1802
-	 *                 %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
1803
-	 *   UTF8-4      = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
1804
-	 *                 %xF4 %x80-8F 2( UTF8-tail )
1805
-	 *   UTF8-tail   = %x80-BF
1806
-	 *   ---------------------------------------------------------------------
1807
-	 * </pre>
1808
-	 * @param $uch (string) character string to process.
1809
-	 * @return integer Unicode value
1810
-	 * @author Nicola Asuni
1811
-	 * @public static
1812
-	 */
1813
-	public static function getUniord($uch) {
1814
-		if (function_exists('mb_convert_encoding')) {
1815
-			list(, $char) = @unpack('N', mb_convert_encoding($uch, 'UCS-4BE', 'UTF-8'));
1816
-			if ($char >= 0) {
1817
-				return $char;
1818
-			}
1819
-		}
1820
-		$bytes = array(); // array containing single character byte sequences
1821
-		$countbytes = 0;
1822
-		$numbytes = 1; // number of octetc needed to represent the UTF-8 character
1823
-		$length = strlen($uch);
1824
-		for ($i = 0; $i < $length; ++$i) {
1825
-			$char = ord($uch[$i]); // get one string character at time
1826
-			if ($countbytes == 0) { // get starting octect
1827
-				if ($char <= 0x7F) {
1828
-					return $char; // use the character "as is" because is ASCII
1829
-				} elseif (($char >> 0x05) == 0x06) { // 2 bytes character (0x06 = 110 BIN)
1830
-					$bytes[] = ($char - 0xC0) << 0x06;
1831
-					++$countbytes;
1832
-					$numbytes = 2;
1833
-				} elseif (($char >> 0x04) == 0x0E) { // 3 bytes character (0x0E = 1110 BIN)
1834
-					$bytes[] = ($char - 0xE0) << 0x0C;
1835
-					++$countbytes;
1836
-					$numbytes = 3;
1837
-				} elseif (($char >> 0x03) == 0x1E) { // 4 bytes character (0x1E = 11110 BIN)
1838
-					$bytes[] = ($char - 0xF0) << 0x12;
1839
-					++$countbytes;
1840
-					$numbytes = 4;
1841
-				} else {
1842
-					// use replacement character for other invalid sequences
1843
-					return 0xFFFD;
1844
-				}
1845
-			} elseif (($char >> 0x06) == 0x02) { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN
1846
-				$bytes[] = $char - 0x80;
1847
-				++$countbytes;
1848
-				if ($countbytes == $numbytes) {
1849
-					// compose UTF-8 bytes to a single unicode value
1850
-					$char = $bytes[0];
1851
-					for ($j = 1; $j < $numbytes; ++$j) {
1852
-						$char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
1853
-					}
1854
-					if ((($char >= 0xD800) AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
1855
-						// The definition of UTF-8 prohibits encoding character numbers between
1856
-						// U+D800 and U+DFFF, which are reserved for use with the UTF-16
1857
-						// encoding form (as surrogate pairs) and do not directly represent
1858
-						// characters.
1859
-						return 0xFFFD; // use replacement character
1860
-					} else {
1861
-						return $char;
1862
-					}
1863
-				}
1864
-			} else {
1865
-				// use replacement character for other invalid sequences
1866
-				return 0xFFFD;
1867
-			}
1868
-		}
1869
-		return 0xFFFD;
1870
-	}
1780
+    /**
1781
+     * Converts UTF-8 character to integer value.<br>
1782
+     * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
1783
+     * Based on: http://www.faqs.org/rfcs/rfc3629.html
1784
+     * <pre>
1785
+     *    Char. number range  |        UTF-8 octet sequence
1786
+     *       (hexadecimal)    |              (binary)
1787
+     *    --------------------+-----------------------------------------------
1788
+     *    0000 0000-0000 007F | 0xxxxxxx
1789
+     *    0000 0080-0000 07FF | 110xxxxx 10xxxxxx
1790
+     *    0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
1791
+     *    0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
1792
+     *    ---------------------------------------------------------------------
1793
+     *
1794
+     *   ABFN notation:
1795
+     *   ---------------------------------------------------------------------
1796
+     *   UTF8-octets = *( UTF8-char )
1797
+     *   UTF8-char   = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
1798
+     *   UTF8-1      = %x00-7F
1799
+     *   UTF8-2      = %xC2-DF UTF8-tail
1800
+     *
1801
+     *   UTF8-3      = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
1802
+     *                 %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
1803
+     *   UTF8-4      = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
1804
+     *                 %xF4 %x80-8F 2( UTF8-tail )
1805
+     *   UTF8-tail   = %x80-BF
1806
+     *   ---------------------------------------------------------------------
1807
+     * </pre>
1808
+     * @param $uch (string) character string to process.
1809
+     * @return integer Unicode value
1810
+     * @author Nicola Asuni
1811
+     * @public static
1812
+     */
1813
+    public static function getUniord($uch) {
1814
+        if (function_exists('mb_convert_encoding')) {
1815
+            list(, $char) = @unpack('N', mb_convert_encoding($uch, 'UCS-4BE', 'UTF-8'));
1816
+            if ($char >= 0) {
1817
+                return $char;
1818
+            }
1819
+        }
1820
+        $bytes = array(); // array containing single character byte sequences
1821
+        $countbytes = 0;
1822
+        $numbytes = 1; // number of octetc needed to represent the UTF-8 character
1823
+        $length = strlen($uch);
1824
+        for ($i = 0; $i < $length; ++$i) {
1825
+            $char = ord($uch[$i]); // get one string character at time
1826
+            if ($countbytes == 0) { // get starting octect
1827
+                if ($char <= 0x7F) {
1828
+                    return $char; // use the character "as is" because is ASCII
1829
+                } elseif (($char >> 0x05) == 0x06) { // 2 bytes character (0x06 = 110 BIN)
1830
+                    $bytes[] = ($char - 0xC0) << 0x06;
1831
+                    ++$countbytes;
1832
+                    $numbytes = 2;
1833
+                } elseif (($char >> 0x04) == 0x0E) { // 3 bytes character (0x0E = 1110 BIN)
1834
+                    $bytes[] = ($char - 0xE0) << 0x0C;
1835
+                    ++$countbytes;
1836
+                    $numbytes = 3;
1837
+                } elseif (($char >> 0x03) == 0x1E) { // 4 bytes character (0x1E = 11110 BIN)
1838
+                    $bytes[] = ($char - 0xF0) << 0x12;
1839
+                    ++$countbytes;
1840
+                    $numbytes = 4;
1841
+                } else {
1842
+                    // use replacement character for other invalid sequences
1843
+                    return 0xFFFD;
1844
+                }
1845
+            } elseif (($char >> 0x06) == 0x02) { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN
1846
+                $bytes[] = $char - 0x80;
1847
+                ++$countbytes;
1848
+                if ($countbytes == $numbytes) {
1849
+                    // compose UTF-8 bytes to a single unicode value
1850
+                    $char = $bytes[0];
1851
+                    for ($j = 1; $j < $numbytes; ++$j) {
1852
+                        $char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
1853
+                    }
1854
+                    if ((($char >= 0xD800) AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
1855
+                        // The definition of UTF-8 prohibits encoding character numbers between
1856
+                        // U+D800 and U+DFFF, which are reserved for use with the UTF-16
1857
+                        // encoding form (as surrogate pairs) and do not directly represent
1858
+                        // characters.
1859
+                        return 0xFFFD; // use replacement character
1860
+                    } else {
1861
+                        return $char;
1862
+                    }
1863
+                }
1864
+            } else {
1865
+                // use replacement character for other invalid sequences
1866
+                return 0xFFFD;
1867
+            }
1868
+        }
1869
+        return 0xFFFD;
1870
+    }
1871 1871
 
1872
-	/**
1873
-	 * Converts UTF-8 strings to codepoints array.<br>
1874
-	 * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
1875
-	 * @param $str (string) string to process.
1876
-	 * @param $isunicode (boolean) True when the documetn is in Unicode mode, false otherwise.
1877
-	 * @param $currentfont (array) Reference to current font array.
1878
-	 * @return array containing codepoints (UTF-8 characters values)
1879
-	 * @author Nicola Asuni
1880
-	 * @public static
1881
-	 */
1882
-	public static function UTF8StringToArray($str, $isunicode=true, &$currentfont) {
1883
-		if ($isunicode) {
1884
-			// requires PCRE unicode support turned on
1885
-			$chars = TCPDF_STATIC::pregSplit('//','u', $str, -1, PREG_SPLIT_NO_EMPTY);
1886
-			$carr = array_map(array('TCPDF_FONTS', 'uniord'), $chars);
1887
-		} else {
1888
-			$chars = str_split($str);
1889
-			$carr = array_map('ord', $chars);
1890
-		}
1891
-		$currentfont['subsetchars'] += array_fill_keys($carr, true);
1892
-		return $carr;
1893
-	}
1872
+    /**
1873
+     * Converts UTF-8 strings to codepoints array.<br>
1874
+     * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
1875
+     * @param $str (string) string to process.
1876
+     * @param $isunicode (boolean) True when the documetn is in Unicode mode, false otherwise.
1877
+     * @param $currentfont (array) Reference to current font array.
1878
+     * @return array containing codepoints (UTF-8 characters values)
1879
+     * @author Nicola Asuni
1880
+     * @public static
1881
+     */
1882
+    public static function UTF8StringToArray($str, $isunicode=true, &$currentfont) {
1883
+        if ($isunicode) {
1884
+            // requires PCRE unicode support turned on
1885
+            $chars = TCPDF_STATIC::pregSplit('//','u', $str, -1, PREG_SPLIT_NO_EMPTY);
1886
+            $carr = array_map(array('TCPDF_FONTS', 'uniord'), $chars);
1887
+        } else {
1888
+            $chars = str_split($str);
1889
+            $carr = array_map('ord', $chars);
1890
+        }
1891
+        $currentfont['subsetchars'] += array_fill_keys($carr, true);
1892
+        return $carr;
1893
+    }
1894 1894
 
1895
-	/**
1896
-	 * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.<br>
1897
-	 * @param $str (string) string to process.
1898
-	 * @param $isunicode (boolean) True when the documetn is in Unicode mode, false otherwise.
1899
-	 * @param $currentfont (array) Reference to current font array.
1900
-	 * @return string
1901
-	 * @since 3.2.000 (2008-06-23)
1902
-	 * @public static
1903
-	 */
1904
-	public static function UTF8ToLatin1($str, $isunicode=true, &$currentfont) {
1905
-		$unicode = self::UTF8StringToArray($str, $isunicode, $currentfont); // array containing UTF-8 unicode values
1906
-		return self::UTF8ArrToLatin1($unicode);
1907
-	}
1895
+    /**
1896
+     * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.<br>
1897
+     * @param $str (string) string to process.
1898
+     * @param $isunicode (boolean) True when the documetn is in Unicode mode, false otherwise.
1899
+     * @param $currentfont (array) Reference to current font array.
1900
+     * @return string
1901
+     * @since 3.2.000 (2008-06-23)
1902
+     * @public static
1903
+     */
1904
+    public static function UTF8ToLatin1($str, $isunicode=true, &$currentfont) {
1905
+        $unicode = self::UTF8StringToArray($str, $isunicode, $currentfont); // array containing UTF-8 unicode values
1906
+        return self::UTF8ArrToLatin1($unicode);
1907
+    }
1908 1908
 
1909
-	/**
1910
-	 * Converts UTF-8 strings to UTF16-BE.<br>
1911
-	 * @param $str (string) string to process.
1912
-	 * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF)
1913
-	 * @param $isunicode (boolean) True when the documetn is in Unicode mode, false otherwise.
1914
-	 * @param $currentfont (array) Reference to current font array.
1915
-	 * @return string
1916
-	 * @author Nicola Asuni
1917
-	 * @since 1.53.0.TC005 (2005-01-05)
1918
-	 * @public static
1919
-	 */
1920
-	public static function UTF8ToUTF16BE($str, $setbom=false, $isunicode=true, &$currentfont) {
1921
-		if (!$isunicode) {
1922
-			return $str; // string is not in unicode
1923
-		}
1924
-		$unicode = self::UTF8StringToArray($str, $isunicode, $currentfont); // array containing UTF-8 unicode values
1925
-		return self::arrUTF8ToUTF16BE($unicode, $setbom);
1926
-	}
1909
+    /**
1910
+     * Converts UTF-8 strings to UTF16-BE.<br>
1911
+     * @param $str (string) string to process.
1912
+     * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF)
1913
+     * @param $isunicode (boolean) True when the documetn is in Unicode mode, false otherwise.
1914
+     * @param $currentfont (array) Reference to current font array.
1915
+     * @return string
1916
+     * @author Nicola Asuni
1917
+     * @since 1.53.0.TC005 (2005-01-05)
1918
+     * @public static
1919
+     */
1920
+    public static function UTF8ToUTF16BE($str, $setbom=false, $isunicode=true, &$currentfont) {
1921
+        if (!$isunicode) {
1922
+            return $str; // string is not in unicode
1923
+        }
1924
+        $unicode = self::UTF8StringToArray($str, $isunicode, $currentfont); // array containing UTF-8 unicode values
1925
+        return self::arrUTF8ToUTF16BE($unicode, $setbom);
1926
+    }
1927 1927
 
1928
-	/**
1929
-	 * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
1930
-	 * @param $str (string) string to manipulate.
1931
-	 * @param $setbom (bool) if true set the Byte Order Mark (BOM = 0xFEFF)
1932
-	 * @param $forcertl (bool) if true forces RTL text direction
1933
-	 * @param $isunicode (boolean) True if the document is in Unicode mode, false otherwise.
1934
-	 * @param $currentfont (array) Reference to current font array.
1935
-	 * @return string
1936
-	 * @author Nicola Asuni
1937
-	 * @since 2.1.000 (2008-01-08)
1938
-	 * @public static
1939
-	 */
1940
-	public static function utf8StrRev($str, $setbom=false, $forcertl=false, $isunicode=true, &$currentfont) {
1941
-		return self::utf8StrArrRev(self::UTF8StringToArray($str, $isunicode, $currentfont), $str, $setbom, $forcertl, $isunicode, $currentfont);
1942
-	}
1928
+    /**
1929
+     * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
1930
+     * @param $str (string) string to manipulate.
1931
+     * @param $setbom (bool) if true set the Byte Order Mark (BOM = 0xFEFF)
1932
+     * @param $forcertl (bool) if true forces RTL text direction
1933
+     * @param $isunicode (boolean) True if the document is in Unicode mode, false otherwise.
1934
+     * @param $currentfont (array) Reference to current font array.
1935
+     * @return string
1936
+     * @author Nicola Asuni
1937
+     * @since 2.1.000 (2008-01-08)
1938
+     * @public static
1939
+     */
1940
+    public static function utf8StrRev($str, $setbom=false, $forcertl=false, $isunicode=true, &$currentfont) {
1941
+        return self::utf8StrArrRev(self::UTF8StringToArray($str, $isunicode, $currentfont), $str, $setbom, $forcertl, $isunicode, $currentfont);
1942
+    }
1943 1943
 
1944
-	/**
1945
-	 * Reverse the RLT substrings array using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
1946
-	 * @param $arr (array) array of unicode values.
1947
-	 * @param $str (string) string to manipulate (or empty value).
1948
-	 * @param $setbom (bool) if true set the Byte Order Mark (BOM = 0xFEFF)
1949
-	 * @param $forcertl (bool) if true forces RTL text direction
1950
-	 * @param $isunicode (boolean) True if the document is in Unicode mode, false otherwise.
1951
-	 * @param $currentfont (array) Reference to current font array.
1952
-	 * @return string
1953
-	 * @author Nicola Asuni
1954
-	 * @since 4.9.000 (2010-03-27)
1955
-	 * @public static
1956
-	 */
1957
-	public static function utf8StrArrRev($arr, $str='', $setbom=false, $forcertl=false, $isunicode=true, &$currentfont) {
1958
-		return self::arrUTF8ToUTF16BE(self::utf8Bidi($arr, $str, $forcertl, $isunicode, $currentfont), $setbom);
1959
-	}
1944
+    /**
1945
+     * Reverse the RLT substrings array using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
1946
+     * @param $arr (array) array of unicode values.
1947
+     * @param $str (string) string to manipulate (or empty value).
1948
+     * @param $setbom (bool) if true set the Byte Order Mark (BOM = 0xFEFF)
1949
+     * @param $forcertl (bool) if true forces RTL text direction
1950
+     * @param $isunicode (boolean) True if the document is in Unicode mode, false otherwise.
1951
+     * @param $currentfont (array) Reference to current font array.
1952
+     * @return string
1953
+     * @author Nicola Asuni
1954
+     * @since 4.9.000 (2010-03-27)
1955
+     * @public static
1956
+     */
1957
+    public static function utf8StrArrRev($arr, $str='', $setbom=false, $forcertl=false, $isunicode=true, &$currentfont) {
1958
+        return self::arrUTF8ToUTF16BE(self::utf8Bidi($arr, $str, $forcertl, $isunicode, $currentfont), $setbom);
1959
+    }
1960 1960
 
1961
-	/**
1962
-	 * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
1963
-	 * @param $ta (array) array of characters composing the string.
1964
-	 * @param $str (string) string to process
1965
-	 * @param $forcertl (bool) if 'R' forces RTL, if 'L' forces LTR
1966
-	 * @param $isunicode (boolean) True if the document is in Unicode mode, false otherwise.
1967
-	 * @param $currentfont (array) Reference to current font array.
1968
-	 * @return array of unicode chars
1969
-	 * @author Nicola Asuni
1970
-	 * @since 2.4.000 (2008-03-06)
1971
-	 * @public static
1972
-	 */
1973
-	public static function utf8Bidi($ta, $str='', $forcertl=false, $isunicode=true, &$currentfont) {
1974
-		// paragraph embedding level
1975
-		$pel = 0;
1976
-		// max level
1977
-		$maxlevel = 0;
1978
-		if (TCPDF_STATIC::empty_string($str)) {
1979
-			// create string from array
1980
-			$str = self::UTF8ArrSubString($ta, '', '', $isunicode);
1981
-		}
1982
-		// check if string contains arabic text
1983
-		if (preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_ARABIC, $str)) {
1984
-			$arabic = true;
1985
-		} else {
1986
-			$arabic = false;
1987
-		}
1988
-		// check if string contains RTL text
1989
-		if (!($forcertl OR $arabic OR preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_RTL, $str))) {
1990
-			return $ta;
1991
-		}
1961
+    /**
1962
+     * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
1963
+     * @param $ta (array) array of characters composing the string.
1964
+     * @param $str (string) string to process
1965
+     * @param $forcertl (bool) if 'R' forces RTL, if 'L' forces LTR
1966
+     * @param $isunicode (boolean) True if the document is in Unicode mode, false otherwise.
1967
+     * @param $currentfont (array) Reference to current font array.
1968
+     * @return array of unicode chars
1969
+     * @author Nicola Asuni
1970
+     * @since 2.4.000 (2008-03-06)
1971
+     * @public static
1972
+     */
1973
+    public static function utf8Bidi($ta, $str='', $forcertl=false, $isunicode=true, &$currentfont) {
1974
+        // paragraph embedding level
1975
+        $pel = 0;
1976
+        // max level
1977
+        $maxlevel = 0;
1978
+        if (TCPDF_STATIC::empty_string($str)) {
1979
+            // create string from array
1980
+            $str = self::UTF8ArrSubString($ta, '', '', $isunicode);
1981
+        }
1982
+        // check if string contains arabic text
1983
+        if (preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_ARABIC, $str)) {
1984
+            $arabic = true;
1985
+        } else {
1986
+            $arabic = false;
1987
+        }
1988
+        // check if string contains RTL text
1989
+        if (!($forcertl OR $arabic OR preg_match(TCPDF_FONT_DATA::$uni_RE_PATTERN_RTL, $str))) {
1990
+            return $ta;
1991
+        }
1992 1992
 
1993
-		// get number of chars
1994
-		$numchars = count($ta);
1993
+        // get number of chars
1994
+        $numchars = count($ta);
1995 1995
 
1996
-		if ($forcertl == 'R') {
1997
-			$pel = 1;
1998
-		} elseif ($forcertl == 'L') {
1999
-			$pel = 0;
2000
-		} else {
2001
-			// P2. In each paragraph, find the first character of type L, AL, or R.
2002
-			// P3. If a character is found in P2 and it is of type AL or R, then set the paragraph embedding level to one; otherwise, set it to zero.
2003
-			for ($i=0; $i < $numchars; ++$i) {
2004
-				$type = TCPDF_FONT_DATA::$uni_type[$ta[$i]];
2005
-				if ($type == 'L') {
2006
-					$pel = 0;
2007
-					break;
2008
-				} elseif (($type == 'AL') OR ($type == 'R')) {
2009
-					$pel = 1;
2010
-					break;
2011
-				}
2012
-			}
2013
-		}
1996
+        if ($forcertl == 'R') {
1997
+            $pel = 1;
1998
+        } elseif ($forcertl == 'L') {
1999
+            $pel = 0;
2000
+        } else {
2001
+            // P2. In each paragraph, find the first character of type L, AL, or R.
2002
+            // P3. If a character is found in P2 and it is of type AL or R, then set the paragraph embedding level to one; otherwise, set it to zero.
2003
+            for ($i=0; $i < $numchars; ++$i) {
2004
+                $type = TCPDF_FONT_DATA::$uni_type[$ta[$i]];
2005
+                if ($type == 'L') {
2006
+                    $pel = 0;
2007
+                    break;
2008
+                } elseif (($type == 'AL') OR ($type == 'R')) {
2009
+                    $pel = 1;
2010
+                    break;
2011
+                }
2012
+            }
2013
+        }
2014 2014
 
2015
-		// Current Embedding Level
2016
-		$cel = $pel;
2017
-		// directional override status
2018
-		$dos = 'N';
2019
-		$remember = array();
2020
-		// start-of-level-run
2021
-		$sor = $pel % 2 ? 'R' : 'L';
2022
-		$eor = $sor;
2015
+        // Current Embedding Level
2016
+        $cel = $pel;
2017
+        // directional override status
2018
+        $dos = 'N';
2019
+        $remember = array();
2020
+        // start-of-level-run
2021
+        $sor = $pel % 2 ? 'R' : 'L';
2022
+        $eor = $sor;
2023 2023
 
2024
-		// Array of characters data
2025
-		$chardata = Array();
2024
+        // Array of characters data
2025
+        $chardata = Array();
2026 2026
 
2027
-		// X1. Begin by setting the current embedding level to the paragraph embedding level. Set the directional override status to neutral. Process each character iteratively, applying rules X2 through X9. Only embedding levels from 0 to 61 are valid in this phase.
2028
-		// In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached.
2029
-		for ($i=0; $i < $numchars; ++$i) {
2030
-			if ($ta[$i] == TCPDF_FONT_DATA::$uni_RLE) {
2031
-				// X2. With each RLE, compute the least greater odd embedding level.
2032
-				//	a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
2033
-				//	b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
2034
-				$next_level = $cel + ($cel % 2) + 1;
2035
-				if ($next_level < 62) {
2036
-					$remember[] = array('num' => TCPDF_FONT_DATA::$uni_RLE, 'cel' => $cel, 'dos' => $dos);
2037
-					$cel = $next_level;
2038
-					$dos = 'N';
2039
-					$sor = $eor;
2040
-					$eor = $cel % 2 ? 'R' : 'L';
2041
-				}
2042
-			} elseif ($ta[$i] == TCPDF_FONT_DATA::$uni_LRE) {
2043
-				// X3. With each LRE, compute the least greater even embedding level.
2044
-				//	a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
2045
-				//	b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
2046
-				$next_level = $cel + 2 - ($cel % 2);
2047
-				if ( $next_level < 62 ) {
2048
-					$remember[] = array('num' => TCPDF_FONT_DATA::$uni_LRE, 'cel' => $cel, 'dos' => $dos);
2049
-					$cel = $next_level;
2050
-					$dos = 'N';
2051
-					$sor = $eor;
2052
-					$eor = $cel % 2 ? 'R' : 'L';
2053
-				}
2054
-			} elseif ($ta[$i] == TCPDF_FONT_DATA::$uni_RLO) {
2055
-				// X4. With each RLO, compute the least greater odd embedding level.
2056
-				//	a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to right-to-left.
2057
-				//	b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
2058
-				$next_level = $cel + ($cel % 2) + 1;
2059
-				if ($next_level < 62) {
2060
-					$remember[] = array('num' => TCPDF_FONT_DATA::$uni_RLO, 'cel' => $cel, 'dos' => $dos);
2061
-					$cel = $next_level;
2062
-					$dos = 'R';
2063
-					$sor = $eor;
2064
-					$eor = $cel % 2 ? 'R' : 'L';
2065
-				}
2066
-			} elseif ($ta[$i] == TCPDF_FONT_DATA::$uni_LRO) {
2067
-				// X5. With each LRO, compute the least greater even embedding level.
2068
-				//	a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to left-to-right.
2069
-				//	b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
2070
-				$next_level = $cel + 2 - ($cel % 2);
2071
-				if ( $next_level < 62 ) {
2072
-					$remember[] = array('num' => TCPDF_FONT_DATA::$uni_LRO, 'cel' => $cel, 'dos' => $dos);
2073
-					$cel = $next_level;
2074
-					$dos = 'L';
2075
-					$sor = $eor;
2076
-					$eor = $cel % 2 ? 'R' : 'L';
2077
-				}
2078
-			} elseif ($ta[$i] == TCPDF_FONT_DATA::$uni_PDF) {
2079
-				// X7. With each PDF, determine the matching embedding or override code. If there was a valid matching code, restore (pop) the last remembered (pushed) embedding level and directional override.
2080
-				if (count($remember)) {
2081
-					$last = count($remember ) - 1;
2082
-					if (($remember[$last]['num'] == TCPDF_FONT_DATA::$uni_RLE) OR
2083
-						($remember[$last]['num'] == TCPDF_FONT_DATA::$uni_LRE) OR
2084
-						($remember[$last]['num'] == TCPDF_FONT_DATA::$uni_RLO) OR
2085
-						($remember[$last]['num'] == TCPDF_FONT_DATA::$uni_LRO)) {
2086
-						$match = array_pop($remember);
2087
-						$cel = $match['cel'];
2088
-						$dos = $match['dos'];
2089
-						$sor = $eor;
2090
-						$eor = ($cel > $match['cel'] ? $cel : $match['cel']) % 2 ? 'R' : 'L';
2091
-					}
2092
-				}
2093
-			} elseif (($ta[$i] != TCPDF_FONT_DATA::$uni_RLE) AND
2094
-							 ($ta[$i] != TCPDF_FONT_DATA::$uni_LRE) AND
2095
-							 ($ta[$i] != TCPDF_FONT_DATA::$uni_RLO) AND
2096
-							 ($ta[$i] != TCPDF_FONT_DATA::$uni_LRO) AND
2097
-							 ($ta[$i] != TCPDF_FONT_DATA::$uni_PDF)) {
2098
-				// X6. For all types besides RLE, LRE, RLO, LRO, and PDF:
2099
-				//	a. Set the level of the current character to the current embedding level.
2100
-				//	b. Whenever the directional override status is not neutral, reset the current character type to the directional override status.
2101
-				if ($dos != 'N') {
2102
-					$chardir = $dos;
2103
-				} else {
2104
-					if (isset(TCPDF_FONT_DATA::$uni_type[$ta[$i]])) {
2105
-						$chardir = TCPDF_FONT_DATA::$uni_type[$ta[$i]];
2106
-					} else {
2107
-						$chardir = 'L';
2108
-					}
2109
-				}
2110
-				// stores string characters and other information
2111
-				$chardata[] = array('char' => $ta[$i], 'level' => $cel, 'type' => $chardir, 'sor' => $sor, 'eor' => $eor);
2112
-			}
2113
-		} // end for each char
2027
+        // X1. Begin by setting the current embedding level to the paragraph embedding level. Set the directional override status to neutral. Process each character iteratively, applying rules X2 through X9. Only embedding levels from 0 to 61 are valid in this phase.
2028
+        // In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached.
2029
+        for ($i=0; $i < $numchars; ++$i) {
2030
+            if ($ta[$i] == TCPDF_FONT_DATA::$uni_RLE) {
2031
+                // X2. With each RLE, compute the least greater odd embedding level.
2032
+                //	a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
2033
+                //	b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
2034
+                $next_level = $cel + ($cel % 2) + 1;
2035
+                if ($next_level < 62) {
2036
+                    $remember[] = array('num' => TCPDF_FONT_DATA::$uni_RLE, 'cel' => $cel, 'dos' => $dos);
2037
+                    $cel = $next_level;
2038
+                    $dos = 'N';
2039
+                    $sor = $eor;
2040
+                    $eor = $cel % 2 ? 'R' : 'L';
2041
+                }
2042
+            } elseif ($ta[$i] == TCPDF_FONT_DATA::$uni_LRE) {
2043
+                // X3. With each LRE, compute the least greater even embedding level.
2044
+                //	a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
2045
+                //	b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
2046
+                $next_level = $cel + 2 - ($cel % 2);
2047
+                if ( $next_level < 62 ) {
2048
+                    $remember[] = array('num' => TCPDF_FONT_DATA::$uni_LRE, 'cel' => $cel, 'dos' => $dos);
2049
+                    $cel = $next_level;
2050
+                    $dos = 'N';
2051
+                    $sor = $eor;
2052
+                    $eor = $cel % 2 ? 'R' : 'L';
2053
+                }
2054
+            } elseif ($ta[$i] == TCPDF_FONT_DATA::$uni_RLO) {
2055
+                // X4. With each RLO, compute the least greater odd embedding level.
2056
+                //	a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to right-to-left.
2057
+                //	b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
2058
+                $next_level = $cel + ($cel % 2) + 1;
2059
+                if ($next_level < 62) {
2060
+                    $remember[] = array('num' => TCPDF_FONT_DATA::$uni_RLO, 'cel' => $cel, 'dos' => $dos);
2061
+                    $cel = $next_level;
2062
+                    $dos = 'R';
2063
+                    $sor = $eor;
2064
+                    $eor = $cel % 2 ? 'R' : 'L';
2065
+                }
2066
+            } elseif ($ta[$i] == TCPDF_FONT_DATA::$uni_LRO) {
2067
+                // X5. With each LRO, compute the least greater even embedding level.
2068
+                //	a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to left-to-right.
2069
+                //	b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
2070
+                $next_level = $cel + 2 - ($cel % 2);
2071
+                if ( $next_level < 62 ) {
2072
+                    $remember[] = array('num' => TCPDF_FONT_DATA::$uni_LRO, 'cel' => $cel, 'dos' => $dos);
2073
+                    $cel = $next_level;
2074
+                    $dos = 'L';
2075
+                    $sor = $eor;
2076
+                    $eor = $cel % 2 ? 'R' : 'L';
2077
+                }
2078
+            } elseif ($ta[$i] == TCPDF_FONT_DATA::$uni_PDF) {
2079
+                // X7. With each PDF, determine the matching embedding or override code. If there was a valid matching code, restore (pop) the last remembered (pushed) embedding level and directional override.
2080
+                if (count($remember)) {
2081
+                    $last = count($remember ) - 1;
2082
+                    if (($remember[$last]['num'] == TCPDF_FONT_DATA::$uni_RLE) OR
2083
+                        ($remember[$last]['num'] == TCPDF_FONT_DATA::$uni_LRE) OR
2084
+                        ($remember[$last]['num'] == TCPDF_FONT_DATA::$uni_RLO) OR
2085
+                        ($remember[$last]['num'] == TCPDF_FONT_DATA::$uni_LRO)) {
2086
+                        $match = array_pop($remember);
2087
+                        $cel = $match['cel'];
2088
+                        $dos = $match['dos'];
2089
+                        $sor = $eor;
2090
+                        $eor = ($cel > $match['cel'] ? $cel : $match['cel']) % 2 ? 'R' : 'L';
2091
+                    }
2092
+                }
2093
+            } elseif (($ta[$i] != TCPDF_FONT_DATA::$uni_RLE) AND
2094
+                             ($ta[$i] != TCPDF_FONT_DATA::$uni_LRE) AND
2095
+                             ($ta[$i] != TCPDF_FONT_DATA::$uni_RLO) AND
2096
+                             ($ta[$i] != TCPDF_FONT_DATA::$uni_LRO) AND
2097
+                             ($ta[$i] != TCPDF_FONT_DATA::$uni_PDF)) {
2098
+                // X6. For all types besides RLE, LRE, RLO, LRO, and PDF:
2099
+                //	a. Set the level of the current character to the current embedding level.
2100
+                //	b. Whenever the directional override status is not neutral, reset the current character type to the directional override status.
2101
+                if ($dos != 'N') {
2102
+                    $chardir = $dos;
2103
+                } else {
2104
+                    if (isset(TCPDF_FONT_DATA::$uni_type[$ta[$i]])) {
2105
+                        $chardir = TCPDF_FONT_DATA::$uni_type[$ta[$i]];
2106
+                    } else {
2107
+                        $chardir = 'L';
2108
+                    }
2109
+                }
2110
+                // stores string characters and other information
2111
+                $chardata[] = array('char' => $ta[$i], 'level' => $cel, 'type' => $chardir, 'sor' => $sor, 'eor' => $eor);
2112
+            }
2113
+        } // end for each char
2114 2114
 
2115
-		// X8. All explicit directional embeddings and overrides are completely terminated at the end of each paragraph. Paragraph separators are not included in the embedding.
2116
-		// X9. Remove all RLE, LRE, RLO, LRO, PDF, and BN codes.
2117
-		// X10. The remaining rules are applied to each run of characters at the same level. For each run, determine the start-of-level-run (sor) and end-of-level-run (eor) type, either L or R. This depends on the higher of the two levels on either side of the boundary (at the start or end of the paragraph, the level of the 'other' run is the base embedding level). If the higher level is odd, the type is R; otherwise, it is L.
2115
+        // X8. All explicit directional embeddings and overrides are completely terminated at the end of each paragraph. Paragraph separators are not included in the embedding.
2116
+        // X9. Remove all RLE, LRE, RLO, LRO, PDF, and BN codes.
2117
+        // X10. The remaining rules are applied to each run of characters at the same level. For each run, determine the start-of-level-run (sor) and end-of-level-run (eor) type, either L or R. This depends on the higher of the two levels on either side of the boundary (at the start or end of the paragraph, the level of the 'other' run is the base embedding level). If the higher level is odd, the type is R; otherwise, it is L.
2118 2118
 
2119
-		// 3.3.3 Resolving Weak Types
2120
-		// Weak types are now resolved one level run at a time. At level run boundaries where the type of the character on the other side of the boundary is required, the type assigned to sor or eor is used.
2121
-		// Nonspacing marks are now resolved based on the previous characters.
2122
-		$numchars = count($chardata);
2119
+        // 3.3.3 Resolving Weak Types
2120
+        // Weak types are now resolved one level run at a time. At level run boundaries where the type of the character on the other side of the boundary is required, the type assigned to sor or eor is used.
2121
+        // Nonspacing marks are now resolved based on the previous characters.
2122
+        $numchars = count($chardata);
2123 2123
 
2124
-		// W1. Examine each nonspacing mark (NSM) in the level run, and change the type of the NSM to the type of the previous character. If the NSM is at the start of the level run, it will get the type of sor.
2125
-		$prevlevel = -1; // track level changes
2126
-		$levcount = 0; // counts consecutive chars at the same level
2127
-		for ($i=0; $i < $numchars; ++$i) {
2128
-			if ($chardata[$i]['type'] == 'NSM') {
2129
-				if ($levcount) {
2130
-					$chardata[$i]['type'] = $chardata[$i]['sor'];
2131
-				} elseif ($i > 0) {
2132
-					$chardata[$i]['type'] = $chardata[($i-1)]['type'];
2133
-				}
2134
-			}
2135
-			if ($chardata[$i]['level'] != $prevlevel) {
2136
-				$levcount = 0;
2137
-			} else {
2138
-				++$levcount;
2139
-			}
2140
-			$prevlevel = $chardata[$i]['level'];
2141
-		}
2124
+        // W1. Examine each nonspacing mark (NSM) in the level run, and change the type of the NSM to the type of the previous character. If the NSM is at the start of the level run, it will get the type of sor.
2125
+        $prevlevel = -1; // track level changes
2126
+        $levcount = 0; // counts consecutive chars at the same level
2127
+        for ($i=0; $i < $numchars; ++$i) {
2128
+            if ($chardata[$i]['type'] == 'NSM') {
2129
+                if ($levcount) {
2130
+                    $chardata[$i]['type'] = $chardata[$i]['sor'];
2131
+                } elseif ($i > 0) {
2132
+                    $chardata[$i]['type'] = $chardata[($i-1)]['type'];
2133
+                }
2134
+            }
2135
+            if ($chardata[$i]['level'] != $prevlevel) {
2136
+                $levcount = 0;
2137
+            } else {
2138
+                ++$levcount;
2139
+            }
2140
+            $prevlevel = $chardata[$i]['level'];
2141
+        }
2142 2142
 
2143
-		// W2. Search backward from each instance of a European number until the first strong type (R, L, AL, or sor) is found. If an AL is found, change the type of the European number to Arabic number.
2144
-		$prevlevel = -1;
2145
-		$levcount = 0;
2146
-		for ($i=0; $i < $numchars; ++$i) {
2147
-			if ($chardata[$i]['char'] == 'EN') {
2148
-				for ($j=$levcount; $j >= 0; $j--) {
2149
-					if ($chardata[$j]['type'] == 'AL') {
2150
-						$chardata[$i]['type'] = 'AN';
2151
-					} elseif (($chardata[$j]['type'] == 'L') OR ($chardata[$j]['type'] == 'R')) {
2152
-						break;
2153
-					}
2154
-				}
2155
-			}
2156
-			if ($chardata[$i]['level'] != $prevlevel) {
2157
-				$levcount = 0;
2158
-			} else {
2159
-				++$levcount;
2160
-			}
2161
-			$prevlevel = $chardata[$i]['level'];
2162
-		}
2143
+        // W2. Search backward from each instance of a European number until the first strong type (R, L, AL, or sor) is found. If an AL is found, change the type of the European number to Arabic number.
2144
+        $prevlevel = -1;
2145
+        $levcount = 0;
2146
+        for ($i=0; $i < $numchars; ++$i) {
2147
+            if ($chardata[$i]['char'] == 'EN') {
2148
+                for ($j=$levcount; $j >= 0; $j--) {
2149
+                    if ($chardata[$j]['type'] == 'AL') {
2150
+                        $chardata[$i]['type'] = 'AN';
2151
+                    } elseif (($chardata[$j]['type'] == 'L') OR ($chardata[$j]['type'] == 'R')) {
2152
+                        break;
2153
+                    }
2154
+                }
2155
+            }
2156
+            if ($chardata[$i]['level'] != $prevlevel) {
2157
+                $levcount = 0;
2158
+            } else {
2159
+                ++$levcount;
2160
+            }
2161
+            $prevlevel = $chardata[$i]['level'];
2162
+        }
2163 2163
 
2164
-		// W3. Change all ALs to R.
2165
-		for ($i=0; $i < $numchars; ++$i) {
2166
-			if ($chardata[$i]['type'] == 'AL') {
2167
-				$chardata[$i]['type'] = 'R';
2168
-			}
2169
-		}
2164
+        // W3. Change all ALs to R.
2165
+        for ($i=0; $i < $numchars; ++$i) {
2166
+            if ($chardata[$i]['type'] == 'AL') {
2167
+                $chardata[$i]['type'] = 'R';
2168
+            }
2169
+        }
2170 2170
 
2171
-		// W4. A single European separator between two European numbers changes to a European number. A single common separator between two numbers of the same type changes to that type.
2172
-		$prevlevel = -1;
2173
-		$levcount = 0;
2174
-		for ($i=0; $i < $numchars; ++$i) {
2175
-			if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
2176
-				if (($chardata[$i]['type'] == 'ES') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+1)]['type'] == 'EN')) {
2177
-					$chardata[$i]['type'] = 'EN';
2178
-				} elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+1)]['type'] == 'EN')) {
2179
-					$chardata[$i]['type'] = 'EN';
2180
-				} elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'AN') AND ($chardata[($i+1)]['type'] == 'AN')) {
2181
-					$chardata[$i]['type'] = 'AN';
2182
-				}
2183
-			}
2184
-			if ($chardata[$i]['level'] != $prevlevel) {
2185
-				$levcount = 0;
2186
-			} else {
2187
-				++$levcount;
2188
-			}
2189
-			$prevlevel = $chardata[$i]['level'];
2190
-		}
2171
+        // W4. A single European separator between two European numbers changes to a European number. A single common separator between two numbers of the same type changes to that type.
2172
+        $prevlevel = -1;
2173
+        $levcount = 0;
2174
+        for ($i=0; $i < $numchars; ++$i) {
2175
+            if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
2176
+                if (($chardata[$i]['type'] == 'ES') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+1)]['type'] == 'EN')) {
2177
+                    $chardata[$i]['type'] = 'EN';
2178
+                } elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+1)]['type'] == 'EN')) {
2179
+                    $chardata[$i]['type'] = 'EN';
2180
+                } elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'AN') AND ($chardata[($i+1)]['type'] == 'AN')) {
2181
+                    $chardata[$i]['type'] = 'AN';
2182
+                }
2183
+            }
2184
+            if ($chardata[$i]['level'] != $prevlevel) {
2185
+                $levcount = 0;
2186
+            } else {
2187
+                ++$levcount;
2188
+            }
2189
+            $prevlevel = $chardata[$i]['level'];
2190
+        }
2191 2191
 
2192
-		// W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
2193
-		$prevlevel = -1;
2194
-		$levcount = 0;
2195
-		for ($i=0; $i < $numchars; ++$i) {
2196
-			if ($chardata[$i]['type'] == 'ET') {
2197
-				if (($levcount > 0) AND ($chardata[($i-1)]['type'] == 'EN')) {
2198
-					$chardata[$i]['type'] = 'EN';
2199
-				} else {
2200
-					$j = $i+1;
2201
-					while (($j < $numchars) AND ($chardata[$j]['level'] == $prevlevel)) {
2202
-						if ($chardata[$j]['type'] == 'EN') {
2203
-							$chardata[$i]['type'] = 'EN';
2204
-							break;
2205
-						} elseif ($chardata[$j]['type'] != 'ET') {
2206
-							break;
2207
-						}
2208
-						++$j;
2209
-					}
2210
-				}
2211
-			}
2212
-			if ($chardata[$i]['level'] != $prevlevel) {
2213
-				$levcount = 0;
2214
-			} else {
2215
-				++$levcount;
2216
-			}
2217
-			$prevlevel = $chardata[$i]['level'];
2218
-		}
2192
+        // W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
2193
+        $prevlevel = -1;
2194
+        $levcount = 0;
2195
+        for ($i=0; $i < $numchars; ++$i) {
2196
+            if ($chardata[$i]['type'] == 'ET') {
2197
+                if (($levcount > 0) AND ($chardata[($i-1)]['type'] == 'EN')) {
2198
+                    $chardata[$i]['type'] = 'EN';
2199
+                } else {
2200
+                    $j = $i+1;
2201
+                    while (($j < $numchars) AND ($chardata[$j]['level'] == $prevlevel)) {
2202
+                        if ($chardata[$j]['type'] == 'EN') {
2203
+                            $chardata[$i]['type'] = 'EN';
2204
+                            break;
2205
+                        } elseif ($chardata[$j]['type'] != 'ET') {
2206
+                            break;
2207
+                        }
2208
+                        ++$j;
2209
+                    }
2210
+                }
2211
+            }
2212
+            if ($chardata[$i]['level'] != $prevlevel) {
2213
+                $levcount = 0;
2214
+            } else {
2215
+                ++$levcount;
2216
+            }
2217
+            $prevlevel = $chardata[$i]['level'];
2218
+        }
2219 2219
 
2220
-		// W6. Otherwise, separators and terminators change to Other Neutral.
2221
-		$prevlevel = -1;
2222
-		$levcount = 0;
2223
-		for ($i=0; $i < $numchars; ++$i) {
2224
-			if (($chardata[$i]['type'] == 'ET') OR ($chardata[$i]['type'] == 'ES') OR ($chardata[$i]['type'] == 'CS')) {
2225
-				$chardata[$i]['type'] = 'ON';
2226
-			}
2227
-			if ($chardata[$i]['level'] != $prevlevel) {
2228
-				$levcount = 0;
2229
-			} else {
2230
-				++$levcount;
2231
-			}
2232
-			$prevlevel = $chardata[$i]['level'];
2233
-		}
2220
+        // W6. Otherwise, separators and terminators change to Other Neutral.
2221
+        $prevlevel = -1;
2222
+        $levcount = 0;
2223
+        for ($i=0; $i < $numchars; ++$i) {
2224
+            if (($chardata[$i]['type'] == 'ET') OR ($chardata[$i]['type'] == 'ES') OR ($chardata[$i]['type'] == 'CS')) {
2225
+                $chardata[$i]['type'] = 'ON';
2226
+            }
2227
+            if ($chardata[$i]['level'] != $prevlevel) {
2228
+                $levcount = 0;
2229
+            } else {
2230
+                ++$levcount;
2231
+            }
2232
+            $prevlevel = $chardata[$i]['level'];
2233
+        }
2234 2234
 
2235
-		//W7. Search backward from each instance of a European number until the first strong type (R, L, or sor) is found. If an L is found, then change the type of the European number to L.
2236
-		$prevlevel = -1;
2237
-		$levcount = 0;
2238
-		for ($i=0; $i < $numchars; ++$i) {
2239
-			if ($chardata[$i]['char'] == 'EN') {
2240
-				for ($j=$levcount; $j >= 0; $j--) {
2241
-					if ($chardata[$j]['type'] == 'L') {
2242
-						$chardata[$i]['type'] = 'L';
2243
-					} elseif ($chardata[$j]['type'] == 'R') {
2244
-						break;
2245
-					}
2246
-				}
2247
-			}
2248
-			if ($chardata[$i]['level'] != $prevlevel) {
2249
-				$levcount = 0;
2250
-			} else {
2251
-				++$levcount;
2252
-			}
2253
-			$prevlevel = $chardata[$i]['level'];
2254
-		}
2235
+        //W7. Search backward from each instance of a European number until the first strong type (R, L, or sor) is found. If an L is found, then change the type of the European number to L.
2236
+        $prevlevel = -1;
2237
+        $levcount = 0;
2238
+        for ($i=0; $i < $numchars; ++$i) {
2239
+            if ($chardata[$i]['char'] == 'EN') {
2240
+                for ($j=$levcount; $j >= 0; $j--) {
2241
+                    if ($chardata[$j]['type'] == 'L') {
2242
+                        $chardata[$i]['type'] = 'L';
2243
+                    } elseif ($chardata[$j]['type'] == 'R') {
2244
+                        break;
2245
+                    }
2246
+                }
2247
+            }
2248
+            if ($chardata[$i]['level'] != $prevlevel) {
2249
+                $levcount = 0;
2250
+            } else {
2251
+                ++$levcount;
2252
+            }
2253
+            $prevlevel = $chardata[$i]['level'];
2254
+        }
2255 2255
 
2256
-		// N1. A sequence of neutrals takes the direction of the surrounding strong text if the text on both sides has the same direction. European and Arabic numbers act as if they were R in terms of their influence on neutrals. Start-of-level-run (sor) and end-of-level-run (eor) are used at level run boundaries.
2257
-		$prevlevel = -1;
2258
-		$levcount = 0;
2259
-		for ($i=0; $i < $numchars; ++$i) {
2260
-			if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
2261
-				if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[($i+1)]['type'] == 'L')) {
2262
-					$chardata[$i]['type'] = 'L';
2263
-				} elseif (($chardata[$i]['type'] == 'N') AND
2264
-				 (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
2265
-				 (($chardata[($i+1)]['type'] == 'R') OR ($chardata[($i+1)]['type'] == 'EN') OR ($chardata[($i+1)]['type'] == 'AN'))) {
2266
-					$chardata[$i]['type'] = 'R';
2267
-				} elseif ($chardata[$i]['type'] == 'N') {
2268
-					// N2. Any remaining neutrals take the embedding direction
2269
-					$chardata[$i]['type'] = $chardata[$i]['sor'];
2270
-				}
2271
-			} elseif (($levcount == 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
2272
-				// first char
2273
-				if (($chardata[$i]['type'] == 'N') AND ($chardata[$i]['sor'] == 'L') AND ($chardata[($i+1)]['type'] == 'L')) {
2274
-					$chardata[$i]['type'] = 'L';
2275
-				} elseif (($chardata[$i]['type'] == 'N') AND
2276
-				 (($chardata[$i]['sor'] == 'R') OR ($chardata[$i]['sor'] == 'EN') OR ($chardata[$i]['sor'] == 'AN')) AND
2277
-				 (($chardata[($i+1)]['type'] == 'R') OR ($chardata[($i+1)]['type'] == 'EN') OR ($chardata[($i+1)]['type'] == 'AN'))) {
2278
-					$chardata[$i]['type'] = 'R';
2279
-				} elseif ($chardata[$i]['type'] == 'N') {
2280
-					// N2. Any remaining neutrals take the embedding direction
2281
-					$chardata[$i]['type'] = $chardata[$i]['sor'];
2282
-				}
2283
-			} elseif (($levcount > 0) AND ((($i+1) == $numchars) OR (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] != $prevlevel))) {
2284
-				//last char
2285
-				if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[$i]['eor'] == 'L')) {
2286
-					$chardata[$i]['type'] = 'L';
2287
-				} elseif (($chardata[$i]['type'] == 'N') AND
2288
-				 (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
2289
-				 (($chardata[$i]['eor'] == 'R') OR ($chardata[$i]['eor'] == 'EN') OR ($chardata[$i]['eor'] == 'AN'))) {
2290
-					$chardata[$i]['type'] = 'R';
2291
-				} elseif ($chardata[$i]['type'] == 'N') {
2292
-					// N2. Any remaining neutrals take the embedding direction
2293
-					$chardata[$i]['type'] = $chardata[$i]['sor'];
2294
-				}
2295
-			} elseif ($chardata[$i]['type'] == 'N') {
2296
-				// N2. Any remaining neutrals take the embedding direction
2297
-				$chardata[$i]['type'] = $chardata[$i]['sor'];
2298
-			}
2299
-			if ($chardata[$i]['level'] != $prevlevel) {
2300
-				$levcount = 0;
2301
-			} else {
2302
-				++$levcount;
2303
-			}
2304
-			$prevlevel = $chardata[$i]['level'];
2305
-		}
2256
+        // N1. A sequence of neutrals takes the direction of the surrounding strong text if the text on both sides has the same direction. European and Arabic numbers act as if they were R in terms of their influence on neutrals. Start-of-level-run (sor) and end-of-level-run (eor) are used at level run boundaries.
2257
+        $prevlevel = -1;
2258
+        $levcount = 0;
2259
+        for ($i=0; $i < $numchars; ++$i) {
2260
+            if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
2261
+                if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[($i+1)]['type'] == 'L')) {
2262
+                    $chardata[$i]['type'] = 'L';
2263
+                } elseif (($chardata[$i]['type'] == 'N') AND
2264
+                 (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
2265
+                 (($chardata[($i+1)]['type'] == 'R') OR ($chardata[($i+1)]['type'] == 'EN') OR ($chardata[($i+1)]['type'] == 'AN'))) {
2266
+                    $chardata[$i]['type'] = 'R';
2267
+                } elseif ($chardata[$i]['type'] == 'N') {
2268
+                    // N2. Any remaining neutrals take the embedding direction
2269
+                    $chardata[$i]['type'] = $chardata[$i]['sor'];
2270
+                }
2271
+            } elseif (($levcount == 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
2272
+                // first char
2273
+                if (($chardata[$i]['type'] == 'N') AND ($chardata[$i]['sor'] == 'L') AND ($chardata[($i+1)]['type'] == 'L')) {
2274
+                    $chardata[$i]['type'] = 'L';
2275
+                } elseif (($chardata[$i]['type'] == 'N') AND
2276
+                 (($chardata[$i]['sor'] == 'R') OR ($chardata[$i]['sor'] == 'EN') OR ($chardata[$i]['sor'] == 'AN')) AND
2277
+                 (($chardata[($i+1)]['type'] == 'R') OR ($chardata[($i+1)]['type'] == 'EN') OR ($chardata[($i+1)]['type'] == 'AN'))) {
2278
+                    $chardata[$i]['type'] = 'R';
2279
+                } elseif ($chardata[$i]['type'] == 'N') {
2280
+                    // N2. Any remaining neutrals take the embedding direction
2281
+                    $chardata[$i]['type'] = $chardata[$i]['sor'];
2282
+                }
2283
+            } elseif (($levcount > 0) AND ((($i+1) == $numchars) OR (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] != $prevlevel))) {
2284
+                //last char
2285
+                if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[$i]['eor'] == 'L')) {
2286
+                    $chardata[$i]['type'] = 'L';
2287
+                } elseif (($chardata[$i]['type'] == 'N') AND
2288
+                 (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
2289
+                 (($chardata[$i]['eor'] == 'R') OR ($chardata[$i]['eor'] == 'EN') OR ($chardata[$i]['eor'] == 'AN'))) {
2290
+                    $chardata[$i]['type'] = 'R';
2291
+                } elseif ($chardata[$i]['type'] == 'N') {
2292
+                    // N2. Any remaining neutrals take the embedding direction
2293
+                    $chardata[$i]['type'] = $chardata[$i]['sor'];
2294
+                }
2295
+            } elseif ($chardata[$i]['type'] == 'N') {
2296
+                // N2. Any remaining neutrals take the embedding direction
2297
+                $chardata[$i]['type'] = $chardata[$i]['sor'];
2298
+            }
2299
+            if ($chardata[$i]['level'] != $prevlevel) {
2300
+                $levcount = 0;
2301
+            } else {
2302
+                ++$levcount;
2303
+            }
2304
+            $prevlevel = $chardata[$i]['level'];
2305
+        }
2306 2306
 
2307
-		// I1. For all characters with an even (left-to-right) embedding direction, those of type R go up one level and those of type AN or EN go up two levels.
2308
-		// I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level.
2309
-		for ($i=0; $i < $numchars; ++$i) {
2310
-			$odd = $chardata[$i]['level'] % 2;
2311
-			if ($odd) {
2312
-				if (($chardata[$i]['type'] == 'L') OR ($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
2313
-					$chardata[$i]['level'] += 1;
2314
-				}
2315
-			} else {
2316
-				if ($chardata[$i]['type'] == 'R') {
2317
-					$chardata[$i]['level'] += 1;
2318
-				} elseif (($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
2319
-					$chardata[$i]['level'] += 2;
2320
-				}
2321
-			}
2322
-			$maxlevel = max($chardata[$i]['level'],$maxlevel);
2323
-		}
2307
+        // I1. For all characters with an even (left-to-right) embedding direction, those of type R go up one level and those of type AN or EN go up two levels.
2308
+        // I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level.
2309
+        for ($i=0; $i < $numchars; ++$i) {
2310
+            $odd = $chardata[$i]['level'] % 2;
2311
+            if ($odd) {
2312
+                if (($chardata[$i]['type'] == 'L') OR ($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
2313
+                    $chardata[$i]['level'] += 1;
2314
+                }
2315
+            } else {
2316
+                if ($chardata[$i]['type'] == 'R') {
2317
+                    $chardata[$i]['level'] += 1;
2318
+                } elseif (($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
2319
+                    $chardata[$i]['level'] += 2;
2320
+                }
2321
+            }
2322
+            $maxlevel = max($chardata[$i]['level'],$maxlevel);
2323
+        }
2324 2324
 
2325
-		// L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
2326
-		//	1. Segment separators,
2327
-		//	2. Paragraph separators,
2328
-		//	3. Any sequence of whitespace characters preceding a segment separator or paragraph separator, and
2329
-		//	4. Any sequence of white space characters at the end of the line.
2330
-		for ($i=0; $i < $numchars; ++$i) {
2331
-			if (($chardata[$i]['type'] == 'B') OR ($chardata[$i]['type'] == 'S')) {
2332
-				$chardata[$i]['level'] = $pel;
2333
-			} elseif ($chardata[$i]['type'] == 'WS') {
2334
-				$j = $i+1;
2335
-				while ($j < $numchars) {
2336
-					if ((($chardata[$j]['type'] == 'B') OR ($chardata[$j]['type'] == 'S')) OR
2337
-						(($j == ($numchars-1)) AND ($chardata[$j]['type'] == 'WS'))) {
2338
-						$chardata[$i]['level'] = $pel;
2339
-						break;
2340
-					} elseif ($chardata[$j]['type'] != 'WS') {
2341
-						break;
2342
-					}
2343
-					++$j;
2344
-				}
2345
-			}
2346
-		}
2325
+        // L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
2326
+        //	1. Segment separators,
2327
+        //	2. Paragraph separators,
2328
+        //	3. Any sequence of whitespace characters preceding a segment separator or paragraph separator, and
2329
+        //	4. Any sequence of white space characters at the end of the line.
2330
+        for ($i=0; $i < $numchars; ++$i) {
2331
+            if (($chardata[$i]['type'] == 'B') OR ($chardata[$i]['type'] == 'S')) {
2332
+                $chardata[$i]['level'] = $pel;
2333
+            } elseif ($chardata[$i]['type'] == 'WS') {
2334
+                $j = $i+1;
2335
+                while ($j < $numchars) {
2336
+                    if ((($chardata[$j]['type'] == 'B') OR ($chardata[$j]['type'] == 'S')) OR
2337
+                        (($j == ($numchars-1)) AND ($chardata[$j]['type'] == 'WS'))) {
2338
+                        $chardata[$i]['level'] = $pel;
2339
+                        break;
2340
+                    } elseif ($chardata[$j]['type'] != 'WS') {
2341
+                        break;
2342
+                    }
2343
+                    ++$j;
2344
+                }
2345
+            }
2346
+        }
2347 2347
 
2348
-		// Arabic Shaping
2349
-		// Cursively connected scripts, such as Arabic or Syriac, require the selection of positional character shapes that depend on adjacent characters. Shaping is logically applied after the Bidirectional Algorithm is used and is limited to characters within the same directional run.
2350
-		if ($arabic) {
2351
-			$endedletter = array(1569,1570,1571,1572,1573,1575,1577,1583,1584,1585,1586,1608,1688);
2352
-			$alfletter = array(1570,1571,1573,1575);
2353
-			$chardata2 = $chardata;
2354
-			$laaletter = false;
2355
-			$charAL = array();
2356
-			$x = 0;
2357
-			for ($i=0; $i < $numchars; ++$i) {
2358
-				if ((TCPDF_FONT_DATA::$uni_type[$chardata[$i]['char']] == 'AL') OR ($chardata[$i]['char'] == 32) OR ($chardata[$i]['char'] == 8204)) {
2359
-					$charAL[$x] = $chardata[$i];
2360
-					$charAL[$x]['i'] = $i;
2361
-					$chardata[$i]['x'] = $x;
2362
-					++$x;
2363
-				}
2364
-			}
2365
-			$numAL = $x;
2366
-			for ($i=0; $i < $numchars; ++$i) {
2367
-				$thischar = $chardata[$i];
2368
-				if ($i > 0) {
2369
-					$prevchar = $chardata[($i-1)];
2370
-				} else {
2371
-					$prevchar = false;
2372
-				}
2373
-				if (($i+1) < $numchars) {
2374
-					$nextchar = $chardata[($i+1)];
2375
-				} else {
2376
-					$nextchar = false;
2377
-				}
2378
-				if (TCPDF_FONT_DATA::$uni_type[$thischar['char']] == 'AL') {
2379
-					$x = $thischar['x'];
2380
-					if ($x > 0) {
2381
-						$prevchar = $charAL[($x-1)];
2382
-					} else {
2383
-						$prevchar = false;
2384
-					}
2385
-					if (($x+1) < $numAL) {
2386
-						$nextchar = $charAL[($x+1)];
2387
-					} else {
2388
-						$nextchar = false;
2389
-					}
2390
-					// if laa letter
2391
-					if (($prevchar !== false) AND ($prevchar['char'] == 1604) AND (in_array($thischar['char'], $alfletter))) {
2392
-						$arabicarr = TCPDF_FONT_DATA::$uni_laa_array;
2393
-						$laaletter = true;
2394
-						if ($x > 1) {
2395
-							$prevchar = $charAL[($x-2)];
2396
-						} else {
2397
-							$prevchar = false;
2398
-						}
2399
-					} else {
2400
-						$arabicarr = TCPDF_FONT_DATA::$uni_arabicsubst;
2401
-						$laaletter = false;
2402
-					}
2403
-					if (($prevchar !== false) AND ($nextchar !== false) AND
2404
-						((TCPDF_FONT_DATA::$uni_type[$prevchar['char']] == 'AL') OR (TCPDF_FONT_DATA::$uni_type[$prevchar['char']] == 'NSM')) AND
2405
-						((TCPDF_FONT_DATA::$uni_type[$nextchar['char']] == 'AL') OR (TCPDF_FONT_DATA::$uni_type[$nextchar['char']] == 'NSM')) AND
2406
-						($prevchar['type'] == $thischar['type']) AND
2407
-						($nextchar['type'] == $thischar['type']) AND
2408
-						($nextchar['char'] != 1567)) {
2409
-						if (in_array($prevchar['char'], $endedletter)) {
2410
-							if (isset($arabicarr[$thischar['char']][2])) {
2411
-								// initial
2412
-								$chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
2413
-							}
2414
-						} else {
2415
-							if (isset($arabicarr[$thischar['char']][3])) {
2416
-								// medial
2417
-								$chardata2[$i]['char'] = $arabicarr[$thischar['char']][3];
2418
-							}
2419
-						}
2420
-					} elseif (($nextchar !== false) AND
2421
-						((TCPDF_FONT_DATA::$uni_type[$nextchar['char']] == 'AL') OR (TCPDF_FONT_DATA::$uni_type[$nextchar['char']] == 'NSM')) AND
2422
-						($nextchar['type'] == $thischar['type']) AND
2423
-						($nextchar['char'] != 1567)) {
2424
-						if (isset($arabicarr[$chardata[$i]['char']][2])) {
2425
-							// initial
2426
-							$chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
2427
-						}
2428
-					} elseif ((($prevchar !== false) AND
2429
-						((TCPDF_FONT_DATA::$uni_type[$prevchar['char']] == 'AL') OR (TCPDF_FONT_DATA::$uni_type[$prevchar['char']] == 'NSM')) AND
2430
-						($prevchar['type'] == $thischar['type'])) OR
2431
-						(($nextchar !== false) AND ($nextchar['char'] == 1567))) {
2432
-						// final
2433
-						if (($i > 1) AND ($thischar['char'] == 1607) AND
2434
-							($chardata[$i-1]['char'] == 1604) AND
2435
-							($chardata[$i-2]['char'] == 1604)) {
2436
-							//Allah Word
2437
-							// mark characters to delete with false
2438
-							$chardata2[$i-2]['char'] = false;
2439
-							$chardata2[$i-1]['char'] = false;
2440
-							$chardata2[$i]['char'] = 65010;
2441
-						} else {
2442
-							if (($prevchar !== false) AND in_array($prevchar['char'], $endedletter)) {
2443
-								if (isset($arabicarr[$thischar['char']][0])) {
2444
-									// isolated
2445
-									$chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
2446
-								}
2447
-							} else {
2448
-								if (isset($arabicarr[$thischar['char']][1])) {
2449
-									// final
2450
-									$chardata2[$i]['char'] = $arabicarr[$thischar['char']][1];
2451
-								}
2452
-							}
2453
-						}
2454
-					} elseif (isset($arabicarr[$thischar['char']][0])) {
2455
-						// isolated
2456
-						$chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
2457
-					}
2458
-					// if laa letter
2459
-					if ($laaletter) {
2460
-						// mark characters to delete with false
2461
-						$chardata2[($charAL[($x-1)]['i'])]['char'] = false;
2462
-					}
2463
-				} // end if AL (Arabic Letter)
2464
-			} // end for each char
2465
-			/*
2348
+        // Arabic Shaping
2349
+        // Cursively connected scripts, such as Arabic or Syriac, require the selection of positional character shapes that depend on adjacent characters. Shaping is logically applied after the Bidirectional Algorithm is used and is limited to characters within the same directional run.
2350
+        if ($arabic) {
2351
+            $endedletter = array(1569,1570,1571,1572,1573,1575,1577,1583,1584,1585,1586,1608,1688);
2352
+            $alfletter = array(1570,1571,1573,1575);
2353
+            $chardata2 = $chardata;
2354
+            $laaletter = false;
2355
+            $charAL = array();
2356
+            $x = 0;
2357
+            for ($i=0; $i < $numchars; ++$i) {
2358
+                if ((TCPDF_FONT_DATA::$uni_type[$chardata[$i]['char']] == 'AL') OR ($chardata[$i]['char'] == 32) OR ($chardata[$i]['char'] == 8204)) {
2359
+                    $charAL[$x] = $chardata[$i];
2360
+                    $charAL[$x]['i'] = $i;
2361
+                    $chardata[$i]['x'] = $x;
2362
+                    ++$x;
2363
+                }
2364
+            }
2365
+            $numAL = $x;
2366
+            for ($i=0; $i < $numchars; ++$i) {
2367
+                $thischar = $chardata[$i];
2368
+                if ($i > 0) {
2369
+                    $prevchar = $chardata[($i-1)];
2370
+                } else {
2371
+                    $prevchar = false;
2372
+                }
2373
+                if (($i+1) < $numchars) {
2374
+                    $nextchar = $chardata[($i+1)];
2375
+                } else {
2376
+                    $nextchar = false;
2377
+                }
2378
+                if (TCPDF_FONT_DATA::$uni_type[$thischar['char']] == 'AL') {
2379
+                    $x = $thischar['x'];
2380
+                    if ($x > 0) {
2381
+                        $prevchar = $charAL[($x-1)];
2382
+                    } else {
2383
+                        $prevchar = false;
2384
+                    }
2385
+                    if (($x+1) < $numAL) {
2386
+                        $nextchar = $charAL[($x+1)];
2387
+                    } else {
2388
+                        $nextchar = false;
2389
+                    }
2390
+                    // if laa letter
2391
+                    if (($prevchar !== false) AND ($prevchar['char'] == 1604) AND (in_array($thischar['char'], $alfletter))) {
2392
+                        $arabicarr = TCPDF_FONT_DATA::$uni_laa_array;
2393
+                        $laaletter = true;
2394
+                        if ($x > 1) {
2395
+                            $prevchar = $charAL[($x-2)];
2396
+                        } else {
2397
+                            $prevchar = false;
2398
+                        }
2399
+                    } else {
2400
+                        $arabicarr = TCPDF_FONT_DATA::$uni_arabicsubst;
2401
+                        $laaletter = false;
2402
+                    }
2403
+                    if (($prevchar !== false) AND ($nextchar !== false) AND
2404
+                        ((TCPDF_FONT_DATA::$uni_type[$prevchar['char']] == 'AL') OR (TCPDF_FONT_DATA::$uni_type[$prevchar['char']] == 'NSM')) AND
2405
+                        ((TCPDF_FONT_DATA::$uni_type[$nextchar['char']] == 'AL') OR (TCPDF_FONT_DATA::$uni_type[$nextchar['char']] == 'NSM')) AND
2406
+                        ($prevchar['type'] == $thischar['type']) AND
2407
+                        ($nextchar['type'] == $thischar['type']) AND
2408
+                        ($nextchar['char'] != 1567)) {
2409
+                        if (in_array($prevchar['char'], $endedletter)) {
2410
+                            if (isset($arabicarr[$thischar['char']][2])) {
2411
+                                // initial
2412
+                                $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
2413
+                            }
2414
+                        } else {
2415
+                            if (isset($arabicarr[$thischar['char']][3])) {
2416
+                                // medial
2417
+                                $chardata2[$i]['char'] = $arabicarr[$thischar['char']][3];
2418
+                            }
2419
+                        }
2420
+                    } elseif (($nextchar !== false) AND
2421
+                        ((TCPDF_FONT_DATA::$uni_type[$nextchar['char']] == 'AL') OR (TCPDF_FONT_DATA::$uni_type[$nextchar['char']] == 'NSM')) AND
2422
+                        ($nextchar['type'] == $thischar['type']) AND
2423
+                        ($nextchar['char'] != 1567)) {
2424
+                        if (isset($arabicarr[$chardata[$i]['char']][2])) {
2425
+                            // initial
2426
+                            $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
2427
+                        }
2428
+                    } elseif ((($prevchar !== false) AND
2429
+                        ((TCPDF_FONT_DATA::$uni_type[$prevchar['char']] == 'AL') OR (TCPDF_FONT_DATA::$uni_type[$prevchar['char']] == 'NSM')) AND
2430
+                        ($prevchar['type'] == $thischar['type'])) OR
2431
+                        (($nextchar !== false) AND ($nextchar['char'] == 1567))) {
2432
+                        // final
2433
+                        if (($i > 1) AND ($thischar['char'] == 1607) AND
2434
+                            ($chardata[$i-1]['char'] == 1604) AND
2435
+                            ($chardata[$i-2]['char'] == 1604)) {
2436
+                            //Allah Word
2437
+                            // mark characters to delete with false
2438
+                            $chardata2[$i-2]['char'] = false;
2439
+                            $chardata2[$i-1]['char'] = false;
2440
+                            $chardata2[$i]['char'] = 65010;
2441
+                        } else {
2442
+                            if (($prevchar !== false) AND in_array($prevchar['char'], $endedletter)) {
2443
+                                if (isset($arabicarr[$thischar['char']][0])) {
2444
+                                    // isolated
2445
+                                    $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
2446
+                                }
2447
+                            } else {
2448
+                                if (isset($arabicarr[$thischar['char']][1])) {
2449
+                                    // final
2450
+                                    $chardata2[$i]['char'] = $arabicarr[$thischar['char']][1];
2451
+                                }
2452
+                            }
2453
+                        }
2454
+                    } elseif (isset($arabicarr[$thischar['char']][0])) {
2455
+                        // isolated
2456
+                        $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
2457
+                    }
2458
+                    // if laa letter
2459
+                    if ($laaletter) {
2460
+                        // mark characters to delete with false
2461
+                        $chardata2[($charAL[($x-1)]['i'])]['char'] = false;
2462
+                    }
2463
+                } // end if AL (Arabic Letter)
2464
+            } // end for each char
2465
+            /*
2466 2466
 			 * Combining characters that can occur with Arabic Shadda (0651 HEX, 1617 DEC) are replaced.
2467 2467
 			 * Putting the combining mark and shadda in the same glyph allows us to avoid the two marks overlapping each other in an illegible manner.
2468 2468
 			 */
2469
-			for ($i = 0; $i < ($numchars-1); ++$i) {
2470
-				if (($chardata2[$i]['char'] == 1617) AND (isset(TCPDF_FONT_DATA::$uni_diacritics[($chardata2[$i+1]['char'])]))) {
2471
-					// check if the subtitution font is defined on current font
2472
-					if (isset($currentfont['cw'][(TCPDF_FONT_DATA::$uni_diacritics[($chardata2[$i+1]['char'])])])) {
2473
-						$chardata2[$i]['char'] = false;
2474
-						$chardata2[$i+1]['char'] = TCPDF_FONT_DATA::$uni_diacritics[($chardata2[$i+1]['char'])];
2475
-					}
2476
-				}
2477
-			}
2478
-			// remove marked characters
2479
-			foreach ($chardata2 as $key => $value) {
2480
-				if ($value['char'] === false) {
2481
-					unset($chardata2[$key]);
2482
-				}
2483
-			}
2484
-			$chardata = array_values($chardata2);
2485
-			$numchars = count($chardata);
2486
-			unset($chardata2);
2487
-			unset($arabicarr);
2488
-			unset($laaletter);
2489
-			unset($charAL);
2490
-		}
2469
+            for ($i = 0; $i < ($numchars-1); ++$i) {
2470
+                if (($chardata2[$i]['char'] == 1617) AND (isset(TCPDF_FONT_DATA::$uni_diacritics[($chardata2[$i+1]['char'])]))) {
2471
+                    // check if the subtitution font is defined on current font
2472
+                    if (isset($currentfont['cw'][(TCPDF_FONT_DATA::$uni_diacritics[($chardata2[$i+1]['char'])])])) {
2473
+                        $chardata2[$i]['char'] = false;
2474
+                        $chardata2[$i+1]['char'] = TCPDF_FONT_DATA::$uni_diacritics[($chardata2[$i+1]['char'])];
2475
+                    }
2476
+                }
2477
+            }
2478
+            // remove marked characters
2479
+            foreach ($chardata2 as $key => $value) {
2480
+                if ($value['char'] === false) {
2481
+                    unset($chardata2[$key]);
2482
+                }
2483
+            }
2484
+            $chardata = array_values($chardata2);
2485
+            $numchars = count($chardata);
2486
+            unset($chardata2);
2487
+            unset($arabicarr);
2488
+            unset($laaletter);
2489
+            unset($charAL);
2490
+        }
2491 2491
 
2492
-		// L2. From the highest level found in the text to the lowest odd level on each line, including intermediate levels not actually present in the text, reverse any contiguous sequence of characters that are at that level or higher.
2493
-		for ($j=$maxlevel; $j > 0; $j--) {
2494
-			$ordarray = Array();
2495
-			$revarr = Array();
2496
-			$onlevel = false;
2497
-			for ($i=0; $i < $numchars; ++$i) {
2498
-				if ($chardata[$i]['level'] >= $j) {
2499
-					$onlevel = true;
2500
-					if (isset(TCPDF_FONT_DATA::$uni_mirror[$chardata[$i]['char']])) {
2501
-						// L4. A character is depicted by a mirrored glyph if and only if (a) the resolved directionality of that character is R, and (b) the Bidi_Mirrored property value of that character is true.
2502
-						$chardata[$i]['char'] = TCPDF_FONT_DATA::$uni_mirror[$chardata[$i]['char']];
2503
-					}
2504
-					$revarr[] = $chardata[$i];
2505
-				} else {
2506
-					if ($onlevel) {
2507
-						$revarr = array_reverse($revarr);
2508
-						$ordarray = array_merge($ordarray, $revarr);
2509
-						$revarr = Array();
2510
-						$onlevel = false;
2511
-					}
2512
-					$ordarray[] = $chardata[$i];
2513
-				}
2514
-			}
2515
-			if ($onlevel) {
2516
-				$revarr = array_reverse($revarr);
2517
-				$ordarray = array_merge($ordarray, $revarr);
2518
-			}
2519
-			$chardata = $ordarray;
2520
-		}
2521
-		$ordarray = array();
2522
-		foreach ($chardata as $cd) {
2523
-			$ordarray[] = $cd['char'];
2524
-			// store char values for subsetting
2525
-			$currentfont['subsetchars'][$cd['char']] = true;
2526
-		}
2527
-		return $ordarray;
2528
-	}
2492
+        // L2. From the highest level found in the text to the lowest odd level on each line, including intermediate levels not actually present in the text, reverse any contiguous sequence of characters that are at that level or higher.
2493
+        for ($j=$maxlevel; $j > 0; $j--) {
2494
+            $ordarray = Array();
2495
+            $revarr = Array();
2496
+            $onlevel = false;
2497
+            for ($i=0; $i < $numchars; ++$i) {
2498
+                if ($chardata[$i]['level'] >= $j) {
2499
+                    $onlevel = true;
2500
+                    if (isset(TCPDF_FONT_DATA::$uni_mirror[$chardata[$i]['char']])) {
2501
+                        // L4. A character is depicted by a mirrored glyph if and only if (a) the resolved directionality of that character is R, and (b) the Bidi_Mirrored property value of that character is true.
2502
+                        $chardata[$i]['char'] = TCPDF_FONT_DATA::$uni_mirror[$chardata[$i]['char']];
2503
+                    }
2504
+                    $revarr[] = $chardata[$i];
2505
+                } else {
2506
+                    if ($onlevel) {
2507
+                        $revarr = array_reverse($revarr);
2508
+                        $ordarray = array_merge($ordarray, $revarr);
2509
+                        $revarr = Array();
2510
+                        $onlevel = false;
2511
+                    }
2512
+                    $ordarray[] = $chardata[$i];
2513
+                }
2514
+            }
2515
+            if ($onlevel) {
2516
+                $revarr = array_reverse($revarr);
2517
+                $ordarray = array_merge($ordarray, $revarr);
2518
+            }
2519
+            $chardata = $ordarray;
2520
+        }
2521
+        $ordarray = array();
2522
+        foreach ($chardata as $cd) {
2523
+            $ordarray[] = $cd['char'];
2524
+            // store char values for subsetting
2525
+            $currentfont['subsetchars'][$cd['char']] = true;
2526
+        }
2527
+        return $ordarray;
2528
+    }
2529 2529
 
2530
-	/**
2531
-	 * Get a reference font size.
2532
-	 * @param $size (string) String containing font size value.
2533
-	 * @param $refsize (float) Reference font size in points.
2534
-	 * @return float value in points
2535
-	 * @public static
2536
-	 */
2537
-	public static function getFontRefSize($size, $refsize=12) {
2538
-		switch ($size) {
2539
-			case 'xx-small': {
2540
-				$size = ($refsize - 4);
2541
-				break;
2542
-			}
2543
-			case 'x-small': {
2544
-				$size = ($refsize - 3);
2545
-				break;
2546
-			}
2547
-			case 'small': {
2548
-				$size = ($refsize - 2);
2549
-				break;
2550
-			}
2551
-			case 'medium': {
2552
-				$size = $refsize;
2553
-				break;
2554
-			}
2555
-			case 'large': {
2556
-				$size = ($refsize + 2);
2557
-				break;
2558
-			}
2559
-			case 'x-large': {
2560
-				$size = ($refsize + 4);
2561
-				break;
2562
-			}
2563
-			case 'xx-large': {
2564
-				$size = ($refsize + 6);
2565
-				break;
2566
-			}
2567
-			case 'smaller': {
2568
-				$size = ($refsize - 3);
2569
-				break;
2570
-			}
2571
-			case 'larger': {
2572
-				$size = ($refsize + 3);
2573
-				break;
2574
-			}
2575
-		}
2576
-		return $size;
2577
-	}
2530
+    /**
2531
+     * Get a reference font size.
2532
+     * @param $size (string) String containing font size value.
2533
+     * @param $refsize (float) Reference font size in points.
2534
+     * @return float value in points
2535
+     * @public static
2536
+     */
2537
+    public static function getFontRefSize($size, $refsize=12) {
2538
+        switch ($size) {
2539
+            case 'xx-small': {
2540
+                $size = ($refsize - 4);
2541
+                break;
2542
+            }
2543
+            case 'x-small': {
2544
+                $size = ($refsize - 3);
2545
+                break;
2546
+            }
2547
+            case 'small': {
2548
+                $size = ($refsize - 2);
2549
+                break;
2550
+            }
2551
+            case 'medium': {
2552
+                $size = $refsize;
2553
+                break;
2554
+            }
2555
+            case 'large': {
2556
+                $size = ($refsize + 2);
2557
+                break;
2558
+            }
2559
+            case 'x-large': {
2560
+                $size = ($refsize + 4);
2561
+                break;
2562
+            }
2563
+            case 'xx-large': {
2564
+                $size = ($refsize + 6);
2565
+                break;
2566
+            }
2567
+            case 'smaller': {
2568
+                $size = ($refsize - 3);
2569
+                break;
2570
+            }
2571
+            case 'larger': {
2572
+                $size = ($refsize + 3);
2573
+                break;
2574
+            }
2575
+        }
2576
+        return $size;
2577
+    }
2578 2578
 
2579 2579
 } // END OF TCPDF_FONTS CLASS
2580 2580
 
Please login to merge, or discard this patch.
Spacing   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * @since 5.9.123 (2010-09-30)
70 70
 	 * @public static
71 71
 	 */
72
-	public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1, $addcbbox=false, $link=false) {
72
+	public static function addTTFfont($fontfile, $fonttype = '', $enc = '', $flags = 32, $outpath = '', $platid = 3, $encid = 1, $addcbbox = false, $link = false) {
73 73
 		if (!file_exists($fontfile)) {
74 74
 			// Could not find file
75 75
 			return false;
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 			fclose($fp);
192 192
 			// get font info
193 193
 			$fmetric['Flags'] = $flags;
194
-			preg_match ('#/FullName[\s]*\(([^\)]*)#', $font, $matches);
194
+			preg_match('#/FullName[\s]*\(([^\)]*)#', $font, $matches);
195 195
 			$fmetric['name'] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $matches[1]);
196 196
 			preg_match('#/FontBBox[\s]*{([^}]*)#', $font, $matches);
197 197
 			$fmetric['bbox'] = trim($matches[1]);
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 			for ($i = 0; $i < $elen; ++$i) {
228 228
 				$chr = ord($encrypted[$i]);
229 229
 				$eplain .= chr($chr ^ ($r >> 8));
230
-				$r = ((($chr + $r) * $c1 + $c2) % 65536);
230
+				$r = ((($chr + $r)*$c1 + $c2)%65536);
231 231
 			}
232 232
 			if (preg_match('#/ForceBold[\s]*([^\s]*)#', $eplain, $matches) > 0) {
233 233
 				if ($matches[1] == 'true') {
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 				for ($i = 0; $i < $clen; ++$i) {
305 305
 					$chr = ord($cd[$i]);
306 306
 					$ccom[] = ($chr ^ ($r >> 8));
307
-					$r = ((($chr + $r) * $c1 + $c2) % 65536);
307
+					$r = ((($chr + $r)*$c1 + $c2)%65536);
308 308
 				}
309 309
 				// decode numbers
310 310
 				$cdec = array();
@@ -322,10 +322,10 @@  discard block
 block discarded – undo
322 322
 						$cdec[$ck] = ($ccom[$i] - 139);
323 323
 						++$i;
324 324
 					} elseif (($ccom[$i] >= 247) AND ($ccom[$i] <= 250)) {
325
-						$cdec[$ck] = ((($ccom[$i] - 247) * 256) + $ccom[($i + 1)] + 108);
325
+						$cdec[$ck] = ((($ccom[$i] - 247)*256) + $ccom[($i + 1)] + 108);
326 326
 						$i += 2;
327 327
 					} elseif (($ccom[$i] >= 251) AND ($ccom[$i] <= 254)) {
328
-						$cdec[$ck] = ((-($ccom[$i] - 251) * 256) - $ccom[($i + 1)] - 108);
328
+						$cdec[$ck] = ((-($ccom[$i] - 251)*256) - $ccom[($i + 1)] - 108);
329 329
 						$i += 2;
330 330
 					} elseif ($ccom[$i] == 255) {
331 331
 						$sval = chr($ccom[($i + 1)]).chr($ccom[($i + 2)]).chr($ccom[($i + 3)]).chr($ccom[($i + 4)]);
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 					$fmetric['cw'] .= ','.$cid.'=>'.$fmetric['MissingWidth'];
352 352
 				}
353 353
 			}
354
-			$fmetric['AvgWidth'] = round($fmetric['AvgWidth'] / count($cwidths));
354
+			$fmetric['AvgWidth'] = round($fmetric['AvgWidth']/count($cwidths));
355 355
 		} else {
356 356
 			// ---------- TRUE TYPE ----------
357 357
 			if ($fmetric['type'] != 'cidfont0') {
@@ -404,15 +404,15 @@  discard block
 block discarded – undo
404 404
 			$fmetric['unitsPerEm'] = TCPDF_STATIC::_getUSHORT($font, $offset);
405 405
 			$offset += 2;
406 406
 			// units ratio constant
407
-			$urk = (1000 / $fmetric['unitsPerEm']);
407
+			$urk = (1000/$fmetric['unitsPerEm']);
408 408
 			$offset += 16; // skip created, modified
409
-			$xMin = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
409
+			$xMin = round(TCPDF_STATIC::_getFWORD($font, $offset)*$urk);
410 410
 			$offset += 2;
411
-			$yMin = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
411
+			$yMin = round(TCPDF_STATIC::_getFWORD($font, $offset)*$urk);
412 412
 			$offset += 2;
413
-			$xMax = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
413
+			$xMax = round(TCPDF_STATIC::_getFWORD($font, $offset)*$urk);
414 414
 			$offset += 2;
415
-			$yMax = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
415
+			$yMax = round(TCPDF_STATIC::_getFWORD($font, $offset)*$urk);
416 416
 			$offset += 2;
417 417
 			$fmetric['bbox'] = ''.$xMin.' '.$yMin.' '.$xMax.' '.$yMax.'';
418 418
 			$macStyle = TCPDF_STATIC::_getUSHORT($font, $offset);
@@ -432,14 +432,14 @@  discard block
 block discarded – undo
432 432
 			$offset = $table['loca']['offset'];
433 433
 			if ($short_offset) {
434 434
 				// short version
435
-				$tot_num_glyphs = floor($table['loca']['length'] / 2); // numGlyphs + 1
435
+				$tot_num_glyphs = floor($table['loca']['length']/2); // numGlyphs + 1
436 436
 				for ($i = 0; $i < $tot_num_glyphs; ++$i) {
437
-					$indexToLoc[$i] = TCPDF_STATIC::_getUSHORT($font, $offset) * 2;
437
+					$indexToLoc[$i] = TCPDF_STATIC::_getUSHORT($font, $offset)*2;
438 438
 					$offset += 2;
439 439
 				}
440 440
 			} else {
441 441
 				// long version
442
-				$tot_num_glyphs = floor($table['loca']['length'] / 4); // numGlyphs + 1
442
+				$tot_num_glyphs = floor($table['loca']['length']/4); // numGlyphs + 1
443 443
 				for ($i = 0; $i < $tot_num_glyphs; ++$i) {
444 444
 					$indexToLoc[$i] = TCPDF_STATIC::_getULONG($font, $offset);
445 445
 					$offset += 4;
@@ -462,13 +462,13 @@  discard block
 block discarded – undo
462 462
 			$offset = $table['OS/2']['offset'];
463 463
 			$offset += 2; // skip version
464 464
 			// xAvgCharWidth
465
-			$fmetric['AvgWidth'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
465
+			$fmetric['AvgWidth'] = round(TCPDF_STATIC::_getFWORD($font, $offset)*$urk);
466 466
 			$offset += 2;
467 467
 			// usWeightClass
468
-			$usWeightClass = round(TCPDF_STATIC::_getUFWORD($font, $offset) * $urk);
468
+			$usWeightClass = round(TCPDF_STATIC::_getUFWORD($font, $offset)*$urk);
469 469
 			// estimate StemV and StemH (400 = usWeightClass for Normal - Regular font)
470
-			$fmetric['StemV'] = round((70 * $usWeightClass) / 400);
471
-			$fmetric['StemH'] = round((30 * $usWeightClass) / 400);
470
+			$fmetric['StemV'] = round((70*$usWeightClass)/400);
471
+			$fmetric['StemH'] = round((30*$usWeightClass)/400);
472 472
 			$offset += 2;
473 473
 			$offset += 2; // usWidthClass
474 474
 			$fsType = TCPDF_STATIC::_getSHORT($font, $offset);
@@ -515,9 +515,9 @@  discard block
 block discarded – undo
515 515
 			$offset += 4; // skip Format Type
516 516
 			$fmetric['italicAngle'] = TCPDF_STATIC::_getFIXED($font, $offset);
517 517
 			$offset += 4;
518
-			$fmetric['underlinePosition'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
518
+			$fmetric['underlinePosition'] = round(TCPDF_STATIC::_getFWORD($font, $offset)*$urk);
519 519
 			$offset += 2;
520
-			$fmetric['underlineThickness'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
520
+			$fmetric['underlineThickness'] = round(TCPDF_STATIC::_getFWORD($font, $offset)*$urk);
521 521
 			$offset += 2;
522 522
 			$isFixedPitch = (TCPDF_STATIC::_getULONG($font, $offset) == 0) ? false : true;
523 523
 			$offset += 2;
@@ -528,16 +528,16 @@  discard block
 block discarded – undo
528 528
 			$offset = $table['hhea']['offset'];
529 529
 			$offset += 4; // skip Table version number
530 530
 			// Ascender
531
-			$fmetric['Ascent'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
531
+			$fmetric['Ascent'] = round(TCPDF_STATIC::_getFWORD($font, $offset)*$urk);
532 532
 			$offset += 2;
533 533
 			// Descender
534
-			$fmetric['Descent'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
534
+			$fmetric['Descent'] = round(TCPDF_STATIC::_getFWORD($font, $offset)*$urk);
535 535
 			$offset += 2;
536 536
 			// LineGap
537
-			$fmetric['Leading'] = round(TCPDF_STATIC::_getFWORD($font, $offset) * $urk);
537
+			$fmetric['Leading'] = round(TCPDF_STATIC::_getFWORD($font, $offset)*$urk);
538 538
 			$offset += 2;
539 539
 			// advanceWidthMax
540
-			$fmetric['MaxWidth'] = round(TCPDF_STATIC::_getUFWORD($font, $offset) * $urk);
540
+			$fmetric['MaxWidth'] = round(TCPDF_STATIC::_getUFWORD($font, $offset)*$urk);
541 541
 			$offset += 2;
542 542
 			$offset += 22; // skip some values
543 543
 			// get the number of hMetric entries in hmtx table
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
 							$numSubHeaders = 0;
571 571
 							for ($i = 0; $i < 256; ++$i) {
572 572
 								// Array that maps high bytes to subHeaders: value is subHeader index * 8.
573
-								$subHeaderKeys[$i] = (TCPDF_STATIC::_getUSHORT($font, $offset) / 8);
573
+								$subHeaderKeys[$i] = (TCPDF_STATIC::_getUSHORT($font, $offset)/8);
574 574
 								$offset += 2;
575 575
 								if ($numSubHeaders < $subHeaderKeys[$i]) {
576 576
 									$numSubHeaders = $subHeaderKeys[$i];
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 								$offset += 2;
591 591
 								$subHeaders[$k]['idRangeOffset'] = TCPDF_STATIC::_getUSHORT($font, $offset);
592 592
 								$offset += 2;
593
-								$subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1) * 8));
593
+								$subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1)*8));
594 594
 								$subHeaders[$k]['idRangeOffset'] /= 2;
595 595
 								$numGlyphIndexArray += $subHeaders[$k]['entryCount'];
596 596
 							}
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
 										// combine high and low bytes
614 614
 										$c = (($i << 8) + $j);
615 615
 										$idRangeOffset = ($subHeaders[$k]['idRangeOffset'] + $j - $subHeaders[$k]['firstCode']);
616
-										$g = ($glyphIndexArray[$idRangeOffset] + $subHeaders[$k]['idDelta']) % 65536;
616
+										$g = ($glyphIndexArray[$idRangeOffset] + $subHeaders[$k]['idDelta'])%65536;
617 617
 										if ($g < 0) {
618 618
 											$g = 0;
619 619
 										}
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 							$length = TCPDF_STATIC::_getUSHORT($font, $offset);
628 628
 							$offset += 2;
629 629
 							$offset += 2; // skip version/language
630
-							$segCount = floor(TCPDF_STATIC::_getUSHORT($font, $offset) / 2);
630
+							$segCount = floor(TCPDF_STATIC::_getUSHORT($font, $offset)/2);
631 631
 							$offset += 2;
632 632
 							$offset += 6; // skip searchRange, entrySelector, rangeShift
633 633
 							$endCount = array(); // array of end character codes for each segment
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
 								$idRangeOffset[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
652 652
 								$offset += 2;
653 653
 							}
654
-							$gidlen = (floor($length / 2) - 8 - (4 * $segCount));
654
+							$gidlen = (floor($length/2) - 8 - (4*$segCount));
655 655
 							$glyphIdArray = array(); // glyph index array
656 656
 							for ($k = 0; $k < $gidlen; ++$k) {
657 657
 								$glyphIdArray[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
@@ -660,10 +660,10 @@  discard block
 block discarded – undo
660 660
 							for ($k = 0; $k < $segCount; ++$k) {
661 661
 								for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) {
662 662
 									if ($idRangeOffset[$k] == 0) {
663
-										$g = ($idDelta[$k] + $c) % 65536;
663
+										$g = ($idDelta[$k] + $c)%65536;
664 664
 									} else {
665
-										$gid = (floor($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k));
666
-										$g = ($glyphIdArray[$gid] + $idDelta[$k]) % 65536;
665
+										$gid = (floor($idRangeOffset[$k]/2) + ($c - $startCount[$k]) - ($segCount - $k));
666
+										$g = ($glyphIdArray[$gid] + $idDelta[$k])%65536;
667 667
 									}
668 668
 									if ($g < 0) {
669 669
 										$g = 0;
@@ -703,15 +703,15 @@  discard block
 block discarded – undo
703 703
 								$startGlyphID = TCPDF_STATIC::_getULONG($font, $offset);
704 704
 								$offset += 4;
705 705
 								for ($k = $startCharCode; $k <= $endCharCode; ++$k) {
706
-									$is32idx = floor($c / 8);
707
-									if ((isset($is32[$is32idx])) AND (($is32[$is32idx] & (1 << (7 - ($c % 8)))) == 0)) {
706
+									$is32idx = floor($c/8);
707
+									if ((isset($is32[$is32idx])) AND (($is32[$is32idx] & (1 << (7 - ($c%8)))) == 0)) {
708 708
 										$c = $k;
709 709
 									} else {
710 710
 										// 32 bit format
711 711
 										// convert to decimal (http://www.unicode.org/faq//utf_bom.html#utf16-4)
712 712
 										//LEAD_OFFSET = (0xD800 - (0x10000 >> 10)) = 55232
713 713
 										//SURROGATE_OFFSET = (0x10000 - (0xD800 << 10) - 0xDC00) = -56613888
714
-										$c = ((55232 + ($k >> 10)) << 10) + (0xDC00 + ($k & 0x3FF)) -56613888;
714
+										$c = ((55232 + ($k >> 10)) << 10) + (0xDC00 + ($k & 0x3FF)) - 56613888;
715 715
 									}
716 716
 									$ctg[$c] = 0;
717 717
 									++$startGlyphID;
@@ -771,19 +771,19 @@  discard block
 block discarded – undo
771 771
 			$offset += 4;
772 772
 			$yMax = TCPDF_STATIC::_getFWORD($font, $offset);
773 773
 			$offset += 2;
774
-			$fmetric['XHeight'] = round(($yMax - $yMin) * $urk);
774
+			$fmetric['XHeight'] = round(($yMax - $yMin)*$urk);
775 775
 			// get CapHeight (height of H)
776 776
 			$offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[72]] + 4);
777 777
 			$yMin = TCPDF_STATIC::_getFWORD($font, $offset);
778 778
 			$offset += 4;
779 779
 			$yMax = TCPDF_STATIC::_getFWORD($font, $offset);
780 780
 			$offset += 2;
781
-			$fmetric['CapHeight'] = round(($yMax - $yMin) * $urk);
781
+			$fmetric['CapHeight'] = round(($yMax - $yMin)*$urk);
782 782
 			// ceate widths array
783 783
 			$cw = array();
784 784
 			$offset = $table['hmtx']['offset'];
785
-			for ($i = 0 ; $i < $numberOfHMetrics; ++$i) {
786
-				$cw[$i] = round(TCPDF_STATIC::_getUFWORD($font, $offset) * $urk);
785
+			for ($i = 0; $i < $numberOfHMetrics; ++$i) {
786
+				$cw[$i] = round(TCPDF_STATIC::_getUFWORD($font, $offset)*$urk);
787 787
 				$offset += 4; // skip lsb
788 788
 			}
789 789
 			if ($numberOfHMetrics < $numGlyphs) {
@@ -800,10 +800,10 @@  discard block
 block discarded – undo
800 800
 					}
801 801
 					if ($addcbbox AND isset($indexToLoc[$ctg[$cid]])) {
802 802
 						$offset = ($table['glyf']['offset'] + $indexToLoc[$ctg[$cid]]);
803
-						$xMin = round(TCPDF_STATIC::_getFWORD($font, $offset + 2) * $urk);
804
-						$yMin = round(TCPDF_STATIC::_getFWORD($font, $offset + 4) * $urk);
805
-						$xMax = round(TCPDF_STATIC::_getFWORD($font, $offset + 6) * $urk);
806
-						$yMax = round(TCPDF_STATIC::_getFWORD($font, $offset + 8) * $urk);
803
+						$xMin = round(TCPDF_STATIC::_getFWORD($font, $offset + 2)*$urk);
804
+						$yMin = round(TCPDF_STATIC::_getFWORD($font, $offset + 4)*$urk);
805
+						$xMax = round(TCPDF_STATIC::_getFWORD($font, $offset + 6)*$urk);
806
+						$yMax = round(TCPDF_STATIC::_getFWORD($font, $offset + 8)*$urk);
807 807
 						$fmetric['cbbox'] .= ','.$cid.'=>array('.$xMin.','.$yMin.','.$xMax.','.$yMax.')';
808 808
 					}
809 809
 				}
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
 	 */
922 922
 	public static function _getTTFtableChecksum($table, $length) {
923 923
 		$sum = 0;
924
-		$tlen = ($length / 4);
924
+		$tlen = ($length/4);
925 925
 		$offset = 0;
926 926
 		for ($i = 0; $i < $tlen; ++$i) {
927 927
 			$v = unpack('Ni', substr($table, $offset, 4));
@@ -985,14 +985,14 @@  discard block
 block discarded – undo
985 985
 		$offset = $table['loca']['offset'];
986 986
 		if ($short_offset) {
987 987
 			// short version
988
-			$tot_num_glyphs = floor($table['loca']['length'] / 2); // numGlyphs + 1
988
+			$tot_num_glyphs = floor($table['loca']['length']/2); // numGlyphs + 1
989 989
 			for ($i = 0; $i < $tot_num_glyphs; ++$i) {
990
-				$indexToLoc[$i] = TCPDF_STATIC::_getUSHORT($font, $offset) * 2;
990
+				$indexToLoc[$i] = TCPDF_STATIC::_getUSHORT($font, $offset)*2;
991 991
 				$offset += 2;
992 992
 			}
993 993
 		} else {
994 994
 			// long version
995
-			$tot_num_glyphs = ($table['loca']['length'] / 4); // numGlyphs + 1
995
+			$tot_num_glyphs = ($table['loca']['length']/4); // numGlyphs + 1
996 996
 			for ($i = 0; $i < $tot_num_glyphs; ++$i) {
997 997
 				$indexToLoc[$i] = TCPDF_STATIC::_getULONG($font, $offset);
998 998
 				$offset += 4;
@@ -1035,7 +1035,7 @@  discard block
 block discarded – undo
1035 1035
 					$numSubHeaders = 0;
1036 1036
 					for ($i = 0; $i < 256; ++$i) {
1037 1037
 						// Array that maps high bytes to subHeaders: value is subHeader index * 8.
1038
-						$subHeaderKeys[$i] = (TCPDF_STATIC::_getUSHORT($font, $offset) / 8);
1038
+						$subHeaderKeys[$i] = (TCPDF_STATIC::_getUSHORT($font, $offset)/8);
1039 1039
 						$offset += 2;
1040 1040
 						if ($numSubHeaders < $subHeaderKeys[$i]) {
1041 1041
 							$numSubHeaders = $subHeaderKeys[$i];
@@ -1055,7 +1055,7 @@  discard block
 block discarded – undo
1055 1055
 						$offset += 2;
1056 1056
 						$subHeaders[$k]['idRangeOffset'] = TCPDF_STATIC::_getUSHORT($font, $offset);
1057 1057
 						$offset += 2;
1058
-						$subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1) * 8));
1058
+						$subHeaders[$k]['idRangeOffset'] -= (2 + (($numSubHeaders - $k - 1)*8));
1059 1059
 						$subHeaders[$k]['idRangeOffset'] /= 2;
1060 1060
 						$numGlyphIndexArray += $subHeaders[$k]['entryCount'];
1061 1061
 					}
@@ -1081,7 +1081,7 @@  discard block
 block discarded – undo
1081 1081
 								$c = (($i << 8) + $j);
1082 1082
 								if (isset($subsetchars[$c])) {
1083 1083
 									$idRangeOffset = ($subHeaders[$k]['idRangeOffset'] + $j - $subHeaders[$k]['firstCode']);
1084
-									$g = ($glyphIndexArray[$idRangeOffset] + $subHeaders[$k]['idDelta']) % 65536;
1084
+									$g = ($glyphIndexArray[$idRangeOffset] + $subHeaders[$k]['idDelta'])%65536;
1085 1085
 									if ($g < 0) {
1086 1086
 										$g = 0;
1087 1087
 									}
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
 					$length = TCPDF_STATIC::_getUSHORT($font, $offset);
1097 1097
 					$offset += 2;
1098 1098
 					$offset += 2; // skip version/language
1099
-					$segCount = floor(TCPDF_STATIC::_getUSHORT($font, $offset) / 2);
1099
+					$segCount = floor(TCPDF_STATIC::_getUSHORT($font, $offset)/2);
1100 1100
 					$offset += 2;
1101 1101
 					$offset += 6; // skip searchRange, entrySelector, rangeShift
1102 1102
 					$endCount = array(); // array of end character codes for each segment
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
 						$idRangeOffset[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
1121 1121
 						$offset += 2;
1122 1122
 					}
1123
-					$gidlen = (floor($length / 2) - 8 - (4 * $segCount));
1123
+					$gidlen = (floor($length/2) - 8 - (4*$segCount));
1124 1124
 					$glyphIdArray = array(); // glyph index array
1125 1125
 					for ($k = 0; $k < $gidlen; ++$k) {
1126 1126
 						$glyphIdArray[$k] = TCPDF_STATIC::_getUSHORT($font, $offset);
@@ -1130,10 +1130,10 @@  discard block
 block discarded – undo
1130 1130
 						for ($c = $startCount[$k]; $c <= $endCount[$k]; ++$c) {
1131 1131
 							if (isset($subsetchars[$c])) {
1132 1132
 								if ($idRangeOffset[$k] == 0) {
1133
-									$g = ($idDelta[$k] + $c) % 65536;
1133
+									$g = ($idDelta[$k] + $c)%65536;
1134 1134
 								} else {
1135
-									$gid = (floor($idRangeOffset[$k] / 2) + ($c - $startCount[$k]) - ($segCount - $k));
1136
-									$g = ($glyphIdArray[$gid] + $idDelta[$k]) % 65536;
1135
+									$gid = (floor($idRangeOffset[$k]/2) + ($c - $startCount[$k]) - ($segCount - $k));
1136
+									$g = ($glyphIdArray[$gid] + $idDelta[$k])%65536;
1137 1137
 								}
1138 1138
 								if ($g < 0) {
1139 1139
 									$g = 0;
@@ -1176,15 +1176,15 @@  discard block
 block discarded – undo
1176 1176
 						$startGlyphID = TCPDF_STATIC::_getULONG($font, $offset);
1177 1177
 						$offset += 4;
1178 1178
 						for ($k = $startCharCode; $k <= $endCharCode; ++$k) {
1179
-							$is32idx = floor($c / 8);
1180
-							if ((isset($is32[$is32idx])) AND (($is32[$is32idx] & (1 << (7 - ($c % 8)))) == 0)) {
1179
+							$is32idx = floor($c/8);
1180
+							if ((isset($is32[$is32idx])) AND (($is32[$is32idx] & (1 << (7 - ($c%8)))) == 0)) {
1181 1181
 								$c = $k;
1182 1182
 							} else {
1183 1183
 								// 32 bit format
1184 1184
 								// convert to decimal (http://www.unicode.org/faq//utf_bom.html#utf16-4)
1185 1185
 								//LEAD_OFFSET = (0xD800 - (0x10000 >> 10)) = 55232
1186 1186
 								//SURROGATE_OFFSET = (0x10000 - (0xD800 << 10) - 0xDC00) = -56613888
1187
-								$c = ((55232 + ($k >> 10)) << 10) + (0xDC00 + ($k & 0x3FF)) -56613888;
1187
+								$c = ((55232 + ($k >> 10)) << 10) + (0xDC00 + ($k & 0x3FF)) - 56613888;
1188 1188
 							}
1189 1189
 							if (isset($subsetchars[$c])) {
1190 1190
 								$subsetglyphs[$startGlyphID] = true;
@@ -1295,7 +1295,7 @@  discard block
 block discarded – undo
1295 1295
 				$length = 0;
1296 1296
 			}
1297 1297
 			if ($short_offset) {
1298
-				$loca .= pack('n', floor($offset / 2));
1298
+				$loca .= pack('n', floor($offset/2));
1299 1299
 			} else {
1300 1300
 				$loca .= pack('N', $offset);
1301 1301
 			}
@@ -1303,7 +1303,7 @@  discard block
 block discarded – undo
1303 1303
 		}
1304 1304
 		// array of table names to preserve (loca and glyf tables will be added later)
1305 1305
 		// the cmap table is not needed and shall not be present, since the mapping from character codes to glyph descriptions is provided separately
1306
-		$table_names = array ('head', 'hhea', 'hmtx', 'maxp', 'cvt ', 'fpgm', 'prep'); // minimum required table names
1306
+		$table_names = array('head', 'hhea', 'hmtx', 'maxp', 'cvt ', 'fpgm', 'prep'); // minimum required table names
1307 1307
 		// get the tables to preserve
1308 1308
 		$offset = 12;
1309 1309
 		foreach ($table as $tag => $val) {
@@ -1313,7 +1313,7 @@  discard block
 block discarded – undo
1313 1313
 					// set the checkSumAdjustment to 0
1314 1314
 					$table[$tag]['data'] = substr($table[$tag]['data'], 0, 8)."\x0\x0\x0\x0".substr($table[$tag]['data'], 12);
1315 1315
 				}
1316
-				$pad = 4 - ($table[$tag]['length'] % 4);
1316
+				$pad = 4 - ($table[$tag]['length']%4);
1317 1317
 				if ($pad != 4) {
1318 1318
 					// the length of a table must be a multiple of four bytes
1319 1319
 					$table[$tag]['length'] += $pad;
@@ -1330,7 +1330,7 @@  discard block
 block discarded – undo
1330 1330
 		// add loca
1331 1331
 		$table['loca']['data'] = $loca;
1332 1332
 		$table['loca']['length'] = strlen($loca);
1333
-		$pad = 4 - ($table['loca']['length'] % 4);
1333
+		$pad = 4 - ($table['loca']['length']%4);
1334 1334
 		if ($pad != 4) {
1335 1335
 			// the length of a table must be a multiple of four bytes
1336 1336
 			$table['loca']['length'] += $pad;
@@ -1342,7 +1342,7 @@  discard block
 block discarded – undo
1342 1342
 		// add glyf
1343 1343
 		$table['glyf']['data'] = $glyf;
1344 1344
 		$table['glyf']['length'] = strlen($glyf);
1345
-		$pad = 4 - ($table['glyf']['length'] % 4);
1345
+		$pad = 4 - ($table['glyf']['length']%4);
1346 1346
 		if ($pad != 4) {
1347 1347
 			// the length of a table must be a multiple of four bytes
1348 1348
 			$table['glyf']['length'] += $pad;
@@ -1356,12 +1356,12 @@  discard block
 block discarded – undo
1356 1356
 		$numTables = count($table);
1357 1357
 		$font .= pack('n', $numTables); // numTables
1358 1358
 		$entrySelector = floor(log($numTables, 2));
1359
-		$searchRange = pow(2, $entrySelector) * 16;
1360
-		$rangeShift = ($numTables * 16) - $searchRange;
1359
+		$searchRange = pow(2, $entrySelector)*16;
1360
+		$rangeShift = ($numTables*16) - $searchRange;
1361 1361
 		$font .= pack('n', $searchRange); // searchRange
1362 1362
 		$font .= pack('n', $entrySelector); // entrySelector
1363 1363
 		$font .= pack('n', $rangeShift); // rangeShift
1364
-		$offset = ($numTables * 16);
1364
+		$offset = ($numTables*16);
1365 1365
 		foreach ($table as $tag => $data) {
1366 1366
 			$font .= $tag; // tag
1367 1367
 			$font .= pack('N', $data['checkSum']); // checkSum
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
 	 * @since 4.4.000 (2008-12-07)
1387 1387
 	 * @public static
1388 1388
 	 */
1389
-	public static function _putfontwidths($font, $cidoffset=0) {
1389
+	public static function _putfontwidths($font, $cidoffset = 0) {
1390 1390
 		ksort($font['cw']);
1391 1391
 		$rangeid = 0;
1392 1392
 		$range = array();
@@ -1490,7 +1490,7 @@  discard block
 block discarded – undo
1490 1490
 	 * @since 2.3.000 (2008-03-05)
1491 1491
 	 * @public static
1492 1492
 	 */
1493
-	public static function unichr($c, $unicode=true) {
1493
+	public static function unichr($c, $unicode = true) {
1494 1494
 		if (!$unicode) {
1495 1495
 			return chr($c);
1496 1496
 		} elseif ($c <= 0x7F) {
@@ -1568,7 +1568,7 @@  discard block
 block discarded – undo
1568 1568
 	 * @since 2.1.000 (2008-01-08)
1569 1569
 	 * @public static
1570 1570
 	 */
1571
-	public static function arrUTF8ToUTF16BE($unicode, $setbom=false) {
1571
+	public static function arrUTF8ToUTF16BE($unicode, $setbom = false) {
1572 1572
 		$outstr = ''; // string to be returned
1573 1573
 		if ($setbom) {
1574 1574
 			$outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
@@ -1602,7 +1602,7 @@  discard block
 block discarded – undo
1602 1602
 	 * @since 4.5.037 (2009-04-07)
1603 1603
 	 * @public static
1604 1604
 	 */
1605
-	public static function UTF8ArrayToUniArray($ta, $isunicode=true) {
1605
+	public static function UTF8ArrayToUniArray($ta, $isunicode = true) {
1606 1606
 		if ($isunicode) {
1607 1607
 			return array_map(array('TCPDF_FONTS', 'unichrUnicode'), $ta);
1608 1608
 		}
@@ -1618,7 +1618,7 @@  discard block
 block discarded – undo
1618 1618
 	 * @return Return part of a string
1619 1619
 	 * @public static
1620 1620
 	 */
1621
-	public static function UTF8ArrSubString($strarr, $start='', $end='', $unicode=true) {
1621
+	public static function UTF8ArrSubString($strarr, $start = '', $end = '', $unicode = true) {
1622 1622
 		if (strlen($start) == 0) {
1623 1623
 			$start = 0;
1624 1624
 		}
@@ -1641,7 +1641,7 @@  discard block
 block discarded – undo
1641 1641
 	 * @since 4.5.037 (2009-04-07)
1642 1642
 	 * @public static
1643 1643
 	 */
1644
-	public static function UniArrSubString($uniarr, $start='', $end='') {
1644
+	public static function UniArrSubString($uniarr, $start = '', $end = '') {
1645 1645
 		if (strlen($start) == 0) {
1646 1646
 			$start = 0;
1647 1647
 		}
@@ -1649,7 +1649,7 @@  discard block
 block discarded – undo
1649 1649
 			$end = count($uniarr);
1650 1650
 		}
1651 1651
 		$string = '';
1652
-		for ($i=$start; $i < $end; ++$i) {
1652
+		for ($i = $start; $i < $end; ++$i) {
1653 1653
 			$string .= $uniarr[$i];
1654 1654
 		}
1655 1655
 		return $string;
@@ -1670,8 +1670,8 @@  discard block
 block discarded – undo
1670 1670
 			if ($gid > 0xFFFF) {
1671 1671
 				$gid -= 0x10000;
1672 1672
 			}
1673
-			$map[($cid * 2)] = chr($gid >> 8);
1674
-			$map[(($cid * 2) + 1)] = chr($gid & 0xFF);
1673
+			$map[($cid*2)] = chr($gid >> 8);
1674
+			$map[(($cid*2) + 1)] = chr($gid & 0xFF);
1675 1675
 		}
1676 1676
 		return $map;
1677 1677
 	}
@@ -1700,7 +1700,7 @@  discard block
 block discarded – undo
1700 1700
 	 * @since 6.0.025
1701 1701
 	 * @public static
1702 1702
 	 */
1703
-	public static function getFontFullPath($file, $fontdir=false) {
1703
+	public static function getFontFullPath($file, $fontdir = false) {
1704 1704
 		$fontfile = '';
1705 1705
 		// search files on various directories
1706 1706
 		if (($fontdir !== false) AND @file_exists($fontdir.$file)) {
@@ -1849,7 +1849,7 @@  discard block
 block discarded – undo
1849 1849
 					// compose UTF-8 bytes to a single unicode value
1850 1850
 					$char = $bytes[0];
1851 1851
 					for ($j = 1; $j < $numbytes; ++$j) {
1852
-						$char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
1852
+						$char += ($bytes[$j] << (($numbytes - $j - 1)*0x06));
1853 1853
 					}
1854 1854
 					if ((($char >= 0xD800) AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
1855 1855
 						// The definition of UTF-8 prohibits encoding character numbers between
@@ -1879,10 +1879,10 @@  discard block
 block discarded – undo
1879 1879
 	 * @author Nicola Asuni
1880 1880
 	 * @public static
1881 1881
 	 */
1882
-	public static function UTF8StringToArray($str, $isunicode=true, &$currentfont) {
1882
+	public static function UTF8StringToArray($str, $isunicode = true, &$currentfont) {
1883 1883
 		if ($isunicode) {
1884 1884
 			// requires PCRE unicode support turned on
1885
-			$chars = TCPDF_STATIC::pregSplit('//','u', $str, -1, PREG_SPLIT_NO_EMPTY);
1885
+			$chars = TCPDF_STATIC::pregSplit('//', 'u', $str, -1, PREG_SPLIT_NO_EMPTY);
1886 1886
 			$carr = array_map(array('TCPDF_FONTS', 'uniord'), $chars);
1887 1887
 		} else {
1888 1888
 			$chars = str_split($str);
@@ -1901,7 +1901,7 @@  discard block
 block discarded – undo
1901 1901
 	 * @since 3.2.000 (2008-06-23)
1902 1902
 	 * @public static
1903 1903
 	 */
1904
-	public static function UTF8ToLatin1($str, $isunicode=true, &$currentfont) {
1904
+	public static function UTF8ToLatin1($str, $isunicode = true, &$currentfont) {
1905 1905
 		$unicode = self::UTF8StringToArray($str, $isunicode, $currentfont); // array containing UTF-8 unicode values
1906 1906
 		return self::UTF8ArrToLatin1($unicode);
1907 1907
 	}
@@ -1917,7 +1917,7 @@  discard block
 block discarded – undo
1917 1917
 	 * @since 1.53.0.TC005 (2005-01-05)
1918 1918
 	 * @public static
1919 1919
 	 */
1920
-	public static function UTF8ToUTF16BE($str, $setbom=false, $isunicode=true, &$currentfont) {
1920
+	public static function UTF8ToUTF16BE($str, $setbom = false, $isunicode = true, &$currentfont) {
1921 1921
 		if (!$isunicode) {
1922 1922
 			return $str; // string is not in unicode
1923 1923
 		}
@@ -1937,7 +1937,7 @@  discard block
 block discarded – undo
1937 1937
 	 * @since 2.1.000 (2008-01-08)
1938 1938
 	 * @public static
1939 1939
 	 */
1940
-	public static function utf8StrRev($str, $setbom=false, $forcertl=false, $isunicode=true, &$currentfont) {
1940
+	public static function utf8StrRev($str, $setbom = false, $forcertl = false, $isunicode = true, &$currentfont) {
1941 1941
 		return self::utf8StrArrRev(self::UTF8StringToArray($str, $isunicode, $currentfont), $str, $setbom, $forcertl, $isunicode, $currentfont);
1942 1942
 	}
1943 1943
 
@@ -1954,7 +1954,7 @@  discard block
 block discarded – undo
1954 1954
 	 * @since 4.9.000 (2010-03-27)
1955 1955
 	 * @public static
1956 1956
 	 */
1957
-	public static function utf8StrArrRev($arr, $str='', $setbom=false, $forcertl=false, $isunicode=true, &$currentfont) {
1957
+	public static function utf8StrArrRev($arr, $str = '', $setbom = false, $forcertl = false, $isunicode = true, &$currentfont) {
1958 1958
 		return self::arrUTF8ToUTF16BE(self::utf8Bidi($arr, $str, $forcertl, $isunicode, $currentfont), $setbom);
1959 1959
 	}
1960 1960
 
@@ -1970,7 +1970,7 @@  discard block
 block discarded – undo
1970 1970
 	 * @since 2.4.000 (2008-03-06)
1971 1971
 	 * @public static
1972 1972
 	 */
1973
-	public static function utf8Bidi($ta, $str='', $forcertl=false, $isunicode=true, &$currentfont) {
1973
+	public static function utf8Bidi($ta, $str = '', $forcertl = false, $isunicode = true, &$currentfont) {
1974 1974
 		// paragraph embedding level
1975 1975
 		$pel = 0;
1976 1976
 		// max level
@@ -2000,7 +2000,7 @@  discard block
 block discarded – undo
2000 2000
 		} else {
2001 2001
 			// P2. In each paragraph, find the first character of type L, AL, or R.
2002 2002
 			// P3. If a character is found in P2 and it is of type AL or R, then set the paragraph embedding level to one; otherwise, set it to zero.
2003
-			for ($i=0; $i < $numchars; ++$i) {
2003
+			for ($i = 0; $i < $numchars; ++$i) {
2004 2004
 				$type = TCPDF_FONT_DATA::$uni_type[$ta[$i]];
2005 2005
 				if ($type == 'L') {
2006 2006
 					$pel = 0;
@@ -2018,7 +2018,7 @@  discard block
 block discarded – undo
2018 2018
 		$dos = 'N';
2019 2019
 		$remember = array();
2020 2020
 		// start-of-level-run
2021
-		$sor = $pel % 2 ? 'R' : 'L';
2021
+		$sor = $pel%2 ? 'R' : 'L';
2022 2022
 		$eor = $sor;
2023 2023
 
2024 2024
 		// Array of characters data
@@ -2026,59 +2026,59 @@  discard block
 block discarded – undo
2026 2026
 
2027 2027
 		// X1. Begin by setting the current embedding level to the paragraph embedding level. Set the directional override status to neutral. Process each character iteratively, applying rules X2 through X9. Only embedding levels from 0 to 61 are valid in this phase.
2028 2028
 		// In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached.
2029
-		for ($i=0; $i < $numchars; ++$i) {
2029
+		for ($i = 0; $i < $numchars; ++$i) {
2030 2030
 			if ($ta[$i] == TCPDF_FONT_DATA::$uni_RLE) {
2031 2031
 				// X2. With each RLE, compute the least greater odd embedding level.
2032 2032
 				//	a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
2033 2033
 				//	b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
2034
-				$next_level = $cel + ($cel % 2) + 1;
2034
+				$next_level = $cel + ($cel%2) + 1;
2035 2035
 				if ($next_level < 62) {
2036 2036
 					$remember[] = array('num' => TCPDF_FONT_DATA::$uni_RLE, 'cel' => $cel, 'dos' => $dos);
2037 2037
 					$cel = $next_level;
2038 2038
 					$dos = 'N';
2039 2039
 					$sor = $eor;
2040
-					$eor = $cel % 2 ? 'R' : 'L';
2040
+					$eor = $cel%2 ? 'R' : 'L';
2041 2041
 				}
2042 2042
 			} elseif ($ta[$i] == TCPDF_FONT_DATA::$uni_LRE) {
2043 2043
 				// X3. With each LRE, compute the least greater even embedding level.
2044 2044
 				//	a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
2045 2045
 				//	b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
2046
-				$next_level = $cel + 2 - ($cel % 2);
2047
-				if ( $next_level < 62 ) {
2046
+				$next_level = $cel + 2 - ($cel%2);
2047
+				if ($next_level < 62) {
2048 2048
 					$remember[] = array('num' => TCPDF_FONT_DATA::$uni_LRE, 'cel' => $cel, 'dos' => $dos);
2049 2049
 					$cel = $next_level;
2050 2050
 					$dos = 'N';
2051 2051
 					$sor = $eor;
2052
-					$eor = $cel % 2 ? 'R' : 'L';
2052
+					$eor = $cel%2 ? 'R' : 'L';
2053 2053
 				}
2054 2054
 			} elseif ($ta[$i] == TCPDF_FONT_DATA::$uni_RLO) {
2055 2055
 				// X4. With each RLO, compute the least greater odd embedding level.
2056 2056
 				//	a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to right-to-left.
2057 2057
 				//	b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
2058
-				$next_level = $cel + ($cel % 2) + 1;
2058
+				$next_level = $cel + ($cel%2) + 1;
2059 2059
 				if ($next_level < 62) {
2060 2060
 					$remember[] = array('num' => TCPDF_FONT_DATA::$uni_RLO, 'cel' => $cel, 'dos' => $dos);
2061 2061
 					$cel = $next_level;
2062 2062
 					$dos = 'R';
2063 2063
 					$sor = $eor;
2064
-					$eor = $cel % 2 ? 'R' : 'L';
2064
+					$eor = $cel%2 ? 'R' : 'L';
2065 2065
 				}
2066 2066
 			} elseif ($ta[$i] == TCPDF_FONT_DATA::$uni_LRO) {
2067 2067
 				// X5. With each LRO, compute the least greater even embedding level.
2068 2068
 				//	a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to left-to-right.
2069 2069
 				//	b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
2070
-				$next_level = $cel + 2 - ($cel % 2);
2071
-				if ( $next_level < 62 ) {
2070
+				$next_level = $cel + 2 - ($cel%2);
2071
+				if ($next_level < 62) {
2072 2072
 					$remember[] = array('num' => TCPDF_FONT_DATA::$uni_LRO, 'cel' => $cel, 'dos' => $dos);
2073 2073
 					$cel = $next_level;
2074 2074
 					$dos = 'L';
2075 2075
 					$sor = $eor;
2076
-					$eor = $cel % 2 ? 'R' : 'L';
2076
+					$eor = $cel%2 ? 'R' : 'L';
2077 2077
 				}
2078 2078
 			} elseif ($ta[$i] == TCPDF_FONT_DATA::$uni_PDF) {
2079 2079
 				// X7. With each PDF, determine the matching embedding or override code. If there was a valid matching code, restore (pop) the last remembered (pushed) embedding level and directional override.
2080 2080
 				if (count($remember)) {
2081
-					$last = count($remember ) - 1;
2081
+					$last = count($remember) - 1;
2082 2082
 					if (($remember[$last]['num'] == TCPDF_FONT_DATA::$uni_RLE) OR
2083 2083
 						($remember[$last]['num'] == TCPDF_FONT_DATA::$uni_LRE) OR
2084 2084
 						($remember[$last]['num'] == TCPDF_FONT_DATA::$uni_RLO) OR
@@ -2087,7 +2087,7 @@  discard block
 block discarded – undo
2087 2087
 						$cel = $match['cel'];
2088 2088
 						$dos = $match['dos'];
2089 2089
 						$sor = $eor;
2090
-						$eor = ($cel > $match['cel'] ? $cel : $match['cel']) % 2 ? 'R' : 'L';
2090
+						$eor = ($cel > $match['cel'] ? $cel : $match['cel'])%2 ? 'R' : 'L';
2091 2091
 					}
2092 2092
 				}
2093 2093
 			} elseif (($ta[$i] != TCPDF_FONT_DATA::$uni_RLE) AND
@@ -2124,12 +2124,12 @@  discard block
 block discarded – undo
2124 2124
 		// W1. Examine each nonspacing mark (NSM) in the level run, and change the type of the NSM to the type of the previous character. If the NSM is at the start of the level run, it will get the type of sor.
2125 2125
 		$prevlevel = -1; // track level changes
2126 2126
 		$levcount = 0; // counts consecutive chars at the same level
2127
-		for ($i=0; $i < $numchars; ++$i) {
2127
+		for ($i = 0; $i < $numchars; ++$i) {
2128 2128
 			if ($chardata[$i]['type'] == 'NSM') {
2129 2129
 				if ($levcount) {
2130 2130
 					$chardata[$i]['type'] = $chardata[$i]['sor'];
2131 2131
 				} elseif ($i > 0) {
2132
-					$chardata[$i]['type'] = $chardata[($i-1)]['type'];
2132
+					$chardata[$i]['type'] = $chardata[($i - 1)]['type'];
2133 2133
 				}
2134 2134
 			}
2135 2135
 			if ($chardata[$i]['level'] != $prevlevel) {
@@ -2143,9 +2143,9 @@  discard block
 block discarded – undo
2143 2143
 		// W2. Search backward from each instance of a European number until the first strong type (R, L, AL, or sor) is found. If an AL is found, change the type of the European number to Arabic number.
2144 2144
 		$prevlevel = -1;
2145 2145
 		$levcount = 0;
2146
-		for ($i=0; $i < $numchars; ++$i) {
2146
+		for ($i = 0; $i < $numchars; ++$i) {
2147 2147
 			if ($chardata[$i]['char'] == 'EN') {
2148
-				for ($j=$levcount; $j >= 0; $j--) {
2148
+				for ($j = $levcount; $j >= 0; $j--) {
2149 2149
 					if ($chardata[$j]['type'] == 'AL') {
2150 2150
 						$chardata[$i]['type'] = 'AN';
2151 2151
 					} elseif (($chardata[$j]['type'] == 'L') OR ($chardata[$j]['type'] == 'R')) {
@@ -2162,7 +2162,7 @@  discard block
 block discarded – undo
2162 2162
 		}
2163 2163
 
2164 2164
 		// W3. Change all ALs to R.
2165
-		for ($i=0; $i < $numchars; ++$i) {
2165
+		for ($i = 0; $i < $numchars; ++$i) {
2166 2166
 			if ($chardata[$i]['type'] == 'AL') {
2167 2167
 				$chardata[$i]['type'] = 'R';
2168 2168
 			}
@@ -2171,13 +2171,13 @@  discard block
 block discarded – undo
2171 2171
 		// W4. A single European separator between two European numbers changes to a European number. A single common separator between two numbers of the same type changes to that type.
2172 2172
 		$prevlevel = -1;
2173 2173
 		$levcount = 0;
2174
-		for ($i=0; $i < $numchars; ++$i) {
2175
-			if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
2176
-				if (($chardata[$i]['type'] == 'ES') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+1)]['type'] == 'EN')) {
2174
+		for ($i = 0; $i < $numchars; ++$i) {
2175
+			if (($levcount > 0) AND (($i + 1) < $numchars) AND ($chardata[($i + 1)]['level'] == $prevlevel)) {
2176
+				if (($chardata[$i]['type'] == 'ES') AND ($chardata[($i - 1)]['type'] == 'EN') AND ($chardata[($i + 1)]['type'] == 'EN')) {
2177 2177
 					$chardata[$i]['type'] = 'EN';
2178
-				} elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+1)]['type'] == 'EN')) {
2178
+				} elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i - 1)]['type'] == 'EN') AND ($chardata[($i + 1)]['type'] == 'EN')) {
2179 2179
 					$chardata[$i]['type'] = 'EN';
2180
-				} elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'AN') AND ($chardata[($i+1)]['type'] == 'AN')) {
2180
+				} elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i - 1)]['type'] == 'AN') AND ($chardata[($i + 1)]['type'] == 'AN')) {
2181 2181
 					$chardata[$i]['type'] = 'AN';
2182 2182
 				}
2183 2183
 			}
@@ -2192,12 +2192,12 @@  discard block
 block discarded – undo
2192 2192
 		// W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
2193 2193
 		$prevlevel = -1;
2194 2194
 		$levcount = 0;
2195
-		for ($i=0; $i < $numchars; ++$i) {
2195
+		for ($i = 0; $i < $numchars; ++$i) {
2196 2196
 			if ($chardata[$i]['type'] == 'ET') {
2197
-				if (($levcount > 0) AND ($chardata[($i-1)]['type'] == 'EN')) {
2197
+				if (($levcount > 0) AND ($chardata[($i - 1)]['type'] == 'EN')) {
2198 2198
 					$chardata[$i]['type'] = 'EN';
2199 2199
 				} else {
2200
-					$j = $i+1;
2200
+					$j = $i + 1;
2201 2201
 					while (($j < $numchars) AND ($chardata[$j]['level'] == $prevlevel)) {
2202 2202
 						if ($chardata[$j]['type'] == 'EN') {
2203 2203
 							$chardata[$i]['type'] = 'EN';
@@ -2220,7 +2220,7 @@  discard block
 block discarded – undo
2220 2220
 		// W6. Otherwise, separators and terminators change to Other Neutral.
2221 2221
 		$prevlevel = -1;
2222 2222
 		$levcount = 0;
2223
-		for ($i=0; $i < $numchars; ++$i) {
2223
+		for ($i = 0; $i < $numchars; ++$i) {
2224 2224
 			if (($chardata[$i]['type'] == 'ET') OR ($chardata[$i]['type'] == 'ES') OR ($chardata[$i]['type'] == 'CS')) {
2225 2225
 				$chardata[$i]['type'] = 'ON';
2226 2226
 			}
@@ -2235,9 +2235,9 @@  discard block
 block discarded – undo
2235 2235
 		//W7. Search backward from each instance of a European number until the first strong type (R, L, or sor) is found. If an L is found, then change the type of the European number to L.
2236 2236
 		$prevlevel = -1;
2237 2237
 		$levcount = 0;
2238
-		for ($i=0; $i < $numchars; ++$i) {
2238
+		for ($i = 0; $i < $numchars; ++$i) {
2239 2239
 			if ($chardata[$i]['char'] == 'EN') {
2240
-				for ($j=$levcount; $j >= 0; $j--) {
2240
+				for ($j = $levcount; $j >= 0; $j--) {
2241 2241
 					if ($chardata[$j]['type'] == 'L') {
2242 2242
 						$chardata[$i]['type'] = 'L';
2243 2243
 					} elseif ($chardata[$j]['type'] == 'R') {
@@ -2256,36 +2256,36 @@  discard block
 block discarded – undo
2256 2256
 		// N1. A sequence of neutrals takes the direction of the surrounding strong text if the text on both sides has the same direction. European and Arabic numbers act as if they were R in terms of their influence on neutrals. Start-of-level-run (sor) and end-of-level-run (eor) are used at level run boundaries.
2257 2257
 		$prevlevel = -1;
2258 2258
 		$levcount = 0;
2259
-		for ($i=0; $i < $numchars; ++$i) {
2260
-			if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
2261
-				if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[($i+1)]['type'] == 'L')) {
2259
+		for ($i = 0; $i < $numchars; ++$i) {
2260
+			if (($levcount > 0) AND (($i + 1) < $numchars) AND ($chardata[($i + 1)]['level'] == $prevlevel)) {
2261
+				if (($chardata[$i]['type'] == 'N') AND ($chardata[($i - 1)]['type'] == 'L') AND ($chardata[($i + 1)]['type'] == 'L')) {
2262 2262
 					$chardata[$i]['type'] = 'L';
2263 2263
 				} elseif (($chardata[$i]['type'] == 'N') AND
2264
-				 (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
2265
-				 (($chardata[($i+1)]['type'] == 'R') OR ($chardata[($i+1)]['type'] == 'EN') OR ($chardata[($i+1)]['type'] == 'AN'))) {
2264
+				 (($chardata[($i - 1)]['type'] == 'R') OR ($chardata[($i - 1)]['type'] == 'EN') OR ($chardata[($i - 1)]['type'] == 'AN')) AND
2265
+				 (($chardata[($i + 1)]['type'] == 'R') OR ($chardata[($i + 1)]['type'] == 'EN') OR ($chardata[($i + 1)]['type'] == 'AN'))) {
2266 2266
 					$chardata[$i]['type'] = 'R';
2267 2267
 				} elseif ($chardata[$i]['type'] == 'N') {
2268 2268
 					// N2. Any remaining neutrals take the embedding direction
2269 2269
 					$chardata[$i]['type'] = $chardata[$i]['sor'];
2270 2270
 				}
2271
-			} elseif (($levcount == 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] == $prevlevel)) {
2271
+			} elseif (($levcount == 0) AND (($i + 1) < $numchars) AND ($chardata[($i + 1)]['level'] == $prevlevel)) {
2272 2272
 				// first char
2273
-				if (($chardata[$i]['type'] == 'N') AND ($chardata[$i]['sor'] == 'L') AND ($chardata[($i+1)]['type'] == 'L')) {
2273
+				if (($chardata[$i]['type'] == 'N') AND ($chardata[$i]['sor'] == 'L') AND ($chardata[($i + 1)]['type'] == 'L')) {
2274 2274
 					$chardata[$i]['type'] = 'L';
2275 2275
 				} elseif (($chardata[$i]['type'] == 'N') AND
2276 2276
 				 (($chardata[$i]['sor'] == 'R') OR ($chardata[$i]['sor'] == 'EN') OR ($chardata[$i]['sor'] == 'AN')) AND
2277
-				 (($chardata[($i+1)]['type'] == 'R') OR ($chardata[($i+1)]['type'] == 'EN') OR ($chardata[($i+1)]['type'] == 'AN'))) {
2277
+				 (($chardata[($i + 1)]['type'] == 'R') OR ($chardata[($i + 1)]['type'] == 'EN') OR ($chardata[($i + 1)]['type'] == 'AN'))) {
2278 2278
 					$chardata[$i]['type'] = 'R';
2279 2279
 				} elseif ($chardata[$i]['type'] == 'N') {
2280 2280
 					// N2. Any remaining neutrals take the embedding direction
2281 2281
 					$chardata[$i]['type'] = $chardata[$i]['sor'];
2282 2282
 				}
2283
-			} elseif (($levcount > 0) AND ((($i+1) == $numchars) OR (($i+1) < $numchars) AND ($chardata[($i+1)]['level'] != $prevlevel))) {
2283
+			} elseif (($levcount > 0) AND ((($i + 1) == $numchars) OR (($i + 1) < $numchars) AND ($chardata[($i + 1)]['level'] != $prevlevel))) {
2284 2284
 				//last char
2285
-				if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[$i]['eor'] == 'L')) {
2285
+				if (($chardata[$i]['type'] == 'N') AND ($chardata[($i - 1)]['type'] == 'L') AND ($chardata[$i]['eor'] == 'L')) {
2286 2286
 					$chardata[$i]['type'] = 'L';
2287 2287
 				} elseif (($chardata[$i]['type'] == 'N') AND
2288
-				 (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
2288
+				 (($chardata[($i - 1)]['type'] == 'R') OR ($chardata[($i - 1)]['type'] == 'EN') OR ($chardata[($i - 1)]['type'] == 'AN')) AND
2289 2289
 				 (($chardata[$i]['eor'] == 'R') OR ($chardata[$i]['eor'] == 'EN') OR ($chardata[$i]['eor'] == 'AN'))) {
2290 2290
 					$chardata[$i]['type'] = 'R';
2291 2291
 				} elseif ($chardata[$i]['type'] == 'N') {
@@ -2306,8 +2306,8 @@  discard block
 block discarded – undo
2306 2306
 
2307 2307
 		// I1. For all characters with an even (left-to-right) embedding direction, those of type R go up one level and those of type AN or EN go up two levels.
2308 2308
 		// I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level.
2309
-		for ($i=0; $i < $numchars; ++$i) {
2310
-			$odd = $chardata[$i]['level'] % 2;
2309
+		for ($i = 0; $i < $numchars; ++$i) {
2310
+			$odd = $chardata[$i]['level']%2;
2311 2311
 			if ($odd) {
2312 2312
 				if (($chardata[$i]['type'] == 'L') OR ($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
2313 2313
 					$chardata[$i]['level'] += 1;
@@ -2319,7 +2319,7 @@  discard block
 block discarded – undo
2319 2319
 					$chardata[$i]['level'] += 2;
2320 2320
 				}
2321 2321
 			}
2322
-			$maxlevel = max($chardata[$i]['level'],$maxlevel);
2322
+			$maxlevel = max($chardata[$i]['level'], $maxlevel);
2323 2323
 		}
2324 2324
 
2325 2325
 		// L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
@@ -2327,14 +2327,14 @@  discard block
 block discarded – undo
2327 2327
 		//	2. Paragraph separators,
2328 2328
 		//	3. Any sequence of whitespace characters preceding a segment separator or paragraph separator, and
2329 2329
 		//	4. Any sequence of white space characters at the end of the line.
2330
-		for ($i=0; $i < $numchars; ++$i) {
2330
+		for ($i = 0; $i < $numchars; ++$i) {
2331 2331
 			if (($chardata[$i]['type'] == 'B') OR ($chardata[$i]['type'] == 'S')) {
2332 2332
 				$chardata[$i]['level'] = $pel;
2333 2333
 			} elseif ($chardata[$i]['type'] == 'WS') {
2334
-				$j = $i+1;
2334
+				$j = $i + 1;
2335 2335
 				while ($j < $numchars) {
2336 2336
 					if ((($chardata[$j]['type'] == 'B') OR ($chardata[$j]['type'] == 'S')) OR
2337
-						(($j == ($numchars-1)) AND ($chardata[$j]['type'] == 'WS'))) {
2337
+						(($j == ($numchars - 1)) AND ($chardata[$j]['type'] == 'WS'))) {
2338 2338
 						$chardata[$i]['level'] = $pel;
2339 2339
 						break;
2340 2340
 					} elseif ($chardata[$j]['type'] != 'WS') {
@@ -2348,13 +2348,13 @@  discard block
 block discarded – undo
2348 2348
 		// Arabic Shaping
2349 2349
 		// Cursively connected scripts, such as Arabic or Syriac, require the selection of positional character shapes that depend on adjacent characters. Shaping is logically applied after the Bidirectional Algorithm is used and is limited to characters within the same directional run.
2350 2350
 		if ($arabic) {
2351
-			$endedletter = array(1569,1570,1571,1572,1573,1575,1577,1583,1584,1585,1586,1608,1688);
2352
-			$alfletter = array(1570,1571,1573,1575);
2351
+			$endedletter = array(1569, 1570, 1571, 1572, 1573, 1575, 1577, 1583, 1584, 1585, 1586, 1608, 1688);
2352
+			$alfletter = array(1570, 1571, 1573, 1575);
2353 2353
 			$chardata2 = $chardata;
2354 2354
 			$laaletter = false;
2355 2355
 			$charAL = array();
2356 2356
 			$x = 0;
2357
-			for ($i=0; $i < $numchars; ++$i) {
2357
+			for ($i = 0; $i < $numchars; ++$i) {
2358 2358
 				if ((TCPDF_FONT_DATA::$uni_type[$chardata[$i]['char']] == 'AL') OR ($chardata[$i]['char'] == 32) OR ($chardata[$i]['char'] == 8204)) {
2359 2359
 					$charAL[$x] = $chardata[$i];
2360 2360
 					$charAL[$x]['i'] = $i;
@@ -2363,27 +2363,27 @@  discard block
 block discarded – undo
2363 2363
 				}
2364 2364
 			}
2365 2365
 			$numAL = $x;
2366
-			for ($i=0; $i < $numchars; ++$i) {
2366
+			for ($i = 0; $i < $numchars; ++$i) {
2367 2367
 				$thischar = $chardata[$i];
2368 2368
 				if ($i > 0) {
2369
-					$prevchar = $chardata[($i-1)];
2369
+					$prevchar = $chardata[($i - 1)];
2370 2370
 				} else {
2371 2371
 					$prevchar = false;
2372 2372
 				}
2373
-				if (($i+1) < $numchars) {
2374
-					$nextchar = $chardata[($i+1)];
2373
+				if (($i + 1) < $numchars) {
2374
+					$nextchar = $chardata[($i + 1)];
2375 2375
 				} else {
2376 2376
 					$nextchar = false;
2377 2377
 				}
2378 2378
 				if (TCPDF_FONT_DATA::$uni_type[$thischar['char']] == 'AL') {
2379 2379
 					$x = $thischar['x'];
2380 2380
 					if ($x > 0) {
2381
-						$prevchar = $charAL[($x-1)];
2381
+						$prevchar = $charAL[($x - 1)];
2382 2382
 					} else {
2383 2383
 						$prevchar = false;
2384 2384
 					}
2385
-					if (($x+1) < $numAL) {
2386
-						$nextchar = $charAL[($x+1)];
2385
+					if (($x + 1) < $numAL) {
2386
+						$nextchar = $charAL[($x + 1)];
2387 2387
 					} else {
2388 2388
 						$nextchar = false;
2389 2389
 					}
@@ -2392,7 +2392,7 @@  discard block
 block discarded – undo
2392 2392
 						$arabicarr = TCPDF_FONT_DATA::$uni_laa_array;
2393 2393
 						$laaletter = true;
2394 2394
 						if ($x > 1) {
2395
-							$prevchar = $charAL[($x-2)];
2395
+							$prevchar = $charAL[($x - 2)];
2396 2396
 						} else {
2397 2397
 							$prevchar = false;
2398 2398
 						}
@@ -2431,12 +2431,12 @@  discard block
 block discarded – undo
2431 2431
 						(($nextchar !== false) AND ($nextchar['char'] == 1567))) {
2432 2432
 						// final
2433 2433
 						if (($i > 1) AND ($thischar['char'] == 1607) AND
2434
-							($chardata[$i-1]['char'] == 1604) AND
2435
-							($chardata[$i-2]['char'] == 1604)) {
2434
+							($chardata[$i - 1]['char'] == 1604) AND
2435
+							($chardata[$i - 2]['char'] == 1604)) {
2436 2436
 							//Allah Word
2437 2437
 							// mark characters to delete with false
2438
-							$chardata2[$i-2]['char'] = false;
2439
-							$chardata2[$i-1]['char'] = false;
2438
+							$chardata2[$i - 2]['char'] = false;
2439
+							$chardata2[$i - 1]['char'] = false;
2440 2440
 							$chardata2[$i]['char'] = 65010;
2441 2441
 						} else {
2442 2442
 							if (($prevchar !== false) AND in_array($prevchar['char'], $endedletter)) {
@@ -2458,7 +2458,7 @@  discard block
 block discarded – undo
2458 2458
 					// if laa letter
2459 2459
 					if ($laaletter) {
2460 2460
 						// mark characters to delete with false
2461
-						$chardata2[($charAL[($x-1)]['i'])]['char'] = false;
2461
+						$chardata2[($charAL[($x - 1)]['i'])]['char'] = false;
2462 2462
 					}
2463 2463
 				} // end if AL (Arabic Letter)
2464 2464
 			} // end for each char
@@ -2466,12 +2466,12 @@  discard block
 block discarded – undo
2466 2466
 			 * Combining characters that can occur with Arabic Shadda (0651 HEX, 1617 DEC) are replaced.
2467 2467
 			 * Putting the combining mark and shadda in the same glyph allows us to avoid the two marks overlapping each other in an illegible manner.
2468 2468
 			 */
2469
-			for ($i = 0; $i < ($numchars-1); ++$i) {
2470
-				if (($chardata2[$i]['char'] == 1617) AND (isset(TCPDF_FONT_DATA::$uni_diacritics[($chardata2[$i+1]['char'])]))) {
2469
+			for ($i = 0; $i < ($numchars - 1); ++$i) {
2470
+				if (($chardata2[$i]['char'] == 1617) AND (isset(TCPDF_FONT_DATA::$uni_diacritics[($chardata2[$i + 1]['char'])]))) {
2471 2471
 					// check if the subtitution font is defined on current font
2472
-					if (isset($currentfont['cw'][(TCPDF_FONT_DATA::$uni_diacritics[($chardata2[$i+1]['char'])])])) {
2472
+					if (isset($currentfont['cw'][(TCPDF_FONT_DATA::$uni_diacritics[($chardata2[$i + 1]['char'])])])) {
2473 2473
 						$chardata2[$i]['char'] = false;
2474
-						$chardata2[$i+1]['char'] = TCPDF_FONT_DATA::$uni_diacritics[($chardata2[$i+1]['char'])];
2474
+						$chardata2[$i + 1]['char'] = TCPDF_FONT_DATA::$uni_diacritics[($chardata2[$i + 1]['char'])];
2475 2475
 					}
2476 2476
 				}
2477 2477
 			}
@@ -2490,11 +2490,11 @@  discard block
 block discarded – undo
2490 2490
 		}
2491 2491
 
2492 2492
 		// L2. From the highest level found in the text to the lowest odd level on each line, including intermediate levels not actually present in the text, reverse any contiguous sequence of characters that are at that level or higher.
2493
-		for ($j=$maxlevel; $j > 0; $j--) {
2493
+		for ($j = $maxlevel; $j > 0; $j--) {
2494 2494
 			$ordarray = Array();
2495 2495
 			$revarr = Array();
2496 2496
 			$onlevel = false;
2497
-			for ($i=0; $i < $numchars; ++$i) {
2497
+			for ($i = 0; $i < $numchars; ++$i) {
2498 2498
 				if ($chardata[$i]['level'] >= $j) {
2499 2499
 					$onlevel = true;
2500 2500
 					if (isset(TCPDF_FONT_DATA::$uni_mirror[$chardata[$i]['char']])) {
@@ -2534,7 +2534,7 @@  discard block
 block discarded – undo
2534 2534
 	 * @return float value in points
2535 2535
 	 * @public static
2536 2536
 	 */
2537
-	public static function getFontRefSize($size, $refsize=12) {
2537
+	public static function getFontRefSize($size, $refsize = 12) {
2538 2538
 		switch ($size) {
2539 2539
 			case 'xx-small': {
2540 2540
 				$size = ($refsize - 4);
Please login to merge, or discard this patch.
phpmyfaq/inc/libs/tcpdf/include/tcpdf_images.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 
156 156
 	/**
157 157
 	 * Extract info from a JPEG file without using the GD library.
158
-	 * @param $file (string) image file to parse
158
+	 * @param string $file (string) image file to parse
159 159
 	 * @return array structure containing the image data
160 160
 	 * @public static
161 161
 	 */
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 
231 231
 	/**
232 232
 	 * Extract info from a PNG file without using the GD library.
233
-	 * @param $file (string) image file to parse
233
+	 * @param string $file (string) image file to parse
234 234
 	 * @return array structure containing the image data
235 235
 	 * @public static
236 236
 	 */
Please login to merge, or discard this patch.
Indentation   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -51,304 +51,304 @@
 block discarded – undo
51 51
  */
52 52
 class TCPDF_IMAGES {
53 53
 
54
-	/**
55
-	 * Array of hinheritable SVG properties.
56
-	 * @since 5.0.000 (2010-05-02)
57
-	 * @public static
58
-	 */
59
-	public static $svginheritprop = array('clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cursor', 'direction', 'fill', 'fill-opacity', 'fill-rule', 'font', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'image-rendering', 'kerning', 'letter-spacing', 'marker', 'marker-end', 'marker-mid', 'marker-start', 'pointer-events', 'shape-rendering', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-rendering', 'visibility', 'word-spacing', 'writing-mode');
54
+    /**
55
+     * Array of hinheritable SVG properties.
56
+     * @since 5.0.000 (2010-05-02)
57
+     * @public static
58
+     */
59
+    public static $svginheritprop = array('clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cursor', 'direction', 'fill', 'fill-opacity', 'fill-rule', 'font', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'image-rendering', 'kerning', 'letter-spacing', 'marker', 'marker-end', 'marker-mid', 'marker-start', 'pointer-events', 'shape-rendering', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-rendering', 'visibility', 'word-spacing', 'writing-mode');
60 60
 
61 61
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
62 62
 
63
-	/**
64
-	 * Return the image type given the file name or array returned by getimagesize() function.
65
-	 * @param $imgfile (string) image file name
66
-	 * @param $iminfo (array) array of image information returned by getimagesize() function.
67
-	 * @return string image type
68
-	 * @since 4.8.017 (2009-11-27)
69
-	 * @public static
70
-	 */
71
-	public static function getImageFileType($imgfile, $iminfo=array()) {
72
-		$type = '';
73
-		if (isset($iminfo['mime']) AND !empty($iminfo['mime'])) {
74
-			$mime = explode('/', $iminfo['mime']);
75
-			if ((count($mime) > 1) AND ($mime[0] == 'image') AND (!empty($mime[1]))) {
76
-				$type = strtolower(trim($mime[1]));
77
-			}
78
-		}
79
-		if (empty($type)) {
80
-			$fileinfo = pathinfo($imgfile);
81
-			if (isset($fileinfo['extension']) AND (!TCPDF_STATIC::empty_string($fileinfo['extension']))) {
82
-				$type = strtolower(trim($fileinfo['extension']));
83
-			}
84
-		}
85
-		if ($type == 'jpg') {
86
-			$type = 'jpeg';
87
-		}
88
-		return $type;
89
-	}
63
+    /**
64
+     * Return the image type given the file name or array returned by getimagesize() function.
65
+     * @param $imgfile (string) image file name
66
+     * @param $iminfo (array) array of image information returned by getimagesize() function.
67
+     * @return string image type
68
+     * @since 4.8.017 (2009-11-27)
69
+     * @public static
70
+     */
71
+    public static function getImageFileType($imgfile, $iminfo=array()) {
72
+        $type = '';
73
+        if (isset($iminfo['mime']) AND !empty($iminfo['mime'])) {
74
+            $mime = explode('/', $iminfo['mime']);
75
+            if ((count($mime) > 1) AND ($mime[0] == 'image') AND (!empty($mime[1]))) {
76
+                $type = strtolower(trim($mime[1]));
77
+            }
78
+        }
79
+        if (empty($type)) {
80
+            $fileinfo = pathinfo($imgfile);
81
+            if (isset($fileinfo['extension']) AND (!TCPDF_STATIC::empty_string($fileinfo['extension']))) {
82
+                $type = strtolower(trim($fileinfo['extension']));
83
+            }
84
+        }
85
+        if ($type == 'jpg') {
86
+            $type = 'jpeg';
87
+        }
88
+        return $type;
89
+    }
90 90
 
91
-	/**
92
-	 * Set the transparency for the given GD image.
93
-	 * @param $new_image (image) GD image object
94
-	 * @param $image (image) GD image object.
95
-	 * return GD image object.
96
-	 * @since 4.9.016 (2010-04-20)
97
-	 * @public static
98
-	 */
99
-	public static function setGDImageTransparency($new_image, $image) {
100
-		// transparency index
101
-		$tid = imagecolortransparent($image);
102
-		// default transparency color
103
-		$tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
104
-		if ($tid >= 0) {
105
-			// get the colors for the transparency index
106
-			$tcol = imagecolorsforindex($image, $tid);
107
-		}
108
-		$tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
109
-		imagefill($new_image, 0, 0, $tid);
110
-		imagecolortransparent($new_image, $tid);
111
-		return $new_image;
112
-	}
91
+    /**
92
+     * Set the transparency for the given GD image.
93
+     * @param $new_image (image) GD image object
94
+     * @param $image (image) GD image object.
95
+     * return GD image object.
96
+     * @since 4.9.016 (2010-04-20)
97
+     * @public static
98
+     */
99
+    public static function setGDImageTransparency($new_image, $image) {
100
+        // transparency index
101
+        $tid = imagecolortransparent($image);
102
+        // default transparency color
103
+        $tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
104
+        if ($tid >= 0) {
105
+            // get the colors for the transparency index
106
+            $tcol = imagecolorsforindex($image, $tid);
107
+        }
108
+        $tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
109
+        imagefill($new_image, 0, 0, $tid);
110
+        imagecolortransparent($new_image, $tid);
111
+        return $new_image;
112
+    }
113 113
 
114
-	/**
115
-	 * Convert the loaded image to a PNG and then return a structure for the PDF creator.
116
-	 * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
117
-	 * @param $image (image) Image object.
118
-	 * return image PNG image object.
119
-	 * @since 4.9.016 (2010-04-20)
120
-	 * @public static
121
-	 */
122
-	public static function _toPNG($image) {
123
-		// set temporary image file name
124
-		$tempname = TCPDF_STATIC::getObjFilename('img');
125
-		// turn off interlaced mode
126
-		imageinterlace($image, 0);
127
-		// create temporary PNG image
128
-		imagepng($image, $tempname);
129
-		// remove image from memory
130
-		imagedestroy($image);
131
-		// get PNG image data
132
-		$retvars = self::_parsepng($tempname);
133
-		// tidy up by removing temporary image
134
-		unlink($tempname);
135
-		return $retvars;
136
-	}
114
+    /**
115
+     * Convert the loaded image to a PNG and then return a structure for the PDF creator.
116
+     * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
117
+     * @param $image (image) Image object.
118
+     * return image PNG image object.
119
+     * @since 4.9.016 (2010-04-20)
120
+     * @public static
121
+     */
122
+    public static function _toPNG($image) {
123
+        // set temporary image file name
124
+        $tempname = TCPDF_STATIC::getObjFilename('img');
125
+        // turn off interlaced mode
126
+        imageinterlace($image, 0);
127
+        // create temporary PNG image
128
+        imagepng($image, $tempname);
129
+        // remove image from memory
130
+        imagedestroy($image);
131
+        // get PNG image data
132
+        $retvars = self::_parsepng($tempname);
133
+        // tidy up by removing temporary image
134
+        unlink($tempname);
135
+        return $retvars;
136
+    }
137 137
 
138
-	/**
139
-	 * Convert the loaded image to a JPEG and then return a structure for the PDF creator.
140
-	 * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
141
-	 * @param $image (image) Image object.
142
-	 * @param $quality (int) JPEG quality.
143
-	 * return image JPEG image object.
144
-	 * @public static
145
-	 */
146
-	public static function _toJPEG($image, $quality) {
147
-		$tempname = TCPDF_STATIC::getObjFilename('img');
148
-		imagejpeg($image, $tempname, $quality);
149
-		imagedestroy($image);
150
-		$retvars = self::_parsejpeg($tempname);
151
-		// tidy up by removing temporary image
152
-		unlink($tempname);
153
-		return $retvars;
154
-	}
138
+    /**
139
+     * Convert the loaded image to a JPEG and then return a structure for the PDF creator.
140
+     * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
141
+     * @param $image (image) Image object.
142
+     * @param $quality (int) JPEG quality.
143
+     * return image JPEG image object.
144
+     * @public static
145
+     */
146
+    public static function _toJPEG($image, $quality) {
147
+        $tempname = TCPDF_STATIC::getObjFilename('img');
148
+        imagejpeg($image, $tempname, $quality);
149
+        imagedestroy($image);
150
+        $retvars = self::_parsejpeg($tempname);
151
+        // tidy up by removing temporary image
152
+        unlink($tempname);
153
+        return $retvars;
154
+    }
155 155
 
156
-	/**
157
-	 * Extract info from a JPEG file without using the GD library.
158
-	 * @param $file (string) image file to parse
159
-	 * @return array structure containing the image data
160
-	 * @public static
161
-	 */
162
-	public static function _parsejpeg($file) {
163
-		$a = getimagesize($file);
164
-		if (empty($a)) {
165
-			//Missing or incorrect image file
166
-			return false;
167
-		}
168
-		if ($a[2] != 2) {
169
-			// Not a JPEG file
170
-			return false;
171
-		}
172
-		// bits per pixel
173
-		$bpc = isset($a['bits']) ? intval($a['bits']) : 8;
174
-		// number of image channels
175
-		if (!isset($a['channels'])) {
176
-			$channels = 3;
177
-		} else {
178
-			$channels = intval($a['channels']);
179
-		}
180
-		// default colour space
181
-		switch ($channels) {
182
-			case 1: {
183
-				$colspace = 'DeviceGray';
184
-				break;
185
-			}
186
-			case 3: {
187
-				$colspace = 'DeviceRGB';
188
-				break;
189
-			}
190
-			case 4: {
191
-				$colspace = 'DeviceCMYK';
192
-				break;
193
-			}
194
-			default: {
195
-				$channels = 3;
196
-				$colspace = 'DeviceRGB';
197
-				break;
198
-			}
199
-		}
200
-		// get file content
201
-		$data = file_get_contents($file);
202
-		// check for embedded ICC profile
203
-		$icc = array();
204
-		$offset = 0;
205
-		while (($pos = strpos($data, "ICC_PROFILE\0", $offset)) !== false) {
206
-			// get ICC sequence length
207
-			$length = (TCPDF_STATIC::_getUSHORT($data, ($pos - 2)) - 16);
208
-			// marker sequence number
209
-			$msn = max(1, ord($data[($pos + 12)]));
210
-			// number of markers (total of APP2 used)
211
-			$nom = max(1, ord($data[($pos + 13)]));
212
-			// get sequence segment
213
-			$icc[($msn - 1)] = substr($data, ($pos + 14), $length);
214
-			// move forward to next sequence
215
-			$offset = ($pos + 14 + $length);
216
-		}
217
-		// order and compact ICC segments
218
-		if (count($icc) > 0) {
219
-			ksort($icc);
220
-			$icc = implode('', $icc);
221
-			if ((ord($icc[36]) != 0x61) OR (ord($icc[37]) != 0x63) OR (ord($icc[38]) != 0x73) OR (ord($icc[39]) != 0x70)) {
222
-				// invalid ICC profile
223
-				$icc = false;
224
-			}
225
-		} else {
226
-			$icc = false;
227
-		}
228
-		return array('w' => $a[0], 'h' => $a[1], 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
229
-	}
156
+    /**
157
+     * Extract info from a JPEG file without using the GD library.
158
+     * @param $file (string) image file to parse
159
+     * @return array structure containing the image data
160
+     * @public static
161
+     */
162
+    public static function _parsejpeg($file) {
163
+        $a = getimagesize($file);
164
+        if (empty($a)) {
165
+            //Missing or incorrect image file
166
+            return false;
167
+        }
168
+        if ($a[2] != 2) {
169
+            // Not a JPEG file
170
+            return false;
171
+        }
172
+        // bits per pixel
173
+        $bpc = isset($a['bits']) ? intval($a['bits']) : 8;
174
+        // number of image channels
175
+        if (!isset($a['channels'])) {
176
+            $channels = 3;
177
+        } else {
178
+            $channels = intval($a['channels']);
179
+        }
180
+        // default colour space
181
+        switch ($channels) {
182
+            case 1: {
183
+                $colspace = 'DeviceGray';
184
+                break;
185
+            }
186
+            case 3: {
187
+                $colspace = 'DeviceRGB';
188
+                break;
189
+            }
190
+            case 4: {
191
+                $colspace = 'DeviceCMYK';
192
+                break;
193
+            }
194
+            default: {
195
+                $channels = 3;
196
+                $colspace = 'DeviceRGB';
197
+                break;
198
+            }
199
+        }
200
+        // get file content
201
+        $data = file_get_contents($file);
202
+        // check for embedded ICC profile
203
+        $icc = array();
204
+        $offset = 0;
205
+        while (($pos = strpos($data, "ICC_PROFILE\0", $offset)) !== false) {
206
+            // get ICC sequence length
207
+            $length = (TCPDF_STATIC::_getUSHORT($data, ($pos - 2)) - 16);
208
+            // marker sequence number
209
+            $msn = max(1, ord($data[($pos + 12)]));
210
+            // number of markers (total of APP2 used)
211
+            $nom = max(1, ord($data[($pos + 13)]));
212
+            // get sequence segment
213
+            $icc[($msn - 1)] = substr($data, ($pos + 14), $length);
214
+            // move forward to next sequence
215
+            $offset = ($pos + 14 + $length);
216
+        }
217
+        // order and compact ICC segments
218
+        if (count($icc) > 0) {
219
+            ksort($icc);
220
+            $icc = implode('', $icc);
221
+            if ((ord($icc[36]) != 0x61) OR (ord($icc[37]) != 0x63) OR (ord($icc[38]) != 0x73) OR (ord($icc[39]) != 0x70)) {
222
+                // invalid ICC profile
223
+                $icc = false;
224
+            }
225
+        } else {
226
+            $icc = false;
227
+        }
228
+        return array('w' => $a[0], 'h' => $a[1], 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
229
+    }
230 230
 
231
-	/**
232
-	 * Extract info from a PNG file without using the GD library.
233
-	 * @param $file (string) image file to parse
234
-	 * @return array structure containing the image data
235
-	 * @public static
236
-	 */
237
-	public static function _parsepng($file) {
238
-		$f = @fopen($file, 'rb');
239
-		if ($f === false) {
240
-			// Can't open image file
241
-			return false;
242
-		}
243
-		//Check signature
244
-		if (fread($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
245
-			// Not a PNG file
246
-			return false;
247
-		}
248
-		//Read header chunk
249
-		fread($f, 4);
250
-		if (fread($f, 4) != 'IHDR') {
251
-			//Incorrect PNG file
252
-			return false;
253
-		}
254
-		$w = TCPDF_STATIC::_freadint($f);
255
-		$h = TCPDF_STATIC::_freadint($f);
256
-		$bpc = ord(fread($f, 1));
257
-		$ct = ord(fread($f, 1));
258
-		if ($ct == 0) {
259
-			$colspace = 'DeviceGray';
260
-		} elseif ($ct == 2) {
261
-			$colspace = 'DeviceRGB';
262
-		} elseif ($ct == 3) {
263
-			$colspace = 'Indexed';
264
-		} else {
265
-			// alpha channel
266
-			fclose($f);
267
-			return 'pngalpha';
268
-		}
269
-		if (ord(fread($f, 1)) != 0) {
270
-			// Unknown compression method
271
-			fclose($f);
272
-			return false;
273
-		}
274
-		if (ord(fread($f, 1)) != 0) {
275
-			// Unknown filter method
276
-			fclose($f);
277
-			return false;
278
-		}
279
-		if (ord(fread($f, 1)) != 0) {
280
-			// Interlacing not supported
281
-			fclose($f);
282
-			return false;
283
-		}
284
-		fread($f, 4);
285
-		$channels = ($ct == 2 ? 3 : 1);
286
-		$parms = '/DecodeParms << /Predictor 15 /Colors '.$channels.' /BitsPerComponent '.$bpc.' /Columns '.$w.' >>';
287
-		//Scan chunks looking for palette, transparency and image data
288
-		$pal = '';
289
-		$trns = '';
290
-		$data = '';
291
-		$icc = false;
292
-		do {
293
-			$n = TCPDF_STATIC::_freadint($f);
294
-			$type = fread($f, 4);
295
-			if ($type == 'PLTE') {
296
-				// read palette
297
-				$pal = TCPDF_STATIC::rfread($f, $n);
298
-				fread($f, 4);
299
-			} elseif ($type == 'tRNS') {
300
-				// read transparency info
301
-				$t = TCPDF_STATIC::rfread($f, $n);
302
-				if ($ct == 0) { // DeviceGray
303
-					$trns = array(ord($t[1]));
304
-				} elseif ($ct == 2) { // DeviceRGB
305
-					$trns = array(ord($t[1]), ord($t[3]), ord($t[5]));
306
-				} else { // Indexed
307
-					if ($n > 0) {
308
-						$trns = array();
309
-						for ($i = 0; $i < $n; ++ $i) {
310
-							$trns[] = ord($t{$i});
311
-						}
312
-					}
313
-				}
314
-				fread($f, 4);
315
-			} elseif ($type == 'IDAT') {
316
-				// read image data block
317
-				$data .= TCPDF_STATIC::rfread($f, $n);
318
-				fread($f, 4);
319
-			} elseif ($type == 'iCCP') {
320
-				// skip profile name
321
-				$len = 0;
322
-				while ((ord(fread($f, 1)) > 0) AND ($len < 80)) {
323
-					++$len;
324
-				}
325
-				// skip null separator
326
-				fread($f, 1);
327
-				// get compression method
328
-				if (ord(fread($f, 1)) != 0) {
329
-					// Unknown filter method
330
-					fclose($f);
331
-					return false;
332
-				}
333
-				// read ICC Color Profile
334
-				$icc = TCPDF_STATIC::rfread($f, ($n - $len - 2));
335
-				// decompress profile
336
-				$icc = gzuncompress($icc);
337
-				fread($f, 4);
338
-			} elseif ($type == 'IEND') {
339
-				break;
340
-			} else {
341
-				TCPDF_STATIC::rfread($f, $n + 4);
342
-			}
343
-		} while ($n);
344
-		if (($colspace == 'Indexed') AND (empty($pal))) {
345
-			// Missing palette
346
-			fclose($f);
347
-			return false;
348
-		}
349
-		fclose($f);
350
-		return array('w' => $w, 'h' => $h, 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
351
-	}
231
+    /**
232
+     * Extract info from a PNG file without using the GD library.
233
+     * @param $file (string) image file to parse
234
+     * @return array structure containing the image data
235
+     * @public static
236
+     */
237
+    public static function _parsepng($file) {
238
+        $f = @fopen($file, 'rb');
239
+        if ($f === false) {
240
+            // Can't open image file
241
+            return false;
242
+        }
243
+        //Check signature
244
+        if (fread($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
245
+            // Not a PNG file
246
+            return false;
247
+        }
248
+        //Read header chunk
249
+        fread($f, 4);
250
+        if (fread($f, 4) != 'IHDR') {
251
+            //Incorrect PNG file
252
+            return false;
253
+        }
254
+        $w = TCPDF_STATIC::_freadint($f);
255
+        $h = TCPDF_STATIC::_freadint($f);
256
+        $bpc = ord(fread($f, 1));
257
+        $ct = ord(fread($f, 1));
258
+        if ($ct == 0) {
259
+            $colspace = 'DeviceGray';
260
+        } elseif ($ct == 2) {
261
+            $colspace = 'DeviceRGB';
262
+        } elseif ($ct == 3) {
263
+            $colspace = 'Indexed';
264
+        } else {
265
+            // alpha channel
266
+            fclose($f);
267
+            return 'pngalpha';
268
+        }
269
+        if (ord(fread($f, 1)) != 0) {
270
+            // Unknown compression method
271
+            fclose($f);
272
+            return false;
273
+        }
274
+        if (ord(fread($f, 1)) != 0) {
275
+            // Unknown filter method
276
+            fclose($f);
277
+            return false;
278
+        }
279
+        if (ord(fread($f, 1)) != 0) {
280
+            // Interlacing not supported
281
+            fclose($f);
282
+            return false;
283
+        }
284
+        fread($f, 4);
285
+        $channels = ($ct == 2 ? 3 : 1);
286
+        $parms = '/DecodeParms << /Predictor 15 /Colors '.$channels.' /BitsPerComponent '.$bpc.' /Columns '.$w.' >>';
287
+        //Scan chunks looking for palette, transparency and image data
288
+        $pal = '';
289
+        $trns = '';
290
+        $data = '';
291
+        $icc = false;
292
+        do {
293
+            $n = TCPDF_STATIC::_freadint($f);
294
+            $type = fread($f, 4);
295
+            if ($type == 'PLTE') {
296
+                // read palette
297
+                $pal = TCPDF_STATIC::rfread($f, $n);
298
+                fread($f, 4);
299
+            } elseif ($type == 'tRNS') {
300
+                // read transparency info
301
+                $t = TCPDF_STATIC::rfread($f, $n);
302
+                if ($ct == 0) { // DeviceGray
303
+                    $trns = array(ord($t[1]));
304
+                } elseif ($ct == 2) { // DeviceRGB
305
+                    $trns = array(ord($t[1]), ord($t[3]), ord($t[5]));
306
+                } else { // Indexed
307
+                    if ($n > 0) {
308
+                        $trns = array();
309
+                        for ($i = 0; $i < $n; ++ $i) {
310
+                            $trns[] = ord($t{$i});
311
+                        }
312
+                    }
313
+                }
314
+                fread($f, 4);
315
+            } elseif ($type == 'IDAT') {
316
+                // read image data block
317
+                $data .= TCPDF_STATIC::rfread($f, $n);
318
+                fread($f, 4);
319
+            } elseif ($type == 'iCCP') {
320
+                // skip profile name
321
+                $len = 0;
322
+                while ((ord(fread($f, 1)) > 0) AND ($len < 80)) {
323
+                    ++$len;
324
+                }
325
+                // skip null separator
326
+                fread($f, 1);
327
+                // get compression method
328
+                if (ord(fread($f, 1)) != 0) {
329
+                    // Unknown filter method
330
+                    fclose($f);
331
+                    return false;
332
+                }
333
+                // read ICC Color Profile
334
+                $icc = TCPDF_STATIC::rfread($f, ($n - $len - 2));
335
+                // decompress profile
336
+                $icc = gzuncompress($icc);
337
+                fread($f, 4);
338
+            } elseif ($type == 'IEND') {
339
+                break;
340
+            } else {
341
+                TCPDF_STATIC::rfread($f, $n + 4);
342
+            }
343
+        } while ($n);
344
+        if (($colspace == 'Indexed') AND (empty($pal))) {
345
+            // Missing palette
346
+            fclose($f);
347
+            return false;
348
+        }
349
+        fclose($f);
350
+        return array('w' => $w, 'h' => $h, 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
351
+    }
352 352
 
353 353
 } // END OF TCPDF_IMAGES CLASS
354 354
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
68 68
 	 * @since 4.8.017 (2009-11-27)
69 69
 	 * @public static
70 70
 	 */
71
-	public static function getImageFileType($imgfile, $iminfo=array()) {
71
+	public static function getImageFileType($imgfile, $iminfo = array()) {
72 72
 		$type = '';
73 73
 		if (isset($iminfo['mime']) AND !empty($iminfo['mime'])) {
74 74
 			$mime = explode('/', $iminfo['mime']);
Please login to merge, or discard this patch.
phpmyfaq/inc/libs/tcpdf/include/tcpdf_static.php 3 patches
Doc Comments   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 
111 111
 	/**
112 112
 	 * Return the current TCPDF version.
113
-	 * @return TCPDF version string
113
+	 * @return string version string
114 114
 	 * @since 5.9.012 (2010-11-10)
115 115
 	 * @public static
116 116
 	 */
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 
121 121
 	/**
122 122
 	 * Return the current TCPDF producer.
123
-	 * @return TCPDF producer string
123
+	 * @return string producer string
124 124
 	 * @since 6.0.000 (2013-03-16)
125 125
 	 * @public static
126 126
 	 */
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 	 * <li>FR_TELLIERE (340x440 mm ; 13.39x17.32 in)</li>
472 472
 	 * <li>FR_POT (310x400 mm ; 12.20x15.75 in)</li>
473 473
 	 * </ul>
474
-	 * @return array containing page width and height in points
474
+	 * @return double[] containing page width and height in points
475 475
 	 * @since 5.0.010 (2010-05-17)
476 476
 	 * @public static
477 477
 	 */
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
 	/**
1116 1116
 	* Escape some special characters (&lt; &gt; &amp;) for XML output.
1117 1117
 	* @param $str (string) Input string to convert.
1118
-	* @return converted string
1118
+	* @return string string
1119 1119
 	* @since 5.9.121 (2011-09-28)
1120 1120
 	 * @public static
1121 1121
 	 */
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
 
1263 1263
 	/**
1264 1264
 	 * Get UFWORD from string (Big Endian 16-bit unsigned integer).
1265
-	 * @param $str (string) string from where to extract value
1265
+	 * @param string $str (string) string from where to extract value
1266 1266
 	 * @param $offset (int) point from where to read the data
1267 1267
 	 * @return int 16 bit value
1268 1268
 	 * @author Nicola Asuni
@@ -1276,9 +1276,9 @@  discard block
 block discarded – undo
1276 1276
 
1277 1277
 	/**
1278 1278
 	 * Get FIXED from string (32-bit signed fixed-point number (16.16).
1279
-	 * @param $str (string) string from where to extract value
1280
-	 * @param $offset (int) point from where to read the data
1281
-	 * @return int 16 bit value
1279
+	 * @param string $str (string) string from where to extract value
1280
+	 * @param integer $offset (int) point from where to read the data
1281
+	 * @return double 16 bit value
1282 1282
 	 * @author Nicola Asuni
1283 1283
 	 * @since 5.9.123 (2011-09-30)
1284 1284
 	 * @public static
@@ -1295,7 +1295,7 @@  discard block
 block discarded – undo
1295 1295
 	/**
1296 1296
 	 * Get BYTE from string (8-bit unsigned integer).
1297 1297
 	 * @param $str (string) String from where to extract value.
1298
-	 * @param $offset (int) Point from where to read the data.
1298
+	 * @param integer $offset (int) Point from where to read the data.
1299 1299
 	 * @return int 8 bit value
1300 1300
 	 * @author Nicola Asuni
1301 1301
 	 * @since 5.2.000 (2010-06-02)
@@ -1310,7 +1310,7 @@  discard block
 block discarded – undo
1310 1310
 	 * Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached.
1311 1311
 	 * @param $handle (resource)
1312 1312
 	 * @param $length (int)
1313
-	 * @return Returns the read string or FALSE in case of error.
1313
+	 * @return false|string the read string or FALSE in case of error.
1314 1314
 	 * @author Nicola Asuni
1315 1315
 	 * @since 4.5.027 (2009-03-16)
1316 1316
 	 * @public static
@@ -1525,7 +1525,7 @@  discard block
 block discarded – undo
1525 1525
 	/**
1526 1526
 	 * Convert string to hexadecimal string (byte string)
1527 1527
 	 * @param $s (string) string to convert
1528
-	 * @return byte string
1528
+	 * @return string string
1529 1529
 	 * @since 5.0.010 (2010-05-17)
1530 1530
 	 * @author Nicola Asuni
1531 1531
 	 * @public static
@@ -2135,7 +2135,7 @@  discard block
 block discarded – undo
2135 2135
 	 * Returns true if the CSS selector is valid for the selected HTML tag
2136 2136
 	 * @param $dom (array) array of HTML tags and properties
2137 2137
 	 * @param $key (int) key of the current HTML tag
2138
-	 * @param $selector (string) CSS selector string
2138
+	 * @param string $selector (string) CSS selector string
2139 2139
 	 * @return true if the selector is valid, false otherwise
2140 2140
 	 * @since 5.1.000 (2010-05-25)
2141 2141
 	 * @public static
@@ -2438,7 +2438,7 @@  discard block
 block discarded – undo
2438 2438
 	 * @param $haystack (string) The string to search in.
2439 2439
 	 * @param $needle (string) substring to search.
2440 2440
 	 * @param $offset (int) May be specified to begin searching an arbitrary number of characters into the string.
2441
-	 * @return Returns the position where the needle exists. Returns FALSE if the needle was not found.
2441
+	 * @return integer the position where the needle exists. Returns FALSE if the needle was not found.
2442 2442
 	 * @since 4.8.038 (2010-03-13)
2443 2443
 	 * @public static
2444 2444
 	 */
@@ -2452,7 +2452,7 @@  discard block
 block discarded – undo
2452 2452
 	/**
2453 2453
 	 * Serialize an array of parameters to be used with TCPDF tag in HTML code.
2454 2454
 	 * @param $pararray (array) parameters array
2455
-	 * @return sting containing serialized data
2455
+	 * @return string containing serialized data
2456 2456
 	 * @since 4.9.006 (2010-04-02)
2457 2457
 	 * @public static
2458 2458
 	 */
@@ -2588,7 +2588,7 @@  discard block
 block discarded – undo
2588 2588
 	 * Get the product of two SVG tranformation matrices
2589 2589
 	 * @param $ta (array) first SVG tranformation matrix
2590 2590
 	 * @param $tb (array) second SVG tranformation matrix
2591
-	 * @return transformation array
2591
+	 * @return double[] array
2592 2592
 	 * @author Nicola Asuni
2593 2593
 	 * @since 5.0.000 (2010-05-02)
2594 2594
 	 * @public static
@@ -2726,11 +2726,11 @@  discard block
 block discarded – undo
2726 2726
 	/**
2727 2727
 	 * Split string by a regular expression.
2728 2728
 	 * This is a wrapper for the preg_split function to avoid the bug: https://bugs.php.net/bug.php?id=45850
2729
-	 * @param $pattern (string) The regular expression pattern to search for without the modifiers, as a string.
2730
-	 * @param $modifiers (string) The modifiers part of the pattern,
2729
+	 * @param string $pattern (string) The regular expression pattern to search for without the modifiers, as a string.
2730
+	 * @param string $modifiers (string) The modifiers part of the pattern,
2731 2731
 	 * @param $subject (string) The input string.
2732
-	 * @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.
2733
-	 * @param $flags (int) The flags as specified on the preg_split PHP function.
2732
+	 * @param integer $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.
2733
+	 * @param integer $flags (int) The flags as specified on the preg_split PHP function.
2734 2734
 	 * @return Returns an array containing substrings of subject split along boundaries matched by pattern.modifier
2735 2735
 	 * @author Nicola Asuni
2736 2736
 	 * @since 6.0.023
Please login to merge, or discard this patch.
Indentation   +2783 added lines, -2783 removed lines patch added patch discarded remove patch
@@ -51,2789 +51,2789 @@
 block discarded – undo
51 51
  */
52 52
 class TCPDF_STATIC {
53 53
 
54
-	/**
55
-	 * Current TCPDF version.
56
-	 * @private static
57
-	 */
58
-	private static $tcpdf_version = '6.0.078';
59
-
60
-	/**
61
-	 * String alias for total number of pages.
62
-	 * @public static
63
-	 */
64
-	public static $alias_tot_pages = '{:ptp:}';
65
-
66
-	/**
67
-	 * String alias for page number.
68
-	 * @public static
69
-	 */
70
-	public static $alias_num_page = '{:pnp:}';
71
-
72
-	/**
73
-	 * String alias for total number of pages in a single group.
74
-	 * @public static
75
-	 */
76
-	public static $alias_group_tot_pages = '{:ptg:}';
77
-
78
-	/**
79
-	 * String alias for group page number.
80
-	 * @public static
81
-	 */
82
-	public static $alias_group_num_page = '{:png:}';
83
-
84
-	/**
85
-	 * String alias for right shift compensation used to correctly align page numbers on the right.
86
-	 * @public static
87
-	 */
88
-	public static $alias_right_shift = '{rsc:';
89
-
90
-	/**
91
-	 * Encryption padding string.
92
-	 * @public static
93
-	 */
94
-	public static $enc_padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
95
-
96
-	/**
97
-	 * ByteRange placemark used during digital signature process.
98
-	 * @since 4.6.028 (2009-08-25)
99
-	 * @public static
100
-	 */
101
-	public static $byterange_string = '/ByteRange[0 ********** ********** **********]';
102
-
103
-	/**
104
-	 * Array page boxes names
105
-	 * @public static
106
-	 */
107
-	public static $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
108
-
109
-	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
110
-
111
-	/**
112
-	 * Return the current TCPDF version.
113
-	 * @return TCPDF version string
114
-	 * @since 5.9.012 (2010-11-10)
115
-	 * @public static
116
-	 */
117
-	public static function getTCPDFVersion() {
118
-		return self::$tcpdf_version;
119
-	}
120
-
121
-	/**
122
-	 * Return the current TCPDF producer.
123
-	 * @return TCPDF producer string
124
-	 * @since 6.0.000 (2013-03-16)
125
-	 * @public static
126
-	 */
127
-	public static function getTCPDFProducer() {
128
-		return "\x54\x43\x50\x44\x46\x20".self::getTCPDFVersion()."\x20\x28\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
129
-	}
130
-
131
-	/**
132
-	 * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
133
-	 * @param $mqr (boolean) FALSE for off, TRUE for on.
134
-	 * @since 4.6.025 (2009-08-17)
135
-	 * @public static
136
-	 */
137
-	public static function set_mqr($mqr) {
138
-		if (!defined('PHP_VERSION_ID')) {
139
-			$version = PHP_VERSION;
140
-			define('PHP_VERSION_ID', (($version[0] * 10000) + ($version[2] * 100) + $version[4]));
141
-		}
142
-		if (PHP_VERSION_ID < 50300) {
143
-			@set_magic_quotes_runtime($mqr);
144
-		}
145
-	}
146
-
147
-	/**
148
-	 * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
149
-	 * @return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
150
-	 * @since 4.6.025 (2009-08-17)
151
-	 * @public static
152
-	 */
153
-	public static function get_mqr() {
154
-		if (!defined('PHP_VERSION_ID')) {
155
-			$version = PHP_VERSION;
156
-			define('PHP_VERSION_ID', (($version[0] * 10000) + ($version[2] * 100) + $version[4]));
157
-		}
158
-		if (PHP_VERSION_ID < 50300) {
159
-			return @get_magic_quotes_runtime();
160
-		}
161
-		return 0;
162
-	}
163
-
164
-	/**
165
-	 * Get page dimensions from format name.
166
-	 * @param $format (mixed) The format name. It can be: <ul>
167
-	 * <li><b>ISO 216 A Series + 2 SIS 014711 extensions</b></li>
168
-	 * <li>A0 (841x1189 mm ; 33.11x46.81 in)</li>
169
-	 * <li>A1 (594x841 mm ; 23.39x33.11 in)</li>
170
-	 * <li>A2 (420x594 mm ; 16.54x23.39 in)</li>
171
-	 * <li>A3 (297x420 mm ; 11.69x16.54 in)</li>
172
-	 * <li>A4 (210x297 mm ; 8.27x11.69 in)</li>
173
-	 * <li>A5 (148x210 mm ; 5.83x8.27 in)</li>
174
-	 * <li>A6 (105x148 mm ; 4.13x5.83 in)</li>
175
-	 * <li>A7 (74x105 mm ; 2.91x4.13 in)</li>
176
-	 * <li>A8 (52x74 mm ; 2.05x2.91 in)</li>
177
-	 * <li>A9 (37x52 mm ; 1.46x2.05 in)</li>
178
-	 * <li>A10 (26x37 mm ; 1.02x1.46 in)</li>
179
-	 * <li>A11 (18x26 mm ; 0.71x1.02 in)</li>
180
-	 * <li>A12 (13x18 mm ; 0.51x0.71 in)</li>
181
-	 * <li><b>ISO 216 B Series + 2 SIS 014711 extensions</b></li>
182
-	 * <li>B0 (1000x1414 mm ; 39.37x55.67 in)</li>
183
-	 * <li>B1 (707x1000 mm ; 27.83x39.37 in)</li>
184
-	 * <li>B2 (500x707 mm ; 19.69x27.83 in)</li>
185
-	 * <li>B3 (353x500 mm ; 13.90x19.69 in)</li>
186
-	 * <li>B4 (250x353 mm ; 9.84x13.90 in)</li>
187
-	 * <li>B5 (176x250 mm ; 6.93x9.84 in)</li>
188
-	 * <li>B6 (125x176 mm ; 4.92x6.93 in)</li>
189
-	 * <li>B7 (88x125 mm ; 3.46x4.92 in)</li>
190
-	 * <li>B8 (62x88 mm ; 2.44x3.46 in)</li>
191
-	 * <li>B9 (44x62 mm ; 1.73x2.44 in)</li>
192
-	 * <li>B10 (31x44 mm ; 1.22x1.73 in)</li>
193
-	 * <li>B11 (22x31 mm ; 0.87x1.22 in)</li>
194
-	 * <li>B12 (15x22 mm ; 0.59x0.87 in)</li>
195
-	 * <li><b>ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION</b></li>
196
-	 * <li>C0 (917x1297 mm ; 36.10x51.06 in)</li>
197
-	 * <li>C1 (648x917 mm ; 25.51x36.10 in)</li>
198
-	 * <li>C2 (458x648 mm ; 18.03x25.51 in)</li>
199
-	 * <li>C3 (324x458 mm ; 12.76x18.03 in)</li>
200
-	 * <li>C4 (229x324 mm ; 9.02x12.76 in)</li>
201
-	 * <li>C5 (162x229 mm ; 6.38x9.02 in)</li>
202
-	 * <li>C6 (114x162 mm ; 4.49x6.38 in)</li>
203
-	 * <li>C7 (81x114 mm ; 3.19x4.49 in)</li>
204
-	 * <li>C8 (57x81 mm ; 2.24x3.19 in)</li>
205
-	 * <li>C9 (40x57 mm ; 1.57x2.24 in)</li>
206
-	 * <li>C10 (28x40 mm ; 1.10x1.57 in)</li>
207
-	 * <li>C11 (20x28 mm ; 0.79x1.10 in)</li>
208
-	 * <li>C12 (14x20 mm ; 0.55x0.79 in)</li>
209
-	 * <li>C76 (81x162 mm ; 3.19x6.38 in)</li>
210
-	 * <li>DL (110x220 mm ; 4.33x8.66 in)</li>
211
-	 * <li><b>SIS 014711 E Series</b></li>
212
-	 * <li>E0 (879x1241 mm ; 34.61x48.86 in)</li>
213
-	 * <li>E1 (620x879 mm ; 24.41x34.61 in)</li>
214
-	 * <li>E2 (440x620 mm ; 17.32x24.41 in)</li>
215
-	 * <li>E3 (310x440 mm ; 12.20x17.32 in)</li>
216
-	 * <li>E4 (220x310 mm ; 8.66x12.20 in)</li>
217
-	 * <li>E5 (155x220 mm ; 6.10x8.66 in)</li>
218
-	 * <li>E6 (110x155 mm ; 4.33x6.10 in)</li>
219
-	 * <li>E7 (78x110 mm ; 3.07x4.33 in)</li>
220
-	 * <li>E8 (55x78 mm ; 2.17x3.07 in)</li>
221
-	 * <li>E9 (39x55 mm ; 1.54x2.17 in)</li>
222
-	 * <li>E10 (27x39 mm ; 1.06x1.54 in)</li>
223
-	 * <li>E11 (19x27 mm ; 0.75x1.06 in)</li>
224
-	 * <li>E12 (13x19 mm ; 0.51x0.75 in)</li>
225
-	 * <li><b>SIS 014711 G Series</b></li>
226
-	 * <li>G0 (958x1354 mm ; 37.72x53.31 in)</li>
227
-	 * <li>G1 (677x958 mm ; 26.65x37.72 in)</li>
228
-	 * <li>G2 (479x677 mm ; 18.86x26.65 in)</li>
229
-	 * <li>G3 (338x479 mm ; 13.31x18.86 in)</li>
230
-	 * <li>G4 (239x338 mm ; 9.41x13.31 in)</li>
231
-	 * <li>G5 (169x239 mm ; 6.65x9.41 in)</li>
232
-	 * <li>G6 (119x169 mm ; 4.69x6.65 in)</li>
233
-	 * <li>G7 (84x119 mm ; 3.31x4.69 in)</li>
234
-	 * <li>G8 (59x84 mm ; 2.32x3.31 in)</li>
235
-	 * <li>G9 (42x59 mm ; 1.65x2.32 in)</li>
236
-	 * <li>G10 (29x42 mm ; 1.14x1.65 in)</li>
237
-	 * <li>G11 (21x29 mm ; 0.83x1.14 in)</li>
238
-	 * <li>G12 (14x21 mm ; 0.55x0.83 in)</li>
239
-	 * <li><b>ISO Press</b></li>
240
-	 * <li>RA0 (860x1220 mm ; 33.86x48.03 in)</li>
241
-	 * <li>RA1 (610x860 mm ; 24.02x33.86 in)</li>
242
-	 * <li>RA2 (430x610 mm ; 16.93x24.02 in)</li>
243
-	 * <li>RA3 (305x430 mm ; 12.01x16.93 in)</li>
244
-	 * <li>RA4 (215x305 mm ; 8.46x12.01 in)</li>
245
-	 * <li>SRA0 (900x1280 mm ; 35.43x50.39 in)</li>
246
-	 * <li>SRA1 (640x900 mm ; 25.20x35.43 in)</li>
247
-	 * <li>SRA2 (450x640 mm ; 17.72x25.20 in)</li>
248
-	 * <li>SRA3 (320x450 mm ; 12.60x17.72 in)</li>
249
-	 * <li>SRA4 (225x320 mm ; 8.86x12.60 in)</li>
250
-	 * <li><b>German DIN 476</b></li>
251
-	 * <li>4A0 (1682x2378 mm ; 66.22x93.62 in)</li>
252
-	 * <li>2A0 (1189x1682 mm ; 46.81x66.22 in)</li>
253
-	 * <li><b>Variations on the ISO Standard</b></li>
254
-	 * <li>A2_EXTRA (445x619 mm ; 17.52x24.37 in)</li>
255
-	 * <li>A3+ (329x483 mm ; 12.95x19.02 in)</li>
256
-	 * <li>A3_EXTRA (322x445 mm ; 12.68x17.52 in)</li>
257
-	 * <li>A3_SUPER (305x508 mm ; 12.01x20.00 in)</li>
258
-	 * <li>SUPER_A3 (305x487 mm ; 12.01x19.17 in)</li>
259
-	 * <li>A4_EXTRA (235x322 mm ; 9.25x12.68 in)</li>
260
-	 * <li>A4_SUPER (229x322 mm ; 9.02x12.68 in)</li>
261
-	 * <li>SUPER_A4 (227x356 mm ; 8.94x14.02 in)</li>
262
-	 * <li>A4_LONG (210x348 mm ; 8.27x13.70 in)</li>
263
-	 * <li>F4 (210x330 mm ; 8.27x12.99 in)</li>
264
-	 * <li>SO_B5_EXTRA (202x276 mm ; 7.95x10.87 in)</li>
265
-	 * <li>A5_EXTRA (173x235 mm ; 6.81x9.25 in)</li>
266
-	 * <li><b>ANSI Series</b></li>
267
-	 * <li>ANSI_E (864x1118 mm ; 34.00x44.00 in)</li>
268
-	 * <li>ANSI_D (559x864 mm ; 22.00x34.00 in)</li>
269
-	 * <li>ANSI_C (432x559 mm ; 17.00x22.00 in)</li>
270
-	 * <li>ANSI_B (279x432 mm ; 11.00x17.00 in)</li>
271
-	 * <li>ANSI_A (216x279 mm ; 8.50x11.00 in)</li>
272
-	 * <li><b>Traditional 'Loose' North American Paper Sizes</b></li>
273
-	 * <li>LEDGER, USLEDGER (432x279 mm ; 17.00x11.00 in)</li>
274
-	 * <li>TABLOID, USTABLOID, BIBLE, ORGANIZERK (279x432 mm ; 11.00x17.00 in)</li>
275
-	 * <li>LETTER, USLETTER, ORGANIZERM (216x279 mm ; 8.50x11.00 in)</li>
276
-	 * <li>LEGAL, USLEGAL (216x356 mm ; 8.50x14.00 in)</li>
277
-	 * <li>GLETTER, GOVERNMENTLETTER (203x267 mm ; 8.00x10.50 in)</li>
278
-	 * <li>JLEGAL, JUNIORLEGAL (203x127 mm ; 8.00x5.00 in)</li>
279
-	 * <li><b>Other North American Paper Sizes</b></li>
280
-	 * <li>QUADDEMY (889x1143 mm ; 35.00x45.00 in)</li>
281
-	 * <li>SUPER_B (330x483 mm ; 13.00x19.00 in)</li>
282
-	 * <li>QUARTO (229x279 mm ; 9.00x11.00 in)</li>
283
-	 * <li>FOLIO, GOVERNMENTLEGAL (216x330 mm ; 8.50x13.00 in)</li>
284
-	 * <li>EXECUTIVE, MONARCH (184x267 mm ; 7.25x10.50 in)</li>
285
-	 * <li>MEMO, STATEMENT, ORGANIZERL (140x216 mm ; 5.50x8.50 in)</li>
286
-	 * <li>FOOLSCAP (210x330 mm ; 8.27x13.00 in)</li>
287
-	 * <li>COMPACT (108x171 mm ; 4.25x6.75 in)</li>
288
-	 * <li>ORGANIZERJ (70x127 mm ; 2.75x5.00 in)</li>
289
-	 * <li><b>Canadian standard CAN 2-9.60M</b></li>
290
-	 * <li>P1 (560x860 mm ; 22.05x33.86 in)</li>
291
-	 * <li>P2 (430x560 mm ; 16.93x22.05 in)</li>
292
-	 * <li>P3 (280x430 mm ; 11.02x16.93 in)</li>
293
-	 * <li>P4 (215x280 mm ; 8.46x11.02 in)</li>
294
-	 * <li>P5 (140x215 mm ; 5.51x8.46 in)</li>
295
-	 * <li>P6 (107x140 mm ; 4.21x5.51 in)</li>
296
-	 * <li><b>North American Architectural Sizes</b></li>
297
-	 * <li>ARCH_E (914x1219 mm ; 36.00x48.00 in)</li>
298
-	 * <li>ARCH_E1 (762x1067 mm ; 30.00x42.00 in)</li>
299
-	 * <li>ARCH_D (610x914 mm ; 24.00x36.00 in)</li>
300
-	 * <li>ARCH_C, BROADSHEET (457x610 mm ; 18.00x24.00 in)</li>
301
-	 * <li>ARCH_B (305x457 mm ; 12.00x18.00 in)</li>
302
-	 * <li>ARCH_A (229x305 mm ; 9.00x12.00 in)</li>
303
-	 * <li><b>Announcement Envelopes</b></li>
304
-	 * <li>ANNENV_A2 (111x146 mm ; 4.37x5.75 in)</li>
305
-	 * <li>ANNENV_A6 (121x165 mm ; 4.75x6.50 in)</li>
306
-	 * <li>ANNENV_A7 (133x184 mm ; 5.25x7.25 in)</li>
307
-	 * <li>ANNENV_A8 (140x206 mm ; 5.50x8.12 in)</li>
308
-	 * <li>ANNENV_A10 (159x244 mm ; 6.25x9.62 in)</li>
309
-	 * <li>ANNENV_SLIM (98x225 mm ; 3.87x8.87 in)</li>
310
-	 * <li><b>Commercial Envelopes</b></li>
311
-	 * <li>COMMENV_N6_1/4 (89x152 mm ; 3.50x6.00 in)</li>
312
-	 * <li>COMMENV_N6_3/4 (92x165 mm ; 3.62x6.50 in)</li>
313
-	 * <li>COMMENV_N8 (98x191 mm ; 3.87x7.50 in)</li>
314
-	 * <li>COMMENV_N9 (98x225 mm ; 3.87x8.87 in)</li>
315
-	 * <li>COMMENV_N10 (105x241 mm ; 4.12x9.50 in)</li>
316
-	 * <li>COMMENV_N11 (114x263 mm ; 4.50x10.37 in)</li>
317
-	 * <li>COMMENV_N12 (121x279 mm ; 4.75x11.00 in)</li>
318
-	 * <li>COMMENV_N14 (127x292 mm ; 5.00x11.50 in)</li>
319
-	 * <li><b>Catalogue Envelopes</b></li>
320
-	 * <li>CATENV_N1 (152x229 mm ; 6.00x9.00 in)</li>
321
-	 * <li>CATENV_N1_3/4 (165x241 mm ; 6.50x9.50 in)</li>
322
-	 * <li>CATENV_N2 (165x254 mm ; 6.50x10.00 in)</li>
323
-	 * <li>CATENV_N3 (178x254 mm ; 7.00x10.00 in)</li>
324
-	 * <li>CATENV_N6 (191x267 mm ; 7.50x10.50 in)</li>
325
-	 * <li>CATENV_N7 (203x279 mm ; 8.00x11.00 in)</li>
326
-	 * <li>CATENV_N8 (210x286 mm ; 8.25x11.25 in)</li>
327
-	 * <li>CATENV_N9_1/2 (216x267 mm ; 8.50x10.50 in)</li>
328
-	 * <li>CATENV_N9_3/4 (222x286 mm ; 8.75x11.25 in)</li>
329
-	 * <li>CATENV_N10_1/2 (229x305 mm ; 9.00x12.00 in)</li>
330
-	 * <li>CATENV_N12_1/2 (241x318 mm ; 9.50x12.50 in)</li>
331
-	 * <li>CATENV_N13_1/2 (254x330 mm ; 10.00x13.00 in)</li>
332
-	 * <li>CATENV_N14_1/4 (286x311 mm ; 11.25x12.25 in)</li>
333
-	 * <li>CATENV_N14_1/2 (292x368 mm ; 11.50x14.50 in)</li>
334
-	 * <li><b>Japanese (JIS P 0138-61) Standard B-Series</b></li>
335
-	 * <li>JIS_B0 (1030x1456 mm ; 40.55x57.32 in)</li>
336
-	 * <li>JIS_B1 (728x1030 mm ; 28.66x40.55 in)</li>
337
-	 * <li>JIS_B2 (515x728 mm ; 20.28x28.66 in)</li>
338
-	 * <li>JIS_B3 (364x515 mm ; 14.33x20.28 in)</li>
339
-	 * <li>JIS_B4 (257x364 mm ; 10.12x14.33 in)</li>
340
-	 * <li>JIS_B5 (182x257 mm ; 7.17x10.12 in)</li>
341
-	 * <li>JIS_B6 (128x182 mm ; 5.04x7.17 in)</li>
342
-	 * <li>JIS_B7 (91x128 mm ; 3.58x5.04 in)</li>
343
-	 * <li>JIS_B8 (64x91 mm ; 2.52x3.58 in)</li>
344
-	 * <li>JIS_B9 (45x64 mm ; 1.77x2.52 in)</li>
345
-	 * <li>JIS_B10 (32x45 mm ; 1.26x1.77 in)</li>
346
-	 * <li>JIS_B11 (22x32 mm ; 0.87x1.26 in)</li>
347
-	 * <li>JIS_B12 (16x22 mm ; 0.63x0.87 in)</li>
348
-	 * <li><b>PA Series</b></li>
349
-	 * <li>PA0 (840x1120 mm ; 33.07x44.09 in)</li>
350
-	 * <li>PA1 (560x840 mm ; 22.05x33.07 in)</li>
351
-	 * <li>PA2 (420x560 mm ; 16.54x22.05 in)</li>
352
-	 * <li>PA3 (280x420 mm ; 11.02x16.54 in)</li>
353
-	 * <li>PA4 (210x280 mm ; 8.27x11.02 in)</li>
354
-	 * <li>PA5 (140x210 mm ; 5.51x8.27 in)</li>
355
-	 * <li>PA6 (105x140 mm ; 4.13x5.51 in)</li>
356
-	 * <li>PA7 (70x105 mm ; 2.76x4.13 in)</li>
357
-	 * <li>PA8 (52x70 mm ; 2.05x2.76 in)</li>
358
-	 * <li>PA9 (35x52 mm ; 1.38x2.05 in)</li>
359
-	 * <li>PA10 (26x35 mm ; 1.02x1.38 in)</li>
360
-	 * <li><b>Standard Photographic Print Sizes</b></li>
361
-	 * <li>PASSPORT_PHOTO (35x45 mm ; 1.38x1.77 in)</li>
362
-	 * <li>E (82x120 mm ; 3.25x4.72 in)</li>
363
-	 * <li>3R, L (89x127 mm ; 3.50x5.00 in)</li>
364
-	 * <li>4R, KG (102x152 mm ; 4.02x5.98 in)</li>
365
-	 * <li>4D (120x152 mm ; 4.72x5.98 in)</li>
366
-	 * <li>5R, 2L (127x178 mm ; 5.00x7.01 in)</li>
367
-	 * <li>6R, 8P (152x203 mm ; 5.98x7.99 in)</li>
368
-	 * <li>8R, 6P (203x254 mm ; 7.99x10.00 in)</li>
369
-	 * <li>S8R, 6PW (203x305 mm ; 7.99x12.01 in)</li>
370
-	 * <li>10R, 4P (254x305 mm ; 10.00x12.01 in)</li>
371
-	 * <li>S10R, 4PW (254x381 mm ; 10.00x15.00 in)</li>
372
-	 * <li>11R (279x356 mm ; 10.98x14.02 in)</li>
373
-	 * <li>S11R (279x432 mm ; 10.98x17.01 in)</li>
374
-	 * <li>12R (305x381 mm ; 12.01x15.00 in)</li>
375
-	 * <li>S12R (305x456 mm ; 12.01x17.95 in)</li>
376
-	 * <li><b>Common Newspaper Sizes</b></li>
377
-	 * <li>NEWSPAPER_BROADSHEET (750x600 mm ; 29.53x23.62 in)</li>
378
-	 * <li>NEWSPAPER_BERLINER (470x315 mm ; 18.50x12.40 in)</li>
379
-	 * <li>NEWSPAPER_COMPACT, NEWSPAPER_TABLOID (430x280 mm ; 16.93x11.02 in)</li>
380
-	 * <li><b>Business Cards</b></li>
381
-	 * <li>CREDIT_CARD, BUSINESS_CARD, BUSINESS_CARD_ISO7810 (54x86 mm ; 2.13x3.37 in)</li>
382
-	 * <li>BUSINESS_CARD_ISO216 (52x74 mm ; 2.05x2.91 in)</li>
383
-	 * <li>BUSINESS_CARD_IT, BUSINESS_CARD_UK, BUSINESS_CARD_FR, BUSINESS_CARD_DE, BUSINESS_CARD_ES (55x85 mm ; 2.17x3.35 in)</li>
384
-	 * <li>BUSINESS_CARD_US, BUSINESS_CARD_CA (51x89 mm ; 2.01x3.50 in)</li>
385
-	 * <li>BUSINESS_CARD_JP (55x91 mm ; 2.17x3.58 in)</li>
386
-	 * <li>BUSINESS_CARD_HK (54x90 mm ; 2.13x3.54 in)</li>
387
-	 * <li>BUSINESS_CARD_AU, BUSINESS_CARD_DK, BUSINESS_CARD_SE (55x90 mm ; 2.17x3.54 in)</li>
388
-	 * <li>BUSINESS_CARD_RU, BUSINESS_CARD_CZ, BUSINESS_CARD_FI, BUSINESS_CARD_HU, BUSINESS_CARD_IL (50x90 mm ; 1.97x3.54 in)</li>
389
-	 * <li><b>Billboards</b></li>
390
-	 * <li>4SHEET (1016x1524 mm ; 40.00x60.00 in)</li>
391
-	 * <li>6SHEET (1200x1800 mm ; 47.24x70.87 in)</li>
392
-	 * <li>12SHEET (3048x1524 mm ; 120.00x60.00 in)</li>
393
-	 * <li>16SHEET (2032x3048 mm ; 80.00x120.00 in)</li>
394
-	 * <li>32SHEET (4064x3048 mm ; 160.00x120.00 in)</li>
395
-	 * <li>48SHEET (6096x3048 mm ; 240.00x120.00 in)</li>
396
-	 * <li>64SHEET (8128x3048 mm ; 320.00x120.00 in)</li>
397
-	 * <li>96SHEET (12192x3048 mm ; 480.00x120.00 in)</li>
398
-	 * <li><b>Old Imperial English (some are still used in USA)</b></li>
399
-	 * <li>EN_EMPEROR (1219x1829 mm ; 48.00x72.00 in)</li>
400
-	 * <li>EN_ANTIQUARIAN (787x1346 mm ; 31.00x53.00 in)</li>
401
-	 * <li>EN_GRAND_EAGLE (730x1067 mm ; 28.75x42.00 in)</li>
402
-	 * <li>EN_DOUBLE_ELEPHANT (679x1016 mm ; 26.75x40.00 in)</li>
403
-	 * <li>EN_ATLAS (660x864 mm ; 26.00x34.00 in)</li>
404
-	 * <li>EN_COLOMBIER (597x876 mm ; 23.50x34.50 in)</li>
405
-	 * <li>EN_ELEPHANT (584x711 mm ; 23.00x28.00 in)</li>
406
-	 * <li>EN_DOUBLE_DEMY (572x902 mm ; 22.50x35.50 in)</li>
407
-	 * <li>EN_IMPERIAL (559x762 mm ; 22.00x30.00 in)</li>
408
-	 * <li>EN_PRINCESS (546x711 mm ; 21.50x28.00 in)</li>
409
-	 * <li>EN_CARTRIDGE (533x660 mm ; 21.00x26.00 in)</li>
410
-	 * <li>EN_DOUBLE_LARGE_POST (533x838 mm ; 21.00x33.00 in)</li>
411
-	 * <li>EN_ROYAL (508x635 mm ; 20.00x25.00 in)</li>
412
-	 * <li>EN_SHEET, EN_HALF_POST (495x597 mm ; 19.50x23.50 in)</li>
413
-	 * <li>EN_SUPER_ROYAL (483x686 mm ; 19.00x27.00 in)</li>
414
-	 * <li>EN_DOUBLE_POST (483x775 mm ; 19.00x30.50 in)</li>
415
-	 * <li>EN_MEDIUM (445x584 mm ; 17.50x23.00 in)</li>
416
-	 * <li>EN_DEMY (445x572 mm ; 17.50x22.50 in)</li>
417
-	 * <li>EN_LARGE_POST (419x533 mm ; 16.50x21.00 in)</li>
418
-	 * <li>EN_COPY_DRAUGHT (406x508 mm ; 16.00x20.00 in)</li>
419
-	 * <li>EN_POST (394x489 mm ; 15.50x19.25 in)</li>
420
-	 * <li>EN_CROWN (381x508 mm ; 15.00x20.00 in)</li>
421
-	 * <li>EN_PINCHED_POST (375x470 mm ; 14.75x18.50 in)</li>
422
-	 * <li>EN_BRIEF (343x406 mm ; 13.50x16.00 in)</li>
423
-	 * <li>EN_FOOLSCAP (343x432 mm ; 13.50x17.00 in)</li>
424
-	 * <li>EN_SMALL_FOOLSCAP (337x419 mm ; 13.25x16.50 in)</li>
425
-	 * <li>EN_POTT (318x381 mm ; 12.50x15.00 in)</li>
426
-	 * <li><b>Old Imperial Belgian</b></li>
427
-	 * <li>BE_GRAND_AIGLE (700x1040 mm ; 27.56x40.94 in)</li>
428
-	 * <li>BE_COLOMBIER (620x850 mm ; 24.41x33.46 in)</li>
429
-	 * <li>BE_DOUBLE_CARRE (620x920 mm ; 24.41x36.22 in)</li>
430
-	 * <li>BE_ELEPHANT (616x770 mm ; 24.25x30.31 in)</li>
431
-	 * <li>BE_PETIT_AIGLE (600x840 mm ; 23.62x33.07 in)</li>
432
-	 * <li>BE_GRAND_JESUS (550x730 mm ; 21.65x28.74 in)</li>
433
-	 * <li>BE_JESUS (540x730 mm ; 21.26x28.74 in)</li>
434
-	 * <li>BE_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
435
-	 * <li>BE_GRAND_MEDIAN (460x605 mm ; 18.11x23.82 in)</li>
436
-	 * <li>BE_DOUBLE_POSTE (435x565 mm ; 17.13x22.24 in)</li>
437
-	 * <li>BE_COQUILLE (430x560 mm ; 16.93x22.05 in)</li>
438
-	 * <li>BE_PETIT_MEDIAN (415x530 mm ; 16.34x20.87 in)</li>
439
-	 * <li>BE_RUCHE (360x460 mm ; 14.17x18.11 in)</li>
440
-	 * <li>BE_PROPATRIA (345x430 mm ; 13.58x16.93 in)</li>
441
-	 * <li>BE_LYS (317x397 mm ; 12.48x15.63 in)</li>
442
-	 * <li>BE_POT (307x384 mm ; 12.09x15.12 in)</li>
443
-	 * <li>BE_ROSETTE (270x347 mm ; 10.63x13.66 in)</li>
444
-	 * <li><b>Old Imperial French</b></li>
445
-	 * <li>FR_UNIVERS (1000x1300 mm ; 39.37x51.18 in)</li>
446
-	 * <li>FR_DOUBLE_COLOMBIER (900x1260 mm ; 35.43x49.61 in)</li>
447
-	 * <li>FR_GRANDE_MONDE (900x1260 mm ; 35.43x49.61 in)</li>
448
-	 * <li>FR_DOUBLE_SOLEIL (800x1200 mm ; 31.50x47.24 in)</li>
449
-	 * <li>FR_DOUBLE_JESUS (760x1120 mm ; 29.92x44.09 in)</li>
450
-	 * <li>FR_GRAND_AIGLE (750x1060 mm ; 29.53x41.73 in)</li>
451
-	 * <li>FR_PETIT_AIGLE (700x940 mm ; 27.56x37.01 in)</li>
452
-	 * <li>FR_DOUBLE_RAISIN (650x1000 mm ; 25.59x39.37 in)</li>
453
-	 * <li>FR_JOURNAL (650x940 mm ; 25.59x37.01 in)</li>
454
-	 * <li>FR_COLOMBIER_AFFICHE (630x900 mm ; 24.80x35.43 in)</li>
455
-	 * <li>FR_DOUBLE_CAVALIER (620x920 mm ; 24.41x36.22 in)</li>
456
-	 * <li>FR_CLOCHE (600x800 mm ; 23.62x31.50 in)</li>
457
-	 * <li>FR_SOLEIL (600x800 mm ; 23.62x31.50 in)</li>
458
-	 * <li>FR_DOUBLE_CARRE (560x900 mm ; 22.05x35.43 in)</li>
459
-	 * <li>FR_DOUBLE_COQUILLE (560x880 mm ; 22.05x34.65 in)</li>
460
-	 * <li>FR_JESUS (560x760 mm ; 22.05x29.92 in)</li>
461
-	 * <li>FR_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
462
-	 * <li>FR_CAVALIER (460x620 mm ; 18.11x24.41 in)</li>
463
-	 * <li>FR_DOUBLE_COURONNE (460x720 mm ; 18.11x28.35 in)</li>
464
-	 * <li>FR_CARRE (450x560 mm ; 17.72x22.05 in)</li>
465
-	 * <li>FR_COQUILLE (440x560 mm ; 17.32x22.05 in)</li>
466
-	 * <li>FR_DOUBLE_TELLIERE (440x680 mm ; 17.32x26.77 in)</li>
467
-	 * <li>FR_DOUBLE_CLOCHE (400x600 mm ; 15.75x23.62 in)</li>
468
-	 * <li>FR_DOUBLE_POT (400x620 mm ; 15.75x24.41 in)</li>
469
-	 * <li>FR_ECU (400x520 mm ; 15.75x20.47 in)</li>
470
-	 * <li>FR_COURONNE (360x460 mm ; 14.17x18.11 in)</li>
471
-	 * <li>FR_TELLIERE (340x440 mm ; 13.39x17.32 in)</li>
472
-	 * <li>FR_POT (310x400 mm ; 12.20x15.75 in)</li>
473
-	 * </ul>
474
-	 * @return array containing page width and height in points
475
-	 * @since 5.0.010 (2010-05-17)
476
-	 * @public static
477
-	 */
478
-	public static function getPageSizeFromFormat($format) {
479
-		// Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 25.4 mm)
480
-		switch (strtoupper($format)) {
481
-			// ISO 216 A Series + 2 SIS 014711 extensions
482
-			case 'A0' : {$pf = array( 2383.937, 3370.394); break;}
483
-			case 'A1' : {$pf = array( 1683.780, 2383.937); break;}
484
-			case 'A2' : {$pf = array( 1190.551, 1683.780); break;}
485
-			case 'A3' : {$pf = array(  841.890, 1190.551); break;}
486
-			case 'A4' : {$pf = array(  595.276,  841.890); break;}
487
-			case 'A5' : {$pf = array(  419.528,  595.276); break;}
488
-			case 'A6' : {$pf = array(  297.638,  419.528); break;}
489
-			case 'A7' : {$pf = array(  209.764,  297.638); break;}
490
-			case 'A8' : {$pf = array(  147.402,  209.764); break;}
491
-			case 'A9' : {$pf = array(  104.882,  147.402); break;}
492
-			case 'A10': {$pf = array(   73.701,  104.882); break;}
493
-			case 'A11': {$pf = array(   51.024,   73.701); break;}
494
-			case 'A12': {$pf = array(   36.850,   51.024); break;}
495
-			// ISO 216 B Series + 2 SIS 014711 extensions
496
-			case 'B0' : {$pf = array( 2834.646, 4008.189); break;}
497
-			case 'B1' : {$pf = array( 2004.094, 2834.646); break;}
498
-			case 'B2' : {$pf = array( 1417.323, 2004.094); break;}
499
-			case 'B3' : {$pf = array( 1000.630, 1417.323); break;}
500
-			case 'B4' : {$pf = array(  708.661, 1000.630); break;}
501
-			case 'B5' : {$pf = array(  498.898,  708.661); break;}
502
-			case 'B6' : {$pf = array(  354.331,  498.898); break;}
503
-			case 'B7' : {$pf = array(  249.449,  354.331); break;}
504
-			case 'B8' : {$pf = array(  175.748,  249.449); break;}
505
-			case 'B9' : {$pf = array(  124.724,  175.748); break;}
506
-			case 'B10': {$pf = array(   87.874,  124.724); break;}
507
-			case 'B11': {$pf = array(   62.362,   87.874); break;}
508
-			case 'B12': {$pf = array(   42.520,   62.362); break;}
509
-			// ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION
510
-			case 'C0' : {$pf = array( 2599.370, 3676.535); break;}
511
-			case 'C1' : {$pf = array( 1836.850, 2599.370); break;}
512
-			case 'C2' : {$pf = array( 1298.268, 1836.850); break;}
513
-			case 'C3' : {$pf = array(  918.425, 1298.268); break;}
514
-			case 'C4' : {$pf = array(  649.134,  918.425); break;}
515
-			case 'C5' : {$pf = array(  459.213,  649.134); break;}
516
-			case 'C6' : {$pf = array(  323.150,  459.213); break;}
517
-			case 'C7' : {$pf = array(  229.606,  323.150); break;}
518
-			case 'C8' : {$pf = array(  161.575,  229.606); break;}
519
-			case 'C9' : {$pf = array(  113.386,  161.575); break;}
520
-			case 'C10': {$pf = array(   79.370,  113.386); break;}
521
-			case 'C11': {$pf = array(   56.693,   79.370); break;}
522
-			case 'C12': {$pf = array(   39.685,   56.693); break;}
523
-			case 'C76': {$pf = array(  229.606,  459.213); break;}
524
-			case 'DL' : {$pf = array(  311.811,  623.622); break;}
525
-			// SIS 014711 E Series
526
-			case 'E0' : {$pf = array( 2491.654, 3517.795); break;}
527
-			case 'E1' : {$pf = array( 1757.480, 2491.654); break;}
528
-			case 'E2' : {$pf = array( 1247.244, 1757.480); break;}
529
-			case 'E3' : {$pf = array(  878.740, 1247.244); break;}
530
-			case 'E4' : {$pf = array(  623.622,  878.740); break;}
531
-			case 'E5' : {$pf = array(  439.370,  623.622); break;}
532
-			case 'E6' : {$pf = array(  311.811,  439.370); break;}
533
-			case 'E7' : {$pf = array(  221.102,  311.811); break;}
534
-			case 'E8' : {$pf = array(  155.906,  221.102); break;}
535
-			case 'E9' : {$pf = array(  110.551,  155.906); break;}
536
-			case 'E10': {$pf = array(   76.535,  110.551); break;}
537
-			case 'E11': {$pf = array(   53.858,   76.535); break;}
538
-			case 'E12': {$pf = array(   36.850,   53.858); break;}
539
-			// SIS 014711 G Series
540
-			case 'G0' : {$pf = array( 2715.591, 3838.110); break;}
541
-			case 'G1' : {$pf = array( 1919.055, 2715.591); break;}
542
-			case 'G2' : {$pf = array( 1357.795, 1919.055); break;}
543
-			case 'G3' : {$pf = array(  958.110, 1357.795); break;}
544
-			case 'G4' : {$pf = array(  677.480,  958.110); break;}
545
-			case 'G5' : {$pf = array(  479.055,  677.480); break;}
546
-			case 'G6' : {$pf = array(  337.323,  479.055); break;}
547
-			case 'G7' : {$pf = array(  238.110,  337.323); break;}
548
-			case 'G8' : {$pf = array(  167.244,  238.110); break;}
549
-			case 'G9' : {$pf = array(  119.055,  167.244); break;}
550
-			case 'G10': {$pf = array(   82.205,  119.055); break;}
551
-			case 'G11': {$pf = array(   59.528,   82.205); break;}
552
-			case 'G12': {$pf = array(   39.685,   59.528); break;}
553
-			// ISO Press
554
-			case 'RA0': {$pf = array( 2437.795, 3458.268); break;}
555
-			case 'RA1': {$pf = array( 1729.134, 2437.795); break;}
556
-			case 'RA2': {$pf = array( 1218.898, 1729.134); break;}
557
-			case 'RA3': {$pf = array(  864.567, 1218.898); break;}
558
-			case 'RA4': {$pf = array(  609.449,  864.567); break;}
559
-			case 'SRA0': {$pf = array( 2551.181, 3628.346); break;}
560
-			case 'SRA1': {$pf = array( 1814.173, 2551.181); break;}
561
-			case 'SRA2': {$pf = array( 1275.591, 1814.173); break;}
562
-			case 'SRA3': {$pf = array(  907.087, 1275.591); break;}
563
-			case 'SRA4': {$pf = array(  637.795,  907.087); break;}
564
-			// German  DIN 476
565
-			case '4A0': {$pf = array( 4767.874, 6740.787); break;}
566
-			case '2A0': {$pf = array( 3370.394, 4767.874); break;}
567
-			// Variations on the ISO Standard
568
-			case 'A2_EXTRA'   : {$pf = array( 1261.417, 1754.646); break;}
569
-			case 'A3+'        : {$pf = array(  932.598, 1369.134); break;}
570
-			case 'A3_EXTRA'   : {$pf = array(  912.756, 1261.417); break;}
571
-			case 'A3_SUPER'   : {$pf = array(  864.567, 1440.000); break;}
572
-			case 'SUPER_A3'   : {$pf = array(  864.567, 1380.472); break;}
573
-			case 'A4_EXTRA'   : {$pf = array(  666.142,  912.756); break;}
574
-			case 'A4_SUPER'   : {$pf = array(  649.134,  912.756); break;}
575
-			case 'SUPER_A4'   : {$pf = array(  643.465, 1009.134); break;}
576
-			case 'A4_LONG'    : {$pf = array(  595.276,  986.457); break;}
577
-			case 'F4'         : {$pf = array(  595.276,  935.433); break;}
578
-			case 'SO_B5_EXTRA': {$pf = array(  572.598,  782.362); break;}
579
-			case 'A5_EXTRA'   : {$pf = array(  490.394,  666.142); break;}
580
-			// ANSI Series
581
-			case 'ANSI_E': {$pf = array( 2448.000, 3168.000); break;}
582
-			case 'ANSI_D': {$pf = array( 1584.000, 2448.000); break;}
583
-			case 'ANSI_C': {$pf = array( 1224.000, 1584.000); break;}
584
-			case 'ANSI_B': {$pf = array(  792.000, 1224.000); break;}
585
-			case 'ANSI_A': {$pf = array(  612.000,  792.000); break;}
586
-			// Traditional 'Loose' North American Paper Sizes
587
-			case 'USLEDGER':
588
-			case 'LEDGER' : {$pf = array( 1224.000,  792.000); break;}
589
-			case 'ORGANIZERK':
590
-			case 'BIBLE':
591
-			case 'USTABLOID':
592
-			case 'TABLOID': {$pf = array(  792.000, 1224.000); break;}
593
-			case 'ORGANIZERM':
594
-			case 'USLETTER':
595
-			case 'LETTER' : {$pf = array(  612.000,  792.000); break;}
596
-			case 'USLEGAL':
597
-			case 'LEGAL'  : {$pf = array(  612.000, 1008.000); break;}
598
-			case 'GOVERNMENTLETTER':
599
-			case 'GLETTER': {$pf = array(  576.000,  756.000); break;}
600
-			case 'JUNIORLEGAL':
601
-			case 'JLEGAL' : {$pf = array(  576.000,  360.000); break;}
602
-			// Other North American Paper Sizes
603
-			case 'QUADDEMY': {$pf = array( 2520.000, 3240.000); break;}
604
-			case 'SUPER_B': {$pf = array(  936.000, 1368.000); break;}
605
-			case 'QUARTO': {$pf = array(  648.000,  792.000); break;}
606
-			case 'GOVERNMENTLEGAL':
607
-			case 'FOLIO': {$pf = array(  612.000,  936.000); break;}
608
-			case 'MONARCH':
609
-			case 'EXECUTIVE': {$pf = array(  522.000,  756.000); break;}
610
-			case 'ORGANIZERL':
611
-			case 'STATEMENT':
612
-			case 'MEMO': {$pf = array(  396.000,  612.000); break;}
613
-			case 'FOOLSCAP': {$pf = array(  595.440,  936.000); break;}
614
-			case 'COMPACT': {$pf = array(  306.000,  486.000); break;}
615
-			case 'ORGANIZERJ': {$pf = array(  198.000,  360.000); break;}
616
-			// Canadian standard CAN 2-9.60M
617
-			case 'P1': {$pf = array( 1587.402, 2437.795); break;}
618
-			case 'P2': {$pf = array( 1218.898, 1587.402); break;}
619
-			case 'P3': {$pf = array(  793.701, 1218.898); break;}
620
-			case 'P4': {$pf = array(  609.449,  793.701); break;}
621
-			case 'P5': {$pf = array(  396.850,  609.449); break;}
622
-			case 'P6': {$pf = array(  303.307,  396.850); break;}
623
-			// North American Architectural Sizes
624
-			case 'ARCH_E' : {$pf = array( 2592.000, 3456.000); break;}
625
-			case 'ARCH_E1': {$pf = array( 2160.000, 3024.000); break;}
626
-			case 'ARCH_D' : {$pf = array( 1728.000, 2592.000); break;}
627
-			case 'BROADSHEET':
628
-			case 'ARCH_C' : {$pf = array( 1296.000, 1728.000); break;}
629
-			case 'ARCH_B' : {$pf = array(  864.000, 1296.000); break;}
630
-			case 'ARCH_A' : {$pf = array(  648.000,  864.000); break;}
631
-			// --- North American Envelope Sizes ---
632
-			//   - Announcement Envelopes
633
-			case 'ANNENV_A2'  : {$pf = array(  314.640,  414.000); break;}
634
-			case 'ANNENV_A6'  : {$pf = array(  342.000,  468.000); break;}
635
-			case 'ANNENV_A7'  : {$pf = array(  378.000,  522.000); break;}
636
-			case 'ANNENV_A8'  : {$pf = array(  396.000,  584.640); break;}
637
-			case 'ANNENV_A10' : {$pf = array(  450.000,  692.640); break;}
638
-			case 'ANNENV_SLIM': {$pf = array(  278.640,  638.640); break;}
639
-			//   - Commercial Envelopes
640
-			case 'COMMENV_N6_1/4': {$pf = array(  252.000,  432.000); break;}
641
-			case 'COMMENV_N6_3/4': {$pf = array(  260.640,  468.000); break;}
642
-			case 'COMMENV_N8'    : {$pf = array(  278.640,  540.000); break;}
643
-			case 'COMMENV_N9'    : {$pf = array(  278.640,  638.640); break;}
644
-			case 'COMMENV_N10'   : {$pf = array(  296.640,  684.000); break;}
645
-			case 'COMMENV_N11'   : {$pf = array(  324.000,  746.640); break;}
646
-			case 'COMMENV_N12'   : {$pf = array(  342.000,  792.000); break;}
647
-			case 'COMMENV_N14'   : {$pf = array(  360.000,  828.000); break;}
648
-			//   - Catalogue Envelopes
649
-			case 'CATENV_N1'     : {$pf = array(  432.000,  648.000); break;}
650
-			case 'CATENV_N1_3/4' : {$pf = array(  468.000,  684.000); break;}
651
-			case 'CATENV_N2'     : {$pf = array(  468.000,  720.000); break;}
652
-			case 'CATENV_N3'     : {$pf = array(  504.000,  720.000); break;}
653
-			case 'CATENV_N6'     : {$pf = array(  540.000,  756.000); break;}
654
-			case 'CATENV_N7'     : {$pf = array(  576.000,  792.000); break;}
655
-			case 'CATENV_N8'     : {$pf = array(  594.000,  810.000); break;}
656
-			case 'CATENV_N9_1/2' : {$pf = array(  612.000,  756.000); break;}
657
-			case 'CATENV_N9_3/4' : {$pf = array(  630.000,  810.000); break;}
658
-			case 'CATENV_N10_1/2': {$pf = array(  648.000,  864.000); break;}
659
-			case 'CATENV_N12_1/2': {$pf = array(  684.000,  900.000); break;}
660
-			case 'CATENV_N13_1/2': {$pf = array(  720.000,  936.000); break;}
661
-			case 'CATENV_N14_1/4': {$pf = array(  810.000,  882.000); break;}
662
-			case 'CATENV_N14_1/2': {$pf = array(  828.000, 1044.000); break;}
663
-			// Japanese (JIS P 0138-61) Standard B-Series
664
-			case 'JIS_B0' : {$pf = array( 2919.685, 4127.244); break;}
665
-			case 'JIS_B1' : {$pf = array( 2063.622, 2919.685); break;}
666
-			case 'JIS_B2' : {$pf = array( 1459.843, 2063.622); break;}
667
-			case 'JIS_B3' : {$pf = array( 1031.811, 1459.843); break;}
668
-			case 'JIS_B4' : {$pf = array(  728.504, 1031.811); break;}
669
-			case 'JIS_B5' : {$pf = array(  515.906,  728.504); break;}
670
-			case 'JIS_B6' : {$pf = array(  362.835,  515.906); break;}
671
-			case 'JIS_B7' : {$pf = array(  257.953,  362.835); break;}
672
-			case 'JIS_B8' : {$pf = array(  181.417,  257.953); break;}
673
-			case 'JIS_B9' : {$pf = array(  127.559,  181.417); break;}
674
-			case 'JIS_B10': {$pf = array(   90.709,  127.559); break;}
675
-			case 'JIS_B11': {$pf = array(   62.362,   90.709); break;}
676
-			case 'JIS_B12': {$pf = array(   45.354,   62.362); break;}
677
-			// PA Series
678
-			case 'PA0' : {$pf = array( 2381.102, 3174.803,); break;}
679
-			case 'PA1' : {$pf = array( 1587.402, 2381.102); break;}
680
-			case 'PA2' : {$pf = array( 1190.551, 1587.402); break;}
681
-			case 'PA3' : {$pf = array(  793.701, 1190.551); break;}
682
-			case 'PA4' : {$pf = array(  595.276,  793.701); break;}
683
-			case 'PA5' : {$pf = array(  396.850,  595.276); break;}
684
-			case 'PA6' : {$pf = array(  297.638,  396.850); break;}
685
-			case 'PA7' : {$pf = array(  198.425,  297.638); break;}
686
-			case 'PA8' : {$pf = array(  147.402,  198.425); break;}
687
-			case 'PA9' : {$pf = array(   99.213,  147.402); break;}
688
-			case 'PA10': {$pf = array(   73.701,   99.213); break;}
689
-			// Standard Photographic Print Sizes
690
-			case 'PASSPORT_PHOTO': {$pf = array(   99.213,  127.559); break;}
691
-			case 'E'   : {$pf = array(  233.858,  340.157); break;}
692
-			case 'L':
693
-			case '3R'  : {$pf = array(  252.283,  360.000); break;}
694
-			case 'KG':
695
-			case '4R'  : {$pf = array(  289.134,  430.866); break;}
696
-			case '4D'  : {$pf = array(  340.157,  430.866); break;}
697
-			case '2L':
698
-			case '5R'  : {$pf = array(  360.000,  504.567); break;}
699
-			case '8P':
700
-			case '6R'  : {$pf = array(  430.866,  575.433); break;}
701
-			case '6P':
702
-			case '8R'  : {$pf = array(  575.433,  720.000); break;}
703
-			case '6PW':
704
-			case 'S8R' : {$pf = array(  575.433,  864.567); break;}
705
-			case '4P':
706
-			case '10R' : {$pf = array(  720.000,  864.567); break;}
707
-			case '4PW':
708
-			case 'S10R': {$pf = array(  720.000, 1080.000); break;}
709
-			case '11R' : {$pf = array(  790.866, 1009.134); break;}
710
-			case 'S11R': {$pf = array(  790.866, 1224.567); break;}
711
-			case '12R' : {$pf = array(  864.567, 1080.000); break;}
712
-			case 'S12R': {$pf = array(  864.567, 1292.598); break;}
713
-			// Common Newspaper Sizes
714
-			case 'NEWSPAPER_BROADSHEET': {$pf = array( 2125.984, 1700.787); break;}
715
-			case 'NEWSPAPER_BERLINER'  : {$pf = array( 1332.283,  892.913); break;}
716
-			case 'NEWSPAPER_TABLOID':
717
-			case 'NEWSPAPER_COMPACT'   : {$pf = array( 1218.898,  793.701); break;}
718
-			// Business Cards
719
-			case 'CREDIT_CARD':
720
-			case 'BUSINESS_CARD':
721
-			case 'BUSINESS_CARD_ISO7810': {$pf = array(  153.014,  242.646); break;}
722
-			case 'BUSINESS_CARD_ISO216' : {$pf = array(  147.402,  209.764); break;}
723
-			case 'BUSINESS_CARD_IT':
724
-			case 'BUSINESS_CARD_UK':
725
-			case 'BUSINESS_CARD_FR':
726
-			case 'BUSINESS_CARD_DE':
727
-			case 'BUSINESS_CARD_ES'     : {$pf = array(  155.906,  240.945); break;}
728
-			case 'BUSINESS_CARD_CA':
729
-			case 'BUSINESS_CARD_US'     : {$pf = array(  144.567,  252.283); break;}
730
-			case 'BUSINESS_CARD_JP'     : {$pf = array(  155.906,  257.953); break;}
731
-			case 'BUSINESS_CARD_HK'     : {$pf = array(  153.071,  255.118); break;}
732
-			case 'BUSINESS_CARD_AU':
733
-			case 'BUSINESS_CARD_DK':
734
-			case 'BUSINESS_CARD_SE'     : {$pf = array(  155.906,  255.118); break;}
735
-			case 'BUSINESS_CARD_RU':
736
-			case 'BUSINESS_CARD_CZ':
737
-			case 'BUSINESS_CARD_FI':
738
-			case 'BUSINESS_CARD_HU':
739
-			case 'BUSINESS_CARD_IL'     : {$pf = array(  141.732,  255.118); break;}
740
-			// Billboards
741
-			case '4SHEET' : {$pf = array( 2880.000, 4320.000); break;}
742
-			case '6SHEET' : {$pf = array( 3401.575, 5102.362); break;}
743
-			case '12SHEET': {$pf = array( 8640.000, 4320.000); break;}
744
-			case '16SHEET': {$pf = array( 5760.000, 8640.000); break;}
745
-			case '32SHEET': {$pf = array(11520.000, 8640.000); break;}
746
-			case '48SHEET': {$pf = array(17280.000, 8640.000); break;}
747
-			case '64SHEET': {$pf = array(23040.000, 8640.000); break;}
748
-			case '96SHEET': {$pf = array(34560.000, 8640.000); break;}
749
-			// Old European Sizes
750
-			//   - Old Imperial English Sizes
751
-			case 'EN_EMPEROR'          : {$pf = array( 3456.000, 5184.000); break;}
752
-			case 'EN_ANTIQUARIAN'      : {$pf = array( 2232.000, 3816.000); break;}
753
-			case 'EN_GRAND_EAGLE'      : {$pf = array( 2070.000, 3024.000); break;}
754
-			case 'EN_DOUBLE_ELEPHANT'  : {$pf = array( 1926.000, 2880.000); break;}
755
-			case 'EN_ATLAS'            : {$pf = array( 1872.000, 2448.000); break;}
756
-			case 'EN_COLOMBIER'        : {$pf = array( 1692.000, 2484.000); break;}
757
-			case 'EN_ELEPHANT'         : {$pf = array( 1656.000, 2016.000); break;}
758
-			case 'EN_DOUBLE_DEMY'      : {$pf = array( 1620.000, 2556.000); break;}
759
-			case 'EN_IMPERIAL'         : {$pf = array( 1584.000, 2160.000); break;}
760
-			case 'EN_PRINCESS'         : {$pf = array( 1548.000, 2016.000); break;}
761
-			case 'EN_CARTRIDGE'        : {$pf = array( 1512.000, 1872.000); break;}
762
-			case 'EN_DOUBLE_LARGE_POST': {$pf = array( 1512.000, 2376.000); break;}
763
-			case 'EN_ROYAL'            : {$pf = array( 1440.000, 1800.000); break;}
764
-			case 'EN_SHEET':
765
-			case 'EN_HALF_POST'        : {$pf = array( 1404.000, 1692.000); break;}
766
-			case 'EN_SUPER_ROYAL'      : {$pf = array( 1368.000, 1944.000); break;}
767
-			case 'EN_DOUBLE_POST'      : {$pf = array( 1368.000, 2196.000); break;}
768
-			case 'EN_MEDIUM'           : {$pf = array( 1260.000, 1656.000); break;}
769
-			case 'EN_DEMY'             : {$pf = array( 1260.000, 1620.000); break;}
770
-			case 'EN_LARGE_POST'       : {$pf = array( 1188.000, 1512.000); break;}
771
-			case 'EN_COPY_DRAUGHT'     : {$pf = array( 1152.000, 1440.000); break;}
772
-			case 'EN_POST'             : {$pf = array( 1116.000, 1386.000); break;}
773
-			case 'EN_CROWN'            : {$pf = array( 1080.000, 1440.000); break;}
774
-			case 'EN_PINCHED_POST'     : {$pf = array( 1062.000, 1332.000); break;}
775
-			case 'EN_BRIEF'            : {$pf = array(  972.000, 1152.000); break;}
776
-			case 'EN_FOOLSCAP'         : {$pf = array(  972.000, 1224.000); break;}
777
-			case 'EN_SMALL_FOOLSCAP'   : {$pf = array(  954.000, 1188.000); break;}
778
-			case 'EN_POTT'             : {$pf = array(  900.000, 1080.000); break;}
779
-			//   - Old Imperial Belgian Sizes
780
-			case 'BE_GRAND_AIGLE' : {$pf = array( 1984.252, 2948.031); break;}
781
-			case 'BE_COLOMBIER'   : {$pf = array( 1757.480, 2409.449); break;}
782
-			case 'BE_DOUBLE_CARRE': {$pf = array( 1757.480, 2607.874); break;}
783
-			case 'BE_ELEPHANT'    : {$pf = array( 1746.142, 2182.677); break;}
784
-			case 'BE_PETIT_AIGLE' : {$pf = array( 1700.787, 2381.102); break;}
785
-			case 'BE_GRAND_JESUS' : {$pf = array( 1559.055, 2069.291); break;}
786
-			case 'BE_JESUS'       : {$pf = array( 1530.709, 2069.291); break;}
787
-			case 'BE_RAISIN'      : {$pf = array( 1417.323, 1842.520); break;}
788
-			case 'BE_GRAND_MEDIAN': {$pf = array( 1303.937, 1714.961); break;}
789
-			case 'BE_DOUBLE_POSTE': {$pf = array( 1233.071, 1601.575); break;}
790
-			case 'BE_COQUILLE'    : {$pf = array( 1218.898, 1587.402); break;}
791
-			case 'BE_PETIT_MEDIAN': {$pf = array( 1176.378, 1502.362); break;}
792
-			case 'BE_RUCHE'       : {$pf = array( 1020.472, 1303.937); break;}
793
-			case 'BE_PROPATRIA'   : {$pf = array(  977.953, 1218.898); break;}
794
-			case 'BE_LYS'         : {$pf = array(  898.583, 1125.354); break;}
795
-			case 'BE_POT'         : {$pf = array(  870.236, 1088.504); break;}
796
-			case 'BE_ROSETTE'     : {$pf = array(  765.354,  983.622); break;}
797
-			//   - Old Imperial French Sizes
798
-			case 'FR_UNIVERS'          : {$pf = array( 2834.646, 3685.039); break;}
799
-			case 'FR_DOUBLE_COLOMBIER' : {$pf = array( 2551.181, 3571.654); break;}
800
-			case 'FR_GRANDE_MONDE'     : {$pf = array( 2551.181, 3571.654); break;}
801
-			case 'FR_DOUBLE_SOLEIL'    : {$pf = array( 2267.717, 3401.575); break;}
802
-			case 'FR_DOUBLE_JESUS'     : {$pf = array( 2154.331, 3174.803); break;}
803
-			case 'FR_GRAND_AIGLE'      : {$pf = array( 2125.984, 3004.724); break;}
804
-			case 'FR_PETIT_AIGLE'      : {$pf = array( 1984.252, 2664.567); break;}
805
-			case 'FR_DOUBLE_RAISIN'    : {$pf = array( 1842.520, 2834.646); break;}
806
-			case 'FR_JOURNAL'          : {$pf = array( 1842.520, 2664.567); break;}
807
-			case 'FR_COLOMBIER_AFFICHE': {$pf = array( 1785.827, 2551.181); break;}
808
-			case 'FR_DOUBLE_CAVALIER'  : {$pf = array( 1757.480, 2607.874); break;}
809
-			case 'FR_CLOCHE'           : {$pf = array( 1700.787, 2267.717); break;}
810
-			case 'FR_SOLEIL'           : {$pf = array( 1700.787, 2267.717); break;}
811
-			case 'FR_DOUBLE_CARRE'     : {$pf = array( 1587.402, 2551.181); break;}
812
-			case 'FR_DOUBLE_COQUILLE'  : {$pf = array( 1587.402, 2494.488); break;}
813
-			case 'FR_JESUS'            : {$pf = array( 1587.402, 2154.331); break;}
814
-			case 'FR_RAISIN'           : {$pf = array( 1417.323, 1842.520); break;}
815
-			case 'FR_CAVALIER'         : {$pf = array( 1303.937, 1757.480); break;}
816
-			case 'FR_DOUBLE_COURONNE'  : {$pf = array( 1303.937, 2040.945); break;}
817
-			case 'FR_CARRE'            : {$pf = array( 1275.591, 1587.402); break;}
818
-			case 'FR_COQUILLE'         : {$pf = array( 1247.244, 1587.402); break;}
819
-			case 'FR_DOUBLE_TELLIERE'  : {$pf = array( 1247.244, 1927.559); break;}
820
-			case 'FR_DOUBLE_CLOCHE'    : {$pf = array( 1133.858, 1700.787); break;}
821
-			case 'FR_DOUBLE_POT'       : {$pf = array( 1133.858, 1757.480); break;}
822
-			case 'FR_ECU'              : {$pf = array( 1133.858, 1474.016); break;}
823
-			case 'FR_COURONNE'         : {$pf = array( 1020.472, 1303.937); break;}
824
-			case 'FR_TELLIERE'         : {$pf = array(  963.780, 1247.244); break;}
825
-			case 'FR_POT'              : {$pf = array(  878.740, 1133.858); break;}
826
-			// DEFAULT ISO A4
827
-			default: {$pf = array(  595.276,  841.890); break;}
828
-		}
829
-		return $pf;
830
-	}
831
-
832
-	/**
833
-	 * Set page boundaries.
834
-	 * @param $page (int) page number
835
-	 * @param $type (string) valid values are: <ul><li>'MediaBox' : the boundaries of the physical medium on which the page shall be displayed or printed;</li><li>'CropBox' : the visible region of default user space;</li><li>'BleedBox' : the region to which the contents of the page shall be clipped when output in a production environment;</li><li>'TrimBox' : the intended dimensions of the finished page after trimming;</li><li>'ArtBox' : the page's meaningful content (including potential white space).</li></ul>
836
-	 * @param $llx (float) lower-left x coordinate in user units.
837
-	 * @param $lly (float) lower-left y coordinate in user units.
838
-	 * @param $urx (float) upper-right x coordinate in user units.
839
-	 * @param $ury (float) upper-right y coordinate in user units.
840
-	 * @param $points (boolean) If true uses user units as unit of measure, otherwise uses PDF points.
841
-	 * @param $k (float) Scale factor (number of points in user unit).
842
-	 * @param $pagedim (array) Array of page dimensions.
843
-	 * @return pagedim array of page dimensions.
844
-	 * @since 5.0.010 (2010-05-17)
845
-	 * @public static
846
-	 */
847
-	public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points=false, $k, $pagedim=array()) {
848
-		if (!isset($pagedim[$page])) {
849
-			// initialize array
850
-			$pagedim[$page] = array();
851
-		}
852
-		if (!in_array($type, self::$pageboxes)) {
853
-			return;
854
-		}
855
-		if ($points) {
856
-			$k = 1;
857
-		}
858
-		$pagedim[$page][$type]['llx'] = ($llx * $k);
859
-		$pagedim[$page][$type]['lly'] = ($lly * $k);
860
-		$pagedim[$page][$type]['urx'] = ($urx * $k);
861
-		$pagedim[$page][$type]['ury'] = ($ury * $k);
862
-		return $pagedim;
863
-	}
864
-
865
-	/**
866
-	 * Swap X and Y coordinates of page boxes (change page boxes orientation).
867
-	 * @param $page (int) page number
868
-	 * @param $pagedim (array) Array of page dimensions.
869
-	 * @return pagedim array of page dimensions.
870
-	 * @since 5.0.010 (2010-05-17)
871
-	 * @public static
872
-	 */
873
-	public static function swapPageBoxCoordinates($page, $pagedim) {
874
-		foreach (self::$pageboxes as $type) {
875
-			// swap X and Y coordinates
876
-			if (isset($pagedim[$page][$type])) {
877
-				$tmp = $pagedim[$page][$type]['llx'];
878
-				$pagedim[$page][$type]['llx'] = $pagedim[$page][$type]['lly'];
879
-				$pagedim[$page][$type]['lly'] = $tmp;
880
-				$tmp = $pagedim[$page][$type]['urx'];
881
-				$pagedim[$page][$type]['urx'] = $pagedim[$page][$type]['ury'];
882
-				$pagedim[$page][$type]['ury'] = $tmp;
883
-			}
884
-		}
885
-		return $pagedim;
886
-	}
887
-
888
-	/**
889
-	 * Get the canonical page layout mode.
890
-	 * @param $layout (string) The page layout. Possible values are:<ul><li>SinglePage Display one page at a time</li><li>OneColumn Display the pages in one column</li><li>TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left</li><li>TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right</li><li>TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left</li><li>TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right</li></ul>
891
-	 * @return (string) Canonical page layout name.
892
-	 * @public static
893
-	 */
894
-	public static function getPageLayoutMode($layout='SinglePage') {
895
-		switch ($layout) {
896
-			case 'default':
897
-			case 'single':
898
-			case 'SinglePage': {
899
-				$layout_mode = 'SinglePage';
900
-				break;
901
-			}
902
-			case 'continuous':
903
-			case 'OneColumn': {
904
-				$layout_mode = 'OneColumn';
905
-				break;
906
-			}
907
-			case 'two':
908
-			case 'TwoColumnLeft': {
909
-				$layout_mode = 'TwoColumnLeft';
910
-				break;
911
-			}
912
-			case 'TwoColumnRight': {
913
-				$layout_mode = 'TwoColumnRight';
914
-				break;
915
-			}
916
-			case 'TwoPageLeft': {
917
-				$layout_mode = 'TwoPageLeft';
918
-				break;
919
-			}
920
-			case 'TwoPageRight': {
921
-				$layout_mode = 'TwoPageRight';
922
-				break;
923
-			}
924
-			default: {
925
-				$layout_mode = 'SinglePage';
926
-			}
927
-		}
928
-		return $layout_mode;
929
-	}
930
-
931
-	/**
932
-	 * Get the canonical page layout mode.
933
-	 * @param $mode (string) A name object specifying how the document should be displayed when opened:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible</li><li>UseOC (PDF 1.5) Optional content group panel visible</li><li>UseAttachments (PDF 1.6) Attachments panel visible</li></ul>
934
-	 * @return (string) Canonical page mode name.
935
-	 * @public static
936
-	 */
937
-	public static function getPageMode($mode='UseNone') {
938
-		switch ($mode) {
939
-			case 'UseNone': {
940
-				$page_mode = 'UseNone';
941
-				break;
942
-			}
943
-			case 'UseOutlines': {
944
-				$page_mode = 'UseOutlines';
945
-				break;
946
-			}
947
-			case 'UseThumbs': {
948
-				$page_mode = 'UseThumbs';
949
-				break;
950
-			}
951
-			case 'FullScreen': {
952
-				$page_mode = 'FullScreen';
953
-				break;
954
-			}
955
-			case 'UseOC': {
956
-				$page_mode = 'UseOC';
957
-				break;
958
-			}
959
-			case '': {
960
-				$page_mode = 'UseAttachments';
961
-				break;
962
-			}
963
-			default: {
964
-				$page_mode = 'UseNone';
965
-			}
966
-		}
967
-		return $page_mode;
968
-	}
969
-
970
-	/**
971
-	 * Check if the URL exist.
972
-	 * @param $url (string) URL to check.
973
-	 * @return Boolean true if the URl exist, false otherwise.
974
-	 * @since 5.9.204 (2013-01-28)
975
-	 * @public static
976
-	 */
977
-	public static function isValidURL($url) {
978
-		$headers = @get_headers($url);
979
-    	return (strpos($headers[0], '200') !== false);
980
-	}
981
-
982
-	/**
983
-	 * Removes SHY characters from text.
984
-	 * Unicode Data:<ul>
985
-	 * <li>Name : SOFT HYPHEN, commonly abbreviated as SHY</li>
986
-	 * <li>HTML Entity (decimal): "&amp;#173;"</li>
987
-	 * <li>HTML Entity (hex): "&amp;#xad;"</li>
988
-	 * <li>HTML Entity (named): "&amp;shy;"</li>
989
-	 * <li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li>
990
-	 * <li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li>
991
-	 * <li>UTF-8 character: chr(194).chr(173)</li>
992
-	 * </ul>
993
-	 * @param $txt (string) input string
994
-	 * @param $unicode (boolean) True if we are in unicode mode, false otherwise.
995
-	 * @return string without SHY characters.
996
-	 * @since (4.5.019) 2009-02-28
997
-	 * @public static
998
-	 */
999
-	public static function removeSHY($txt='', $unicode=true) {
1000
-		$txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
1001
-		if (!$unicode) {
1002
-			$txt = preg_replace('/([\\xad]{1})/', '', $txt);
1003
-		}
1004
-		return $txt;
1005
-	}
1006
-
1007
-
1008
-	/**
1009
-	 * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
1010
-	 * @param $brd (mixed) Indicates if borders must be drawn around the cell block. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
1011
-	 * @param $position (string) multicell position: 'start', 'middle', 'end'
1012
-	 * @param $opencell (boolean) True when the cell is left open at the page bottom, false otherwise.
1013
-	 * @return border mode array
1014
-	 * @since 4.4.002 (2008-12-09)
1015
-	 * @public static
1016
-	 */
1017
-	public static function getBorderMode($brd, $position='start', $opencell=true) {
1018
-		if ((!$opencell) OR empty($brd)) {
1019
-			return $brd;
1020
-		}
1021
-		if ($brd == 1) {
1022
-			$brd = 'LTRB';
1023
-		}
1024
-		if (is_string($brd)) {
1025
-			// convert string to array
1026
-			$slen = strlen($brd);
1027
-			$newbrd = array();
1028
-			for ($i = 0; $i < $slen; ++$i) {
1029
-				$newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
1030
-			}
1031
-			$brd = $newbrd;
1032
-		}
1033
-		foreach ($brd as $border => $style) {
1034
-			switch ($position) {
1035
-				case 'start': {
1036
-					if (strpos($border, 'B') !== false) {
1037
-						// remove bottom line
1038
-						$newkey = str_replace('B', '', $border);
1039
-						if (strlen($newkey) > 0) {
1040
-							$brd[$newkey] = $style;
1041
-						}
1042
-						unset($brd[$border]);
1043
-					}
1044
-					break;
1045
-				}
1046
-				case 'middle': {
1047
-					if (strpos($border, 'B') !== false) {
1048
-						// remove bottom line
1049
-						$newkey = str_replace('B', '', $border);
1050
-						if (strlen($newkey) > 0) {
1051
-							$brd[$newkey] = $style;
1052
-						}
1053
-						unset($brd[$border]);
1054
-						$border = $newkey;
1055
-					}
1056
-					if (strpos($border, 'T') !== false) {
1057
-						// remove bottom line
1058
-						$newkey = str_replace('T', '', $border);
1059
-						if (strlen($newkey) > 0) {
1060
-							$brd[$newkey] = $style;
1061
-						}
1062
-						unset($brd[$border]);
1063
-					}
1064
-					break;
1065
-				}
1066
-				case 'end': {
1067
-					if (strpos($border, 'T') !== false) {
1068
-						// remove bottom line
1069
-						$newkey = str_replace('T', '', $border);
1070
-						if (strlen($newkey) > 0) {
1071
-							$brd[$newkey] = $style;
1072
-						}
1073
-						unset($brd[$border]);
1074
-					}
1075
-					break;
1076
-				}
1077
-			}
1078
-		}
1079
-		return $brd;
1080
-	}
1081
-
1082
-	/**
1083
-	 * Determine whether a string is empty.
1084
-	 * @param $str (string) string to be checked
1085
-	 * @return boolean true if string is empty
1086
-	 * @since 4.5.044 (2009-04-16)
1087
-	 * @public static
1088
-	 */
1089
-	public static function empty_string($str) {
1090
-		return (is_null($str) OR (is_string($str) AND (strlen($str) == 0)));
1091
-	}
1092
-
1093
-	/**
1094
-	 * Returns a temporary filename for caching object on filesystem.
1095
-	 * @param $type (string) Type of file (name of the subdir on the tcpdf cache folder).
1096
-	 * @return string filename.
1097
-	 * @since 4.5.000 (2008-12-31)
1098
-	 * @public static
1099
-	 */
1100
-	public static function getObjFilename($type='tmp') {
1101
-		return tempnam(K_PATH_CACHE, '__tcpdf_'.$type.'_'.md5(getmypid().uniqid('', true).rand().microtime(true)).'_');
1102
-	}
1103
-
1104
-	/**
1105
-	 * Add "\" before "\", "(" and ")"
1106
-	 * @param $s (string) string to escape.
1107
-	 * @return string escaped string.
1108
-	 * @public static
1109
-	 */
1110
-	public static function _escape($s) {
1111
-		// the chr(13) substitution fixes the Bugs item #1421290.
1112
-		return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
1113
-	}
1114
-
1115
-	/**
1116
-	* Escape some special characters (&lt; &gt; &amp;) for XML output.
1117
-	* @param $str (string) Input string to convert.
1118
-	* @return converted string
1119
-	* @since 5.9.121 (2011-09-28)
1120
-	 * @public static
1121
-	 */
1122
-	public static function _escapeXML($str) {
1123
-		$replaceTable = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
1124
-		$str = strtr($str, $replaceTable);
1125
-		return $str;
1126
-	}
1127
-
1128
-	/**
1129
-	 * Creates a copy of a class object
1130
-	 * @param $object (object) class object to be cloned
1131
-	 * @return cloned object
1132
-	 * @since 4.5.029 (2009-03-19)
1133
-	 * @public static
1134
-	 */
1135
-	public static function objclone($object) {
1136
-		if (($object instanceof Imagick) AND (version_compare(phpversion('imagick'), '3.0.1') !== 1)) {
1137
-			// on the versions after 3.0.1 the clone() method was deprecated in favour of clone keyword
1138
-			return @$object->clone();
1139
-		}
1140
-		return @clone($object);
1141
-	}
1142
-
1143
-	/**
1144
-	 * Ouput input data and compress it if possible.
1145
-	 * @param $data (string) Data to output.
1146
-	 * @param $length (int) Data length in bytes.
1147
-	 * @since 5.9.086
1148
-	 * @public static
1149
-	 */
1150
-	public static function sendOutputData($data, $length) {
1151
-		if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
1152
-			// the content length may vary if the server is using compression
1153
-			header('Content-Length: '.$length);
1154
-		}
1155
-		echo $data;
1156
-	}
1157
-
1158
-	/**
1159
-	 * Replace page number aliases with number.
1160
-	 * @param $page (string) Page content.
1161
-	 * @param $replace (array) Array of replacements (array keys are replacement strings, values are alias arrays).
1162
-	 * @param $diff (int) If passed, this will be set to the total char number difference between alias and replacements.
1163
-	 * @return replaced page content and updated $diff parameter as array.
1164
-	 * @public static
1165
-	 */
1166
-	public static function replacePageNumAliases($page, $replace, $diff=0) {
1167
-		foreach ($replace as $rep) {
1168
-			foreach ($rep[3] as $a) {
1169
-				if (strpos($page, $a) !== false) {
1170
-					$page = str_replace($a, $rep[0], $page);
1171
-					$diff += ($rep[2] - $rep[1]);
1172
-				}
1173
-			}
1174
-		}
1175
-		return array($page, $diff);
1176
-	}
1177
-
1178
-	/**
1179
-	 * Returns timestamp in seconds from formatted date-time.
1180
-	 * @param $date (string) Formatted date-time.
1181
-	 * @return int seconds.
1182
-	 * @since 5.9.152 (2012-03-23)
1183
-	 * @public static
1184
-	 */
1185
-	public static function getTimestamp($date) {
1186
-		if (($date[0] == 'D') AND ($date[1] == ':')) {
1187
-			// remove date prefix if present
1188
-			$date = substr($date, 2);
1189
-		}
1190
-		return strtotime($date);
1191
-	}
1192
-
1193
-	/**
1194
-	 * Returns a formatted date-time.
1195
-	 * @param $time (int) Time in seconds.
1196
-	 * @return string escaped date string.
1197
-	 * @since 5.9.152 (2012-03-23)
1198
-	 * @public static
1199
-	 */
1200
-	public static function getFormattedDate($time) {
1201
-		return substr_replace(date('YmdHisO', intval($time)), '\'', (0 - 2), 0).'\'';
1202
-	}
1203
-
1204
-	/**
1205
-	 * Get ULONG from string (Big Endian 32-bit unsigned integer).
1206
-	 * @param $str (string) string from where to extract value
1207
-	 * @param $offset (int) point from where to read the data
1208
-	 * @return int 32 bit value
1209
-	 * @author Nicola Asuni
1210
-	 * @since 5.2.000 (2010-06-02)
1211
-	 * @public static
1212
-	 */
1213
-	public static function _getULONG($str, $offset) {
1214
-		$v = unpack('Ni', substr($str, $offset, 4));
1215
-		return $v['i'];
1216
-	}
1217
-
1218
-	/**
1219
-	 * Get USHORT from string (Big Endian 16-bit unsigned integer).
1220
-	 * @param $str (string) string from where to extract value
1221
-	 * @param $offset (int) point from where to read the data
1222
-	 * @return int 16 bit value
1223
-	 * @author Nicola Asuni
1224
-	 * @since 5.2.000 (2010-06-02)
1225
-	 * @public static
1226
-	 */
1227
-	public static function _getUSHORT($str, $offset) {
1228
-		$v = unpack('ni', substr($str, $offset, 2));
1229
-		return $v['i'];
1230
-	}
1231
-
1232
-	/**
1233
-	 * Get SHORT from string (Big Endian 16-bit signed integer).
1234
-	 * @param $str (string) String from where to extract value.
1235
-	 * @param $offset (int) Point from where to read the data.
1236
-	 * @return int 16 bit value
1237
-	 * @author Nicola Asuni
1238
-	 * @since 5.2.000 (2010-06-02)
1239
-	 * @public static
1240
-	 */
1241
-	public static function _getSHORT($str, $offset) {
1242
-		$v = unpack('si', substr($str, $offset, 2));
1243
-		return $v['i'];
1244
-	}
1245
-
1246
-	/**
1247
-	 * Get FWORD from string (Big Endian 16-bit signed integer).
1248
-	 * @param $str (string) String from where to extract value.
1249
-	 * @param $offset (int) Point from where to read the data.
1250
-	 * @return int 16 bit value
1251
-	 * @author Nicola Asuni
1252
-	 * @since 5.9.123 (2011-09-30)
1253
-	 * @public static
1254
-	 */
1255
-	public static function _getFWORD($str, $offset) {
1256
-		$v = self::_getUSHORT($str, $offset);
1257
-		if ($v > 0x7fff) {
1258
-			$v -= 0x10000;
1259
-		}
1260
-		return $v;
1261
-	}
1262
-
1263
-	/**
1264
-	 * Get UFWORD from string (Big Endian 16-bit unsigned integer).
1265
-	 * @param $str (string) string from where to extract value
1266
-	 * @param $offset (int) point from where to read the data
1267
-	 * @return int 16 bit value
1268
-	 * @author Nicola Asuni
1269
-	 * @since 5.9.123 (2011-09-30)
1270
-	 * @public static
1271
-	 */
1272
-	public static function _getUFWORD($str, $offset) {
1273
-		$v = self::_getUSHORT($str, $offset);
1274
-		return $v;
1275
-	}
1276
-
1277
-	/**
1278
-	 * Get FIXED from string (32-bit signed fixed-point number (16.16).
1279
-	 * @param $str (string) string from where to extract value
1280
-	 * @param $offset (int) point from where to read the data
1281
-	 * @return int 16 bit value
1282
-	 * @author Nicola Asuni
1283
-	 * @since 5.9.123 (2011-09-30)
1284
-	 * @public static
1285
-	 */
1286
-	public static function _getFIXED($str, $offset) {
1287
-		// mantissa
1288
-		$m = self::_getFWORD($str, $offset);
1289
-		// fraction
1290
-		$f = self::_getUSHORT($str, ($offset + 2));
1291
-		$v = floatval(''.$m.'.'.$f.'');
1292
-		return $v;
1293
-	}
1294
-
1295
-	/**
1296
-	 * Get BYTE from string (8-bit unsigned integer).
1297
-	 * @param $str (string) String from where to extract value.
1298
-	 * @param $offset (int) Point from where to read the data.
1299
-	 * @return int 8 bit value
1300
-	 * @author Nicola Asuni
1301
-	 * @since 5.2.000 (2010-06-02)
1302
-	 * @public static
1303
-	 */
1304
-	public static function _getBYTE($str, $offset) {
1305
-		$v = unpack('Ci', substr($str, $offset, 1));
1306
-		return $v['i'];
1307
-	}
1308
-	/**
1309
-	 * Binary-safe and URL-safe file read.
1310
-	 * Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached.
1311
-	 * @param $handle (resource)
1312
-	 * @param $length (int)
1313
-	 * @return Returns the read string or FALSE in case of error.
1314
-	 * @author Nicola Asuni
1315
-	 * @since 4.5.027 (2009-03-16)
1316
-	 * @public static
1317
-	 */
1318
-	public static function rfread($handle, $length) {
1319
-		$data = fread($handle, $length);
1320
-		if ($data === false) {
1321
-			return false;
1322
-		}
1323
-		$rest = ($length - strlen($data));
1324
-		if ($rest > 0) {
1325
-			$data .= self::rfread($handle, $rest);
1326
-		}
1327
-		return $data;
1328
-	}
1329
-
1330
-	/**
1331
-	 * Read a 4-byte (32 bit) integer from file.
1332
-	 * @param $f (string) file name.
1333
-	 * @return 4-byte integer
1334
-	 * @public static
1335
-	 */
1336
-	public static function _freadint($f) {
1337
-		$a = unpack('Ni', fread($f, 4));
1338
-		return $a['i'];
1339
-	}
1340
-
1341
-	/**
1342
-	 * Returns a string containing random data to be used as a seed for encryption methods.
1343
-	 * @param $seed (string) starting seed value
1344
-	 * @return string containing random data
1345
-	 * @author Nicola Asuni
1346
-	 * @since 5.9.006 (2010-10-19)
1347
-	 * @public static
1348
-	 */
1349
-	public static function getRandomSeed($seed='') {
1350
-		$seed .= microtime();
1351
-		if (function_exists('openssl_random_pseudo_bytes') AND (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) {
1352
-			// this is not used on windows systems because it is very slow for a know bug
1353
-			$seed .= openssl_random_pseudo_bytes(512);
1354
-		} else {
1355
-			for ($i = 0; $i < 23; ++$i) {
1356
-				$seed .= uniqid('', true);
1357
-			}
1358
-		}
1359
-		$seed .= uniqid('', true);
1360
-		$seed .= rand();
1361
-		$seed .= getmypid();
1362
-		$seed .= __FILE__;
1363
-		if (isset($_SERVER['REMOTE_ADDR'])) {
1364
-			$seed .= $_SERVER['REMOTE_ADDR'];
1365
-		}
1366
-		if (isset($_SERVER['HTTP_USER_AGENT'])) {
1367
-			$seed .= $_SERVER['HTTP_USER_AGENT'];
1368
-		}
1369
-		if (isset($_SERVER['HTTP_ACCEPT'])) {
1370
-			$seed .= $_SERVER['HTTP_ACCEPT'];
1371
-		}
1372
-		if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
1373
-			$seed .= $_SERVER['HTTP_ACCEPT_ENCODING'];
1374
-		}
1375
-		if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
1376
-			$seed .= $_SERVER['HTTP_ACCEPT_LANGUAGE'];
1377
-		}
1378
-		if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
1379
-			$seed .= $_SERVER['HTTP_ACCEPT_CHARSET'];
1380
-		}
1381
-		$seed .= rand();
1382
-		$seed .= uniqid('', true);
1383
-		$seed .= microtime();
1384
-		return $seed;
1385
-	}
1386
-
1387
-	/**
1388
-	 * Encrypts a string using MD5 and returns it's value as a binary string.
1389
-	 * @param $str (string) input string
1390
-	 * @return String MD5 encrypted binary string
1391
-	 * @since 2.0.000 (2008-01-02)
1392
-	 * @public static
1393
-	 */
1394
-	public static function _md5_16($str) {
1395
-		return pack('H*', md5($str));
1396
-	}
1397
-
1398
-	/**
1399
-	 * Returns the input text exrypted using AES algorithm and the specified key.
1400
-	 * This method requires mcrypt.
1401
-	 * @param $key (string) encryption key
1402
-	 * @param $text (String) input text to be encrypted
1403
-	 * @return String encrypted text
1404
-	 * @author Nicola Asuni
1405
-	 * @since 5.0.005 (2010-05-11)
1406
-	 * @public static
1407
-	 */
1408
-	public static function _AES($key, $text) {
1409
-		// padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0)
1410
-		$padding = 16 - (strlen($text) % 16);
1411
-		$text .= str_repeat(chr($padding), $padding);
1412
-		$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
1413
-		$text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
1414
-		$text = $iv.$text;
1415
-		return $text;
1416
-	}
1417
-
1418
-	/**
1419
-	 * Returns the input text encrypted using RC4 algorithm and the specified key.
1420
-	 * RC4 is the standard encryption algorithm used in PDF format
1421
-	 * @param $key (string) Encryption key.
1422
-	 * @param $text (String) Input text to be encrypted.
1423
-	 * @param $last_enc_key (String) Reference to last RC4 key encrypted.
1424
-	 * @param $last_enc_key_c (String) Reference to last RC4 computed key.
1425
-	 * @return String encrypted text
1426
-	 * @since 2.0.000 (2008-01-02)
1427
-	 * @author Klemen Vodopivec, Nicola Asuni
1428
-	 * @public static
1429
-	 */
1430
-	public static function _RC4($key, $text, &$last_enc_key, &$last_enc_key_c) {
1431
-		if (function_exists('mcrypt_encrypt') AND ($out = @mcrypt_encrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, ''))) {
1432
-			// try to use mcrypt function if exist
1433
-			return $out;
1434
-		}
1435
-		if ($last_enc_key != $key) {
1436
-			$k = str_repeat($key, ((256 / strlen($key)) + 1));
1437
-			$rc4 = range(0, 255);
1438
-			$j = 0;
1439
-			for ($i = 0; $i < 256; ++$i) {
1440
-				$t = $rc4[$i];
1441
-				$j = ($j + $t + ord($k[$i])) % 256;
1442
-				$rc4[$i] = $rc4[$j];
1443
-				$rc4[$j] = $t;
1444
-			}
1445
-			$last_enc_key = $key;
1446
-			$last_enc_key_c = $rc4;
1447
-		} else {
1448
-			$rc4 = $last_enc_key_c;
1449
-		}
1450
-		$len = strlen($text);
1451
-		$a = 0;
1452
-		$b = 0;
1453
-		$out = '';
1454
-		for ($i = 0; $i < $len; ++$i) {
1455
-			$a = ($a + 1) % 256;
1456
-			$t = $rc4[$a];
1457
-			$b = ($b + $t) % 256;
1458
-			$rc4[$a] = $rc4[$b];
1459
-			$rc4[$b] = $t;
1460
-			$k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
1461
-			$out .= chr(ord($text[$i]) ^ $k);
1462
-		}
1463
-		return $out;
1464
-	}
1465
-
1466
-	/**
1467
-	 * Return the premission code used on encryption (P value).
1468
-	 * @param $permissions (Array) the set of permissions (specify the ones you want to block).
1469
-	 * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
1470
-	 * @since 5.0.005 (2010-05-12)
1471
-	 * @author Nicola Asuni
1472
-	 * @public static
1473
-	 */
1474
-	public static function getUserPermissionCode($permissions, $mode=0) {
1475
-		$options = array(
1476
-			'owner' => 2, // bit 2 -- inverted logic: cleared by default
1477
-			'print' => 4, // bit 3
1478
-			'modify' => 8, // bit 4
1479
-			'copy' => 16, // bit 5
1480
-			'annot-forms' => 32, // bit 6
1481
-			'fill-forms' => 256, // bit 9
1482
-			'extract' => 512, // bit 10
1483
-			'assemble' => 1024,// bit 11
1484
-			'print-high' => 2048 // bit 12
1485
-			);
1486
-		$protection = 2147422012; // 32 bit: (01111111 11111111 00001111 00111100)
1487
-		foreach ($permissions as $permission) {
1488
-			if (isset($options[$permission])) {
1489
-				if (($mode > 0) OR ($options[$permission] <= 32)) {
1490
-					// set only valid permissions
1491
-					if ($options[$permission] == 2) {
1492
-						// the logic for bit 2 is inverted (cleared by default)
1493
-						$protection += $options[$permission];
1494
-					} else {
1495
-						$protection -= $options[$permission];
1496
-					}
1497
-				}
1498
-			}
1499
-		}
1500
-		return $protection;
1501
-	}
1502
-
1503
-	/**
1504
-	 * Convert hexadecimal string to string
1505
-	 * @param $bs (string) byte-string to convert
1506
-	 * @return String
1507
-	 * @since 5.0.005 (2010-05-12)
1508
-	 * @author Nicola Asuni
1509
-	 * @public static
1510
-	 */
1511
-	public static function convertHexStringToString($bs) {
1512
-		$string = ''; // string to be returned
1513
-		$bslength = strlen($bs);
1514
-		if (($bslength % 2) != 0) {
1515
-			// padding
1516
-			$bs .= '0';
1517
-			++$bslength;
1518
-		}
1519
-		for ($i = 0; $i < $bslength; $i += 2) {
1520
-			$string .= chr(hexdec($bs[$i].$bs[($i + 1)]));
1521
-		}
1522
-		return $string;
1523
-	}
1524
-
1525
-	/**
1526
-	 * Convert string to hexadecimal string (byte string)
1527
-	 * @param $s (string) string to convert
1528
-	 * @return byte string
1529
-	 * @since 5.0.010 (2010-05-17)
1530
-	 * @author Nicola Asuni
1531
-	 * @public static
1532
-	 */
1533
-	public static function convertStringToHexString($s) {
1534
-		$bs = '';
1535
-		$chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY);
1536
-		foreach ($chars as $c) {
1537
-			$bs .= sprintf('%02s', dechex(ord($c)));
1538
-		}
1539
-		return $bs;
1540
-	}
1541
-
1542
-	/**
1543
-	 * Convert encryption P value to a string of bytes, low-order byte first.
1544
-	 * @param $protection (string) 32bit encryption permission value (P value)
1545
-	 * @return String
1546
-	 * @since 5.0.005 (2010-05-12)
1547
-	 * @author Nicola Asuni
1548
-	 * @public static
1549
-	 */
1550
-	public static function getEncPermissionsString($protection) {
1551
-		$binprot = sprintf('%032b', $protection);
1552
-		$str = chr(bindec(substr($binprot, 24, 8)));
1553
-		$str .= chr(bindec(substr($binprot, 16, 8)));
1554
-		$str .= chr(bindec(substr($binprot, 8, 8)));
1555
-		$str .= chr(bindec(substr($binprot, 0, 8)));
1556
-		return $str;
1557
-	}
1558
-
1559
-	/**
1560
-	 * Encode a name object.
1561
-	 * @param $name (string) Name object to encode.
1562
-	 * @return (string) Encoded name object.
1563
-	 * @author Nicola Asuni
1564
-	 * @since 5.9.097 (2011-06-23)
1565
-	 * @public static
1566
-	 */
1567
-	public static function encodeNameObject($name) {
1568
-		$escname = '';
1569
-		$length = strlen($name);
1570
-		for ($i = 0; $i < $length; ++$i) {
1571
-			$chr = $name[$i];
1572
-			if (preg_match('/[0-9a-zA-Z]/', $chr) == 1) {
1573
-				$escname .= $chr;
1574
-			} else {
1575
-				$escname .= sprintf('#%02X', ord($chr));
1576
-			}
1577
-		}
1578
-		return $escname;
1579
-	}
1580
-
1581
-	/**
1582
-	 * Convert JavaScript form fields properties array to Annotation Properties array.
1583
-	 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
1584
-	 * @param $spot_colors (array) Reference to spot colors array.
1585
-	 * @param $rtl (boolean) True if in Right-To-Left text direction mode, false otherwise.
1586
-	 * @return array of annotation properties
1587
-	 * @author Nicola Asuni
1588
-	 * @since 4.8.000 (2009-09-06)
1589
-	 * @public static
1590
-	 */
1591
-	public static function getAnnotOptFromJSProp($prop, &$spot_colors, $rtl=false) {
1592
-		if (isset($prop['aopt']) AND is_array($prop['aopt'])) {
1593
-			// the annotation options area lready defined
1594
-			return $prop['aopt'];
1595
-		}
1596
-		$opt = array(); // value to be returned
1597
-		// alignment: Controls how the text is laid out within the text field.
1598
-		if (isset($prop['alignment'])) {
1599
-			switch ($prop['alignment']) {
1600
-				case 'left': {
1601
-					$opt['q'] = 0;
1602
-					break;
1603
-				}
1604
-				case 'center': {
1605
-					$opt['q'] = 1;
1606
-					break;
1607
-				}
1608
-				case 'right': {
1609
-					$opt['q'] = 2;
1610
-					break;
1611
-				}
1612
-				default: {
1613
-					$opt['q'] = ($rtl)?2:0;
1614
-					break;
1615
-				}
1616
-			}
1617
-		}
1618
-		// lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle.
1619
-		if (isset($prop['lineWidth'])) {
1620
-			$linewidth = intval($prop['lineWidth']);
1621
-		} else {
1622
-			$linewidth = 1;
1623
-		}
1624
-		// borderStyle: The border style for a field.
1625
-		if (isset($prop['borderStyle'])) {
1626
-			switch ($prop['borderStyle']) {
1627
-				case 'border.d':
1628
-				case 'dashed': {
1629
-					$opt['border'] = array(0, 0, $linewidth, array(3, 2));
1630
-					$opt['bs'] = array('w'=>$linewidth, 's'=>'D', 'd'=>array(3, 2));
1631
-					break;
1632
-				}
1633
-				case 'border.b':
1634
-				case 'beveled': {
1635
-					$opt['border'] = array(0, 0, $linewidth);
1636
-					$opt['bs'] = array('w'=>$linewidth, 's'=>'B');
1637
-					break;
1638
-				}
1639
-				case 'border.i':
1640
-				case 'inset': {
1641
-					$opt['border'] = array(0, 0, $linewidth);
1642
-					$opt['bs'] = array('w'=>$linewidth, 's'=>'I');
1643
-					break;
1644
-				}
1645
-				case 'border.u':
1646
-				case 'underline': {
1647
-					$opt['border'] = array(0, 0, $linewidth);
1648
-					$opt['bs'] = array('w'=>$linewidth, 's'=>'U');
1649
-					break;
1650
-				}
1651
-				case 'border.s':
1652
-				case 'solid': {
1653
-					$opt['border'] = array(0, 0, $linewidth);
1654
-					$opt['bs'] = array('w'=>$linewidth, 's'=>'S');
1655
-					break;
1656
-				}
1657
-				default: {
1658
-					break;
1659
-				}
1660
-			}
1661
-		}
1662
-		if (isset($prop['border']) AND is_array($prop['border'])) {
1663
-			$opt['border'] = $prop['border'];
1664
-		}
1665
-		if (!isset($opt['mk'])) {
1666
-			$opt['mk'] = array();
1667
-		}
1668
-		if (!isset($opt['mk']['if'])) {
1669
-			$opt['mk']['if'] = array();
1670
-		}
1671
-		$opt['mk']['if']['a'] = array(0.5, 0.5);
1672
-		// buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon.
1673
-		if (isset($prop['buttonAlignX'])) {
1674
-			$opt['mk']['if']['a'][0] = $prop['buttonAlignX'];
1675
-		}
1676
-		// buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon.
1677
-		if (isset($prop['buttonAlignY'])) {
1678
-			$opt['mk']['if']['a'][1] = $prop['buttonAlignY'];
1679
-		}
1680
-		// buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field.
1681
-		if (isset($prop['buttonFitBounds']) AND ($prop['buttonFitBounds'] == 'true')) {
1682
-			$opt['mk']['if']['fb'] = true;
1683
-		}
1684
-		// buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face.
1685
-		if (isset($prop['buttonScaleHow'])) {
1686
-			switch ($prop['buttonScaleHow']) {
1687
-				case 'scaleHow.proportional': {
1688
-					$opt['mk']['if']['s'] = 'P';
1689
-					break;
1690
-				}
1691
-				case 'scaleHow.anamorphic': {
1692
-					$opt['mk']['if']['s'] = 'A';
1693
-					break;
1694
-				}
1695
-			}
1696
-		}
1697
-		// buttonScaleWhen: Controls when an icon is scaled to fit inside the button face.
1698
-		if (isset($prop['buttonScaleWhen'])) {
1699
-			switch ($prop['buttonScaleWhen']) {
1700
-				case 'scaleWhen.always': {
1701
-					$opt['mk']['if']['sw'] = 'A';
1702
-					break;
1703
-				}
1704
-				case 'scaleWhen.never': {
1705
-					$opt['mk']['if']['sw'] = 'N';
1706
-					break;
1707
-				}
1708
-				case 'scaleWhen.tooBig': {
1709
-					$opt['mk']['if']['sw'] = 'B';
1710
-					break;
1711
-				}
1712
-				case 'scaleWhen.tooSmall': {
1713
-					$opt['mk']['if']['sw'] = 'S';
1714
-					break;
1715
-				}
1716
-			}
1717
-		}
1718
-		// buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face.
1719
-		if (isset($prop['buttonPosition'])) {
1720
-			switch ($prop['buttonPosition']) {
1721
-				case 0:
1722
-				case 'position.textOnly': {
1723
-					$opt['mk']['tp'] = 0;
1724
-					break;
1725
-				}
1726
-				case 1:
1727
-				case 'position.iconOnly': {
1728
-					$opt['mk']['tp'] = 1;
1729
-					break;
1730
-				}
1731
-				case 2:
1732
-				case 'position.iconTextV': {
1733
-					$opt['mk']['tp'] = 2;
1734
-					break;
1735
-				}
1736
-				case 3:
1737
-				case 'position.textIconV': {
1738
-					$opt['mk']['tp'] = 3;
1739
-					break;
1740
-				}
1741
-				case 4:
1742
-				case 'position.iconTextH': {
1743
-					$opt['mk']['tp'] = 4;
1744
-					break;
1745
-				}
1746
-				case 5:
1747
-				case 'position.textIconH': {
1748
-					$opt['mk']['tp'] = 5;
1749
-					break;
1750
-				}
1751
-				case 6:
1752
-				case 'position.overlay': {
1753
-					$opt['mk']['tp'] = 6;
1754
-					break;
1755
-				}
1756
-			}
1757
-		}
1758
-		// fillColor: Specifies the background color for a field.
1759
-		if (isset($prop['fillColor'])) {
1760
-			if (is_array($prop['fillColor'])) {
1761
-				$opt['mk']['bg'] = $prop['fillColor'];
1762
-			} else {
1763
-				$opt['mk']['bg'] = TCPDF_COLORS::convertHTMLColorToDec($prop['fillColor'], $spot_colors);
1764
-			}
1765
-		}
1766
-		// 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.
1767
-		if (isset($prop['strokeColor'])) {
1768
-			if (is_array($prop['strokeColor'])) {
1769
-				$opt['mk']['bc'] = $prop['strokeColor'];
1770
-			} else {
1771
-				$opt['mk']['bc'] = TCPDF_COLORS::convertHTMLColorToDec($prop['strokeColor'], $spot_colors);
1772
-			}
1773
-		}
1774
-		// rotation: The rotation of a widget in counterclockwise increments.
1775
-		if (isset($prop['rotation'])) {
1776
-			$opt['mk']['r'] = $prop['rotation'];
1777
-		}
1778
-		// charLimit: Limits the number of characters that a user can type into a text field.
1779
-		if (isset($prop['charLimit'])) {
1780
-			$opt['maxlen'] = intval($prop['charLimit']);
1781
-		}
1782
-		if (!isset($ff)) {
1783
-			$ff = 0; // default value
1784
-		}
1785
-		// readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
1786
-		if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
1787
-			$ff += 1 << 0;
1788
-		}
1789
-		// required: Specifies whether a field requires a value.
1790
-		if (isset($prop['required']) AND ($prop['required'] == 'true')) {
1791
-			$ff += 1 << 1;
1792
-		}
1793
-		// multiline: Controls how text is wrapped within the field.
1794
-		if (isset($prop['multiline']) AND ($prop['multiline'] == 'true')) {
1795
-			$ff += 1 << 12;
1796
-		}
1797
-		// password: Specifies whether the field should display asterisks when data is entered in the field.
1798
-		if (isset($prop['password']) AND ($prop['password'] == 'true')) {
1799
-			$ff += 1 << 13;
1800
-		}
1801
-		// NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect.
1802
-		if (isset($prop['NoToggleToOff']) AND ($prop['NoToggleToOff'] == 'true')) {
1803
-			$ff += 1 << 14;
1804
-		}
1805
-		// Radio: If set, the field is a set of radio buttons.
1806
-		if (isset($prop['Radio']) AND ($prop['Radio'] == 'true')) {
1807
-			$ff += 1 << 15;
1808
-		}
1809
-		// Pushbutton: If set, the field is a pushbutton that does not retain a permanent value.
1810
-		if (isset($prop['Pushbutton']) AND ($prop['Pushbutton'] == 'true')) {
1811
-			$ff += 1 << 16;
1812
-		}
1813
-		// Combo: If set, the field is a combo box; if clear, the field is a list box.
1814
-		if (isset($prop['Combo']) AND ($prop['Combo'] == 'true')) {
1815
-			$ff += 1 << 17;
1816
-		}
1817
-		// editable: Controls whether a combo box is editable.
1818
-		if (isset($prop['editable']) AND ($prop['editable'] == 'true')) {
1819
-			$ff += 1 << 18;
1820
-		}
1821
-		// Sort: If set, the field's option items shall be sorted alphabetically.
1822
-		if (isset($prop['Sort']) AND ($prop['Sort'] == 'true')) {
1823
-			$ff += 1 << 19;
1824
-		}
1825
-		// fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection).
1826
-		if (isset($prop['fileSelect']) AND ($prop['fileSelect'] == 'true')) {
1827
-			$ff += 1 << 20;
1828
-		}
1829
-		// multipleSelection: If true, indicates that a list box allows a multiple selection of items.
1830
-		if (isset($prop['multipleSelection']) AND ($prop['multipleSelection'] == 'true')) {
1831
-			$ff += 1 << 21;
1832
-		}
1833
-		// doNotSpellCheck: If true, spell checking is not performed on this editable text field.
1834
-		if (isset($prop['doNotSpellCheck']) AND ($prop['doNotSpellCheck'] == 'true')) {
1835
-			$ff += 1 << 22;
1836
-		}
1837
-		// doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field.
1838
-		if (isset($prop['doNotScroll']) AND ($prop['doNotScroll'] == 'true')) {
1839
-			$ff += 1 << 23;
1840
-		}
1841
-		// 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.
1842
-		if (isset($prop['comb']) AND ($prop['comb'] == 'true')) {
1843
-			$ff += 1 << 24;
1844
-		}
1845
-		// 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.
1846
-		if (isset($prop['radiosInUnison']) AND ($prop['radiosInUnison'] == 'true')) {
1847
-			$ff += 1 << 25;
1848
-		}
1849
-		// richText: If true, the field allows rich text formatting.
1850
-		if (isset($prop['richText']) AND ($prop['richText'] == 'true')) {
1851
-			$ff += 1 << 25;
1852
-		}
1853
-		// commitOnSelChange: Controls whether a field value is committed after a selection change.
1854
-		if (isset($prop['commitOnSelChange']) AND ($prop['commitOnSelChange'] == 'true')) {
1855
-			$ff += 1 << 26;
1856
-		}
1857
-		$opt['ff'] = $ff;
1858
-		// defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset.
1859
-		if (isset($prop['defaultValue'])) {
1860
-			$opt['dv'] = $prop['defaultValue'];
1861
-		}
1862
-		$f = 4; // default value for annotation flags
1863
-		// readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
1864
-		if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
1865
-			$f += 1 << 6;
1866
-		}
1867
-		// display: Controls whether the field is hidden or visible on screen and in print.
1868
-		if (isset($prop['display'])) {
1869
-			if ($prop['display'] == 'display.visible') {
1870
-				//
1871
-			} elseif ($prop['display'] == 'display.hidden') {
1872
-				$f += 1 << 1;
1873
-			} elseif ($prop['display'] == 'display.noPrint') {
1874
-				$f -= 1 << 2;
1875
-			} elseif ($prop['display'] == 'display.noView') {
1876
-				$f += 1 << 5;
1877
-			}
1878
-		}
1879
-		$opt['f'] = $f;
1880
-		// currentValueIndices: Reads and writes single or multiple values of a list box or combo box.
1881
-		if (isset($prop['currentValueIndices']) AND is_array($prop['currentValueIndices'])) {
1882
-			$opt['i'] = $prop['currentValueIndices'];
1883
-		}
1884
-		// value: The value of the field data that the user has entered.
1885
-		if (isset($prop['value'])) {
1886
-			if (is_array($prop['value'])) {
1887
-				$opt['opt'] = array();
1888
-				foreach ($prop['value'] AS $key => $optval) {
1889
-					// exportValues: An array of strings representing the export values for the field.
1890
-					if (isset($prop['exportValues'][$key])) {
1891
-						$opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]);
1892
-					} else {
1893
-						$opt['opt'][$key] = $prop['value'][$key];
1894
-					}
1895
-				}
1896
-			} else {
1897
-				$opt['v'] = $prop['value'];
1898
-			}
1899
-		}
1900
-		// richValue: This property specifies the text contents and formatting of a rich text field.
1901
-		if (isset($prop['richValue'])) {
1902
-			$opt['rv'] = $prop['richValue'];
1903
-		}
1904
-		// submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded).
1905
-		if (isset($prop['submitName'])) {
1906
-			$opt['tm'] = $prop['submitName'];
1907
-		}
1908
-		// name: Fully qualified field name.
1909
-		if (isset($prop['name'])) {
1910
-			$opt['t'] = $prop['name'];
1911
-		}
1912
-		// userName: The user name (short description string) of the field.
1913
-		if (isset($prop['userName'])) {
1914
-			$opt['tu'] = $prop['userName'];
1915
-		}
1916
-		// highlight: Defines how a button reacts when a user clicks it.
1917
-		if (isset($prop['highlight'])) {
1918
-			switch ($prop['highlight']) {
1919
-				case 'none':
1920
-				case 'highlight.n': {
1921
-					$opt['h'] = 'N';
1922
-					break;
1923
-				}
1924
-				case 'invert':
1925
-				case 'highlight.i': {
1926
-					$opt['h'] = 'i';
1927
-					break;
1928
-				}
1929
-				case 'push':
1930
-				case 'highlight.p': {
1931
-					$opt['h'] = 'P';
1932
-					break;
1933
-				}
1934
-				case 'outline':
1935
-				case 'highlight.o': {
1936
-					$opt['h'] = 'O';
1937
-					break;
1938
-				}
1939
-			}
1940
-		}
1941
-		// Unsupported options:
1942
-		// - calcOrderIndex: Changes the calculation order of fields in the document.
1943
-		// - delay: Delays the redrawing of a field's appearance.
1944
-		// - defaultStyle: This property defines the default style attributes for the form field.
1945
-		// - style: Allows the user to set the glyph style of a check box or radio button.
1946
-		// - textColor, textFont, textSize
1947
-		return $opt;
1948
-	}
1949
-
1950
-	/**
1951
-	 * Format the page numbers.
1952
-	 * This method can be overriden for custom formats.
1953
-	 * @param $num (int) page number
1954
-	 * @since 4.2.005 (2008-11-06)
1955
-	 * @public static
1956
-	 */
1957
-	public static function formatPageNumber($num) {
1958
-		return number_format((float)$num, 0, '', '.');
1959
-	}
1960
-
1961
-	/**
1962
-	 * Format the page numbers on the Table Of Content.
1963
-	 * This method can be overriden for custom formats.
1964
-	 * @param $num (int) page number
1965
-	 * @since 4.5.001 (2009-01-04)
1966
-	 * @see addTOC(), addHTMLTOC()
1967
-	 * @public static
1968
-	 */
1969
-	public static function formatTOCPageNumber($num) {
1970
-		return number_format((float)$num, 0, '', '.');
1971
-	}
1972
-
1973
-	/**
1974
-	 * Extracts the CSS properties from a CSS string.
1975
-	 * @param $cssdata (string) string containing CSS definitions.
1976
-	 * @return An array where the keys are the CSS selectors and the values are the CSS properties.
1977
-	 * @author Nicola Asuni
1978
-	 * @since 5.1.000 (2010-05-25)
1979
-	 * @public static
1980
-	 */
1981
-	public static function extractCSSproperties($cssdata) {
1982
-		if (empty($cssdata)) {
1983
-			return array();
1984
-		}
1985
-		// remove comments
1986
-		$cssdata = preg_replace('/\/\*[^\*]*\*\//', '', $cssdata);
1987
-		// remove newlines and multiple spaces
1988
-		$cssdata = preg_replace('/[\s]+/', ' ', $cssdata);
1989
-		// remove some spaces
1990
-		$cssdata = preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata);
1991
-		// remove empty blocks
1992
-		$cssdata = preg_replace('/([^\}\{]+)\{\}/', '', $cssdata);
1993
-		// replace media type parenthesis
1994
-		$cssdata = preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1§', $cssdata);
1995
-		$cssdata = preg_replace('/\}\}/si', '}§', $cssdata);
1996
-		// trim string
1997
-		$cssdata = trim($cssdata);
1998
-		// find media blocks (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
1999
-		$cssblocks = array();
2000
-		$matches = array();
2001
-		if (preg_match_all('/@media[\s]+([^\§]*)§([^§]*)§/i', $cssdata, $matches) > 0) {
2002
-			foreach ($matches[1] as $key => $type) {
2003
-				$cssblocks[$type] = $matches[2][$key];
2004
-			}
2005
-			// remove media blocks
2006
-			$cssdata = preg_replace('/@media[\s]+([^\§]*)§([^§]*)§/i', '', $cssdata);
2007
-		}
2008
-		// keep 'all' and 'print' media, other media types are discarded
2009
-		if (isset($cssblocks['all']) AND !empty($cssblocks['all'])) {
2010
-			$cssdata .= $cssblocks['all'];
2011
-		}
2012
-		if (isset($cssblocks['print']) AND !empty($cssblocks['print'])) {
2013
-			$cssdata .= $cssblocks['print'];
2014
-		}
2015
-		// reset css blocks array
2016
-		$cssblocks = array();
2017
-		$matches = array();
2018
-		// explode css data string into array
2019
-		if (substr($cssdata, -1) == '}') {
2020
-			// remove last parethesis
2021
-			$cssdata = substr($cssdata, 0, -1);
2022
-		}
2023
-		$matches = explode('}', $cssdata);
2024
-		foreach ($matches as $key => $block) {
2025
-			// index 0 contains the CSS selector, index 1 contains CSS properties
2026
-			$cssblocks[$key] = explode('{', $block);
2027
-			if (!isset($cssblocks[$key][1])) {
2028
-				// remove empty definitions
2029
-				unset($cssblocks[$key]);
2030
-			}
2031
-		}
2032
-		// split groups of selectors (comma-separated list of selectors)
2033
-		foreach ($cssblocks as $key => $block) {
2034
-			if (strpos($block[0], ',') > 0) {
2035
-				$selectors = explode(',', $block[0]);
2036
-				foreach ($selectors as $sel) {
2037
-					$cssblocks[] = array(0 => trim($sel), 1 => $block[1]);
2038
-				}
2039
-				unset($cssblocks[$key]);
2040
-			}
2041
-		}
2042
-		// covert array to selector => properties
2043
-		$cssdata = array();
2044
-		foreach ($cssblocks as $block) {
2045
-			$selector = $block[0];
2046
-			// calculate selector's specificity
2047
-			$matches = array();
2048
-			$a = 0; // the declaration is not from is a 'style' attribute
2049
-			$b = intval(preg_match_all('/[\#]/', $selector, $matches)); // number of ID attributes
2050
-			$c = intval(preg_match_all('/[\[\.]/', $selector, $matches)); // number of other attributes
2051
-			$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
2052
-			$d = intval(preg_match_all('/[\>\+\~\s]{1}[a-zA-Z0-9]+/', ' '.$selector, $matches)); // number of element names
2053
-			$d += intval(preg_match_all('/[\:][\:]/', $selector, $matches)); // number of pseudo-elements
2054
-			$specificity = $a.$b.$c.$d;
2055
-			// add specificity to the beginning of the selector
2056
-			$cssdata[$specificity.' '.$selector] = $block[1];
2057
-		}
2058
-		// sort selectors alphabetically to account for specificity
2059
-		ksort($cssdata, SORT_STRING);
2060
-		// return array
2061
-		return $cssdata;
2062
-	}
2063
-
2064
-	/**
2065
-	 * Cleanup HTML code (requires HTML Tidy library).
2066
-	 * @param $html (string) htmlcode to fix
2067
-	 * @param $default_css (string) CSS commands to add
2068
-	 * @param $tagvs (array) parameters for setHtmlVSpace method
2069
-	 * @param $tidy_options (array) options for tidy_parse_string function
2070
-	 * @param $tagvspaces (array) Array of vertical spaces for tags.
2071
-	 * @return string XHTML code cleaned up
2072
-	 * @author Nicola Asuni
2073
-	 * @since 5.9.017 (2010-11-16)
2074
-	 * @see setHtmlVSpace()
2075
-	 * @public static
2076
-	 */
2077
-	public static function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='', &$tagvspaces) {
2078
-		// configure parameters for HTML Tidy
2079
-		if ($tidy_options === '') {
2080
-			$tidy_options = array (
2081
-				'clean' => 1,
2082
-				'drop-empty-paras' => 0,
2083
-				'drop-proprietary-attributes' => 1,
2084
-				'fix-backslash' => 1,
2085
-				'hide-comments' => 1,
2086
-				'join-styles' => 1,
2087
-				'lower-literals' => 1,
2088
-				'merge-divs' => 1,
2089
-				'merge-spans' => 1,
2090
-				'output-xhtml' => 1,
2091
-				'word-2000' => 1,
2092
-				'wrap' => 0,
2093
-				'output-bom' => 0,
2094
-				//'char-encoding' => 'utf8',
2095
-				//'input-encoding' => 'utf8',
2096
-				//'output-encoding' => 'utf8'
2097
-			);
2098
-		}
2099
-		// clean up the HTML code
2100
-		$tidy = tidy_parse_string($html, $tidy_options);
2101
-		// fix the HTML
2102
-		$tidy->cleanRepair();
2103
-		// get the CSS part
2104
-		$tidy_head = tidy_get_head($tidy);
2105
-		$css = $tidy_head->value;
2106
-		$css = preg_replace('/<style([^>]+)>/ims', '<style>', $css);
2107
-		$css = preg_replace('/<\/style>(.*)<style>/ims', "\n", $css);
2108
-		$css = str_replace('/*<![CDATA[*/', '', $css);
2109
-		$css = str_replace('/*]]>*/', '', $css);
2110
-		preg_match('/<style>(.*)<\/style>/ims', $css, $matches);
2111
-		if (isset($matches[1])) {
2112
-			$css = strtolower($matches[1]);
2113
-		} else {
2114
-			$css = '';
2115
-		}
2116
-		// include default css
2117
-		$css = '<style>'.$default_css.$css.'</style>';
2118
-		// get the body part
2119
-		$tidy_body = tidy_get_body($tidy);
2120
-		$html = $tidy_body->value;
2121
-		// fix some self-closing tags
2122
-		$html = str_replace('<br>', '<br />', $html);
2123
-		// remove some empty tag blocks
2124
-		$html = preg_replace('/<div([^\>]*)><\/div>/', '', $html);
2125
-		$html = preg_replace('/<p([^\>]*)><\/p>/', '', $html);
2126
-		if ($tagvs !== '') {
2127
-			// set vertical space for some XHTML tags
2128
-			$tagvspaces = $tagvs;
2129
-		}
2130
-		// return the cleaned XHTML code + CSS
2131
-		return $css.$html;
2132
-	}
2133
-
2134
-	/**
2135
-	 * Returns true if the CSS selector is valid for the selected HTML tag
2136
-	 * @param $dom (array) array of HTML tags and properties
2137
-	 * @param $key (int) key of the current HTML tag
2138
-	 * @param $selector (string) CSS selector string
2139
-	 * @return true if the selector is valid, false otherwise
2140
-	 * @since 5.1.000 (2010-05-25)
2141
-	 * @public static
2142
-	 */
2143
-	public static function isValidCSSSelectorForTag($dom, $key, $selector) {
2144
-		$valid = false; // value to be returned
2145
-		$tag = $dom[$key]['value'];
2146
-		$class = array();
2147
-		if (isset($dom[$key]['attribute']['class']) AND !empty($dom[$key]['attribute']['class'])) {
2148
-			$class = explode(' ', strtolower($dom[$key]['attribute']['class']));
2149
-		}
2150
-		$id = '';
2151
-		if (isset($dom[$key]['attribute']['id']) AND !empty($dom[$key]['attribute']['id'])) {
2152
-			$id = strtolower($dom[$key]['attribute']['id']);
2153
-		}
2154
-		$selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector);
2155
-		$matches = array();
2156
-		if (preg_match_all('/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si', $selector, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) > 0) {
2157
-			$parentop = array_pop($matches[1]);
2158
-			$operator = $parentop[0];
2159
-			$offset = $parentop[1];
2160
-			$lasttag = array_pop($matches[2]);
2161
-			$lasttag = strtolower(trim($lasttag[0]));
2162
-			if (($lasttag == '*') OR ($lasttag == $tag)) {
2163
-				// the last element on selector is our tag or 'any tag'
2164
-				$attrib = array_pop($matches[3]);
2165
-				$attrib = strtolower(trim($attrib[0]));
2166
-				if (!empty($attrib)) {
2167
-					// check if matches class, id, attribute, pseudo-class or pseudo-element
2168
-					switch ($attrib[0]) {
2169
-						case '.': { // class
2170
-							if (in_array(substr($attrib, 1), $class)) {
2171
-								$valid = true;
2172
-							}
2173
-							break;
2174
-						}
2175
-						case '#': { // ID
2176
-							if (substr($attrib, 1) == $id) {
2177
-								$valid = true;
2178
-							}
2179
-							break;
2180
-						}
2181
-						case '[': { // attribute
2182
-							$attrmatch = array();
2183
-							if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) {
2184
-								$att = strtolower($attrmatch[1]);
2185
-								$val = $attrmatch[3];
2186
-								if (isset($dom[$key]['attribute'][$att])) {
2187
-									switch ($attrmatch[2]) {
2188
-										case '=': {
2189
-											if ($dom[$key]['attribute'][$att] == $val) {
2190
-												$valid = true;
2191
-											}
2192
-											break;
2193
-										}
2194
-										case '~=': {
2195
-											if (in_array($val, explode(' ', $dom[$key]['attribute'][$att]))) {
2196
-												$valid = true;
2197
-											}
2198
-											break;
2199
-										}
2200
-										case '^=': {
2201
-											if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val))) {
2202
-												$valid = true;
2203
-											}
2204
-											break;
2205
-										}
2206
-										case '$=': {
2207
-											if ($val == substr($dom[$key]['attribute'][$att], -strlen($val))) {
2208
-												$valid = true;
2209
-											}
2210
-											break;
2211
-										}
2212
-										case '*=': {
2213
-											if (strpos($dom[$key]['attribute'][$att], $val) !== false) {
2214
-												$valid = true;
2215
-											}
2216
-											break;
2217
-										}
2218
-										case '|=': {
2219
-											if ($dom[$key]['attribute'][$att] == $val) {
2220
-												$valid = true;
2221
-											} elseif (preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) {
2222
-												$valid = true;
2223
-											}
2224
-											break;
2225
-										}
2226
-										default: {
2227
-											$valid = true;
2228
-										}
2229
-									}
2230
-								}
2231
-							}
2232
-							break;
2233
-						}
2234
-						case ':': { // pseudo-class or pseudo-element
2235
-							if ($attrib[1] == ':') { // pseudo-element
2236
-								// pseudo-elements are not supported!
2237
-								// (::first-line, ::first-letter, ::before, ::after)
2238
-							} else { // pseudo-class
2239
-								// pseudo-classes are not supported!
2240
-								// (: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)
2241
-							}
2242
-							break;
2243
-						}
2244
-					} // end of switch
2245
-				} else {
2246
-					$valid = true;
2247
-				}
2248
-				if ($valid AND ($offset > 0)) {
2249
-					$valid = false;
2250
-					// check remaining selector part
2251
-					$selector = substr($selector, 0, $offset);
2252
-					switch ($operator) {
2253
-						case ' ': { // descendant of an element
2254
-							while ($dom[$key]['parent'] > 0) {
2255
-								if (self::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector)) {
2256
-									$valid = true;
2257
-									break;
2258
-								} else {
2259
-									$key = $dom[$key]['parent'];
2260
-								}
2261
-							}
2262
-							break;
2263
-						}
2264
-						case '>': { // child of an element
2265
-							$valid = self::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector);
2266
-							break;
2267
-						}
2268
-						case '+': { // immediately preceded by an element
2269
-							for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
2270
-								if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
2271
-									$valid = self::isValidCSSSelectorForTag($dom, $i, $selector);
2272
-									break;
2273
-								}
2274
-							}
2275
-							break;
2276
-						}
2277
-						case '~': { // preceded by an element
2278
-							for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
2279
-								if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
2280
-									if (self::isValidCSSSelectorForTag($dom, $i, $selector)) {
2281
-										break;
2282
-									}
2283
-								}
2284
-							}
2285
-							break;
2286
-						}
2287
-					}
2288
-				}
2289
-			}
2290
-		}
2291
-		return $valid;
2292
-	}
2293
-
2294
-	/**
2295
-	 * Returns the styles array that apply for the selected HTML tag.
2296
-	 * @param $dom (array) array of HTML tags and properties
2297
-	 * @param $key (int) key of the current HTML tag
2298
-	 * @param $css (array) array of CSS properties
2299
-	 * @return array containing CSS properties
2300
-	 * @since 5.1.000 (2010-05-25)
2301
-	 * @public static
2302
-	 */
2303
-	public static function getCSSdataArray($dom, $key, $css) {
2304
-		$cssarray = array(); // style to be returned
2305
-		// get parent CSS selectors
2306
-		$selectors = array();
2307
-		if (isset($dom[($dom[$key]['parent'])]['csssel'])) {
2308
-			$selectors = $dom[($dom[$key]['parent'])]['csssel'];
2309
-		}
2310
-		// get all styles that apply
2311
-		foreach($css as $selector => $style) {
2312
-			$pos = strpos($selector, ' ');
2313
-			// get specificity
2314
-			$specificity = substr($selector, 0, $pos);
2315
-			// remove specificity
2316
-			$selector = substr($selector, $pos);
2317
-			// check if this selector apply to current tag
2318
-			if (self::isValidCSSSelectorForTag($dom, $key, $selector)) {
2319
-				if (!in_array($selector, $selectors)) {
2320
-					// add style if not already added on parent selector
2321
-					$cssarray[] = array('k' => $selector, 's' => $specificity, 'c' => $style);
2322
-					$selectors[] = $selector;
2323
-				}
2324
-			}
2325
-		}
2326
-		if (isset($dom[$key]['attribute']['style'])) {
2327
-			// attach inline style (latest properties have high priority)
2328
-			$cssarray[] = array('k' => '', 's' => '1000', 'c' => $dom[$key]['attribute']['style']);
2329
-		}
2330
-		// order the css array to account for specificity
2331
-		$cssordered = array();
2332
-		foreach ($cssarray as $key => $val) {
2333
-			$skey = sprintf('%04d', $key);
2334
-			$cssordered[$val['s'].'_'.$skey] = $val;
2335
-		}
2336
-		// sort selectors alphabetically to account for specificity
2337
-		ksort($cssordered, SORT_STRING);
2338
-		return array($selectors, $cssordered);
2339
-	}
2340
-
2341
-	/**
2342
-	 * Compact CSS data array into single string.
2343
-	 * @param $css (array) array of CSS properties
2344
-	 * @return string containing merged CSS properties
2345
-	 * @since 5.9.070 (2011-04-19)
2346
-	 * @public static
2347
-	 */
2348
-	public static function getTagStyleFromCSSarray($css) {
2349
-		$tagstyle = ''; // value to be returned
2350
-		foreach ($css as $style) {
2351
-			// split single css commands
2352
-			$csscmds = explode(';', $style['c']);
2353
-			foreach ($csscmds as $cmd) {
2354
-				if (!empty($cmd)) {
2355
-					$pos = strpos($cmd, ':');
2356
-					if ($pos !== false) {
2357
-						$cmd = substr($cmd, 0, ($pos + 1));
2358
-						if (strpos($tagstyle, $cmd) !== false) {
2359
-							// remove duplicate commands (last commands have high priority)
2360
-							$tagstyle = preg_replace('/'.$cmd.'[^;]+/i', '', $tagstyle);
2361
-						}
2362
-					}
2363
-				}
2364
-			}
2365
-			$tagstyle .= ';'.$style['c'];
2366
-		}
2367
-		// remove multiple semicolons
2368
-		$tagstyle = preg_replace('/[;]+/', ';', $tagstyle);
2369
-		return $tagstyle;
2370
-	}
2371
-
2372
-	/**
2373
-	 * Returns the Roman representation of an integer number
2374
-	 * @param $number (int) number to convert
2375
-	 * @return string roman representation of the specified number
2376
-	 * @since 4.4.004 (2008-12-10)
2377
-	 * @public static
2378
-	 */
2379
-	public static function intToRoman($number) {
2380
-		$roman = '';
2381
-		while ($number >= 1000) {
2382
-			$roman .= 'M';
2383
-			$number -= 1000;
2384
-		}
2385
-		while ($number >= 900) {
2386
-			$roman .= 'CM';
2387
-			$number -= 900;
2388
-		}
2389
-		while ($number >= 500) {
2390
-			$roman .= 'D';
2391
-			$number -= 500;
2392
-		}
2393
-		while ($number >= 400) {
2394
-			$roman .= 'CD';
2395
-			$number -= 400;
2396
-		}
2397
-		while ($number >= 100) {
2398
-			$roman .= 'C';
2399
-			$number -= 100;
2400
-		}
2401
-		while ($number >= 90) {
2402
-			$roman .= 'XC';
2403
-			$number -= 90;
2404
-		}
2405
-		while ($number >= 50) {
2406
-			$roman .= 'L';
2407
-			$number -= 50;
2408
-		}
2409
-		while ($number >= 40) {
2410
-			$roman .= 'XL';
2411
-			$number -= 40;
2412
-		}
2413
-		while ($number >= 10) {
2414
-			$roman .= 'X';
2415
-			$number -= 10;
2416
-		}
2417
-		while ($number >= 9) {
2418
-			$roman .= 'IX';
2419
-			$number -= 9;
2420
-		}
2421
-		while ($number >= 5) {
2422
-			$roman .= 'V';
2423
-			$number -= 5;
2424
-		}
2425
-		while ($number >= 4) {
2426
-			$roman .= 'IV';
2427
-			$number -= 4;
2428
-		}
2429
-		while ($number >= 1) {
2430
-			$roman .= 'I';
2431
-			--$number;
2432
-		}
2433
-		return $roman;
2434
-	}
2435
-
2436
-	/**
2437
-	 * Find position of last occurrence of a substring in a string
2438
-	 * @param $haystack (string) The string to search in.
2439
-	 * @param $needle (string) substring to search.
2440
-	 * @param $offset (int) May be specified to begin searching an arbitrary number of characters into the string.
2441
-	 * @return Returns the position where the needle exists. Returns FALSE if the needle was not found.
2442
-	 * @since 4.8.038 (2010-03-13)
2443
-	 * @public static
2444
-	 */
2445
-	public static function revstrpos($haystack, $needle, $offset = 0) {
2446
-		$length = strlen($haystack);
2447
-		$offset = ($offset > 0)?($length - $offset):abs($offset);
2448
-		$pos = strpos(strrev($haystack), strrev($needle), $offset);
2449
-		return ($pos === false)?false:($length - $pos - strlen($needle));
2450
-	}
2451
-
2452
-	/**
2453
-	 * Serialize an array of parameters to be used with TCPDF tag in HTML code.
2454
-	 * @param $pararray (array) parameters array
2455
-	 * @return sting containing serialized data
2456
-	 * @since 4.9.006 (2010-04-02)
2457
-	 * @public static
2458
-	 */
2459
-	public static function serializeTCPDFtagParameters($pararray) {
2460
-		return urlencode(serialize($pararray));
2461
-	}
2462
-
2463
-	/**
2464
-	 * Returns an array of hyphenation patterns.
2465
-	 * @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/
2466
-	 * @return array of hyphenation patterns
2467
-	 * @author Nicola Asuni
2468
-	 * @since 4.9.012 (2010-04-12)
2469
-	 * @public static
2470
-	 */
2471
-	public static function getHyphenPatternsFromTEX($file) {
2472
-		// TEX patterns are available at:
2473
-		// http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
2474
-		$data = file_get_contents($file);
2475
-		$patterns = array();
2476
-		// remove comments
2477
-		$data = preg_replace('/\%[^\n]*/', '', $data);
2478
-		// extract the patterns part
2479
-		preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches);
2480
-		$data = trim(substr($matches[0], 10, -1));
2481
-		// extract each pattern
2482
-		$patterns_array = preg_split('/[\s]+/', $data);
2483
-		// create new language array of patterns
2484
-		$patterns = array();
2485
-		foreach($patterns_array as $val) {
2486
-			if (!TCPDF_STATIC::empty_string($val)) {
2487
-				$val = trim($val);
2488
-				$val = str_replace('\'', '\\\'', $val);
2489
-				$key = preg_replace('/[0-9]+/', '', $val);
2490
-				$patterns[$key] = $val;
2491
-			}
2492
-		}
2493
-		return $patterns;
2494
-	}
2495
-
2496
-	/**
2497
-	 * Get the Path-Painting Operators.
2498
-	 * @param $style (string) Style of rendering. Possible values are:
2499
-	 * <ul>
2500
-	 *   <li>S or D: Stroke the path.</li>
2501
-	 *   <li>s or d: Close and stroke the path.</li>
2502
-	 *   <li>f or F: Fill the path, using the nonzero winding number rule to determine the region to fill.</li>
2503
-	 *   <li>f* or F*: Fill the path, using the even-odd rule to determine the region to fill.</li>
2504
-	 *   <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>
2505
-	 *   <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>
2506
-	 *   <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>
2507
-	 *   <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>
2508
-	 *   <li>CNZ: Clipping mode using the even-odd rule to determine which regions lie inside the clipping path.</li>
2509
-	 *   <li>CEO: Clipping mode using the nonzero winding number rule to determine which regions lie inside the clipping path</li>
2510
-	 *   <li>n: End the path object without filling or stroking it.</li>
2511
-	 * </ul>
2512
-	 * @param $default (string) default style
2513
-	 * @author Nicola Asuni
2514
-	 * @since 5.0.000 (2010-04-30)
2515
-	 * @public static
2516
-	 */
2517
-	public static function getPathPaintOperator($style, $default='S') {
2518
-		$op = '';
2519
-		switch($style) {
2520
-			case 'S':
2521
-			case 'D': {
2522
-				$op = 'S';
2523
-				break;
2524
-			}
2525
-			case 's':
2526
-			case 'd': {
2527
-				$op = 's';
2528
-				break;
2529
-			}
2530
-			case 'f':
2531
-			case 'F': {
2532
-				$op = 'f';
2533
-				break;
2534
-			}
2535
-			case 'f*':
2536
-			case 'F*': {
2537
-				$op = 'f*';
2538
-				break;
2539
-			}
2540
-			case 'B':
2541
-			case 'FD':
2542
-			case 'DF': {
2543
-				$op = 'B';
2544
-				break;
2545
-			}
2546
-			case 'B*':
2547
-			case 'F*D':
2548
-			case 'DF*': {
2549
-				$op = 'B*';
2550
-				break;
2551
-			}
2552
-			case 'b':
2553
-			case 'fd':
2554
-			case 'df': {
2555
-				$op = 'b';
2556
-				break;
2557
-			}
2558
-			case 'b*':
2559
-			case 'f*d':
2560
-			case 'df*': {
2561
-				$op = 'b*';
2562
-				break;
2563
-			}
2564
-			case 'CNZ': {
2565
-				$op = 'W n';
2566
-				break;
2567
-			}
2568
-			case 'CEO': {
2569
-				$op = 'W* n';
2570
-				break;
2571
-			}
2572
-			case 'n': {
2573
-				$op = 'n';
2574
-				break;
2575
-			}
2576
-			default: {
2577
-				if (!empty($default)) {
2578
-					$op = self::getPathPaintOperator($default, '');
2579
-				} else {
2580
-					$op = '';
2581
-				}
2582
-			}
2583
-		}
2584
-		return $op;
2585
-	}
2586
-
2587
-	/**
2588
-	 * Get the product of two SVG tranformation matrices
2589
-	 * @param $ta (array) first SVG tranformation matrix
2590
-	 * @param $tb (array) second SVG tranformation matrix
2591
-	 * @return transformation array
2592
-	 * @author Nicola Asuni
2593
-	 * @since 5.0.000 (2010-05-02)
2594
-	 * @public static
2595
-	 */
2596
-	public static function getTransformationMatrixProduct($ta, $tb) {
2597
-		$tm = array();
2598
-		$tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]);
2599
-		$tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]);
2600
-		$tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]);
2601
-		$tm[3] = ($ta[1] * $tb[2]) + ($ta[3] * $tb[3]);
2602
-		$tm[4] = ($ta[0] * $tb[4]) + ($ta[2] * $tb[5]) + $ta[4];
2603
-		$tm[5] = ($ta[1] * $tb[4]) + ($ta[3] * $tb[5]) + $ta[5];
2604
-		return $tm;
2605
-	}
2606
-
2607
-	/**
2608
-	 * Get the tranformation matrix from SVG transform attribute
2609
-	 * @param $attribute (string) transformation
2610
-	 * @return array of transformations
2611
-	 * @author Nicola Asuni
2612
-	 * @since 5.0.000 (2010-05-02)
2613
-	 * @public static
2614
-	 */
2615
-	public static function getSVGTransformMatrix($attribute) {
2616
-		// identity matrix
2617
-		$tm = array(1, 0, 0, 1, 0, 0);
2618
-		$transform = array();
2619
-		if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0) {
2620
-			foreach ($transform as $key => $data) {
2621
-				if (!empty($data[2])) {
2622
-					$a = 1;
2623
-					$b = 0;
2624
-					$c = 0;
2625
-					$d = 1;
2626
-					$e = 0;
2627
-					$f = 0;
2628
-					$regs = array();
2629
-					switch ($data[1]) {
2630
-						case 'matrix': {
2631
-							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)) {
2632
-								$a = $regs[1];
2633
-								$b = $regs[2];
2634
-								$c = $regs[3];
2635
-								$d = $regs[4];
2636
-								$e = $regs[5];
2637
-								$f = $regs[6];
2638
-							}
2639
-							break;
2640
-						}
2641
-						case 'translate': {
2642
-							if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2643
-								$e = $regs[1];
2644
-								$f = $regs[2];
2645
-							} elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2646
-								$e = $regs[1];
2647
-							}
2648
-							break;
2649
-						}
2650
-						case 'scale': {
2651
-							if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2652
-								$a = $regs[1];
2653
-								$d = $regs[2];
2654
-							} elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2655
-								$a = $regs[1];
2656
-								$d = $a;
2657
-							}
2658
-							break;
2659
-						}
2660
-						case 'rotate': {
2661
-							if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2662
-								$ang = deg2rad($regs[1]);
2663
-								$x = $regs[2];
2664
-								$y = $regs[3];
2665
-								$a = cos($ang);
2666
-								$b = sin($ang);
2667
-								$c = -$b;
2668
-								$d = $a;
2669
-								$e = ($x * (1 - $a)) - ($y * $c);
2670
-								$f = ($y * (1 - $d)) - ($x * $b);
2671
-							} elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
2672
-								$ang = deg2rad($regs[1]);
2673
-								$a = cos($ang);
2674
-								$b = sin($ang);
2675
-								$c = -$b;
2676
-								$d = $a;
2677
-								$e = 0;
2678
-								$f = 0;
2679
-							}
2680
-							break;
2681
-						}
2682
-						case 'skewX': {
2683
-							if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
2684
-								$c = tan(deg2rad($regs[1]));
2685
-							}
2686
-							break;
2687
-						}
2688
-						case 'skewY': {
2689
-							if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
2690
-								$b = tan(deg2rad($regs[1]));
2691
-							}
2692
-							break;
2693
-						}
2694
-					}
2695
-					$tm = self::getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f));
2696
-				}
2697
-			}
2698
-		}
2699
-		return $tm;
2700
-	}
2701
-
2702
-	/**
2703
-	 * Returns the angle in radiants between two vectors
2704
-	 * @param $x1 (int) X coordinate of first vector point
2705
-	 * @param $y1 (int) Y coordinate of first vector point
2706
-	 * @param $x2 (int) X coordinate of second vector point
2707
-	 * @param $y2 (int) Y coordinate of second vector point
2708
-	 * @author Nicola Asuni
2709
-	 * @since 5.0.000 (2010-05-04)
2710
-	 * @public static
2711
-	 */
2712
-	public static function getVectorsAngle($x1, $y1, $x2, $y2) {
2713
-		$dprod = ($x1 * $x2) + ($y1 * $y2);
2714
-		$dist1 = sqrt(($x1 * $x1) + ($y1 * $y1));
2715
-		$dist2 = sqrt(($x2 * $x2) + ($y2 * $y2));
2716
-		$angle = acos($dprod / ($dist1 * $dist2));
2717
-		if (is_nan($angle)) {
2718
-			$angle = M_PI;
2719
-		}
2720
-		if ((($x1 * $y2) - ($x2 * $y1)) < 0) {
2721
-			$angle *= -1;
2722
-		}
2723
-		return $angle;
2724
-	}
2725
-
2726
-	/**
2727
-	 * Split string by a regular expression.
2728
-	 * This is a wrapper for the preg_split function to avoid the bug: https://bugs.php.net/bug.php?id=45850
2729
-	 * @param $pattern (string) The regular expression pattern to search for without the modifiers, as a string.
2730
-	 * @param $modifiers (string) The modifiers part of the pattern,
2731
-	 * @param $subject (string) The input string.
2732
-	 * @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.
2733
-	 * @param $flags (int) The flags as specified on the preg_split PHP function.
2734
-	 * @return Returns an array containing substrings of subject split along boundaries matched by pattern.modifier
2735
-	 * @author Nicola Asuni
2736
-	 * @since 6.0.023
2737
-	 * @public static
2738
-	 */
2739
-	public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $flags=NULL) {
2740
-		// the bug only happens on PHP 5.2 when using the u modifier
2741
-		if ((strpos($modifiers, 'u') === FALSE) OR (count(preg_split('//u', "\n\t", -1, PREG_SPLIT_NO_EMPTY)) == 2)) {
2742
-			return preg_split($pattern.$modifiers, $subject, $limit, $flags);
2743
-		}
2744
-		// preg_split is bugged - try alternative solution
2745
-		$ret = array();
2746
-		while (($nl = strpos($subject, "\n")) !== FALSE) {
2747
-			$ret = array_merge($ret, preg_split($pattern.$modifiers, substr($subject, 0, $nl), $limit, $flags));
2748
-			$ret[] = "\n";
2749
-			$subject = substr($subject, ($nl + 1));
2750
-		}
2751
-		if (strlen($subject) > 0) {
2752
-			$ret = array_merge($ret, preg_split($pattern.$modifiers, $subject, $limit, $flags));
2753
-		}
2754
-		return $ret;
2755
-	}
2756
-
2757
-	/**
2758
-	 * Reads entire file into a string.
2759
-	 * The file can be also an URL.
2760
-	 * @param $file (string) Name of the file or URL to read.
2761
-	 * @return The function returns the read data or FALSE on failure. 
2762
-	 * @author Nicola Asuni
2763
-	 * @since 6.0.025
2764
-	 * @public static
2765
-	 */
2766
-	public static function fileGetContents($file) {
2767
-		//$file = html_entity_decode($file);
2768
-		// array of possible alternative paths/URLs
2769
-		$alt = array($file);
2770
-		// replace URL relative path with full real server path
2771
-		if ((strlen($file) > 1)
2772
-			AND ($file[0] == '/')
2773
-			AND ($file[1] != '/')
2774
-			AND !empty($_SERVER['DOCUMENT_ROOT'])
2775
-			AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
2776
-			$findroot = strpos($file, $_SERVER['DOCUMENT_ROOT']);
2777
-			if (($findroot === false) OR ($findroot > 1)) {
2778
-				if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
2779
-					$tmp = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$file;
2780
-				} else {
2781
-					$tmp = $_SERVER['DOCUMENT_ROOT'].$file;
2782
-				}
2783
-				$alt[] = htmlspecialchars_decode(urldecode($tmp));
2784
-			}
2785
-		}
2786
-		// URL mode
2787
-		$url = $file;
2788
-		// check for missing protocol
2789
-		if (preg_match('%^/{2}%', $url)) {
2790
-			if (preg_match('%^([^:]+:)//%i', K_PATH_URL, $match)) {
2791
-				$url = $match[1].str_replace(' ', '%20', $url);
2792
-				$alt[] = $url;
2793
-			}
2794
-		}
2795
-		$urldata = @parse_url($url);
2796
-		if (!isset($urldata['query']) OR (strlen($urldata['query']) <= 0)) {
2797
-			if (strpos($url, K_PATH_URL) === 0) {
2798
-				// convert URL to full server path
2799
-				$tmp = str_replace(K_PATH_URL, K_PATH_MAIN, $url);
2800
-				$tmp = htmlspecialchars_decode(urldecode($tmp));
2801
-				$alt[] = $tmp;
2802
-			}
2803
-		}
2804
-		if (isset($_SERVER['SCRIPT_URI'])) {
2805
-			$urldata = @parse_url($_SERVER['SCRIPT_URI']);
2806
-			$alt[] = $urldata['scheme'].'://'.$urldata['host'].(($file[0] == '/') ? '' : '/').$file;
2807
-		}
2808
-		foreach ($alt as $f) {
2809
-			$ret = @file_get_contents($f);
2810
-			if (($ret === FALSE)
2811
-				AND !ini_get('allow_url_fopen')
2812
-				AND function_exists('curl_init')
2813
-				AND preg_match('%^(https?|ftp)://%', $f)) {
2814
-				// try to get remote file data using cURL
2815
-				$cs = curl_init(); // curl session
2816
-				curl_setopt($cs, CURLOPT_URL, $f);
2817
-				curl_setopt($cs, CURLOPT_BINARYTRANSFER, true);
2818
-				curl_setopt($cs, CURLOPT_FAILONERROR, true);
2819
-				curl_setopt($cs, CURLOPT_RETURNTRANSFER, true);
2820
-				if ((ini_get('open_basedir') == '') AND (!ini_get('safe_mode'))) {
2821
-					curl_setopt($cs, CURLOPT_FOLLOWLOCATION, true);
2822
-				}
2823
-				curl_setopt($cs, CURLOPT_CONNECTTIMEOUT, 5);
2824
-				curl_setopt($cs, CURLOPT_TIMEOUT, 30);
2825
-				curl_setopt($cs, CURLOPT_SSL_VERIFYPEER, false);
2826
-				curl_setopt($cs, CURLOPT_SSL_VERIFYHOST, false);
2827
-				curl_setopt($cs, CURLOPT_USERAGENT, 'TCPDF');
2828
-				$ret = curl_exec($cs);
2829
-				curl_close($cs);
2830
-			}
2831
-			if ($ret !== FALSE) {
2832
-				break;
2833
-			}
2834
-		}
2835
-		return $ret;
2836
-	}
54
+    /**
55
+     * Current TCPDF version.
56
+     * @private static
57
+     */
58
+    private static $tcpdf_version = '6.0.078';
59
+
60
+    /**
61
+     * String alias for total number of pages.
62
+     * @public static
63
+     */
64
+    public static $alias_tot_pages = '{:ptp:}';
65
+
66
+    /**
67
+     * String alias for page number.
68
+     * @public static
69
+     */
70
+    public static $alias_num_page = '{:pnp:}';
71
+
72
+    /**
73
+     * String alias for total number of pages in a single group.
74
+     * @public static
75
+     */
76
+    public static $alias_group_tot_pages = '{:ptg:}';
77
+
78
+    /**
79
+     * String alias for group page number.
80
+     * @public static
81
+     */
82
+    public static $alias_group_num_page = '{:png:}';
83
+
84
+    /**
85
+     * String alias for right shift compensation used to correctly align page numbers on the right.
86
+     * @public static
87
+     */
88
+    public static $alias_right_shift = '{rsc:';
89
+
90
+    /**
91
+     * Encryption padding string.
92
+     * @public static
93
+     */
94
+    public static $enc_padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
95
+
96
+    /**
97
+     * ByteRange placemark used during digital signature process.
98
+     * @since 4.6.028 (2009-08-25)
99
+     * @public static
100
+     */
101
+    public static $byterange_string = '/ByteRange[0 ********** ********** **********]';
102
+
103
+    /**
104
+     * Array page boxes names
105
+     * @public static
106
+     */
107
+    public static $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
108
+
109
+    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
110
+
111
+    /**
112
+     * Return the current TCPDF version.
113
+     * @return TCPDF version string
114
+     * @since 5.9.012 (2010-11-10)
115
+     * @public static
116
+     */
117
+    public static function getTCPDFVersion() {
118
+        return self::$tcpdf_version;
119
+    }
120
+
121
+    /**
122
+     * Return the current TCPDF producer.
123
+     * @return TCPDF producer string
124
+     * @since 6.0.000 (2013-03-16)
125
+     * @public static
126
+     */
127
+    public static function getTCPDFProducer() {
128
+        return "\x54\x43\x50\x44\x46\x20".self::getTCPDFVersion()."\x20\x28\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
129
+    }
130
+
131
+    /**
132
+     * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
133
+     * @param $mqr (boolean) FALSE for off, TRUE for on.
134
+     * @since 4.6.025 (2009-08-17)
135
+     * @public static
136
+     */
137
+    public static function set_mqr($mqr) {
138
+        if (!defined('PHP_VERSION_ID')) {
139
+            $version = PHP_VERSION;
140
+            define('PHP_VERSION_ID', (($version[0] * 10000) + ($version[2] * 100) + $version[4]));
141
+        }
142
+        if (PHP_VERSION_ID < 50300) {
143
+            @set_magic_quotes_runtime($mqr);
144
+        }
145
+    }
146
+
147
+    /**
148
+     * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
149
+     * @return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
150
+     * @since 4.6.025 (2009-08-17)
151
+     * @public static
152
+     */
153
+    public static function get_mqr() {
154
+        if (!defined('PHP_VERSION_ID')) {
155
+            $version = PHP_VERSION;
156
+            define('PHP_VERSION_ID', (($version[0] * 10000) + ($version[2] * 100) + $version[4]));
157
+        }
158
+        if (PHP_VERSION_ID < 50300) {
159
+            return @get_magic_quotes_runtime();
160
+        }
161
+        return 0;
162
+    }
163
+
164
+    /**
165
+     * Get page dimensions from format name.
166
+     * @param $format (mixed) The format name. It can be: <ul>
167
+     * <li><b>ISO 216 A Series + 2 SIS 014711 extensions</b></li>
168
+     * <li>A0 (841x1189 mm ; 33.11x46.81 in)</li>
169
+     * <li>A1 (594x841 mm ; 23.39x33.11 in)</li>
170
+     * <li>A2 (420x594 mm ; 16.54x23.39 in)</li>
171
+     * <li>A3 (297x420 mm ; 11.69x16.54 in)</li>
172
+     * <li>A4 (210x297 mm ; 8.27x11.69 in)</li>
173
+     * <li>A5 (148x210 mm ; 5.83x8.27 in)</li>
174
+     * <li>A6 (105x148 mm ; 4.13x5.83 in)</li>
175
+     * <li>A7 (74x105 mm ; 2.91x4.13 in)</li>
176
+     * <li>A8 (52x74 mm ; 2.05x2.91 in)</li>
177
+     * <li>A9 (37x52 mm ; 1.46x2.05 in)</li>
178
+     * <li>A10 (26x37 mm ; 1.02x1.46 in)</li>
179
+     * <li>A11 (18x26 mm ; 0.71x1.02 in)</li>
180
+     * <li>A12 (13x18 mm ; 0.51x0.71 in)</li>
181
+     * <li><b>ISO 216 B Series + 2 SIS 014711 extensions</b></li>
182
+     * <li>B0 (1000x1414 mm ; 39.37x55.67 in)</li>
183
+     * <li>B1 (707x1000 mm ; 27.83x39.37 in)</li>
184
+     * <li>B2 (500x707 mm ; 19.69x27.83 in)</li>
185
+     * <li>B3 (353x500 mm ; 13.90x19.69 in)</li>
186
+     * <li>B4 (250x353 mm ; 9.84x13.90 in)</li>
187
+     * <li>B5 (176x250 mm ; 6.93x9.84 in)</li>
188
+     * <li>B6 (125x176 mm ; 4.92x6.93 in)</li>
189
+     * <li>B7 (88x125 mm ; 3.46x4.92 in)</li>
190
+     * <li>B8 (62x88 mm ; 2.44x3.46 in)</li>
191
+     * <li>B9 (44x62 mm ; 1.73x2.44 in)</li>
192
+     * <li>B10 (31x44 mm ; 1.22x1.73 in)</li>
193
+     * <li>B11 (22x31 mm ; 0.87x1.22 in)</li>
194
+     * <li>B12 (15x22 mm ; 0.59x0.87 in)</li>
195
+     * <li><b>ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION</b></li>
196
+     * <li>C0 (917x1297 mm ; 36.10x51.06 in)</li>
197
+     * <li>C1 (648x917 mm ; 25.51x36.10 in)</li>
198
+     * <li>C2 (458x648 mm ; 18.03x25.51 in)</li>
199
+     * <li>C3 (324x458 mm ; 12.76x18.03 in)</li>
200
+     * <li>C4 (229x324 mm ; 9.02x12.76 in)</li>
201
+     * <li>C5 (162x229 mm ; 6.38x9.02 in)</li>
202
+     * <li>C6 (114x162 mm ; 4.49x6.38 in)</li>
203
+     * <li>C7 (81x114 mm ; 3.19x4.49 in)</li>
204
+     * <li>C8 (57x81 mm ; 2.24x3.19 in)</li>
205
+     * <li>C9 (40x57 mm ; 1.57x2.24 in)</li>
206
+     * <li>C10 (28x40 mm ; 1.10x1.57 in)</li>
207
+     * <li>C11 (20x28 mm ; 0.79x1.10 in)</li>
208
+     * <li>C12 (14x20 mm ; 0.55x0.79 in)</li>
209
+     * <li>C76 (81x162 mm ; 3.19x6.38 in)</li>
210
+     * <li>DL (110x220 mm ; 4.33x8.66 in)</li>
211
+     * <li><b>SIS 014711 E Series</b></li>
212
+     * <li>E0 (879x1241 mm ; 34.61x48.86 in)</li>
213
+     * <li>E1 (620x879 mm ; 24.41x34.61 in)</li>
214
+     * <li>E2 (440x620 mm ; 17.32x24.41 in)</li>
215
+     * <li>E3 (310x440 mm ; 12.20x17.32 in)</li>
216
+     * <li>E4 (220x310 mm ; 8.66x12.20 in)</li>
217
+     * <li>E5 (155x220 mm ; 6.10x8.66 in)</li>
218
+     * <li>E6 (110x155 mm ; 4.33x6.10 in)</li>
219
+     * <li>E7 (78x110 mm ; 3.07x4.33 in)</li>
220
+     * <li>E8 (55x78 mm ; 2.17x3.07 in)</li>
221
+     * <li>E9 (39x55 mm ; 1.54x2.17 in)</li>
222
+     * <li>E10 (27x39 mm ; 1.06x1.54 in)</li>
223
+     * <li>E11 (19x27 mm ; 0.75x1.06 in)</li>
224
+     * <li>E12 (13x19 mm ; 0.51x0.75 in)</li>
225
+     * <li><b>SIS 014711 G Series</b></li>
226
+     * <li>G0 (958x1354 mm ; 37.72x53.31 in)</li>
227
+     * <li>G1 (677x958 mm ; 26.65x37.72 in)</li>
228
+     * <li>G2 (479x677 mm ; 18.86x26.65 in)</li>
229
+     * <li>G3 (338x479 mm ; 13.31x18.86 in)</li>
230
+     * <li>G4 (239x338 mm ; 9.41x13.31 in)</li>
231
+     * <li>G5 (169x239 mm ; 6.65x9.41 in)</li>
232
+     * <li>G6 (119x169 mm ; 4.69x6.65 in)</li>
233
+     * <li>G7 (84x119 mm ; 3.31x4.69 in)</li>
234
+     * <li>G8 (59x84 mm ; 2.32x3.31 in)</li>
235
+     * <li>G9 (42x59 mm ; 1.65x2.32 in)</li>
236
+     * <li>G10 (29x42 mm ; 1.14x1.65 in)</li>
237
+     * <li>G11 (21x29 mm ; 0.83x1.14 in)</li>
238
+     * <li>G12 (14x21 mm ; 0.55x0.83 in)</li>
239
+     * <li><b>ISO Press</b></li>
240
+     * <li>RA0 (860x1220 mm ; 33.86x48.03 in)</li>
241
+     * <li>RA1 (610x860 mm ; 24.02x33.86 in)</li>
242
+     * <li>RA2 (430x610 mm ; 16.93x24.02 in)</li>
243
+     * <li>RA3 (305x430 mm ; 12.01x16.93 in)</li>
244
+     * <li>RA4 (215x305 mm ; 8.46x12.01 in)</li>
245
+     * <li>SRA0 (900x1280 mm ; 35.43x50.39 in)</li>
246
+     * <li>SRA1 (640x900 mm ; 25.20x35.43 in)</li>
247
+     * <li>SRA2 (450x640 mm ; 17.72x25.20 in)</li>
248
+     * <li>SRA3 (320x450 mm ; 12.60x17.72 in)</li>
249
+     * <li>SRA4 (225x320 mm ; 8.86x12.60 in)</li>
250
+     * <li><b>German DIN 476</b></li>
251
+     * <li>4A0 (1682x2378 mm ; 66.22x93.62 in)</li>
252
+     * <li>2A0 (1189x1682 mm ; 46.81x66.22 in)</li>
253
+     * <li><b>Variations on the ISO Standard</b></li>
254
+     * <li>A2_EXTRA (445x619 mm ; 17.52x24.37 in)</li>
255
+     * <li>A3+ (329x483 mm ; 12.95x19.02 in)</li>
256
+     * <li>A3_EXTRA (322x445 mm ; 12.68x17.52 in)</li>
257
+     * <li>A3_SUPER (305x508 mm ; 12.01x20.00 in)</li>
258
+     * <li>SUPER_A3 (305x487 mm ; 12.01x19.17 in)</li>
259
+     * <li>A4_EXTRA (235x322 mm ; 9.25x12.68 in)</li>
260
+     * <li>A4_SUPER (229x322 mm ; 9.02x12.68 in)</li>
261
+     * <li>SUPER_A4 (227x356 mm ; 8.94x14.02 in)</li>
262
+     * <li>A4_LONG (210x348 mm ; 8.27x13.70 in)</li>
263
+     * <li>F4 (210x330 mm ; 8.27x12.99 in)</li>
264
+     * <li>SO_B5_EXTRA (202x276 mm ; 7.95x10.87 in)</li>
265
+     * <li>A5_EXTRA (173x235 mm ; 6.81x9.25 in)</li>
266
+     * <li><b>ANSI Series</b></li>
267
+     * <li>ANSI_E (864x1118 mm ; 34.00x44.00 in)</li>
268
+     * <li>ANSI_D (559x864 mm ; 22.00x34.00 in)</li>
269
+     * <li>ANSI_C (432x559 mm ; 17.00x22.00 in)</li>
270
+     * <li>ANSI_B (279x432 mm ; 11.00x17.00 in)</li>
271
+     * <li>ANSI_A (216x279 mm ; 8.50x11.00 in)</li>
272
+     * <li><b>Traditional 'Loose' North American Paper Sizes</b></li>
273
+     * <li>LEDGER, USLEDGER (432x279 mm ; 17.00x11.00 in)</li>
274
+     * <li>TABLOID, USTABLOID, BIBLE, ORGANIZERK (279x432 mm ; 11.00x17.00 in)</li>
275
+     * <li>LETTER, USLETTER, ORGANIZERM (216x279 mm ; 8.50x11.00 in)</li>
276
+     * <li>LEGAL, USLEGAL (216x356 mm ; 8.50x14.00 in)</li>
277
+     * <li>GLETTER, GOVERNMENTLETTER (203x267 mm ; 8.00x10.50 in)</li>
278
+     * <li>JLEGAL, JUNIORLEGAL (203x127 mm ; 8.00x5.00 in)</li>
279
+     * <li><b>Other North American Paper Sizes</b></li>
280
+     * <li>QUADDEMY (889x1143 mm ; 35.00x45.00 in)</li>
281
+     * <li>SUPER_B (330x483 mm ; 13.00x19.00 in)</li>
282
+     * <li>QUARTO (229x279 mm ; 9.00x11.00 in)</li>
283
+     * <li>FOLIO, GOVERNMENTLEGAL (216x330 mm ; 8.50x13.00 in)</li>
284
+     * <li>EXECUTIVE, MONARCH (184x267 mm ; 7.25x10.50 in)</li>
285
+     * <li>MEMO, STATEMENT, ORGANIZERL (140x216 mm ; 5.50x8.50 in)</li>
286
+     * <li>FOOLSCAP (210x330 mm ; 8.27x13.00 in)</li>
287
+     * <li>COMPACT (108x171 mm ; 4.25x6.75 in)</li>
288
+     * <li>ORGANIZERJ (70x127 mm ; 2.75x5.00 in)</li>
289
+     * <li><b>Canadian standard CAN 2-9.60M</b></li>
290
+     * <li>P1 (560x860 mm ; 22.05x33.86 in)</li>
291
+     * <li>P2 (430x560 mm ; 16.93x22.05 in)</li>
292
+     * <li>P3 (280x430 mm ; 11.02x16.93 in)</li>
293
+     * <li>P4 (215x280 mm ; 8.46x11.02 in)</li>
294
+     * <li>P5 (140x215 mm ; 5.51x8.46 in)</li>
295
+     * <li>P6 (107x140 mm ; 4.21x5.51 in)</li>
296
+     * <li><b>North American Architectural Sizes</b></li>
297
+     * <li>ARCH_E (914x1219 mm ; 36.00x48.00 in)</li>
298
+     * <li>ARCH_E1 (762x1067 mm ; 30.00x42.00 in)</li>
299
+     * <li>ARCH_D (610x914 mm ; 24.00x36.00 in)</li>
300
+     * <li>ARCH_C, BROADSHEET (457x610 mm ; 18.00x24.00 in)</li>
301
+     * <li>ARCH_B (305x457 mm ; 12.00x18.00 in)</li>
302
+     * <li>ARCH_A (229x305 mm ; 9.00x12.00 in)</li>
303
+     * <li><b>Announcement Envelopes</b></li>
304
+     * <li>ANNENV_A2 (111x146 mm ; 4.37x5.75 in)</li>
305
+     * <li>ANNENV_A6 (121x165 mm ; 4.75x6.50 in)</li>
306
+     * <li>ANNENV_A7 (133x184 mm ; 5.25x7.25 in)</li>
307
+     * <li>ANNENV_A8 (140x206 mm ; 5.50x8.12 in)</li>
308
+     * <li>ANNENV_A10 (159x244 mm ; 6.25x9.62 in)</li>
309
+     * <li>ANNENV_SLIM (98x225 mm ; 3.87x8.87 in)</li>
310
+     * <li><b>Commercial Envelopes</b></li>
311
+     * <li>COMMENV_N6_1/4 (89x152 mm ; 3.50x6.00 in)</li>
312
+     * <li>COMMENV_N6_3/4 (92x165 mm ; 3.62x6.50 in)</li>
313
+     * <li>COMMENV_N8 (98x191 mm ; 3.87x7.50 in)</li>
314
+     * <li>COMMENV_N9 (98x225 mm ; 3.87x8.87 in)</li>
315
+     * <li>COMMENV_N10 (105x241 mm ; 4.12x9.50 in)</li>
316
+     * <li>COMMENV_N11 (114x263 mm ; 4.50x10.37 in)</li>
317
+     * <li>COMMENV_N12 (121x279 mm ; 4.75x11.00 in)</li>
318
+     * <li>COMMENV_N14 (127x292 mm ; 5.00x11.50 in)</li>
319
+     * <li><b>Catalogue Envelopes</b></li>
320
+     * <li>CATENV_N1 (152x229 mm ; 6.00x9.00 in)</li>
321
+     * <li>CATENV_N1_3/4 (165x241 mm ; 6.50x9.50 in)</li>
322
+     * <li>CATENV_N2 (165x254 mm ; 6.50x10.00 in)</li>
323
+     * <li>CATENV_N3 (178x254 mm ; 7.00x10.00 in)</li>
324
+     * <li>CATENV_N6 (191x267 mm ; 7.50x10.50 in)</li>
325
+     * <li>CATENV_N7 (203x279 mm ; 8.00x11.00 in)</li>
326
+     * <li>CATENV_N8 (210x286 mm ; 8.25x11.25 in)</li>
327
+     * <li>CATENV_N9_1/2 (216x267 mm ; 8.50x10.50 in)</li>
328
+     * <li>CATENV_N9_3/4 (222x286 mm ; 8.75x11.25 in)</li>
329
+     * <li>CATENV_N10_1/2 (229x305 mm ; 9.00x12.00 in)</li>
330
+     * <li>CATENV_N12_1/2 (241x318 mm ; 9.50x12.50 in)</li>
331
+     * <li>CATENV_N13_1/2 (254x330 mm ; 10.00x13.00 in)</li>
332
+     * <li>CATENV_N14_1/4 (286x311 mm ; 11.25x12.25 in)</li>
333
+     * <li>CATENV_N14_1/2 (292x368 mm ; 11.50x14.50 in)</li>
334
+     * <li><b>Japanese (JIS P 0138-61) Standard B-Series</b></li>
335
+     * <li>JIS_B0 (1030x1456 mm ; 40.55x57.32 in)</li>
336
+     * <li>JIS_B1 (728x1030 mm ; 28.66x40.55 in)</li>
337
+     * <li>JIS_B2 (515x728 mm ; 20.28x28.66 in)</li>
338
+     * <li>JIS_B3 (364x515 mm ; 14.33x20.28 in)</li>
339
+     * <li>JIS_B4 (257x364 mm ; 10.12x14.33 in)</li>
340
+     * <li>JIS_B5 (182x257 mm ; 7.17x10.12 in)</li>
341
+     * <li>JIS_B6 (128x182 mm ; 5.04x7.17 in)</li>
342
+     * <li>JIS_B7 (91x128 mm ; 3.58x5.04 in)</li>
343
+     * <li>JIS_B8 (64x91 mm ; 2.52x3.58 in)</li>
344
+     * <li>JIS_B9 (45x64 mm ; 1.77x2.52 in)</li>
345
+     * <li>JIS_B10 (32x45 mm ; 1.26x1.77 in)</li>
346
+     * <li>JIS_B11 (22x32 mm ; 0.87x1.26 in)</li>
347
+     * <li>JIS_B12 (16x22 mm ; 0.63x0.87 in)</li>
348
+     * <li><b>PA Series</b></li>
349
+     * <li>PA0 (840x1120 mm ; 33.07x44.09 in)</li>
350
+     * <li>PA1 (560x840 mm ; 22.05x33.07 in)</li>
351
+     * <li>PA2 (420x560 mm ; 16.54x22.05 in)</li>
352
+     * <li>PA3 (280x420 mm ; 11.02x16.54 in)</li>
353
+     * <li>PA4 (210x280 mm ; 8.27x11.02 in)</li>
354
+     * <li>PA5 (140x210 mm ; 5.51x8.27 in)</li>
355
+     * <li>PA6 (105x140 mm ; 4.13x5.51 in)</li>
356
+     * <li>PA7 (70x105 mm ; 2.76x4.13 in)</li>
357
+     * <li>PA8 (52x70 mm ; 2.05x2.76 in)</li>
358
+     * <li>PA9 (35x52 mm ; 1.38x2.05 in)</li>
359
+     * <li>PA10 (26x35 mm ; 1.02x1.38 in)</li>
360
+     * <li><b>Standard Photographic Print Sizes</b></li>
361
+     * <li>PASSPORT_PHOTO (35x45 mm ; 1.38x1.77 in)</li>
362
+     * <li>E (82x120 mm ; 3.25x4.72 in)</li>
363
+     * <li>3R, L (89x127 mm ; 3.50x5.00 in)</li>
364
+     * <li>4R, KG (102x152 mm ; 4.02x5.98 in)</li>
365
+     * <li>4D (120x152 mm ; 4.72x5.98 in)</li>
366
+     * <li>5R, 2L (127x178 mm ; 5.00x7.01 in)</li>
367
+     * <li>6R, 8P (152x203 mm ; 5.98x7.99 in)</li>
368
+     * <li>8R, 6P (203x254 mm ; 7.99x10.00 in)</li>
369
+     * <li>S8R, 6PW (203x305 mm ; 7.99x12.01 in)</li>
370
+     * <li>10R, 4P (254x305 mm ; 10.00x12.01 in)</li>
371
+     * <li>S10R, 4PW (254x381 mm ; 10.00x15.00 in)</li>
372
+     * <li>11R (279x356 mm ; 10.98x14.02 in)</li>
373
+     * <li>S11R (279x432 mm ; 10.98x17.01 in)</li>
374
+     * <li>12R (305x381 mm ; 12.01x15.00 in)</li>
375
+     * <li>S12R (305x456 mm ; 12.01x17.95 in)</li>
376
+     * <li><b>Common Newspaper Sizes</b></li>
377
+     * <li>NEWSPAPER_BROADSHEET (750x600 mm ; 29.53x23.62 in)</li>
378
+     * <li>NEWSPAPER_BERLINER (470x315 mm ; 18.50x12.40 in)</li>
379
+     * <li>NEWSPAPER_COMPACT, NEWSPAPER_TABLOID (430x280 mm ; 16.93x11.02 in)</li>
380
+     * <li><b>Business Cards</b></li>
381
+     * <li>CREDIT_CARD, BUSINESS_CARD, BUSINESS_CARD_ISO7810 (54x86 mm ; 2.13x3.37 in)</li>
382
+     * <li>BUSINESS_CARD_ISO216 (52x74 mm ; 2.05x2.91 in)</li>
383
+     * <li>BUSINESS_CARD_IT, BUSINESS_CARD_UK, BUSINESS_CARD_FR, BUSINESS_CARD_DE, BUSINESS_CARD_ES (55x85 mm ; 2.17x3.35 in)</li>
384
+     * <li>BUSINESS_CARD_US, BUSINESS_CARD_CA (51x89 mm ; 2.01x3.50 in)</li>
385
+     * <li>BUSINESS_CARD_JP (55x91 mm ; 2.17x3.58 in)</li>
386
+     * <li>BUSINESS_CARD_HK (54x90 mm ; 2.13x3.54 in)</li>
387
+     * <li>BUSINESS_CARD_AU, BUSINESS_CARD_DK, BUSINESS_CARD_SE (55x90 mm ; 2.17x3.54 in)</li>
388
+     * <li>BUSINESS_CARD_RU, BUSINESS_CARD_CZ, BUSINESS_CARD_FI, BUSINESS_CARD_HU, BUSINESS_CARD_IL (50x90 mm ; 1.97x3.54 in)</li>
389
+     * <li><b>Billboards</b></li>
390
+     * <li>4SHEET (1016x1524 mm ; 40.00x60.00 in)</li>
391
+     * <li>6SHEET (1200x1800 mm ; 47.24x70.87 in)</li>
392
+     * <li>12SHEET (3048x1524 mm ; 120.00x60.00 in)</li>
393
+     * <li>16SHEET (2032x3048 mm ; 80.00x120.00 in)</li>
394
+     * <li>32SHEET (4064x3048 mm ; 160.00x120.00 in)</li>
395
+     * <li>48SHEET (6096x3048 mm ; 240.00x120.00 in)</li>
396
+     * <li>64SHEET (8128x3048 mm ; 320.00x120.00 in)</li>
397
+     * <li>96SHEET (12192x3048 mm ; 480.00x120.00 in)</li>
398
+     * <li><b>Old Imperial English (some are still used in USA)</b></li>
399
+     * <li>EN_EMPEROR (1219x1829 mm ; 48.00x72.00 in)</li>
400
+     * <li>EN_ANTIQUARIAN (787x1346 mm ; 31.00x53.00 in)</li>
401
+     * <li>EN_GRAND_EAGLE (730x1067 mm ; 28.75x42.00 in)</li>
402
+     * <li>EN_DOUBLE_ELEPHANT (679x1016 mm ; 26.75x40.00 in)</li>
403
+     * <li>EN_ATLAS (660x864 mm ; 26.00x34.00 in)</li>
404
+     * <li>EN_COLOMBIER (597x876 mm ; 23.50x34.50 in)</li>
405
+     * <li>EN_ELEPHANT (584x711 mm ; 23.00x28.00 in)</li>
406
+     * <li>EN_DOUBLE_DEMY (572x902 mm ; 22.50x35.50 in)</li>
407
+     * <li>EN_IMPERIAL (559x762 mm ; 22.00x30.00 in)</li>
408
+     * <li>EN_PRINCESS (546x711 mm ; 21.50x28.00 in)</li>
409
+     * <li>EN_CARTRIDGE (533x660 mm ; 21.00x26.00 in)</li>
410
+     * <li>EN_DOUBLE_LARGE_POST (533x838 mm ; 21.00x33.00 in)</li>
411
+     * <li>EN_ROYAL (508x635 mm ; 20.00x25.00 in)</li>
412
+     * <li>EN_SHEET, EN_HALF_POST (495x597 mm ; 19.50x23.50 in)</li>
413
+     * <li>EN_SUPER_ROYAL (483x686 mm ; 19.00x27.00 in)</li>
414
+     * <li>EN_DOUBLE_POST (483x775 mm ; 19.00x30.50 in)</li>
415
+     * <li>EN_MEDIUM (445x584 mm ; 17.50x23.00 in)</li>
416
+     * <li>EN_DEMY (445x572 mm ; 17.50x22.50 in)</li>
417
+     * <li>EN_LARGE_POST (419x533 mm ; 16.50x21.00 in)</li>
418
+     * <li>EN_COPY_DRAUGHT (406x508 mm ; 16.00x20.00 in)</li>
419
+     * <li>EN_POST (394x489 mm ; 15.50x19.25 in)</li>
420
+     * <li>EN_CROWN (381x508 mm ; 15.00x20.00 in)</li>
421
+     * <li>EN_PINCHED_POST (375x470 mm ; 14.75x18.50 in)</li>
422
+     * <li>EN_BRIEF (343x406 mm ; 13.50x16.00 in)</li>
423
+     * <li>EN_FOOLSCAP (343x432 mm ; 13.50x17.00 in)</li>
424
+     * <li>EN_SMALL_FOOLSCAP (337x419 mm ; 13.25x16.50 in)</li>
425
+     * <li>EN_POTT (318x381 mm ; 12.50x15.00 in)</li>
426
+     * <li><b>Old Imperial Belgian</b></li>
427
+     * <li>BE_GRAND_AIGLE (700x1040 mm ; 27.56x40.94 in)</li>
428
+     * <li>BE_COLOMBIER (620x850 mm ; 24.41x33.46 in)</li>
429
+     * <li>BE_DOUBLE_CARRE (620x920 mm ; 24.41x36.22 in)</li>
430
+     * <li>BE_ELEPHANT (616x770 mm ; 24.25x30.31 in)</li>
431
+     * <li>BE_PETIT_AIGLE (600x840 mm ; 23.62x33.07 in)</li>
432
+     * <li>BE_GRAND_JESUS (550x730 mm ; 21.65x28.74 in)</li>
433
+     * <li>BE_JESUS (540x730 mm ; 21.26x28.74 in)</li>
434
+     * <li>BE_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
435
+     * <li>BE_GRAND_MEDIAN (460x605 mm ; 18.11x23.82 in)</li>
436
+     * <li>BE_DOUBLE_POSTE (435x565 mm ; 17.13x22.24 in)</li>
437
+     * <li>BE_COQUILLE (430x560 mm ; 16.93x22.05 in)</li>
438
+     * <li>BE_PETIT_MEDIAN (415x530 mm ; 16.34x20.87 in)</li>
439
+     * <li>BE_RUCHE (360x460 mm ; 14.17x18.11 in)</li>
440
+     * <li>BE_PROPATRIA (345x430 mm ; 13.58x16.93 in)</li>
441
+     * <li>BE_LYS (317x397 mm ; 12.48x15.63 in)</li>
442
+     * <li>BE_POT (307x384 mm ; 12.09x15.12 in)</li>
443
+     * <li>BE_ROSETTE (270x347 mm ; 10.63x13.66 in)</li>
444
+     * <li><b>Old Imperial French</b></li>
445
+     * <li>FR_UNIVERS (1000x1300 mm ; 39.37x51.18 in)</li>
446
+     * <li>FR_DOUBLE_COLOMBIER (900x1260 mm ; 35.43x49.61 in)</li>
447
+     * <li>FR_GRANDE_MONDE (900x1260 mm ; 35.43x49.61 in)</li>
448
+     * <li>FR_DOUBLE_SOLEIL (800x1200 mm ; 31.50x47.24 in)</li>
449
+     * <li>FR_DOUBLE_JESUS (760x1120 mm ; 29.92x44.09 in)</li>
450
+     * <li>FR_GRAND_AIGLE (750x1060 mm ; 29.53x41.73 in)</li>
451
+     * <li>FR_PETIT_AIGLE (700x940 mm ; 27.56x37.01 in)</li>
452
+     * <li>FR_DOUBLE_RAISIN (650x1000 mm ; 25.59x39.37 in)</li>
453
+     * <li>FR_JOURNAL (650x940 mm ; 25.59x37.01 in)</li>
454
+     * <li>FR_COLOMBIER_AFFICHE (630x900 mm ; 24.80x35.43 in)</li>
455
+     * <li>FR_DOUBLE_CAVALIER (620x920 mm ; 24.41x36.22 in)</li>
456
+     * <li>FR_CLOCHE (600x800 mm ; 23.62x31.50 in)</li>
457
+     * <li>FR_SOLEIL (600x800 mm ; 23.62x31.50 in)</li>
458
+     * <li>FR_DOUBLE_CARRE (560x900 mm ; 22.05x35.43 in)</li>
459
+     * <li>FR_DOUBLE_COQUILLE (560x880 mm ; 22.05x34.65 in)</li>
460
+     * <li>FR_JESUS (560x760 mm ; 22.05x29.92 in)</li>
461
+     * <li>FR_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
462
+     * <li>FR_CAVALIER (460x620 mm ; 18.11x24.41 in)</li>
463
+     * <li>FR_DOUBLE_COURONNE (460x720 mm ; 18.11x28.35 in)</li>
464
+     * <li>FR_CARRE (450x560 mm ; 17.72x22.05 in)</li>
465
+     * <li>FR_COQUILLE (440x560 mm ; 17.32x22.05 in)</li>
466
+     * <li>FR_DOUBLE_TELLIERE (440x680 mm ; 17.32x26.77 in)</li>
467
+     * <li>FR_DOUBLE_CLOCHE (400x600 mm ; 15.75x23.62 in)</li>
468
+     * <li>FR_DOUBLE_POT (400x620 mm ; 15.75x24.41 in)</li>
469
+     * <li>FR_ECU (400x520 mm ; 15.75x20.47 in)</li>
470
+     * <li>FR_COURONNE (360x460 mm ; 14.17x18.11 in)</li>
471
+     * <li>FR_TELLIERE (340x440 mm ; 13.39x17.32 in)</li>
472
+     * <li>FR_POT (310x400 mm ; 12.20x15.75 in)</li>
473
+     * </ul>
474
+     * @return array containing page width and height in points
475
+     * @since 5.0.010 (2010-05-17)
476
+     * @public static
477
+     */
478
+    public static function getPageSizeFromFormat($format) {
479
+        // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 25.4 mm)
480
+        switch (strtoupper($format)) {
481
+            // ISO 216 A Series + 2 SIS 014711 extensions
482
+            case 'A0' : {$pf = array( 2383.937, 3370.394); break;}
483
+            case 'A1' : {$pf = array( 1683.780, 2383.937); break;}
484
+            case 'A2' : {$pf = array( 1190.551, 1683.780); break;}
485
+            case 'A3' : {$pf = array(  841.890, 1190.551); break;}
486
+            case 'A4' : {$pf = array(  595.276,  841.890); break;}
487
+            case 'A5' : {$pf = array(  419.528,  595.276); break;}
488
+            case 'A6' : {$pf = array(  297.638,  419.528); break;}
489
+            case 'A7' : {$pf = array(  209.764,  297.638); break;}
490
+            case 'A8' : {$pf = array(  147.402,  209.764); break;}
491
+            case 'A9' : {$pf = array(  104.882,  147.402); break;}
492
+            case 'A10': {$pf = array(   73.701,  104.882); break;}
493
+            case 'A11': {$pf = array(   51.024,   73.701); break;}
494
+            case 'A12': {$pf = array(   36.850,   51.024); break;}
495
+            // ISO 216 B Series + 2 SIS 014711 extensions
496
+            case 'B0' : {$pf = array( 2834.646, 4008.189); break;}
497
+            case 'B1' : {$pf = array( 2004.094, 2834.646); break;}
498
+            case 'B2' : {$pf = array( 1417.323, 2004.094); break;}
499
+            case 'B3' : {$pf = array( 1000.630, 1417.323); break;}
500
+            case 'B4' : {$pf = array(  708.661, 1000.630); break;}
501
+            case 'B5' : {$pf = array(  498.898,  708.661); break;}
502
+            case 'B6' : {$pf = array(  354.331,  498.898); break;}
503
+            case 'B7' : {$pf = array(  249.449,  354.331); break;}
504
+            case 'B8' : {$pf = array(  175.748,  249.449); break;}
505
+            case 'B9' : {$pf = array(  124.724,  175.748); break;}
506
+            case 'B10': {$pf = array(   87.874,  124.724); break;}
507
+            case 'B11': {$pf = array(   62.362,   87.874); break;}
508
+            case 'B12': {$pf = array(   42.520,   62.362); break;}
509
+            // ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION
510
+            case 'C0' : {$pf = array( 2599.370, 3676.535); break;}
511
+            case 'C1' : {$pf = array( 1836.850, 2599.370); break;}
512
+            case 'C2' : {$pf = array( 1298.268, 1836.850); break;}
513
+            case 'C3' : {$pf = array(  918.425, 1298.268); break;}
514
+            case 'C4' : {$pf = array(  649.134,  918.425); break;}
515
+            case 'C5' : {$pf = array(  459.213,  649.134); break;}
516
+            case 'C6' : {$pf = array(  323.150,  459.213); break;}
517
+            case 'C7' : {$pf = array(  229.606,  323.150); break;}
518
+            case 'C8' : {$pf = array(  161.575,  229.606); break;}
519
+            case 'C9' : {$pf = array(  113.386,  161.575); break;}
520
+            case 'C10': {$pf = array(   79.370,  113.386); break;}
521
+            case 'C11': {$pf = array(   56.693,   79.370); break;}
522
+            case 'C12': {$pf = array(   39.685,   56.693); break;}
523
+            case 'C76': {$pf = array(  229.606,  459.213); break;}
524
+            case 'DL' : {$pf = array(  311.811,  623.622); break;}
525
+            // SIS 014711 E Series
526
+            case 'E0' : {$pf = array( 2491.654, 3517.795); break;}
527
+            case 'E1' : {$pf = array( 1757.480, 2491.654); break;}
528
+            case 'E2' : {$pf = array( 1247.244, 1757.480); break;}
529
+            case 'E3' : {$pf = array(  878.740, 1247.244); break;}
530
+            case 'E4' : {$pf = array(  623.622,  878.740); break;}
531
+            case 'E5' : {$pf = array(  439.370,  623.622); break;}
532
+            case 'E6' : {$pf = array(  311.811,  439.370); break;}
533
+            case 'E7' : {$pf = array(  221.102,  311.811); break;}
534
+            case 'E8' : {$pf = array(  155.906,  221.102); break;}
535
+            case 'E9' : {$pf = array(  110.551,  155.906); break;}
536
+            case 'E10': {$pf = array(   76.535,  110.551); break;}
537
+            case 'E11': {$pf = array(   53.858,   76.535); break;}
538
+            case 'E12': {$pf = array(   36.850,   53.858); break;}
539
+            // SIS 014711 G Series
540
+            case 'G0' : {$pf = array( 2715.591, 3838.110); break;}
541
+            case 'G1' : {$pf = array( 1919.055, 2715.591); break;}
542
+            case 'G2' : {$pf = array( 1357.795, 1919.055); break;}
543
+            case 'G3' : {$pf = array(  958.110, 1357.795); break;}
544
+            case 'G4' : {$pf = array(  677.480,  958.110); break;}
545
+            case 'G5' : {$pf = array(  479.055,  677.480); break;}
546
+            case 'G6' : {$pf = array(  337.323,  479.055); break;}
547
+            case 'G7' : {$pf = array(  238.110,  337.323); break;}
548
+            case 'G8' : {$pf = array(  167.244,  238.110); break;}
549
+            case 'G9' : {$pf = array(  119.055,  167.244); break;}
550
+            case 'G10': {$pf = array(   82.205,  119.055); break;}
551
+            case 'G11': {$pf = array(   59.528,   82.205); break;}
552
+            case 'G12': {$pf = array(   39.685,   59.528); break;}
553
+            // ISO Press
554
+            case 'RA0': {$pf = array( 2437.795, 3458.268); break;}
555
+            case 'RA1': {$pf = array( 1729.134, 2437.795); break;}
556
+            case 'RA2': {$pf = array( 1218.898, 1729.134); break;}
557
+            case 'RA3': {$pf = array(  864.567, 1218.898); break;}
558
+            case 'RA4': {$pf = array(  609.449,  864.567); break;}
559
+            case 'SRA0': {$pf = array( 2551.181, 3628.346); break;}
560
+            case 'SRA1': {$pf = array( 1814.173, 2551.181); break;}
561
+            case 'SRA2': {$pf = array( 1275.591, 1814.173); break;}
562
+            case 'SRA3': {$pf = array(  907.087, 1275.591); break;}
563
+            case 'SRA4': {$pf = array(  637.795,  907.087); break;}
564
+            // German  DIN 476
565
+            case '4A0': {$pf = array( 4767.874, 6740.787); break;}
566
+            case '2A0': {$pf = array( 3370.394, 4767.874); break;}
567
+            // Variations on the ISO Standard
568
+            case 'A2_EXTRA'   : {$pf = array( 1261.417, 1754.646); break;}
569
+            case 'A3+'        : {$pf = array(  932.598, 1369.134); break;}
570
+            case 'A3_EXTRA'   : {$pf = array(  912.756, 1261.417); break;}
571
+            case 'A3_SUPER'   : {$pf = array(  864.567, 1440.000); break;}
572
+            case 'SUPER_A3'   : {$pf = array(  864.567, 1380.472); break;}
573
+            case 'A4_EXTRA'   : {$pf = array(  666.142,  912.756); break;}
574
+            case 'A4_SUPER'   : {$pf = array(  649.134,  912.756); break;}
575
+            case 'SUPER_A4'   : {$pf = array(  643.465, 1009.134); break;}
576
+            case 'A4_LONG'    : {$pf = array(  595.276,  986.457); break;}
577
+            case 'F4'         : {$pf = array(  595.276,  935.433); break;}
578
+            case 'SO_B5_EXTRA': {$pf = array(  572.598,  782.362); break;}
579
+            case 'A5_EXTRA'   : {$pf = array(  490.394,  666.142); break;}
580
+            // ANSI Series
581
+            case 'ANSI_E': {$pf = array( 2448.000, 3168.000); break;}
582
+            case 'ANSI_D': {$pf = array( 1584.000, 2448.000); break;}
583
+            case 'ANSI_C': {$pf = array( 1224.000, 1584.000); break;}
584
+            case 'ANSI_B': {$pf = array(  792.000, 1224.000); break;}
585
+            case 'ANSI_A': {$pf = array(  612.000,  792.000); break;}
586
+            // Traditional 'Loose' North American Paper Sizes
587
+            case 'USLEDGER':
588
+            case 'LEDGER' : {$pf = array( 1224.000,  792.000); break;}
589
+            case 'ORGANIZERK':
590
+            case 'BIBLE':
591
+            case 'USTABLOID':
592
+            case 'TABLOID': {$pf = array(  792.000, 1224.000); break;}
593
+            case 'ORGANIZERM':
594
+            case 'USLETTER':
595
+            case 'LETTER' : {$pf = array(  612.000,  792.000); break;}
596
+            case 'USLEGAL':
597
+            case 'LEGAL'  : {$pf = array(  612.000, 1008.000); break;}
598
+            case 'GOVERNMENTLETTER':
599
+            case 'GLETTER': {$pf = array(  576.000,  756.000); break;}
600
+            case 'JUNIORLEGAL':
601
+            case 'JLEGAL' : {$pf = array(  576.000,  360.000); break;}
602
+            // Other North American Paper Sizes
603
+            case 'QUADDEMY': {$pf = array( 2520.000, 3240.000); break;}
604
+            case 'SUPER_B': {$pf = array(  936.000, 1368.000); break;}
605
+            case 'QUARTO': {$pf = array(  648.000,  792.000); break;}
606
+            case 'GOVERNMENTLEGAL':
607
+            case 'FOLIO': {$pf = array(  612.000,  936.000); break;}
608
+            case 'MONARCH':
609
+            case 'EXECUTIVE': {$pf = array(  522.000,  756.000); break;}
610
+            case 'ORGANIZERL':
611
+            case 'STATEMENT':
612
+            case 'MEMO': {$pf = array(  396.000,  612.000); break;}
613
+            case 'FOOLSCAP': {$pf = array(  595.440,  936.000); break;}
614
+            case 'COMPACT': {$pf = array(  306.000,  486.000); break;}
615
+            case 'ORGANIZERJ': {$pf = array(  198.000,  360.000); break;}
616
+            // Canadian standard CAN 2-9.60M
617
+            case 'P1': {$pf = array( 1587.402, 2437.795); break;}
618
+            case 'P2': {$pf = array( 1218.898, 1587.402); break;}
619
+            case 'P3': {$pf = array(  793.701, 1218.898); break;}
620
+            case 'P4': {$pf = array(  609.449,  793.701); break;}
621
+            case 'P5': {$pf = array(  396.850,  609.449); break;}
622
+            case 'P6': {$pf = array(  303.307,  396.850); break;}
623
+            // North American Architectural Sizes
624
+            case 'ARCH_E' : {$pf = array( 2592.000, 3456.000); break;}
625
+            case 'ARCH_E1': {$pf = array( 2160.000, 3024.000); break;}
626
+            case 'ARCH_D' : {$pf = array( 1728.000, 2592.000); break;}
627
+            case 'BROADSHEET':
628
+            case 'ARCH_C' : {$pf = array( 1296.000, 1728.000); break;}
629
+            case 'ARCH_B' : {$pf = array(  864.000, 1296.000); break;}
630
+            case 'ARCH_A' : {$pf = array(  648.000,  864.000); break;}
631
+            // --- North American Envelope Sizes ---
632
+            //   - Announcement Envelopes
633
+            case 'ANNENV_A2'  : {$pf = array(  314.640,  414.000); break;}
634
+            case 'ANNENV_A6'  : {$pf = array(  342.000,  468.000); break;}
635
+            case 'ANNENV_A7'  : {$pf = array(  378.000,  522.000); break;}
636
+            case 'ANNENV_A8'  : {$pf = array(  396.000,  584.640); break;}
637
+            case 'ANNENV_A10' : {$pf = array(  450.000,  692.640); break;}
638
+            case 'ANNENV_SLIM': {$pf = array(  278.640,  638.640); break;}
639
+            //   - Commercial Envelopes
640
+            case 'COMMENV_N6_1/4': {$pf = array(  252.000,  432.000); break;}
641
+            case 'COMMENV_N6_3/4': {$pf = array(  260.640,  468.000); break;}
642
+            case 'COMMENV_N8'    : {$pf = array(  278.640,  540.000); break;}
643
+            case 'COMMENV_N9'    : {$pf = array(  278.640,  638.640); break;}
644
+            case 'COMMENV_N10'   : {$pf = array(  296.640,  684.000); break;}
645
+            case 'COMMENV_N11'   : {$pf = array(  324.000,  746.640); break;}
646
+            case 'COMMENV_N12'   : {$pf = array(  342.000,  792.000); break;}
647
+            case 'COMMENV_N14'   : {$pf = array(  360.000,  828.000); break;}
648
+            //   - Catalogue Envelopes
649
+            case 'CATENV_N1'     : {$pf = array(  432.000,  648.000); break;}
650
+            case 'CATENV_N1_3/4' : {$pf = array(  468.000,  684.000); break;}
651
+            case 'CATENV_N2'     : {$pf = array(  468.000,  720.000); break;}
652
+            case 'CATENV_N3'     : {$pf = array(  504.000,  720.000); break;}
653
+            case 'CATENV_N6'     : {$pf = array(  540.000,  756.000); break;}
654
+            case 'CATENV_N7'     : {$pf = array(  576.000,  792.000); break;}
655
+            case 'CATENV_N8'     : {$pf = array(  594.000,  810.000); break;}
656
+            case 'CATENV_N9_1/2' : {$pf = array(  612.000,  756.000); break;}
657
+            case 'CATENV_N9_3/4' : {$pf = array(  630.000,  810.000); break;}
658
+            case 'CATENV_N10_1/2': {$pf = array(  648.000,  864.000); break;}
659
+            case 'CATENV_N12_1/2': {$pf = array(  684.000,  900.000); break;}
660
+            case 'CATENV_N13_1/2': {$pf = array(  720.000,  936.000); break;}
661
+            case 'CATENV_N14_1/4': {$pf = array(  810.000,  882.000); break;}
662
+            case 'CATENV_N14_1/2': {$pf = array(  828.000, 1044.000); break;}
663
+            // Japanese (JIS P 0138-61) Standard B-Series
664
+            case 'JIS_B0' : {$pf = array( 2919.685, 4127.244); break;}
665
+            case 'JIS_B1' : {$pf = array( 2063.622, 2919.685); break;}
666
+            case 'JIS_B2' : {$pf = array( 1459.843, 2063.622); break;}
667
+            case 'JIS_B3' : {$pf = array( 1031.811, 1459.843); break;}
668
+            case 'JIS_B4' : {$pf = array(  728.504, 1031.811); break;}
669
+            case 'JIS_B5' : {$pf = array(  515.906,  728.504); break;}
670
+            case 'JIS_B6' : {$pf = array(  362.835,  515.906); break;}
671
+            case 'JIS_B7' : {$pf = array(  257.953,  362.835); break;}
672
+            case 'JIS_B8' : {$pf = array(  181.417,  257.953); break;}
673
+            case 'JIS_B9' : {$pf = array(  127.559,  181.417); break;}
674
+            case 'JIS_B10': {$pf = array(   90.709,  127.559); break;}
675
+            case 'JIS_B11': {$pf = array(   62.362,   90.709); break;}
676
+            case 'JIS_B12': {$pf = array(   45.354,   62.362); break;}
677
+            // PA Series
678
+            case 'PA0' : {$pf = array( 2381.102, 3174.803,); break;}
679
+            case 'PA1' : {$pf = array( 1587.402, 2381.102); break;}
680
+            case 'PA2' : {$pf = array( 1190.551, 1587.402); break;}
681
+            case 'PA3' : {$pf = array(  793.701, 1190.551); break;}
682
+            case 'PA4' : {$pf = array(  595.276,  793.701); break;}
683
+            case 'PA5' : {$pf = array(  396.850,  595.276); break;}
684
+            case 'PA6' : {$pf = array(  297.638,  396.850); break;}
685
+            case 'PA7' : {$pf = array(  198.425,  297.638); break;}
686
+            case 'PA8' : {$pf = array(  147.402,  198.425); break;}
687
+            case 'PA9' : {$pf = array(   99.213,  147.402); break;}
688
+            case 'PA10': {$pf = array(   73.701,   99.213); break;}
689
+            // Standard Photographic Print Sizes
690
+            case 'PASSPORT_PHOTO': {$pf = array(   99.213,  127.559); break;}
691
+            case 'E'   : {$pf = array(  233.858,  340.157); break;}
692
+            case 'L':
693
+            case '3R'  : {$pf = array(  252.283,  360.000); break;}
694
+            case 'KG':
695
+            case '4R'  : {$pf = array(  289.134,  430.866); break;}
696
+            case '4D'  : {$pf = array(  340.157,  430.866); break;}
697
+            case '2L':
698
+            case '5R'  : {$pf = array(  360.000,  504.567); break;}
699
+            case '8P':
700
+            case '6R'  : {$pf = array(  430.866,  575.433); break;}
701
+            case '6P':
702
+            case '8R'  : {$pf = array(  575.433,  720.000); break;}
703
+            case '6PW':
704
+            case 'S8R' : {$pf = array(  575.433,  864.567); break;}
705
+            case '4P':
706
+            case '10R' : {$pf = array(  720.000,  864.567); break;}
707
+            case '4PW':
708
+            case 'S10R': {$pf = array(  720.000, 1080.000); break;}
709
+            case '11R' : {$pf = array(  790.866, 1009.134); break;}
710
+            case 'S11R': {$pf = array(  790.866, 1224.567); break;}
711
+            case '12R' : {$pf = array(  864.567, 1080.000); break;}
712
+            case 'S12R': {$pf = array(  864.567, 1292.598); break;}
713
+            // Common Newspaper Sizes
714
+            case 'NEWSPAPER_BROADSHEET': {$pf = array( 2125.984, 1700.787); break;}
715
+            case 'NEWSPAPER_BERLINER'  : {$pf = array( 1332.283,  892.913); break;}
716
+            case 'NEWSPAPER_TABLOID':
717
+            case 'NEWSPAPER_COMPACT'   : {$pf = array( 1218.898,  793.701); break;}
718
+            // Business Cards
719
+            case 'CREDIT_CARD':
720
+            case 'BUSINESS_CARD':
721
+            case 'BUSINESS_CARD_ISO7810': {$pf = array(  153.014,  242.646); break;}
722
+            case 'BUSINESS_CARD_ISO216' : {$pf = array(  147.402,  209.764); break;}
723
+            case 'BUSINESS_CARD_IT':
724
+            case 'BUSINESS_CARD_UK':
725
+            case 'BUSINESS_CARD_FR':
726
+            case 'BUSINESS_CARD_DE':
727
+            case 'BUSINESS_CARD_ES'     : {$pf = array(  155.906,  240.945); break;}
728
+            case 'BUSINESS_CARD_CA':
729
+            case 'BUSINESS_CARD_US'     : {$pf = array(  144.567,  252.283); break;}
730
+            case 'BUSINESS_CARD_JP'     : {$pf = array(  155.906,  257.953); break;}
731
+            case 'BUSINESS_CARD_HK'     : {$pf = array(  153.071,  255.118); break;}
732
+            case 'BUSINESS_CARD_AU':
733
+            case 'BUSINESS_CARD_DK':
734
+            case 'BUSINESS_CARD_SE'     : {$pf = array(  155.906,  255.118); break;}
735
+            case 'BUSINESS_CARD_RU':
736
+            case 'BUSINESS_CARD_CZ':
737
+            case 'BUSINESS_CARD_FI':
738
+            case 'BUSINESS_CARD_HU':
739
+            case 'BUSINESS_CARD_IL'     : {$pf = array(  141.732,  255.118); break;}
740
+            // Billboards
741
+            case '4SHEET' : {$pf = array( 2880.000, 4320.000); break;}
742
+            case '6SHEET' : {$pf = array( 3401.575, 5102.362); break;}
743
+            case '12SHEET': {$pf = array( 8640.000, 4320.000); break;}
744
+            case '16SHEET': {$pf = array( 5760.000, 8640.000); break;}
745
+            case '32SHEET': {$pf = array(11520.000, 8640.000); break;}
746
+            case '48SHEET': {$pf = array(17280.000, 8640.000); break;}
747
+            case '64SHEET': {$pf = array(23040.000, 8640.000); break;}
748
+            case '96SHEET': {$pf = array(34560.000, 8640.000); break;}
749
+            // Old European Sizes
750
+            //   - Old Imperial English Sizes
751
+            case 'EN_EMPEROR'          : {$pf = array( 3456.000, 5184.000); break;}
752
+            case 'EN_ANTIQUARIAN'      : {$pf = array( 2232.000, 3816.000); break;}
753
+            case 'EN_GRAND_EAGLE'      : {$pf = array( 2070.000, 3024.000); break;}
754
+            case 'EN_DOUBLE_ELEPHANT'  : {$pf = array( 1926.000, 2880.000); break;}
755
+            case 'EN_ATLAS'            : {$pf = array( 1872.000, 2448.000); break;}
756
+            case 'EN_COLOMBIER'        : {$pf = array( 1692.000, 2484.000); break;}
757
+            case 'EN_ELEPHANT'         : {$pf = array( 1656.000, 2016.000); break;}
758
+            case 'EN_DOUBLE_DEMY'      : {$pf = array( 1620.000, 2556.000); break;}
759
+            case 'EN_IMPERIAL'         : {$pf = array( 1584.000, 2160.000); break;}
760
+            case 'EN_PRINCESS'         : {$pf = array( 1548.000, 2016.000); break;}
761
+            case 'EN_CARTRIDGE'        : {$pf = array( 1512.000, 1872.000); break;}
762
+            case 'EN_DOUBLE_LARGE_POST': {$pf = array( 1512.000, 2376.000); break;}
763
+            case 'EN_ROYAL'            : {$pf = array( 1440.000, 1800.000); break;}
764
+            case 'EN_SHEET':
765
+            case 'EN_HALF_POST'        : {$pf = array( 1404.000, 1692.000); break;}
766
+            case 'EN_SUPER_ROYAL'      : {$pf = array( 1368.000, 1944.000); break;}
767
+            case 'EN_DOUBLE_POST'      : {$pf = array( 1368.000, 2196.000); break;}
768
+            case 'EN_MEDIUM'           : {$pf = array( 1260.000, 1656.000); break;}
769
+            case 'EN_DEMY'             : {$pf = array( 1260.000, 1620.000); break;}
770
+            case 'EN_LARGE_POST'       : {$pf = array( 1188.000, 1512.000); break;}
771
+            case 'EN_COPY_DRAUGHT'     : {$pf = array( 1152.000, 1440.000); break;}
772
+            case 'EN_POST'             : {$pf = array( 1116.000, 1386.000); break;}
773
+            case 'EN_CROWN'            : {$pf = array( 1080.000, 1440.000); break;}
774
+            case 'EN_PINCHED_POST'     : {$pf = array( 1062.000, 1332.000); break;}
775
+            case 'EN_BRIEF'            : {$pf = array(  972.000, 1152.000); break;}
776
+            case 'EN_FOOLSCAP'         : {$pf = array(  972.000, 1224.000); break;}
777
+            case 'EN_SMALL_FOOLSCAP'   : {$pf = array(  954.000, 1188.000); break;}
778
+            case 'EN_POTT'             : {$pf = array(  900.000, 1080.000); break;}
779
+            //   - Old Imperial Belgian Sizes
780
+            case 'BE_GRAND_AIGLE' : {$pf = array( 1984.252, 2948.031); break;}
781
+            case 'BE_COLOMBIER'   : {$pf = array( 1757.480, 2409.449); break;}
782
+            case 'BE_DOUBLE_CARRE': {$pf = array( 1757.480, 2607.874); break;}
783
+            case 'BE_ELEPHANT'    : {$pf = array( 1746.142, 2182.677); break;}
784
+            case 'BE_PETIT_AIGLE' : {$pf = array( 1700.787, 2381.102); break;}
785
+            case 'BE_GRAND_JESUS' : {$pf = array( 1559.055, 2069.291); break;}
786
+            case 'BE_JESUS'       : {$pf = array( 1530.709, 2069.291); break;}
787
+            case 'BE_RAISIN'      : {$pf = array( 1417.323, 1842.520); break;}
788
+            case 'BE_GRAND_MEDIAN': {$pf = array( 1303.937, 1714.961); break;}
789
+            case 'BE_DOUBLE_POSTE': {$pf = array( 1233.071, 1601.575); break;}
790
+            case 'BE_COQUILLE'    : {$pf = array( 1218.898, 1587.402); break;}
791
+            case 'BE_PETIT_MEDIAN': {$pf = array( 1176.378, 1502.362); break;}
792
+            case 'BE_RUCHE'       : {$pf = array( 1020.472, 1303.937); break;}
793
+            case 'BE_PROPATRIA'   : {$pf = array(  977.953, 1218.898); break;}
794
+            case 'BE_LYS'         : {$pf = array(  898.583, 1125.354); break;}
795
+            case 'BE_POT'         : {$pf = array(  870.236, 1088.504); break;}
796
+            case 'BE_ROSETTE'     : {$pf = array(  765.354,  983.622); break;}
797
+            //   - Old Imperial French Sizes
798
+            case 'FR_UNIVERS'          : {$pf = array( 2834.646, 3685.039); break;}
799
+            case 'FR_DOUBLE_COLOMBIER' : {$pf = array( 2551.181, 3571.654); break;}
800
+            case 'FR_GRANDE_MONDE'     : {$pf = array( 2551.181, 3571.654); break;}
801
+            case 'FR_DOUBLE_SOLEIL'    : {$pf = array( 2267.717, 3401.575); break;}
802
+            case 'FR_DOUBLE_JESUS'     : {$pf = array( 2154.331, 3174.803); break;}
803
+            case 'FR_GRAND_AIGLE'      : {$pf = array( 2125.984, 3004.724); break;}
804
+            case 'FR_PETIT_AIGLE'      : {$pf = array( 1984.252, 2664.567); break;}
805
+            case 'FR_DOUBLE_RAISIN'    : {$pf = array( 1842.520, 2834.646); break;}
806
+            case 'FR_JOURNAL'          : {$pf = array( 1842.520, 2664.567); break;}
807
+            case 'FR_COLOMBIER_AFFICHE': {$pf = array( 1785.827, 2551.181); break;}
808
+            case 'FR_DOUBLE_CAVALIER'  : {$pf = array( 1757.480, 2607.874); break;}
809
+            case 'FR_CLOCHE'           : {$pf = array( 1700.787, 2267.717); break;}
810
+            case 'FR_SOLEIL'           : {$pf = array( 1700.787, 2267.717); break;}
811
+            case 'FR_DOUBLE_CARRE'     : {$pf = array( 1587.402, 2551.181); break;}
812
+            case 'FR_DOUBLE_COQUILLE'  : {$pf = array( 1587.402, 2494.488); break;}
813
+            case 'FR_JESUS'            : {$pf = array( 1587.402, 2154.331); break;}
814
+            case 'FR_RAISIN'           : {$pf = array( 1417.323, 1842.520); break;}
815
+            case 'FR_CAVALIER'         : {$pf = array( 1303.937, 1757.480); break;}
816
+            case 'FR_DOUBLE_COURONNE'  : {$pf = array( 1303.937, 2040.945); break;}
817
+            case 'FR_CARRE'            : {$pf = array( 1275.591, 1587.402); break;}
818
+            case 'FR_COQUILLE'         : {$pf = array( 1247.244, 1587.402); break;}
819
+            case 'FR_DOUBLE_TELLIERE'  : {$pf = array( 1247.244, 1927.559); break;}
820
+            case 'FR_DOUBLE_CLOCHE'    : {$pf = array( 1133.858, 1700.787); break;}
821
+            case 'FR_DOUBLE_POT'       : {$pf = array( 1133.858, 1757.480); break;}
822
+            case 'FR_ECU'              : {$pf = array( 1133.858, 1474.016); break;}
823
+            case 'FR_COURONNE'         : {$pf = array( 1020.472, 1303.937); break;}
824
+            case 'FR_TELLIERE'         : {$pf = array(  963.780, 1247.244); break;}
825
+            case 'FR_POT'              : {$pf = array(  878.740, 1133.858); break;}
826
+            // DEFAULT ISO A4
827
+            default: {$pf = array(  595.276,  841.890); break;}
828
+        }
829
+        return $pf;
830
+    }
831
+
832
+    /**
833
+     * Set page boundaries.
834
+     * @param $page (int) page number
835
+     * @param $type (string) valid values are: <ul><li>'MediaBox' : the boundaries of the physical medium on which the page shall be displayed or printed;</li><li>'CropBox' : the visible region of default user space;</li><li>'BleedBox' : the region to which the contents of the page shall be clipped when output in a production environment;</li><li>'TrimBox' : the intended dimensions of the finished page after trimming;</li><li>'ArtBox' : the page's meaningful content (including potential white space).</li></ul>
836
+     * @param $llx (float) lower-left x coordinate in user units.
837
+     * @param $lly (float) lower-left y coordinate in user units.
838
+     * @param $urx (float) upper-right x coordinate in user units.
839
+     * @param $ury (float) upper-right y coordinate in user units.
840
+     * @param $points (boolean) If true uses user units as unit of measure, otherwise uses PDF points.
841
+     * @param $k (float) Scale factor (number of points in user unit).
842
+     * @param $pagedim (array) Array of page dimensions.
843
+     * @return pagedim array of page dimensions.
844
+     * @since 5.0.010 (2010-05-17)
845
+     * @public static
846
+     */
847
+    public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points=false, $k, $pagedim=array()) {
848
+        if (!isset($pagedim[$page])) {
849
+            // initialize array
850
+            $pagedim[$page] = array();
851
+        }
852
+        if (!in_array($type, self::$pageboxes)) {
853
+            return;
854
+        }
855
+        if ($points) {
856
+            $k = 1;
857
+        }
858
+        $pagedim[$page][$type]['llx'] = ($llx * $k);
859
+        $pagedim[$page][$type]['lly'] = ($lly * $k);
860
+        $pagedim[$page][$type]['urx'] = ($urx * $k);
861
+        $pagedim[$page][$type]['ury'] = ($ury * $k);
862
+        return $pagedim;
863
+    }
864
+
865
+    /**
866
+     * Swap X and Y coordinates of page boxes (change page boxes orientation).
867
+     * @param $page (int) page number
868
+     * @param $pagedim (array) Array of page dimensions.
869
+     * @return pagedim array of page dimensions.
870
+     * @since 5.0.010 (2010-05-17)
871
+     * @public static
872
+     */
873
+    public static function swapPageBoxCoordinates($page, $pagedim) {
874
+        foreach (self::$pageboxes as $type) {
875
+            // swap X and Y coordinates
876
+            if (isset($pagedim[$page][$type])) {
877
+                $tmp = $pagedim[$page][$type]['llx'];
878
+                $pagedim[$page][$type]['llx'] = $pagedim[$page][$type]['lly'];
879
+                $pagedim[$page][$type]['lly'] = $tmp;
880
+                $tmp = $pagedim[$page][$type]['urx'];
881
+                $pagedim[$page][$type]['urx'] = $pagedim[$page][$type]['ury'];
882
+                $pagedim[$page][$type]['ury'] = $tmp;
883
+            }
884
+        }
885
+        return $pagedim;
886
+    }
887
+
888
+    /**
889
+     * Get the canonical page layout mode.
890
+     * @param $layout (string) The page layout. Possible values are:<ul><li>SinglePage Display one page at a time</li><li>OneColumn Display the pages in one column</li><li>TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left</li><li>TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right</li><li>TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left</li><li>TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right</li></ul>
891
+     * @return (string) Canonical page layout name.
892
+     * @public static
893
+     */
894
+    public static function getPageLayoutMode($layout='SinglePage') {
895
+        switch ($layout) {
896
+            case 'default':
897
+            case 'single':
898
+            case 'SinglePage': {
899
+                $layout_mode = 'SinglePage';
900
+                break;
901
+            }
902
+            case 'continuous':
903
+            case 'OneColumn': {
904
+                $layout_mode = 'OneColumn';
905
+                break;
906
+            }
907
+            case 'two':
908
+            case 'TwoColumnLeft': {
909
+                $layout_mode = 'TwoColumnLeft';
910
+                break;
911
+            }
912
+            case 'TwoColumnRight': {
913
+                $layout_mode = 'TwoColumnRight';
914
+                break;
915
+            }
916
+            case 'TwoPageLeft': {
917
+                $layout_mode = 'TwoPageLeft';
918
+                break;
919
+            }
920
+            case 'TwoPageRight': {
921
+                $layout_mode = 'TwoPageRight';
922
+                break;
923
+            }
924
+            default: {
925
+                $layout_mode = 'SinglePage';
926
+            }
927
+        }
928
+        return $layout_mode;
929
+    }
930
+
931
+    /**
932
+     * Get the canonical page layout mode.
933
+     * @param $mode (string) A name object specifying how the document should be displayed when opened:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible</li><li>UseOC (PDF 1.5) Optional content group panel visible</li><li>UseAttachments (PDF 1.6) Attachments panel visible</li></ul>
934
+     * @return (string) Canonical page mode name.
935
+     * @public static
936
+     */
937
+    public static function getPageMode($mode='UseNone') {
938
+        switch ($mode) {
939
+            case 'UseNone': {
940
+                $page_mode = 'UseNone';
941
+                break;
942
+            }
943
+            case 'UseOutlines': {
944
+                $page_mode = 'UseOutlines';
945
+                break;
946
+            }
947
+            case 'UseThumbs': {
948
+                $page_mode = 'UseThumbs';
949
+                break;
950
+            }
951
+            case 'FullScreen': {
952
+                $page_mode = 'FullScreen';
953
+                break;
954
+            }
955
+            case 'UseOC': {
956
+                $page_mode = 'UseOC';
957
+                break;
958
+            }
959
+            case '': {
960
+                $page_mode = 'UseAttachments';
961
+                break;
962
+            }
963
+            default: {
964
+                $page_mode = 'UseNone';
965
+            }
966
+        }
967
+        return $page_mode;
968
+    }
969
+
970
+    /**
971
+     * Check if the URL exist.
972
+     * @param $url (string) URL to check.
973
+     * @return Boolean true if the URl exist, false otherwise.
974
+     * @since 5.9.204 (2013-01-28)
975
+     * @public static
976
+     */
977
+    public static function isValidURL($url) {
978
+        $headers = @get_headers($url);
979
+        return (strpos($headers[0], '200') !== false);
980
+    }
981
+
982
+    /**
983
+     * Removes SHY characters from text.
984
+     * Unicode Data:<ul>
985
+     * <li>Name : SOFT HYPHEN, commonly abbreviated as SHY</li>
986
+     * <li>HTML Entity (decimal): "&amp;#173;"</li>
987
+     * <li>HTML Entity (hex): "&amp;#xad;"</li>
988
+     * <li>HTML Entity (named): "&amp;shy;"</li>
989
+     * <li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li>
990
+     * <li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li>
991
+     * <li>UTF-8 character: chr(194).chr(173)</li>
992
+     * </ul>
993
+     * @param $txt (string) input string
994
+     * @param $unicode (boolean) True if we are in unicode mode, false otherwise.
995
+     * @return string without SHY characters.
996
+     * @since (4.5.019) 2009-02-28
997
+     * @public static
998
+     */
999
+    public static function removeSHY($txt='', $unicode=true) {
1000
+        $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
1001
+        if (!$unicode) {
1002
+            $txt = preg_replace('/([\\xad]{1})/', '', $txt);
1003
+        }
1004
+        return $txt;
1005
+    }
1006
+
1007
+
1008
+    /**
1009
+     * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
1010
+     * @param $brd (mixed) Indicates if borders must be drawn around the cell block. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
1011
+     * @param $position (string) multicell position: 'start', 'middle', 'end'
1012
+     * @param $opencell (boolean) True when the cell is left open at the page bottom, false otherwise.
1013
+     * @return border mode array
1014
+     * @since 4.4.002 (2008-12-09)
1015
+     * @public static
1016
+     */
1017
+    public static function getBorderMode($brd, $position='start', $opencell=true) {
1018
+        if ((!$opencell) OR empty($brd)) {
1019
+            return $brd;
1020
+        }
1021
+        if ($brd == 1) {
1022
+            $brd = 'LTRB';
1023
+        }
1024
+        if (is_string($brd)) {
1025
+            // convert string to array
1026
+            $slen = strlen($brd);
1027
+            $newbrd = array();
1028
+            for ($i = 0; $i < $slen; ++$i) {
1029
+                $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
1030
+            }
1031
+            $brd = $newbrd;
1032
+        }
1033
+        foreach ($brd as $border => $style) {
1034
+            switch ($position) {
1035
+                case 'start': {
1036
+                    if (strpos($border, 'B') !== false) {
1037
+                        // remove bottom line
1038
+                        $newkey = str_replace('B', '', $border);
1039
+                        if (strlen($newkey) > 0) {
1040
+                            $brd[$newkey] = $style;
1041
+                        }
1042
+                        unset($brd[$border]);
1043
+                    }
1044
+                    break;
1045
+                }
1046
+                case 'middle': {
1047
+                    if (strpos($border, 'B') !== false) {
1048
+                        // remove bottom line
1049
+                        $newkey = str_replace('B', '', $border);
1050
+                        if (strlen($newkey) > 0) {
1051
+                            $brd[$newkey] = $style;
1052
+                        }
1053
+                        unset($brd[$border]);
1054
+                        $border = $newkey;
1055
+                    }
1056
+                    if (strpos($border, 'T') !== false) {
1057
+                        // remove bottom line
1058
+                        $newkey = str_replace('T', '', $border);
1059
+                        if (strlen($newkey) > 0) {
1060
+                            $brd[$newkey] = $style;
1061
+                        }
1062
+                        unset($brd[$border]);
1063
+                    }
1064
+                    break;
1065
+                }
1066
+                case 'end': {
1067
+                    if (strpos($border, 'T') !== false) {
1068
+                        // remove bottom line
1069
+                        $newkey = str_replace('T', '', $border);
1070
+                        if (strlen($newkey) > 0) {
1071
+                            $brd[$newkey] = $style;
1072
+                        }
1073
+                        unset($brd[$border]);
1074
+                    }
1075
+                    break;
1076
+                }
1077
+            }
1078
+        }
1079
+        return $brd;
1080
+    }
1081
+
1082
+    /**
1083
+     * Determine whether a string is empty.
1084
+     * @param $str (string) string to be checked
1085
+     * @return boolean true if string is empty
1086
+     * @since 4.5.044 (2009-04-16)
1087
+     * @public static
1088
+     */
1089
+    public static function empty_string($str) {
1090
+        return (is_null($str) OR (is_string($str) AND (strlen($str) == 0)));
1091
+    }
1092
+
1093
+    /**
1094
+     * Returns a temporary filename for caching object on filesystem.
1095
+     * @param $type (string) Type of file (name of the subdir on the tcpdf cache folder).
1096
+     * @return string filename.
1097
+     * @since 4.5.000 (2008-12-31)
1098
+     * @public static
1099
+     */
1100
+    public static function getObjFilename($type='tmp') {
1101
+        return tempnam(K_PATH_CACHE, '__tcpdf_'.$type.'_'.md5(getmypid().uniqid('', true).rand().microtime(true)).'_');
1102
+    }
1103
+
1104
+    /**
1105
+     * Add "\" before "\", "(" and ")"
1106
+     * @param $s (string) string to escape.
1107
+     * @return string escaped string.
1108
+     * @public static
1109
+     */
1110
+    public static function _escape($s) {
1111
+        // the chr(13) substitution fixes the Bugs item #1421290.
1112
+        return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
1113
+    }
1114
+
1115
+    /**
1116
+     * Escape some special characters (&lt; &gt; &amp;) for XML output.
1117
+     * @param $str (string) Input string to convert.
1118
+     * @return converted string
1119
+     * @since 5.9.121 (2011-09-28)
1120
+     * @public static
1121
+     */
1122
+    public static function _escapeXML($str) {
1123
+        $replaceTable = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
1124
+        $str = strtr($str, $replaceTable);
1125
+        return $str;
1126
+    }
1127
+
1128
+    /**
1129
+     * Creates a copy of a class object
1130
+     * @param $object (object) class object to be cloned
1131
+     * @return cloned object
1132
+     * @since 4.5.029 (2009-03-19)
1133
+     * @public static
1134
+     */
1135
+    public static function objclone($object) {
1136
+        if (($object instanceof Imagick) AND (version_compare(phpversion('imagick'), '3.0.1') !== 1)) {
1137
+            // on the versions after 3.0.1 the clone() method was deprecated in favour of clone keyword
1138
+            return @$object->clone();
1139
+        }
1140
+        return @clone($object);
1141
+    }
1142
+
1143
+    /**
1144
+     * Ouput input data and compress it if possible.
1145
+     * @param $data (string) Data to output.
1146
+     * @param $length (int) Data length in bytes.
1147
+     * @since 5.9.086
1148
+     * @public static
1149
+     */
1150
+    public static function sendOutputData($data, $length) {
1151
+        if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
1152
+            // the content length may vary if the server is using compression
1153
+            header('Content-Length: '.$length);
1154
+        }
1155
+        echo $data;
1156
+    }
1157
+
1158
+    /**
1159
+     * Replace page number aliases with number.
1160
+     * @param $page (string) Page content.
1161
+     * @param $replace (array) Array of replacements (array keys are replacement strings, values are alias arrays).
1162
+     * @param $diff (int) If passed, this will be set to the total char number difference between alias and replacements.
1163
+     * @return replaced page content and updated $diff parameter as array.
1164
+     * @public static
1165
+     */
1166
+    public static function replacePageNumAliases($page, $replace, $diff=0) {
1167
+        foreach ($replace as $rep) {
1168
+            foreach ($rep[3] as $a) {
1169
+                if (strpos($page, $a) !== false) {
1170
+                    $page = str_replace($a, $rep[0], $page);
1171
+                    $diff += ($rep[2] - $rep[1]);
1172
+                }
1173
+            }
1174
+        }
1175
+        return array($page, $diff);
1176
+    }
1177
+
1178
+    /**
1179
+     * Returns timestamp in seconds from formatted date-time.
1180
+     * @param $date (string) Formatted date-time.
1181
+     * @return int seconds.
1182
+     * @since 5.9.152 (2012-03-23)
1183
+     * @public static
1184
+     */
1185
+    public static function getTimestamp($date) {
1186
+        if (($date[0] == 'D') AND ($date[1] == ':')) {
1187
+            // remove date prefix if present
1188
+            $date = substr($date, 2);
1189
+        }
1190
+        return strtotime($date);
1191
+    }
1192
+
1193
+    /**
1194
+     * Returns a formatted date-time.
1195
+     * @param $time (int) Time in seconds.
1196
+     * @return string escaped date string.
1197
+     * @since 5.9.152 (2012-03-23)
1198
+     * @public static
1199
+     */
1200
+    public static function getFormattedDate($time) {
1201
+        return substr_replace(date('YmdHisO', intval($time)), '\'', (0 - 2), 0).'\'';
1202
+    }
1203
+
1204
+    /**
1205
+     * Get ULONG from string (Big Endian 32-bit unsigned integer).
1206
+     * @param $str (string) string from where to extract value
1207
+     * @param $offset (int) point from where to read the data
1208
+     * @return int 32 bit value
1209
+     * @author Nicola Asuni
1210
+     * @since 5.2.000 (2010-06-02)
1211
+     * @public static
1212
+     */
1213
+    public static function _getULONG($str, $offset) {
1214
+        $v = unpack('Ni', substr($str, $offset, 4));
1215
+        return $v['i'];
1216
+    }
1217
+
1218
+    /**
1219
+     * Get USHORT from string (Big Endian 16-bit unsigned integer).
1220
+     * @param $str (string) string from where to extract value
1221
+     * @param $offset (int) point from where to read the data
1222
+     * @return int 16 bit value
1223
+     * @author Nicola Asuni
1224
+     * @since 5.2.000 (2010-06-02)
1225
+     * @public static
1226
+     */
1227
+    public static function _getUSHORT($str, $offset) {
1228
+        $v = unpack('ni', substr($str, $offset, 2));
1229
+        return $v['i'];
1230
+    }
1231
+
1232
+    /**
1233
+     * Get SHORT from string (Big Endian 16-bit signed integer).
1234
+     * @param $str (string) String from where to extract value.
1235
+     * @param $offset (int) Point from where to read the data.
1236
+     * @return int 16 bit value
1237
+     * @author Nicola Asuni
1238
+     * @since 5.2.000 (2010-06-02)
1239
+     * @public static
1240
+     */
1241
+    public static function _getSHORT($str, $offset) {
1242
+        $v = unpack('si', substr($str, $offset, 2));
1243
+        return $v['i'];
1244
+    }
1245
+
1246
+    /**
1247
+     * Get FWORD from string (Big Endian 16-bit signed integer).
1248
+     * @param $str (string) String from where to extract value.
1249
+     * @param $offset (int) Point from where to read the data.
1250
+     * @return int 16 bit value
1251
+     * @author Nicola Asuni
1252
+     * @since 5.9.123 (2011-09-30)
1253
+     * @public static
1254
+     */
1255
+    public static function _getFWORD($str, $offset) {
1256
+        $v = self::_getUSHORT($str, $offset);
1257
+        if ($v > 0x7fff) {
1258
+            $v -= 0x10000;
1259
+        }
1260
+        return $v;
1261
+    }
1262
+
1263
+    /**
1264
+     * Get UFWORD from string (Big Endian 16-bit unsigned integer).
1265
+     * @param $str (string) string from where to extract value
1266
+     * @param $offset (int) point from where to read the data
1267
+     * @return int 16 bit value
1268
+     * @author Nicola Asuni
1269
+     * @since 5.9.123 (2011-09-30)
1270
+     * @public static
1271
+     */
1272
+    public static function _getUFWORD($str, $offset) {
1273
+        $v = self::_getUSHORT($str, $offset);
1274
+        return $v;
1275
+    }
1276
+
1277
+    /**
1278
+     * Get FIXED from string (32-bit signed fixed-point number (16.16).
1279
+     * @param $str (string) string from where to extract value
1280
+     * @param $offset (int) point from where to read the data
1281
+     * @return int 16 bit value
1282
+     * @author Nicola Asuni
1283
+     * @since 5.9.123 (2011-09-30)
1284
+     * @public static
1285
+     */
1286
+    public static function _getFIXED($str, $offset) {
1287
+        // mantissa
1288
+        $m = self::_getFWORD($str, $offset);
1289
+        // fraction
1290
+        $f = self::_getUSHORT($str, ($offset + 2));
1291
+        $v = floatval(''.$m.'.'.$f.'');
1292
+        return $v;
1293
+    }
1294
+
1295
+    /**
1296
+     * Get BYTE from string (8-bit unsigned integer).
1297
+     * @param $str (string) String from where to extract value.
1298
+     * @param $offset (int) Point from where to read the data.
1299
+     * @return int 8 bit value
1300
+     * @author Nicola Asuni
1301
+     * @since 5.2.000 (2010-06-02)
1302
+     * @public static
1303
+     */
1304
+    public static function _getBYTE($str, $offset) {
1305
+        $v = unpack('Ci', substr($str, $offset, 1));
1306
+        return $v['i'];
1307
+    }
1308
+    /**
1309
+     * Binary-safe and URL-safe file read.
1310
+     * Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached.
1311
+     * @param $handle (resource)
1312
+     * @param $length (int)
1313
+     * @return Returns the read string or FALSE in case of error.
1314
+     * @author Nicola Asuni
1315
+     * @since 4.5.027 (2009-03-16)
1316
+     * @public static
1317
+     */
1318
+    public static function rfread($handle, $length) {
1319
+        $data = fread($handle, $length);
1320
+        if ($data === false) {
1321
+            return false;
1322
+        }
1323
+        $rest = ($length - strlen($data));
1324
+        if ($rest > 0) {
1325
+            $data .= self::rfread($handle, $rest);
1326
+        }
1327
+        return $data;
1328
+    }
1329
+
1330
+    /**
1331
+     * Read a 4-byte (32 bit) integer from file.
1332
+     * @param $f (string) file name.
1333
+     * @return 4-byte integer
1334
+     * @public static
1335
+     */
1336
+    public static function _freadint($f) {
1337
+        $a = unpack('Ni', fread($f, 4));
1338
+        return $a['i'];
1339
+    }
1340
+
1341
+    /**
1342
+     * Returns a string containing random data to be used as a seed for encryption methods.
1343
+     * @param $seed (string) starting seed value
1344
+     * @return string containing random data
1345
+     * @author Nicola Asuni
1346
+     * @since 5.9.006 (2010-10-19)
1347
+     * @public static
1348
+     */
1349
+    public static function getRandomSeed($seed='') {
1350
+        $seed .= microtime();
1351
+        if (function_exists('openssl_random_pseudo_bytes') AND (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) {
1352
+            // this is not used on windows systems because it is very slow for a know bug
1353
+            $seed .= openssl_random_pseudo_bytes(512);
1354
+        } else {
1355
+            for ($i = 0; $i < 23; ++$i) {
1356
+                $seed .= uniqid('', true);
1357
+            }
1358
+        }
1359
+        $seed .= uniqid('', true);
1360
+        $seed .= rand();
1361
+        $seed .= getmypid();
1362
+        $seed .= __FILE__;
1363
+        if (isset($_SERVER['REMOTE_ADDR'])) {
1364
+            $seed .= $_SERVER['REMOTE_ADDR'];
1365
+        }
1366
+        if (isset($_SERVER['HTTP_USER_AGENT'])) {
1367
+            $seed .= $_SERVER['HTTP_USER_AGENT'];
1368
+        }
1369
+        if (isset($_SERVER['HTTP_ACCEPT'])) {
1370
+            $seed .= $_SERVER['HTTP_ACCEPT'];
1371
+        }
1372
+        if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
1373
+            $seed .= $_SERVER['HTTP_ACCEPT_ENCODING'];
1374
+        }
1375
+        if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
1376
+            $seed .= $_SERVER['HTTP_ACCEPT_LANGUAGE'];
1377
+        }
1378
+        if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
1379
+            $seed .= $_SERVER['HTTP_ACCEPT_CHARSET'];
1380
+        }
1381
+        $seed .= rand();
1382
+        $seed .= uniqid('', true);
1383
+        $seed .= microtime();
1384
+        return $seed;
1385
+    }
1386
+
1387
+    /**
1388
+     * Encrypts a string using MD5 and returns it's value as a binary string.
1389
+     * @param $str (string) input string
1390
+     * @return String MD5 encrypted binary string
1391
+     * @since 2.0.000 (2008-01-02)
1392
+     * @public static
1393
+     */
1394
+    public static function _md5_16($str) {
1395
+        return pack('H*', md5($str));
1396
+    }
1397
+
1398
+    /**
1399
+     * Returns the input text exrypted using AES algorithm and the specified key.
1400
+     * This method requires mcrypt.
1401
+     * @param $key (string) encryption key
1402
+     * @param $text (String) input text to be encrypted
1403
+     * @return String encrypted text
1404
+     * @author Nicola Asuni
1405
+     * @since 5.0.005 (2010-05-11)
1406
+     * @public static
1407
+     */
1408
+    public static function _AES($key, $text) {
1409
+        // padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0)
1410
+        $padding = 16 - (strlen($text) % 16);
1411
+        $text .= str_repeat(chr($padding), $padding);
1412
+        $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
1413
+        $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
1414
+        $text = $iv.$text;
1415
+        return $text;
1416
+    }
1417
+
1418
+    /**
1419
+     * Returns the input text encrypted using RC4 algorithm and the specified key.
1420
+     * RC4 is the standard encryption algorithm used in PDF format
1421
+     * @param $key (string) Encryption key.
1422
+     * @param $text (String) Input text to be encrypted.
1423
+     * @param $last_enc_key (String) Reference to last RC4 key encrypted.
1424
+     * @param $last_enc_key_c (String) Reference to last RC4 computed key.
1425
+     * @return String encrypted text
1426
+     * @since 2.0.000 (2008-01-02)
1427
+     * @author Klemen Vodopivec, Nicola Asuni
1428
+     * @public static
1429
+     */
1430
+    public static function _RC4($key, $text, &$last_enc_key, &$last_enc_key_c) {
1431
+        if (function_exists('mcrypt_encrypt') AND ($out = @mcrypt_encrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, ''))) {
1432
+            // try to use mcrypt function if exist
1433
+            return $out;
1434
+        }
1435
+        if ($last_enc_key != $key) {
1436
+            $k = str_repeat($key, ((256 / strlen($key)) + 1));
1437
+            $rc4 = range(0, 255);
1438
+            $j = 0;
1439
+            for ($i = 0; $i < 256; ++$i) {
1440
+                $t = $rc4[$i];
1441
+                $j = ($j + $t + ord($k[$i])) % 256;
1442
+                $rc4[$i] = $rc4[$j];
1443
+                $rc4[$j] = $t;
1444
+            }
1445
+            $last_enc_key = $key;
1446
+            $last_enc_key_c = $rc4;
1447
+        } else {
1448
+            $rc4 = $last_enc_key_c;
1449
+        }
1450
+        $len = strlen($text);
1451
+        $a = 0;
1452
+        $b = 0;
1453
+        $out = '';
1454
+        for ($i = 0; $i < $len; ++$i) {
1455
+            $a = ($a + 1) % 256;
1456
+            $t = $rc4[$a];
1457
+            $b = ($b + $t) % 256;
1458
+            $rc4[$a] = $rc4[$b];
1459
+            $rc4[$b] = $t;
1460
+            $k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
1461
+            $out .= chr(ord($text[$i]) ^ $k);
1462
+        }
1463
+        return $out;
1464
+    }
1465
+
1466
+    /**
1467
+     * Return the premission code used on encryption (P value).
1468
+     * @param $permissions (Array) the set of permissions (specify the ones you want to block).
1469
+     * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
1470
+     * @since 5.0.005 (2010-05-12)
1471
+     * @author Nicola Asuni
1472
+     * @public static
1473
+     */
1474
+    public static function getUserPermissionCode($permissions, $mode=0) {
1475
+        $options = array(
1476
+            'owner' => 2, // bit 2 -- inverted logic: cleared by default
1477
+            'print' => 4, // bit 3
1478
+            'modify' => 8, // bit 4
1479
+            'copy' => 16, // bit 5
1480
+            'annot-forms' => 32, // bit 6
1481
+            'fill-forms' => 256, // bit 9
1482
+            'extract' => 512, // bit 10
1483
+            'assemble' => 1024,// bit 11
1484
+            'print-high' => 2048 // bit 12
1485
+            );
1486
+        $protection = 2147422012; // 32 bit: (01111111 11111111 00001111 00111100)
1487
+        foreach ($permissions as $permission) {
1488
+            if (isset($options[$permission])) {
1489
+                if (($mode > 0) OR ($options[$permission] <= 32)) {
1490
+                    // set only valid permissions
1491
+                    if ($options[$permission] == 2) {
1492
+                        // the logic for bit 2 is inverted (cleared by default)
1493
+                        $protection += $options[$permission];
1494
+                    } else {
1495
+                        $protection -= $options[$permission];
1496
+                    }
1497
+                }
1498
+            }
1499
+        }
1500
+        return $protection;
1501
+    }
1502
+
1503
+    /**
1504
+     * Convert hexadecimal string to string
1505
+     * @param $bs (string) byte-string to convert
1506
+     * @return String
1507
+     * @since 5.0.005 (2010-05-12)
1508
+     * @author Nicola Asuni
1509
+     * @public static
1510
+     */
1511
+    public static function convertHexStringToString($bs) {
1512
+        $string = ''; // string to be returned
1513
+        $bslength = strlen($bs);
1514
+        if (($bslength % 2) != 0) {
1515
+            // padding
1516
+            $bs .= '0';
1517
+            ++$bslength;
1518
+        }
1519
+        for ($i = 0; $i < $bslength; $i += 2) {
1520
+            $string .= chr(hexdec($bs[$i].$bs[($i + 1)]));
1521
+        }
1522
+        return $string;
1523
+    }
1524
+
1525
+    /**
1526
+     * Convert string to hexadecimal string (byte string)
1527
+     * @param $s (string) string to convert
1528
+     * @return byte string
1529
+     * @since 5.0.010 (2010-05-17)
1530
+     * @author Nicola Asuni
1531
+     * @public static
1532
+     */
1533
+    public static function convertStringToHexString($s) {
1534
+        $bs = '';
1535
+        $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY);
1536
+        foreach ($chars as $c) {
1537
+            $bs .= sprintf('%02s', dechex(ord($c)));
1538
+        }
1539
+        return $bs;
1540
+    }
1541
+
1542
+    /**
1543
+     * Convert encryption P value to a string of bytes, low-order byte first.
1544
+     * @param $protection (string) 32bit encryption permission value (P value)
1545
+     * @return String
1546
+     * @since 5.0.005 (2010-05-12)
1547
+     * @author Nicola Asuni
1548
+     * @public static
1549
+     */
1550
+    public static function getEncPermissionsString($protection) {
1551
+        $binprot = sprintf('%032b', $protection);
1552
+        $str = chr(bindec(substr($binprot, 24, 8)));
1553
+        $str .= chr(bindec(substr($binprot, 16, 8)));
1554
+        $str .= chr(bindec(substr($binprot, 8, 8)));
1555
+        $str .= chr(bindec(substr($binprot, 0, 8)));
1556
+        return $str;
1557
+    }
1558
+
1559
+    /**
1560
+     * Encode a name object.
1561
+     * @param $name (string) Name object to encode.
1562
+     * @return (string) Encoded name object.
1563
+     * @author Nicola Asuni
1564
+     * @since 5.9.097 (2011-06-23)
1565
+     * @public static
1566
+     */
1567
+    public static function encodeNameObject($name) {
1568
+        $escname = '';
1569
+        $length = strlen($name);
1570
+        for ($i = 0; $i < $length; ++$i) {
1571
+            $chr = $name[$i];
1572
+            if (preg_match('/[0-9a-zA-Z]/', $chr) == 1) {
1573
+                $escname .= $chr;
1574
+            } else {
1575
+                $escname .= sprintf('#%02X', ord($chr));
1576
+            }
1577
+        }
1578
+        return $escname;
1579
+    }
1580
+
1581
+    /**
1582
+     * Convert JavaScript form fields properties array to Annotation Properties array.
1583
+     * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
1584
+     * @param $spot_colors (array) Reference to spot colors array.
1585
+     * @param $rtl (boolean) True if in Right-To-Left text direction mode, false otherwise.
1586
+     * @return array of annotation properties
1587
+     * @author Nicola Asuni
1588
+     * @since 4.8.000 (2009-09-06)
1589
+     * @public static
1590
+     */
1591
+    public static function getAnnotOptFromJSProp($prop, &$spot_colors, $rtl=false) {
1592
+        if (isset($prop['aopt']) AND is_array($prop['aopt'])) {
1593
+            // the annotation options area lready defined
1594
+            return $prop['aopt'];
1595
+        }
1596
+        $opt = array(); // value to be returned
1597
+        // alignment: Controls how the text is laid out within the text field.
1598
+        if (isset($prop['alignment'])) {
1599
+            switch ($prop['alignment']) {
1600
+                case 'left': {
1601
+                    $opt['q'] = 0;
1602
+                    break;
1603
+                }
1604
+                case 'center': {
1605
+                    $opt['q'] = 1;
1606
+                    break;
1607
+                }
1608
+                case 'right': {
1609
+                    $opt['q'] = 2;
1610
+                    break;
1611
+                }
1612
+                default: {
1613
+                    $opt['q'] = ($rtl)?2:0;
1614
+                    break;
1615
+                }
1616
+            }
1617
+        }
1618
+        // lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle.
1619
+        if (isset($prop['lineWidth'])) {
1620
+            $linewidth = intval($prop['lineWidth']);
1621
+        } else {
1622
+            $linewidth = 1;
1623
+        }
1624
+        // borderStyle: The border style for a field.
1625
+        if (isset($prop['borderStyle'])) {
1626
+            switch ($prop['borderStyle']) {
1627
+                case 'border.d':
1628
+                case 'dashed': {
1629
+                    $opt['border'] = array(0, 0, $linewidth, array(3, 2));
1630
+                    $opt['bs'] = array('w'=>$linewidth, 's'=>'D', 'd'=>array(3, 2));
1631
+                    break;
1632
+                }
1633
+                case 'border.b':
1634
+                case 'beveled': {
1635
+                    $opt['border'] = array(0, 0, $linewidth);
1636
+                    $opt['bs'] = array('w'=>$linewidth, 's'=>'B');
1637
+                    break;
1638
+                }
1639
+                case 'border.i':
1640
+                case 'inset': {
1641
+                    $opt['border'] = array(0, 0, $linewidth);
1642
+                    $opt['bs'] = array('w'=>$linewidth, 's'=>'I');
1643
+                    break;
1644
+                }
1645
+                case 'border.u':
1646
+                case 'underline': {
1647
+                    $opt['border'] = array(0, 0, $linewidth);
1648
+                    $opt['bs'] = array('w'=>$linewidth, 's'=>'U');
1649
+                    break;
1650
+                }
1651
+                case 'border.s':
1652
+                case 'solid': {
1653
+                    $opt['border'] = array(0, 0, $linewidth);
1654
+                    $opt['bs'] = array('w'=>$linewidth, 's'=>'S');
1655
+                    break;
1656
+                }
1657
+                default: {
1658
+                    break;
1659
+                }
1660
+            }
1661
+        }
1662
+        if (isset($prop['border']) AND is_array($prop['border'])) {
1663
+            $opt['border'] = $prop['border'];
1664
+        }
1665
+        if (!isset($opt['mk'])) {
1666
+            $opt['mk'] = array();
1667
+        }
1668
+        if (!isset($opt['mk']['if'])) {
1669
+            $opt['mk']['if'] = array();
1670
+        }
1671
+        $opt['mk']['if']['a'] = array(0.5, 0.5);
1672
+        // buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon.
1673
+        if (isset($prop['buttonAlignX'])) {
1674
+            $opt['mk']['if']['a'][0] = $prop['buttonAlignX'];
1675
+        }
1676
+        // buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon.
1677
+        if (isset($prop['buttonAlignY'])) {
1678
+            $opt['mk']['if']['a'][1] = $prop['buttonAlignY'];
1679
+        }
1680
+        // buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field.
1681
+        if (isset($prop['buttonFitBounds']) AND ($prop['buttonFitBounds'] == 'true')) {
1682
+            $opt['mk']['if']['fb'] = true;
1683
+        }
1684
+        // buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face.
1685
+        if (isset($prop['buttonScaleHow'])) {
1686
+            switch ($prop['buttonScaleHow']) {
1687
+                case 'scaleHow.proportional': {
1688
+                    $opt['mk']['if']['s'] = 'P';
1689
+                    break;
1690
+                }
1691
+                case 'scaleHow.anamorphic': {
1692
+                    $opt['mk']['if']['s'] = 'A';
1693
+                    break;
1694
+                }
1695
+            }
1696
+        }
1697
+        // buttonScaleWhen: Controls when an icon is scaled to fit inside the button face.
1698
+        if (isset($prop['buttonScaleWhen'])) {
1699
+            switch ($prop['buttonScaleWhen']) {
1700
+                case 'scaleWhen.always': {
1701
+                    $opt['mk']['if']['sw'] = 'A';
1702
+                    break;
1703
+                }
1704
+                case 'scaleWhen.never': {
1705
+                    $opt['mk']['if']['sw'] = 'N';
1706
+                    break;
1707
+                }
1708
+                case 'scaleWhen.tooBig': {
1709
+                    $opt['mk']['if']['sw'] = 'B';
1710
+                    break;
1711
+                }
1712
+                case 'scaleWhen.tooSmall': {
1713
+                    $opt['mk']['if']['sw'] = 'S';
1714
+                    break;
1715
+                }
1716
+            }
1717
+        }
1718
+        // buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face.
1719
+        if (isset($prop['buttonPosition'])) {
1720
+            switch ($prop['buttonPosition']) {
1721
+                case 0:
1722
+                case 'position.textOnly': {
1723
+                    $opt['mk']['tp'] = 0;
1724
+                    break;
1725
+                }
1726
+                case 1:
1727
+                case 'position.iconOnly': {
1728
+                    $opt['mk']['tp'] = 1;
1729
+                    break;
1730
+                }
1731
+                case 2:
1732
+                case 'position.iconTextV': {
1733
+                    $opt['mk']['tp'] = 2;
1734
+                    break;
1735
+                }
1736
+                case 3:
1737
+                case 'position.textIconV': {
1738
+                    $opt['mk']['tp'] = 3;
1739
+                    break;
1740
+                }
1741
+                case 4:
1742
+                case 'position.iconTextH': {
1743
+                    $opt['mk']['tp'] = 4;
1744
+                    break;
1745
+                }
1746
+                case 5:
1747
+                case 'position.textIconH': {
1748
+                    $opt['mk']['tp'] = 5;
1749
+                    break;
1750
+                }
1751
+                case 6:
1752
+                case 'position.overlay': {
1753
+                    $opt['mk']['tp'] = 6;
1754
+                    break;
1755
+                }
1756
+            }
1757
+        }
1758
+        // fillColor: Specifies the background color for a field.
1759
+        if (isset($prop['fillColor'])) {
1760
+            if (is_array($prop['fillColor'])) {
1761
+                $opt['mk']['bg'] = $prop['fillColor'];
1762
+            } else {
1763
+                $opt['mk']['bg'] = TCPDF_COLORS::convertHTMLColorToDec($prop['fillColor'], $spot_colors);
1764
+            }
1765
+        }
1766
+        // 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.
1767
+        if (isset($prop['strokeColor'])) {
1768
+            if (is_array($prop['strokeColor'])) {
1769
+                $opt['mk']['bc'] = $prop['strokeColor'];
1770
+            } else {
1771
+                $opt['mk']['bc'] = TCPDF_COLORS::convertHTMLColorToDec($prop['strokeColor'], $spot_colors);
1772
+            }
1773
+        }
1774
+        // rotation: The rotation of a widget in counterclockwise increments.
1775
+        if (isset($prop['rotation'])) {
1776
+            $opt['mk']['r'] = $prop['rotation'];
1777
+        }
1778
+        // charLimit: Limits the number of characters that a user can type into a text field.
1779
+        if (isset($prop['charLimit'])) {
1780
+            $opt['maxlen'] = intval($prop['charLimit']);
1781
+        }
1782
+        if (!isset($ff)) {
1783
+            $ff = 0; // default value
1784
+        }
1785
+        // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
1786
+        if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
1787
+            $ff += 1 << 0;
1788
+        }
1789
+        // required: Specifies whether a field requires a value.
1790
+        if (isset($prop['required']) AND ($prop['required'] == 'true')) {
1791
+            $ff += 1 << 1;
1792
+        }
1793
+        // multiline: Controls how text is wrapped within the field.
1794
+        if (isset($prop['multiline']) AND ($prop['multiline'] == 'true')) {
1795
+            $ff += 1 << 12;
1796
+        }
1797
+        // password: Specifies whether the field should display asterisks when data is entered in the field.
1798
+        if (isset($prop['password']) AND ($prop['password'] == 'true')) {
1799
+            $ff += 1 << 13;
1800
+        }
1801
+        // NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect.
1802
+        if (isset($prop['NoToggleToOff']) AND ($prop['NoToggleToOff'] == 'true')) {
1803
+            $ff += 1 << 14;
1804
+        }
1805
+        // Radio: If set, the field is a set of radio buttons.
1806
+        if (isset($prop['Radio']) AND ($prop['Radio'] == 'true')) {
1807
+            $ff += 1 << 15;
1808
+        }
1809
+        // Pushbutton: If set, the field is a pushbutton that does not retain a permanent value.
1810
+        if (isset($prop['Pushbutton']) AND ($prop['Pushbutton'] == 'true')) {
1811
+            $ff += 1 << 16;
1812
+        }
1813
+        // Combo: If set, the field is a combo box; if clear, the field is a list box.
1814
+        if (isset($prop['Combo']) AND ($prop['Combo'] == 'true')) {
1815
+            $ff += 1 << 17;
1816
+        }
1817
+        // editable: Controls whether a combo box is editable.
1818
+        if (isset($prop['editable']) AND ($prop['editable'] == 'true')) {
1819
+            $ff += 1 << 18;
1820
+        }
1821
+        // Sort: If set, the field's option items shall be sorted alphabetically.
1822
+        if (isset($prop['Sort']) AND ($prop['Sort'] == 'true')) {
1823
+            $ff += 1 << 19;
1824
+        }
1825
+        // fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection).
1826
+        if (isset($prop['fileSelect']) AND ($prop['fileSelect'] == 'true')) {
1827
+            $ff += 1 << 20;
1828
+        }
1829
+        // multipleSelection: If true, indicates that a list box allows a multiple selection of items.
1830
+        if (isset($prop['multipleSelection']) AND ($prop['multipleSelection'] == 'true')) {
1831
+            $ff += 1 << 21;
1832
+        }
1833
+        // doNotSpellCheck: If true, spell checking is not performed on this editable text field.
1834
+        if (isset($prop['doNotSpellCheck']) AND ($prop['doNotSpellCheck'] == 'true')) {
1835
+            $ff += 1 << 22;
1836
+        }
1837
+        // doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field.
1838
+        if (isset($prop['doNotScroll']) AND ($prop['doNotScroll'] == 'true')) {
1839
+            $ff += 1 << 23;
1840
+        }
1841
+        // 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.
1842
+        if (isset($prop['comb']) AND ($prop['comb'] == 'true')) {
1843
+            $ff += 1 << 24;
1844
+        }
1845
+        // 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.
1846
+        if (isset($prop['radiosInUnison']) AND ($prop['radiosInUnison'] == 'true')) {
1847
+            $ff += 1 << 25;
1848
+        }
1849
+        // richText: If true, the field allows rich text formatting.
1850
+        if (isset($prop['richText']) AND ($prop['richText'] == 'true')) {
1851
+            $ff += 1 << 25;
1852
+        }
1853
+        // commitOnSelChange: Controls whether a field value is committed after a selection change.
1854
+        if (isset($prop['commitOnSelChange']) AND ($prop['commitOnSelChange'] == 'true')) {
1855
+            $ff += 1 << 26;
1856
+        }
1857
+        $opt['ff'] = $ff;
1858
+        // defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset.
1859
+        if (isset($prop['defaultValue'])) {
1860
+            $opt['dv'] = $prop['defaultValue'];
1861
+        }
1862
+        $f = 4; // default value for annotation flags
1863
+        // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
1864
+        if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
1865
+            $f += 1 << 6;
1866
+        }
1867
+        // display: Controls whether the field is hidden or visible on screen and in print.
1868
+        if (isset($prop['display'])) {
1869
+            if ($prop['display'] == 'display.visible') {
1870
+                //
1871
+            } elseif ($prop['display'] == 'display.hidden') {
1872
+                $f += 1 << 1;
1873
+            } elseif ($prop['display'] == 'display.noPrint') {
1874
+                $f -= 1 << 2;
1875
+            } elseif ($prop['display'] == 'display.noView') {
1876
+                $f += 1 << 5;
1877
+            }
1878
+        }
1879
+        $opt['f'] = $f;
1880
+        // currentValueIndices: Reads and writes single or multiple values of a list box or combo box.
1881
+        if (isset($prop['currentValueIndices']) AND is_array($prop['currentValueIndices'])) {
1882
+            $opt['i'] = $prop['currentValueIndices'];
1883
+        }
1884
+        // value: The value of the field data that the user has entered.
1885
+        if (isset($prop['value'])) {
1886
+            if (is_array($prop['value'])) {
1887
+                $opt['opt'] = array();
1888
+                foreach ($prop['value'] AS $key => $optval) {
1889
+                    // exportValues: An array of strings representing the export values for the field.
1890
+                    if (isset($prop['exportValues'][$key])) {
1891
+                        $opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]);
1892
+                    } else {
1893
+                        $opt['opt'][$key] = $prop['value'][$key];
1894
+                    }
1895
+                }
1896
+            } else {
1897
+                $opt['v'] = $prop['value'];
1898
+            }
1899
+        }
1900
+        // richValue: This property specifies the text contents and formatting of a rich text field.
1901
+        if (isset($prop['richValue'])) {
1902
+            $opt['rv'] = $prop['richValue'];
1903
+        }
1904
+        // submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded).
1905
+        if (isset($prop['submitName'])) {
1906
+            $opt['tm'] = $prop['submitName'];
1907
+        }
1908
+        // name: Fully qualified field name.
1909
+        if (isset($prop['name'])) {
1910
+            $opt['t'] = $prop['name'];
1911
+        }
1912
+        // userName: The user name (short description string) of the field.
1913
+        if (isset($prop['userName'])) {
1914
+            $opt['tu'] = $prop['userName'];
1915
+        }
1916
+        // highlight: Defines how a button reacts when a user clicks it.
1917
+        if (isset($prop['highlight'])) {
1918
+            switch ($prop['highlight']) {
1919
+                case 'none':
1920
+                case 'highlight.n': {
1921
+                    $opt['h'] = 'N';
1922
+                    break;
1923
+                }
1924
+                case 'invert':
1925
+                case 'highlight.i': {
1926
+                    $opt['h'] = 'i';
1927
+                    break;
1928
+                }
1929
+                case 'push':
1930
+                case 'highlight.p': {
1931
+                    $opt['h'] = 'P';
1932
+                    break;
1933
+                }
1934
+                case 'outline':
1935
+                case 'highlight.o': {
1936
+                    $opt['h'] = 'O';
1937
+                    break;
1938
+                }
1939
+            }
1940
+        }
1941
+        // Unsupported options:
1942
+        // - calcOrderIndex: Changes the calculation order of fields in the document.
1943
+        // - delay: Delays the redrawing of a field's appearance.
1944
+        // - defaultStyle: This property defines the default style attributes for the form field.
1945
+        // - style: Allows the user to set the glyph style of a check box or radio button.
1946
+        // - textColor, textFont, textSize
1947
+        return $opt;
1948
+    }
1949
+
1950
+    /**
1951
+     * Format the page numbers.
1952
+     * This method can be overriden for custom formats.
1953
+     * @param $num (int) page number
1954
+     * @since 4.2.005 (2008-11-06)
1955
+     * @public static
1956
+     */
1957
+    public static function formatPageNumber($num) {
1958
+        return number_format((float)$num, 0, '', '.');
1959
+    }
1960
+
1961
+    /**
1962
+     * Format the page numbers on the Table Of Content.
1963
+     * This method can be overriden for custom formats.
1964
+     * @param $num (int) page number
1965
+     * @since 4.5.001 (2009-01-04)
1966
+     * @see addTOC(), addHTMLTOC()
1967
+     * @public static
1968
+     */
1969
+    public static function formatTOCPageNumber($num) {
1970
+        return number_format((float)$num, 0, '', '.');
1971
+    }
1972
+
1973
+    /**
1974
+     * Extracts the CSS properties from a CSS string.
1975
+     * @param $cssdata (string) string containing CSS definitions.
1976
+     * @return An array where the keys are the CSS selectors and the values are the CSS properties.
1977
+     * @author Nicola Asuni
1978
+     * @since 5.1.000 (2010-05-25)
1979
+     * @public static
1980
+     */
1981
+    public static function extractCSSproperties($cssdata) {
1982
+        if (empty($cssdata)) {
1983
+            return array();
1984
+        }
1985
+        // remove comments
1986
+        $cssdata = preg_replace('/\/\*[^\*]*\*\//', '', $cssdata);
1987
+        // remove newlines and multiple spaces
1988
+        $cssdata = preg_replace('/[\s]+/', ' ', $cssdata);
1989
+        // remove some spaces
1990
+        $cssdata = preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata);
1991
+        // remove empty blocks
1992
+        $cssdata = preg_replace('/([^\}\{]+)\{\}/', '', $cssdata);
1993
+        // replace media type parenthesis
1994
+        $cssdata = preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1§', $cssdata);
1995
+        $cssdata = preg_replace('/\}\}/si', '}§', $cssdata);
1996
+        // trim string
1997
+        $cssdata = trim($cssdata);
1998
+        // find media blocks (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
1999
+        $cssblocks = array();
2000
+        $matches = array();
2001
+        if (preg_match_all('/@media[\s]+([^\§]*)§([^§]*)§/i', $cssdata, $matches) > 0) {
2002
+            foreach ($matches[1] as $key => $type) {
2003
+                $cssblocks[$type] = $matches[2][$key];
2004
+            }
2005
+            // remove media blocks
2006
+            $cssdata = preg_replace('/@media[\s]+([^\§]*)§([^§]*)§/i', '', $cssdata);
2007
+        }
2008
+        // keep 'all' and 'print' media, other media types are discarded
2009
+        if (isset($cssblocks['all']) AND !empty($cssblocks['all'])) {
2010
+            $cssdata .= $cssblocks['all'];
2011
+        }
2012
+        if (isset($cssblocks['print']) AND !empty($cssblocks['print'])) {
2013
+            $cssdata .= $cssblocks['print'];
2014
+        }
2015
+        // reset css blocks array
2016
+        $cssblocks = array();
2017
+        $matches = array();
2018
+        // explode css data string into array
2019
+        if (substr($cssdata, -1) == '}') {
2020
+            // remove last parethesis
2021
+            $cssdata = substr($cssdata, 0, -1);
2022
+        }
2023
+        $matches = explode('}', $cssdata);
2024
+        foreach ($matches as $key => $block) {
2025
+            // index 0 contains the CSS selector, index 1 contains CSS properties
2026
+            $cssblocks[$key] = explode('{', $block);
2027
+            if (!isset($cssblocks[$key][1])) {
2028
+                // remove empty definitions
2029
+                unset($cssblocks[$key]);
2030
+            }
2031
+        }
2032
+        // split groups of selectors (comma-separated list of selectors)
2033
+        foreach ($cssblocks as $key => $block) {
2034
+            if (strpos($block[0], ',') > 0) {
2035
+                $selectors = explode(',', $block[0]);
2036
+                foreach ($selectors as $sel) {
2037
+                    $cssblocks[] = array(0 => trim($sel), 1 => $block[1]);
2038
+                }
2039
+                unset($cssblocks[$key]);
2040
+            }
2041
+        }
2042
+        // covert array to selector => properties
2043
+        $cssdata = array();
2044
+        foreach ($cssblocks as $block) {
2045
+            $selector = $block[0];
2046
+            // calculate selector's specificity
2047
+            $matches = array();
2048
+            $a = 0; // the declaration is not from is a 'style' attribute
2049
+            $b = intval(preg_match_all('/[\#]/', $selector, $matches)); // number of ID attributes
2050
+            $c = intval(preg_match_all('/[\[\.]/', $selector, $matches)); // number of other attributes
2051
+            $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
2052
+            $d = intval(preg_match_all('/[\>\+\~\s]{1}[a-zA-Z0-9]+/', ' '.$selector, $matches)); // number of element names
2053
+            $d += intval(preg_match_all('/[\:][\:]/', $selector, $matches)); // number of pseudo-elements
2054
+            $specificity = $a.$b.$c.$d;
2055
+            // add specificity to the beginning of the selector
2056
+            $cssdata[$specificity.' '.$selector] = $block[1];
2057
+        }
2058
+        // sort selectors alphabetically to account for specificity
2059
+        ksort($cssdata, SORT_STRING);
2060
+        // return array
2061
+        return $cssdata;
2062
+    }
2063
+
2064
+    /**
2065
+     * Cleanup HTML code (requires HTML Tidy library).
2066
+     * @param $html (string) htmlcode to fix
2067
+     * @param $default_css (string) CSS commands to add
2068
+     * @param $tagvs (array) parameters for setHtmlVSpace method
2069
+     * @param $tidy_options (array) options for tidy_parse_string function
2070
+     * @param $tagvspaces (array) Array of vertical spaces for tags.
2071
+     * @return string XHTML code cleaned up
2072
+     * @author Nicola Asuni
2073
+     * @since 5.9.017 (2010-11-16)
2074
+     * @see setHtmlVSpace()
2075
+     * @public static
2076
+     */
2077
+    public static function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='', &$tagvspaces) {
2078
+        // configure parameters for HTML Tidy
2079
+        if ($tidy_options === '') {
2080
+            $tidy_options = array (
2081
+                'clean' => 1,
2082
+                'drop-empty-paras' => 0,
2083
+                'drop-proprietary-attributes' => 1,
2084
+                'fix-backslash' => 1,
2085
+                'hide-comments' => 1,
2086
+                'join-styles' => 1,
2087
+                'lower-literals' => 1,
2088
+                'merge-divs' => 1,
2089
+                'merge-spans' => 1,
2090
+                'output-xhtml' => 1,
2091
+                'word-2000' => 1,
2092
+                'wrap' => 0,
2093
+                'output-bom' => 0,
2094
+                //'char-encoding' => 'utf8',
2095
+                //'input-encoding' => 'utf8',
2096
+                //'output-encoding' => 'utf8'
2097
+            );
2098
+        }
2099
+        // clean up the HTML code
2100
+        $tidy = tidy_parse_string($html, $tidy_options);
2101
+        // fix the HTML
2102
+        $tidy->cleanRepair();
2103
+        // get the CSS part
2104
+        $tidy_head = tidy_get_head($tidy);
2105
+        $css = $tidy_head->value;
2106
+        $css = preg_replace('/<style([^>]+)>/ims', '<style>', $css);
2107
+        $css = preg_replace('/<\/style>(.*)<style>/ims', "\n", $css);
2108
+        $css = str_replace('/*<![CDATA[*/', '', $css);
2109
+        $css = str_replace('/*]]>*/', '', $css);
2110
+        preg_match('/<style>(.*)<\/style>/ims', $css, $matches);
2111
+        if (isset($matches[1])) {
2112
+            $css = strtolower($matches[1]);
2113
+        } else {
2114
+            $css = '';
2115
+        }
2116
+        // include default css
2117
+        $css = '<style>'.$default_css.$css.'</style>';
2118
+        // get the body part
2119
+        $tidy_body = tidy_get_body($tidy);
2120
+        $html = $tidy_body->value;
2121
+        // fix some self-closing tags
2122
+        $html = str_replace('<br>', '<br />', $html);
2123
+        // remove some empty tag blocks
2124
+        $html = preg_replace('/<div([^\>]*)><\/div>/', '', $html);
2125
+        $html = preg_replace('/<p([^\>]*)><\/p>/', '', $html);
2126
+        if ($tagvs !== '') {
2127
+            // set vertical space for some XHTML tags
2128
+            $tagvspaces = $tagvs;
2129
+        }
2130
+        // return the cleaned XHTML code + CSS
2131
+        return $css.$html;
2132
+    }
2133
+
2134
+    /**
2135
+     * Returns true if the CSS selector is valid for the selected HTML tag
2136
+     * @param $dom (array) array of HTML tags and properties
2137
+     * @param $key (int) key of the current HTML tag
2138
+     * @param $selector (string) CSS selector string
2139
+     * @return true if the selector is valid, false otherwise
2140
+     * @since 5.1.000 (2010-05-25)
2141
+     * @public static
2142
+     */
2143
+    public static function isValidCSSSelectorForTag($dom, $key, $selector) {
2144
+        $valid = false; // value to be returned
2145
+        $tag = $dom[$key]['value'];
2146
+        $class = array();
2147
+        if (isset($dom[$key]['attribute']['class']) AND !empty($dom[$key]['attribute']['class'])) {
2148
+            $class = explode(' ', strtolower($dom[$key]['attribute']['class']));
2149
+        }
2150
+        $id = '';
2151
+        if (isset($dom[$key]['attribute']['id']) AND !empty($dom[$key]['attribute']['id'])) {
2152
+            $id = strtolower($dom[$key]['attribute']['id']);
2153
+        }
2154
+        $selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector);
2155
+        $matches = array();
2156
+        if (preg_match_all('/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si', $selector, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) > 0) {
2157
+            $parentop = array_pop($matches[1]);
2158
+            $operator = $parentop[0];
2159
+            $offset = $parentop[1];
2160
+            $lasttag = array_pop($matches[2]);
2161
+            $lasttag = strtolower(trim($lasttag[0]));
2162
+            if (($lasttag == '*') OR ($lasttag == $tag)) {
2163
+                // the last element on selector is our tag or 'any tag'
2164
+                $attrib = array_pop($matches[3]);
2165
+                $attrib = strtolower(trim($attrib[0]));
2166
+                if (!empty($attrib)) {
2167
+                    // check if matches class, id, attribute, pseudo-class or pseudo-element
2168
+                    switch ($attrib[0]) {
2169
+                        case '.': { // class
2170
+                            if (in_array(substr($attrib, 1), $class)) {
2171
+                                $valid = true;
2172
+                            }
2173
+                            break;
2174
+                        }
2175
+                        case '#': { // ID
2176
+                            if (substr($attrib, 1) == $id) {
2177
+                                $valid = true;
2178
+                            }
2179
+                            break;
2180
+                        }
2181
+                        case '[': { // attribute
2182
+                            $attrmatch = array();
2183
+                            if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) {
2184
+                                $att = strtolower($attrmatch[1]);
2185
+                                $val = $attrmatch[3];
2186
+                                if (isset($dom[$key]['attribute'][$att])) {
2187
+                                    switch ($attrmatch[2]) {
2188
+                                        case '=': {
2189
+                                            if ($dom[$key]['attribute'][$att] == $val) {
2190
+                                                $valid = true;
2191
+                                            }
2192
+                                            break;
2193
+                                        }
2194
+                                        case '~=': {
2195
+                                            if (in_array($val, explode(' ', $dom[$key]['attribute'][$att]))) {
2196
+                                                $valid = true;
2197
+                                            }
2198
+                                            break;
2199
+                                        }
2200
+                                        case '^=': {
2201
+                                            if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val))) {
2202
+                                                $valid = true;
2203
+                                            }
2204
+                                            break;
2205
+                                        }
2206
+                                        case '$=': {
2207
+                                            if ($val == substr($dom[$key]['attribute'][$att], -strlen($val))) {
2208
+                                                $valid = true;
2209
+                                            }
2210
+                                            break;
2211
+                                        }
2212
+                                        case '*=': {
2213
+                                            if (strpos($dom[$key]['attribute'][$att], $val) !== false) {
2214
+                                                $valid = true;
2215
+                                            }
2216
+                                            break;
2217
+                                        }
2218
+                                        case '|=': {
2219
+                                            if ($dom[$key]['attribute'][$att] == $val) {
2220
+                                                $valid = true;
2221
+                                            } elseif (preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) {
2222
+                                                $valid = true;
2223
+                                            }
2224
+                                            break;
2225
+                                        }
2226
+                                        default: {
2227
+                                            $valid = true;
2228
+                                        }
2229
+                                    }
2230
+                                }
2231
+                            }
2232
+                            break;
2233
+                        }
2234
+                        case ':': { // pseudo-class or pseudo-element
2235
+                            if ($attrib[1] == ':') { // pseudo-element
2236
+                                // pseudo-elements are not supported!
2237
+                                // (::first-line, ::first-letter, ::before, ::after)
2238
+                            } else { // pseudo-class
2239
+                                // pseudo-classes are not supported!
2240
+                                // (: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)
2241
+                            }
2242
+                            break;
2243
+                        }
2244
+                    } // end of switch
2245
+                } else {
2246
+                    $valid = true;
2247
+                }
2248
+                if ($valid AND ($offset > 0)) {
2249
+                    $valid = false;
2250
+                    // check remaining selector part
2251
+                    $selector = substr($selector, 0, $offset);
2252
+                    switch ($operator) {
2253
+                        case ' ': { // descendant of an element
2254
+                            while ($dom[$key]['parent'] > 0) {
2255
+                                if (self::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector)) {
2256
+                                    $valid = true;
2257
+                                    break;
2258
+                                } else {
2259
+                                    $key = $dom[$key]['parent'];
2260
+                                }
2261
+                            }
2262
+                            break;
2263
+                        }
2264
+                        case '>': { // child of an element
2265
+                            $valid = self::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector);
2266
+                            break;
2267
+                        }
2268
+                        case '+': { // immediately preceded by an element
2269
+                            for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
2270
+                                if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
2271
+                                    $valid = self::isValidCSSSelectorForTag($dom, $i, $selector);
2272
+                                    break;
2273
+                                }
2274
+                            }
2275
+                            break;
2276
+                        }
2277
+                        case '~': { // preceded by an element
2278
+                            for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
2279
+                                if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
2280
+                                    if (self::isValidCSSSelectorForTag($dom, $i, $selector)) {
2281
+                                        break;
2282
+                                    }
2283
+                                }
2284
+                            }
2285
+                            break;
2286
+                        }
2287
+                    }
2288
+                }
2289
+            }
2290
+        }
2291
+        return $valid;
2292
+    }
2293
+
2294
+    /**
2295
+     * Returns the styles array that apply for the selected HTML tag.
2296
+     * @param $dom (array) array of HTML tags and properties
2297
+     * @param $key (int) key of the current HTML tag
2298
+     * @param $css (array) array of CSS properties
2299
+     * @return array containing CSS properties
2300
+     * @since 5.1.000 (2010-05-25)
2301
+     * @public static
2302
+     */
2303
+    public static function getCSSdataArray($dom, $key, $css) {
2304
+        $cssarray = array(); // style to be returned
2305
+        // get parent CSS selectors
2306
+        $selectors = array();
2307
+        if (isset($dom[($dom[$key]['parent'])]['csssel'])) {
2308
+            $selectors = $dom[($dom[$key]['parent'])]['csssel'];
2309
+        }
2310
+        // get all styles that apply
2311
+        foreach($css as $selector => $style) {
2312
+            $pos = strpos($selector, ' ');
2313
+            // get specificity
2314
+            $specificity = substr($selector, 0, $pos);
2315
+            // remove specificity
2316
+            $selector = substr($selector, $pos);
2317
+            // check if this selector apply to current tag
2318
+            if (self::isValidCSSSelectorForTag($dom, $key, $selector)) {
2319
+                if (!in_array($selector, $selectors)) {
2320
+                    // add style if not already added on parent selector
2321
+                    $cssarray[] = array('k' => $selector, 's' => $specificity, 'c' => $style);
2322
+                    $selectors[] = $selector;
2323
+                }
2324
+            }
2325
+        }
2326
+        if (isset($dom[$key]['attribute']['style'])) {
2327
+            // attach inline style (latest properties have high priority)
2328
+            $cssarray[] = array('k' => '', 's' => '1000', 'c' => $dom[$key]['attribute']['style']);
2329
+        }
2330
+        // order the css array to account for specificity
2331
+        $cssordered = array();
2332
+        foreach ($cssarray as $key => $val) {
2333
+            $skey = sprintf('%04d', $key);
2334
+            $cssordered[$val['s'].'_'.$skey] = $val;
2335
+        }
2336
+        // sort selectors alphabetically to account for specificity
2337
+        ksort($cssordered, SORT_STRING);
2338
+        return array($selectors, $cssordered);
2339
+    }
2340
+
2341
+    /**
2342
+     * Compact CSS data array into single string.
2343
+     * @param $css (array) array of CSS properties
2344
+     * @return string containing merged CSS properties
2345
+     * @since 5.9.070 (2011-04-19)
2346
+     * @public static
2347
+     */
2348
+    public static function getTagStyleFromCSSarray($css) {
2349
+        $tagstyle = ''; // value to be returned
2350
+        foreach ($css as $style) {
2351
+            // split single css commands
2352
+            $csscmds = explode(';', $style['c']);
2353
+            foreach ($csscmds as $cmd) {
2354
+                if (!empty($cmd)) {
2355
+                    $pos = strpos($cmd, ':');
2356
+                    if ($pos !== false) {
2357
+                        $cmd = substr($cmd, 0, ($pos + 1));
2358
+                        if (strpos($tagstyle, $cmd) !== false) {
2359
+                            // remove duplicate commands (last commands have high priority)
2360
+                            $tagstyle = preg_replace('/'.$cmd.'[^;]+/i', '', $tagstyle);
2361
+                        }
2362
+                    }
2363
+                }
2364
+            }
2365
+            $tagstyle .= ';'.$style['c'];
2366
+        }
2367
+        // remove multiple semicolons
2368
+        $tagstyle = preg_replace('/[;]+/', ';', $tagstyle);
2369
+        return $tagstyle;
2370
+    }
2371
+
2372
+    /**
2373
+     * Returns the Roman representation of an integer number
2374
+     * @param $number (int) number to convert
2375
+     * @return string roman representation of the specified number
2376
+     * @since 4.4.004 (2008-12-10)
2377
+     * @public static
2378
+     */
2379
+    public static function intToRoman($number) {
2380
+        $roman = '';
2381
+        while ($number >= 1000) {
2382
+            $roman .= 'M';
2383
+            $number -= 1000;
2384
+        }
2385
+        while ($number >= 900) {
2386
+            $roman .= 'CM';
2387
+            $number -= 900;
2388
+        }
2389
+        while ($number >= 500) {
2390
+            $roman .= 'D';
2391
+            $number -= 500;
2392
+        }
2393
+        while ($number >= 400) {
2394
+            $roman .= 'CD';
2395
+            $number -= 400;
2396
+        }
2397
+        while ($number >= 100) {
2398
+            $roman .= 'C';
2399
+            $number -= 100;
2400
+        }
2401
+        while ($number >= 90) {
2402
+            $roman .= 'XC';
2403
+            $number -= 90;
2404
+        }
2405
+        while ($number >= 50) {
2406
+            $roman .= 'L';
2407
+            $number -= 50;
2408
+        }
2409
+        while ($number >= 40) {
2410
+            $roman .= 'XL';
2411
+            $number -= 40;
2412
+        }
2413
+        while ($number >= 10) {
2414
+            $roman .= 'X';
2415
+            $number -= 10;
2416
+        }
2417
+        while ($number >= 9) {
2418
+            $roman .= 'IX';
2419
+            $number -= 9;
2420
+        }
2421
+        while ($number >= 5) {
2422
+            $roman .= 'V';
2423
+            $number -= 5;
2424
+        }
2425
+        while ($number >= 4) {
2426
+            $roman .= 'IV';
2427
+            $number -= 4;
2428
+        }
2429
+        while ($number >= 1) {
2430
+            $roman .= 'I';
2431
+            --$number;
2432
+        }
2433
+        return $roman;
2434
+    }
2435
+
2436
+    /**
2437
+     * Find position of last occurrence of a substring in a string
2438
+     * @param $haystack (string) The string to search in.
2439
+     * @param $needle (string) substring to search.
2440
+     * @param $offset (int) May be specified to begin searching an arbitrary number of characters into the string.
2441
+     * @return Returns the position where the needle exists. Returns FALSE if the needle was not found.
2442
+     * @since 4.8.038 (2010-03-13)
2443
+     * @public static
2444
+     */
2445
+    public static function revstrpos($haystack, $needle, $offset = 0) {
2446
+        $length = strlen($haystack);
2447
+        $offset = ($offset > 0)?($length - $offset):abs($offset);
2448
+        $pos = strpos(strrev($haystack), strrev($needle), $offset);
2449
+        return ($pos === false)?false:($length - $pos - strlen($needle));
2450
+    }
2451
+
2452
+    /**
2453
+     * Serialize an array of parameters to be used with TCPDF tag in HTML code.
2454
+     * @param $pararray (array) parameters array
2455
+     * @return sting containing serialized data
2456
+     * @since 4.9.006 (2010-04-02)
2457
+     * @public static
2458
+     */
2459
+    public static function serializeTCPDFtagParameters($pararray) {
2460
+        return urlencode(serialize($pararray));
2461
+    }
2462
+
2463
+    /**
2464
+     * Returns an array of hyphenation patterns.
2465
+     * @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/
2466
+     * @return array of hyphenation patterns
2467
+     * @author Nicola Asuni
2468
+     * @since 4.9.012 (2010-04-12)
2469
+     * @public static
2470
+     */
2471
+    public static function getHyphenPatternsFromTEX($file) {
2472
+        // TEX patterns are available at:
2473
+        // http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
2474
+        $data = file_get_contents($file);
2475
+        $patterns = array();
2476
+        // remove comments
2477
+        $data = preg_replace('/\%[^\n]*/', '', $data);
2478
+        // extract the patterns part
2479
+        preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches);
2480
+        $data = trim(substr($matches[0], 10, -1));
2481
+        // extract each pattern
2482
+        $patterns_array = preg_split('/[\s]+/', $data);
2483
+        // create new language array of patterns
2484
+        $patterns = array();
2485
+        foreach($patterns_array as $val) {
2486
+            if (!TCPDF_STATIC::empty_string($val)) {
2487
+                $val = trim($val);
2488
+                $val = str_replace('\'', '\\\'', $val);
2489
+                $key = preg_replace('/[0-9]+/', '', $val);
2490
+                $patterns[$key] = $val;
2491
+            }
2492
+        }
2493
+        return $patterns;
2494
+    }
2495
+
2496
+    /**
2497
+     * Get the Path-Painting Operators.
2498
+     * @param $style (string) Style of rendering. Possible values are:
2499
+     * <ul>
2500
+     *   <li>S or D: Stroke the path.</li>
2501
+     *   <li>s or d: Close and stroke the path.</li>
2502
+     *   <li>f or F: Fill the path, using the nonzero winding number rule to determine the region to fill.</li>
2503
+     *   <li>f* or F*: Fill the path, using the even-odd rule to determine the region to fill.</li>
2504
+     *   <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>
2505
+     *   <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>
2506
+     *   <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>
2507
+     *   <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>
2508
+     *   <li>CNZ: Clipping mode using the even-odd rule to determine which regions lie inside the clipping path.</li>
2509
+     *   <li>CEO: Clipping mode using the nonzero winding number rule to determine which regions lie inside the clipping path</li>
2510
+     *   <li>n: End the path object without filling or stroking it.</li>
2511
+     * </ul>
2512
+     * @param $default (string) default style
2513
+     * @author Nicola Asuni
2514
+     * @since 5.0.000 (2010-04-30)
2515
+     * @public static
2516
+     */
2517
+    public static function getPathPaintOperator($style, $default='S') {
2518
+        $op = '';
2519
+        switch($style) {
2520
+            case 'S':
2521
+            case 'D': {
2522
+                $op = 'S';
2523
+                break;
2524
+            }
2525
+            case 's':
2526
+            case 'd': {
2527
+                $op = 's';
2528
+                break;
2529
+            }
2530
+            case 'f':
2531
+            case 'F': {
2532
+                $op = 'f';
2533
+                break;
2534
+            }
2535
+            case 'f*':
2536
+            case 'F*': {
2537
+                $op = 'f*';
2538
+                break;
2539
+            }
2540
+            case 'B':
2541
+            case 'FD':
2542
+            case 'DF': {
2543
+                $op = 'B';
2544
+                break;
2545
+            }
2546
+            case 'B*':
2547
+            case 'F*D':
2548
+            case 'DF*': {
2549
+                $op = 'B*';
2550
+                break;
2551
+            }
2552
+            case 'b':
2553
+            case 'fd':
2554
+            case 'df': {
2555
+                $op = 'b';
2556
+                break;
2557
+            }
2558
+            case 'b*':
2559
+            case 'f*d':
2560
+            case 'df*': {
2561
+                $op = 'b*';
2562
+                break;
2563
+            }
2564
+            case 'CNZ': {
2565
+                $op = 'W n';
2566
+                break;
2567
+            }
2568
+            case 'CEO': {
2569
+                $op = 'W* n';
2570
+                break;
2571
+            }
2572
+            case 'n': {
2573
+                $op = 'n';
2574
+                break;
2575
+            }
2576
+            default: {
2577
+                if (!empty($default)) {
2578
+                    $op = self::getPathPaintOperator($default, '');
2579
+                } else {
2580
+                    $op = '';
2581
+                }
2582
+            }
2583
+        }
2584
+        return $op;
2585
+    }
2586
+
2587
+    /**
2588
+     * Get the product of two SVG tranformation matrices
2589
+     * @param $ta (array) first SVG tranformation matrix
2590
+     * @param $tb (array) second SVG tranformation matrix
2591
+     * @return transformation array
2592
+     * @author Nicola Asuni
2593
+     * @since 5.0.000 (2010-05-02)
2594
+     * @public static
2595
+     */
2596
+    public static function getTransformationMatrixProduct($ta, $tb) {
2597
+        $tm = array();
2598
+        $tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]);
2599
+        $tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]);
2600
+        $tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]);
2601
+        $tm[3] = ($ta[1] * $tb[2]) + ($ta[3] * $tb[3]);
2602
+        $tm[4] = ($ta[0] * $tb[4]) + ($ta[2] * $tb[5]) + $ta[4];
2603
+        $tm[5] = ($ta[1] * $tb[4]) + ($ta[3] * $tb[5]) + $ta[5];
2604
+        return $tm;
2605
+    }
2606
+
2607
+    /**
2608
+     * Get the tranformation matrix from SVG transform attribute
2609
+     * @param $attribute (string) transformation
2610
+     * @return array of transformations
2611
+     * @author Nicola Asuni
2612
+     * @since 5.0.000 (2010-05-02)
2613
+     * @public static
2614
+     */
2615
+    public static function getSVGTransformMatrix($attribute) {
2616
+        // identity matrix
2617
+        $tm = array(1, 0, 0, 1, 0, 0);
2618
+        $transform = array();
2619
+        if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0) {
2620
+            foreach ($transform as $key => $data) {
2621
+                if (!empty($data[2])) {
2622
+                    $a = 1;
2623
+                    $b = 0;
2624
+                    $c = 0;
2625
+                    $d = 1;
2626
+                    $e = 0;
2627
+                    $f = 0;
2628
+                    $regs = array();
2629
+                    switch ($data[1]) {
2630
+                        case 'matrix': {
2631
+                            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)) {
2632
+                                $a = $regs[1];
2633
+                                $b = $regs[2];
2634
+                                $c = $regs[3];
2635
+                                $d = $regs[4];
2636
+                                $e = $regs[5];
2637
+                                $f = $regs[6];
2638
+                            }
2639
+                            break;
2640
+                        }
2641
+                        case 'translate': {
2642
+                            if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2643
+                                $e = $regs[1];
2644
+                                $f = $regs[2];
2645
+                            } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2646
+                                $e = $regs[1];
2647
+                            }
2648
+                            break;
2649
+                        }
2650
+                        case 'scale': {
2651
+                            if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2652
+                                $a = $regs[1];
2653
+                                $d = $regs[2];
2654
+                            } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2655
+                                $a = $regs[1];
2656
+                                $d = $a;
2657
+                            }
2658
+                            break;
2659
+                        }
2660
+                        case 'rotate': {
2661
+                            if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2662
+                                $ang = deg2rad($regs[1]);
2663
+                                $x = $regs[2];
2664
+                                $y = $regs[3];
2665
+                                $a = cos($ang);
2666
+                                $b = sin($ang);
2667
+                                $c = -$b;
2668
+                                $d = $a;
2669
+                                $e = ($x * (1 - $a)) - ($y * $c);
2670
+                                $f = ($y * (1 - $d)) - ($x * $b);
2671
+                            } elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
2672
+                                $ang = deg2rad($regs[1]);
2673
+                                $a = cos($ang);
2674
+                                $b = sin($ang);
2675
+                                $c = -$b;
2676
+                                $d = $a;
2677
+                                $e = 0;
2678
+                                $f = 0;
2679
+                            }
2680
+                            break;
2681
+                        }
2682
+                        case 'skewX': {
2683
+                            if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
2684
+                                $c = tan(deg2rad($regs[1]));
2685
+                            }
2686
+                            break;
2687
+                        }
2688
+                        case 'skewY': {
2689
+                            if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
2690
+                                $b = tan(deg2rad($regs[1]));
2691
+                            }
2692
+                            break;
2693
+                        }
2694
+                    }
2695
+                    $tm = self::getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f));
2696
+                }
2697
+            }
2698
+        }
2699
+        return $tm;
2700
+    }
2701
+
2702
+    /**
2703
+     * Returns the angle in radiants between two vectors
2704
+     * @param $x1 (int) X coordinate of first vector point
2705
+     * @param $y1 (int) Y coordinate of first vector point
2706
+     * @param $x2 (int) X coordinate of second vector point
2707
+     * @param $y2 (int) Y coordinate of second vector point
2708
+     * @author Nicola Asuni
2709
+     * @since 5.0.000 (2010-05-04)
2710
+     * @public static
2711
+     */
2712
+    public static function getVectorsAngle($x1, $y1, $x2, $y2) {
2713
+        $dprod = ($x1 * $x2) + ($y1 * $y2);
2714
+        $dist1 = sqrt(($x1 * $x1) + ($y1 * $y1));
2715
+        $dist2 = sqrt(($x2 * $x2) + ($y2 * $y2));
2716
+        $angle = acos($dprod / ($dist1 * $dist2));
2717
+        if (is_nan($angle)) {
2718
+            $angle = M_PI;
2719
+        }
2720
+        if ((($x1 * $y2) - ($x2 * $y1)) < 0) {
2721
+            $angle *= -1;
2722
+        }
2723
+        return $angle;
2724
+    }
2725
+
2726
+    /**
2727
+     * Split string by a regular expression.
2728
+     * This is a wrapper for the preg_split function to avoid the bug: https://bugs.php.net/bug.php?id=45850
2729
+     * @param $pattern (string) The regular expression pattern to search for without the modifiers, as a string.
2730
+     * @param $modifiers (string) The modifiers part of the pattern,
2731
+     * @param $subject (string) The input string.
2732
+     * @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.
2733
+     * @param $flags (int) The flags as specified on the preg_split PHP function.
2734
+     * @return Returns an array containing substrings of subject split along boundaries matched by pattern.modifier
2735
+     * @author Nicola Asuni
2736
+     * @since 6.0.023
2737
+     * @public static
2738
+     */
2739
+    public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $flags=NULL) {
2740
+        // the bug only happens on PHP 5.2 when using the u modifier
2741
+        if ((strpos($modifiers, 'u') === FALSE) OR (count(preg_split('//u', "\n\t", -1, PREG_SPLIT_NO_EMPTY)) == 2)) {
2742
+            return preg_split($pattern.$modifiers, $subject, $limit, $flags);
2743
+        }
2744
+        // preg_split is bugged - try alternative solution
2745
+        $ret = array();
2746
+        while (($nl = strpos($subject, "\n")) !== FALSE) {
2747
+            $ret = array_merge($ret, preg_split($pattern.$modifiers, substr($subject, 0, $nl), $limit, $flags));
2748
+            $ret[] = "\n";
2749
+            $subject = substr($subject, ($nl + 1));
2750
+        }
2751
+        if (strlen($subject) > 0) {
2752
+            $ret = array_merge($ret, preg_split($pattern.$modifiers, $subject, $limit, $flags));
2753
+        }
2754
+        return $ret;
2755
+    }
2756
+
2757
+    /**
2758
+     * Reads entire file into a string.
2759
+     * The file can be also an URL.
2760
+     * @param $file (string) Name of the file or URL to read.
2761
+     * @return The function returns the read data or FALSE on failure. 
2762
+     * @author Nicola Asuni
2763
+     * @since 6.0.025
2764
+     * @public static
2765
+     */
2766
+    public static function fileGetContents($file) {
2767
+        //$file = html_entity_decode($file);
2768
+        // array of possible alternative paths/URLs
2769
+        $alt = array($file);
2770
+        // replace URL relative path with full real server path
2771
+        if ((strlen($file) > 1)
2772
+            AND ($file[0] == '/')
2773
+            AND ($file[1] != '/')
2774
+            AND !empty($_SERVER['DOCUMENT_ROOT'])
2775
+            AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
2776
+            $findroot = strpos($file, $_SERVER['DOCUMENT_ROOT']);
2777
+            if (($findroot === false) OR ($findroot > 1)) {
2778
+                if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
2779
+                    $tmp = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$file;
2780
+                } else {
2781
+                    $tmp = $_SERVER['DOCUMENT_ROOT'].$file;
2782
+                }
2783
+                $alt[] = htmlspecialchars_decode(urldecode($tmp));
2784
+            }
2785
+        }
2786
+        // URL mode
2787
+        $url = $file;
2788
+        // check for missing protocol
2789
+        if (preg_match('%^/{2}%', $url)) {
2790
+            if (preg_match('%^([^:]+:)//%i', K_PATH_URL, $match)) {
2791
+                $url = $match[1].str_replace(' ', '%20', $url);
2792
+                $alt[] = $url;
2793
+            }
2794
+        }
2795
+        $urldata = @parse_url($url);
2796
+        if (!isset($urldata['query']) OR (strlen($urldata['query']) <= 0)) {
2797
+            if (strpos($url, K_PATH_URL) === 0) {
2798
+                // convert URL to full server path
2799
+                $tmp = str_replace(K_PATH_URL, K_PATH_MAIN, $url);
2800
+                $tmp = htmlspecialchars_decode(urldecode($tmp));
2801
+                $alt[] = $tmp;
2802
+            }
2803
+        }
2804
+        if (isset($_SERVER['SCRIPT_URI'])) {
2805
+            $urldata = @parse_url($_SERVER['SCRIPT_URI']);
2806
+            $alt[] = $urldata['scheme'].'://'.$urldata['host'].(($file[0] == '/') ? '' : '/').$file;
2807
+        }
2808
+        foreach ($alt as $f) {
2809
+            $ret = @file_get_contents($f);
2810
+            if (($ret === FALSE)
2811
+                AND !ini_get('allow_url_fopen')
2812
+                AND function_exists('curl_init')
2813
+                AND preg_match('%^(https?|ftp)://%', $f)) {
2814
+                // try to get remote file data using cURL
2815
+                $cs = curl_init(); // curl session
2816
+                curl_setopt($cs, CURLOPT_URL, $f);
2817
+                curl_setopt($cs, CURLOPT_BINARYTRANSFER, true);
2818
+                curl_setopt($cs, CURLOPT_FAILONERROR, true);
2819
+                curl_setopt($cs, CURLOPT_RETURNTRANSFER, true);
2820
+                if ((ini_get('open_basedir') == '') AND (!ini_get('safe_mode'))) {
2821
+                    curl_setopt($cs, CURLOPT_FOLLOWLOCATION, true);
2822
+                }
2823
+                curl_setopt($cs, CURLOPT_CONNECTTIMEOUT, 5);
2824
+                curl_setopt($cs, CURLOPT_TIMEOUT, 30);
2825
+                curl_setopt($cs, CURLOPT_SSL_VERIFYPEER, false);
2826
+                curl_setopt($cs, CURLOPT_SSL_VERIFYHOST, false);
2827
+                curl_setopt($cs, CURLOPT_USERAGENT, 'TCPDF');
2828
+                $ret = curl_exec($cs);
2829
+                curl_close($cs);
2830
+            }
2831
+            if ($ret !== FALSE) {
2832
+                break;
2833
+            }
2834
+        }
2835
+        return $ret;
2836
+    }
2837 2837
 
2838 2838
 } // END OF TCPDF_STATIC CLASS
2839 2839
 
Please login to merge, or discard this patch.
Spacing   +329 added lines, -329 removed lines patch added patch discarded remove patch
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	public static function set_mqr($mqr) {
138 138
 		if (!defined('PHP_VERSION_ID')) {
139 139
 			$version = PHP_VERSION;
140
-			define('PHP_VERSION_ID', (($version[0] * 10000) + ($version[2] * 100) + $version[4]));
140
+			define('PHP_VERSION_ID', (($version[0]*10000) + ($version[2]*100) + $version[4]));
141 141
 		}
142 142
 		if (PHP_VERSION_ID < 50300) {
143 143
 			@set_magic_quotes_runtime($mqr);
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	public static function get_mqr() {
154 154
 		if (!defined('PHP_VERSION_ID')) {
155 155
 			$version = PHP_VERSION;
156
-			define('PHP_VERSION_ID', (($version[0] * 10000) + ($version[2] * 100) + $version[4]));
156
+			define('PHP_VERSION_ID', (($version[0]*10000) + ($version[2]*100) + $version[4]));
157 157
 		}
158 158
 		if (PHP_VERSION_ID < 50300) {
159 159
 			return @get_magic_quotes_runtime();
@@ -479,352 +479,352 @@  discard block
 block discarded – undo
479 479
 		// Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 25.4 mm)
480 480
 		switch (strtoupper($format)) {
481 481
 			// ISO 216 A Series + 2 SIS 014711 extensions
482
-			case 'A0' : {$pf = array( 2383.937, 3370.394); break;}
483
-			case 'A1' : {$pf = array( 1683.780, 2383.937); break;}
484
-			case 'A2' : {$pf = array( 1190.551, 1683.780); break;}
485
-			case 'A3' : {$pf = array(  841.890, 1190.551); break;}
486
-			case 'A4' : {$pf = array(  595.276,  841.890); break;}
487
-			case 'A5' : {$pf = array(  419.528,  595.276); break;}
488
-			case 'A6' : {$pf = array(  297.638,  419.528); break;}
489
-			case 'A7' : {$pf = array(  209.764,  297.638); break;}
490
-			case 'A8' : {$pf = array(  147.402,  209.764); break;}
491
-			case 'A9' : {$pf = array(  104.882,  147.402); break;}
492
-			case 'A10': {$pf = array(   73.701,  104.882); break;}
493
-			case 'A11': {$pf = array(   51.024,   73.701); break;}
494
-			case 'A12': {$pf = array(   36.850,   51.024); break;}
482
+			case 'A0' : {$pf = array(2383.937, 3370.394); break; }
483
+			case 'A1' : {$pf = array(1683.780, 2383.937); break; }
484
+			case 'A2' : {$pf = array(1190.551, 1683.780); break; }
485
+			case 'A3' : {$pf = array(841.890, 1190.551); break; }
486
+			case 'A4' : {$pf = array(595.276, 841.890); break; }
487
+			case 'A5' : {$pf = array(419.528, 595.276); break; }
488
+			case 'A6' : {$pf = array(297.638, 419.528); break; }
489
+			case 'A7' : {$pf = array(209.764, 297.638); break; }
490
+			case 'A8' : {$pf = array(147.402, 209.764); break; }
491
+			case 'A9' : {$pf = array(104.882, 147.402); break; }
492
+			case 'A10': {$pf = array(73.701, 104.882); break; }
493
+			case 'A11': {$pf = array(51.024, 73.701); break; }
494
+			case 'A12': {$pf = array(36.850, 51.024); break; }
495 495
 			// ISO 216 B Series + 2 SIS 014711 extensions
496
-			case 'B0' : {$pf = array( 2834.646, 4008.189); break;}
497
-			case 'B1' : {$pf = array( 2004.094, 2834.646); break;}
498
-			case 'B2' : {$pf = array( 1417.323, 2004.094); break;}
499
-			case 'B3' : {$pf = array( 1000.630, 1417.323); break;}
500
-			case 'B4' : {$pf = array(  708.661, 1000.630); break;}
501
-			case 'B5' : {$pf = array(  498.898,  708.661); break;}
502
-			case 'B6' : {$pf = array(  354.331,  498.898); break;}
503
-			case 'B7' : {$pf = array(  249.449,  354.331); break;}
504
-			case 'B8' : {$pf = array(  175.748,  249.449); break;}
505
-			case 'B9' : {$pf = array(  124.724,  175.748); break;}
506
-			case 'B10': {$pf = array(   87.874,  124.724); break;}
507
-			case 'B11': {$pf = array(   62.362,   87.874); break;}
508
-			case 'B12': {$pf = array(   42.520,   62.362); break;}
496
+			case 'B0' : {$pf = array(2834.646, 4008.189); break; }
497
+			case 'B1' : {$pf = array(2004.094, 2834.646); break; }
498
+			case 'B2' : {$pf = array(1417.323, 2004.094); break; }
499
+			case 'B3' : {$pf = array(1000.630, 1417.323); break; }
500
+			case 'B4' : {$pf = array(708.661, 1000.630); break; }
501
+			case 'B5' : {$pf = array(498.898, 708.661); break; }
502
+			case 'B6' : {$pf = array(354.331, 498.898); break; }
503
+			case 'B7' : {$pf = array(249.449, 354.331); break; }
504
+			case 'B8' : {$pf = array(175.748, 249.449); break; }
505
+			case 'B9' : {$pf = array(124.724, 175.748); break; }
506
+			case 'B10': {$pf = array(87.874, 124.724); break; }
507
+			case 'B11': {$pf = array(62.362, 87.874); break; }
508
+			case 'B12': {$pf = array(42.520, 62.362); break; }
509 509
 			// ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION
510
-			case 'C0' : {$pf = array( 2599.370, 3676.535); break;}
511
-			case 'C1' : {$pf = array( 1836.850, 2599.370); break;}
512
-			case 'C2' : {$pf = array( 1298.268, 1836.850); break;}
513
-			case 'C3' : {$pf = array(  918.425, 1298.268); break;}
514
-			case 'C4' : {$pf = array(  649.134,  918.425); break;}
515
-			case 'C5' : {$pf = array(  459.213,  649.134); break;}
516
-			case 'C6' : {$pf = array(  323.150,  459.213); break;}
517
-			case 'C7' : {$pf = array(  229.606,  323.150); break;}
518
-			case 'C8' : {$pf = array(  161.575,  229.606); break;}
519
-			case 'C9' : {$pf = array(  113.386,  161.575); break;}
520
-			case 'C10': {$pf = array(   79.370,  113.386); break;}
521
-			case 'C11': {$pf = array(   56.693,   79.370); break;}
522
-			case 'C12': {$pf = array(   39.685,   56.693); break;}
523
-			case 'C76': {$pf = array(  229.606,  459.213); break;}
524
-			case 'DL' : {$pf = array(  311.811,  623.622); break;}
510
+			case 'C0' : {$pf = array(2599.370, 3676.535); break; }
511
+			case 'C1' : {$pf = array(1836.850, 2599.370); break; }
512
+			case 'C2' : {$pf = array(1298.268, 1836.850); break; }
513
+			case 'C3' : {$pf = array(918.425, 1298.268); break; }
514
+			case 'C4' : {$pf = array(649.134, 918.425); break; }
515
+			case 'C5' : {$pf = array(459.213, 649.134); break; }
516
+			case 'C6' : {$pf = array(323.150, 459.213); break; }
517
+			case 'C7' : {$pf = array(229.606, 323.150); break; }
518
+			case 'C8' : {$pf = array(161.575, 229.606); break; }
519
+			case 'C9' : {$pf = array(113.386, 161.575); break; }
520
+			case 'C10': {$pf = array(79.370, 113.386); break; }
521
+			case 'C11': {$pf = array(56.693, 79.370); break; }
522
+			case 'C12': {$pf = array(39.685, 56.693); break; }
523
+			case 'C76': {$pf = array(229.606, 459.213); break; }
524
+			case 'DL' : {$pf = array(311.811, 623.622); break; }
525 525
 			// SIS 014711 E Series
526
-			case 'E0' : {$pf = array( 2491.654, 3517.795); break;}
527
-			case 'E1' : {$pf = array( 1757.480, 2491.654); break;}
528
-			case 'E2' : {$pf = array( 1247.244, 1757.480); break;}
529
-			case 'E3' : {$pf = array(  878.740, 1247.244); break;}
530
-			case 'E4' : {$pf = array(  623.622,  878.740); break;}
531
-			case 'E5' : {$pf = array(  439.370,  623.622); break;}
532
-			case 'E6' : {$pf = array(  311.811,  439.370); break;}
533
-			case 'E7' : {$pf = array(  221.102,  311.811); break;}
534
-			case 'E8' : {$pf = array(  155.906,  221.102); break;}
535
-			case 'E9' : {$pf = array(  110.551,  155.906); break;}
536
-			case 'E10': {$pf = array(   76.535,  110.551); break;}
537
-			case 'E11': {$pf = array(   53.858,   76.535); break;}
538
-			case 'E12': {$pf = array(   36.850,   53.858); break;}
526
+			case 'E0' : {$pf = array(2491.654, 3517.795); break; }
527
+			case 'E1' : {$pf = array(1757.480, 2491.654); break; }
528
+			case 'E2' : {$pf = array(1247.244, 1757.480); break; }
529
+			case 'E3' : {$pf = array(878.740, 1247.244); break; }
530
+			case 'E4' : {$pf = array(623.622, 878.740); break; }
531
+			case 'E5' : {$pf = array(439.370, 623.622); break; }
532
+			case 'E6' : {$pf = array(311.811, 439.370); break; }
533
+			case 'E7' : {$pf = array(221.102, 311.811); break; }
534
+			case 'E8' : {$pf = array(155.906, 221.102); break; }
535
+			case 'E9' : {$pf = array(110.551, 155.906); break; }
536
+			case 'E10': {$pf = array(76.535, 110.551); break; }
537
+			case 'E11': {$pf = array(53.858, 76.535); break; }
538
+			case 'E12': {$pf = array(36.850, 53.858); break; }
539 539
 			// SIS 014711 G Series
540
-			case 'G0' : {$pf = array( 2715.591, 3838.110); break;}
541
-			case 'G1' : {$pf = array( 1919.055, 2715.591); break;}
542
-			case 'G2' : {$pf = array( 1357.795, 1919.055); break;}
543
-			case 'G3' : {$pf = array(  958.110, 1357.795); break;}
544
-			case 'G4' : {$pf = array(  677.480,  958.110); break;}
545
-			case 'G5' : {$pf = array(  479.055,  677.480); break;}
546
-			case 'G6' : {$pf = array(  337.323,  479.055); break;}
547
-			case 'G7' : {$pf = array(  238.110,  337.323); break;}
548
-			case 'G8' : {$pf = array(  167.244,  238.110); break;}
549
-			case 'G9' : {$pf = array(  119.055,  167.244); break;}
550
-			case 'G10': {$pf = array(   82.205,  119.055); break;}
551
-			case 'G11': {$pf = array(   59.528,   82.205); break;}
552
-			case 'G12': {$pf = array(   39.685,   59.528); break;}
540
+			case 'G0' : {$pf = array(2715.591, 3838.110); break; }
541
+			case 'G1' : {$pf = array(1919.055, 2715.591); break; }
542
+			case 'G2' : {$pf = array(1357.795, 1919.055); break; }
543
+			case 'G3' : {$pf = array(958.110, 1357.795); break; }
544
+			case 'G4' : {$pf = array(677.480, 958.110); break; }
545
+			case 'G5' : {$pf = array(479.055, 677.480); break; }
546
+			case 'G6' : {$pf = array(337.323, 479.055); break; }
547
+			case 'G7' : {$pf = array(238.110, 337.323); break; }
548
+			case 'G8' : {$pf = array(167.244, 238.110); break; }
549
+			case 'G9' : {$pf = array(119.055, 167.244); break; }
550
+			case 'G10': {$pf = array(82.205, 119.055); break; }
551
+			case 'G11': {$pf = array(59.528, 82.205); break; }
552
+			case 'G12': {$pf = array(39.685, 59.528); break; }
553 553
 			// ISO Press
554
-			case 'RA0': {$pf = array( 2437.795, 3458.268); break;}
555
-			case 'RA1': {$pf = array( 1729.134, 2437.795); break;}
556
-			case 'RA2': {$pf = array( 1218.898, 1729.134); break;}
557
-			case 'RA3': {$pf = array(  864.567, 1218.898); break;}
558
-			case 'RA4': {$pf = array(  609.449,  864.567); break;}
559
-			case 'SRA0': {$pf = array( 2551.181, 3628.346); break;}
560
-			case 'SRA1': {$pf = array( 1814.173, 2551.181); break;}
561
-			case 'SRA2': {$pf = array( 1275.591, 1814.173); break;}
562
-			case 'SRA3': {$pf = array(  907.087, 1275.591); break;}
563
-			case 'SRA4': {$pf = array(  637.795,  907.087); break;}
554
+			case 'RA0': {$pf = array(2437.795, 3458.268); break; }
555
+			case 'RA1': {$pf = array(1729.134, 2437.795); break; }
556
+			case 'RA2': {$pf = array(1218.898, 1729.134); break; }
557
+			case 'RA3': {$pf = array(864.567, 1218.898); break; }
558
+			case 'RA4': {$pf = array(609.449, 864.567); break; }
559
+			case 'SRA0': {$pf = array(2551.181, 3628.346); break; }
560
+			case 'SRA1': {$pf = array(1814.173, 2551.181); break; }
561
+			case 'SRA2': {$pf = array(1275.591, 1814.173); break; }
562
+			case 'SRA3': {$pf = array(907.087, 1275.591); break; }
563
+			case 'SRA4': {$pf = array(637.795, 907.087); break; }
564 564
 			// German  DIN 476
565
-			case '4A0': {$pf = array( 4767.874, 6740.787); break;}
566
-			case '2A0': {$pf = array( 3370.394, 4767.874); break;}
565
+			case '4A0': {$pf = array(4767.874, 6740.787); break; }
566
+			case '2A0': {$pf = array(3370.394, 4767.874); break; }
567 567
 			// Variations on the ISO Standard
568
-			case 'A2_EXTRA'   : {$pf = array( 1261.417, 1754.646); break;}
569
-			case 'A3+'        : {$pf = array(  932.598, 1369.134); break;}
570
-			case 'A3_EXTRA'   : {$pf = array(  912.756, 1261.417); break;}
571
-			case 'A3_SUPER'   : {$pf = array(  864.567, 1440.000); break;}
572
-			case 'SUPER_A3'   : {$pf = array(  864.567, 1380.472); break;}
573
-			case 'A4_EXTRA'   : {$pf = array(  666.142,  912.756); break;}
574
-			case 'A4_SUPER'   : {$pf = array(  649.134,  912.756); break;}
575
-			case 'SUPER_A4'   : {$pf = array(  643.465, 1009.134); break;}
576
-			case 'A4_LONG'    : {$pf = array(  595.276,  986.457); break;}
577
-			case 'F4'         : {$pf = array(  595.276,  935.433); break;}
578
-			case 'SO_B5_EXTRA': {$pf = array(  572.598,  782.362); break;}
579
-			case 'A5_EXTRA'   : {$pf = array(  490.394,  666.142); break;}
568
+			case 'A2_EXTRA'   : {$pf = array(1261.417, 1754.646); break; }
569
+			case 'A3+'        : {$pf = array(932.598, 1369.134); break; }
570
+			case 'A3_EXTRA'   : {$pf = array(912.756, 1261.417); break; }
571
+			case 'A3_SUPER'   : {$pf = array(864.567, 1440.000); break; }
572
+			case 'SUPER_A3'   : {$pf = array(864.567, 1380.472); break; }
573
+			case 'A4_EXTRA'   : {$pf = array(666.142, 912.756); break; }
574
+			case 'A4_SUPER'   : {$pf = array(649.134, 912.756); break; }
575
+			case 'SUPER_A4'   : {$pf = array(643.465, 1009.134); break; }
576
+			case 'A4_LONG'    : {$pf = array(595.276, 986.457); break; }
577
+			case 'F4'         : {$pf = array(595.276, 935.433); break; }
578
+			case 'SO_B5_EXTRA': {$pf = array(572.598, 782.362); break; }
579
+			case 'A5_EXTRA'   : {$pf = array(490.394, 666.142); break; }
580 580
 			// ANSI Series
581
-			case 'ANSI_E': {$pf = array( 2448.000, 3168.000); break;}
582
-			case 'ANSI_D': {$pf = array( 1584.000, 2448.000); break;}
583
-			case 'ANSI_C': {$pf = array( 1224.000, 1584.000); break;}
584
-			case 'ANSI_B': {$pf = array(  792.000, 1224.000); break;}
585
-			case 'ANSI_A': {$pf = array(  612.000,  792.000); break;}
581
+			case 'ANSI_E': {$pf = array(2448.000, 3168.000); break; }
582
+			case 'ANSI_D': {$pf = array(1584.000, 2448.000); break; }
583
+			case 'ANSI_C': {$pf = array(1224.000, 1584.000); break; }
584
+			case 'ANSI_B': {$pf = array(792.000, 1224.000); break; }
585
+			case 'ANSI_A': {$pf = array(612.000, 792.000); break; }
586 586
 			// Traditional 'Loose' North American Paper Sizes
587 587
 			case 'USLEDGER':
588
-			case 'LEDGER' : {$pf = array( 1224.000,  792.000); break;}
588
+			case 'LEDGER' : {$pf = array(1224.000, 792.000); break; }
589 589
 			case 'ORGANIZERK':
590 590
 			case 'BIBLE':
591 591
 			case 'USTABLOID':
592
-			case 'TABLOID': {$pf = array(  792.000, 1224.000); break;}
592
+			case 'TABLOID': {$pf = array(792.000, 1224.000); break; }
593 593
 			case 'ORGANIZERM':
594 594
 			case 'USLETTER':
595
-			case 'LETTER' : {$pf = array(  612.000,  792.000); break;}
595
+			case 'LETTER' : {$pf = array(612.000, 792.000); break; }
596 596
 			case 'USLEGAL':
597
-			case 'LEGAL'  : {$pf = array(  612.000, 1008.000); break;}
597
+			case 'LEGAL'  : {$pf = array(612.000, 1008.000); break; }
598 598
 			case 'GOVERNMENTLETTER':
599
-			case 'GLETTER': {$pf = array(  576.000,  756.000); break;}
599
+			case 'GLETTER': {$pf = array(576.000, 756.000); break; }
600 600
 			case 'JUNIORLEGAL':
601
-			case 'JLEGAL' : {$pf = array(  576.000,  360.000); break;}
601
+			case 'JLEGAL' : {$pf = array(576.000, 360.000); break; }
602 602
 			// Other North American Paper Sizes
603
-			case 'QUADDEMY': {$pf = array( 2520.000, 3240.000); break;}
604
-			case 'SUPER_B': {$pf = array(  936.000, 1368.000); break;}
605
-			case 'QUARTO': {$pf = array(  648.000,  792.000); break;}
603
+			case 'QUADDEMY': {$pf = array(2520.000, 3240.000); break; }
604
+			case 'SUPER_B': {$pf = array(936.000, 1368.000); break; }
605
+			case 'QUARTO': {$pf = array(648.000, 792.000); break; }
606 606
 			case 'GOVERNMENTLEGAL':
607
-			case 'FOLIO': {$pf = array(  612.000,  936.000); break;}
607
+			case 'FOLIO': {$pf = array(612.000, 936.000); break; }
608 608
 			case 'MONARCH':
609
-			case 'EXECUTIVE': {$pf = array(  522.000,  756.000); break;}
609
+			case 'EXECUTIVE': {$pf = array(522.000, 756.000); break; }
610 610
 			case 'ORGANIZERL':
611 611
 			case 'STATEMENT':
612
-			case 'MEMO': {$pf = array(  396.000,  612.000); break;}
613
-			case 'FOOLSCAP': {$pf = array(  595.440,  936.000); break;}
614
-			case 'COMPACT': {$pf = array(  306.000,  486.000); break;}
615
-			case 'ORGANIZERJ': {$pf = array(  198.000,  360.000); break;}
612
+			case 'MEMO': {$pf = array(396.000, 612.000); break; }
613
+			case 'FOOLSCAP': {$pf = array(595.440, 936.000); break; }
614
+			case 'COMPACT': {$pf = array(306.000, 486.000); break; }
615
+			case 'ORGANIZERJ': {$pf = array(198.000, 360.000); break; }
616 616
 			// Canadian standard CAN 2-9.60M
617
-			case 'P1': {$pf = array( 1587.402, 2437.795); break;}
618
-			case 'P2': {$pf = array( 1218.898, 1587.402); break;}
619
-			case 'P3': {$pf = array(  793.701, 1218.898); break;}
620
-			case 'P4': {$pf = array(  609.449,  793.701); break;}
621
-			case 'P5': {$pf = array(  396.850,  609.449); break;}
622
-			case 'P6': {$pf = array(  303.307,  396.850); break;}
617
+			case 'P1': {$pf = array(1587.402, 2437.795); break; }
618
+			case 'P2': {$pf = array(1218.898, 1587.402); break; }
619
+			case 'P3': {$pf = array(793.701, 1218.898); break; }
620
+			case 'P4': {$pf = array(609.449, 793.701); break; }
621
+			case 'P5': {$pf = array(396.850, 609.449); break; }
622
+			case 'P6': {$pf = array(303.307, 396.850); break; }
623 623
 			// North American Architectural Sizes
624
-			case 'ARCH_E' : {$pf = array( 2592.000, 3456.000); break;}
625
-			case 'ARCH_E1': {$pf = array( 2160.000, 3024.000); break;}
626
-			case 'ARCH_D' : {$pf = array( 1728.000, 2592.000); break;}
624
+			case 'ARCH_E' : {$pf = array(2592.000, 3456.000); break; }
625
+			case 'ARCH_E1': {$pf = array(2160.000, 3024.000); break; }
626
+			case 'ARCH_D' : {$pf = array(1728.000, 2592.000); break; }
627 627
 			case 'BROADSHEET':
628
-			case 'ARCH_C' : {$pf = array( 1296.000, 1728.000); break;}
629
-			case 'ARCH_B' : {$pf = array(  864.000, 1296.000); break;}
630
-			case 'ARCH_A' : {$pf = array(  648.000,  864.000); break;}
628
+			case 'ARCH_C' : {$pf = array(1296.000, 1728.000); break; }
629
+			case 'ARCH_B' : {$pf = array(864.000, 1296.000); break; }
630
+			case 'ARCH_A' : {$pf = array(648.000, 864.000); break; }
631 631
 			// --- North American Envelope Sizes ---
632 632
 			//   - Announcement Envelopes
633
-			case 'ANNENV_A2'  : {$pf = array(  314.640,  414.000); break;}
634
-			case 'ANNENV_A6'  : {$pf = array(  342.000,  468.000); break;}
635
-			case 'ANNENV_A7'  : {$pf = array(  378.000,  522.000); break;}
636
-			case 'ANNENV_A8'  : {$pf = array(  396.000,  584.640); break;}
637
-			case 'ANNENV_A10' : {$pf = array(  450.000,  692.640); break;}
638
-			case 'ANNENV_SLIM': {$pf = array(  278.640,  638.640); break;}
633
+			case 'ANNENV_A2'  : {$pf = array(314.640, 414.000); break; }
634
+			case 'ANNENV_A6'  : {$pf = array(342.000, 468.000); break; }
635
+			case 'ANNENV_A7'  : {$pf = array(378.000, 522.000); break; }
636
+			case 'ANNENV_A8'  : {$pf = array(396.000, 584.640); break; }
637
+			case 'ANNENV_A10' : {$pf = array(450.000, 692.640); break; }
638
+			case 'ANNENV_SLIM': {$pf = array(278.640, 638.640); break; }
639 639
 			//   - Commercial Envelopes
640
-			case 'COMMENV_N6_1/4': {$pf = array(  252.000,  432.000); break;}
641
-			case 'COMMENV_N6_3/4': {$pf = array(  260.640,  468.000); break;}
642
-			case 'COMMENV_N8'    : {$pf = array(  278.640,  540.000); break;}
643
-			case 'COMMENV_N9'    : {$pf = array(  278.640,  638.640); break;}
644
-			case 'COMMENV_N10'   : {$pf = array(  296.640,  684.000); break;}
645
-			case 'COMMENV_N11'   : {$pf = array(  324.000,  746.640); break;}
646
-			case 'COMMENV_N12'   : {$pf = array(  342.000,  792.000); break;}
647
-			case 'COMMENV_N14'   : {$pf = array(  360.000,  828.000); break;}
640
+			case 'COMMENV_N6_1/4': {$pf = array(252.000, 432.000); break; }
641
+			case 'COMMENV_N6_3/4': {$pf = array(260.640, 468.000); break; }
642
+			case 'COMMENV_N8'    : {$pf = array(278.640, 540.000); break; }
643
+			case 'COMMENV_N9'    : {$pf = array(278.640, 638.640); break; }
644
+			case 'COMMENV_N10'   : {$pf = array(296.640, 684.000); break; }
645
+			case 'COMMENV_N11'   : {$pf = array(324.000, 746.640); break; }
646
+			case 'COMMENV_N12'   : {$pf = array(342.000, 792.000); break; }
647
+			case 'COMMENV_N14'   : {$pf = array(360.000, 828.000); break; }
648 648
 			//   - Catalogue Envelopes
649
-			case 'CATENV_N1'     : {$pf = array(  432.000,  648.000); break;}
650
-			case 'CATENV_N1_3/4' : {$pf = array(  468.000,  684.000); break;}
651
-			case 'CATENV_N2'     : {$pf = array(  468.000,  720.000); break;}
652
-			case 'CATENV_N3'     : {$pf = array(  504.000,  720.000); break;}
653
-			case 'CATENV_N6'     : {$pf = array(  540.000,  756.000); break;}
654
-			case 'CATENV_N7'     : {$pf = array(  576.000,  792.000); break;}
655
-			case 'CATENV_N8'     : {$pf = array(  594.000,  810.000); break;}
656
-			case 'CATENV_N9_1/2' : {$pf = array(  612.000,  756.000); break;}
657
-			case 'CATENV_N9_3/4' : {$pf = array(  630.000,  810.000); break;}
658
-			case 'CATENV_N10_1/2': {$pf = array(  648.000,  864.000); break;}
659
-			case 'CATENV_N12_1/2': {$pf = array(  684.000,  900.000); break;}
660
-			case 'CATENV_N13_1/2': {$pf = array(  720.000,  936.000); break;}
661
-			case 'CATENV_N14_1/4': {$pf = array(  810.000,  882.000); break;}
662
-			case 'CATENV_N14_1/2': {$pf = array(  828.000, 1044.000); break;}
649
+			case 'CATENV_N1'     : {$pf = array(432.000, 648.000); break; }
650
+			case 'CATENV_N1_3/4' : {$pf = array(468.000, 684.000); break; }
651
+			case 'CATENV_N2'     : {$pf = array(468.000, 720.000); break; }
652
+			case 'CATENV_N3'     : {$pf = array(504.000, 720.000); break; }
653
+			case 'CATENV_N6'     : {$pf = array(540.000, 756.000); break; }
654
+			case 'CATENV_N7'     : {$pf = array(576.000, 792.000); break; }
655
+			case 'CATENV_N8'     : {$pf = array(594.000, 810.000); break; }
656
+			case 'CATENV_N9_1/2' : {$pf = array(612.000, 756.000); break; }
657
+			case 'CATENV_N9_3/4' : {$pf = array(630.000, 810.000); break; }
658
+			case 'CATENV_N10_1/2': {$pf = array(648.000, 864.000); break; }
659
+			case 'CATENV_N12_1/2': {$pf = array(684.000, 900.000); break; }
660
+			case 'CATENV_N13_1/2': {$pf = array(720.000, 936.000); break; }
661
+			case 'CATENV_N14_1/4': {$pf = array(810.000, 882.000); break; }
662
+			case 'CATENV_N14_1/2': {$pf = array(828.000, 1044.000); break; }
663 663
 			// Japanese (JIS P 0138-61) Standard B-Series
664
-			case 'JIS_B0' : {$pf = array( 2919.685, 4127.244); break;}
665
-			case 'JIS_B1' : {$pf = array( 2063.622, 2919.685); break;}
666
-			case 'JIS_B2' : {$pf = array( 1459.843, 2063.622); break;}
667
-			case 'JIS_B3' : {$pf = array( 1031.811, 1459.843); break;}
668
-			case 'JIS_B4' : {$pf = array(  728.504, 1031.811); break;}
669
-			case 'JIS_B5' : {$pf = array(  515.906,  728.504); break;}
670
-			case 'JIS_B6' : {$pf = array(  362.835,  515.906); break;}
671
-			case 'JIS_B7' : {$pf = array(  257.953,  362.835); break;}
672
-			case 'JIS_B8' : {$pf = array(  181.417,  257.953); break;}
673
-			case 'JIS_B9' : {$pf = array(  127.559,  181.417); break;}
674
-			case 'JIS_B10': {$pf = array(   90.709,  127.559); break;}
675
-			case 'JIS_B11': {$pf = array(   62.362,   90.709); break;}
676
-			case 'JIS_B12': {$pf = array(   45.354,   62.362); break;}
664
+			case 'JIS_B0' : {$pf = array(2919.685, 4127.244); break; }
665
+			case 'JIS_B1' : {$pf = array(2063.622, 2919.685); break; }
666
+			case 'JIS_B2' : {$pf = array(1459.843, 2063.622); break; }
667
+			case 'JIS_B3' : {$pf = array(1031.811, 1459.843); break; }
668
+			case 'JIS_B4' : {$pf = array(728.504, 1031.811); break; }
669
+			case 'JIS_B5' : {$pf = array(515.906, 728.504); break; }
670
+			case 'JIS_B6' : {$pf = array(362.835, 515.906); break; }
671
+			case 'JIS_B7' : {$pf = array(257.953, 362.835); break; }
672
+			case 'JIS_B8' : {$pf = array(181.417, 257.953); break; }
673
+			case 'JIS_B9' : {$pf = array(127.559, 181.417); break; }
674
+			case 'JIS_B10': {$pf = array(90.709, 127.559); break; }
675
+			case 'JIS_B11': {$pf = array(62.362, 90.709); break; }
676
+			case 'JIS_B12': {$pf = array(45.354, 62.362); break; }
677 677
 			// PA Series
678
-			case 'PA0' : {$pf = array( 2381.102, 3174.803,); break;}
679
-			case 'PA1' : {$pf = array( 1587.402, 2381.102); break;}
680
-			case 'PA2' : {$pf = array( 1190.551, 1587.402); break;}
681
-			case 'PA3' : {$pf = array(  793.701, 1190.551); break;}
682
-			case 'PA4' : {$pf = array(  595.276,  793.701); break;}
683
-			case 'PA5' : {$pf = array(  396.850,  595.276); break;}
684
-			case 'PA6' : {$pf = array(  297.638,  396.850); break;}
685
-			case 'PA7' : {$pf = array(  198.425,  297.638); break;}
686
-			case 'PA8' : {$pf = array(  147.402,  198.425); break;}
687
-			case 'PA9' : {$pf = array(   99.213,  147.402); break;}
688
-			case 'PA10': {$pf = array(   73.701,   99.213); break;}
678
+			case 'PA0' : {$pf = array(2381.102, 3174.803,); break; }
679
+			case 'PA1' : {$pf = array(1587.402, 2381.102); break; }
680
+			case 'PA2' : {$pf = array(1190.551, 1587.402); break; }
681
+			case 'PA3' : {$pf = array(793.701, 1190.551); break; }
682
+			case 'PA4' : {$pf = array(595.276, 793.701); break; }
683
+			case 'PA5' : {$pf = array(396.850, 595.276); break; }
684
+			case 'PA6' : {$pf = array(297.638, 396.850); break; }
685
+			case 'PA7' : {$pf = array(198.425, 297.638); break; }
686
+			case 'PA8' : {$pf = array(147.402, 198.425); break; }
687
+			case 'PA9' : {$pf = array(99.213, 147.402); break; }
688
+			case 'PA10': {$pf = array(73.701, 99.213); break; }
689 689
 			// Standard Photographic Print Sizes
690
-			case 'PASSPORT_PHOTO': {$pf = array(   99.213,  127.559); break;}
691
-			case 'E'   : {$pf = array(  233.858,  340.157); break;}
690
+			case 'PASSPORT_PHOTO': {$pf = array(99.213, 127.559); break; }
691
+			case 'E'   : {$pf = array(233.858, 340.157); break; }
692 692
 			case 'L':
693
-			case '3R'  : {$pf = array(  252.283,  360.000); break;}
693
+			case '3R'  : {$pf = array(252.283, 360.000); break; }
694 694
 			case 'KG':
695
-			case '4R'  : {$pf = array(  289.134,  430.866); break;}
696
-			case '4D'  : {$pf = array(  340.157,  430.866); break;}
695
+			case '4R'  : {$pf = array(289.134, 430.866); break; }
696
+			case '4D'  : {$pf = array(340.157, 430.866); break; }
697 697
 			case '2L':
698
-			case '5R'  : {$pf = array(  360.000,  504.567); break;}
698
+			case '5R'  : {$pf = array(360.000, 504.567); break; }
699 699
 			case '8P':
700
-			case '6R'  : {$pf = array(  430.866,  575.433); break;}
700
+			case '6R'  : {$pf = array(430.866, 575.433); break; }
701 701
 			case '6P':
702
-			case '8R'  : {$pf = array(  575.433,  720.000); break;}
702
+			case '8R'  : {$pf = array(575.433, 720.000); break; }
703 703
 			case '6PW':
704
-			case 'S8R' : {$pf = array(  575.433,  864.567); break;}
704
+			case 'S8R' : {$pf = array(575.433, 864.567); break; }
705 705
 			case '4P':
706
-			case '10R' : {$pf = array(  720.000,  864.567); break;}
706
+			case '10R' : {$pf = array(720.000, 864.567); break; }
707 707
 			case '4PW':
708
-			case 'S10R': {$pf = array(  720.000, 1080.000); break;}
709
-			case '11R' : {$pf = array(  790.866, 1009.134); break;}
710
-			case 'S11R': {$pf = array(  790.866, 1224.567); break;}
711
-			case '12R' : {$pf = array(  864.567, 1080.000); break;}
712
-			case 'S12R': {$pf = array(  864.567, 1292.598); break;}
708
+			case 'S10R': {$pf = array(720.000, 1080.000); break; }
709
+			case '11R' : {$pf = array(790.866, 1009.134); break; }
710
+			case 'S11R': {$pf = array(790.866, 1224.567); break; }
711
+			case '12R' : {$pf = array(864.567, 1080.000); break; }
712
+			case 'S12R': {$pf = array(864.567, 1292.598); break; }
713 713
 			// Common Newspaper Sizes
714
-			case 'NEWSPAPER_BROADSHEET': {$pf = array( 2125.984, 1700.787); break;}
715
-			case 'NEWSPAPER_BERLINER'  : {$pf = array( 1332.283,  892.913); break;}
714
+			case 'NEWSPAPER_BROADSHEET': {$pf = array(2125.984, 1700.787); break; }
715
+			case 'NEWSPAPER_BERLINER'  : {$pf = array(1332.283, 892.913); break; }
716 716
 			case 'NEWSPAPER_TABLOID':
717
-			case 'NEWSPAPER_COMPACT'   : {$pf = array( 1218.898,  793.701); break;}
717
+			case 'NEWSPAPER_COMPACT'   : {$pf = array(1218.898, 793.701); break; }
718 718
 			// Business Cards
719 719
 			case 'CREDIT_CARD':
720 720
 			case 'BUSINESS_CARD':
721
-			case 'BUSINESS_CARD_ISO7810': {$pf = array(  153.014,  242.646); break;}
722
-			case 'BUSINESS_CARD_ISO216' : {$pf = array(  147.402,  209.764); break;}
721
+			case 'BUSINESS_CARD_ISO7810': {$pf = array(153.014, 242.646); break; }
722
+			case 'BUSINESS_CARD_ISO216' : {$pf = array(147.402, 209.764); break; }
723 723
 			case 'BUSINESS_CARD_IT':
724 724
 			case 'BUSINESS_CARD_UK':
725 725
 			case 'BUSINESS_CARD_FR':
726 726
 			case 'BUSINESS_CARD_DE':
727
-			case 'BUSINESS_CARD_ES'     : {$pf = array(  155.906,  240.945); break;}
727
+			case 'BUSINESS_CARD_ES'     : {$pf = array(155.906, 240.945); break; }
728 728
 			case 'BUSINESS_CARD_CA':
729
-			case 'BUSINESS_CARD_US'     : {$pf = array(  144.567,  252.283); break;}
730
-			case 'BUSINESS_CARD_JP'     : {$pf = array(  155.906,  257.953); break;}
731
-			case 'BUSINESS_CARD_HK'     : {$pf = array(  153.071,  255.118); break;}
729
+			case 'BUSINESS_CARD_US'     : {$pf = array(144.567, 252.283); break; }
730
+			case 'BUSINESS_CARD_JP'     : {$pf = array(155.906, 257.953); break; }
731
+			case 'BUSINESS_CARD_HK'     : {$pf = array(153.071, 255.118); break; }
732 732
 			case 'BUSINESS_CARD_AU':
733 733
 			case 'BUSINESS_CARD_DK':
734
-			case 'BUSINESS_CARD_SE'     : {$pf = array(  155.906,  255.118); break;}
734
+			case 'BUSINESS_CARD_SE'     : {$pf = array(155.906, 255.118); break; }
735 735
 			case 'BUSINESS_CARD_RU':
736 736
 			case 'BUSINESS_CARD_CZ':
737 737
 			case 'BUSINESS_CARD_FI':
738 738
 			case 'BUSINESS_CARD_HU':
739
-			case 'BUSINESS_CARD_IL'     : {$pf = array(  141.732,  255.118); break;}
739
+			case 'BUSINESS_CARD_IL'     : {$pf = array(141.732, 255.118); break; }
740 740
 			// Billboards
741
-			case '4SHEET' : {$pf = array( 2880.000, 4320.000); break;}
742
-			case '6SHEET' : {$pf = array( 3401.575, 5102.362); break;}
743
-			case '12SHEET': {$pf = array( 8640.000, 4320.000); break;}
744
-			case '16SHEET': {$pf = array( 5760.000, 8640.000); break;}
745
-			case '32SHEET': {$pf = array(11520.000, 8640.000); break;}
746
-			case '48SHEET': {$pf = array(17280.000, 8640.000); break;}
747
-			case '64SHEET': {$pf = array(23040.000, 8640.000); break;}
748
-			case '96SHEET': {$pf = array(34560.000, 8640.000); break;}
741
+			case '4SHEET' : {$pf = array(2880.000, 4320.000); break; }
742
+			case '6SHEET' : {$pf = array(3401.575, 5102.362); break; }
743
+			case '12SHEET': {$pf = array(8640.000, 4320.000); break; }
744
+			case '16SHEET': {$pf = array(5760.000, 8640.000); break; }
745
+			case '32SHEET': {$pf = array(11520.000, 8640.000); break; }
746
+			case '48SHEET': {$pf = array(17280.000, 8640.000); break; }
747
+			case '64SHEET': {$pf = array(23040.000, 8640.000); break; }
748
+			case '96SHEET': {$pf = array(34560.000, 8640.000); break; }
749 749
 			// Old European Sizes
750 750
 			//   - Old Imperial English Sizes
751
-			case 'EN_EMPEROR'          : {$pf = array( 3456.000, 5184.000); break;}
752
-			case 'EN_ANTIQUARIAN'      : {$pf = array( 2232.000, 3816.000); break;}
753
-			case 'EN_GRAND_EAGLE'      : {$pf = array( 2070.000, 3024.000); break;}
754
-			case 'EN_DOUBLE_ELEPHANT'  : {$pf = array( 1926.000, 2880.000); break;}
755
-			case 'EN_ATLAS'            : {$pf = array( 1872.000, 2448.000); break;}
756
-			case 'EN_COLOMBIER'        : {$pf = array( 1692.000, 2484.000); break;}
757
-			case 'EN_ELEPHANT'         : {$pf = array( 1656.000, 2016.000); break;}
758
-			case 'EN_DOUBLE_DEMY'      : {$pf = array( 1620.000, 2556.000); break;}
759
-			case 'EN_IMPERIAL'         : {$pf = array( 1584.000, 2160.000); break;}
760
-			case 'EN_PRINCESS'         : {$pf = array( 1548.000, 2016.000); break;}
761
-			case 'EN_CARTRIDGE'        : {$pf = array( 1512.000, 1872.000); break;}
762
-			case 'EN_DOUBLE_LARGE_POST': {$pf = array( 1512.000, 2376.000); break;}
763
-			case 'EN_ROYAL'            : {$pf = array( 1440.000, 1800.000); break;}
751
+			case 'EN_EMPEROR'          : {$pf = array(3456.000, 5184.000); break; }
752
+			case 'EN_ANTIQUARIAN'      : {$pf = array(2232.000, 3816.000); break; }
753
+			case 'EN_GRAND_EAGLE'      : {$pf = array(2070.000, 3024.000); break; }
754
+			case 'EN_DOUBLE_ELEPHANT'  : {$pf = array(1926.000, 2880.000); break; }
755
+			case 'EN_ATLAS'            : {$pf = array(1872.000, 2448.000); break; }
756
+			case 'EN_COLOMBIER'        : {$pf = array(1692.000, 2484.000); break; }
757
+			case 'EN_ELEPHANT'         : {$pf = array(1656.000, 2016.000); break; }
758
+			case 'EN_DOUBLE_DEMY'      : {$pf = array(1620.000, 2556.000); break; }
759
+			case 'EN_IMPERIAL'         : {$pf = array(1584.000, 2160.000); break; }
760
+			case 'EN_PRINCESS'         : {$pf = array(1548.000, 2016.000); break; }
761
+			case 'EN_CARTRIDGE'        : {$pf = array(1512.000, 1872.000); break; }
762
+			case 'EN_DOUBLE_LARGE_POST': {$pf = array(1512.000, 2376.000); break; }
763
+			case 'EN_ROYAL'            : {$pf = array(1440.000, 1800.000); break; }
764 764
 			case 'EN_SHEET':
765
-			case 'EN_HALF_POST'        : {$pf = array( 1404.000, 1692.000); break;}
766
-			case 'EN_SUPER_ROYAL'      : {$pf = array( 1368.000, 1944.000); break;}
767
-			case 'EN_DOUBLE_POST'      : {$pf = array( 1368.000, 2196.000); break;}
768
-			case 'EN_MEDIUM'           : {$pf = array( 1260.000, 1656.000); break;}
769
-			case 'EN_DEMY'             : {$pf = array( 1260.000, 1620.000); break;}
770
-			case 'EN_LARGE_POST'       : {$pf = array( 1188.000, 1512.000); break;}
771
-			case 'EN_COPY_DRAUGHT'     : {$pf = array( 1152.000, 1440.000); break;}
772
-			case 'EN_POST'             : {$pf = array( 1116.000, 1386.000); break;}
773
-			case 'EN_CROWN'            : {$pf = array( 1080.000, 1440.000); break;}
774
-			case 'EN_PINCHED_POST'     : {$pf = array( 1062.000, 1332.000); break;}
775
-			case 'EN_BRIEF'            : {$pf = array(  972.000, 1152.000); break;}
776
-			case 'EN_FOOLSCAP'         : {$pf = array(  972.000, 1224.000); break;}
777
-			case 'EN_SMALL_FOOLSCAP'   : {$pf = array(  954.000, 1188.000); break;}
778
-			case 'EN_POTT'             : {$pf = array(  900.000, 1080.000); break;}
765
+			case 'EN_HALF_POST'        : {$pf = array(1404.000, 1692.000); break; }
766
+			case 'EN_SUPER_ROYAL'      : {$pf = array(1368.000, 1944.000); break; }
767
+			case 'EN_DOUBLE_POST'      : {$pf = array(1368.000, 2196.000); break; }
768
+			case 'EN_MEDIUM'           : {$pf = array(1260.000, 1656.000); break; }
769
+			case 'EN_DEMY'             : {$pf = array(1260.000, 1620.000); break; }
770
+			case 'EN_LARGE_POST'       : {$pf = array(1188.000, 1512.000); break; }
771
+			case 'EN_COPY_DRAUGHT'     : {$pf = array(1152.000, 1440.000); break; }
772
+			case 'EN_POST'             : {$pf = array(1116.000, 1386.000); break; }
773
+			case 'EN_CROWN'            : {$pf = array(1080.000, 1440.000); break; }
774
+			case 'EN_PINCHED_POST'     : {$pf = array(1062.000, 1332.000); break; }
775
+			case 'EN_BRIEF'            : {$pf = array(972.000, 1152.000); break; }
776
+			case 'EN_FOOLSCAP'         : {$pf = array(972.000, 1224.000); break; }
777
+			case 'EN_SMALL_FOOLSCAP'   : {$pf = array(954.000, 1188.000); break; }
778
+			case 'EN_POTT'             : {$pf = array(900.000, 1080.000); break; }
779 779
 			//   - Old Imperial Belgian Sizes
780
-			case 'BE_GRAND_AIGLE' : {$pf = array( 1984.252, 2948.031); break;}
781
-			case 'BE_COLOMBIER'   : {$pf = array( 1757.480, 2409.449); break;}
782
-			case 'BE_DOUBLE_CARRE': {$pf = array( 1757.480, 2607.874); break;}
783
-			case 'BE_ELEPHANT'    : {$pf = array( 1746.142, 2182.677); break;}
784
-			case 'BE_PETIT_AIGLE' : {$pf = array( 1700.787, 2381.102); break;}
785
-			case 'BE_GRAND_JESUS' : {$pf = array( 1559.055, 2069.291); break;}
786
-			case 'BE_JESUS'       : {$pf = array( 1530.709, 2069.291); break;}
787
-			case 'BE_RAISIN'      : {$pf = array( 1417.323, 1842.520); break;}
788
-			case 'BE_GRAND_MEDIAN': {$pf = array( 1303.937, 1714.961); break;}
789
-			case 'BE_DOUBLE_POSTE': {$pf = array( 1233.071, 1601.575); break;}
790
-			case 'BE_COQUILLE'    : {$pf = array( 1218.898, 1587.402); break;}
791
-			case 'BE_PETIT_MEDIAN': {$pf = array( 1176.378, 1502.362); break;}
792
-			case 'BE_RUCHE'       : {$pf = array( 1020.472, 1303.937); break;}
793
-			case 'BE_PROPATRIA'   : {$pf = array(  977.953, 1218.898); break;}
794
-			case 'BE_LYS'         : {$pf = array(  898.583, 1125.354); break;}
795
-			case 'BE_POT'         : {$pf = array(  870.236, 1088.504); break;}
796
-			case 'BE_ROSETTE'     : {$pf = array(  765.354,  983.622); break;}
780
+			case 'BE_GRAND_AIGLE' : {$pf = array(1984.252, 2948.031); break; }
781
+			case 'BE_COLOMBIER'   : {$pf = array(1757.480, 2409.449); break; }
782
+			case 'BE_DOUBLE_CARRE': {$pf = array(1757.480, 2607.874); break; }
783
+			case 'BE_ELEPHANT'    : {$pf = array(1746.142, 2182.677); break; }
784
+			case 'BE_PETIT_AIGLE' : {$pf = array(1700.787, 2381.102); break; }
785
+			case 'BE_GRAND_JESUS' : {$pf = array(1559.055, 2069.291); break; }
786
+			case 'BE_JESUS'       : {$pf = array(1530.709, 2069.291); break; }
787
+			case 'BE_RAISIN'      : {$pf = array(1417.323, 1842.520); break; }
788
+			case 'BE_GRAND_MEDIAN': {$pf = array(1303.937, 1714.961); break; }
789
+			case 'BE_DOUBLE_POSTE': {$pf = array(1233.071, 1601.575); break; }
790
+			case 'BE_COQUILLE'    : {$pf = array(1218.898, 1587.402); break; }
791
+			case 'BE_PETIT_MEDIAN': {$pf = array(1176.378, 1502.362); break; }
792
+			case 'BE_RUCHE'       : {$pf = array(1020.472, 1303.937); break; }
793
+			case 'BE_PROPATRIA'   : {$pf = array(977.953, 1218.898); break; }
794
+			case 'BE_LYS'         : {$pf = array(898.583, 1125.354); break; }
795
+			case 'BE_POT'         : {$pf = array(870.236, 1088.504); break; }
796
+			case 'BE_ROSETTE'     : {$pf = array(765.354, 983.622); break; }
797 797
 			//   - Old Imperial French Sizes
798
-			case 'FR_UNIVERS'          : {$pf = array( 2834.646, 3685.039); break;}
799
-			case 'FR_DOUBLE_COLOMBIER' : {$pf = array( 2551.181, 3571.654); break;}
800
-			case 'FR_GRANDE_MONDE'     : {$pf = array( 2551.181, 3571.654); break;}
801
-			case 'FR_DOUBLE_SOLEIL'    : {$pf = array( 2267.717, 3401.575); break;}
802
-			case 'FR_DOUBLE_JESUS'     : {$pf = array( 2154.331, 3174.803); break;}
803
-			case 'FR_GRAND_AIGLE'      : {$pf = array( 2125.984, 3004.724); break;}
804
-			case 'FR_PETIT_AIGLE'      : {$pf = array( 1984.252, 2664.567); break;}
805
-			case 'FR_DOUBLE_RAISIN'    : {$pf = array( 1842.520, 2834.646); break;}
806
-			case 'FR_JOURNAL'          : {$pf = array( 1842.520, 2664.567); break;}
807
-			case 'FR_COLOMBIER_AFFICHE': {$pf = array( 1785.827, 2551.181); break;}
808
-			case 'FR_DOUBLE_CAVALIER'  : {$pf = array( 1757.480, 2607.874); break;}
809
-			case 'FR_CLOCHE'           : {$pf = array( 1700.787, 2267.717); break;}
810
-			case 'FR_SOLEIL'           : {$pf = array( 1700.787, 2267.717); break;}
811
-			case 'FR_DOUBLE_CARRE'     : {$pf = array( 1587.402, 2551.181); break;}
812
-			case 'FR_DOUBLE_COQUILLE'  : {$pf = array( 1587.402, 2494.488); break;}
813
-			case 'FR_JESUS'            : {$pf = array( 1587.402, 2154.331); break;}
814
-			case 'FR_RAISIN'           : {$pf = array( 1417.323, 1842.520); break;}
815
-			case 'FR_CAVALIER'         : {$pf = array( 1303.937, 1757.480); break;}
816
-			case 'FR_DOUBLE_COURONNE'  : {$pf = array( 1303.937, 2040.945); break;}
817
-			case 'FR_CARRE'            : {$pf = array( 1275.591, 1587.402); break;}
818
-			case 'FR_COQUILLE'         : {$pf = array( 1247.244, 1587.402); break;}
819
-			case 'FR_DOUBLE_TELLIERE'  : {$pf = array( 1247.244, 1927.559); break;}
820
-			case 'FR_DOUBLE_CLOCHE'    : {$pf = array( 1133.858, 1700.787); break;}
821
-			case 'FR_DOUBLE_POT'       : {$pf = array( 1133.858, 1757.480); break;}
822
-			case 'FR_ECU'              : {$pf = array( 1133.858, 1474.016); break;}
823
-			case 'FR_COURONNE'         : {$pf = array( 1020.472, 1303.937); break;}
824
-			case 'FR_TELLIERE'         : {$pf = array(  963.780, 1247.244); break;}
825
-			case 'FR_POT'              : {$pf = array(  878.740, 1133.858); break;}
798
+			case 'FR_UNIVERS'          : {$pf = array(2834.646, 3685.039); break; }
799
+			case 'FR_DOUBLE_COLOMBIER' : {$pf = array(2551.181, 3571.654); break; }
800
+			case 'FR_GRANDE_MONDE'     : {$pf = array(2551.181, 3571.654); break; }
801
+			case 'FR_DOUBLE_SOLEIL'    : {$pf = array(2267.717, 3401.575); break; }
802
+			case 'FR_DOUBLE_JESUS'     : {$pf = array(2154.331, 3174.803); break; }
803
+			case 'FR_GRAND_AIGLE'      : {$pf = array(2125.984, 3004.724); break; }
804
+			case 'FR_PETIT_AIGLE'      : {$pf = array(1984.252, 2664.567); break; }
805
+			case 'FR_DOUBLE_RAISIN'    : {$pf = array(1842.520, 2834.646); break; }
806
+			case 'FR_JOURNAL'          : {$pf = array(1842.520, 2664.567); break; }
807
+			case 'FR_COLOMBIER_AFFICHE': {$pf = array(1785.827, 2551.181); break; }
808
+			case 'FR_DOUBLE_CAVALIER'  : {$pf = array(1757.480, 2607.874); break; }
809
+			case 'FR_CLOCHE'           : {$pf = array(1700.787, 2267.717); break; }
810
+			case 'FR_SOLEIL'           : {$pf = array(1700.787, 2267.717); break; }
811
+			case 'FR_DOUBLE_CARRE'     : {$pf = array(1587.402, 2551.181); break; }
812
+			case 'FR_DOUBLE_COQUILLE'  : {$pf = array(1587.402, 2494.488); break; }
813
+			case 'FR_JESUS'            : {$pf = array(1587.402, 2154.331); break; }
814
+			case 'FR_RAISIN'           : {$pf = array(1417.323, 1842.520); break; }
815
+			case 'FR_CAVALIER'         : {$pf = array(1303.937, 1757.480); break; }
816
+			case 'FR_DOUBLE_COURONNE'  : {$pf = array(1303.937, 2040.945); break; }
817
+			case 'FR_CARRE'            : {$pf = array(1275.591, 1587.402); break; }
818
+			case 'FR_COQUILLE'         : {$pf = array(1247.244, 1587.402); break; }
819
+			case 'FR_DOUBLE_TELLIERE'  : {$pf = array(1247.244, 1927.559); break; }
820
+			case 'FR_DOUBLE_CLOCHE'    : {$pf = array(1133.858, 1700.787); break; }
821
+			case 'FR_DOUBLE_POT'       : {$pf = array(1133.858, 1757.480); break; }
822
+			case 'FR_ECU'              : {$pf = array(1133.858, 1474.016); break; }
823
+			case 'FR_COURONNE'         : {$pf = array(1020.472, 1303.937); break; }
824
+			case 'FR_TELLIERE'         : {$pf = array(963.780, 1247.244); break; }
825
+			case 'FR_POT'              : {$pf = array(878.740, 1133.858); break; }
826 826
 			// DEFAULT ISO A4
827
-			default: {$pf = array(  595.276,  841.890); break;}
827
+			default: {$pf = array(595.276, 841.890); break; }
828 828
 		}
829 829
 		return $pf;
830 830
 	}
@@ -844,7 +844,7 @@  discard block
 block discarded – undo
844 844
 	 * @since 5.0.010 (2010-05-17)
845 845
 	 * @public static
846 846
 	 */
847
-	public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points=false, $k, $pagedim=array()) {
847
+	public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points = false, $k, $pagedim = array()) {
848 848
 		if (!isset($pagedim[$page])) {
849 849
 			// initialize array
850 850
 			$pagedim[$page] = array();
@@ -855,10 +855,10 @@  discard block
 block discarded – undo
855 855
 		if ($points) {
856 856
 			$k = 1;
857 857
 		}
858
-		$pagedim[$page][$type]['llx'] = ($llx * $k);
859
-		$pagedim[$page][$type]['lly'] = ($lly * $k);
860
-		$pagedim[$page][$type]['urx'] = ($urx * $k);
861
-		$pagedim[$page][$type]['ury'] = ($ury * $k);
858
+		$pagedim[$page][$type]['llx'] = ($llx*$k);
859
+		$pagedim[$page][$type]['lly'] = ($lly*$k);
860
+		$pagedim[$page][$type]['urx'] = ($urx*$k);
861
+		$pagedim[$page][$type]['ury'] = ($ury*$k);
862 862
 		return $pagedim;
863 863
 	}
864 864
 
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
 	 * @return (string) Canonical page layout name.
892 892
 	 * @public static
893 893
 	 */
894
-	public static function getPageLayoutMode($layout='SinglePage') {
894
+	public static function getPageLayoutMode($layout = 'SinglePage') {
895 895
 		switch ($layout) {
896 896
 			case 'default':
897 897
 			case 'single':
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
 	 * @return (string) Canonical page mode name.
935 935
 	 * @public static
936 936
 	 */
937
-	public static function getPageMode($mode='UseNone') {
937
+	public static function getPageMode($mode = 'UseNone') {
938 938
 		switch ($mode) {
939 939
 			case 'UseNone': {
940 940
 				$page_mode = 'UseNone';
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
 	 * @since (4.5.019) 2009-02-28
997 997
 	 * @public static
998 998
 	 */
999
-	public static function removeSHY($txt='', $unicode=true) {
999
+	public static function removeSHY($txt = '', $unicode = true) {
1000 1000
 		$txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
1001 1001
 		if (!$unicode) {
1002 1002
 			$txt = preg_replace('/([\\xad]{1})/', '', $txt);
@@ -1014,7 +1014,7 @@  discard block
 block discarded – undo
1014 1014
 	 * @since 4.4.002 (2008-12-09)
1015 1015
 	 * @public static
1016 1016
 	 */
1017
-	public static function getBorderMode($brd, $position='start', $opencell=true) {
1017
+	public static function getBorderMode($brd, $position = 'start', $opencell = true) {
1018 1018
 		if ((!$opencell) OR empty($brd)) {
1019 1019
 			return $brd;
1020 1020
 		}
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
 	 * @since 4.5.000 (2008-12-31)
1098 1098
 	 * @public static
1099 1099
 	 */
1100
-	public static function getObjFilename($type='tmp') {
1100
+	public static function getObjFilename($type = 'tmp') {
1101 1101
 		return tempnam(K_PATH_CACHE, '__tcpdf_'.$type.'_'.md5(getmypid().uniqid('', true).rand().microtime(true)).'_');
1102 1102
 	}
1103 1103
 
@@ -1163,7 +1163,7 @@  discard block
 block discarded – undo
1163 1163
 	 * @return replaced page content and updated $diff parameter as array.
1164 1164
 	 * @public static
1165 1165
 	 */
1166
-	public static function replacePageNumAliases($page, $replace, $diff=0) {
1166
+	public static function replacePageNumAliases($page, $replace, $diff = 0) {
1167 1167
 		foreach ($replace as $rep) {
1168 1168
 			foreach ($rep[3] as $a) {
1169 1169
 				if (strpos($page, $a) !== false) {
@@ -1346,7 +1346,7 @@  discard block
 block discarded – undo
1346 1346
 	 * @since 5.9.006 (2010-10-19)
1347 1347
 	 * @public static
1348 1348
 	 */
1349
-	public static function getRandomSeed($seed='') {
1349
+	public static function getRandomSeed($seed = '') {
1350 1350
 		$seed .= microtime();
1351 1351
 		if (function_exists('openssl_random_pseudo_bytes') AND (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) {
1352 1352
 			// this is not used on windows systems because it is very slow for a know bug
@@ -1407,7 +1407,7 @@  discard block
 block discarded – undo
1407 1407
 	 */
1408 1408
 	public static function _AES($key, $text) {
1409 1409
 		// padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0)
1410
-		$padding = 16 - (strlen($text) % 16);
1410
+		$padding = 16 - (strlen($text)%16);
1411 1411
 		$text .= str_repeat(chr($padding), $padding);
1412 1412
 		$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
1413 1413
 		$text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
@@ -1433,12 +1433,12 @@  discard block
 block discarded – undo
1433 1433
 			return $out;
1434 1434
 		}
1435 1435
 		if ($last_enc_key != $key) {
1436
-			$k = str_repeat($key, ((256 / strlen($key)) + 1));
1436
+			$k = str_repeat($key, ((256/strlen($key)) + 1));
1437 1437
 			$rc4 = range(0, 255);
1438 1438
 			$j = 0;
1439 1439
 			for ($i = 0; $i < 256; ++$i) {
1440 1440
 				$t = $rc4[$i];
1441
-				$j = ($j + $t + ord($k[$i])) % 256;
1441
+				$j = ($j + $t + ord($k[$i]))%256;
1442 1442
 				$rc4[$i] = $rc4[$j];
1443 1443
 				$rc4[$j] = $t;
1444 1444
 			}
@@ -1452,12 +1452,12 @@  discard block
 block discarded – undo
1452 1452
 		$b = 0;
1453 1453
 		$out = '';
1454 1454
 		for ($i = 0; $i < $len; ++$i) {
1455
-			$a = ($a + 1) % 256;
1455
+			$a = ($a + 1)%256;
1456 1456
 			$t = $rc4[$a];
1457
-			$b = ($b + $t) % 256;
1457
+			$b = ($b + $t)%256;
1458 1458
 			$rc4[$a] = $rc4[$b];
1459 1459
 			$rc4[$b] = $t;
1460
-			$k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
1460
+			$k = $rc4[($rc4[$a] + $rc4[$b])%256];
1461 1461
 			$out .= chr(ord($text[$i]) ^ $k);
1462 1462
 		}
1463 1463
 		return $out;
@@ -1471,7 +1471,7 @@  discard block
 block discarded – undo
1471 1471
 	 * @author Nicola Asuni
1472 1472
 	 * @public static
1473 1473
 	 */
1474
-	public static function getUserPermissionCode($permissions, $mode=0) {
1474
+	public static function getUserPermissionCode($permissions, $mode = 0) {
1475 1475
 		$options = array(
1476 1476
 			'owner' => 2, // bit 2 -- inverted logic: cleared by default
1477 1477
 			'print' => 4, // bit 3
@@ -1480,7 +1480,7 @@  discard block
 block discarded – undo
1480 1480
 			'annot-forms' => 32, // bit 6
1481 1481
 			'fill-forms' => 256, // bit 9
1482 1482
 			'extract' => 512, // bit 10
1483
-			'assemble' => 1024,// bit 11
1483
+			'assemble' => 1024, // bit 11
1484 1484
 			'print-high' => 2048 // bit 12
1485 1485
 			);
1486 1486
 		$protection = 2147422012; // 32 bit: (01111111 11111111 00001111 00111100)
@@ -1511,7 +1511,7 @@  discard block
 block discarded – undo
1511 1511
 	public static function convertHexStringToString($bs) {
1512 1512
 		$string = ''; // string to be returned
1513 1513
 		$bslength = strlen($bs);
1514
-		if (($bslength % 2) != 0) {
1514
+		if (($bslength%2) != 0) {
1515 1515
 			// padding
1516 1516
 			$bs .= '0';
1517 1517
 			++$bslength;
@@ -1588,7 +1588,7 @@  discard block
 block discarded – undo
1588 1588
 	 * @since 4.8.000 (2009-09-06)
1589 1589
 	 * @public static
1590 1590
 	 */
1591
-	public static function getAnnotOptFromJSProp($prop, &$spot_colors, $rtl=false) {
1591
+	public static function getAnnotOptFromJSProp($prop, &$spot_colors, $rtl = false) {
1592 1592
 		if (isset($prop['aopt']) AND is_array($prop['aopt'])) {
1593 1593
 			// the annotation options area lready defined
1594 1594
 			return $prop['aopt'];
@@ -1610,7 +1610,7 @@  discard block
 block discarded – undo
1610 1610
 					break;
1611 1611
 				}
1612 1612
 				default: {
1613
-					$opt['q'] = ($rtl)?2:0;
1613
+					$opt['q'] = ($rtl) ? 2 : 0;
1614 1614
 					break;
1615 1615
 				}
1616 1616
 			}
@@ -2074,10 +2074,10 @@  discard block
 block discarded – undo
2074 2074
 	 * @see setHtmlVSpace()
2075 2075
 	 * @public static
2076 2076
 	 */
2077
-	public static function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='', &$tagvspaces) {
2077
+	public static function fixHTMLCode($html, $default_css = '', $tagvs = '', $tidy_options = '', &$tagvspaces) {
2078 2078
 		// configure parameters for HTML Tidy
2079 2079
 		if ($tidy_options === '') {
2080
-			$tidy_options = array (
2080
+			$tidy_options = array(
2081 2081
 				'clean' => 1,
2082 2082
 				'drop-empty-paras' => 0,
2083 2083
 				'drop-proprietary-attributes' => 1,
@@ -2308,7 +2308,7 @@  discard block
 block discarded – undo
2308 2308
 			$selectors = $dom[($dom[$key]['parent'])]['csssel'];
2309 2309
 		}
2310 2310
 		// get all styles that apply
2311
-		foreach($css as $selector => $style) {
2311
+		foreach ($css as $selector => $style) {
2312 2312
 			$pos = strpos($selector, ' ');
2313 2313
 			// get specificity
2314 2314
 			$specificity = substr($selector, 0, $pos);
@@ -2444,9 +2444,9 @@  discard block
 block discarded – undo
2444 2444
 	 */
2445 2445
 	public static function revstrpos($haystack, $needle, $offset = 0) {
2446 2446
 		$length = strlen($haystack);
2447
-		$offset = ($offset > 0)?($length - $offset):abs($offset);
2447
+		$offset = ($offset > 0) ? ($length - $offset) : abs($offset);
2448 2448
 		$pos = strpos(strrev($haystack), strrev($needle), $offset);
2449
-		return ($pos === false)?false:($length - $pos - strlen($needle));
2449
+		return ($pos === false) ? false : ($length - $pos - strlen($needle));
2450 2450
 	}
2451 2451
 
2452 2452
 	/**
@@ -2482,7 +2482,7 @@  discard block
 block discarded – undo
2482 2482
 		$patterns_array = preg_split('/[\s]+/', $data);
2483 2483
 		// create new language array of patterns
2484 2484
 		$patterns = array();
2485
-		foreach($patterns_array as $val) {
2485
+		foreach ($patterns_array as $val) {
2486 2486
 			if (!TCPDF_STATIC::empty_string($val)) {
2487 2487
 				$val = trim($val);
2488 2488
 				$val = str_replace('\'', '\\\'', $val);
@@ -2514,9 +2514,9 @@  discard block
 block discarded – undo
2514 2514
 	 * @since 5.0.000 (2010-04-30)
2515 2515
 	 * @public static
2516 2516
 	 */
2517
-	public static function getPathPaintOperator($style, $default='S') {
2517
+	public static function getPathPaintOperator($style, $default = 'S') {
2518 2518
 		$op = '';
2519
-		switch($style) {
2519
+		switch ($style) {
2520 2520
 			case 'S':
2521 2521
 			case 'D': {
2522 2522
 				$op = 'S';
@@ -2595,12 +2595,12 @@  discard block
 block discarded – undo
2595 2595
 	 */
2596 2596
 	public static function getTransformationMatrixProduct($ta, $tb) {
2597 2597
 		$tm = array();
2598
-		$tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]);
2599
-		$tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]);
2600
-		$tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]);
2601
-		$tm[3] = ($ta[1] * $tb[2]) + ($ta[3] * $tb[3]);
2602
-		$tm[4] = ($ta[0] * $tb[4]) + ($ta[2] * $tb[5]) + $ta[4];
2603
-		$tm[5] = ($ta[1] * $tb[4]) + ($ta[3] * $tb[5]) + $ta[5];
2598
+		$tm[0] = ($ta[0]*$tb[0]) + ($ta[2]*$tb[1]);
2599
+		$tm[1] = ($ta[1]*$tb[0]) + ($ta[3]*$tb[1]);
2600
+		$tm[2] = ($ta[0]*$tb[2]) + ($ta[2]*$tb[3]);
2601
+		$tm[3] = ($ta[1]*$tb[2]) + ($ta[3]*$tb[3]);
2602
+		$tm[4] = ($ta[0]*$tb[4]) + ($ta[2]*$tb[5]) + $ta[4];
2603
+		$tm[5] = ($ta[1]*$tb[4]) + ($ta[3]*$tb[5]) + $ta[5];
2604 2604
 		return $tm;
2605 2605
 	}
2606 2606
 
@@ -2666,8 +2666,8 @@  discard block
 block discarded – undo
2666 2666
 								$b = sin($ang);
2667 2667
 								$c = -$b;
2668 2668
 								$d = $a;
2669
-								$e = ($x * (1 - $a)) - ($y * $c);
2670
-								$f = ($y * (1 - $d)) - ($x * $b);
2669
+								$e = ($x*(1 - $a)) - ($y*$c);
2670
+								$f = ($y*(1 - $d)) - ($x*$b);
2671 2671
 							} elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
2672 2672
 								$ang = deg2rad($regs[1]);
2673 2673
 								$a = cos($ang);
@@ -2710,14 +2710,14 @@  discard block
 block discarded – undo
2710 2710
 	 * @public static
2711 2711
 	 */
2712 2712
 	public static function getVectorsAngle($x1, $y1, $x2, $y2) {
2713
-		$dprod = ($x1 * $x2) + ($y1 * $y2);
2714
-		$dist1 = sqrt(($x1 * $x1) + ($y1 * $y1));
2715
-		$dist2 = sqrt(($x2 * $x2) + ($y2 * $y2));
2716
-		$angle = acos($dprod / ($dist1 * $dist2));
2713
+		$dprod = ($x1*$x2) + ($y1*$y2);
2714
+		$dist1 = sqrt(($x1*$x1) + ($y1*$y1));
2715
+		$dist2 = sqrt(($x2*$x2) + ($y2*$y2));
2716
+		$angle = acos($dprod/($dist1*$dist2));
2717 2717
 		if (is_nan($angle)) {
2718 2718
 			$angle = M_PI;
2719 2719
 		}
2720
-		if ((($x1 * $y2) - ($x2 * $y1)) < 0) {
2720
+		if ((($x1*$y2) - ($x2*$y1)) < 0) {
2721 2721
 			$angle *= -1;
2722 2722
 		}
2723 2723
 		return $angle;
@@ -2736,7 +2736,7 @@  discard block
 block discarded – undo
2736 2736
 	 * @since 6.0.023
2737 2737
 	 * @public static
2738 2738
 	 */
2739
-	public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $flags=NULL) {
2739
+	public static function pregSplit($pattern, $modifiers, $subject, $limit = NULL, $flags = NULL) {
2740 2740
 		// the bug only happens on PHP 5.2 when using the u modifier
2741 2741
 		if ((strpos($modifiers, 'u') === FALSE) OR (count(preg_split('//u', "\n\t", -1, PREG_SPLIT_NO_EMPTY)) == 2)) {
2742 2742
 			return preg_split($pattern.$modifiers, $subject, $limit, $flags);
Please login to merge, or discard this patch.
phpmyfaq/inc/libs/tcpdf/tcpdf_barcodes_1d.php 3 patches
Doc Comments   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	 * @param $w (int) Width of a single bar element in pixels.
168 168
 	 * @param $h (int) Height of a single bar element in pixels.
169 169
 	 * @param $color (array) RGB (0-255) foreground color for bar elements (background is transparent).
170
- 	 * @return image or false in case of error.
170
+ 	 * @return false|null or false in case of error.
171 171
  	 * @public
172 172
 	 */
173 173
 	public function getBarcodePNG($w=2, $h=30, $color=array(0,0,0)) {
@@ -459,8 +459,8 @@  discard block
 block discarded – undo
459 459
 
460 460
 	/**
461 461
 	 * Encode a string to be used for CODE 39 Extended mode.
462
-	 * @param $code (string) code to represent.
463
-	 * @return encoded string.
462
+	 * @param string $code (string) code to represent.
463
+	 * @return false|string string.
464 464
 	 * @protected
465 465
 	 */
466 466
 	protected function encode_code39_ext($code) {
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 	/**
512 512
 	 * Calculate CODE 39 checksum (modulo 43).
513 513
 	 * @param $code (string) code to represent.
514
-	 * @return char checksum.
514
+	 * @return string checksum.
515 515
 	 * @protected
516 516
 	 */
517 517
 	protected function checksum_code39($code) {
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
 
662 662
 	/**
663 663
 	 * Calculate CODE 93 checksum (modulo 47).
664
-	 * @param $code (string) code to represent.
664
+	 * @param string $code (string) code to represent.
665 665
 	 * @return string checksum code.
666 666
 	 * @protected
667 667
 	 */
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
 
836 836
 	/**
837 837
 	 * Convert binary barcode sequence to TCPDF barcode array.
838
-	 * @param $seq (string) barcode as binary sequence.
838
+	 * @param string $seq (string) barcode as binary sequence.
839 839
 	 * @param $bararray (array) barcode array.
840 840
 	 * òparam array $bararray TCPDF barcode array to fill up
841 841
 	 * @return array barcode representation.
@@ -2153,7 +2153,7 @@  discard block
 block discarded – undo
2153 2153
 	/**
2154 2154
 	 * Convert large integer number to hexadecimal representation.
2155 2155
 	 * (requires PHP bcmath extension)
2156
-	 * @param $number (string) number to convert specified as a string
2156
+	 * @param string $number (string) number to convert specified as a string
2157 2157
 	 * @return string hexadecimal representation
2158 2158
 	 */
2159 2159
 	public function dec_to_hex($number) {
@@ -2177,7 +2177,7 @@  discard block
 block discarded – undo
2177 2177
 	/**
2178 2178
 	 * Convert large hexadecimal number to decimal representation (string).
2179 2179
 	 * (requires PHP bcmath extension)
2180
-	 * @param $hex (string) hexadecimal number to convert specified as a string
2180
+	 * @param string $hex (string) hexadecimal number to convert specified as a string
2181 2181
 	 * @return string hexadecimal representation
2182 2182
 	 */
2183 2183
 	public function hex_to_dec($hex) {
@@ -2229,7 +2229,7 @@  discard block
 block discarded – undo
2229 2229
 
2230 2230
 	/**
2231 2231
 	 * Reverse unsigned short value
2232
-	 * @param $num (int) value to reversr
2232
+	 * @param integer $num (int) value to reversr
2233 2233
 	 * @return int reversed value
2234 2234
 	 * @protected
2235 2235
 	 */
@@ -2245,8 +2245,8 @@  discard block
 block discarded – undo
2245 2245
 
2246 2246
 	/**
2247 2247
 	 * generate Nof13 tables used for Intelligent Mail Barcode
2248
-	 * @param $n (int) is the type of table: 2 for 2of13 table, 5 for 5of13table
2249
-	 * @param $size (int) size of table (78 for n=2 and 1287 for n=5)
2248
+	 * @param integer $n (int) is the type of table: 2 for 2of13 table, 5 for 5of13table
2249
+	 * @param integer $size (int) size of table (78 for n=2 and 1287 for n=5)
2250 2250
 	 * @return array requested table
2251 2251
 	 * @protected
2252 2252
 	 */
Please login to merge, or discard this patch.
Indentation   +2196 added lines, -2196 removed lines patch added patch discarded remove patch
@@ -49,2237 +49,2237 @@
 block discarded – undo
49 49
  */
50 50
 class TCPDFBarcode {
51 51
 
52
-	/**
53
-	 * Array representation of barcode.
54
-	 * @protected
55
-	 */
56
-	protected $barcode_array;
52
+    /**
53
+     * Array representation of barcode.
54
+     * @protected
55
+     */
56
+    protected $barcode_array;
57 57
 
58
-	/**
59
-	 * This is the class constructor.
60
-	 * Return an array representations for common 1D barcodes:<ul>
61
-	 * <li>$arrcode['code'] code to be printed on text label</li>
62
-	 * <li>$arrcode['maxh'] max barcode height</li>
63
-	 * <li>$arrcode['maxw'] max barcode width</li>
64
-	 * <li>$arrcode['bcode'][$k] single bar or space in $k position</li>
65
-	 * <li>$arrcode['bcode'][$k]['t'] bar type: true = bar, false = space.</li>
66
-	 * <li>$arrcode['bcode'][$k]['w'] bar width in units.</li>
67
-	 * <li>$arrcode['bcode'][$k]['h'] bar height in units.</li>
68
-	 * <li>$arrcode['bcode'][$k]['p'] bar top position (0 = top, 1 = middle)</li></ul>
69
-	 * @param $code (string) code to print
70
- 	 * @param $type (string) type of barcode: <ul><li>C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.</li><li>C39+ : CODE 39 with checksum</li><li>C39E : CODE 39 EXTENDED</li><li>C39E+ : CODE 39 EXTENDED + CHECKSUM</li><li>C93 : CODE 93 - USS-93</li><li>S25 : Standard 2 of 5</li><li>S25+ : Standard 2 of 5 + CHECKSUM</li><li>I25 : Interleaved 2 of 5</li><li>I25+ : Interleaved 2 of 5 + CHECKSUM</li><li>C128 : CODE 128</li><li>C128A : CODE 128 A</li><li>C128B : CODE 128 B</li><li>C128C : CODE 128 C</li><li>EAN2 : 2-Digits UPC-Based Extention</li><li>EAN5 : 5-Digits UPC-Based Extention</li><li>EAN8 : EAN 8</li><li>EAN13 : EAN 13</li><li>UPCA : UPC-A</li><li>UPCE : UPC-E</li><li>MSI : MSI (Variation of Plessey code)</li><li>MSI+ : MSI + CHECKSUM (modulo 11)</li><li>POSTNET : POSTNET</li><li>PLANET : PLANET</li><li>RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)</li><li>KIX : KIX (Klant index - Customer index)</li><li>IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200</li><li>CODABAR : CODABAR</li><li>CODE11 : CODE 11</li><li>PHARMA : PHARMACODE</li><li>PHARMA2T : PHARMACODE TWO-TRACKS</li></ul>
71
- 	 * @public
72
-	 */
73
-	public function __construct($code, $type) {
74
-		$this->setBarcode($code, $type);
75
-	}
58
+    /**
59
+     * This is the class constructor.
60
+     * Return an array representations for common 1D barcodes:<ul>
61
+     * <li>$arrcode['code'] code to be printed on text label</li>
62
+     * <li>$arrcode['maxh'] max barcode height</li>
63
+     * <li>$arrcode['maxw'] max barcode width</li>
64
+     * <li>$arrcode['bcode'][$k] single bar or space in $k position</li>
65
+     * <li>$arrcode['bcode'][$k]['t'] bar type: true = bar, false = space.</li>
66
+     * <li>$arrcode['bcode'][$k]['w'] bar width in units.</li>
67
+     * <li>$arrcode['bcode'][$k]['h'] bar height in units.</li>
68
+     * <li>$arrcode['bcode'][$k]['p'] bar top position (0 = top, 1 = middle)</li></ul>
69
+     * @param $code (string) code to print
70
+     * @param $type (string) type of barcode: <ul><li>C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.</li><li>C39+ : CODE 39 with checksum</li><li>C39E : CODE 39 EXTENDED</li><li>C39E+ : CODE 39 EXTENDED + CHECKSUM</li><li>C93 : CODE 93 - USS-93</li><li>S25 : Standard 2 of 5</li><li>S25+ : Standard 2 of 5 + CHECKSUM</li><li>I25 : Interleaved 2 of 5</li><li>I25+ : Interleaved 2 of 5 + CHECKSUM</li><li>C128 : CODE 128</li><li>C128A : CODE 128 A</li><li>C128B : CODE 128 B</li><li>C128C : CODE 128 C</li><li>EAN2 : 2-Digits UPC-Based Extention</li><li>EAN5 : 5-Digits UPC-Based Extention</li><li>EAN8 : EAN 8</li><li>EAN13 : EAN 13</li><li>UPCA : UPC-A</li><li>UPCE : UPC-E</li><li>MSI : MSI (Variation of Plessey code)</li><li>MSI+ : MSI + CHECKSUM (modulo 11)</li><li>POSTNET : POSTNET</li><li>PLANET : PLANET</li><li>RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)</li><li>KIX : KIX (Klant index - Customer index)</li><li>IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200</li><li>CODABAR : CODABAR</li><li>CODE11 : CODE 11</li><li>PHARMA : PHARMACODE</li><li>PHARMA2T : PHARMACODE TWO-TRACKS</li></ul>
71
+     * @public
72
+     */
73
+    public function __construct($code, $type) {
74
+        $this->setBarcode($code, $type);
75
+    }
76 76
 
77
-	/**
78
-	 * Return an array representations of barcode.
79
- 	 * @return array
80
- 	 * @public
81
-	 */
82
-	public function getBarcodeArray() {
83
-		return $this->barcode_array;
84
-	}
77
+    /**
78
+     * Return an array representations of barcode.
79
+     * @return array
80
+     * @public
81
+     */
82
+    public function getBarcodeArray() {
83
+        return $this->barcode_array;
84
+    }
85 85
 
86
-	/**
87
-	 * Send barcode as SVG image object to the standard output.
88
-	 * @param $w (int) Minimum width of a single bar in user units.
89
-	 * @param $h (int) Height of barcode in user units.
90
-	 * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
91
- 	 * @public
92
-	 */
93
-	public function getBarcodeSVG($w=2, $h=30, $color='black') {
94
-		// send headers
95
-		$code = $this->getBarcodeSVGcode($w, $h, $color);
96
-		header('Content-Type: application/svg+xml');
97
-		header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
98
-		header('Pragma: public');
99
-		header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
100
-		header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
101
-		header('Content-Disposition: inline; filename="'.md5($code).'.svg";');
102
-		//header('Content-Length: '.strlen($code));
103
-		echo $code;
104
-	}
86
+    /**
87
+     * Send barcode as SVG image object to the standard output.
88
+     * @param $w (int) Minimum width of a single bar in user units.
89
+     * @param $h (int) Height of barcode in user units.
90
+     * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
91
+     * @public
92
+     */
93
+    public function getBarcodeSVG($w=2, $h=30, $color='black') {
94
+        // send headers
95
+        $code = $this->getBarcodeSVGcode($w, $h, $color);
96
+        header('Content-Type: application/svg+xml');
97
+        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
98
+        header('Pragma: public');
99
+        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
100
+        header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
101
+        header('Content-Disposition: inline; filename="'.md5($code).'.svg";');
102
+        //header('Content-Length: '.strlen($code));
103
+        echo $code;
104
+    }
105 105
 
106
-	/**
107
-	 * Return a SVG string representation of barcode.
108
-	 * @param $w (int) Minimum width of a single bar in user units.
109
-	 * @param $h (int) Height of barcode in user units.
110
-	 * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
111
- 	 * @return string SVG code.
112
- 	 * @public
113
-	 */
114
-	public function getBarcodeSVGcode($w=2, $h=30, $color='black') {
115
-		// replace table for special characters
116
-		$repstr = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
117
-		$svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n";
118
-		$svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'."\n";
119
-		$svg .= '<svg width="'.round(($this->barcode_array['maxw'] * $w), 3).'" height="'.$h.'" version="1.1" xmlns="http://www.w3.org/2000/svg">'."\n";
120
-		$svg .= "\t".'<desc>'.strtr($this->barcode_array['code'], $repstr).'</desc>'."\n";
121
-		$svg .= "\t".'<g id="bars" fill="'.$color.'" stroke="none">'."\n";
122
-		// print bars
123
-		$x = 0;
124
-		foreach ($this->barcode_array['bcode'] as $k => $v) {
125
-			$bw = round(($v['w'] * $w), 3);
126
-			$bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3);
127
-			if ($v['t']) {
128
-				$y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3);
129
-				// draw a vertical bar
130
-				$svg .= "\t\t".'<rect x="'.$x.'" y="'.$y.'" width="'.$bw.'" height="'.$bh.'" />'."\n";
131
-			}
132
-			$x += $bw;
133
-		}
134
-		$svg .= "\t".'</g>'."\n";
135
-		$svg .= '</svg>'."\n";
136
-		return $svg;
137
-	}
106
+    /**
107
+     * Return a SVG string representation of barcode.
108
+     * @param $w (int) Minimum width of a single bar in user units.
109
+     * @param $h (int) Height of barcode in user units.
110
+     * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
111
+     * @return string SVG code.
112
+     * @public
113
+     */
114
+    public function getBarcodeSVGcode($w=2, $h=30, $color='black') {
115
+        // replace table for special characters
116
+        $repstr = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
117
+        $svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n";
118
+        $svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'."\n";
119
+        $svg .= '<svg width="'.round(($this->barcode_array['maxw'] * $w), 3).'" height="'.$h.'" version="1.1" xmlns="http://www.w3.org/2000/svg">'."\n";
120
+        $svg .= "\t".'<desc>'.strtr($this->barcode_array['code'], $repstr).'</desc>'."\n";
121
+        $svg .= "\t".'<g id="bars" fill="'.$color.'" stroke="none">'."\n";
122
+        // print bars
123
+        $x = 0;
124
+        foreach ($this->barcode_array['bcode'] as $k => $v) {
125
+            $bw = round(($v['w'] * $w), 3);
126
+            $bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3);
127
+            if ($v['t']) {
128
+                $y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3);
129
+                // draw a vertical bar
130
+                $svg .= "\t\t".'<rect x="'.$x.'" y="'.$y.'" width="'.$bw.'" height="'.$bh.'" />'."\n";
131
+            }
132
+            $x += $bw;
133
+        }
134
+        $svg .= "\t".'</g>'."\n";
135
+        $svg .= '</svg>'."\n";
136
+        return $svg;
137
+    }
138 138
 
139
-	/**
140
-	 * Return an HTML representation of barcode.
141
-	 * @param $w (int) Width of a single bar element in pixels.
142
-	 * @param $h (int) Height of a single bar element in pixels.
143
-	 * @param $color (string) Foreground color for bar elements (background is transparent).
144
- 	 * @return string HTML code.
145
- 	 * @public
146
-	 */
147
-	public function getBarcodeHTML($w=2, $h=30, $color='black') {
148
-		$html = '<div style="font-size:0;position:relative;width:'.($this->barcode_array['maxw'] * $w).'px;height:'.($h).'px;">'."\n";
149
-		// print bars
150
-		$x = 0;
151
-		foreach ($this->barcode_array['bcode'] as $k => $v) {
152
-			$bw = round(($v['w'] * $w), 3);
153
-			$bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3);
154
-			if ($v['t']) {
155
-				$y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3);
156
-				// draw a vertical bar
157
-				$html .= '<div style="background-color:'.$color.';width:'.$bw.'px;height:'.$bh.'px;position:absolute;left:'.$x.'px;top:'.$y.'px;">&nbsp;</div>'."\n";
158
-			}
159
-			$x += $bw;
160
-		}
161
-		$html .= '</div>'."\n";
162
-		return $html;
163
-	}
139
+    /**
140
+     * Return an HTML representation of barcode.
141
+     * @param $w (int) Width of a single bar element in pixels.
142
+     * @param $h (int) Height of a single bar element in pixels.
143
+     * @param $color (string) Foreground color for bar elements (background is transparent).
144
+     * @return string HTML code.
145
+     * @public
146
+     */
147
+    public function getBarcodeHTML($w=2, $h=30, $color='black') {
148
+        $html = '<div style="font-size:0;position:relative;width:'.($this->barcode_array['maxw'] * $w).'px;height:'.($h).'px;">'."\n";
149
+        // print bars
150
+        $x = 0;
151
+        foreach ($this->barcode_array['bcode'] as $k => $v) {
152
+            $bw = round(($v['w'] * $w), 3);
153
+            $bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3);
154
+            if ($v['t']) {
155
+                $y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3);
156
+                // draw a vertical bar
157
+                $html .= '<div style="background-color:'.$color.';width:'.$bw.'px;height:'.$bh.'px;position:absolute;left:'.$x.'px;top:'.$y.'px;">&nbsp;</div>'."\n";
158
+            }
159
+            $x += $bw;
160
+        }
161
+        $html .= '</div>'."\n";
162
+        return $html;
163
+    }
164 164
 
165
-	/**
166
-	 * Return a PNG image representation of barcode (requires GD or Imagick library).
167
-	 * @param $w (int) Width of a single bar element in pixels.
168
-	 * @param $h (int) Height of a single bar element in pixels.
169
-	 * @param $color (array) RGB (0-255) foreground color for bar elements (background is transparent).
170
- 	 * @return image or false in case of error.
171
- 	 * @public
172
-	 */
173
-	public function getBarcodePNG($w=2, $h=30, $color=array(0,0,0)) {
174
-		// calculate image size
175
-		$width = ($this->barcode_array['maxw'] * $w);
176
-		$height = $h;
177
-		if (function_exists('imagecreate')) {
178
-			// GD library
179
-			$imagick = false;
180
-			$png = imagecreate($width, $height);
181
-			$bgcol = imagecolorallocate($png, 255, 255, 255);
182
-			imagecolortransparent($png, $bgcol);
183
-			$fgcol = imagecolorallocate($png, $color[0], $color[1], $color[2]);
184
-		} elseif (extension_loaded('imagick')) {
185
-			$imagick = true;
186
-			$bgcol = new imagickpixel('rgb(255,255,255');
187
-			$fgcol = new imagickpixel('rgb('.$color[0].','.$color[1].','.$color[2].')');
188
-			$png = new Imagick();
189
-			$png->newImage($width, $height, 'none', 'png');
190
-			$bar = new imagickdraw();
191
-			$bar->setfillcolor($fgcol);
192
-		} else {
193
-			return false;
194
-		}
195
-		// print bars
196
-		$x = 0;
197
-		foreach ($this->barcode_array['bcode'] as $k => $v) {
198
-			$bw = round(($v['w'] * $w), 3);
199
-			$bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3);
200
-			if ($v['t']) {
201
-				$y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3);
202
-				// draw a vertical bar
203
-				if ($imagick) {
204
-					$bar->rectangle($x, $y, ($x + $bw - 1), ($y + $bh - 1));
205
-				} else {
206
-					imagefilledrectangle($png, $x, $y, ($x + $bw - 1), ($y + $bh - 1), $fgcol);
207
-				}
208
-			}
209
-			$x += $bw;
210
-		}
211
-		// send headers
212
-		header('Content-Type: image/png');
213
-		header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
214
-		header('Pragma: public');
215
-		header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
216
-		header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
217
-		if ($imagick) {
218
-			$png->drawimage($bar);
219
-			echo $png;
220
-		} else {
221
-			imagepng($png);
222
-			imagedestroy($png);
223
-		}
224
-	}
165
+    /**
166
+     * Return a PNG image representation of barcode (requires GD or Imagick library).
167
+     * @param $w (int) Width of a single bar element in pixels.
168
+     * @param $h (int) Height of a single bar element in pixels.
169
+     * @param $color (array) RGB (0-255) foreground color for bar elements (background is transparent).
170
+     * @return image or false in case of error.
171
+     * @public
172
+     */
173
+    public function getBarcodePNG($w=2, $h=30, $color=array(0,0,0)) {
174
+        // calculate image size
175
+        $width = ($this->barcode_array['maxw'] * $w);
176
+        $height = $h;
177
+        if (function_exists('imagecreate')) {
178
+            // GD library
179
+            $imagick = false;
180
+            $png = imagecreate($width, $height);
181
+            $bgcol = imagecolorallocate($png, 255, 255, 255);
182
+            imagecolortransparent($png, $bgcol);
183
+            $fgcol = imagecolorallocate($png, $color[0], $color[1], $color[2]);
184
+        } elseif (extension_loaded('imagick')) {
185
+            $imagick = true;
186
+            $bgcol = new imagickpixel('rgb(255,255,255');
187
+            $fgcol = new imagickpixel('rgb('.$color[0].','.$color[1].','.$color[2].')');
188
+            $png = new Imagick();
189
+            $png->newImage($width, $height, 'none', 'png');
190
+            $bar = new imagickdraw();
191
+            $bar->setfillcolor($fgcol);
192
+        } else {
193
+            return false;
194
+        }
195
+        // print bars
196
+        $x = 0;
197
+        foreach ($this->barcode_array['bcode'] as $k => $v) {
198
+            $bw = round(($v['w'] * $w), 3);
199
+            $bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3);
200
+            if ($v['t']) {
201
+                $y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3);
202
+                // draw a vertical bar
203
+                if ($imagick) {
204
+                    $bar->rectangle($x, $y, ($x + $bw - 1), ($y + $bh - 1));
205
+                } else {
206
+                    imagefilledrectangle($png, $x, $y, ($x + $bw - 1), ($y + $bh - 1), $fgcol);
207
+                }
208
+            }
209
+            $x += $bw;
210
+        }
211
+        // send headers
212
+        header('Content-Type: image/png');
213
+        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
214
+        header('Pragma: public');
215
+        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
216
+        header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
217
+        if ($imagick) {
218
+            $png->drawimage($bar);
219
+            echo $png;
220
+        } else {
221
+            imagepng($png);
222
+            imagedestroy($png);
223
+        }
224
+    }
225 225
 
226
-	/**
227
-	 * Set the barcode.
228
-	 * @param $code (string) code to print
229
- 	 * @param $type (string) type of barcode: <ul><li>C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.</li><li>C39+ : CODE 39 with checksum</li><li>C39E : CODE 39 EXTENDED</li><li>C39E+ : CODE 39 EXTENDED + CHECKSUM</li><li>C93 : CODE 93 - USS-93</li><li>S25 : Standard 2 of 5</li><li>S25+ : Standard 2 of 5 + CHECKSUM</li><li>I25 : Interleaved 2 of 5</li><li>I25+ : Interleaved 2 of 5 + CHECKSUM</li><li>C128 : CODE 128</li><li>C128A : CODE 128 A</li><li>C128B : CODE 128 B</li><li>C128C : CODE 128 C</li><li>EAN2 : 2-Digits UPC-Based Extention</li><li>EAN5 : 5-Digits UPC-Based Extention</li><li>EAN8 : EAN 8</li><li>EAN13 : EAN 13</li><li>UPCA : UPC-A</li><li>UPCE : UPC-E</li><li>MSI : MSI (Variation of Plessey code)</li><li>MSI+ : MSI + CHECKSUM (modulo 11)</li><li>POSTNET : POSTNET</li><li>PLANET : PLANET</li><li>RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)</li><li>KIX : KIX (Klant index - Customer index)</li><li>IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200</li><li>CODABAR : CODABAR</li><li>CODE11 : CODE 11</li><li>PHARMA : PHARMACODE</li><li>PHARMA2T : PHARMACODE TWO-TRACKS</li></ul>
230
- 	 * @return array barcode array
231
- 	 * @public
232
-	 */
233
-	public function setBarcode($code, $type) {
234
-		switch (strtoupper($type)) {
235
-			case 'C39': { // CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
236
-				$arrcode = $this->barcode_code39($code, false, false);
237
-				break;
238
-			}
239
-			case 'C39+': { // CODE 39 with checksum
240
-				$arrcode = $this->barcode_code39($code, false, true);
241
-				break;
242
-			}
243
-			case 'C39E': { // CODE 39 EXTENDED
244
-				$arrcode = $this->barcode_code39($code, true, false);
245
-				break;
246
-			}
247
-			case 'C39E+': { // CODE 39 EXTENDED + CHECKSUM
248
-				$arrcode = $this->barcode_code39($code, true, true);
249
-				break;
250
-			}
251
-			case 'C93': { // CODE 93 - USS-93
252
-				$arrcode = $this->barcode_code93($code);
253
-				break;
254
-			}
255
-			case 'S25': { // Standard 2 of 5
256
-				$arrcode = $this->barcode_s25($code, false);
257
-				break;
258
-			}
259
-			case 'S25+': { // Standard 2 of 5 + CHECKSUM
260
-				$arrcode = $this->barcode_s25($code, true);
261
-				break;
262
-			}
263
-			case 'I25': { // Interleaved 2 of 5
264
-				$arrcode = $this->barcode_i25($code, false);
265
-				break;
266
-			}
267
-			case 'I25+': { // Interleaved 2 of 5 + CHECKSUM
268
-				$arrcode = $this->barcode_i25($code, true);
269
-				break;
270
-			}
271
-			case 'C128': { // CODE 128
272
-				$arrcode = $this->barcode_c128($code, '');
273
-				break;
274
-			}
275
-			case 'C128A': { // CODE 128 A
276
-				$arrcode = $this->barcode_c128($code, 'A');
277
-				break;
278
-			}
279
-			case 'C128B': { // CODE 128 B
280
-				$arrcode = $this->barcode_c128($code, 'B');
281
-				break;
282
-			}
283
-			case 'C128C': { // CODE 128 C
284
-				$arrcode = $this->barcode_c128($code, 'C');
285
-				break;
286
-			}
287
-			case 'EAN2': { // 2-Digits UPC-Based Extention
288
-				$arrcode = $this->barcode_eanext($code, 2);
289
-				break;
290
-			}
291
-			case 'EAN5': { // 5-Digits UPC-Based Extention
292
-				$arrcode = $this->barcode_eanext($code, 5);
293
-				break;
294
-			}
295
-			case 'EAN8': { // EAN 8
296
-				$arrcode = $this->barcode_eanupc($code, 8);
297
-				break;
298
-			}
299
-			case 'EAN13': { // EAN 13
300
-				$arrcode = $this->barcode_eanupc($code, 13);
301
-				break;
302
-			}
303
-			case 'UPCA': { // UPC-A
304
-				$arrcode = $this->barcode_eanupc($code, 12);
305
-				break;
306
-			}
307
-			case 'UPCE': { // UPC-E
308
-				$arrcode = $this->barcode_eanupc($code, 6);
309
-				break;
310
-			}
311
-			case 'MSI': { // MSI (Variation of Plessey code)
312
-				$arrcode = $this->barcode_msi($code, false);
313
-				break;
314
-			}
315
-			case 'MSI+': { // MSI + CHECKSUM (modulo 11)
316
-				$arrcode = $this->barcode_msi($code, true);
317
-				break;
318
-			}
319
-			case 'POSTNET': { // POSTNET
320
-				$arrcode = $this->barcode_postnet($code, false);
321
-				break;
322
-			}
323
-			case 'PLANET': { // PLANET
324
-				$arrcode = $this->barcode_postnet($code, true);
325
-				break;
326
-			}
327
-			case 'RMS4CC': { // RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
328
-				$arrcode = $this->barcode_rms4cc($code, false);
329
-				break;
330
-			}
331
-			case 'KIX': { // KIX (Klant index - Customer index)
332
-				$arrcode = $this->barcode_rms4cc($code, true);
333
-				break;
334
-			}
335
-			case 'IMB': { // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
336
-				$arrcode = $this->barcode_imb($code);
337
-				break;
338
-			}
339
-			case 'CODABAR': { // CODABAR
340
-				$arrcode = $this->barcode_codabar($code);
341
-				break;
342
-			}
343
-			case 'CODE11': { // CODE 11
344
-				$arrcode = $this->barcode_code11($code);
345
-				break;
346
-			}
347
-			case 'PHARMA': { // PHARMACODE
348
-				$arrcode = $this->barcode_pharmacode($code);
349
-				break;
350
-			}
351
-			case 'PHARMA2T': { // PHARMACODE TWO-TRACKS
352
-				$arrcode = $this->barcode_pharmacode2t($code);
353
-				break;
354
-			}
355
-			default: {
356
-				$this->barcode_array = false;
357
-				$arrcode = false;
358
-				break;
359
-			}
360
-		}
361
-		$this->barcode_array = $arrcode;
362
-	}
226
+    /**
227
+     * Set the barcode.
228
+     * @param $code (string) code to print
229
+     * @param $type (string) type of barcode: <ul><li>C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.</li><li>C39+ : CODE 39 with checksum</li><li>C39E : CODE 39 EXTENDED</li><li>C39E+ : CODE 39 EXTENDED + CHECKSUM</li><li>C93 : CODE 93 - USS-93</li><li>S25 : Standard 2 of 5</li><li>S25+ : Standard 2 of 5 + CHECKSUM</li><li>I25 : Interleaved 2 of 5</li><li>I25+ : Interleaved 2 of 5 + CHECKSUM</li><li>C128 : CODE 128</li><li>C128A : CODE 128 A</li><li>C128B : CODE 128 B</li><li>C128C : CODE 128 C</li><li>EAN2 : 2-Digits UPC-Based Extention</li><li>EAN5 : 5-Digits UPC-Based Extention</li><li>EAN8 : EAN 8</li><li>EAN13 : EAN 13</li><li>UPCA : UPC-A</li><li>UPCE : UPC-E</li><li>MSI : MSI (Variation of Plessey code)</li><li>MSI+ : MSI + CHECKSUM (modulo 11)</li><li>POSTNET : POSTNET</li><li>PLANET : PLANET</li><li>RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)</li><li>KIX : KIX (Klant index - Customer index)</li><li>IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200</li><li>CODABAR : CODABAR</li><li>CODE11 : CODE 11</li><li>PHARMA : PHARMACODE</li><li>PHARMA2T : PHARMACODE TWO-TRACKS</li></ul>
230
+     * @return array barcode array
231
+     * @public
232
+     */
233
+    public function setBarcode($code, $type) {
234
+        switch (strtoupper($type)) {
235
+            case 'C39': { // CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
236
+                $arrcode = $this->barcode_code39($code, false, false);
237
+                break;
238
+            }
239
+            case 'C39+': { // CODE 39 with checksum
240
+                $arrcode = $this->barcode_code39($code, false, true);
241
+                break;
242
+            }
243
+            case 'C39E': { // CODE 39 EXTENDED
244
+                $arrcode = $this->barcode_code39($code, true, false);
245
+                break;
246
+            }
247
+            case 'C39E+': { // CODE 39 EXTENDED + CHECKSUM
248
+                $arrcode = $this->barcode_code39($code, true, true);
249
+                break;
250
+            }
251
+            case 'C93': { // CODE 93 - USS-93
252
+                $arrcode = $this->barcode_code93($code);
253
+                break;
254
+            }
255
+            case 'S25': { // Standard 2 of 5
256
+                $arrcode = $this->barcode_s25($code, false);
257
+                break;
258
+            }
259
+            case 'S25+': { // Standard 2 of 5 + CHECKSUM
260
+                $arrcode = $this->barcode_s25($code, true);
261
+                break;
262
+            }
263
+            case 'I25': { // Interleaved 2 of 5
264
+                $arrcode = $this->barcode_i25($code, false);
265
+                break;
266
+            }
267
+            case 'I25+': { // Interleaved 2 of 5 + CHECKSUM
268
+                $arrcode = $this->barcode_i25($code, true);
269
+                break;
270
+            }
271
+            case 'C128': { // CODE 128
272
+                $arrcode = $this->barcode_c128($code, '');
273
+                break;
274
+            }
275
+            case 'C128A': { // CODE 128 A
276
+                $arrcode = $this->barcode_c128($code, 'A');
277
+                break;
278
+            }
279
+            case 'C128B': { // CODE 128 B
280
+                $arrcode = $this->barcode_c128($code, 'B');
281
+                break;
282
+            }
283
+            case 'C128C': { // CODE 128 C
284
+                $arrcode = $this->barcode_c128($code, 'C');
285
+                break;
286
+            }
287
+            case 'EAN2': { // 2-Digits UPC-Based Extention
288
+                $arrcode = $this->barcode_eanext($code, 2);
289
+                break;
290
+            }
291
+            case 'EAN5': { // 5-Digits UPC-Based Extention
292
+                $arrcode = $this->barcode_eanext($code, 5);
293
+                break;
294
+            }
295
+            case 'EAN8': { // EAN 8
296
+                $arrcode = $this->barcode_eanupc($code, 8);
297
+                break;
298
+            }
299
+            case 'EAN13': { // EAN 13
300
+                $arrcode = $this->barcode_eanupc($code, 13);
301
+                break;
302
+            }
303
+            case 'UPCA': { // UPC-A
304
+                $arrcode = $this->barcode_eanupc($code, 12);
305
+                break;
306
+            }
307
+            case 'UPCE': { // UPC-E
308
+                $arrcode = $this->barcode_eanupc($code, 6);
309
+                break;
310
+            }
311
+            case 'MSI': { // MSI (Variation of Plessey code)
312
+                $arrcode = $this->barcode_msi($code, false);
313
+                break;
314
+            }
315
+            case 'MSI+': { // MSI + CHECKSUM (modulo 11)
316
+                $arrcode = $this->barcode_msi($code, true);
317
+                break;
318
+            }
319
+            case 'POSTNET': { // POSTNET
320
+                $arrcode = $this->barcode_postnet($code, false);
321
+                break;
322
+            }
323
+            case 'PLANET': { // PLANET
324
+                $arrcode = $this->barcode_postnet($code, true);
325
+                break;
326
+            }
327
+            case 'RMS4CC': { // RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
328
+                $arrcode = $this->barcode_rms4cc($code, false);
329
+                break;
330
+            }
331
+            case 'KIX': { // KIX (Klant index - Customer index)
332
+                $arrcode = $this->barcode_rms4cc($code, true);
333
+                break;
334
+            }
335
+            case 'IMB': { // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
336
+                $arrcode = $this->barcode_imb($code);
337
+                break;
338
+            }
339
+            case 'CODABAR': { // CODABAR
340
+                $arrcode = $this->barcode_codabar($code);
341
+                break;
342
+            }
343
+            case 'CODE11': { // CODE 11
344
+                $arrcode = $this->barcode_code11($code);
345
+                break;
346
+            }
347
+            case 'PHARMA': { // PHARMACODE
348
+                $arrcode = $this->barcode_pharmacode($code);
349
+                break;
350
+            }
351
+            case 'PHARMA2T': { // PHARMACODE TWO-TRACKS
352
+                $arrcode = $this->barcode_pharmacode2t($code);
353
+                break;
354
+            }
355
+            default: {
356
+                $this->barcode_array = false;
357
+                $arrcode = false;
358
+                break;
359
+            }
360
+        }
361
+        $this->barcode_array = $arrcode;
362
+    }
363 363
 
364
-	/**
365
-	 * CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
366
-	 * General-purpose code in very wide use world-wide
367
-	 * @param $code (string) code to represent.
368
-	 * @param $extended (boolean) if true uses the extended mode.
369
-	 * @param $checksum (boolean) if true add a checksum to the code.
370
-	 * @return array barcode representation.
371
-	 * @protected
372
-	 */
373
-	protected function barcode_code39($code, $extended=false, $checksum=false) {
374
-		$chr['0'] = '111331311';
375
-		$chr['1'] = '311311113';
376
-		$chr['2'] = '113311113';
377
-		$chr['3'] = '313311111';
378
-		$chr['4'] = '111331113';
379
-		$chr['5'] = '311331111';
380
-		$chr['6'] = '113331111';
381
-		$chr['7'] = '111311313';
382
-		$chr['8'] = '311311311';
383
-		$chr['9'] = '113311311';
384
-		$chr['A'] = '311113113';
385
-		$chr['B'] = '113113113';
386
-		$chr['C'] = '313113111';
387
-		$chr['D'] = '111133113';
388
-		$chr['E'] = '311133111';
389
-		$chr['F'] = '113133111';
390
-		$chr['G'] = '111113313';
391
-		$chr['H'] = '311113311';
392
-		$chr['I'] = '113113311';
393
-		$chr['J'] = '111133311';
394
-		$chr['K'] = '311111133';
395
-		$chr['L'] = '113111133';
396
-		$chr['M'] = '313111131';
397
-		$chr['N'] = '111131133';
398
-		$chr['O'] = '311131131';
399
-		$chr['P'] = '113131131';
400
-		$chr['Q'] = '111111333';
401
-		$chr['R'] = '311111331';
402
-		$chr['S'] = '113111331';
403
-		$chr['T'] = '111131331';
404
-		$chr['U'] = '331111113';
405
-		$chr['V'] = '133111113';
406
-		$chr['W'] = '333111111';
407
-		$chr['X'] = '131131113';
408
-		$chr['Y'] = '331131111';
409
-		$chr['Z'] = '133131111';
410
-		$chr['-'] = '131111313';
411
-		$chr['.'] = '331111311';
412
-		$chr[' '] = '133111311';
413
-		$chr['$'] = '131313111';
414
-		$chr['/'] = '131311131';
415
-		$chr['+'] = '131113131';
416
-		$chr['%'] = '111313131';
417
-		$chr['*'] = '131131311';
418
-		$code = strtoupper($code);
419
-		if ($extended) {
420
-			// extended mode
421
-			$code = $this->encode_code39_ext($code);
422
-		}
423
-		if ($code === false) {
424
-			return false;
425
-		}
426
-		if ($checksum) {
427
-			// checksum
428
-			$code .= $this->checksum_code39($code);
429
-		}
430
-		// add start and stop codes
431
-		$code = '*'.$code.'*';
432
-		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
433
-		$k = 0;
434
-		$clen = strlen($code);
435
-		for ($i = 0; $i < $clen; ++$i) {
436
-			$char = $code{$i};
437
-			if(!isset($chr[$char])) {
438
-				// invalid character
439
-				return false;
440
-			}
441
-			for ($j = 0; $j < 9; ++$j) {
442
-				if (($j % 2) == 0) {
443
-					$t = true; // bar
444
-				} else {
445
-					$t = false; // space
446
-				}
447
-				$w = $chr[$char]{$j};
448
-				$bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
449
-				$bararray['maxw'] += $w;
450
-				++$k;
451
-			}
452
-			// intercharacter gap
453
-			$bararray['bcode'][$k] = array('t' => false, 'w' => 1, 'h' => 1, 'p' => 0);
454
-			$bararray['maxw'] += 1;
455
-			++$k;
456
-		}
457
-		return $bararray;
458
-	}
364
+    /**
365
+     * CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
366
+     * General-purpose code in very wide use world-wide
367
+     * @param $code (string) code to represent.
368
+     * @param $extended (boolean) if true uses the extended mode.
369
+     * @param $checksum (boolean) if true add a checksum to the code.
370
+     * @return array barcode representation.
371
+     * @protected
372
+     */
373
+    protected function barcode_code39($code, $extended=false, $checksum=false) {
374
+        $chr['0'] = '111331311';
375
+        $chr['1'] = '311311113';
376
+        $chr['2'] = '113311113';
377
+        $chr['3'] = '313311111';
378
+        $chr['4'] = '111331113';
379
+        $chr['5'] = '311331111';
380
+        $chr['6'] = '113331111';
381
+        $chr['7'] = '111311313';
382
+        $chr['8'] = '311311311';
383
+        $chr['9'] = '113311311';
384
+        $chr['A'] = '311113113';
385
+        $chr['B'] = '113113113';
386
+        $chr['C'] = '313113111';
387
+        $chr['D'] = '111133113';
388
+        $chr['E'] = '311133111';
389
+        $chr['F'] = '113133111';
390
+        $chr['G'] = '111113313';
391
+        $chr['H'] = '311113311';
392
+        $chr['I'] = '113113311';
393
+        $chr['J'] = '111133311';
394
+        $chr['K'] = '311111133';
395
+        $chr['L'] = '113111133';
396
+        $chr['M'] = '313111131';
397
+        $chr['N'] = '111131133';
398
+        $chr['O'] = '311131131';
399
+        $chr['P'] = '113131131';
400
+        $chr['Q'] = '111111333';
401
+        $chr['R'] = '311111331';
402
+        $chr['S'] = '113111331';
403
+        $chr['T'] = '111131331';
404
+        $chr['U'] = '331111113';
405
+        $chr['V'] = '133111113';
406
+        $chr['W'] = '333111111';
407
+        $chr['X'] = '131131113';
408
+        $chr['Y'] = '331131111';
409
+        $chr['Z'] = '133131111';
410
+        $chr['-'] = '131111313';
411
+        $chr['.'] = '331111311';
412
+        $chr[' '] = '133111311';
413
+        $chr['$'] = '131313111';
414
+        $chr['/'] = '131311131';
415
+        $chr['+'] = '131113131';
416
+        $chr['%'] = '111313131';
417
+        $chr['*'] = '131131311';
418
+        $code = strtoupper($code);
419
+        if ($extended) {
420
+            // extended mode
421
+            $code = $this->encode_code39_ext($code);
422
+        }
423
+        if ($code === false) {
424
+            return false;
425
+        }
426
+        if ($checksum) {
427
+            // checksum
428
+            $code .= $this->checksum_code39($code);
429
+        }
430
+        // add start and stop codes
431
+        $code = '*'.$code.'*';
432
+        $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
433
+        $k = 0;
434
+        $clen = strlen($code);
435
+        for ($i = 0; $i < $clen; ++$i) {
436
+            $char = $code{$i};
437
+            if(!isset($chr[$char])) {
438
+                // invalid character
439
+                return false;
440
+            }
441
+            for ($j = 0; $j < 9; ++$j) {
442
+                if (($j % 2) == 0) {
443
+                    $t = true; // bar
444
+                } else {
445
+                    $t = false; // space
446
+                }
447
+                $w = $chr[$char]{$j};
448
+                $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
449
+                $bararray['maxw'] += $w;
450
+                ++$k;
451
+            }
452
+            // intercharacter gap
453
+            $bararray['bcode'][$k] = array('t' => false, 'w' => 1, 'h' => 1, 'p' => 0);
454
+            $bararray['maxw'] += 1;
455
+            ++$k;
456
+        }
457
+        return $bararray;
458
+    }
459 459
 
460
-	/**
461
-	 * Encode a string to be used for CODE 39 Extended mode.
462
-	 * @param $code (string) code to represent.
463
-	 * @return encoded string.
464
-	 * @protected
465
-	 */
466
-	protected function encode_code39_ext($code) {
467
-		$encode = array(
468
-			chr(0) => '%U', chr(1) => '$A', chr(2) => '$B', chr(3) => '$C',
469
-			chr(4) => '$D', chr(5) => '$E', chr(6) => '$F', chr(7) => '$G',
470
-			chr(8) => '$H', chr(9) => '$I', chr(10) => '$J', chr(11) => '£K',
471
-			chr(12) => '$L', chr(13) => '$M', chr(14) => '$N', chr(15) => '$O',
472
-			chr(16) => '$P', chr(17) => '$Q', chr(18) => '$R', chr(19) => '$S',
473
-			chr(20) => '$T', chr(21) => '$U', chr(22) => '$V', chr(23) => '$W',
474
-			chr(24) => '$X', chr(25) => '$Y', chr(26) => '$Z', chr(27) => '%A',
475
-			chr(28) => '%B', chr(29) => '%C', chr(30) => '%D', chr(31) => '%E',
476
-			chr(32) => ' ', chr(33) => '/A', chr(34) => '/B', chr(35) => '/C',
477
-			chr(36) => '/D', chr(37) => '/E', chr(38) => '/F', chr(39) => '/G',
478
-			chr(40) => '/H', chr(41) => '/I', chr(42) => '/J', chr(43) => '/K',
479
-			chr(44) => '/L', chr(45) => '-', chr(46) => '.', chr(47) => '/O',
480
-			chr(48) => '0', chr(49) => '1', chr(50) => '2', chr(51) => '3',
481
-			chr(52) => '4', chr(53) => '5', chr(54) => '6', chr(55) => '7',
482
-			chr(56) => '8', chr(57) => '9', chr(58) => '/Z', chr(59) => '%F',
483
-			chr(60) => '%G', chr(61) => '%H', chr(62) => '%I', chr(63) => '%J',
484
-			chr(64) => '%V', chr(65) => 'A', chr(66) => 'B', chr(67) => 'C',
485
-			chr(68) => 'D', chr(69) => 'E', chr(70) => 'F', chr(71) => 'G',
486
-			chr(72) => 'H', chr(73) => 'I', chr(74) => 'J', chr(75) => 'K',
487
-			chr(76) => 'L', chr(77) => 'M', chr(78) => 'N', chr(79) => 'O',
488
-			chr(80) => 'P', chr(81) => 'Q', chr(82) => 'R', chr(83) => 'S',
489
-			chr(84) => 'T', chr(85) => 'U', chr(86) => 'V', chr(87) => 'W',
490
-			chr(88) => 'X', chr(89) => 'Y', chr(90) => 'Z', chr(91) => '%K',
491
-			chr(92) => '%L', chr(93) => '%M', chr(94) => '%N', chr(95) => '%O',
492
-			chr(96) => '%W', chr(97) => '+A', chr(98) => '+B', chr(99) => '+C',
493
-			chr(100) => '+D', chr(101) => '+E', chr(102) => '+F', chr(103) => '+G',
494
-			chr(104) => '+H', chr(105) => '+I', chr(106) => '+J', chr(107) => '+K',
495
-			chr(108) => '+L', chr(109) => '+M', chr(110) => '+N', chr(111) => '+O',
496
-			chr(112) => '+P', chr(113) => '+Q', chr(114) => '+R', chr(115) => '+S',
497
-			chr(116) => '+T', chr(117) => '+U', chr(118) => '+V', chr(119) => '+W',
498
-			chr(120) => '+X', chr(121) => '+Y', chr(122) => '+Z', chr(123) => '%P',
499
-			chr(124) => '%Q', chr(125) => '%R', chr(126) => '%S', chr(127) => '%T');
500
-		$code_ext = '';
501
-		$clen = strlen($code);
502
-		for ($i = 0 ; $i < $clen; ++$i) {
503
-			if (ord($code{$i}) > 127) {
504
-				return false;
505
-			}
506
-			$code_ext .= $encode[$code{$i}];
507
-		}
508
-		return $code_ext;
509
-	}
460
+    /**
461
+     * Encode a string to be used for CODE 39 Extended mode.
462
+     * @param $code (string) code to represent.
463
+     * @return encoded string.
464
+     * @protected
465
+     */
466
+    protected function encode_code39_ext($code) {
467
+        $encode = array(
468
+            chr(0) => '%U', chr(1) => '$A', chr(2) => '$B', chr(3) => '$C',
469
+            chr(4) => '$D', chr(5) => '$E', chr(6) => '$F', chr(7) => '$G',
470
+            chr(8) => '$H', chr(9) => '$I', chr(10) => '$J', chr(11) => '£K',
471
+            chr(12) => '$L', chr(13) => '$M', chr(14) => '$N', chr(15) => '$O',
472
+            chr(16) => '$P', chr(17) => '$Q', chr(18) => '$R', chr(19) => '$S',
473
+            chr(20) => '$T', chr(21) => '$U', chr(22) => '$V', chr(23) => '$W',
474
+            chr(24) => '$X', chr(25) => '$Y', chr(26) => '$Z', chr(27) => '%A',
475
+            chr(28) => '%B', chr(29) => '%C', chr(30) => '%D', chr(31) => '%E',
476
+            chr(32) => ' ', chr(33) => '/A', chr(34) => '/B', chr(35) => '/C',
477
+            chr(36) => '/D', chr(37) => '/E', chr(38) => '/F', chr(39) => '/G',
478
+            chr(40) => '/H', chr(41) => '/I', chr(42) => '/J', chr(43) => '/K',
479
+            chr(44) => '/L', chr(45) => '-', chr(46) => '.', chr(47) => '/O',
480
+            chr(48) => '0', chr(49) => '1', chr(50) => '2', chr(51) => '3',
481
+            chr(52) => '4', chr(53) => '5', chr(54) => '6', chr(55) => '7',
482
+            chr(56) => '8', chr(57) => '9', chr(58) => '/Z', chr(59) => '%F',
483
+            chr(60) => '%G', chr(61) => '%H', chr(62) => '%I', chr(63) => '%J',
484
+            chr(64) => '%V', chr(65) => 'A', chr(66) => 'B', chr(67) => 'C',
485
+            chr(68) => 'D', chr(69) => 'E', chr(70) => 'F', chr(71) => 'G',
486
+            chr(72) => 'H', chr(73) => 'I', chr(74) => 'J', chr(75) => 'K',
487
+            chr(76) => 'L', chr(77) => 'M', chr(78) => 'N', chr(79) => 'O',
488
+            chr(80) => 'P', chr(81) => 'Q', chr(82) => 'R', chr(83) => 'S',
489
+            chr(84) => 'T', chr(85) => 'U', chr(86) => 'V', chr(87) => 'W',
490
+            chr(88) => 'X', chr(89) => 'Y', chr(90) => 'Z', chr(91) => '%K',
491
+            chr(92) => '%L', chr(93) => '%M', chr(94) => '%N', chr(95) => '%O',
492
+            chr(96) => '%W', chr(97) => '+A', chr(98) => '+B', chr(99) => '+C',
493
+            chr(100) => '+D', chr(101) => '+E', chr(102) => '+F', chr(103) => '+G',
494
+            chr(104) => '+H', chr(105) => '+I', chr(106) => '+J', chr(107) => '+K',
495
+            chr(108) => '+L', chr(109) => '+M', chr(110) => '+N', chr(111) => '+O',
496
+            chr(112) => '+P', chr(113) => '+Q', chr(114) => '+R', chr(115) => '+S',
497
+            chr(116) => '+T', chr(117) => '+U', chr(118) => '+V', chr(119) => '+W',
498
+            chr(120) => '+X', chr(121) => '+Y', chr(122) => '+Z', chr(123) => '%P',
499
+            chr(124) => '%Q', chr(125) => '%R', chr(126) => '%S', chr(127) => '%T');
500
+        $code_ext = '';
501
+        $clen = strlen($code);
502
+        for ($i = 0 ; $i < $clen; ++$i) {
503
+            if (ord($code{$i}) > 127) {
504
+                return false;
505
+            }
506
+            $code_ext .= $encode[$code{$i}];
507
+        }
508
+        return $code_ext;
509
+    }
510 510
 
511
-	/**
512
-	 * Calculate CODE 39 checksum (modulo 43).
513
-	 * @param $code (string) code to represent.
514
-	 * @return char checksum.
515
-	 * @protected
516
-	 */
517
-	protected function checksum_code39($code) {
518
-		$chars = array(
519
-			'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
520
-			'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
521
-			'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
522
-			'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%');
523
-		$sum = 0;
524
-		$clen = strlen($code);
525
-		for ($i = 0 ; $i < $clen; ++$i) {
526
-			$k = array_keys($chars, $code{$i});
527
-			$sum += $k[0];
528
-		}
529
-		$j = ($sum % 43);
530
-		return $chars[$j];
531
-	}
511
+    /**
512
+     * Calculate CODE 39 checksum (modulo 43).
513
+     * @param $code (string) code to represent.
514
+     * @return char checksum.
515
+     * @protected
516
+     */
517
+    protected function checksum_code39($code) {
518
+        $chars = array(
519
+            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
520
+            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
521
+            'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
522
+            'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%');
523
+        $sum = 0;
524
+        $clen = strlen($code);
525
+        for ($i = 0 ; $i < $clen; ++$i) {
526
+            $k = array_keys($chars, $code{$i});
527
+            $sum += $k[0];
528
+        }
529
+        $j = ($sum % 43);
530
+        return $chars[$j];
531
+    }
532 532
 
533
-	/**
534
-	 * CODE 93 - USS-93
535
-	 * Compact code similar to Code 39
536
-	 * @param $code (string) code to represent.
537
-	 * @return array barcode representation.
538
-	 * @protected
539
-	 */
540
-	protected function barcode_code93($code) {
541
-		$chr[48] = '131112'; // 0
542
-		$chr[49] = '111213'; // 1
543
-		$chr[50] = '111312'; // 2
544
-		$chr[51] = '111411'; // 3
545
-		$chr[52] = '121113'; // 4
546
-		$chr[53] = '121212'; // 5
547
-		$chr[54] = '121311'; // 6
548
-		$chr[55] = '111114'; // 7
549
-		$chr[56] = '131211'; // 8
550
-		$chr[57] = '141111'; // 9
551
-		$chr[65] = '211113'; // A
552
-		$chr[66] = '211212'; // B
553
-		$chr[67] = '211311'; // C
554
-		$chr[68] = '221112'; // D
555
-		$chr[69] = '221211'; // E
556
-		$chr[70] = '231111'; // F
557
-		$chr[71] = '112113'; // G
558
-		$chr[72] = '112212'; // H
559
-		$chr[73] = '112311'; // I
560
-		$chr[74] = '122112'; // J
561
-		$chr[75] = '132111'; // K
562
-		$chr[76] = '111123'; // L
563
-		$chr[77] = '111222'; // M
564
-		$chr[78] = '111321'; // N
565
-		$chr[79] = '121122'; // O
566
-		$chr[80] = '131121'; // P
567
-		$chr[81] = '212112'; // Q
568
-		$chr[82] = '212211'; // R
569
-		$chr[83] = '211122'; // S
570
-		$chr[84] = '211221'; // T
571
-		$chr[85] = '221121'; // U
572
-		$chr[86] = '222111'; // V
573
-		$chr[87] = '112122'; // W
574
-		$chr[88] = '112221'; // X
575
-		$chr[89] = '122121'; // Y
576
-		$chr[90] = '123111'; // Z
577
-		$chr[45] = '121131'; // -
578
-		$chr[46] = '311112'; // .
579
-		$chr[32] = '311211'; //
580
-		$chr[36] = '321111'; // $
581
-		$chr[47] = '112131'; // /
582
-		$chr[43] = '113121'; // +
583
-		$chr[37] = '211131'; // %
584
-		$chr[128] = '121221'; // ($)
585
-		$chr[129] = '311121'; // (/)
586
-		$chr[130] = '122211'; // (+)
587
-		$chr[131] = '312111'; // (%)
588
-		$chr[42] = '111141'; // start-stop
589
-		$code = strtoupper($code);
590
-		$encode = array(
591
-			chr(0) => chr(131).'U', chr(1) => chr(128).'A', chr(2) => chr(128).'B', chr(3) => chr(128).'C',
592
-			chr(4) => chr(128).'D', chr(5) => chr(128).'E', chr(6) => chr(128).'F', chr(7) => chr(128).'G',
593
-			chr(8) => chr(128).'H', chr(9) => chr(128).'I', chr(10) => chr(128).'J', chr(11) => '£K',
594
-			chr(12) => chr(128).'L', chr(13) => chr(128).'M', chr(14) => chr(128).'N', chr(15) => chr(128).'O',
595
-			chr(16) => chr(128).'P', chr(17) => chr(128).'Q', chr(18) => chr(128).'R', chr(19) => chr(128).'S',
596
-			chr(20) => chr(128).'T', chr(21) => chr(128).'U', chr(22) => chr(128).'V', chr(23) => chr(128).'W',
597
-			chr(24) => chr(128).'X', chr(25) => chr(128).'Y', chr(26) => chr(128).'Z', chr(27) => chr(131).'A',
598
-			chr(28) => chr(131).'B', chr(29) => chr(131).'C', chr(30) => chr(131).'D', chr(31) => chr(131).'E',
599
-			chr(32) => ' ', chr(33) => chr(129).'A', chr(34) => chr(129).'B', chr(35) => chr(129).'C',
600
-			chr(36) => chr(129).'D', chr(37) => chr(129).'E', chr(38) => chr(129).'F', chr(39) => chr(129).'G',
601
-			chr(40) => chr(129).'H', chr(41) => chr(129).'I', chr(42) => chr(129).'J', chr(43) => chr(129).'K',
602
-			chr(44) => chr(129).'L', chr(45) => '-', chr(46) => '.', chr(47) => chr(129).'O',
603
-			chr(48) => '0', chr(49) => '1', chr(50) => '2', chr(51) => '3',
604
-			chr(52) => '4', chr(53) => '5', chr(54) => '6', chr(55) => '7',
605
-			chr(56) => '8', chr(57) => '9', chr(58) => chr(129).'Z', chr(59) => chr(131).'F',
606
-			chr(60) => chr(131).'G', chr(61) => chr(131).'H', chr(62) => chr(131).'I', chr(63) => chr(131).'J',
607
-			chr(64) => chr(131).'V', chr(65) => 'A', chr(66) => 'B', chr(67) => 'C',
608
-			chr(68) => 'D', chr(69) => 'E', chr(70) => 'F', chr(71) => 'G',
609
-			chr(72) => 'H', chr(73) => 'I', chr(74) => 'J', chr(75) => 'K',
610
-			chr(76) => 'L', chr(77) => 'M', chr(78) => 'N', chr(79) => 'O',
611
-			chr(80) => 'P', chr(81) => 'Q', chr(82) => 'R', chr(83) => 'S',
612
-			chr(84) => 'T', chr(85) => 'U', chr(86) => 'V', chr(87) => 'W',
613
-			chr(88) => 'X', chr(89) => 'Y', chr(90) => 'Z', chr(91) => chr(131).'K',
614
-			chr(92) => chr(131).'L', chr(93) => chr(131).'M', chr(94) => chr(131).'N', chr(95) => chr(131).'O',
615
-			chr(96) => chr(131).'W', chr(97) => chr(130).'A', chr(98) => chr(130).'B', chr(99) => chr(130).'C',
616
-			chr(100) => chr(130).'D', chr(101) => chr(130).'E', chr(102) => chr(130).'F', chr(103) => chr(130).'G',
617
-			chr(104) => chr(130).'H', chr(105) => chr(130).'I', chr(106) => chr(130).'J', chr(107) => chr(130).'K',
618
-			chr(108) => chr(130).'L', chr(109) => chr(130).'M', chr(110) => chr(130).'N', chr(111) => chr(130).'O',
619
-			chr(112) => chr(130).'P', chr(113) => chr(130).'Q', chr(114) => chr(130).'R', chr(115) => chr(130).'S',
620
-			chr(116) => chr(130).'T', chr(117) => chr(130).'U', chr(118) => chr(130).'V', chr(119) => chr(130).'W',
621
-			chr(120) => chr(130).'X', chr(121) => chr(130).'Y', chr(122) => chr(130).'Z', chr(123) => chr(131).'P',
622
-			chr(124) => chr(131).'Q', chr(125) => chr(131).'R', chr(126) => chr(131).'S', chr(127) => chr(131).'T');
623
-		$code_ext = '';
624
-		$clen = strlen($code);
625
-		for ($i = 0 ; $i < $clen; ++$i) {
626
-			if (ord($code{$i}) > 127) {
627
-				return false;
628
-			}
629
-			$code_ext .= $encode[$code{$i}];
630
-		}
631
-		// checksum
632
-		$code_ext .= $this->checksum_code93($code_ext);
633
-		// add start and stop codes
634
-		$code = '*'.$code_ext.'*';
635
-		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
636
-		$k = 0;
637
-		$clen = strlen($code);
638
-		for ($i = 0; $i < $clen; ++$i) {
639
-			$char = ord($code{$i});
640
-			if(!isset($chr[$char])) {
641
-				// invalid character
642
-				return false;
643
-			}
644
-			for ($j = 0; $j < 6; ++$j) {
645
-				if (($j % 2) == 0) {
646
-					$t = true; // bar
647
-				} else {
648
-					$t = false; // space
649
-				}
650
-				$w = $chr[$char]{$j};
651
-				$bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
652
-				$bararray['maxw'] += $w;
653
-				++$k;
654
-			}
655
-		}
656
-		$bararray['bcode'][$k] = array('t' => true, 'w' => 1, 'h' => 1, 'p' => 0);
657
-		$bararray['maxw'] += 1;
658
-		++$k;
659
-		return $bararray;
660
-	}
533
+    /**
534
+     * CODE 93 - USS-93
535
+     * Compact code similar to Code 39
536
+     * @param $code (string) code to represent.
537
+     * @return array barcode representation.
538
+     * @protected
539
+     */
540
+    protected function barcode_code93($code) {
541
+        $chr[48] = '131112'; // 0
542
+        $chr[49] = '111213'; // 1
543
+        $chr[50] = '111312'; // 2
544
+        $chr[51] = '111411'; // 3
545
+        $chr[52] = '121113'; // 4
546
+        $chr[53] = '121212'; // 5
547
+        $chr[54] = '121311'; // 6
548
+        $chr[55] = '111114'; // 7
549
+        $chr[56] = '131211'; // 8
550
+        $chr[57] = '141111'; // 9
551
+        $chr[65] = '211113'; // A
552
+        $chr[66] = '211212'; // B
553
+        $chr[67] = '211311'; // C
554
+        $chr[68] = '221112'; // D
555
+        $chr[69] = '221211'; // E
556
+        $chr[70] = '231111'; // F
557
+        $chr[71] = '112113'; // G
558
+        $chr[72] = '112212'; // H
559
+        $chr[73] = '112311'; // I
560
+        $chr[74] = '122112'; // J
561
+        $chr[75] = '132111'; // K
562
+        $chr[76] = '111123'; // L
563
+        $chr[77] = '111222'; // M
564
+        $chr[78] = '111321'; // N
565
+        $chr[79] = '121122'; // O
566
+        $chr[80] = '131121'; // P
567
+        $chr[81] = '212112'; // Q
568
+        $chr[82] = '212211'; // R
569
+        $chr[83] = '211122'; // S
570
+        $chr[84] = '211221'; // T
571
+        $chr[85] = '221121'; // U
572
+        $chr[86] = '222111'; // V
573
+        $chr[87] = '112122'; // W
574
+        $chr[88] = '112221'; // X
575
+        $chr[89] = '122121'; // Y
576
+        $chr[90] = '123111'; // Z
577
+        $chr[45] = '121131'; // -
578
+        $chr[46] = '311112'; // .
579
+        $chr[32] = '311211'; //
580
+        $chr[36] = '321111'; // $
581
+        $chr[47] = '112131'; // /
582
+        $chr[43] = '113121'; // +
583
+        $chr[37] = '211131'; // %
584
+        $chr[128] = '121221'; // ($)
585
+        $chr[129] = '311121'; // (/)
586
+        $chr[130] = '122211'; // (+)
587
+        $chr[131] = '312111'; // (%)
588
+        $chr[42] = '111141'; // start-stop
589
+        $code = strtoupper($code);
590
+        $encode = array(
591
+            chr(0) => chr(131).'U', chr(1) => chr(128).'A', chr(2) => chr(128).'B', chr(3) => chr(128).'C',
592
+            chr(4) => chr(128).'D', chr(5) => chr(128).'E', chr(6) => chr(128).'F', chr(7) => chr(128).'G',
593
+            chr(8) => chr(128).'H', chr(9) => chr(128).'I', chr(10) => chr(128).'J', chr(11) => '£K',
594
+            chr(12) => chr(128).'L', chr(13) => chr(128).'M', chr(14) => chr(128).'N', chr(15) => chr(128).'O',
595
+            chr(16) => chr(128).'P', chr(17) => chr(128).'Q', chr(18) => chr(128).'R', chr(19) => chr(128).'S',
596
+            chr(20) => chr(128).'T', chr(21) => chr(128).'U', chr(22) => chr(128).'V', chr(23) => chr(128).'W',
597
+            chr(24) => chr(128).'X', chr(25) => chr(128).'Y', chr(26) => chr(128).'Z', chr(27) => chr(131).'A',
598
+            chr(28) => chr(131).'B', chr(29) => chr(131).'C', chr(30) => chr(131).'D', chr(31) => chr(131).'E',
599
+            chr(32) => ' ', chr(33) => chr(129).'A', chr(34) => chr(129).'B', chr(35) => chr(129).'C',
600
+            chr(36) => chr(129).'D', chr(37) => chr(129).'E', chr(38) => chr(129).'F', chr(39) => chr(129).'G',
601
+            chr(40) => chr(129).'H', chr(41) => chr(129).'I', chr(42) => chr(129).'J', chr(43) => chr(129).'K',
602
+            chr(44) => chr(129).'L', chr(45) => '-', chr(46) => '.', chr(47) => chr(129).'O',
603
+            chr(48) => '0', chr(49) => '1', chr(50) => '2', chr(51) => '3',
604
+            chr(52) => '4', chr(53) => '5', chr(54) => '6', chr(55) => '7',
605
+            chr(56) => '8', chr(57) => '9', chr(58) => chr(129).'Z', chr(59) => chr(131).'F',
606
+            chr(60) => chr(131).'G', chr(61) => chr(131).'H', chr(62) => chr(131).'I', chr(63) => chr(131).'J',
607
+            chr(64) => chr(131).'V', chr(65) => 'A', chr(66) => 'B', chr(67) => 'C',
608
+            chr(68) => 'D', chr(69) => 'E', chr(70) => 'F', chr(71) => 'G',
609
+            chr(72) => 'H', chr(73) => 'I', chr(74) => 'J', chr(75) => 'K',
610
+            chr(76) => 'L', chr(77) => 'M', chr(78) => 'N', chr(79) => 'O',
611
+            chr(80) => 'P', chr(81) => 'Q', chr(82) => 'R', chr(83) => 'S',
612
+            chr(84) => 'T', chr(85) => 'U', chr(86) => 'V', chr(87) => 'W',
613
+            chr(88) => 'X', chr(89) => 'Y', chr(90) => 'Z', chr(91) => chr(131).'K',
614
+            chr(92) => chr(131).'L', chr(93) => chr(131).'M', chr(94) => chr(131).'N', chr(95) => chr(131).'O',
615
+            chr(96) => chr(131).'W', chr(97) => chr(130).'A', chr(98) => chr(130).'B', chr(99) => chr(130).'C',
616
+            chr(100) => chr(130).'D', chr(101) => chr(130).'E', chr(102) => chr(130).'F', chr(103) => chr(130).'G',
617
+            chr(104) => chr(130).'H', chr(105) => chr(130).'I', chr(106) => chr(130).'J', chr(107) => chr(130).'K',
618
+            chr(108) => chr(130).'L', chr(109) => chr(130).'M', chr(110) => chr(130).'N', chr(111) => chr(130).'O',
619
+            chr(112) => chr(130).'P', chr(113) => chr(130).'Q', chr(114) => chr(130).'R', chr(115) => chr(130).'S',
620
+            chr(116) => chr(130).'T', chr(117) => chr(130).'U', chr(118) => chr(130).'V', chr(119) => chr(130).'W',
621
+            chr(120) => chr(130).'X', chr(121) => chr(130).'Y', chr(122) => chr(130).'Z', chr(123) => chr(131).'P',
622
+            chr(124) => chr(131).'Q', chr(125) => chr(131).'R', chr(126) => chr(131).'S', chr(127) => chr(131).'T');
623
+        $code_ext = '';
624
+        $clen = strlen($code);
625
+        for ($i = 0 ; $i < $clen; ++$i) {
626
+            if (ord($code{$i}) > 127) {
627
+                return false;
628
+            }
629
+            $code_ext .= $encode[$code{$i}];
630
+        }
631
+        // checksum
632
+        $code_ext .= $this->checksum_code93($code_ext);
633
+        // add start and stop codes
634
+        $code = '*'.$code_ext.'*';
635
+        $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
636
+        $k = 0;
637
+        $clen = strlen($code);
638
+        for ($i = 0; $i < $clen; ++$i) {
639
+            $char = ord($code{$i});
640
+            if(!isset($chr[$char])) {
641
+                // invalid character
642
+                return false;
643
+            }
644
+            for ($j = 0; $j < 6; ++$j) {
645
+                if (($j % 2) == 0) {
646
+                    $t = true; // bar
647
+                } else {
648
+                    $t = false; // space
649
+                }
650
+                $w = $chr[$char]{$j};
651
+                $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
652
+                $bararray['maxw'] += $w;
653
+                ++$k;
654
+            }
655
+        }
656
+        $bararray['bcode'][$k] = array('t' => true, 'w' => 1, 'h' => 1, 'p' => 0);
657
+        $bararray['maxw'] += 1;
658
+        ++$k;
659
+        return $bararray;
660
+    }
661 661
 
662
-	/**
663
-	 * Calculate CODE 93 checksum (modulo 47).
664
-	 * @param $code (string) code to represent.
665
-	 * @return string checksum code.
666
-	 * @protected
667
-	 */
668
-	protected function checksum_code93($code) {
669
-		$chars = array(
670
-			'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
671
-			'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
672
-			'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
673
-			'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%',
674
-			'<', '=', '>', '?');
675
-		// translate special characters
676
-		$code = strtr($code, chr(128).chr(131).chr(129).chr(130), '<=>?');
677
-		$len = strlen($code);
678
-		// calculate check digit C
679
-		$p = 1;
680
-		$check = 0;
681
-		for ($i = ($len - 1); $i >= 0; --$i) {
682
-			$k = array_keys($chars, $code{$i});
683
-			$check += ($k[0] * $p);
684
-			++$p;
685
-			if ($p > 20) {
686
-				$p = 1;
687
-			}
688
-		}
689
-		$check %= 47;
690
-		$c = $chars[$check];
691
-		$code .= $c;
692
-		// calculate check digit K
693
-		$p = 1;
694
-		$check = 0;
695
-		for ($i = $len; $i >= 0; --$i) {
696
-			$k = array_keys($chars, $code{$i});
697
-			$check += ($k[0] * $p);
698
-			++$p;
699
-			if ($p > 15) {
700
-				$p = 1;
701
-			}
702
-		}
703
-		$check %= 47;
704
-		$k = $chars[$check];
705
-		$checksum = $c.$k;
706
-		// resto respecial characters
707
-		$checksum = strtr($checksum, '<=>?', chr(128).chr(131).chr(129).chr(130));
708
-		return $checksum;
709
-	}
662
+    /**
663
+     * Calculate CODE 93 checksum (modulo 47).
664
+     * @param $code (string) code to represent.
665
+     * @return string checksum code.
666
+     * @protected
667
+     */
668
+    protected function checksum_code93($code) {
669
+        $chars = array(
670
+            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
671
+            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
672
+            'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
673
+            'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%',
674
+            '<', '=', '>', '?');
675
+        // translate special characters
676
+        $code = strtr($code, chr(128).chr(131).chr(129).chr(130), '<=>?');
677
+        $len = strlen($code);
678
+        // calculate check digit C
679
+        $p = 1;
680
+        $check = 0;
681
+        for ($i = ($len - 1); $i >= 0; --$i) {
682
+            $k = array_keys($chars, $code{$i});
683
+            $check += ($k[0] * $p);
684
+            ++$p;
685
+            if ($p > 20) {
686
+                $p = 1;
687
+            }
688
+        }
689
+        $check %= 47;
690
+        $c = $chars[$check];
691
+        $code .= $c;
692
+        // calculate check digit K
693
+        $p = 1;
694
+        $check = 0;
695
+        for ($i = $len; $i >= 0; --$i) {
696
+            $k = array_keys($chars, $code{$i});
697
+            $check += ($k[0] * $p);
698
+            ++$p;
699
+            if ($p > 15) {
700
+                $p = 1;
701
+            }
702
+        }
703
+        $check %= 47;
704
+        $k = $chars[$check];
705
+        $checksum = $c.$k;
706
+        // resto respecial characters
707
+        $checksum = strtr($checksum, '<=>?', chr(128).chr(131).chr(129).chr(130));
708
+        return $checksum;
709
+    }
710 710
 
711
-	/**
712
-	 * Checksum for standard 2 of 5 barcodes.
713
-	 * @param $code (string) code to process.
714
-	 * @return int checksum.
715
-	 * @protected
716
-	 */
717
-	protected function checksum_s25($code) {
718
-		$len = strlen($code);
719
-		$sum = 0;
720
-		for ($i = 0; $i < $len; $i+=2) {
721
-			$sum += $code{$i};
722
-		}
723
-		$sum *= 3;
724
-		for ($i = 1; $i < $len; $i+=2) {
725
-			$sum += ($code{$i});
726
-		}
727
-		$r = $sum % 10;
728
-		if($r > 0) {
729
-			$r = (10 - $r);
730
-		}
731
-		return $r;
732
-	}
711
+    /**
712
+     * Checksum for standard 2 of 5 barcodes.
713
+     * @param $code (string) code to process.
714
+     * @return int checksum.
715
+     * @protected
716
+     */
717
+    protected function checksum_s25($code) {
718
+        $len = strlen($code);
719
+        $sum = 0;
720
+        for ($i = 0; $i < $len; $i+=2) {
721
+            $sum += $code{$i};
722
+        }
723
+        $sum *= 3;
724
+        for ($i = 1; $i < $len; $i+=2) {
725
+            $sum += ($code{$i});
726
+        }
727
+        $r = $sum % 10;
728
+        if($r > 0) {
729
+            $r = (10 - $r);
730
+        }
731
+        return $r;
732
+    }
733 733
 
734
-	/**
735
-	 * MSI.
736
-	 * Variation of Plessey code, with similar applications
737
-	 * Contains digits (0 to 9) and encodes the data only in the width of bars.
738
-	 * @param $code (string) code to represent.
739
-	 * @param $checksum (boolean) if true add a checksum to the code (modulo 11)
740
-	 * @return array barcode representation.
741
-	 * @protected
742
-	 */
743
-	protected function barcode_msi($code, $checksum=false) {
744
-		$chr['0'] = '100100100100';
745
-		$chr['1'] = '100100100110';
746
-		$chr['2'] = '100100110100';
747
-		$chr['3'] = '100100110110';
748
-		$chr['4'] = '100110100100';
749
-		$chr['5'] = '100110100110';
750
-		$chr['6'] = '100110110100';
751
-		$chr['7'] = '100110110110';
752
-		$chr['8'] = '110100100100';
753
-		$chr['9'] = '110100100110';
754
-		$chr['A'] = '110100110100';
755
-		$chr['B'] = '110100110110';
756
-		$chr['C'] = '110110100100';
757
-		$chr['D'] = '110110100110';
758
-		$chr['E'] = '110110110100';
759
-		$chr['F'] = '110110110110';
760
-		if ($checksum) {
761
-			// add checksum
762
-			$clen = strlen($code);
763
-			$p = 2;
764
-			$check = 0;
765
-			for ($i = ($clen - 1); $i >= 0; --$i) {
766
-				$check += (hexdec($code{$i}) * $p);
767
-				++$p;
768
-				if ($p > 7) {
769
-					$p = 2;
770
-				}
771
-			}
772
-			$check %= 11;
773
-			if ($check > 0) {
774
-				$check = 11 - $check;
775
-			}
776
-			$code .= $check;
777
-		}
778
-		$seq = '110'; // left guard
779
-		$clen = strlen($code);
780
-		for ($i = 0; $i < $clen; ++$i) {
781
-			$digit = $code{$i};
782
-			if (!isset($chr[$digit])) {
783
-				// invalid character
784
-				return false;
785
-			}
786
-			$seq .= $chr[$digit];
787
-		}
788
-		$seq .= '1001'; // right guard
789
-		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
790
-		return $this->binseq_to_array($seq, $bararray);
791
-	}
734
+    /**
735
+     * MSI.
736
+     * Variation of Plessey code, with similar applications
737
+     * Contains digits (0 to 9) and encodes the data only in the width of bars.
738
+     * @param $code (string) code to represent.
739
+     * @param $checksum (boolean) if true add a checksum to the code (modulo 11)
740
+     * @return array barcode representation.
741
+     * @protected
742
+     */
743
+    protected function barcode_msi($code, $checksum=false) {
744
+        $chr['0'] = '100100100100';
745
+        $chr['1'] = '100100100110';
746
+        $chr['2'] = '100100110100';
747
+        $chr['3'] = '100100110110';
748
+        $chr['4'] = '100110100100';
749
+        $chr['5'] = '100110100110';
750
+        $chr['6'] = '100110110100';
751
+        $chr['7'] = '100110110110';
752
+        $chr['8'] = '110100100100';
753
+        $chr['9'] = '110100100110';
754
+        $chr['A'] = '110100110100';
755
+        $chr['B'] = '110100110110';
756
+        $chr['C'] = '110110100100';
757
+        $chr['D'] = '110110100110';
758
+        $chr['E'] = '110110110100';
759
+        $chr['F'] = '110110110110';
760
+        if ($checksum) {
761
+            // add checksum
762
+            $clen = strlen($code);
763
+            $p = 2;
764
+            $check = 0;
765
+            for ($i = ($clen - 1); $i >= 0; --$i) {
766
+                $check += (hexdec($code{$i}) * $p);
767
+                ++$p;
768
+                if ($p > 7) {
769
+                    $p = 2;
770
+                }
771
+            }
772
+            $check %= 11;
773
+            if ($check > 0) {
774
+                $check = 11 - $check;
775
+            }
776
+            $code .= $check;
777
+        }
778
+        $seq = '110'; // left guard
779
+        $clen = strlen($code);
780
+        for ($i = 0; $i < $clen; ++$i) {
781
+            $digit = $code{$i};
782
+            if (!isset($chr[$digit])) {
783
+                // invalid character
784
+                return false;
785
+            }
786
+            $seq .= $chr[$digit];
787
+        }
788
+        $seq .= '1001'; // right guard
789
+        $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
790
+        return $this->binseq_to_array($seq, $bararray);
791
+    }
792 792
 
793
-	/**
794
-	 * Standard 2 of 5 barcodes.
795
-	 * Used in airline ticket marking, photofinishing
796
-	 * Contains digits (0 to 9) and encodes the data only in the width of bars.
797
-	 * @param $code (string) code to represent.
798
-	 * @param $checksum (boolean) if true add a checksum to the code
799
-	 * @return array barcode representation.
800
-	 * @protected
801
-	 */
802
-	protected function barcode_s25($code, $checksum=false) {
803
-		$chr['0'] = '10101110111010';
804
-		$chr['1'] = '11101010101110';
805
-		$chr['2'] = '10111010101110';
806
-		$chr['3'] = '11101110101010';
807
-		$chr['4'] = '10101110101110';
808
-		$chr['5'] = '11101011101010';
809
-		$chr['6'] = '10111011101010';
810
-		$chr['7'] = '10101011101110';
811
-		$chr['8'] = '10101110111010';
812
-		$chr['9'] = '10111010111010';
813
-		if ($checksum) {
814
-			// add checksum
815
-			$code .= $this->checksum_s25($code);
816
-		}
817
-		if((strlen($code) % 2) != 0) {
818
-			// add leading zero if code-length is odd
819
-			$code = '0'.$code;
820
-		}
821
-		$seq = '11011010';
822
-		$clen = strlen($code);
823
-		for ($i = 0; $i < $clen; ++$i) {
824
-			$digit = $code{$i};
825
-			if (!isset($chr[$digit])) {
826
-				// invalid character
827
-				return false;
828
-			}
829
-			$seq .= $chr[$digit];
830
-		}
831
-		$seq .= '1101011';
832
-		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
833
-		return $this->binseq_to_array($seq, $bararray);
834
-	}
793
+    /**
794
+     * Standard 2 of 5 barcodes.
795
+     * Used in airline ticket marking, photofinishing
796
+     * Contains digits (0 to 9) and encodes the data only in the width of bars.
797
+     * @param $code (string) code to represent.
798
+     * @param $checksum (boolean) if true add a checksum to the code
799
+     * @return array barcode representation.
800
+     * @protected
801
+     */
802
+    protected function barcode_s25($code, $checksum=false) {
803
+        $chr['0'] = '10101110111010';
804
+        $chr['1'] = '11101010101110';
805
+        $chr['2'] = '10111010101110';
806
+        $chr['3'] = '11101110101010';
807
+        $chr['4'] = '10101110101110';
808
+        $chr['5'] = '11101011101010';
809
+        $chr['6'] = '10111011101010';
810
+        $chr['7'] = '10101011101110';
811
+        $chr['8'] = '10101110111010';
812
+        $chr['9'] = '10111010111010';
813
+        if ($checksum) {
814
+            // add checksum
815
+            $code .= $this->checksum_s25($code);
816
+        }
817
+        if((strlen($code) % 2) != 0) {
818
+            // add leading zero if code-length is odd
819
+            $code = '0'.$code;
820
+        }
821
+        $seq = '11011010';
822
+        $clen = strlen($code);
823
+        for ($i = 0; $i < $clen; ++$i) {
824
+            $digit = $code{$i};
825
+            if (!isset($chr[$digit])) {
826
+                // invalid character
827
+                return false;
828
+            }
829
+            $seq .= $chr[$digit];
830
+        }
831
+        $seq .= '1101011';
832
+        $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
833
+        return $this->binseq_to_array($seq, $bararray);
834
+    }
835 835
 
836
-	/**
837
-	 * Convert binary barcode sequence to TCPDF barcode array.
838
-	 * @param $seq (string) barcode as binary sequence.
839
-	 * @param $bararray (array) barcode array.
840
-	 * òparam array $bararray TCPDF barcode array to fill up
841
-	 * @return array barcode representation.
842
-	 * @protected
843
-	 */
844
-	protected function binseq_to_array($seq, $bararray) {
845
-		$len = strlen($seq);
846
-		$w = 0;
847
-		$k = 0;
848
-		for ($i = 0; $i < $len; ++$i) {
849
-			$w += 1;
850
-			if (($i == ($len - 1)) OR (($i < ($len - 1)) AND ($seq{$i} != $seq{($i+1)}))) {
851
-				if ($seq{$i} == '1') {
852
-					$t = true; // bar
853
-				} else {
854
-					$t = false; // space
855
-				}
856
-				$bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
857
-				$bararray['maxw'] += $w;
858
-				++$k;
859
-				$w = 0;
860
-			}
861
-		}
862
-		return $bararray;
863
-	}
836
+    /**
837
+     * Convert binary barcode sequence to TCPDF barcode array.
838
+     * @param $seq (string) barcode as binary sequence.
839
+     * @param $bararray (array) barcode array.
840
+     * òparam array $bararray TCPDF barcode array to fill up
841
+     * @return array barcode representation.
842
+     * @protected
843
+     */
844
+    protected function binseq_to_array($seq, $bararray) {
845
+        $len = strlen($seq);
846
+        $w = 0;
847
+        $k = 0;
848
+        for ($i = 0; $i < $len; ++$i) {
849
+            $w += 1;
850
+            if (($i == ($len - 1)) OR (($i < ($len - 1)) AND ($seq{$i} != $seq{($i+1)}))) {
851
+                if ($seq{$i} == '1') {
852
+                    $t = true; // bar
853
+                } else {
854
+                    $t = false; // space
855
+                }
856
+                $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
857
+                $bararray['maxw'] += $w;
858
+                ++$k;
859
+                $w = 0;
860
+            }
861
+        }
862
+        return $bararray;
863
+    }
864 864
 
865
-	/**
866
-	 * Interleaved 2 of 5 barcodes.
867
-	 * Compact numeric code, widely used in industry, air cargo
868
-	 * Contains digits (0 to 9) and encodes the data in the width of both bars and spaces.
869
-	 * @param $code (string) code to represent.
870
-	 * @param $checksum (boolean) if true add a checksum to the code
871
-	 * @return array barcode representation.
872
-	 * @protected
873
-	 */
874
-	protected function barcode_i25($code, $checksum=false) {
875
-		$chr['0'] = '11221';
876
-		$chr['1'] = '21112';
877
-		$chr['2'] = '12112';
878
-		$chr['3'] = '22111';
879
-		$chr['4'] = '11212';
880
-		$chr['5'] = '21211';
881
-		$chr['6'] = '12211';
882
-		$chr['7'] = '11122';
883
-		$chr['8'] = '21121';
884
-		$chr['9'] = '12121';
885
-		$chr['A'] = '11';
886
-		$chr['Z'] = '21';
887
-		if ($checksum) {
888
-			// add checksum
889
-			$code .= $this->checksum_s25($code);
890
-		}
891
-		if((strlen($code) % 2) != 0) {
892
-			// add leading zero if code-length is odd
893
-			$code = '0'.$code;
894
-		}
895
-		// add start and stop codes
896
-		$code = 'AA'.strtolower($code).'ZA';
865
+    /**
866
+     * Interleaved 2 of 5 barcodes.
867
+     * Compact numeric code, widely used in industry, air cargo
868
+     * Contains digits (0 to 9) and encodes the data in the width of both bars and spaces.
869
+     * @param $code (string) code to represent.
870
+     * @param $checksum (boolean) if true add a checksum to the code
871
+     * @return array barcode representation.
872
+     * @protected
873
+     */
874
+    protected function barcode_i25($code, $checksum=false) {
875
+        $chr['0'] = '11221';
876
+        $chr['1'] = '21112';
877
+        $chr['2'] = '12112';
878
+        $chr['3'] = '22111';
879
+        $chr['4'] = '11212';
880
+        $chr['5'] = '21211';
881
+        $chr['6'] = '12211';
882
+        $chr['7'] = '11122';
883
+        $chr['8'] = '21121';
884
+        $chr['9'] = '12121';
885
+        $chr['A'] = '11';
886
+        $chr['Z'] = '21';
887
+        if ($checksum) {
888
+            // add checksum
889
+            $code .= $this->checksum_s25($code);
890
+        }
891
+        if((strlen($code) % 2) != 0) {
892
+            // add leading zero if code-length is odd
893
+            $code = '0'.$code;
894
+        }
895
+        // add start and stop codes
896
+        $code = 'AA'.strtolower($code).'ZA';
897 897
 
898
-		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
899
-		$k = 0;
900
-		$clen = strlen($code);
901
-		for ($i = 0; $i < $clen; $i = ($i + 2)) {
902
-			$char_bar = $code{$i};
903
-			$char_space = $code{$i+1};
904
-			if((!isset($chr[$char_bar])) OR (!isset($chr[$char_space]))) {
905
-				// invalid character
906
-				return false;
907
-			}
908
-			// create a bar-space sequence
909
-			$seq = '';
910
-			$chrlen = strlen($chr[$char_bar]);
911
-			for ($s = 0; $s < $chrlen; $s++){
912
-				$seq .= $chr[$char_bar]{$s} . $chr[$char_space]{$s};
913
-			}
914
-			$seqlen = strlen($seq);
915
-			for ($j = 0; $j < $seqlen; ++$j) {
916
-				if (($j % 2) == 0) {
917
-					$t = true; // bar
918
-				} else {
919
-					$t = false; // space
920
-				}
921
-				$w = $seq{$j};
922
-				$bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
923
-				$bararray['maxw'] += $w;
924
-				++$k;
925
-			}
926
-		}
927
-		return $bararray;
928
-	}
898
+        $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
899
+        $k = 0;
900
+        $clen = strlen($code);
901
+        for ($i = 0; $i < $clen; $i = ($i + 2)) {
902
+            $char_bar = $code{$i};
903
+            $char_space = $code{$i+1};
904
+            if((!isset($chr[$char_bar])) OR (!isset($chr[$char_space]))) {
905
+                // invalid character
906
+                return false;
907
+            }
908
+            // create a bar-space sequence
909
+            $seq = '';
910
+            $chrlen = strlen($chr[$char_bar]);
911
+            for ($s = 0; $s < $chrlen; $s++){
912
+                $seq .= $chr[$char_bar]{$s} . $chr[$char_space]{$s};
913
+            }
914
+            $seqlen = strlen($seq);
915
+            for ($j = 0; $j < $seqlen; ++$j) {
916
+                if (($j % 2) == 0) {
917
+                    $t = true; // bar
918
+                } else {
919
+                    $t = false; // space
920
+                }
921
+                $w = $seq{$j};
922
+                $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
923
+                $bararray['maxw'] += $w;
924
+                ++$k;
925
+            }
926
+        }
927
+        return $bararray;
928
+    }
929 929
 
930
-	/**
931
-	 * C128 barcodes.
932
-	 * Very capable code, excellent density, high reliability; in very wide use world-wide
933
-	 * @param $code (string) code to represent.
934
-	 * @param $type (string) barcode type: A, B, C or empty for automatic switch (AUTO mode)
935
-	 * @return array barcode representation.
936
-	 * @protected
937
-	 */
938
-	protected function barcode_c128($code, $type='') {
939
-		$chr = array(
940
-			'212222', /* 00 */
941
-			'222122', /* 01 */
942
-			'222221', /* 02 */
943
-			'121223', /* 03 */
944
-			'121322', /* 04 */
945
-			'131222', /* 05 */
946
-			'122213', /* 06 */
947
-			'122312', /* 07 */
948
-			'132212', /* 08 */
949
-			'221213', /* 09 */
950
-			'221312', /* 10 */
951
-			'231212', /* 11 */
952
-			'112232', /* 12 */
953
-			'122132', /* 13 */
954
-			'122231', /* 14 */
955
-			'113222', /* 15 */
956
-			'123122', /* 16 */
957
-			'123221', /* 17 */
958
-			'223211', /* 18 */
959
-			'221132', /* 19 */
960
-			'221231', /* 20 */
961
-			'213212', /* 21 */
962
-			'223112', /* 22 */
963
-			'312131', /* 23 */
964
-			'311222', /* 24 */
965
-			'321122', /* 25 */
966
-			'321221', /* 26 */
967
-			'312212', /* 27 */
968
-			'322112', /* 28 */
969
-			'322211', /* 29 */
970
-			'212123', /* 30 */
971
-			'212321', /* 31 */
972
-			'232121', /* 32 */
973
-			'111323', /* 33 */
974
-			'131123', /* 34 */
975
-			'131321', /* 35 */
976
-			'112313', /* 36 */
977
-			'132113', /* 37 */
978
-			'132311', /* 38 */
979
-			'211313', /* 39 */
980
-			'231113', /* 40 */
981
-			'231311', /* 41 */
982
-			'112133', /* 42 */
983
-			'112331', /* 43 */
984
-			'132131', /* 44 */
985
-			'113123', /* 45 */
986
-			'113321', /* 46 */
987
-			'133121', /* 47 */
988
-			'313121', /* 48 */
989
-			'211331', /* 49 */
990
-			'231131', /* 50 */
991
-			'213113', /* 51 */
992
-			'213311', /* 52 */
993
-			'213131', /* 53 */
994
-			'311123', /* 54 */
995
-			'311321', /* 55 */
996
-			'331121', /* 56 */
997
-			'312113', /* 57 */
998
-			'312311', /* 58 */
999
-			'332111', /* 59 */
1000
-			'314111', /* 60 */
1001
-			'221411', /* 61 */
1002
-			'431111', /* 62 */
1003
-			'111224', /* 63 */
1004
-			'111422', /* 64 */
1005
-			'121124', /* 65 */
1006
-			'121421', /* 66 */
1007
-			'141122', /* 67 */
1008
-			'141221', /* 68 */
1009
-			'112214', /* 69 */
1010
-			'112412', /* 70 */
1011
-			'122114', /* 71 */
1012
-			'122411', /* 72 */
1013
-			'142112', /* 73 */
1014
-			'142211', /* 74 */
1015
-			'241211', /* 75 */
1016
-			'221114', /* 76 */
1017
-			'413111', /* 77 */
1018
-			'241112', /* 78 */
1019
-			'134111', /* 79 */
1020
-			'111242', /* 80 */
1021
-			'121142', /* 81 */
1022
-			'121241', /* 82 */
1023
-			'114212', /* 83 */
1024
-			'124112', /* 84 */
1025
-			'124211', /* 85 */
1026
-			'411212', /* 86 */
1027
-			'421112', /* 87 */
1028
-			'421211', /* 88 */
1029
-			'212141', /* 89 */
1030
-			'214121', /* 90 */
1031
-			'412121', /* 91 */
1032
-			'111143', /* 92 */
1033
-			'111341', /* 93 */
1034
-			'131141', /* 94 */
1035
-			'114113', /* 95 */
1036
-			'114311', /* 96 */
1037
-			'411113', /* 97 */
1038
-			'411311', /* 98 */
1039
-			'113141', /* 99 */
1040
-			'114131', /* 100 */
1041
-			'311141', /* 101 */
1042
-			'411131', /* 102 */
1043
-			'211412', /* 103 START A */
1044
-			'211214', /* 104 START B */
1045
-			'211232', /* 105 START C */
1046
-			'233111', /* STOP */
1047
-			'200000'  /* END */
1048
-		);
1049
-		// ASCII characters for code A (ASCII 00 - 95)
1050
-		$keys_a = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_';
1051
-		$keys_a .= chr(0).chr(1).chr(2).chr(3).chr(4).chr(5).chr(6).chr(7).chr(8).chr(9);
1052
-		$keys_a .= chr(10).chr(11).chr(12).chr(13).chr(14).chr(15).chr(16).chr(17).chr(18).chr(19);
1053
-		$keys_a .= chr(20).chr(21).chr(22).chr(23).chr(24).chr(25).chr(26).chr(27).chr(28).chr(29);
1054
-		$keys_a .= chr(30).chr(31);
1055
-		// ASCII characters for code B (ASCII 32 - 127)
1056
-		$keys_b = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'.chr(127);
1057
-		// special codes
1058
-		$fnc_a = array(241 => 102, 242 => 97, 243 => 96, 244 => 101);
1059
-		$fnc_b = array(241 => 102, 242 => 97, 243 => 96, 244 => 100);
1060
-		// array of symbols
1061
-		$code_data = array();
1062
-		// lenght of the code
1063
-		$len = strlen($code);
1064
-		switch(strtoupper($type)) {
1065
-			case 'A': { // MODE A
1066
-				$startid = 103;
1067
-				for ($i = 0; $i < $len; ++$i) {
1068
-					$char = $code{$i};
1069
-					$char_id = ord($char);
1070
-					if (($char_id >= 241) AND ($char_id <= 244)) {
1071
-						$code_data[] = $fnc_a[$char_id];
1072
-					} elseif (($char_id >= 0) AND ($char_id <= 95)) {
1073
-						$code_data[] = strpos($keys_a, $char);
1074
-					} else {
1075
-						return false;
1076
-					}
1077
-				}
1078
-				break;
1079
-			}
1080
-			case 'B': { // MODE B
1081
-				$startid = 104;
1082
-				for ($i = 0; $i < $len; ++$i) {
1083
-					$char = $code{$i};
1084
-					$char_id = ord($char);
1085
-					if (($char_id >= 241) AND ($char_id <= 244)) {
1086
-						$code_data[] = $fnc_b[$char_id];
1087
-					} elseif (($char_id >= 32) AND ($char_id <= 127)) {
1088
-						$code_data[] = strpos($keys_b, $char);
1089
-					} else {
1090
-						return false;
1091
-					}
1092
-				}
1093
-				break;
1094
-			}
1095
-			case 'C': { // MODE C
1096
-				$startid = 105;
1097
-				if (ord($code[0]) == 241) {
1098
-					$code_data[] = 102;
1099
-					$code = substr($code, 1);
1100
-					--$len;
1101
-				}
1102
-				if (($len % 2) != 0) {
1103
-					// the length must be even
1104
-					return false;
1105
-				}
1106
-				for ($i = 0; $i < $len; $i+=2) {
1107
-					$chrnum = $code{$i}.$code{$i+1};
1108
-					if (preg_match('/([0-9]{2})/', $chrnum) > 0) {
1109
-						$code_data[] = intval($chrnum);
1110
-					} else {
1111
-						return false;
1112
-					}
1113
-				}
1114
-				break;
1115
-			}
1116
-			default: { // MODE AUTO
1117
-				// split code into sequences
1118
-				$sequence = array();
1119
-				// get numeric sequences (if any)
1120
-				$numseq = array();
1121
-				preg_match_all('/([0-9]{4,})/', $code, $numseq, PREG_OFFSET_CAPTURE);
1122
-				if (isset($numseq[1]) AND !empty($numseq[1])) {
1123
-					$end_offset = 0;
1124
-					foreach ($numseq[1] as $val) {
1125
-						$offset = $val[1];
1126
-						if ($offset > $end_offset) {
1127
-							// non numeric sequence
1128
-							$sequence = array_merge($sequence, $this->get128ABsequence(substr($code, $end_offset, ($offset - $end_offset))));
1129
-						}
1130
-						// numeric sequence
1131
-						$slen = strlen($val[0]);
1132
-						if (($slen % 2) != 0) {
1133
-							// the length must be even
1134
-							--$slen;
1135
-						}
1136
-						$sequence[] = array('C', substr($code, $offset, $slen), $slen);
1137
-						$end_offset = $offset + $slen;
1138
-					}
1139
-					if ($end_offset < $len) {
1140
-						$sequence = array_merge($sequence, $this->get128ABsequence(substr($code, $end_offset)));
1141
-					}
1142
-				} else {
1143
-					// text code (non C mode)
1144
-					$sequence = array_merge($sequence, $this->get128ABsequence($code));
1145
-				}
1146
-				// process the sequence
1147
-				foreach ($sequence as $key => $seq) {
1148
-					switch($seq[0]) {
1149
-						case 'A': {
1150
-							if ($key == 0) {
1151
-								$startid = 103;
1152
-							} elseif ($sequence[($key - 1)][0] != 'A') {
1153
-								if (($seq[2] == 1) AND ($key > 0) AND ($sequence[($key - 1)][0] == 'B') AND (!isset($sequence[($key - 1)][3]))) {
1154
-									// single character shift
1155
-									$code_data[] = 98;
1156
-									// mark shift
1157
-									$sequence[$key][3] = true;
1158
-								} elseif (!isset($sequence[($key - 1)][3])) {
1159
-									$code_data[] = 101;
1160
-								}
1161
-							}
1162
-							for ($i = 0; $i < $seq[2]; ++$i) {
1163
-								$char = $seq[1]{$i};
1164
-								$char_id = ord($char);
1165
-								if (($char_id >= 241) AND ($char_id <= 244)) {
1166
-									$code_data[] = $fnc_a[$char_id];
1167
-								} else {
1168
-									$code_data[] = strpos($keys_a, $char);
1169
-								}
1170
-							}
1171
-							break;
1172
-						}
1173
-						case 'B': {
1174
-							if ($key == 0) {
1175
-								$tmpchr = ord($seq[1][0]);
1176
-								if (($seq[2] == 1) AND ($tmpchr >= 241) AND ($tmpchr <= 244) AND isset($sequence[($key + 1)]) AND ($sequence[($key + 1)][0] != 'B')) {
1177
-									switch ($sequence[($key + 1)][0]) {
1178
-										case 'A': {
1179
-											$startid = 103;
1180
-											$sequence[$key][0] = 'A';
1181
-											$code_data[] = $fnc_a[$tmpchr];
1182
-											break;
1183
-										}
1184
-										case 'C': {
1185
-											$startid = 105;
1186
-											$sequence[$key][0] = 'C';
1187
-											$code_data[] = $fnc_a[$tmpchr];
1188
-											break;
1189
-										}
1190
-									}
1191
-									break;
1192
-								} else {
1193
-									$startid = 104;
1194
-								}
1195
-							} elseif ($sequence[($key - 1)][0] != 'B') {
1196
-								if (($seq[2] == 1) AND ($key > 0) AND ($sequence[($key - 1)][0] == 'A') AND (!isset($sequence[($key - 1)][3]))) {
1197
-									// single character shift
1198
-									$code_data[] = 98;
1199
-									// mark shift
1200
-									$sequence[$key][3] = true;
1201
-								} elseif (!isset($sequence[($key - 1)][3])) {
1202
-									$code_data[] = 100;
1203
-								}
1204
-							}
1205
-							for ($i = 0; $i < $seq[2]; ++$i) {
1206
-								$char = $seq[1]{$i};
1207
-								$char_id = ord($char);
1208
-								if (($char_id >= 241) AND ($char_id <= 244)) {
1209
-									$code_data[] = $fnc_b[$char_id];
1210
-								} else {
1211
-									$code_data[] = strpos($keys_b, $char);
1212
-								}
1213
-							}
1214
-							break;
1215
-						}
1216
-						case 'C': {
1217
-							if ($key == 0) {
1218
-								$startid = 105;
1219
-							} elseif ($sequence[($key - 1)][0] != 'C') {
1220
-								$code_data[] = 99;
1221
-							}
1222
-							for ($i = 0; $i < $seq[2]; $i+=2) {
1223
-								$chrnum = $seq[1]{$i}.$seq[1]{$i+1};
1224
-								$code_data[] = intval($chrnum);
1225
-							}
1226
-							break;
1227
-						}
1228
-					}
1229
-				}
1230
-			}
1231
-		}
1232
-		// calculate check character
1233
-		$sum = $startid;
1234
-		foreach ($code_data as $key => $val) {
1235
-			$sum += ($val * ($key + 1));
1236
-		}
1237
-		// add check character
1238
-		$code_data[] = ($sum % 103);
1239
-		// add stop sequence
1240
-		$code_data[] = 106;
1241
-		$code_data[] = 107;
1242
-		// add start code at the beginning
1243
-		array_unshift($code_data, $startid);
1244
-		// build barcode array
1245
-		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1246
-		foreach ($code_data as $val) {
1247
-			$seq = $chr[$val];
1248
-			for ($j = 0; $j < 6; ++$j) {
1249
-				if (($j % 2) == 0) {
1250
-					$t = true; // bar
1251
-				} else {
1252
-					$t = false; // space
1253
-				}
1254
-				$w = $seq{$j};
1255
-				$bararray['bcode'][] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1256
-				$bararray['maxw'] += $w;
1257
-			}
1258
-		}
1259
-		return $bararray;
1260
-	}
930
+    /**
931
+     * C128 barcodes.
932
+     * Very capable code, excellent density, high reliability; in very wide use world-wide
933
+     * @param $code (string) code to represent.
934
+     * @param $type (string) barcode type: A, B, C or empty for automatic switch (AUTO mode)
935
+     * @return array barcode representation.
936
+     * @protected
937
+     */
938
+    protected function barcode_c128($code, $type='') {
939
+        $chr = array(
940
+            '212222', /* 00 */
941
+            '222122', /* 01 */
942
+            '222221', /* 02 */
943
+            '121223', /* 03 */
944
+            '121322', /* 04 */
945
+            '131222', /* 05 */
946
+            '122213', /* 06 */
947
+            '122312', /* 07 */
948
+            '132212', /* 08 */
949
+            '221213', /* 09 */
950
+            '221312', /* 10 */
951
+            '231212', /* 11 */
952
+            '112232', /* 12 */
953
+            '122132', /* 13 */
954
+            '122231', /* 14 */
955
+            '113222', /* 15 */
956
+            '123122', /* 16 */
957
+            '123221', /* 17 */
958
+            '223211', /* 18 */
959
+            '221132', /* 19 */
960
+            '221231', /* 20 */
961
+            '213212', /* 21 */
962
+            '223112', /* 22 */
963
+            '312131', /* 23 */
964
+            '311222', /* 24 */
965
+            '321122', /* 25 */
966
+            '321221', /* 26 */
967
+            '312212', /* 27 */
968
+            '322112', /* 28 */
969
+            '322211', /* 29 */
970
+            '212123', /* 30 */
971
+            '212321', /* 31 */
972
+            '232121', /* 32 */
973
+            '111323', /* 33 */
974
+            '131123', /* 34 */
975
+            '131321', /* 35 */
976
+            '112313', /* 36 */
977
+            '132113', /* 37 */
978
+            '132311', /* 38 */
979
+            '211313', /* 39 */
980
+            '231113', /* 40 */
981
+            '231311', /* 41 */
982
+            '112133', /* 42 */
983
+            '112331', /* 43 */
984
+            '132131', /* 44 */
985
+            '113123', /* 45 */
986
+            '113321', /* 46 */
987
+            '133121', /* 47 */
988
+            '313121', /* 48 */
989
+            '211331', /* 49 */
990
+            '231131', /* 50 */
991
+            '213113', /* 51 */
992
+            '213311', /* 52 */
993
+            '213131', /* 53 */
994
+            '311123', /* 54 */
995
+            '311321', /* 55 */
996
+            '331121', /* 56 */
997
+            '312113', /* 57 */
998
+            '312311', /* 58 */
999
+            '332111', /* 59 */
1000
+            '314111', /* 60 */
1001
+            '221411', /* 61 */
1002
+            '431111', /* 62 */
1003
+            '111224', /* 63 */
1004
+            '111422', /* 64 */
1005
+            '121124', /* 65 */
1006
+            '121421', /* 66 */
1007
+            '141122', /* 67 */
1008
+            '141221', /* 68 */
1009
+            '112214', /* 69 */
1010
+            '112412', /* 70 */
1011
+            '122114', /* 71 */
1012
+            '122411', /* 72 */
1013
+            '142112', /* 73 */
1014
+            '142211', /* 74 */
1015
+            '241211', /* 75 */
1016
+            '221114', /* 76 */
1017
+            '413111', /* 77 */
1018
+            '241112', /* 78 */
1019
+            '134111', /* 79 */
1020
+            '111242', /* 80 */
1021
+            '121142', /* 81 */
1022
+            '121241', /* 82 */
1023
+            '114212', /* 83 */
1024
+            '124112', /* 84 */
1025
+            '124211', /* 85 */
1026
+            '411212', /* 86 */
1027
+            '421112', /* 87 */
1028
+            '421211', /* 88 */
1029
+            '212141', /* 89 */
1030
+            '214121', /* 90 */
1031
+            '412121', /* 91 */
1032
+            '111143', /* 92 */
1033
+            '111341', /* 93 */
1034
+            '131141', /* 94 */
1035
+            '114113', /* 95 */
1036
+            '114311', /* 96 */
1037
+            '411113', /* 97 */
1038
+            '411311', /* 98 */
1039
+            '113141', /* 99 */
1040
+            '114131', /* 100 */
1041
+            '311141', /* 101 */
1042
+            '411131', /* 102 */
1043
+            '211412', /* 103 START A */
1044
+            '211214', /* 104 START B */
1045
+            '211232', /* 105 START C */
1046
+            '233111', /* STOP */
1047
+            '200000'  /* END */
1048
+        );
1049
+        // ASCII characters for code A (ASCII 00 - 95)
1050
+        $keys_a = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_';
1051
+        $keys_a .= chr(0).chr(1).chr(2).chr(3).chr(4).chr(5).chr(6).chr(7).chr(8).chr(9);
1052
+        $keys_a .= chr(10).chr(11).chr(12).chr(13).chr(14).chr(15).chr(16).chr(17).chr(18).chr(19);
1053
+        $keys_a .= chr(20).chr(21).chr(22).chr(23).chr(24).chr(25).chr(26).chr(27).chr(28).chr(29);
1054
+        $keys_a .= chr(30).chr(31);
1055
+        // ASCII characters for code B (ASCII 32 - 127)
1056
+        $keys_b = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'.chr(127);
1057
+        // special codes
1058
+        $fnc_a = array(241 => 102, 242 => 97, 243 => 96, 244 => 101);
1059
+        $fnc_b = array(241 => 102, 242 => 97, 243 => 96, 244 => 100);
1060
+        // array of symbols
1061
+        $code_data = array();
1062
+        // lenght of the code
1063
+        $len = strlen($code);
1064
+        switch(strtoupper($type)) {
1065
+            case 'A': { // MODE A
1066
+                $startid = 103;
1067
+                for ($i = 0; $i < $len; ++$i) {
1068
+                    $char = $code{$i};
1069
+                    $char_id = ord($char);
1070
+                    if (($char_id >= 241) AND ($char_id <= 244)) {
1071
+                        $code_data[] = $fnc_a[$char_id];
1072
+                    } elseif (($char_id >= 0) AND ($char_id <= 95)) {
1073
+                        $code_data[] = strpos($keys_a, $char);
1074
+                    } else {
1075
+                        return false;
1076
+                    }
1077
+                }
1078
+                break;
1079
+            }
1080
+            case 'B': { // MODE B
1081
+                $startid = 104;
1082
+                for ($i = 0; $i < $len; ++$i) {
1083
+                    $char = $code{$i};
1084
+                    $char_id = ord($char);
1085
+                    if (($char_id >= 241) AND ($char_id <= 244)) {
1086
+                        $code_data[] = $fnc_b[$char_id];
1087
+                    } elseif (($char_id >= 32) AND ($char_id <= 127)) {
1088
+                        $code_data[] = strpos($keys_b, $char);
1089
+                    } else {
1090
+                        return false;
1091
+                    }
1092
+                }
1093
+                break;
1094
+            }
1095
+            case 'C': { // MODE C
1096
+                $startid = 105;
1097
+                if (ord($code[0]) == 241) {
1098
+                    $code_data[] = 102;
1099
+                    $code = substr($code, 1);
1100
+                    --$len;
1101
+                }
1102
+                if (($len % 2) != 0) {
1103
+                    // the length must be even
1104
+                    return false;
1105
+                }
1106
+                for ($i = 0; $i < $len; $i+=2) {
1107
+                    $chrnum = $code{$i}.$code{$i+1};
1108
+                    if (preg_match('/([0-9]{2})/', $chrnum) > 0) {
1109
+                        $code_data[] = intval($chrnum);
1110
+                    } else {
1111
+                        return false;
1112
+                    }
1113
+                }
1114
+                break;
1115
+            }
1116
+            default: { // MODE AUTO
1117
+                // split code into sequences
1118
+                $sequence = array();
1119
+                // get numeric sequences (if any)
1120
+                $numseq = array();
1121
+                preg_match_all('/([0-9]{4,})/', $code, $numseq, PREG_OFFSET_CAPTURE);
1122
+                if (isset($numseq[1]) AND !empty($numseq[1])) {
1123
+                    $end_offset = 0;
1124
+                    foreach ($numseq[1] as $val) {
1125
+                        $offset = $val[1];
1126
+                        if ($offset > $end_offset) {
1127
+                            // non numeric sequence
1128
+                            $sequence = array_merge($sequence, $this->get128ABsequence(substr($code, $end_offset, ($offset - $end_offset))));
1129
+                        }
1130
+                        // numeric sequence
1131
+                        $slen = strlen($val[0]);
1132
+                        if (($slen % 2) != 0) {
1133
+                            // the length must be even
1134
+                            --$slen;
1135
+                        }
1136
+                        $sequence[] = array('C', substr($code, $offset, $slen), $slen);
1137
+                        $end_offset = $offset + $slen;
1138
+                    }
1139
+                    if ($end_offset < $len) {
1140
+                        $sequence = array_merge($sequence, $this->get128ABsequence(substr($code, $end_offset)));
1141
+                    }
1142
+                } else {
1143
+                    // text code (non C mode)
1144
+                    $sequence = array_merge($sequence, $this->get128ABsequence($code));
1145
+                }
1146
+                // process the sequence
1147
+                foreach ($sequence as $key => $seq) {
1148
+                    switch($seq[0]) {
1149
+                        case 'A': {
1150
+                            if ($key == 0) {
1151
+                                $startid = 103;
1152
+                            } elseif ($sequence[($key - 1)][0] != 'A') {
1153
+                                if (($seq[2] == 1) AND ($key > 0) AND ($sequence[($key - 1)][0] == 'B') AND (!isset($sequence[($key - 1)][3]))) {
1154
+                                    // single character shift
1155
+                                    $code_data[] = 98;
1156
+                                    // mark shift
1157
+                                    $sequence[$key][3] = true;
1158
+                                } elseif (!isset($sequence[($key - 1)][3])) {
1159
+                                    $code_data[] = 101;
1160
+                                }
1161
+                            }
1162
+                            for ($i = 0; $i < $seq[2]; ++$i) {
1163
+                                $char = $seq[1]{$i};
1164
+                                $char_id = ord($char);
1165
+                                if (($char_id >= 241) AND ($char_id <= 244)) {
1166
+                                    $code_data[] = $fnc_a[$char_id];
1167
+                                } else {
1168
+                                    $code_data[] = strpos($keys_a, $char);
1169
+                                }
1170
+                            }
1171
+                            break;
1172
+                        }
1173
+                        case 'B': {
1174
+                            if ($key == 0) {
1175
+                                $tmpchr = ord($seq[1][0]);
1176
+                                if (($seq[2] == 1) AND ($tmpchr >= 241) AND ($tmpchr <= 244) AND isset($sequence[($key + 1)]) AND ($sequence[($key + 1)][0] != 'B')) {
1177
+                                    switch ($sequence[($key + 1)][0]) {
1178
+                                        case 'A': {
1179
+                                            $startid = 103;
1180
+                                            $sequence[$key][0] = 'A';
1181
+                                            $code_data[] = $fnc_a[$tmpchr];
1182
+                                            break;
1183
+                                        }
1184
+                                        case 'C': {
1185
+                                            $startid = 105;
1186
+                                            $sequence[$key][0] = 'C';
1187
+                                            $code_data[] = $fnc_a[$tmpchr];
1188
+                                            break;
1189
+                                        }
1190
+                                    }
1191
+                                    break;
1192
+                                } else {
1193
+                                    $startid = 104;
1194
+                                }
1195
+                            } elseif ($sequence[($key - 1)][0] != 'B') {
1196
+                                if (($seq[2] == 1) AND ($key > 0) AND ($sequence[($key - 1)][0] == 'A') AND (!isset($sequence[($key - 1)][3]))) {
1197
+                                    // single character shift
1198
+                                    $code_data[] = 98;
1199
+                                    // mark shift
1200
+                                    $sequence[$key][3] = true;
1201
+                                } elseif (!isset($sequence[($key - 1)][3])) {
1202
+                                    $code_data[] = 100;
1203
+                                }
1204
+                            }
1205
+                            for ($i = 0; $i < $seq[2]; ++$i) {
1206
+                                $char = $seq[1]{$i};
1207
+                                $char_id = ord($char);
1208
+                                if (($char_id >= 241) AND ($char_id <= 244)) {
1209
+                                    $code_data[] = $fnc_b[$char_id];
1210
+                                } else {
1211
+                                    $code_data[] = strpos($keys_b, $char);
1212
+                                }
1213
+                            }
1214
+                            break;
1215
+                        }
1216
+                        case 'C': {
1217
+                            if ($key == 0) {
1218
+                                $startid = 105;
1219
+                            } elseif ($sequence[($key - 1)][0] != 'C') {
1220
+                                $code_data[] = 99;
1221
+                            }
1222
+                            for ($i = 0; $i < $seq[2]; $i+=2) {
1223
+                                $chrnum = $seq[1]{$i}.$seq[1]{$i+1};
1224
+                                $code_data[] = intval($chrnum);
1225
+                            }
1226
+                            break;
1227
+                        }
1228
+                    }
1229
+                }
1230
+            }
1231
+        }
1232
+        // calculate check character
1233
+        $sum = $startid;
1234
+        foreach ($code_data as $key => $val) {
1235
+            $sum += ($val * ($key + 1));
1236
+        }
1237
+        // add check character
1238
+        $code_data[] = ($sum % 103);
1239
+        // add stop sequence
1240
+        $code_data[] = 106;
1241
+        $code_data[] = 107;
1242
+        // add start code at the beginning
1243
+        array_unshift($code_data, $startid);
1244
+        // build barcode array
1245
+        $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1246
+        foreach ($code_data as $val) {
1247
+            $seq = $chr[$val];
1248
+            for ($j = 0; $j < 6; ++$j) {
1249
+                if (($j % 2) == 0) {
1250
+                    $t = true; // bar
1251
+                } else {
1252
+                    $t = false; // space
1253
+                }
1254
+                $w = $seq{$j};
1255
+                $bararray['bcode'][] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1256
+                $bararray['maxw'] += $w;
1257
+            }
1258
+        }
1259
+        return $bararray;
1260
+    }
1261 1261
 
1262
-	/**
1263
-	 * Split text code in A/B sequence for 128 code
1264
-	 * @param $code (string) code to split.
1265
-	 * @return array sequence
1266
-	 * @protected
1267
-	 */
1268
-	protected function get128ABsequence($code) {
1269
-		$len = strlen($code);
1270
-		$sequence = array();
1271
-		// get A sequences (if any)
1272
-		$numseq = array();
1273
-		preg_match_all('/([\0-\31])/', $code, $numseq, PREG_OFFSET_CAPTURE);
1274
-		if (isset($numseq[1]) AND !empty($numseq[1])) {
1275
-			$end_offset = 0;
1276
-			foreach ($numseq[1] as $val) {
1277
-				$offset = $val[1];
1278
-				if ($offset > $end_offset) {
1279
-					// B sequence
1280
-					$sequence[] = array('B', substr($code, $end_offset, ($offset - $end_offset)), ($offset - $end_offset));
1281
-				}
1282
-				// A sequence
1283
-				$slen = strlen($val[0]);
1284
-				$sequence[] = array('A', substr($code, $offset, $slen), $slen);
1285
-				$end_offset = $offset + $slen;
1286
-			}
1287
-			if ($end_offset < $len) {
1288
-				$sequence[] = array('B', substr($code, $end_offset), ($len - $end_offset));
1289
-			}
1290
-		} else {
1291
-			// only B sequence
1292
-			$sequence[] = array('B', $code, $len);
1293
-		}
1294
-		return $sequence;
1295
-	}
1262
+    /**
1263
+     * Split text code in A/B sequence for 128 code
1264
+     * @param $code (string) code to split.
1265
+     * @return array sequence
1266
+     * @protected
1267
+     */
1268
+    protected function get128ABsequence($code) {
1269
+        $len = strlen($code);
1270
+        $sequence = array();
1271
+        // get A sequences (if any)
1272
+        $numseq = array();
1273
+        preg_match_all('/([\0-\31])/', $code, $numseq, PREG_OFFSET_CAPTURE);
1274
+        if (isset($numseq[1]) AND !empty($numseq[1])) {
1275
+            $end_offset = 0;
1276
+            foreach ($numseq[1] as $val) {
1277
+                $offset = $val[1];
1278
+                if ($offset > $end_offset) {
1279
+                    // B sequence
1280
+                    $sequence[] = array('B', substr($code, $end_offset, ($offset - $end_offset)), ($offset - $end_offset));
1281
+                }
1282
+                // A sequence
1283
+                $slen = strlen($val[0]);
1284
+                $sequence[] = array('A', substr($code, $offset, $slen), $slen);
1285
+                $end_offset = $offset + $slen;
1286
+            }
1287
+            if ($end_offset < $len) {
1288
+                $sequence[] = array('B', substr($code, $end_offset), ($len - $end_offset));
1289
+            }
1290
+        } else {
1291
+            // only B sequence
1292
+            $sequence[] = array('B', $code, $len);
1293
+        }
1294
+        return $sequence;
1295
+    }
1296 1296
 
1297
-	/**
1298
-	 * EAN13 and UPC-A barcodes.
1299
-	 * EAN13: European Article Numbering international retail product code
1300
-	 * UPC-A: Universal product code seen on almost all retail products in the USA and Canada
1301
-	 * UPC-E: Short version of UPC symbol
1302
-	 * @param $code (string) code to represent.
1303
-	 * @param $len (string) barcode type: 6 = UPC-E, 8 = EAN8, 13 = EAN13, 12 = UPC-A
1304
-	 * @return array barcode representation.
1305
-	 * @protected
1306
-	 */
1307
-	protected function barcode_eanupc($code, $len=13) {
1308
-		$upce = false;
1309
-		if ($len == 6) {
1310
-			$len = 12; // UPC-A
1311
-			$upce = true; // UPC-E mode
1312
-		}
1313
-		$data_len = $len - 1;
1314
-		//Padding
1315
-		$code = str_pad($code, $data_len, '0', STR_PAD_LEFT);
1316
-		$code_len = strlen($code);
1317
-		// calculate check digit
1318
-		$sum_a = 0;
1319
-		for ($i = 1; $i < $data_len; $i+=2) {
1320
-			$sum_a += $code{$i};
1321
-		}
1322
-		if ($len > 12) {
1323
-			$sum_a *= 3;
1324
-		}
1325
-		$sum_b = 0;
1326
-		for ($i = 0; $i < $data_len; $i+=2) {
1327
-			$sum_b += ($code{$i});
1328
-		}
1329
-		if ($len < 13) {
1330
-			$sum_b *= 3;
1331
-		}
1332
-		$r = ($sum_a + $sum_b) % 10;
1333
-		if($r > 0) {
1334
-			$r = (10 - $r);
1335
-		}
1336
-		if ($code_len == $data_len) {
1337
-			// add check digit
1338
-			$code .= $r;
1339
-		} elseif ($r !== intval($code{$data_len})) {
1340
-			// wrong checkdigit
1341
-			return false;
1342
-		}
1343
-		if ($len == 12) {
1344
-			// UPC-A
1345
-			$code = '0'.$code;
1346
-			++$len;
1347
-		}
1348
-		if ($upce) {
1349
-			// convert UPC-A to UPC-E
1350
-			$tmp = substr($code, 4, 3);
1351
-			if (($tmp == '000') OR ($tmp == '100') OR ($tmp == '200')) {
1352
-				// manufacturer code ends in 000, 100, or 200
1353
-				$upce_code = substr($code, 2, 2).substr($code, 9, 3).substr($code, 4, 1);
1354
-			} else {
1355
-				$tmp = substr($code, 5, 2);
1356
-				if ($tmp == '00') {
1357
-					// manufacturer code ends in 00
1358
-					$upce_code = substr($code, 2, 3).substr($code, 10, 2).'3';
1359
-				} else {
1360
-					$tmp = substr($code, 6, 1);
1361
-					if ($tmp == '0') {
1362
-						// manufacturer code ends in 0
1363
-						$upce_code = substr($code, 2, 4).substr($code, 11, 1).'4';
1364
-					} else {
1365
-						// manufacturer code does not end in zero
1366
-						$upce_code = substr($code, 2, 5).substr($code, 11, 1);
1367
-					}
1368
-				}
1369
-			}
1370
-		}
1371
-		//Convert digits to bars
1372
-		$codes = array(
1373
-			'A'=>array( // left odd parity
1374
-				'0'=>'0001101',
1375
-				'1'=>'0011001',
1376
-				'2'=>'0010011',
1377
-				'3'=>'0111101',
1378
-				'4'=>'0100011',
1379
-				'5'=>'0110001',
1380
-				'6'=>'0101111',
1381
-				'7'=>'0111011',
1382
-				'8'=>'0110111',
1383
-				'9'=>'0001011'),
1384
-			'B'=>array( // left even parity
1385
-				'0'=>'0100111',
1386
-				'1'=>'0110011',
1387
-				'2'=>'0011011',
1388
-				'3'=>'0100001',
1389
-				'4'=>'0011101',
1390
-				'5'=>'0111001',
1391
-				'6'=>'0000101',
1392
-				'7'=>'0010001',
1393
-				'8'=>'0001001',
1394
-				'9'=>'0010111'),
1395
-			'C'=>array( // right
1396
-				'0'=>'1110010',
1397
-				'1'=>'1100110',
1398
-				'2'=>'1101100',
1399
-				'3'=>'1000010',
1400
-				'4'=>'1011100',
1401
-				'5'=>'1001110',
1402
-				'6'=>'1010000',
1403
-				'7'=>'1000100',
1404
-				'8'=>'1001000',
1405
-				'9'=>'1110100')
1406
-		);
1407
-		$parities = array(
1408
-			'0'=>array('A','A','A','A','A','A'),
1409
-			'1'=>array('A','A','B','A','B','B'),
1410
-			'2'=>array('A','A','B','B','A','B'),
1411
-			'3'=>array('A','A','B','B','B','A'),
1412
-			'4'=>array('A','B','A','A','B','B'),
1413
-			'5'=>array('A','B','B','A','A','B'),
1414
-			'6'=>array('A','B','B','B','A','A'),
1415
-			'7'=>array('A','B','A','B','A','B'),
1416
-			'8'=>array('A','B','A','B','B','A'),
1417
-			'9'=>array('A','B','B','A','B','A')
1418
-		);
1419
-		$upce_parities = array();
1420
-		$upce_parities[0] = array(
1421
-			'0'=>array('B','B','B','A','A','A'),
1422
-			'1'=>array('B','B','A','B','A','A'),
1423
-			'2'=>array('B','B','A','A','B','A'),
1424
-			'3'=>array('B','B','A','A','A','B'),
1425
-			'4'=>array('B','A','B','B','A','A'),
1426
-			'5'=>array('B','A','A','B','B','A'),
1427
-			'6'=>array('B','A','A','A','B','B'),
1428
-			'7'=>array('B','A','B','A','B','A'),
1429
-			'8'=>array('B','A','B','A','A','B'),
1430
-			'9'=>array('B','A','A','B','A','B')
1431
-		);
1432
-		$upce_parities[1] = array(
1433
-			'0'=>array('A','A','A','B','B','B'),
1434
-			'1'=>array('A','A','B','A','B','B'),
1435
-			'2'=>array('A','A','B','B','A','B'),
1436
-			'3'=>array('A','A','B','B','B','A'),
1437
-			'4'=>array('A','B','A','A','B','B'),
1438
-			'5'=>array('A','B','B','A','A','B'),
1439
-			'6'=>array('A','B','B','B','A','A'),
1440
-			'7'=>array('A','B','A','B','A','B'),
1441
-			'8'=>array('A','B','A','B','B','A'),
1442
-			'9'=>array('A','B','B','A','B','A')
1443
-		);
1444
-		$k = 0;
1445
-		$seq = '101'; // left guard bar
1446
-		if ($upce) {
1447
-			$bararray = array('code' => $upce_code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1448
-			$p = $upce_parities[$code[1]][$r];
1449
-			for ($i = 0; $i < 6; ++$i) {
1450
-				$seq .= $codes[$p[$i]][$upce_code{$i}];
1451
-			}
1452
-			$seq .= '010101'; // right guard bar
1453
-		} else {
1454
-			$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1455
-			$half_len = intval(ceil($len / 2));
1456
-			if ($len == 8) {
1457
-				for ($i = 0; $i < $half_len; ++$i) {
1458
-					$seq .= $codes['A'][$code{$i}];
1459
-				}
1460
-			} else {
1461
-				$p = $parities[$code[0]];
1462
-				for ($i = 1; $i < $half_len; ++$i) {
1463
-					$seq .= $codes[$p[$i-1]][$code{$i}];
1464
-				}
1465
-			}
1466
-			$seq .= '01010'; // center guard bar
1467
-			for ($i = $half_len; $i < $len; ++$i) {
1468
-				$seq .= $codes['C'][$code{$i}];
1469
-			}
1470
-			$seq .= '101'; // right guard bar
1471
-		}
1472
-		$clen = strlen($seq);
1473
-		$w = 0;
1474
-		for ($i = 0; $i < $clen; ++$i) {
1475
-			$w += 1;
1476
-			if (($i == ($clen - 1)) OR (($i < ($clen - 1)) AND ($seq{$i} != $seq{($i+1)}))) {
1477
-				if ($seq{$i} == '1') {
1478
-					$t = true; // bar
1479
-				} else {
1480
-					$t = false; // space
1481
-				}
1482
-				$bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1483
-				$bararray['maxw'] += $w;
1484
-				++$k;
1485
-				$w = 0;
1486
-			}
1487
-		}
1488
-		return $bararray;
1489
-	}
1297
+    /**
1298
+     * EAN13 and UPC-A barcodes.
1299
+     * EAN13: European Article Numbering international retail product code
1300
+     * UPC-A: Universal product code seen on almost all retail products in the USA and Canada
1301
+     * UPC-E: Short version of UPC symbol
1302
+     * @param $code (string) code to represent.
1303
+     * @param $len (string) barcode type: 6 = UPC-E, 8 = EAN8, 13 = EAN13, 12 = UPC-A
1304
+     * @return array barcode representation.
1305
+     * @protected
1306
+     */
1307
+    protected function barcode_eanupc($code, $len=13) {
1308
+        $upce = false;
1309
+        if ($len == 6) {
1310
+            $len = 12; // UPC-A
1311
+            $upce = true; // UPC-E mode
1312
+        }
1313
+        $data_len = $len - 1;
1314
+        //Padding
1315
+        $code = str_pad($code, $data_len, '0', STR_PAD_LEFT);
1316
+        $code_len = strlen($code);
1317
+        // calculate check digit
1318
+        $sum_a = 0;
1319
+        for ($i = 1; $i < $data_len; $i+=2) {
1320
+            $sum_a += $code{$i};
1321
+        }
1322
+        if ($len > 12) {
1323
+            $sum_a *= 3;
1324
+        }
1325
+        $sum_b = 0;
1326
+        for ($i = 0; $i < $data_len; $i+=2) {
1327
+            $sum_b += ($code{$i});
1328
+        }
1329
+        if ($len < 13) {
1330
+            $sum_b *= 3;
1331
+        }
1332
+        $r = ($sum_a + $sum_b) % 10;
1333
+        if($r > 0) {
1334
+            $r = (10 - $r);
1335
+        }
1336
+        if ($code_len == $data_len) {
1337
+            // add check digit
1338
+            $code .= $r;
1339
+        } elseif ($r !== intval($code{$data_len})) {
1340
+            // wrong checkdigit
1341
+            return false;
1342
+        }
1343
+        if ($len == 12) {
1344
+            // UPC-A
1345
+            $code = '0'.$code;
1346
+            ++$len;
1347
+        }
1348
+        if ($upce) {
1349
+            // convert UPC-A to UPC-E
1350
+            $tmp = substr($code, 4, 3);
1351
+            if (($tmp == '000') OR ($tmp == '100') OR ($tmp == '200')) {
1352
+                // manufacturer code ends in 000, 100, or 200
1353
+                $upce_code = substr($code, 2, 2).substr($code, 9, 3).substr($code, 4, 1);
1354
+            } else {
1355
+                $tmp = substr($code, 5, 2);
1356
+                if ($tmp == '00') {
1357
+                    // manufacturer code ends in 00
1358
+                    $upce_code = substr($code, 2, 3).substr($code, 10, 2).'3';
1359
+                } else {
1360
+                    $tmp = substr($code, 6, 1);
1361
+                    if ($tmp == '0') {
1362
+                        // manufacturer code ends in 0
1363
+                        $upce_code = substr($code, 2, 4).substr($code, 11, 1).'4';
1364
+                    } else {
1365
+                        // manufacturer code does not end in zero
1366
+                        $upce_code = substr($code, 2, 5).substr($code, 11, 1);
1367
+                    }
1368
+                }
1369
+            }
1370
+        }
1371
+        //Convert digits to bars
1372
+        $codes = array(
1373
+            'A'=>array( // left odd parity
1374
+                '0'=>'0001101',
1375
+                '1'=>'0011001',
1376
+                '2'=>'0010011',
1377
+                '3'=>'0111101',
1378
+                '4'=>'0100011',
1379
+                '5'=>'0110001',
1380
+                '6'=>'0101111',
1381
+                '7'=>'0111011',
1382
+                '8'=>'0110111',
1383
+                '9'=>'0001011'),
1384
+            'B'=>array( // left even parity
1385
+                '0'=>'0100111',
1386
+                '1'=>'0110011',
1387
+                '2'=>'0011011',
1388
+                '3'=>'0100001',
1389
+                '4'=>'0011101',
1390
+                '5'=>'0111001',
1391
+                '6'=>'0000101',
1392
+                '7'=>'0010001',
1393
+                '8'=>'0001001',
1394
+                '9'=>'0010111'),
1395
+            'C'=>array( // right
1396
+                '0'=>'1110010',
1397
+                '1'=>'1100110',
1398
+                '2'=>'1101100',
1399
+                '3'=>'1000010',
1400
+                '4'=>'1011100',
1401
+                '5'=>'1001110',
1402
+                '6'=>'1010000',
1403
+                '7'=>'1000100',
1404
+                '8'=>'1001000',
1405
+                '9'=>'1110100')
1406
+        );
1407
+        $parities = array(
1408
+            '0'=>array('A','A','A','A','A','A'),
1409
+            '1'=>array('A','A','B','A','B','B'),
1410
+            '2'=>array('A','A','B','B','A','B'),
1411
+            '3'=>array('A','A','B','B','B','A'),
1412
+            '4'=>array('A','B','A','A','B','B'),
1413
+            '5'=>array('A','B','B','A','A','B'),
1414
+            '6'=>array('A','B','B','B','A','A'),
1415
+            '7'=>array('A','B','A','B','A','B'),
1416
+            '8'=>array('A','B','A','B','B','A'),
1417
+            '9'=>array('A','B','B','A','B','A')
1418
+        );
1419
+        $upce_parities = array();
1420
+        $upce_parities[0] = array(
1421
+            '0'=>array('B','B','B','A','A','A'),
1422
+            '1'=>array('B','B','A','B','A','A'),
1423
+            '2'=>array('B','B','A','A','B','A'),
1424
+            '3'=>array('B','B','A','A','A','B'),
1425
+            '4'=>array('B','A','B','B','A','A'),
1426
+            '5'=>array('B','A','A','B','B','A'),
1427
+            '6'=>array('B','A','A','A','B','B'),
1428
+            '7'=>array('B','A','B','A','B','A'),
1429
+            '8'=>array('B','A','B','A','A','B'),
1430
+            '9'=>array('B','A','A','B','A','B')
1431
+        );
1432
+        $upce_parities[1] = array(
1433
+            '0'=>array('A','A','A','B','B','B'),
1434
+            '1'=>array('A','A','B','A','B','B'),
1435
+            '2'=>array('A','A','B','B','A','B'),
1436
+            '3'=>array('A','A','B','B','B','A'),
1437
+            '4'=>array('A','B','A','A','B','B'),
1438
+            '5'=>array('A','B','B','A','A','B'),
1439
+            '6'=>array('A','B','B','B','A','A'),
1440
+            '7'=>array('A','B','A','B','A','B'),
1441
+            '8'=>array('A','B','A','B','B','A'),
1442
+            '9'=>array('A','B','B','A','B','A')
1443
+        );
1444
+        $k = 0;
1445
+        $seq = '101'; // left guard bar
1446
+        if ($upce) {
1447
+            $bararray = array('code' => $upce_code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1448
+            $p = $upce_parities[$code[1]][$r];
1449
+            for ($i = 0; $i < 6; ++$i) {
1450
+                $seq .= $codes[$p[$i]][$upce_code{$i}];
1451
+            }
1452
+            $seq .= '010101'; // right guard bar
1453
+        } else {
1454
+            $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1455
+            $half_len = intval(ceil($len / 2));
1456
+            if ($len == 8) {
1457
+                for ($i = 0; $i < $half_len; ++$i) {
1458
+                    $seq .= $codes['A'][$code{$i}];
1459
+                }
1460
+            } else {
1461
+                $p = $parities[$code[0]];
1462
+                for ($i = 1; $i < $half_len; ++$i) {
1463
+                    $seq .= $codes[$p[$i-1]][$code{$i}];
1464
+                }
1465
+            }
1466
+            $seq .= '01010'; // center guard bar
1467
+            for ($i = $half_len; $i < $len; ++$i) {
1468
+                $seq .= $codes['C'][$code{$i}];
1469
+            }
1470
+            $seq .= '101'; // right guard bar
1471
+        }
1472
+        $clen = strlen($seq);
1473
+        $w = 0;
1474
+        for ($i = 0; $i < $clen; ++$i) {
1475
+            $w += 1;
1476
+            if (($i == ($clen - 1)) OR (($i < ($clen - 1)) AND ($seq{$i} != $seq{($i+1)}))) {
1477
+                if ($seq{$i} == '1') {
1478
+                    $t = true; // bar
1479
+                } else {
1480
+                    $t = false; // space
1481
+                }
1482
+                $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1483
+                $bararray['maxw'] += $w;
1484
+                ++$k;
1485
+                $w = 0;
1486
+            }
1487
+        }
1488
+        return $bararray;
1489
+    }
1490 1490
 
1491
-	/**
1492
-	 * UPC-Based Extentions
1493
-	 * 2-Digit Ext.: Used to indicate magazines and newspaper issue numbers
1494
-	 * 5-Digit Ext.: Used to mark suggested retail price of books
1495
-	 * @param $code (string) code to represent.
1496
-	 * @param $len (string) barcode type: 2 = 2-Digit, 5 = 5-Digit
1497
-	 * @return array barcode representation.
1498
-	 * @protected
1499
-	 */
1500
-	protected function barcode_eanext($code, $len=5) {
1501
-		//Padding
1502
-		$code = str_pad($code, $len, '0', STR_PAD_LEFT);
1503
-		// calculate check digit
1504
-		if ($len == 2) {
1505
-			$r = $code % 4;
1506
-		} elseif ($len == 5) {
1507
-			$r = (3 * ($code[0] + $code[2] + $code[4])) + (9 * ($code[1] + $code[3]));
1508
-			$r %= 10;
1509
-		} else {
1510
-			return false;
1511
-		}
1512
-		//Convert digits to bars
1513
-		$codes = array(
1514
-			'A'=>array( // left odd parity
1515
-				'0'=>'0001101',
1516
-				'1'=>'0011001',
1517
-				'2'=>'0010011',
1518
-				'3'=>'0111101',
1519
-				'4'=>'0100011',
1520
-				'5'=>'0110001',
1521
-				'6'=>'0101111',
1522
-				'7'=>'0111011',
1523
-				'8'=>'0110111',
1524
-				'9'=>'0001011'),
1525
-			'B'=>array( // left even parity
1526
-				'0'=>'0100111',
1527
-				'1'=>'0110011',
1528
-				'2'=>'0011011',
1529
-				'3'=>'0100001',
1530
-				'4'=>'0011101',
1531
-				'5'=>'0111001',
1532
-				'6'=>'0000101',
1533
-				'7'=>'0010001',
1534
-				'8'=>'0001001',
1535
-				'9'=>'0010111')
1536
-		);
1537
-		$parities = array();
1538
-		$parities[2] = array(
1539
-			'0'=>array('A','A'),
1540
-			'1'=>array('A','B'),
1541
-			'2'=>array('B','A'),
1542
-			'3'=>array('B','B')
1543
-		);
1544
-		$parities[5] = array(
1545
-			'0'=>array('B','B','A','A','A'),
1546
-			'1'=>array('B','A','B','A','A'),
1547
-			'2'=>array('B','A','A','B','A'),
1548
-			'3'=>array('B','A','A','A','B'),
1549
-			'4'=>array('A','B','B','A','A'),
1550
-			'5'=>array('A','A','B','B','A'),
1551
-			'6'=>array('A','A','A','B','B'),
1552
-			'7'=>array('A','B','A','B','A'),
1553
-			'8'=>array('A','B','A','A','B'),
1554
-			'9'=>array('A','A','B','A','B')
1555
-		);
1556
-		$p = $parities[$len][$r];
1557
-		$seq = '1011'; // left guard bar
1558
-		$seq .= $codes[$p[0]][$code[0]];
1559
-		for ($i = 1; $i < $len; ++$i) {
1560
-			$seq .= '01'; // separator
1561
-			$seq .= $codes[$p[$i]][$code{$i}];
1562
-		}
1563
-		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1564
-		return $this->binseq_to_array($seq, $bararray);
1565
-	}
1491
+    /**
1492
+     * UPC-Based Extentions
1493
+     * 2-Digit Ext.: Used to indicate magazines and newspaper issue numbers
1494
+     * 5-Digit Ext.: Used to mark suggested retail price of books
1495
+     * @param $code (string) code to represent.
1496
+     * @param $len (string) barcode type: 2 = 2-Digit, 5 = 5-Digit
1497
+     * @return array barcode representation.
1498
+     * @protected
1499
+     */
1500
+    protected function barcode_eanext($code, $len=5) {
1501
+        //Padding
1502
+        $code = str_pad($code, $len, '0', STR_PAD_LEFT);
1503
+        // calculate check digit
1504
+        if ($len == 2) {
1505
+            $r = $code % 4;
1506
+        } elseif ($len == 5) {
1507
+            $r = (3 * ($code[0] + $code[2] + $code[4])) + (9 * ($code[1] + $code[3]));
1508
+            $r %= 10;
1509
+        } else {
1510
+            return false;
1511
+        }
1512
+        //Convert digits to bars
1513
+        $codes = array(
1514
+            'A'=>array( // left odd parity
1515
+                '0'=>'0001101',
1516
+                '1'=>'0011001',
1517
+                '2'=>'0010011',
1518
+                '3'=>'0111101',
1519
+                '4'=>'0100011',
1520
+                '5'=>'0110001',
1521
+                '6'=>'0101111',
1522
+                '7'=>'0111011',
1523
+                '8'=>'0110111',
1524
+                '9'=>'0001011'),
1525
+            'B'=>array( // left even parity
1526
+                '0'=>'0100111',
1527
+                '1'=>'0110011',
1528
+                '2'=>'0011011',
1529
+                '3'=>'0100001',
1530
+                '4'=>'0011101',
1531
+                '5'=>'0111001',
1532
+                '6'=>'0000101',
1533
+                '7'=>'0010001',
1534
+                '8'=>'0001001',
1535
+                '9'=>'0010111')
1536
+        );
1537
+        $parities = array();
1538
+        $parities[2] = array(
1539
+            '0'=>array('A','A'),
1540
+            '1'=>array('A','B'),
1541
+            '2'=>array('B','A'),
1542
+            '3'=>array('B','B')
1543
+        );
1544
+        $parities[5] = array(
1545
+            '0'=>array('B','B','A','A','A'),
1546
+            '1'=>array('B','A','B','A','A'),
1547
+            '2'=>array('B','A','A','B','A'),
1548
+            '3'=>array('B','A','A','A','B'),
1549
+            '4'=>array('A','B','B','A','A'),
1550
+            '5'=>array('A','A','B','B','A'),
1551
+            '6'=>array('A','A','A','B','B'),
1552
+            '7'=>array('A','B','A','B','A'),
1553
+            '8'=>array('A','B','A','A','B'),
1554
+            '9'=>array('A','A','B','A','B')
1555
+        );
1556
+        $p = $parities[$len][$r];
1557
+        $seq = '1011'; // left guard bar
1558
+        $seq .= $codes[$p[0]][$code[0]];
1559
+        for ($i = 1; $i < $len; ++$i) {
1560
+            $seq .= '01'; // separator
1561
+            $seq .= $codes[$p[$i]][$code{$i}];
1562
+        }
1563
+        $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1564
+        return $this->binseq_to_array($seq, $bararray);
1565
+    }
1566 1566
 
1567
-	/**
1568
-	 * POSTNET and PLANET barcodes.
1569
-	 * Used by U.S. Postal Service for automated mail sorting
1570
-	 * @param $code (string) zip code to represent. Must be a string containing a zip code of the form DDDDD or DDDDD-DDDD.
1571
-	 * @param $planet (boolean) if true print the PLANET barcode, otherwise print POSTNET
1572
-	 * @return array barcode representation.
1573
-	 * @protected
1574
-	 */
1575
-	protected function barcode_postnet($code, $planet=false) {
1576
-		// bar lenght
1577
-		if ($planet) {
1578
-			$barlen = Array(
1579
-				0 => Array(1,1,2,2,2),
1580
-				1 => Array(2,2,2,1,1),
1581
-				2 => Array(2,2,1,2,1),
1582
-				3 => Array(2,2,1,1,2),
1583
-				4 => Array(2,1,2,2,1),
1584
-				5 => Array(2,1,2,1,2),
1585
-				6 => Array(2,1,1,2,2),
1586
-				7 => Array(1,2,2,2,1),
1587
-				8 => Array(1,2,2,1,2),
1588
-				9 => Array(1,2,1,2,2)
1589
-			);
1590
-		} else {
1591
-			$barlen = Array(
1592
-				0 => Array(2,2,1,1,1),
1593
-				1 => Array(1,1,1,2,2),
1594
-				2 => Array(1,1,2,1,2),
1595
-				3 => Array(1,1,2,2,1),
1596
-				4 => Array(1,2,1,1,2),
1597
-				5 => Array(1,2,1,2,1),
1598
-				6 => Array(1,2,2,1,1),
1599
-				7 => Array(2,1,1,1,2),
1600
-				8 => Array(2,1,1,2,1),
1601
-				9 => Array(2,1,2,1,1)
1602
-			);
1603
-		}
1604
-		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 2, 'bcode' => array());
1605
-		$k = 0;
1606
-		$code = str_replace('-', '', $code);
1607
-		$code = str_replace(' ', '', $code);
1608
-		$len = strlen($code);
1609
-		// calculate checksum
1610
-		$sum = 0;
1611
-		for ($i = 0; $i < $len; ++$i) {
1612
-			$sum += intval($code{$i});
1613
-		}
1614
-		$chkd = ($sum % 10);
1615
-		if($chkd > 0) {
1616
-			$chkd = (10 - $chkd);
1617
-		}
1618
-		$code .= $chkd;
1619
-		$len = strlen($code);
1620
-		// start bar
1621
-		$bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 2, 'p' => 0);
1622
-		$bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0);
1623
-		$bararray['maxw'] += 2;
1624
-		for ($i = 0; $i < $len; ++$i) {
1625
-			for ($j = 0; $j < 5; ++$j) {
1626
-				$h = $barlen[$code{$i}][$j];
1627
-				$p = floor(1 / $h);
1628
-				$bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
1629
-				$bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0);
1630
-				$bararray['maxw'] += 2;
1631
-			}
1632
-		}
1633
-		// end bar
1634
-		$bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 2, 'p' => 0);
1635
-		$bararray['maxw'] += 1;
1636
-		return $bararray;
1637
-	}
1567
+    /**
1568
+     * POSTNET and PLANET barcodes.
1569
+     * Used by U.S. Postal Service for automated mail sorting
1570
+     * @param $code (string) zip code to represent. Must be a string containing a zip code of the form DDDDD or DDDDD-DDDD.
1571
+     * @param $planet (boolean) if true print the PLANET barcode, otherwise print POSTNET
1572
+     * @return array barcode representation.
1573
+     * @protected
1574
+     */
1575
+    protected function barcode_postnet($code, $planet=false) {
1576
+        // bar lenght
1577
+        if ($planet) {
1578
+            $barlen = Array(
1579
+                0 => Array(1,1,2,2,2),
1580
+                1 => Array(2,2,2,1,1),
1581
+                2 => Array(2,2,1,2,1),
1582
+                3 => Array(2,2,1,1,2),
1583
+                4 => Array(2,1,2,2,1),
1584
+                5 => Array(2,1,2,1,2),
1585
+                6 => Array(2,1,1,2,2),
1586
+                7 => Array(1,2,2,2,1),
1587
+                8 => Array(1,2,2,1,2),
1588
+                9 => Array(1,2,1,2,2)
1589
+            );
1590
+        } else {
1591
+            $barlen = Array(
1592
+                0 => Array(2,2,1,1,1),
1593
+                1 => Array(1,1,1,2,2),
1594
+                2 => Array(1,1,2,1,2),
1595
+                3 => Array(1,1,2,2,1),
1596
+                4 => Array(1,2,1,1,2),
1597
+                5 => Array(1,2,1,2,1),
1598
+                6 => Array(1,2,2,1,1),
1599
+                7 => Array(2,1,1,1,2),
1600
+                8 => Array(2,1,1,2,1),
1601
+                9 => Array(2,1,2,1,1)
1602
+            );
1603
+        }
1604
+        $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 2, 'bcode' => array());
1605
+        $k = 0;
1606
+        $code = str_replace('-', '', $code);
1607
+        $code = str_replace(' ', '', $code);
1608
+        $len = strlen($code);
1609
+        // calculate checksum
1610
+        $sum = 0;
1611
+        for ($i = 0; $i < $len; ++$i) {
1612
+            $sum += intval($code{$i});
1613
+        }
1614
+        $chkd = ($sum % 10);
1615
+        if($chkd > 0) {
1616
+            $chkd = (10 - $chkd);
1617
+        }
1618
+        $code .= $chkd;
1619
+        $len = strlen($code);
1620
+        // start bar
1621
+        $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 2, 'p' => 0);
1622
+        $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0);
1623
+        $bararray['maxw'] += 2;
1624
+        for ($i = 0; $i < $len; ++$i) {
1625
+            for ($j = 0; $j < 5; ++$j) {
1626
+                $h = $barlen[$code{$i}][$j];
1627
+                $p = floor(1 / $h);
1628
+                $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
1629
+                $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0);
1630
+                $bararray['maxw'] += 2;
1631
+            }
1632
+        }
1633
+        // end bar
1634
+        $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 2, 'p' => 0);
1635
+        $bararray['maxw'] += 1;
1636
+        return $bararray;
1637
+    }
1638 1638
 
1639
-	/**
1640
-	 * RMS4CC - CBC - KIX
1641
-	 * RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code) - KIX (Klant index - Customer index)
1642
-	 * RM4SCC is the name of the barcode symbology used by the Royal Mail for its Cleanmail service.
1643
-	 * @param $code (string) code to print
1644
-	 * @param $kix (boolean) if true prints the KIX variation (doesn't use the start and end symbols, and the checksum) - in this case the house number must be sufficed with an X and placed at the end of the code.
1645
-	 * @return array barcode representation.
1646
-	 * @protected
1647
-	 */
1648
-	protected function barcode_rms4cc($code, $kix=false) {
1649
-		$notkix = !$kix;
1650
-		// bar mode
1651
-		// 1 = pos 1, length 2
1652
-		// 2 = pos 1, length 3
1653
-		// 3 = pos 2, length 1
1654
-		// 4 = pos 2, length 2
1655
-		$barmode = array(
1656
-			'0' => array(3,3,2,2),
1657
-			'1' => array(3,4,1,2),
1658
-			'2' => array(3,4,2,1),
1659
-			'3' => array(4,3,1,2),
1660
-			'4' => array(4,3,2,1),
1661
-			'5' => array(4,4,1,1),
1662
-			'6' => array(3,1,4,2),
1663
-			'7' => array(3,2,3,2),
1664
-			'8' => array(3,2,4,1),
1665
-			'9' => array(4,1,3,2),
1666
-			'A' => array(4,1,4,1),
1667
-			'B' => array(4,2,3,1),
1668
-			'C' => array(3,1,2,4),
1669
-			'D' => array(3,2,1,4),
1670
-			'E' => array(3,2,2,3),
1671
-			'F' => array(4,1,1,4),
1672
-			'G' => array(4,1,2,3),
1673
-			'H' => array(4,2,1,3),
1674
-			'I' => array(1,3,4,2),
1675
-			'J' => array(1,4,3,2),
1676
-			'K' => array(1,4,4,1),
1677
-			'L' => array(2,3,3,2),
1678
-			'M' => array(2,3,4,1),
1679
-			'N' => array(2,4,3,1),
1680
-			'O' => array(1,3,2,4),
1681
-			'P' => array(1,4,1,4),
1682
-			'Q' => array(1,4,2,3),
1683
-			'R' => array(2,3,1,4),
1684
-			'S' => array(2,3,2,3),
1685
-			'T' => array(2,4,1,3),
1686
-			'U' => array(1,1,4,4),
1687
-			'V' => array(1,2,3,4),
1688
-			'W' => array(1,2,4,3),
1689
-			'X' => array(2,1,3,4),
1690
-			'Y' => array(2,1,4,3),
1691
-			'Z' => array(2,2,3,3)
1692
-		);
1693
-		$code = strtoupper($code);
1694
-		$len = strlen($code);
1695
-		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 3, 'bcode' => array());
1696
-		if ($notkix) {
1697
-			// table for checksum calculation (row,col)
1698
-			$checktable = array(
1699
-				'0' => array(1,1),
1700
-				'1' => array(1,2),
1701
-				'2' => array(1,3),
1702
-				'3' => array(1,4),
1703
-				'4' => array(1,5),
1704
-				'5' => array(1,0),
1705
-				'6' => array(2,1),
1706
-				'7' => array(2,2),
1707
-				'8' => array(2,3),
1708
-				'9' => array(2,4),
1709
-				'A' => array(2,5),
1710
-				'B' => array(2,0),
1711
-				'C' => array(3,1),
1712
-				'D' => array(3,2),
1713
-				'E' => array(3,3),
1714
-				'F' => array(3,4),
1715
-				'G' => array(3,5),
1716
-				'H' => array(3,0),
1717
-				'I' => array(4,1),
1718
-				'J' => array(4,2),
1719
-				'K' => array(4,3),
1720
-				'L' => array(4,4),
1721
-				'M' => array(4,5),
1722
-				'N' => array(4,0),
1723
-				'O' => array(5,1),
1724
-				'P' => array(5,2),
1725
-				'Q' => array(5,3),
1726
-				'R' => array(5,4),
1727
-				'S' => array(5,5),
1728
-				'T' => array(5,0),
1729
-				'U' => array(0,1),
1730
-				'V' => array(0,2),
1731
-				'W' => array(0,3),
1732
-				'X' => array(0,4),
1733
-				'Y' => array(0,5),
1734
-				'Z' => array(0,0)
1735
-			);
1736
-			$row = 0;
1737
-			$col = 0;
1738
-			for ($i = 0; $i < $len; ++$i) {
1739
-				$row += $checktable[$code{$i}][0];
1740
-				$col += $checktable[$code{$i}][1];
1741
-			}
1742
-			$row %= 6;
1743
-			$col %= 6;
1744
-			$chk = array_keys($checktable, array($row,$col));
1745
-			$code .= $chk[0];
1746
-			++$len;
1747
-		}
1748
-		$k = 0;
1749
-		if ($notkix) {
1750
-			// start bar
1751
-			$bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 2, 'p' => 0);
1752
-			$bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0);
1753
-			$bararray['maxw'] += 2;
1754
-		}
1755
-		for ($i = 0; $i < $len; ++$i) {
1756
-			for ($j = 0; $j < 4; ++$j) {
1757
-				switch ($barmode[$code{$i}][$j]) {
1758
-					case 1: {
1759
-						$p = 0;
1760
-						$h = 2;
1761
-						break;
1762
-					}
1763
-					case 2: {
1764
-						$p = 0;
1765
-						$h = 3;
1766
-						break;
1767
-					}
1768
-					case 3: {
1769
-						$p = 1;
1770
-						$h = 1;
1771
-						break;
1772
-					}
1773
-					case 4: {
1774
-						$p = 1;
1775
-						$h = 2;
1776
-						break;
1777
-					}
1778
-				}
1779
-				$bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
1780
-				$bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0);
1781
-				$bararray['maxw'] += 2;
1782
-			}
1783
-		}
1784
-		if ($notkix) {
1785
-			// stop bar
1786
-			$bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 3, 'p' => 0);
1787
-			$bararray['maxw'] += 1;
1788
-		}
1789
-		return $bararray;
1790
-	}
1639
+    /**
1640
+     * RMS4CC - CBC - KIX
1641
+     * RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code) - KIX (Klant index - Customer index)
1642
+     * RM4SCC is the name of the barcode symbology used by the Royal Mail for its Cleanmail service.
1643
+     * @param $code (string) code to print
1644
+     * @param $kix (boolean) if true prints the KIX variation (doesn't use the start and end symbols, and the checksum) - in this case the house number must be sufficed with an X and placed at the end of the code.
1645
+     * @return array barcode representation.
1646
+     * @protected
1647
+     */
1648
+    protected function barcode_rms4cc($code, $kix=false) {
1649
+        $notkix = !$kix;
1650
+        // bar mode
1651
+        // 1 = pos 1, length 2
1652
+        // 2 = pos 1, length 3
1653
+        // 3 = pos 2, length 1
1654
+        // 4 = pos 2, length 2
1655
+        $barmode = array(
1656
+            '0' => array(3,3,2,2),
1657
+            '1' => array(3,4,1,2),
1658
+            '2' => array(3,4,2,1),
1659
+            '3' => array(4,3,1,2),
1660
+            '4' => array(4,3,2,1),
1661
+            '5' => array(4,4,1,1),
1662
+            '6' => array(3,1,4,2),
1663
+            '7' => array(3,2,3,2),
1664
+            '8' => array(3,2,4,1),
1665
+            '9' => array(4,1,3,2),
1666
+            'A' => array(4,1,4,1),
1667
+            'B' => array(4,2,3,1),
1668
+            'C' => array(3,1,2,4),
1669
+            'D' => array(3,2,1,4),
1670
+            'E' => array(3,2,2,3),
1671
+            'F' => array(4,1,1,4),
1672
+            'G' => array(4,1,2,3),
1673
+            'H' => array(4,2,1,3),
1674
+            'I' => array(1,3,4,2),
1675
+            'J' => array(1,4,3,2),
1676
+            'K' => array(1,4,4,1),
1677
+            'L' => array(2,3,3,2),
1678
+            'M' => array(2,3,4,1),
1679
+            'N' => array(2,4,3,1),
1680
+            'O' => array(1,3,2,4),
1681
+            'P' => array(1,4,1,4),
1682
+            'Q' => array(1,4,2,3),
1683
+            'R' => array(2,3,1,4),
1684
+            'S' => array(2,3,2,3),
1685
+            'T' => array(2,4,1,3),
1686
+            'U' => array(1,1,4,4),
1687
+            'V' => array(1,2,3,4),
1688
+            'W' => array(1,2,4,3),
1689
+            'X' => array(2,1,3,4),
1690
+            'Y' => array(2,1,4,3),
1691
+            'Z' => array(2,2,3,3)
1692
+        );
1693
+        $code = strtoupper($code);
1694
+        $len = strlen($code);
1695
+        $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 3, 'bcode' => array());
1696
+        if ($notkix) {
1697
+            // table for checksum calculation (row,col)
1698
+            $checktable = array(
1699
+                '0' => array(1,1),
1700
+                '1' => array(1,2),
1701
+                '2' => array(1,3),
1702
+                '3' => array(1,4),
1703
+                '4' => array(1,5),
1704
+                '5' => array(1,0),
1705
+                '6' => array(2,1),
1706
+                '7' => array(2,2),
1707
+                '8' => array(2,3),
1708
+                '9' => array(2,4),
1709
+                'A' => array(2,5),
1710
+                'B' => array(2,0),
1711
+                'C' => array(3,1),
1712
+                'D' => array(3,2),
1713
+                'E' => array(3,3),
1714
+                'F' => array(3,4),
1715
+                'G' => array(3,5),
1716
+                'H' => array(3,0),
1717
+                'I' => array(4,1),
1718
+                'J' => array(4,2),
1719
+                'K' => array(4,3),
1720
+                'L' => array(4,4),
1721
+                'M' => array(4,5),
1722
+                'N' => array(4,0),
1723
+                'O' => array(5,1),
1724
+                'P' => array(5,2),
1725
+                'Q' => array(5,3),
1726
+                'R' => array(5,4),
1727
+                'S' => array(5,5),
1728
+                'T' => array(5,0),
1729
+                'U' => array(0,1),
1730
+                'V' => array(0,2),
1731
+                'W' => array(0,3),
1732
+                'X' => array(0,4),
1733
+                'Y' => array(0,5),
1734
+                'Z' => array(0,0)
1735
+            );
1736
+            $row = 0;
1737
+            $col = 0;
1738
+            for ($i = 0; $i < $len; ++$i) {
1739
+                $row += $checktable[$code{$i}][0];
1740
+                $col += $checktable[$code{$i}][1];
1741
+            }
1742
+            $row %= 6;
1743
+            $col %= 6;
1744
+            $chk = array_keys($checktable, array($row,$col));
1745
+            $code .= $chk[0];
1746
+            ++$len;
1747
+        }
1748
+        $k = 0;
1749
+        if ($notkix) {
1750
+            // start bar
1751
+            $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 2, 'p' => 0);
1752
+            $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0);
1753
+            $bararray['maxw'] += 2;
1754
+        }
1755
+        for ($i = 0; $i < $len; ++$i) {
1756
+            for ($j = 0; $j < 4; ++$j) {
1757
+                switch ($barmode[$code{$i}][$j]) {
1758
+                    case 1: {
1759
+                        $p = 0;
1760
+                        $h = 2;
1761
+                        break;
1762
+                    }
1763
+                    case 2: {
1764
+                        $p = 0;
1765
+                        $h = 3;
1766
+                        break;
1767
+                    }
1768
+                    case 3: {
1769
+                        $p = 1;
1770
+                        $h = 1;
1771
+                        break;
1772
+                    }
1773
+                    case 4: {
1774
+                        $p = 1;
1775
+                        $h = 2;
1776
+                        break;
1777
+                    }
1778
+                }
1779
+                $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
1780
+                $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0);
1781
+                $bararray['maxw'] += 2;
1782
+            }
1783
+        }
1784
+        if ($notkix) {
1785
+            // stop bar
1786
+            $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 3, 'p' => 0);
1787
+            $bararray['maxw'] += 1;
1788
+        }
1789
+        return $bararray;
1790
+    }
1791 1791
 
1792
-	/**
1793
-	 * CODABAR barcodes.
1794
-	 * Older code often used in library systems, sometimes in blood banks
1795
-	 * @param $code (string) code to represent.
1796
-	 * @return array barcode representation.
1797
-	 * @protected
1798
-	 */
1799
-	protected function barcode_codabar($code) {
1800
-		$chr = array(
1801
-			'0' => '11111221',
1802
-			'1' => '11112211',
1803
-			'2' => '11121121',
1804
-			'3' => '22111111',
1805
-			'4' => '11211211',
1806
-			'5' => '21111211',
1807
-			'6' => '12111121',
1808
-			'7' => '12112111',
1809
-			'8' => '12211111',
1810
-			'9' => '21121111',
1811
-			'-' => '11122111',
1812
-			'$' => '11221111',
1813
-			':' => '21112121',
1814
-			'/' => '21211121',
1815
-			'.' => '21212111',
1816
-			'+' => '11222221',
1817
-			'A' => '11221211',
1818
-			'B' => '12121121',
1819
-			'C' => '11121221',
1820
-			'D' => '11122211'
1821
-		);
1822
-		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1823
-		$k = 0;
1824
-		$w = 0;
1825
-		$seq = '';
1826
-		$code = 'A'.strtoupper($code).'A';
1827
-		$len = strlen($code);
1828
-		for ($i = 0; $i < $len; ++$i) {
1829
-			if (!isset($chr[$code{$i}])) {
1830
-				return false;
1831
-			}
1832
-			$seq = $chr[$code{$i}];
1833
-			for ($j = 0; $j < 8; ++$j) {
1834
-				if (($j % 2) == 0) {
1835
-					$t = true; // bar
1836
-				} else {
1837
-					$t = false; // space
1838
-				}
1839
-				$w = $seq{$j};
1840
-				$bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1841
-				$bararray['maxw'] += $w;
1842
-				++$k;
1843
-			}
1844
-		}
1845
-		return $bararray;
1846
-	}
1792
+    /**
1793
+     * CODABAR barcodes.
1794
+     * Older code often used in library systems, sometimes in blood banks
1795
+     * @param $code (string) code to represent.
1796
+     * @return array barcode representation.
1797
+     * @protected
1798
+     */
1799
+    protected function barcode_codabar($code) {
1800
+        $chr = array(
1801
+            '0' => '11111221',
1802
+            '1' => '11112211',
1803
+            '2' => '11121121',
1804
+            '3' => '22111111',
1805
+            '4' => '11211211',
1806
+            '5' => '21111211',
1807
+            '6' => '12111121',
1808
+            '7' => '12112111',
1809
+            '8' => '12211111',
1810
+            '9' => '21121111',
1811
+            '-' => '11122111',
1812
+            '$' => '11221111',
1813
+            ':' => '21112121',
1814
+            '/' => '21211121',
1815
+            '.' => '21212111',
1816
+            '+' => '11222221',
1817
+            'A' => '11221211',
1818
+            'B' => '12121121',
1819
+            'C' => '11121221',
1820
+            'D' => '11122211'
1821
+        );
1822
+        $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1823
+        $k = 0;
1824
+        $w = 0;
1825
+        $seq = '';
1826
+        $code = 'A'.strtoupper($code).'A';
1827
+        $len = strlen($code);
1828
+        for ($i = 0; $i < $len; ++$i) {
1829
+            if (!isset($chr[$code{$i}])) {
1830
+                return false;
1831
+            }
1832
+            $seq = $chr[$code{$i}];
1833
+            for ($j = 0; $j < 8; ++$j) {
1834
+                if (($j % 2) == 0) {
1835
+                    $t = true; // bar
1836
+                } else {
1837
+                    $t = false; // space
1838
+                }
1839
+                $w = $seq{$j};
1840
+                $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1841
+                $bararray['maxw'] += $w;
1842
+                ++$k;
1843
+            }
1844
+        }
1845
+        return $bararray;
1846
+    }
1847 1847
 
1848
-	/**
1849
-	 * CODE11 barcodes.
1850
-	 * Used primarily for labeling telecommunications equipment
1851
-	 * @param $code (string) code to represent.
1852
-	 * @return array barcode representation.
1853
-	 * @protected
1854
-	 */
1855
-	protected function barcode_code11($code) {
1856
-		$chr = array(
1857
-			'0' => '111121',
1858
-			'1' => '211121',
1859
-			'2' => '121121',
1860
-			'3' => '221111',
1861
-			'4' => '112121',
1862
-			'5' => '212111',
1863
-			'6' => '122111',
1864
-			'7' => '111221',
1865
-			'8' => '211211',
1866
-			'9' => '211111',
1867
-			'-' => '112111',
1868
-			'S' => '112211'
1869
-		);
1870
-		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1871
-		$k = 0;
1872
-		$w = 0;
1873
-		$seq = '';
1874
-		$len = strlen($code);
1875
-		// calculate check digit C
1876
-		$p = 1;
1877
-		$check = 0;
1878
-		for ($i = ($len - 1); $i >= 0; --$i) {
1879
-			$digit = $code{$i};
1880
-			if ($digit == '-') {
1881
-				$dval = 10;
1882
-			} else {
1883
-				$dval = intval($digit);
1884
-			}
1885
-			$check += ($dval * $p);
1886
-			++$p;
1887
-			if ($p > 10) {
1888
-				$p = 1;
1889
-			}
1890
-		}
1891
-		$check %= 11;
1892
-		if ($check == 10) {
1893
-			$check = '-';
1894
-		}
1895
-		$code .= $check;
1896
-		if ($len > 10) {
1897
-			// calculate check digit K
1898
-			$p = 1;
1899
-			$check = 0;
1900
-			for ($i = $len; $i >= 0; --$i) {
1901
-				$digit = $code{$i};
1902
-				if ($digit == '-') {
1903
-					$dval = 10;
1904
-				} else {
1905
-					$dval = intval($digit);
1906
-				}
1907
-				$check += ($dval * $p);
1908
-				++$p;
1909
-				if ($p > 9) {
1910
-					$p = 1;
1911
-				}
1912
-			}
1913
-			$check %= 11;
1914
-			$code .= $check;
1915
-			++$len;
1916
-		}
1917
-		$code = 'S'.$code.'S';
1918
-		$len += 3;
1919
-		for ($i = 0; $i < $len; ++$i) {
1920
-			if (!isset($chr[$code{$i}])) {
1921
-				return false;
1922
-			}
1923
-			$seq = $chr[$code{$i}];
1924
-			for ($j = 0; $j < 6; ++$j) {
1925
-				if (($j % 2) == 0) {
1926
-					$t = true; // bar
1927
-				} else {
1928
-					$t = false; // space
1929
-				}
1930
-				$w = $seq{$j};
1931
-				$bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1932
-				$bararray['maxw'] += $w;
1933
-				++$k;
1934
-			}
1935
-		}
1936
-		return $bararray;
1937
-	}
1848
+    /**
1849
+     * CODE11 barcodes.
1850
+     * Used primarily for labeling telecommunications equipment
1851
+     * @param $code (string) code to represent.
1852
+     * @return array barcode representation.
1853
+     * @protected
1854
+     */
1855
+    protected function barcode_code11($code) {
1856
+        $chr = array(
1857
+            '0' => '111121',
1858
+            '1' => '211121',
1859
+            '2' => '121121',
1860
+            '3' => '221111',
1861
+            '4' => '112121',
1862
+            '5' => '212111',
1863
+            '6' => '122111',
1864
+            '7' => '111221',
1865
+            '8' => '211211',
1866
+            '9' => '211111',
1867
+            '-' => '112111',
1868
+            'S' => '112211'
1869
+        );
1870
+        $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1871
+        $k = 0;
1872
+        $w = 0;
1873
+        $seq = '';
1874
+        $len = strlen($code);
1875
+        // calculate check digit C
1876
+        $p = 1;
1877
+        $check = 0;
1878
+        for ($i = ($len - 1); $i >= 0; --$i) {
1879
+            $digit = $code{$i};
1880
+            if ($digit == '-') {
1881
+                $dval = 10;
1882
+            } else {
1883
+                $dval = intval($digit);
1884
+            }
1885
+            $check += ($dval * $p);
1886
+            ++$p;
1887
+            if ($p > 10) {
1888
+                $p = 1;
1889
+            }
1890
+        }
1891
+        $check %= 11;
1892
+        if ($check == 10) {
1893
+            $check = '-';
1894
+        }
1895
+        $code .= $check;
1896
+        if ($len > 10) {
1897
+            // calculate check digit K
1898
+            $p = 1;
1899
+            $check = 0;
1900
+            for ($i = $len; $i >= 0; --$i) {
1901
+                $digit = $code{$i};
1902
+                if ($digit == '-') {
1903
+                    $dval = 10;
1904
+                } else {
1905
+                    $dval = intval($digit);
1906
+                }
1907
+                $check += ($dval * $p);
1908
+                ++$p;
1909
+                if ($p > 9) {
1910
+                    $p = 1;
1911
+                }
1912
+            }
1913
+            $check %= 11;
1914
+            $code .= $check;
1915
+            ++$len;
1916
+        }
1917
+        $code = 'S'.$code.'S';
1918
+        $len += 3;
1919
+        for ($i = 0; $i < $len; ++$i) {
1920
+            if (!isset($chr[$code{$i}])) {
1921
+                return false;
1922
+            }
1923
+            $seq = $chr[$code{$i}];
1924
+            for ($j = 0; $j < 6; ++$j) {
1925
+                if (($j % 2) == 0) {
1926
+                    $t = true; // bar
1927
+                } else {
1928
+                    $t = false; // space
1929
+                }
1930
+                $w = $seq{$j};
1931
+                $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1932
+                $bararray['maxw'] += $w;
1933
+                ++$k;
1934
+            }
1935
+        }
1936
+        return $bararray;
1937
+    }
1938 1938
 
1939
-	/**
1940
-	 * Pharmacode
1941
-	 * Contains digits (0 to 9)
1942
-	 * @param $code (string) code to represent.
1943
-	 * @return array barcode representation.
1944
-	 * @protected
1945
-	 */
1946
-	protected function barcode_pharmacode($code) {
1947
-		$seq = '';
1948
-		$code = intval($code);
1949
-		while ($code > 0) {
1950
-			if (($code % 2) == 0) {
1951
-				$seq .= '11100';
1952
-				$code -= 2;
1953
-			} else {
1954
-				$seq .= '100';
1955
-				$code -= 1;
1956
-			}
1957
-			$code /= 2;
1958
-		}
1959
-		$seq = substr($seq, 0, -2);
1960
-		$seq = strrev($seq);
1961
-		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1962
-		return $this->binseq_to_array($seq, $bararray);
1963
-	}
1939
+    /**
1940
+     * Pharmacode
1941
+     * Contains digits (0 to 9)
1942
+     * @param $code (string) code to represent.
1943
+     * @return array barcode representation.
1944
+     * @protected
1945
+     */
1946
+    protected function barcode_pharmacode($code) {
1947
+        $seq = '';
1948
+        $code = intval($code);
1949
+        while ($code > 0) {
1950
+            if (($code % 2) == 0) {
1951
+                $seq .= '11100';
1952
+                $code -= 2;
1953
+            } else {
1954
+                $seq .= '100';
1955
+                $code -= 1;
1956
+            }
1957
+            $code /= 2;
1958
+        }
1959
+        $seq = substr($seq, 0, -2);
1960
+        $seq = strrev($seq);
1961
+        $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1962
+        return $this->binseq_to_array($seq, $bararray);
1963
+    }
1964 1964
 
1965
-	/**
1966
-	 * Pharmacode two-track
1967
-	 * Contains digits (0 to 9)
1968
-	 * @param $code (string) code to represent.
1969
-	 * @return array barcode representation.
1970
-	 * @protected
1971
-	 */
1972
-	protected function barcode_pharmacode2t($code) {
1973
-		$seq = '';
1974
-		$code = intval($code);
1975
-		do {
1976
-			switch ($code % 3) {
1977
-				case 0: {
1978
-					$seq .= '3';
1979
-					$code = ($code - 3) / 3;
1980
-					break;
1981
-				}
1982
-				case 1: {
1983
-					$seq .= '1';
1984
-					$code = ($code - 1) / 3;
1985
-					break;
1986
-				}
1987
-				case 2: {
1988
-					$seq .= '2';
1989
-					$code = ($code - 2) / 3;
1990
-					break;
1991
-				}
1992
-			}
1993
-		} while($code != 0);
1994
-		$seq = strrev($seq);
1995
-		$k = 0;
1996
-		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 2, 'bcode' => array());
1997
-		$len = strlen($seq);
1998
-		for ($i = 0; $i < $len; ++$i) {
1999
-			switch ($seq{$i}) {
2000
-				case '1': {
2001
-					$p = 1;
2002
-					$h = 1;
2003
-					break;
2004
-				}
2005
-				case '2': {
2006
-					$p = 0;
2007
-					$h = 1;
2008
-					break;
2009
-				}
2010
-				case '3': {
2011
-					$p = 0;
2012
-					$h = 2;
2013
-					break;
2014
-				}
2015
-			}
2016
-			$bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
2017
-			$bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0);
2018
-			$bararray['maxw'] += 2;
2019
-		}
2020
-		unset($bararray['bcode'][($k - 1)]);
2021
-		--$bararray['maxw'];
2022
-		return $bararray;
2023
-	}
1965
+    /**
1966
+     * Pharmacode two-track
1967
+     * Contains digits (0 to 9)
1968
+     * @param $code (string) code to represent.
1969
+     * @return array barcode representation.
1970
+     * @protected
1971
+     */
1972
+    protected function barcode_pharmacode2t($code) {
1973
+        $seq = '';
1974
+        $code = intval($code);
1975
+        do {
1976
+            switch ($code % 3) {
1977
+                case 0: {
1978
+                    $seq .= '3';
1979
+                    $code = ($code - 3) / 3;
1980
+                    break;
1981
+                }
1982
+                case 1: {
1983
+                    $seq .= '1';
1984
+                    $code = ($code - 1) / 3;
1985
+                    break;
1986
+                }
1987
+                case 2: {
1988
+                    $seq .= '2';
1989
+                    $code = ($code - 2) / 3;
1990
+                    break;
1991
+                }
1992
+            }
1993
+        } while($code != 0);
1994
+        $seq = strrev($seq);
1995
+        $k = 0;
1996
+        $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 2, 'bcode' => array());
1997
+        $len = strlen($seq);
1998
+        for ($i = 0; $i < $len; ++$i) {
1999
+            switch ($seq{$i}) {
2000
+                case '1': {
2001
+                    $p = 1;
2002
+                    $h = 1;
2003
+                    break;
2004
+                }
2005
+                case '2': {
2006
+                    $p = 0;
2007
+                    $h = 1;
2008
+                    break;
2009
+                }
2010
+                case '3': {
2011
+                    $p = 0;
2012
+                    $h = 2;
2013
+                    break;
2014
+                }
2015
+            }
2016
+            $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
2017
+            $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0);
2018
+            $bararray['maxw'] += 2;
2019
+        }
2020
+        unset($bararray['bcode'][($k - 1)]);
2021
+        --$bararray['maxw'];
2022
+        return $bararray;
2023
+    }
2024 2024
 
2025 2025
 
2026
-	/**
2027
-	 * IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
2028
-	 * (requires PHP bcmath extension)
2029
-	 * Intelligent Mail barcode is a 65-bar code for use on mail in the United States.
2030
-	 * The fields are described as follows:<ul><li>The Barcode Identifier shall be assigned by USPS to encode the presort identification that is currently printed in human readable form on the optional endorsement line (OEL) as well as for future USPS use. This shall be two digits, with the second digit in the range of 0–4. The allowable encoding ranges shall be 00–04, 10–14, 20–24, 30–34, 40–44, 50–54, 60–64, 70–74, 80–84, and 90–94.</li><li>The Service Type Identifier shall be assigned by USPS for any combination of services requested on the mailpiece. The allowable encoding range shall be 000http://it2.php.net/manual/en/function.dechex.php–999. Each 3-digit value shall correspond to a particular mail class with a particular combination of service(s). Each service program, such as OneCode Confirm and OneCode ACS, shall provide the list of Service Type Identifier values.</li><li>The Mailer or Customer Identifier shall be assigned by USPS as a unique, 6 or 9 digit number that identifies a business entity. The allowable encoding range for the 6 digit Mailer ID shall be 000000- 899999, while the allowable encoding range for the 9 digit Mailer ID shall be 900000000-999999999.</li><li>The Serial or Sequence Number shall be assigned by the mailer for uniquely identifying and tracking mailpieces. The allowable encoding range shall be 000000000–999999999 when used with a 6 digit Mailer ID and 000000-999999 when used with a 9 digit Mailer ID. e. The Delivery Point ZIP Code shall be assigned by the mailer for routing the mailpiece. This shall replace POSTNET for routing the mailpiece to its final delivery point. The length may be 0, 5, 9, or 11 digits. The allowable encoding ranges shall be no ZIP Code, 00000–99999,  000000000–999999999, and 00000000000–99999999999.</li></ul>
2031
-	 * @param $code (string) code to print, separate the ZIP (routing code) from the rest using a minus char '-' (BarcodeID_ServiceTypeID_MailerID_SerialNumber-RoutingCode)
2032
-	 * @return array barcode representation.
2033
-	 * @protected
2034
-	 */
2035
-	protected function barcode_imb($code) {
2036
-		$asc_chr = array(4,0,2,6,3,5,1,9,8,7,1,2,0,6,4,8,2,9,5,3,0,1,3,7,4,6,8,9,2,0,5,1,9,4,3,8,6,7,1,2,4,3,9,5,7,8,3,0,2,1,4,0,9,1,7,0,2,4,6,3,7,1,9,5,8);
2037
-		$dsc_chr = array(7,1,9,5,8,0,2,4,6,3,5,8,9,7,3,0,6,1,7,4,6,8,9,2,5,1,7,5,4,3,8,7,6,0,2,5,4,9,3,0,1,6,8,2,0,4,5,9,6,7,5,2,6,3,8,5,1,9,8,7,4,0,2,6,3);
2038
-		$asc_pos = array(3,0,8,11,1,12,8,11,10,6,4,12,2,7,9,6,7,9,2,8,4,0,12,7,10,9,0,7,10,5,7,9,6,8,2,12,1,4,2,0,1,5,4,6,12,1,0,9,4,7,5,10,2,6,9,11,2,12,6,7,5,11,0,3,2);
2039
-		$dsc_pos = array(2,10,12,5,9,1,5,4,3,9,11,5,10,1,6,3,4,1,10,0,2,11,8,6,1,12,3,8,6,4,4,11,0,6,1,9,11,5,3,7,3,10,7,11,8,2,10,3,5,8,0,3,12,11,8,4,5,1,3,0,7,12,9,8,10);
2040
-		$code_arr = explode('-', $code);
2041
-		$tracking_number = $code_arr[0];
2042
-		if (isset($code_arr[1])) {
2043
-			$routing_code = $code_arr[1];
2044
-		} else {
2045
-			$routing_code = '';
2046
-		}
2047
-		// Conversion of Routing Code
2048
-		switch (strlen($routing_code)) {
2049
-			case 0: {
2050
-				$binary_code = 0;
2051
-				break;
2052
-			}
2053
-			case 5: {
2054
-				$binary_code = bcadd($routing_code, '1');
2055
-				break;
2056
-			}
2057
-			case 9: {
2058
-				$binary_code = bcadd($routing_code, '100001');
2059
-				break;
2060
-			}
2061
-			case 11: {
2062
-				$binary_code = bcadd($routing_code, '1000100001');
2063
-				break;
2064
-			}
2065
-			default: {
2066
-				return false;
2067
-				break;
2068
-			}
2069
-		}
2070
-		$binary_code = bcmul($binary_code, 10);
2071
-		$binary_code = bcadd($binary_code, $tracking_number[0]);
2072
-		$binary_code = bcmul($binary_code, 5);
2073
-		$binary_code = bcadd($binary_code, $tracking_number[1]);
2074
-		$binary_code .= substr($tracking_number, 2, 18);
2075
-		// convert to hexadecimal
2076
-		$binary_code = $this->dec_to_hex($binary_code);
2077
-		// pad to get 13 bytes
2078
-		$binary_code = str_pad($binary_code, 26, '0', STR_PAD_LEFT);
2079
-		// convert string to array of bytes
2080
-		$binary_code_arr = chunk_split($binary_code, 2, "\r");
2081
-		$binary_code_arr = substr($binary_code_arr, 0, -1);
2082
-		$binary_code_arr = explode("\r", $binary_code_arr);
2083
-		// calculate frame check sequence
2084
-		$fcs = $this->imb_crc11fcs($binary_code_arr);
2085
-		// exclude first 2 bits from first byte
2086
-		$first_byte = sprintf('%2s', dechex((hexdec($binary_code_arr[0]) << 2) >> 2));
2087
-		$binary_code_102bit = $first_byte.substr($binary_code, 2);
2088
-		// convert binary data to codewords
2089
-		$codewords = array();
2090
-		$data = $this->hex_to_dec($binary_code_102bit);
2091
-		$codewords[0] = bcmod($data, 636) * 2;
2092
-		$data = bcdiv($data, 636);
2093
-		for ($i = 1; $i < 9; ++$i) {
2094
-			$codewords[$i] = bcmod($data, 1365);
2095
-			$data = bcdiv($data, 1365);
2096
-		}
2097
-		$codewords[9] = $data;
2098
-		if (($fcs >> 10) == 1) {
2099
-			$codewords[9] += 659;
2100
-		}
2101
-		// generate lookup tables
2102
-		$table2of13 = $this->imb_tables(2, 78);
2103
-		$table5of13 = $this->imb_tables(5, 1287);
2104
-		// convert codewords to characters
2105
-		$characters = array();
2106
-		$bitmask = 512;
2107
-		foreach($codewords as $k => $val) {
2108
-			if ($val <= 1286) {
2109
-				$chrcode = $table5of13[$val];
2110
-			} else {
2111
-				$chrcode = $table2of13[($val - 1287)];
2112
-			}
2113
-			if (($fcs & $bitmask) > 0) {
2114
-				// bitwise invert
2115
-				$chrcode = ((~$chrcode) & 8191);
2116
-			}
2117
-			$characters[] = $chrcode;
2118
-			$bitmask /= 2;
2119
-		}
2120
-		$characters = array_reverse($characters);
2121
-		// build bars
2122
-		$k = 0;
2123
-		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 3, 'bcode' => array());
2124
-		for ($i = 0; $i < 65; ++$i) {
2125
-			$asc = (($characters[$asc_chr[$i]] & pow(2, $asc_pos[$i])) > 0);
2126
-			$dsc = (($characters[$dsc_chr[$i]] & pow(2, $dsc_pos[$i])) > 0);
2127
-			if ($asc AND $dsc) {
2128
-				// full bar (F)
2129
-				$p = 0;
2130
-				$h = 3;
2131
-			} elseif ($asc) {
2132
-				// ascender (A)
2133
-				$p = 0;
2134
-				$h = 2;
2135
-			} elseif ($dsc) {
2136
-				// descender (D)
2137
-				$p = 1;
2138
-				$h = 2;
2139
-			} else {
2140
-				// tracker (T)
2141
-				$p = 1;
2142
-				$h = 1;
2143
-			}
2144
-			$bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
2145
-			$bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0);
2146
-			$bararray['maxw'] += 2;
2147
-		}
2148
-		unset($bararray['bcode'][($k - 1)]);
2149
-		--$bararray['maxw'];
2150
-		return $bararray;
2151
-	}
2026
+    /**
2027
+     * IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
2028
+     * (requires PHP bcmath extension)
2029
+     * Intelligent Mail barcode is a 65-bar code for use on mail in the United States.
2030
+     * The fields are described as follows:<ul><li>The Barcode Identifier shall be assigned by USPS to encode the presort identification that is currently printed in human readable form on the optional endorsement line (OEL) as well as for future USPS use. This shall be two digits, with the second digit in the range of 0–4. The allowable encoding ranges shall be 00–04, 10–14, 20–24, 30–34, 40–44, 50–54, 60–64, 70–74, 80–84, and 90–94.</li><li>The Service Type Identifier shall be assigned by USPS for any combination of services requested on the mailpiece. The allowable encoding range shall be 000http://it2.php.net/manual/en/function.dechex.php–999. Each 3-digit value shall correspond to a particular mail class with a particular combination of service(s). Each service program, such as OneCode Confirm and OneCode ACS, shall provide the list of Service Type Identifier values.</li><li>The Mailer or Customer Identifier shall be assigned by USPS as a unique, 6 or 9 digit number that identifies a business entity. The allowable encoding range for the 6 digit Mailer ID shall be 000000- 899999, while the allowable encoding range for the 9 digit Mailer ID shall be 900000000-999999999.</li><li>The Serial or Sequence Number shall be assigned by the mailer for uniquely identifying and tracking mailpieces. The allowable encoding range shall be 000000000–999999999 when used with a 6 digit Mailer ID and 000000-999999 when used with a 9 digit Mailer ID. e. The Delivery Point ZIP Code shall be assigned by the mailer for routing the mailpiece. This shall replace POSTNET for routing the mailpiece to its final delivery point. The length may be 0, 5, 9, or 11 digits. The allowable encoding ranges shall be no ZIP Code, 00000–99999,  000000000–999999999, and 00000000000–99999999999.</li></ul>
2031
+     * @param $code (string) code to print, separate the ZIP (routing code) from the rest using a minus char '-' (BarcodeID_ServiceTypeID_MailerID_SerialNumber-RoutingCode)
2032
+     * @return array barcode representation.
2033
+     * @protected
2034
+     */
2035
+    protected function barcode_imb($code) {
2036
+        $asc_chr = array(4,0,2,6,3,5,1,9,8,7,1,2,0,6,4,8,2,9,5,3,0,1,3,7,4,6,8,9,2,0,5,1,9,4,3,8,6,7,1,2,4,3,9,5,7,8,3,0,2,1,4,0,9,1,7,0,2,4,6,3,7,1,9,5,8);
2037
+        $dsc_chr = array(7,1,9,5,8,0,2,4,6,3,5,8,9,7,3,0,6,1,7,4,6,8,9,2,5,1,7,5,4,3,8,7,6,0,2,5,4,9,3,0,1,6,8,2,0,4,5,9,6,7,5,2,6,3,8,5,1,9,8,7,4,0,2,6,3);
2038
+        $asc_pos = array(3,0,8,11,1,12,8,11,10,6,4,12,2,7,9,6,7,9,2,8,4,0,12,7,10,9,0,7,10,5,7,9,6,8,2,12,1,4,2,0,1,5,4,6,12,1,0,9,4,7,5,10,2,6,9,11,2,12,6,7,5,11,0,3,2);
2039
+        $dsc_pos = array(2,10,12,5,9,1,5,4,3,9,11,5,10,1,6,3,4,1,10,0,2,11,8,6,1,12,3,8,6,4,4,11,0,6,1,9,11,5,3,7,3,10,7,11,8,2,10,3,5,8,0,3,12,11,8,4,5,1,3,0,7,12,9,8,10);
2040
+        $code_arr = explode('-', $code);
2041
+        $tracking_number = $code_arr[0];
2042
+        if (isset($code_arr[1])) {
2043
+            $routing_code = $code_arr[1];
2044
+        } else {
2045
+            $routing_code = '';
2046
+        }
2047
+        // Conversion of Routing Code
2048
+        switch (strlen($routing_code)) {
2049
+            case 0: {
2050
+                $binary_code = 0;
2051
+                break;
2052
+            }
2053
+            case 5: {
2054
+                $binary_code = bcadd($routing_code, '1');
2055
+                break;
2056
+            }
2057
+            case 9: {
2058
+                $binary_code = bcadd($routing_code, '100001');
2059
+                break;
2060
+            }
2061
+            case 11: {
2062
+                $binary_code = bcadd($routing_code, '1000100001');
2063
+                break;
2064
+            }
2065
+            default: {
2066
+                return false;
2067
+                break;
2068
+            }
2069
+        }
2070
+        $binary_code = bcmul($binary_code, 10);
2071
+        $binary_code = bcadd($binary_code, $tracking_number[0]);
2072
+        $binary_code = bcmul($binary_code, 5);
2073
+        $binary_code = bcadd($binary_code, $tracking_number[1]);
2074
+        $binary_code .= substr($tracking_number, 2, 18);
2075
+        // convert to hexadecimal
2076
+        $binary_code = $this->dec_to_hex($binary_code);
2077
+        // pad to get 13 bytes
2078
+        $binary_code = str_pad($binary_code, 26, '0', STR_PAD_LEFT);
2079
+        // convert string to array of bytes
2080
+        $binary_code_arr = chunk_split($binary_code, 2, "\r");
2081
+        $binary_code_arr = substr($binary_code_arr, 0, -1);
2082
+        $binary_code_arr = explode("\r", $binary_code_arr);
2083
+        // calculate frame check sequence
2084
+        $fcs = $this->imb_crc11fcs($binary_code_arr);
2085
+        // exclude first 2 bits from first byte
2086
+        $first_byte = sprintf('%2s', dechex((hexdec($binary_code_arr[0]) << 2) >> 2));
2087
+        $binary_code_102bit = $first_byte.substr($binary_code, 2);
2088
+        // convert binary data to codewords
2089
+        $codewords = array();
2090
+        $data = $this->hex_to_dec($binary_code_102bit);
2091
+        $codewords[0] = bcmod($data, 636) * 2;
2092
+        $data = bcdiv($data, 636);
2093
+        for ($i = 1; $i < 9; ++$i) {
2094
+            $codewords[$i] = bcmod($data, 1365);
2095
+            $data = bcdiv($data, 1365);
2096
+        }
2097
+        $codewords[9] = $data;
2098
+        if (($fcs >> 10) == 1) {
2099
+            $codewords[9] += 659;
2100
+        }
2101
+        // generate lookup tables
2102
+        $table2of13 = $this->imb_tables(2, 78);
2103
+        $table5of13 = $this->imb_tables(5, 1287);
2104
+        // convert codewords to characters
2105
+        $characters = array();
2106
+        $bitmask = 512;
2107
+        foreach($codewords as $k => $val) {
2108
+            if ($val <= 1286) {
2109
+                $chrcode = $table5of13[$val];
2110
+            } else {
2111
+                $chrcode = $table2of13[($val - 1287)];
2112
+            }
2113
+            if (($fcs & $bitmask) > 0) {
2114
+                // bitwise invert
2115
+                $chrcode = ((~$chrcode) & 8191);
2116
+            }
2117
+            $characters[] = $chrcode;
2118
+            $bitmask /= 2;
2119
+        }
2120
+        $characters = array_reverse($characters);
2121
+        // build bars
2122
+        $k = 0;
2123
+        $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 3, 'bcode' => array());
2124
+        for ($i = 0; $i < 65; ++$i) {
2125
+            $asc = (($characters[$asc_chr[$i]] & pow(2, $asc_pos[$i])) > 0);
2126
+            $dsc = (($characters[$dsc_chr[$i]] & pow(2, $dsc_pos[$i])) > 0);
2127
+            if ($asc AND $dsc) {
2128
+                // full bar (F)
2129
+                $p = 0;
2130
+                $h = 3;
2131
+            } elseif ($asc) {
2132
+                // ascender (A)
2133
+                $p = 0;
2134
+                $h = 2;
2135
+            } elseif ($dsc) {
2136
+                // descender (D)
2137
+                $p = 1;
2138
+                $h = 2;
2139
+            } else {
2140
+                // tracker (T)
2141
+                $p = 1;
2142
+                $h = 1;
2143
+            }
2144
+            $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
2145
+            $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0);
2146
+            $bararray['maxw'] += 2;
2147
+        }
2148
+        unset($bararray['bcode'][($k - 1)]);
2149
+        --$bararray['maxw'];
2150
+        return $bararray;
2151
+    }
2152 2152
 
2153
-	/**
2154
-	 * Convert large integer number to hexadecimal representation.
2155
-	 * (requires PHP bcmath extension)
2156
-	 * @param $number (string) number to convert specified as a string
2157
-	 * @return string hexadecimal representation
2158
-	 */
2159
-	public function dec_to_hex($number) {
2160
-		$i = 0;
2161
-		$hex = array();
2162
-		if($number == 0) {
2163
-			return '00';
2164
-		}
2165
-		while($number > 0) {
2166
-			if($number == 0) {
2167
-				array_push($hex, '0');
2168
-			} else {
2169
-				array_push($hex, strtoupper(dechex(bcmod($number, '16'))));
2170
-				$number = bcdiv($number, '16', 0);
2171
-			}
2172
-		}
2173
-		$hex = array_reverse($hex);
2174
-		return implode($hex);
2175
-	}
2153
+    /**
2154
+     * Convert large integer number to hexadecimal representation.
2155
+     * (requires PHP bcmath extension)
2156
+     * @param $number (string) number to convert specified as a string
2157
+     * @return string hexadecimal representation
2158
+     */
2159
+    public function dec_to_hex($number) {
2160
+        $i = 0;
2161
+        $hex = array();
2162
+        if($number == 0) {
2163
+            return '00';
2164
+        }
2165
+        while($number > 0) {
2166
+            if($number == 0) {
2167
+                array_push($hex, '0');
2168
+            } else {
2169
+                array_push($hex, strtoupper(dechex(bcmod($number, '16'))));
2170
+                $number = bcdiv($number, '16', 0);
2171
+            }
2172
+        }
2173
+        $hex = array_reverse($hex);
2174
+        return implode($hex);
2175
+    }
2176 2176
 
2177
-	/**
2178
-	 * Convert large hexadecimal number to decimal representation (string).
2179
-	 * (requires PHP bcmath extension)
2180
-	 * @param $hex (string) hexadecimal number to convert specified as a string
2181
-	 * @return string hexadecimal representation
2182
-	 */
2183
-	public function hex_to_dec($hex) {
2184
-		$dec = 0;
2185
-		$bitval = 1;
2186
-		$len = strlen($hex);
2187
-		for($pos = ($len - 1); $pos >= 0; --$pos) {
2188
-			$dec = bcadd($dec, bcmul(hexdec($hex{$pos}), $bitval));
2189
-			$bitval = bcmul($bitval, 16);
2190
-		}
2191
-		return $dec;
2192
-	}
2177
+    /**
2178
+     * Convert large hexadecimal number to decimal representation (string).
2179
+     * (requires PHP bcmath extension)
2180
+     * @param $hex (string) hexadecimal number to convert specified as a string
2181
+     * @return string hexadecimal representation
2182
+     */
2183
+    public function hex_to_dec($hex) {
2184
+        $dec = 0;
2185
+        $bitval = 1;
2186
+        $len = strlen($hex);
2187
+        for($pos = ($len - 1); $pos >= 0; --$pos) {
2188
+            $dec = bcadd($dec, bcmul(hexdec($hex{$pos}), $bitval));
2189
+            $bitval = bcmul($bitval, 16);
2190
+        }
2191
+        return $dec;
2192
+    }
2193 2193
 
2194
-	/**
2195
-	 * Intelligent Mail Barcode calculation of Frame Check Sequence
2196
-	 * @param $code_arr (string) array of hexadecimal values (13 bytes holding 102 bits right justified).
2197
-	 * @return int 11 bit Frame Check Sequence as integer (decimal base)
2198
-	 * @protected
2199
-	 */
2200
-	protected function imb_crc11fcs($code_arr) {
2201
-		$genpoly = 0x0F35; // generator polynomial
2202
-		$fcs = 0x07FF; // Frame Check Sequence
2203
-		// do most significant byte skipping the 2 most significant bits
2204
-		$data = hexdec($code_arr[0]) << 5;
2205
-		for ($bit = 2; $bit < 8; ++$bit) {
2206
-			if (($fcs ^ $data) & 0x400) {
2207
-				$fcs = ($fcs << 1) ^ $genpoly;
2208
-			} else {
2209
-				$fcs = ($fcs << 1);
2210
-			}
2211
-			$fcs &= 0x7FF;
2212
-			$data <<= 1;
2213
-		}
2214
-		// do rest of bytes
2215
-		for ($byte = 1; $byte < 13; ++$byte) {
2216
-			$data = hexdec($code_arr[$byte]) << 3;
2217
-			for ($bit = 0; $bit < 8; ++$bit) {
2218
-				if (($fcs ^ $data) & 0x400) {
2219
-					$fcs = ($fcs << 1) ^ $genpoly;
2220
-				} else {
2221
-					$fcs = ($fcs << 1);
2222
-				}
2223
-				$fcs &= 0x7FF;
2224
-				$data <<= 1;
2225
-			}
2226
-		}
2227
-		return $fcs;
2228
-	}
2194
+    /**
2195
+     * Intelligent Mail Barcode calculation of Frame Check Sequence
2196
+     * @param $code_arr (string) array of hexadecimal values (13 bytes holding 102 bits right justified).
2197
+     * @return int 11 bit Frame Check Sequence as integer (decimal base)
2198
+     * @protected
2199
+     */
2200
+    protected function imb_crc11fcs($code_arr) {
2201
+        $genpoly = 0x0F35; // generator polynomial
2202
+        $fcs = 0x07FF; // Frame Check Sequence
2203
+        // do most significant byte skipping the 2 most significant bits
2204
+        $data = hexdec($code_arr[0]) << 5;
2205
+        for ($bit = 2; $bit < 8; ++$bit) {
2206
+            if (($fcs ^ $data) & 0x400) {
2207
+                $fcs = ($fcs << 1) ^ $genpoly;
2208
+            } else {
2209
+                $fcs = ($fcs << 1);
2210
+            }
2211
+            $fcs &= 0x7FF;
2212
+            $data <<= 1;
2213
+        }
2214
+        // do rest of bytes
2215
+        for ($byte = 1; $byte < 13; ++$byte) {
2216
+            $data = hexdec($code_arr[$byte]) << 3;
2217
+            for ($bit = 0; $bit < 8; ++$bit) {
2218
+                if (($fcs ^ $data) & 0x400) {
2219
+                    $fcs = ($fcs << 1) ^ $genpoly;
2220
+                } else {
2221
+                    $fcs = ($fcs << 1);
2222
+                }
2223
+                $fcs &= 0x7FF;
2224
+                $data <<= 1;
2225
+            }
2226
+        }
2227
+        return $fcs;
2228
+    }
2229 2229
 
2230
-	/**
2231
-	 * Reverse unsigned short value
2232
-	 * @param $num (int) value to reversr
2233
-	 * @return int reversed value
2234
-	 * @protected
2235
-	 */
2236
-	protected function imb_reverse_us($num) {
2237
-		$rev = 0;
2238
-		for ($i = 0; $i < 16; ++$i) {
2239
-			$rev <<= 1;
2240
-			$rev |= ($num & 1);
2241
-			$num >>= 1;
2242
-		}
2243
-		return $rev;
2244
-	}
2230
+    /**
2231
+     * Reverse unsigned short value
2232
+     * @param $num (int) value to reversr
2233
+     * @return int reversed value
2234
+     * @protected
2235
+     */
2236
+    protected function imb_reverse_us($num) {
2237
+        $rev = 0;
2238
+        for ($i = 0; $i < 16; ++$i) {
2239
+            $rev <<= 1;
2240
+            $rev |= ($num & 1);
2241
+            $num >>= 1;
2242
+        }
2243
+        return $rev;
2244
+    }
2245 2245
 
2246
-	/**
2247
-	 * generate Nof13 tables used for Intelligent Mail Barcode
2248
-	 * @param $n (int) is the type of table: 2 for 2of13 table, 5 for 5of13table
2249
-	 * @param $size (int) size of table (78 for n=2 and 1287 for n=5)
2250
-	 * @return array requested table
2251
-	 * @protected
2252
-	 */
2253
-	protected function imb_tables($n, $size) {
2254
-		$table = array();
2255
-		$lli = 0; // LUT lower index
2256
-		$lui = $size - 1; // LUT upper index
2257
-		for ($count = 0; $count < 8192; ++$count) {
2258
-			$bit_count = 0;
2259
-			for ($bit_index = 0; $bit_index < 13; ++$bit_index) {
2260
-				$bit_count += intval(($count & (1 << $bit_index)) != 0);
2261
-			}
2262
-			// if we don't have the right number of bits on, go on to the next value
2263
-			if ($bit_count == $n) {
2264
-				$reverse = ($this->imb_reverse_us($count) >> 3);
2265
-				// if the reverse is less than count, we have already visited this pair before
2266
-				if ($reverse >= $count) {
2267
-					// If count is symmetric, place it at the first free slot from the end of the list.
2268
-					// Otherwise, place it at the first free slot from the beginning of the list AND place $reverse ath the next free slot from the beginning of the list
2269
-					if ($reverse == $count) {
2270
-						$table[$lui] = $count;
2271
-						--$lui;
2272
-					} else {
2273
-						$table[$lli] = $count;
2274
-						++$lli;
2275
-						$table[$lli] = $reverse;
2276
-						++$lli;
2277
-					}
2278
-				}
2279
-			}
2280
-		}
2281
-		return $table;
2282
-	}
2246
+    /**
2247
+     * generate Nof13 tables used for Intelligent Mail Barcode
2248
+     * @param $n (int) is the type of table: 2 for 2of13 table, 5 for 5of13table
2249
+     * @param $size (int) size of table (78 for n=2 and 1287 for n=5)
2250
+     * @return array requested table
2251
+     * @protected
2252
+     */
2253
+    protected function imb_tables($n, $size) {
2254
+        $table = array();
2255
+        $lli = 0; // LUT lower index
2256
+        $lui = $size - 1; // LUT upper index
2257
+        for ($count = 0; $count < 8192; ++$count) {
2258
+            $bit_count = 0;
2259
+            for ($bit_index = 0; $bit_index < 13; ++$bit_index) {
2260
+                $bit_count += intval(($count & (1 << $bit_index)) != 0);
2261
+            }
2262
+            // if we don't have the right number of bits on, go on to the next value
2263
+            if ($bit_count == $n) {
2264
+                $reverse = ($this->imb_reverse_us($count) >> 3);
2265
+                // if the reverse is less than count, we have already visited this pair before
2266
+                if ($reverse >= $count) {
2267
+                    // If count is symmetric, place it at the first free slot from the end of the list.
2268
+                    // Otherwise, place it at the first free slot from the beginning of the list AND place $reverse ath the next free slot from the beginning of the list
2269
+                    if ($reverse == $count) {
2270
+                        $table[$lui] = $count;
2271
+                        --$lui;
2272
+                    } else {
2273
+                        $table[$lli] = $count;
2274
+                        ++$lli;
2275
+                        $table[$lli] = $reverse;
2276
+                        ++$lli;
2277
+                    }
2278
+                }
2279
+            }
2280
+        }
2281
+        return $table;
2282
+    }
2283 2283
 
2284 2284
 } // end of class
2285 2285
 //============================================================+
Please login to merge, or discard this patch.
Spacing   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
91 91
  	 * @public
92 92
 	 */
93
-	public function getBarcodeSVG($w=2, $h=30, $color='black') {
93
+	public function getBarcodeSVG($w = 2, $h = 30, $color = 'black') {
94 94
 		// send headers
95 95
 		$code = $this->getBarcodeSVGcode($w, $h, $color);
96 96
 		header('Content-Type: application/svg+xml');
@@ -111,21 +111,21 @@  discard block
 block discarded – undo
111 111
  	 * @return string SVG code.
112 112
  	 * @public
113 113
 	 */
114
-	public function getBarcodeSVGcode($w=2, $h=30, $color='black') {
114
+	public function getBarcodeSVGcode($w = 2, $h = 30, $color = 'black') {
115 115
 		// replace table for special characters
116 116
 		$repstr = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
117 117
 		$svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n";
118 118
 		$svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'."\n";
119
-		$svg .= '<svg width="'.round(($this->barcode_array['maxw'] * $w), 3).'" height="'.$h.'" version="1.1" xmlns="http://www.w3.org/2000/svg">'."\n";
119
+		$svg .= '<svg width="'.round(($this->barcode_array['maxw']*$w), 3).'" height="'.$h.'" version="1.1" xmlns="http://www.w3.org/2000/svg">'."\n";
120 120
 		$svg .= "\t".'<desc>'.strtr($this->barcode_array['code'], $repstr).'</desc>'."\n";
121 121
 		$svg .= "\t".'<g id="bars" fill="'.$color.'" stroke="none">'."\n";
122 122
 		// print bars
123 123
 		$x = 0;
124 124
 		foreach ($this->barcode_array['bcode'] as $k => $v) {
125
-			$bw = round(($v['w'] * $w), 3);
126
-			$bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3);
125
+			$bw = round(($v['w']*$w), 3);
126
+			$bh = round(($v['h']*$h/$this->barcode_array['maxh']), 3);
127 127
 			if ($v['t']) {
128
-				$y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3);
128
+				$y = round(($v['p']*$h/$this->barcode_array['maxh']), 3);
129 129
 				// draw a vertical bar
130 130
 				$svg .= "\t\t".'<rect x="'.$x.'" y="'.$y.'" width="'.$bw.'" height="'.$bh.'" />'."\n";
131 131
 			}
@@ -144,15 +144,15 @@  discard block
 block discarded – undo
144 144
  	 * @return string HTML code.
145 145
  	 * @public
146 146
 	 */
147
-	public function getBarcodeHTML($w=2, $h=30, $color='black') {
148
-		$html = '<div style="font-size:0;position:relative;width:'.($this->barcode_array['maxw'] * $w).'px;height:'.($h).'px;">'."\n";
147
+	public function getBarcodeHTML($w = 2, $h = 30, $color = 'black') {
148
+		$html = '<div style="font-size:0;position:relative;width:'.($this->barcode_array['maxw']*$w).'px;height:'.($h).'px;">'."\n";
149 149
 		// print bars
150 150
 		$x = 0;
151 151
 		foreach ($this->barcode_array['bcode'] as $k => $v) {
152
-			$bw = round(($v['w'] * $w), 3);
153
-			$bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3);
152
+			$bw = round(($v['w']*$w), 3);
153
+			$bh = round(($v['h']*$h/$this->barcode_array['maxh']), 3);
154 154
 			if ($v['t']) {
155
-				$y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3);
155
+				$y = round(($v['p']*$h/$this->barcode_array['maxh']), 3);
156 156
 				// draw a vertical bar
157 157
 				$html .= '<div style="background-color:'.$color.';width:'.$bw.'px;height:'.$bh.'px;position:absolute;left:'.$x.'px;top:'.$y.'px;">&nbsp;</div>'."\n";
158 158
 			}
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
  	 * @return image or false in case of error.
171 171
  	 * @public
172 172
 	 */
173
-	public function getBarcodePNG($w=2, $h=30, $color=array(0,0,0)) {
173
+	public function getBarcodePNG($w = 2, $h = 30, $color = array(0, 0, 0)) {
174 174
 		// calculate image size
175
-		$width = ($this->barcode_array['maxw'] * $w);
175
+		$width = ($this->barcode_array['maxw']*$w);
176 176
 		$height = $h;
177 177
 		if (function_exists('imagecreate')) {
178 178
 			// GD library
@@ -195,10 +195,10 @@  discard block
 block discarded – undo
195 195
 		// print bars
196 196
 		$x = 0;
197 197
 		foreach ($this->barcode_array['bcode'] as $k => $v) {
198
-			$bw = round(($v['w'] * $w), 3);
199
-			$bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3);
198
+			$bw = round(($v['w']*$w), 3);
199
+			$bh = round(($v['h']*$h/$this->barcode_array['maxh']), 3);
200 200
 			if ($v['t']) {
201
-				$y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3);
201
+				$y = round(($v['p']*$h/$this->barcode_array['maxh']), 3);
202 202
 				// draw a vertical bar
203 203
 				if ($imagick) {
204 204
 					$bar->rectangle($x, $y, ($x + $bw - 1), ($y + $bh - 1));
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 	 * @return array barcode representation.
371 371
 	 * @protected
372 372
 	 */
373
-	protected function barcode_code39($code, $extended=false, $checksum=false) {
373
+	protected function barcode_code39($code, $extended = false, $checksum = false) {
374 374
 		$chr['0'] = '111331311';
375 375
 		$chr['1'] = '311311113';
376 376
 		$chr['2'] = '113311113';
@@ -434,12 +434,12 @@  discard block
 block discarded – undo
434 434
 		$clen = strlen($code);
435 435
 		for ($i = 0; $i < $clen; ++$i) {
436 436
 			$char = $code{$i};
437
-			if(!isset($chr[$char])) {
437
+			if (!isset($chr[$char])) {
438 438
 				// invalid character
439 439
 				return false;
440 440
 			}
441 441
 			for ($j = 0; $j < 9; ++$j) {
442
-				if (($j % 2) == 0) {
442
+				if (($j%2) == 0) {
443 443
 					$t = true; // bar
444 444
 				} else {
445 445
 					$t = false; // space
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 			chr(124) => '%Q', chr(125) => '%R', chr(126) => '%S', chr(127) => '%T');
500 500
 		$code_ext = '';
501 501
 		$clen = strlen($code);
502
-		for ($i = 0 ; $i < $clen; ++$i) {
502
+		for ($i = 0; $i < $clen; ++$i) {
503 503
 			if (ord($code{$i}) > 127) {
504 504
 				return false;
505 505
 			}
@@ -522,11 +522,11 @@  discard block
 block discarded – undo
522 522
 			'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%');
523 523
 		$sum = 0;
524 524
 		$clen = strlen($code);
525
-		for ($i = 0 ; $i < $clen; ++$i) {
525
+		for ($i = 0; $i < $clen; ++$i) {
526 526
 			$k = array_keys($chars, $code{$i});
527 527
 			$sum += $k[0];
528 528
 		}
529
-		$j = ($sum % 43);
529
+		$j = ($sum%43);
530 530
 		return $chars[$j];
531 531
 	}
532 532
 
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
 			chr(124) => chr(131).'Q', chr(125) => chr(131).'R', chr(126) => chr(131).'S', chr(127) => chr(131).'T');
623 623
 		$code_ext = '';
624 624
 		$clen = strlen($code);
625
-		for ($i = 0 ; $i < $clen; ++$i) {
625
+		for ($i = 0; $i < $clen; ++$i) {
626 626
 			if (ord($code{$i}) > 127) {
627 627
 				return false;
628 628
 			}
@@ -637,12 +637,12 @@  discard block
 block discarded – undo
637 637
 		$clen = strlen($code);
638 638
 		for ($i = 0; $i < $clen; ++$i) {
639 639
 			$char = ord($code{$i});
640
-			if(!isset($chr[$char])) {
640
+			if (!isset($chr[$char])) {
641 641
 				// invalid character
642 642
 				return false;
643 643
 			}
644 644
 			for ($j = 0; $j < 6; ++$j) {
645
-				if (($j % 2) == 0) {
645
+				if (($j%2) == 0) {
646 646
 					$t = true; // bar
647 647
 				} else {
648 648
 					$t = false; // space
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
 		$check = 0;
681 681
 		for ($i = ($len - 1); $i >= 0; --$i) {
682 682
 			$k = array_keys($chars, $code{$i});
683
-			$check += ($k[0] * $p);
683
+			$check += ($k[0]*$p);
684 684
 			++$p;
685 685
 			if ($p > 20) {
686 686
 				$p = 1;
@@ -694,7 +694,7 @@  discard block
 block discarded – undo
694 694
 		$check = 0;
695 695
 		for ($i = $len; $i >= 0; --$i) {
696 696
 			$k = array_keys($chars, $code{$i});
697
-			$check += ($k[0] * $p);
697
+			$check += ($k[0]*$p);
698 698
 			++$p;
699 699
 			if ($p > 15) {
700 700
 				$p = 1;
@@ -717,15 +717,15 @@  discard block
 block discarded – undo
717 717
 	protected function checksum_s25($code) {
718 718
 		$len = strlen($code);
719 719
 		$sum = 0;
720
-		for ($i = 0; $i < $len; $i+=2) {
720
+		for ($i = 0; $i < $len; $i += 2) {
721 721
 			$sum += $code{$i};
722 722
 		}
723 723
 		$sum *= 3;
724
-		for ($i = 1; $i < $len; $i+=2) {
724
+		for ($i = 1; $i < $len; $i += 2) {
725 725
 			$sum += ($code{$i});
726 726
 		}
727
-		$r = $sum % 10;
728
-		if($r > 0) {
727
+		$r = $sum%10;
728
+		if ($r > 0) {
729 729
 			$r = (10 - $r);
730 730
 		}
731 731
 		return $r;
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
 	 * @return array barcode representation.
741 741
 	 * @protected
742 742
 	 */
743
-	protected function barcode_msi($code, $checksum=false) {
743
+	protected function barcode_msi($code, $checksum = false) {
744 744
 		$chr['0'] = '100100100100';
745 745
 		$chr['1'] = '100100100110';
746 746
 		$chr['2'] = '100100110100';
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 			$p = 2;
764 764
 			$check = 0;
765 765
 			for ($i = ($clen - 1); $i >= 0; --$i) {
766
-				$check += (hexdec($code{$i}) * $p);
766
+				$check += (hexdec($code{$i})*$p);
767 767
 				++$p;
768 768
 				if ($p > 7) {
769 769
 					$p = 2;
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
 	 * @return array barcode representation.
800 800
 	 * @protected
801 801
 	 */
802
-	protected function barcode_s25($code, $checksum=false) {
802
+	protected function barcode_s25($code, $checksum = false) {
803 803
 		$chr['0'] = '10101110111010';
804 804
 		$chr['1'] = '11101010101110';
805 805
 		$chr['2'] = '10111010101110';
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
 			// add checksum
815 815
 			$code .= $this->checksum_s25($code);
816 816
 		}
817
-		if((strlen($code) % 2) != 0) {
817
+		if ((strlen($code)%2) != 0) {
818 818
 			// add leading zero if code-length is odd
819 819
 			$code = '0'.$code;
820 820
 		}
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 		$k = 0;
848 848
 		for ($i = 0; $i < $len; ++$i) {
849 849
 			$w += 1;
850
-			if (($i == ($len - 1)) OR (($i < ($len - 1)) AND ($seq{$i} != $seq{($i+1)}))) {
850
+			if (($i == ($len - 1)) OR (($i < ($len - 1)) AND ($seq{$i} != $seq{($i + 1)}))) {
851 851
 				if ($seq{$i} == '1') {
852 852
 					$t = true; // bar
853 853
 				} else {
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
 	 * @return array barcode representation.
872 872
 	 * @protected
873 873
 	 */
874
-	protected function barcode_i25($code, $checksum=false) {
874
+	protected function barcode_i25($code, $checksum = false) {
875 875
 		$chr['0'] = '11221';
876 876
 		$chr['1'] = '21112';
877 877
 		$chr['2'] = '12112';
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
 			// add checksum
889 889
 			$code .= $this->checksum_s25($code);
890 890
 		}
891
-		if((strlen($code) % 2) != 0) {
891
+		if ((strlen($code)%2) != 0) {
892 892
 			// add leading zero if code-length is odd
893 893
 			$code = '0'.$code;
894 894
 		}
@@ -900,20 +900,20 @@  discard block
 block discarded – undo
900 900
 		$clen = strlen($code);
901 901
 		for ($i = 0; $i < $clen; $i = ($i + 2)) {
902 902
 			$char_bar = $code{$i};
903
-			$char_space = $code{$i+1};
904
-			if((!isset($chr[$char_bar])) OR (!isset($chr[$char_space]))) {
903
+			$char_space = $code{$i + 1};
904
+			if ((!isset($chr[$char_bar])) OR (!isset($chr[$char_space]))) {
905 905
 				// invalid character
906 906
 				return false;
907 907
 			}
908 908
 			// create a bar-space sequence
909 909
 			$seq = '';
910 910
 			$chrlen = strlen($chr[$char_bar]);
911
-			for ($s = 0; $s < $chrlen; $s++){
912
-				$seq .= $chr[$char_bar]{$s} . $chr[$char_space]{$s};
911
+			for ($s = 0; $s < $chrlen; $s++) {
912
+				$seq .= $chr[$char_bar]{$s}.$chr[$char_space]{$s};
913 913
 			}
914 914
 			$seqlen = strlen($seq);
915 915
 			for ($j = 0; $j < $seqlen; ++$j) {
916
-				if (($j % 2) == 0) {
916
+				if (($j%2) == 0) {
917 917
 					$t = true; // bar
918 918
 				} else {
919 919
 					$t = false; // space
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
 	 * @return array barcode representation.
936 936
 	 * @protected
937 937
 	 */
938
-	protected function barcode_c128($code, $type='') {
938
+	protected function barcode_c128($code, $type = '') {
939 939
 		$chr = array(
940 940
 			'212222', /* 00 */
941 941
 			'222122', /* 01 */
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
 		$code_data = array();
1062 1062
 		// lenght of the code
1063 1063
 		$len = strlen($code);
1064
-		switch(strtoupper($type)) {
1064
+		switch (strtoupper($type)) {
1065 1065
 			case 'A': { // MODE A
1066 1066
 				$startid = 103;
1067 1067
 				for ($i = 0; $i < $len; ++$i) {
@@ -1099,12 +1099,12 @@  discard block
 block discarded – undo
1099 1099
 					$code = substr($code, 1);
1100 1100
 					--$len;
1101 1101
 				}
1102
-				if (($len % 2) != 0) {
1102
+				if (($len%2) != 0) {
1103 1103
 					// the length must be even
1104 1104
 					return false;
1105 1105
 				}
1106
-				for ($i = 0; $i < $len; $i+=2) {
1107
-					$chrnum = $code{$i}.$code{$i+1};
1106
+				for ($i = 0; $i < $len; $i += 2) {
1107
+					$chrnum = $code{$i}.$code{$i + 1};
1108 1108
 					if (preg_match('/([0-9]{2})/', $chrnum) > 0) {
1109 1109
 						$code_data[] = intval($chrnum);
1110 1110
 					} else {
@@ -1129,7 +1129,7 @@  discard block
 block discarded – undo
1129 1129
 						}
1130 1130
 						// numeric sequence
1131 1131
 						$slen = strlen($val[0]);
1132
-						if (($slen % 2) != 0) {
1132
+						if (($slen%2) != 0) {
1133 1133
 							// the length must be even
1134 1134
 							--$slen;
1135 1135
 						}
@@ -1145,7 +1145,7 @@  discard block
 block discarded – undo
1145 1145
 				}
1146 1146
 				// process the sequence
1147 1147
 				foreach ($sequence as $key => $seq) {
1148
-					switch($seq[0]) {
1148
+					switch ($seq[0]) {
1149 1149
 						case 'A': {
1150 1150
 							if ($key == 0) {
1151 1151
 								$startid = 103;
@@ -1219,8 +1219,8 @@  discard block
 block discarded – undo
1219 1219
 							} elseif ($sequence[($key - 1)][0] != 'C') {
1220 1220
 								$code_data[] = 99;
1221 1221
 							}
1222
-							for ($i = 0; $i < $seq[2]; $i+=2) {
1223
-								$chrnum = $seq[1]{$i}.$seq[1]{$i+1};
1222
+							for ($i = 0; $i < $seq[2]; $i += 2) {
1223
+								$chrnum = $seq[1]{$i}.$seq[1]{$i + 1};
1224 1224
 								$code_data[] = intval($chrnum);
1225 1225
 							}
1226 1226
 							break;
@@ -1232,10 +1232,10 @@  discard block
 block discarded – undo
1232 1232
 		// calculate check character
1233 1233
 		$sum = $startid;
1234 1234
 		foreach ($code_data as $key => $val) {
1235
-			$sum += ($val * ($key + 1));
1235
+			$sum += ($val*($key + 1));
1236 1236
 		}
1237 1237
 		// add check character
1238
-		$code_data[] = ($sum % 103);
1238
+		$code_data[] = ($sum%103);
1239 1239
 		// add stop sequence
1240 1240
 		$code_data[] = 106;
1241 1241
 		$code_data[] = 107;
@@ -1246,7 +1246,7 @@  discard block
 block discarded – undo
1246 1246
 		foreach ($code_data as $val) {
1247 1247
 			$seq = $chr[$val];
1248 1248
 			for ($j = 0; $j < 6; ++$j) {
1249
-				if (($j % 2) == 0) {
1249
+				if (($j%2) == 0) {
1250 1250
 					$t = true; // bar
1251 1251
 				} else {
1252 1252
 					$t = false; // space
@@ -1304,7 +1304,7 @@  discard block
 block discarded – undo
1304 1304
 	 * @return array barcode representation.
1305 1305
 	 * @protected
1306 1306
 	 */
1307
-	protected function barcode_eanupc($code, $len=13) {
1307
+	protected function barcode_eanupc($code, $len = 13) {
1308 1308
 		$upce = false;
1309 1309
 		if ($len == 6) {
1310 1310
 			$len = 12; // UPC-A
@@ -1316,21 +1316,21 @@  discard block
 block discarded – undo
1316 1316
 		$code_len = strlen($code);
1317 1317
 		// calculate check digit
1318 1318
 		$sum_a = 0;
1319
-		for ($i = 1; $i < $data_len; $i+=2) {
1319
+		for ($i = 1; $i < $data_len; $i += 2) {
1320 1320
 			$sum_a += $code{$i};
1321 1321
 		}
1322 1322
 		if ($len > 12) {
1323 1323
 			$sum_a *= 3;
1324 1324
 		}
1325 1325
 		$sum_b = 0;
1326
-		for ($i = 0; $i < $data_len; $i+=2) {
1326
+		for ($i = 0; $i < $data_len; $i += 2) {
1327 1327
 			$sum_b += ($code{$i});
1328 1328
 		}
1329 1329
 		if ($len < 13) {
1330 1330
 			$sum_b *= 3;
1331 1331
 		}
1332
-		$r = ($sum_a + $sum_b) % 10;
1333
-		if($r > 0) {
1332
+		$r = ($sum_a + $sum_b)%10;
1333
+		if ($r > 0) {
1334 1334
 			$r = (10 - $r);
1335 1335
 		}
1336 1336
 		if ($code_len == $data_len) {
@@ -1405,41 +1405,41 @@  discard block
 block discarded – undo
1405 1405
 				'9'=>'1110100')
1406 1406
 		);
1407 1407
 		$parities = array(
1408
-			'0'=>array('A','A','A','A','A','A'),
1409
-			'1'=>array('A','A','B','A','B','B'),
1410
-			'2'=>array('A','A','B','B','A','B'),
1411
-			'3'=>array('A','A','B','B','B','A'),
1412
-			'4'=>array('A','B','A','A','B','B'),
1413
-			'5'=>array('A','B','B','A','A','B'),
1414
-			'6'=>array('A','B','B','B','A','A'),
1415
-			'7'=>array('A','B','A','B','A','B'),
1416
-			'8'=>array('A','B','A','B','B','A'),
1417
-			'9'=>array('A','B','B','A','B','A')
1408
+			'0'=>array('A', 'A', 'A', 'A', 'A', 'A'),
1409
+			'1'=>array('A', 'A', 'B', 'A', 'B', 'B'),
1410
+			'2'=>array('A', 'A', 'B', 'B', 'A', 'B'),
1411
+			'3'=>array('A', 'A', 'B', 'B', 'B', 'A'),
1412
+			'4'=>array('A', 'B', 'A', 'A', 'B', 'B'),
1413
+			'5'=>array('A', 'B', 'B', 'A', 'A', 'B'),
1414
+			'6'=>array('A', 'B', 'B', 'B', 'A', 'A'),
1415
+			'7'=>array('A', 'B', 'A', 'B', 'A', 'B'),
1416
+			'8'=>array('A', 'B', 'A', 'B', 'B', 'A'),
1417
+			'9'=>array('A', 'B', 'B', 'A', 'B', 'A')
1418 1418
 		);
1419 1419
 		$upce_parities = array();
1420 1420
 		$upce_parities[0] = array(
1421
-			'0'=>array('B','B','B','A','A','A'),
1422
-			'1'=>array('B','B','A','B','A','A'),
1423
-			'2'=>array('B','B','A','A','B','A'),
1424
-			'3'=>array('B','B','A','A','A','B'),
1425
-			'4'=>array('B','A','B','B','A','A'),
1426
-			'5'=>array('B','A','A','B','B','A'),
1427
-			'6'=>array('B','A','A','A','B','B'),
1428
-			'7'=>array('B','A','B','A','B','A'),
1429
-			'8'=>array('B','A','B','A','A','B'),
1430
-			'9'=>array('B','A','A','B','A','B')
1421
+			'0'=>array('B', 'B', 'B', 'A', 'A', 'A'),
1422
+			'1'=>array('B', 'B', 'A', 'B', 'A', 'A'),
1423
+			'2'=>array('B', 'B', 'A', 'A', 'B', 'A'),
1424
+			'3'=>array('B', 'B', 'A', 'A', 'A', 'B'),
1425
+			'4'=>array('B', 'A', 'B', 'B', 'A', 'A'),
1426
+			'5'=>array('B', 'A', 'A', 'B', 'B', 'A'),
1427
+			'6'=>array('B', 'A', 'A', 'A', 'B', 'B'),
1428
+			'7'=>array('B', 'A', 'B', 'A', 'B', 'A'),
1429
+			'8'=>array('B', 'A', 'B', 'A', 'A', 'B'),
1430
+			'9'=>array('B', 'A', 'A', 'B', 'A', 'B')
1431 1431
 		);
1432 1432
 		$upce_parities[1] = array(
1433
-			'0'=>array('A','A','A','B','B','B'),
1434
-			'1'=>array('A','A','B','A','B','B'),
1435
-			'2'=>array('A','A','B','B','A','B'),
1436
-			'3'=>array('A','A','B','B','B','A'),
1437
-			'4'=>array('A','B','A','A','B','B'),
1438
-			'5'=>array('A','B','B','A','A','B'),
1439
-			'6'=>array('A','B','B','B','A','A'),
1440
-			'7'=>array('A','B','A','B','A','B'),
1441
-			'8'=>array('A','B','A','B','B','A'),
1442
-			'9'=>array('A','B','B','A','B','A')
1433
+			'0'=>array('A', 'A', 'A', 'B', 'B', 'B'),
1434
+			'1'=>array('A', 'A', 'B', 'A', 'B', 'B'),
1435
+			'2'=>array('A', 'A', 'B', 'B', 'A', 'B'),
1436
+			'3'=>array('A', 'A', 'B', 'B', 'B', 'A'),
1437
+			'4'=>array('A', 'B', 'A', 'A', 'B', 'B'),
1438
+			'5'=>array('A', 'B', 'B', 'A', 'A', 'B'),
1439
+			'6'=>array('A', 'B', 'B', 'B', 'A', 'A'),
1440
+			'7'=>array('A', 'B', 'A', 'B', 'A', 'B'),
1441
+			'8'=>array('A', 'B', 'A', 'B', 'B', 'A'),
1442
+			'9'=>array('A', 'B', 'B', 'A', 'B', 'A')
1443 1443
 		);
1444 1444
 		$k = 0;
1445 1445
 		$seq = '101'; // left guard bar
@@ -1452,7 +1452,7 @@  discard block
 block discarded – undo
1452 1452
 			$seq .= '010101'; // right guard bar
1453 1453
 		} else {
1454 1454
 			$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1455
-			$half_len = intval(ceil($len / 2));
1455
+			$half_len = intval(ceil($len/2));
1456 1456
 			if ($len == 8) {
1457 1457
 				for ($i = 0; $i < $half_len; ++$i) {
1458 1458
 					$seq .= $codes['A'][$code{$i}];
@@ -1460,7 +1460,7 @@  discard block
 block discarded – undo
1460 1460
 			} else {
1461 1461
 				$p = $parities[$code[0]];
1462 1462
 				for ($i = 1; $i < $half_len; ++$i) {
1463
-					$seq .= $codes[$p[$i-1]][$code{$i}];
1463
+					$seq .= $codes[$p[$i - 1]][$code{$i}];
1464 1464
 				}
1465 1465
 			}
1466 1466
 			$seq .= '01010'; // center guard bar
@@ -1473,7 +1473,7 @@  discard block
 block discarded – undo
1473 1473
 		$w = 0;
1474 1474
 		for ($i = 0; $i < $clen; ++$i) {
1475 1475
 			$w += 1;
1476
-			if (($i == ($clen - 1)) OR (($i < ($clen - 1)) AND ($seq{$i} != $seq{($i+1)}))) {
1476
+			if (($i == ($clen - 1)) OR (($i < ($clen - 1)) AND ($seq{$i} != $seq{($i + 1)}))) {
1477 1477
 				if ($seq{$i} == '1') {
1478 1478
 					$t = true; // bar
1479 1479
 				} else {
@@ -1497,14 +1497,14 @@  discard block
 block discarded – undo
1497 1497
 	 * @return array barcode representation.
1498 1498
 	 * @protected
1499 1499
 	 */
1500
-	protected function barcode_eanext($code, $len=5) {
1500
+	protected function barcode_eanext($code, $len = 5) {
1501 1501
 		//Padding
1502 1502
 		$code = str_pad($code, $len, '0', STR_PAD_LEFT);
1503 1503
 		// calculate check digit
1504 1504
 		if ($len == 2) {
1505
-			$r = $code % 4;
1505
+			$r = $code%4;
1506 1506
 		} elseif ($len == 5) {
1507
-			$r = (3 * ($code[0] + $code[2] + $code[4])) + (9 * ($code[1] + $code[3]));
1507
+			$r = (3*($code[0] + $code[2] + $code[4])) + (9*($code[1] + $code[3]));
1508 1508
 			$r %= 10;
1509 1509
 		} else {
1510 1510
 			return false;
@@ -1536,22 +1536,22 @@  discard block
 block discarded – undo
1536 1536
 		);
1537 1537
 		$parities = array();
1538 1538
 		$parities[2] = array(
1539
-			'0'=>array('A','A'),
1540
-			'1'=>array('A','B'),
1541
-			'2'=>array('B','A'),
1542
-			'3'=>array('B','B')
1539
+			'0'=>array('A', 'A'),
1540
+			'1'=>array('A', 'B'),
1541
+			'2'=>array('B', 'A'),
1542
+			'3'=>array('B', 'B')
1543 1543
 		);
1544 1544
 		$parities[5] = array(
1545
-			'0'=>array('B','B','A','A','A'),
1546
-			'1'=>array('B','A','B','A','A'),
1547
-			'2'=>array('B','A','A','B','A'),
1548
-			'3'=>array('B','A','A','A','B'),
1549
-			'4'=>array('A','B','B','A','A'),
1550
-			'5'=>array('A','A','B','B','A'),
1551
-			'6'=>array('A','A','A','B','B'),
1552
-			'7'=>array('A','B','A','B','A'),
1553
-			'8'=>array('A','B','A','A','B'),
1554
-			'9'=>array('A','A','B','A','B')
1545
+			'0'=>array('B', 'B', 'A', 'A', 'A'),
1546
+			'1'=>array('B', 'A', 'B', 'A', 'A'),
1547
+			'2'=>array('B', 'A', 'A', 'B', 'A'),
1548
+			'3'=>array('B', 'A', 'A', 'A', 'B'),
1549
+			'4'=>array('A', 'B', 'B', 'A', 'A'),
1550
+			'5'=>array('A', 'A', 'B', 'B', 'A'),
1551
+			'6'=>array('A', 'A', 'A', 'B', 'B'),
1552
+			'7'=>array('A', 'B', 'A', 'B', 'A'),
1553
+			'8'=>array('A', 'B', 'A', 'A', 'B'),
1554
+			'9'=>array('A', 'A', 'B', 'A', 'B')
1555 1555
 		);
1556 1556
 		$p = $parities[$len][$r];
1557 1557
 		$seq = '1011'; // left guard bar
@@ -1572,33 +1572,33 @@  discard block
 block discarded – undo
1572 1572
 	 * @return array barcode representation.
1573 1573
 	 * @protected
1574 1574
 	 */
1575
-	protected function barcode_postnet($code, $planet=false) {
1575
+	protected function barcode_postnet($code, $planet = false) {
1576 1576
 		// bar lenght
1577 1577
 		if ($planet) {
1578 1578
 			$barlen = Array(
1579
-				0 => Array(1,1,2,2,2),
1580
-				1 => Array(2,2,2,1,1),
1581
-				2 => Array(2,2,1,2,1),
1582
-				3 => Array(2,2,1,1,2),
1583
-				4 => Array(2,1,2,2,1),
1584
-				5 => Array(2,1,2,1,2),
1585
-				6 => Array(2,1,1,2,2),
1586
-				7 => Array(1,2,2,2,1),
1587
-				8 => Array(1,2,2,1,2),
1588
-				9 => Array(1,2,1,2,2)
1579
+				0 => Array(1, 1, 2, 2, 2),
1580
+				1 => Array(2, 2, 2, 1, 1),
1581
+				2 => Array(2, 2, 1, 2, 1),
1582
+				3 => Array(2, 2, 1, 1, 2),
1583
+				4 => Array(2, 1, 2, 2, 1),
1584
+				5 => Array(2, 1, 2, 1, 2),
1585
+				6 => Array(2, 1, 1, 2, 2),
1586
+				7 => Array(1, 2, 2, 2, 1),
1587
+				8 => Array(1, 2, 2, 1, 2),
1588
+				9 => Array(1, 2, 1, 2, 2)
1589 1589
 			);
1590 1590
 		} else {
1591 1591
 			$barlen = Array(
1592
-				0 => Array(2,2,1,1,1),
1593
-				1 => Array(1,1,1,2,2),
1594
-				2 => Array(1,1,2,1,2),
1595
-				3 => Array(1,1,2,2,1),
1596
-				4 => Array(1,2,1,1,2),
1597
-				5 => Array(1,2,1,2,1),
1598
-				6 => Array(1,2,2,1,1),
1599
-				7 => Array(2,1,1,1,2),
1600
-				8 => Array(2,1,1,2,1),
1601
-				9 => Array(2,1,2,1,1)
1592
+				0 => Array(2, 2, 1, 1, 1),
1593
+				1 => Array(1, 1, 1, 2, 2),
1594
+				2 => Array(1, 1, 2, 1, 2),
1595
+				3 => Array(1, 1, 2, 2, 1),
1596
+				4 => Array(1, 2, 1, 1, 2),
1597
+				5 => Array(1, 2, 1, 2, 1),
1598
+				6 => Array(1, 2, 2, 1, 1),
1599
+				7 => Array(2, 1, 1, 1, 2),
1600
+				8 => Array(2, 1, 1, 2, 1),
1601
+				9 => Array(2, 1, 2, 1, 1)
1602 1602
 			);
1603 1603
 		}
1604 1604
 		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 2, 'bcode' => array());
@@ -1611,8 +1611,8 @@  discard block
 block discarded – undo
1611 1611
 		for ($i = 0; $i < $len; ++$i) {
1612 1612
 			$sum += intval($code{$i});
1613 1613
 		}
1614
-		$chkd = ($sum % 10);
1615
-		if($chkd > 0) {
1614
+		$chkd = ($sum%10);
1615
+		if ($chkd > 0) {
1616 1616
 			$chkd = (10 - $chkd);
1617 1617
 		}
1618 1618
 		$code .= $chkd;
@@ -1624,7 +1624,7 @@  discard block
 block discarded – undo
1624 1624
 		for ($i = 0; $i < $len; ++$i) {
1625 1625
 			for ($j = 0; $j < 5; ++$j) {
1626 1626
 				$h = $barlen[$code{$i}][$j];
1627
-				$p = floor(1 / $h);
1627
+				$p = floor(1/$h);
1628 1628
 				$bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
1629 1629
 				$bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0);
1630 1630
 				$bararray['maxw'] += 2;
@@ -1645,7 +1645,7 @@  discard block
 block discarded – undo
1645 1645
 	 * @return array barcode representation.
1646 1646
 	 * @protected
1647 1647
 	 */
1648
-	protected function barcode_rms4cc($code, $kix=false) {
1648
+	protected function barcode_rms4cc($code, $kix = false) {
1649 1649
 		$notkix = !$kix;
1650 1650
 		// bar mode
1651 1651
 		// 1 = pos 1, length 2
@@ -1653,42 +1653,42 @@  discard block
 block discarded – undo
1653 1653
 		// 3 = pos 2, length 1
1654 1654
 		// 4 = pos 2, length 2
1655 1655
 		$barmode = array(
1656
-			'0' => array(3,3,2,2),
1657
-			'1' => array(3,4,1,2),
1658
-			'2' => array(3,4,2,1),
1659
-			'3' => array(4,3,1,2),
1660
-			'4' => array(4,3,2,1),
1661
-			'5' => array(4,4,1,1),
1662
-			'6' => array(3,1,4,2),
1663
-			'7' => array(3,2,3,2),
1664
-			'8' => array(3,2,4,1),
1665
-			'9' => array(4,1,3,2),
1666
-			'A' => array(4,1,4,1),
1667
-			'B' => array(4,2,3,1),
1668
-			'C' => array(3,1,2,4),
1669
-			'D' => array(3,2,1,4),
1670
-			'E' => array(3,2,2,3),
1671
-			'F' => array(4,1,1,4),
1672
-			'G' => array(4,1,2,3),
1673
-			'H' => array(4,2,1,3),
1674
-			'I' => array(1,3,4,2),
1675
-			'J' => array(1,4,3,2),
1676
-			'K' => array(1,4,4,1),
1677
-			'L' => array(2,3,3,2),
1678
-			'M' => array(2,3,4,1),
1679
-			'N' => array(2,4,3,1),
1680
-			'O' => array(1,3,2,4),
1681
-			'P' => array(1,4,1,4),
1682
-			'Q' => array(1,4,2,3),
1683
-			'R' => array(2,3,1,4),
1684
-			'S' => array(2,3,2,3),
1685
-			'T' => array(2,4,1,3),
1686
-			'U' => array(1,1,4,4),
1687
-			'V' => array(1,2,3,4),
1688
-			'W' => array(1,2,4,3),
1689
-			'X' => array(2,1,3,4),
1690
-			'Y' => array(2,1,4,3),
1691
-			'Z' => array(2,2,3,3)
1656
+			'0' => array(3, 3, 2, 2),
1657
+			'1' => array(3, 4, 1, 2),
1658
+			'2' => array(3, 4, 2, 1),
1659
+			'3' => array(4, 3, 1, 2),
1660
+			'4' => array(4, 3, 2, 1),
1661
+			'5' => array(4, 4, 1, 1),
1662
+			'6' => array(3, 1, 4, 2),
1663
+			'7' => array(3, 2, 3, 2),
1664
+			'8' => array(3, 2, 4, 1),
1665
+			'9' => array(4, 1, 3, 2),
1666
+			'A' => array(4, 1, 4, 1),
1667
+			'B' => array(4, 2, 3, 1),
1668
+			'C' => array(3, 1, 2, 4),
1669
+			'D' => array(3, 2, 1, 4),
1670
+			'E' => array(3, 2, 2, 3),
1671
+			'F' => array(4, 1, 1, 4),
1672
+			'G' => array(4, 1, 2, 3),
1673
+			'H' => array(4, 2, 1, 3),
1674
+			'I' => array(1, 3, 4, 2),
1675
+			'J' => array(1, 4, 3, 2),
1676
+			'K' => array(1, 4, 4, 1),
1677
+			'L' => array(2, 3, 3, 2),
1678
+			'M' => array(2, 3, 4, 1),
1679
+			'N' => array(2, 4, 3, 1),
1680
+			'O' => array(1, 3, 2, 4),
1681
+			'P' => array(1, 4, 1, 4),
1682
+			'Q' => array(1, 4, 2, 3),
1683
+			'R' => array(2, 3, 1, 4),
1684
+			'S' => array(2, 3, 2, 3),
1685
+			'T' => array(2, 4, 1, 3),
1686
+			'U' => array(1, 1, 4, 4),
1687
+			'V' => array(1, 2, 3, 4),
1688
+			'W' => array(1, 2, 4, 3),
1689
+			'X' => array(2, 1, 3, 4),
1690
+			'Y' => array(2, 1, 4, 3),
1691
+			'Z' => array(2, 2, 3, 3)
1692 1692
 		);
1693 1693
 		$code = strtoupper($code);
1694 1694
 		$len = strlen($code);
@@ -1696,42 +1696,42 @@  discard block
 block discarded – undo
1696 1696
 		if ($notkix) {
1697 1697
 			// table for checksum calculation (row,col)
1698 1698
 			$checktable = array(
1699
-				'0' => array(1,1),
1700
-				'1' => array(1,2),
1701
-				'2' => array(1,3),
1702
-				'3' => array(1,4),
1703
-				'4' => array(1,5),
1704
-				'5' => array(1,0),
1705
-				'6' => array(2,1),
1706
-				'7' => array(2,2),
1707
-				'8' => array(2,3),
1708
-				'9' => array(2,4),
1709
-				'A' => array(2,5),
1710
-				'B' => array(2,0),
1711
-				'C' => array(3,1),
1712
-				'D' => array(3,2),
1713
-				'E' => array(3,3),
1714
-				'F' => array(3,4),
1715
-				'G' => array(3,5),
1716
-				'H' => array(3,0),
1717
-				'I' => array(4,1),
1718
-				'J' => array(4,2),
1719
-				'K' => array(4,3),
1720
-				'L' => array(4,4),
1721
-				'M' => array(4,5),
1722
-				'N' => array(4,0),
1723
-				'O' => array(5,1),
1724
-				'P' => array(5,2),
1725
-				'Q' => array(5,3),
1726
-				'R' => array(5,4),
1727
-				'S' => array(5,5),
1728
-				'T' => array(5,0),
1729
-				'U' => array(0,1),
1730
-				'V' => array(0,2),
1731
-				'W' => array(0,3),
1732
-				'X' => array(0,4),
1733
-				'Y' => array(0,5),
1734
-				'Z' => array(0,0)
1699
+				'0' => array(1, 1),
1700
+				'1' => array(1, 2),
1701
+				'2' => array(1, 3),
1702
+				'3' => array(1, 4),
1703
+				'4' => array(1, 5),
1704
+				'5' => array(1, 0),
1705
+				'6' => array(2, 1),
1706
+				'7' => array(2, 2),
1707
+				'8' => array(2, 3),
1708
+				'9' => array(2, 4),
1709
+				'A' => array(2, 5),
1710
+				'B' => array(2, 0),
1711
+				'C' => array(3, 1),
1712
+				'D' => array(3, 2),
1713
+				'E' => array(3, 3),
1714
+				'F' => array(3, 4),
1715
+				'G' => array(3, 5),
1716
+				'H' => array(3, 0),
1717
+				'I' => array(4, 1),
1718
+				'J' => array(4, 2),
1719
+				'K' => array(4, 3),
1720
+				'L' => array(4, 4),
1721
+				'M' => array(4, 5),
1722
+				'N' => array(4, 0),
1723
+				'O' => array(5, 1),
1724
+				'P' => array(5, 2),
1725
+				'Q' => array(5, 3),
1726
+				'R' => array(5, 4),
1727
+				'S' => array(5, 5),
1728
+				'T' => array(5, 0),
1729
+				'U' => array(0, 1),
1730
+				'V' => array(0, 2),
1731
+				'W' => array(0, 3),
1732
+				'X' => array(0, 4),
1733
+				'Y' => array(0, 5),
1734
+				'Z' => array(0, 0)
1735 1735
 			);
1736 1736
 			$row = 0;
1737 1737
 			$col = 0;
@@ -1741,7 +1741,7 @@  discard block
 block discarded – undo
1741 1741
 			}
1742 1742
 			$row %= 6;
1743 1743
 			$col %= 6;
1744
-			$chk = array_keys($checktable, array($row,$col));
1744
+			$chk = array_keys($checktable, array($row, $col));
1745 1745
 			$code .= $chk[0];
1746 1746
 			++$len;
1747 1747
 		}
@@ -1831,7 +1831,7 @@  discard block
 block discarded – undo
1831 1831
 			}
1832 1832
 			$seq = $chr[$code{$i}];
1833 1833
 			for ($j = 0; $j < 8; ++$j) {
1834
-				if (($j % 2) == 0) {
1834
+				if (($j%2) == 0) {
1835 1835
 					$t = true; // bar
1836 1836
 				} else {
1837 1837
 					$t = false; // space
@@ -1882,7 +1882,7 @@  discard block
 block discarded – undo
1882 1882
 			} else {
1883 1883
 				$dval = intval($digit);
1884 1884
 			}
1885
-			$check += ($dval * $p);
1885
+			$check += ($dval*$p);
1886 1886
 			++$p;
1887 1887
 			if ($p > 10) {
1888 1888
 				$p = 1;
@@ -1904,7 +1904,7 @@  discard block
 block discarded – undo
1904 1904
 				} else {
1905 1905
 					$dval = intval($digit);
1906 1906
 				}
1907
-				$check += ($dval * $p);
1907
+				$check += ($dval*$p);
1908 1908
 				++$p;
1909 1909
 				if ($p > 9) {
1910 1910
 					$p = 1;
@@ -1922,7 +1922,7 @@  discard block
 block discarded – undo
1922 1922
 			}
1923 1923
 			$seq = $chr[$code{$i}];
1924 1924
 			for ($j = 0; $j < 6; ++$j) {
1925
-				if (($j % 2) == 0) {
1925
+				if (($j%2) == 0) {
1926 1926
 					$t = true; // bar
1927 1927
 				} else {
1928 1928
 					$t = false; // space
@@ -1947,7 +1947,7 @@  discard block
 block discarded – undo
1947 1947
 		$seq = '';
1948 1948
 		$code = intval($code);
1949 1949
 		while ($code > 0) {
1950
-			if (($code % 2) == 0) {
1950
+			if (($code%2) == 0) {
1951 1951
 				$seq .= '11100';
1952 1952
 				$code -= 2;
1953 1953
 			} else {
@@ -1973,24 +1973,24 @@  discard block
 block discarded – undo
1973 1973
 		$seq = '';
1974 1974
 		$code = intval($code);
1975 1975
 		do {
1976
-			switch ($code % 3) {
1976
+			switch ($code%3) {
1977 1977
 				case 0: {
1978 1978
 					$seq .= '3';
1979
-					$code = ($code - 3) / 3;
1979
+					$code = ($code - 3)/3;
1980 1980
 					break;
1981 1981
 				}
1982 1982
 				case 1: {
1983 1983
 					$seq .= '1';
1984
-					$code = ($code - 1) / 3;
1984
+					$code = ($code - 1)/3;
1985 1985
 					break;
1986 1986
 				}
1987 1987
 				case 2: {
1988 1988
 					$seq .= '2';
1989
-					$code = ($code - 2) / 3;
1989
+					$code = ($code - 2)/3;
1990 1990
 					break;
1991 1991
 				}
1992 1992
 			}
1993
-		} while($code != 0);
1993
+		} while ($code != 0);
1994 1994
 		$seq = strrev($seq);
1995 1995
 		$k = 0;
1996 1996
 		$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 2, 'bcode' => array());
@@ -2033,10 +2033,10 @@  discard block
 block discarded – undo
2033 2033
 	 * @protected
2034 2034
 	 */
2035 2035
 	protected function barcode_imb($code) {
2036
-		$asc_chr = array(4,0,2,6,3,5,1,9,8,7,1,2,0,6,4,8,2,9,5,3,0,1,3,7,4,6,8,9,2,0,5,1,9,4,3,8,6,7,1,2,4,3,9,5,7,8,3,0,2,1,4,0,9,1,7,0,2,4,6,3,7,1,9,5,8);
2037
-		$dsc_chr = array(7,1,9,5,8,0,2,4,6,3,5,8,9,7,3,0,6,1,7,4,6,8,9,2,5,1,7,5,4,3,8,7,6,0,2,5,4,9,3,0,1,6,8,2,0,4,5,9,6,7,5,2,6,3,8,5,1,9,8,7,4,0,2,6,3);
2038
-		$asc_pos = array(3,0,8,11,1,12,8,11,10,6,4,12,2,7,9,6,7,9,2,8,4,0,12,7,10,9,0,7,10,5,7,9,6,8,2,12,1,4,2,0,1,5,4,6,12,1,0,9,4,7,5,10,2,6,9,11,2,12,6,7,5,11,0,3,2);
2039
-		$dsc_pos = array(2,10,12,5,9,1,5,4,3,9,11,5,10,1,6,3,4,1,10,0,2,11,8,6,1,12,3,8,6,4,4,11,0,6,1,9,11,5,3,7,3,10,7,11,8,2,10,3,5,8,0,3,12,11,8,4,5,1,3,0,7,12,9,8,10);
2036
+		$asc_chr = array(4, 0, 2, 6, 3, 5, 1, 9, 8, 7, 1, 2, 0, 6, 4, 8, 2, 9, 5, 3, 0, 1, 3, 7, 4, 6, 8, 9, 2, 0, 5, 1, 9, 4, 3, 8, 6, 7, 1, 2, 4, 3, 9, 5, 7, 8, 3, 0, 2, 1, 4, 0, 9, 1, 7, 0, 2, 4, 6, 3, 7, 1, 9, 5, 8);
2037
+		$dsc_chr = array(7, 1, 9, 5, 8, 0, 2, 4, 6, 3, 5, 8, 9, 7, 3, 0, 6, 1, 7, 4, 6, 8, 9, 2, 5, 1, 7, 5, 4, 3, 8, 7, 6, 0, 2, 5, 4, 9, 3, 0, 1, 6, 8, 2, 0, 4, 5, 9, 6, 7, 5, 2, 6, 3, 8, 5, 1, 9, 8, 7, 4, 0, 2, 6, 3);
2038
+		$asc_pos = array(3, 0, 8, 11, 1, 12, 8, 11, 10, 6, 4, 12, 2, 7, 9, 6, 7, 9, 2, 8, 4, 0, 12, 7, 10, 9, 0, 7, 10, 5, 7, 9, 6, 8, 2, 12, 1, 4, 2, 0, 1, 5, 4, 6, 12, 1, 0, 9, 4, 7, 5, 10, 2, 6, 9, 11, 2, 12, 6, 7, 5, 11, 0, 3, 2);
2039
+		$dsc_pos = array(2, 10, 12, 5, 9, 1, 5, 4, 3, 9, 11, 5, 10, 1, 6, 3, 4, 1, 10, 0, 2, 11, 8, 6, 1, 12, 3, 8, 6, 4, 4, 11, 0, 6, 1, 9, 11, 5, 3, 7, 3, 10, 7, 11, 8, 2, 10, 3, 5, 8, 0, 3, 12, 11, 8, 4, 5, 1, 3, 0, 7, 12, 9, 8, 10);
2040 2040
 		$code_arr = explode('-', $code);
2041 2041
 		$tracking_number = $code_arr[0];
2042 2042
 		if (isset($code_arr[1])) {
@@ -2088,7 +2088,7 @@  discard block
 block discarded – undo
2088 2088
 		// convert binary data to codewords
2089 2089
 		$codewords = array();
2090 2090
 		$data = $this->hex_to_dec($binary_code_102bit);
2091
-		$codewords[0] = bcmod($data, 636) * 2;
2091
+		$codewords[0] = bcmod($data, 636)*2;
2092 2092
 		$data = bcdiv($data, 636);
2093 2093
 		for ($i = 1; $i < 9; ++$i) {
2094 2094
 			$codewords[$i] = bcmod($data, 1365);
@@ -2104,7 +2104,7 @@  discard block
 block discarded – undo
2104 2104
 		// convert codewords to characters
2105 2105
 		$characters = array();
2106 2106
 		$bitmask = 512;
2107
-		foreach($codewords as $k => $val) {
2107
+		foreach ($codewords as $k => $val) {
2108 2108
 			if ($val <= 1286) {
2109 2109
 				$chrcode = $table5of13[$val];
2110 2110
 			} else {
@@ -2159,11 +2159,11 @@  discard block
 block discarded – undo
2159 2159
 	public function dec_to_hex($number) {
2160 2160
 		$i = 0;
2161 2161
 		$hex = array();
2162
-		if($number == 0) {
2162
+		if ($number == 0) {
2163 2163
 			return '00';
2164 2164
 		}
2165
-		while($number > 0) {
2166
-			if($number == 0) {
2165
+		while ($number > 0) {
2166
+			if ($number == 0) {
2167 2167
 				array_push($hex, '0');
2168 2168
 			} else {
2169 2169
 				array_push($hex, strtoupper(dechex(bcmod($number, '16'))));
@@ -2184,7 +2184,7 @@  discard block
 block discarded – undo
2184 2184
 		$dec = 0;
2185 2185
 		$bitval = 1;
2186 2186
 		$len = strlen($hex);
2187
-		for($pos = ($len - 1); $pos >= 0; --$pos) {
2187
+		for ($pos = ($len - 1); $pos >= 0; --$pos) {
2188 2188
 			$dec = bcadd($dec, bcmul(hexdec($hex{$pos}), $bitval));
2189 2189
 			$bitval = bcmul($bitval, 16);
2190 2190
 		}
Please login to merge, or discard this patch.
phpmyfaq/inc/libs/tcpdf/tcpdf_barcodes_2d.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 
72 72
 	/**
73 73
 	 * Return an array representations of barcode.
74
- 	 * @return array
74
+ 	 * @return boolean
75 75
 	 */
76 76
 	public function getBarcodeArray() {
77 77
 		return $this->barcode_array;
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	 * @param $w (int) Width of a single rectangle element in pixels.
168 168
 	 * @param $h (int) Height of a single rectangle element in pixels.
169 169
 	 * @param $color (array) RGB (0-255) foreground color for bar elements (background is transparent).
170
- 	 * @return image or false in case of error.
170
+ 	 * @return false|null or false in case of error.
171 171
  	 * @public
172 172
 	 */
173 173
 	public function getBarcodePNG($w=3, $h=3, $color=array(0,0,0)) {
Please login to merge, or discard this patch.
Indentation   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -49,282 +49,282 @@
 block discarded – undo
49 49
  */
50 50
 class TCPDF2DBarcode {
51 51
 
52
-	/**
53
-	 * Array representation of barcode.
54
-	 * @protected
55
-	 */
56
-	protected $barcode_array = false;
52
+    /**
53
+     * Array representation of barcode.
54
+     * @protected
55
+     */
56
+    protected $barcode_array = false;
57 57
 
58
-	/**
59
-	 * This is the class constructor.
60
-	 * Return an array representations for 2D barcodes:<ul>
61
-	 * <li>$arrcode['code'] code to be printed on text label</li>
62
-	 * <li>$arrcode['num_rows'] required number of rows</li>
63
-	 * <li>$arrcode['num_cols'] required number of columns</li>
64
-	 * <li>$arrcode['bcode'][$r][$c] value of the cell is $r row and $c column (0 = transparent, 1 = black)</li></ul>
65
-	 * @param $code (string) code to print
66
- 	 * @param $type (string) type of barcode: <ul><li>DATAMATRIX : Datamatrix (ISO/IEC 16022)</li><li>PDF417 : PDF417 (ISO/IEC 15438:2006)</li><li>PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6 : PDF417 with parameters: a = aspect ratio (width/height); e = error correction level (0-8); t = total number of macro segments; s = macro segment index (0-99998); f = file ID; o0 = File Name (text); o1 = Segment Count (numeric); o2 = Time Stamp (numeric); o3 = Sender (text); o4 = Addressee (text); o5 = File Size (numeric); o6 = Checksum (numeric). NOTES: Parameters t, s and f are required for a Macro Control Block, all other parametrs are optional. To use a comma character ',' on text options, replace it with the character 255: "\xff".</li><li>QRCODE : QRcode Low error correction</li><li>QRCODE,L : QRcode Low error correction</li><li>QRCODE,M : QRcode Medium error correction</li><li>QRCODE,Q : QRcode Better error correction</li><li>QRCODE,H : QR-CODE Best error correction</li><li>RAW: raw mode - comma-separad list of array rows</li><li>RAW2: raw mode - array rows are surrounded by square parenthesis.</li><li>TEST : Test matrix</li></ul>
67
-	 */
68
-	public function __construct($code, $type) {
69
-		$this->setBarcode($code, $type);
70
-	}
58
+    /**
59
+     * This is the class constructor.
60
+     * Return an array representations for 2D barcodes:<ul>
61
+     * <li>$arrcode['code'] code to be printed on text label</li>
62
+     * <li>$arrcode['num_rows'] required number of rows</li>
63
+     * <li>$arrcode['num_cols'] required number of columns</li>
64
+     * <li>$arrcode['bcode'][$r][$c] value of the cell is $r row and $c column (0 = transparent, 1 = black)</li></ul>
65
+     * @param $code (string) code to print
66
+     * @param $type (string) type of barcode: <ul><li>DATAMATRIX : Datamatrix (ISO/IEC 16022)</li><li>PDF417 : PDF417 (ISO/IEC 15438:2006)</li><li>PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6 : PDF417 with parameters: a = aspect ratio (width/height); e = error correction level (0-8); t = total number of macro segments; s = macro segment index (0-99998); f = file ID; o0 = File Name (text); o1 = Segment Count (numeric); o2 = Time Stamp (numeric); o3 = Sender (text); o4 = Addressee (text); o5 = File Size (numeric); o6 = Checksum (numeric). NOTES: Parameters t, s and f are required for a Macro Control Block, all other parametrs are optional. To use a comma character ',' on text options, replace it with the character 255: "\xff".</li><li>QRCODE : QRcode Low error correction</li><li>QRCODE,L : QRcode Low error correction</li><li>QRCODE,M : QRcode Medium error correction</li><li>QRCODE,Q : QRcode Better error correction</li><li>QRCODE,H : QR-CODE Best error correction</li><li>RAW: raw mode - comma-separad list of array rows</li><li>RAW2: raw mode - array rows are surrounded by square parenthesis.</li><li>TEST : Test matrix</li></ul>
67
+     */
68
+    public function __construct($code, $type) {
69
+        $this->setBarcode($code, $type);
70
+    }
71 71
 
72
-	/**
73
-	 * Return an array representations of barcode.
74
- 	 * @return array
75
-	 */
76
-	public function getBarcodeArray() {
77
-		return $this->barcode_array;
78
-	}
72
+    /**
73
+     * Return an array representations of barcode.
74
+     * @return array
75
+     */
76
+    public function getBarcodeArray() {
77
+        return $this->barcode_array;
78
+    }
79 79
 
80
-	/**
81
-	 * Send barcode as SVG image object to the standard output.
82
-	 * @param $w (int) Width of a single rectangle element in user units.
83
-	 * @param $h (int) Height of a single rectangle element in user units.
84
-	 * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
85
- 	 * @public
86
-	 */
87
-	public function getBarcodeSVG($w=3, $h=3, $color='black') {
88
-		// send headers
89
-		$code = $this->getBarcodeSVGcode($w, $h, $color);
90
-		header('Content-Type: application/svg+xml');
91
-		header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
92
-		header('Pragma: public');
93
-		header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
94
-		header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
95
-		header('Content-Disposition: inline; filename="'.md5($code).'.svg";');
96
-		//header('Content-Length: '.strlen($code));
97
-		echo $code;
98
-	}
80
+    /**
81
+     * Send barcode as SVG image object to the standard output.
82
+     * @param $w (int) Width of a single rectangle element in user units.
83
+     * @param $h (int) Height of a single rectangle element in user units.
84
+     * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
85
+     * @public
86
+     */
87
+    public function getBarcodeSVG($w=3, $h=3, $color='black') {
88
+        // send headers
89
+        $code = $this->getBarcodeSVGcode($w, $h, $color);
90
+        header('Content-Type: application/svg+xml');
91
+        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
92
+        header('Pragma: public');
93
+        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
94
+        header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
95
+        header('Content-Disposition: inline; filename="'.md5($code).'.svg";');
96
+        //header('Content-Length: '.strlen($code));
97
+        echo $code;
98
+    }
99 99
 
100
-	/**
101
-	 * Return a SVG string representation of barcode.
102
-	 * @param $w (int) Width of a single rectangle element in user units.
103
-	 * @param $h (int) Height of a single rectangle element in user units.
104
-	 * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
105
- 	 * @return string SVG code.
106
- 	 * @public
107
-	 */
108
-	public function getBarcodeSVGcode($w=3, $h=3, $color='black') {
109
-		// replace table for special characters
110
-		$repstr = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
111
-		$svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n";
112
-		$svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'."\n";
113
-		$svg .= '<svg width="'.round(($this->barcode_array['num_cols'] * $w), 3).'" height="'.round(($this->barcode_array['num_rows'] * $h), 3).'" version="1.1" xmlns="http://www.w3.org/2000/svg">'."\n";
114
-		$svg .= "\t".'<desc>'.strtr($this->barcode_array['code'], $repstr).'</desc>'."\n";
115
-		$svg .= "\t".'<g id="elements" fill="'.$color.'" stroke="none">'."\n";
116
-		// print barcode elements
117
-		$y = 0;
118
-		// for each row
119
-		for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) {
120
-			$x = 0;
121
-			// for each column
122
-			for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) {
123
-				if ($this->barcode_array['bcode'][$r][$c] == 1) {
124
-					// draw a single barcode cell
125
-					$svg .= "\t\t".'<rect x="'.$x.'" y="'.$y.'" width="'.$w.'" height="'.$h.'" />'."\n";
126
-				}
127
-				$x += $w;
128
-			}
129
-			$y += $h;
130
-		}
131
-		$svg .= "\t".'</g>'."\n";
132
-		$svg .= '</svg>'."\n";
133
-		return $svg;
134
-	}
100
+    /**
101
+     * Return a SVG string representation of barcode.
102
+     * @param $w (int) Width of a single rectangle element in user units.
103
+     * @param $h (int) Height of a single rectangle element in user units.
104
+     * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
105
+     * @return string SVG code.
106
+     * @public
107
+     */
108
+    public function getBarcodeSVGcode($w=3, $h=3, $color='black') {
109
+        // replace table for special characters
110
+        $repstr = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
111
+        $svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n";
112
+        $svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'."\n";
113
+        $svg .= '<svg width="'.round(($this->barcode_array['num_cols'] * $w), 3).'" height="'.round(($this->barcode_array['num_rows'] * $h), 3).'" version="1.1" xmlns="http://www.w3.org/2000/svg">'."\n";
114
+        $svg .= "\t".'<desc>'.strtr($this->barcode_array['code'], $repstr).'</desc>'."\n";
115
+        $svg .= "\t".'<g id="elements" fill="'.$color.'" stroke="none">'."\n";
116
+        // print barcode elements
117
+        $y = 0;
118
+        // for each row
119
+        for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) {
120
+            $x = 0;
121
+            // for each column
122
+            for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) {
123
+                if ($this->barcode_array['bcode'][$r][$c] == 1) {
124
+                    // draw a single barcode cell
125
+                    $svg .= "\t\t".'<rect x="'.$x.'" y="'.$y.'" width="'.$w.'" height="'.$h.'" />'."\n";
126
+                }
127
+                $x += $w;
128
+            }
129
+            $y += $h;
130
+        }
131
+        $svg .= "\t".'</g>'."\n";
132
+        $svg .= '</svg>'."\n";
133
+        return $svg;
134
+    }
135 135
 
136
-	/**
137
-	 * Return an HTML representation of barcode.
138
-	 * @param $w (int) Width of a single rectangle element in pixels.
139
-	 * @param $h (int) Height of a single rectangle element in pixels.
140
-	 * @param $color (string) Foreground color for bar elements (background is transparent).
141
- 	 * @return string HTML code.
142
- 	 * @public
143
-	 */
144
-	public function getBarcodeHTML($w=10, $h=10, $color='black') {
145
-		$html = '<div style="font-size:0;position:relative;width:'.($w * $this->barcode_array['num_cols']).'px;height:'.($h * $this->barcode_array['num_rows']).'px;">'."\n";
146
-		// print barcode elements
147
-		$y = 0;
148
-		// for each row
149
-		for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) {
150
-			$x = 0;
151
-			// for each column
152
-			for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) {
153
-				if ($this->barcode_array['bcode'][$r][$c] == 1) {
154
-					// draw a single barcode cell
155
-					$html .= '<div style="background-color:'.$color.';width:'.$w.'px;height:'.$h.'px;position:absolute;left:'.$x.'px;top:'.$y.'px;">&nbsp;</div>'."\n";
156
-				}
157
-				$x += $w;
158
-			}
159
-			$y += $h;
160
-		}
161
-		$html .= '</div>'."\n";
162
-		return $html;
163
-	}
136
+    /**
137
+     * Return an HTML representation of barcode.
138
+     * @param $w (int) Width of a single rectangle element in pixels.
139
+     * @param $h (int) Height of a single rectangle element in pixels.
140
+     * @param $color (string) Foreground color for bar elements (background is transparent).
141
+     * @return string HTML code.
142
+     * @public
143
+     */
144
+    public function getBarcodeHTML($w=10, $h=10, $color='black') {
145
+        $html = '<div style="font-size:0;position:relative;width:'.($w * $this->barcode_array['num_cols']).'px;height:'.($h * $this->barcode_array['num_rows']).'px;">'."\n";
146
+        // print barcode elements
147
+        $y = 0;
148
+        // for each row
149
+        for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) {
150
+            $x = 0;
151
+            // for each column
152
+            for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) {
153
+                if ($this->barcode_array['bcode'][$r][$c] == 1) {
154
+                    // draw a single barcode cell
155
+                    $html .= '<div style="background-color:'.$color.';width:'.$w.'px;height:'.$h.'px;position:absolute;left:'.$x.'px;top:'.$y.'px;">&nbsp;</div>'."\n";
156
+                }
157
+                $x += $w;
158
+            }
159
+            $y += $h;
160
+        }
161
+        $html .= '</div>'."\n";
162
+        return $html;
163
+    }
164 164
 
165
-	/**
166
-	 * Return a PNG image representation of barcode (requires GD or Imagick library).
167
-	 * @param $w (int) Width of a single rectangle element in pixels.
168
-	 * @param $h (int) Height of a single rectangle element in pixels.
169
-	 * @param $color (array) RGB (0-255) foreground color for bar elements (background is transparent).
170
- 	 * @return image or false in case of error.
171
- 	 * @public
172
-	 */
173
-	public function getBarcodePNG($w=3, $h=3, $color=array(0,0,0)) {
174
-		// calculate image size
175
-		$width = ($this->barcode_array['num_cols'] * $w);
176
-		$height = ($this->barcode_array['num_rows'] * $h);
177
-		if (function_exists('imagecreate')) {
178
-			// GD library
179
-			$imagick = false;
180
-			$png = imagecreate($width, $height);
181
-			$bgcol = imagecolorallocate($png, 255, 255, 255);
182
-			imagecolortransparent($png, $bgcol);
183
-			$fgcol = imagecolorallocate($png, $color[0], $color[1], $color[2]);
184
-		} elseif (extension_loaded('imagick')) {
185
-			$imagick = true;
186
-			$bgcol = new imagickpixel('rgb(255,255,255');
187
-			$fgcol = new imagickpixel('rgb('.$color[0].','.$color[1].','.$color[2].')');
188
-			$png = new Imagick();
189
-			$png->newImage($width, $height, 'none', 'png');
190
-			$bar = new imagickdraw();
191
-			$bar->setfillcolor($fgcol);
192
-		} else {
193
-			return false;
194
-		}
195
-		// print barcode elements
196
-		$y = 0;
197
-		// for each row
198
-		for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) {
199
-			$x = 0;
200
-			// for each column
201
-			for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) {
202
-				if ($this->barcode_array['bcode'][$r][$c] == 1) {
203
-					// draw a single barcode cell
204
-					if ($imagick) {
205
-						$bar->rectangle($x, $y, ($x + $w - 1), ($y + $h - 1));
206
-					} else {
207
-						imagefilledrectangle($png, $x, $y, ($x + $w - 1), ($y + $h - 1), $fgcol);
208
-					}
209
-				}
210
-				$x += $w;
211
-			}
212
-			$y += $h;
213
-		}
214
-		// send headers
215
-		header('Content-Type: image/png');
216
-		header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
217
-		header('Pragma: public');
218
-		header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
219
-		header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
220
-		if ($imagick) {
221
-			$png->drawimage($bar);
222
-			echo $png;
223
-		} else {
224
-			imagepng($png);
225
-			imagedestroy($png);
226
-		}
227
-	}
165
+    /**
166
+     * Return a PNG image representation of barcode (requires GD or Imagick library).
167
+     * @param $w (int) Width of a single rectangle element in pixels.
168
+     * @param $h (int) Height of a single rectangle element in pixels.
169
+     * @param $color (array) RGB (0-255) foreground color for bar elements (background is transparent).
170
+     * @return image or false in case of error.
171
+     * @public
172
+     */
173
+    public function getBarcodePNG($w=3, $h=3, $color=array(0,0,0)) {
174
+        // calculate image size
175
+        $width = ($this->barcode_array['num_cols'] * $w);
176
+        $height = ($this->barcode_array['num_rows'] * $h);
177
+        if (function_exists('imagecreate')) {
178
+            // GD library
179
+            $imagick = false;
180
+            $png = imagecreate($width, $height);
181
+            $bgcol = imagecolorallocate($png, 255, 255, 255);
182
+            imagecolortransparent($png, $bgcol);
183
+            $fgcol = imagecolorallocate($png, $color[0], $color[1], $color[2]);
184
+        } elseif (extension_loaded('imagick')) {
185
+            $imagick = true;
186
+            $bgcol = new imagickpixel('rgb(255,255,255');
187
+            $fgcol = new imagickpixel('rgb('.$color[0].','.$color[1].','.$color[2].')');
188
+            $png = new Imagick();
189
+            $png->newImage($width, $height, 'none', 'png');
190
+            $bar = new imagickdraw();
191
+            $bar->setfillcolor($fgcol);
192
+        } else {
193
+            return false;
194
+        }
195
+        // print barcode elements
196
+        $y = 0;
197
+        // for each row
198
+        for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) {
199
+            $x = 0;
200
+            // for each column
201
+            for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) {
202
+                if ($this->barcode_array['bcode'][$r][$c] == 1) {
203
+                    // draw a single barcode cell
204
+                    if ($imagick) {
205
+                        $bar->rectangle($x, $y, ($x + $w - 1), ($y + $h - 1));
206
+                    } else {
207
+                        imagefilledrectangle($png, $x, $y, ($x + $w - 1), ($y + $h - 1), $fgcol);
208
+                    }
209
+                }
210
+                $x += $w;
211
+            }
212
+            $y += $h;
213
+        }
214
+        // send headers
215
+        header('Content-Type: image/png');
216
+        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
217
+        header('Pragma: public');
218
+        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
219
+        header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
220
+        if ($imagick) {
221
+            $png->drawimage($bar);
222
+            echo $png;
223
+        } else {
224
+            imagepng($png);
225
+            imagedestroy($png);
226
+        }
227
+    }
228 228
 
229
-	/**
230
-	 * Set the barcode.
231
-	 * @param $code (string) code to print
232
- 	 * @param $type (string) type of barcode: <ul><li>DATAMATRIX : Datamatrix (ISO/IEC 16022)</li><li>PDF417 : PDF417 (ISO/IEC 15438:2006)</li><li>PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6 : PDF417 with parameters: a = aspect ratio (width/height); e = error correction level (0-8); t = total number of macro segments; s = macro segment index (0-99998); f = file ID; o0 = File Name (text); o1 = Segment Count (numeric); o2 = Time Stamp (numeric); o3 = Sender (text); o4 = Addressee (text); o5 = File Size (numeric); o6 = Checksum (numeric). NOTES: Parameters t, s and f are required for a Macro Control Block, all other parametrs are optional. To use a comma character ',' on text options, replace it with the character 255: "\xff".</li><li>QRCODE : QRcode Low error correction</li><li>QRCODE,L : QRcode Low error correction</li><li>QRCODE,M : QRcode Medium error correction</li><li>QRCODE,Q : QRcode Better error correction</li><li>QRCODE,H : QR-CODE Best error correction</li><li>RAW: raw mode - comma-separad list of array rows</li><li>RAW2: raw mode - array rows are surrounded by square parenthesis.</li><li>TEST : Test matrix</li></ul>
233
- 	 * @return array
234
-	 */
235
-	public function setBarcode($code, $type) {
236
-		$mode = explode(',', $type);
237
-		$qrtype = strtoupper($mode[0]);
238
-		switch ($qrtype) {
239
-			case 'DATAMATRIX': { // DATAMATRIX (ISO/IEC 16022)
240
-				require_once(dirname(__FILE__).'/include/barcodes/datamatrix.php');
241
-				$qrcode = new Datamatrix($code);
242
-				$this->barcode_array = $qrcode->getBarcodeArray();
243
-				$this->barcode_array['code'] = $code;
244
-				break;
245
-			}
246
-			case 'PDF417': { // PDF417 (ISO/IEC 15438:2006)
247
-				require_once(dirname(__FILE__).'/include/barcodes/pdf417.php');
248
-				if (!isset($mode[1]) OR ($mode[1] === '')) {
249
-					$aspectratio = 2; // default aspect ratio (width / height)
250
-				} else {
251
-					$aspectratio = floatval($mode[1]);
252
-				}
253
-				if (!isset($mode[2]) OR ($mode[2] === '')) {
254
-					$ecl = -1; // default error correction level (auto)
255
-				} else {
256
-					$ecl = intval($mode[2]);
257
-				}
258
-				// set macro block
259
-				$macro = array();
260
-				if (isset($mode[3]) AND ($mode[3] !== '') AND isset($mode[4]) AND ($mode[4] !== '') AND isset($mode[5]) AND ($mode[5] !== '')) {
261
-					$macro['segment_total'] = intval($mode[3]);
262
-					$macro['segment_index'] = intval($mode[4]);
263
-					$macro['file_id'] = strtr($mode[5], "\xff", ',');
264
-					for ($i = 0; $i < 7; ++$i) {
265
-						$o = $i + 6;
266
-						if (isset($mode[$o]) AND ($mode[$o] !== '')) {
267
-							// add option
268
-							$macro['option_'.$i] = strtr($mode[$o], "\xff", ',');
269
-						}
270
-					}
271
-				}
272
-				$qrcode = new PDF417($code, $ecl, $aspectratio, $macro);
273
-				$this->barcode_array = $qrcode->getBarcodeArray();
274
-				$this->barcode_array['code'] = $code;
275
-				break;
276
-			}
277
-			case 'QRCODE': { // QR-CODE
278
-				require_once(dirname(__FILE__).'/include/barcodes/qrcode.php');
279
-				if (!isset($mode[1]) OR (!in_array($mode[1],array('L','M','Q','H')))) {
280
-					$mode[1] = 'L'; // Ddefault: Low error correction
281
-				}
282
-				$qrcode = new QRcode($code, strtoupper($mode[1]));
283
-				$this->barcode_array = $qrcode->getBarcodeArray();
284
-				$this->barcode_array['code'] = $code;
285
-				break;
286
-			}
287
-			case 'RAW':
288
-			case 'RAW2': { // RAW MODE
289
-				// remove spaces
290
-				$code = preg_replace('/[\s]*/si', '', $code);
291
-				if (strlen($code) < 3) {
292
-					break;
293
-				}
294
-				if ($qrtype == 'RAW') {
295
-					// comma-separated rows
296
-					$rows = explode(',', $code);
297
-				} else { // RAW2
298
-					// rows enclosed in square parentheses
299
-					$code = substr($code, 1, -1);
300
-					$rows = explode('][', $code);
301
-				}
302
-				$this->barcode_array['num_rows'] = count($rows);
303
-				$this->barcode_array['num_cols'] = strlen($rows[0]);
304
-				$this->barcode_array['bcode'] = array();
305
-				foreach ($rows as $r) {
306
-					$this->barcode_array['bcode'][] = str_split($r, 1);
307
-				}
308
-				$this->barcode_array['code'] = $code;
309
-				break;
310
-			}
311
-			case 'TEST': { // TEST MODE
312
-				$this->barcode_array['num_rows'] = 5;
313
-				$this->barcode_array['num_cols'] = 15;
314
-				$this->barcode_array['bcode'] = array(
315
-					array(1,1,1,0,1,1,1,0,1,1,1,0,1,1,1),
316
-					array(0,1,0,0,1,0,0,0,1,0,0,0,0,1,0),
317
-					array(0,1,0,0,1,1,0,0,1,1,1,0,0,1,0),
318
-					array(0,1,0,0,1,0,0,0,0,0,1,0,0,1,0),
319
-					array(0,1,0,0,1,1,1,0,1,1,1,0,0,1,0));
320
-				$this->barcode_array['code'] = $code;
321
-				break;
322
-			}
323
-			default: {
324
-				$this->barcode_array = false;
325
-			}
326
-		}
327
-	}
229
+    /**
230
+     * Set the barcode.
231
+     * @param $code (string) code to print
232
+     * @param $type (string) type of barcode: <ul><li>DATAMATRIX : Datamatrix (ISO/IEC 16022)</li><li>PDF417 : PDF417 (ISO/IEC 15438:2006)</li><li>PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6 : PDF417 with parameters: a = aspect ratio (width/height); e = error correction level (0-8); t = total number of macro segments; s = macro segment index (0-99998); f = file ID; o0 = File Name (text); o1 = Segment Count (numeric); o2 = Time Stamp (numeric); o3 = Sender (text); o4 = Addressee (text); o5 = File Size (numeric); o6 = Checksum (numeric). NOTES: Parameters t, s and f are required for a Macro Control Block, all other parametrs are optional. To use a comma character ',' on text options, replace it with the character 255: "\xff".</li><li>QRCODE : QRcode Low error correction</li><li>QRCODE,L : QRcode Low error correction</li><li>QRCODE,M : QRcode Medium error correction</li><li>QRCODE,Q : QRcode Better error correction</li><li>QRCODE,H : QR-CODE Best error correction</li><li>RAW: raw mode - comma-separad list of array rows</li><li>RAW2: raw mode - array rows are surrounded by square parenthesis.</li><li>TEST : Test matrix</li></ul>
233
+     * @return array
234
+     */
235
+    public function setBarcode($code, $type) {
236
+        $mode = explode(',', $type);
237
+        $qrtype = strtoupper($mode[0]);
238
+        switch ($qrtype) {
239
+            case 'DATAMATRIX': { // DATAMATRIX (ISO/IEC 16022)
240
+                require_once(dirname(__FILE__).'/include/barcodes/datamatrix.php');
241
+                $qrcode = new Datamatrix($code);
242
+                $this->barcode_array = $qrcode->getBarcodeArray();
243
+                $this->barcode_array['code'] = $code;
244
+                break;
245
+            }
246
+            case 'PDF417': { // PDF417 (ISO/IEC 15438:2006)
247
+                require_once(dirname(__FILE__).'/include/barcodes/pdf417.php');
248
+                if (!isset($mode[1]) OR ($mode[1] === '')) {
249
+                    $aspectratio = 2; // default aspect ratio (width / height)
250
+                } else {
251
+                    $aspectratio = floatval($mode[1]);
252
+                }
253
+                if (!isset($mode[2]) OR ($mode[2] === '')) {
254
+                    $ecl = -1; // default error correction level (auto)
255
+                } else {
256
+                    $ecl = intval($mode[2]);
257
+                }
258
+                // set macro block
259
+                $macro = array();
260
+                if (isset($mode[3]) AND ($mode[3] !== '') AND isset($mode[4]) AND ($mode[4] !== '') AND isset($mode[5]) AND ($mode[5] !== '')) {
261
+                    $macro['segment_total'] = intval($mode[3]);
262
+                    $macro['segment_index'] = intval($mode[4]);
263
+                    $macro['file_id'] = strtr($mode[5], "\xff", ',');
264
+                    for ($i = 0; $i < 7; ++$i) {
265
+                        $o = $i + 6;
266
+                        if (isset($mode[$o]) AND ($mode[$o] !== '')) {
267
+                            // add option
268
+                            $macro['option_'.$i] = strtr($mode[$o], "\xff", ',');
269
+                        }
270
+                    }
271
+                }
272
+                $qrcode = new PDF417($code, $ecl, $aspectratio, $macro);
273
+                $this->barcode_array = $qrcode->getBarcodeArray();
274
+                $this->barcode_array['code'] = $code;
275
+                break;
276
+            }
277
+            case 'QRCODE': { // QR-CODE
278
+                require_once(dirname(__FILE__).'/include/barcodes/qrcode.php');
279
+                if (!isset($mode[1]) OR (!in_array($mode[1],array('L','M','Q','H')))) {
280
+                    $mode[1] = 'L'; // Ddefault: Low error correction
281
+                }
282
+                $qrcode = new QRcode($code, strtoupper($mode[1]));
283
+                $this->barcode_array = $qrcode->getBarcodeArray();
284
+                $this->barcode_array['code'] = $code;
285
+                break;
286
+            }
287
+            case 'RAW':
288
+            case 'RAW2': { // RAW MODE
289
+                // remove spaces
290
+                $code = preg_replace('/[\s]*/si', '', $code);
291
+                if (strlen($code) < 3) {
292
+                    break;
293
+                }
294
+                if ($qrtype == 'RAW') {
295
+                    // comma-separated rows
296
+                    $rows = explode(',', $code);
297
+                } else { // RAW2
298
+                    // rows enclosed in square parentheses
299
+                    $code = substr($code, 1, -1);
300
+                    $rows = explode('][', $code);
301
+                }
302
+                $this->barcode_array['num_rows'] = count($rows);
303
+                $this->barcode_array['num_cols'] = strlen($rows[0]);
304
+                $this->barcode_array['bcode'] = array();
305
+                foreach ($rows as $r) {
306
+                    $this->barcode_array['bcode'][] = str_split($r, 1);
307
+                }
308
+                $this->barcode_array['code'] = $code;
309
+                break;
310
+            }
311
+            case 'TEST': { // TEST MODE
312
+                $this->barcode_array['num_rows'] = 5;
313
+                $this->barcode_array['num_cols'] = 15;
314
+                $this->barcode_array['bcode'] = array(
315
+                    array(1,1,1,0,1,1,1,0,1,1,1,0,1,1,1),
316
+                    array(0,1,0,0,1,0,0,0,1,0,0,0,0,1,0),
317
+                    array(0,1,0,0,1,1,0,0,1,1,1,0,0,1,0),
318
+                    array(0,1,0,0,1,0,0,0,0,0,1,0,0,1,0),
319
+                    array(0,1,0,0,1,1,1,0,1,1,1,0,0,1,0));
320
+                $this->barcode_array['code'] = $code;
321
+                break;
322
+            }
323
+            default: {
324
+                $this->barcode_array = false;
325
+            }
326
+        }
327
+    }
328 328
 } // end of class
329 329
 
330 330
 //============================================================+
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 * @param $color (string) Foreground color (in SVG format) for bar elements (background is transparent).
85 85
  	 * @public
86 86
 	 */
87
-	public function getBarcodeSVG($w=3, $h=3, $color='black') {
87
+	public function getBarcodeSVG($w = 3, $h = 3, $color = 'black') {
88 88
 		// send headers
89 89
 		$code = $this->getBarcodeSVGcode($w, $h, $color);
90 90
 		header('Content-Type: application/svg+xml');
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
  	 * @return string SVG code.
106 106
  	 * @public
107 107
 	 */
108
-	public function getBarcodeSVGcode($w=3, $h=3, $color='black') {
108
+	public function getBarcodeSVGcode($w = 3, $h = 3, $color = 'black') {
109 109
 		// replace table for special characters
110 110
 		$repstr = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
111 111
 		$svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n";
112 112
 		$svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'."\n";
113
-		$svg .= '<svg width="'.round(($this->barcode_array['num_cols'] * $w), 3).'" height="'.round(($this->barcode_array['num_rows'] * $h), 3).'" version="1.1" xmlns="http://www.w3.org/2000/svg">'."\n";
113
+		$svg .= '<svg width="'.round(($this->barcode_array['num_cols']*$w), 3).'" height="'.round(($this->barcode_array['num_rows']*$h), 3).'" version="1.1" xmlns="http://www.w3.org/2000/svg">'."\n";
114 114
 		$svg .= "\t".'<desc>'.strtr($this->barcode_array['code'], $repstr).'</desc>'."\n";
115 115
 		$svg .= "\t".'<g id="elements" fill="'.$color.'" stroke="none">'."\n";
116 116
 		// print barcode elements
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
  	 * @return string HTML code.
142 142
  	 * @public
143 143
 	 */
144
-	public function getBarcodeHTML($w=10, $h=10, $color='black') {
145
-		$html = '<div style="font-size:0;position:relative;width:'.($w * $this->barcode_array['num_cols']).'px;height:'.($h * $this->barcode_array['num_rows']).'px;">'."\n";
144
+	public function getBarcodeHTML($w = 10, $h = 10, $color = 'black') {
145
+		$html = '<div style="font-size:0;position:relative;width:'.($w*$this->barcode_array['num_cols']).'px;height:'.($h*$this->barcode_array['num_rows']).'px;">'."\n";
146 146
 		// print barcode elements
147 147
 		$y = 0;
148 148
 		// for each row
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
  	 * @return image or false in case of error.
171 171
  	 * @public
172 172
 	 */
173
-	public function getBarcodePNG($w=3, $h=3, $color=array(0,0,0)) {
173
+	public function getBarcodePNG($w = 3, $h = 3, $color = array(0, 0, 0)) {
174 174
 		// calculate image size
175
-		$width = ($this->barcode_array['num_cols'] * $w);
176
-		$height = ($this->barcode_array['num_rows'] * $h);
175
+		$width = ($this->barcode_array['num_cols']*$w);
176
+		$height = ($this->barcode_array['num_rows']*$h);
177 177
 		if (function_exists('imagecreate')) {
178 178
 			// GD library
179 179
 			$imagick = false;
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 			}
277 277
 			case 'QRCODE': { // QR-CODE
278 278
 				require_once(dirname(__FILE__).'/include/barcodes/qrcode.php');
279
-				if (!isset($mode[1]) OR (!in_array($mode[1],array('L','M','Q','H')))) {
279
+				if (!isset($mode[1]) OR (!in_array($mode[1], array('L', 'M', 'Q', 'H')))) {
280 280
 					$mode[1] = 'L'; // Ddefault: Low error correction
281 281
 				}
282 282
 				$qrcode = new QRcode($code, strtoupper($mode[1]));
@@ -312,11 +312,11 @@  discard block
 block discarded – undo
312 312
 				$this->barcode_array['num_rows'] = 5;
313 313
 				$this->barcode_array['num_cols'] = 15;
314 314
 				$this->barcode_array['bcode'] = array(
315
-					array(1,1,1,0,1,1,1,0,1,1,1,0,1,1,1),
316
-					array(0,1,0,0,1,0,0,0,1,0,0,0,0,1,0),
317
-					array(0,1,0,0,1,1,0,0,1,1,1,0,0,1,0),
318
-					array(0,1,0,0,1,0,0,0,0,0,1,0,0,1,0),
319
-					array(0,1,0,0,1,1,1,0,1,1,1,0,0,1,0));
315
+					array(1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1),
316
+					array(0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0),
317
+					array(0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0),
318
+					array(0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0),
319
+					array(0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0));
320 320
 				$this->barcode_array['code'] = $code;
321 321
 				break;
322 322
 			}
Please login to merge, or discard this patch.