Completed
Push — 1.10.x ( 0f48ee...7b08cd )
by Angel Fernando Quiroz
165:10 queued 123:19
created
main/inc/lib/phpdocx/pdf/include/table_frame_reflower.cls.php 1 patch
Indentation   +157 added lines, -158 removed lines patch added patch discarded remove patch
@@ -34,7 +34,6 @@  discard block
 block discarded – undo
34 34
  * @copyright 2004 Benj Carson
35 35
  * @author Benj Carson <[email protected]>
36 36
  * @package dompdf
37
-
38 37
  */
39 38
 
40 39
 /* $Id: table_frame_reflower.cls.php 219 2010-03-11 23:18:31Z ryan.masten $ */
@@ -47,29 +46,29 @@  discard block
 block discarded – undo
47 46
  */
48 47
 class Table_Frame_Reflower extends Frame_Reflower {
49 48
 
50
-  /**
51
-   * Cache of results between call to get_min_max_width and assign_widths
52
-   *
53
-   * @var array
54
-   */
55
-  protected $_state;
49
+    /**
50
+     * Cache of results between call to get_min_max_width and assign_widths
51
+     *
52
+     * @var array
53
+     */
54
+    protected $_state;
56 55
 
57
-  function __construct(Table_Frame_Decorator $frame) {
56
+    function __construct(Table_Frame_Decorator $frame) {
58 57
     $this->_state = null;
59 58
     parent::__construct($frame);
60
-  }
59
+    }
61 60
 
62
-  /**
63
-   * State is held here so it needs to be reset along with the decorator
64
-   */
65
-  function reset() {
61
+    /**
62
+     * State is held here so it needs to be reset along with the decorator
63
+     */
64
+    function reset() {
66 65
     $this->_state = null;
67 66
     $this->_min_max_cache = null;
68
-  }
67
+    }
69 68
 
70
-  //........................................................................
69
+    //........................................................................
71 70
 
72
-  protected function _assign_widths() {
71
+    protected function _assign_widths() {
73 72
     $style = $this->_frame->get_style();
74 73
 
75 74
     // Find the min/max width of the table and sort the columns into
@@ -98,9 +97,9 @@  discard block
 block discarded – undo
98 97
     $right = $right === "auto" ? 0 : $style->length_in_pt($right, $cb["w"]);
99 98
 
100 99
     $delta = $left + $right + $style->length_in_pt(array($style->padding_left,
101
-                                                         $style->border_left_width,
102
-                                                         $style->border_right_width,
103
-                                                         $style->padding_right), $cb["w"]);
100
+                                                            $style->border_left_width,
101
+                                                            $style->border_right_width,
102
+                                                            $style->padding_right), $cb["w"]);
104 103
 
105 104
     $min_table_width = $style->length_in_pt( $style->min_width, $cb["w"] - $delta );
106 105
 
@@ -110,26 +109,26 @@  discard block
 block discarded – undo
110 109
     
111 110
     if ( $width !== "auto" ) {
112 111
 
113
-      $preferred_width = $style->length_in_pt($width, $cb["w"]) - $delta;
112
+        $preferred_width = $style->length_in_pt($width, $cb["w"]) - $delta;
114 113
 
115
-      if ( $preferred_width < $min_table_width )
114
+        if ( $preferred_width < $min_table_width )
116 115
         $preferred_width = $min_table_width;
117 116
 
118
-      if ( $preferred_width > $min_width )
117
+        if ( $preferred_width > $min_width )
119 118
         $width = $preferred_width;
120
-      else
119
+        else
121 120
         $width = $min_width;
122 121
 
123 122
     } else {
124 123
 
125
-      if ( $max_width + $delta < $cb["w"] )
124
+        if ( $max_width + $delta < $cb["w"] )
126 125
         $width = $max_width;
127
-      else if ( $cb["w"] - $delta > $min_width )
126
+        else if ( $cb["w"] - $delta > $min_width )
128 127
         $width = $cb["w"] - $delta;
129
-      else
128
+        else
130 129
         $width = $min_width;
131 130
 
132
-      if ( $width < $min_table_width )
131
+        if ( $width < $min_table_width )
133 132
         $width = $min_table_width;
134 133
 
135 134
     }
@@ -142,68 +141,68 @@  discard block
 block discarded – undo
142 141
     // If the whole table fits on the page, then assign each column it's max width
143 142
     if ( $width == $max_width ) {
144 143
 
145
-      foreach (array_keys($columns) as $i)
144
+        foreach (array_keys($columns) as $i)
146 145
         $cellmap->set_column_width($i, $columns[$i]["max-width"]);
147 146
 
148
-      return;
147
+        return;
149 148
     }
150 149
 
151 150
     // Determine leftover and assign it evenly to all columns
152 151
     if ( $width > $min_width ) {
153 152
 
154
-      // We have four cases to deal with:
155
-      //
156
-      // 1. All columns are auto--no widths have been specified.  In this
157
-      // case we distribute extra space across all columns weighted by max-width.
158
-      //
159
-      // 2. Only absolute widths have been specified.  In this case we
160
-      // distribute any extra space equally among 'width: auto' columns, or all
161
-      // columns if no auto columns have been specified.
162
-      //
163
-      // 3. Only percentage widths have been specified.  In this case we
164
-      // normalize the percentage values and distribute any remaining % to
165
-      // width: auto columns.  We then proceed to assign widths as fractions
166
-      // of the table width.
167
-      //
168
-      // 4. Both absolute and percentage widths have been specified.
169
-
170
-      // Case 1:
171
-      if ( $absolute_used == 0 && $percent_used == 0 ) {
153
+        // We have four cases to deal with:
154
+        //
155
+        // 1. All columns are auto--no widths have been specified.  In this
156
+        // case we distribute extra space across all columns weighted by max-width.
157
+        //
158
+        // 2. Only absolute widths have been specified.  In this case we
159
+        // distribute any extra space equally among 'width: auto' columns, or all
160
+        // columns if no auto columns have been specified.
161
+        //
162
+        // 3. Only percentage widths have been specified.  In this case we
163
+        // normalize the percentage values and distribute any remaining % to
164
+        // width: auto columns.  We then proceed to assign widths as fractions
165
+        // of the table width.
166
+        //
167
+        // 4. Both absolute and percentage widths have been specified.
168
+
169
+        // Case 1:
170
+        if ( $absolute_used == 0 && $percent_used == 0 ) {
172 171
         $increment = $width - $min_width;
173 172
 
174 173
         foreach (array_keys($columns) as $i)
175
-          $cellmap->set_column_width($i, $columns[$i]["min-width"] + $increment * ($columns[$i]["max-width"] / $max_width));
174
+            $cellmap->set_column_width($i, $columns[$i]["min-width"] + $increment * ($columns[$i]["max-width"] / $max_width));
176 175
         return;
177
-      }
176
+        }
178 177
 
179 178
 
180
-      // Case 2
181
-      if ( $absolute_used > 0 && $percent_used == 0 ) {
179
+        // Case 2
180
+        if ( $absolute_used > 0 && $percent_used == 0 ) {
182 181
 
183 182
         if ( count($auto) > 0 )
184
-          $increment = ($width - $auto_min - $absolute_used) / count($auto);
183
+            $increment = ($width - $auto_min - $absolute_used) / count($auto);
185 184
 
186 185
         // Use the absolutely specified width or the increment
187 186
         foreach (array_keys($columns) as $i) {
188 187
 
189
-          if ( $columns[$i]["absolute"] > 0 && count($auto) )
188
+            if ( $columns[$i]["absolute"] > 0 && count($auto) )
190 189
             $cellmap->set_column_width($i, $columns[$i]["min-width"]);
191
-          else if ( count($auto) ) 
190
+            else if ( count($auto) ) 
192 191
             $cellmap->set_column_width($i, $columns[$i]["min-width"] + $increment);
193
-          else {
192
+            else {
194 193
             // All absolute columns
195 194
             $increment = ($width - $absolute_used) * $columns[$i]["absolute"] / $absolute_used;
196 195
 
197 196
             $cellmap->set_column_width($i, $columns[$i]["min-width"] + $increment);
198
-          }
197
+            }
199 198
 
200 199
         }
201 200
         return;
202
-      }
201
+        }
203 202
 
204 203
 
205
-      // Case 3:
206
-      if ( $absolute_used == 0 && $percent_used > 0 ) {
204
+        // Case 3:
205
+        if ( $absolute_used == 0 && $percent_used > 0 ) {
207 206
 
208 207
         $scale = null;
209 208
         $remaining = null;
@@ -211,99 +210,99 @@  discard block
 block discarded – undo
211 210
         // Scale percent values if the total percentage is > 100, or if all
212 211
         // values are specified as percentages.
213 212
         if ( $percent_used > 100 || count($auto) == 0)
214
-          $scale = 100 / $percent_used;
213
+            $scale = 100 / $percent_used;
215 214
         else
216
-          $scale = 1;
215
+            $scale = 1;
217 216
 
218 217
         // Account for the minimum space used by the unassigned auto columns
219 218
         $used_width = $auto_min;
220 219
 
221 220
         foreach ($percent as $i) {
222
-          $columns[$i]["percent"] *= $scale;
221
+            $columns[$i]["percent"] *= $scale;
223 222
 
224
-          $slack = $width - $used_width;
223
+            $slack = $width - $used_width;
225 224
 
226
-          $w = min($columns[$i]["percent"] * $width/100, $slack);
225
+            $w = min($columns[$i]["percent"] * $width/100, $slack);
227 226
 
228
-          if ( $w < $columns[$i]["min-width"] )
227
+            if ( $w < $columns[$i]["min-width"] )
229 228
             $w = $columns[$i]["min-width"];
230 229
 
231
-          $cellmap->set_column_width($i, $w);
232
-          $used_width += $w;
230
+            $cellmap->set_column_width($i, $w);
231
+            $used_width += $w;
233 232
 
234 233
         }
235 234
 
236 235
         // This works because $used_width includes the min-width of each
237 236
         // unassigned column
238 237
         if ( count($auto) > 0 ) {
239
-          $increment = ($width - $used_width) / count($auto);
238
+            $increment = ($width - $used_width) / count($auto);
240 239
 
241
-          foreach ($auto as $i)
240
+            foreach ($auto as $i)
242 241
             $cellmap->set_column_width($i, $columns[$i]["min-width"] + $increment);
243 242
 
244 243
         }
245 244
         return;
246
-      }
245
+        }
247 246
 
248
-      // Case 4:
247
+        // Case 4:
249 248
 
250
-      // First-come, first served
251
-      if ( $absolute_used > 0 && $percent_used > 0 ) {
249
+        // First-come, first served
250
+        if ( $absolute_used > 0 && $percent_used > 0 ) {
252 251
 
253 252
         $used_width = $auto_min;
254 253
 
255 254
         foreach ($absolute as $i) {
256
-          $cellmap->set_column_width($i, $columns[$i]["min-width"]);
257
-          $used_width +=  $columns[$i]["min-width"];
255
+            $cellmap->set_column_width($i, $columns[$i]["min-width"]);
256
+            $used_width +=  $columns[$i]["min-width"];
258 257
         }
259 258
 
260 259
         // Scale percent values if the total percentage is > 100 or there
261 260
         // are no auto values to take up slack
262 261
         if ( $percent_used > 100 || count($auto) == 0 )
263
-          $scale = 100 / $percent_used;
262
+            $scale = 100 / $percent_used;
264 263
         else
265
-          $scale = 1;
264
+            $scale = 1;
266 265
 
267 266
         $remaining_width = $width - $used_width;
268 267
 
269 268
         foreach ($percent as $i) {
270
-          $slack = $remaining_width - $used_width;
269
+            $slack = $remaining_width - $used_width;
271 270
 
272
-          $columns[$i]["percent"] *= $scale;
273
-          $w = min($columns[$i]["percent"] * $remaining_width / 100, $slack);
271
+            $columns[$i]["percent"] *= $scale;
272
+            $w = min($columns[$i]["percent"] * $remaining_width / 100, $slack);
274 273
 
275
-          if ( $w < $columns[$i]["min-width"] )
274
+            if ( $w < $columns[$i]["min-width"] )
276 275
             $w = $columns[$i]["min-width"];
277 276
 
278
-          $columns[$i]["used-width"] = $w;
279
-          $used_width += $w;
277
+            $columns[$i]["used-width"] = $w;
278
+            $used_width += $w;
280 279
         }
281 280
 
282 281
         if ( count($auto) > 0 ) {
283
-          $increment = ($width - $used_width) / count($auto);
282
+            $increment = ($width - $used_width) / count($auto);
284 283
 
285
-          foreach ($auto as $i)
284
+            foreach ($auto as $i)
286 285
             $cellmap->set_column_width($i, $columns[$i]["min-width"] + $increment);
287 286
 
288 287
         }
289 288
 
290 289
         return;
291
-      }
290
+        }
292 291
 
293 292
 
294 293
     } else { // we are over constrained
295 294
 
296
-      // Each column gets its minimum width
297
-      foreach (array_keys($columns) as $i)
295
+        // Each column gets its minimum width
296
+        foreach (array_keys($columns) as $i)
298 297
         $cellmap->set_column_width($i, $columns[$i]["min-width"]);
299 298
 
300 299
     }
301
-  }
300
+    }
302 301
 
303
-  //........................................................................
302
+    //........................................................................
304 303
 
305
-  // Determine the frame's height based on min/max height
306
-  protected function _calculate_height() {
304
+    // Determine the frame's height based on min/max height
305
+    protected function _calculate_height() {
307 306
 
308 307
     $style = $this->_frame->get_style();
309 308
     $height = $style->height;
@@ -315,67 +314,67 @@  discard block
 block discarded – undo
315 314
     // Determine our content height
316 315
     $content_height = 0;
317 316
     foreach ( $rows as $r )
318
-      $content_height += $r["height"];
317
+        $content_height += $r["height"];
319 318
 
320 319
     $cb = $this->_frame->get_containing_block();
321 320
 
322 321
     if ( !($style->overflow === "visible" ||
323 322
            ($style->overflow === "hidden" && $height === "auto")) ) {
324 323
 
325
-      // Only handle min/max height if the height is independent of the frame's content
324
+        // Only handle min/max height if the height is independent of the frame's content
326 325
 
327
-      $min_height = $style->min_height;
328
-      $max_height = $style->max_height;
326
+        $min_height = $style->min_height;
327
+        $max_height = $style->max_height;
329 328
 
330
-      if ( isset($cb["h"]) ) {
329
+        if ( isset($cb["h"]) ) {
331 330
         $min_height = $style->length_in_pt($min_height, $cb["h"]);
332 331
         $max_height = $style->length_in_pt($max_height, $cb["h"]);
333 332
 
334
-      } else if ( isset($cb["w"]) ) {
333
+        } else if ( isset($cb["w"]) ) {
335 334
 
336 335
         if ( mb_strpos($min_height, "%") !== false )
337
-          $min_height = 0;
336
+            $min_height = 0;
338 337
         else
339
-          $min_height = $style->length_in_pt($min_height, $cb["w"]);
338
+            $min_height = $style->length_in_pt($min_height, $cb["w"]);
340 339
 
341 340
         if ( mb_strpos($max_height, "%") !== false )
342
-          $max_height = "none";
341
+            $max_height = "none";
343 342
         else
344
-          $max_height = $style->length_in_pt($max_height, $cb["w"]);
345
-      }
343
+            $max_height = $style->length_in_pt($max_height, $cb["w"]);
344
+        }
346 345
 
347
-      if ( $max_height !== "none" && $min_height > $max_height )
346
+        if ( $max_height !== "none" && $min_height > $max_height )
348 347
         // Swap 'em
349 348
         list($max_height, $min_height) = array($min_height, $max_height);
350 349
 
351
-      if ( $max_height !== "none" && $height > $max_height )
350
+        if ( $max_height !== "none" && $height > $max_height )
352 351
         $height = $max_height;
353 352
 
354
-      if ( $height < $min_height )
353
+        if ( $height < $min_height )
355 354
         $height = $min_height;
356 355
 
357 356
     } else {
358 357
 
359
-      // Use the content height or the height value, whichever is greater
360
-      if ( $height !== "auto" ) {
358
+        // Use the content height or the height value, whichever is greater
359
+        if ( $height !== "auto" ) {
361 360
         $height = $style->length_in_pt($height, $cb["h"]);
362 361
 
363 362
         if ( $height <= $content_height )
364
-          $height = $content_height;
363
+            $height = $content_height;
365 364
         else
366
-          $cellmap->set_frame_heights($height,$content_height);
365
+            $cellmap->set_frame_heights($height,$content_height);
367 366
 
368
-      } else
367
+        } else
369 368
         $height = $content_height;
370 369
 
371 370
     }
372 371
 
373 372
     return $height;
374 373
 
375
-  }
376
-  //........................................................................
374
+    }
375
+    //........................................................................
377 376
 
378
-  function reflow() {
377
+    function reflow() {
379 378
 
380 379
     // Check if a page break is forced
381 380
     $page = $this->_frame->get_root();
@@ -383,7 +382,7 @@  discard block
 block discarded – undo
383 382
 
384 383
     // Bail if the page is full
385 384
     if ( $page->is_full() )
386
-      return;
385
+        return;
387 386
     
388 387
     // Let the page know that we're reflowing a table so that splits
389 388
     // are suppressed (simply setting page-break-inside: avoid won't
@@ -401,7 +400,7 @@  discard block
 block discarded – undo
401 400
     // http://www.w3.org/TR/CSS21/tables.html#auto-table-layout
402 401
 
403 402
     if ( is_null($this->_state) )
404
-      $this->get_min_max_width();
403
+        $this->get_min_max_width();
405 404
 
406 405
     $cb = $this->_frame->get_containing_block();
407 406
     $style = $this->_frame->get_style();
@@ -410,15 +409,15 @@  discard block
 block discarded – undo
410 409
     // border-spacing to the table as padding.  The other half is added to
411 410
     // the cells themselves.
412 411
     if ( $style->border_collapse === "separate" ) {
413
-      list($h, $v) = $style->border_spacing;
412
+        list($h, $v) = $style->border_spacing;
414 413
 
415
-      $v = $style->length_in_pt($v) / 2;
416
-      $h = $style->length_in_pt($h) / 2;
414
+        $v = $style->length_in_pt($v) / 2;
415
+        $h = $style->length_in_pt($h) / 2;
417 416
 
418
-      $style->padding_left = $style->length_in_pt($style->padding_left, $cb["w"]) + $h;
419
-      $style->padding_right = $style->length_in_pt($style->padding_right, $cb["w"]) + $h;
420
-      $style->padding_top = $style->length_in_pt($style->padding_top, $cb["w"]) + $v;
421
-      $style->padding_bottom = $style->length_in_pt($style->padding_bottom, $cb["w"]) + $v;
417
+        $style->padding_left = $style->length_in_pt($style->padding_left, $cb["w"]) + $h;
418
+        $style->padding_right = $style->length_in_pt($style->padding_right, $cb["w"]) + $h;
419
+        $style->padding_top = $style->length_in_pt($style->padding_top, $cb["w"]) + $v;
420
+        $style->padding_bottom = $style->length_in_pt($style->padding_bottom, $cb["w"]) + $v;
422 421
 
423 422
     }
424 423
 
@@ -432,16 +431,16 @@  discard block
 block discarded – undo
432 431
     $diff = $cb["w"] - $width;
433 432
 
434 433
     if ( $left === "auto" && $right === "auto" && $diff > 0 ) {
435
-      $left = $right = $diff / 2;
436
-      $style->margin_left = "$left pt";
437
-      $style->margin_right = "$right pt";
434
+        $left = $right = $diff / 2;
435
+        $style->margin_left = "$left pt";
436
+        $style->margin_right = "$right pt";
438 437
 
439 438
     } else {
440 439
         if($left === "auto") {
441
-          $left = $style->length_in_pt($cb["w"] - $right - $width, $cb["w"]);
440
+            $left = $style->length_in_pt($cb["w"] - $right - $width, $cb["w"]);
442 441
         }
443 442
         if($right === "auto") {
444
-          $left = $style->length_in_pt($left, $cb["w"]);
443
+            $left = $style->length_in_pt($left, $cb["w"]);
445 444
         }
446 445
     }
447 446
 
@@ -450,15 +449,15 @@  discard block
 block discarded – undo
450 449
 
451 450
     // Determine the content edge
452 451
     $content_x = $x + $left + $style->length_in_pt(array($style->padding_left,
453
-                                                         $style->border_left_width), $cb["w"]);
452
+                                                            $style->border_left_width), $cb["w"]);
454 453
     $content_y = $y + $style->length_in_pt(array($style->margin_top,
455
-                                                 $style->border_top_width,
456
-                                                 $style->padding_top), $cb["w"]);
454
+                                                    $style->border_top_width,
455
+                                                    $style->padding_top), $cb["w"]);
457 456
 
458 457
     if ( isset($cb["h"]) )
459
-      $h = $cb["h"];
458
+        $h = $cb["h"];
460 459
     else
461
-      $h = null;
460
+        $h = null;
462 461
 
463 462
 
464 463
     $cellmap = $this->_frame->get_cellmap();
@@ -473,14 +472,14 @@  discard block
 block discarded – undo
473 472
     // Set the containing block of each child & reflow
474 473
     foreach ( $this->_frame->get_children() as $child ) {
475 474
 
476
-      // Bail if the page is full
477
-      if ( !$page->in_nested_table() && $page->is_full() )
475
+        // Bail if the page is full
476
+        if ( !$page->in_nested_table() && $page->is_full() )
478 477
         break;
479 478
 
480
-      $child->set_containing_block($content_x, $content_y, $width, $h);
481
-      $child->reflow();
479
+        $child->set_containing_block($content_x, $content_y, $width, $h);
480
+        $child->reflow();
482 481
 
483
-      if ( !$page->in_nested_table() )
482
+        if ( !$page->in_nested_table() )
484 483
         // Check if a split has occured
485 484
         $page->check_page_break($child);
486 485
 
@@ -490,22 +489,22 @@  discard block
 block discarded – undo
490 489
     $style->height = $this->_calculate_height();
491 490
 
492 491
     if ( $style->border_collapse === "collapse" ) {
493
-      // Unset our borders because our cells are now using them
494
-      $style->border_style = "none";
492
+        // Unset our borders because our cells are now using them
493
+        $style->border_style = "none";
495 494
     }
496 495
 
497 496
     $page->table_reflow_end();
498 497
 
499 498
     // Debugging:
500 499
     //echo ($this->_frame->get_cellmap());
501
-  }
500
+    }
502 501
 
503
-  //........................................................................
502
+    //........................................................................
504 503
 
505
-  function get_min_max_width() {
504
+    function get_min_max_width() {
506 505
 
507 506
     if ( !is_null($this->_min_max_cache)  )
508
-      return $this->_min_max_cache;
507
+        return $this->_min_max_cache;
509 508
 
510 509
     $style = $this->_frame->get_style();
511 510
 
@@ -531,33 +530,33 @@  discard block
 block discarded – undo
531 530
 
532 531
     $columns =& $this->_frame->get_cellmap()->get_columns();
533 532
     foreach (array_keys($columns) as $i) {
534
-      $this->_state["min_width"] += $columns[$i]["min-width"];
535
-      $this->_state["max_width"] += $columns[$i]["max-width"];
533
+        $this->_state["min_width"] += $columns[$i]["min-width"];
534
+        $this->_state["max_width"] += $columns[$i]["max-width"];
536 535
 
537
-      if ( $columns[$i]["absolute"] > 0 ) {
536
+        if ( $columns[$i]["absolute"] > 0 ) {
538 537
         $this->_state["absolute"][] = $i;
539 538
         $this->_state["absolute_used"] += $columns[$i]["absolute"];
540 539
 
541
-      } else if ( $columns[$i]["percent"] > 0 ) {
540
+        } else if ( $columns[$i]["percent"] > 0 ) {
542 541
         $this->_state["percent"][] = $i;
543 542
         $this->_state["percent_used"] += $columns[$i]["percent"];
544 543
 
545
-      } else {
544
+        } else {
546 545
         $this->_state["auto"][] = $i;
547 546
         $this->_state["auto_min"] += $columns[$i]["min-width"];
548
-      }
547
+        }
549 548
     }
550 549
 
551 550
     // Account for margins & padding
552 551
     $dims = array($style->border_left_width,
553
-                  $style->border_right_width,
554
-                  $style->padding_left,
555
-                  $style->padding_right,
556
-                  $style->margin_left,
557
-                  $style->margin_right);
552
+                    $style->border_right_width,
553
+                    $style->padding_left,
554
+                    $style->padding_right,
555
+                    $style->margin_left,
556
+                    $style->margin_right);
558 557
 
559 558
     if ( $style->border_collapse !== "collapse" ) 
560
-      list($dims[]) = $style->border_spacing;
559
+        list($dims[]) = $style->border_spacing;
561 560
 
562 561
     $delta = $style->length_in_pt($dims, $this->_frame->get_containing_block("w"));
563 562
 
@@ -565,6 +564,6 @@  discard block
 block discarded – undo
565 564
     $this->_state["max_width"] += $delta;
566 565
 
567 566
     return $this->_min_max_cache = array($this->_state["min_width"], $this->_state["max_width"],
568
-                 "min" => $this->_state["min_width"], "max" => $this->_state["max_width"]);
569
-  }
567
+                    "min" => $this->_state["min_width"], "max" => $this->_state["max_width"]);
568
+    }
570 569
 }
Please login to merge, or discard this patch.
main/inc/lib/phpdocx/pdf/lib/class.pdf.php 1 patch
Indentation   +2039 added lines, -2039 removed lines patch added patch discarded remove patch
@@ -1,324 +1,324 @@  discard block
 block discarded – undo
1 1
 <?php
2
-  /**
3
-   * Cpdf
4
-   *
5
-   * http://www.ros.co.nz/pdf
6
-   *
7
-   * A PHP class to provide the basic functionality to create a pdf document without
8
-   * any requirement for additional modules.
9
-   *
10
-   * Note that the companion class CezPdf can be used to extend this class and dramatically
11
-   * simplify the creation of documents.
12
-   *
13
-   * Extended by Orion Richardson to support Unicode / UTF-8 characters using
14
-   * TCPDF and others as a guide.
15
-   *
16
-   * IMPORTANT NOTE
17
-   * there is no warranty, implied or otherwise with this software.
18
-   *
19
-   * LICENCE
20
-   * This code has been placed in the Public Domain for all to enjoy.
21
-   *
22
-   * @author       Wayne Munro <[email protected]>
23
-   * @contributor  Orion Richardson <[email protected]>
24
-   * @contributor  Helmut Tischer <[email protected]>
25
-   * @contributor  Ryan H. Masten <[email protected]>
26
-   * @version  009
27
-   * @package  Cpdf
28
-   *
29
-   * Changes
30
-   * @contributor Helmut Tischer <[email protected]>
31
-   * @version 0.5.1.htischer.20090507
32
-   * - On multiple identical png and jpg images, put only one copy into the pdf file and refer to it.
33
-   *   This reduces file size and rendering time.
34
-   * - Allow font metrics cache to be a different folder as the font metrics. This allows a read only installation.
35
-   * - Allow adding images directly from a gd object. This increases performance by avoiding temporary files.
36
-   * - On png image files remove alpa channel to allow display of typical png files in pdf.
37
-   * - On addImage avoid temporary file. Todo: Duplicate Image (currently not used)
38
-   * - Add a check function, whether image is already cached, This avoids double creation by caller which saves
39
-   *   CPU time and memory.
40
-   * @contributor Helmut Tischer <[email protected]>
41
-   * @version dompdf_trunk_with_helmut_mods.20090524
42
-   * - Allow temp and fontcache folders to be passed in by class creator
43
-   * @version dompdf_trunk_with_helmut_mods.20090528
44
-   * - typo 'decent' instead of 'descent' at various locations made getFontDescender worthless
45
-   */
2
+    /**
3
+     * Cpdf
4
+     *
5
+     * http://www.ros.co.nz/pdf
6
+     *
7
+     * A PHP class to provide the basic functionality to create a pdf document without
8
+     * any requirement for additional modules.
9
+     *
10
+     * Note that the companion class CezPdf can be used to extend this class and dramatically
11
+     * simplify the creation of documents.
12
+     *
13
+     * Extended by Orion Richardson to support Unicode / UTF-8 characters using
14
+     * TCPDF and others as a guide.
15
+     *
16
+     * IMPORTANT NOTE
17
+     * there is no warranty, implied or otherwise with this software.
18
+     *
19
+     * LICENCE
20
+     * This code has been placed in the Public Domain for all to enjoy.
21
+     *
22
+     * @author       Wayne Munro <[email protected]>
23
+     * @contributor  Orion Richardson <[email protected]>
24
+     * @contributor  Helmut Tischer <[email protected]>
25
+     * @contributor  Ryan H. Masten <[email protected]>
26
+     * @version  009
27
+     * @package  Cpdf
28
+     *
29
+     * Changes
30
+     * @contributor Helmut Tischer <[email protected]>
31
+     * @version 0.5.1.htischer.20090507
32
+     * - On multiple identical png and jpg images, put only one copy into the pdf file and refer to it.
33
+     *   This reduces file size and rendering time.
34
+     * - Allow font metrics cache to be a different folder as the font metrics. This allows a read only installation.
35
+     * - Allow adding images directly from a gd object. This increases performance by avoiding temporary files.
36
+     * - On png image files remove alpa channel to allow display of typical png files in pdf.
37
+     * - On addImage avoid temporary file. Todo: Duplicate Image (currently not used)
38
+     * - Add a check function, whether image is already cached, This avoids double creation by caller which saves
39
+     *   CPU time and memory.
40
+     * @contributor Helmut Tischer <[email protected]>
41
+     * @version dompdf_trunk_with_helmut_mods.20090524
42
+     * - Allow temp and fontcache folders to be passed in by class creator
43
+     * @version dompdf_trunk_with_helmut_mods.20090528
44
+     * - typo 'decent' instead of 'descent' at various locations made getFontDescender worthless
45
+     */
46 46
 
47 47
 /* $Id: class.pdf.php 217 2010-03-11 23:03:57Z ryan.masten $ */
48 48
 
49 49
 class  Cpdf {
50 50
 
51 51
 
52
-  /**
53
-   * the current number of pdf objects in the document
54
-   */
55
-  public  $numObj = 0;
52
+    /**
53
+     * the current number of pdf objects in the document
54
+     */
55
+    public  $numObj = 0;
56 56
 
57
-  /**
58
-   * this array contains all of the pdf objects, ready for final assembly
59
-   */
60
-  public  $objects =  array();
57
+    /**
58
+     * this array contains all of the pdf objects, ready for final assembly
59
+     */
60
+    public  $objects =  array();
61 61
 
62
-  /**
63
-   * the objectId (number within the objects array) of the document catalog
64
-   */
65
-  public  $catalogId;
62
+    /**
63
+     * the objectId (number within the objects array) of the document catalog
64
+     */
65
+    public  $catalogId;
66 66
 
67
-  /**
68
-   * array carrying information about the fonts that the system currently knows about
69
-   * used to ensure that a font is not loaded twice, among other things
70
-   */
71
-  public  $fonts = array();
67
+    /**
68
+     * array carrying information about the fonts that the system currently knows about
69
+     * used to ensure that a font is not loaded twice, among other things
70
+     */
71
+    public  $fonts = array();
72 72
   
73
-  /**
74
-   * the default font metrics file to use if no other font has been loaded
75
-   * the path to the directory containing the font metrics should be included
76
-   */
77
-  public  $defaultFont = './fonts/Helvetica.afm';
73
+    /**
74
+     * the default font metrics file to use if no other font has been loaded
75
+     * the path to the directory containing the font metrics should be included
76
+     */
77
+    public  $defaultFont = './fonts/Helvetica.afm';
78 78
   
79
-  /**
80
-   * a record of the current font
81
-   */
82
-  public  $currentFont = '';
79
+    /**
80
+     * a record of the current font
81
+     */
82
+    public  $currentFont = '';
83 83
 
84
-  /**
85
-   * the current base font
86
-   */
87
-  public  $currentBaseFont = '';
84
+    /**
85
+     * the current base font
86
+     */
87
+    public  $currentBaseFont = '';
88 88
 
89
-  /**
90
-   * the number of the current font within the font array
91
-   */
92
-  public  $currentFontNum = 0;
89
+    /**
90
+     * the number of the current font within the font array
91
+     */
92
+    public  $currentFontNum = 0;
93 93
 
94
-  /**
95
-   *
96
-   */
97
-  public  $currentNode;
94
+    /**
95
+     *
96
+     */
97
+    public  $currentNode;
98 98
 
99
-  /**
100
-   * object number of the current page
101
-   */
102
-  public  $currentPage;
99
+    /**
100
+     * object number of the current page
101
+     */
102
+    public  $currentPage;
103 103
 
104
-  /**
105
-   * object number of the currently active contents block
106
-   */
107
-  public  $currentContents;
104
+    /**
105
+     * object number of the currently active contents block
106
+     */
107
+    public  $currentContents;
108 108
 
109
-  /**
110
-   * number of fonts within the system
111
-   */
112
-  public  $numFonts = 0;
109
+    /**
110
+     * number of fonts within the system
111
+     */
112
+    public  $numFonts = 0;
113 113
 
114
-  /**
115
-   * Number of graphic state resources used
116
-   */
117
-  private  $numStates =  0;
114
+    /**
115
+     * Number of graphic state resources used
116
+     */
117
+    private  $numStates =  0;
118 118
 
119 119
 
120
-  /**
121
-   * current colour for fill operations, defaults to inactive value, all three components should be between 0 and 1 inclusive when active
122
-   */
123
-  public  $currentColour = array('r'=>-1, 'g'=>-1, 'b'=>-1);
120
+    /**
121
+     * current colour for fill operations, defaults to inactive value, all three components should be between 0 and 1 inclusive when active
122
+     */
123
+    public  $currentColour = array('r'=>-1, 'g'=>-1, 'b'=>-1);
124 124
 
125
-  /**
126
-   * current colour for stroke operations (lines etc.)
127
-   */
128
-  public  $currentStrokeColour = array('r'=>-1, 'g'=>-1, 'b'=>-1);
125
+    /**
126
+     * current colour for stroke operations (lines etc.)
127
+     */
128
+    public  $currentStrokeColour = array('r'=>-1, 'g'=>-1, 'b'=>-1);
129 129
 
130
-  /**
131
-   * current style that lines are drawn in
132
-   */
133
-  public  $currentLineStyle = '';
130
+    /**
131
+     * current style that lines are drawn in
132
+     */
133
+    public  $currentLineStyle = '';
134 134
 
135
-  /**
136
-   * current line transparency (partial graphics state)
137
-   */
138
-  public $currentLineTransparency = array("mode" => "Normal", "opacity" => 1.0);
135
+    /**
136
+     * current line transparency (partial graphics state)
137
+     */
138
+    public $currentLineTransparency = array("mode" => "Normal", "opacity" => 1.0);
139 139
   
140
-  /**
141
-   * current fill transparency (partial graphics state)
142
-   */
143
-  public $currentFillTransparency = array("mode" => "Normal", "opacity" => 1.0);
140
+    /**
141
+     * current fill transparency (partial graphics state)
142
+     */
143
+    public $currentFillTransparency = array("mode" => "Normal", "opacity" => 1.0);
144 144
   
145
-  /**
146
-   * an array which is used to save the state of the document, mainly the colours and styles
147
-   * it is used to temporarily change to another state, the change back to what it was before
148
-   */
149
-  public  $stateStack =  array();
145
+    /**
146
+     * an array which is used to save the state of the document, mainly the colours and styles
147
+     * it is used to temporarily change to another state, the change back to what it was before
148
+     */
149
+    public  $stateStack =  array();
150 150
 
151
-  /**
152
-   * number of elements within the state stack
153
-   */
154
-  public  $nStateStack =  0;
151
+    /**
152
+     * number of elements within the state stack
153
+     */
154
+    public  $nStateStack =  0;
155 155
 
156
-  /**
157
-   * number of page objects within the document
158
-   */
159
-  public  $numPages = 0;
156
+    /**
157
+     * number of page objects within the document
158
+     */
159
+    public  $numPages = 0;
160 160
 
161
-  /**
162
-   * object Id storage stack
163
-   */
164
-  public  $stack = array();
161
+    /**
162
+     * object Id storage stack
163
+     */
164
+    public  $stack = array();
165 165
 
166
-  /**
167
-   * number of elements within the object Id storage stack
168
-   */
169
-  public  $nStack = 0;
166
+    /**
167
+     * number of elements within the object Id storage stack
168
+     */
169
+    public  $nStack = 0;
170 170
 
171
-  /**
172
-   * an array which contains information about the objects which are not firmly attached to pages
173
-   * these have been added with the addObject function
174
-   */
175
-  public  $looseObjects = array();
171
+    /**
172
+     * an array which contains information about the objects which are not firmly attached to pages
173
+     * these have been added with the addObject function
174
+     */
175
+    public  $looseObjects = array();
176 176
 
177
-  /**
178
-   * array contains infomation about how the loose objects are to be added to the document
179
-   */
180
-  public  $addLooseObjects = array();
177
+    /**
178
+     * array contains infomation about how the loose objects are to be added to the document
179
+     */
180
+    public  $addLooseObjects = array();
181 181
 
182
-  /**
183
-   * the objectId of the information object for the document
184
-   * this contains authorship, title etc.
185
-   */
186
-  public  $infoObject = 0;
182
+    /**
183
+     * the objectId of the information object for the document
184
+     * this contains authorship, title etc.
185
+     */
186
+    public  $infoObject = 0;
187 187
 
188
-  /**
189
-   * number of images being tracked within the document
190
-   */
191
-  public  $numImages = 0;
188
+    /**
189
+     * number of images being tracked within the document
190
+     */
191
+    public  $numImages = 0;
192 192
 
193
-  /**
194
-   * an array containing options about the document
195
-   * it defaults to turning on the compression of the objects
196
-   */
197
-  public  $options = array('compression'=>1);
193
+    /**
194
+     * an array containing options about the document
195
+     * it defaults to turning on the compression of the objects
196
+     */
197
+    public  $options = array('compression'=>1);
198 198
 
199
-  /**
200
-   * the objectId of the first page of the document
201
-   */
202
-  public  $firstPageId;
199
+    /**
200
+     * the objectId of the first page of the document
201
+     */
202
+    public  $firstPageId;
203 203
 
204
-  /**
205
-   * used to track the last used value of the inter-word spacing, this is so that it is known
206
-   * when the spacing is changed.
207
-   */
208
-  public  $wordSpaceAdjust = 0;
204
+    /**
205
+     * used to track the last used value of the inter-word spacing, this is so that it is known
206
+     * when the spacing is changed.
207
+     */
208
+    public  $wordSpaceAdjust = 0;
209 209
 
210
-  /**
211
-   * the object Id of the procset object
212
-   */
213
-  public  $procsetObjectId;
210
+    /**
211
+     * the object Id of the procset object
212
+     */
213
+    public  $procsetObjectId;
214 214
 
215
-  /**
216
-   * store the information about the relationship between font families
217
-   * this used so that the code knows which font is the bold version of another font, etc.
218
-   * the value of this array is initialised in the constuctor function.
219
-   */
220
-  public  $fontFamilies =  array();
215
+    /**
216
+     * store the information about the relationship between font families
217
+     * this used so that the code knows which font is the bold version of another font, etc.
218
+     * the value of this array is initialised in the constuctor function.
219
+     */
220
+    public  $fontFamilies =  array();
221 221
  
222
-  /**
223
-   * folder for php serialized formats of font metrics files.
224
-   * If empty string, use same folder as original metrics files.
225
-   * This can be passed in from class creator.
226
-   * If this folder does not exist or is not writable, Cpdf will be **much** slower.
227
-   * Because of potential trouble with php safe mode, folder cannot be created at runtime.
228
-   */
229
-  public  $fontcache = '';
222
+    /**
223
+     * folder for php serialized formats of font metrics files.
224
+     * If empty string, use same folder as original metrics files.
225
+     * This can be passed in from class creator.
226
+     * If this folder does not exist or is not writable, Cpdf will be **much** slower.
227
+     * Because of potential trouble with php safe mode, folder cannot be created at runtime.
228
+     */
229
+    public  $fontcache = '';
230 230
   
231
-  /**
232
-   * The version of the font metrics cache file.
233
-   * This value must be manually incremented whenever the internal font data structure is modified.
234
-   */
235
-  public  $fontcacheVersion = 2;
231
+    /**
232
+     * The version of the font metrics cache file.
233
+     * This value must be manually incremented whenever the internal font data structure is modified.
234
+     */
235
+    public  $fontcacheVersion = 2;
236 236
 
237
-  /**
238
-   * temporary folder.
239
-   * If empty string, will attempty system tmp folder.
240
-   * This can be passed in from class creator.
241
-   * Only used for conversion of gd images to jpeg images.
242
-   */
243
-  public  $tmp = '';
237
+    /**
238
+     * temporary folder.
239
+     * If empty string, will attempty system tmp folder.
240
+     * This can be passed in from class creator.
241
+     * Only used for conversion of gd images to jpeg images.
242
+     */
243
+    public  $tmp = '';
244 244
 
245
-  /**
246
-   * track if the current font is bolded or italicised
247
-   */
248
-  public  $currentTextState =  '';
245
+    /**
246
+     * track if the current font is bolded or italicised
247
+     */
248
+    public  $currentTextState =  '';
249 249
 
250
-  /**
251
-   * messages are stored here during processing, these can be selected afterwards to give some useful debug information
252
-   */
253
-  public  $messages = '';
250
+    /**
251
+     * messages are stored here during processing, these can be selected afterwards to give some useful debug information
252
+     */
253
+    public  $messages = '';
254 254
 
255
-  /**
256
-   * the ancryption array for the document encryption is stored here
257
-   */
258
-  public  $arc4 = '';
255
+    /**
256
+     * the ancryption array for the document encryption is stored here
257
+     */
258
+    public  $arc4 = '';
259 259
 
260
-  /**
261
-   * the object Id of the encryption information
262
-   */
263
-  public  $arc4_objnum = 0;
260
+    /**
261
+     * the object Id of the encryption information
262
+     */
263
+    public  $arc4_objnum = 0;
264 264
 
265
-  /**
266
-   * the file identifier, used to uniquely identify a pdf document
267
-   */
268
-  public  $fileIdentifier = '';
265
+    /**
266
+     * the file identifier, used to uniquely identify a pdf document
267
+     */
268
+    public  $fileIdentifier = '';
269 269
 
270
-  /**
271
-   * a flag to say if a document is to be encrypted or not
272
-   */
273
-  public  $encrypted = 0;
270
+    /**
271
+     * a flag to say if a document is to be encrypted or not
272
+     */
273
+    public  $encrypted = 0;
274 274
 
275
-  /**
276
-   * the ancryption key for the encryption of all the document content (structure is not encrypted)
277
-   */
278
-  public  $encryptionKey = '';
275
+    /**
276
+     * the ancryption key for the encryption of all the document content (structure is not encrypted)
277
+     */
278
+    public  $encryptionKey = '';
279 279
 
280
-  /**
281
-   * array which forms a stack to keep track of nested callback functions
282
-   */
283
-  public  $callback =  array();
280
+    /**
281
+     * array which forms a stack to keep track of nested callback functions
282
+     */
283
+    public  $callback =  array();
284 284
 
285
-  /**
286
-   * the number of callback functions in the callback array
287
-   */
288
-  public  $nCallback =  0;
285
+    /**
286
+     * the number of callback functions in the callback array
287
+     */
288
+    public  $nCallback =  0;
289 289
 
290
-  /**
291
-   * store label->id pairs for named destinations, these will be used to replace internal links
292
-   * done this way so that destinations can be defined after the location that links to them
293
-   */
294
-  public  $destinations =  array();
290
+    /**
291
+     * store label->id pairs for named destinations, these will be used to replace internal links
292
+     * done this way so that destinations can be defined after the location that links to them
293
+     */
294
+    public  $destinations =  array();
295 295
 
296
-  /**
297
-   * store the stack for the transaction commands, each item in here is a record of the values of all the
298
-   * publiciables within the class, so that the user can rollback at will (from each 'start' command)
299
-   * note that this includes the objects array, so these can be large.
300
-   */
301
-  public  $checkpoint =  '';
296
+    /**
297
+     * store the stack for the transaction commands, each item in here is a record of the values of all the
298
+     * publiciables within the class, so that the user can rollback at will (from each 'start' command)
299
+     * note that this includes the objects array, so these can be large.
300
+     */
301
+    public  $checkpoint =  '';
302 302
 
303
-  /* Table of Image origin filenames and image labels which were already added with o_image().
303
+    /* Table of Image origin filenames and image labels which were already added with o_image().
304 304
    * Allows to merge identical images
305 305
    */
306
-  public  $imagelist = array();
306
+    public  $imagelist = array();
307 307
 
308
-  /**
309
-   * whether the text passed in should be treated as Unicode or just local character set.
310
-   */
311
-  public  $isUnicode = false;
308
+    /**
309
+     * whether the text passed in should be treated as Unicode or just local character set.
310
+     */
311
+    public  $isUnicode = false;
312 312
   
313
-  public  $javascript = '';
313
+    public  $javascript = '';
314 314
 
315
-  /**
316
-   * class constructor
317
-   * this will start a new document
318
-   * @var array array of 4 numbers, defining the bottom left and upper right corner of the page. first two are normally zero.
319
-   * @var boolean whether text will be treated as Unicode or not.
320
-   */
321
-  function  Cpdf ($pageSize = array(0, 0, 612, 792), $isUnicode = false, $fontcache = '', $tmp = '') {
315
+    /**
316
+     * class constructor
317
+     * this will start a new document
318
+     * @var array array of 4 numbers, defining the bottom left and upper right corner of the page. first two are normally zero.
319
+     * @var boolean whether text will be treated as Unicode or not.
320
+     */
321
+    function  Cpdf ($pageSize = array(0, 0, 612, 792), $isUnicode = false, $fontcache = '', $tmp = '') {
322 322
     $this->isUnicode = $isUnicode;
323 323
     $this->fontcache = $fontcache;
324 324
     $this->tmp = $tmp;
@@ -327,73 +327,73 @@  discard block
 block discarded – undo
327 327
     // also initialize the font families that are known about already
328 328
     $this->setFontFamily('init');
329 329
     //  $this->fileIdentifier = md5('xxxxxxxx'.time());
330
-  }
331
-
332
-
333
-  /**
334
-   * Document object methods (internal use only)
335
-   *
336
-   * There is about one object method for each type of object in the pdf document
337
-   * Each function has the same call list ($id,$action,$options).
338
-   * $id = the object ID of the object, or what it is to be if it is being created
339
-   * $action = a string specifying the action to be performed, though ALL must support:
340
-   *           'new' - create the object with the id $id
341
-   *           'out' - produce the output for the pdf object
342
-   * $options = optional, a string or array containing the various parameters for the object
343
-   *
344
-   * These, in conjunction with the output function are the ONLY way for output to be produced
345
-   * within the pdf 'file'.
346
-   */
330
+    }
347 331
 
348
-  /**
349
-   *destination object, used to specify the location for the user to jump to, presently on opening
350
-   */
351
-  protected function  o_destination($id, $action, $options = '') {
332
+
333
+    /**
334
+     * Document object methods (internal use only)
335
+     *
336
+     * There is about one object method for each type of object in the pdf document
337
+     * Each function has the same call list ($id,$action,$options).
338
+     * $id = the object ID of the object, or what it is to be if it is being created
339
+     * $action = a string specifying the action to be performed, though ALL must support:
340
+     *           'new' - create the object with the id $id
341
+     *           'out' - produce the output for the pdf object
342
+     * $options = optional, a string or array containing the various parameters for the object
343
+     *
344
+     * These, in conjunction with the output function are the ONLY way for output to be produced
345
+     * within the pdf 'file'.
346
+     */
347
+
348
+    /**
349
+     *destination object, used to specify the location for the user to jump to, presently on opening
350
+     */
351
+    protected function  o_destination($id, $action, $options = '') {
352 352
     if  ($action !== 'new') {
353
-      $o = & $this->objects[$id];
353
+        $o = & $this->objects[$id];
354 354
     }
355 355
 
356 356
     switch ($action) {
357 357
     case  'new':
358 358
       $this->objects[$id] = array('t'=>'destination', 'info'=>array());
359
-      $tmp =  '';
360
-      switch  ($options['type']) {
361
-      case  'XYZ':
359
+        $tmp =  '';
360
+        switch  ($options['type']) {
361
+        case  'XYZ':
362 362
       case  'FitR':
363 363
         $tmp =   ' '.$options['p3'].$tmp;
364
-      case  'FitH':
364
+        case  'FitH':
365 365
       case  'FitV':
366 366
       case  'FitBH':
367 367
       case  'FitBV':
368 368
         $tmp =   ' '.$options['p1'].' '.$options['p2'].$tmp;
369
-      case  'Fit':
369
+        case  'Fit':
370 370
       case  'FitB':
371 371
         $tmp =   $options['type'].$tmp;
372 372
         $this->objects[$id]['info']['string'] = $tmp;
373 373
         $this->objects[$id]['info']['page'] = $options['page'];
374
-      }
375
-      break;
374
+        }
375
+        break;
376 376
 
377 377
     case  'out':
378 378
       $tmp =  $o['info'];
379
-      $res = "\n".$id." 0 obj\n".'['.$tmp['page'].' 0 R /'.$tmp['string']."]\nendobj";
380
-      return  $res;
379
+        $res = "\n".$id." 0 obj\n".'['.$tmp['page'].' 0 R /'.$tmp['string']."]\nendobj";
380
+        return  $res;
381
+    }
381 382
     }
382
-  }
383 383
 
384 384
 
385
-  /**
386
-   * set the viewer preferences
387
-   */
388
-  protected function  o_viewerPreferences($id, $action, $options = '') {
385
+    /**
386
+     * set the viewer preferences
387
+     */
388
+    protected function  o_viewerPreferences($id, $action, $options = '') {
389 389
     if  ($action !== 'new') {
390
-      $o = & $this->objects[$id];
390
+        $o = & $this->objects[$id];
391 391
     }
392 392
 
393 393
     switch  ($action) {
394 394
     case  'new':
395 395
       $this->objects[$id] = array('t'=>'viewerPreferences', 'info'=>array());
396
-      break;
396
+        break;
397 397
 
398 398
     case  'add':
399 399
       foreach($options as  $k=>$v) {
@@ -406,167 +406,167 @@  discard block
 block discarded – undo
406 406
         case  'NonFullScreenPageMode':
407 407
         case  'Direction':
408 408
           $o['info'][$k] = $v;
409
-          break;
409
+            break;
410
+        }
410 411
         }
411
-      }
412
-      break;
412
+        break;
413 413
 
414 414
     case  'out':
415 415
       $res = "\n".$id." 0 obj\n".'<< ';
416
-      foreach($o['info'] as  $k=>$v) {
416
+        foreach($o['info'] as  $k=>$v) {
417 417
         $res.= "\n/".$k.' '.$v;
418
-      }
419
-      $res.= "\n>>\n";
420
-      return  $res;
418
+        }
419
+        $res.= "\n>>\n";
420
+        return  $res;
421
+    }
421 422
     }
422
-  }
423 423
 
424 424
 
425
-  /**
426
-   * define the document catalog, the overall controller for the document
427
-   */
428
-  protected function  o_catalog($id, $action, $options = '') {
425
+    /**
426
+     * define the document catalog, the overall controller for the document
427
+     */
428
+    protected function  o_catalog($id, $action, $options = '') {
429 429
     if  ($action !== 'new') {
430
-      $o = & $this->objects[$id];
430
+        $o = & $this->objects[$id];
431 431
     }
432 432
 
433 433
     switch  ($action) {
434 434
     case  'new':
435 435
       $this->objects[$id] = array('t'=>'catalog', 'info'=>array());
436
-      $this->catalogId = $id;
437
-      break;
436
+        $this->catalogId = $id;
437
+        break;
438 438
 
439 439
     case  'outlines':
440 440
     case  'pages':
441 441
     case  'openHere':
442 442
     case  'javascript':
443 443
       $o['info'][$action] = $options;
444
-      break;
444
+        break;
445 445
 
446 446
     case  'viewerPreferences':
447 447
       if  (!isset($o['info']['viewerPreferences'])) {
448 448
         $this->numObj++;
449 449
         $this->o_viewerPreferences($this->numObj, 'new');
450 450
         $o['info']['viewerPreferences'] = $this->numObj;
451
-      }
451
+        }
452 452
 
453
-      $vp =  $o['info']['viewerPreferences'];
454
-      $this->o_viewerPreferences($vp, 'add', $options);
453
+        $vp =  $o['info']['viewerPreferences'];
454
+        $this->o_viewerPreferences($vp, 'add', $options);
455 455
 
456
-      break;
456
+        break;
457 457
 
458 458
     case  'out':
459 459
       $res = "\n".$id." 0 obj\n".'<< /Type /Catalog';
460 460
 
461
-      foreach($o['info'] as  $k=>$v) {
461
+        foreach($o['info'] as  $k=>$v) {
462 462
         switch ($k) {
463 463
         case  'outlines':
464 464
           $res.= "\n".'/Outlines '.$v.' 0 R';
465
-          break;
465
+            break;
466 466
           
467 467
         case  'pages':
468 468
           $res.= "\n".'/Pages '.$v.' 0 R';
469
-          break;
469
+            break;
470 470
 
471 471
         case  'viewerPreferences':
472 472
           $res.= "\n".'/ViewerPreferences '.$v.' 0 R';
473
-          break;
473
+            break;
474 474
 
475 475
         case  'openHere':
476 476
           $res.= "\n".'/OpenAction '.$v.' 0 R';
477
-          break;
477
+            break;
478 478
 
479 479
         case  'javascript':
480 480
           $res.= "\n".'/Names <</JavaScript '.$v.' 0 R>>';
481
-          break;
481
+            break;
482
+        }
482 483
         }
483
-      }
484 484
 
485
-      $res.= " >>\nendobj";
486
-      return  $res;
485
+        $res.= " >>\nendobj";
486
+        return  $res;
487
+    }
487 488
     }
488
-  }
489 489
 
490 490
 
491
-  /**
492
-   * object which is a parent to the pages in the document
493
-   */
494
-  protected function  o_pages($id, $action, $options = '') {
491
+    /**
492
+     * object which is a parent to the pages in the document
493
+     */
494
+    protected function  o_pages($id, $action, $options = '') {
495 495
     if  ($action !== 'new') {
496
-      $o = & $this->objects[$id];
496
+        $o = & $this->objects[$id];
497 497
     }
498 498
 
499 499
     switch  ($action) {
500 500
     case  'new':
501 501
       $this->objects[$id] = array('t'=>'pages', 'info'=>array());
502
-      $this->o_catalog($this->catalogId, 'pages', $id);
503
-      break;
502
+        $this->o_catalog($this->catalogId, 'pages', $id);
503
+        break;
504 504
 
505 505
     case  'page':
506 506
       if  (!is_array($options)) {
507 507
         // then it will just be the id of the new page
508 508
         $o['info']['pages'][] = $options;
509
-      } else {
509
+        } else {
510 510
         // then it should be an array having 'id','rid','pos', where rid=the page to which this one will be placed relative
511 511
         // and pos is either 'before' or 'after', saying where this page will fit.
512 512
         if  (isset($options['id']) &&  isset($options['rid']) &&  isset($options['pos'])) {
513
-          $i =  array_search($options['rid'], $o['info']['pages']);
514
-          if  (isset($o['info']['pages'][$i]) &&  $o['info']['pages'][$i] == $options['rid']) {
513
+            $i =  array_search($options['rid'], $o['info']['pages']);
514
+            if  (isset($o['info']['pages'][$i]) &&  $o['info']['pages'][$i] == $options['rid']) {
515 515
 
516 516
             // then there is a match
517 517
             // make a space
518 518
             switch  ($options['pos']) {
519 519
             case  'before':
520 520
               $k =  $i;
521
-              break;
521
+                break;
522 522
 
523 523
             case  'after':
524 524
               $k = $i+1;
525
-              break;
525
+                break;
526 526
 
527 527
             default:
528 528
               $k = -1;
529
-              break;
529
+                break;
530 530
             }
531 531
 
532 532
             if  ($k >= 0) {
533
-              for  ($j = count($o['info']['pages']) -1;$j >= $k;$j--) {
533
+                for  ($j = count($o['info']['pages']) -1;$j >= $k;$j--) {
534 534
                 $o['info']['pages'][$j+1] = $o['info']['pages'][$j];
535
-              }
535
+                }
536 536
 
537
-              $o['info']['pages'][$k] = $options['id'];
537
+                $o['info']['pages'][$k] = $options['id'];
538
+            }
538 539
             }
539
-          }
540 540
         }
541
-      }
542
-      break;
541
+        }
542
+        break;
543 543
 
544 544
     case  'procset':
545 545
       $o['info']['procset'] = $options;
546
-      break;
546
+        break;
547 547
 
548 548
     case  'mediaBox':
549 549
       $o['info']['mediaBox'] = $options;
550
-      // which should be an array of 4 numbers
551
-      break;
550
+        // which should be an array of 4 numbers
551
+        break;
552 552
 
553 553
     case  'font':
554 554
       $o['info']['fonts'][] = array('objNum'=>$options['objNum'], 'fontNum'=>$options['fontNum']);
555
-      break;
555
+        break;
556 556
 
557 557
     case  'extGState':
558 558
       $o['info']['extGStates'][] =  array('objNum' => $options['objNum'],  'stateNum' => $options['stateNum']);
559
-      break;
559
+        break;
560 560
 
561 561
     case  'xObject':
562 562
       $o['info']['xObjects'][] = array('objNum'=>$options['objNum'], 'label'=>$options['label']);
563
-      break;
563
+        break;
564 564
 
565 565
     case  'out':
566 566
       if  (count($o['info']['pages'])) {
567 567
         $res = "\n".$id." 0 obj\n<< /Type /Pages\n/Kids [";
568 568
         foreach($o['info']['pages'] as  $k=>$v) {
569
-          $res.= $v." 0 R\n";
569
+            $res.= $v." 0 R\n";
570 570
         }
571 571
 
572 572
         $res.= "]\n/Count ".count($this->objects[$id]['info']['pages']);
@@ -574,129 +574,129 @@  discard block
 block discarded – undo
574 574
         if  ( (isset($o['info']['fonts']) &&  count($o['info']['fonts'])) ||
575 575
               isset($o['info']['procset']) ||
576 576
               (isset($o['info']['extGStates']) &&  count($o['info']['extGStates']))) {
577
-          $res.= "\n/Resources <<";
577
+            $res.= "\n/Resources <<";
578 578
 
579
-          if  (isset($o['info']['procset'])) {
579
+            if  (isset($o['info']['procset'])) {
580 580
             $res.= "\n/ProcSet ".$o['info']['procset']." 0 R";
581
-          }
581
+            }
582 582
 
583
-          if  (isset($o['info']['fonts']) &&  count($o['info']['fonts'])) {
583
+            if  (isset($o['info']['fonts']) &&  count($o['info']['fonts'])) {
584 584
             $res.= "\n/Font << ";
585 585
             foreach($o['info']['fonts'] as  $finfo) {
586
-              $res.= "\n/F".$finfo['fontNum']." ".$finfo['objNum']." 0 R";
586
+                $res.= "\n/F".$finfo['fontNum']." ".$finfo['objNum']." 0 R";
587 587
             }
588 588
             $res.= "\n>>";
589
-          }
589
+            }
590 590
 
591
-          if  (isset($o['info']['xObjects']) &&  count($o['info']['xObjects'])) {
591
+            if  (isset($o['info']['xObjects']) &&  count($o['info']['xObjects'])) {
592 592
             $res.= "\n/XObject << ";
593 593
             foreach($o['info']['xObjects'] as  $finfo) {
594
-              $res.= "\n/".$finfo['label']." ".$finfo['objNum']." 0 R";
594
+                $res.= "\n/".$finfo['label']." ".$finfo['objNum']." 0 R";
595 595
             }
596 596
             $res.= "\n>>";
597
-          }
597
+            }
598 598
 
599
-          if  ( isset($o['info']['extGStates']) &&  count($o['info']['extGStates'])) {
599
+            if  ( isset($o['info']['extGStates']) &&  count($o['info']['extGStates'])) {
600 600
             $res.=  "\n/ExtGState << ";
601 601
             foreach ($o['info']['extGStates'] as  $gstate) {
602
-              $res.=  "\n/GS" . $gstate['stateNum'] . " " . $gstate['objNum'] . " 0 R";
602
+                $res.=  "\n/GS" . $gstate['stateNum'] . " " . $gstate['objNum'] . " 0 R";
603 603
             }
604 604
             $res.=  "\n>>";
605
-          }
605
+            }
606 606
 
607
-          $res.= "\n>>";
608
-          if  (isset($o['info']['mediaBox'])) {
607
+            $res.= "\n>>";
608
+            if  (isset($o['info']['mediaBox'])) {
609 609
             $tmp = $o['info']['mediaBox'];
610 610
             $res.= "\n/MediaBox [".sprintf('%.3F', $tmp[0]) .' '.sprintf('%.3F', $tmp[1]) .' '.sprintf('%.3F', $tmp[2]) .' '.sprintf('%.3F', $tmp[3]) .']';
611
-          }
611
+            }
612 612
         }
613 613
 
614 614
         $res.= "\n >>\nendobj";
615
-      } else {
615
+        } else {
616 616
         $res = "\n".$id." 0 obj\n<< /Type /Pages\n/Count 0\n>>\nendobj";
617
-      }
617
+        }
618 618
 
619
-      return  $res;
619
+        return  $res;
620
+    }
620 621
     }
621
-  }
622 622
 
623 623
 
624
-  /**
625
-   * define the outlines in the doc, empty for now
626
-   */
627
-  protected function  o_outlines($id, $action, $options = '') {
624
+    /**
625
+     * define the outlines in the doc, empty for now
626
+     */
627
+    protected function  o_outlines($id, $action, $options = '') {
628 628
     if  ($action !== 'new') {
629
-      $o = & $this->objects[$id];
629
+        $o = & $this->objects[$id];
630 630
     }
631 631
 
632 632
     switch  ($action) {
633 633
     case  'new':
634 634
       $this->objects[$id] = array('t'=>'outlines', 'info'=>array('outlines'=>array()));
635
-      $this->o_catalog($this->catalogId, 'outlines', $id);
636
-      break;
635
+        $this->o_catalog($this->catalogId, 'outlines', $id);
636
+        break;
637 637
 
638 638
     case  'outline':
639 639
       $o['info']['outlines'][] = $options;
640
-      break;
640
+        break;
641 641
 
642 642
     case  'out':
643 643
       if  (count($o['info']['outlines'])) {
644 644
         $res = "\n".$id." 0 obj\n<< /Type /Outlines /Kids [";
645 645
         foreach($o['info']['outlines'] as  $k=>$v) {
646
-          $res.= $v." 0 R ";
646
+            $res.= $v." 0 R ";
647 647
         }
648 648
 
649 649
         $res.= "] /Count ".count($o['info']['outlines']) ." >>\nendobj";
650
-      } else {
650
+        } else {
651 651
         $res = "\n".$id." 0 obj\n<< /Type /Outlines /Count 0 >>\nendobj";
652
-      }
652
+        }
653 653
 
654
-      return  $res;
654
+        return  $res;
655
+    }
655 656
     }
656
-  }
657 657
 
658 658
 
659
-  /**
660
-   * an object to hold the font description
661
-   */
662
-  protected function  o_font($id, $action, $options = '') {
659
+    /**
660
+     * an object to hold the font description
661
+     */
662
+    protected function  o_font($id, $action, $options = '') {
663 663
     if  ($action !== 'new') {
664
-      $o = & $this->objects[$id];
664
+        $o = & $this->objects[$id];
665 665
     }
666 666
 
667 667
     switch  ($action) {
668 668
     case  'new':
669 669
       $this->objects[$id] =  array('t' => 'font', 'info' => array('name' => $options['name'], 'fontFileName' => $options['fontFileName'], 'SubType' => 'Type1'));
670
-      $fontNum =  $this->numFonts;
671
-      $this->objects[$id]['info']['fontNum'] =  $fontNum;
670
+        $fontNum =  $this->numFonts;
671
+        $this->objects[$id]['info']['fontNum'] =  $fontNum;
672 672
 
673
-      // deal with the encoding and the differences
674
-      if  (isset($options['differences'])) {
673
+        // deal with the encoding and the differences
674
+        if  (isset($options['differences'])) {
675 675
         // then we'll need an encoding dictionary
676 676
         $this->numObj++;
677 677
         $this->o_fontEncoding($this->numObj, 'new', $options);
678 678
         $this->objects[$id]['info']['encodingDictionary'] =  $this->numObj;
679
-      } else  if  (isset($options['encoding'])) {
679
+        } else  if  (isset($options['encoding'])) {
680 680
         // we can specify encoding here
681 681
         switch ($options['encoding']) {
682 682
         case  'WinAnsiEncoding':
683 683
         case  'MacRomanEncoding':
684 684
         case  'MacExpertEncoding':
685 685
           $this->objects[$id]['info']['encoding'] =  $options['encoding'];
686
-          break;
686
+            break;
687 687
 
688 688
         case  'none':
689 689
           break;
690 690
 
691 691
         default:
692 692
           $this->objects[$id]['info']['encoding'] =  'WinAnsiEncoding';
693
-          break;
693
+            break;
694 694
         }
695
-      } else {
695
+        } else {
696 696
         $this->objects[$id]['info']['encoding'] =  'WinAnsiEncoding';
697
-      }
697
+        }
698 698
 
699
-      if ($this->fonts[$options['fontFileName']]['isUnicode']) {
699
+        if ($this->fonts[$options['fontFileName']]['isUnicode']) {
700 700
         // For Unicode fonts, we need to incorporate font data into
701 701
         // sub-sections that are linked from the primary font section.
702 702
         // Look at o_fontGIDtoCID and o_fontDescendentCID functions
@@ -738,34 +738,34 @@  discard block
 block discarded – undo
738 738
         $cidFontId = ++$this->numObj;
739 739
         $this->o_fontDescendentCID($cidFontId, 'new', $options);
740 740
         $this->objects[$id]['info']['cidFont'] = $cidFontId;
741
-      }
741
+        }
742 742
       
743
-      // also tell the pages node about the new font
744
-      $this->o_pages($this->currentNode, 'font', array('fontNum' => $fontNum, 'objNum' => $id));
745
-      break;
743
+        // also tell the pages node about the new font
744
+        $this->o_pages($this->currentNode, 'font', array('fontNum' => $fontNum, 'objNum' => $id));
745
+        break;
746 746
 
747 747
     case  'add':
748 748
       foreach ($options as  $k => $v) {
749 749
         switch  ($k) {
750 750
         case  'BaseFont':
751 751
           $o['info']['name'] =  $v;
752
-          break;
752
+            break;
753 753
         case  'FirstChar':
754 754
         case  'LastChar':
755 755
         case  'Widths':
756 756
         case  'FontDescriptor':
757 757
         case  'SubType':
758 758
           $this->addMessage('o_font '.$k." : ".$v);
759
-          $o['info'][$k] =  $v;
760
-          break;
759
+            $o['info'][$k] =  $v;
760
+            break;
761
+        }
761 762
         }
762
-      }
763 763
 
764
-      // pass values down to descendent font
765
-      if (isset($o['info']['cidFont'])) {
764
+        // pass values down to descendent font
765
+        if (isset($o['info']['cidFont'])) {
766 766
         $this->o_fontDescendentCID($o['info']['cidFont'], 'add', $options);
767
-      }
768
-      break;
767
+        }
768
+        break;
769 769
 
770 770
     case  'out':
771 771
       if ($this->fonts[$this->objects[$id]['info']['fontFileName']]['isUnicode']) {
@@ -787,60 +787,60 @@  discard block
 block discarded – undo
787 787
         $res.=  "/ToUnicode ".$o['info']['toUnicode']." 0 R\n";
788 788
         $res.=  ">>\n";
789 789
         $res.=  "endobj";
790
-      } else {
791
-      $res =  "\n".$id." 0 obj\n<< /Type /Font\n/Subtype /".$o['info']['SubType']."\n";
792
-      $res.=  "/Name /F".$o['info']['fontNum']."\n";
793
-      $res.=  "/BaseFont /".$o['info']['name']."\n";
790
+        } else {
791
+        $res =  "\n".$id." 0 obj\n<< /Type /Font\n/Subtype /".$o['info']['SubType']."\n";
792
+        $res.=  "/Name /F".$o['info']['fontNum']."\n";
793
+        $res.=  "/BaseFont /".$o['info']['name']."\n";
794 794
 
795
-      if  (isset($o['info']['encodingDictionary'])) {
795
+        if  (isset($o['info']['encodingDictionary'])) {
796 796
         // then place a reference to the dictionary
797 797
         $res.=  "/Encoding ".$o['info']['encodingDictionary']." 0 R\n";
798
-      } else  if  (isset($o['info']['encoding'])) {
798
+        } else  if  (isset($o['info']['encoding'])) {
799 799
         // use the specified encoding
800 800
         $res.=  "/Encoding /".$o['info']['encoding']."\n";
801
-      }
801
+        }
802 802
 
803
-      if  (isset($o['info']['FirstChar'])) {
803
+        if  (isset($o['info']['FirstChar'])) {
804 804
         $res.=  "/FirstChar ".$o['info']['FirstChar']."\n";
805
-      }
805
+        }
806 806
 
807
-      if  (isset($o['info']['LastChar'])) {
807
+        if  (isset($o['info']['LastChar'])) {
808 808
         $res.=  "/LastChar ".$o['info']['LastChar']."\n";
809
-      }
809
+        }
810 810
 
811
-      if  (isset($o['info']['Widths'])) {
811
+        if  (isset($o['info']['Widths'])) {
812 812
         $res.=  "/Widths ".$o['info']['Widths']." 0 R\n";
813
-      }
813
+        }
814 814
 
815
-      if  (isset($o['info']['FontDescriptor'])) {
815
+        if  (isset($o['info']['FontDescriptor'])) {
816 816
         $res.=  "/FontDescriptor ".$o['info']['FontDescriptor']." 0 R\n";
817
-      }
817
+        }
818 818
 
819 819
         $res.=  ">>\n";
820 820
         $res.=  "endobj";
821
-      }
821
+        }
822 822
 
823
-      return  $res;
823
+        return  $res;
824
+    }
824 825
     }
825
-  }
826 826
 
827 827
 
828
-  /**
829
-   * a font descriptor, needed for including additional fonts
830
-   */
831
-  protected function  o_fontDescriptor($id, $action, $options = '') {
828
+    /**
829
+     * a font descriptor, needed for including additional fonts
830
+     */
831
+    protected function  o_fontDescriptor($id, $action, $options = '') {
832 832
     if  ($action !== 'new') {
833
-      $o = & $this->objects[$id];
833
+        $o = & $this->objects[$id];
834 834
     }
835 835
 
836 836
     switch  ($action) {
837 837
     case  'new':
838 838
       $this->objects[$id] = array('t'=>'fontDescriptor', 'info'=>$options);
839
-      break;
839
+        break;
840 840
 
841 841
     case  'out':
842 842
       $res = "\n".$id." 0 obj\n<< /Type /FontDescriptor\n";
843
-      foreach ($o['info'] as  $label => $value) {
843
+        foreach ($o['info'] as  $label => $value) {
844 844
         switch  ($label) {
845 845
         case  'Ascent':
846 846
         case  'CapHeight':
@@ -857,111 +857,111 @@  discard block
 block discarded – undo
857 857
         case  'CharSet':
858 858
           if  (mb_strlen($value, '8bit')) {
859 859
             $res.= '/'.$label.' '.$value."\n";
860
-          }
860
+            }
861 861
 
862
-          break;
862
+            break;
863 863
         case  'FontFile':
864 864
         case  'FontFile2':
865 865
         case  'FontFile3':
866 866
           $res.= '/'.$label.' '.$value." 0 R\n";
867
-          break;
867
+            break;
868 868
 
869 869
         case  'FontBBox':
870 870
           $res.= '/'.$label.' ['.$value[0].' '.$value[1].' '.$value[2].' '.$value[3]."]\n";
871
-          break;
871
+            break;
872 872
 
873 873
         case  'FontName':
874 874
           $res.= '/'.$label.' /'.$value."\n";
875
-          break;
875
+            break;
876
+        }
876 877
         }
877
-      }
878 878
 
879
-      $res.= ">>\nendobj";
879
+        $res.= ">>\nendobj";
880 880
 
881
-      return  $res;
881
+        return  $res;
882
+    }
882 883
     }
883
-  }
884 884
 
885 885
 
886
-  /**
887
-   * the font encoding
888
-   */
889
-  protected function  o_fontEncoding($id, $action, $options = '') {
886
+    /**
887
+     * the font encoding
888
+     */
889
+    protected function  o_fontEncoding($id, $action, $options = '') {
890 890
     if  ($action !== 'new') {
891
-      $o = & $this->objects[$id];
891
+        $o = & $this->objects[$id];
892 892
     }
893 893
 
894 894
     switch  ($action) {
895 895
     case  'new':
896 896
       // the options array should contain 'differences' and maybe 'encoding'
897 897
       $this->objects[$id] = array('t'=>'fontEncoding', 'info'=>$options);
898
-      break;
898
+        break;
899 899
 
900 900
     case  'out':
901 901
       $res = "\n".$id." 0 obj\n<< /Type /Encoding\n";
902
-      if  (!isset($o['info']['encoding'])) {
902
+        if  (!isset($o['info']['encoding'])) {
903 903
         $o['info']['encoding'] = 'WinAnsiEncoding';
904
-      }
904
+        }
905 905
 
906
-      if  ($o['info']['encoding'] !== 'none') {
906
+        if  ($o['info']['encoding'] !== 'none') {
907 907
         $res.= "/BaseEncoding /".$o['info']['encoding']."\n";
908
-      }
908
+        }
909 909
 
910
-      $res.= "/Differences \n[";
910
+        $res.= "/Differences \n[";
911 911
 
912
-      $onum = -100;
912
+        $onum = -100;
913 913
 
914
-      foreach($o['info']['differences'] as  $num=>$label) {
914
+        foreach($o['info']['differences'] as  $num=>$label) {
915 915
         if  ($num != $onum+1) {
916
-          // we cannot make use of consecutive numbering
917
-          $res.=  "\n".$num." /".$label;
916
+            // we cannot make use of consecutive numbering
917
+            $res.=  "\n".$num." /".$label;
918 918
         } else {
919
-          $res.=  " /".$label;
919
+            $res.=  " /".$label;
920 920
         }
921 921
 
922 922
         $onum = $num;
923
-      }
923
+        }
924 924
 
925
-      $res.= "\n]\n>>\nendobj";
926
-      return  $res;
925
+        $res.= "\n]\n>>\nendobj";
926
+        return  $res;
927
+    }
927 928
     }
928
-  }
929 929
 
930 930
 
931
-  /**
932
-   * a descendent cid font,  needed for unicode fonts
933
-   */
934
-  protected function  o_fontDescendentCID($id, $action, $options = '') {
931
+    /**
932
+     * a descendent cid font,  needed for unicode fonts
933
+     */
934
+    protected function  o_fontDescendentCID($id, $action, $options = '') {
935 935
     if  ($action !== 'new') {
936
-      $o = & $this->objects[$id];
936
+        $o = & $this->objects[$id];
937 937
     }
938 938
 
939 939
     switch  ($action) {
940 940
     case  'new':
941 941
       $this->objects[$id] =  array('t'=>'fontDescendentCID', 'info'=>$options);
942 942
 
943
-      // we need a CID system info section
944
-      $cidSystemInfoId = ++$this->numObj;
945
-      $this->o_contents($cidSystemInfoId, 'new', 'raw');
946
-      $this->objects[$id]['info']['cidSystemInfo'] = $cidSystemInfoId;
947
-      $res=   "<</Registry (Adobe)\n"; // A string identifying an issuer of character collections
948
-      $res.=  "/Ordering (UCS)\n"; // A string that uniquely names a character collection issued by a specific registry
949
-      $res.=  "/Supplement 0\n"; // The supplement number of the character collection.
950
-      $res.=  ">>";
951
-      $this->objects[$cidSystemInfoId]['c'] = $res;
952
-
953
-      // and a CID to GID map
954
-      $cidToGidMapId = ++$this->numObj;
955
-      $this->o_fontGIDtoCIDMap($cidToGidMapId, 'new', $options);
956
-      $this->objects[$id]['info']['cidToGidMap'] = $cidToGidMapId;
957
-      break;
943
+        // we need a CID system info section
944
+        $cidSystemInfoId = ++$this->numObj;
945
+        $this->o_contents($cidSystemInfoId, 'new', 'raw');
946
+        $this->objects[$id]['info']['cidSystemInfo'] = $cidSystemInfoId;
947
+        $res=   "<</Registry (Adobe)\n"; // A string identifying an issuer of character collections
948
+        $res.=  "/Ordering (UCS)\n"; // A string that uniquely names a character collection issued by a specific registry
949
+        $res.=  "/Supplement 0\n"; // The supplement number of the character collection.
950
+        $res.=  ">>";
951
+        $this->objects[$cidSystemInfoId]['c'] = $res;
952
+
953
+        // and a CID to GID map
954
+        $cidToGidMapId = ++$this->numObj;
955
+        $this->o_fontGIDtoCIDMap($cidToGidMapId, 'new', $options);
956
+        $this->objects[$id]['info']['cidToGidMap'] = $cidToGidMapId;
957
+        break;
958 958
 
959 959
     case  'add':
960 960
       foreach ($options as  $k => $v) {
961 961
         switch  ($k) {
962 962
         case  'BaseFont':
963 963
           $o['info']['name'] =  $v;
964
-          break;
964
+            break;
965 965
 
966 966
         case  'FirstChar':
967 967
         case  'LastChar':
@@ -969,21 +969,21 @@  discard block
 block discarded – undo
969 969
         case  'FontDescriptor':
970 970
         case  'SubType':
971 971
           $this->addMessage('o_fontDescendentCID '.$k." : ".$v);
972
-          $o['info'][$k] =  $v;
973
-          break;
972
+            $o['info'][$k] =  $v;
973
+            break;
974
+        }
974 975
         }
975
-      }
976 976
 
977
-      // pass values down to cid to gid map
978
-      $this->o_fontGIDtoCIDMap($o['info']['cidToGidMap'], 'add', $options);
979
-      break;
977
+        // pass values down to cid to gid map
978
+        $this->o_fontGIDtoCIDMap($o['info']['cidToGidMap'], 'add', $options);
979
+        break;
980 980
 
981 981
     case  'out':
982 982
       $res =  "\n".$id." 0 obj\n";
983
-      $res.=  "<</Type /Font\n";
984
-      $res.=  "/Subtype /CIDFontType2\n";
985
-      $res.=  "/BaseFont /".$o['info']['name']."\n";
986
-      $res.=  "/CIDSystemInfo ".$o['info']['cidSystemInfo']." 0 R\n";
983
+        $res.=  "<</Type /Font\n";
984
+        $res.=  "/Subtype /CIDFontType2\n";
985
+        $res.=  "/BaseFont /".$o['info']['name']."\n";
986
+        $res.=  "/CIDSystemInfo ".$o['info']['cidSystemInfo']." 0 R\n";
987 987
 //      if  (isset($o['info']['FirstChar'])) {
988 988
 //        $res.=  "/FirstChar ".$o['info']['FirstChar']."\n";
989 989
 //      }
@@ -991,126 +991,126 @@  discard block
 block discarded – undo
991 991
 //      if  (isset($o['info']['LastChar'])) {
992 992
 //        $res.=  "/LastChar ".$o['info']['LastChar']."\n";
993 993
 //      }
994
-      if  (isset($o['info']['FontDescriptor'])) {
994
+        if  (isset($o['info']['FontDescriptor'])) {
995 995
         $res.=  "/FontDescriptor ".$o['info']['FontDescriptor']." 0 R\n";
996
-      }
996
+        }
997 997
 
998
-      if  (isset($o['info']['MissingWidth'])) {
998
+        if  (isset($o['info']['MissingWidth'])) {
999 999
         $res.=  "/DW ".$o['info']['MissingWidth']."\n";
1000
-      }
1000
+        }
1001 1001
 
1002
-      if  (isset($o['info']['fontFileName']) && isset($this->fonts[$o['info']['fontFileName']]['CIDWidths'])) {
1002
+        if  (isset($o['info']['fontFileName']) && isset($this->fonts[$o['info']['fontFileName']]['CIDWidths'])) {
1003 1003
         $cid_widths = &$this->fonts[$o['info']['fontFileName']]['CIDWidths'];
1004 1004
         $w = '';
1005 1005
         foreach ($cid_widths as $cid => $width) {
1006
-          $w .= $cid.' ['.$width.'] ';
1006
+            $w .= $cid.' ['.$width.'] ';
1007 1007
         }
1008 1008
         $res.=  "/W [".$w."]\n";
1009
-      }
1009
+        }
1010 1010
 
1011
-      $res.=  "/CIDToGIDMap ".$o['info']['cidToGidMap']." 0 R\n";
1012
-      $res.=  ">>\n";
1013
-      $res.=  "endobj";
1011
+        $res.=  "/CIDToGIDMap ".$o['info']['cidToGidMap']." 0 R\n";
1012
+        $res.=  ">>\n";
1013
+        $res.=  "endobj";
1014 1014
 
1015
-      return  $res;
1015
+        return  $res;
1016
+    }
1016 1017
     }
1017
-  }
1018 1018
   
1019 1019
 
1020
-  /**
1021
-   * a font glyph to character map,  needed for unicode fonts
1022
-   */
1023
-  protected function  o_fontGIDtoCIDMap($id, $action, $options = '') {
1020
+    /**
1021
+     * a font glyph to character map,  needed for unicode fonts
1022
+     */
1023
+    protected function  o_fontGIDtoCIDMap($id, $action, $options = '') {
1024 1024
     if  ($action !== 'new') {
1025
-      $o = & $this->objects[$id];
1025
+        $o = & $this->objects[$id];
1026 1026
     }
1027 1027
 
1028 1028
     switch  ($action) {
1029 1029
     case  'new':
1030 1030
       $this->objects[$id] =  array('t'=>'fontGIDtoCIDMap', 'info'=>$options);
1031
-      break;
1031
+        break;
1032 1032
 
1033 1033
     case  'out':
1034 1034
       $res = "\n".$id." 0 obj\n";
1035
-      $tmp = $this->fonts[$o['info']['fontFileName']]['CIDtoGID'] = base64_decode($this->fonts[$o['info']['fontFileName']]['CIDtoGID']);
1036
-      $compressed = isset($this->fonts[$o['info']['fontFileName']]['CIDtoGID_Compressed']) &&
1035
+        $tmp = $this->fonts[$o['info']['fontFileName']]['CIDtoGID'] = base64_decode($this->fonts[$o['info']['fontFileName']]['CIDtoGID']);
1036
+        $compressed = isset($this->fonts[$o['info']['fontFileName']]['CIDtoGID_Compressed']) &&
1037 1037
                     $this->fonts[$o['info']['fontFileName']]['CIDtoGID_Compressed'];
1038 1038
 
1039
-      if  (!$compressed && isset($o['raw'])) {
1039
+        if  (!$compressed && isset($o['raw'])) {
1040 1040
         $res.= $tmp;
1041
-      } else {
1041
+        } else {
1042 1042
         $res.=  "<<";
1043 1043
 
1044 1044
         if  (!$compressed && function_exists('gzcompress') &&  $this->options['compression']) {
1045
-          // then implement ZLIB based compression on this content stream
1046
-          $compressed = true;
1047
-          $tmp =  gzcompress($tmp,  6);
1045
+            // then implement ZLIB based compression on this content stream
1046
+            $compressed = true;
1047
+            $tmp =  gzcompress($tmp,  6);
1048 1048
         }
1049 1049
         if ($compressed) {
1050
-          $res.= "\n/Filter /FlateDecode";
1050
+            $res.= "\n/Filter /FlateDecode";
1051 1051
         }
1052 1052
 
1053 1053
         $res.= "\n/Length ".mb_strlen($tmp, '8bit') .">>\nstream\n".$tmp."\nendstream";
1054
-      }
1054
+        }
1055 1055
 
1056
-      $res.= "\nendobj";
1057
-      return  $res;
1056
+        $res.= "\nendobj";
1057
+        return  $res;
1058
+    }
1058 1059
     }
1059
-  }
1060 1060
   
1061 1061
 
1062
-  /**
1063
-   * the document procset, solves some problems with printing to old PS printers
1064
-   */
1065
-  protected function  o_procset($id, $action, $options = '') {
1062
+    /**
1063
+     * the document procset, solves some problems with printing to old PS printers
1064
+     */
1065
+    protected function  o_procset($id, $action, $options = '') {
1066 1066
     if  ($action !== 'new') {
1067
-      $o = & $this->objects[$id];
1067
+        $o = & $this->objects[$id];
1068 1068
     }
1069 1069
 
1070 1070
     switch  ($action) {
1071 1071
     case  'new':
1072 1072
       $this->objects[$id] = array('t'=>'procset', 'info'=>array('PDF'=>1, 'Text'=>1));
1073
-      $this->o_pages($this->currentNode, 'procset', $id);
1074
-      $this->procsetObjectId = $id;
1075
-      break;
1073
+        $this->o_pages($this->currentNode, 'procset', $id);
1074
+        $this->procsetObjectId = $id;
1075
+        break;
1076 1076
 
1077 1077
     case  'add':
1078 1078
       // this is to add new items to the procset list, despite the fact that this is considered
1079 1079
       // obselete, the items are required for printing to some postscript printers
1080 1080
       switch  ($options) {
1081
-      case  'ImageB':
1081
+        case  'ImageB':
1082 1082
       case  'ImageC':
1083 1083
       case  'ImageI':
1084 1084
         $o['info'][$options] = 1;
1085 1085
         break;
1086
-      }
1087
-      break;
1086
+        }
1087
+        break;
1088 1088
 
1089 1089
     case  'out':
1090 1090
       $res = "\n".$id." 0 obj\n[";
1091
-      foreach ($o['info'] as  $label=>$val) {
1091
+        foreach ($o['info'] as  $label=>$val) {
1092 1092
         $res.= '/'.$label.' ';
1093
-      }
1094
-      $res.= "]\nendobj";
1095
-      return  $res;
1093
+        }
1094
+        $res.= "]\nendobj";
1095
+        return  $res;
1096
+    }
1096 1097
     }
1097
-  }
1098 1098
 
1099 1099
 
1100
-  /**
1101
-   * define the document information
1102
-   */
1103
-  protected function  o_info($id, $action, $options = '') {
1100
+    /**
1101
+     * define the document information
1102
+     */
1103
+    protected function  o_info($id, $action, $options = '') {
1104 1104
     if  ($action !== 'new') {
1105
-      $o = & $this->objects[$id];
1105
+        $o = & $this->objects[$id];
1106 1106
     }
1107 1107
 
1108 1108
     switch  ($action) {
1109 1109
     case  'new':
1110 1110
       $this->infoObject = $id;
1111
-      $date = 'D:'.@date('Ymd');
1112
-      $this->objects[$id] = array('t'=>'info', 'info'=>array('Creator'=>'R and OS php pdf writer, http://www.ros.co.nz', 'CreationDate'=>$date));
1113
-      break;
1111
+        $date = 'D:'.@date('Ymd');
1112
+        $this->objects[$id] = array('t'=>'info', 'info'=>array('Creator'=>'R and OS php pdf writer, http://www.ros.co.nz', 'CreationDate'=>$date));
1113
+        break;
1114 1114
     case  'Title':
1115 1115
     case  'Author':
1116 1116
     case  'Subject':
@@ -1121,107 +1121,107 @@  discard block
 block discarded – undo
1121 1121
     case  'ModDate':
1122 1122
     case  'Trapped':
1123 1123
       $o['info'][$action] = $options;
1124
-      break;
1124
+        break;
1125 1125
 
1126 1126
     case  'out':
1127 1127
       if  ($this->encrypted) {
1128 1128
         $this->encryptInit($id);
1129
-      }
1129
+        }
1130 1130
 
1131
-      $res = "\n".$id." 0 obj\n<<\n";
1132
-      foreach ($o['info'] as  $k=>$v) {
1131
+        $res = "\n".$id." 0 obj\n<<\n";
1132
+        foreach ($o['info'] as  $k=>$v) {
1133 1133
         $res.= '/'.$k.' (';
1134 1134
         // dates must be outputted as-is, without Unicode transformations
1135 1135
         $raw = ($k === 'CreationDate' || $k === 'ModDate');
1136 1136
         $c = $v;
1137 1137
 
1138 1138
         if  ($this->encrypted) {
1139
-          $c = $this->ARC4($c);
1139
+            $c = $this->ARC4($c);
1140 1140
         }
1141 1141
 
1142 1142
         $res.= ($raw) ? $c : $this->filterText($c);
1143 1143
         $res.= ")\n";
1144
-      }
1144
+        }
1145 1145
 
1146
-      $res.= ">>\nendobj";
1147
-      return  $res;
1146
+        $res.= ">>\nendobj";
1147
+        return  $res;
1148
+    }
1148 1149
     }
1149
-  }
1150 1150
 
1151 1151
 
1152
-  /**
1153
-   * an action object, used to link to URLS initially
1154
-   */
1155
-  protected function  o_action($id, $action, $options = '') {
1152
+    /**
1153
+     * an action object, used to link to URLS initially
1154
+     */
1155
+    protected function  o_action($id, $action, $options = '') {
1156 1156
     if  ($action !== 'new') {
1157
-      $o = & $this->objects[$id];
1157
+        $o = & $this->objects[$id];
1158 1158
     }
1159 1159
 
1160 1160
     switch  ($action) {
1161 1161
     case  'new':
1162 1162
       if  (is_array($options)) {
1163 1163
         $this->objects[$id] = array('t'=>'action', 'info'=>$options, 'type'=>$options['type']);
1164
-      } else {
1164
+        } else {
1165 1165
         // then assume a URI action
1166 1166
         $this->objects[$id] = array('t'=>'action', 'info'=>$options, 'type'=>'URI');
1167
-      }
1168
-      break;
1167
+        }
1168
+        break;
1169 1169
 
1170 1170
     case  'out':
1171 1171
       if  ($this->encrypted) {
1172 1172
         $this->encryptInit($id);
1173
-      }
1173
+        }
1174 1174
 
1175
-      $res = "\n".$id." 0 obj\n<< /Type /Action";
1176
-      switch ($o['type']) {
1177
-      case  'ilink':
1175
+        $res = "\n".$id." 0 obj\n<< /Type /Action";
1176
+        switch ($o['type']) {
1177
+        case  'ilink':
1178 1178
         // there will be an 'label' setting, this is the name of the destination
1179 1179
         $res.= "\n/S /GoTo\n/D ".$this->destinations[(string)$o['info']['label']]." 0 R";
1180 1180
         break;
1181 1181
 
1182
-      case  'URI':
1182
+        case  'URI':
1183 1183
         $res.= "\n/S /URI\n/URI (";
1184 1184
         if  ($this->encrypted) {
1185
-          $res.= $this->filterText($this->ARC4($o['info']));
1185
+            $res.= $this->filterText($this->ARC4($o['info']));
1186 1186
         } else {
1187
-          $res.= $this->filterText($o['info']);
1187
+            $res.= $this->filterText($o['info']);
1188 1188
         }
1189 1189
 
1190 1190
         $res.= ")";
1191 1191
         break;
1192
-      }
1192
+        }
1193 1193
 
1194
-      $res.= "\n>>\nendobj";
1195
-      return  $res;
1194
+        $res.= "\n>>\nendobj";
1195
+        return  $res;
1196
+    }
1196 1197
     }
1197
-  }
1198 1198
 
1199 1199
 
1200
-  /**
1201
-   * an annotation object, this will add an annotation to the current page.
1202
-   * initially will support just link annotations
1203
-   */
1204
-  protected function  o_annotation($id, $action, $options = '') {
1200
+    /**
1201
+     * an annotation object, this will add an annotation to the current page.
1202
+     * initially will support just link annotations
1203
+     */
1204
+    protected function  o_annotation($id, $action, $options = '') {
1205 1205
     if  ($action !== 'new') {
1206
-      $o = & $this->objects[$id];
1206
+        $o = & $this->objects[$id];
1207 1207
     }
1208 1208
 
1209 1209
     switch  ($action) {
1210 1210
     case  'new':
1211 1211
       // add the annotation to the current page
1212 1212
       $pageId =  $this->currentPage;
1213
-      $this->o_page($pageId, 'annot', $id);
1213
+        $this->o_page($pageId, 'annot', $id);
1214 1214
 
1215
-      // and add the action object which is going to be required
1216
-      switch ($options['type']) {
1217
-      case  'link':
1215
+        // and add the action object which is going to be required
1216
+        switch ($options['type']) {
1217
+        case  'link':
1218 1218
         $this->objects[$id] = array('t'=>'annotation', 'info'=>$options);
1219 1219
         $this->numObj++;
1220 1220
         $this->o_action($this->numObj, 'new', $options['url']);
1221 1221
         $this->objects[$id]['info']['actionId'] = $this->numObj;
1222 1222
         break;
1223 1223
 
1224
-      case  'ilink':
1224
+        case  'ilink':
1225 1225
         // this is to a named internal link
1226 1226
         $label =  $options['label'];
1227 1227
         $this->objects[$id] = array('t'=>'annotation', 'info'=>$options);
@@ -1229,199 +1229,199 @@  discard block
 block discarded – undo
1229 1229
         $this->o_action($this->numObj, 'new', array('type'=>'ilink', 'label'=>$label));
1230 1230
         $this->objects[$id]['info']['actionId'] = $this->numObj;
1231 1231
         break;
1232
-      }
1233
-      break;
1232
+        }
1233
+        break;
1234 1234
 
1235 1235
     case  'out':
1236 1236
       $res = "\n".$id." 0 obj\n<< /Type /Annot";
1237
-      switch ($o['info']['type']) {
1238
-      case  'link':
1237
+        switch ($o['info']['type']) {
1238
+        case  'link':
1239 1239
       case  'ilink':
1240 1240
         $res.=  "\n/Subtype /Link";
1241 1241
         break;
1242
-      }
1243
-      $res.= "\n/A ".$o['info']['actionId']." 0 R";
1244
-      $res.= "\n/Border [0 0 0]";
1245
-      $res.= "\n/H /I";
1246
-      $res.= "\n/Rect [ ";
1242
+        }
1243
+        $res.= "\n/A ".$o['info']['actionId']." 0 R";
1244
+        $res.= "\n/Border [0 0 0]";
1245
+        $res.= "\n/H /I";
1246
+        $res.= "\n/Rect [ ";
1247 1247
 
1248
-      foreach($o['info']['rect'] as  $v) {
1248
+        foreach($o['info']['rect'] as  $v) {
1249 1249
         $res.=  sprintf("%.4F ", $v);
1250
-      }
1250
+        }
1251 1251
 
1252
-      $res.= "]";
1253
-      $res.= "\n>>\nendobj";
1254
-      return  $res;
1252
+        $res.= "]";
1253
+        $res.= "\n>>\nendobj";
1254
+        return  $res;
1255
+    }
1255 1256
     }
1256
-  }
1257 1257
 
1258 1258
 
1259
-  /**
1260
-   * a page object, it also creates a contents object to hold its contents
1261
-   */
1262
-  protected function  o_page($id, $action, $options = '') {
1259
+    /**
1260
+     * a page object, it also creates a contents object to hold its contents
1261
+     */
1262
+    protected function  o_page($id, $action, $options = '') {
1263 1263
     if  ($action !== 'new') {
1264
-      $o = & $this->objects[$id];
1264
+        $o = & $this->objects[$id];
1265 1265
     }
1266 1266
 
1267 1267
     switch  ($action) {
1268 1268
     case  'new':
1269 1269
       $this->numPages++;
1270
-      $this->objects[$id] = array('t'=>'page', 'info'=>array('parent'=>$this->currentNode, 'pageNum'=>$this->numPages));
1270
+        $this->objects[$id] = array('t'=>'page', 'info'=>array('parent'=>$this->currentNode, 'pageNum'=>$this->numPages));
1271 1271
 
1272
-      if  (is_array($options)) {
1272
+        if  (is_array($options)) {
1273 1273
         // then this must be a page insertion, array should contain 'rid','pos'=[before|after]
1274 1274
         $options['id'] = $id;
1275 1275
         $this->o_pages($this->currentNode, 'page', $options);
1276
-      } else {
1276
+        } else {
1277 1277
         $this->o_pages($this->currentNode, 'page', $id);
1278
-      }
1279
-
1280
-      $this->currentPage = $id;
1281
-      //make a contents object to go with this page
1282
-      $this->numObj++;
1283
-      $this->o_contents($this->numObj, 'new', $id);
1284
-      $this->currentContents = $this->numObj;
1285
-      $this->objects[$id]['info']['contents'] = array();
1286
-      $this->objects[$id]['info']['contents'][] = $this->numObj;
1287
-
1288
-      $match =  ($this->numPages%2 ?  'odd' :  'even');
1289
-      foreach($this->addLooseObjects as  $oId=>$target) {
1278
+        }
1279
+
1280
+        $this->currentPage = $id;
1281
+        //make a contents object to go with this page
1282
+        $this->numObj++;
1283
+        $this->o_contents($this->numObj, 'new', $id);
1284
+        $this->currentContents = $this->numObj;
1285
+        $this->objects[$id]['info']['contents'] = array();
1286
+        $this->objects[$id]['info']['contents'][] = $this->numObj;
1287
+
1288
+        $match =  ($this->numPages%2 ?  'odd' :  'even');
1289
+        foreach($this->addLooseObjects as  $oId=>$target) {
1290 1290
         if  ($target === 'all' || $match === $target) {
1291
-          $this->objects[$id]['info']['contents'][] = $oId;
1291
+            $this->objects[$id]['info']['contents'][] = $oId;
1292 1292
         }
1293
-      }
1294
-      break;
1293
+        }
1294
+        break;
1295 1295
 
1296 1296
     case  'content':
1297 1297
       $o['info']['contents'][] = $options;
1298
-      break;
1298
+        break;
1299 1299
 
1300 1300
     case  'annot':
1301 1301
       // add an annotation to this page
1302 1302
       if  (!isset($o['info']['annot'])) {
1303 1303
         $o['info']['annot'] = array();
1304
-      }
1304
+        }
1305 1305
 
1306
-      // $options should contain the id of the annotation dictionary
1307
-      $o['info']['annot'][] = $options;
1308
-      break;
1306
+        // $options should contain the id of the annotation dictionary
1307
+        $o['info']['annot'][] = $options;
1308
+        break;
1309 1309
 
1310 1310
     case  'out':
1311 1311
       $res = "\n".$id." 0 obj\n<< /Type /Page";
1312
-      $res.= "\n/Parent ".$o['info']['parent']." 0 R";
1312
+        $res.= "\n/Parent ".$o['info']['parent']." 0 R";
1313 1313
 
1314
-      if  (isset($o['info']['annot'])) {
1314
+        if  (isset($o['info']['annot'])) {
1315 1315
         $res.= "\n/Annots [";
1316 1316
         foreach($o['info']['annot'] as  $aId) {
1317
-          $res.= " ".$aId." 0 R";
1317
+            $res.= " ".$aId." 0 R";
1318 1318
         }
1319 1319
         $res.= " ]";
1320
-      }
1320
+        }
1321 1321
 
1322
-      $count =  count($o['info']['contents']);
1323
-      if  ($count == 1) {
1322
+        $count =  count($o['info']['contents']);
1323
+        if  ($count == 1) {
1324 1324
         $res.= "\n/Contents ".$o['info']['contents'][0]." 0 R";
1325
-      } else  if  ($count>1) {
1325
+        } else  if  ($count>1) {
1326 1326
         $res.= "\n/Contents [\n";
1327 1327
 
1328 1328
         // reverse the page contents so added objects are below normal content
1329 1329
         //foreach (array_reverse($o['info']['contents']) as  $cId) {
1330 1330
         // Back to normal now that I've got transparency working --Benj
1331 1331
         foreach ($o['info']['contents'] as  $cId) {
1332
-          $res.= $cId." 0 R\n";
1332
+            $res.= $cId." 0 R\n";
1333 1333
         }
1334 1334
         $res.= "]";
1335
-      }
1335
+        }
1336 1336
 
1337
-      $res.= "\n>>\nendobj";
1338
-      return  $res;
1337
+        $res.= "\n>>\nendobj";
1338
+        return  $res;
1339
+    }
1339 1340
     }
1340
-  }
1341 1341
 
1342 1342
 
1343
-  /**
1344
-   * the contents objects hold all of the content which appears on pages
1345
-   */
1346
-  protected function  o_contents($id, $action, $options = '') {
1343
+    /**
1344
+     * the contents objects hold all of the content which appears on pages
1345
+     */
1346
+    protected function  o_contents($id, $action, $options = '') {
1347 1347
     if  ($action !== 'new') {
1348
-      $o = & $this->objects[$id];
1348
+        $o = & $this->objects[$id];
1349 1349
     }
1350 1350
 
1351 1351
     switch  ($action) {
1352 1352
     case  'new':
1353 1353
       $this->objects[$id] = array('t'=>'contents', 'c'=>'', 'info'=>array());
1354
-      if  (mb_strlen($options, '8bit') &&  intval($options)) {
1354
+        if  (mb_strlen($options, '8bit') &&  intval($options)) {
1355 1355
         // then this contents is the primary for a page
1356 1356
         $this->objects[$id]['onPage'] = $options;
1357
-      } else  if  ($options === 'raw') {
1357
+        } else  if  ($options === 'raw') {
1358 1358
         // then this page contains some other type of system object
1359 1359
         $this->objects[$id]['raw'] = 1;
1360
-      }
1361
-      break;
1360
+        }
1361
+        break;
1362 1362
 
1363 1363
     case  'add':
1364 1364
       // add more options to the decleration
1365 1365
       foreach ($options as  $k=>$v) {
1366 1366
         $o['info'][$k] = $v;
1367
-      }
1367
+        }
1368 1368
 
1369 1369
     case  'out':
1370 1370
       $tmp = $o['c'];
1371
-      $res =  "\n".$id." 0 obj\n";
1371
+        $res =  "\n".$id." 0 obj\n";
1372 1372
 
1373
-      if  (isset($this->objects[$id]['raw'])) {
1373
+        if  (isset($this->objects[$id]['raw'])) {
1374 1374
         $res.= $tmp;
1375
-      } else {
1375
+        } else {
1376 1376
         $res.=  "<<";
1377 1377
         if  (function_exists('gzcompress') &&  $this->options['compression']) {
1378
-          // then implement ZLIB based compression on this content stream
1379
-          $res.= " /Filter /FlateDecode";
1380
-          $tmp =  gzcompress($tmp,  6);
1378
+            // then implement ZLIB based compression on this content stream
1379
+            $res.= " /Filter /FlateDecode";
1380
+            $tmp =  gzcompress($tmp,  6);
1381 1381
         }
1382 1382
 
1383 1383
         if  ($this->encrypted) {
1384
-          $this->encryptInit($id);
1385
-          $tmp =  $this->ARC4($tmp);
1384
+            $this->encryptInit($id);
1385
+            $tmp =  $this->ARC4($tmp);
1386 1386
         }
1387 1387
 
1388 1388
         foreach($o['info'] as  $k=>$v) {
1389
-          $res.=  "\n/".$k.' '.$v;
1389
+            $res.=  "\n/".$k.' '.$v;
1390 1390
         }
1391 1391
 
1392 1392
         $res.= "\n/Length ".mb_strlen($tmp, '8bit') ." >>\nstream\n".$tmp."\nendstream";
1393
-      }
1393
+        }
1394 1394
 
1395
-      $res.= "\nendobj";
1396
-      return  $res;
1395
+        $res.= "\nendobj";
1396
+        return  $res;
1397
+    }
1397 1398
     }
1398
-  }
1399 1399
 
1400
-  protected function  o_embedjs($id, $action, $code = '') {
1400
+    protected function  o_embedjs($id, $action, $code = '') {
1401 1401
     if  ($action !== 'new') {
1402
-      $o = & $this->objects[$id];
1402
+        $o = & $this->objects[$id];
1403 1403
     }
1404 1404
 
1405 1405
     switch  ($action) {
1406 1406
     case  'new':
1407 1407
       $this->objects[$id] = array('t'=>'embedjs', 'info'=>array(
1408 1408
         'Names' => '[(EmbeddedJS) '.($id+1).' 0 R]'
1409
-      ));
1410
-      break;
1409
+        ));
1410
+        break;
1411 1411
 
1412 1412
     case  'out':
1413 1413
       $res .= "\n".$id." 0 obj\n".'<< ';
1414
-      foreach($o['info'] as  $k=>$v) {
1414
+        foreach($o['info'] as  $k=>$v) {
1415 1415
         $res.=  "\n/".$k.' '.$v;
1416
-      }
1417
-      $res.= "\n>>\nendobj";
1418
-      return  $res;
1416
+        }
1417
+        $res.= "\n>>\nendobj";
1418
+        return  $res;
1419
+    }
1419 1420
     }
1420
-  }
1421 1421
   
1422
-  protected function  o_javascript($id, $action, $code = '') {
1422
+    protected function  o_javascript($id, $action, $code = '') {
1423 1423
     if  ($action !== 'new') {
1424
-      $o = & $this->objects[$id];
1424
+        $o = & $this->objects[$id];
1425 1425
     }
1426 1426
 
1427 1427
     switch  ($action) {
@@ -1429,71 +1429,71 @@  discard block
 block discarded – undo
1429 1429
       $this->objects[$id] = array('t'=>'javascript', 'info'=>array(
1430 1430
         'S' => '/JavaScript',
1431 1431
         'JS' => '('.$this->filterText($code).')',
1432
-      ));
1433
-      break;
1432
+        ));
1433
+        break;
1434 1434
 
1435 1435
     case  'out':
1436 1436
       $res = "\n".$id." 0 obj\n".'<< ';
1437
-      foreach($o['info'] as  $k=>$v) {
1437
+        foreach($o['info'] as  $k=>$v) {
1438 1438
         $res.=  "\n/".$k.' '.$v;
1439
-      }
1440
-      $res.= "\n>>\nendobj";
1441
-      return  $res;
1439
+        }
1440
+        $res.= "\n>>\nendobj";
1441
+        return  $res;
1442
+    }
1442 1443
     }
1443
-  }
1444 1444
 
1445
-  /**
1446
-   * an image object, will be an XObject in the document, includes description and data
1447
-   */
1448
-  protected function  o_image($id, $action, $options = '') {
1445
+    /**
1446
+     * an image object, will be an XObject in the document, includes description and data
1447
+     */
1448
+    protected function  o_image($id, $action, $options = '') {
1449 1449
     if  ($action !== 'new') {
1450
-      $o = & $this->objects[$id];
1450
+        $o = & $this->objects[$id];
1451 1451
     }
1452 1452
 
1453 1453
     switch ($action) {
1454 1454
     case  'new':
1455 1455
       // make the new object
1456 1456
       $this->objects[$id] = array('t'=>'image', 'data'=>&$options['data'], 'info'=>array());
1457
-      $this->objects[$id]['info']['Type'] = '/XObject';
1458
-      $this->objects[$id]['info']['Subtype'] = '/Image';
1459
-      $this->objects[$id]['info']['Width'] = $options['iw'];
1460
-      $this->objects[$id]['info']['Height'] = $options['ih'];
1457
+        $this->objects[$id]['info']['Type'] = '/XObject';
1458
+        $this->objects[$id]['info']['Subtype'] = '/Image';
1459
+        $this->objects[$id]['info']['Width'] = $options['iw'];
1460
+        $this->objects[$id]['info']['Height'] = $options['ih'];
1461 1461
 
1462
-      if  (!isset($options['type']) ||  $options['type'] === 'jpg') {
1462
+        if  (!isset($options['type']) ||  $options['type'] === 'jpg') {
1463 1463
         if  (!isset($options['channels'])) {
1464
-          $options['channels'] = 3;
1464
+            $options['channels'] = 3;
1465 1465
         }
1466 1466
 
1467 1467
         switch ($options['channels']) {
1468 1468
         case  1:
1469 1469
           $this->objects[$id]['info']['ColorSpace'] = '/DeviceGray';
1470
-          break;
1470
+            break;
1471 1471
 
1472 1472
         default:
1473 1473
           $this->objects[$id]['info']['ColorSpace'] = '/DeviceRGB';
1474
-          break;
1474
+            break;
1475 1475
         }
1476 1476
 
1477 1477
         $this->objects[$id]['info']['Filter'] = '/DCTDecode';
1478 1478
         $this->objects[$id]['info']['BitsPerComponent'] = 8;
1479
-      } else  if  ($options['type'] === 'png') {
1479
+        } else  if  ($options['type'] === 'png') {
1480 1480
         $this->objects[$id]['info']['Filter'] = '/FlateDecode';
1481 1481
         $this->objects[$id]['info']['DecodeParms'] = '<< /Predictor 15 /Colors '.$options['ncolor'].' /Columns '.$options['iw'].' /BitsPerComponent '.$options['bitsPerComponent'].'>>';
1482 1482
 
1483 1483
         if  (mb_strlen($options['pdata'], '8bit')) {
1484
-          $tmp =  ' [ /Indexed /DeviceRGB '.(mb_strlen($options['pdata'], '8bit') /3-1) .' ';
1485
-          $this->numObj++;
1486
-          $this->o_contents($this->numObj, 'new');
1487
-          $this->objects[$this->numObj]['c'] = $options['pdata'];
1488
-          $tmp.= $this->numObj.' 0 R';
1489
-          $tmp.= ' ]';
1490
-          $this->objects[$id]['info']['ColorSpace'] =  $tmp;
1491
-          if  (isset($options['transparency'])) {
1484
+            $tmp =  ' [ /Indexed /DeviceRGB '.(mb_strlen($options['pdata'], '8bit') /3-1) .' ';
1485
+            $this->numObj++;
1486
+            $this->o_contents($this->numObj, 'new');
1487
+            $this->objects[$this->numObj]['c'] = $options['pdata'];
1488
+            $tmp.= $this->numObj.' 0 R';
1489
+            $tmp.= ' ]';
1490
+            $this->objects[$id]['info']['ColorSpace'] =  $tmp;
1491
+            if  (isset($options['transparency'])) {
1492 1492
             switch ($options['transparency']['type']) {
1493 1493
             case  'indexed':
1494 1494
               $tmp = ' [ '.$options['transparency']['data'].' '.$options['transparency']['data'].'] ';
1495
-              $this->objects[$id]['info']['Mask'] =  $tmp;
1496
-              break;
1495
+                $this->objects[$id]['info']['Mask'] =  $tmp;
1496
+                break;
1497 1497
 
1498 1498
             case 'color-key':
1499 1499
               $tmp = ' [ '.
@@ -1501,19 +1501,19 @@  discard block
 block discarded – undo
1501 1501
                 $options['transparency']['g'] . ' ' . $options['transparency']['g'] .
1502 1502
                 $options['transparency']['b'] . ' ' . $options['transparency']['b'] .
1503 1503
                 ' ] ';
1504
-              $this->objects[$id]['info']['Mask'] = $tmp;
1505
-              pre_r($tmp);
1506
-              break;
1504
+                $this->objects[$id]['info']['Mask'] = $tmp;
1505
+                pre_r($tmp);
1506
+                break;
1507 1507
               
1508 1508
             }
1509
-          }
1509
+            }
1510 1510
         } else {
1511
-          if  (isset($options['transparency'])) {
1511
+            if  (isset($options['transparency'])) {
1512 1512
             switch ($options['transparency']['type']) {
1513 1513
             case  'indexed':
1514 1514
               $tmp = ' [ '.$options['transparency']['data'].' '.$options['transparency']['data'].'] ';
1515
-              $this->objects[$id]['info']['Mask'] =  $tmp;
1516
-              break;
1515
+                $this->objects[$id]['info']['Mask'] =  $tmp;
1516
+                break;
1517 1517
 
1518 1518
             case 'color-key':
1519 1519
               $tmp = ' [ '.
@@ -1521,329 +1521,329 @@  discard block
 block discarded – undo
1521 1521
                 $options['transparency']['g'] . ' ' . $options['transparency']['g'] . ' ' .
1522 1522
                 $options['transparency']['b'] . ' ' . $options['transparency']['b'] .
1523 1523
                 ' ] ';
1524
-              $this->objects[$id]['info']['Mask'] = $tmp;
1525
-              break;              
1524
+                $this->objects[$id]['info']['Mask'] = $tmp;
1525
+                break;              
1526
+            }
1526 1527
             }
1527
-          }
1528
-          $this->objects[$id]['info']['ColorSpace'] = '/'.$options['color'];
1528
+            $this->objects[$id]['info']['ColorSpace'] = '/'.$options['color'];
1529 1529
         }
1530 1530
 
1531 1531
         $this->objects[$id]['info']['BitsPerComponent'] = $options['bitsPerComponent'];
1532
-      }
1532
+        }
1533 1533
 
1534
-      // assign it a place in the named resource dictionary as an external object, according to
1535
-      // the label passed in with it.
1536
-      $this->o_pages($this->currentNode, 'xObject', array('label'=>$options['label'], 'objNum'=>$id));
1534
+        // assign it a place in the named resource dictionary as an external object, according to
1535
+        // the label passed in with it.
1536
+        $this->o_pages($this->currentNode, 'xObject', array('label'=>$options['label'], 'objNum'=>$id));
1537 1537
 
1538
-      // also make sure that we have the right procset object for it.
1539
-      $this->o_procset($this->procsetObjectId, 'add', 'ImageC');
1540
-      break;
1538
+        // also make sure that we have the right procset object for it.
1539
+        $this->o_procset($this->procsetObjectId, 'add', 'ImageC');
1540
+        break;
1541 1541
 
1542 1542
     case  'out':
1543 1543
       $tmp = &$o['data'];
1544
-      $res =  "\n".$id." 0 obj\n<<";
1544
+        $res =  "\n".$id." 0 obj\n<<";
1545 1545
 
1546
-      foreach($o['info'] as  $k=>$v) {
1546
+        foreach($o['info'] as  $k=>$v) {
1547 1547
         $res.= "\n/".$k.' '.$v;
1548
-      }
1548
+        }
1549 1549
 
1550
-      if  ($this->encrypted) {
1550
+        if  ($this->encrypted) {
1551 1551
         $this->encryptInit($id);
1552 1552
         $tmp =  $this->ARC4($tmp);
1553
-      }
1553
+        }
1554 1554
 
1555
-      $res.= "\n/Length ".mb_strlen($tmp, '8bit') .">>\nstream\n".$tmp."\nendstream\nendobj";
1555
+        $res.= "\n/Length ".mb_strlen($tmp, '8bit') .">>\nstream\n".$tmp."\nendstream\nendobj";
1556 1556
 
1557
-      return  $res;
1557
+        return  $res;
1558
+    }
1558 1559
     }
1559
-  }
1560 1560
 
1561 1561
 
1562
-  /**
1563
-   * graphics state object
1564
-   */
1565
-  protected function  o_extGState($id,  $action,  $options = "") {
1562
+    /**
1563
+     * graphics state object
1564
+     */
1565
+    protected function  o_extGState($id,  $action,  $options = "") {
1566 1566
     static  $valid_params =  array("LW",  "LC",  "LC",  "LJ",  "ML",
1567
-                                   "D",  "RI",  "OP",  "op",  "OPM",
1568
-                                   "Font",  "BG",  "BG2",  "UCR",
1569
-                                   "TR",  "TR2",  "HT",  "FL",
1570
-                                   "SM",  "SA",  "BM",  "SMask",
1571
-                                   "CA",  "ca",  "AIS",  "TK");
1567
+                                    "D",  "RI",  "OP",  "op",  "OPM",
1568
+                                    "Font",  "BG",  "BG2",  "UCR",
1569
+                                    "TR",  "TR2",  "HT",  "FL",
1570
+                                    "SM",  "SA",  "BM",  "SMask",
1571
+                                    "CA",  "ca",  "AIS",  "TK");
1572 1572
 
1573 1573
     if  ($action !==  "new") {
1574
-      $o = & $this->objects[$id];
1574
+        $o = & $this->objects[$id];
1575 1575
     }
1576 1576
 
1577 1577
     switch  ($action) {
1578 1578
     case  "new":
1579 1579
       $this->objects[$id] =  array('t' => 'extGState',  'info' => $options);
1580 1580
 
1581
-      // Tell the pages about the new resource
1582
-      $this->numStates++;
1583
-      $this->o_pages($this->currentNode,  'extGState',  array("objNum" => $id,  "stateNum" => $this->numStates));
1584
-      break;
1581
+        // Tell the pages about the new resource
1582
+        $this->numStates++;
1583
+        $this->o_pages($this->currentNode,  'extGState',  array("objNum" => $id,  "stateNum" => $this->numStates));
1584
+        break;
1585 1585
 
1586 1586
     case  "out":
1587 1587
       $res =
1588 1588
         "\n" . $id . " 0 obj\n".
1589 1589
         "<< /Type /ExtGState\n";
1590 1590
 
1591
-      foreach ($o["info"] as  $parameter => $value) {
1591
+        foreach ($o["info"] as  $parameter => $value) {
1592 1592
         if  ( !in_array($parameter,  $valid_params))
1593
-          continue;
1593
+            continue;
1594 1594
         $res.=  "/$parameter $value\n";
1595
-      }
1595
+        }
1596 1596
 
1597
-      $res.=
1597
+        $res.=
1598 1598
         ">>\n".
1599 1599
         "endobj";
1600
-      return  $res;
1600
+        return  $res;
1601
+    }
1601 1602
     }
1602
-  }
1603 1603
 
1604 1604
 
1605
-  /**
1606
-   * encryption object.
1607
-   */
1608
-  protected function  o_encryption($id, $action, $options = '') {
1605
+    /**
1606
+     * encryption object.
1607
+     */
1608
+    protected function  o_encryption($id, $action, $options = '') {
1609 1609
     if  ($action !== 'new') {
1610
-      $o = & $this->objects[$id];
1610
+        $o = & $this->objects[$id];
1611 1611
     }
1612 1612
 
1613 1613
     switch ($action) {
1614 1614
     case  'new':
1615 1615
       // make the new object
1616 1616
       $this->objects[$id] = array('t'=>'encryption', 'info'=>$options);
1617
-      $this->arc4_objnum = $id;
1617
+        $this->arc4_objnum = $id;
1618 1618
 
1619
-      // figure out the additional paramaters required
1620
-      $pad =  chr(0x28) .chr(0xBF) .chr(0x4E) .chr(0x5E) .chr(0x4E) .chr(0x75) .chr(0x8A) .chr(0x41) .chr(0x64) .chr(0x00) .chr(0x4E) .chr(0x56) .chr(0xFF) .chr(0xFA) .chr(0x01) .chr(0x08) .chr(0x2E) .chr(0x2E) .chr(0x00) .chr(0xB6) .chr(0xD0) .chr(0x68) .chr(0x3E) .chr(0x80) .chr(0x2F) .chr(0x0C) .chr(0xA9) .chr(0xFE) .chr(0x64) .chr(0x53) .chr(0x69) .chr(0x7A);
1621
-      $len =  mb_strlen($options['owner'], '8bit');
1619
+        // figure out the additional paramaters required
1620
+        $pad =  chr(0x28) .chr(0xBF) .chr(0x4E) .chr(0x5E) .chr(0x4E) .chr(0x75) .chr(0x8A) .chr(0x41) .chr(0x64) .chr(0x00) .chr(0x4E) .chr(0x56) .chr(0xFF) .chr(0xFA) .chr(0x01) .chr(0x08) .chr(0x2E) .chr(0x2E) .chr(0x00) .chr(0xB6) .chr(0xD0) .chr(0x68) .chr(0x3E) .chr(0x80) .chr(0x2F) .chr(0x0C) .chr(0xA9) .chr(0xFE) .chr(0x64) .chr(0x53) .chr(0x69) .chr(0x7A);
1621
+        $len =  mb_strlen($options['owner'], '8bit');
1622 1622
 
1623
-      if  ($len>32) {
1623
+        if  ($len>32) {
1624 1624
         $owner =  substr($options['owner'], 0, 32);
1625
-      } else  if  ($len<32) {
1625
+        } else  if  ($len<32) {
1626 1626
         $owner =  $options['owner'].substr($pad, 0, 32-$len);
1627
-      } else {
1627
+        } else {
1628 1628
         $owner =  $options['owner'];
1629
-      }
1629
+        }
1630 1630
 
1631
-      $len =  mb_strlen($options['user'], '8bit');
1632
-      if  ($len>32) {
1631
+        $len =  mb_strlen($options['user'], '8bit');
1632
+        if  ($len>32) {
1633 1633
         $user =  substr($options['user'], 0, 32);
1634
-      } else  if  ($len<32) {
1634
+        } else  if  ($len<32) {
1635 1635
         $user =  $options['user'].substr($pad, 0, 32-$len);
1636
-      } else {
1636
+        } else {
1637 1637
         $user =  $options['user'];
1638
-      }
1639
-
1640
-      $tmp =  $this->md5_16($owner);
1641
-      $okey =  substr($tmp, 0, 5);
1642
-      $this->ARC4_init($okey);
1643
-      $ovalue = $this->ARC4($user);
1644
-      $this->objects[$id]['info']['O'] = $ovalue;
1645
-
1646
-      // now make the u value, phew.
1647
-      $tmp =  $this->md5_16($user.$ovalue.chr($options['p']) .chr(255) .chr(255) .chr(255) .$this->fileIdentifier);
1648
-
1649
-      $ukey =  substr($tmp, 0, 5);
1650
-      $this->ARC4_init($ukey);
1651
-      $this->encryptionKey =  $ukey;
1652
-      $this->encrypted = 1;
1653
-      $uvalue = $this->ARC4($pad);
1654
-      $this->objects[$id]['info']['U'] = $uvalue;
1655
-      $this->encryptionKey = $ukey;
1656
-      // initialize the arc4 array
1657
-      break;
1638
+        }
1639
+
1640
+        $tmp =  $this->md5_16($owner);
1641
+        $okey =  substr($tmp, 0, 5);
1642
+        $this->ARC4_init($okey);
1643
+        $ovalue = $this->ARC4($user);
1644
+        $this->objects[$id]['info']['O'] = $ovalue;
1645
+
1646
+        // now make the u value, phew.
1647
+        $tmp =  $this->md5_16($user.$ovalue.chr($options['p']) .chr(255) .chr(255) .chr(255) .$this->fileIdentifier);
1648
+
1649
+        $ukey =  substr($tmp, 0, 5);
1650
+        $this->ARC4_init($ukey);
1651
+        $this->encryptionKey =  $ukey;
1652
+        $this->encrypted = 1;
1653
+        $uvalue = $this->ARC4($pad);
1654
+        $this->objects[$id]['info']['U'] = $uvalue;
1655
+        $this->encryptionKey = $ukey;
1656
+        // initialize the arc4 array
1657
+        break;
1658 1658
 
1659 1659
     case  'out':
1660 1660
       $res =  "\n".$id." 0 obj\n<<";
1661
-      $res.= "\n/Filter /Standard";
1662
-      $res.= "\n/V 1";
1663
-      $res.= "\n/R 2";
1664
-      $res.= "\n/O (".$this->filterText($o['info']['O']) .')';
1665
-      $res.= "\n/U (".$this->filterText($o['info']['U']) .')';
1666
-      // and the p-value needs to be converted to account for the twos-complement approach
1667
-      $o['info']['p'] =  (($o['info']['p']^255) +1) *-1;
1668
-      $res.= "\n/P ".($o['info']['p']);
1669
-      $res.= "\n>>\nendobj";
1670
-      return  $res;
1671
-    }
1672
-  }
1673
-
1674
-
1675
-  /**
1676
-   * ARC4 functions
1677
-   * A series of function to implement ARC4 encoding in PHP
1678
-   */
1661
+        $res.= "\n/Filter /Standard";
1662
+        $res.= "\n/V 1";
1663
+        $res.= "\n/R 2";
1664
+        $res.= "\n/O (".$this->filterText($o['info']['O']) .')';
1665
+        $res.= "\n/U (".$this->filterText($o['info']['U']) .')';
1666
+        // and the p-value needs to be converted to account for the twos-complement approach
1667
+        $o['info']['p'] =  (($o['info']['p']^255) +1) *-1;
1668
+        $res.= "\n/P ".($o['info']['p']);
1669
+        $res.= "\n>>\nendobj";
1670
+        return  $res;
1671
+    }
1672
+    }
1679 1673
 
1680
-  /**
1681
-   * calculate the 16 byte version of the 128 bit md5 digest of the string
1682
-   */
1683
-  function  md5_16($string) {
1674
+
1675
+    /**
1676
+     * ARC4 functions
1677
+     * A series of function to implement ARC4 encoding in PHP
1678
+     */
1679
+
1680
+    /**
1681
+     * calculate the 16 byte version of the 128 bit md5 digest of the string
1682
+     */
1683
+    function  md5_16($string) {
1684 1684
     $tmp =  md5($string);
1685 1685
     $out = '';
1686 1686
     for  ($i = 0;$i <= 30;$i = $i+2) {
1687
-      $out.= chr(hexdec(substr($tmp, $i, 2)));
1687
+        $out.= chr(hexdec(substr($tmp, $i, 2)));
1688 1688
     }
1689 1689
     return  $out;
1690
-  }
1690
+    }
1691 1691
 
1692 1692
 
1693
-  /**
1694
-   * initialize the encryption for processing a particular object
1695
-   */
1696
-  function  encryptInit($id) {
1693
+    /**
1694
+     * initialize the encryption for processing a particular object
1695
+     */
1696
+    function  encryptInit($id) {
1697 1697
     $tmp =  $this->encryptionKey;
1698 1698
     $hex =  dechex($id);
1699 1699
     if  (mb_strlen($hex, '8bit') <6) {
1700
-      $hex =  substr('000000', 0, 6-mb_strlen($hex, '8bit')) .$hex;
1700
+        $hex =  substr('000000', 0, 6-mb_strlen($hex, '8bit')) .$hex;
1701 1701
     }
1702 1702
     $tmp.=  chr(hexdec(substr($hex, 4, 2))) .chr(hexdec(substr($hex, 2, 2))) .chr(hexdec(substr($hex, 0, 2))) .chr(0) .chr(0);
1703 1703
     $key =  $this->md5_16($tmp);
1704 1704
     $this->ARC4_init(substr($key, 0, 10));
1705
-  }
1705
+    }
1706 1706
 
1707 1707
 
1708
-  /**
1709
-   * initialize the ARC4 encryption
1710
-   */
1711
-  function  ARC4_init($key = '') {
1708
+    /**
1709
+     * initialize the ARC4 encryption
1710
+     */
1711
+    function  ARC4_init($key = '') {
1712 1712
     $this->arc4 =  '';
1713 1713
 
1714 1714
     // setup the control array
1715 1715
     if  (mb_strlen($key, '8bit') == 0) {
1716
-      return;
1716
+        return;
1717 1717
     }
1718 1718
 
1719 1719
     $k =  '';
1720 1720
     while (mb_strlen($k, '8bit') <256) {
1721
-      $k.= $key;
1721
+        $k.= $key;
1722 1722
     }
1723 1723
 
1724 1724
     $k = substr($k, 0, 256);
1725 1725
     for  ($i = 0;$i<256;$i++) {
1726
-      $this->arc4.=  chr($i);
1726
+        $this->arc4.=  chr($i);
1727 1727
     }
1728 1728
 
1729 1729
     $j = 0;
1730 1730
 
1731 1731
     for  ($i = 0;$i<256;$i++) {
1732
-      $t =  $this->arc4[$i];
1733
-      $j =  ($j + ord($t)  + ord($k[$i])) %256;
1734
-      $this->arc4[$i] = $this->arc4[$j];
1735
-      $this->arc4[$j] = $t;
1732
+        $t =  $this->arc4[$i];
1733
+        $j =  ($j + ord($t)  + ord($k[$i])) %256;
1734
+        $this->arc4[$i] = $this->arc4[$j];
1735
+        $this->arc4[$j] = $t;
1736
+    }
1736 1737
     }
1737
-  }
1738 1738
 
1739 1739
 
1740
-  /**
1741
-   * ARC4 encrypt a text string
1742
-   */
1743
-  function  ARC4($text) {
1740
+    /**
1741
+     * ARC4 encrypt a text string
1742
+     */
1743
+    function  ARC4($text) {
1744 1744
     $len = mb_strlen($text, '8bit');
1745 1745
     $a = 0;
1746 1746
     $b = 0;
1747 1747
     $c =  $this->arc4;
1748 1748
     $out = '';
1749 1749
     for  ($i = 0;$i<$len;$i++) {
1750
-      $a =  ($a+1) %256;
1751
-      $t =  $c[$a];
1752
-      $b =  ($b+ord($t)) %256;
1753
-      $c[$a] = $c[$b];
1754
-      $c[$b] = $t;
1755
-      $k =  ord($c[(ord($c[$a]) +ord($c[$b])) %256]);
1756
-      $out.= chr(ord($text[$i])  ^ $k);
1750
+        $a =  ($a+1) %256;
1751
+        $t =  $c[$a];
1752
+        $b =  ($b+ord($t)) %256;
1753
+        $c[$a] = $c[$b];
1754
+        $c[$b] = $t;
1755
+        $k =  ord($c[(ord($c[$a]) +ord($c[$b])) %256]);
1756
+        $out.= chr(ord($text[$i])  ^ $k);
1757 1757
     }
1758 1758
     return  $out;
1759
-  }
1759
+    }
1760 1760
 
1761 1761
 
1762
-  /**
1763
-   * functions which can be called to adjust or add to the document
1764
-   */
1762
+    /**
1763
+     * functions which can be called to adjust or add to the document
1764
+     */
1765 1765
 
1766
-  /**
1767
-   * add a link in the document to an external URL
1768
-   */
1769
-  function  addLink($url, $x0, $y0, $x1, $y1) {
1766
+    /**
1767
+     * add a link in the document to an external URL
1768
+     */
1769
+    function  addLink($url, $x0, $y0, $x1, $y1) {
1770 1770
     $this->numObj++;
1771 1771
     $info =  array('type'=>'link', 'url'=>$url, 'rect'=>array($x0, $y0, $x1, $y1));
1772 1772
     $this->o_annotation($this->numObj, 'new', $info);
1773
-  }
1773
+    }
1774 1774
 
1775 1775
 
1776
-  /**
1777
-   * add a link in the document to an internal destination (ie. within the document)
1778
-   */
1779
-  function  addInternalLink($label, $x0, $y0, $x1, $y1) {
1776
+    /**
1777
+     * add a link in the document to an internal destination (ie. within the document)
1778
+     */
1779
+    function  addInternalLink($label, $x0, $y0, $x1, $y1) {
1780 1780
     $this->numObj++;
1781 1781
     $info =  array('type'=>'ilink', 'label'=>$label, 'rect'=>array($x0, $y0, $x1, $y1));
1782 1782
     $this->o_annotation($this->numObj, 'new', $info);
1783
-  }
1783
+    }
1784 1784
 
1785 1785
 
1786
-  /**
1787
-   * set the encryption of the document
1788
-   * can be used to turn it on and/or set the passwords which it will have.
1789
-   * also the functions that the user will have are set here, such as print, modify, add
1790
-   */
1791
-  function  setEncryption($userPass = '', $ownerPass = '', $pc = array()) {
1786
+    /**
1787
+     * set the encryption of the document
1788
+     * can be used to turn it on and/or set the passwords which it will have.
1789
+     * also the functions that the user will have are set here, such as print, modify, add
1790
+     */
1791
+    function  setEncryption($userPass = '', $ownerPass = '', $pc = array()) {
1792 1792
     $p = bindec(11000000);
1793 1793
 
1794 1794
     $options =  array('print'=>4, 'modify'=>8, 'copy'=>16, 'add'=>32);
1795 1795
 
1796 1796
     foreach($pc as  $k=>$v) {
1797
-      if  ($v &&  isset($options[$k])) {
1797
+        if  ($v &&  isset($options[$k])) {
1798 1798
         $p+= $options[$k];
1799
-      } else  if  (isset($options[$v])) {
1799
+        } else  if  (isset($options[$v])) {
1800 1800
         $p+= $options[$v];
1801
-      }
1801
+        }
1802 1802
     }
1803 1803
 
1804 1804
     // implement encryption on the document
1805 1805
     if  ($this->arc4_objnum ==  0) {
1806
-      // then the block does not exist already, add it.
1807
-      $this->numObj++;
1808
-      if  (mb_strlen($ownerPass) == 0) {
1806
+        // then the block does not exist already, add it.
1807
+        $this->numObj++;
1808
+        if  (mb_strlen($ownerPass) == 0) {
1809 1809
         $ownerPass = $userPass;
1810
-      }
1810
+        }
1811 1811
 
1812
-      $this->o_encryption($this->numObj, 'new', array('user'=>$userPass, 'owner'=>$ownerPass, 'p'=>$p));
1812
+        $this->o_encryption($this->numObj, 'new', array('user'=>$userPass, 'owner'=>$ownerPass, 'p'=>$p));
1813
+    }
1813 1814
     }
1814
-  }
1815 1815
 
1816 1816
 
1817
-  /**
1818
-   * should be used for internal checks, not implemented as yet
1819
-   */
1820
-  function  checkAllHere() {
1821
-  }
1817
+    /**
1818
+     * should be used for internal checks, not implemented as yet
1819
+     */
1820
+    function  checkAllHere() {
1821
+    }
1822 1822
 
1823 1823
 
1824
-  /**
1825
-   * return the pdf stream as a string returned from the function
1826
-   */
1827
-  function  output($debug = false) {
1824
+    /**
1825
+     * return the pdf stream as a string returned from the function
1826
+     */
1827
+    function  output($debug = false) {
1828 1828
     if  ($debug) {
1829
-      // turn compression off
1830
-      $this->options['compression'] = 0;
1829
+        // turn compression off
1830
+        $this->options['compression'] = 0;
1831 1831
     }
1832 1832
     
1833 1833
     if ($this->javascript) {
1834
-      $this->numObj++;
1834
+        $this->numObj++;
1835 1835
       
1836
-      $js_id = $this->numObj;
1837
-      $this->o_embedjs($js_id, 'new');
1838
-      $this->o_javascript(++$this->numObj, 'new', $this->javascript);
1836
+        $js_id = $this->numObj;
1837
+        $this->o_embedjs($js_id, 'new');
1838
+        $this->o_javascript(++$this->numObj, 'new', $this->javascript);
1839 1839
       
1840
-      $id =  $this->catalogId;
1840
+        $id =  $this->catalogId;
1841 1841
       
1842
-      $this->o_catalog($id, 'javascript', $js_id);
1842
+        $this->o_catalog($id, 'javascript', $js_id);
1843 1843
     }
1844 1844
 
1845 1845
     if  ($this->arc4_objnum) {
1846
-      $this->ARC4_init($this->encryptionKey);
1846
+        $this->ARC4_init($this->encryptionKey);
1847 1847
     }
1848 1848
 
1849 1849
     $this->checkAllHere();
@@ -1854,43 +1854,43 @@  discard block
 block discarded – undo
1854 1854
     $pos = mb_strlen($content, '8bit');
1855 1855
 
1856 1856
     foreach($this->objects as  $k=>$v) {
1857
-      $tmp = 'o_'.$v['t'];
1858
-      $cont = $this->$tmp($k, 'out');
1859
-      $content.= $cont;
1860
-      $xref[] = $pos;
1861
-      $pos+= mb_strlen($cont, '8bit');
1857
+        $tmp = 'o_'.$v['t'];
1858
+        $cont = $this->$tmp($k, 'out');
1859
+        $content.= $cont;
1860
+        $xref[] = $pos;
1861
+        $pos+= mb_strlen($cont, '8bit');
1862 1862
     }
1863 1863
 
1864 1864
     $content.= "\nxref\n0 ".(count($xref) +1) ."\n0000000000 65535 f \n";
1865 1865
 
1866 1866
     foreach($xref as  $p) {
1867
-      $content.= str_pad($p,  10,  "0",  STR_PAD_LEFT)  . " 00000 n \n";
1867
+        $content.= str_pad($p,  10,  "0",  STR_PAD_LEFT)  . " 00000 n \n";
1868 1868
     }
1869 1869
 
1870 1870
     $content.= "trailer\n<<\n/Size ".(count($xref) +1) ."\n/Root 1 0 R\n/Info ".$this->infoObject." 0 R\n";
1871 1871
 
1872 1872
     // if encryption has been applied to this document then add the marker for this dictionary
1873 1873
     if  ($this->arc4_objnum > 0) {
1874
-      $content.=  "/Encrypt ".$this->arc4_objnum." 0 R\n";
1874
+        $content.=  "/Encrypt ".$this->arc4_objnum." 0 R\n";
1875 1875
     }
1876 1876
 
1877 1877
     if  (mb_strlen($this->fileIdentifier, '8bit')) {
1878
-      $content.=  "/ID[<".$this->fileIdentifier."><".$this->fileIdentifier.">]\n";
1878
+        $content.=  "/ID[<".$this->fileIdentifier."><".$this->fileIdentifier.">]\n";
1879 1879
     }
1880 1880
 
1881 1881
     $content.=  ">>\nstartxref\n".$pos."\n%%EOF\n";
1882 1882
 
1883 1883
     return  $content;
1884
-  }
1885
-
1886
-  /**
1887
-   * intialize a new document
1888
-   * if this is called on an existing document results may be unpredictable, but the existing document would be lost at minimum
1889
-   * this function is called automatically by the constructor function
1890
-   *
1891
-   * @access private
1892
-   */
1893
-  function  newDocument($pageSize = array(0, 0, 612, 792)) {
1884
+    }
1885
+
1886
+    /**
1887
+     * intialize a new document
1888
+     * if this is called on an existing document results may be unpredictable, but the existing document would be lost at minimum
1889
+     * this function is called automatically by the constructor function
1890
+     *
1891
+     * @access private
1892
+     */
1893
+    function  newDocument($pageSize = array(0, 0, 612, 792)) {
1894 1894
     $this->numObj = 0;
1895 1895
     $this->objects =  array();
1896 1896
 
@@ -1918,32 +1918,32 @@  discard block
 block discarded – undo
1918 1918
     // need to store the first page id as there is no way to get it to the user during
1919 1919
     // startup
1920 1920
     $this->firstPageId =  $this->currentContents;
1921
-  }
1922
-
1923
-  /**
1924
-   * open the font file and return a php structure containing it.
1925
-   * first check if this one has been done before and saved in a form more suited to php
1926
-   * note that if a php serialized version does not exist it will try and make one, but will
1927
-   * require write access to the directory to do it... it is MUCH faster to have these serialized
1928
-   * files.
1929
-   *
1930
-   * @access private
1931
-   */
1932
-  function  openFont($font) {
1921
+    }
1922
+
1923
+    /**
1924
+     * open the font file and return a php structure containing it.
1925
+     * first check if this one has been done before and saved in a form more suited to php
1926
+     * note that if a php serialized version does not exist it will try and make one, but will
1927
+     * require write access to the directory to do it... it is MUCH faster to have these serialized
1928
+     * files.
1929
+     *
1930
+     * @access private
1931
+     */
1932
+    function  openFont($font) {
1933 1933
     // assume that $font contains the path and file but not the extension
1934 1934
     $pos = strrpos($font, '/');
1935 1935
 
1936 1936
     if  ($pos === false) {
1937
-      $dir =  './';
1938
-      $name =  $font;
1937
+        $dir =  './';
1938
+        $name =  $font;
1939 1939
     } else {
1940
-      $dir = substr($font, 0, $pos+1);
1941
-      $name = substr($font, $pos+1);
1940
+        $dir = substr($font, 0, $pos+1);
1941
+        $name = substr($font, $pos+1);
1942 1942
     }
1943 1943
     
1944 1944
     $fontcache = $this->fontcache;
1945 1945
     if ($fontcache == '') {
1946
-    	$fontcache = $dir;
1946
+        $fontcache = $dir;
1947 1947
     }
1948 1948
     
1949 1949
     //$name       filename without folder and extension of font metrics
@@ -1964,42 +1964,42 @@  discard block
 block discarded – undo
1964 1964
     $cache_name = 'php_' . $metrics_name;
1965 1965
     $this->addMessage('metrics: '.$metrics_name.', cache: '.$cache_name);
1966 1966
     if  (file_exists($fontcache . $cache_name)) {
1967
-      $this->addMessage('openFont: php file exists ' . $fontcache . $cache_name);
1968
-      $tmp =  file_get_contents($fontcache . $cache_name);
1969
-      eval($tmp);
1967
+        $this->addMessage('openFont: php file exists ' . $fontcache . $cache_name);
1968
+        $tmp =  file_get_contents($fontcache . $cache_name);
1969
+        eval($tmp);
1970 1970
 
1971
-      if  (!isset($this->fonts[$font]['_version_']) ||  $this->fonts[$font]['_version_'] != $this->fontcacheVersion) {
1971
+        if  (!isset($this->fonts[$font]['_version_']) ||  $this->fonts[$font]['_version_'] != $this->fontcacheVersion) {
1972 1972
         // if the font file is old, then clear it out and prepare for re-creation
1973 1973
         $this->addMessage('openFont: clear out, make way for new version.');
1974 1974
         unset($this->fonts[$font]);
1975
-      }
1975
+        }
1976 1976
     }
1977 1977
 
1978 1978
     if  (!isset($this->fonts[$font]) &&  file_exists($dir . $metrics_name)) {
1979
-      // then rebuild the php_<font>.afm file from the <font>.afm file
1980
-      $this->addMessage('openFont: build php file from ' . $dir . $metrics_name);
1981
-      $data =  array();
1979
+        // then rebuild the php_<font>.afm file from the <font>.afm file
1980
+        $this->addMessage('openFont: build php file from ' . $dir . $metrics_name);
1981
+        $data =  array();
1982 1982
       
1983
-      // Since we're not going to enable Unicode for the core fonts we need to use a font-based
1984
-      // setting for Unicode support rather than a global setting.
1985
-      $data['isUnicode'] = (strtolower(substr($metrics_name, -3)) !== 'afm');
1983
+        // Since we're not going to enable Unicode for the core fonts we need to use a font-based
1984
+        // setting for Unicode support rather than a global setting.
1985
+        $data['isUnicode'] = (strtolower(substr($metrics_name, -3)) !== 'afm');
1986 1986
       
1987
-      $cidtogid = '';
1988
-      if ($data['isUnicode']) {
1987
+        $cidtogid = '';
1988
+        if ($data['isUnicode']) {
1989 1989
         $cidtogid = str_pad('', 256*256*2, "\x00");
1990
-      }
1990
+        }
1991 1991
 
1992
-      $file =  file($dir . $metrics_name);
1992
+        $file =  file($dir . $metrics_name);
1993 1993
 
1994
-      foreach ($file as  $rowA) {
1994
+        foreach ($file as  $rowA) {
1995 1995
         $row = trim($rowA);
1996 1996
         $pos = strpos($row, ' ');
1997 1997
 
1998 1998
         if  ($pos) {
1999
-          // then there must be some keyword
2000
-          $key =  substr($row, 0, $pos);
2001
-          switch  ($key) {
2002
-          case  'FontName':
1999
+            // then there must be some keyword
2000
+            $key =  substr($row, 0, $pos);
2001
+            switch  ($key) {
2002
+            case  'FontName':
2003 2003
           case  'FullName':
2004 2004
           case  'FamilyName':
2005 2005
           case  'Weight':
@@ -2021,140 +2021,140 @@  discard block
 block discarded – undo
2021 2021
             $data[$key] = trim(substr($row, $pos));
2022 2022
             break;
2023 2023
 
2024
-          case  'FontBBox':
2024
+            case  'FontBBox':
2025 2025
             $data[$key] = explode(' ', trim(substr($row, $pos)));
2026 2026
             break;
2027 2027
 
2028
-          case  'C': // Found in AFM files
2028
+            case  'C': // Found in AFM files
2029 2029
             //C 39 ; WX 222 ; N quoteright ; B 53 463 157 718 ;
2030 2030
             $bits = explode(';', trim($row));
2031 2031
             $dtmp = array();
2032 2032
 
2033 2033
             foreach($bits as  $bit) {
2034
-              $bits2 =  explode(' ', trim($bit));
2035
-              if  (mb_strlen($bits2[0], '8bit')) {
2034
+                $bits2 =  explode(' ', trim($bit));
2035
+                if  (mb_strlen($bits2[0], '8bit')) {
2036 2036
                 if  (count($bits2) >2) {
2037
-                  $dtmp[$bits2[0]] = array();
2038
-                  for  ($i = 1;$i<count($bits2);$i++) {
2037
+                    $dtmp[$bits2[0]] = array();
2038
+                    for  ($i = 1;$i<count($bits2);$i++) {
2039 2039
                     $dtmp[$bits2[0]][] = $bits2[$i];
2040
-                  }
2040
+                    }
2041 2041
                 } else  if  (count($bits2) == 2) {
2042
-                  $dtmp[$bits2[0]] = $bits2[1];
2042
+                    $dtmp[$bits2[0]] = $bits2[1];
2043
+                }
2043 2044
                 }
2044
-              }
2045 2045
             }
2046 2046
 
2047 2047
             $cc = (int)$dtmp['C'];
2048 2048
             if  ($cc >= 0) {
2049
-              $data['C'][$dtmp['C']] = $dtmp;
2050
-              $data['C'][$dtmp['N']] = $dtmp;
2049
+                $data['C'][$dtmp['C']] = $dtmp;
2050
+                $data['C'][$dtmp['N']] = $dtmp;
2051 2051
             } else {
2052
-              $data['C'][$dtmp['N']] = $dtmp;
2052
+                $data['C'][$dtmp['N']] = $dtmp;
2053 2053
             }
2054 2054
 
2055 2055
             if  (!isset($data['MissingWidth']) && $cc == -1 && $dtmp['N'] === '.notdef') {
2056
-              $data['MissingWidth'] = $width;
2056
+                $data['MissingWidth'] = $width;
2057 2057
             }
2058 2058
             
2059 2059
             break;
2060 2060
 
2061
-          case  'U': // Found in UFM files
2061
+            case  'U': // Found in UFM files
2062 2062
             if ($data['isUnicode']) {
2063
-              // U 827 ; WX 0 ; N squaresubnosp ; G 675 ;
2064
-              $bits = explode(';', trim($row));
2065
-              $dtmp = array();
2063
+                // U 827 ; WX 0 ; N squaresubnosp ; G 675 ;
2064
+                $bits = explode(';', trim($row));
2065
+                $dtmp = array();
2066 2066
 
2067
-              foreach($bits as  $bit) {
2067
+                foreach($bits as  $bit) {
2068 2068
                 $bits2 =  explode(' ', trim($bit));
2069 2069
                 if  (mb_strlen($bits2[0], '8bit')) {
2070
-                  if  (count($bits2) >2) {
2070
+                    if  (count($bits2) >2) {
2071 2071
                     $dtmp[$bits2[0]] = array();
2072 2072
                     for  ($i = 1;$i<count($bits2);$i++) {
2073
-                      $dtmp[$bits2[0]][] = $bits2[$i];
2073
+                        $dtmp[$bits2[0]][] = $bits2[$i];
2074 2074
                     }
2075
-                  } else  if  (count($bits2) == 2) {
2075
+                    } else  if  (count($bits2) == 2) {
2076 2076
                     $dtmp[$bits2[0]] = $bits2[1];
2077
-                  }
2077
+                    }
2078
+                }
2078 2079
                 }
2079
-              }
2080 2080
 
2081
-              $cc = (int)$dtmp['U'];
2082
-              $glyph = $dtmp['G'];
2083
-              $width = $dtmp['WX'];
2084
-              if  ($cc >= 0) {
2081
+                $cc = (int)$dtmp['U'];
2082
+                $glyph = $dtmp['G'];
2083
+                $width = $dtmp['WX'];
2084
+                if  ($cc >= 0) {
2085 2085
                 // Set values in CID to GID map
2086 2086
                 if ($cc >= 0 && $cc < 0xFFFF && $glyph) {
2087
-                  $cidtogid[$cc*2] = chr($glyph >> 8);
2088
-                  $cidtogid[$cc*2 + 1] = chr($glyph & 0xFF);
2087
+                    $cidtogid[$cc*2] = chr($glyph >> 8);
2088
+                    $cidtogid[$cc*2 + 1] = chr($glyph & 0xFF);
2089 2089
                 }
2090 2090
 
2091 2091
                 $data['C'][$dtmp['U']] = $dtmp;
2092 2092
                 $data['C'][$dtmp['N']] = $dtmp;
2093
-              } else {
2093
+                } else {
2094 2094
                 $data['C'][$dtmp['N']] = $dtmp;
2095
-              }
2095
+                }
2096 2096
               
2097
-              if  (!isset($data['MissingWidth']) && $cc == -1 && $dtmp['N'] === '.notdef') {
2097
+                if  (!isset($data['MissingWidth']) && $cc == -1 && $dtmp['N'] === '.notdef') {
2098 2098
                 $data['MissingWidth'] = $width;
2099
-              }
2099
+                }
2100 2100
             }
2101 2101
             break;
2102 2102
 
2103
-          case  'KPX':
2103
+            case  'KPX':
2104 2104
             //KPX Adieresis yacute -40
2105 2105
             $bits = explode(' ', trim($row));
2106 2106
             $data['KPX'][$bits[1]][$bits[2]] = $bits[3];
2107 2107
             break;
2108
-          }
2108
+            }
2109
+        }
2109 2110
         }
2110
-      }
2111 2111
 
2112
-      //    echo $cidtogid; die("CIDtoGID Displayed!");
2113
-      if  (function_exists('gzcompress') &&  $this->options['compression']) {
2112
+        //    echo $cidtogid; die("CIDtoGID Displayed!");
2113
+        if  (function_exists('gzcompress') &&  $this->options['compression']) {
2114 2114
         // then implement ZLIB based compression on CIDtoGID string
2115 2115
         $data['CIDtoGID_Compressed'] = true;
2116 2116
         $cidtogid =  gzcompress($cidtogid,  6);
2117
-      }
2118
-      $data['CIDtoGID'] = base64_encode($cidtogid);
2119
-      $data['_version_'] = $this->fontcacheVersion;
2120
-      $this->fonts[$font] = $data;
2121
-
2122
-      //Because of potential trouble with php safe mode, expect that the folder already exists.
2123
-      //If not existing, this will hit performance because of missing cached results.
2124
-      if ( is_dir(substr($fontcache,0,-1)) ) {
2117
+        }
2118
+        $data['CIDtoGID'] = base64_encode($cidtogid);
2119
+        $data['_version_'] = $this->fontcacheVersion;
2120
+        $this->fonts[$font] = $data;
2121
+
2122
+        //Because of potential trouble with php safe mode, expect that the folder already exists.
2123
+        //If not existing, this will hit performance because of missing cached results.
2124
+        if ( is_dir(substr($fontcache,0,-1)) ) {
2125 2125
         file_put_contents($fontcache . $cache_name,  '$this->fonts[$font]=' . var_export($data,  true)  . ';');
2126
-      }
2126
+        }
2127 2127
     }
2128 2128
     
2129 2129
     if  (!isset($this->fonts[$font])) {
2130
-      $this->addMessage("openFont: no font file found for $font.  Do you need to run load_font.php?");
2131
-      //echo 'Font not Found '.$font;
2130
+        $this->addMessage("openFont: no font file found for $font.  Do you need to run load_font.php?");
2131
+        //echo 'Font not Found '.$font;
2132 2132
     }
2133 2133
 
2134 2134
     //pre_r($this->messages);
2135
-  }
2136
-
2137
-  /**
2138
-   * if the font is not loaded then load it and make the required object
2139
-   * else just make it the current font
2140
-   * the encoding array can contain 'encoding'=> 'none','WinAnsiEncoding','MacRomanEncoding' or 'MacExpertEncoding'
2141
-   * note that encoding='none' will need to be used for symbolic fonts
2142
-   * and 'differences' => an array of mappings between numbers 0->255 and character names.
2143
-   *
2144
-   */
2145
-  function  selectFont($fontName, $encoding =  '', $set =  true) {
2135
+    }
2136
+
2137
+    /**
2138
+     * if the font is not loaded then load it and make the required object
2139
+     * else just make it the current font
2140
+     * the encoding array can contain 'encoding'=> 'none','WinAnsiEncoding','MacRomanEncoding' or 'MacExpertEncoding'
2141
+     * note that encoding='none' will need to be used for symbolic fonts
2142
+     * and 'differences' => an array of mappings between numbers 0->255 and character names.
2143
+     *
2144
+     */
2145
+    function  selectFont($fontName, $encoding =  '', $set =  true) {
2146 2146
     $ext = substr($fontName, -4);
2147 2147
     if  ($ext === '.afm' || $ext === '.ufm') {
2148
-      $fontName = substr($fontName, 0, mb_strlen($fontName)-4);
2148
+        $fontName = substr($fontName, 0, mb_strlen($fontName)-4);
2149 2149
     }
2150 2150
 
2151 2151
     if  (!isset($this->fonts[$fontName])) {
2152
-      $this->addMessage("selectFont: selecting - $fontName - $encoding, $set");
2152
+        $this->addMessage("selectFont: selecting - $fontName - $encoding, $set");
2153 2153
 
2154
-      // load the file
2155
-      $this->openFont($fontName);
2154
+        // load the file
2155
+        $this->openFont($fontName);
2156 2156
 
2157
-      if  (isset($this->fonts[$fontName])) {
2157
+        if  (isset($this->fonts[$fontName])) {
2158 2158
         $this->numObj++;
2159 2159
         $this->numFonts++;
2160 2160
 
@@ -2165,17 +2165,17 @@  discard block
 block discarded – undo
2165 2165
         $options =  array('name' => $name, 'fontFileName' => $fontName);
2166 2166
 
2167 2167
         if  (is_array($encoding)) {
2168
-          // then encoding and differences might be set
2169
-          if  (isset($encoding['encoding'])) {
2168
+            // then encoding and differences might be set
2169
+            if  (isset($encoding['encoding'])) {
2170 2170
             $options['encoding'] =  $encoding['encoding'];
2171
-          }
2171
+            }
2172 2172
 
2173
-          if  (isset($encoding['differences'])) {
2173
+            if  (isset($encoding['differences'])) {
2174 2174
             $options['differences'] =  $encoding['differences'];
2175
-          }
2175
+            }
2176 2176
         } else  if  (mb_strlen($encoding, '8bit')) {
2177
-          // then perhaps only the encoding has been set
2178
-          $options['encoding'] =  $encoding;
2177
+            // then perhaps only the encoding has been set
2178
+            $options['encoding'] =  $encoding;
2179 2179
         }
2180 2180
 
2181 2181
         $fontObj =  $this->numObj;
@@ -2187,11 +2187,11 @@  discard block
 block discarded – undo
2187 2187
         // references into the font object
2188 2188
         $basefile =  $fontName;
2189 2189
         if  (file_exists($basefile.'.pfb')) {
2190
-          $fbtype =  'pfb';
2190
+            $fbtype =  'pfb';
2191 2191
         } else  if  (file_exists($basefile.'.ttf')) {
2192
-          $fbtype =  'ttf';
2192
+            $fbtype =  'ttf';
2193 2193
         } else {
2194
-          $fbtype =  '';
2194
+            $fbtype =  '';
2195 2195
         }
2196 2196
 
2197 2197
         $fbfile =  $basefile.'.'.$fbtype;
@@ -2203,74 +2203,74 @@  discard block
 block discarded – undo
2203 2203
         // OAR - I don't understand this old check
2204 2204
         // if  (substr($fontName, -4) ===  '.afm' &&  strlen($fbtype)) {
2205 2205
         if  (mb_strlen($fbtype, '8bit')) {
2206
-          $adobeFontName =  $this->fonts[$fontName]['FontName'];
2207
-          //        $fontObj = $this->numObj;
2208
-          $this->addMessage('selectFont: adding font file - '.$fbfile.' - '.$adobeFontName);
2206
+            $adobeFontName =  $this->fonts[$fontName]['FontName'];
2207
+            //        $fontObj = $this->numObj;
2208
+            $this->addMessage('selectFont: adding font file - '.$fbfile.' - '.$adobeFontName);
2209 2209
 
2210
-          // find the array of font widths, and put that into an object.
2211
-          $firstChar =  -1;
2212
-          $lastChar =  0;
2213
-          $widths =  array();
2214
-          $cid_widths = array();
2210
+            // find the array of font widths, and put that into an object.
2211
+            $firstChar =  -1;
2212
+            $lastChar =  0;
2213
+            $widths =  array();
2214
+            $cid_widths = array();
2215 2215
 
2216
-          foreach ($this->fonts[$fontName]['C'] as  $num => $d) {
2216
+            foreach ($this->fonts[$fontName]['C'] as  $num => $d) {
2217 2217
             if  (intval($num) >0 ||  $num ==  '0') {
2218
-              if (!$this->fonts[$fontName]['isUnicode']) {
2218
+                if (!$this->fonts[$fontName]['isUnicode']) {
2219 2219
                 // With Unicode, widths array isn't used
2220 2220
                 if  ($lastChar>0 &&  $num>$lastChar+1) {
2221
-                  for ($i =  $lastChar+1;$i<$num;$i++) {
2221
+                    for ($i =  $lastChar+1;$i<$num;$i++) {
2222 2222
                     $widths[] =  0;
2223
-                  }
2223
+                    }
2224
+                }
2224 2225
                 }
2225
-              }
2226 2226
 
2227
-              $widths[] =  $d['WX'];
2227
+                $widths[] =  $d['WX'];
2228 2228
 
2229
-              if ($this->fonts[$fontName]['isUnicode']) {
2229
+                if ($this->fonts[$fontName]['isUnicode']) {
2230 2230
                 $cid_widths[$num] =  $d['WX'];
2231
-              }
2231
+                }
2232 2232
 
2233
-              if  ($firstChar ==  -1) {
2233
+                if  ($firstChar ==  -1) {
2234 2234
                 $firstChar =  $num;
2235
-              }
2235
+                }
2236 2236
 
2237
-              $lastChar =  $num;
2237
+                $lastChar =  $num;
2238
+            }
2238 2239
             }
2239
-          }
2240 2240
 
2241
-          // also need to adjust the widths for the differences array
2242
-          if  (isset($options['differences'])) {
2241
+            // also need to adjust the widths for the differences array
2242
+            if  (isset($options['differences'])) {
2243 2243
             foreach($options['differences'] as  $charNum => $charName) {
2244
-              if  ($charNum > $lastChar) {
2244
+                if  ($charNum > $lastChar) {
2245 2245
                 if (!$this->fonts[$fontName]['isUnicode']) {
2246
-                  // With Unicode, widths array isn't used
2247
-                  for ($i =  $lastChar + 1; $i <=  $charNum; $i++) {
2246
+                    // With Unicode, widths array isn't used
2247
+                    for ($i =  $lastChar + 1; $i <=  $charNum; $i++) {
2248 2248
                     $widths[] =  0;
2249
-                  }
2249
+                    }
2250 2250
                 }
2251 2251
 
2252 2252
                 $lastChar =  $charNum;
2253
-              }
2253
+                }
2254 2254
 
2255
-              if  (isset($this->fonts[$fontName]['C'][$charName])) {
2255
+                if  (isset($this->fonts[$fontName]['C'][$charName])) {
2256 2256
                 $widths[$charNum-$firstChar] =  $this->fonts[$fontName]['C'][$charName]['WX'];
2257 2257
                 if ($this->fonts[$fontName]['isUnicode']) {
2258
-                  $cid_widths[$charName] =  $this->fonts[$fontName]['C'][$charName]['WX'];
2258
+                    $cid_widths[$charName] =  $this->fonts[$fontName]['C'][$charName]['WX'];
2259 2259
                 }
2260
-              }
2260
+                }
2261
+            }
2261 2262
             }
2262
-          }
2263 2263
 
2264
-          if ($this->fonts[$fontName]['isUnicode']) {
2264
+            if ($this->fonts[$fontName]['isUnicode']) {
2265 2265
             $this->fonts[$fontName]['CIDWidths'] = $cid_widths;
2266
-          }
2266
+            }
2267 2267
 
2268
-          $this->addMessage('selectFont: FirstChar = '.$firstChar);
2269
-          $this->addMessage('selectFont: LastChar = '.$lastChar);
2268
+            $this->addMessage('selectFont: FirstChar = '.$firstChar);
2269
+            $this->addMessage('selectFont: LastChar = '.$lastChar);
2270 2270
 
2271
-          $widthid = -1;
2271
+            $widthid = -1;
2272 2272
 
2273
-          if (!$this->fonts[$fontName]['isUnicode']) {
2273
+            if (!$this->fonts[$fontName]['isUnicode']) {
2274 2274
             // With Unicode, widths array isn't used
2275 2275
 
2276 2276
             $this->numObj++;
@@ -2278,147 +2278,147 @@  discard block
 block discarded – undo
2278 2278
             $this->objects[$this->numObj]['c'].=  '[';
2279 2279
 
2280 2280
             foreach($widths as  $width) {
2281
-              $this->objects[$this->numObj]['c'].=  ' '.$width;
2281
+                $this->objects[$this->numObj]['c'].=  ' '.$width;
2282 2282
             }
2283 2283
 
2284 2284
             $this->objects[$this->numObj]['c'].=  ' ]';
2285 2285
             $widthid =  $this->numObj;
2286
-          }
2286
+            }
2287 2287
 
2288
-          $missing_width = 500;
2289
-          $stemV = 70;
2288
+            $missing_width = 500;
2289
+            $stemV = 70;
2290 2290
 
2291
-          if (isset($this->fonts[$fontName]['MissingWidth'])) {
2291
+            if (isset($this->fonts[$fontName]['MissingWidth'])) {
2292 2292
             $missing_width =  $this->fonts[$fontName]['MissingWidth'];
2293
-          }
2294
-          if (isset($this->fonts[$fontName]['StdVW'])) {
2293
+            }
2294
+            if (isset($this->fonts[$fontName]['StdVW'])) {
2295 2295
             $stemV = $this->fonts[$fontName]['StdVW'];
2296
-          } elseif (isset($this->fonts[$fontName]['Weight']) && preg_match('!(bold|black)!i', $this->fonts[$fontName]['Weight'])) {
2296
+            } elseif (isset($this->fonts[$fontName]['Weight']) && preg_match('!(bold|black)!i', $this->fonts[$fontName]['Weight'])) {
2297 2297
             $stemV = 120;
2298
-          }
2298
+            }
2299 2299
 
2300
-          // load the pfb file, and put that into an object too.
2301
-          // note that pdf supports only binary format type 1 font files, though there is a
2302
-          // simple utility to convert them from pfa to pfb.
2303
-          $data =  file_get_contents($fbfile);
2300
+            // load the pfb file, and put that into an object too.
2301
+            // note that pdf supports only binary format type 1 font files, though there is a
2302
+            // simple utility to convert them from pfa to pfb.
2303
+            $data =  file_get_contents($fbfile);
2304 2304
 
2305
-          // create the font descriptor
2306
-          $this->numObj++;
2307
-          $fontDescriptorId =  $this->numObj;
2305
+            // create the font descriptor
2306
+            $this->numObj++;
2307
+            $fontDescriptorId =  $this->numObj;
2308 2308
 
2309
-          $this->numObj++;
2310
-          $pfbid =  $this->numObj;
2309
+            $this->numObj++;
2310
+            $pfbid =  $this->numObj;
2311 2311
 
2312
-          // determine flags (more than a little flakey, hopefully will not matter much)
2313
-          $flags =  0;
2312
+            // determine flags (more than a little flakey, hopefully will not matter much)
2313
+            $flags =  0;
2314 2314
 
2315
-          if  ($this->fonts[$fontName]['ItalicAngle'] !=  0) {
2315
+            if  ($this->fonts[$fontName]['ItalicAngle'] !=  0) {
2316 2316
             $flags+=  pow(2, 6);
2317
-          }
2317
+            }
2318 2318
 
2319
-          if  ($this->fonts[$fontName]['IsFixedPitch'] === 'true') {
2319
+            if  ($this->fonts[$fontName]['IsFixedPitch'] === 'true') {
2320 2320
             $flags+=  1;
2321
-          }
2321
+            }
2322 2322
 
2323
-          $flags+=  pow(2, 5); // assume non-sybolic
2324
-          $list =  array(
2323
+            $flags+=  pow(2, 5); // assume non-sybolic
2324
+            $list =  array(
2325 2325
             'Ascent' => 'Ascender', 
2326 2326
             'CapHeight' => 'CapHeight', 
2327 2327
             'MissingWidth' => 'MissingWidth', 
2328 2328
             'Descent' => 'Descender', 
2329 2329
             'FontBBox' => 'FontBBox', 
2330 2330
             'ItalicAngle' => 'ItalicAngle'
2331
-          );
2332
-          $fdopt =  array(
2331
+            );
2332
+            $fdopt =  array(
2333 2333
             'Flags' => $flags, 
2334 2334
             'FontName' => $adobeFontName, 
2335 2335
             'StemV' => $stemV
2336
-          );
2336
+            );
2337 2337
 
2338
-          foreach($list as  $k => $v) {
2338
+            foreach($list as  $k => $v) {
2339 2339
             if  (isset($this->fonts[$fontName][$v])) {
2340
-              $fdopt[$k] =  $this->fonts[$fontName][$v];
2340
+                $fdopt[$k] =  $this->fonts[$fontName][$v];
2341
+            }
2341 2342
             }
2342
-          }
2343 2343
 
2344
-          if  ($fbtype === 'pfb') {
2344
+            if  ($fbtype === 'pfb') {
2345 2345
             $fdopt['FontFile'] =  $pfbid;
2346
-          } else  if  ($fbtype === 'ttf') {
2346
+            } else  if  ($fbtype === 'ttf') {
2347 2347
             $fdopt['FontFile2'] =  $pfbid;
2348
-          }
2348
+            }
2349 2349
 
2350
-          $this->o_fontDescriptor($fontDescriptorId, 'new', $fdopt);
2350
+            $this->o_fontDescriptor($fontDescriptorId, 'new', $fdopt);
2351 2351
 
2352
-          // embed the font program
2353
-          $this->o_contents($this->numObj, 'new');
2354
-          $this->objects[$pfbid]['c'].=  $data;
2352
+            // embed the font program
2353
+            $this->o_contents($this->numObj, 'new');
2354
+            $this->objects[$pfbid]['c'].=  $data;
2355 2355
 
2356
-          // determine the cruicial lengths within this file
2357
-          if  ($fbtype === 'pfb') {
2356
+            // determine the cruicial lengths within this file
2357
+            if  ($fbtype === 'pfb') {
2358 2358
             $l1 =  strpos($data, 'eexec') +6;
2359 2359
             $l2 =  strpos($data, '00000000') -$l1;
2360 2360
             $l3 =  mb_strlen($data, '8bit') -$l2-$l1;
2361 2361
             $this->o_contents($this->numObj, 'add', array('Length1' => $l1, 'Length2' => $l2, 'Length3' => $l3));
2362
-          } else  if  ($fbtype == 'ttf') {
2362
+            } else  if  ($fbtype == 'ttf') {
2363 2363
             $l1 =  mb_strlen($data, '8bit');
2364 2364
             $this->o_contents($this->numObj, 'add', array('Length1' => $l1));
2365
-          }
2365
+            }
2366 2366
 
2367
-          // tell the font object about all this new stuff
2368
-          $tmp =  array('BaseFont' => $adobeFontName, 'MissingWidth' => $missing_width, 'Widths' => $widthid, 'FirstChar' => $firstChar, 'LastChar' => $lastChar, 'FontDescriptor' => $fontDescriptorId);
2367
+            // tell the font object about all this new stuff
2368
+            $tmp =  array('BaseFont' => $adobeFontName, 'MissingWidth' => $missing_width, 'Widths' => $widthid, 'FirstChar' => $firstChar, 'LastChar' => $lastChar, 'FontDescriptor' => $fontDescriptorId);
2369 2369
 
2370
-          if  ($fbtype === 'ttf') {
2370
+            if  ($fbtype === 'ttf') {
2371 2371
             $tmp['SubType'] =  'TrueType';
2372
-          }
2372
+            }
2373 2373
 
2374
-          $this->addMessage('adding extra info to font.('.$fontObj.')');
2374
+            $this->addMessage('adding extra info to font.('.$fontObj.')');
2375 2375
 
2376
-          foreach($tmp as  $fk => $fv) {
2376
+            foreach($tmp as  $fk => $fv) {
2377 2377
             $this->addMessage($fk." : ".$fv);
2378
-          }
2378
+            }
2379 2379
 
2380
-          $this->o_font($fontObj, 'add', $tmp);
2380
+            $this->o_font($fontObj, 'add', $tmp);
2381 2381
         } else {
2382
-          $this->addMessage('selectFont: pfb or ttf file not found, ok if this is one of the 14 standard fonts');
2382
+            $this->addMessage('selectFont: pfb or ttf file not found, ok if this is one of the 14 standard fonts');
2383 2383
         }
2384 2384
 
2385 2385
         // also set the differences here, note that this means that these will take effect only the
2386 2386
         //first time that a font is selected, else they are ignored
2387 2387
         if  (isset($options['differences'])) {
2388
-          $this->fonts[$fontName]['differences'] =  $options['differences'];
2388
+            $this->fonts[$fontName]['differences'] =  $options['differences'];
2389
+        }
2389 2390
         }
2390
-      }
2391 2391
     }
2392 2392
 
2393 2393
     if  ($set &&  isset($this->fonts[$fontName])) {
2394
-      // so if for some reason the font was not set in the last one then it will not be selected
2395
-      $this->currentBaseFont =  $fontName;
2394
+        // so if for some reason the font was not set in the last one then it will not be selected
2395
+        $this->currentBaseFont =  $fontName;
2396 2396
 
2397
-      // the next lines mean that if a new font is selected, then the current text state will be
2398
-      // applied to it as well.
2399
-      $this->currentFont =  $this->currentBaseFont;
2400
-      $this->currentFontNum =  $this->fonts[$this->currentFont]['fontNum'];
2397
+        // the next lines mean that if a new font is selected, then the current text state will be
2398
+        // applied to it as well.
2399
+        $this->currentFont =  $this->currentBaseFont;
2400
+        $this->currentFontNum =  $this->fonts[$this->currentFont]['fontNum'];
2401 2401
 
2402
-      //$this->setCurrentFont();
2402
+        //$this->setCurrentFont();
2403 2403
     }
2404 2404
 
2405 2405
     return  $this->currentFontNum;
2406 2406
     //return $this->numObj;
2407
-  }
2408
-
2409
-  /**
2410
-   * sets up the current font, based on the font families, and the current text state
2411
-   * note that this system is quite flexible, a bold-italic font can be completely different to a
2412
-   * italic-bold font, and even bold-bold will have to be defined within the family to have meaning
2413
-   * This function is to be called whenever the currentTextState is changed, it will update
2414
-   * the currentFont setting to whatever the appropriatte family one is.
2415
-   * If the user calls selectFont themselves then that will reset the currentBaseFont, and the currentFont
2416
-   * This function will change the currentFont to whatever it should be, but will not change the
2417
-   * currentBaseFont.
2418
-   *
2419
-   * @access private
2420
-   */
2421
-  function  setCurrentFont() {
2407
+    }
2408
+
2409
+    /**
2410
+     * sets up the current font, based on the font families, and the current text state
2411
+     * note that this system is quite flexible, a bold-italic font can be completely different to a
2412
+     * italic-bold font, and even bold-bold will have to be defined within the family to have meaning
2413
+     * This function is to be called whenever the currentTextState is changed, it will update
2414
+     * the currentFont setting to whatever the appropriatte family one is.
2415
+     * If the user calls selectFont themselves then that will reset the currentBaseFont, and the currentFont
2416
+     * This function will change the currentFont to whatever it should be, but will not change the
2417
+     * currentBaseFont.
2418
+     *
2419
+     * @access private
2420
+     */
2421
+    function  setCurrentFont() {
2422 2422
     //   if (strlen($this->currentBaseFont) == 0){
2423 2423
     //     // then assume an initial font
2424 2424
     //     $this->selectFont($this->defaultFont);
@@ -2440,185 +2440,185 @@  discard block
 block discarded – undo
2440 2440
     $this->currentFont =  $this->currentBaseFont;
2441 2441
     $this->currentFontNum =  $this->fonts[$this->currentFont]['fontNum'];
2442 2442
     //  }
2443
-  }
2443
+    }
2444 2444
 
2445 2445
 
2446
-  /**
2447
-   * function for the user to find out what the ID is of the first page that was created during
2448
-   * startup - useful if they wish to add something to it later.
2449
-   */
2450
-  function  getFirstPageId() {
2446
+    /**
2447
+     * function for the user to find out what the ID is of the first page that was created during
2448
+     * startup - useful if they wish to add something to it later.
2449
+     */
2450
+    function  getFirstPageId() {
2451 2451
     return  $this->firstPageId;
2452
-  }
2452
+    }
2453 2453
 
2454 2454
 
2455
-  /**
2456
-   * add content to the currently active object
2457
-   *
2458
-   * @access private
2459
-   */
2460
-  function  addContent($content) {
2455
+    /**
2456
+     * add content to the currently active object
2457
+     *
2458
+     * @access private
2459
+     */
2460
+    function  addContent($content) {
2461 2461
     $this->objects[$this->currentContents]['c'].=  $content;
2462
-  }
2462
+    }
2463 2463
 
2464 2464
 
2465
-  /**
2466
-   * sets the colour for fill operations
2467
-   */
2468
-  function  setColor($r, $g, $b, $force =  0) {
2465
+    /**
2466
+     * sets the colour for fill operations
2467
+     */
2468
+    function  setColor($r, $g, $b, $force =  0) {
2469 2469
     if  ($r >=  0 &&  ($force ||  $r !=  $this->currentColour['r'] ||  $g !=  $this->currentColour['g'] ||  $b !=  $this->currentColour['b'])) {
2470
-      $this->objects[$this->currentContents]['c'].=  "\n".sprintf('%.3F', $r) .' '.sprintf('%.3F', $g) .' '.sprintf('%.3F', $b) .' rg';
2471
-      $this->currentColour =  array('r' => $r, 'g' => $g, 'b' => $b);
2470
+        $this->objects[$this->currentContents]['c'].=  "\n".sprintf('%.3F', $r) .' '.sprintf('%.3F', $g) .' '.sprintf('%.3F', $b) .' rg';
2471
+        $this->currentColour =  array('r' => $r, 'g' => $g, 'b' => $b);
2472
+    }
2472 2473
     }
2473
-  }
2474 2474
 
2475 2475
 
2476
-  /**
2477
-   * sets the colour for stroke operations
2478
-   */
2479
-  function  setStrokeColor($r, $g, $b, $force =  0) {
2476
+    /**
2477
+     * sets the colour for stroke operations
2478
+     */
2479
+    function  setStrokeColor($r, $g, $b, $force =  0) {
2480 2480
     if  ($r >=  0 &&  ($force ||  $r !=  $this->currentStrokeColour['r'] ||  $g !=  $this->currentStrokeColour['g'] ||  $b !=  $this->currentStrokeColour['b'])) {
2481
-      $this->objects[$this->currentContents]['c'].=  "\n".sprintf('%.3F', $r) .' '.sprintf('%.3F', $g) .' '.sprintf('%.3F', $b) .' RG';
2482
-      $this->currentStrokeColour =  array('r' => $r, 'g' => $g, 'b' => $b);
2481
+        $this->objects[$this->currentContents]['c'].=  "\n".sprintf('%.3F', $r) .' '.sprintf('%.3F', $g) .' '.sprintf('%.3F', $b) .' RG';
2482
+        $this->currentStrokeColour =  array('r' => $r, 'g' => $g, 'b' => $b);
2483
+    }
2483 2484
     }
2484
-  }
2485 2485
 
2486 2486
 
2487
-  /**
2488
-   * Set the graphics state for compositions
2489
-   */
2490
-  function  setGraphicsState($parameters) {
2487
+    /**
2488
+     * Set the graphics state for compositions
2489
+     */
2490
+    function  setGraphicsState($parameters) {
2491 2491
     // Create a new graphics state object
2492 2492
     // FIXME: should actually keep track of states that have already been created...
2493 2493
     $this->numObj++;
2494 2494
     $this->o_extGState($this->numObj,  'new',  $parameters);
2495 2495
     $this->objects[ $this->currentContents ]['c'].=  "\n/GS" . $this->numStates . " gs";
2496
-  }
2497
-
2498
-
2499
-  /**
2500
-   * Set current blend mode & opacity for lines.
2501
-   *
2502
-   * Valid blend modes are:
2503
-   *
2504
-   * Normal, Multiply, Screen, Overlay, Darken, Lighten,
2505
-   * ColorDogde, ColorBurn, HardLight, SoftLight, Difference,
2506
-   * Exclusion
2507
-   *
2508
-   * @param string $mode the blend mode to use
2509
-   * @param float $opacity 0.0 fully transparent, 1.0 fully opaque
2510
-   */
2511
-  function setLineTransparency($mode, $opacity) {
2496
+    }
2497
+
2498
+
2499
+    /**
2500
+     * Set current blend mode & opacity for lines.
2501
+     *
2502
+     * Valid blend modes are:
2503
+     *
2504
+     * Normal, Multiply, Screen, Overlay, Darken, Lighten,
2505
+     * ColorDogde, ColorBurn, HardLight, SoftLight, Difference,
2506
+     * Exclusion
2507
+     *
2508
+     * @param string $mode the blend mode to use
2509
+     * @param float $opacity 0.0 fully transparent, 1.0 fully opaque
2510
+     */
2511
+    function setLineTransparency($mode, $opacity) {
2512 2512
     static $blend_modes = array("Normal", "Multiply", "Screen",
2513 2513
                                 "Overlay", "Darken", "Lighten",
2514 2514
                                 "ColorDogde", "ColorBurn", "HardLight",
2515 2515
                                 "SoftLight", "Difference", "Exclusion");
2516 2516
 
2517 2517
     if ( !in_array($mode, $blend_modes) )
2518
-      $mode = "Normal";
2518
+        $mode = "Normal";
2519 2519
     
2520 2520
     // Only create a new graphics state if required
2521 2521
     if ( $mode == $this->currentLineTransparency["mode"]  &&
2522 2522
          $opacity == $this->currentLineTransparency["opacity"] )
2523
-      return;
2523
+        return;
2524 2524
 
2525 2525
     $options = array("BM" => "/$mode",
2526
-                     "CA" => (float)$opacity);
2526
+                        "CA" => (float)$opacity);
2527 2527
 
2528 2528
     $this->setGraphicsState($options);
2529
-  }
2529
+    }
2530 2530
   
2531
-  /**
2532
-   * Set current blend mode & opacity for filled objects.
2533
-   *
2534
-   * Valid blend modes are:
2535
-   *
2536
-   * Normal, Multiply, Screen, Overlay, Darken, Lighten,
2537
-   * ColorDogde, ColorBurn, HardLight, SoftLight, Difference,
2538
-   * Exclusion
2539
-   *
2540
-   * @param string $mode the blend mode to use
2541
-   * @param float $opacity 0.0 fully transparent, 1.0 fully opaque
2542
-   */
2543
-  function setFillTransparency($mode, $opacity) {
2531
+    /**
2532
+     * Set current blend mode & opacity for filled objects.
2533
+     *
2534
+     * Valid blend modes are:
2535
+     *
2536
+     * Normal, Multiply, Screen, Overlay, Darken, Lighten,
2537
+     * ColorDogde, ColorBurn, HardLight, SoftLight, Difference,
2538
+     * Exclusion
2539
+     *
2540
+     * @param string $mode the blend mode to use
2541
+     * @param float $opacity 0.0 fully transparent, 1.0 fully opaque
2542
+     */
2543
+    function setFillTransparency($mode, $opacity) {
2544 2544
     static $blend_modes = array("Normal", "Multiply", "Screen",
2545 2545
                                 "Overlay", "Darken", "Lighten",
2546 2546
                                 "ColorDogde", "ColorBurn", "HardLight",
2547 2547
                                 "SoftLight", "Difference", "Exclusion");
2548 2548
 
2549 2549
     if ( !in_array($mode, $blend_modes) )
2550
-      $mode = "Normal";
2550
+        $mode = "Normal";
2551 2551
 
2552 2552
     if ( $mode == $this->currentFillTransparency["mode"]  &&
2553 2553
          $opacity == $this->currentFillTransparency["opacity"] )
2554
-      return;
2554
+        return;
2555 2555
 
2556 2556
     $options = array("BM" => "/$mode",
2557
-                     "ca" => (float)$opacity);
2557
+                        "ca" => (float)$opacity);
2558 2558
     
2559 2559
     $this->setGraphicsState($options);
2560
-  }
2560
+    }
2561 2561
 
2562
-  /**
2563
-   * draw a line from one set of coordinates to another
2564
-   */
2565
-  function  line($x1, $y1, $x2, $y2) {
2562
+    /**
2563
+     * draw a line from one set of coordinates to another
2564
+     */
2565
+    function  line($x1, $y1, $x2, $y2) {
2566 2566
     $this->objects[$this->currentContents]['c'] .=
2567
-      "\n".sprintf('%.3F', $x1) .' '.sprintf('%.3F', $y1) .' m '.sprintf('%.3F', $x2) .' '.sprintf('%.3F', $y2) .' l S';
2568
-  }
2567
+        "\n".sprintf('%.3F', $x1) .' '.sprintf('%.3F', $y1) .' m '.sprintf('%.3F', $x2) .' '.sprintf('%.3F', $y2) .' l S';
2568
+    }
2569 2569
 
2570 2570
 
2571
-  /**
2572
-   * draw a bezier curve based on 4 control points
2573
-   */
2574
-  function  curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3) {
2571
+    /**
2572
+     * draw a bezier curve based on 4 control points
2573
+     */
2574
+    function  curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3) {
2575 2575
     // in the current line style, draw a bezier curve from (x0,y0) to (x3,y3) using the other two points
2576 2576
     // as the control points for the curve.
2577 2577
     $this->objects[$this->currentContents]['c'] .=
2578
-      "\n".sprintf('%.3F', $x0) .' '.sprintf('%.3F', $y0) .' m '.sprintf('%.3F', $x1) .' '.sprintf('%.3F', $y1);
2578
+        "\n".sprintf('%.3F', $x0) .' '.sprintf('%.3F', $y0) .' m '.sprintf('%.3F', $x1) .' '.sprintf('%.3F', $y1);
2579 2579
 
2580 2580
     $this->objects[$this->currentContents]['c'] .=
2581
-      ' '.sprintf('%.3F', $x2) .' '.sprintf('%.3F', $y2) .' '.sprintf('%.3F', $x3) .' '.sprintf('%.3F', $y3) .' c S';
2582
-  }
2581
+        ' '.sprintf('%.3F', $x2) .' '.sprintf('%.3F', $y2) .' '.sprintf('%.3F', $x3) .' '.sprintf('%.3F', $y3) .' c S';
2582
+    }
2583 2583
 
2584 2584
 
2585
-  /**
2586
-   * draw a part of an ellipse
2587
-   */
2588
-  function  partEllipse($x0, $y0, $astart, $afinish, $r1, $r2 =  0, $angle =  0, $nSeg =  8) {
2585
+    /**
2586
+     * draw a part of an ellipse
2587
+     */
2588
+    function  partEllipse($x0, $y0, $astart, $afinish, $r1, $r2 =  0, $angle =  0, $nSeg =  8) {
2589 2589
     $this->ellipse($x0, $y0, $r1, $r2, $angle, $nSeg, $astart, $afinish, 0);
2590
-  }
2590
+    }
2591 2591
 
2592 2592
 
2593
-  /**
2594
-   * draw a filled ellipse
2595
-   */
2596
-  function  filledEllipse($x0, $y0, $r1, $r2 =  0, $angle =  0, $nSeg =  8, $astart =  0, $afinish =  360) {
2593
+    /**
2594
+     * draw a filled ellipse
2595
+     */
2596
+    function  filledEllipse($x0, $y0, $r1, $r2 =  0, $angle =  0, $nSeg =  8, $astart =  0, $afinish =  360) {
2597 2597
     return  $this->ellipse($x0, $y0, $r1, $r2 =  0, $angle, $nSeg, $astart, $afinish, 1, 1);
2598
-  }
2599
-
2600
-
2601
-  /**
2602
-   * draw an ellipse
2603
-   * note that the part and filled ellipse are just special cases of this function
2604
-   *
2605
-   * draws an ellipse in the current line style
2606
-   * centered at $x0,$y0, radii $r1,$r2
2607
-   * if $r2 is not set, then a circle is drawn
2608
-   * nSeg is not allowed to be less than 2, as this will simply draw a line (and will even draw a
2609
-   * pretty crappy shape at 2, as we are approximating with bezier curves.
2610
-   */
2611
-  function  ellipse($x0, $y0, $r1, $r2 =  0, $angle =  0, $nSeg =  8, $astart =  0, $afinish =  360, $close =  1, $fill =  0) {
2598
+    }
2599
+
2600
+
2601
+    /**
2602
+     * draw an ellipse
2603
+     * note that the part and filled ellipse are just special cases of this function
2604
+     *
2605
+     * draws an ellipse in the current line style
2606
+     * centered at $x0,$y0, radii $r1,$r2
2607
+     * if $r2 is not set, then a circle is drawn
2608
+     * nSeg is not allowed to be less than 2, as this will simply draw a line (and will even draw a
2609
+     * pretty crappy shape at 2, as we are approximating with bezier curves.
2610
+     */
2611
+    function  ellipse($x0, $y0, $r1, $r2 =  0, $angle =  0, $nSeg =  8, $astart =  0, $afinish =  360, $close =  1, $fill =  0) {
2612 2612
     if  ($r1 ==  0) {
2613
-      return;
2613
+        return;
2614 2614
     }
2615 2615
 
2616 2616
     if  ($r2 ==  0) {
2617
-      $r2 =  $r1;
2617
+        $r2 =  $r1;
2618 2618
     }
2619 2619
 
2620 2620
     if  ($nSeg < 2) {
2621
-      $nSeg =  2;
2621
+        $nSeg =  2;
2622 2622
     }
2623 2623
 
2624 2624
     $astart =  deg2rad((float)$astart);
@@ -2629,16 +2629,16 @@  discard block
 block discarded – undo
2629 2629
     $dtm =  $dt/3;
2630 2630
 
2631 2631
     if  ($angle !=  0) {
2632
-      $a =  -1*deg2rad((float)$angle);
2632
+        $a =  -1*deg2rad((float)$angle);
2633 2633
 
2634
-      $tmp  =  "\n q ";
2635
-      $tmp .=  sprintf('%.3F', cos($a)) .' '.sprintf('%.3F', (-1.0*sin($a))) .' '.sprintf('%.3F', sin($a)) .' '.sprintf('%.3F', cos($a)) .' ';
2636
-      $tmp .=  sprintf('%.3F', $x0) .' '.sprintf('%.3F', $y0) .' cm';
2634
+        $tmp  =  "\n q ";
2635
+        $tmp .=  sprintf('%.3F', cos($a)) .' '.sprintf('%.3F', (-1.0*sin($a))) .' '.sprintf('%.3F', sin($a)) .' '.sprintf('%.3F', cos($a)) .' ';
2636
+        $tmp .=  sprintf('%.3F', $x0) .' '.sprintf('%.3F', $y0) .' cm';
2637 2637
 
2638
-      $this->objects[$this->currentContents]['c'].=  $tmp;
2638
+        $this->objects[$this->currentContents]['c'].=  $tmp;
2639 2639
 
2640
-      $x0 =  0;
2641
-      $y0 =  0;
2640
+        $x0 =  0;
2641
+        $y0 =  0;
2642 2642
     }
2643 2643
 
2644 2644
     $t1 =  $astart;
@@ -2650,183 +2650,183 @@  discard block
 block discarded – undo
2650 2650
     $this->objects[$this->currentContents]['c'] .=  "\n".sprintf('%.3F', $a0) .' '.sprintf('%.3F', $b0) .' m ';
2651 2651
 
2652 2652
     for  ($i = 1; $i <=  $nSeg; $i++) {
2653
-      // draw this bit of the total curve
2654
-      $t1 =  $i * $dt + $astart;
2655
-      $a1 =  $x0 + $r1 * cos($t1);
2656
-      $b1 =  $y0 + $r2 * sin($t1);
2657
-      $c1 = -$r1 * sin($t1);
2658
-      $d1 =  $r2 * cos($t1);
2659
-
2660
-      $this->objects[$this->currentContents]['c']
2653
+        // draw this bit of the total curve
2654
+        $t1 =  $i * $dt + $astart;
2655
+        $a1 =  $x0 + $r1 * cos($t1);
2656
+        $b1 =  $y0 + $r2 * sin($t1);
2657
+        $c1 = -$r1 * sin($t1);
2658
+        $d1 =  $r2 * cos($t1);
2659
+
2660
+        $this->objects[$this->currentContents]['c']
2661 2661
         .=  "\n".sprintf('%.3F', ($a0+$c0*$dtm)) .' '.sprintf('%.3F', ($b0 + $d0 * $dtm));
2662 2662
 
2663
-      $this->objects[$this->currentContents]['c'] .=
2663
+        $this->objects[$this->currentContents]['c'] .=
2664 2664
         ' '.sprintf('%.3F', ($a1-$c1*$dtm)) .' '.sprintf('%.3F', ($b1-$d1*$dtm)) .' '.sprintf('%.3F', $a1) .' '.sprintf('%.3F', $b1) .' c';
2665 2665
 
2666
-      $a0 =  $a1;
2667
-      $b0 =  $b1;
2668
-      $c0 =  $c1;
2669
-      $d0 =  $d1;
2666
+        $a0 =  $a1;
2667
+        $b0 =  $b1;
2668
+        $c0 =  $c1;
2669
+        $d0 =  $d1;
2670 2670
     }
2671 2671
 
2672 2672
     if  ($fill) {
2673
-      $this->objects[$this->currentContents]['c'].=  ' f';
2673
+        $this->objects[$this->currentContents]['c'].=  ' f';
2674 2674
     } else if ($close) {
2675 2675
         $this->objects[$this->currentContents]['c'].=  ' s';
2676 2676
         // small 's' signifies closing the path as well
2677 2677
     } else {
2678
-      $this->objects[$this->currentContents]['c'].=  ' S';
2678
+        $this->objects[$this->currentContents]['c'].=  ' S';
2679 2679
     }
2680 2680
 
2681 2681
     if  ($angle !=  0) {
2682
-      $this->objects[$this->currentContents]['c'].=  ' Q';
2683
-    }
2684
-  }
2685
-
2686
-
2687
-  /**
2688
-   * this sets the line drawing style.
2689
-   * width, is the thickness of the line in user units
2690
-   * cap is the type of cap to put on the line, values can be 'butt','round','square'
2691
-   *    where the diffference between 'square' and 'butt' is that 'square' projects a flat end past the
2692
-   *    end of the line.
2693
-   * join can be 'miter', 'round', 'bevel'
2694
-   * dash is an array which sets the dash pattern, is a series of length values, which are the lengths of the
2695
-   *   on and off dashes.
2696
-   *   (2) represents 2 on, 2 off, 2 on , 2 off ...
2697
-   *   (2,1) is 2 on, 1 off, 2 on, 1 off.. etc
2698
-   * phase is a modifier on the dash pattern which is used to shift the point at which the pattern starts.
2699
-   */
2700
-  function  setLineStyle($width =  1, $cap =  '', $join =  '', $dash =  '', $phase =  0) {
2682
+        $this->objects[$this->currentContents]['c'].=  ' Q';
2683
+    }
2684
+    }
2685
+
2686
+
2687
+    /**
2688
+     * this sets the line drawing style.
2689
+     * width, is the thickness of the line in user units
2690
+     * cap is the type of cap to put on the line, values can be 'butt','round','square'
2691
+     *    where the diffference between 'square' and 'butt' is that 'square' projects a flat end past the
2692
+     *    end of the line.
2693
+     * join can be 'miter', 'round', 'bevel'
2694
+     * dash is an array which sets the dash pattern, is a series of length values, which are the lengths of the
2695
+     *   on and off dashes.
2696
+     *   (2) represents 2 on, 2 off, 2 on , 2 off ...
2697
+     *   (2,1) is 2 on, 1 off, 2 on, 1 off.. etc
2698
+     * phase is a modifier on the dash pattern which is used to shift the point at which the pattern starts.
2699
+     */
2700
+    function  setLineStyle($width =  1, $cap =  '', $join =  '', $dash =  '', $phase =  0) {
2701 2701
     // this is quite inefficient in that it sets all the parameters whenever 1 is changed, but will fix another day
2702 2702
     $string =  '';
2703 2703
 
2704 2704
     if  ($width>0) {
2705
-      $string.=  $width.' w';
2705
+        $string.=  $width.' w';
2706 2706
     }
2707 2707
 
2708 2708
     $ca =  array('butt' => 0, 'round' => 1, 'square' => 2);
2709 2709
 
2710 2710
     if  (isset($ca[$cap])) {
2711
-      $string.=  ' '.$ca[$cap].' J';
2711
+        $string.=  ' '.$ca[$cap].' J';
2712 2712
     }
2713 2713
 
2714 2714
     $ja =  array('miter' => 0, 'round' => 1, 'bevel' => 2);
2715 2715
 
2716 2716
     if  (isset($ja[$join])) {
2717
-      $string.=  ' '.$ja[$join].' j';
2717
+        $string.=  ' '.$ja[$join].' j';
2718 2718
     }
2719 2719
 
2720 2720
     if  (is_array($dash)) {
2721
-      $string.=  ' [';
2721
+        $string.=  ' [';
2722 2722
 
2723
-      foreach ($dash as  $len) {
2723
+        foreach ($dash as  $len) {
2724 2724
         $string.=  ' '.$len;
2725
-      }
2725
+        }
2726 2726
 
2727
-      $string.=  ' ] '.$phase.' d';
2727
+        $string.=  ' ] '.$phase.' d';
2728 2728
     }
2729 2729
 
2730 2730
     $this->currentLineStyle =  $string;
2731 2731
     $this->objects[$this->currentContents]['c'].=  "\n".$string;
2732
-  }
2732
+    }
2733 2733
 
2734 2734
 
2735 2735
 
2736
-  /**
2737
-   * draw a polygon, the syntax for this is similar to the GD polygon command
2738
-   */
2739
-  function  polygon($p, $np, $f =  0) {
2736
+    /**
2737
+     * draw a polygon, the syntax for this is similar to the GD polygon command
2738
+     */
2739
+    function  polygon($p, $np, $f =  0) {
2740 2740
     $this->objects[$this->currentContents]['c'].=  "\n";
2741 2741
     $this->objects[$this->currentContents]['c'].=  sprintf('%.3F', $p[0]) .' '.sprintf('%.3F', $p[1]) .' m ';
2742 2742
 
2743 2743
     for  ($i =  2; $i < $np * 2; $i =  $i + 2) {
2744
-      $this->objects[$this->currentContents]['c'].=  sprintf('%.3F', $p[$i]) .' '.sprintf('%.3F', $p[$i+1]) .' l ';
2744
+        $this->objects[$this->currentContents]['c'].=  sprintf('%.3F', $p[$i]) .' '.sprintf('%.3F', $p[$i+1]) .' l ';
2745 2745
     }
2746 2746
 
2747 2747
     if  ($f ==  1) {
2748
-      $this->objects[$this->currentContents]['c'].=  ' f';
2748
+        $this->objects[$this->currentContents]['c'].=  ' f';
2749 2749
     } else {
2750
-      $this->objects[$this->currentContents]['c'].=  ' S';
2750
+        $this->objects[$this->currentContents]['c'].=  ' S';
2751
+    }
2751 2752
     }
2752
-  }
2753 2753
 
2754 2754
 
2755
-  /**
2756
-   * a filled rectangle, note that it is the width and height of the rectangle which are the secondary paramaters, not
2757
-   * the coordinates of the upper-right corner
2758
-   */
2759
-  function  filledRectangle($x1, $y1, $width, $height) {
2755
+    /**
2756
+     * a filled rectangle, note that it is the width and height of the rectangle which are the secondary paramaters, not
2757
+     * the coordinates of the upper-right corner
2758
+     */
2759
+    function  filledRectangle($x1, $y1, $width, $height) {
2760 2760
     $this->objects[$this->currentContents]['c'].=  "\n".sprintf('%.3F', $x1) .' '.sprintf('%.3F', $y1) .' '.sprintf('%.3F', $width) .' '.sprintf('%.3F', $height) .' re f';
2761
-  }
2761
+    }
2762 2762
 
2763 2763
 
2764
-  /**
2765
-   * draw a rectangle, note that it is the width and height of the rectangle which are the secondary paramaters, not
2766
-   * the coordinates of the upper-right corner
2767
-   */
2768
-  function  rectangle($x1, $y1, $width, $height) {
2764
+    /**
2765
+     * draw a rectangle, note that it is the width and height of the rectangle which are the secondary paramaters, not
2766
+     * the coordinates of the upper-right corner
2767
+     */
2768
+    function  rectangle($x1, $y1, $width, $height) {
2769 2769
     $this->objects[$this->currentContents]['c'].=  "\n".sprintf('%.3F', $x1) .' '.sprintf('%.3F', $y1) .' '.sprintf('%.3F', $width) .' '.sprintf('%.3F', $height) .' re S';
2770
-  }
2770
+    }
2771 2771
 
2772 2772
 
2773
-  /**
2774
-   * add a new page to the document
2775
-   * this also makes the new page the current active object
2776
-   */
2777
-  function  newPage($insert =  0, $id =  0, $pos =  'after') {
2773
+    /**
2774
+     * add a new page to the document
2775
+     * this also makes the new page the current active object
2776
+     */
2777
+    function  newPage($insert =  0, $id =  0, $pos =  'after') {
2778 2778
     // if there is a state saved, then go up the stack closing them
2779 2779
     // then on the new page, re-open them with the right setings
2780 2780
 
2781 2781
     if  ($this->nStateStack) {
2782
-      for  ($i =  $this->nStateStack;$i >=  1;$i--) {
2782
+        for  ($i =  $this->nStateStack;$i >=  1;$i--) {
2783 2783
         $this->restoreState($i);
2784
-      }
2784
+        }
2785 2785
     }
2786 2786
 
2787 2787
     $this->numObj++;
2788 2788
 
2789 2789
     if  ($insert) {
2790
-      // the id from the ezPdf class is the id of the contents of the page, not the page object itself
2791
-      // query that object to find the parent
2792
-      $rid =  $this->objects[$id]['onPage'];
2793
-      $opt =  array('rid' => $rid, 'pos' => $pos);
2794
-      $this->o_page($this->numObj, 'new', $opt);
2790
+        // the id from the ezPdf class is the id of the contents of the page, not the page object itself
2791
+        // query that object to find the parent
2792
+        $rid =  $this->objects[$id]['onPage'];
2793
+        $opt =  array('rid' => $rid, 'pos' => $pos);
2794
+        $this->o_page($this->numObj, 'new', $opt);
2795 2795
     } else {
2796
-      $this->o_page($this->numObj, 'new');
2796
+        $this->o_page($this->numObj, 'new');
2797 2797
     }
2798 2798
 
2799 2799
     // if there is a stack saved, then put that onto the page
2800 2800
     if  ($this->nStateStack) {
2801
-      for  ($i =  1;$i <=  $this->nStateStack;$i++) {
2801
+        for  ($i =  1;$i <=  $this->nStateStack;$i++) {
2802 2802
         $this->saveState($i);
2803
-      }
2803
+        }
2804 2804
     }
2805 2805
 
2806 2806
     // and if there has been a stroke or fill colour set, then transfer them
2807 2807
     if  ($this->currentColour['r'] >=  0) {
2808
-      $this->setColor($this->currentColour['r'], $this->currentColour['g'], $this->currentColour['b'], 1);
2808
+        $this->setColor($this->currentColour['r'], $this->currentColour['g'], $this->currentColour['b'], 1);
2809 2809
     }
2810 2810
 
2811 2811
     if  ($this->currentStrokeColour['r'] >=  0) {
2812
-      $this->setStrokeColor($this->currentStrokeColour['r'], $this->currentStrokeColour['g'], $this->currentStrokeColour['b'], 1);
2812
+        $this->setStrokeColor($this->currentStrokeColour['r'], $this->currentStrokeColour['g'], $this->currentStrokeColour['b'], 1);
2813 2813
     }
2814 2814
 
2815 2815
     // if there is a line style set, then put this in too
2816 2816
     if  (mb_strlen($this->currentLineStyle, '8bit')) {
2817
-      $this->objects[$this->currentContents]['c'].=  "\n".$this->currentLineStyle;
2817
+        $this->objects[$this->currentContents]['c'].=  "\n".$this->currentLineStyle;
2818 2818
     }
2819 2819
 
2820 2820
     // the call to the o_page object set currentContents to the present page, so this can be returned as the page id
2821 2821
     return  $this->currentContents;
2822
-  }
2822
+    }
2823 2823
 
2824 2824
 
2825
-  /**
2826
-   * output the pdf code, streaming it to the browser
2827
-   * the relevant headers are set so that hopefully the browser will recognise it
2828
-   */
2829
-  function  stream($options =  '') {
2825
+    /**
2826
+     * output the pdf code, streaming it to the browser
2827
+     * the relevant headers are set so that hopefully the browser will recognise it
2828
+     */
2829
+    function  stream($options =  '') {
2830 2830
     // setting the options allows the adjustment of the headers
2831 2831
     // values at the moment are:
2832 2832
     // 'Content-Disposition' => 'filename'  - sets the filename, though not too sure how well this will
@@ -2837,16 +2837,16 @@  discard block
 block discarded – undo
2837 2837
     // 'compress' = > 1 or 0 - apply content stream compression, this is on (1) by default
2838 2838
     // 'Attachment' => 1 or 0 - if 1, force the browser to open a download dialog
2839 2839
     if  (!is_array($options)) {
2840
-      $options =  array();
2840
+        $options =  array();
2841 2841
     }
2842 2842
 
2843 2843
     if  ( headers_sent())
2844
-      die("Unable to stream pdf: headers already sent");
2844
+        die("Unable to stream pdf: headers already sent");
2845 2845
 
2846 2846
     if  ( isset($options['compress']) &&  $options['compress'] ==  0) {
2847
-      $tmp =  ltrim($this->output(1));
2847
+        $tmp =  ltrim($this->output(1));
2848 2848
     } else {
2849
-      $tmp =  ltrim($this->output());
2849
+        $tmp =  ltrim($this->output());
2850 2850
     }
2851 2851
 
2852 2852
     header("Cache-Control: private");
@@ -2857,28 +2857,28 @@  discard block
 block discarded – undo
2857 2857
     $fileName =  (isset($options['Content-Disposition']) ?  $options['Content-Disposition'] :  'file.pdf');
2858 2858
 
2859 2859
     if  ( !isset($options["Attachment"]))
2860
-      $options["Attachment"] =  true;
2860
+        $options["Attachment"] =  true;
2861 2861
 
2862 2862
     $attachment =  $options["Attachment"] ?  "attachment" :  "inline";
2863 2863
 
2864 2864
     header("Content-Disposition: $attachment; filename=\"$fileName\"");
2865 2865
 
2866 2866
     if  (isset($options['Accept-Ranges']) &&  $options['Accept-Ranges'] ==  1) {
2867
-      //FIXME: Is this the correct value ... spec says 1#range-unit
2868
-      header("Accept-Ranges: " . mb_strlen($tmp, '8bit'));
2867
+        //FIXME: Is this the correct value ... spec says 1#range-unit
2868
+        header("Accept-Ranges: " . mb_strlen($tmp, '8bit'));
2869 2869
     }
2870 2870
 
2871 2871
     echo  $tmp;
2872 2872
     flush();
2873
-  }
2873
+    }
2874 2874
 
2875 2875
 
2876
-  /**
2877
-   * return the height in units of the current font in the given size
2878
-   */
2879
-  function  getFontHeight($size) {
2876
+    /**
2877
+     * return the height in units of the current font in the given size
2878
+     */
2879
+    function  getFontHeight($size) {
2880 2880
     if  (!$this->numFonts) {
2881
-      $this->selectFont($this->defaultFont);
2881
+        $this->selectFont($this->defaultFont);
2882 2882
     }
2883 2883
     
2884 2884
     // for the current font, and the given size, what is the height of the font in user units
@@ -2887,165 +2887,165 @@  discard block
 block discarded – undo
2887 2887
     // have to adjust by a font offset for Windows fonts.  unfortunately it looks like
2888 2888
     // the bounding box calculations are wrong and I don't know why.
2889 2889
     if (isset($this->fonts[$this->currentFont]['FontHeightOffset'])) {
2890
-      // For CourierNew from Windows this needs to be -646 to match the
2891
-      // Adobe native Courier font.
2892
-      //
2893
-      // For FreeMono from GNU this needs to be -337 to match the
2894
-      // Courier font.
2895
-      //
2896
-      // Both have been added manually to the .afm and .ufm files.
2897
-      $h += (int)$this->fonts[$this->currentFont]['FontHeightOffset'];
2890
+        // For CourierNew from Windows this needs to be -646 to match the
2891
+        // Adobe native Courier font.
2892
+        //
2893
+        // For FreeMono from GNU this needs to be -337 to match the
2894
+        // Courier font.
2895
+        //
2896
+        // Both have been added manually to the .afm and .ufm files.
2897
+        $h += (int)$this->fonts[$this->currentFont]['FontHeightOffset'];
2898 2898
     }
2899 2899
 
2900 2900
     return  $size*$h/1000;
2901
-  }
2901
+    }
2902 2902
 
2903 2903
 
2904
-  /**
2905
-   * return the font descender, this will normally return a negative number
2906
-   * if you add this number to the baseline, you get the level of the bottom of the font
2907
-   * it is in the pdf user units
2908
-   */
2909
-  function  getFontDescender($size) {
2904
+    /**
2905
+     * return the font descender, this will normally return a negative number
2906
+     * if you add this number to the baseline, you get the level of the bottom of the font
2907
+     * it is in the pdf user units
2908
+     */
2909
+    function  getFontDescender($size) {
2910 2910
     // note that this will most likely return a negative value
2911 2911
     if  (!$this->numFonts) {
2912
-      $this->selectFont($this->defaultFont);
2912
+        $this->selectFont($this->defaultFont);
2913 2913
     }
2914 2914
 
2915 2915
     //$h = $this->fonts[$this->currentFont]['FontBBox'][1];
2916 2916
     $h = $this->fonts[$this->currentFont]['Descender'];
2917 2917
 
2918 2918
     return  $size*$h/1000;
2919
-  }
2919
+    }
2920 2920
 
2921 2921
 
2922
-  /**
2923
-   * filter the text, this is applied to all text just before being inserted into the pdf document
2924
-   * it escapes the various things that need to be escaped, and so on
2925
-   *
2926
-   * @access private
2927
-   */
2928
-  function  filterText($text, $bom = true) {
2922
+    /**
2923
+     * filter the text, this is applied to all text just before being inserted into the pdf document
2924
+     * it escapes the various things that need to be escaped, and so on
2925
+     *
2926
+     * @access private
2927
+     */
2928
+    function  filterText($text, $bom = true) {
2929 2929
     if (!$this->numFonts) {
2930
-      $this->selectFont($this->defaultFont);
2930
+        $this->selectFont($this->defaultFont);
2931 2931
     }
2932 2932
     
2933
-  	$cf = $this->currentFont;
2933
+        $cf = $this->currentFont;
2934 2934
     if ($this->fonts[$cf]['isUnicode']) {
2935
-      $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
2936
-      $text =  $this->utf8toUtf16BE($text, $bom);
2935
+        $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
2936
+        $text =  $this->utf8toUtf16BE($text, $bom);
2937 2937
     } else {
2938
-      if (in_array('Windows-1252', mb_list_encodings())) {
2938
+        if (in_array('Windows-1252', mb_list_encodings())) {
2939 2939
         $text = mb_convert_encoding($text, 'Windows-1252', 'UTF-8');
2940
-      } else {
2940
+        } else {
2941 2941
         $text = mb_convert_encoding($text, 'iso-8859-1', 'UTF-8');
2942
-      }
2943
-      $text = html_entity_decode($text, ENT_QUOTES);
2942
+        }
2943
+        $text = html_entity_decode($text, ENT_QUOTES);
2944 2944
     }
2945 2945
 
2946 2946
     // the chr(13) substitution fixes a bug seen in TCPDF (bug #1421290)
2947 2947
     $text = strtr($text, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
2948 2948
     return  $text;
2949
-  }
2950
-
2951
-  /**
2952
-   * return array containing codepoints (UTF-8 character values) for the
2953
-   * string passed in.
2954
-   *
2955
-   * based on the excellent TCPDF code by Nicola Asuni and the
2956
-   * RFC for UTF-8 at http://www.faqs.org/rfcs/rfc3629.html
2957
-   *
2958
-   * @access private
2959
-   * @author Orion Richardson
2960
-   * @since January 5, 2008
2961
-   * @param string $text UTF-8 string to process
2962
-   * @return array UTF-8 codepoints array for the string
2963
-   */
2964
-  function  utf8toCodePointsArray(&$text) {
2949
+    }
2950
+
2951
+    /**
2952
+     * return array containing codepoints (UTF-8 character values) for the
2953
+     * string passed in.
2954
+     *
2955
+     * based on the excellent TCPDF code by Nicola Asuni and the
2956
+     * RFC for UTF-8 at http://www.faqs.org/rfcs/rfc3629.html
2957
+     *
2958
+     * @access private
2959
+     * @author Orion Richardson
2960
+     * @since January 5, 2008
2961
+     * @param string $text UTF-8 string to process
2962
+     * @return array UTF-8 codepoints array for the string
2963
+     */
2964
+    function  utf8toCodePointsArray(&$text) {
2965 2965
     $length = mb_strlen($text, '8bit'); // http://www.php.net/manual/en/function.mb-strlen.php#77040
2966 2966
     $unicode = array(); // array containing unicode values
2967 2967
     $bytes = array(); // array containing single character byte sequences
2968 2968
     $numbytes = 1; // number of octetc needed to represent the UTF-8 character
2969 2969
     
2970 2970
     for ($i = 0; $i < $length; $i++) {
2971
-      $c = ord($text[$i]); // get one string character at time
2972
-      if (count($bytes) == 0) { // get starting octect
2971
+        $c = ord($text[$i]); // get one string character at time
2972
+        if (count($bytes) == 0) { // get starting octect
2973 2973
         if ($c <= 0x7F) {
2974
-          $unicode[] = $c; // use the character "as is" because is ASCII
2975
-          $numbytes = 1;
2974
+            $unicode[] = $c; // use the character "as is" because is ASCII
2975
+            $numbytes = 1;
2976 2976
         } elseif (($c >> 0x05) == 0x06) { // 2 bytes character (0x06 = 110 BIN)
2977
-          $bytes[] = ($c - 0xC0) << 0x06;
2978
-          $numbytes = 2;
2977
+            $bytes[] = ($c - 0xC0) << 0x06;
2978
+            $numbytes = 2;
2979 2979
         } elseif (($c >> 0x04) == 0x0E) { // 3 bytes character (0x0E = 1110 BIN)
2980
-          $bytes[] = ($c - 0xE0) << 0x0C;
2981
-          $numbytes = 3;
2980
+            $bytes[] = ($c - 0xE0) << 0x0C;
2981
+            $numbytes = 3;
2982 2982
         } elseif (($c >> 0x03) == 0x1E) { // 4 bytes character (0x1E = 11110 BIN)
2983
-          $bytes[] = ($c - 0xF0) << 0x12;
2984
-          $numbytes = 4;
2983
+            $bytes[] = ($c - 0xF0) << 0x12;
2984
+            $numbytes = 4;
2985 2985
         } else {
2986
-          // use replacement character for other invalid sequences
2987
-          $unicode[] = 0xFFFD;
2988
-          $bytes = array();
2989
-          $numbytes = 1;
2986
+            // use replacement character for other invalid sequences
2987
+            $unicode[] = 0xFFFD;
2988
+            $bytes = array();
2989
+            $numbytes = 1;
2990 2990
         }
2991
-      } elseif (($c >> 0x06) == 0x02) { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN
2991
+        } elseif (($c >> 0x06) == 0x02) { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN
2992 2992
         $bytes[] = $c - 0x80;
2993 2993
         if (count($bytes) == $numbytes) {
2994
-          // compose UTF-8 bytes to a single unicode value
2995
-          $c = $bytes[0];
2996
-          for ($j = 1; $j < $numbytes; $j++) {
2994
+            // compose UTF-8 bytes to a single unicode value
2995
+            $c = $bytes[0];
2996
+            for ($j = 1; $j < $numbytes; $j++) {
2997 2997
             $c += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
2998
-          }
2999
-          if ((($c >= 0xD800) AND ($c <= 0xDFFF)) OR ($c >= 0x10FFFF)) {
2998
+            }
2999
+            if ((($c >= 0xD800) AND ($c <= 0xDFFF)) OR ($c >= 0x10FFFF)) {
3000 3000
             // The definition of UTF-8 prohibits encoding character numbers between
3001 3001
             // U+D800 and U+DFFF, which are reserved for use with the UTF-16
3002 3002
             // encoding form (as surrogate pairs) and do not directly represent
3003 3003
             // characters.
3004 3004
             $unicode[] = 0xFFFD; // use replacement character
3005
-          } else {
3005
+            } else {
3006 3006
             $unicode[] = $c; // add char to array
3007
-          }
3008
-          // reset data for next char
3009
-          $bytes = array();
3010
-          $numbytes = 1;
3007
+            }
3008
+            // reset data for next char
3009
+            $bytes = array();
3010
+            $numbytes = 1;
3011 3011
         }
3012
-      } else {
3012
+        } else {
3013 3013
         // use replacement character for other invalid sequences
3014 3014
         $unicode[] = 0xFFFD;
3015 3015
         $bytes = array();
3016 3016
         $numbytes = 1;
3017
-      }
3017
+        }
3018 3018
     }
3019 3019
     return $unicode;
3020
-  }
3021
-
3022
-  /**
3023
-   * convert UTF-8 to UTF-16 with an additional byte order marker
3024
-   * at the front if required.
3025
-   *
3026
-   * based on the excellent TCPDF code by Nicola Asuni and the
3027
-   * RFC for UTF-8 at http://www.faqs.org/rfcs/rfc3629.html
3028
-   *
3029
-   * @access private
3030
-   * @author Orion Richardson
3031
-   * @since January 5, 2008
3032
-   * @param string $text UTF-8 string to process
3033
-   * @param boolean $bom whether to add the byte order marker
3034
-   * @return string UTF-16 result string
3035
-   */
3036
-  function  utf8toUtf16BE(&$text, $bom = true) {
3020
+    }
3021
+
3022
+    /**
3023
+     * convert UTF-8 to UTF-16 with an additional byte order marker
3024
+     * at the front if required.
3025
+     *
3026
+     * based on the excellent TCPDF code by Nicola Asuni and the
3027
+     * RFC for UTF-8 at http://www.faqs.org/rfcs/rfc3629.html
3028
+     *
3029
+     * @access private
3030
+     * @author Orion Richardson
3031
+     * @since January 5, 2008
3032
+     * @param string $text UTF-8 string to process
3033
+     * @param boolean $bom whether to add the byte order marker
3034
+     * @return string UTF-16 result string
3035
+     */
3036
+    function  utf8toUtf16BE(&$text, $bom = true) {
3037 3037
     $cf =  $this->currentFont;
3038 3038
     if (!$this->fonts[$cf]['isUnicode']) return $text;
3039 3039
     $out = $bom ? "\xFE\xFF" : '';
3040 3040
     
3041 3041
     $unicode = $this->utf8toCodePointsArray($text);
3042 3042
     foreach ($unicode as $c) {
3043
-      if ($c == 0xFFFD) {
3043
+        if ($c == 0xFFFD) {
3044 3044
         $out .= "\xFF\xFD"; // replacement character
3045
-      } elseif ($c < 0x10000) {
3045
+        } elseif ($c < 0x10000) {
3046 3046
         $out .= chr($c >> 0x08);
3047 3047
         $out .= chr($c & 0xFF);
3048
-       } else {
3048
+        } else {
3049 3049
         $c -= 0x10000;
3050 3050
         $w1 = 0xD800 | ($c >> 0x10);
3051 3051
         $w2 = 0xDC00 | ($c & 0x3FF);
@@ -3053,19 +3053,19 @@  discard block
 block discarded – undo
3053 3053
         $out .= chr($w1 & 0xFF);
3054 3054
         $out .= chr($w2 >> 0x08);
3055 3055
         $out .= chr($w2 & 0xFF);
3056
-      }
3056
+        }
3057 3057
     }
3058 3058
     return $out;
3059
-  }
3059
+    }
3060 3060
 
3061 3061
 
3062
-  /**
3063
-   * given a start position and information about how text is to be laid out, calculate where
3064
-   * on the page the text will end
3065
-   *
3066
-   * @access private
3067
-   */
3068
-  function  PRVTgetTextPosition($x, $y, $angle, $size, $wa, $text) {
3062
+    /**
3063
+     * given a start position and information about how text is to be laid out, calculate where
3064
+     * on the page the text will end
3065
+     *
3066
+     * @access private
3067
+     */
3068
+    function  PRVTgetTextPosition($x, $y, $angle, $size, $wa, $text) {
3069 3069
     // given this information return an array containing x and y for the end position as elements 0 and 1
3070 3070
     $w =  $this->getTextWidth($size, $text);
3071 3071
 
@@ -3076,66 +3076,66 @@  discard block
 block discarded – undo
3076 3076
     $a =  deg2rad((float)$angle);
3077 3077
 
3078 3078
     return  array(cos($a) *$w+$x, -sin($a) *$w+$y);
3079
-  }
3079
+    }
3080 3080
 
3081 3081
 
3082
-  /**
3083
-   * wrapper function for PRVTcheckTextDirective1
3084
-   *
3085
-   * @access private
3086
-   */
3087
-  function  PRVTcheckTextDirective(&$text, $i, &$f) {
3082
+    /**
3083
+     * wrapper function for PRVTcheckTextDirective1
3084
+     *
3085
+     * @access private
3086
+     */
3087
+    function  PRVTcheckTextDirective(&$text, $i, &$f) {
3088 3088
     return  0;
3089 3089
     $x =  0;
3090 3090
     $y =  0;
3091 3091
     return  $this->PRVTcheckTextDirective1($text, $i, $f, 0, $x, $y);
3092
-  }
3092
+    }
3093 3093
 
3094 3094
 
3095
-  /**
3096
-   * checks if the text stream contains a control directive
3097
-   * if so then makes some changes and returns the number of characters involved in the directive
3098
-   * this has been re-worked to include everything neccesary to find the current writing point, so that
3099
-   * the location can be sent to the callback function if required
3100
-   * if the directive does not require a font change, then $f should be set to 0
3101
-   *
3102
-   * @access private
3103
-   */
3104
-  function  PRVTcheckTextDirective1(&$text, $i, &$f, $final, &$x, &$y, $size =  0, $angle =  0, $wordSpaceAdjust =  0) {
3095
+    /**
3096
+     * checks if the text stream contains a control directive
3097
+     * if so then makes some changes and returns the number of characters involved in the directive
3098
+     * this has been re-worked to include everything neccesary to find the current writing point, so that
3099
+     * the location can be sent to the callback function if required
3100
+     * if the directive does not require a font change, then $f should be set to 0
3101
+     *
3102
+     * @access private
3103
+     */
3104
+    function  PRVTcheckTextDirective1(&$text, $i, &$f, $final, &$x, &$y, $size =  0, $angle =  0, $wordSpaceAdjust =  0) {
3105 3105
     return  0;
3106 3106
     $directive =  0;
3107 3107
     $j =  $i;
3108 3108
     if  ($text[$j] === '<') {
3109
-      $j++;
3110
-      switch ($text[$j]) {
3111
-      case  '/':
3109
+        $j++;
3110
+        switch ($text[$j]) {
3111
+        case  '/':
3112 3112
         $j++;
3113 3113
         if  (mb_strlen($text) <=  $j) {
3114
-          return  $directive;
3114
+            return  $directive;
3115 3115
         }
3116 3116
 
3117 3117
         switch ($text[$j]) {
3118 3118
         case  'b':
3119 3119
         case  'i':
3120 3120
           $j++;
3121
-          if  ($text[$j] === '>') {
3121
+            if  ($text[$j] === '>') {
3122 3122
             $p =  mb_strrpos($this->currentTextState, $text[$j-1]);
3123 3123
 
3124 3124
             if  ($p !==  false) {
3125
-              // then there is one to remove
3126
-              $this->currentTextState =  mb_substr($this->currentTextState, 0, $p) .substr($this->currentTextState, $p+1);
3125
+                // then there is one to remove
3126
+                $this->currentTextState =  mb_substr($this->currentTextState, 0, $p) .substr($this->currentTextState, $p+1);
3127 3127
             }
3128 3128
 
3129 3129
             $directive =  $j-$i+1;
3130
-          }
3131
-          break;
3130
+            }
3131
+            break;
3132 3132
 
3133 3133
         case  'c':
3134 3134
           // this this might be a callback function
3135 3135
           $j++;
3136
-          $k =  mb_strpos($text, '>', $j);
3136
+            $k =  mb_strpos($text, '>', $j);
3137 3137
 
3138
-          if  ($k !==  false &&  $text[$j] === ':') {
3138
+            if  ($k !==  false &&  $text[$j] === ':') {
3139 3139
             // then this will be treated as a callback directive
3140 3140
             $directive =  $k-$i+1;
3141 3141
             $f =  0;
@@ -3144,18 +3144,18 @@  discard block
 block discarded – undo
3144 3144
             $b1 =  mb_strpos($tmp, ':');
3145 3145
 
3146 3146
             if  ($b1 !==  false) {
3147
-              $func =  mb_substr($tmp, 0, $b1);
3148
-              $parm =  mb_substr($tmp, $b1+1);
3147
+                $func =  mb_substr($tmp, 0, $b1);
3148
+                $parm =  mb_substr($tmp, $b1+1);
3149 3149
             } else {
3150
-              $func =  $tmp;
3151
-              $parm =  '';
3150
+                $func =  $tmp;
3151
+                $parm =  '';
3152 3152
             }
3153 3153
 
3154 3154
             if  (!isset($func) ||  !mb_strlen(trim($func), '8bit')) {
3155
-              $directive =  0;
3155
+                $directive =  0;
3156 3156
             } else {
3157
-              // only call the function if this is the final call
3158
-              if  ($final) {
3157
+                // only call the function if this is the final call
3158
+                if  ($final) {
3159 3159
                 // need to assess the text position, calculate the text width to this point
3160 3160
                 // can use getTextWidth to find the text width I think
3161 3161
                 $tmp =  $this->PRVTgetTextPosition($x, $y, $angle, $size, $wordSpaceAdjust, mb_substr($text, 0, $i));
@@ -3166,76 +3166,76 @@  discard block
 block discarded – undo
3166 3166
                 $ret =  $this->$func($info);
3167 3167
 
3168 3168
                 if  (is_array($ret)) {
3169
-                  // then the return from the callback function could set the position, to start with, later will do font colour, and font
3170
-                  foreach($ret as  $rk => $rv) {
3169
+                    // then the return from the callback function could set the position, to start with, later will do font colour, and font
3170
+                    foreach($ret as  $rk => $rv) {
3171 3171
                     switch ($rk) {
3172 3172
                     case  'x':
3173 3173
                     case  'y':
3174 3174
                       $$rk =  $rv;
3175
-                      break;
3175
+                        break;
3176
+                    }
3176 3177
                     }
3177
-                  }
3178 3178
                 }
3179 3179
 
3180 3180
                 // also remove from to the stack
3181 3181
                 // for simplicity, just take from the end, fix this another day
3182 3182
                 $this->nCallback--;
3183 3183
                 if  ($this->nCallback<0) {
3184
-                  $this->nCallBack =  0;
3184
+                    $this->nCallBack =  0;
3185
+                }
3185 3186
                 }
3186
-              }
3187 3187
             }
3188
-          }
3189
-          break;
3188
+            }
3189
+            break;
3190 3190
         }
3191 3191
         break;
3192 3192
 
3193
-      case  'b':
3193
+        case  'b':
3194 3194
       case  'i':
3195 3195
         $j++;
3196 3196
         if  ($text[$j] === '>') {
3197
-          $this->currentTextState.=  $text[$j-1];
3198
-          $directive =  $j-$i+1;
3197
+            $this->currentTextState.=  $text[$j-1];
3198
+            $directive =  $j-$i+1;
3199 3199
         }
3200 3200
         break;
3201 3201
 
3202
-      case  'C':
3202
+        case  'C':
3203 3203
         $noClose =  1;
3204
-      case  'c':
3204
+        case  'c':
3205 3205
         // this this might be a callback function
3206 3206
         $j++;
3207 3207
         $k =  mb_strpos($text, '>', $j);
3208 3208
 
3209 3209
         if  ($k !==  false &&  $text[$j] ===  ':') {
3210
-          // then this will be treated as a callback directive
3211
-          $directive =  $k-$i+1;
3210
+            // then this will be treated as a callback directive
3211
+            $directive =  $k-$i+1;
3212 3212
 
3213
-          $f =  0;
3213
+            $f =  0;
3214 3214
 
3215
-          // split the remainder on colons to get the function name and the paramater
3216
-          //          $bits = explode(':',substr($text,$j+1,$k-$j-1));
3217
-          $tmp =  mb_substr($text, $j+1, $k-$j-1);
3218
-          $b1 =  mb_strpos($tmp, ':');
3215
+            // split the remainder on colons to get the function name and the paramater
3216
+            //          $bits = explode(':',substr($text,$j+1,$k-$j-1));
3217
+            $tmp =  mb_substr($text, $j+1, $k-$j-1);
3218
+            $b1 =  mb_strpos($tmp, ':');
3219 3219
 
3220
-          if  ($b1 !==  false) {
3220
+            if  ($b1 !==  false) {
3221 3221
             $func =  mb_substr($tmp, 0, $b1);
3222 3222
             $parm =  mb_substr($tmp, $b1+1);
3223
-          } else {
3223
+            } else {
3224 3224
             $func =  $tmp;
3225 3225
             $parm =  '';
3226
-          }
3226
+            }
3227 3227
 
3228
-          if  (!isset($func) ||  !mb_strlen(trim($func), '8bit')) {
3228
+            if  (!isset($func) ||  !mb_strlen(trim($func), '8bit')) {
3229 3229
             $directive =  0;
3230
-          } else {
3230
+            } else {
3231 3231
             // only call the function if this is the final call, ie, the one actually doing printing, not measurement
3232 3232
             if  ($final) {
3233
-              // need to assess the text position, calculate the text width to this point
3234
-              // can use getTextWidth to find the text width I think
3235
-              // also add the text height and descender
3236
-              $tmp =  $this->PRVTgetTextPosition($x, $y, $angle, $size, $wordSpaceAdjust, mb_substr($text, 0, $i));
3233
+                // need to assess the text position, calculate the text width to this point
3234
+                // can use getTextWidth to find the text width I think
3235
+                // also add the text height and descender
3236
+                $tmp =  $this->PRVTgetTextPosition($x, $y, $angle, $size, $wordSpaceAdjust, mb_substr($text, 0, $i));
3237 3237
 
3238
-              $info =  array(
3238
+                $info =  array(
3239 3239
                 'x' => $tmp[0], 
3240 3240
                 'y' => $tmp[1], 
3241 3241
                 'angle' => $angle, 
@@ -3244,79 +3244,79 @@  discard block
 block discarded – undo
3244 3244
                 'f' => $func, 
3245 3245
                 'height' => $this->getFontHeight($size), 
3246 3246
                 'descender' => $this->getFontDescender($size)
3247
-              );
3248
-              $x =  $tmp[0];
3249
-              $y =  $tmp[1];
3247
+                );
3248
+                $x =  $tmp[0];
3249
+                $y =  $tmp[1];
3250 3250
 
3251
-              if  (!isset($noClose) ||  !$noClose) {
3251
+                if  (!isset($noClose) ||  !$noClose) {
3252 3252
                 // only add to the stack if this is a small 'c', therefore is a start-stop pair
3253 3253
                 $this->nCallback++;
3254 3254
                 $info['nCallback'] =  $this->nCallback;
3255 3255
                 $this->callback[$this->nCallback] =  $info;
3256
-              }
3256
+                }
3257 3257
 
3258
-              $ret =  $this->$func($info);
3259
-              if  (is_array($ret)) {
3258
+                $ret =  $this->$func($info);
3259
+                if  (is_array($ret)) {
3260 3260
                 // then the return from the callback function could set the position, to start with, later will do font colour, and font
3261 3261
                 foreach($ret as  $rk => $rv) {
3262
-                  switch ($rk) {
3263
-                  case  'x':
3262
+                    switch ($rk) {
3263
+                    case  'x':
3264 3264
                   case  'y':
3265 3265
                     $$rk =  $rv;
3266 3266
                     break;
3267
-                  }
3267
+                    }
3268
+                }
3268 3269
                 }
3269
-              }
3270 3270
             }
3271
-          }
3271
+            }
3272 3272
         }
3273 3273
         break;
3274
-      }
3274
+        }
3275 3275
     }
3276 3276
 
3277 3277
     return  $directive;
3278
-  }
3278
+    }
3279 3279
 
3280 3280
 
3281
-  /**
3282
-   * add text to the document, at a specified location, size and angle on the page
3283
-   */
3284
-  function  addText($x, $y, $size, $text, $angle =  0, $wordSpaceAdjust =  0) {
3281
+    /**
3282
+     * add text to the document, at a specified location, size and angle on the page
3283
+     */
3284
+    function  addText($x, $y, $size, $text, $angle =  0, $wordSpaceAdjust =  0) {
3285 3285
     if  (!$this->numFonts) {
3286
-      $this->selectFont($this->defaultFont);
3286
+        $this->selectFont($this->defaultFont);
3287 3287
     }
3288 3288
 
3289 3289
     // if there are any open callbacks, then they should be called, to show the start of the line
3290 3290
     if  ($this->nCallback>0) {
3291
-      for  ($i =  $this->nCallback;$i>0;$i--) {
3291
+        for  ($i =  $this->nCallback;$i>0;$i--) {
3292 3292
         // call each function
3293 3293
         $info =  array('x' => $x,
3294
-                       'y' => $y,
3295
-                       'angle' => $angle,
3296
-                       'status' => 'sol',
3297
-                       'p' => $this->callback[$i]['p'],
3298
-                       'nCallback' => $this->callback[$i]['nCallback'],
3299
-                       'height' => $this->callback[$i]['height'],
3300
-                       'descender' => $this->callback[$i]['descender']);
3294
+                        'y' => $y,
3295
+                        'angle' => $angle,
3296
+                        'status' => 'sol',
3297
+                        'p' => $this->callback[$i]['p'],
3298
+                        'nCallback' => $this->callback[$i]['nCallback'],
3299
+                        'height' => $this->callback[$i]['height'],
3300
+                        'descender' => $this->callback[$i]['descender']);
3301 3301
 
3302 3302
         $func =  $this->callback[$i]['f'];
3303 3303
         $this->$func($info);
3304
-      }
3304
+        }
3305 3305
     }
3306 3306
 
3307 3307
     if  ($angle ==  0) {
3308
-      $this->objects[$this->currentContents]['c'].=  "\n".'BT '.sprintf('%.3F', $x) .' '.sprintf('%.3F', $y) .' Td';
3308
+        $this->objects[$this->currentContents]['c'].=  "\n".'BT '.sprintf('%.3F', $x) .' '.sprintf('%.3F', $y) .' Td';
3309 3309
     } else {
3310
-      $a =  deg2rad((float)$angle);
3311
-      $tmp =  "\n".'BT ';
3312
-      $tmp.=  sprintf('%.3F', cos($a)) .' '.sprintf('%.3F', (-1.0*sin($a))) .' '.sprintf('%.3F', sin($a)) .' '.sprintf('%.3F', cos($a)) .' ';
3313
-      $tmp.=  sprintf('%.3F', $x) .' '.sprintf('%.3F', $y) .' Tm';
3314
-      $this->objects[$this->currentContents]['c'].=  $tmp;
3310
+        $a =  deg2rad((float)$angle);
3311
+        $tmp =  "\n".'BT ';
3312
+        $tmp.=  sprintf('%.3F', cos($a)) .' '.sprintf('%.3F', (-1.0*sin($a))) .' '.sprintf('%.3F', sin($a)) .' '.sprintf('%.3F', cos($a)) .' ';
3313
+        $tmp.=  sprintf('%.3F', $x) .' '.sprintf('%.3F', $y) .' Tm';
3314
+        $this->objects[$this->currentContents]['c'].=  $tmp;
3315 3315
     }
3316 3316
 
3317 3317
     if  ($wordSpaceAdjust !=  0 ||  $wordSpaceAdjust !=  $this->wordSpaceAdjust) {
3318
-      $this->wordSpaceAdjust =  $wordSpaceAdjust;
3319
-      $this->objects[$this->currentContents]['c'].=  ' '.sprintf('%.3F', $wordSpaceAdjust) .' Tw';
3318
+        $this->wordSpaceAdjust =  $wordSpaceAdjust;
3319
+        $this->objects[$this->currentContents]['c'].=  ' '.sprintf('%.3F', $wordSpaceAdjust) .' Tw';
3320 3320
     }
3321 3321
 
3322 3322
     $len =  mb_strlen($text);
@@ -3366,47 +3366,47 @@  discard block
 block discarded – undo
3366 3366
      }
3367 3367
     */
3368 3368
     if  ($start < $len) {
3369
-      $part =  $text; // OAR - Don't need this anymore, given that $start always equals zero.  substr($text, $start);
3370
-      $this->objects[$this->currentContents]['c'].=  ' /F'.$this->currentFontNum.' '.sprintf('%.1F', $size) .' Tf ';
3371
-      $this->objects[$this->currentContents]['c'].=  ' ('.$this->filterText($part, false) .') Tj';
3369
+        $part =  $text; // OAR - Don't need this anymore, given that $start always equals zero.  substr($text, $start);
3370
+        $this->objects[$this->currentContents]['c'].=  ' /F'.$this->currentFontNum.' '.sprintf('%.1F', $size) .' Tf ';
3371
+        $this->objects[$this->currentContents]['c'].=  ' ('.$this->filterText($part, false) .') Tj';
3372 3372
     }
3373 3373
 
3374 3374
     $this->objects[$this->currentContents]['c'].=  ' ET';
3375 3375
 
3376 3376
     // if there are any open callbacks, then they should be called, to show the end of the line
3377 3377
     if  ($this->nCallback>0) {
3378
-      for  ($i =  $this->nCallback;$i>0;$i--) {
3378
+        for  ($i =  $this->nCallback;$i>0;$i--) {
3379 3379
         // call each function
3380 3380
         $tmp =  $this->PRVTgetTextPosition($x, $y, $angle, $size, $wordSpaceAdjust, $text);
3381 3381
         $info =  array(
3382
-          'x' => $tmp[0], 
3383
-          'y' => $tmp[1], 
3384
-          'angle' => $angle,
3385
-          'status' => 'eol', 
3386
-          'p' => $this->callback[$i]['p'], 
3387
-          'nCallback' => $this->callback[$i]['nCallback'], 
3388
-          'height' => $this->callback[$i]['height'], 
3389
-          'descender' => $this->callback[$i]['descender']
3382
+            'x' => $tmp[0], 
3383
+            'y' => $tmp[1], 
3384
+            'angle' => $angle,
3385
+            'status' => 'eol', 
3386
+            'p' => $this->callback[$i]['p'], 
3387
+            'nCallback' => $this->callback[$i]['nCallback'], 
3388
+            'height' => $this->callback[$i]['height'], 
3389
+            'descender' => $this->callback[$i]['descender']
3390 3390
         );
3391 3391
         $func =  $this->callback[$i]['f'];
3392 3392
         $this->$func($info);
3393
-      }
3393
+        }
3394
+    }
3394 3395
     }
3395
-  }
3396 3396
 
3397 3397
 
3398
-  /**
3399
-   * calculate how wide a given text string will be on a page, at a given size.
3400
-   * this can be called externally, but is alse used by the other class functions
3401
-   */
3402
-  function  getTextWidth($size, $text, $spacing =  0) {
3398
+    /**
3399
+     * calculate how wide a given text string will be on a page, at a given size.
3400
+     * this can be called externally, but is alse used by the other class functions
3401
+     */
3402
+    function  getTextWidth($size, $text, $spacing =  0) {
3403 3403
     // this function should not change any of the settings, though it will need to
3404 3404
     // track any directives which change during calculation, so copy them at the start
3405 3405
     // and put them back at the end.
3406 3406
     $store_currentTextState =  $this->currentTextState;
3407 3407
 
3408 3408
     if  (!$this->numFonts) {
3409
-      $this->selectFont($this->defaultFont);
3409
+        $this->selectFont($this->defaultFont);
3410 3410
     }
3411 3411
 
3412 3412
     // converts a number or a float to a string so it can get the width
@@ -3418,33 +3418,33 @@  discard block
 block discarded – undo
3418 3418
     $cf =  $this->currentFont;
3419 3419
     $space_scale =  1000 / $size;
3420 3420
     if ( $this->fonts[$cf]['isUnicode']) {
3421
-      // for Unicode, use the code points array to calculate width rather
3422
-      // than just the string itself
3423
-      $unicode =  $this->utf8toCodePointsArray($text);
3421
+        // for Unicode, use the code points array to calculate width rather
3422
+        // than just the string itself
3423
+        $unicode =  $this->utf8toCodePointsArray($text);
3424 3424
 
3425
-      foreach ($unicode as $char) {
3425
+        foreach ($unicode as $char) {
3426 3426
         // check if we have to replace character
3427
-      if  ( isset($this->fonts[$cf]['differences'][$char])) {
3428
-          $char =  $this->fonts[$cf]['differences'][$char];
3427
+        if  ( isset($this->fonts[$cf]['differences'][$char])) {
3428
+            $char =  $this->fonts[$cf]['differences'][$char];
3429 3429
         }
3430 3430
         // add the character width
3431 3431
         if  ( isset($this->fonts[$cf]['C'][$char]['WX'])) {
3432
-          $w+=  $this->fonts[$cf]['C'][$char]['WX'];
3432
+            $w+=  $this->fonts[$cf]['C'][$char]['WX'];
3433 3433
         }
3434 3434
         // add additional padding for space
3435 3435
         if  ( $char ==  32) {  // Space
3436
-          $w+=  $spacing * $space_scale;
3436
+            $w+=  $spacing * $space_scale;
3437
+        }
3437 3438
         }
3438
-      }
3439 3439
 
3440 3440
     } else {
3441
-      $len =  mb_strlen($text, 'Windows-1252');
3441
+        $len =  mb_strlen($text, 'Windows-1252');
3442 3442
 
3443
-      for  ($i =  0; $i < $len; $i++) {
3443
+        for  ($i =  0; $i < $len; $i++) {
3444 3444
         $char =  ord($text[$i]);
3445 3445
         // check if we have to replace character
3446 3446
         if  ( isset($this->fonts[$cf]['differences'][$char])) {
3447
-          $char =  $this->fonts[$cf]['differences'][$char];
3447
+            $char =  $this->fonts[$cf]['differences'][$char];
3448 3448
         }
3449 3449
         // add the character width
3450 3450
         if  ( isset($this->fonts[$cf]['C'][$char]['WX'])) {
@@ -3452,60 +3452,60 @@  discard block
 block discarded – undo
3452 3452
         }
3453 3453
         // add additional padding for space
3454 3454
         if  ( $char ==  32) {  // Space
3455
-          $w+=  $spacing * $space_scale;
3455
+            $w+=  $spacing * $space_scale;
3456
+        }
3456 3457
         }
3457
-      }
3458 3458
     }
3459 3459
 
3460 3460
     $this->currentTextState =  $store_currentTextState;
3461 3461
     $this->setCurrentFont();
3462 3462
 
3463 3463
     return  $w*$size/1000;
3464
-  }
3464
+    }
3465 3465
 
3466 3466
 
3467
-  /**
3468
-   * do a part of the calculation for sorting out the justification of the text
3469
-   *
3470
-   * @access private
3471
-   */
3472
-  function  PRVTadjustWrapText($text, $actual, $width, &$x, &$adjust, $justification) {
3467
+    /**
3468
+     * do a part of the calculation for sorting out the justification of the text
3469
+     *
3470
+     * @access private
3471
+     */
3472
+    function  PRVTadjustWrapText($text, $actual, $width, &$x, &$adjust, $justification) {
3473 3473
     switch  ($justification) {
3474 3474
     case  'left':
3475 3475
       return;
3476 3476
 
3477 3477
     case  'right':
3478 3478
       $x+=  $width-$actual;
3479
-      break;
3479
+        break;
3480 3480
 
3481 3481
     case  'center':
3482 3482
     case  'centre':
3483 3483
       $x+=  ($width-$actual) /2;
3484
-      break;
3484
+        break;
3485 3485
 
3486 3486
     case  'full':
3487 3487
       // count the number of words
3488 3488
       $words =  explode(' ', $text);
3489
-      $nspaces =  count($words) -1;
3489
+        $nspaces =  count($words) -1;
3490 3490
 
3491
-      if  ($nspaces>0) {
3491
+        if  ($nspaces>0) {
3492 3492
         $adjust =  ($width-$actual) /$nspaces;
3493
-      } else {
3493
+        } else {
3494 3494
         $adjust =  0;
3495
-      }
3496
-      break;
3495
+        }
3496
+        break;
3497
+    }
3497 3498
     }
3498
-  }
3499 3499
 
3500 3500
 
3501
-  /**
3502
-   * add text to the page, but ensure that it fits within a certain width
3503
-   * if it does not fit then put in as much as possible, splitting at word boundaries
3504
-   * and return the remainder.
3505
-   * justification and angle can also be specified for the text
3506
-   */
3507
-  function  addTextWrap($x, $y, $width, $size, $text, $justification =  'left', $angle =  0, $test =  0) {
3508
-  	// TODO - need to support Unicode
3501
+    /**
3502
+     * add text to the page, but ensure that it fits within a certain width
3503
+     * if it does not fit then put in as much as possible, splitting at word boundaries
3504
+     * and return the remainder.
3505
+     * justification and angle can also be specified for the text
3506
+     */
3507
+    function  addTextWrap($x, $y, $width, $size, $text, $justification =  'left', $angle =  0, $test =  0) {
3508
+        // TODO - need to support Unicode
3509 3509
     $cf =  $this->currentFont;
3510 3510
     if ($this->fonts[$cf]['isUnicode']) {
3511 3511
         die("addTextWrap does not support Unicode yet!");
@@ -3521,12 +3521,12 @@  discard block
 block discarded – undo
3521 3521
     $store_currentTextState =  $this->currentTextState;
3522 3522
 
3523 3523
     if  (!$this->numFonts) {
3524
-      $this->selectFont($this->defaultFont);
3524
+        $this->selectFont($this->defaultFont);
3525 3525
     }
3526 3526
 
3527 3527
     if  ($width <=  0) {
3528
-      // error, pretend it printed ok, otherwise risking a loop
3529
-      return  '';
3528
+        // error, pretend it printed ok, otherwise risking a loop
3529
+        return  '';
3530 3530
     }
3531 3531
 
3532 3532
     $w =  0;
@@ -3537,38 +3537,38 @@  discard block
 block discarded – undo
3537 3537
     $tw =  $width/$size*1000;
3538 3538
 
3539 3539
     for  ($i =  0;$i<$len;$i++) {
3540
-      $f =  1;
3541
-      $directive =  0;
3542
-      //$this->PRVTcheckTextDirective($text,$i,$f);
3543
-      if  ($directive) {
3540
+        $f =  1;
3541
+        $directive =  0;
3542
+        //$this->PRVTcheckTextDirective($text,$i,$f);
3543
+        if  ($directive) {
3544 3544
         if  ($f) {
3545
-          $this->setCurrentFont();
3546
-          $cf =  $this->currentFont;
3545
+            $this->setCurrentFont();
3546
+            $cf =  $this->currentFont;
3547 3547
         }
3548 3548
 
3549 3549
         $i =  $i+$directive-1;
3550
-      } else {
3550
+        } else {
3551 3551
         $cOrd =  ord($text[$i]);
3552 3552
 
3553 3553
         if  (isset($this->fonts[$cf]['differences'][$cOrd])) {
3554
-          // then this character is being replaced by another
3555
-          $cOrd2 =  $this->fonts[$cf]['differences'][$cOrd];
3554
+            // then this character is being replaced by another
3555
+            $cOrd2 =  $this->fonts[$cf]['differences'][$cOrd];
3556 3556
         } else {
3557
-          $cOrd2 =  $cOrd;
3557
+            $cOrd2 =  $cOrd;
3558 3558
         }
3559 3559
 
3560 3560
         if  (isset($this->fonts[$cf]['C'][$cOrd2]['WX'])) {
3561
-          $w+=  $this->fonts[$cf]['C'][$cOrd2]['WX'];
3561
+            $w+=  $this->fonts[$cf]['C'][$cOrd2]['WX'];
3562 3562
         }
3563 3563
 
3564 3564
         if  ($w>$tw) {
3565
-          // then we need to truncate this line
3566
-          if  ($break>0) {
3565
+            // then we need to truncate this line
3566
+            if  ($break>0) {
3567 3567
             // then we have somewhere that we can split :)
3568 3568
             if  ($text[$break] ===  ' ') {
3569
-              $tmp =  mb_substr($text, 0, $break);
3569
+                $tmp =  mb_substr($text, 0, $break);
3570 3570
             } else {
3571
-              $tmp =  mb_substr($text, 0, $break+1);
3571
+                $tmp =  mb_substr($text, 0, $break+1);
3572 3572
             }
3573 3573
 
3574 3574
             $adjust =  0;
@@ -3579,18 +3579,18 @@  discard block
 block discarded – undo
3579 3579
             $this->setCurrentFont();
3580 3580
 
3581 3581
             if  (!$test) {
3582
-              $this->addText($x, $y, $size, $tmp, $angle, $adjust);
3582
+                $this->addText($x, $y, $size, $tmp, $angle, $adjust);
3583 3583
             }
3584 3584
 
3585 3585
             return  mb_substr($text, $break+1);
3586
-          } else {
3586
+            } else {
3587 3587
             // just split before the current character
3588 3588
             $tmp =  mb_substr($text, 0, $i);
3589 3589
             $adjust =  0;
3590 3590
             $ctmp =  ord($text[$i]);
3591 3591
 
3592 3592
             if  (isset($this->fonts[$cf]['differences'][$ctmp])) {
3593
-              $ctmp =  $this->fonts[$cf]['differences'][$ctmp];
3593
+                $ctmp =  $this->fonts[$cf]['differences'][$ctmp];
3594 3594
             }
3595 3595
 
3596 3596
             $tmpw =  ($w-$this->fonts[$cf]['C'][$ctmp]['WX']) *$size/1000;
@@ -3601,34 +3601,34 @@  discard block
 block discarded – undo
3601 3601
             $this->setCurrentFont();
3602 3602
 
3603 3603
             if  (!$test) {
3604
-              $this->addText($x, $y, $size, $tmp, $angle, $adjust);
3604
+                $this->addText($x, $y, $size, $tmp, $angle, $adjust);
3605 3605
             }
3606 3606
 
3607 3607
             return  mb_substr($text, $i);
3608
-          }
3608
+            }
3609 3609
         }
3610 3610
 
3611 3611
         if  ($text[$i] ===  '-') {
3612
-          $break =  $i;
3613
-          $breakWidth =  $w*$size/1000;
3612
+            $break =  $i;
3613
+            $breakWidth =  $w*$size/1000;
3614 3614
         }
3615 3615
 
3616 3616
         if  ($text[$i] ===  ' ') {
3617
-          $break =  $i;
3618
-          $ctmp =  ord($text[$i]);
3617
+            $break =  $i;
3618
+            $ctmp =  ord($text[$i]);
3619 3619
 
3620
-          if  (isset($this->fonts[$cf]['differences'][$ctmp])) {
3620
+            if  (isset($this->fonts[$cf]['differences'][$ctmp])) {
3621 3621
             $ctmp =  $this->fonts[$cf]['differences'][$ctmp];
3622
-          }
3622
+            }
3623 3623
 
3624
-          $breakWidth =  ($w-$this->fonts[$cf]['C'][$ctmp]['WX']) *$size/1000;
3624
+            $breakWidth =  ($w-$this->fonts[$cf]['C'][$ctmp]['WX']) *$size/1000;
3625
+        }
3625 3626
         }
3626
-      }
3627 3627
     }
3628 3628
 
3629 3629
     // then there was no need to break this line
3630 3630
     if  ($justification ===  'full') {
3631
-      $justification =  'left';
3631
+        $justification =  'left';
3632 3632
     }
3633 3633
 
3634 3634
     $adjust =  0;
@@ -3641,68 +3641,68 @@  discard block
 block discarded – undo
3641 3641
     $this->setCurrentFont();
3642 3642
 
3643 3643
     if  (!$test) {
3644
-      $this->addText($x, $y, $size, $text, $angle, $adjust, $angle);
3644
+        $this->addText($x, $y, $size, $text, $angle, $adjust, $angle);
3645 3645
     }
3646 3646
 
3647 3647
     return  '';
3648
-  }
3648
+    }
3649 3649
 
3650 3650
 
3651
-  /**
3652
-   * this will be called at a new page to return the state to what it was on the
3653
-   * end of the previous page, before the stack was closed down
3654
-   * This is to get around not being able to have open 'q' across pages
3655
-   *
3656
-   */
3657
-  function  saveState($pageEnd =  0) {
3651
+    /**
3652
+     * this will be called at a new page to return the state to what it was on the
3653
+     * end of the previous page, before the stack was closed down
3654
+     * This is to get around not being able to have open 'q' across pages
3655
+     *
3656
+     */
3657
+    function  saveState($pageEnd =  0) {
3658 3658
     if  ($pageEnd) {
3659
-      // this will be called at a new page to return the state to what it was on the
3660
-      // end of the previous page, before the stack was closed down
3661
-      // This is to get around not being able to have open 'q' across pages
3662
-      $opt =  $this->stateStack[$pageEnd];
3663
-      // ok to use this as stack starts numbering at 1
3664
-      $this->setColor($opt['col']['r'], $opt['col']['g'], $opt['col']['b'], 1);
3665
-      $this->setStrokeColor($opt['str']['r'], $opt['str']['g'], $opt['str']['b'], 1);
3666
-      $this->objects[$this->currentContents]['c'].=  "\n".$opt['lin'];
3667
-      //    $this->currentLineStyle = $opt['lin'];
3659
+        // this will be called at a new page to return the state to what it was on the
3660
+        // end of the previous page, before the stack was closed down
3661
+        // This is to get around not being able to have open 'q' across pages
3662
+        $opt =  $this->stateStack[$pageEnd];
3663
+        // ok to use this as stack starts numbering at 1
3664
+        $this->setColor($opt['col']['r'], $opt['col']['g'], $opt['col']['b'], 1);
3665
+        $this->setStrokeColor($opt['str']['r'], $opt['str']['g'], $opt['str']['b'], 1);
3666
+        $this->objects[$this->currentContents]['c'].=  "\n".$opt['lin'];
3667
+        //    $this->currentLineStyle = $opt['lin'];
3668 3668
     } else {
3669
-      $this->nStateStack++;
3670
-      $this->stateStack[$this->nStateStack] =  array(
3669
+        $this->nStateStack++;
3670
+        $this->stateStack[$this->nStateStack] =  array(
3671 3671
         'col' => $this->currentColour, 
3672 3672
         'str' => $this->currentStrokeColour, 
3673 3673
         'lin' => $this->currentLineStyle
3674
-      );
3674
+        );
3675 3675
     }
3676 3676
 
3677 3677
     $this->objects[$this->currentContents]['c'].=  "\nq";
3678
-  }
3678
+    }
3679 3679
 
3680 3680
 
3681
-  /**
3682
-   * restore a previously saved state
3683
-   */
3684
-  function  restoreState($pageEnd =  0) {
3681
+    /**
3682
+     * restore a previously saved state
3683
+     */
3684
+    function  restoreState($pageEnd =  0) {
3685 3685
     if  (!$pageEnd) {
3686
-      $n =  $this->nStateStack;
3687
-      $this->currentColour =  $this->stateStack[$n]['col'];
3688
-      $this->currentStrokeColour =  $this->stateStack[$n]['str'];
3689
-      $this->objects[$this->currentContents]['c'].=  "\n".$this->stateStack[$n]['lin'];
3690
-      $this->currentLineStyle =  $this->stateStack[$n]['lin'];
3691
-      unset($this->stateStack[$n]);
3692
-      $this->nStateStack--;
3686
+        $n =  $this->nStateStack;
3687
+        $this->currentColour =  $this->stateStack[$n]['col'];
3688
+        $this->currentStrokeColour =  $this->stateStack[$n]['str'];
3689
+        $this->objects[$this->currentContents]['c'].=  "\n".$this->stateStack[$n]['lin'];
3690
+        $this->currentLineStyle =  $this->stateStack[$n]['lin'];
3691
+        unset($this->stateStack[$n]);
3692
+        $this->nStateStack--;
3693 3693
     }
3694 3694
     
3695 3695
     $this->objects[$this->currentContents]['c'].=  "\nQ";
3696
-  }
3696
+    }
3697 3697
 
3698 3698
 
3699
-  /**
3700
-   * make a loose object, the output will go into this object, until it is closed, then will revert to
3701
-   * the current one.
3702
-   * this object will not appear until it is included within a page.
3703
-   * the function will return the object number
3704
-   */
3705
-  function  openObject() {
3699
+    /**
3700
+     * make a loose object, the output will go into this object, until it is closed, then will revert to
3701
+     * the current one.
3702
+     * this object will not appear until it is included within a page.
3703
+     * the function will return the object number
3704
+     */
3705
+    function  openObject() {
3706 3706
     $this->nStack++;
3707 3707
     $this->stack[$this->nStack] =  array('c' => $this->currentContents, 'p' => $this->currentPage);
3708 3708
     // add a new object of the content type, to hold the data flow
@@ -3712,315 +3712,315 @@  discard block
 block discarded – undo
3712 3712
     $this->looseObjects[$this->numObj] =  1;
3713 3713
 
3714 3714
     return  $this->numObj;
3715
-  }
3715
+    }
3716 3716
 
3717 3717
 
3718
-  /**
3719
-   * open an existing object for editing
3720
-   */
3721
-  function  reopenObject($id) {
3718
+    /**
3719
+     * open an existing object for editing
3720
+     */
3721
+    function  reopenObject($id) {
3722 3722
     $this->nStack++;
3723 3723
     $this->stack[$this->nStack] =  array('c' => $this->currentContents, 'p' => $this->currentPage);
3724 3724
     $this->currentContents =  $id;
3725 3725
 
3726 3726
     // also if this object is the primary contents for a page, then set the current page to its parent
3727 3727
     if  (isset($this->objects[$id]['onPage'])) {
3728
-      $this->currentPage =  $this->objects[$id]['onPage'];
3728
+        $this->currentPage =  $this->objects[$id]['onPage'];
3729
+    }
3729 3730
     }
3730
-  }
3731 3731
 
3732 3732
 
3733
-  /**
3734
-   * close an object
3735
-   */
3736
-  function  closeObject() {
3733
+    /**
3734
+     * close an object
3735
+     */
3736
+    function  closeObject() {
3737 3737
     // close the object, as long as there was one open in the first place, which will be indicated by
3738 3738
     // an objectId on the stack.
3739 3739
     if  ($this->nStack>0) {
3740
-      $this->currentContents =  $this->stack[$this->nStack]['c'];
3741
-      $this->currentPage =  $this->stack[$this->nStack]['p'];
3742
-      $this->nStack--;
3743
-      // easier to probably not worry about removing the old entries, they will be overwritten
3744
-      // if there are new ones.
3740
+        $this->currentContents =  $this->stack[$this->nStack]['c'];
3741
+        $this->currentPage =  $this->stack[$this->nStack]['p'];
3742
+        $this->nStack--;
3743
+        // easier to probably not worry about removing the old entries, they will be overwritten
3744
+        // if there are new ones.
3745
+    }
3745 3746
     }
3746
-  }
3747 3747
 
3748 3748
 
3749
-  /**
3750
-   * stop an object from appearing on pages from this point on
3751
-   */
3752
-  function  stopObject($id) {
3749
+    /**
3750
+     * stop an object from appearing on pages from this point on
3751
+     */
3752
+    function  stopObject($id) {
3753 3753
     // if an object has been appearing on pages up to now, then stop it, this page will
3754 3754
     // be the last one that could contian it.
3755 3755
     if  (isset($this->addLooseObjects[$id])) {
3756
-      $this->addLooseObjects[$id] =  '';
3756
+        $this->addLooseObjects[$id] =  '';
3757
+    }
3757 3758
     }
3758
-  }
3759 3759
 
3760 3760
 
3761
-  /**
3762
-   * after an object has been created, it wil only show if it has been added, using this function.
3763
-   */
3764
-  function  addObject($id, $options =  'add') {
3761
+    /**
3762
+     * after an object has been created, it wil only show if it has been added, using this function.
3763
+     */
3764
+    function  addObject($id, $options =  'add') {
3765 3765
     // add the specified object to the page
3766 3766
     if  (isset($this->looseObjects[$id]) &&  $this->currentContents !=  $id) {
3767
-      // then it is a valid object, and it is not being added to itself
3768
-      switch ($options) {
3769
-      case  'all':
3767
+        // then it is a valid object, and it is not being added to itself
3768
+        switch ($options) {
3769
+        case  'all':
3770 3770
         // then this object is to be added to this page (done in the next block) and
3771 3771
         // all future new pages.
3772 3772
         $this->addLooseObjects[$id] =  'all';
3773 3773
 
3774
-      case  'add':
3774
+        case  'add':
3775 3775
         if  (isset($this->objects[$this->currentContents]['onPage'])) {
3776
-          // then the destination contents is the primary for the page
3777
-          // (though this object is actually added to that page)
3778
-          $this->o_page($this->objects[$this->currentContents]['onPage'], 'content', $id);
3776
+            // then the destination contents is the primary for the page
3777
+            // (though this object is actually added to that page)
3778
+            $this->o_page($this->objects[$this->currentContents]['onPage'], 'content', $id);
3779 3779
         }
3780 3780
         break;
3781 3781
 
3782
-      case  'even':
3782
+        case  'even':
3783 3783
         $this->addLooseObjects[$id] =  'even';
3784 3784
         $pageObjectId =  $this->objects[$this->currentContents]['onPage'];
3785 3785
         if  ($this->objects[$pageObjectId]['info']['pageNum']%2 ==  0) {
3786
-          $this->addObject($id);
3787
-          // hacky huh :)
3786
+            $this->addObject($id);
3787
+            // hacky huh :)
3788 3788
         }
3789 3789
         break;
3790 3790
 
3791
-      case  'odd':
3791
+        case  'odd':
3792 3792
         $this->addLooseObjects[$id] =  'odd';
3793 3793
         $pageObjectId =  $this->objects[$this->currentContents]['onPage'];
3794 3794
         if  ($this->objects[$pageObjectId]['info']['pageNum']%2 ==  1) {
3795
-          $this->addObject($id);
3796
-          // hacky huh :)
3795
+            $this->addObject($id);
3796
+            // hacky huh :)
3797 3797
         }
3798 3798
         break;
3799 3799
 
3800
-      case  'next':
3800
+        case  'next':
3801 3801
         $this->addLooseObjects[$id] =  'all';
3802 3802
         break;
3803 3803
 
3804
-      case  'nexteven':
3804
+        case  'nexteven':
3805 3805
         $this->addLooseObjects[$id] =  'even';
3806 3806
         break;
3807 3807
 
3808
-      case  'nextodd':
3808
+        case  'nextodd':
3809 3809
         $this->addLooseObjects[$id] =  'odd';
3810 3810
         break;
3811
-      }
3811
+        }
3812
+    }
3812 3813
     }
3813
-  }
3814 3814
 
3815 3815
 
3816
-  /**
3817
-   * return a storable representation of a specific object
3818
-   */
3819
-  function  serializeObject($id) {
3816
+    /**
3817
+     * return a storable representation of a specific object
3818
+     */
3819
+    function  serializeObject($id) {
3820 3820
     if  ( array_key_exists($id,  $this->objects))
3821
-      return  var_export($this->objects[$id],  true);
3822
-  }
3821
+        return  var_export($this->objects[$id],  true);
3822
+    }
3823 3823
 
3824 3824
 
3825
-  /**
3826
-   * restore an object from its stored representation.  returns its new object id.
3827
-   */
3828
-  function  restoreSerializedObject($obj) {
3825
+    /**
3826
+     * restore an object from its stored representation.  returns its new object id.
3827
+     */
3828
+    function  restoreSerializedObject($obj) {
3829 3829
     $obj_id =  $this->openObject();
3830 3830
     eval('$this->objects[$obj_id] = ' . $obj . ';');
3831 3831
     $this->closeObject();
3832 3832
     return  $obj_id;
3833
-  }
3833
+    }
3834 3834
 
3835 3835
 
3836
-  /**
3837
-   * add content to the documents info object
3838
-   */
3839
-  function  addInfo($label, $value =  0) {
3836
+    /**
3837
+     * add content to the documents info object
3838
+     */
3839
+    function  addInfo($label, $value =  0) {
3840 3840
     // this will only work if the label is one of the valid ones.
3841 3841
     // modify this so that arrays can be passed as well.
3842 3842
     // if $label is an array then assume that it is key => value pairs
3843 3843
     // else assume that they are both scalar, anything else will probably error
3844 3844
     if  (is_array($label)) {
3845
-      foreach ($label as  $l => $v) {
3845
+        foreach ($label as  $l => $v) {
3846 3846
         $this->o_info($this->infoObject, $l, $v);
3847
-      }
3847
+        }
3848 3848
     } else {
3849
-      $this->o_info($this->infoObject, $label, $value);
3849
+        $this->o_info($this->infoObject, $label, $value);
3850
+    }
3850 3851
     }
3851
-  }
3852 3852
 
3853 3853
 
3854
-  /**
3855
-   * set the viewer preferences of the document, it is up to the browser to obey these.
3856
-   */
3857
-  function  setPreferences($label, $value =  0) {
3854
+    /**
3855
+     * set the viewer preferences of the document, it is up to the browser to obey these.
3856
+     */
3857
+    function  setPreferences($label, $value =  0) {
3858 3858
     // this will only work if the label is one of the valid ones.
3859 3859
     if  (is_array($label)) {
3860
-      foreach ($label as  $l => $v) {
3860
+        foreach ($label as  $l => $v) {
3861 3861
         $this->o_catalog($this->catalogId, 'viewerPreferences', array($l => $v));
3862
-      }
3862
+        }
3863 3863
     } else {
3864
-      $this->o_catalog($this->catalogId, 'viewerPreferences', array($label => $value));
3864
+        $this->o_catalog($this->catalogId, 'viewerPreferences', array($label => $value));
3865
+    }
3865 3866
     }
3866
-  }
3867 3867
 
3868 3868
 
3869
-  /**
3870
-   * extract an integer from a position in a byte stream
3871
-   *
3872
-   * @access private
3873
-   */
3874
-  function  PRVT_getBytes(&$data, $pos, $num) {
3869
+    /**
3870
+     * extract an integer from a position in a byte stream
3871
+     *
3872
+     * @access private
3873
+     */
3874
+    function  PRVT_getBytes(&$data, $pos, $num) {
3875 3875
     // return the integer represented by $num bytes from $pos within $data
3876 3876
     $ret =  0;
3877 3877
     for  ($i =  0;$i<$num;$i++) {
3878
-      $ret =  $ret*256;
3879
-      $ret+=  ord($data[$pos+$i]);
3878
+        $ret =  $ret*256;
3879
+        $ret+=  ord($data[$pos+$i]);
3880 3880
     }
3881 3881
 
3882 3882
     return  $ret;
3883
-  }
3883
+    }
3884 3884
 
3885 3885
 
3886
-  /**
3887
-   * add a PNG image into the document, from a GD object
3888
-   * this should work with remote files
3889
-   */
3890
-  function addImagePng($file, $x, $y, $w =  0, $h =  0, &$img) {
3886
+    /**
3887
+     * add a PNG image into the document, from a GD object
3888
+     * this should work with remote files
3889
+     */
3890
+    function addImagePng($file, $x, $y, $w =  0, $h =  0, &$img) {
3891 3891
     //if already cached, need not to read again
3892
-	if ( isset($this->imagelist[$file]) ) {
3893
-	  $data = null;
3894
-	} else {
3895
-  	  // Example for transparency handling on new image. Retain for current image
3896
-      // $tIndex = imagecolortransparent($img);
3897
-      // if ($tIndex > 0) {
3898
-      //   $tColor    = imagecolorsforindex($img, $tIndex);
3899
-      //   $new_tIndex    = imagecolorallocate($new_img, $tColor['red'], $tColor['green'], $tColor['blue']);
3900
-      //   imagefill($new_img, 0, 0, $new_tIndex);
3901
-      //   imagecolortransparent($new_img, $new_tIndex);
3902
-      // }
3903
-	  // blending mode (literal/blending) on drawing into current image. not relevant when not saved or not drawn
3904
-	  //imagealphablending($img, true);
3905
-	  //default, but explicitely set to ensure pdf compatibility
3906
-      imagesavealpha($img, false);
3892
+    if ( isset($this->imagelist[$file]) ) {
3893
+        $data = null;
3894
+    } else {
3895
+        // Example for transparency handling on new image. Retain for current image
3896
+        // $tIndex = imagecolortransparent($img);
3897
+        // if ($tIndex > 0) {
3898
+        //   $tColor    = imagecolorsforindex($img, $tIndex);
3899
+        //   $new_tIndex    = imagecolorallocate($new_img, $tColor['red'], $tColor['green'], $tColor['blue']);
3900
+        //   imagefill($new_img, 0, 0, $new_tIndex);
3901
+        //   imagecolortransparent($new_img, $new_tIndex);
3902
+        // }
3903
+        // blending mode (literal/blending) on drawing into current image. not relevant when not saved or not drawn
3904
+        //imagealphablending($img, true);
3905
+        //default, but explicitely set to ensure pdf compatibility
3906
+        imagesavealpha($img, false);
3907 3907
       
3908
-      $error =  0;
3909
-      //DEBUG_IMG_TEMP
3910
-      //debugpng
3911
-      if (DEBUGPNG) print '[addImagePng '.$file.']';
3908
+        $error =  0;
3909
+        //DEBUG_IMG_TEMP
3910
+        //debugpng
3911
+        if (DEBUGPNG) print '[addImagePng '.$file.']';
3912 3912
 
3913
-      ob_start();
3914
-      @imagepng($img);
3915
-      //$data = ob_get_contents(); ob_end_clean();
3916
-      $data = ob_get_clean();
3913
+        ob_start();
3914
+        @imagepng($img);
3915
+        //$data = ob_get_contents(); ob_end_clean();
3916
+        $data = ob_get_clean();
3917 3917
 
3918
-      if ($data == '') {
3918
+        if ($data == '') {
3919 3919
         $error = 1;
3920 3920
         $errormsg = 'trouble writing file from GD';
3921 3921
         //DEBUG_IMG_TEMP
3922 3922
         //debugpng
3923 3923
         if (DEBUGPNG) print 'trouble writing file from GD';
3924
-	  }
3924
+        }
3925 3925
 
3926
-      if  ($error) {
3926
+        if  ($error) {
3927 3927
         $this->addMessage('PNG error - ('.$file.') '.$errormsg);
3928 3928
         return;
3929
-      }
3929
+        }
3930 3930
     }  //End isset($this->imagelist[$file]) (png Duplicate removal)
3931 3931
 
3932 3932
     $this->addPngFromBuf($file, $x, $y, $w, $h, $data);
3933
-  }
3933
+    }
3934 3934
 
3935 3935
 
3936
-  /**
3937
-   * add a PNG image into the document, from a file
3938
-   * this should work with remote files
3939
-   */
3940
-  function  addPngFromFile($file, $x, $y, $w =  0, $h =  0) {
3936
+    /**
3937
+     * add a PNG image into the document, from a file
3938
+     * this should work with remote files
3939
+     */
3940
+    function  addPngFromFile($file, $x, $y, $w =  0, $h =  0) {
3941 3941
     //if already cached, need not to read again
3942
-	if ( isset($this->imagelist[$file]) ) {
3943
-	  $img = null;
3944
-	} else {
3945
-      //png files typically contain an alpha channel.
3946
-      //pdf file format or class.pdf does not support alpha blending.
3947
-      //on alpha blended images, more transparent areas have a color near black.
3948
-      //This appears in the result on not storing the alpha channel.
3949
-      //Correct would be the box background image or its parent when transparent.
3950
-      //But this would make the image dependent on the background.
3951
-      //Therefore create an image with white background and copy in
3952
-      //A more natural background than black is white.
3953
-      //Therefore create an empty image with white background and merge the
3954
-      //image in with alpha blending.
3955
-      $imgtmp = @imagecreatefrompng($file);
3956
-      if (!$imgtmp) {
3942
+    if ( isset($this->imagelist[$file]) ) {
3943
+        $img = null;
3944
+    } else {
3945
+        //png files typically contain an alpha channel.
3946
+        //pdf file format or class.pdf does not support alpha blending.
3947
+        //on alpha blended images, more transparent areas have a color near black.
3948
+        //This appears in the result on not storing the alpha channel.
3949
+        //Correct would be the box background image or its parent when transparent.
3950
+        //But this would make the image dependent on the background.
3951
+        //Therefore create an image with white background and copy in
3952
+        //A more natural background than black is white.
3953
+        //Therefore create an empty image with white background and merge the
3954
+        //image in with alpha blending.
3955
+        $imgtmp = @imagecreatefrompng($file);
3956
+        if (!$imgtmp) {
3957 3957
         return;
3958
-      }
3959
-      $sx = imagesx($imgtmp);
3960
-      $sy = imagesy($imgtmp);
3961
-      $img = imagecreatetruecolor($sx,$sy);
3962
-      imagealphablending($img, true);
3963
-  	  $ti = imagecolortransparent($imgtmp);
3964
-	  if ($ti >= 0) {
3965
-	    $tc = imagecolorsforindex($imgtmp,$ti);
3958
+        }
3959
+        $sx = imagesx($imgtmp);
3960
+        $sy = imagesy($imgtmp);
3961
+        $img = imagecreatetruecolor($sx,$sy);
3962
+        imagealphablending($img, true);
3963
+        $ti = imagecolortransparent($imgtmp);
3964
+        if ($ti >= 0) {
3965
+        $tc = imagecolorsforindex($imgtmp,$ti);
3966 3966
         $ti = imagecolorallocate($img,$tc['red'],$tc['green'],$tc['blue']);
3967 3967
         imagefill($img,0,0,$ti);
3968 3968
         imagecolortransparent($img, $ti);
3969
-      } else {
3969
+        } else {
3970 3970
         imagefill($img,1,1,imagecolorallocate($img,255,255,255));
3971
-      }
3972
-      imagecopy($img,$imgtmp,0,0,0,0,$sx,$sy);
3973
-      imagedestroy($imgtmp);
3971
+        }
3972
+        imagecopy($img,$imgtmp,0,0,0,0,$sx,$sy);
3973
+        imagedestroy($imgtmp);
3974 3974
     }
3975 3975
     $this->addImagePng($file, $x, $y, $w, $h, $img);
3976
-  }
3976
+    }
3977 3977
 
3978 3978
 
3979
-  /**
3980
-   * add a PNG image into the document, from a memory buffer of the file
3981
-   */
3982
-  function  addPngFromBuf($file, $x, $y, $w =  0, $h =  0, &$data) {
3983
-	if ( isset($this->imagelist[$file]) ) {
3984
-      //debugpng
3985
-      //if (DEBUGPNG) print '[addPngFromBuf Duplicate '.$file.']';
3986
-	  $data = null;
3987
-      $info['width'] = $this->imagelist[$file]['w'];
3988
-      $info['height'] = $this->imagelist[$file]['h'];
3989
-      $label = $this->imagelist[$file]['label'];
3990
-
3991
-	} else {
3992
-      if ($data == null) {
3993
-      	$this->addMessage('addPngFromBuf error - ('.$imgname.') data not present!');
3979
+    /**
3980
+     * add a PNG image into the document, from a memory buffer of the file
3981
+     */
3982
+    function  addPngFromBuf($file, $x, $y, $w =  0, $h =  0, &$data) {
3983
+    if ( isset($this->imagelist[$file]) ) {
3984
+        //debugpng
3985
+        //if (DEBUGPNG) print '[addPngFromBuf Duplicate '.$file.']';
3986
+        $data = null;
3987
+        $info['width'] = $this->imagelist[$file]['w'];
3988
+        $info['height'] = $this->imagelist[$file]['h'];
3989
+        $label = $this->imagelist[$file]['label'];
3990
+
3991
+    } else {
3992
+        if ($data == null) {
3993
+            $this->addMessage('addPngFromBuf error - ('.$imgname.') data not present!');
3994 3994
         return;
3995
-      }
3996
-      //debugpng
3997
-      //if (DEBUGPNG) print '[addPngFromBuf file='.$file.']';
3995
+        }
3996
+        //debugpng
3997
+        //if (DEBUGPNG) print '[addPngFromBuf file='.$file.']';
3998 3998
     $error =  0;
3999 3999
 
4000 4000
     if  (!$error) {
4001
-      $header =  chr(137) .chr(80) .chr(78) .chr(71) .chr(13) .chr(10) .chr(26) .chr(10);
4002
-      if  (mb_substr($data, 0, 8, '8bit') !=  $header) {
4001
+        $header =  chr(137) .chr(80) .chr(78) .chr(71) .chr(13) .chr(10) .chr(26) .chr(10);
4002
+        if  (mb_substr($data, 0, 8, '8bit') !=  $header) {
4003 4003
         $error =  1;
4004 4004
         //debugpng
4005 4005
         if (DEBUGPNG) print '[addPngFromFile this file does not have a valid header '.$file.']';
4006 4006
 
4007 4007
         $errormsg =  'this file does not have a valid header';
4008
-      }
4008
+        }
4009 4009
     }
4010 4010
 
4011 4011
 
4012 4012
     if  (!$error) {
4013
-      // set pointer
4014
-      $p =  8;
4015
-      $len =  mb_strlen($data, '8bit');
4013
+        // set pointer
4014
+        $p =  8;
4015
+        $len =  mb_strlen($data, '8bit');
4016 4016
 
4017
-      // cycle through the file, identifying chunks
4018
-      $haveHeader =  0;
4019
-      $info =  array();
4020
-      $idata =  '';
4021
-      $pdata =  '';
4017
+        // cycle through the file, identifying chunks
4018
+        $haveHeader =  0;
4019
+        $info =  array();
4020
+        $idata =  '';
4021
+        $pdata =  '';
4022 4022
 
4023
-      while  ($p < $len) {
4023
+        while  ($p < $len) {
4024 4024
         $chunkLen =  $this->PRVT_getBytes($data, $p, 4);
4025 4025
         $chunkType =  mb_substr($data, $p+4, 4, '8bit');
4026 4026
         //      echo $chunkType.' - '.$chunkLen.'<br>';
@@ -4028,48 +4028,48 @@  discard block
 block discarded – undo
4028 4028
         case  'IHDR':
4029 4029
           // this is where all the file information comes from
4030 4030
           $info['width'] =  $this->PRVT_getBytes($data, $p+8, 4);
4031
-          $info['height'] =  $this->PRVT_getBytes($data, $p+12, 4);
4032
-          $info['bitDepth'] =  ord($data[$p+16]);
4033
-          $info['colorType'] =  ord($data[$p+17]);
4034
-          $info['compressionMethod'] =  ord($data[$p+18]);
4035
-          $info['filterMethod'] =  ord($data[$p+19]);
4036
-          $info['interlaceMethod'] =  ord($data[$p+20]);
4037
-
4038
-          //print_r($info);
4039
-          $haveHeader =  1;
4040
-          if  ($info['compressionMethod'] !=  0) {
4031
+            $info['height'] =  $this->PRVT_getBytes($data, $p+12, 4);
4032
+            $info['bitDepth'] =  ord($data[$p+16]);
4033
+            $info['colorType'] =  ord($data[$p+17]);
4034
+            $info['compressionMethod'] =  ord($data[$p+18]);
4035
+            $info['filterMethod'] =  ord($data[$p+19]);
4036
+            $info['interlaceMethod'] =  ord($data[$p+20]);
4037
+
4038
+            //print_r($info);
4039
+            $haveHeader =  1;
4040
+            if  ($info['compressionMethod'] !=  0) {
4041 4041
             $error =  1;
4042 4042
 
4043 4043
             //debugpng
4044 4044
             if (DEBUGPNG) print '[addPngFromFile unsupported compression method '.$file.']';
4045 4045
 
4046 4046
             $errormsg =  'unsupported compression method';
4047
-          }
4047
+            }
4048 4048
 
4049
-          if  ($info['filterMethod'] !=  0) {
4049
+            if  ($info['filterMethod'] !=  0) {
4050 4050
             $error =  1;
4051 4051
 
4052 4052
             //debugpng
4053 4053
             if (DEBUGPNG) print '[addPngFromFile unsupported filter method '.$file.']';
4054 4054
 
4055 4055
             $errormsg =  'unsupported filter method';
4056
-          }
4057
-          break;
4056
+            }
4057
+            break;
4058 4058
 
4059 4059
         case  'PLTE':
4060 4060
           $pdata.=  mb_substr($data, $p+8, $chunkLen, '8bit');
4061
-          break;
4061
+            break;
4062 4062
 
4063 4063
         case  'IDAT':
4064 4064
           $idata.=  mb_substr($data, $p+8, $chunkLen, '8bit');
4065
-          break;
4065
+            break;
4066 4066
 
4067 4067
         case  'tRNS':
4068 4068
           //this chunk can only occur once and it must occur after the PLTE chunk and before IDAT chunk
4069 4069
           //print "tRNS found, color type = ".$info['colorType']."\n";
4070 4070
           $transparency =  array();
4071 4071
 
4072
-          if  ($info['colorType'] ==  3) {
4072
+            if  ($info['colorType'] ==  3) {
4073 4073
             // indexed color, rbg
4074 4074
             /* corresponding to entries in the plte chunk
4075 4075
              Alpha for palette index 0: 1 byte
@@ -4083,13 +4083,13 @@  discard block
 block discarded – undo
4083 4083
             $trans =  0;
4084 4084
 
4085 4085
             for  ($i =  $chunkLen;$i >=  0;$i--) {
4086
-              if  (ord($data[$p+8+$i]) ==  0) {
4086
+                if  (ord($data[$p+8+$i]) ==  0) {
4087 4087
                 $trans =  $i;
4088
-              }
4088
+                }
4089 4089
             }
4090 4090
 
4091 4091
             $transparency['data'] =  $trans;
4092
-          } elseif ($info['colorType'] ==  0) {
4092
+            } elseif ($info['colorType'] ==  0) {
4093 4093
             // grayscale
4094 4094
             /* corresponding to entries in the plte chunk
4095 4095
              Gray: 2 bytes, range 0 .. (2^bitdepth)-1
@@ -4098,7 +4098,7 @@  discard block
 block discarded – undo
4098 4098
             $transparency['type'] =  'indexed';
4099 4099
 
4100 4100
             $transparency['data'] =  ord($data[$p+8+1]);
4101
-          } elseif ($info['colorType'] ==  2) {
4101
+            } elseif ($info['colorType'] ==  2) {
4102 4102
             // truecolor
4103 4103
             /* corresponding to entries in the plte chunk
4104 4104
              Red: 2 bytes, range 0 .. (2^bitdepth)-1
@@ -4114,176 +4114,176 @@  discard block
 block discarded – undo
4114 4114
 
4115 4115
             $transparency['type'] = 'color-key';
4116 4116
             
4117
-          } else {
4117
+            } else {
4118 4118
             //unsupported transparency type
4119 4119
             //debugpng
4120 4120
             if (DEBUGPNG) print '[addPngFromFile unsupported transparency type '.$file.']';
4121
-          }
4122
-          // KS End new code
4123
-          break;
4121
+            }
4122
+            // KS End new code
4123
+            break;
4124 4124
 
4125 4125
         default:
4126 4126
           break;
4127 4127
         }
4128 4128
 
4129 4129
         $p+=  $chunkLen+12;
4130
-      }
4130
+        }
4131 4131
 
4132 4132
 
4133
-      if (!$haveHeader) {
4133
+        if (!$haveHeader) {
4134 4134
         $error =  1;
4135 4135
 
4136 4136
         //debugpng
4137 4137
         if (DEBUGPNG) print '[addPngFromFile information header is missing '.$file.']';
4138 4138
 
4139 4139
         $errormsg =  'information header is missing';
4140
-      }
4140
+        }
4141 4141
 
4142
-      if  (isset($info['interlaceMethod']) &&  $info['interlaceMethod']) {
4142
+        if  (isset($info['interlaceMethod']) &&  $info['interlaceMethod']) {
4143 4143
         $error =  1;
4144 4144
 
4145 4145
         //debugpng
4146 4146
         if (DEBUGPNG) print '[addPngFromFile no support for interlaced images in pdf '.$file.']';
4147 4147
 
4148 4148
         $errormsg =  'There appears to be no support for interlaced images in pdf.';
4149
-      }
4149
+        }
4150 4150
     }
4151 4151
 
4152 4152
     if  (!$error &&  $info['bitDepth'] > 8) {
4153
-      $error =  1;
4153
+        $error =  1;
4154 4154
 
4155
-      //debugpng
4156
-      if (DEBUGPNG) print '[addPngFromFile bit depth of 8 or less is supported '.$file.']';
4155
+        //debugpng
4156
+        if (DEBUGPNG) print '[addPngFromFile bit depth of 8 or less is supported '.$file.']';
4157 4157
 
4158
-      $errormsg =  'only bit depth of 8 or less is supported';
4158
+        $errormsg =  'only bit depth of 8 or less is supported';
4159 4159
     }
4160 4160
 
4161 4161
     if  (!$error) {
4162
-      if  ($info['colorType'] !=  2 &&  $info['colorType'] !=  0 &&  $info['colorType'] !=  3) {
4162
+        if  ($info['colorType'] !=  2 &&  $info['colorType'] !=  0 &&  $info['colorType'] !=  3) {
4163 4163
         $error =  1;
4164 4164
 
4165 4165
         //debugpng
4166 4166
         if (DEBUGPNG) print '[addPngFromFile alpha channel not supported: '.$info['colorType'].' '.$file.']';
4167 4167
 
4168 4168
         $errormsg =  'transparancey alpha channel not supported, transparency only supported for palette images.';
4169
-      } else {
4169
+        } else {
4170 4170
         switch  ($info['colorType']) {
4171 4171
         case  3:
4172 4172
           $color =  'DeviceRGB';
4173
-          $ncolor =  1;
4174
-          break;
4173
+            $ncolor =  1;
4174
+            break;
4175 4175
 
4176 4176
         case  2:
4177 4177
           $color =  'DeviceRGB';
4178
-          $ncolor =  3;
4179
-          break;
4178
+            $ncolor =  3;
4179
+            break;
4180 4180
 
4181 4181
         case  0:
4182 4182
           $color =  'DeviceGray';
4183
-          $ncolor =  1;
4184
-          break;
4183
+            $ncolor =  1;
4184
+            break;
4185
+        }
4185 4186
         }
4186
-      }
4187 4187
     }
4188 4188
 
4189 4189
     if  ($error) {
4190
-      $this->addMessage('PNG error - ('.$file.') '.$errormsg);
4191
-      return;
4190
+        $this->addMessage('PNG error - ('.$file.') '.$errormsg);
4191
+        return;
4192 4192
     }
4193 4193
 
4194
-      //print_r($info);
4195
-      // so this image is ok... add it in.
4196
-      $this->numImages++;
4197
-      $im =  $this->numImages;
4198
-      $label =  'I'.$im;
4199
-      $this->numObj++;
4194
+        //print_r($info);
4195
+        // so this image is ok... add it in.
4196
+        $this->numImages++;
4197
+        $im =  $this->numImages;
4198
+        $label =  'I'.$im;
4199
+        $this->numObj++;
4200 4200
 
4201
-      //  $this->o_image($this->numObj,'new',array('label' => $label,'data' => $idata,'iw' => $w,'ih' => $h,'type' => 'png','ic' => $info['width']));
4202
-      $options =  array('label' => $label, 'data' => $idata, 'bitsPerComponent' => $info['bitDepth'], 'pdata' => $pdata, 'iw' => $info['width'], 'ih' => $info['height'], 'type' => 'png', 'color' => $color, 'ncolor' => $ncolor);
4201
+        //  $this->o_image($this->numObj,'new',array('label' => $label,'data' => $idata,'iw' => $w,'ih' => $h,'type' => 'png','ic' => $info['width']));
4202
+        $options =  array('label' => $label, 'data' => $idata, 'bitsPerComponent' => $info['bitDepth'], 'pdata' => $pdata, 'iw' => $info['width'], 'ih' => $info['height'], 'type' => 'png', 'color' => $color, 'ncolor' => $ncolor);
4203 4203
 
4204
-      if  (isset($transparency)) {
4204
+        if  (isset($transparency)) {
4205 4205
         $options['transparency'] =  $transparency;
4206
-      }
4206
+        }
4207 4207
 
4208
-      $this->o_image($this->numObj, 'new', $options);
4209
-      $this->imagelist[$file] = array('label' =>$label, 'w' => $info['width'], 'h' => $info['height']);
4208
+        $this->o_image($this->numObj, 'new', $options);
4209
+        $this->imagelist[$file] = array('label' =>$label, 'w' => $info['width'], 'h' => $info['height']);
4210 4210
     }
4211 4211
 
4212 4212
     if  ($w <=  0 && $h <=  0) {
4213
-      $w =  $info['width'];
4214
-      $h =  $info['height'];
4213
+        $w =  $info['width'];
4214
+        $h =  $info['height'];
4215 4215
     }
4216 4216
 
4217 4217
     if  ($w <=  0) {
4218
-      $w =  $h/$info['height']*$info['width'];
4218
+        $w =  $h/$info['height']*$info['width'];
4219 4219
     }
4220 4220
 
4221 4221
     if  ($h <=  0) {
4222
-      $h =  $w*$info['height']/$info['width'];
4222
+        $h =  $w*$info['height']/$info['width'];
4223 4223
     }
4224 4224
 
4225 4225
     $this->objects[$this->currentContents]['c'].=  "\nq";
4226 4226
     $this->objects[$this->currentContents]['c'].=  "\n".sprintf('%.3F', $w) ." 0 0 ".sprintf('%.3F', $h) ." ".sprintf('%.3F', $x) ." ".sprintf('%.3F', $y) ." cm";
4227 4227
     $this->objects[$this->currentContents]['c'].=  "\n/".$label.' Do';
4228 4228
     $this->objects[$this->currentContents]['c'].=  "\nQ";
4229
-  }
4229
+    }
4230 4230
 
4231 4231
 
4232
-  /**
4233
-   * add a JPEG image into the document, from a file
4234
-   */
4235
-  function  addJpegFromFile($img, $x, $y, $w =  0, $h =  0) {
4232
+    /**
4233
+     * add a JPEG image into the document, from a file
4234
+     */
4235
+    function  addJpegFromFile($img, $x, $y, $w =  0, $h =  0) {
4236 4236
     // attempt to add a jpeg image straight from a file, using no GD commands
4237 4237
     // note that this function is unable to operate on a remote file.
4238 4238
 
4239 4239
     if  (!file_exists($img)) {
4240
-      return;
4240
+        return;
4241 4241
     }
4242 4242
 
4243
-	if ( isset($this->imagelist[$img]) ) {
4244
-	  $data = null;
4245
-      $imageWidth = $this->imagelist[$img]['w'];
4246
-      $imageHeight = $this->imagelist[$img]['h'];
4247
-      $channels =  $this->imagelist[$img]['c'];
4248
-	} else {
4249
-      $tmp =  getimagesize($img);
4250
-      $imageWidth =  $tmp[0];
4251
-      $imageHeight =  $tmp[1];
4243
+    if ( isset($this->imagelist[$img]) ) {
4244
+        $data = null;
4245
+        $imageWidth = $this->imagelist[$img]['w'];
4246
+        $imageHeight = $this->imagelist[$img]['h'];
4247
+        $channels =  $this->imagelist[$img]['c'];
4248
+    } else {
4249
+        $tmp =  getimagesize($img);
4250
+        $imageWidth =  $tmp[0];
4251
+        $imageHeight =  $tmp[1];
4252 4252
 
4253
-      if  (isset($tmp['channels'])) {
4253
+        if  (isset($tmp['channels'])) {
4254 4254
         $channels =  $tmp['channels'];
4255
-      } else {
4255
+        } else {
4256 4256
         $channels =  3;
4257
-      }
4257
+        }
4258 4258
 
4259
-      //$fp = fopen($img,'rb');
4260
-      $data =  file_get_contents($img);
4261
-      //fread($fp,filesize($img));
4262
-      //fclose($fp);
4259
+        //$fp = fopen($img,'rb');
4260
+        $data =  file_get_contents($img);
4261
+        //fread($fp,filesize($img));
4262
+        //fclose($fp);
4263 4263
     }
4264 4264
 
4265 4265
     if  ($w <=  0 &&  $h <=  0) {
4266
-      $w =  $imageWidth;
4266
+        $w =  $imageWidth;
4267 4267
     }
4268 4268
 
4269 4269
     if  ($w ==  0) {
4270
-      $w =  $h/$imageHeight*$imageWidth;
4270
+        $w =  $h/$imageHeight*$imageWidth;
4271 4271
     }
4272 4272
 
4273 4273
     if  ($h ==  0) {
4274
-      $h =  $w*$imageHeight/$imageWidth;
4274
+        $h =  $w*$imageHeight/$imageWidth;
4275 4275
     }
4276 4276
 
4277 4277
     $this->addJpegImage_common($data, $x, $y, $w, $h, $imageWidth, $imageHeight, $channels, $img);
4278
-  }
4278
+    }
4279 4279
 
4280 4280
 
4281
-  /**
4282
-   * add an image into the document, from a GD object
4283
-   * this function is not all that reliable, and I would probably encourage people to use
4284
-   * the file based functions
4285
-   */
4286
-  function  addImage(&$img, $x, $y, $w =  0, $h =  0, $quality =  75) {
4281
+    /**
4282
+     * add an image into the document, from a GD object
4283
+     * this function is not all that reliable, and I would probably encourage people to use
4284
+     * the file based functions
4285
+     */
4286
+    function  addImage(&$img, $x, $y, $w =  0, $h =  0, $quality =  75) {
4287 4287
     /* Todo:
4288 4288
      * Pass in original filename as $imgname
4289 4289
      * If already cached like image_iscached(), allow empty $img
@@ -4303,7 +4303,7 @@  discard block
 block discarded – undo
4303 4303
     // there seems to be some problem here in that images that have quality set above 75 do not appear
4304 4304
     // not too sure why this is, but in the meantime I have restricted this to 75.
4305 4305
     if  ($quality>75) {
4306
-      $quality =  75;
4306
+        $quality =  75;
4307 4307
     }
4308 4308
 
4309 4309
     // if the width or height are set to zero, then set the other one based on keeping the image
@@ -4312,15 +4312,15 @@  discard block
 block discarded – undo
4312 4312
     $imageHeight =  imagesy($img);
4313 4313
 
4314 4314
     if  ($w <=  0 &&  $h <=  0) {
4315
-      return;
4315
+        return;
4316 4316
     }
4317 4317
 
4318 4318
     if  ($w ==  0) {
4319
-      $w =  $h/$imageHeight*$imageWidth;
4319
+        $w =  $h/$imageHeight*$imageWidth;
4320 4320
     }
4321 4321
 
4322 4322
     if  ($h ==  0) {
4323
-      $h =  $w*$imageHeight/$imageWidth;
4323
+        $h =  $w*$imageHeight/$imageWidth;
4324 4324
     }
4325 4325
 
4326 4326
     // gotta get the data out of the img..
@@ -4330,55 +4330,55 @@  discard block
 block discarded – undo
4330 4330
     $data = ob_get_clean();
4331 4331
 
4332 4332
     $this->addJpegImage_common($data, $x, $y, $w, $h, $imageWidth, $imageHeight, $imgname);
4333
-  }
4333
+    }
4334 4334
 
4335 4335
 
4336
-  /* Check if image already added to pdf image directory.
4336
+    /* Check if image already added to pdf image directory.
4337 4337
    * If yes, need not to create again (pass empty data)
4338 4338
    */
4339
-  function  image_iscached($imgname) {
4339
+    function  image_iscached($imgname) {
4340 4340
     return isset($this->imagelist[$imgname]);
4341
-  }
4341
+    }
4342 4342
 
4343 4343
 
4344
-  /**
4345
-   * common code used by the two JPEG adding functions
4346
-   *
4347
-   * @access private
4348
-   */
4349
-  function  addJpegImage_common(&$data, $x, $y, $w =  0, $h =  0, $imageWidth, $imageHeight, $channels =  3, $imgname) {
4344
+    /**
4345
+     * common code used by the two JPEG adding functions
4346
+     *
4347
+     * @access private
4348
+     */
4349
+    function  addJpegImage_common(&$data, $x, $y, $w =  0, $h =  0, $imageWidth, $imageHeight, $channels =  3, $imgname) {
4350 4350
     if ( isset($this->imagelist[$imgname]) ) {
4351
-      $label = $this->imagelist[$imgname]['label'];
4352
-      //debugpng
4353
-      //if (DEBUGPNG) print '[addJpegImage_common Duplicate '.$imgname.']';
4351
+        $label = $this->imagelist[$imgname]['label'];
4352
+        //debugpng
4353
+        //if (DEBUGPNG) print '[addJpegImage_common Duplicate '.$imgname.']';
4354 4354
 
4355 4355
     } else {
4356
-      if ($data == null) {
4357
-      	$this->addMessage('addJpegImage_common error - ('.$imgname.') data not present!');
4356
+        if ($data == null) {
4357
+            $this->addMessage('addJpegImage_common error - ('.$imgname.') data not present!');
4358 4358
         return;
4359
-      }
4359
+        }
4360 4360
 
4361
-      // note that this function is not to be called externally
4362
-      // it is just the common code between the GD and the file options
4363
-      $this->numImages++;
4364
-      $im =  $this->numImages;
4365
-      $label =  'I'.$im;
4366
-      $this->numObj++;
4367
-      $this->o_image($this->numObj, 'new', array('label' => $label, 'data' => &$data, 'iw' => $imageWidth, 'ih' => $imageHeight, 'channels' => $channels));
4368
-      $this->imagelist[$imgname] = array('label' =>$label, 'w' => $imageWidth, 'h' => $imageHeight, 'c'=> $channels );
4361
+        // note that this function is not to be called externally
4362
+        // it is just the common code between the GD and the file options
4363
+        $this->numImages++;
4364
+        $im =  $this->numImages;
4365
+        $label =  'I'.$im;
4366
+        $this->numObj++;
4367
+        $this->o_image($this->numObj, 'new', array('label' => $label, 'data' => &$data, 'iw' => $imageWidth, 'ih' => $imageHeight, 'channels' => $channels));
4368
+        $this->imagelist[$imgname] = array('label' =>$label, 'w' => $imageWidth, 'h' => $imageHeight, 'c'=> $channels );
4369 4369
     }
4370 4370
 
4371 4371
     $this->objects[$this->currentContents]['c'].=  "\nq";
4372 4372
     $this->objects[$this->currentContents]['c'].=  "\n".sprintf('%.3F', $w) ." 0 0 ".sprintf('%.3F', $h) ." ".sprintf('%.3F', $x) ." ".sprintf('%.3F', $y) ." cm";
4373 4373
     $this->objects[$this->currentContents]['c'].=  "\n/".$label.' Do';
4374 4374
     $this->objects[$this->currentContents]['c'].=  "\nQ";
4375
-  }
4375
+    }
4376 4376
 
4377 4377
 
4378
-  /**
4379
-   * specify where the document should open when it first starts
4380
-   */
4381
-  function  openHere($style, $a =  0, $b =  0, $c =  0) {
4378
+    /**
4379
+     * specify where the document should open when it first starts
4380
+     */
4381
+    function  openHere($style, $a =  0, $b =  0, $c =  0) {
4382 4382
     // this function will open the document at a specified page, in a specified style
4383 4383
     // the values for style, and the required paramters are:
4384 4384
     // 'XYZ'  left, top, zoom
@@ -4393,17 +4393,17 @@  discard block
 block discarded – undo
4393 4393
     $this->o_destination($this->numObj, 'new', array('page' => $this->currentPage, 'type' => $style, 'p1' => $a, 'p2' => $b, 'p3' => $c));
4394 4394
     $id =  $this->catalogId;
4395 4395
     $this->o_catalog($id, 'openHere', $this->numObj);
4396
-  }
4396
+    }
4397 4397
   
4398
-  function addJavascript($code) {
4398
+    function addJavascript($code) {
4399 4399
     $this->javascript .= $code;
4400
-  }
4400
+    }
4401 4401
 
4402 4402
 
4403
-  /**
4404
-   * create a labelled destination within the document
4405
-   */
4406
-  function  addDestination($label, $style, $a =  0, $b =  0, $c =  0) {
4403
+    /**
4404
+     * create a labelled destination within the document
4405
+     */
4406
+    function  addDestination($label, $style, $a =  0, $b =  0, $c =  0) {
4407 4407
     // associates the given label with the destination, it is done this way so that a destination can be specified after
4408 4408
     // it has been linked to
4409 4409
     // styles are the same as the 'openHere' function
@@ -4413,78 +4413,78 @@  discard block
 block discarded – undo
4413 4413
 
4414 4414
     // store the label->idf relationship, note that this means that labels can be used only once
4415 4415
     $this->destinations["$label"] =  $id;
4416
-  }
4416
+    }
4417 4417
 
4418 4418
 
4419
-  /**
4420
-   * define font families, this is used to initialize the font families for the default fonts
4421
-   * and for the user to add new ones for their fonts. The default bahavious can be overridden should
4422
-   * that be desired.
4423
-   */
4424
-  function  setFontFamily($family, $options =  '') {
4419
+    /**
4420
+     * define font families, this is used to initialize the font families for the default fonts
4421
+     * and for the user to add new ones for their fonts. The default bahavious can be overridden should
4422
+     * that be desired.
4423
+     */
4424
+    function  setFontFamily($family, $options =  '') {
4425 4425
     if  (!is_array($options)) {
4426
-      if  ($family ===  'init') {
4426
+        if  ($family ===  'init') {
4427 4427
         // set the known family groups
4428 4428
         // these font families will be used to enable bold and italic markers to be included
4429 4429
         // within text streams. html forms will be used... <b></b> <i></i>
4430 4430
         $this->fontFamilies['Helvetica.afm'] =
4431
-          array('b' => 'Helvetica-Bold.afm',
4431
+            array('b' => 'Helvetica-Bold.afm',
4432 4432
                 'i' => 'Helvetica-Oblique.afm',
4433 4433
                 'bi' => 'Helvetica-BoldOblique.afm',
4434 4434
                 'ib' => 'Helvetica-BoldOblique.afm');
4435 4435
 
4436 4436
         $this->fontFamilies['Courier.afm'] =
4437
-          array('b' => 'Courier-Bold.afm',
4437
+            array('b' => 'Courier-Bold.afm',
4438 4438
                 'i' => 'Courier-Oblique.afm',
4439 4439
                 'bi' => 'Courier-BoldOblique.afm',
4440 4440
                 'ib' => 'Courier-BoldOblique.afm');
4441 4441
 
4442 4442
         $this->fontFamilies['Times-Roman.afm'] =
4443
-          array('b' => 'Times-Bold.afm',
4443
+            array('b' => 'Times-Bold.afm',
4444 4444
                 'i' => 'Times-Italic.afm',
4445 4445
                 'bi' => 'Times-BoldItalic.afm',
4446 4446
                 'ib' => 'Times-BoldItalic.afm');
4447
-      }
4447
+        }
4448 4448
     } else {
4449 4449
 
4450
-      // the user is trying to set a font family
4451
-      // note that this can also be used to set the base ones to something else
4452
-      if  (mb_strlen($family)) {
4450
+        // the user is trying to set a font family
4451
+        // note that this can also be used to set the base ones to something else
4452
+        if  (mb_strlen($family)) {
4453 4453
         $this->fontFamilies[$family] =  $options;
4454
-      }
4454
+        }
4455
+    }
4455 4456
     }
4456
-  }
4457 4457
 
4458 4458
 
4459
-  /**
4460
-   * used to add messages for use in debugging
4461
-   */
4462
-  function  addMessage($message) {
4459
+    /**
4460
+     * used to add messages for use in debugging
4461
+     */
4462
+    function  addMessage($message) {
4463 4463
     $this->messages.=  $message."\n";
4464
-  }
4464
+    }
4465 4465
 
4466 4466
 
4467
-  /**
4468
-   * a few functions which should allow the document to be treated transactionally.
4469
-   */
4470
-  function  transaction($action) {
4467
+    /**
4468
+     * a few functions which should allow the document to be treated transactionally.
4469
+     */
4470
+    function  transaction($action) {
4471 4471
     switch  ($action) {
4472 4472
     case  'start':
4473 4473
       // store all the data away into the checkpoint variable
4474 4474
       $data =  get_object_vars($this);
4475
-      $this->checkpoint =  $data;
4476
-      unset($data);
4477
-      break;
4475
+        $this->checkpoint =  $data;
4476
+        unset($data);
4477
+        break;
4478 4478
 
4479 4479
     case  'commit':
4480 4480
       if  (is_array($this->checkpoint) &&  isset($this->checkpoint['checkpoint'])) {
4481 4481
         $tmp =  $this->checkpoint['checkpoint'];
4482 4482
         $this->checkpoint =  $tmp;
4483 4483
         unset($tmp);
4484
-      } else {
4484
+        } else {
4485 4485
         $this->checkpoint =  '';
4486
-      }
4487
-      break;
4486
+        }
4487
+        break;
4488 4488
 
4489 4489
     case  'rewind':
4490 4490
       // do not destroy the current checkpoint, but move us back to the state then, so that we can try again
@@ -4493,25 +4493,25 @@  discard block
 block discarded – undo
4493 4493
         $tmp =  $this->checkpoint;
4494 4494
 
4495 4495
         foreach ($tmp as  $k => $v) {
4496
-          if  ($k !==  'checkpoint') {
4496
+            if  ($k !==  'checkpoint') {
4497 4497
             $this->$k =  $v;
4498
-          }
4498
+            }
4499 4499
         }
4500 4500
         unset($tmp);
4501
-      }
4502
-      break;
4501
+        }
4502
+        break;
4503 4503
 
4504 4504
     case  'abort':
4505 4505
       if  (is_array($this->checkpoint)) {
4506 4506
         // can only abort if were inside a checkpoint
4507 4507
         $tmp =  $this->checkpoint;
4508 4508
         foreach ($tmp as  $k => $v) {
4509
-          $this->$k =  $v;
4509
+            $this->$k =  $v;
4510 4510
         }
4511 4511
         unset($tmp);
4512
-      }
4513
-      break;
4512
+        }
4513
+        break;
4514
+    }
4514 4515
     }
4515
-  }
4516 4516
 }
4517 4517
 // end of class
Please login to merge, or discard this patch.
main/inc/lib/phpdocx/classes/CreateExcelTable.inc 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -132,11 +132,11 @@  discard block
 block discarded – undo
132 132
             $chart++;
133 133
         $rows++;
134 134
         $this->_xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.
135
-                      '<table xmlns="http://schemas.openxmlformats.org/spreads'.
136
-                      'heetml/2006/main" id="1" name="Tabla1" displayName='.
137
-                      '"Tabla1" ref="A1:' . $chart . $rows .
138
-                      '" totalsRowShown="0" tableBorderDxfId="0">'.
139
-                      '__GENERATETABLE__</table>';
135
+                        '<table xmlns="http://schemas.openxmlformats.org/spreads'.
136
+                        'heetml/2006/main" id="1" name="Tabla1" displayName='.
137
+                        '"Tabla1" ref="A1:' . $chart . $rows .
138
+                        '" totalsRowShown="0" tableBorderDxfId="0">'.
139
+                        '__GENERATETABLE__</table>';
140 140
     }
141 141
 
142 142
     /**
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
     protected function generateTABLECOLUMNS($count = '2')
149 149
     {
150 150
         $xml = '<tableColumns count="' . $count .
151
-               '">__GENERATETABLECOLUMNS__</tableColumns>__GENERATETABLE__';
151
+                '">__GENERATETABLECOLUMNS__</tableColumns>__GENERATETABLE__';
152 152
         
153 153
         $this->_xml = str_replace('__GENERATETABLE__', $xml, $this->_xml);
154 154
     }
@@ -180,15 +180,15 @@  discard block
 block discarded – undo
180 180
      * @access protected
181 181
      */
182 182
     protected function generateTABLESTYLEINFO($showFirstColumn = '0',
183
-                                               $showLastColumn  = "0",
184
-                                               $showRowStripes  = "1",
185
-                                               $showColumnStripes = "0")
183
+                                                $showLastColumn  = "0",
184
+                                                $showRowStripes  = "1",
185
+                                                $showColumnStripes = "0")
186 186
     {
187 187
         $xml = '<tableStyleInfo   showFirstColumn="' . $showFirstColumn .
188
-               '" showLastColumn="' . $showLastColumn .
189
-               '" showRowStripes="' . $showRowStripes .
190
-               '" showColumnStripes="' . $showColumnStripes .
191
-               '"></tableStyleInfo >';
188
+                '" showLastColumn="' . $showLastColumn .
189
+                '" showRowStripes="' . $showRowStripes .
190
+                '" showColumnStripes="' . $showColumnStripes .
191
+                '"></tableStyleInfo >';
192 192
         
193 193
         $this->_xml = str_replace('__GENERATETABLE__', $xml, $this->_xml);
194 194
     }
Please login to merge, or discard this patch.
main/inc/lib/phpdocx/classes/CreateExcelSharedStrings.inc 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -142,10 +142,10 @@
 block discarded – undo
142 142
     protected function generateSST($num)
143 143
     {
144 144
         $this->_xml = '<?xml version="1.0" encoding="UTF-8" '.
145
-                      'standalone="yes" ?><sst xmlns="http://schemas.'.
146
-                      'openxmlformats.org/spreadsheetml/2006/main" '.
147
-                      'count="' . $num . '" uniqueCount="' . $num .
148
-                      '">__GENERATESST__</sst>';
145
+                        'standalone="yes" ?><sst xmlns="http://schemas.'.
146
+                        'openxmlformats.org/spreadsheetml/2006/main" '.
147
+                        'count="' . $num . '" uniqueCount="' . $num .
148
+                        '">__GENERATESST__</sst>';
149 149
     }
150 150
 
151 151
     /**
Please login to merge, or discard this patch.
main/inc/lib/phpdocx/classes/CreateElement.inc 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
      * @access protected
229 229
      */
230 230
     protected function generateINLINE($distT = '0', $distB ='0',
231
-                                      $distL = '0', $distR ='0')
231
+                                        $distL = '0', $distR ='0')
232 232
     {
233 233
         $xml = '<' . CreateImage::NAMESPACEWORD .
234 234
                 ':inline distT="' . $distT . '" distB="' . $distB .
@@ -255,11 +255,11 @@  discard block
 block discarded – undo
255 255
      * @access protected
256 256
      */
257 257
     protected function generateANCHOR($behindDoc = 0, $distT = '0',
258
-                                      $distB = '0', $distL = '114300',
259
-                                      $distR = '114300', $simplePos = 0,
260
-                                      $relativeHeight = '251658240',
261
-                                      $locked = 0, $layoutInCell = 1,
262
-                                      $allowOverlap = 1)
258
+                                        $distB = '0', $distL = '114300',
259
+                                        $distR = '114300', $simplePos = 0,
260
+                                        $relativeHeight = '251658240',
261
+                                        $locked = 0, $layoutInCell = 1,
262
+                                        $allowOverlap = 1)
263 263
     {
264 264
         $xml = '<' . CreateImage::NAMESPACEWORD . ':anchor distT="' . $distT .
265 265
                 '" distB="' . $distB . '" distL="' . $distL .
@@ -871,8 +871,8 @@  discard block
 block discarded – undo
871 871
     protected function generateQUITAR()
872 872
     {
873 873
         $this->_xml = '<' . CreateElement::NAMESPACEWORD .
874
-                      ':r>__GENERATER__</' . CreateElement::NAMESPACEWORD .
875
-                      ':r>';
874
+                        ':r>__GENERATER__</' . CreateElement::NAMESPACEWORD .
875
+                        ':r>';
876 876
     }
877 877
 
878 878
     /**
Please login to merge, or discard this patch.
main/inc/lib/phpdocx/classes/CreateGraphic.inc 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -993,8 +993,8 @@  discard block
 block discarded – undo
993 993
     protected function generateLEGENDPOS($val = 'r')
994 994
     {
995 995
         $xml = '<' . CreateGraphic::NAMESPACEWORD . ':legendPos val="' . 
996
-             $val . '"></' . CreateGraphic::NAMESPACEWORD .
997
-             ':legendPos>__GENERATELEGEND__';
996
+                $val . '"></' . CreateGraphic::NAMESPACEWORD .
997
+                ':legendPos>__GENERATELEGEND__';
998 998
         $this->_xmlChart = str_replace(
999 999
             '__GENERATELEGEND__', $xml, $this->_xmlChart
1000 1000
         );
@@ -1416,7 +1416,7 @@  discard block
 block discarded – undo
1416 1416
      * @param string $sourceLinked
1417 1417
      */
1418 1418
     protected function generateNUMFMT($formatCode='General',
1419
-                                      $sourceLinked = '1')
1419
+                                        $sourceLinked = '1')
1420 1420
     {
1421 1421
         $this->_xmlChart = str_replace(
1422 1422
             '__GENERATEAX__', '<' .
Please login to merge, or discard this patch.
main/inc/lib/phpdocx/classes/CreateFooter.inc 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
             }
169 169
         } else {
170 170
             $this->_xml = '<' . CreateElement::NAMESPACEWORD .
171
-                          ':r>__GENERATER__</' . CreateElement::NAMESPACEWORD .
172
-                          ':r>__GENERATERSUB__';
171
+                            ':r>__GENERATER__</' . CreateElement::NAMESPACEWORD .
172
+                            ':r>__GENERATERSUB__';
173 173
         }
174 174
     }
175 175
 
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
      * @access protected
183 183
      */
184 184
     protected function generatePTAB($relativeTo = 'margin',
185
-                                     $alignment = 'right',
186
-                                     $leader = 'none')
185
+                                        $alignment = 'right',
186
+                                        $leader = 'none')
187 187
     {
188 188
         $xml = '<' . CreateElement::NAMESPACEWORD .
189 189
                 ':ptab ' . CreateElement::NAMESPACEWORD .
Please login to merge, or discard this patch.
main/inc/lib/phpdocx/classes/CreateFootnote.inc 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
         if ($type != '')
193 193
             $xmlAux .= ' ' . CreateElement::NAMESPACEWORD . 
194
-                       ':type="' . $type . '"';
194
+                        ':type="' . $type . '"';
195 195
 
196 196
         $this->_xml = $xmlAux . ' ' . CreateElement::NAMESPACEWORD .
197 197
                     ':id="' . (self::$_id - 2) .
@@ -208,11 +208,11 @@  discard block
 block discarded – undo
208 208
      * @access protected
209 209
      */
210 210
     protected function generateP($rsidR = '005F02E5', 
211
-                                 $rsidRDefault = '005F02E5',
212
-                                 $rsidP = '005F02E5')
211
+                                    $rsidRDefault = '005F02E5',
212
+                                    $rsidP = '005F02E5')
213 213
     {
214 214
         $xml = '<' . CreateElement::NAMESPACEWORD .
215
-               ':p>__GENERATEP__</' . CreateElement::NAMESPACEWORD . ':p>';
215
+                ':p>__GENERATEP__</' . CreateElement::NAMESPACEWORD . ':p>';
216 216
 
217 217
         $this->_xml = str_replace('__GENERATEFOOTNOTE__', $xml, $this->_xml);
218 218
     }
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
      * @access protected
253 253
      */
254 254
     protected function generateSPACING($after = '0',
255
-                                       $line = '240', $lineRule = 'auto')
255
+                                        $line = '240', $lineRule = 'auto')
256 256
     {
257 257
         $xml = '<' . CreateElement::NAMESPACEWORD .
258 258
                 ':spacing w:after="' . $after .
Please login to merge, or discard this patch.
main/inc/lib/phpdocx/classes/CreateFontTable.inc 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
     protected function generateFONT($name = 'Calibri')
128 128
     {
129 129
         $this->_xml = '<' . CreateElement::NAMESPACEWORD . 
130
-                       ':font ' . CreateDocx::NAMESPACEWORD .
131
-                       ':name="' . $name .
132
-                       '">__GENERATEFONT__</' . CreateElement::NAMESPACEWORD .
133
-                       ':font>';
130
+                        ':font ' . CreateDocx::NAMESPACEWORD .
131
+                        ':name="' . $name .
132
+                        '">__GENERATEFONT__</' . CreateElement::NAMESPACEWORD .
133
+                        ':font>';
134 134
     }
135 135
 
136 136
     /**
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
     protected function generatePANOSE1($val = '020F0502020204030204')
143 143
     {
144 144
         $xml = '<' . CreateElement::NAMESPACEWORD .
145
-               ':panose1 ' . CreateElement::NAMESPACEWORD .
146
-               ':val="' . $val .
147
-               '"></' . CreateElement::NAMESPACEWORD .
148
-               ':panose1>__GENERATEPANOSE1__';
145
+                ':panose1 ' . CreateElement::NAMESPACEWORD .
146
+                ':val="' . $val .
147
+                '"></' . CreateElement::NAMESPACEWORD .
148
+                ':panose1>__GENERATEPANOSE1__';
149 149
 
150 150
         $this->_xml = str_replace('__GENERATEFONT__', $xml, $this->_xml);
151 151
     }
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
     protected function generateCHARSET($val = '00')
160 160
     {
161 161
         $xml = '<' . CreateElement::NAMESPACEWORD .
162
-               ':charset ' . CreateElement::NAMESPACEWORD .
163
-               ':val="' . $val . '"></' . CreateElement::NAMESPACEWORD .
164
-               ':charset>__GENERATECHARSET__';
162
+                ':charset ' . CreateElement::NAMESPACEWORD .
163
+                ':val="' . $val . '"></' . CreateElement::NAMESPACEWORD .
164
+                ':charset>__GENERATECHARSET__';
165 165
 
166 166
         $this->_xml = str_replace('__GENERATEPANOSE1__', $xml, $this->_xml);
167 167
     }
@@ -212,18 +212,18 @@  discard block
 block discarded – undo
212 212
      * @access protected
213 213
      */
214 214
     protected function generateSIG($usbA = 'A00002EF', $usbB = '4000207B',
215
-                                   $usbC = '00000000', $usbD = '00000000',
216
-                                   $csbA = '0000009F', $csbB = '00000000')
215
+                                    $usbC = '00000000', $usbD = '00000000',
216
+                                    $csbA = '0000009F', $csbB = '00000000')
217 217
     {
218 218
         $xml = '<' . CreateElement::NAMESPACEWORD .
219
-               ':sig ' . CreateElement::NAMESPACEWORD .
220
-               ':usb0="' . $usbA . '" ' . CreateElement::NAMESPACEWORD .
221
-               ':usb1="' . $usbB . '" ' . CreateElement::NAMESPACEWORD .
222
-               ':usb2="' . $usbC . '" ' . CreateElement::NAMESPACEWORD .
223
-               ':usb3="' . $usbD . '" ' . CreateElement::NAMESPACEWORD .
224
-               ':csb0="' . $csbA . '" ' . CreateElement::NAMESPACEWORD .
225
-               ':csb1="' . $csbB . '"></' . CreateElement::NAMESPACEWORD .
226
-               ':sig>';
219
+                ':sig ' . CreateElement::NAMESPACEWORD .
220
+                ':usb0="' . $usbA . '" ' . CreateElement::NAMESPACEWORD .
221
+                ':usb1="' . $usbB . '" ' . CreateElement::NAMESPACEWORD .
222
+                ':usb2="' . $usbC . '" ' . CreateElement::NAMESPACEWORD .
223
+                ':usb3="' . $usbD . '" ' . CreateElement::NAMESPACEWORD .
224
+                ':csb0="' . $csbA . '" ' . CreateElement::NAMESPACEWORD .
225
+                ':csb1="' . $csbB . '"></' . CreateElement::NAMESPACEWORD .
226
+                ':sig>';
227 227
 
228 228
         $this->_xml = str_replace('__GENERATEPITCH__', $xml, $this->_xml);
229 229
     }
Please login to merge, or discard this patch.