@@ -175,101 +175,101 @@ discard block |
||
175 | 175 | */ |
176 | 176 | public function __construct(string $orientation='P', string $unit='mm', $size='A4') |
177 | 177 | { |
178 | - // Some checks |
|
179 | - $this->_dochecks(); |
|
180 | - // Initialization of properties |
|
181 | - $this->state = 0; |
|
182 | - $this->page = 0; |
|
183 | - $this->n = 2; |
|
184 | - $this->buffer = ''; |
|
185 | - $this->pages = array(); |
|
186 | - $this->PageInfo = array(); |
|
187 | - $this->fonts = array(); |
|
188 | - $this->FontFiles = array(); |
|
189 | - $this->encodings = array(); |
|
190 | - $this->cmaps = array(); |
|
191 | - $this->images = array(); |
|
192 | - $this->links = array(); |
|
193 | - $this->InHeader = false; |
|
194 | - $this->InFooter = false; |
|
195 | - $this->lasth = 0; |
|
196 | - $this->FontFamily = ''; |
|
197 | - $this->FontStyle = ''; |
|
198 | - $this->FontSizePt = 12; |
|
199 | - $this->underline = false; |
|
200 | - $this->DrawColor = '0 G'; |
|
201 | - $this->FillColor = '0 g'; |
|
202 | - $this->TextColor = '0 g'; |
|
203 | - $this->ColorFlag = false; |
|
204 | - $this->WithAlpha = false; |
|
205 | - $this->ws = 0; |
|
206 | - // Font path |
|
207 | - if (defined('FPDF_FONTPATH')) { |
|
208 | - $this->fontpath = FPDF_FONTPATH; |
|
209 | - if (substr($this->fontpath, -1) != '/' && substr($this->fontpath, -1) != '\\') { |
|
210 | - $this->fontpath .= '/'; |
|
211 | - } |
|
212 | - } elseif (is_dir(dirname(__FILE__) . '/font')) { |
|
213 | - $this->fontpath = dirname(__FILE__) . '/font/'; |
|
214 | - } else { |
|
215 | - $this->fontpath = ''; |
|
216 | - } |
|
217 | - // Core fonts |
|
218 | - $this->CoreFonts = array('courier', 'helvetica', 'times', 'symbol', 'zapfdingbats'); |
|
219 | - // Scale factor |
|
220 | - if($unit == 'pt') { |
|
221 | - $this->k = 1; |
|
222 | - } elseif($unit == 'mm') { |
|
223 | - $this->k = 72/25.4; |
|
224 | - } elseif($unit == 'cm') { |
|
225 | - $this->k = 72/2.54; |
|
226 | - } elseif($unit == 'in') { |
|
227 | - $this->k = 72; |
|
228 | - } else { |
|
229 | - $this->Error('Incorrect unit: ' . $unit); |
|
230 | - } |
|
231 | - // Page sizes |
|
232 | - $this->StdPageSizes = array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28), |
|
233 | - 'letter'=>array(612,792), 'legal'=>array(612,1008)); |
|
234 | - $size = $this->_getpagesize($size); |
|
235 | - $this->DefPageSize = $size; |
|
236 | - $this->CurPageSize = $size; |
|
237 | - // Page orientation |
|
238 | - $orientation = strtolower($orientation); |
|
239 | - if($orientation=='p' || $orientation=='portrait') |
|
240 | - { |
|
241 | - $this->DefOrientation = 'P'; |
|
242 | - $this->w = $size[0]; |
|
243 | - $this->h = $size[1]; |
|
244 | - } |
|
245 | - elseif($orientation=='l' || $orientation=='landscape') |
|
246 | - { |
|
247 | - $this->DefOrientation = 'L'; |
|
248 | - $this->w = $size[1]; |
|
249 | - $this->h = $size[0]; |
|
250 | - } |
|
251 | - else |
|
252 | - $this->Error('Incorrect orientation: '.$orientation); |
|
253 | - $this->CurOrientation = $this->DefOrientation; |
|
254 | - $this->wPt = $this->w*$this->k; |
|
255 | - $this->hPt = $this->h*$this->k; |
|
256 | - // Page rotation |
|
257 | - $this->CurRotation = 0; |
|
258 | - // Page margins (1 cm) |
|
259 | - $margin = 28.35/$this->k; |
|
260 | - $this->setMargins($margin,$margin); |
|
261 | - // Interior cell margin (1 mm) |
|
262 | - $this->cMargin = $margin/10; |
|
263 | - // Line width (0.2 mm) |
|
264 | - $this->LineWidth = .567/$this->k; |
|
265 | - // Automatic page break |
|
266 | - $this->setAutoPageBreak(true,2*$margin); |
|
267 | - // Default display mode |
|
268 | - $this->setDisplayMode('default'); |
|
269 | - // Enable compression |
|
270 | - $this->setCompression(true); |
|
271 | - // Set default PDF version number |
|
272 | - $this->PDFVersion = '1.3'; |
|
178 | + // Some checks |
|
179 | + $this->_dochecks(); |
|
180 | + // Initialization of properties |
|
181 | + $this->state = 0; |
|
182 | + $this->page = 0; |
|
183 | + $this->n = 2; |
|
184 | + $this->buffer = ''; |
|
185 | + $this->pages = array(); |
|
186 | + $this->PageInfo = array(); |
|
187 | + $this->fonts = array(); |
|
188 | + $this->FontFiles = array(); |
|
189 | + $this->encodings = array(); |
|
190 | + $this->cmaps = array(); |
|
191 | + $this->images = array(); |
|
192 | + $this->links = array(); |
|
193 | + $this->InHeader = false; |
|
194 | + $this->InFooter = false; |
|
195 | + $this->lasth = 0; |
|
196 | + $this->FontFamily = ''; |
|
197 | + $this->FontStyle = ''; |
|
198 | + $this->FontSizePt = 12; |
|
199 | + $this->underline = false; |
|
200 | + $this->DrawColor = '0 G'; |
|
201 | + $this->FillColor = '0 g'; |
|
202 | + $this->TextColor = '0 g'; |
|
203 | + $this->ColorFlag = false; |
|
204 | + $this->WithAlpha = false; |
|
205 | + $this->ws = 0; |
|
206 | + // Font path |
|
207 | + if (defined('FPDF_FONTPATH')) { |
|
208 | + $this->fontpath = FPDF_FONTPATH; |
|
209 | + if (substr($this->fontpath, -1) != '/' && substr($this->fontpath, -1) != '\\') { |
|
210 | + $this->fontpath .= '/'; |
|
211 | + } |
|
212 | + } elseif (is_dir(dirname(__FILE__) . '/font')) { |
|
213 | + $this->fontpath = dirname(__FILE__) . '/font/'; |
|
214 | + } else { |
|
215 | + $this->fontpath = ''; |
|
216 | + } |
|
217 | + // Core fonts |
|
218 | + $this->CoreFonts = array('courier', 'helvetica', 'times', 'symbol', 'zapfdingbats'); |
|
219 | + // Scale factor |
|
220 | + if($unit == 'pt') { |
|
221 | + $this->k = 1; |
|
222 | + } elseif($unit == 'mm') { |
|
223 | + $this->k = 72/25.4; |
|
224 | + } elseif($unit == 'cm') { |
|
225 | + $this->k = 72/2.54; |
|
226 | + } elseif($unit == 'in') { |
|
227 | + $this->k = 72; |
|
228 | + } else { |
|
229 | + $this->Error('Incorrect unit: ' . $unit); |
|
230 | + } |
|
231 | + // Page sizes |
|
232 | + $this->StdPageSizes = array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28), |
|
233 | + 'letter'=>array(612,792), 'legal'=>array(612,1008)); |
|
234 | + $size = $this->_getpagesize($size); |
|
235 | + $this->DefPageSize = $size; |
|
236 | + $this->CurPageSize = $size; |
|
237 | + // Page orientation |
|
238 | + $orientation = strtolower($orientation); |
|
239 | + if($orientation=='p' || $orientation=='portrait') |
|
240 | + { |
|
241 | + $this->DefOrientation = 'P'; |
|
242 | + $this->w = $size[0]; |
|
243 | + $this->h = $size[1]; |
|
244 | + } |
|
245 | + elseif($orientation=='l' || $orientation=='landscape') |
|
246 | + { |
|
247 | + $this->DefOrientation = 'L'; |
|
248 | + $this->w = $size[1]; |
|
249 | + $this->h = $size[0]; |
|
250 | + } |
|
251 | + else |
|
252 | + $this->Error('Incorrect orientation: '.$orientation); |
|
253 | + $this->CurOrientation = $this->DefOrientation; |
|
254 | + $this->wPt = $this->w*$this->k; |
|
255 | + $this->hPt = $this->h*$this->k; |
|
256 | + // Page rotation |
|
257 | + $this->CurRotation = 0; |
|
258 | + // Page margins (1 cm) |
|
259 | + $margin = 28.35/$this->k; |
|
260 | + $this->setMargins($margin,$margin); |
|
261 | + // Interior cell margin (1 mm) |
|
262 | + $this->cMargin = $margin/10; |
|
263 | + // Line width (0.2 mm) |
|
264 | + $this->LineWidth = .567/$this->k; |
|
265 | + // Automatic page break |
|
266 | + $this->setAutoPageBreak(true,2*$margin); |
|
267 | + // Default display mode |
|
268 | + $this->setDisplayMode('default'); |
|
269 | + // Enable compression |
|
270 | + $this->setCompression(true); |
|
271 | + // Set default PDF version number |
|
272 | + $this->PDFVersion = '1.3'; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -281,12 +281,12 @@ discard block |
||
281 | 281 | */ |
282 | 282 | public function SetMargins(float $left, float $top, ?float $right=null) : void |
283 | 283 | { |
284 | - // Set left, top and right margins |
|
285 | - $this->lMargin = $left; |
|
286 | - $this->tMargin = $top; |
|
287 | - if($right===null) |
|
288 | - $right = $left; |
|
289 | - $this->rMargin = $right; |
|
284 | + // Set left, top and right margins |
|
285 | + $this->lMargin = $left; |
|
286 | + $this->tMargin = $top; |
|
287 | + if($right===null) |
|
288 | + $right = $left; |
|
289 | + $this->rMargin = $right; |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -297,10 +297,10 @@ discard block |
||
297 | 297 | */ |
298 | 298 | public function SetLeftMargin(float $margin) : void |
299 | 299 | { |
300 | - // Set left margin |
|
301 | - $this->lMargin = $margin; |
|
302 | - if($this->page>0 && $this->x<$margin) |
|
303 | - $this->x = $margin; |
|
300 | + // Set left margin |
|
301 | + $this->lMargin = $margin; |
|
302 | + if($this->page>0 && $this->x<$margin) |
|
303 | + $this->x = $margin; |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -310,8 +310,8 @@ discard block |
||
310 | 310 | */ |
311 | 311 | public function SetTopMargin(float $margin) : void |
312 | 312 | { |
313 | - // Set top margin |
|
314 | - $this->tMargin = $margin; |
|
313 | + // Set top margin |
|
314 | + $this->tMargin = $margin; |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -321,8 +321,8 @@ discard block |
||
321 | 321 | */ |
322 | 322 | public function SetRightMargin(float $margin) : void |
323 | 323 | { |
324 | - // Set right margin |
|
325 | - $this->rMargin = $margin; |
|
324 | + // Set right margin |
|
325 | + $this->rMargin = $margin; |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -335,10 +335,10 @@ discard block |
||
335 | 335 | */ |
336 | 336 | public function SetAutoPageBreak(bool $auto, float $margin=0) : void |
337 | 337 | { |
338 | - // Set auto page break mode and triggering margin |
|
339 | - $this->AutoPageBreak = $auto; |
|
340 | - $this->bMargin = $margin; |
|
341 | - $this->PageBreakTrigger = $this->h-$margin; |
|
338 | + // Set auto page break mode and triggering margin |
|
339 | + $this->AutoPageBreak = $auto; |
|
340 | + $this->bMargin = $margin; |
|
341 | + $this->PageBreakTrigger = $this->h-$margin; |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -371,15 +371,15 @@ discard block |
||
371 | 371 | */ |
372 | 372 | public function SetDisplayMode($zoom, string $layout='default') : void |
373 | 373 | { |
374 | - // Set display mode in viewer |
|
375 | - if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) |
|
376 | - $this->ZoomMode = $zoom; |
|
377 | - else |
|
378 | - $this->Error('Incorrect zoom display mode: '.$zoom); |
|
379 | - if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') |
|
380 | - $this->LayoutMode = $layout; |
|
381 | - else |
|
382 | - $this->Error('Incorrect layout display mode: '.$layout); |
|
374 | + // Set display mode in viewer |
|
375 | + if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) |
|
376 | + $this->ZoomMode = $zoom; |
|
377 | + else |
|
378 | + $this->Error('Incorrect zoom display mode: '.$zoom); |
|
379 | + if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') |
|
380 | + $this->LayoutMode = $layout; |
|
381 | + else |
|
382 | + $this->Error('Incorrect layout display mode: '.$layout); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
@@ -393,11 +393,11 @@ discard block |
||
393 | 393 | */ |
394 | 394 | public function SetCompression(bool $compress) : void |
395 | 395 | { |
396 | - // Set page compression |
|
397 | - if(function_exists('gzcompress')) |
|
398 | - $this->compress = $compress; |
|
399 | - else |
|
400 | - $this->compress = false; |
|
396 | + // Set page compression |
|
397 | + if(function_exists('gzcompress')) |
|
398 | + $this->compress = $compress; |
|
399 | + else |
|
400 | + $this->compress = false; |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
@@ -407,8 +407,8 @@ discard block |
||
407 | 407 | */ |
408 | 408 | public function SetTitle(string $title, bool $isUTF8=false) : void |
409 | 409 | { |
410 | - // Title of document |
|
411 | - $this->metadata['Title'] = $isUTF8 ? $title : utf8_encode($title); |
|
410 | + // Title of document |
|
411 | + $this->metadata['Title'] = $isUTF8 ? $title : utf8_encode($title); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | /** |
@@ -418,8 +418,8 @@ discard block |
||
418 | 418 | */ |
419 | 419 | public function SetAuthor(string $author, bool $isUTF8=false) : void |
420 | 420 | { |
421 | - // Author of document |
|
422 | - $this->metadata['Author'] = $isUTF8 ? $author : utf8_encode($author); |
|
421 | + // Author of document |
|
422 | + $this->metadata['Author'] = $isUTF8 ? $author : utf8_encode($author); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | /** |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | */ |
430 | 430 | public function SetSubject(string $subject, bool $isUTF8=false) : void |
431 | 431 | { |
432 | - // Subject of document |
|
433 | - $this->metadata['Subject'] = $isUTF8 ? $subject : utf8_encode($subject); |
|
432 | + // Subject of document |
|
433 | + $this->metadata['Subject'] = $isUTF8 ? $subject : utf8_encode($subject); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -440,8 +440,8 @@ discard block |
||
440 | 440 | */ |
441 | 441 | public function SetKeywords(string $keywords, bool $isUTF8=false) : void |
442 | 442 | { |
443 | - // Keywords of document |
|
444 | - $this->metadata['Keywords'] = $isUTF8 ? $keywords : utf8_encode($keywords); |
|
443 | + // Keywords of document |
|
444 | + $this->metadata['Keywords'] = $isUTF8 ? $keywords : utf8_encode($keywords); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -451,8 +451,8 @@ discard block |
||
451 | 451 | */ |
452 | 452 | public function SetCreator(string $creator, bool $isUTF8=false) : void |
453 | 453 | { |
454 | - // Creator of document |
|
455 | - $this->metadata['Creator'] = $isUTF8 ? $creator : utf8_encode($creator); |
|
454 | + // Creator of document |
|
455 | + $this->metadata['Creator'] = $isUTF8 ? $creator : utf8_encode($creator); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | /** |
@@ -461,8 +461,8 @@ discard block |
||
461 | 461 | */ |
462 | 462 | public function AliasNbPages(string $alias='{nb}') : void |
463 | 463 | { |
464 | - // Define an alias for total number of pages |
|
465 | - $this->AliasNbPages = $alias; |
|
464 | + // Define an alias for total number of pages |
|
465 | + $this->AliasNbPages = $alias; |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
@@ -475,8 +475,8 @@ discard block |
||
475 | 475 | */ |
476 | 476 | public function Error(string $msg) : void |
477 | 477 | { |
478 | - // Fatal error |
|
479 | - throw new \Exception('FPDF error: '.$msg); |
|
478 | + // Fatal error |
|
479 | + throw new \Exception('FPDF error: '.$msg); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | /** |
@@ -487,19 +487,19 @@ discard block |
||
487 | 487 | */ |
488 | 488 | public function Close() : void |
489 | 489 | { |
490 | - // Terminate document |
|
491 | - if($this->state==3) |
|
492 | - return; |
|
493 | - if($this->page==0) |
|
494 | - $this->addPage(); |
|
495 | - // Page footer |
|
496 | - $this->InFooter = true; |
|
497 | - $this->Footer(); |
|
498 | - $this->InFooter = false; |
|
499 | - // Close page |
|
500 | - $this->_endpage(); |
|
501 | - // Close document |
|
502 | - $this->_enddoc(); |
|
490 | + // Terminate document |
|
491 | + if($this->state==3) |
|
492 | + return; |
|
493 | + if($this->page==0) |
|
494 | + $this->addPage(); |
|
495 | + // Page footer |
|
496 | + $this->InFooter = true; |
|
497 | + $this->Footer(); |
|
498 | + $this->InFooter = false; |
|
499 | + // Close page |
|
500 | + $this->_endpage(); |
|
501 | + // Close document |
|
502 | + $this->_enddoc(); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | /** |
@@ -532,71 +532,71 @@ discard block |
||
532 | 532 | */ |
533 | 533 | public function AddPage(string $orientation='', $size='', int $rotation=0) : void |
534 | 534 | { |
535 | - // Start a new page |
|
536 | - if($this->state==3) |
|
537 | - $this->Error('The document is closed'); |
|
538 | - $family = $this->FontFamily; |
|
539 | - $style = $this->FontStyle.($this->underline ? 'U' : ''); |
|
540 | - $fontsize = $this->FontSizePt; |
|
541 | - $lw = $this->LineWidth; |
|
542 | - $dc = $this->DrawColor; |
|
543 | - $fc = $this->FillColor; |
|
544 | - $tc = $this->TextColor; |
|
545 | - $cf = $this->ColorFlag; |
|
546 | - if($this->page>0) |
|
547 | - { |
|
548 | - // Page footer |
|
549 | - $this->InFooter = true; |
|
550 | - $this->Footer(); |
|
551 | - $this->InFooter = false; |
|
552 | - // Close page |
|
553 | - $this->_endpage(); |
|
554 | - } |
|
555 | - // Start new page |
|
556 | - $this->_beginpage($orientation,$size,$rotation); |
|
557 | - // Set line cap style to square |
|
558 | - $this->_out('2 J'); |
|
559 | - // Set line width |
|
560 | - $this->LineWidth = $lw; |
|
561 | - $this->_out(sprintf('%.2F w',$lw*$this->k)); |
|
562 | - // Set font |
|
563 | - if($family) |
|
564 | - $this->setFont($family,$style,$fontsize); |
|
565 | - // Set colors |
|
566 | - $this->DrawColor = $dc; |
|
567 | - if($dc!='0 G') |
|
568 | - $this->_out($dc); |
|
569 | - $this->FillColor = $fc; |
|
570 | - if($fc!='0 g') |
|
571 | - $this->_out($fc); |
|
572 | - $this->TextColor = $tc; |
|
573 | - $this->ColorFlag = $cf; |
|
574 | - // Page header |
|
575 | - $this->InHeader = true; |
|
576 | - $this->Header(); |
|
577 | - $this->InHeader = false; |
|
578 | - // Restore line width |
|
579 | - if($this->LineWidth!=$lw) |
|
580 | - { |
|
581 | - $this->LineWidth = $lw; |
|
582 | - $this->_out(sprintf('%.2F w',$lw*$this->k)); |
|
583 | - } |
|
584 | - // Restore font |
|
585 | - if($family) |
|
586 | - $this->setFont($family,$style,$fontsize); |
|
587 | - // Restore colors |
|
588 | - if($this->DrawColor!=$dc) |
|
589 | - { |
|
590 | - $this->DrawColor = $dc; |
|
591 | - $this->_out($dc); |
|
592 | - } |
|
593 | - if($this->FillColor!=$fc) |
|
594 | - { |
|
595 | - $this->FillColor = $fc; |
|
596 | - $this->_out($fc); |
|
597 | - } |
|
598 | - $this->TextColor = $tc; |
|
599 | - $this->ColorFlag = $cf; |
|
535 | + // Start a new page |
|
536 | + if($this->state==3) |
|
537 | + $this->Error('The document is closed'); |
|
538 | + $family = $this->FontFamily; |
|
539 | + $style = $this->FontStyle.($this->underline ? 'U' : ''); |
|
540 | + $fontsize = $this->FontSizePt; |
|
541 | + $lw = $this->LineWidth; |
|
542 | + $dc = $this->DrawColor; |
|
543 | + $fc = $this->FillColor; |
|
544 | + $tc = $this->TextColor; |
|
545 | + $cf = $this->ColorFlag; |
|
546 | + if($this->page>0) |
|
547 | + { |
|
548 | + // Page footer |
|
549 | + $this->InFooter = true; |
|
550 | + $this->Footer(); |
|
551 | + $this->InFooter = false; |
|
552 | + // Close page |
|
553 | + $this->_endpage(); |
|
554 | + } |
|
555 | + // Start new page |
|
556 | + $this->_beginpage($orientation,$size,$rotation); |
|
557 | + // Set line cap style to square |
|
558 | + $this->_out('2 J'); |
|
559 | + // Set line width |
|
560 | + $this->LineWidth = $lw; |
|
561 | + $this->_out(sprintf('%.2F w',$lw*$this->k)); |
|
562 | + // Set font |
|
563 | + if($family) |
|
564 | + $this->setFont($family,$style,$fontsize); |
|
565 | + // Set colors |
|
566 | + $this->DrawColor = $dc; |
|
567 | + if($dc!='0 G') |
|
568 | + $this->_out($dc); |
|
569 | + $this->FillColor = $fc; |
|
570 | + if($fc!='0 g') |
|
571 | + $this->_out($fc); |
|
572 | + $this->TextColor = $tc; |
|
573 | + $this->ColorFlag = $cf; |
|
574 | + // Page header |
|
575 | + $this->InHeader = true; |
|
576 | + $this->Header(); |
|
577 | + $this->InHeader = false; |
|
578 | + // Restore line width |
|
579 | + if($this->LineWidth!=$lw) |
|
580 | + { |
|
581 | + $this->LineWidth = $lw; |
|
582 | + $this->_out(sprintf('%.2F w',$lw*$this->k)); |
|
583 | + } |
|
584 | + // Restore font |
|
585 | + if($family) |
|
586 | + $this->setFont($family,$style,$fontsize); |
|
587 | + // Restore colors |
|
588 | + if($this->DrawColor!=$dc) |
|
589 | + { |
|
590 | + $this->DrawColor = $dc; |
|
591 | + $this->_out($dc); |
|
592 | + } |
|
593 | + if($this->FillColor!=$fc) |
|
594 | + { |
|
595 | + $this->FillColor = $fc; |
|
596 | + $this->_out($fc); |
|
597 | + } |
|
598 | + $this->TextColor = $tc; |
|
599 | + $this->ColorFlag = $cf; |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | /** |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | */ |
608 | 608 | public function Header() : void |
609 | 609 | { |
610 | - // To be implemented in your own inherited class |
|
610 | + // To be implemented in your own inherited class |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | /** |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | */ |
619 | 619 | public function Footer() : void |
620 | 620 | { |
621 | - // To be implemented in your own inherited class |
|
621 | + // To be implemented in your own inherited class |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | /** |
@@ -627,8 +627,8 @@ discard block |
||
627 | 627 | */ |
628 | 628 | public function PageNo() : int |
629 | 629 | { |
630 | - // Get current page number |
|
631 | - return $this->page; |
|
630 | + // Get current page number |
|
631 | + return $this->page; |
|
632 | 632 | } |
633 | 633 | |
634 | 634 | /** |
@@ -641,14 +641,14 @@ discard block |
||
641 | 641 | */ |
642 | 642 | public function SetDrawColor(int $r, ?int $g=null, ?int $b=null) : void |
643 | 643 | { |
644 | - // Set color for all stroking operations |
|
644 | + // Set color for all stroking operations |
|
645 | 645 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) { |
646 | - $this->DrawColor = sprintf('%.3F G', $r / 255); |
|
646 | + $this->DrawColor = sprintf('%.3F G', $r / 255); |
|
647 | 647 | } else { |
648 | - $this->DrawColor = sprintf('%.3F %.3F %.3F RG', $r / 255, $g / 255, $b / 255); |
|
648 | + $this->DrawColor = sprintf('%.3F %.3F %.3F RG', $r / 255, $g / 255, $b / 255); |
|
649 | 649 | } |
650 | 650 | if ($this->page > 0) { |
651 | - $this->_out($this->DrawColor); |
|
651 | + $this->_out($this->DrawColor); |
|
652 | 652 | } |
653 | 653 | } |
654 | 654 | |
@@ -662,16 +662,16 @@ discard block |
||
662 | 662 | */ |
663 | 663 | public function SetFillColor(int $r, ?int $g=null, ?int $b=null) : void |
664 | 664 | { |
665 | - // Set color for all filling operations |
|
665 | + // Set color for all filling operations |
|
666 | 666 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) { |
667 | - $this->FillColor = sprintf('%.3F g', $r / 255); |
|
667 | + $this->FillColor = sprintf('%.3F g', $r / 255); |
|
668 | 668 | } else { |
669 | - $this->FillColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255); |
|
669 | + $this->FillColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255); |
|
670 | + } |
|
671 | + $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
672 | + if ($this->page > 0) { |
|
673 | + $this->_out($this->FillColor); |
|
670 | 674 | } |
671 | - $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
672 | - if ($this->page > 0) { |
|
673 | - $this->_out($this->FillColor); |
|
674 | - } |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | /** |
@@ -684,13 +684,13 @@ discard block |
||
684 | 684 | */ |
685 | 685 | public function SetTextColor(int $r, ?int $g=null, ?int $b=null) : void |
686 | 686 | { |
687 | - // Set color for text |
|
687 | + // Set color for text |
|
688 | 688 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) { |
689 | - $this->TextColor = sprintf('%.3F g', $r / 255); |
|
689 | + $this->TextColor = sprintf('%.3F g', $r / 255); |
|
690 | 690 | } else { |
691 | - $this->TextColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255); |
|
691 | + $this->TextColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255); |
|
692 | 692 | } |
693 | - $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
693 | + $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | /** |
@@ -701,14 +701,14 @@ discard block |
||
701 | 701 | */ |
702 | 702 | public function GetStringWidth(string $s) : float |
703 | 703 | { |
704 | - // Get width of a string in the current font |
|
705 | - $s = (string)$s; |
|
706 | - $cw = &$this->CurrentFont['cw']; |
|
707 | - $w = 0; |
|
708 | - $l = strlen($s); |
|
709 | - for($i=0;$i<$l;$i++) |
|
710 | - $w += $cw[$s[$i]]; |
|
711 | - return $w*$this->FontSize/1000; |
|
704 | + // Get width of a string in the current font |
|
705 | + $s = (string)$s; |
|
706 | + $cw = &$this->CurrentFont['cw']; |
|
707 | + $w = 0; |
|
708 | + $l = strlen($s); |
|
709 | + for($i=0;$i<$l;$i++) |
|
710 | + $w += $cw[$s[$i]]; |
|
711 | + return $w*$this->FontSize/1000; |
|
712 | 712 | } |
713 | 713 | |
714 | 714 | /** |
@@ -719,10 +719,10 @@ discard block |
||
719 | 719 | */ |
720 | 720 | public function SetLineWidth(float $width) : void |
721 | 721 | { |
722 | - // Set line width |
|
723 | - $this->LineWidth = $width; |
|
724 | - if($this->page>0) |
|
725 | - $this->_out(sprintf('%.2F w',$width*$this->k)); |
|
722 | + // Set line width |
|
723 | + $this->LineWidth = $width; |
|
724 | + if($this->page>0) |
|
725 | + $this->_out(sprintf('%.2F w',$width*$this->k)); |
|
726 | 726 | } |
727 | 727 | |
728 | 728 | /** |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | */ |
737 | 737 | public function Line(float $x1, float $y1, float $x2, float $y2) : void |
738 | 738 | { |
739 | - // Draw a line |
|
740 | - $this->_out(sprintf('%.2F %.2F m %.2F %.2F l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k)); |
|
739 | + // Draw a line |
|
740 | + $this->_out(sprintf('%.2F %.2F m %.2F %.2F l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k)); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -757,14 +757,14 @@ discard block |
||
757 | 757 | */ |
758 | 758 | public function Rect(float $x, float $y, float $w, float $h, string $style='') : void |
759 | 759 | { |
760 | - // Draw a rectangle |
|
761 | - if($style=='F') |
|
762 | - $op = 'f'; |
|
763 | - elseif($style=='FD' || $style=='DF') |
|
764 | - $op = 'B'; |
|
765 | - else |
|
766 | - $op = 'S'; |
|
767 | - $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); |
|
760 | + // Draw a rectangle |
|
761 | + if($style=='F') |
|
762 | + $op = 'f'; |
|
763 | + elseif($style=='FD' || $style=='DF') |
|
764 | + $op = 'B'; |
|
765 | + else |
|
766 | + $op = 'S'; |
|
767 | + $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | /** |
@@ -786,27 +786,27 @@ discard block |
||
786 | 786 | */ |
787 | 787 | public function AddFont(string $family, string $style='', string $file='') : void |
788 | 788 | { |
789 | - // Add a TrueType, OpenType or Type1 font |
|
790 | - $family = strtolower($family); |
|
791 | - if($file=='') |
|
792 | - $file = str_replace(' ','',$family).strtolower($style).'.php'; |
|
793 | - $style = strtoupper($style); |
|
794 | - if($style=='IB') |
|
795 | - $style = 'BI'; |
|
796 | - $fontkey = $family.$style; |
|
797 | - if(isset($this->fonts[$fontkey])) |
|
798 | - return; |
|
799 | - $info = $this->_loadfont($file); |
|
800 | - $info['i'] = count($this->fonts)+1; |
|
801 | - if(!empty($info['file'])) |
|
802 | - { |
|
803 | - // Embedded font |
|
804 | - if($info['type']=='TrueType') |
|
805 | - $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']); |
|
806 | - else |
|
807 | - $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']); |
|
808 | - } |
|
809 | - $this->fonts[$fontkey] = $info; |
|
789 | + // Add a TrueType, OpenType or Type1 font |
|
790 | + $family = strtolower($family); |
|
791 | + if($file=='') |
|
792 | + $file = str_replace(' ','',$family).strtolower($style).'.php'; |
|
793 | + $style = strtoupper($style); |
|
794 | + if($style=='IB') |
|
795 | + $style = 'BI'; |
|
796 | + $fontkey = $family.$style; |
|
797 | + if(isset($this->fonts[$fontkey])) |
|
798 | + return; |
|
799 | + $info = $this->_loadfont($file); |
|
800 | + $info['i'] = count($this->fonts)+1; |
|
801 | + if(!empty($info['file'])) |
|
802 | + { |
|
803 | + // Embedded font |
|
804 | + if($info['type']=='TrueType') |
|
805 | + $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']); |
|
806 | + else |
|
807 | + $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']); |
|
808 | + } |
|
809 | + $this->fonts[$fontkey] = $info; |
|
810 | 810 | } |
811 | 811 | |
812 | 812 | /** |
@@ -846,52 +846,52 @@ discard block |
||
846 | 846 | */ |
847 | 847 | public function SetFont(string $family, string $style='', float $size=0) : void |
848 | 848 | { |
849 | - // Select a font; size given in points |
|
850 | - if($family=='') |
|
851 | - $family = $this->FontFamily; |
|
852 | - else |
|
853 | - $family = strtolower($family); |
|
854 | - $style = strtoupper($style); |
|
855 | - if(strpos($style,'U')!==false) |
|
856 | - { |
|
857 | - $this->underline = true; |
|
858 | - $style = str_replace('U','',$style); |
|
859 | - } |
|
860 | - else |
|
861 | - $this->underline = false; |
|
862 | - if($style=='IB') |
|
863 | - $style = 'BI'; |
|
864 | - if($size==0) |
|
865 | - $size = $this->FontSizePt; |
|
866 | - // Test if font is already selected |
|
867 | - if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) |
|
868 | - return; |
|
869 | - // Test if font is already loaded |
|
870 | - $fontkey = $family.$style; |
|
871 | - if(!isset($this->fonts[$fontkey])) |
|
872 | - { |
|
873 | - // Test if one of the core fonts |
|
874 | - if($family=='arial') |
|
875 | - $family = 'helvetica'; |
|
876 | - if(in_array($family,$this->CoreFonts)) |
|
877 | - { |
|
878 | - if($family=='symbol' || $family=='zapfdingbats') |
|
879 | - $style = ''; |
|
880 | - $fontkey = $family.$style; |
|
881 | - if(!isset($this->fonts[$fontkey])) |
|
882 | - $this->addFont($family,$style); |
|
883 | - } |
|
884 | - else |
|
885 | - $this->Error('Undefined font: '.$family.' '.$style); |
|
886 | - } |
|
887 | - // Select it |
|
888 | - $this->FontFamily = $family; |
|
889 | - $this->FontStyle = $style; |
|
890 | - $this->FontSizePt = $size; |
|
891 | - $this->FontSize = $size/$this->k; |
|
892 | - $this->CurrentFont = &$this->fonts[$fontkey]; |
|
893 | - if($this->page>0) |
|
894 | - $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); |
|
849 | + // Select a font; size given in points |
|
850 | + if($family=='') |
|
851 | + $family = $this->FontFamily; |
|
852 | + else |
|
853 | + $family = strtolower($family); |
|
854 | + $style = strtoupper($style); |
|
855 | + if(strpos($style,'U')!==false) |
|
856 | + { |
|
857 | + $this->underline = true; |
|
858 | + $style = str_replace('U','',$style); |
|
859 | + } |
|
860 | + else |
|
861 | + $this->underline = false; |
|
862 | + if($style=='IB') |
|
863 | + $style = 'BI'; |
|
864 | + if($size==0) |
|
865 | + $size = $this->FontSizePt; |
|
866 | + // Test if font is already selected |
|
867 | + if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) |
|
868 | + return; |
|
869 | + // Test if font is already loaded |
|
870 | + $fontkey = $family.$style; |
|
871 | + if(!isset($this->fonts[$fontkey])) |
|
872 | + { |
|
873 | + // Test if one of the core fonts |
|
874 | + if($family=='arial') |
|
875 | + $family = 'helvetica'; |
|
876 | + if(in_array($family,$this->CoreFonts)) |
|
877 | + { |
|
878 | + if($family=='symbol' || $family=='zapfdingbats') |
|
879 | + $style = ''; |
|
880 | + $fontkey = $family.$style; |
|
881 | + if(!isset($this->fonts[$fontkey])) |
|
882 | + $this->addFont($family,$style); |
|
883 | + } |
|
884 | + else |
|
885 | + $this->Error('Undefined font: '.$family.' '.$style); |
|
886 | + } |
|
887 | + // Select it |
|
888 | + $this->FontFamily = $family; |
|
889 | + $this->FontStyle = $style; |
|
890 | + $this->FontSizePt = $size; |
|
891 | + $this->FontSize = $size/$this->k; |
|
892 | + $this->CurrentFont = &$this->fonts[$fontkey]; |
|
893 | + if($this->page>0) |
|
894 | + $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | /** |
@@ -900,13 +900,13 @@ discard block |
||
900 | 900 | */ |
901 | 901 | public function SetFontSize(float $size) : void |
902 | 902 | { |
903 | - // Set font size in points |
|
904 | - if($this->FontSizePt==$size) |
|
905 | - return; |
|
906 | - $this->FontSizePt = $size; |
|
907 | - $this->FontSize = $size/$this->k; |
|
908 | - if($this->page>0) |
|
909 | - $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); |
|
903 | + // Set font size in points |
|
904 | + if($this->FontSizePt==$size) |
|
905 | + return; |
|
906 | + $this->FontSizePt = $size; |
|
907 | + $this->FontSize = $size/$this->k; |
|
908 | + if($this->page>0) |
|
909 | + $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); |
|
910 | 910 | } |
911 | 911 | |
912 | 912 | /** |
@@ -918,10 +918,10 @@ discard block |
||
918 | 918 | */ |
919 | 919 | public function AddLink() : int |
920 | 920 | { |
921 | - // Create a new internal link |
|
922 | - $n = count($this->links)+1; |
|
923 | - $this->links[$n] = array(0, 0); |
|
924 | - return $n; |
|
921 | + // Create a new internal link |
|
922 | + $n = count($this->links)+1; |
|
923 | + $this->links[$n] = array(0, 0); |
|
924 | + return $n; |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | /** |
@@ -932,12 +932,12 @@ discard block |
||
932 | 932 | */ |
933 | 933 | public function SetLink(int $link, float $y=0, int $page=-1) : void |
934 | 934 | { |
935 | - // Set destination of internal link |
|
936 | - if($y==-1) |
|
937 | - $y = $this->y; |
|
938 | - if($page==-1) |
|
939 | - $page = $this->page; |
|
940 | - $this->links[$link] = array($page, $y); |
|
935 | + // Set destination of internal link |
|
936 | + if($y==-1) |
|
937 | + $y = $this->y; |
|
938 | + if($page==-1) |
|
939 | + $page = $this->page; |
|
940 | + $this->links[$link] = array($page, $y); |
|
941 | 941 | } |
942 | 942 | |
943 | 943 | /** |
@@ -953,8 +953,8 @@ discard block |
||
953 | 953 | */ |
954 | 954 | public function Link(float $x, float $y, float $w, float $h, $link) : void |
955 | 955 | { |
956 | - // Put a link on the page |
|
957 | - $this->PageLinks[$this->page][] = array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link); |
|
956 | + // Put a link on the page |
|
957 | + $this->PageLinks[$this->page][] = array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link); |
|
958 | 958 | } |
959 | 959 | |
960 | 960 | /** |
@@ -969,15 +969,15 @@ discard block |
||
969 | 969 | */ |
970 | 970 | public function Text(float $x, float $y, string $txt) : void |
971 | 971 | { |
972 | - // Output a string |
|
973 | - if(!isset($this->CurrentFont)) |
|
974 | - $this->Error('No font has been set'); |
|
975 | - $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); |
|
976 | - if($this->underline && $txt!='') |
|
977 | - $s .= ' '.$this->_dounderline($x,$y,$txt); |
|
978 | - if($this->ColorFlag) |
|
979 | - $s = 'q '.$this->TextColor.' '.$s.' Q'; |
|
980 | - $this->_out($s); |
|
972 | + // Output a string |
|
973 | + if(!isset($this->CurrentFont)) |
|
974 | + $this->Error('No font has been set'); |
|
975 | + $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); |
|
976 | + if($this->underline && $txt!='') |
|
977 | + $s .= ' '.$this->_dounderline($x,$y,$txt); |
|
978 | + if($this->ColorFlag) |
|
979 | + $s = 'q '.$this->TextColor.' '.$s.' Q'; |
|
980 | + $this->_out($s); |
|
981 | 981 | } |
982 | 982 | |
983 | 983 | /** |
@@ -993,8 +993,8 @@ discard block |
||
993 | 993 | */ |
994 | 994 | public function AcceptPageBreak() : bool |
995 | 995 | { |
996 | - // Accept automatic page break or not |
|
997 | - return $this->AutoPageBreak; |
|
996 | + // Accept automatic page break or not |
|
997 | + return $this->AutoPageBreak; |
|
998 | 998 | } |
999 | 999 | |
1000 | 1000 | /** |
@@ -1036,82 +1036,82 @@ discard block |
||
1036 | 1036 | */ |
1037 | 1037 | public function Cell(float $w, float $h=0, string $txt='', $border=0, float $ln=0, $align='', $fill=false, $link='') : void |
1038 | 1038 | { |
1039 | - // Output a cell |
|
1040 | - $k = $this->k; |
|
1041 | - if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
1042 | - { |
|
1043 | - // Automatic page break |
|
1044 | - $x = $this->x; |
|
1045 | - $ws = $this->ws; |
|
1046 | - if($ws>0) |
|
1047 | - { |
|
1048 | - $this->ws = 0; |
|
1049 | - $this->_out('0 Tw'); |
|
1050 | - } |
|
1051 | - $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
1052 | - $this->x = $x; |
|
1053 | - if($ws>0) |
|
1054 | - { |
|
1055 | - $this->ws = $ws; |
|
1056 | - $this->_out(sprintf('%.3F Tw',$ws*$k)); |
|
1057 | - } |
|
1058 | - } |
|
1059 | - if($w==0) |
|
1060 | - $w = $this->w-$this->rMargin-$this->x; |
|
1061 | - $s = ''; |
|
1062 | - if($fill || $border==1) |
|
1063 | - { |
|
1064 | - if($fill) |
|
1065 | - $op = ($border==1) ? 'B' : 'f'; |
|
1066 | - else |
|
1067 | - $op = 'S'; |
|
1068 | - $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); |
|
1069 | - } |
|
1070 | - if(is_string($border)) |
|
1071 | - { |
|
1072 | - $x = $this->x; |
|
1073 | - $y = $this->y; |
|
1074 | - if(strpos($border,'L')!==false) |
|
1075 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); |
|
1076 | - if(strpos($border,'T')!==false) |
|
1077 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); |
|
1078 | - if(strpos($border,'R')!==false) |
|
1079 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); |
|
1080 | - if(strpos($border,'B')!==false) |
|
1081 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); |
|
1082 | - } |
|
1083 | - if($txt!=='') |
|
1084 | - { |
|
1085 | - if(!isset($this->CurrentFont)) |
|
1086 | - $this->Error('No font has been set'); |
|
1087 | - if($align=='R') |
|
1088 | - $dx = $w-$this->cMargin-$this->getStringWidth($txt); |
|
1089 | - elseif($align=='C') |
|
1090 | - $dx = ($w-$this->getStringWidth($txt))/2; |
|
1091 | - else |
|
1092 | - $dx = $this->cMargin; |
|
1093 | - if($this->ColorFlag) |
|
1094 | - $s .= 'q '.$this->TextColor.' '; |
|
1095 | - $s .= sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$this->_escape($txt)); |
|
1096 | - if($this->underline) |
|
1097 | - $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); |
|
1098 | - if($this->ColorFlag) |
|
1099 | - $s .= ' Q'; |
|
1100 | - if($link) |
|
1101 | - $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->getStringWidth($txt),$this->FontSize,$link); |
|
1102 | - } |
|
1103 | - if($s) |
|
1104 | - $this->_out($s); |
|
1105 | - $this->lasth = $h; |
|
1106 | - if($ln>0) |
|
1107 | - { |
|
1108 | - // Go to next line |
|
1109 | - $this->y += $h; |
|
1110 | - if($ln==1) |
|
1111 | - $this->x = $this->lMargin; |
|
1112 | - } |
|
1113 | - else |
|
1114 | - $this->x += $w; |
|
1039 | + // Output a cell |
|
1040 | + $k = $this->k; |
|
1041 | + if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
1042 | + { |
|
1043 | + // Automatic page break |
|
1044 | + $x = $this->x; |
|
1045 | + $ws = $this->ws; |
|
1046 | + if($ws>0) |
|
1047 | + { |
|
1048 | + $this->ws = 0; |
|
1049 | + $this->_out('0 Tw'); |
|
1050 | + } |
|
1051 | + $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
1052 | + $this->x = $x; |
|
1053 | + if($ws>0) |
|
1054 | + { |
|
1055 | + $this->ws = $ws; |
|
1056 | + $this->_out(sprintf('%.3F Tw',$ws*$k)); |
|
1057 | + } |
|
1058 | + } |
|
1059 | + if($w==0) |
|
1060 | + $w = $this->w-$this->rMargin-$this->x; |
|
1061 | + $s = ''; |
|
1062 | + if($fill || $border==1) |
|
1063 | + { |
|
1064 | + if($fill) |
|
1065 | + $op = ($border==1) ? 'B' : 'f'; |
|
1066 | + else |
|
1067 | + $op = 'S'; |
|
1068 | + $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); |
|
1069 | + } |
|
1070 | + if(is_string($border)) |
|
1071 | + { |
|
1072 | + $x = $this->x; |
|
1073 | + $y = $this->y; |
|
1074 | + if(strpos($border,'L')!==false) |
|
1075 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); |
|
1076 | + if(strpos($border,'T')!==false) |
|
1077 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); |
|
1078 | + if(strpos($border,'R')!==false) |
|
1079 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); |
|
1080 | + if(strpos($border,'B')!==false) |
|
1081 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); |
|
1082 | + } |
|
1083 | + if($txt!=='') |
|
1084 | + { |
|
1085 | + if(!isset($this->CurrentFont)) |
|
1086 | + $this->Error('No font has been set'); |
|
1087 | + if($align=='R') |
|
1088 | + $dx = $w-$this->cMargin-$this->getStringWidth($txt); |
|
1089 | + elseif($align=='C') |
|
1090 | + $dx = ($w-$this->getStringWidth($txt))/2; |
|
1091 | + else |
|
1092 | + $dx = $this->cMargin; |
|
1093 | + if($this->ColorFlag) |
|
1094 | + $s .= 'q '.$this->TextColor.' '; |
|
1095 | + $s .= sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$this->_escape($txt)); |
|
1096 | + if($this->underline) |
|
1097 | + $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); |
|
1098 | + if($this->ColorFlag) |
|
1099 | + $s .= ' Q'; |
|
1100 | + if($link) |
|
1101 | + $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->getStringWidth($txt),$this->FontSize,$link); |
|
1102 | + } |
|
1103 | + if($s) |
|
1104 | + $this->_out($s); |
|
1105 | + $this->lasth = $h; |
|
1106 | + if($ln>0) |
|
1107 | + { |
|
1108 | + // Go to next line |
|
1109 | + $this->y += $h; |
|
1110 | + if($ln==1) |
|
1111 | + $this->x = $this->lMargin; |
|
1112 | + } |
|
1113 | + else |
|
1114 | + $this->x += $w; |
|
1115 | 1115 | } |
1116 | 1116 | |
1117 | 1117 | /** |
@@ -1144,119 +1144,119 @@ discard block |
||
1144 | 1144 | */ |
1145 | 1145 | public function MultiCell(float $w, float $h, string $txt, $border=0, string $align='J', bool $fill=false) : void |
1146 | 1146 | { |
1147 | - // Output text with automatic or explicit line breaks |
|
1148 | - if(!isset($this->CurrentFont)) |
|
1149 | - $this->Error('No font has been set'); |
|
1150 | - $cw = &$this->CurrentFont['cw']; |
|
1151 | - if($w==0) |
|
1152 | - $w = $this->w-$this->rMargin-$this->x; |
|
1153 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1154 | - $s = str_replace("\r",'',$txt); |
|
1155 | - $nb = strlen($s); |
|
1156 | - if($nb>0 && $s[$nb-1]=="\n") |
|
1157 | - $nb--; |
|
1158 | - $b = 0; |
|
1159 | - $b2 = ''; |
|
1160 | - if($border) |
|
1161 | - { |
|
1162 | - if($border==1) |
|
1163 | - { |
|
1164 | - $border = 'LTRB'; |
|
1165 | - $b = 'LRT'; |
|
1166 | - $b2 = 'LR'; |
|
1167 | - } |
|
1168 | - else |
|
1169 | - { |
|
1170 | - $b2 = ''; |
|
1171 | - if(strpos($border,'L')!==false) |
|
1172 | - $b2 .= 'L'; |
|
1173 | - if(strpos($border,'R')!==false) |
|
1174 | - $b2 .= 'R'; |
|
1175 | - $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; |
|
1176 | - } |
|
1177 | - } |
|
1178 | - $sep = -1; |
|
1179 | - $i = 0; |
|
1180 | - $j = 0; |
|
1181 | - $l = 0; |
|
1182 | - $ns = 0; |
|
1183 | - $nl = 1; |
|
1184 | - $ls = 0; |
|
1185 | - while($i<$nb) |
|
1186 | - { |
|
1187 | - // Get next character |
|
1188 | - $c = $s[$i]; |
|
1189 | - if($c=="\n") |
|
1190 | - { |
|
1191 | - // Explicit line break |
|
1192 | - if($this->ws>0) |
|
1193 | - { |
|
1194 | - $this->ws = 0; |
|
1195 | - $this->_out('0 Tw'); |
|
1196 | - } |
|
1197 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
1198 | - $i++; |
|
1199 | - $sep = -1; |
|
1200 | - $j = $i; |
|
1201 | - $l = 0; |
|
1202 | - $ns = 0; |
|
1203 | - $nl++; |
|
1204 | - if($border && $nl==2) |
|
1205 | - $b = $b2; |
|
1206 | - continue; |
|
1207 | - } |
|
1208 | - if($c==' ') |
|
1209 | - { |
|
1210 | - $sep = $i; |
|
1211 | - $ls = $l; |
|
1212 | - $ns++; |
|
1213 | - } |
|
1214 | - $l += $cw[$c]; |
|
1215 | - if($l>$wmax) |
|
1216 | - { |
|
1217 | - // Automatic line break |
|
1218 | - if($sep==-1) |
|
1219 | - { |
|
1220 | - if($i==$j) |
|
1221 | - $i++; |
|
1222 | - if($this->ws>0) |
|
1223 | - { |
|
1224 | - $this->ws = 0; |
|
1225 | - $this->_out('0 Tw'); |
|
1226 | - } |
|
1227 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
1228 | - } |
|
1229 | - else |
|
1230 | - { |
|
1231 | - if($align=='J') |
|
1232 | - { |
|
1233 | - $this->ws = ($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; |
|
1234 | - $this->_out(sprintf('%.3F Tw',$this->ws*$this->k)); |
|
1235 | - } |
|
1236 | - $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); |
|
1237 | - $i = $sep+1; |
|
1238 | - } |
|
1239 | - $sep = -1; |
|
1240 | - $j = $i; |
|
1241 | - $l = 0; |
|
1242 | - $ns = 0; |
|
1243 | - $nl++; |
|
1244 | - if($border && $nl==2) |
|
1245 | - $b = $b2; |
|
1246 | - } |
|
1247 | - else |
|
1248 | - $i++; |
|
1249 | - } |
|
1250 | - // Last chunk |
|
1251 | - if($this->ws>0) |
|
1252 | - { |
|
1253 | - $this->ws = 0; |
|
1254 | - $this->_out('0 Tw'); |
|
1255 | - } |
|
1256 | - if($border && strpos($border,'B')!==false) |
|
1257 | - $b .= 'B'; |
|
1258 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
1259 | - $this->x = $this->lMargin; |
|
1147 | + // Output text with automatic or explicit line breaks |
|
1148 | + if(!isset($this->CurrentFont)) |
|
1149 | + $this->Error('No font has been set'); |
|
1150 | + $cw = &$this->CurrentFont['cw']; |
|
1151 | + if($w==0) |
|
1152 | + $w = $this->w-$this->rMargin-$this->x; |
|
1153 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1154 | + $s = str_replace("\r",'',$txt); |
|
1155 | + $nb = strlen($s); |
|
1156 | + if($nb>0 && $s[$nb-1]=="\n") |
|
1157 | + $nb--; |
|
1158 | + $b = 0; |
|
1159 | + $b2 = ''; |
|
1160 | + if($border) |
|
1161 | + { |
|
1162 | + if($border==1) |
|
1163 | + { |
|
1164 | + $border = 'LTRB'; |
|
1165 | + $b = 'LRT'; |
|
1166 | + $b2 = 'LR'; |
|
1167 | + } |
|
1168 | + else |
|
1169 | + { |
|
1170 | + $b2 = ''; |
|
1171 | + if(strpos($border,'L')!==false) |
|
1172 | + $b2 .= 'L'; |
|
1173 | + if(strpos($border,'R')!==false) |
|
1174 | + $b2 .= 'R'; |
|
1175 | + $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; |
|
1176 | + } |
|
1177 | + } |
|
1178 | + $sep = -1; |
|
1179 | + $i = 0; |
|
1180 | + $j = 0; |
|
1181 | + $l = 0; |
|
1182 | + $ns = 0; |
|
1183 | + $nl = 1; |
|
1184 | + $ls = 0; |
|
1185 | + while($i<$nb) |
|
1186 | + { |
|
1187 | + // Get next character |
|
1188 | + $c = $s[$i]; |
|
1189 | + if($c=="\n") |
|
1190 | + { |
|
1191 | + // Explicit line break |
|
1192 | + if($this->ws>0) |
|
1193 | + { |
|
1194 | + $this->ws = 0; |
|
1195 | + $this->_out('0 Tw'); |
|
1196 | + } |
|
1197 | + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
1198 | + $i++; |
|
1199 | + $sep = -1; |
|
1200 | + $j = $i; |
|
1201 | + $l = 0; |
|
1202 | + $ns = 0; |
|
1203 | + $nl++; |
|
1204 | + if($border && $nl==2) |
|
1205 | + $b = $b2; |
|
1206 | + continue; |
|
1207 | + } |
|
1208 | + if($c==' ') |
|
1209 | + { |
|
1210 | + $sep = $i; |
|
1211 | + $ls = $l; |
|
1212 | + $ns++; |
|
1213 | + } |
|
1214 | + $l += $cw[$c]; |
|
1215 | + if($l>$wmax) |
|
1216 | + { |
|
1217 | + // Automatic line break |
|
1218 | + if($sep==-1) |
|
1219 | + { |
|
1220 | + if($i==$j) |
|
1221 | + $i++; |
|
1222 | + if($this->ws>0) |
|
1223 | + { |
|
1224 | + $this->ws = 0; |
|
1225 | + $this->_out('0 Tw'); |
|
1226 | + } |
|
1227 | + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
1228 | + } |
|
1229 | + else |
|
1230 | + { |
|
1231 | + if($align=='J') |
|
1232 | + { |
|
1233 | + $this->ws = ($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; |
|
1234 | + $this->_out(sprintf('%.3F Tw',$this->ws*$this->k)); |
|
1235 | + } |
|
1236 | + $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); |
|
1237 | + $i = $sep+1; |
|
1238 | + } |
|
1239 | + $sep = -1; |
|
1240 | + $j = $i; |
|
1241 | + $l = 0; |
|
1242 | + $ns = 0; |
|
1243 | + $nl++; |
|
1244 | + if($border && $nl==2) |
|
1245 | + $b = $b2; |
|
1246 | + } |
|
1247 | + else |
|
1248 | + $i++; |
|
1249 | + } |
|
1250 | + // Last chunk |
|
1251 | + if($this->ws>0) |
|
1252 | + { |
|
1253 | + $this->ws = 0; |
|
1254 | + $this->_out('0 Tw'); |
|
1255 | + } |
|
1256 | + if($border && strpos($border,'B')!==false) |
|
1257 | + $b .= 'B'; |
|
1258 | + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
1259 | + $this->x = $this->lMargin; |
|
1260 | 1260 | } |
1261 | 1261 | |
1262 | 1262 | /** |
@@ -1271,85 +1271,85 @@ discard block |
||
1271 | 1271 | */ |
1272 | 1272 | public function Write(float $h, string $txt, $link='') : void |
1273 | 1273 | { |
1274 | - // Output text in flowing mode |
|
1275 | - if(!isset($this->CurrentFont)) |
|
1276 | - $this->Error('No font has been set'); |
|
1277 | - $cw = &$this->CurrentFont['cw']; |
|
1278 | - $w = $this->w-$this->rMargin-$this->x; |
|
1279 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1280 | - $s = str_replace("\r",'',$txt); |
|
1281 | - $nb = strlen($s); |
|
1282 | - $sep = -1; |
|
1283 | - $i = 0; |
|
1284 | - $j = 0; |
|
1285 | - $l = 0; |
|
1286 | - $nl = 1; |
|
1287 | - while($i<$nb) |
|
1288 | - { |
|
1289 | - // Get next character |
|
1290 | - $c = $s[$i]; |
|
1291 | - if($c=="\n") |
|
1292 | - { |
|
1293 | - // Explicit line break |
|
1294 | - $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
1295 | - $i++; |
|
1296 | - $sep = -1; |
|
1297 | - $j = $i; |
|
1298 | - $l = 0; |
|
1299 | - if($nl==1) |
|
1300 | - { |
|
1301 | - $this->x = $this->lMargin; |
|
1302 | - $w = $this->w-$this->rMargin-$this->x; |
|
1303 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1304 | - } |
|
1305 | - $nl++; |
|
1306 | - continue; |
|
1307 | - } |
|
1308 | - if($c==' ') |
|
1309 | - $sep = $i; |
|
1310 | - $l += $cw[$c]; |
|
1311 | - if($l>$wmax) |
|
1312 | - { |
|
1313 | - // Automatic line break |
|
1314 | - if($sep==-1) |
|
1315 | - { |
|
1316 | - if($this->x>$this->lMargin) |
|
1317 | - { |
|
1318 | - // Move to next line |
|
1319 | - $this->x = $this->lMargin; |
|
1320 | - $this->y += $h; |
|
1321 | - $w = $this->w-$this->rMargin-$this->x; |
|
1322 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1323 | - $i++; |
|
1324 | - $nl++; |
|
1325 | - continue; |
|
1326 | - } |
|
1327 | - if($i==$j) |
|
1328 | - $i++; |
|
1329 | - $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
1330 | - } |
|
1331 | - else |
|
1332 | - { |
|
1333 | - $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link); |
|
1334 | - $i = $sep+1; |
|
1335 | - } |
|
1336 | - $sep = -1; |
|
1337 | - $j = $i; |
|
1338 | - $l = 0; |
|
1339 | - if($nl==1) |
|
1340 | - { |
|
1341 | - $this->x = $this->lMargin; |
|
1342 | - $w = $this->w-$this->rMargin-$this->x; |
|
1343 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1344 | - } |
|
1345 | - $nl++; |
|
1346 | - } |
|
1347 | - else |
|
1348 | - $i++; |
|
1349 | - } |
|
1350 | - // Last chunk |
|
1351 | - if($i!=$j) |
|
1352 | - $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link); |
|
1274 | + // Output text in flowing mode |
|
1275 | + if(!isset($this->CurrentFont)) |
|
1276 | + $this->Error('No font has been set'); |
|
1277 | + $cw = &$this->CurrentFont['cw']; |
|
1278 | + $w = $this->w-$this->rMargin-$this->x; |
|
1279 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1280 | + $s = str_replace("\r",'',$txt); |
|
1281 | + $nb = strlen($s); |
|
1282 | + $sep = -1; |
|
1283 | + $i = 0; |
|
1284 | + $j = 0; |
|
1285 | + $l = 0; |
|
1286 | + $nl = 1; |
|
1287 | + while($i<$nb) |
|
1288 | + { |
|
1289 | + // Get next character |
|
1290 | + $c = $s[$i]; |
|
1291 | + if($c=="\n") |
|
1292 | + { |
|
1293 | + // Explicit line break |
|
1294 | + $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
1295 | + $i++; |
|
1296 | + $sep = -1; |
|
1297 | + $j = $i; |
|
1298 | + $l = 0; |
|
1299 | + if($nl==1) |
|
1300 | + { |
|
1301 | + $this->x = $this->lMargin; |
|
1302 | + $w = $this->w-$this->rMargin-$this->x; |
|
1303 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1304 | + } |
|
1305 | + $nl++; |
|
1306 | + continue; |
|
1307 | + } |
|
1308 | + if($c==' ') |
|
1309 | + $sep = $i; |
|
1310 | + $l += $cw[$c]; |
|
1311 | + if($l>$wmax) |
|
1312 | + { |
|
1313 | + // Automatic line break |
|
1314 | + if($sep==-1) |
|
1315 | + { |
|
1316 | + if($this->x>$this->lMargin) |
|
1317 | + { |
|
1318 | + // Move to next line |
|
1319 | + $this->x = $this->lMargin; |
|
1320 | + $this->y += $h; |
|
1321 | + $w = $this->w-$this->rMargin-$this->x; |
|
1322 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1323 | + $i++; |
|
1324 | + $nl++; |
|
1325 | + continue; |
|
1326 | + } |
|
1327 | + if($i==$j) |
|
1328 | + $i++; |
|
1329 | + $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
1330 | + } |
|
1331 | + else |
|
1332 | + { |
|
1333 | + $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link); |
|
1334 | + $i = $sep+1; |
|
1335 | + } |
|
1336 | + $sep = -1; |
|
1337 | + $j = $i; |
|
1338 | + $l = 0; |
|
1339 | + if($nl==1) |
|
1340 | + { |
|
1341 | + $this->x = $this->lMargin; |
|
1342 | + $w = $this->w-$this->rMargin-$this->x; |
|
1343 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1344 | + } |
|
1345 | + $nl++; |
|
1346 | + } |
|
1347 | + else |
|
1348 | + $i++; |
|
1349 | + } |
|
1350 | + // Last chunk |
|
1351 | + if($i!=$j) |
|
1352 | + $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link); |
|
1353 | 1353 | } |
1354 | 1354 | |
1355 | 1355 | /** |
@@ -1361,12 +1361,12 @@ discard block |
||
1361 | 1361 | */ |
1362 | 1362 | public function Ln(float $h=null) : void |
1363 | 1363 | { |
1364 | - // Line feed; default value is the last cell height |
|
1365 | - $this->x = $this->lMargin; |
|
1366 | - if($h===null) |
|
1367 | - $this->y += $this->lasth; |
|
1368 | - else |
|
1369 | - $this->y += $h; |
|
1364 | + // Line feed; default value is the last cell height |
|
1365 | + $this->x = $this->lMargin; |
|
1366 | + if($h===null) |
|
1367 | + $this->y += $this->lasth; |
|
1368 | + else |
|
1369 | + $this->y += $h; |
|
1370 | 1370 | } |
1371 | 1371 | |
1372 | 1372 | /** |
@@ -1417,67 +1417,67 @@ discard block |
||
1417 | 1417 | */ |
1418 | 1418 | public function Image(string $file, ?float $x=null, ?float $y=null, float $w=0, float $h=0, string $type='', $link='') : void |
1419 | 1419 | { |
1420 | - // Put an image on the page |
|
1421 | - if($file=='') |
|
1422 | - $this->Error('Image file name is empty'); |
|
1423 | - if(!isset($this->images[$file])) |
|
1424 | - { |
|
1425 | - // First use of this image, get info |
|
1426 | - if($type=='') |
|
1427 | - { |
|
1428 | - $pos = strrpos($file,'.'); |
|
1429 | - if(!$pos) |
|
1430 | - $this->Error('Image file has no extension and no type was specified: '.$file); |
|
1431 | - $type = substr($file,$pos+1); |
|
1432 | - } |
|
1433 | - $type = strtolower($type); |
|
1434 | - if($type=='jpeg') |
|
1435 | - $type = 'jpg'; |
|
1436 | - $mtd = '_parse'.$type; |
|
1437 | - if(!method_exists($this,$mtd)) |
|
1438 | - $this->Error('Unsupported image type: '.$type); |
|
1439 | - $info = $this->$mtd($file); |
|
1440 | - $info['i'] = count($this->images)+1; |
|
1441 | - $this->images[$file] = $info; |
|
1442 | - } |
|
1443 | - else |
|
1444 | - $info = $this->images[$file]; |
|
1445 | - |
|
1446 | - // Automatic width and height calculation if needed |
|
1447 | - if($w==0 && $h==0) |
|
1448 | - { |
|
1449 | - // Put image at 96 dpi |
|
1450 | - $w = -96; |
|
1451 | - $h = -96; |
|
1452 | - } |
|
1453 | - if($w<0) |
|
1454 | - $w = -$info['w']*72/$w/$this->k; |
|
1455 | - if($h<0) |
|
1456 | - $h = -$info['h']*72/$h/$this->k; |
|
1457 | - if($w==0) |
|
1458 | - $w = $h*$info['w']/$info['h']; |
|
1459 | - if($h==0) |
|
1460 | - $h = $w*$info['h']/$info['w']; |
|
1461 | - |
|
1462 | - // Flowing mode |
|
1463 | - if($y===null) |
|
1464 | - { |
|
1465 | - if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
1466 | - { |
|
1467 | - // Automatic page break |
|
1468 | - $x2 = $this->x; |
|
1469 | - $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
1470 | - $this->x = $x2; |
|
1471 | - } |
|
1472 | - $y = $this->y; |
|
1473 | - $this->y += $h; |
|
1474 | - } |
|
1475 | - |
|
1476 | - if($x===null) |
|
1477 | - $x = $this->x; |
|
1478 | - $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q',$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i'])); |
|
1479 | - if($link) |
|
1480 | - $this->Link($x,$y,$w,$h,$link); |
|
1420 | + // Put an image on the page |
|
1421 | + if($file=='') |
|
1422 | + $this->Error('Image file name is empty'); |
|
1423 | + if(!isset($this->images[$file])) |
|
1424 | + { |
|
1425 | + // First use of this image, get info |
|
1426 | + if($type=='') |
|
1427 | + { |
|
1428 | + $pos = strrpos($file,'.'); |
|
1429 | + if(!$pos) |
|
1430 | + $this->Error('Image file has no extension and no type was specified: '.$file); |
|
1431 | + $type = substr($file,$pos+1); |
|
1432 | + } |
|
1433 | + $type = strtolower($type); |
|
1434 | + if($type=='jpeg') |
|
1435 | + $type = 'jpg'; |
|
1436 | + $mtd = '_parse'.$type; |
|
1437 | + if(!method_exists($this,$mtd)) |
|
1438 | + $this->Error('Unsupported image type: '.$type); |
|
1439 | + $info = $this->$mtd($file); |
|
1440 | + $info['i'] = count($this->images)+1; |
|
1441 | + $this->images[$file] = $info; |
|
1442 | + } |
|
1443 | + else |
|
1444 | + $info = $this->images[$file]; |
|
1445 | + |
|
1446 | + // Automatic width and height calculation if needed |
|
1447 | + if($w==0 && $h==0) |
|
1448 | + { |
|
1449 | + // Put image at 96 dpi |
|
1450 | + $w = -96; |
|
1451 | + $h = -96; |
|
1452 | + } |
|
1453 | + if($w<0) |
|
1454 | + $w = -$info['w']*72/$w/$this->k; |
|
1455 | + if($h<0) |
|
1456 | + $h = -$info['h']*72/$h/$this->k; |
|
1457 | + if($w==0) |
|
1458 | + $w = $h*$info['w']/$info['h']; |
|
1459 | + if($h==0) |
|
1460 | + $h = $w*$info['h']/$info['w']; |
|
1461 | + |
|
1462 | + // Flowing mode |
|
1463 | + if($y===null) |
|
1464 | + { |
|
1465 | + if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
1466 | + { |
|
1467 | + // Automatic page break |
|
1468 | + $x2 = $this->x; |
|
1469 | + $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
1470 | + $this->x = $x2; |
|
1471 | + } |
|
1472 | + $y = $this->y; |
|
1473 | + $this->y += $h; |
|
1474 | + } |
|
1475 | + |
|
1476 | + if($x===null) |
|
1477 | + $x = $this->x; |
|
1478 | + $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q',$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i'])); |
|
1479 | + if($link) |
|
1480 | + $this->Link($x,$y,$w,$h,$link); |
|
1481 | 1481 | } |
1482 | 1482 | |
1483 | 1483 | /** |
@@ -1486,8 +1486,8 @@ discard block |
||
1486 | 1486 | */ |
1487 | 1487 | public function GetPageWidth() : float |
1488 | 1488 | { |
1489 | - // Get current page width |
|
1490 | - return $this->w; |
|
1489 | + // Get current page width |
|
1490 | + return $this->w; |
|
1491 | 1491 | } |
1492 | 1492 | |
1493 | 1493 | /** |
@@ -1496,8 +1496,8 @@ discard block |
||
1496 | 1496 | */ |
1497 | 1497 | public function GetPageHeight() : float |
1498 | 1498 | { |
1499 | - // Get current page height |
|
1500 | - return $this->h; |
|
1499 | + // Get current page height |
|
1500 | + return $this->h; |
|
1501 | 1501 | } |
1502 | 1502 | |
1503 | 1503 | /** |
@@ -1506,8 +1506,8 @@ discard block |
||
1506 | 1506 | */ |
1507 | 1507 | public function GetX() : float |
1508 | 1508 | { |
1509 | - // GetX position |
|
1510 | - return $this->x; |
|
1509 | + // GetX position |
|
1510 | + return $this->x; |
|
1511 | 1511 | } |
1512 | 1512 | |
1513 | 1513 | /** |
@@ -1517,11 +1517,11 @@ discard block |
||
1517 | 1517 | */ |
1518 | 1518 | public function SetX(float $x) : void |
1519 | 1519 | { |
1520 | - // Set x position |
|
1521 | - if($x>=0) |
|
1522 | - $this->x = $x; |
|
1523 | - else |
|
1524 | - $this->x = $this->w+$x; |
|
1520 | + // Set x position |
|
1521 | + if($x>=0) |
|
1522 | + $this->x = $x; |
|
1523 | + else |
|
1524 | + $this->x = $this->w+$x; |
|
1525 | 1525 | } |
1526 | 1526 | |
1527 | 1527 | /** |
@@ -1530,8 +1530,8 @@ discard block |
||
1530 | 1530 | */ |
1531 | 1531 | public function GetY() : float |
1532 | 1532 | { |
1533 | - // Get y position |
|
1534 | - return $this->y; |
|
1533 | + // Get y position |
|
1534 | + return $this->y; |
|
1535 | 1535 | } |
1536 | 1536 | |
1537 | 1537 | /** |
@@ -1542,13 +1542,13 @@ discard block |
||
1542 | 1542 | */ |
1543 | 1543 | public function SetY(float $y, bool $resetX=true) : void |
1544 | 1544 | { |
1545 | - // Set y position and optionally reset x |
|
1546 | - if($y>=0) |
|
1547 | - $this->y = $y; |
|
1548 | - else |
|
1549 | - $this->y = $this->h+$y; |
|
1550 | - if($resetX) |
|
1551 | - $this->x = $this->lMargin; |
|
1545 | + // Set y position and optionally reset x |
|
1546 | + if($y>=0) |
|
1547 | + $this->y = $y; |
|
1548 | + else |
|
1549 | + $this->y = $this->h+$y; |
|
1550 | + if($resetX) |
|
1551 | + $this->x = $this->lMargin; |
|
1552 | 1552 | } |
1553 | 1553 | |
1554 | 1554 | /** |
@@ -1559,9 +1559,9 @@ discard block |
||
1559 | 1559 | */ |
1560 | 1560 | public function SetXY(float $x, float $y) : void |
1561 | 1561 | { |
1562 | - // Set x and y positions |
|
1563 | - $this->setX($x); |
|
1564 | - $this->setY($y,false); |
|
1562 | + // Set x and y positions |
|
1563 | + $this->setX($x); |
|
1564 | + $this->setY($y,false); |
|
1565 | 1565 | } |
1566 | 1566 | |
1567 | 1567 | /** |
@@ -1584,55 +1584,55 @@ discard block |
||
1584 | 1584 | */ |
1585 | 1585 | public function Output(string $dest='', string $name='', bool $isUTF8=false) : string |
1586 | 1586 | { |
1587 | - // Output PDF to some destination |
|
1588 | - $this->Close(); |
|
1589 | - if(strlen($name)==1 && strlen($dest)!=1) |
|
1590 | - { |
|
1591 | - // Fix parameter order |
|
1592 | - $tmp = $dest; |
|
1593 | - $dest = $name; |
|
1594 | - $name = $tmp; |
|
1595 | - } |
|
1596 | - if($dest=='') |
|
1597 | - $dest = 'I'; |
|
1598 | - if($name=='') |
|
1599 | - $name = 'doc.pdf'; |
|
1600 | - switch(strtoupper($dest)) |
|
1601 | - { |
|
1602 | - case 'I': |
|
1603 | - // Send to standard output |
|
1604 | - $this->_checkoutput(); |
|
1605 | - if(PHP_SAPI!='cli') |
|
1606 | - { |
|
1607 | - // We send to a browser |
|
1608 | - header('Content-Type: application/pdf; charset=UTF-8'); |
|
1609 | - header('Content-Disposition: inline; '.$this->_httpencode('filename',$name,$isUTF8)); |
|
1610 | - header('Cache-Control: private, max-age=0, must-revalidate'); |
|
1611 | - header('Pragma: public'); |
|
1612 | - } |
|
1613 | - echo $this->buffer; |
|
1614 | - break; |
|
1615 | - case 'D': |
|
1616 | - // Download file |
|
1617 | - $this->_checkoutput(); |
|
1618 | - header('Content-Type: application/x-download'); |
|
1619 | - header('Content-Disposition: attachment; '.$this->_httpencode('filename',$name,$isUTF8)); |
|
1620 | - header('Cache-Control: private, max-age=0, must-revalidate'); |
|
1621 | - header('Pragma: public'); |
|
1622 | - echo $this->buffer; |
|
1623 | - break; |
|
1624 | - case 'F': |
|
1625 | - // Save to local file |
|
1626 | - if(!file_put_contents($name,$this->buffer)) |
|
1627 | - $this->Error('Unable to create output file: '.$name); |
|
1628 | - break; |
|
1629 | - case 'S': |
|
1630 | - // Return as a string |
|
1631 | - return $this->buffer; |
|
1632 | - default: |
|
1633 | - $this->Error('Incorrect output destination: '.$dest); |
|
1634 | - } |
|
1635 | - return ''; |
|
1587 | + // Output PDF to some destination |
|
1588 | + $this->Close(); |
|
1589 | + if(strlen($name)==1 && strlen($dest)!=1) |
|
1590 | + { |
|
1591 | + // Fix parameter order |
|
1592 | + $tmp = $dest; |
|
1593 | + $dest = $name; |
|
1594 | + $name = $tmp; |
|
1595 | + } |
|
1596 | + if($dest=='') |
|
1597 | + $dest = 'I'; |
|
1598 | + if($name=='') |
|
1599 | + $name = 'doc.pdf'; |
|
1600 | + switch(strtoupper($dest)) |
|
1601 | + { |
|
1602 | + case 'I': |
|
1603 | + // Send to standard output |
|
1604 | + $this->_checkoutput(); |
|
1605 | + if(PHP_SAPI!='cli') |
|
1606 | + { |
|
1607 | + // We send to a browser |
|
1608 | + header('Content-Type: application/pdf; charset=UTF-8'); |
|
1609 | + header('Content-Disposition: inline; '.$this->_httpencode('filename',$name,$isUTF8)); |
|
1610 | + header('Cache-Control: private, max-age=0, must-revalidate'); |
|
1611 | + header('Pragma: public'); |
|
1612 | + } |
|
1613 | + echo $this->buffer; |
|
1614 | + break; |
|
1615 | + case 'D': |
|
1616 | + // Download file |
|
1617 | + $this->_checkoutput(); |
|
1618 | + header('Content-Type: application/x-download'); |
|
1619 | + header('Content-Disposition: attachment; '.$this->_httpencode('filename',$name,$isUTF8)); |
|
1620 | + header('Cache-Control: private, max-age=0, must-revalidate'); |
|
1621 | + header('Pragma: public'); |
|
1622 | + echo $this->buffer; |
|
1623 | + break; |
|
1624 | + case 'F': |
|
1625 | + // Save to local file |
|
1626 | + if(!file_put_contents($name,$this->buffer)) |
|
1627 | + $this->Error('Unable to create output file: '.$name); |
|
1628 | + break; |
|
1629 | + case 'S': |
|
1630 | + // Return as a string |
|
1631 | + return $this->buffer; |
|
1632 | + default: |
|
1633 | + $this->Error('Incorrect output destination: '.$dest); |
|
1634 | + } |
|
1635 | + return ''; |
|
1636 | 1636 | } |
1637 | 1637 | |
1638 | 1638 | /** |
@@ -1640,9 +1640,9 @@ discard block |
||
1640 | 1640 | */ |
1641 | 1641 | protected function _dochecks() : void |
1642 | 1642 | { |
1643 | - // Check mbstring overloading |
|
1644 | - if(ini_get('mbstring.func_overload') & 2) |
|
1645 | - $this->Error('mbstring overloading must be disabled'); |
|
1643 | + // Check mbstring overloading |
|
1644 | + if(ini_get('mbstring.func_overload') & 2) |
|
1645 | + $this->Error('mbstring overloading must be disabled'); |
|
1646 | 1646 | } |
1647 | 1647 | |
1648 | 1648 | /** |
@@ -1650,24 +1650,24 @@ discard block |
||
1650 | 1650 | */ |
1651 | 1651 | protected function _checkoutput() : void |
1652 | 1652 | { |
1653 | - if(PHP_SAPI!='cli') |
|
1654 | - { |
|
1655 | - $file = ''; |
|
1656 | - $line = 0; |
|
1657 | - if(headers_sent($file,$line)) |
|
1658 | - $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)"); |
|
1659 | - } |
|
1660 | - if(ob_get_length()) |
|
1661 | - { |
|
1662 | - // The output buffer is not empty |
|
1663 | - if(preg_match('/^(\xEF\xBB\xBF)?\s*$/',ob_get_contents())) |
|
1664 | - { |
|
1665 | - // It contains only a UTF-8 BOM and/or whitespace, let's clean it |
|
1666 | - ob_clean(); |
|
1667 | - } |
|
1668 | - else |
|
1669 | - $this->Error("Some data has already been output, can't send PDF file"); |
|
1670 | - } |
|
1653 | + if(PHP_SAPI!='cli') |
|
1654 | + { |
|
1655 | + $file = ''; |
|
1656 | + $line = 0; |
|
1657 | + if(headers_sent($file,$line)) |
|
1658 | + $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)"); |
|
1659 | + } |
|
1660 | + if(ob_get_length()) |
|
1661 | + { |
|
1662 | + // The output buffer is not empty |
|
1663 | + if(preg_match('/^(\xEF\xBB\xBF)?\s*$/',ob_get_contents())) |
|
1664 | + { |
|
1665 | + // It contains only a UTF-8 BOM and/or whitespace, let's clean it |
|
1666 | + ob_clean(); |
|
1667 | + } |
|
1668 | + else |
|
1669 | + $this->Error("Some data has already been output, can't send PDF file"); |
|
1670 | + } |
|
1671 | 1671 | } |
1672 | 1672 | |
1673 | 1673 | /** |
@@ -1677,21 +1677,21 @@ discard block |
||
1677 | 1677 | */ |
1678 | 1678 | protected function _getpagesize($size) : array |
1679 | 1679 | { |
1680 | - if(is_string($size)) |
|
1681 | - { |
|
1682 | - $size = strtolower($size); |
|
1683 | - if(!isset($this->StdPageSizes[$size])) |
|
1684 | - $this->Error('Unknown page size: '.$size); |
|
1685 | - $a = $this->StdPageSizes[$size]; |
|
1686 | - return array($a[0]/$this->k, $a[1]/$this->k); |
|
1687 | - } |
|
1688 | - else |
|
1689 | - { |
|
1690 | - if($size[0]>$size[1]) |
|
1691 | - return array($size[1], $size[0]); |
|
1692 | - else |
|
1693 | - return $size; |
|
1694 | - } |
|
1680 | + if(is_string($size)) |
|
1681 | + { |
|
1682 | + $size = strtolower($size); |
|
1683 | + if(!isset($this->StdPageSizes[$size])) |
|
1684 | + $this->Error('Unknown page size: '.$size); |
|
1685 | + $a = $this->StdPageSizes[$size]; |
|
1686 | + return array($a[0]/$this->k, $a[1]/$this->k); |
|
1687 | + } |
|
1688 | + else |
|
1689 | + { |
|
1690 | + if($size[0]>$size[1]) |
|
1691 | + return array($size[1], $size[0]); |
|
1692 | + else |
|
1693 | + return $size; |
|
1694 | + } |
|
1695 | 1695 | } |
1696 | 1696 | |
1697 | 1697 | /** |
@@ -1702,49 +1702,49 @@ discard block |
||
1702 | 1702 | */ |
1703 | 1703 | protected function _beginpage(string $orientation, $size, int $rotation) : void |
1704 | 1704 | { |
1705 | - $this->page++; |
|
1706 | - $this->pages[$this->page] = ''; |
|
1707 | - $this->state = 2; |
|
1708 | - $this->x = $this->lMargin; |
|
1709 | - $this->y = $this->tMargin; |
|
1710 | - $this->FontFamily = ''; |
|
1711 | - // Check page size and orientation |
|
1712 | - if($orientation=='') |
|
1713 | - $orientation = $this->DefOrientation; |
|
1714 | - else |
|
1715 | - $orientation = strtoupper($orientation[0]); |
|
1716 | - if($size=='') |
|
1717 | - $size = $this->DefPageSize; |
|
1718 | - else |
|
1719 | - $size = $this->_getpagesize($size); |
|
1720 | - if($orientation!=$this->CurOrientation || $size[0]!=$this->CurPageSize[0] || $size[1]!=$this->CurPageSize[1]) |
|
1721 | - { |
|
1722 | - // New size or orientation |
|
1723 | - if($orientation=='P') |
|
1724 | - { |
|
1725 | - $this->w = $size[0]; |
|
1726 | - $this->h = $size[1]; |
|
1727 | - } |
|
1728 | - else |
|
1729 | - { |
|
1730 | - $this->w = $size[1]; |
|
1731 | - $this->h = $size[0]; |
|
1732 | - } |
|
1733 | - $this->wPt = $this->w*$this->k; |
|
1734 | - $this->hPt = $this->h*$this->k; |
|
1735 | - $this->PageBreakTrigger = $this->h-$this->bMargin; |
|
1736 | - $this->CurOrientation = $orientation; |
|
1737 | - $this->CurPageSize = $size; |
|
1738 | - } |
|
1739 | - if($orientation!=$this->DefOrientation || $size[0]!=$this->DefPageSize[0] || $size[1]!=$this->DefPageSize[1]) |
|
1740 | - $this->PageInfo[$this->page]['size'] = array($this->wPt, $this->hPt); |
|
1741 | - if($rotation!=0) |
|
1742 | - { |
|
1743 | - if($rotation%90!=0) |
|
1744 | - $this->Error('Incorrect rotation value: '.$rotation); |
|
1745 | - $this->CurRotation = $rotation; |
|
1746 | - $this->PageInfo[$this->page]['rotation'] = $rotation; |
|
1747 | - } |
|
1705 | + $this->page++; |
|
1706 | + $this->pages[$this->page] = ''; |
|
1707 | + $this->state = 2; |
|
1708 | + $this->x = $this->lMargin; |
|
1709 | + $this->y = $this->tMargin; |
|
1710 | + $this->FontFamily = ''; |
|
1711 | + // Check page size and orientation |
|
1712 | + if($orientation=='') |
|
1713 | + $orientation = $this->DefOrientation; |
|
1714 | + else |
|
1715 | + $orientation = strtoupper($orientation[0]); |
|
1716 | + if($size=='') |
|
1717 | + $size = $this->DefPageSize; |
|
1718 | + else |
|
1719 | + $size = $this->_getpagesize($size); |
|
1720 | + if($orientation!=$this->CurOrientation || $size[0]!=$this->CurPageSize[0] || $size[1]!=$this->CurPageSize[1]) |
|
1721 | + { |
|
1722 | + // New size or orientation |
|
1723 | + if($orientation=='P') |
|
1724 | + { |
|
1725 | + $this->w = $size[0]; |
|
1726 | + $this->h = $size[1]; |
|
1727 | + } |
|
1728 | + else |
|
1729 | + { |
|
1730 | + $this->w = $size[1]; |
|
1731 | + $this->h = $size[0]; |
|
1732 | + } |
|
1733 | + $this->wPt = $this->w*$this->k; |
|
1734 | + $this->hPt = $this->h*$this->k; |
|
1735 | + $this->PageBreakTrigger = $this->h-$this->bMargin; |
|
1736 | + $this->CurOrientation = $orientation; |
|
1737 | + $this->CurPageSize = $size; |
|
1738 | + } |
|
1739 | + if($orientation!=$this->DefOrientation || $size[0]!=$this->DefPageSize[0] || $size[1]!=$this->DefPageSize[1]) |
|
1740 | + $this->PageInfo[$this->page]['size'] = array($this->wPt, $this->hPt); |
|
1741 | + if($rotation!=0) |
|
1742 | + { |
|
1743 | + if($rotation%90!=0) |
|
1744 | + $this->Error('Incorrect rotation value: '.$rotation); |
|
1745 | + $this->CurRotation = $rotation; |
|
1746 | + $this->PageInfo[$this->page]['rotation'] = $rotation; |
|
1747 | + } |
|
1748 | 1748 | } |
1749 | 1749 | |
1750 | 1750 | /** |
@@ -1752,7 +1752,7 @@ discard block |
||
1752 | 1752 | */ |
1753 | 1753 | protected function _endpage() : void |
1754 | 1754 | { |
1755 | - $this->state = 1; |
|
1755 | + $this->state = 1; |
|
1756 | 1756 | } |
1757 | 1757 | |
1758 | 1758 | /** |
@@ -1762,27 +1762,27 @@ discard block |
||
1762 | 1762 | */ |
1763 | 1763 | protected function _loadfont(string $font) : array |
1764 | 1764 | { |
1765 | - // Load a font definition file from the font directory |
|
1765 | + // Load a font definition file from the font directory |
|
1766 | 1766 | if(strpos($font,'/')!==false || strpos($font,"\\")!==false) { |
1767 | - $this->Error('Incorrect font definition file name: '.$font); |
|
1767 | + $this->Error('Incorrect font definition file name: '.$font); |
|
1768 | 1768 | } |
1769 | 1769 | // following vars must be initialized in the font definition file beeing included |
1770 | - $name = null; |
|
1771 | - $enc = null; |
|
1772 | - $subsetted = null; |
|
1773 | - include($this->fontpath.$font); |
|
1770 | + $name = null; |
|
1771 | + $enc = null; |
|
1772 | + $subsetted = null; |
|
1773 | + include($this->fontpath.$font); |
|
1774 | 1774 | |
1775 | - // phpstan can't see the code dynamicly included before so assuming $name, $enc, $subsetted always set to null! |
|
1776 | - if(!isset($name)) { /* @phpstan-ignore-line */ |
|
1777 | - $this->Error('Could not include font definition file'); |
|
1778 | - } |
|
1779 | - if(isset($enc)) { /* @phpstan-ignore-line */ |
|
1780 | - $enc = strtolower($enc); |
|
1781 | - } |
|
1782 | - if(!isset($subsetted)) { /* @phpstan-ignore-line */ |
|
1783 | - $subsetted = false; |
|
1784 | - } |
|
1785 | - return get_defined_vars(); |
|
1775 | + // phpstan can't see the code dynamicly included before so assuming $name, $enc, $subsetted always set to null! |
|
1776 | + if(!isset($name)) { /* @phpstan-ignore-line */ |
|
1777 | + $this->Error('Could not include font definition file'); |
|
1778 | + } |
|
1779 | + if(isset($enc)) { /* @phpstan-ignore-line */ |
|
1780 | + $enc = strtolower($enc); |
|
1781 | + } |
|
1782 | + if(!isset($subsetted)) { /* @phpstan-ignore-line */ |
|
1783 | + $subsetted = false; |
|
1784 | + } |
|
1785 | + return get_defined_vars(); |
|
1786 | 1786 | } |
1787 | 1787 | |
1788 | 1788 | /** |
@@ -1792,14 +1792,14 @@ discard block |
||
1792 | 1792 | */ |
1793 | 1793 | protected function _isascii(string $s) : bool |
1794 | 1794 | { |
1795 | - // Test if string is ASCII |
|
1796 | - $nb = strlen($s); |
|
1797 | - for($i=0;$i<$nb;$i++) |
|
1798 | - { |
|
1799 | - if(ord($s[$i])>127) |
|
1800 | - return false; |
|
1801 | - } |
|
1802 | - return true; |
|
1795 | + // Test if string is ASCII |
|
1796 | + $nb = strlen($s); |
|
1797 | + for($i=0;$i<$nb;$i++) |
|
1798 | + { |
|
1799 | + if(ord($s[$i])>127) |
|
1800 | + return false; |
|
1801 | + } |
|
1802 | + return true; |
|
1803 | 1803 | } |
1804 | 1804 | |
1805 | 1805 | /** |
@@ -1810,15 +1810,15 @@ discard block |
||
1810 | 1810 | */ |
1811 | 1811 | protected function _httpencode(string $param, string $value, bool $isUTF8) : string |
1812 | 1812 | { |
1813 | - // Encode HTTP header field parameter |
|
1814 | - if($this->_isascii($value)) |
|
1815 | - return $param.'="'.$value.'"'; |
|
1816 | - if(!$isUTF8) |
|
1817 | - $value = utf8_encode($value); |
|
1818 | - if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==false) |
|
1819 | - return $param.'="'.rawurlencode($value).'"'; |
|
1820 | - else |
|
1821 | - return $param."*=UTF-8''".rawurlencode($value); |
|
1813 | + // Encode HTTP header field parameter |
|
1814 | + if($this->_isascii($value)) |
|
1815 | + return $param.'="'.$value.'"'; |
|
1816 | + if(!$isUTF8) |
|
1817 | + $value = utf8_encode($value); |
|
1818 | + if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==false) |
|
1819 | + return $param.'="'.rawurlencode($value).'"'; |
|
1820 | + else |
|
1821 | + return $param."*=UTF-8''".rawurlencode($value); |
|
1822 | 1822 | } |
1823 | 1823 | |
1824 | 1824 | /** |
@@ -1828,35 +1828,35 @@ discard block |
||
1828 | 1828 | */ |
1829 | 1829 | protected function _UTF8toUTF16(string $s) : string |
1830 | 1830 | { |
1831 | - // Convert UTF-8 to UTF-16BE with BOM |
|
1832 | - $res = "\xFE\xFF"; |
|
1833 | - $nb = strlen($s); |
|
1834 | - $i = 0; |
|
1835 | - while($i<$nb) |
|
1836 | - { |
|
1837 | - $c1 = ord($s[$i++]); |
|
1838 | - if($c1>=224) |
|
1839 | - { |
|
1840 | - // 3-byte character |
|
1841 | - $c2 = ord($s[$i++]); |
|
1842 | - $c3 = ord($s[$i++]); |
|
1843 | - $res .= chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2)); |
|
1844 | - $res .= chr((($c2 & 0x03)<<6) + ($c3 & 0x3F)); |
|
1845 | - } |
|
1846 | - elseif($c1>=192) |
|
1847 | - { |
|
1848 | - // 2-byte character |
|
1849 | - $c2 = ord($s[$i++]); |
|
1850 | - $res .= chr(($c1 & 0x1C)>>2); |
|
1851 | - $res .= chr((($c1 & 0x03)<<6) + ($c2 & 0x3F)); |
|
1852 | - } |
|
1853 | - else |
|
1854 | - { |
|
1855 | - // Single-byte character |
|
1856 | - $res .= "\0".chr($c1); |
|
1857 | - } |
|
1858 | - } |
|
1859 | - return $res; |
|
1831 | + // Convert UTF-8 to UTF-16BE with BOM |
|
1832 | + $res = "\xFE\xFF"; |
|
1833 | + $nb = strlen($s); |
|
1834 | + $i = 0; |
|
1835 | + while($i<$nb) |
|
1836 | + { |
|
1837 | + $c1 = ord($s[$i++]); |
|
1838 | + if($c1>=224) |
|
1839 | + { |
|
1840 | + // 3-byte character |
|
1841 | + $c2 = ord($s[$i++]); |
|
1842 | + $c3 = ord($s[$i++]); |
|
1843 | + $res .= chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2)); |
|
1844 | + $res .= chr((($c2 & 0x03)<<6) + ($c3 & 0x3F)); |
|
1845 | + } |
|
1846 | + elseif($c1>=192) |
|
1847 | + { |
|
1848 | + // 2-byte character |
|
1849 | + $c2 = ord($s[$i++]); |
|
1850 | + $res .= chr(($c1 & 0x1C)>>2); |
|
1851 | + $res .= chr((($c1 & 0x03)<<6) + ($c2 & 0x3F)); |
|
1852 | + } |
|
1853 | + else |
|
1854 | + { |
|
1855 | + // Single-byte character |
|
1856 | + $res .= "\0".chr($c1); |
|
1857 | + } |
|
1858 | + } |
|
1859 | + return $res; |
|
1860 | 1860 | } |
1861 | 1861 | |
1862 | 1862 | /** |
@@ -1866,11 +1866,11 @@ discard block |
||
1866 | 1866 | */ |
1867 | 1867 | protected function _escape(string $s) : string |
1868 | 1868 | { |
1869 | - // Escape special characters |
|
1870 | - if(strpos($s,'(')!==false || strpos($s,')')!==false || strpos($s,'\\')!==false || strpos($s,"\r")!==false) |
|
1871 | - return str_replace(array('\\','(',')',"\r"), array('\\\\','\\(','\\)','\\r'), $s); |
|
1872 | - else |
|
1873 | - return $s; |
|
1869 | + // Escape special characters |
|
1870 | + if(strpos($s,'(')!==false || strpos($s,')')!==false || strpos($s,'\\')!==false || strpos($s,"\r")!==false) |
|
1871 | + return str_replace(array('\\','(',')',"\r"), array('\\\\','\\(','\\)','\\r'), $s); |
|
1872 | + else |
|
1873 | + return $s; |
|
1874 | 1874 | } |
1875 | 1875 | |
1876 | 1876 | /** |
@@ -1880,10 +1880,10 @@ discard block |
||
1880 | 1880 | */ |
1881 | 1881 | protected function _textstring(string $s) : string |
1882 | 1882 | { |
1883 | - // Format a text string |
|
1884 | - if(!$this->_isascii($s)) |
|
1885 | - $s = $this->_UTF8toUTF16($s); |
|
1886 | - return '('.$this->_escape($s).')'; |
|
1883 | + // Format a text string |
|
1884 | + if(!$this->_isascii($s)) |
|
1885 | + $s = $this->_UTF8toUTF16($s); |
|
1886 | + return '('.$this->_escape($s).')'; |
|
1887 | 1887 | } |
1888 | 1888 | |
1889 | 1889 | /** |
@@ -1895,11 +1895,11 @@ discard block |
||
1895 | 1895 | */ |
1896 | 1896 | protected function _dounderline(float $x, float $y, string $txt) : string |
1897 | 1897 | { |
1898 | - // Underline text |
|
1899 | - $up = $this->CurrentFont['up']; |
|
1900 | - $ut = $this->CurrentFont['ut']; |
|
1901 | - $w = $this->getStringWidth($txt)+$this->ws*substr_count($txt,' '); |
|
1902 | - return sprintf('%.2F %.2F %.2F %.2F re f',$x*$this->k,($this->h-($y-$up/1000*$this->FontSize))*$this->k,$w*$this->k,-$ut/1000*$this->FontSizePt); |
|
1898 | + // Underline text |
|
1899 | + $up = $this->CurrentFont['up']; |
|
1900 | + $ut = $this->CurrentFont['ut']; |
|
1901 | + $w = $this->getStringWidth($txt)+$this->ws*substr_count($txt,' '); |
|
1902 | + return sprintf('%.2F %.2F %.2F %.2F re f',$x*$this->k,($this->h-($y-$up/1000*$this->FontSize))*$this->k,$w*$this->k,-$ut/1000*$this->FontSizePt); |
|
1903 | 1903 | } |
1904 | 1904 | |
1905 | 1905 | /** |
@@ -1909,21 +1909,21 @@ discard block |
||
1909 | 1909 | */ |
1910 | 1910 | protected function _parsejpg(string $file) : array |
1911 | 1911 | { |
1912 | - // Extract info from a JPEG file |
|
1913 | - $a = getimagesize($file); |
|
1914 | - if(!$a) |
|
1915 | - $this->Error('Missing or incorrect image file: '.$file); |
|
1916 | - if($a[2]!=2) |
|
1917 | - $this->Error('Not a JPEG file: '.$file); |
|
1918 | - if(!isset($a['channels']) || $a['channels']==3) |
|
1919 | - $colspace = 'DeviceRGB'; |
|
1920 | - elseif($a['channels']==4) |
|
1921 | - $colspace = 'DeviceCMYK'; |
|
1922 | - else |
|
1923 | - $colspace = 'DeviceGray'; |
|
1924 | - $bpc = isset($a['bits']) ? $a['bits'] : 8; |
|
1925 | - $data = file_get_contents($file); |
|
1926 | - return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data); |
|
1912 | + // Extract info from a JPEG file |
|
1913 | + $a = getimagesize($file); |
|
1914 | + if(!$a) |
|
1915 | + $this->Error('Missing or incorrect image file: '.$file); |
|
1916 | + if($a[2]!=2) |
|
1917 | + $this->Error('Not a JPEG file: '.$file); |
|
1918 | + if(!isset($a['channels']) || $a['channels']==3) |
|
1919 | + $colspace = 'DeviceRGB'; |
|
1920 | + elseif($a['channels']==4) |
|
1921 | + $colspace = 'DeviceCMYK'; |
|
1922 | + else |
|
1923 | + $colspace = 'DeviceGray'; |
|
1924 | + $bpc = isset($a['bits']) ? $a['bits'] : 8; |
|
1925 | + $data = file_get_contents($file); |
|
1926 | + return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data); |
|
1927 | 1927 | } |
1928 | 1928 | |
1929 | 1929 | /** |
@@ -1933,14 +1933,14 @@ discard block |
||
1933 | 1933 | */ |
1934 | 1934 | protected function _parsepng(string $file) : array |
1935 | 1935 | { |
1936 | - // Extract info from a PNG file |
|
1937 | - $f = fopen($file, 'rb'); |
|
1938 | - if ($f === false) { |
|
1939 | - $this->Error('Can\'t open image file: ' . $file); |
|
1940 | - } |
|
1941 | - $info = $this->_parsepngstream($f, $file); |
|
1942 | - fclose($f); |
|
1943 | - return $info; |
|
1936 | + // Extract info from a PNG file |
|
1937 | + $f = fopen($file, 'rb'); |
|
1938 | + if ($f === false) { |
|
1939 | + $this->Error('Can\'t open image file: ' . $file); |
|
1940 | + } |
|
1941 | + $info = $this->_parsepngstream($f, $file); |
|
1942 | + fclose($f); |
|
1943 | + return $info; |
|
1944 | 1944 | } |
1945 | 1945 | |
1946 | 1946 | /** |
@@ -1951,129 +1951,129 @@ discard block |
||
1951 | 1951 | */ |
1952 | 1952 | protected function _parsepngstream($f, string $file) : array |
1953 | 1953 | { |
1954 | - // Check signature |
|
1955 | - if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) |
|
1956 | - $this->Error('Not a PNG file: '.$file); |
|
1957 | - |
|
1958 | - // Read header chunk |
|
1959 | - $this->_readstream($f,4); |
|
1960 | - if($this->_readstream($f,4)!='IHDR') |
|
1961 | - $this->Error('Incorrect PNG file: '.$file); |
|
1962 | - $w = $this->_readint($f); |
|
1963 | - $h = $this->_readint($f); |
|
1964 | - $bpc = ord($this->_readstream($f,1)); |
|
1965 | - if($bpc>8) |
|
1966 | - $this->Error('16-bit depth not supported: '.$file); |
|
1967 | - $ct = ord($this->_readstream($f,1)); |
|
1968 | - $colspace = ''; |
|
1969 | - if($ct==0 || $ct==4) |
|
1970 | - $colspace = 'DeviceGray'; |
|
1971 | - elseif($ct==2 || $ct==6) |
|
1972 | - $colspace = 'DeviceRGB'; |
|
1973 | - elseif($ct==3) |
|
1974 | - $colspace = 'Indexed'; |
|
1975 | - else |
|
1976 | - $this->Error('Unknown color type: '.$file); |
|
1977 | - if(ord($this->_readstream($f,1))!=0) |
|
1978 | - $this->Error('Unknown compression method: '.$file); |
|
1979 | - if(ord($this->_readstream($f,1))!=0) |
|
1980 | - $this->Error('Unknown filter method: '.$file); |
|
1981 | - if(ord($this->_readstream($f,1))!=0) |
|
1982 | - $this->Error('Interlacing not supported: '.$file); |
|
1983 | - $this->_readstream($f,4); |
|
1984 | - $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w; |
|
1985 | - |
|
1986 | - // Scan chunks looking for palette, transparency and image data |
|
1987 | - $pal = ''; |
|
1988 | - $trns = ''; |
|
1989 | - $data = ''; |
|
1990 | - do |
|
1991 | - { |
|
1992 | - $n = $this->_readint($f); |
|
1993 | - $type = $this->_readstream($f,4); |
|
1994 | - if($type=='PLTE') |
|
1995 | - { |
|
1996 | - // Read palette |
|
1997 | - $pal = $this->_readstream($f,$n); |
|
1998 | - $this->_readstream($f,4); |
|
1999 | - } |
|
2000 | - elseif($type=='tRNS') |
|
2001 | - { |
|
2002 | - // Read transparency info |
|
2003 | - $t = $this->_readstream($f,$n); |
|
2004 | - if($ct==0) |
|
2005 | - $trns = array(ord(substr($t,1,1))); |
|
2006 | - elseif($ct==2) |
|
2007 | - $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); |
|
2008 | - else |
|
2009 | - { |
|
2010 | - $pos = strpos($t,chr(0)); |
|
2011 | - if($pos!==false) |
|
2012 | - $trns = array($pos); |
|
2013 | - } |
|
2014 | - $this->_readstream($f,4); |
|
2015 | - } |
|
2016 | - elseif($type=='IDAT') |
|
2017 | - { |
|
2018 | - // Read image data block |
|
2019 | - $data .= $this->_readstream($f,$n); |
|
2020 | - $this->_readstream($f,4); |
|
2021 | - } |
|
2022 | - elseif($type=='IEND') |
|
2023 | - break; |
|
2024 | - else |
|
2025 | - $this->_readstream($f,$n+4); |
|
2026 | - } |
|
2027 | - while($n); |
|
2028 | - |
|
2029 | - if($colspace=='Indexed' && empty($pal)) |
|
2030 | - $this->Error('Missing palette in '.$file); |
|
2031 | - $info = array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns); |
|
2032 | - if($ct>=4) |
|
2033 | - { |
|
2034 | - // Extract alpha channel |
|
2035 | - if(!function_exists('gzuncompress')) |
|
2036 | - $this->Error('Zlib not available, can\'t handle alpha channel: '.$file); |
|
2037 | - $data = gzuncompress($data); |
|
2038 | - $color = ''; |
|
2039 | - $alpha = ''; |
|
2040 | - if($ct==4) |
|
2041 | - { |
|
2042 | - // Gray image |
|
2043 | - $len = 2*$w; |
|
2044 | - for($i=0;$i<$h;$i++) |
|
2045 | - { |
|
2046 | - $pos = (1+$len)*$i; |
|
2047 | - $color .= $data[$pos]; |
|
2048 | - $alpha .= $data[$pos]; |
|
2049 | - $line = substr($data,$pos+1,$len); |
|
2050 | - $color .= preg_replace('/(.)./s','$1',$line); |
|
2051 | - $alpha .= preg_replace('/.(.)/s','$1',$line); |
|
2052 | - } |
|
2053 | - } |
|
2054 | - else |
|
2055 | - { |
|
2056 | - // RGB image |
|
2057 | - $len = 4*$w; |
|
2058 | - for($i=0;$i<$h;$i++) |
|
2059 | - { |
|
2060 | - $pos = (1+$len)*$i; |
|
2061 | - $color .= $data[$pos]; |
|
2062 | - $alpha .= $data[$pos]; |
|
2063 | - $line = substr($data,$pos+1,$len); |
|
2064 | - $color .= preg_replace('/(.{3})./s','$1',$line); |
|
2065 | - $alpha .= preg_replace('/.{3}(.)/s','$1',$line); |
|
2066 | - } |
|
2067 | - } |
|
2068 | - unset($data); |
|
2069 | - $data = gzcompress($color); |
|
2070 | - $info['smask'] = gzcompress($alpha); |
|
2071 | - $this->WithAlpha = true; |
|
2072 | - if($this->PDFVersion<'1.4') |
|
2073 | - $this->PDFVersion = '1.4'; |
|
2074 | - } |
|
2075 | - $info['data'] = $data; |
|
2076 | - return $info; |
|
1954 | + // Check signature |
|
1955 | + if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) |
|
1956 | + $this->Error('Not a PNG file: '.$file); |
|
1957 | + |
|
1958 | + // Read header chunk |
|
1959 | + $this->_readstream($f,4); |
|
1960 | + if($this->_readstream($f,4)!='IHDR') |
|
1961 | + $this->Error('Incorrect PNG file: '.$file); |
|
1962 | + $w = $this->_readint($f); |
|
1963 | + $h = $this->_readint($f); |
|
1964 | + $bpc = ord($this->_readstream($f,1)); |
|
1965 | + if($bpc>8) |
|
1966 | + $this->Error('16-bit depth not supported: '.$file); |
|
1967 | + $ct = ord($this->_readstream($f,1)); |
|
1968 | + $colspace = ''; |
|
1969 | + if($ct==0 || $ct==4) |
|
1970 | + $colspace = 'DeviceGray'; |
|
1971 | + elseif($ct==2 || $ct==6) |
|
1972 | + $colspace = 'DeviceRGB'; |
|
1973 | + elseif($ct==3) |
|
1974 | + $colspace = 'Indexed'; |
|
1975 | + else |
|
1976 | + $this->Error('Unknown color type: '.$file); |
|
1977 | + if(ord($this->_readstream($f,1))!=0) |
|
1978 | + $this->Error('Unknown compression method: '.$file); |
|
1979 | + if(ord($this->_readstream($f,1))!=0) |
|
1980 | + $this->Error('Unknown filter method: '.$file); |
|
1981 | + if(ord($this->_readstream($f,1))!=0) |
|
1982 | + $this->Error('Interlacing not supported: '.$file); |
|
1983 | + $this->_readstream($f,4); |
|
1984 | + $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w; |
|
1985 | + |
|
1986 | + // Scan chunks looking for palette, transparency and image data |
|
1987 | + $pal = ''; |
|
1988 | + $trns = ''; |
|
1989 | + $data = ''; |
|
1990 | + do |
|
1991 | + { |
|
1992 | + $n = $this->_readint($f); |
|
1993 | + $type = $this->_readstream($f,4); |
|
1994 | + if($type=='PLTE') |
|
1995 | + { |
|
1996 | + // Read palette |
|
1997 | + $pal = $this->_readstream($f,$n); |
|
1998 | + $this->_readstream($f,4); |
|
1999 | + } |
|
2000 | + elseif($type=='tRNS') |
|
2001 | + { |
|
2002 | + // Read transparency info |
|
2003 | + $t = $this->_readstream($f,$n); |
|
2004 | + if($ct==0) |
|
2005 | + $trns = array(ord(substr($t,1,1))); |
|
2006 | + elseif($ct==2) |
|
2007 | + $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); |
|
2008 | + else |
|
2009 | + { |
|
2010 | + $pos = strpos($t,chr(0)); |
|
2011 | + if($pos!==false) |
|
2012 | + $trns = array($pos); |
|
2013 | + } |
|
2014 | + $this->_readstream($f,4); |
|
2015 | + } |
|
2016 | + elseif($type=='IDAT') |
|
2017 | + { |
|
2018 | + // Read image data block |
|
2019 | + $data .= $this->_readstream($f,$n); |
|
2020 | + $this->_readstream($f,4); |
|
2021 | + } |
|
2022 | + elseif($type=='IEND') |
|
2023 | + break; |
|
2024 | + else |
|
2025 | + $this->_readstream($f,$n+4); |
|
2026 | + } |
|
2027 | + while($n); |
|
2028 | + |
|
2029 | + if($colspace=='Indexed' && empty($pal)) |
|
2030 | + $this->Error('Missing palette in '.$file); |
|
2031 | + $info = array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns); |
|
2032 | + if($ct>=4) |
|
2033 | + { |
|
2034 | + // Extract alpha channel |
|
2035 | + if(!function_exists('gzuncompress')) |
|
2036 | + $this->Error('Zlib not available, can\'t handle alpha channel: '.$file); |
|
2037 | + $data = gzuncompress($data); |
|
2038 | + $color = ''; |
|
2039 | + $alpha = ''; |
|
2040 | + if($ct==4) |
|
2041 | + { |
|
2042 | + // Gray image |
|
2043 | + $len = 2*$w; |
|
2044 | + for($i=0;$i<$h;$i++) |
|
2045 | + { |
|
2046 | + $pos = (1+$len)*$i; |
|
2047 | + $color .= $data[$pos]; |
|
2048 | + $alpha .= $data[$pos]; |
|
2049 | + $line = substr($data,$pos+1,$len); |
|
2050 | + $color .= preg_replace('/(.)./s','$1',$line); |
|
2051 | + $alpha .= preg_replace('/.(.)/s','$1',$line); |
|
2052 | + } |
|
2053 | + } |
|
2054 | + else |
|
2055 | + { |
|
2056 | + // RGB image |
|
2057 | + $len = 4*$w; |
|
2058 | + for($i=0;$i<$h;$i++) |
|
2059 | + { |
|
2060 | + $pos = (1+$len)*$i; |
|
2061 | + $color .= $data[$pos]; |
|
2062 | + $alpha .= $data[$pos]; |
|
2063 | + $line = substr($data,$pos+1,$len); |
|
2064 | + $color .= preg_replace('/(.{3})./s','$1',$line); |
|
2065 | + $alpha .= preg_replace('/.{3}(.)/s','$1',$line); |
|
2066 | + } |
|
2067 | + } |
|
2068 | + unset($data); |
|
2069 | + $data = gzcompress($color); |
|
2070 | + $info['smask'] = gzcompress($alpha); |
|
2071 | + $this->WithAlpha = true; |
|
2072 | + if($this->PDFVersion<'1.4') |
|
2073 | + $this->PDFVersion = '1.4'; |
|
2074 | + } |
|
2075 | + $info['data'] = $data; |
|
2076 | + return $info; |
|
2077 | 2077 | } |
2078 | 2078 | |
2079 | 2079 | /** |
@@ -2084,19 +2084,19 @@ discard block |
||
2084 | 2084 | */ |
2085 | 2085 | protected function _readstream($f, int $n) : string |
2086 | 2086 | { |
2087 | - // Read n bytes from stream |
|
2088 | - $res = ''; |
|
2089 | - while($n>0 && !feof($f)) |
|
2090 | - { |
|
2091 | - $s = fread($f,$n); |
|
2092 | - if($s===false) |
|
2093 | - $this->Error('Error while reading stream'); |
|
2094 | - $n -= strlen($s); |
|
2095 | - $res .= $s; |
|
2096 | - } |
|
2097 | - if($n>0) |
|
2098 | - $this->Error('Unexpected end of stream'); |
|
2099 | - return $res; |
|
2087 | + // Read n bytes from stream |
|
2088 | + $res = ''; |
|
2089 | + while($n>0 && !feof($f)) |
|
2090 | + { |
|
2091 | + $s = fread($f,$n); |
|
2092 | + if($s===false) |
|
2093 | + $this->Error('Error while reading stream'); |
|
2094 | + $n -= strlen($s); |
|
2095 | + $res .= $s; |
|
2096 | + } |
|
2097 | + if($n>0) |
|
2098 | + $this->Error('Unexpected end of stream'); |
|
2099 | + return $res; |
|
2100 | 2100 | } |
2101 | 2101 | |
2102 | 2102 | /** |
@@ -2106,9 +2106,9 @@ discard block |
||
2106 | 2106 | */ |
2107 | 2107 | protected function _readint($f) : int |
2108 | 2108 | { |
2109 | - // Read a 4-byte integer from stream |
|
2110 | - $a = unpack('Ni',$this->_readstream($f,4)); |
|
2111 | - return $a['i']; |
|
2109 | + // Read a 4-byte integer from stream |
|
2110 | + $a = unpack('Ni',$this->_readstream($f,4)); |
|
2111 | + return $a['i']; |
|
2112 | 2112 | } |
2113 | 2113 | |
2114 | 2114 | /** |
@@ -2118,31 +2118,31 @@ discard block |
||
2118 | 2118 | */ |
2119 | 2119 | protected function _parsegif(string $file) : array |
2120 | 2120 | { |
2121 | - // Extract info from a GIF file (via PNG conversion) |
|
2121 | + // Extract info from a GIF file (via PNG conversion) |
|
2122 | 2122 | if (!function_exists('imagepng')) { |
2123 | - $this->Error('GD extension is required for GIF support'); |
|
2123 | + $this->Error('GD extension is required for GIF support'); |
|
2124 | 2124 | } |
2125 | 2125 | if (!function_exists('imagecreatefromgif')) { |
2126 | - $this->Error('GD has no GIF read support'); |
|
2127 | - } |
|
2128 | - $im = imagecreatefromgif($file); |
|
2129 | - if ($im === false) { |
|
2130 | - $this->Error('Missing or incorrect image file: ' . $file); |
|
2131 | - } |
|
2132 | - imageinterlace($im, 0); |
|
2133 | - ob_start(); |
|
2134 | - imagepng($im); |
|
2135 | - $data = ob_get_clean(); |
|
2136 | - imagedestroy($im); |
|
2137 | - $f = fopen('php://temp', 'rb+'); |
|
2138 | - if ($f === false) { |
|
2139 | - $this->Error('Unable to create memory stream'); |
|
2140 | - } |
|
2141 | - fwrite($f, $data); |
|
2142 | - rewind($f); |
|
2143 | - $info = $this->_parsepngstream($f, $file); |
|
2144 | - fclose($f); |
|
2145 | - return $info; |
|
2126 | + $this->Error('GD has no GIF read support'); |
|
2127 | + } |
|
2128 | + $im = imagecreatefromgif($file); |
|
2129 | + if ($im === false) { |
|
2130 | + $this->Error('Missing or incorrect image file: ' . $file); |
|
2131 | + } |
|
2132 | + imageinterlace($im, 0); |
|
2133 | + ob_start(); |
|
2134 | + imagepng($im); |
|
2135 | + $data = ob_get_clean(); |
|
2136 | + imagedestroy($im); |
|
2137 | + $f = fopen('php://temp', 'rb+'); |
|
2138 | + if ($f === false) { |
|
2139 | + $this->Error('Unable to create memory stream'); |
|
2140 | + } |
|
2141 | + fwrite($f, $data); |
|
2142 | + rewind($f); |
|
2143 | + $info = $this->_parsepngstream($f, $file); |
|
2144 | + fclose($f); |
|
2145 | + return $info; |
|
2146 | 2146 | } |
2147 | 2147 | |
2148 | 2148 | /** |
@@ -2151,15 +2151,15 @@ discard block |
||
2151 | 2151 | */ |
2152 | 2152 | protected function _out(string $s) : void |
2153 | 2153 | { |
2154 | - // Add a line to the document |
|
2155 | - if($this->state==2) |
|
2156 | - $this->pages[$this->page] .= $s."\n"; |
|
2157 | - elseif($this->state==1) |
|
2158 | - $this->_put($s); |
|
2159 | - elseif($this->state==0) |
|
2160 | - $this->Error('No page has been added yet'); |
|
2161 | - elseif($this->state==3) |
|
2162 | - $this->Error('The document is closed'); |
|
2154 | + // Add a line to the document |
|
2155 | + if($this->state==2) |
|
2156 | + $this->pages[$this->page] .= $s."\n"; |
|
2157 | + elseif($this->state==1) |
|
2158 | + $this->_put($s); |
|
2159 | + elseif($this->state==0) |
|
2160 | + $this->Error('No page has been added yet'); |
|
2161 | + elseif($this->state==3) |
|
2162 | + $this->Error('The document is closed'); |
|
2163 | 2163 | } |
2164 | 2164 | |
2165 | 2165 | /** |
@@ -2168,7 +2168,7 @@ discard block |
||
2168 | 2168 | */ |
2169 | 2169 | protected function _put(string $s) : void |
2170 | 2170 | { |
2171 | - $this->buffer .= $s."\n"; |
|
2171 | + $this->buffer .= $s."\n"; |
|
2172 | 2172 | } |
2173 | 2173 | |
2174 | 2174 | /** |
@@ -2177,7 +2177,7 @@ discard block |
||
2177 | 2177 | */ |
2178 | 2178 | protected function _getoffset() : int |
2179 | 2179 | { |
2180 | - return strlen($this->buffer); |
|
2180 | + return strlen($this->buffer); |
|
2181 | 2181 | } |
2182 | 2182 | |
2183 | 2183 | /** |
@@ -2186,11 +2186,11 @@ discard block |
||
2186 | 2186 | */ |
2187 | 2187 | protected function _newobj(?int $n=null) : void |
2188 | 2188 | { |
2189 | - // Begin a new object |
|
2190 | - if($n===null) |
|
2191 | - $n = ++$this->n; |
|
2192 | - $this->offsets[$n] = $this->_getoffset(); |
|
2193 | - $this->_put($n.' 0 obj'); |
|
2189 | + // Begin a new object |
|
2190 | + if($n===null) |
|
2191 | + $n = ++$this->n; |
|
2192 | + $this->offsets[$n] = $this->_getoffset(); |
|
2193 | + $this->_put($n.' 0 obj'); |
|
2194 | 2194 | } |
2195 | 2195 | |
2196 | 2196 | /** |
@@ -2199,9 +2199,9 @@ discard block |
||
2199 | 2199 | */ |
2200 | 2200 | protected function _putstream(string $data) : void |
2201 | 2201 | { |
2202 | - $this->_put('stream'); |
|
2203 | - $this->_put($data); |
|
2204 | - $this->_put('endstream'); |
|
2202 | + $this->_put('stream'); |
|
2203 | + $this->_put($data); |
|
2204 | + $this->_put('endstream'); |
|
2205 | 2205 | } |
2206 | 2206 | |
2207 | 2207 | /** |
@@ -2210,18 +2210,18 @@ discard block |
||
2210 | 2210 | */ |
2211 | 2211 | protected function _putstreamobject(string $data) : void |
2212 | 2212 | { |
2213 | - if($this->compress) |
|
2214 | - { |
|
2215 | - $entries = '/Filter /FlateDecode '; |
|
2216 | - $data = gzcompress($data); |
|
2217 | - } |
|
2218 | - else |
|
2219 | - $entries = ''; |
|
2220 | - $entries .= '/Length '.strlen($data); |
|
2221 | - $this->_newobj(); |
|
2222 | - $this->_put('<<'.$entries.'>>'); |
|
2223 | - $this->_putstream($data); |
|
2224 | - $this->_put('endobj'); |
|
2213 | + if($this->compress) |
|
2214 | + { |
|
2215 | + $entries = '/Filter /FlateDecode '; |
|
2216 | + $data = gzcompress($data); |
|
2217 | + } |
|
2218 | + else |
|
2219 | + $entries = ''; |
|
2220 | + $entries .= '/Length '.strlen($data); |
|
2221 | + $this->_newobj(); |
|
2222 | + $this->_put('<<'.$entries.'>>'); |
|
2223 | + $this->_putstream($data); |
|
2224 | + $this->_put('endobj'); |
|
2225 | 2225 | } |
2226 | 2226 | |
2227 | 2227 | /** |
@@ -2230,44 +2230,44 @@ discard block |
||
2230 | 2230 | */ |
2231 | 2231 | protected function _putpage(int $n) : void |
2232 | 2232 | { |
2233 | - $this->_newobj(); |
|
2234 | - $this->_put('<</Type /Page'); |
|
2235 | - $this->_put('/Parent 1 0 R'); |
|
2236 | - if(isset($this->PageInfo[$n]['size'])) |
|
2237 | - $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo[$n]['size'][0],$this->PageInfo[$n]['size'][1])); |
|
2238 | - if(isset($this->PageInfo[$n]['rotation'])) |
|
2239 | - $this->_put('/Rotate '.$this->PageInfo[$n]['rotation']); |
|
2240 | - $this->_put('/Resources 2 0 R'); |
|
2241 | - if(isset($this->PageLinks[$n])) |
|
2242 | - { |
|
2243 | - // Links |
|
2244 | - $annots = '/Annots ['; |
|
2245 | - foreach($this->PageLinks[$n] as $pl) |
|
2246 | - { |
|
2247 | - $rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); |
|
2248 | - $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
|
2249 | - if(is_string($pl[4])) |
|
2250 | - $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
|
2251 | - else |
|
2252 | - { |
|
2253 | - $l = $this->links[$pl[4]]; |
|
2254 | - if(isset($this->PageInfo[$l[0]]['size'])) |
|
2255 | - $h = $this->PageInfo[$l[0]]['size'][1]; |
|
2256 | - else |
|
2257 | - $h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k; |
|
2258 | - $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[$l[0]]['n'],$h-$l[1]*$this->k); |
|
2259 | - } |
|
2260 | - } |
|
2261 | - $this->_put($annots.']'); |
|
2262 | - } |
|
2263 | - if($this->WithAlpha) |
|
2264 | - $this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>'); |
|
2265 | - $this->_put('/Contents '.($this->n+1).' 0 R>>'); |
|
2266 | - $this->_put('endobj'); |
|
2267 | - // Page content |
|
2268 | - if(!empty($this->AliasNbPages)) |
|
2269 | - $this->pages[$n] = str_replace($this->AliasNbPages, strval($this->page), $this->pages[$n]); |
|
2270 | - $this->_putstreamobject($this->pages[$n]); |
|
2233 | + $this->_newobj(); |
|
2234 | + $this->_put('<</Type /Page'); |
|
2235 | + $this->_put('/Parent 1 0 R'); |
|
2236 | + if(isset($this->PageInfo[$n]['size'])) |
|
2237 | + $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo[$n]['size'][0],$this->PageInfo[$n]['size'][1])); |
|
2238 | + if(isset($this->PageInfo[$n]['rotation'])) |
|
2239 | + $this->_put('/Rotate '.$this->PageInfo[$n]['rotation']); |
|
2240 | + $this->_put('/Resources 2 0 R'); |
|
2241 | + if(isset($this->PageLinks[$n])) |
|
2242 | + { |
|
2243 | + // Links |
|
2244 | + $annots = '/Annots ['; |
|
2245 | + foreach($this->PageLinks[$n] as $pl) |
|
2246 | + { |
|
2247 | + $rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); |
|
2248 | + $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
|
2249 | + if(is_string($pl[4])) |
|
2250 | + $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
|
2251 | + else |
|
2252 | + { |
|
2253 | + $l = $this->links[$pl[4]]; |
|
2254 | + if(isset($this->PageInfo[$l[0]]['size'])) |
|
2255 | + $h = $this->PageInfo[$l[0]]['size'][1]; |
|
2256 | + else |
|
2257 | + $h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k; |
|
2258 | + $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[$l[0]]['n'],$h-$l[1]*$this->k); |
|
2259 | + } |
|
2260 | + } |
|
2261 | + $this->_put($annots.']'); |
|
2262 | + } |
|
2263 | + if($this->WithAlpha) |
|
2264 | + $this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>'); |
|
2265 | + $this->_put('/Contents '.($this->n+1).' 0 R>>'); |
|
2266 | + $this->_put('endobj'); |
|
2267 | + // Page content |
|
2268 | + if(!empty($this->AliasNbPages)) |
|
2269 | + $this->pages[$n] = str_replace($this->AliasNbPages, strval($this->page), $this->pages[$n]); |
|
2270 | + $this->_putstreamobject($this->pages[$n]); |
|
2271 | 2271 | } |
2272 | 2272 | |
2273 | 2273 | /** |
@@ -2275,32 +2275,32 @@ discard block |
||
2275 | 2275 | */ |
2276 | 2276 | protected function _putpages() : void |
2277 | 2277 | { |
2278 | - $nb = $this->page; |
|
2279 | - for($n=1;$n<=$nb;$n++) |
|
2280 | - $this->PageInfo[$n]['n'] = $this->n+1+2*($n-1); |
|
2281 | - for($n=1;$n<=$nb;$n++) |
|
2282 | - $this->_putpage($n); |
|
2283 | - // Pages root |
|
2284 | - $this->_newobj(1); |
|
2285 | - $this->_put('<</Type /Pages'); |
|
2286 | - $kids = '/Kids ['; |
|
2287 | - for($n=1;$n<=$nb;$n++) |
|
2288 | - $kids .= $this->PageInfo[$n]['n'].' 0 R '; |
|
2289 | - $this->_put($kids.']'); |
|
2290 | - $this->_put('/Count '.$nb); |
|
2291 | - if($this->DefOrientation=='P') |
|
2292 | - { |
|
2293 | - $w = $this->DefPageSize[0]; |
|
2294 | - $h = $this->DefPageSize[1]; |
|
2295 | - } |
|
2296 | - else |
|
2297 | - { |
|
2298 | - $w = $this->DefPageSize[1]; |
|
2299 | - $h = $this->DefPageSize[0]; |
|
2300 | - } |
|
2301 | - $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$w*$this->k,$h*$this->k)); |
|
2302 | - $this->_put('>>'); |
|
2303 | - $this->_put('endobj'); |
|
2278 | + $nb = $this->page; |
|
2279 | + for($n=1;$n<=$nb;$n++) |
|
2280 | + $this->PageInfo[$n]['n'] = $this->n+1+2*($n-1); |
|
2281 | + for($n=1;$n<=$nb;$n++) |
|
2282 | + $this->_putpage($n); |
|
2283 | + // Pages root |
|
2284 | + $this->_newobj(1); |
|
2285 | + $this->_put('<</Type /Pages'); |
|
2286 | + $kids = '/Kids ['; |
|
2287 | + for($n=1;$n<=$nb;$n++) |
|
2288 | + $kids .= $this->PageInfo[$n]['n'].' 0 R '; |
|
2289 | + $this->_put($kids.']'); |
|
2290 | + $this->_put('/Count '.$nb); |
|
2291 | + if($this->DefOrientation=='P') |
|
2292 | + { |
|
2293 | + $w = $this->DefPageSize[0]; |
|
2294 | + $h = $this->DefPageSize[1]; |
|
2295 | + } |
|
2296 | + else |
|
2297 | + { |
|
2298 | + $w = $this->DefPageSize[1]; |
|
2299 | + $h = $this->DefPageSize[0]; |
|
2300 | + } |
|
2301 | + $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$w*$this->k,$h*$this->k)); |
|
2302 | + $this->_put('>>'); |
|
2303 | + $this->_put('endobj'); |
|
2304 | 2304 | } |
2305 | 2305 | |
2306 | 2306 | /** |
@@ -2308,123 +2308,123 @@ discard block |
||
2308 | 2308 | */ |
2309 | 2309 | protected function _putfonts() : void |
2310 | 2310 | { |
2311 | - foreach ($this->FontFiles as $file => $info) { |
|
2312 | - // Font file embedding |
|
2313 | - $this->_newobj(); |
|
2314 | - $this->FontFiles[$file]['n'] = $this->n; |
|
2315 | - $font = file_get_contents($this->fontpath . $file, true); |
|
2316 | - if (!$font) { |
|
2317 | - $this->Error('Font file not found: ' . $file); |
|
2318 | - } |
|
2319 | - $compressed = (substr($file, -2) == '.z'); |
|
2320 | - if (!$compressed && isset($info['length2'])) { |
|
2321 | - $font = substr($font, 6, $info['length1']) . substr($font, 6 + $info['length1'] + 6, $info['length2']); |
|
2322 | - } |
|
2323 | - $this->_put('<</Length ' . strlen($font)); |
|
2324 | - if ($compressed) { |
|
2325 | - $this->_put('/Filter /FlateDecode'); |
|
2326 | - } |
|
2327 | - $this->_put('/Length1 ' . $info['length1']); |
|
2328 | - if (isset($info['length2'])) { |
|
2329 | - $this->_put('/Length2 '.$info['length2'].' /Length3 0'); |
|
2330 | - } |
|
2331 | - $this->_put('>>'); |
|
2332 | - $this->_putstream($font); |
|
2333 | - $this->_put('endobj'); |
|
2334 | - } |
|
2335 | - foreach ($this->fonts as $k => $font) { |
|
2336 | - // Encoding |
|
2337 | - if (isset($font['diff'])) { |
|
2338 | - if (!isset($this->encodings[$font['enc']])) { |
|
2339 | - $this->_newobj(); |
|
2340 | - $this->_put('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' . $font['diff'] . ']>>'); |
|
2341 | - $this->_put('endobj'); |
|
2342 | - $this->encodings[$font['enc']] = $this->n; |
|
2343 | - } |
|
2344 | - } |
|
2345 | - // ToUnicode CMap |
|
2346 | - $cmapkey = ''; |
|
2347 | - if (isset($font['uv'])) { |
|
2348 | - if (isset($font['enc'])) { |
|
2349 | - $cmapkey = $font['enc']; |
|
2350 | - } else { |
|
2351 | - $cmapkey = $font['name']; |
|
2352 | - } |
|
2353 | - if (!isset($this->cmaps[$cmapkey])) { |
|
2354 | - $cmap = $this->_tounicodecmap($font['uv']); |
|
2355 | - $this->_putstreamobject($cmap); |
|
2356 | - $this->cmaps[$cmapkey] = $this->n; |
|
2357 | - } |
|
2358 | - } |
|
2359 | - // Font object |
|
2360 | - $this->fonts[$k]['n'] = $this->n + 1; |
|
2361 | - $type = $font['type']; |
|
2362 | - $name = $font['name']; |
|
2363 | - if ($font['subsetted']) { |
|
2364 | - $name = 'AAAAAA+' . $name; |
|
2365 | - } |
|
2366 | - if ($type=='Core') { |
|
2367 | - // Core font |
|
2368 | - $this->_newobj(); |
|
2369 | - $this->_put('<</Type /Font'); |
|
2370 | - $this->_put('/BaseFont /' . $name); |
|
2371 | - $this->_put('/Subtype /Type1'); |
|
2372 | - if ($name != 'Symbol' && $name != 'ZapfDingbats') { |
|
2373 | - $this->_put('/Encoding /WinAnsiEncoding'); |
|
2374 | - } |
|
2375 | - if (isset($font['uv'])) { |
|
2376 | - $this->_put('/ToUnicode ' . $this->cmaps[$cmapkey] . ' 0 R'); |
|
2377 | - } |
|
2378 | - $this->_put('>>'); |
|
2379 | - $this->_put('endobj'); |
|
2380 | - } elseif ($type == 'Type1' || $type == 'TrueType') { |
|
2381 | - // Additional Type1 or TrueType/OpenType font |
|
2382 | - $this->_newobj(); |
|
2383 | - $this->_put('<</Type /Font'); |
|
2384 | - $this->_put('/BaseFont /' . $name); |
|
2385 | - $this->_put('/Subtype /' . $type); |
|
2386 | - $this->_put('/FirstChar 32 /LastChar 255'); |
|
2387 | - $this->_put('/Widths ' . ($this->n + 1) . ' 0 R'); |
|
2388 | - $this->_put('/FontDescriptor ' . ($this->n + 2) . ' 0 R'); |
|
2389 | - if (isset($font['diff'])) { |
|
2390 | - $this->_put('/Encoding ' . $this->encodings[$font['enc']] . ' 0 R'); |
|
2391 | - } else { |
|
2392 | - $this->_put('/Encoding /WinAnsiEncoding'); |
|
2393 | - } |
|
2394 | - if (isset($font['uv'])) { |
|
2395 | - $this->_put('/ToUnicode ' . $this->cmaps[$cmapkey] . ' 0 R'); |
|
2396 | - } |
|
2397 | - $this->_put('>>'); |
|
2398 | - $this->_put('endobj'); |
|
2399 | - // Widths |
|
2400 | - $this->_newobj(); |
|
2401 | - $cw = &$font['cw']; |
|
2402 | - $s = '['; |
|
2403 | - for ($i = 32; $i <= 255; $i++) { |
|
2404 | - $s .= $cw[chr($i)] . ' '; |
|
2405 | - } |
|
2406 | - $this->_put($s . ']'); |
|
2407 | - $this->_put('endobj'); |
|
2408 | - // Descriptor |
|
2409 | - $this->_newobj(); |
|
2410 | - $s = '<</Type /FontDescriptor /FontName /' . $name; |
|
2411 | - foreach ($font['desc'] as $k2 => $v) { |
|
2412 | - $s .= ' /' . $k2 . ' ' . $v; |
|
2413 | - } |
|
2414 | - if (!empty($font['file'])) { |
|
2415 | - $s .= ' /FontFile' . ($type == 'Type1' ? '' : '2') . ' ' . $this->FontFiles[$font['file']]['n'] . ' 0 R'; |
|
2416 | - } |
|
2417 | - $this->_put($s . '>>'); |
|
2418 | - $this->_put('endobj'); |
|
2419 | - } else { |
|
2420 | - // Allow for additional types |
|
2421 | - $mtd = '_put' . strtolower($type); |
|
2422 | - if (!method_exists($this, $mtd)) { |
|
2423 | - $this->Error('Unsupported font type: ' . $type); |
|
2424 | - } |
|
2425 | - $this->$mtd($font); |
|
2426 | - } |
|
2427 | - } |
|
2311 | + foreach ($this->FontFiles as $file => $info) { |
|
2312 | + // Font file embedding |
|
2313 | + $this->_newobj(); |
|
2314 | + $this->FontFiles[$file]['n'] = $this->n; |
|
2315 | + $font = file_get_contents($this->fontpath . $file, true); |
|
2316 | + if (!$font) { |
|
2317 | + $this->Error('Font file not found: ' . $file); |
|
2318 | + } |
|
2319 | + $compressed = (substr($file, -2) == '.z'); |
|
2320 | + if (!$compressed && isset($info['length2'])) { |
|
2321 | + $font = substr($font, 6, $info['length1']) . substr($font, 6 + $info['length1'] + 6, $info['length2']); |
|
2322 | + } |
|
2323 | + $this->_put('<</Length ' . strlen($font)); |
|
2324 | + if ($compressed) { |
|
2325 | + $this->_put('/Filter /FlateDecode'); |
|
2326 | + } |
|
2327 | + $this->_put('/Length1 ' . $info['length1']); |
|
2328 | + if (isset($info['length2'])) { |
|
2329 | + $this->_put('/Length2 '.$info['length2'].' /Length3 0'); |
|
2330 | + } |
|
2331 | + $this->_put('>>'); |
|
2332 | + $this->_putstream($font); |
|
2333 | + $this->_put('endobj'); |
|
2334 | + } |
|
2335 | + foreach ($this->fonts as $k => $font) { |
|
2336 | + // Encoding |
|
2337 | + if (isset($font['diff'])) { |
|
2338 | + if (!isset($this->encodings[$font['enc']])) { |
|
2339 | + $this->_newobj(); |
|
2340 | + $this->_put('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' . $font['diff'] . ']>>'); |
|
2341 | + $this->_put('endobj'); |
|
2342 | + $this->encodings[$font['enc']] = $this->n; |
|
2343 | + } |
|
2344 | + } |
|
2345 | + // ToUnicode CMap |
|
2346 | + $cmapkey = ''; |
|
2347 | + if (isset($font['uv'])) { |
|
2348 | + if (isset($font['enc'])) { |
|
2349 | + $cmapkey = $font['enc']; |
|
2350 | + } else { |
|
2351 | + $cmapkey = $font['name']; |
|
2352 | + } |
|
2353 | + if (!isset($this->cmaps[$cmapkey])) { |
|
2354 | + $cmap = $this->_tounicodecmap($font['uv']); |
|
2355 | + $this->_putstreamobject($cmap); |
|
2356 | + $this->cmaps[$cmapkey] = $this->n; |
|
2357 | + } |
|
2358 | + } |
|
2359 | + // Font object |
|
2360 | + $this->fonts[$k]['n'] = $this->n + 1; |
|
2361 | + $type = $font['type']; |
|
2362 | + $name = $font['name']; |
|
2363 | + if ($font['subsetted']) { |
|
2364 | + $name = 'AAAAAA+' . $name; |
|
2365 | + } |
|
2366 | + if ($type=='Core') { |
|
2367 | + // Core font |
|
2368 | + $this->_newobj(); |
|
2369 | + $this->_put('<</Type /Font'); |
|
2370 | + $this->_put('/BaseFont /' . $name); |
|
2371 | + $this->_put('/Subtype /Type1'); |
|
2372 | + if ($name != 'Symbol' && $name != 'ZapfDingbats') { |
|
2373 | + $this->_put('/Encoding /WinAnsiEncoding'); |
|
2374 | + } |
|
2375 | + if (isset($font['uv'])) { |
|
2376 | + $this->_put('/ToUnicode ' . $this->cmaps[$cmapkey] . ' 0 R'); |
|
2377 | + } |
|
2378 | + $this->_put('>>'); |
|
2379 | + $this->_put('endobj'); |
|
2380 | + } elseif ($type == 'Type1' || $type == 'TrueType') { |
|
2381 | + // Additional Type1 or TrueType/OpenType font |
|
2382 | + $this->_newobj(); |
|
2383 | + $this->_put('<</Type /Font'); |
|
2384 | + $this->_put('/BaseFont /' . $name); |
|
2385 | + $this->_put('/Subtype /' . $type); |
|
2386 | + $this->_put('/FirstChar 32 /LastChar 255'); |
|
2387 | + $this->_put('/Widths ' . ($this->n + 1) . ' 0 R'); |
|
2388 | + $this->_put('/FontDescriptor ' . ($this->n + 2) . ' 0 R'); |
|
2389 | + if (isset($font['diff'])) { |
|
2390 | + $this->_put('/Encoding ' . $this->encodings[$font['enc']] . ' 0 R'); |
|
2391 | + } else { |
|
2392 | + $this->_put('/Encoding /WinAnsiEncoding'); |
|
2393 | + } |
|
2394 | + if (isset($font['uv'])) { |
|
2395 | + $this->_put('/ToUnicode ' . $this->cmaps[$cmapkey] . ' 0 R'); |
|
2396 | + } |
|
2397 | + $this->_put('>>'); |
|
2398 | + $this->_put('endobj'); |
|
2399 | + // Widths |
|
2400 | + $this->_newobj(); |
|
2401 | + $cw = &$font['cw']; |
|
2402 | + $s = '['; |
|
2403 | + for ($i = 32; $i <= 255; $i++) { |
|
2404 | + $s .= $cw[chr($i)] . ' '; |
|
2405 | + } |
|
2406 | + $this->_put($s . ']'); |
|
2407 | + $this->_put('endobj'); |
|
2408 | + // Descriptor |
|
2409 | + $this->_newobj(); |
|
2410 | + $s = '<</Type /FontDescriptor /FontName /' . $name; |
|
2411 | + foreach ($font['desc'] as $k2 => $v) { |
|
2412 | + $s .= ' /' . $k2 . ' ' . $v; |
|
2413 | + } |
|
2414 | + if (!empty($font['file'])) { |
|
2415 | + $s .= ' /FontFile' . ($type == 'Type1' ? '' : '2') . ' ' . $this->FontFiles[$font['file']]['n'] . ' 0 R'; |
|
2416 | + } |
|
2417 | + $this->_put($s . '>>'); |
|
2418 | + $this->_put('endobj'); |
|
2419 | + } else { |
|
2420 | + // Allow for additional types |
|
2421 | + $mtd = '_put' . strtolower($type); |
|
2422 | + if (!method_exists($this, $mtd)) { |
|
2423 | + $this->Error('Unsupported font type: ' . $type); |
|
2424 | + } |
|
2425 | + $this->$mtd($font); |
|
2426 | + } |
|
2427 | + } |
|
2428 | 2428 | } |
2429 | 2429 | |
2430 | 2430 | /** |
@@ -2433,53 +2433,53 @@ discard block |
||
2433 | 2433 | */ |
2434 | 2434 | protected function _tounicodecmap(array $uv) : string |
2435 | 2435 | { |
2436 | - $ranges = ''; |
|
2437 | - $nbr = 0; |
|
2438 | - $chars = ''; |
|
2439 | - $nbc = 0; |
|
2440 | - foreach($uv as $c=>$v) |
|
2441 | - { |
|
2442 | - if(is_array($v)) |
|
2443 | - { |
|
2444 | - $ranges .= sprintf("<%02X> <%02X> <%04X>\n",$c,$c+$v[1]-1,$v[0]); |
|
2445 | - $nbr++; |
|
2446 | - } |
|
2447 | - else |
|
2448 | - { |
|
2449 | - $chars .= sprintf("<%02X> <%04X>\n",$c,$v); |
|
2450 | - $nbc++; |
|
2451 | - } |
|
2452 | - } |
|
2453 | - $s = "/CIDInit /ProcSet findresource begin\n"; |
|
2454 | - $s .= "12 dict begin\n"; |
|
2455 | - $s .= "begincmap\n"; |
|
2456 | - $s .= "/CIDSystemInfo\n"; |
|
2457 | - $s .= "<</Registry (Adobe)\n"; |
|
2458 | - $s .= "/Ordering (UCS)\n"; |
|
2459 | - $s .= "/Supplement 0\n"; |
|
2460 | - $s .= ">> def\n"; |
|
2461 | - $s .= "/CMapName /Adobe-Identity-UCS def\n"; |
|
2462 | - $s .= "/CMapType 2 def\n"; |
|
2463 | - $s .= "1 begincodespacerange\n"; |
|
2464 | - $s .= "<00> <FF>\n"; |
|
2465 | - $s .= "endcodespacerange\n"; |
|
2466 | - if($nbr>0) |
|
2467 | - { |
|
2468 | - $s .= "$nbr beginbfrange\n"; |
|
2469 | - $s .= $ranges; |
|
2470 | - $s .= "endbfrange\n"; |
|
2471 | - } |
|
2472 | - if($nbc>0) |
|
2473 | - { |
|
2474 | - $s .= "$nbc beginbfchar\n"; |
|
2475 | - $s .= $chars; |
|
2476 | - $s .= "endbfchar\n"; |
|
2477 | - } |
|
2478 | - $s .= "endcmap\n"; |
|
2479 | - $s .= "CMapName currentdict /CMap defineresource pop\n"; |
|
2480 | - $s .= "end\n"; |
|
2481 | - $s .= "end"; |
|
2482 | - return $s; |
|
2436 | + $ranges = ''; |
|
2437 | + $nbr = 0; |
|
2438 | + $chars = ''; |
|
2439 | + $nbc = 0; |
|
2440 | + foreach($uv as $c=>$v) |
|
2441 | + { |
|
2442 | + if(is_array($v)) |
|
2443 | + { |
|
2444 | + $ranges .= sprintf("<%02X> <%02X> <%04X>\n",$c,$c+$v[1]-1,$v[0]); |
|
2445 | + $nbr++; |
|
2446 | + } |
|
2447 | + else |
|
2448 | + { |
|
2449 | + $chars .= sprintf("<%02X> <%04X>\n",$c,$v); |
|
2450 | + $nbc++; |
|
2451 | + } |
|
2452 | + } |
|
2453 | + $s = "/CIDInit /ProcSet findresource begin\n"; |
|
2454 | + $s .= "12 dict begin\n"; |
|
2455 | + $s .= "begincmap\n"; |
|
2456 | + $s .= "/CIDSystemInfo\n"; |
|
2457 | + $s .= "<</Registry (Adobe)\n"; |
|
2458 | + $s .= "/Ordering (UCS)\n"; |
|
2459 | + $s .= "/Supplement 0\n"; |
|
2460 | + $s .= ">> def\n"; |
|
2461 | + $s .= "/CMapName /Adobe-Identity-UCS def\n"; |
|
2462 | + $s .= "/CMapType 2 def\n"; |
|
2463 | + $s .= "1 begincodespacerange\n"; |
|
2464 | + $s .= "<00> <FF>\n"; |
|
2465 | + $s .= "endcodespacerange\n"; |
|
2466 | + if($nbr>0) |
|
2467 | + { |
|
2468 | + $s .= "$nbr beginbfrange\n"; |
|
2469 | + $s .= $ranges; |
|
2470 | + $s .= "endbfrange\n"; |
|
2471 | + } |
|
2472 | + if($nbc>0) |
|
2473 | + { |
|
2474 | + $s .= "$nbc beginbfchar\n"; |
|
2475 | + $s .= $chars; |
|
2476 | + $s .= "endbfchar\n"; |
|
2477 | + } |
|
2478 | + $s .= "endcmap\n"; |
|
2479 | + $s .= "CMapName currentdict /CMap defineresource pop\n"; |
|
2480 | + $s .= "end\n"; |
|
2481 | + $s .= "end"; |
|
2482 | + return $s; |
|
2483 | 2483 | } |
2484 | 2484 | |
2485 | 2485 | /** |
@@ -2487,12 +2487,12 @@ discard block |
||
2487 | 2487 | */ |
2488 | 2488 | protected function _putimages() : void |
2489 | 2489 | { |
2490 | - foreach(array_keys($this->images) as $file) |
|
2491 | - { |
|
2492 | - $this->_putimage($this->images[$file]); |
|
2493 | - unset($this->images[$file]['data']); |
|
2494 | - unset($this->images[$file]['smask']); |
|
2495 | - } |
|
2490 | + foreach(array_keys($this->images) as $file) |
|
2491 | + { |
|
2492 | + $this->_putimage($this->images[$file]); |
|
2493 | + unset($this->images[$file]['data']); |
|
2494 | + unset($this->images[$file]['smask']); |
|
2495 | + } |
|
2496 | 2496 | } |
2497 | 2497 | |
2498 | 2498 | /** |
@@ -2501,59 +2501,59 @@ discard block |
||
2501 | 2501 | */ |
2502 | 2502 | protected function _putimage(array &$info) : void |
2503 | 2503 | { |
2504 | - $this->_newobj(); |
|
2505 | - $info['n'] = $this->n; |
|
2506 | - $this->_put('<</Type /XObject'); |
|
2507 | - $this->_put('/Subtype /Image'); |
|
2508 | - $this->_put('/Width ' . $info['w']); |
|
2509 | - $this->_put('/Height ' . $info['h']); |
|
2510 | - if ($info['cs'] == 'Indexed') { |
|
2511 | - $this->_put('/ColorSpace [/Indexed /DeviceRGB ' . (strlen($info['pal']) / 3 - 1) . ' ' . ($this->n + 1) . ' 0 R]'); |
|
2512 | - } else { |
|
2513 | - $this->_put('/ColorSpace /' . $info['cs']); |
|
2514 | - if($info['cs']=='DeviceCMYK') { |
|
2515 | - $this->_put('/Decode [1 0 1 0 1 0 1 0]'); |
|
2516 | - } |
|
2517 | - } |
|
2518 | - $this->_put('/BitsPerComponent ' . $info['bpc']); |
|
2519 | - if (isset($info['f'])) { |
|
2520 | - $this->_put('/Filter /' . $info['f']); |
|
2521 | - } |
|
2522 | - if (isset($info['dp'])) { |
|
2523 | - $this->_put('/DecodeParms <<' . $info['dp'] . '>>'); |
|
2524 | - } |
|
2525 | - if (isset($info['trns']) && is_array($info['trns'])) { |
|
2526 | - $trns = ''; |
|
2527 | - $cnt = count($info['trns']); |
|
2528 | - for ($i = 0; $i < $cnt; $i++) { |
|
2529 | - $trns .= $info['trns'][$i] . ' ' . $info['trns'][$i] . ' '; |
|
2530 | - } |
|
2531 | - $this->_put('/Mask [' . $trns . ']'); |
|
2532 | - } |
|
2533 | - if (isset($info['smask'])) { |
|
2534 | - $this->_put('/SMask ' . ($this->n+1) . ' 0 R'); |
|
2535 | - } |
|
2536 | - $this->_put('/Length ' . strlen($info['data']) . '>>'); |
|
2537 | - $this->_putstream($info['data']); |
|
2538 | - $this->_put('endobj'); |
|
2539 | - // Soft mask |
|
2540 | - if (isset($info['smask'])) { |
|
2541 | - $dp = '/Predictor 15 /Colors 1 /BitsPerComponent 8 /Columns ' . $info['w']; |
|
2542 | - $smask = array( |
|
2543 | - 'w'=>$info['w'], |
|
2544 | - 'h'=>$info['h'], |
|
2545 | - 'cs'=>'DeviceGray', |
|
2546 | - 'bpc'=>8, |
|
2547 | - 'f'=>$info['f'], |
|
2548 | - 'dp'=>$dp, |
|
2549 | - 'data'=>$info['smask'] |
|
2550 | - ); |
|
2551 | - $this->_putimage($smask); |
|
2552 | - } |
|
2553 | - // Palette |
|
2554 | - if ($info['cs'] == 'Indexed') { |
|
2555 | - $this->_putstreamobject($info['pal']); |
|
2556 | - } |
|
2504 | + $this->_newobj(); |
|
2505 | + $info['n'] = $this->n; |
|
2506 | + $this->_put('<</Type /XObject'); |
|
2507 | + $this->_put('/Subtype /Image'); |
|
2508 | + $this->_put('/Width ' . $info['w']); |
|
2509 | + $this->_put('/Height ' . $info['h']); |
|
2510 | + if ($info['cs'] == 'Indexed') { |
|
2511 | + $this->_put('/ColorSpace [/Indexed /DeviceRGB ' . (strlen($info['pal']) / 3 - 1) . ' ' . ($this->n + 1) . ' 0 R]'); |
|
2512 | + } else { |
|
2513 | + $this->_put('/ColorSpace /' . $info['cs']); |
|
2514 | + if($info['cs']=='DeviceCMYK') { |
|
2515 | + $this->_put('/Decode [1 0 1 0 1 0 1 0]'); |
|
2516 | + } |
|
2517 | + } |
|
2518 | + $this->_put('/BitsPerComponent ' . $info['bpc']); |
|
2519 | + if (isset($info['f'])) { |
|
2520 | + $this->_put('/Filter /' . $info['f']); |
|
2521 | + } |
|
2522 | + if (isset($info['dp'])) { |
|
2523 | + $this->_put('/DecodeParms <<' . $info['dp'] . '>>'); |
|
2524 | + } |
|
2525 | + if (isset($info['trns']) && is_array($info['trns'])) { |
|
2526 | + $trns = ''; |
|
2527 | + $cnt = count($info['trns']); |
|
2528 | + for ($i = 0; $i < $cnt; $i++) { |
|
2529 | + $trns .= $info['trns'][$i] . ' ' . $info['trns'][$i] . ' '; |
|
2530 | + } |
|
2531 | + $this->_put('/Mask [' . $trns . ']'); |
|
2532 | + } |
|
2533 | + if (isset($info['smask'])) { |
|
2534 | + $this->_put('/SMask ' . ($this->n+1) . ' 0 R'); |
|
2535 | + } |
|
2536 | + $this->_put('/Length ' . strlen($info['data']) . '>>'); |
|
2537 | + $this->_putstream($info['data']); |
|
2538 | + $this->_put('endobj'); |
|
2539 | + // Soft mask |
|
2540 | + if (isset($info['smask'])) { |
|
2541 | + $dp = '/Predictor 15 /Colors 1 /BitsPerComponent 8 /Columns ' . $info['w']; |
|
2542 | + $smask = array( |
|
2543 | + 'w'=>$info['w'], |
|
2544 | + 'h'=>$info['h'], |
|
2545 | + 'cs'=>'DeviceGray', |
|
2546 | + 'bpc'=>8, |
|
2547 | + 'f'=>$info['f'], |
|
2548 | + 'dp'=>$dp, |
|
2549 | + 'data'=>$info['smask'] |
|
2550 | + ); |
|
2551 | + $this->_putimage($smask); |
|
2552 | + } |
|
2553 | + // Palette |
|
2554 | + if ($info['cs'] == 'Indexed') { |
|
2555 | + $this->_putstreamobject($info['pal']); |
|
2556 | + } |
|
2557 | 2557 | } |
2558 | 2558 | |
2559 | 2559 | /** |
@@ -2562,7 +2562,7 @@ discard block |
||
2562 | 2562 | protected function _putxobjectdict() : void |
2563 | 2563 | { |
2564 | 2564 | foreach ($this->images as $image) { |
2565 | - $this->_put('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R'); |
|
2565 | + $this->_put('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R'); |
|
2566 | 2566 | } |
2567 | 2567 | } |
2568 | 2568 | |
@@ -2571,15 +2571,15 @@ discard block |
||
2571 | 2571 | */ |
2572 | 2572 | protected function _putresourcedict() : void |
2573 | 2573 | { |
2574 | - $this->_put('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); |
|
2575 | - $this->_put('/Font <<'); |
|
2576 | - foreach ($this->fonts as $font) { |
|
2577 | - $this->_put('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R'); |
|
2578 | - } |
|
2579 | - $this->_put('>>'); |
|
2580 | - $this->_put('/XObject <<'); |
|
2581 | - $this->_putxobjectdict(); |
|
2582 | - $this->_put('>>'); |
|
2574 | + $this->_put('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); |
|
2575 | + $this->_put('/Font <<'); |
|
2576 | + foreach ($this->fonts as $font) { |
|
2577 | + $this->_put('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R'); |
|
2578 | + } |
|
2579 | + $this->_put('>>'); |
|
2580 | + $this->_put('/XObject <<'); |
|
2581 | + $this->_putxobjectdict(); |
|
2582 | + $this->_put('>>'); |
|
2583 | 2583 | } |
2584 | 2584 | |
2585 | 2585 | /** |
@@ -2587,14 +2587,14 @@ discard block |
||
2587 | 2587 | */ |
2588 | 2588 | protected function _putresources() : void |
2589 | 2589 | { |
2590 | - $this->_putfonts(); |
|
2591 | - $this->_putimages(); |
|
2592 | - // Resource dictionary |
|
2593 | - $this->_newobj(2); |
|
2594 | - $this->_put('<<'); |
|
2595 | - $this->_putresourcedict(); |
|
2596 | - $this->_put('>>'); |
|
2597 | - $this->_put('endobj'); |
|
2590 | + $this->_putfonts(); |
|
2591 | + $this->_putimages(); |
|
2592 | + // Resource dictionary |
|
2593 | + $this->_newobj(2); |
|
2594 | + $this->_put('<<'); |
|
2595 | + $this->_putresourcedict(); |
|
2596 | + $this->_put('>>'); |
|
2597 | + $this->_put('endobj'); |
|
2598 | 2598 | } |
2599 | 2599 | |
2600 | 2600 | /** |
@@ -2602,11 +2602,11 @@ discard block |
||
2602 | 2602 | */ |
2603 | 2603 | protected function _putinfo() : void |
2604 | 2604 | { |
2605 | - $this->metadata['Producer'] = 'FPDF '.FPDF_VERSION; |
|
2606 | - $this->metadata['CreationDate'] = 'D:' . @date('YmdHis'); |
|
2607 | - foreach ($this->metadata as $key=>$value) { |
|
2608 | - $this->_put('/' . $key . ' ' . $this->_textstring($value)); |
|
2609 | - } |
|
2605 | + $this->metadata['Producer'] = 'FPDF '.FPDF_VERSION; |
|
2606 | + $this->metadata['CreationDate'] = 'D:' . @date('YmdHis'); |
|
2607 | + foreach ($this->metadata as $key=>$value) { |
|
2608 | + $this->_put('/' . $key . ' ' . $this->_textstring($value)); |
|
2609 | + } |
|
2610 | 2610 | } |
2611 | 2611 | |
2612 | 2612 | /** |
@@ -2614,25 +2614,25 @@ discard block |
||
2614 | 2614 | */ |
2615 | 2615 | protected function _putcatalog() : void |
2616 | 2616 | { |
2617 | - $n = $this->PageInfo[1]['n']; |
|
2618 | - $this->_put('/Type /Catalog'); |
|
2619 | - $this->_put('/Pages 1 0 R'); |
|
2620 | - if($this->ZoomMode=='fullpage') { |
|
2621 | - $this->_put('/OpenAction [' . $n . ' 0 R /Fit]'); |
|
2622 | - } elseif ($this->ZoomMode=='fullwidth') { |
|
2623 | - $this->_put('/OpenAction [' . $n . ' 0 R /FitH null]'); |
|
2624 | - } elseif($this->ZoomMode=='real') { |
|
2625 | - $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null 1]'); |
|
2626 | - } elseif(!is_string($this->ZoomMode)) { |
|
2627 | - $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null ' . sprintf('%.2F', $this->ZoomMode / 100) . ']'); |
|
2628 | - } |
|
2629 | - if($this->LayoutMode=='single') { |
|
2630 | - $this->_put('/PageLayout /SinglePage'); |
|
2631 | - } elseif($this->LayoutMode=='continuous') { |
|
2632 | - $this->_put('/PageLayout /OneColumn'); |
|
2633 | - } elseif($this->LayoutMode=='two') { |
|
2634 | - $this->_put('/PageLayout /TwoColumnLeft'); |
|
2635 | - } |
|
2617 | + $n = $this->PageInfo[1]['n']; |
|
2618 | + $this->_put('/Type /Catalog'); |
|
2619 | + $this->_put('/Pages 1 0 R'); |
|
2620 | + if($this->ZoomMode=='fullpage') { |
|
2621 | + $this->_put('/OpenAction [' . $n . ' 0 R /Fit]'); |
|
2622 | + } elseif ($this->ZoomMode=='fullwidth') { |
|
2623 | + $this->_put('/OpenAction [' . $n . ' 0 R /FitH null]'); |
|
2624 | + } elseif($this->ZoomMode=='real') { |
|
2625 | + $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null 1]'); |
|
2626 | + } elseif(!is_string($this->ZoomMode)) { |
|
2627 | + $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null ' . sprintf('%.2F', $this->ZoomMode / 100) . ']'); |
|
2628 | + } |
|
2629 | + if($this->LayoutMode=='single') { |
|
2630 | + $this->_put('/PageLayout /SinglePage'); |
|
2631 | + } elseif($this->LayoutMode=='continuous') { |
|
2632 | + $this->_put('/PageLayout /OneColumn'); |
|
2633 | + } elseif($this->LayoutMode=='two') { |
|
2634 | + $this->_put('/PageLayout /TwoColumnLeft'); |
|
2635 | + } |
|
2636 | 2636 | } |
2637 | 2637 | |
2638 | 2638 | /** |
@@ -2640,7 +2640,7 @@ discard block |
||
2640 | 2640 | */ |
2641 | 2641 | protected function _putheader() : void |
2642 | 2642 | { |
2643 | - $this->_put('%PDF-' . $this->PDFVersion); |
|
2643 | + $this->_put('%PDF-' . $this->PDFVersion); |
|
2644 | 2644 | } |
2645 | 2645 | |
2646 | 2646 | /** |
@@ -2648,9 +2648,9 @@ discard block |
||
2648 | 2648 | */ |
2649 | 2649 | protected function _puttrailer() : void |
2650 | 2650 | { |
2651 | - $this->_put('/Size ' . ($this->n + 1)); |
|
2652 | - $this->_put('/Root ' . $this->n . ' 0 R'); |
|
2653 | - $this->_put('/Info ' . ($this->n - 1) . ' 0 R'); |
|
2651 | + $this->_put('/Size ' . ($this->n + 1)); |
|
2652 | + $this->_put('/Root ' . $this->n . ' 0 R'); |
|
2653 | + $this->_put('/Info ' . ($this->n - 1) . ' 0 R'); |
|
2654 | 2654 | } |
2655 | 2655 | |
2656 | 2656 | /** |
@@ -2658,37 +2658,37 @@ discard block |
||
2658 | 2658 | */ |
2659 | 2659 | protected function _enddoc() : void |
2660 | 2660 | { |
2661 | - $this->_putheader(); |
|
2662 | - $this->_putpages(); |
|
2663 | - $this->_putresources(); |
|
2664 | - // Info |
|
2665 | - $this->_newobj(); |
|
2666 | - $this->_put('<<'); |
|
2667 | - $this->_putinfo(); |
|
2668 | - $this->_put('>>'); |
|
2669 | - $this->_put('endobj'); |
|
2670 | - // Catalog |
|
2671 | - $this->_newobj(); |
|
2672 | - $this->_put('<<'); |
|
2673 | - $this->_putcatalog(); |
|
2674 | - $this->_put('>>'); |
|
2675 | - $this->_put('endobj'); |
|
2676 | - // Cross-ref |
|
2677 | - $offset = $this->_getoffset(); |
|
2678 | - $this->_put('xref'); |
|
2679 | - $this->_put('0 ' . ($this->n + 1)); |
|
2680 | - $this->_put('0000000000 65535 f '); |
|
2681 | - for ($i = 1; $i <= $this->n; $i++) { |
|
2682 | - $this->_put(sprintf('%010d 00000 n ', $this->offsets[$i])); |
|
2683 | - } |
|
2684 | - // Trailer |
|
2685 | - $this->_put('trailer'); |
|
2686 | - $this->_put('<<'); |
|
2687 | - $this->_puttrailer(); |
|
2688 | - $this->_put('>>'); |
|
2689 | - $this->_put('startxref'); |
|
2690 | - $this->_put(strval($offset)); |
|
2691 | - $this->_put('%%EOF'); |
|
2692 | - $this->state = 3; |
|
2661 | + $this->_putheader(); |
|
2662 | + $this->_putpages(); |
|
2663 | + $this->_putresources(); |
|
2664 | + // Info |
|
2665 | + $this->_newobj(); |
|
2666 | + $this->_put('<<'); |
|
2667 | + $this->_putinfo(); |
|
2668 | + $this->_put('>>'); |
|
2669 | + $this->_put('endobj'); |
|
2670 | + // Catalog |
|
2671 | + $this->_newobj(); |
|
2672 | + $this->_put('<<'); |
|
2673 | + $this->_putcatalog(); |
|
2674 | + $this->_put('>>'); |
|
2675 | + $this->_put('endobj'); |
|
2676 | + // Cross-ref |
|
2677 | + $offset = $this->_getoffset(); |
|
2678 | + $this->_put('xref'); |
|
2679 | + $this->_put('0 ' . ($this->n + 1)); |
|
2680 | + $this->_put('0000000000 65535 f '); |
|
2681 | + for ($i = 1; $i <= $this->n; $i++) { |
|
2682 | + $this->_put(sprintf('%010d 00000 n ', $this->offsets[$i])); |
|
2683 | + } |
|
2684 | + // Trailer |
|
2685 | + $this->_put('trailer'); |
|
2686 | + $this->_put('<<'); |
|
2687 | + $this->_puttrailer(); |
|
2688 | + $this->_put('>>'); |
|
2689 | + $this->_put('startxref'); |
|
2690 | + $this->_put(strval($offset)); |
|
2691 | + $this->_put('%%EOF'); |
|
2692 | + $this->state = 3; |
|
2693 | 2693 | } |
2694 | 2694 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * http://www.fpdf.org/en/doc/index.php |
25 | 25 | *******************************************************************************/ |
26 | 26 | |
27 | -define('FPDF_VERSION','1.82'); |
|
27 | +define('FPDF_VERSION', '1.82'); |
|
28 | 28 | |
29 | 29 | class FPDF |
30 | 30 | { |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * or an array containing the width and the height (expressed in the unit given by unit). <br/> |
174 | 174 | * Default value is 'A4'. |
175 | 175 | */ |
176 | - public function __construct(string $orientation='P', string $unit='mm', $size='A4') |
|
176 | + public function __construct(string $orientation = 'P', string $unit = 'mm', $size = 'A4') |
|
177 | 177 | { |
178 | 178 | // Some checks |
179 | 179 | $this->_dochecks(); |
@@ -217,53 +217,53 @@ discard block |
||
217 | 217 | // Core fonts |
218 | 218 | $this->CoreFonts = array('courier', 'helvetica', 'times', 'symbol', 'zapfdingbats'); |
219 | 219 | // Scale factor |
220 | - if($unit == 'pt') { |
|
220 | + if ($unit == 'pt') { |
|
221 | 221 | $this->k = 1; |
222 | - } elseif($unit == 'mm') { |
|
223 | - $this->k = 72/25.4; |
|
224 | - } elseif($unit == 'cm') { |
|
225 | - $this->k = 72/2.54; |
|
226 | - } elseif($unit == 'in') { |
|
222 | + } elseif ($unit == 'mm') { |
|
223 | + $this->k = 72 / 25.4; |
|
224 | + } elseif ($unit == 'cm') { |
|
225 | + $this->k = 72 / 2.54; |
|
226 | + } elseif ($unit == 'in') { |
|
227 | 227 | $this->k = 72; |
228 | 228 | } else { |
229 | 229 | $this->Error('Incorrect unit: ' . $unit); |
230 | 230 | } |
231 | 231 | // Page sizes |
232 | - $this->StdPageSizes = array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28), |
|
233 | - 'letter'=>array(612,792), 'legal'=>array(612,1008)); |
|
232 | + $this->StdPageSizes = array('a3'=>array(841.89, 1190.55), 'a4'=>array(595.28, 841.89), 'a5'=>array(420.94, 595.28), |
|
233 | + 'letter'=>array(612, 792), 'legal'=>array(612, 1008)); |
|
234 | 234 | $size = $this->_getpagesize($size); |
235 | 235 | $this->DefPageSize = $size; |
236 | 236 | $this->CurPageSize = $size; |
237 | 237 | // Page orientation |
238 | 238 | $orientation = strtolower($orientation); |
239 | - if($orientation=='p' || $orientation=='portrait') |
|
239 | + if ($orientation == 'p' || $orientation == 'portrait') |
|
240 | 240 | { |
241 | 241 | $this->DefOrientation = 'P'; |
242 | 242 | $this->w = $size[0]; |
243 | 243 | $this->h = $size[1]; |
244 | 244 | } |
245 | - elseif($orientation=='l' || $orientation=='landscape') |
|
245 | + elseif ($orientation == 'l' || $orientation == 'landscape') |
|
246 | 246 | { |
247 | 247 | $this->DefOrientation = 'L'; |
248 | 248 | $this->w = $size[1]; |
249 | 249 | $this->h = $size[0]; |
250 | 250 | } |
251 | 251 | else |
252 | - $this->Error('Incorrect orientation: '.$orientation); |
|
252 | + $this->Error('Incorrect orientation: ' . $orientation); |
|
253 | 253 | $this->CurOrientation = $this->DefOrientation; |
254 | - $this->wPt = $this->w*$this->k; |
|
255 | - $this->hPt = $this->h*$this->k; |
|
254 | + $this->wPt = $this->w * $this->k; |
|
255 | + $this->hPt = $this->h * $this->k; |
|
256 | 256 | // Page rotation |
257 | 257 | $this->CurRotation = 0; |
258 | 258 | // Page margins (1 cm) |
259 | - $margin = 28.35/$this->k; |
|
260 | - $this->setMargins($margin,$margin); |
|
259 | + $margin = 28.35 / $this->k; |
|
260 | + $this->setMargins($margin, $margin); |
|
261 | 261 | // Interior cell margin (1 mm) |
262 | - $this->cMargin = $margin/10; |
|
262 | + $this->cMargin = $margin / 10; |
|
263 | 263 | // Line width (0.2 mm) |
264 | - $this->LineWidth = .567/$this->k; |
|
264 | + $this->LineWidth = .567 / $this->k; |
|
265 | 265 | // Automatic page break |
266 | - $this->setAutoPageBreak(true,2*$margin); |
|
266 | + $this->setAutoPageBreak(true, 2 * $margin); |
|
267 | 267 | // Default display mode |
268 | 268 | $this->setDisplayMode('default'); |
269 | 269 | // Enable compression |
@@ -279,12 +279,12 @@ discard block |
||
279 | 279 | * @param float $top Top margin. |
280 | 280 | * @param float $right Right margin. Default value is the left one. |
281 | 281 | */ |
282 | - public function SetMargins(float $left, float $top, ?float $right=null) : void |
|
282 | + public function SetMargins(float $left, float $top, ?float $right = null) : void |
|
283 | 283 | { |
284 | 284 | // Set left, top and right margins |
285 | 285 | $this->lMargin = $left; |
286 | 286 | $this->tMargin = $top; |
287 | - if($right===null) |
|
287 | + if ($right === null) |
|
288 | 288 | $right = $left; |
289 | 289 | $this->rMargin = $right; |
290 | 290 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | { |
300 | 300 | // Set left margin |
301 | 301 | $this->lMargin = $margin; |
302 | - if($this->page>0 && $this->x<$margin) |
|
302 | + if ($this->page > 0 && $this->x < $margin) |
|
303 | 303 | $this->x = $margin; |
304 | 304 | } |
305 | 305 | |
@@ -333,12 +333,12 @@ discard block |
||
333 | 333 | * @param bool $auto indicating if mode should be on or off. |
334 | 334 | * @param float $margin Distance from the bottom of the page. |
335 | 335 | */ |
336 | - public function SetAutoPageBreak(bool $auto, float $margin=0) : void |
|
336 | + public function SetAutoPageBreak(bool $auto, float $margin = 0) : void |
|
337 | 337 | { |
338 | 338 | // Set auto page break mode and triggering margin |
339 | 339 | $this->AutoPageBreak = $auto; |
340 | 340 | $this->bMargin = $margin; |
341 | - $this->PageBreakTrigger = $this->h-$margin; |
|
341 | + $this->PageBreakTrigger = $this->h - $margin; |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -369,17 +369,17 @@ discard block |
||
369 | 369 | * <li> 'defaul't: uses viewer default mode </li></ul> |
370 | 370 | * Default value is default. |
371 | 371 | */ |
372 | - public function SetDisplayMode($zoom, string $layout='default') : void |
|
372 | + public function SetDisplayMode($zoom, string $layout = 'default') : void |
|
373 | 373 | { |
374 | 374 | // Set display mode in viewer |
375 | - if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) |
|
375 | + if ($zoom == 'fullpage' || $zoom == 'fullwidth' || $zoom == 'real' || $zoom == 'default' || !is_string($zoom)) |
|
376 | 376 | $this->ZoomMode = $zoom; |
377 | 377 | else |
378 | - $this->Error('Incorrect zoom display mode: '.$zoom); |
|
379 | - if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') |
|
378 | + $this->Error('Incorrect zoom display mode: ' . $zoom); |
|
379 | + if ($layout == 'single' || $layout == 'continuous' || $layout == 'two' || $layout == 'default') |
|
380 | 380 | $this->LayoutMode = $layout; |
381 | 381 | else |
382 | - $this->Error('Incorrect layout display mode: '.$layout); |
|
382 | + $this->Error('Incorrect layout display mode: ' . $layout); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | public function SetCompression(bool $compress) : void |
395 | 395 | { |
396 | 396 | // Set page compression |
397 | - if(function_exists('gzcompress')) |
|
397 | + if (function_exists('gzcompress')) |
|
398 | 398 | $this->compress = $compress; |
399 | 399 | else |
400 | 400 | $this->compress = false; |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | * @param string $title The title. |
406 | 406 | * @param bool $isUTF8 Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: false. |
407 | 407 | */ |
408 | - public function SetTitle(string $title, bool $isUTF8=false) : void |
|
408 | + public function SetTitle(string $title, bool $isUTF8 = false) : void |
|
409 | 409 | { |
410 | 410 | // Title of document |
411 | 411 | $this->metadata['Title'] = $isUTF8 ? $title : utf8_encode($title); |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | * @param string $author |
417 | 417 | * @param bool $isUTF8 Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: false. |
418 | 418 | */ |
419 | - public function SetAuthor(string $author, bool $isUTF8=false) : void |
|
419 | + public function SetAuthor(string $author, bool $isUTF8 = false) : void |
|
420 | 420 | { |
421 | 421 | // Author of document |
422 | 422 | $this->metadata['Author'] = $isUTF8 ? $author : utf8_encode($author); |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | * @param string $subject |
428 | 428 | * @param bool $isUTF8 Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: false. |
429 | 429 | */ |
430 | - public function SetSubject(string $subject, bool $isUTF8=false) : void |
|
430 | + public function SetSubject(string $subject, bool $isUTF8 = false) : void |
|
431 | 431 | { |
432 | 432 | // Subject of document |
433 | 433 | $this->metadata['Subject'] = $isUTF8 ? $subject : utf8_encode($subject); |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | * @param string $keywords |
439 | 439 | * @param bool $isUTF8 Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: false. |
440 | 440 | */ |
441 | - public function SetKeywords(string $keywords, bool $isUTF8=false) : void |
|
441 | + public function SetKeywords(string $keywords, bool $isUTF8 = false) : void |
|
442 | 442 | { |
443 | 443 | // Keywords of document |
444 | 444 | $this->metadata['Keywords'] = $isUTF8 ? $keywords : utf8_encode($keywords); |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | * @param string $creator |
450 | 450 | * @param bool $isUTF8 Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: false. |
451 | 451 | */ |
452 | - public function SetCreator(string $creator, bool $isUTF8=false) : void |
|
452 | + public function SetCreator(string $creator, bool $isUTF8 = false) : void |
|
453 | 453 | { |
454 | 454 | // Creator of document |
455 | 455 | $this->metadata['Creator'] = $isUTF8 ? $creator : utf8_encode($creator); |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | * Defines an alias for the total number of pages. It will be substituted as the document is closed. |
460 | 460 | * @param string $alias The alias. Default value: {nb}. |
461 | 461 | */ |
462 | - public function AliasNbPages(string $alias='{nb}') : void |
|
462 | + public function AliasNbPages(string $alias = '{nb}') : void |
|
463 | 463 | { |
464 | 464 | // Define an alias for total number of pages |
465 | 465 | $this->AliasNbPages = $alias; |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | public function Error(string $msg) : void |
477 | 477 | { |
478 | 478 | // Fatal error |
479 | - throw new \Exception('FPDF error: '.$msg); |
|
479 | + throw new \Exception('FPDF error: ' . $msg); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | /** |
@@ -488,9 +488,9 @@ discard block |
||
488 | 488 | public function Close() : void |
489 | 489 | { |
490 | 490 | // Terminate document |
491 | - if($this->state==3) |
|
491 | + if ($this->state == 3) |
|
492 | 492 | return; |
493 | - if($this->page==0) |
|
493 | + if ($this->page == 0) |
|
494 | 494 | $this->addPage(); |
495 | 495 | // Page footer |
496 | 496 | $this->InFooter = true; |
@@ -530,20 +530,20 @@ discard block |
||
530 | 530 | * It must be a multiple of 90; positive values mean clockwise rotation. </br> |
531 | 531 | * The default value is 0. |
532 | 532 | */ |
533 | - public function AddPage(string $orientation='', $size='', int $rotation=0) : void |
|
533 | + public function AddPage(string $orientation = '', $size = '', int $rotation = 0) : void |
|
534 | 534 | { |
535 | 535 | // Start a new page |
536 | - if($this->state==3) |
|
536 | + if ($this->state == 3) |
|
537 | 537 | $this->Error('The document is closed'); |
538 | 538 | $family = $this->FontFamily; |
539 | - $style = $this->FontStyle.($this->underline ? 'U' : ''); |
|
539 | + $style = $this->FontStyle . ($this->underline ? 'U' : ''); |
|
540 | 540 | $fontsize = $this->FontSizePt; |
541 | 541 | $lw = $this->LineWidth; |
542 | 542 | $dc = $this->DrawColor; |
543 | 543 | $fc = $this->FillColor; |
544 | 544 | $tc = $this->TextColor; |
545 | 545 | $cf = $this->ColorFlag; |
546 | - if($this->page>0) |
|
546 | + if ($this->page > 0) |
|
547 | 547 | { |
548 | 548 | // Page footer |
549 | 549 | $this->InFooter = true; |
@@ -553,21 +553,21 @@ discard block |
||
553 | 553 | $this->_endpage(); |
554 | 554 | } |
555 | 555 | // Start new page |
556 | - $this->_beginpage($orientation,$size,$rotation); |
|
556 | + $this->_beginpage($orientation, $size, $rotation); |
|
557 | 557 | // Set line cap style to square |
558 | 558 | $this->_out('2 J'); |
559 | 559 | // Set line width |
560 | 560 | $this->LineWidth = $lw; |
561 | - $this->_out(sprintf('%.2F w',$lw*$this->k)); |
|
561 | + $this->_out(sprintf('%.2F w', $lw * $this->k)); |
|
562 | 562 | // Set font |
563 | - if($family) |
|
564 | - $this->setFont($family,$style,$fontsize); |
|
563 | + if ($family) |
|
564 | + $this->setFont($family, $style, $fontsize); |
|
565 | 565 | // Set colors |
566 | 566 | $this->DrawColor = $dc; |
567 | - if($dc!='0 G') |
|
567 | + if ($dc != '0 G') |
|
568 | 568 | $this->_out($dc); |
569 | 569 | $this->FillColor = $fc; |
570 | - if($fc!='0 g') |
|
570 | + if ($fc != '0 g') |
|
571 | 571 | $this->_out($fc); |
572 | 572 | $this->TextColor = $tc; |
573 | 573 | $this->ColorFlag = $cf; |
@@ -576,21 +576,21 @@ discard block |
||
576 | 576 | $this->Header(); |
577 | 577 | $this->InHeader = false; |
578 | 578 | // Restore line width |
579 | - if($this->LineWidth!=$lw) |
|
579 | + if ($this->LineWidth != $lw) |
|
580 | 580 | { |
581 | 581 | $this->LineWidth = $lw; |
582 | - $this->_out(sprintf('%.2F w',$lw*$this->k)); |
|
582 | + $this->_out(sprintf('%.2F w', $lw * $this->k)); |
|
583 | 583 | } |
584 | 584 | // Restore font |
585 | - if($family) |
|
586 | - $this->setFont($family,$style,$fontsize); |
|
585 | + if ($family) |
|
586 | + $this->setFont($family, $style, $fontsize); |
|
587 | 587 | // Restore colors |
588 | - if($this->DrawColor!=$dc) |
|
588 | + if ($this->DrawColor != $dc) |
|
589 | 589 | { |
590 | 590 | $this->DrawColor = $dc; |
591 | 591 | $this->_out($dc); |
592 | 592 | } |
593 | - if($this->FillColor!=$fc) |
|
593 | + if ($this->FillColor != $fc) |
|
594 | 594 | { |
595 | 595 | $this->FillColor = $fc; |
596 | 596 | $this->_out($fc); |
@@ -639,7 +639,7 @@ discard block |
||
639 | 639 | * @param int $g Green component (between 0 and 255). |
640 | 640 | * @param int $b Blue component (between 0 and 255). |
641 | 641 | */ |
642 | - public function SetDrawColor(int $r, ?int $g=null, ?int $b=null) : void |
|
642 | + public function SetDrawColor(int $r, ?int $g = null, ?int $b = null) : void |
|
643 | 643 | { |
644 | 644 | // Set color for all stroking operations |
645 | 645 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) { |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | * @param int $g Green component (between 0 and 255). |
661 | 661 | * @param int $b Blue component (between 0 and 255). |
662 | 662 | */ |
663 | - public function SetFillColor(int $r, ?int $g=null, ?int $b=null) : void |
|
663 | + public function SetFillColor(int $r, ?int $g = null, ?int $b = null) : void |
|
664 | 664 | { |
665 | 665 | // Set color for all filling operations |
666 | 666 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) { |
@@ -682,7 +682,7 @@ discard block |
||
682 | 682 | * @param int $g Green component (between 0 and 255). |
683 | 683 | * @param int $b Blue component (between 0 and 255). |
684 | 684 | */ |
685 | - public function SetTextColor(int $r, ?int $g=null, ?int $b=null) : void |
|
685 | + public function SetTextColor(int $r, ?int $g = null, ?int $b = null) : void |
|
686 | 686 | { |
687 | 687 | // Set color for text |
688 | 688 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) { |
@@ -702,13 +702,13 @@ discard block |
||
702 | 702 | public function GetStringWidth(string $s) : float |
703 | 703 | { |
704 | 704 | // Get width of a string in the current font |
705 | - $s = (string)$s; |
|
705 | + $s = (string) $s; |
|
706 | 706 | $cw = &$this->CurrentFont['cw']; |
707 | 707 | $w = 0; |
708 | 708 | $l = strlen($s); |
709 | - for($i=0;$i<$l;$i++) |
|
709 | + for ($i = 0; $i < $l; $i++) |
|
710 | 710 | $w += $cw[$s[$i]]; |
711 | - return $w*$this->FontSize/1000; |
|
711 | + return $w * $this->FontSize / 1000; |
|
712 | 712 | } |
713 | 713 | |
714 | 714 | /** |
@@ -721,8 +721,8 @@ discard block |
||
721 | 721 | { |
722 | 722 | // Set line width |
723 | 723 | $this->LineWidth = $width; |
724 | - if($this->page>0) |
|
725 | - $this->_out(sprintf('%.2F w',$width*$this->k)); |
|
724 | + if ($this->page > 0) |
|
725 | + $this->_out(sprintf('%.2F w', $width * $this->k)); |
|
726 | 726 | } |
727 | 727 | |
728 | 728 | /** |
@@ -737,7 +737,7 @@ discard block |
||
737 | 737 | public function Line(float $x1, float $y1, float $x2, float $y2) : void |
738 | 738 | { |
739 | 739 | // Draw a line |
740 | - $this->_out(sprintf('%.2F %.2F m %.2F %.2F l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k)); |
|
740 | + $this->_out(sprintf('%.2F %.2F m %.2F %.2F l S', $x1 * $this->k, ($this->h - $y1) * $this->k, $x2 * $this->k, ($this->h - $y2) * $this->k)); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -755,16 +755,16 @@ discard block |
||
755 | 755 | * <li> 'F': fill. </li> |
756 | 756 | * <li> 'DF' or 'FD': draw the shape and fill. </li></ul> |
757 | 757 | */ |
758 | - public function Rect(float $x, float $y, float $w, float $h, string $style='') : void |
|
758 | + public function Rect(float $x, float $y, float $w, float $h, string $style = '') : void |
|
759 | 759 | { |
760 | 760 | // Draw a rectangle |
761 | - if($style=='F') |
|
761 | + if ($style == 'F') |
|
762 | 762 | $op = 'f'; |
763 | - elseif($style=='FD' || $style=='DF') |
|
763 | + elseif ($style == 'FD' || $style == 'DF') |
|
764 | 764 | $op = 'B'; |
765 | 765 | else |
766 | 766 | $op = 'S'; |
767 | - $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); |
|
767 | + $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, -$h * $this->k, $op)); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | /** |
@@ -784,24 +784,24 @@ discard block |
||
784 | 784 | * @param string $file The font definition file. <br/> |
785 | 785 | * By default, the name is built from the family and style, in lower case with no space. |
786 | 786 | */ |
787 | - public function AddFont(string $family, string $style='', string $file='') : void |
|
787 | + public function AddFont(string $family, string $style = '', string $file = '') : void |
|
788 | 788 | { |
789 | 789 | // Add a TrueType, OpenType or Type1 font |
790 | 790 | $family = strtolower($family); |
791 | - if($file=='') |
|
792 | - $file = str_replace(' ','',$family).strtolower($style).'.php'; |
|
791 | + if ($file == '') |
|
792 | + $file = str_replace(' ', '', $family) . strtolower($style) . '.php'; |
|
793 | 793 | $style = strtoupper($style); |
794 | - if($style=='IB') |
|
794 | + if ($style == 'IB') |
|
795 | 795 | $style = 'BI'; |
796 | - $fontkey = $family.$style; |
|
797 | - if(isset($this->fonts[$fontkey])) |
|
796 | + $fontkey = $family . $style; |
|
797 | + if (isset($this->fonts[$fontkey])) |
|
798 | 798 | return; |
799 | 799 | $info = $this->_loadfont($file); |
800 | - $info['i'] = count($this->fonts)+1; |
|
801 | - if(!empty($info['file'])) |
|
800 | + $info['i'] = count($this->fonts) + 1; |
|
801 | + if (!empty($info['file'])) |
|
802 | 802 | { |
803 | 803 | // Embedded font |
804 | - if($info['type']=='TrueType') |
|
804 | + if ($info['type'] == 'TrueType') |
|
805 | 805 | $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']); |
806 | 806 | else |
807 | 807 | $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']); |
@@ -844,54 +844,54 @@ discard block |
||
844 | 844 | * The default value is the current size. <br/> |
845 | 845 | * If no size has been specified since the beginning of the document, the value taken is 12. |
846 | 846 | */ |
847 | - public function SetFont(string $family, string $style='', float $size=0) : void |
|
847 | + public function SetFont(string $family, string $style = '', float $size = 0) : void |
|
848 | 848 | { |
849 | 849 | // Select a font; size given in points |
850 | - if($family=='') |
|
850 | + if ($family == '') |
|
851 | 851 | $family = $this->FontFamily; |
852 | 852 | else |
853 | 853 | $family = strtolower($family); |
854 | 854 | $style = strtoupper($style); |
855 | - if(strpos($style,'U')!==false) |
|
855 | + if (strpos($style, 'U') !== false) |
|
856 | 856 | { |
857 | 857 | $this->underline = true; |
858 | - $style = str_replace('U','',$style); |
|
858 | + $style = str_replace('U', '', $style); |
|
859 | 859 | } |
860 | 860 | else |
861 | 861 | $this->underline = false; |
862 | - if($style=='IB') |
|
862 | + if ($style == 'IB') |
|
863 | 863 | $style = 'BI'; |
864 | - if($size==0) |
|
864 | + if ($size == 0) |
|
865 | 865 | $size = $this->FontSizePt; |
866 | 866 | // Test if font is already selected |
867 | - if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) |
|
867 | + if ($this->FontFamily == $family && $this->FontStyle == $style && $this->FontSizePt == $size) |
|
868 | 868 | return; |
869 | 869 | // Test if font is already loaded |
870 | - $fontkey = $family.$style; |
|
871 | - if(!isset($this->fonts[$fontkey])) |
|
870 | + $fontkey = $family . $style; |
|
871 | + if (!isset($this->fonts[$fontkey])) |
|
872 | 872 | { |
873 | 873 | // Test if one of the core fonts |
874 | - if($family=='arial') |
|
874 | + if ($family == 'arial') |
|
875 | 875 | $family = 'helvetica'; |
876 | - if(in_array($family,$this->CoreFonts)) |
|
876 | + if (in_array($family, $this->CoreFonts)) |
|
877 | 877 | { |
878 | - if($family=='symbol' || $family=='zapfdingbats') |
|
878 | + if ($family == 'symbol' || $family == 'zapfdingbats') |
|
879 | 879 | $style = ''; |
880 | - $fontkey = $family.$style; |
|
881 | - if(!isset($this->fonts[$fontkey])) |
|
882 | - $this->addFont($family,$style); |
|
880 | + $fontkey = $family . $style; |
|
881 | + if (!isset($this->fonts[$fontkey])) |
|
882 | + $this->addFont($family, $style); |
|
883 | 883 | } |
884 | 884 | else |
885 | - $this->Error('Undefined font: '.$family.' '.$style); |
|
885 | + $this->Error('Undefined font: ' . $family . ' ' . $style); |
|
886 | 886 | } |
887 | 887 | // Select it |
888 | 888 | $this->FontFamily = $family; |
889 | 889 | $this->FontStyle = $style; |
890 | 890 | $this->FontSizePt = $size; |
891 | - $this->FontSize = $size/$this->k; |
|
891 | + $this->FontSize = $size / $this->k; |
|
892 | 892 | $this->CurrentFont = &$this->fonts[$fontkey]; |
893 | - if($this->page>0) |
|
894 | - $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); |
|
893 | + if ($this->page > 0) |
|
894 | + $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | /** |
@@ -901,12 +901,12 @@ discard block |
||
901 | 901 | public function SetFontSize(float $size) : void |
902 | 902 | { |
903 | 903 | // Set font size in points |
904 | - if($this->FontSizePt==$size) |
|
904 | + if ($this->FontSizePt == $size) |
|
905 | 905 | return; |
906 | 906 | $this->FontSizePt = $size; |
907 | - $this->FontSize = $size/$this->k; |
|
908 | - if($this->page>0) |
|
909 | - $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); |
|
907 | + $this->FontSize = $size / $this->k; |
|
908 | + if ($this->page > 0) |
|
909 | + $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); |
|
910 | 910 | } |
911 | 911 | |
912 | 912 | /** |
@@ -919,7 +919,7 @@ discard block |
||
919 | 919 | public function AddLink() : int |
920 | 920 | { |
921 | 921 | // Create a new internal link |
922 | - $n = count($this->links)+1; |
|
922 | + $n = count($this->links) + 1; |
|
923 | 923 | $this->links[$n] = array(0, 0); |
924 | 924 | return $n; |
925 | 925 | } |
@@ -930,12 +930,12 @@ discard block |
||
930 | 930 | * @param float $y Y-position of target position; -1 indicates the current position. The default value is 0 (top of page). |
931 | 931 | * @param int $page Number of target page; -1 indicates the current page. This is the default value. |
932 | 932 | */ |
933 | - public function SetLink(int $link, float $y=0, int $page=-1) : void |
|
933 | + public function SetLink(int $link, float $y = 0, int $page = -1) : void |
|
934 | 934 | { |
935 | 935 | // Set destination of internal link |
936 | - if($y==-1) |
|
936 | + if ($y == -1) |
|
937 | 937 | $y = $this->y; |
938 | - if($page==-1) |
|
938 | + if ($page == -1) |
|
939 | 939 | $page = $this->page; |
940 | 940 | $this->links[$link] = array($page, $y); |
941 | 941 | } |
@@ -954,7 +954,7 @@ discard block |
||
954 | 954 | public function Link(float $x, float $y, float $w, float $h, $link) : void |
955 | 955 | { |
956 | 956 | // Put a link on the page |
957 | - $this->PageLinks[$this->page][] = array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link); |
|
957 | + $this->PageLinks[$this->page][] = array($x * $this->k, $this->hPt - $y * $this->k, $w * $this->k, $h * $this->k, $link); |
|
958 | 958 | } |
959 | 959 | |
960 | 960 | /** |
@@ -970,13 +970,13 @@ discard block |
||
970 | 970 | public function Text(float $x, float $y, string $txt) : void |
971 | 971 | { |
972 | 972 | // Output a string |
973 | - if(!isset($this->CurrentFont)) |
|
973 | + if (!isset($this->CurrentFont)) |
|
974 | 974 | $this->Error('No font has been set'); |
975 | - $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); |
|
976 | - if($this->underline && $txt!='') |
|
977 | - $s .= ' '.$this->_dounderline($x,$y,$txt); |
|
978 | - if($this->ColorFlag) |
|
979 | - $s = 'q '.$this->TextColor.' '.$s.' Q'; |
|
975 | + $s = sprintf('BT %.2F %.2F Td (%s) Tj ET', $x * $this->k, ($this->h - $y) * $this->k, $this->_escape($txt)); |
|
976 | + if ($this->underline && $txt != '') |
|
977 | + $s .= ' ' . $this->_dounderline($x, $y, $txt); |
|
978 | + if ($this->ColorFlag) |
|
979 | + $s = 'q ' . $this->TextColor . ' ' . $s . ' Q'; |
|
980 | 980 | $this->_out($s); |
981 | 981 | } |
982 | 982 | |
@@ -1034,80 +1034,80 @@ discard block |
||
1034 | 1034 | * Default value: false. <br/> |
1035 | 1035 | * @param string|int $link URL or identifier for internal link created by AddLink(). |
1036 | 1036 | */ |
1037 | - public function Cell(float $w, float $h=0, string $txt='', $border=0, float $ln=0, $align='', $fill=false, $link='') : void |
|
1037 | + public function Cell(float $w, float $h = 0, string $txt = '', $border = 0, float $ln = 0, $align = '', $fill = false, $link = '') : void |
|
1038 | 1038 | { |
1039 | 1039 | // Output a cell |
1040 | 1040 | $k = $this->k; |
1041 | - if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
1041 | + if ($this->y + $h > $this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
1042 | 1042 | { |
1043 | 1043 | // Automatic page break |
1044 | 1044 | $x = $this->x; |
1045 | 1045 | $ws = $this->ws; |
1046 | - if($ws>0) |
|
1046 | + if ($ws > 0) |
|
1047 | 1047 | { |
1048 | 1048 | $this->ws = 0; |
1049 | 1049 | $this->_out('0 Tw'); |
1050 | 1050 | } |
1051 | - $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
1051 | + $this->addPage($this->CurOrientation, $this->CurPageSize, $this->CurRotation); |
|
1052 | 1052 | $this->x = $x; |
1053 | - if($ws>0) |
|
1053 | + if ($ws > 0) |
|
1054 | 1054 | { |
1055 | 1055 | $this->ws = $ws; |
1056 | - $this->_out(sprintf('%.3F Tw',$ws*$k)); |
|
1056 | + $this->_out(sprintf('%.3F Tw', $ws * $k)); |
|
1057 | 1057 | } |
1058 | 1058 | } |
1059 | - if($w==0) |
|
1060 | - $w = $this->w-$this->rMargin-$this->x; |
|
1059 | + if ($w == 0) |
|
1060 | + $w = $this->w - $this->rMargin - $this->x; |
|
1061 | 1061 | $s = ''; |
1062 | - if($fill || $border==1) |
|
1062 | + if ($fill || $border == 1) |
|
1063 | 1063 | { |
1064 | - if($fill) |
|
1065 | - $op = ($border==1) ? 'B' : 'f'; |
|
1064 | + if ($fill) |
|
1065 | + $op = ($border == 1) ? 'B' : 'f'; |
|
1066 | 1066 | else |
1067 | 1067 | $op = 'S'; |
1068 | - $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); |
|
1068 | + $s = sprintf('%.2F %.2F %.2F %.2F re %s ', $this->x * $k, ($this->h - $this->y) * $k, $w * $k, -$h * $k, $op); |
|
1069 | 1069 | } |
1070 | - if(is_string($border)) |
|
1070 | + if (is_string($border)) |
|
1071 | 1071 | { |
1072 | 1072 | $x = $this->x; |
1073 | 1073 | $y = $this->y; |
1074 | - if(strpos($border,'L')!==false) |
|
1075 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); |
|
1076 | - if(strpos($border,'T')!==false) |
|
1077 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); |
|
1078 | - if(strpos($border,'R')!==false) |
|
1079 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); |
|
1080 | - if(strpos($border,'B')!==false) |
|
1081 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); |
|
1082 | - } |
|
1083 | - if($txt!=='') |
|
1074 | + if (strpos($border, 'L') !== false) |
|
1075 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - $y) * $k, $x * $k, ($this->h - ($y + $h)) * $k); |
|
1076 | + if (strpos($border, 'T') !== false) |
|
1077 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - $y) * $k, ($x + $w) * $k, ($this->h - $y) * $k); |
|
1078 | + if (strpos($border, 'R') !== false) |
|
1079 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', ($x + $w) * $k, ($this->h - $y) * $k, ($x + $w) * $k, ($this->h - ($y + $h)) * $k); |
|
1080 | + if (strpos($border, 'B') !== false) |
|
1081 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - ($y + $h)) * $k, ($x + $w) * $k, ($this->h - ($y + $h)) * $k); |
|
1082 | + } |
|
1083 | + if ($txt !== '') |
|
1084 | 1084 | { |
1085 | - if(!isset($this->CurrentFont)) |
|
1085 | + if (!isset($this->CurrentFont)) |
|
1086 | 1086 | $this->Error('No font has been set'); |
1087 | - if($align=='R') |
|
1088 | - $dx = $w-$this->cMargin-$this->getStringWidth($txt); |
|
1089 | - elseif($align=='C') |
|
1090 | - $dx = ($w-$this->getStringWidth($txt))/2; |
|
1087 | + if ($align == 'R') |
|
1088 | + $dx = $w - $this->cMargin - $this->getStringWidth($txt); |
|
1089 | + elseif ($align == 'C') |
|
1090 | + $dx = ($w - $this->getStringWidth($txt)) / 2; |
|
1091 | 1091 | else |
1092 | 1092 | $dx = $this->cMargin; |
1093 | - if($this->ColorFlag) |
|
1094 | - $s .= 'q '.$this->TextColor.' '; |
|
1095 | - $s .= sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$this->_escape($txt)); |
|
1096 | - if($this->underline) |
|
1097 | - $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); |
|
1098 | - if($this->ColorFlag) |
|
1093 | + if ($this->ColorFlag) |
|
1094 | + $s .= 'q ' . $this->TextColor . ' '; |
|
1095 | + $s .= sprintf('BT %.2F %.2F Td (%s) Tj ET', ($this->x + $dx) * $k, ($this->h - ($this->y + .5 * $h + .3 * $this->FontSize)) * $k, $this->_escape($txt)); |
|
1096 | + if ($this->underline) |
|
1097 | + $s .= ' ' . $this->_dounderline($this->x + $dx, $this->y + .5 * $h + .3 * $this->FontSize, $txt); |
|
1098 | + if ($this->ColorFlag) |
|
1099 | 1099 | $s .= ' Q'; |
1100 | - if($link) |
|
1101 | - $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->getStringWidth($txt),$this->FontSize,$link); |
|
1100 | + if ($link) |
|
1101 | + $this->Link($this->x + $dx, $this->y + .5 * $h - .5 * $this->FontSize, $this->getStringWidth($txt), $this->FontSize, $link); |
|
1102 | 1102 | } |
1103 | - if($s) |
|
1103 | + if ($s) |
|
1104 | 1104 | $this->_out($s); |
1105 | 1105 | $this->lasth = $h; |
1106 | - if($ln>0) |
|
1106 | + if ($ln > 0) |
|
1107 | 1107 | { |
1108 | 1108 | // Go to next line |
1109 | 1109 | $this->y += $h; |
1110 | - if($ln==1) |
|
1110 | + if ($ln == 1) |
|
1111 | 1111 | $this->x = $this->lMargin; |
1112 | 1112 | } |
1113 | 1113 | else |
@@ -1142,24 +1142,24 @@ discard block |
||
1142 | 1142 | * If set to true, current FillColor is used for the background. <br/> |
1143 | 1143 | * Default value: false. |
1144 | 1144 | */ |
1145 | - public function MultiCell(float $w, float $h, string $txt, $border=0, string $align='J', bool $fill=false) : void |
|
1145 | + public function MultiCell(float $w, float $h, string $txt, $border = 0, string $align = 'J', bool $fill = false) : void |
|
1146 | 1146 | { |
1147 | 1147 | // Output text with automatic or explicit line breaks |
1148 | - if(!isset($this->CurrentFont)) |
|
1148 | + if (!isset($this->CurrentFont)) |
|
1149 | 1149 | $this->Error('No font has been set'); |
1150 | 1150 | $cw = &$this->CurrentFont['cw']; |
1151 | - if($w==0) |
|
1152 | - $w = $this->w-$this->rMargin-$this->x; |
|
1153 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1154 | - $s = str_replace("\r",'',$txt); |
|
1151 | + if ($w == 0) |
|
1152 | + $w = $this->w - $this->rMargin - $this->x; |
|
1153 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
1154 | + $s = str_replace("\r", '', $txt); |
|
1155 | 1155 | $nb = strlen($s); |
1156 | - if($nb>0 && $s[$nb-1]=="\n") |
|
1156 | + if ($nb > 0 && $s[$nb - 1] == "\n") |
|
1157 | 1157 | $nb--; |
1158 | 1158 | $b = 0; |
1159 | 1159 | $b2 = ''; |
1160 | - if($border) |
|
1160 | + if ($border) |
|
1161 | 1161 | { |
1162 | - if($border==1) |
|
1162 | + if ($border == 1) |
|
1163 | 1163 | { |
1164 | 1164 | $border = 'LTRB'; |
1165 | 1165 | $b = 'LRT'; |
@@ -1168,11 +1168,11 @@ discard block |
||
1168 | 1168 | else |
1169 | 1169 | { |
1170 | 1170 | $b2 = ''; |
1171 | - if(strpos($border,'L')!==false) |
|
1171 | + if (strpos($border, 'L') !== false) |
|
1172 | 1172 | $b2 .= 'L'; |
1173 | - if(strpos($border,'R')!==false) |
|
1173 | + if (strpos($border, 'R') !== false) |
|
1174 | 1174 | $b2 .= 'R'; |
1175 | - $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; |
|
1175 | + $b = (strpos($border, 'T') !== false) ? $b2 . 'T' : $b2; |
|
1176 | 1176 | } |
1177 | 1177 | } |
1178 | 1178 | $sep = -1; |
@@ -1182,80 +1182,80 @@ discard block |
||
1182 | 1182 | $ns = 0; |
1183 | 1183 | $nl = 1; |
1184 | 1184 | $ls = 0; |
1185 | - while($i<$nb) |
|
1185 | + while ($i < $nb) |
|
1186 | 1186 | { |
1187 | 1187 | // Get next character |
1188 | 1188 | $c = $s[$i]; |
1189 | - if($c=="\n") |
|
1189 | + if ($c == "\n") |
|
1190 | 1190 | { |
1191 | 1191 | // Explicit line break |
1192 | - if($this->ws>0) |
|
1192 | + if ($this->ws > 0) |
|
1193 | 1193 | { |
1194 | 1194 | $this->ws = 0; |
1195 | 1195 | $this->_out('0 Tw'); |
1196 | 1196 | } |
1197 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
1197 | + $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); |
|
1198 | 1198 | $i++; |
1199 | 1199 | $sep = -1; |
1200 | 1200 | $j = $i; |
1201 | 1201 | $l = 0; |
1202 | 1202 | $ns = 0; |
1203 | 1203 | $nl++; |
1204 | - if($border && $nl==2) |
|
1204 | + if ($border && $nl == 2) |
|
1205 | 1205 | $b = $b2; |
1206 | 1206 | continue; |
1207 | 1207 | } |
1208 | - if($c==' ') |
|
1208 | + if ($c == ' ') |
|
1209 | 1209 | { |
1210 | 1210 | $sep = $i; |
1211 | 1211 | $ls = $l; |
1212 | 1212 | $ns++; |
1213 | 1213 | } |
1214 | 1214 | $l += $cw[$c]; |
1215 | - if($l>$wmax) |
|
1215 | + if ($l > $wmax) |
|
1216 | 1216 | { |
1217 | 1217 | // Automatic line break |
1218 | - if($sep==-1) |
|
1218 | + if ($sep == -1) |
|
1219 | 1219 | { |
1220 | - if($i==$j) |
|
1220 | + if ($i == $j) |
|
1221 | 1221 | $i++; |
1222 | - if($this->ws>0) |
|
1222 | + if ($this->ws > 0) |
|
1223 | 1223 | { |
1224 | 1224 | $this->ws = 0; |
1225 | 1225 | $this->_out('0 Tw'); |
1226 | 1226 | } |
1227 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
1227 | + $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); |
|
1228 | 1228 | } |
1229 | 1229 | else |
1230 | 1230 | { |
1231 | - if($align=='J') |
|
1231 | + if ($align == 'J') |
|
1232 | 1232 | { |
1233 | - $this->ws = ($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; |
|
1234 | - $this->_out(sprintf('%.3F Tw',$this->ws*$this->k)); |
|
1233 | + $this->ws = ($ns > 1) ? ($wmax - $ls) / 1000 * $this->FontSize / ($ns - 1) : 0; |
|
1234 | + $this->_out(sprintf('%.3F Tw', $this->ws * $this->k)); |
|
1235 | 1235 | } |
1236 | - $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); |
|
1237 | - $i = $sep+1; |
|
1236 | + $this->Cell($w, $h, substr($s, $j, $sep - $j), $b, 2, $align, $fill); |
|
1237 | + $i = $sep + 1; |
|
1238 | 1238 | } |
1239 | 1239 | $sep = -1; |
1240 | 1240 | $j = $i; |
1241 | 1241 | $l = 0; |
1242 | 1242 | $ns = 0; |
1243 | 1243 | $nl++; |
1244 | - if($border && $nl==2) |
|
1244 | + if ($border && $nl == 2) |
|
1245 | 1245 | $b = $b2; |
1246 | 1246 | } |
1247 | 1247 | else |
1248 | 1248 | $i++; |
1249 | 1249 | } |
1250 | 1250 | // Last chunk |
1251 | - if($this->ws>0) |
|
1251 | + if ($this->ws > 0) |
|
1252 | 1252 | { |
1253 | 1253 | $this->ws = 0; |
1254 | 1254 | $this->_out('0 Tw'); |
1255 | 1255 | } |
1256 | - if($border && strpos($border,'B')!==false) |
|
1256 | + if ($border && strpos($border, 'B') !== false) |
|
1257 | 1257 | $b .= 'B'; |
1258 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
1258 | + $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); |
|
1259 | 1259 | $this->x = $this->lMargin; |
1260 | 1260 | } |
1261 | 1261 | |
@@ -1269,78 +1269,78 @@ discard block |
||
1269 | 1269 | * @param string $txt String to print. |
1270 | 1270 | * @param string|int $link URL or identifier for internal link created by AddLink(). |
1271 | 1271 | */ |
1272 | - public function Write(float $h, string $txt, $link='') : void |
|
1272 | + public function Write(float $h, string $txt, $link = '') : void |
|
1273 | 1273 | { |
1274 | 1274 | // Output text in flowing mode |
1275 | - if(!isset($this->CurrentFont)) |
|
1275 | + if (!isset($this->CurrentFont)) |
|
1276 | 1276 | $this->Error('No font has been set'); |
1277 | 1277 | $cw = &$this->CurrentFont['cw']; |
1278 | - $w = $this->w-$this->rMargin-$this->x; |
|
1279 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1280 | - $s = str_replace("\r",'',$txt); |
|
1278 | + $w = $this->w - $this->rMargin - $this->x; |
|
1279 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
1280 | + $s = str_replace("\r", '', $txt); |
|
1281 | 1281 | $nb = strlen($s); |
1282 | 1282 | $sep = -1; |
1283 | 1283 | $i = 0; |
1284 | 1284 | $j = 0; |
1285 | 1285 | $l = 0; |
1286 | 1286 | $nl = 1; |
1287 | - while($i<$nb) |
|
1287 | + while ($i < $nb) |
|
1288 | 1288 | { |
1289 | 1289 | // Get next character |
1290 | 1290 | $c = $s[$i]; |
1291 | - if($c=="\n") |
|
1291 | + if ($c == "\n") |
|
1292 | 1292 | { |
1293 | 1293 | // Explicit line break |
1294 | - $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
1294 | + $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', false, $link); |
|
1295 | 1295 | $i++; |
1296 | 1296 | $sep = -1; |
1297 | 1297 | $j = $i; |
1298 | 1298 | $l = 0; |
1299 | - if($nl==1) |
|
1299 | + if ($nl == 1) |
|
1300 | 1300 | { |
1301 | 1301 | $this->x = $this->lMargin; |
1302 | - $w = $this->w-$this->rMargin-$this->x; |
|
1303 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1302 | + $w = $this->w - $this->rMargin - $this->x; |
|
1303 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
1304 | 1304 | } |
1305 | 1305 | $nl++; |
1306 | 1306 | continue; |
1307 | 1307 | } |
1308 | - if($c==' ') |
|
1308 | + if ($c == ' ') |
|
1309 | 1309 | $sep = $i; |
1310 | 1310 | $l += $cw[$c]; |
1311 | - if($l>$wmax) |
|
1311 | + if ($l > $wmax) |
|
1312 | 1312 | { |
1313 | 1313 | // Automatic line break |
1314 | - if($sep==-1) |
|
1314 | + if ($sep == -1) |
|
1315 | 1315 | { |
1316 | - if($this->x>$this->lMargin) |
|
1316 | + if ($this->x > $this->lMargin) |
|
1317 | 1317 | { |
1318 | 1318 | // Move to next line |
1319 | 1319 | $this->x = $this->lMargin; |
1320 | 1320 | $this->y += $h; |
1321 | - $w = $this->w-$this->rMargin-$this->x; |
|
1322 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1321 | + $w = $this->w - $this->rMargin - $this->x; |
|
1322 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
1323 | 1323 | $i++; |
1324 | 1324 | $nl++; |
1325 | 1325 | continue; |
1326 | 1326 | } |
1327 | - if($i==$j) |
|
1327 | + if ($i == $j) |
|
1328 | 1328 | $i++; |
1329 | - $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
1329 | + $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', false, $link); |
|
1330 | 1330 | } |
1331 | 1331 | else |
1332 | 1332 | { |
1333 | - $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link); |
|
1334 | - $i = $sep+1; |
|
1333 | + $this->Cell($w, $h, substr($s, $j, $sep - $j), 0, 2, '', false, $link); |
|
1334 | + $i = $sep + 1; |
|
1335 | 1335 | } |
1336 | 1336 | $sep = -1; |
1337 | 1337 | $j = $i; |
1338 | 1338 | $l = 0; |
1339 | - if($nl==1) |
|
1339 | + if ($nl == 1) |
|
1340 | 1340 | { |
1341 | 1341 | $this->x = $this->lMargin; |
1342 | - $w = $this->w-$this->rMargin-$this->x; |
|
1343 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
1342 | + $w = $this->w - $this->rMargin - $this->x; |
|
1343 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
1344 | 1344 | } |
1345 | 1345 | $nl++; |
1346 | 1346 | } |
@@ -1348,8 +1348,8 @@ discard block |
||
1348 | 1348 | $i++; |
1349 | 1349 | } |
1350 | 1350 | // Last chunk |
1351 | - if($i!=$j) |
|
1352 | - $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link); |
|
1351 | + if ($i != $j) |
|
1352 | + $this->Cell($l / 1000 * $this->FontSize, $h, substr($s, $j), 0, 0, '', false, $link); |
|
1353 | 1353 | } |
1354 | 1354 | |
1355 | 1355 | /** |
@@ -1359,11 +1359,11 @@ discard block |
||
1359 | 1359 | * @param float $h The height of the break. <br/> |
1360 | 1360 | * By default, the value equals the height of the last printed cell. |
1361 | 1361 | */ |
1362 | - public function Ln(float $h=null) : void |
|
1362 | + public function Ln(float $h = null) : void |
|
1363 | 1363 | { |
1364 | 1364 | // Line feed; default value is the last cell height |
1365 | 1365 | $this->x = $this->lMargin; |
1366 | - if($h===null) |
|
1366 | + if ($h === null) |
|
1367 | 1367 | $this->y += $this->lasth; |
1368 | 1368 | else |
1369 | 1369 | $this->y += $h; |
@@ -1415,69 +1415,69 @@ discard block |
||
1415 | 1415 | * If not specified, the type is inferred from the file extension. <br/> |
1416 | 1416 | * @param string|int $link URL or identifier for internal link created by AddLink(). |
1417 | 1417 | */ |
1418 | - public function Image(string $file, ?float $x=null, ?float $y=null, float $w=0, float $h=0, string $type='', $link='') : void |
|
1418 | + public function Image(string $file, ?float $x = null, ?float $y = null, float $w = 0, float $h = 0, string $type = '', $link = '') : void |
|
1419 | 1419 | { |
1420 | 1420 | // Put an image on the page |
1421 | - if($file=='') |
|
1421 | + if ($file == '') |
|
1422 | 1422 | $this->Error('Image file name is empty'); |
1423 | - if(!isset($this->images[$file])) |
|
1423 | + if (!isset($this->images[$file])) |
|
1424 | 1424 | { |
1425 | 1425 | // First use of this image, get info |
1426 | - if($type=='') |
|
1426 | + if ($type == '') |
|
1427 | 1427 | { |
1428 | - $pos = strrpos($file,'.'); |
|
1429 | - if(!$pos) |
|
1430 | - $this->Error('Image file has no extension and no type was specified: '.$file); |
|
1431 | - $type = substr($file,$pos+1); |
|
1428 | + $pos = strrpos($file, '.'); |
|
1429 | + if (!$pos) |
|
1430 | + $this->Error('Image file has no extension and no type was specified: ' . $file); |
|
1431 | + $type = substr($file, $pos + 1); |
|
1432 | 1432 | } |
1433 | 1433 | $type = strtolower($type); |
1434 | - if($type=='jpeg') |
|
1434 | + if ($type == 'jpeg') |
|
1435 | 1435 | $type = 'jpg'; |
1436 | - $mtd = '_parse'.$type; |
|
1437 | - if(!method_exists($this,$mtd)) |
|
1438 | - $this->Error('Unsupported image type: '.$type); |
|
1436 | + $mtd = '_parse' . $type; |
|
1437 | + if (!method_exists($this, $mtd)) |
|
1438 | + $this->Error('Unsupported image type: ' . $type); |
|
1439 | 1439 | $info = $this->$mtd($file); |
1440 | - $info['i'] = count($this->images)+1; |
|
1440 | + $info['i'] = count($this->images) + 1; |
|
1441 | 1441 | $this->images[$file] = $info; |
1442 | 1442 | } |
1443 | 1443 | else |
1444 | 1444 | $info = $this->images[$file]; |
1445 | 1445 | |
1446 | 1446 | // Automatic width and height calculation if needed |
1447 | - if($w==0 && $h==0) |
|
1447 | + if ($w == 0 && $h == 0) |
|
1448 | 1448 | { |
1449 | 1449 | // Put image at 96 dpi |
1450 | 1450 | $w = -96; |
1451 | 1451 | $h = -96; |
1452 | 1452 | } |
1453 | - if($w<0) |
|
1454 | - $w = -$info['w']*72/$w/$this->k; |
|
1455 | - if($h<0) |
|
1456 | - $h = -$info['h']*72/$h/$this->k; |
|
1457 | - if($w==0) |
|
1458 | - $w = $h*$info['w']/$info['h']; |
|
1459 | - if($h==0) |
|
1460 | - $h = $w*$info['h']/$info['w']; |
|
1453 | + if ($w < 0) |
|
1454 | + $w = -$info['w'] * 72 / $w / $this->k; |
|
1455 | + if ($h < 0) |
|
1456 | + $h = -$info['h'] * 72 / $h / $this->k; |
|
1457 | + if ($w == 0) |
|
1458 | + $w = $h * $info['w'] / $info['h']; |
|
1459 | + if ($h == 0) |
|
1460 | + $h = $w * $info['h'] / $info['w']; |
|
1461 | 1461 | |
1462 | 1462 | // Flowing mode |
1463 | - if($y===null) |
|
1463 | + if ($y === null) |
|
1464 | 1464 | { |
1465 | - if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
1465 | + if ($this->y + $h > $this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
1466 | 1466 | { |
1467 | 1467 | // Automatic page break |
1468 | 1468 | $x2 = $this->x; |
1469 | - $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
1469 | + $this->addPage($this->CurOrientation, $this->CurPageSize, $this->CurRotation); |
|
1470 | 1470 | $this->x = $x2; |
1471 | 1471 | } |
1472 | 1472 | $y = $this->y; |
1473 | 1473 | $this->y += $h; |
1474 | 1474 | } |
1475 | 1475 | |
1476 | - if($x===null) |
|
1476 | + if ($x === null) |
|
1477 | 1477 | $x = $this->x; |
1478 | - $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q',$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i'])); |
|
1479 | - if($link) |
|
1480 | - $this->Link($x,$y,$w,$h,$link); |
|
1478 | + $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q', $w * $this->k, $h * $this->k, $x * $this->k, ($this->h - ($y + $h)) * $this->k, $info['i'])); |
|
1479 | + if ($link) |
|
1480 | + $this->Link($x, $y, $w, $h, $link); |
|
1481 | 1481 | } |
1482 | 1482 | |
1483 | 1483 | /** |
@@ -1518,10 +1518,10 @@ discard block |
||
1518 | 1518 | public function SetX(float $x) : void |
1519 | 1519 | { |
1520 | 1520 | // Set x position |
1521 | - if($x>=0) |
|
1521 | + if ($x >= 0) |
|
1522 | 1522 | $this->x = $x; |
1523 | 1523 | else |
1524 | - $this->x = $this->w+$x; |
|
1524 | + $this->x = $this->w + $x; |
|
1525 | 1525 | } |
1526 | 1526 | |
1527 | 1527 | /** |
@@ -1540,14 +1540,14 @@ discard block |
||
1540 | 1540 | * @param float $y |
1541 | 1541 | * @param bool $resetX |
1542 | 1542 | */ |
1543 | - public function SetY(float $y, bool $resetX=true) : void |
|
1543 | + public function SetY(float $y, bool $resetX = true) : void |
|
1544 | 1544 | { |
1545 | 1545 | // Set y position and optionally reset x |
1546 | - if($y>=0) |
|
1546 | + if ($y >= 0) |
|
1547 | 1547 | $this->y = $y; |
1548 | 1548 | else |
1549 | - $this->y = $this->h+$y; |
|
1550 | - if($resetX) |
|
1549 | + $this->y = $this->h + $y; |
|
1550 | + if ($resetX) |
|
1551 | 1551 | $this->x = $this->lMargin; |
1552 | 1552 | } |
1553 | 1553 | |
@@ -1561,7 +1561,7 @@ discard block |
||
1561 | 1561 | { |
1562 | 1562 | // Set x and y positions |
1563 | 1563 | $this->setX($x); |
1564 | - $this->setY($y,false); |
|
1564 | + $this->setY($y, false); |
|
1565 | 1565 | } |
1566 | 1566 | |
1567 | 1567 | /** |
@@ -1582,31 +1582,31 @@ discard block |
||
1582 | 1582 | * The default value is false. <br/> |
1583 | 1583 | * @return string |
1584 | 1584 | */ |
1585 | - public function Output(string $dest='', string $name='', bool $isUTF8=false) : string |
|
1585 | + public function Output(string $dest = '', string $name = '', bool $isUTF8 = false) : string |
|
1586 | 1586 | { |
1587 | 1587 | // Output PDF to some destination |
1588 | 1588 | $this->Close(); |
1589 | - if(strlen($name)==1 && strlen($dest)!=1) |
|
1589 | + if (strlen($name) == 1 && strlen($dest) != 1) |
|
1590 | 1590 | { |
1591 | 1591 | // Fix parameter order |
1592 | 1592 | $tmp = $dest; |
1593 | 1593 | $dest = $name; |
1594 | 1594 | $name = $tmp; |
1595 | 1595 | } |
1596 | - if($dest=='') |
|
1596 | + if ($dest == '') |
|
1597 | 1597 | $dest = 'I'; |
1598 | - if($name=='') |
|
1598 | + if ($name == '') |
|
1599 | 1599 | $name = 'doc.pdf'; |
1600 | - switch(strtoupper($dest)) |
|
1600 | + switch (strtoupper($dest)) |
|
1601 | 1601 | { |
1602 | 1602 | case 'I': |
1603 | 1603 | // Send to standard output |
1604 | 1604 | $this->_checkoutput(); |
1605 | - if(PHP_SAPI!='cli') |
|
1605 | + if (PHP_SAPI != 'cli') |
|
1606 | 1606 | { |
1607 | 1607 | // We send to a browser |
1608 | 1608 | header('Content-Type: application/pdf; charset=UTF-8'); |
1609 | - header('Content-Disposition: inline; '.$this->_httpencode('filename',$name,$isUTF8)); |
|
1609 | + header('Content-Disposition: inline; ' . $this->_httpencode('filename', $name, $isUTF8)); |
|
1610 | 1610 | header('Cache-Control: private, max-age=0, must-revalidate'); |
1611 | 1611 | header('Pragma: public'); |
1612 | 1612 | } |
@@ -1616,21 +1616,21 @@ discard block |
||
1616 | 1616 | // Download file |
1617 | 1617 | $this->_checkoutput(); |
1618 | 1618 | header('Content-Type: application/x-download'); |
1619 | - header('Content-Disposition: attachment; '.$this->_httpencode('filename',$name,$isUTF8)); |
|
1619 | + header('Content-Disposition: attachment; ' . $this->_httpencode('filename', $name, $isUTF8)); |
|
1620 | 1620 | header('Cache-Control: private, max-age=0, must-revalidate'); |
1621 | 1621 | header('Pragma: public'); |
1622 | 1622 | echo $this->buffer; |
1623 | 1623 | break; |
1624 | 1624 | case 'F': |
1625 | 1625 | // Save to local file |
1626 | - if(!file_put_contents($name,$this->buffer)) |
|
1627 | - $this->Error('Unable to create output file: '.$name); |
|
1626 | + if (!file_put_contents($name, $this->buffer)) |
|
1627 | + $this->Error('Unable to create output file: ' . $name); |
|
1628 | 1628 | break; |
1629 | 1629 | case 'S': |
1630 | 1630 | // Return as a string |
1631 | 1631 | return $this->buffer; |
1632 | 1632 | default: |
1633 | - $this->Error('Incorrect output destination: '.$dest); |
|
1633 | + $this->Error('Incorrect output destination: ' . $dest); |
|
1634 | 1634 | } |
1635 | 1635 | return ''; |
1636 | 1636 | } |
@@ -1641,7 +1641,7 @@ discard block |
||
1641 | 1641 | protected function _dochecks() : void |
1642 | 1642 | { |
1643 | 1643 | // Check mbstring overloading |
1644 | - if(ini_get('mbstring.func_overload') & 2) |
|
1644 | + if (ini_get('mbstring.func_overload') & 2) |
|
1645 | 1645 | $this->Error('mbstring overloading must be disabled'); |
1646 | 1646 | } |
1647 | 1647 | |
@@ -1650,17 +1650,17 @@ discard block |
||
1650 | 1650 | */ |
1651 | 1651 | protected function _checkoutput() : void |
1652 | 1652 | { |
1653 | - if(PHP_SAPI!='cli') |
|
1653 | + if (PHP_SAPI != 'cli') |
|
1654 | 1654 | { |
1655 | 1655 | $file = ''; |
1656 | 1656 | $line = 0; |
1657 | - if(headers_sent($file,$line)) |
|
1657 | + if (headers_sent($file, $line)) |
|
1658 | 1658 | $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)"); |
1659 | 1659 | } |
1660 | - if(ob_get_length()) |
|
1660 | + if (ob_get_length()) |
|
1661 | 1661 | { |
1662 | 1662 | // The output buffer is not empty |
1663 | - if(preg_match('/^(\xEF\xBB\xBF)?\s*$/',ob_get_contents())) |
|
1663 | + if (preg_match('/^(\xEF\xBB\xBF)?\s*$/', ob_get_contents())) |
|
1664 | 1664 | { |
1665 | 1665 | // It contains only a UTF-8 BOM and/or whitespace, let's clean it |
1666 | 1666 | ob_clean(); |
@@ -1677,17 +1677,17 @@ discard block |
||
1677 | 1677 | */ |
1678 | 1678 | protected function _getpagesize($size) : array |
1679 | 1679 | { |
1680 | - if(is_string($size)) |
|
1680 | + if (is_string($size)) |
|
1681 | 1681 | { |
1682 | 1682 | $size = strtolower($size); |
1683 | - if(!isset($this->StdPageSizes[$size])) |
|
1684 | - $this->Error('Unknown page size: '.$size); |
|
1683 | + if (!isset($this->StdPageSizes[$size])) |
|
1684 | + $this->Error('Unknown page size: ' . $size); |
|
1685 | 1685 | $a = $this->StdPageSizes[$size]; |
1686 | - return array($a[0]/$this->k, $a[1]/$this->k); |
|
1686 | + return array($a[0] / $this->k, $a[1] / $this->k); |
|
1687 | 1687 | } |
1688 | 1688 | else |
1689 | 1689 | { |
1690 | - if($size[0]>$size[1]) |
|
1690 | + if ($size[0] > $size[1]) |
|
1691 | 1691 | return array($size[1], $size[0]); |
1692 | 1692 | else |
1693 | 1693 | return $size; |
@@ -1709,18 +1709,18 @@ discard block |
||
1709 | 1709 | $this->y = $this->tMargin; |
1710 | 1710 | $this->FontFamily = ''; |
1711 | 1711 | // Check page size and orientation |
1712 | - if($orientation=='') |
|
1712 | + if ($orientation == '') |
|
1713 | 1713 | $orientation = $this->DefOrientation; |
1714 | 1714 | else |
1715 | 1715 | $orientation = strtoupper($orientation[0]); |
1716 | - if($size=='') |
|
1716 | + if ($size == '') |
|
1717 | 1717 | $size = $this->DefPageSize; |
1718 | 1718 | else |
1719 | 1719 | $size = $this->_getpagesize($size); |
1720 | - if($orientation!=$this->CurOrientation || $size[0]!=$this->CurPageSize[0] || $size[1]!=$this->CurPageSize[1]) |
|
1720 | + if ($orientation != $this->CurOrientation || $size[0] != $this->CurPageSize[0] || $size[1] != $this->CurPageSize[1]) |
|
1721 | 1721 | { |
1722 | 1722 | // New size or orientation |
1723 | - if($orientation=='P') |
|
1723 | + if ($orientation == 'P') |
|
1724 | 1724 | { |
1725 | 1725 | $this->w = $size[0]; |
1726 | 1726 | $this->h = $size[1]; |
@@ -1730,18 +1730,18 @@ discard block |
||
1730 | 1730 | $this->w = $size[1]; |
1731 | 1731 | $this->h = $size[0]; |
1732 | 1732 | } |
1733 | - $this->wPt = $this->w*$this->k; |
|
1734 | - $this->hPt = $this->h*$this->k; |
|
1735 | - $this->PageBreakTrigger = $this->h-$this->bMargin; |
|
1733 | + $this->wPt = $this->w * $this->k; |
|
1734 | + $this->hPt = $this->h * $this->k; |
|
1735 | + $this->PageBreakTrigger = $this->h - $this->bMargin; |
|
1736 | 1736 | $this->CurOrientation = $orientation; |
1737 | 1737 | $this->CurPageSize = $size; |
1738 | 1738 | } |
1739 | - if($orientation!=$this->DefOrientation || $size[0]!=$this->DefPageSize[0] || $size[1]!=$this->DefPageSize[1]) |
|
1739 | + if ($orientation != $this->DefOrientation || $size[0] != $this->DefPageSize[0] || $size[1] != $this->DefPageSize[1]) |
|
1740 | 1740 | $this->PageInfo[$this->page]['size'] = array($this->wPt, $this->hPt); |
1741 | - if($rotation!=0) |
|
1741 | + if ($rotation != 0) |
|
1742 | 1742 | { |
1743 | - if($rotation%90!=0) |
|
1744 | - $this->Error('Incorrect rotation value: '.$rotation); |
|
1743 | + if ($rotation % 90 != 0) |
|
1744 | + $this->Error('Incorrect rotation value: ' . $rotation); |
|
1745 | 1745 | $this->CurRotation = $rotation; |
1746 | 1746 | $this->PageInfo[$this->page]['rotation'] = $rotation; |
1747 | 1747 | } |
@@ -1763,23 +1763,23 @@ discard block |
||
1763 | 1763 | protected function _loadfont(string $font) : array |
1764 | 1764 | { |
1765 | 1765 | // Load a font definition file from the font directory |
1766 | - if(strpos($font,'/')!==false || strpos($font,"\\")!==false) { |
|
1767 | - $this->Error('Incorrect font definition file name: '.$font); |
|
1766 | + if (strpos($font, '/') !== false || strpos($font, "\\") !== false) { |
|
1767 | + $this->Error('Incorrect font definition file name: ' . $font); |
|
1768 | 1768 | } |
1769 | 1769 | // following vars must be initialized in the font definition file beeing included |
1770 | 1770 | $name = null; |
1771 | 1771 | $enc = null; |
1772 | 1772 | $subsetted = null; |
1773 | - include($this->fontpath.$font); |
|
1773 | + include($this->fontpath . $font); |
|
1774 | 1774 | |
1775 | 1775 | // phpstan can't see the code dynamicly included before so assuming $name, $enc, $subsetted always set to null! |
1776 | - if(!isset($name)) { /* @phpstan-ignore-line */ |
|
1776 | + if (!isset($name)) { /* @phpstan-ignore-line */ |
|
1777 | 1777 | $this->Error('Could not include font definition file'); |
1778 | 1778 | } |
1779 | - if(isset($enc)) { /* @phpstan-ignore-line */ |
|
1779 | + if (isset($enc)) { /* @phpstan-ignore-line */ |
|
1780 | 1780 | $enc = strtolower($enc); |
1781 | 1781 | } |
1782 | - if(!isset($subsetted)) { /* @phpstan-ignore-line */ |
|
1782 | + if (!isset($subsetted)) { /* @phpstan-ignore-line */ |
|
1783 | 1783 | $subsetted = false; |
1784 | 1784 | } |
1785 | 1785 | return get_defined_vars(); |
@@ -1794,9 +1794,9 @@ discard block |
||
1794 | 1794 | { |
1795 | 1795 | // Test if string is ASCII |
1796 | 1796 | $nb = strlen($s); |
1797 | - for($i=0;$i<$nb;$i++) |
|
1797 | + for ($i = 0; $i < $nb; $i++) |
|
1798 | 1798 | { |
1799 | - if(ord($s[$i])>127) |
|
1799 | + if (ord($s[$i]) > 127) |
|
1800 | 1800 | return false; |
1801 | 1801 | } |
1802 | 1802 | return true; |
@@ -1811,14 +1811,14 @@ discard block |
||
1811 | 1811 | protected function _httpencode(string $param, string $value, bool $isUTF8) : string |
1812 | 1812 | { |
1813 | 1813 | // Encode HTTP header field parameter |
1814 | - if($this->_isascii($value)) |
|
1815 | - return $param.'="'.$value.'"'; |
|
1816 | - if(!$isUTF8) |
|
1814 | + if ($this->_isascii($value)) |
|
1815 | + return $param . '="' . $value . '"'; |
|
1816 | + if (!$isUTF8) |
|
1817 | 1817 | $value = utf8_encode($value); |
1818 | - if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==false) |
|
1819 | - return $param.'="'.rawurlencode($value).'"'; |
|
1818 | + if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) |
|
1819 | + return $param . '="' . rawurlencode($value) . '"'; |
|
1820 | 1820 | else |
1821 | - return $param."*=UTF-8''".rawurlencode($value); |
|
1821 | + return $param . "*=UTF-8''" . rawurlencode($value); |
|
1822 | 1822 | } |
1823 | 1823 | |
1824 | 1824 | /** |
@@ -1832,28 +1832,28 @@ discard block |
||
1832 | 1832 | $res = "\xFE\xFF"; |
1833 | 1833 | $nb = strlen($s); |
1834 | 1834 | $i = 0; |
1835 | - while($i<$nb) |
|
1835 | + while ($i < $nb) |
|
1836 | 1836 | { |
1837 | 1837 | $c1 = ord($s[$i++]); |
1838 | - if($c1>=224) |
|
1838 | + if ($c1 >= 224) |
|
1839 | 1839 | { |
1840 | 1840 | // 3-byte character |
1841 | 1841 | $c2 = ord($s[$i++]); |
1842 | 1842 | $c3 = ord($s[$i++]); |
1843 | - $res .= chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2)); |
|
1844 | - $res .= chr((($c2 & 0x03)<<6) + ($c3 & 0x3F)); |
|
1843 | + $res .= chr((($c1 & 0x0F) << 4) + (($c2 & 0x3C) >> 2)); |
|
1844 | + $res .= chr((($c2 & 0x03) << 6) + ($c3 & 0x3F)); |
|
1845 | 1845 | } |
1846 | - elseif($c1>=192) |
|
1846 | + elseif ($c1 >= 192) |
|
1847 | 1847 | { |
1848 | 1848 | // 2-byte character |
1849 | 1849 | $c2 = ord($s[$i++]); |
1850 | - $res .= chr(($c1 & 0x1C)>>2); |
|
1851 | - $res .= chr((($c1 & 0x03)<<6) + ($c2 & 0x3F)); |
|
1850 | + $res .= chr(($c1 & 0x1C) >> 2); |
|
1851 | + $res .= chr((($c1 & 0x03) << 6) + ($c2 & 0x3F)); |
|
1852 | 1852 | } |
1853 | 1853 | else |
1854 | 1854 | { |
1855 | 1855 | // Single-byte character |
1856 | - $res .= "\0".chr($c1); |
|
1856 | + $res .= "\0" . chr($c1); |
|
1857 | 1857 | } |
1858 | 1858 | } |
1859 | 1859 | return $res; |
@@ -1867,8 +1867,8 @@ discard block |
||
1867 | 1867 | protected function _escape(string $s) : string |
1868 | 1868 | { |
1869 | 1869 | // Escape special characters |
1870 | - if(strpos($s,'(')!==false || strpos($s,')')!==false || strpos($s,'\\')!==false || strpos($s,"\r")!==false) |
|
1871 | - return str_replace(array('\\','(',')',"\r"), array('\\\\','\\(','\\)','\\r'), $s); |
|
1870 | + if (strpos($s, '(') !== false || strpos($s, ')') !== false || strpos($s, '\\') !== false || strpos($s, "\r") !== false) |
|
1871 | + return str_replace(array('\\', '(', ')', "\r"), array('\\\\', '\\(', '\\)', '\\r'), $s); |
|
1872 | 1872 | else |
1873 | 1873 | return $s; |
1874 | 1874 | } |
@@ -1881,9 +1881,9 @@ discard block |
||
1881 | 1881 | protected function _textstring(string $s) : string |
1882 | 1882 | { |
1883 | 1883 | // Format a text string |
1884 | - if(!$this->_isascii($s)) |
|
1884 | + if (!$this->_isascii($s)) |
|
1885 | 1885 | $s = $this->_UTF8toUTF16($s); |
1886 | - return '('.$this->_escape($s).')'; |
|
1886 | + return '(' . $this->_escape($s) . ')'; |
|
1887 | 1887 | } |
1888 | 1888 | |
1889 | 1889 | /** |
@@ -1898,8 +1898,8 @@ discard block |
||
1898 | 1898 | // Underline text |
1899 | 1899 | $up = $this->CurrentFont['up']; |
1900 | 1900 | $ut = $this->CurrentFont['ut']; |
1901 | - $w = $this->getStringWidth($txt)+$this->ws*substr_count($txt,' '); |
|
1902 | - return sprintf('%.2F %.2F %.2F %.2F re f',$x*$this->k,($this->h-($y-$up/1000*$this->FontSize))*$this->k,$w*$this->k,-$ut/1000*$this->FontSizePt); |
|
1901 | + $w = $this->getStringWidth($txt) + $this->ws * substr_count($txt, ' '); |
|
1902 | + return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k, ($this->h - ($y - $up / 1000 * $this->FontSize)) * $this->k, $w * $this->k, -$ut / 1000 * $this->FontSizePt); |
|
1903 | 1903 | } |
1904 | 1904 | |
1905 | 1905 | /** |
@@ -1911,13 +1911,13 @@ discard block |
||
1911 | 1911 | { |
1912 | 1912 | // Extract info from a JPEG file |
1913 | 1913 | $a = getimagesize($file); |
1914 | - if(!$a) |
|
1915 | - $this->Error('Missing or incorrect image file: '.$file); |
|
1916 | - if($a[2]!=2) |
|
1917 | - $this->Error('Not a JPEG file: '.$file); |
|
1918 | - if(!isset($a['channels']) || $a['channels']==3) |
|
1914 | + if (!$a) |
|
1915 | + $this->Error('Missing or incorrect image file: ' . $file); |
|
1916 | + if ($a[2] != 2) |
|
1917 | + $this->Error('Not a JPEG file: ' . $file); |
|
1918 | + if (!isset($a['channels']) || $a['channels'] == 3) |
|
1919 | 1919 | $colspace = 'DeviceRGB'; |
1920 | - elseif($a['channels']==4) |
|
1920 | + elseif ($a['channels'] == 4) |
|
1921 | 1921 | $colspace = 'DeviceCMYK'; |
1922 | 1922 | else |
1923 | 1923 | $colspace = 'DeviceGray'; |
@@ -1952,36 +1952,36 @@ discard block |
||
1952 | 1952 | protected function _parsepngstream($f, string $file) : array |
1953 | 1953 | { |
1954 | 1954 | // Check signature |
1955 | - if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) |
|
1956 | - $this->Error('Not a PNG file: '.$file); |
|
1955 | + if ($this->_readstream($f, 8) != chr(137) . 'PNG' . chr(13) . chr(10) . chr(26) . chr(10)) |
|
1956 | + $this->Error('Not a PNG file: ' . $file); |
|
1957 | 1957 | |
1958 | 1958 | // Read header chunk |
1959 | - $this->_readstream($f,4); |
|
1960 | - if($this->_readstream($f,4)!='IHDR') |
|
1961 | - $this->Error('Incorrect PNG file: '.$file); |
|
1959 | + $this->_readstream($f, 4); |
|
1960 | + if ($this->_readstream($f, 4) != 'IHDR') |
|
1961 | + $this->Error('Incorrect PNG file: ' . $file); |
|
1962 | 1962 | $w = $this->_readint($f); |
1963 | 1963 | $h = $this->_readint($f); |
1964 | - $bpc = ord($this->_readstream($f,1)); |
|
1965 | - if($bpc>8) |
|
1966 | - $this->Error('16-bit depth not supported: '.$file); |
|
1967 | - $ct = ord($this->_readstream($f,1)); |
|
1964 | + $bpc = ord($this->_readstream($f, 1)); |
|
1965 | + if ($bpc > 8) |
|
1966 | + $this->Error('16-bit depth not supported: ' . $file); |
|
1967 | + $ct = ord($this->_readstream($f, 1)); |
|
1968 | 1968 | $colspace = ''; |
1969 | - if($ct==0 || $ct==4) |
|
1969 | + if ($ct == 0 || $ct == 4) |
|
1970 | 1970 | $colspace = 'DeviceGray'; |
1971 | - elseif($ct==2 || $ct==6) |
|
1971 | + elseif ($ct == 2 || $ct == 6) |
|
1972 | 1972 | $colspace = 'DeviceRGB'; |
1973 | - elseif($ct==3) |
|
1973 | + elseif ($ct == 3) |
|
1974 | 1974 | $colspace = 'Indexed'; |
1975 | 1975 | else |
1976 | - $this->Error('Unknown color type: '.$file); |
|
1977 | - if(ord($this->_readstream($f,1))!=0) |
|
1978 | - $this->Error('Unknown compression method: '.$file); |
|
1979 | - if(ord($this->_readstream($f,1))!=0) |
|
1980 | - $this->Error('Unknown filter method: '.$file); |
|
1981 | - if(ord($this->_readstream($f,1))!=0) |
|
1982 | - $this->Error('Interlacing not supported: '.$file); |
|
1983 | - $this->_readstream($f,4); |
|
1984 | - $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w; |
|
1976 | + $this->Error('Unknown color type: ' . $file); |
|
1977 | + if (ord($this->_readstream($f, 1)) != 0) |
|
1978 | + $this->Error('Unknown compression method: ' . $file); |
|
1979 | + if (ord($this->_readstream($f, 1)) != 0) |
|
1980 | + $this->Error('Unknown filter method: ' . $file); |
|
1981 | + if (ord($this->_readstream($f, 1)) != 0) |
|
1982 | + $this->Error('Interlacing not supported: ' . $file); |
|
1983 | + $this->_readstream($f, 4); |
|
1984 | + $dp = '/Predictor 15 /Colors ' . ($colspace == 'DeviceRGB' ? 3 : 1) . ' /BitsPerComponent ' . $bpc . ' /Columns ' . $w; |
|
1985 | 1985 | |
1986 | 1986 | // Scan chunks looking for palette, transparency and image data |
1987 | 1987 | $pal = ''; |
@@ -1990,86 +1990,86 @@ discard block |
||
1990 | 1990 | do |
1991 | 1991 | { |
1992 | 1992 | $n = $this->_readint($f); |
1993 | - $type = $this->_readstream($f,4); |
|
1994 | - if($type=='PLTE') |
|
1993 | + $type = $this->_readstream($f, 4); |
|
1994 | + if ($type == 'PLTE') |
|
1995 | 1995 | { |
1996 | 1996 | // Read palette |
1997 | - $pal = $this->_readstream($f,$n); |
|
1998 | - $this->_readstream($f,4); |
|
1997 | + $pal = $this->_readstream($f, $n); |
|
1998 | + $this->_readstream($f, 4); |
|
1999 | 1999 | } |
2000 | - elseif($type=='tRNS') |
|
2000 | + elseif ($type == 'tRNS') |
|
2001 | 2001 | { |
2002 | 2002 | // Read transparency info |
2003 | - $t = $this->_readstream($f,$n); |
|
2004 | - if($ct==0) |
|
2005 | - $trns = array(ord(substr($t,1,1))); |
|
2006 | - elseif($ct==2) |
|
2007 | - $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); |
|
2003 | + $t = $this->_readstream($f, $n); |
|
2004 | + if ($ct == 0) |
|
2005 | + $trns = array(ord(substr($t, 1, 1))); |
|
2006 | + elseif ($ct == 2) |
|
2007 | + $trns = array(ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1))); |
|
2008 | 2008 | else |
2009 | 2009 | { |
2010 | - $pos = strpos($t,chr(0)); |
|
2011 | - if($pos!==false) |
|
2010 | + $pos = strpos($t, chr(0)); |
|
2011 | + if ($pos !== false) |
|
2012 | 2012 | $trns = array($pos); |
2013 | 2013 | } |
2014 | - $this->_readstream($f,4); |
|
2014 | + $this->_readstream($f, 4); |
|
2015 | 2015 | } |
2016 | - elseif($type=='IDAT') |
|
2016 | + elseif ($type == 'IDAT') |
|
2017 | 2017 | { |
2018 | 2018 | // Read image data block |
2019 | - $data .= $this->_readstream($f,$n); |
|
2020 | - $this->_readstream($f,4); |
|
2019 | + $data .= $this->_readstream($f, $n); |
|
2020 | + $this->_readstream($f, 4); |
|
2021 | 2021 | } |
2022 | - elseif($type=='IEND') |
|
2022 | + elseif ($type == 'IEND') |
|
2023 | 2023 | break; |
2024 | 2024 | else |
2025 | - $this->_readstream($f,$n+4); |
|
2025 | + $this->_readstream($f, $n + 4); |
|
2026 | 2026 | } |
2027 | - while($n); |
|
2027 | + while ($n); |
|
2028 | 2028 | |
2029 | - if($colspace=='Indexed' && empty($pal)) |
|
2030 | - $this->Error('Missing palette in '.$file); |
|
2029 | + if ($colspace == 'Indexed' && empty($pal)) |
|
2030 | + $this->Error('Missing palette in ' . $file); |
|
2031 | 2031 | $info = array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns); |
2032 | - if($ct>=4) |
|
2032 | + if ($ct >= 4) |
|
2033 | 2033 | { |
2034 | 2034 | // Extract alpha channel |
2035 | - if(!function_exists('gzuncompress')) |
|
2036 | - $this->Error('Zlib not available, can\'t handle alpha channel: '.$file); |
|
2035 | + if (!function_exists('gzuncompress')) |
|
2036 | + $this->Error('Zlib not available, can\'t handle alpha channel: ' . $file); |
|
2037 | 2037 | $data = gzuncompress($data); |
2038 | 2038 | $color = ''; |
2039 | 2039 | $alpha = ''; |
2040 | - if($ct==4) |
|
2040 | + if ($ct == 4) |
|
2041 | 2041 | { |
2042 | 2042 | // Gray image |
2043 | - $len = 2*$w; |
|
2044 | - for($i=0;$i<$h;$i++) |
|
2043 | + $len = 2 * $w; |
|
2044 | + for ($i = 0; $i < $h; $i++) |
|
2045 | 2045 | { |
2046 | - $pos = (1+$len)*$i; |
|
2046 | + $pos = (1 + $len) * $i; |
|
2047 | 2047 | $color .= $data[$pos]; |
2048 | 2048 | $alpha .= $data[$pos]; |
2049 | - $line = substr($data,$pos+1,$len); |
|
2050 | - $color .= preg_replace('/(.)./s','$1',$line); |
|
2051 | - $alpha .= preg_replace('/.(.)/s','$1',$line); |
|
2049 | + $line = substr($data, $pos + 1, $len); |
|
2050 | + $color .= preg_replace('/(.)./s', '$1', $line); |
|
2051 | + $alpha .= preg_replace('/.(.)/s', '$1', $line); |
|
2052 | 2052 | } |
2053 | 2053 | } |
2054 | 2054 | else |
2055 | 2055 | { |
2056 | 2056 | // RGB image |
2057 | - $len = 4*$w; |
|
2058 | - for($i=0;$i<$h;$i++) |
|
2057 | + $len = 4 * $w; |
|
2058 | + for ($i = 0; $i < $h; $i++) |
|
2059 | 2059 | { |
2060 | - $pos = (1+$len)*$i; |
|
2060 | + $pos = (1 + $len) * $i; |
|
2061 | 2061 | $color .= $data[$pos]; |
2062 | 2062 | $alpha .= $data[$pos]; |
2063 | - $line = substr($data,$pos+1,$len); |
|
2064 | - $color .= preg_replace('/(.{3})./s','$1',$line); |
|
2065 | - $alpha .= preg_replace('/.{3}(.)/s','$1',$line); |
|
2063 | + $line = substr($data, $pos + 1, $len); |
|
2064 | + $color .= preg_replace('/(.{3})./s', '$1', $line); |
|
2065 | + $alpha .= preg_replace('/.{3}(.)/s', '$1', $line); |
|
2066 | 2066 | } |
2067 | 2067 | } |
2068 | 2068 | unset($data); |
2069 | 2069 | $data = gzcompress($color); |
2070 | 2070 | $info['smask'] = gzcompress($alpha); |
2071 | 2071 | $this->WithAlpha = true; |
2072 | - if($this->PDFVersion<'1.4') |
|
2072 | + if ($this->PDFVersion < '1.4') |
|
2073 | 2073 | $this->PDFVersion = '1.4'; |
2074 | 2074 | } |
2075 | 2075 | $info['data'] = $data; |
@@ -2086,15 +2086,15 @@ discard block |
||
2086 | 2086 | { |
2087 | 2087 | // Read n bytes from stream |
2088 | 2088 | $res = ''; |
2089 | - while($n>0 && !feof($f)) |
|
2089 | + while ($n > 0 && !feof($f)) |
|
2090 | 2090 | { |
2091 | - $s = fread($f,$n); |
|
2092 | - if($s===false) |
|
2091 | + $s = fread($f, $n); |
|
2092 | + if ($s === false) |
|
2093 | 2093 | $this->Error('Error while reading stream'); |
2094 | 2094 | $n -= strlen($s); |
2095 | 2095 | $res .= $s; |
2096 | 2096 | } |
2097 | - if($n>0) |
|
2097 | + if ($n > 0) |
|
2098 | 2098 | $this->Error('Unexpected end of stream'); |
2099 | 2099 | return $res; |
2100 | 2100 | } |
@@ -2107,7 +2107,7 @@ discard block |
||
2107 | 2107 | protected function _readint($f) : int |
2108 | 2108 | { |
2109 | 2109 | // Read a 4-byte integer from stream |
2110 | - $a = unpack('Ni',$this->_readstream($f,4)); |
|
2110 | + $a = unpack('Ni', $this->_readstream($f, 4)); |
|
2111 | 2111 | return $a['i']; |
2112 | 2112 | } |
2113 | 2113 | |
@@ -2152,13 +2152,13 @@ discard block |
||
2152 | 2152 | protected function _out(string $s) : void |
2153 | 2153 | { |
2154 | 2154 | // Add a line to the document |
2155 | - if($this->state==2) |
|
2156 | - $this->pages[$this->page] .= $s."\n"; |
|
2157 | - elseif($this->state==1) |
|
2155 | + if ($this->state == 2) |
|
2156 | + $this->pages[$this->page] .= $s . "\n"; |
|
2157 | + elseif ($this->state == 1) |
|
2158 | 2158 | $this->_put($s); |
2159 | - elseif($this->state==0) |
|
2159 | + elseif ($this->state == 0) |
|
2160 | 2160 | $this->Error('No page has been added yet'); |
2161 | - elseif($this->state==3) |
|
2161 | + elseif ($this->state == 3) |
|
2162 | 2162 | $this->Error('The document is closed'); |
2163 | 2163 | } |
2164 | 2164 | |
@@ -2168,7 +2168,7 @@ discard block |
||
2168 | 2168 | */ |
2169 | 2169 | protected function _put(string $s) : void |
2170 | 2170 | { |
2171 | - $this->buffer .= $s."\n"; |
|
2171 | + $this->buffer .= $s . "\n"; |
|
2172 | 2172 | } |
2173 | 2173 | |
2174 | 2174 | /** |
@@ -2184,13 +2184,13 @@ discard block |
||
2184 | 2184 | * Begin a new object. |
2185 | 2185 | * @param int $n |
2186 | 2186 | */ |
2187 | - protected function _newobj(?int $n=null) : void |
|
2187 | + protected function _newobj(?int $n = null) : void |
|
2188 | 2188 | { |
2189 | 2189 | // Begin a new object |
2190 | - if($n===null) |
|
2190 | + if ($n === null) |
|
2191 | 2191 | $n = ++$this->n; |
2192 | 2192 | $this->offsets[$n] = $this->_getoffset(); |
2193 | - $this->_put($n.' 0 obj'); |
|
2193 | + $this->_put($n . ' 0 obj'); |
|
2194 | 2194 | } |
2195 | 2195 | |
2196 | 2196 | /** |
@@ -2210,16 +2210,16 @@ discard block |
||
2210 | 2210 | */ |
2211 | 2211 | protected function _putstreamobject(string $data) : void |
2212 | 2212 | { |
2213 | - if($this->compress) |
|
2213 | + if ($this->compress) |
|
2214 | 2214 | { |
2215 | 2215 | $entries = '/Filter /FlateDecode '; |
2216 | 2216 | $data = gzcompress($data); |
2217 | 2217 | } |
2218 | 2218 | else |
2219 | 2219 | $entries = ''; |
2220 | - $entries .= '/Length '.strlen($data); |
|
2220 | + $entries .= '/Length ' . strlen($data); |
|
2221 | 2221 | $this->_newobj(); |
2222 | - $this->_put('<<'.$entries.'>>'); |
|
2222 | + $this->_put('<<' . $entries . '>>'); |
|
2223 | 2223 | $this->_putstream($data); |
2224 | 2224 | $this->_put('endobj'); |
2225 | 2225 | } |
@@ -2233,39 +2233,39 @@ discard block |
||
2233 | 2233 | $this->_newobj(); |
2234 | 2234 | $this->_put('<</Type /Page'); |
2235 | 2235 | $this->_put('/Parent 1 0 R'); |
2236 | - if(isset($this->PageInfo[$n]['size'])) |
|
2237 | - $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo[$n]['size'][0],$this->PageInfo[$n]['size'][1])); |
|
2238 | - if(isset($this->PageInfo[$n]['rotation'])) |
|
2239 | - $this->_put('/Rotate '.$this->PageInfo[$n]['rotation']); |
|
2236 | + if (isset($this->PageInfo[$n]['size'])) |
|
2237 | + $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]', $this->PageInfo[$n]['size'][0], $this->PageInfo[$n]['size'][1])); |
|
2238 | + if (isset($this->PageInfo[$n]['rotation'])) |
|
2239 | + $this->_put('/Rotate ' . $this->PageInfo[$n]['rotation']); |
|
2240 | 2240 | $this->_put('/Resources 2 0 R'); |
2241 | - if(isset($this->PageLinks[$n])) |
|
2241 | + if (isset($this->PageLinks[$n])) |
|
2242 | 2242 | { |
2243 | 2243 | // Links |
2244 | 2244 | $annots = '/Annots ['; |
2245 | - foreach($this->PageLinks[$n] as $pl) |
|
2245 | + foreach ($this->PageLinks[$n] as $pl) |
|
2246 | 2246 | { |
2247 | - $rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); |
|
2248 | - $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
|
2249 | - if(is_string($pl[4])) |
|
2250 | - $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
|
2247 | + $rect = sprintf('%.2F %.2F %.2F %.2F', $pl[0], $pl[1], $pl[0] + $pl[2], $pl[1] - $pl[3]); |
|
2248 | + $annots .= '<</Type /Annot /Subtype /Link /Rect [' . $rect . '] /Border [0 0 0] '; |
|
2249 | + if (is_string($pl[4])) |
|
2250 | + $annots .= '/A <</S /URI /URI ' . $this->_textstring($pl[4]) . '>>>>'; |
|
2251 | 2251 | else |
2252 | 2252 | { |
2253 | 2253 | $l = $this->links[$pl[4]]; |
2254 | - if(isset($this->PageInfo[$l[0]]['size'])) |
|
2254 | + if (isset($this->PageInfo[$l[0]]['size'])) |
|
2255 | 2255 | $h = $this->PageInfo[$l[0]]['size'][1]; |
2256 | 2256 | else |
2257 | - $h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k; |
|
2258 | - $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[$l[0]]['n'],$h-$l[1]*$this->k); |
|
2257 | + $h = ($this->DefOrientation == 'P') ? $this->DefPageSize[1] * $this->k : $this->DefPageSize[0] * $this->k; |
|
2258 | + $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>', $this->PageInfo[$l[0]]['n'], $h - $l[1] * $this->k); |
|
2259 | 2259 | } |
2260 | 2260 | } |
2261 | - $this->_put($annots.']'); |
|
2261 | + $this->_put($annots . ']'); |
|
2262 | 2262 | } |
2263 | - if($this->WithAlpha) |
|
2263 | + if ($this->WithAlpha) |
|
2264 | 2264 | $this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>'); |
2265 | - $this->_put('/Contents '.($this->n+1).' 0 R>>'); |
|
2265 | + $this->_put('/Contents ' . ($this->n + 1) . ' 0 R>>'); |
|
2266 | 2266 | $this->_put('endobj'); |
2267 | 2267 | // Page content |
2268 | - if(!empty($this->AliasNbPages)) |
|
2268 | + if (!empty($this->AliasNbPages)) |
|
2269 | 2269 | $this->pages[$n] = str_replace($this->AliasNbPages, strval($this->page), $this->pages[$n]); |
2270 | 2270 | $this->_putstreamobject($this->pages[$n]); |
2271 | 2271 | } |
@@ -2276,19 +2276,19 @@ discard block |
||
2276 | 2276 | protected function _putpages() : void |
2277 | 2277 | { |
2278 | 2278 | $nb = $this->page; |
2279 | - for($n=1;$n<=$nb;$n++) |
|
2280 | - $this->PageInfo[$n]['n'] = $this->n+1+2*($n-1); |
|
2281 | - for($n=1;$n<=$nb;$n++) |
|
2279 | + for ($n = 1; $n <= $nb; $n++) |
|
2280 | + $this->PageInfo[$n]['n'] = $this->n + 1 + 2 * ($n - 1); |
|
2281 | + for ($n = 1; $n <= $nb; $n++) |
|
2282 | 2282 | $this->_putpage($n); |
2283 | 2283 | // Pages root |
2284 | 2284 | $this->_newobj(1); |
2285 | 2285 | $this->_put('<</Type /Pages'); |
2286 | 2286 | $kids = '/Kids ['; |
2287 | - for($n=1;$n<=$nb;$n++) |
|
2288 | - $kids .= $this->PageInfo[$n]['n'].' 0 R '; |
|
2289 | - $this->_put($kids.']'); |
|
2290 | - $this->_put('/Count '.$nb); |
|
2291 | - if($this->DefOrientation=='P') |
|
2287 | + for ($n = 1; $n <= $nb; $n++) |
|
2288 | + $kids .= $this->PageInfo[$n]['n'] . ' 0 R '; |
|
2289 | + $this->_put($kids . ']'); |
|
2290 | + $this->_put('/Count ' . $nb); |
|
2291 | + if ($this->DefOrientation == 'P') |
|
2292 | 2292 | { |
2293 | 2293 | $w = $this->DefPageSize[0]; |
2294 | 2294 | $h = $this->DefPageSize[1]; |
@@ -2298,7 +2298,7 @@ discard block |
||
2298 | 2298 | $w = $this->DefPageSize[1]; |
2299 | 2299 | $h = $this->DefPageSize[0]; |
2300 | 2300 | } |
2301 | - $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$w*$this->k,$h*$this->k)); |
|
2301 | + $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]', $w * $this->k, $h * $this->k)); |
|
2302 | 2302 | $this->_put('>>'); |
2303 | 2303 | $this->_put('endobj'); |
2304 | 2304 | } |
@@ -2326,7 +2326,7 @@ discard block |
||
2326 | 2326 | } |
2327 | 2327 | $this->_put('/Length1 ' . $info['length1']); |
2328 | 2328 | if (isset($info['length2'])) { |
2329 | - $this->_put('/Length2 '.$info['length2'].' /Length3 0'); |
|
2329 | + $this->_put('/Length2 ' . $info['length2'] . ' /Length3 0'); |
|
2330 | 2330 | } |
2331 | 2331 | $this->_put('>>'); |
2332 | 2332 | $this->_putstream($font); |
@@ -2363,7 +2363,7 @@ discard block |
||
2363 | 2363 | if ($font['subsetted']) { |
2364 | 2364 | $name = 'AAAAAA+' . $name; |
2365 | 2365 | } |
2366 | - if ($type=='Core') { |
|
2366 | + if ($type == 'Core') { |
|
2367 | 2367 | // Core font |
2368 | 2368 | $this->_newobj(); |
2369 | 2369 | $this->_put('<</Type /Font'); |
@@ -2437,16 +2437,16 @@ discard block |
||
2437 | 2437 | $nbr = 0; |
2438 | 2438 | $chars = ''; |
2439 | 2439 | $nbc = 0; |
2440 | - foreach($uv as $c=>$v) |
|
2440 | + foreach ($uv as $c=>$v) |
|
2441 | 2441 | { |
2442 | - if(is_array($v)) |
|
2442 | + if (is_array($v)) |
|
2443 | 2443 | { |
2444 | - $ranges .= sprintf("<%02X> <%02X> <%04X>\n",$c,$c+$v[1]-1,$v[0]); |
|
2444 | + $ranges .= sprintf("<%02X> <%02X> <%04X>\n", $c, $c + $v[1] - 1, $v[0]); |
|
2445 | 2445 | $nbr++; |
2446 | 2446 | } |
2447 | 2447 | else |
2448 | 2448 | { |
2449 | - $chars .= sprintf("<%02X> <%04X>\n",$c,$v); |
|
2449 | + $chars .= sprintf("<%02X> <%04X>\n", $c, $v); |
|
2450 | 2450 | $nbc++; |
2451 | 2451 | } |
2452 | 2452 | } |
@@ -2463,13 +2463,13 @@ discard block |
||
2463 | 2463 | $s .= "1 begincodespacerange\n"; |
2464 | 2464 | $s .= "<00> <FF>\n"; |
2465 | 2465 | $s .= "endcodespacerange\n"; |
2466 | - if($nbr>0) |
|
2466 | + if ($nbr > 0) |
|
2467 | 2467 | { |
2468 | 2468 | $s .= "$nbr beginbfrange\n"; |
2469 | 2469 | $s .= $ranges; |
2470 | 2470 | $s .= "endbfrange\n"; |
2471 | 2471 | } |
2472 | - if($nbc>0) |
|
2472 | + if ($nbc > 0) |
|
2473 | 2473 | { |
2474 | 2474 | $s .= "$nbc beginbfchar\n"; |
2475 | 2475 | $s .= $chars; |
@@ -2487,7 +2487,7 @@ discard block |
||
2487 | 2487 | */ |
2488 | 2488 | protected function _putimages() : void |
2489 | 2489 | { |
2490 | - foreach(array_keys($this->images) as $file) |
|
2490 | + foreach (array_keys($this->images) as $file) |
|
2491 | 2491 | { |
2492 | 2492 | $this->_putimage($this->images[$file]); |
2493 | 2493 | unset($this->images[$file]['data']); |
@@ -2511,7 +2511,7 @@ discard block |
||
2511 | 2511 | $this->_put('/ColorSpace [/Indexed /DeviceRGB ' . (strlen($info['pal']) / 3 - 1) . ' ' . ($this->n + 1) . ' 0 R]'); |
2512 | 2512 | } else { |
2513 | 2513 | $this->_put('/ColorSpace /' . $info['cs']); |
2514 | - if($info['cs']=='DeviceCMYK') { |
|
2514 | + if ($info['cs'] == 'DeviceCMYK') { |
|
2515 | 2515 | $this->_put('/Decode [1 0 1 0 1 0 1 0]'); |
2516 | 2516 | } |
2517 | 2517 | } |
@@ -2522,7 +2522,7 @@ discard block |
||
2522 | 2522 | if (isset($info['dp'])) { |
2523 | 2523 | $this->_put('/DecodeParms <<' . $info['dp'] . '>>'); |
2524 | 2524 | } |
2525 | - if (isset($info['trns']) && is_array($info['trns'])) { |
|
2525 | + if (isset($info['trns']) && is_array($info['trns'])) { |
|
2526 | 2526 | $trns = ''; |
2527 | 2527 | $cnt = count($info['trns']); |
2528 | 2528 | for ($i = 0; $i < $cnt; $i++) { |
@@ -2531,7 +2531,7 @@ discard block |
||
2531 | 2531 | $this->_put('/Mask [' . $trns . ']'); |
2532 | 2532 | } |
2533 | 2533 | if (isset($info['smask'])) { |
2534 | - $this->_put('/SMask ' . ($this->n+1) . ' 0 R'); |
|
2534 | + $this->_put('/SMask ' . ($this->n + 1) . ' 0 R'); |
|
2535 | 2535 | } |
2536 | 2536 | $this->_put('/Length ' . strlen($info['data']) . '>>'); |
2537 | 2537 | $this->_putstream($info['data']); |
@@ -2602,7 +2602,7 @@ discard block |
||
2602 | 2602 | */ |
2603 | 2603 | protected function _putinfo() : void |
2604 | 2604 | { |
2605 | - $this->metadata['Producer'] = 'FPDF '.FPDF_VERSION; |
|
2605 | + $this->metadata['Producer'] = 'FPDF ' . FPDF_VERSION; |
|
2606 | 2606 | $this->metadata['CreationDate'] = 'D:' . @date('YmdHis'); |
2607 | 2607 | foreach ($this->metadata as $key=>$value) { |
2608 | 2608 | $this->_put('/' . $key . ' ' . $this->_textstring($value)); |
@@ -2617,20 +2617,20 @@ discard block |
||
2617 | 2617 | $n = $this->PageInfo[1]['n']; |
2618 | 2618 | $this->_put('/Type /Catalog'); |
2619 | 2619 | $this->_put('/Pages 1 0 R'); |
2620 | - if($this->ZoomMode=='fullpage') { |
|
2620 | + if ($this->ZoomMode == 'fullpage') { |
|
2621 | 2621 | $this->_put('/OpenAction [' . $n . ' 0 R /Fit]'); |
2622 | - } elseif ($this->ZoomMode=='fullwidth') { |
|
2622 | + } elseif ($this->ZoomMode == 'fullwidth') { |
|
2623 | 2623 | $this->_put('/OpenAction [' . $n . ' 0 R /FitH null]'); |
2624 | - } elseif($this->ZoomMode=='real') { |
|
2624 | + } elseif ($this->ZoomMode == 'real') { |
|
2625 | 2625 | $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null 1]'); |
2626 | - } elseif(!is_string($this->ZoomMode)) { |
|
2626 | + } elseif (!is_string($this->ZoomMode)) { |
|
2627 | 2627 | $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null ' . sprintf('%.2F', $this->ZoomMode / 100) . ']'); |
2628 | 2628 | } |
2629 | - if($this->LayoutMode=='single') { |
|
2629 | + if ($this->LayoutMode == 'single') { |
|
2630 | 2630 | $this->_put('/PageLayout /SinglePage'); |
2631 | - } elseif($this->LayoutMode=='continuous') { |
|
2631 | + } elseif ($this->LayoutMode == 'continuous') { |
|
2632 | 2632 | $this->_put('/PageLayout /OneColumn'); |
2633 | - } elseif($this->LayoutMode=='two') { |
|
2633 | + } elseif ($this->LayoutMode == 'two') { |
|
2634 | 2634 | $this->_put('/PageLayout /TwoColumnLeft'); |
2635 | 2635 | } |
2636 | 2636 | } |
@@ -241,15 +241,14 @@ discard block |
||
241 | 241 | $this->DefOrientation = 'P'; |
242 | 242 | $this->w = $size[0]; |
243 | 243 | $this->h = $size[1]; |
244 | - } |
|
245 | - elseif($orientation=='l' || $orientation=='landscape') |
|
244 | + } elseif($orientation=='l' || $orientation=='landscape') |
|
246 | 245 | { |
247 | 246 | $this->DefOrientation = 'L'; |
248 | 247 | $this->w = $size[1]; |
249 | 248 | $this->h = $size[0]; |
249 | + } else { |
|
250 | + $this->Error('Incorrect orientation: '.$orientation); |
|
250 | 251 | } |
251 | - else |
|
252 | - $this->Error('Incorrect orientation: '.$orientation); |
|
253 | 252 | $this->CurOrientation = $this->DefOrientation; |
254 | 253 | $this->wPt = $this->w*$this->k; |
255 | 254 | $this->hPt = $this->h*$this->k; |
@@ -284,8 +283,9 @@ discard block |
||
284 | 283 | // Set left, top and right margins |
285 | 284 | $this->lMargin = $left; |
286 | 285 | $this->tMargin = $top; |
287 | - if($right===null) |
|
288 | - $right = $left; |
|
286 | + if($right===null) { |
|
287 | + $right = $left; |
|
288 | + } |
|
289 | 289 | $this->rMargin = $right; |
290 | 290 | } |
291 | 291 | |
@@ -299,8 +299,9 @@ discard block |
||
299 | 299 | { |
300 | 300 | // Set left margin |
301 | 301 | $this->lMargin = $margin; |
302 | - if($this->page>0 && $this->x<$margin) |
|
303 | - $this->x = $margin; |
|
302 | + if($this->page>0 && $this->x<$margin) { |
|
303 | + $this->x = $margin; |
|
304 | + } |
|
304 | 305 | } |
305 | 306 | |
306 | 307 | /** |
@@ -372,14 +373,16 @@ discard block |
||
372 | 373 | public function SetDisplayMode($zoom, string $layout='default') : void |
373 | 374 | { |
374 | 375 | // Set display mode in viewer |
375 | - if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) |
|
376 | - $this->ZoomMode = $zoom; |
|
377 | - else |
|
378 | - $this->Error('Incorrect zoom display mode: '.$zoom); |
|
379 | - if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') |
|
380 | - $this->LayoutMode = $layout; |
|
381 | - else |
|
382 | - $this->Error('Incorrect layout display mode: '.$layout); |
|
376 | + if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) { |
|
377 | + $this->ZoomMode = $zoom; |
|
378 | + } else { |
|
379 | + $this->Error('Incorrect zoom display mode: '.$zoom); |
|
380 | + } |
|
381 | + if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') { |
|
382 | + $this->LayoutMode = $layout; |
|
383 | + } else { |
|
384 | + $this->Error('Incorrect layout display mode: '.$layout); |
|
385 | + } |
|
383 | 386 | } |
384 | 387 | |
385 | 388 | /** |
@@ -394,10 +397,11 @@ discard block |
||
394 | 397 | public function SetCompression(bool $compress) : void |
395 | 398 | { |
396 | 399 | // Set page compression |
397 | - if(function_exists('gzcompress')) |
|
398 | - $this->compress = $compress; |
|
399 | - else |
|
400 | - $this->compress = false; |
|
400 | + if(function_exists('gzcompress')) { |
|
401 | + $this->compress = $compress; |
|
402 | + } else { |
|
403 | + $this->compress = false; |
|
404 | + } |
|
401 | 405 | } |
402 | 406 | |
403 | 407 | /** |
@@ -488,10 +492,12 @@ discard block |
||
488 | 492 | public function Close() : void |
489 | 493 | { |
490 | 494 | // Terminate document |
491 | - if($this->state==3) |
|
492 | - return; |
|
493 | - if($this->page==0) |
|
494 | - $this->addPage(); |
|
495 | + if($this->state==3) { |
|
496 | + return; |
|
497 | + } |
|
498 | + if($this->page==0) { |
|
499 | + $this->addPage(); |
|
500 | + } |
|
495 | 501 | // Page footer |
496 | 502 | $this->InFooter = true; |
497 | 503 | $this->Footer(); |
@@ -533,8 +539,9 @@ discard block |
||
533 | 539 | public function AddPage(string $orientation='', $size='', int $rotation=0) : void |
534 | 540 | { |
535 | 541 | // Start a new page |
536 | - if($this->state==3) |
|
537 | - $this->Error('The document is closed'); |
|
542 | + if($this->state==3) { |
|
543 | + $this->Error('The document is closed'); |
|
544 | + } |
|
538 | 545 | $family = $this->FontFamily; |
539 | 546 | $style = $this->FontStyle.($this->underline ? 'U' : ''); |
540 | 547 | $fontsize = $this->FontSizePt; |
@@ -560,15 +567,18 @@ discard block |
||
560 | 567 | $this->LineWidth = $lw; |
561 | 568 | $this->_out(sprintf('%.2F w',$lw*$this->k)); |
562 | 569 | // Set font |
563 | - if($family) |
|
564 | - $this->setFont($family,$style,$fontsize); |
|
570 | + if($family) { |
|
571 | + $this->setFont($family,$style,$fontsize); |
|
572 | + } |
|
565 | 573 | // Set colors |
566 | 574 | $this->DrawColor = $dc; |
567 | - if($dc!='0 G') |
|
568 | - $this->_out($dc); |
|
575 | + if($dc!='0 G') { |
|
576 | + $this->_out($dc); |
|
577 | + } |
|
569 | 578 | $this->FillColor = $fc; |
570 | - if($fc!='0 g') |
|
571 | - $this->_out($fc); |
|
579 | + if($fc!='0 g') { |
|
580 | + $this->_out($fc); |
|
581 | + } |
|
572 | 582 | $this->TextColor = $tc; |
573 | 583 | $this->ColorFlag = $cf; |
574 | 584 | // Page header |
@@ -582,8 +592,9 @@ discard block |
||
582 | 592 | $this->_out(sprintf('%.2F w',$lw*$this->k)); |
583 | 593 | } |
584 | 594 | // Restore font |
585 | - if($family) |
|
586 | - $this->setFont($family,$style,$fontsize); |
|
595 | + if($family) { |
|
596 | + $this->setFont($family,$style,$fontsize); |
|
597 | + } |
|
587 | 598 | // Restore colors |
588 | 599 | if($this->DrawColor!=$dc) |
589 | 600 | { |
@@ -706,8 +717,9 @@ discard block |
||
706 | 717 | $cw = &$this->CurrentFont['cw']; |
707 | 718 | $w = 0; |
708 | 719 | $l = strlen($s); |
709 | - for($i=0;$i<$l;$i++) |
|
710 | - $w += $cw[$s[$i]]; |
|
720 | + for($i=0;$i<$l;$i++) { |
|
721 | + $w += $cw[$s[$i]]; |
|
722 | + } |
|
711 | 723 | return $w*$this->FontSize/1000; |
712 | 724 | } |
713 | 725 | |
@@ -721,8 +733,9 @@ discard block |
||
721 | 733 | { |
722 | 734 | // Set line width |
723 | 735 | $this->LineWidth = $width; |
724 | - if($this->page>0) |
|
725 | - $this->_out(sprintf('%.2F w',$width*$this->k)); |
|
736 | + if($this->page>0) { |
|
737 | + $this->_out(sprintf('%.2F w',$width*$this->k)); |
|
738 | + } |
|
726 | 739 | } |
727 | 740 | |
728 | 741 | /** |
@@ -758,12 +771,13 @@ discard block |
||
758 | 771 | public function Rect(float $x, float $y, float $w, float $h, string $style='') : void |
759 | 772 | { |
760 | 773 | // Draw a rectangle |
761 | - if($style=='F') |
|
762 | - $op = 'f'; |
|
763 | - elseif($style=='FD' || $style=='DF') |
|
764 | - $op = 'B'; |
|
765 | - else |
|
766 | - $op = 'S'; |
|
774 | + if($style=='F') { |
|
775 | + $op = 'f'; |
|
776 | + } elseif($style=='FD' || $style=='DF') { |
|
777 | + $op = 'B'; |
|
778 | + } else { |
|
779 | + $op = 'S'; |
|
780 | + } |
|
767 | 781 | $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); |
768 | 782 | } |
769 | 783 | |
@@ -788,23 +802,27 @@ discard block |
||
788 | 802 | { |
789 | 803 | // Add a TrueType, OpenType or Type1 font |
790 | 804 | $family = strtolower($family); |
791 | - if($file=='') |
|
792 | - $file = str_replace(' ','',$family).strtolower($style).'.php'; |
|
805 | + if($file=='') { |
|
806 | + $file = str_replace(' ','',$family).strtolower($style).'.php'; |
|
807 | + } |
|
793 | 808 | $style = strtoupper($style); |
794 | - if($style=='IB') |
|
795 | - $style = 'BI'; |
|
809 | + if($style=='IB') { |
|
810 | + $style = 'BI'; |
|
811 | + } |
|
796 | 812 | $fontkey = $family.$style; |
797 | - if(isset($this->fonts[$fontkey])) |
|
798 | - return; |
|
813 | + if(isset($this->fonts[$fontkey])) { |
|
814 | + return; |
|
815 | + } |
|
799 | 816 | $info = $this->_loadfont($file); |
800 | 817 | $info['i'] = count($this->fonts)+1; |
801 | 818 | if(!empty($info['file'])) |
802 | 819 | { |
803 | 820 | // Embedded font |
804 | - if($info['type']=='TrueType') |
|
805 | - $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']); |
|
806 | - else |
|
807 | - $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']); |
|
821 | + if($info['type']=='TrueType') { |
|
822 | + $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']); |
|
823 | + } else { |
|
824 | + $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']); |
|
825 | + } |
|
808 | 826 | } |
809 | 827 | $this->fonts[$fontkey] = $info; |
810 | 828 | } |
@@ -847,42 +865,49 @@ discard block |
||
847 | 865 | public function SetFont(string $family, string $style='', float $size=0) : void |
848 | 866 | { |
849 | 867 | // Select a font; size given in points |
850 | - if($family=='') |
|
851 | - $family = $this->FontFamily; |
|
852 | - else |
|
853 | - $family = strtolower($family); |
|
868 | + if($family=='') { |
|
869 | + $family = $this->FontFamily; |
|
870 | + } else { |
|
871 | + $family = strtolower($family); |
|
872 | + } |
|
854 | 873 | $style = strtoupper($style); |
855 | 874 | if(strpos($style,'U')!==false) |
856 | 875 | { |
857 | 876 | $this->underline = true; |
858 | 877 | $style = str_replace('U','',$style); |
878 | + } else { |
|
879 | + $this->underline = false; |
|
880 | + } |
|
881 | + if($style=='IB') { |
|
882 | + $style = 'BI'; |
|
883 | + } |
|
884 | + if($size==0) { |
|
885 | + $size = $this->FontSizePt; |
|
859 | 886 | } |
860 | - else |
|
861 | - $this->underline = false; |
|
862 | - if($style=='IB') |
|
863 | - $style = 'BI'; |
|
864 | - if($size==0) |
|
865 | - $size = $this->FontSizePt; |
|
866 | 887 | // Test if font is already selected |
867 | - if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) |
|
868 | - return; |
|
888 | + if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) { |
|
889 | + return; |
|
890 | + } |
|
869 | 891 | // Test if font is already loaded |
870 | 892 | $fontkey = $family.$style; |
871 | 893 | if(!isset($this->fonts[$fontkey])) |
872 | 894 | { |
873 | 895 | // Test if one of the core fonts |
874 | - if($family=='arial') |
|
875 | - $family = 'helvetica'; |
|
896 | + if($family=='arial') { |
|
897 | + $family = 'helvetica'; |
|
898 | + } |
|
876 | 899 | if(in_array($family,$this->CoreFonts)) |
877 | 900 | { |
878 | - if($family=='symbol' || $family=='zapfdingbats') |
|
879 | - $style = ''; |
|
901 | + if($family=='symbol' || $family=='zapfdingbats') { |
|
902 | + $style = ''; |
|
903 | + } |
|
880 | 904 | $fontkey = $family.$style; |
881 | - if(!isset($this->fonts[$fontkey])) |
|
882 | - $this->addFont($family,$style); |
|
905 | + if(!isset($this->fonts[$fontkey])) { |
|
906 | + $this->addFont($family,$style); |
|
907 | + } |
|
908 | + } else { |
|
909 | + $this->Error('Undefined font: '.$family.' '.$style); |
|
883 | 910 | } |
884 | - else |
|
885 | - $this->Error('Undefined font: '.$family.' '.$style); |
|
886 | 911 | } |
887 | 912 | // Select it |
888 | 913 | $this->FontFamily = $family; |
@@ -890,8 +915,9 @@ discard block |
||
890 | 915 | $this->FontSizePt = $size; |
891 | 916 | $this->FontSize = $size/$this->k; |
892 | 917 | $this->CurrentFont = &$this->fonts[$fontkey]; |
893 | - if($this->page>0) |
|
894 | - $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); |
|
918 | + if($this->page>0) { |
|
919 | + $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); |
|
920 | + } |
|
895 | 921 | } |
896 | 922 | |
897 | 923 | /** |
@@ -901,12 +927,14 @@ discard block |
||
901 | 927 | public function SetFontSize(float $size) : void |
902 | 928 | { |
903 | 929 | // Set font size in points |
904 | - if($this->FontSizePt==$size) |
|
905 | - return; |
|
930 | + if($this->FontSizePt==$size) { |
|
931 | + return; |
|
932 | + } |
|
906 | 933 | $this->FontSizePt = $size; |
907 | 934 | $this->FontSize = $size/$this->k; |
908 | - if($this->page>0) |
|
909 | - $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); |
|
935 | + if($this->page>0) { |
|
936 | + $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); |
|
937 | + } |
|
910 | 938 | } |
911 | 939 | |
912 | 940 | /** |
@@ -933,10 +961,12 @@ discard block |
||
933 | 961 | public function SetLink(int $link, float $y=0, int $page=-1) : void |
934 | 962 | { |
935 | 963 | // Set destination of internal link |
936 | - if($y==-1) |
|
937 | - $y = $this->y; |
|
938 | - if($page==-1) |
|
939 | - $page = $this->page; |
|
964 | + if($y==-1) { |
|
965 | + $y = $this->y; |
|
966 | + } |
|
967 | + if($page==-1) { |
|
968 | + $page = $this->page; |
|
969 | + } |
|
940 | 970 | $this->links[$link] = array($page, $y); |
941 | 971 | } |
942 | 972 | |
@@ -970,13 +1000,16 @@ discard block |
||
970 | 1000 | public function Text(float $x, float $y, string $txt) : void |
971 | 1001 | { |
972 | 1002 | // Output a string |
973 | - if(!isset($this->CurrentFont)) |
|
974 | - $this->Error('No font has been set'); |
|
1003 | + if(!isset($this->CurrentFont)) { |
|
1004 | + $this->Error('No font has been set'); |
|
1005 | + } |
|
975 | 1006 | $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); |
976 | - if($this->underline && $txt!='') |
|
977 | - $s .= ' '.$this->_dounderline($x,$y,$txt); |
|
978 | - if($this->ColorFlag) |
|
979 | - $s = 'q '.$this->TextColor.' '.$s.' Q'; |
|
1007 | + if($this->underline && $txt!='') { |
|
1008 | + $s .= ' '.$this->_dounderline($x,$y,$txt); |
|
1009 | + } |
|
1010 | + if($this->ColorFlag) { |
|
1011 | + $s = 'q '.$this->TextColor.' '.$s.' Q'; |
|
1012 | + } |
|
980 | 1013 | $this->_out($s); |
981 | 1014 | } |
982 | 1015 | |
@@ -1056,62 +1089,76 @@ discard block |
||
1056 | 1089 | $this->_out(sprintf('%.3F Tw',$ws*$k)); |
1057 | 1090 | } |
1058 | 1091 | } |
1059 | - if($w==0) |
|
1060 | - $w = $this->w-$this->rMargin-$this->x; |
|
1092 | + if($w==0) { |
|
1093 | + $w = $this->w-$this->rMargin-$this->x; |
|
1094 | + } |
|
1061 | 1095 | $s = ''; |
1062 | 1096 | if($fill || $border==1) |
1063 | 1097 | { |
1064 | - if($fill) |
|
1065 | - $op = ($border==1) ? 'B' : 'f'; |
|
1066 | - else |
|
1067 | - $op = 'S'; |
|
1098 | + if($fill) { |
|
1099 | + $op = ($border==1) ? 'B' : 'f'; |
|
1100 | + } else { |
|
1101 | + $op = 'S'; |
|
1102 | + } |
|
1068 | 1103 | $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); |
1069 | 1104 | } |
1070 | 1105 | if(is_string($border)) |
1071 | 1106 | { |
1072 | 1107 | $x = $this->x; |
1073 | 1108 | $y = $this->y; |
1074 | - if(strpos($border,'L')!==false) |
|
1075 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); |
|
1076 | - if(strpos($border,'T')!==false) |
|
1077 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); |
|
1078 | - if(strpos($border,'R')!==false) |
|
1079 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); |
|
1080 | - if(strpos($border,'B')!==false) |
|
1081 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); |
|
1109 | + if(strpos($border,'L')!==false) { |
|
1110 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); |
|
1111 | + } |
|
1112 | + if(strpos($border,'T')!==false) { |
|
1113 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); |
|
1114 | + } |
|
1115 | + if(strpos($border,'R')!==false) { |
|
1116 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); |
|
1117 | + } |
|
1118 | + if(strpos($border,'B')!==false) { |
|
1119 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); |
|
1120 | + } |
|
1082 | 1121 | } |
1083 | 1122 | if($txt!=='') |
1084 | 1123 | { |
1085 | - if(!isset($this->CurrentFont)) |
|
1086 | - $this->Error('No font has been set'); |
|
1087 | - if($align=='R') |
|
1088 | - $dx = $w-$this->cMargin-$this->getStringWidth($txt); |
|
1089 | - elseif($align=='C') |
|
1090 | - $dx = ($w-$this->getStringWidth($txt))/2; |
|
1091 | - else |
|
1092 | - $dx = $this->cMargin; |
|
1093 | - if($this->ColorFlag) |
|
1094 | - $s .= 'q '.$this->TextColor.' '; |
|
1124 | + if(!isset($this->CurrentFont)) { |
|
1125 | + $this->Error('No font has been set'); |
|
1126 | + } |
|
1127 | + if($align=='R') { |
|
1128 | + $dx = $w-$this->cMargin-$this->getStringWidth($txt); |
|
1129 | + } elseif($align=='C') { |
|
1130 | + $dx = ($w-$this->getStringWidth($txt))/2; |
|
1131 | + } else { |
|
1132 | + $dx = $this->cMargin; |
|
1133 | + } |
|
1134 | + if($this->ColorFlag) { |
|
1135 | + $s .= 'q '.$this->TextColor.' '; |
|
1136 | + } |
|
1095 | 1137 | $s .= sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$this->_escape($txt)); |
1096 | - if($this->underline) |
|
1097 | - $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); |
|
1098 | - if($this->ColorFlag) |
|
1099 | - $s .= ' Q'; |
|
1100 | - if($link) |
|
1101 | - $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->getStringWidth($txt),$this->FontSize,$link); |
|
1102 | - } |
|
1103 | - if($s) |
|
1104 | - $this->_out($s); |
|
1138 | + if($this->underline) { |
|
1139 | + $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); |
|
1140 | + } |
|
1141 | + if($this->ColorFlag) { |
|
1142 | + $s .= ' Q'; |
|
1143 | + } |
|
1144 | + if($link) { |
|
1145 | + $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->getStringWidth($txt),$this->FontSize,$link); |
|
1146 | + } |
|
1147 | + } |
|
1148 | + if($s) { |
|
1149 | + $this->_out($s); |
|
1150 | + } |
|
1105 | 1151 | $this->lasth = $h; |
1106 | 1152 | if($ln>0) |
1107 | 1153 | { |
1108 | 1154 | // Go to next line |
1109 | 1155 | $this->y += $h; |
1110 | - if($ln==1) |
|
1111 | - $this->x = $this->lMargin; |
|
1156 | + if($ln==1) { |
|
1157 | + $this->x = $this->lMargin; |
|
1158 | + } |
|
1159 | + } else { |
|
1160 | + $this->x += $w; |
|
1112 | 1161 | } |
1113 | - else |
|
1114 | - $this->x += $w; |
|
1115 | 1162 | } |
1116 | 1163 | |
1117 | 1164 | /** |
@@ -1145,16 +1192,19 @@ discard block |
||
1145 | 1192 | public function MultiCell(float $w, float $h, string $txt, $border=0, string $align='J', bool $fill=false) : void |
1146 | 1193 | { |
1147 | 1194 | // Output text with automatic or explicit line breaks |
1148 | - if(!isset($this->CurrentFont)) |
|
1149 | - $this->Error('No font has been set'); |
|
1195 | + if(!isset($this->CurrentFont)) { |
|
1196 | + $this->Error('No font has been set'); |
|
1197 | + } |
|
1150 | 1198 | $cw = &$this->CurrentFont['cw']; |
1151 | - if($w==0) |
|
1152 | - $w = $this->w-$this->rMargin-$this->x; |
|
1199 | + if($w==0) { |
|
1200 | + $w = $this->w-$this->rMargin-$this->x; |
|
1201 | + } |
|
1153 | 1202 | $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
1154 | 1203 | $s = str_replace("\r",'',$txt); |
1155 | 1204 | $nb = strlen($s); |
1156 | - if($nb>0 && $s[$nb-1]=="\n") |
|
1157 | - $nb--; |
|
1205 | + if($nb>0 && $s[$nb-1]=="\n") { |
|
1206 | + $nb--; |
|
1207 | + } |
|
1158 | 1208 | $b = 0; |
1159 | 1209 | $b2 = ''; |
1160 | 1210 | if($border) |
@@ -1164,14 +1214,15 @@ discard block |
||
1164 | 1214 | $border = 'LTRB'; |
1165 | 1215 | $b = 'LRT'; |
1166 | 1216 | $b2 = 'LR'; |
1167 | - } |
|
1168 | - else |
|
1217 | + } else |
|
1169 | 1218 | { |
1170 | 1219 | $b2 = ''; |
1171 | - if(strpos($border,'L')!==false) |
|
1172 | - $b2 .= 'L'; |
|
1173 | - if(strpos($border,'R')!==false) |
|
1174 | - $b2 .= 'R'; |
|
1220 | + if(strpos($border,'L')!==false) { |
|
1221 | + $b2 .= 'L'; |
|
1222 | + } |
|
1223 | + if(strpos($border,'R')!==false) { |
|
1224 | + $b2 .= 'R'; |
|
1225 | + } |
|
1175 | 1226 | $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; |
1176 | 1227 | } |
1177 | 1228 | } |
@@ -1201,8 +1252,9 @@ discard block |
||
1201 | 1252 | $l = 0; |
1202 | 1253 | $ns = 0; |
1203 | 1254 | $nl++; |
1204 | - if($border && $nl==2) |
|
1205 | - $b = $b2; |
|
1255 | + if($border && $nl==2) { |
|
1256 | + $b = $b2; |
|
1257 | + } |
|
1206 | 1258 | continue; |
1207 | 1259 | } |
1208 | 1260 | if($c==' ') |
@@ -1217,16 +1269,16 @@ discard block |
||
1217 | 1269 | // Automatic line break |
1218 | 1270 | if($sep==-1) |
1219 | 1271 | { |
1220 | - if($i==$j) |
|
1221 | - $i++; |
|
1272 | + if($i==$j) { |
|
1273 | + $i++; |
|
1274 | + } |
|
1222 | 1275 | if($this->ws>0) |
1223 | 1276 | { |
1224 | 1277 | $this->ws = 0; |
1225 | 1278 | $this->_out('0 Tw'); |
1226 | 1279 | } |
1227 | 1280 | $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
1228 | - } |
|
1229 | - else |
|
1281 | + } else |
|
1230 | 1282 | { |
1231 | 1283 | if($align=='J') |
1232 | 1284 | { |
@@ -1241,11 +1293,12 @@ discard block |
||
1241 | 1293 | $l = 0; |
1242 | 1294 | $ns = 0; |
1243 | 1295 | $nl++; |
1244 | - if($border && $nl==2) |
|
1245 | - $b = $b2; |
|
1296 | + if($border && $nl==2) { |
|
1297 | + $b = $b2; |
|
1298 | + } |
|
1299 | + } else { |
|
1300 | + $i++; |
|
1246 | 1301 | } |
1247 | - else |
|
1248 | - $i++; |
|
1249 | 1302 | } |
1250 | 1303 | // Last chunk |
1251 | 1304 | if($this->ws>0) |
@@ -1253,8 +1306,9 @@ discard block |
||
1253 | 1306 | $this->ws = 0; |
1254 | 1307 | $this->_out('0 Tw'); |
1255 | 1308 | } |
1256 | - if($border && strpos($border,'B')!==false) |
|
1257 | - $b .= 'B'; |
|
1309 | + if($border && strpos($border,'B')!==false) { |
|
1310 | + $b .= 'B'; |
|
1311 | + } |
|
1258 | 1312 | $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
1259 | 1313 | $this->x = $this->lMargin; |
1260 | 1314 | } |
@@ -1272,8 +1326,9 @@ discard block |
||
1272 | 1326 | public function Write(float $h, string $txt, $link='') : void |
1273 | 1327 | { |
1274 | 1328 | // Output text in flowing mode |
1275 | - if(!isset($this->CurrentFont)) |
|
1276 | - $this->Error('No font has been set'); |
|
1329 | + if(!isset($this->CurrentFont)) { |
|
1330 | + $this->Error('No font has been set'); |
|
1331 | + } |
|
1277 | 1332 | $cw = &$this->CurrentFont['cw']; |
1278 | 1333 | $w = $this->w-$this->rMargin-$this->x; |
1279 | 1334 | $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
@@ -1305,8 +1360,9 @@ discard block |
||
1305 | 1360 | $nl++; |
1306 | 1361 | continue; |
1307 | 1362 | } |
1308 | - if($c==' ') |
|
1309 | - $sep = $i; |
|
1363 | + if($c==' ') { |
|
1364 | + $sep = $i; |
|
1365 | + } |
|
1310 | 1366 | $l += $cw[$c]; |
1311 | 1367 | if($l>$wmax) |
1312 | 1368 | { |
@@ -1324,11 +1380,11 @@ discard block |
||
1324 | 1380 | $nl++; |
1325 | 1381 | continue; |
1326 | 1382 | } |
1327 | - if($i==$j) |
|
1328 | - $i++; |
|
1383 | + if($i==$j) { |
|
1384 | + $i++; |
|
1385 | + } |
|
1329 | 1386 | $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
1330 | - } |
|
1331 | - else |
|
1387 | + } else |
|
1332 | 1388 | { |
1333 | 1389 | $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link); |
1334 | 1390 | $i = $sep+1; |
@@ -1343,13 +1399,14 @@ discard block |
||
1343 | 1399 | $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
1344 | 1400 | } |
1345 | 1401 | $nl++; |
1402 | + } else { |
|
1403 | + $i++; |
|
1346 | 1404 | } |
1347 | - else |
|
1348 | - $i++; |
|
1349 | 1405 | } |
1350 | 1406 | // Last chunk |
1351 | - if($i!=$j) |
|
1352 | - $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link); |
|
1407 | + if($i!=$j) { |
|
1408 | + $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link); |
|
1409 | + } |
|
1353 | 1410 | } |
1354 | 1411 | |
1355 | 1412 | /** |
@@ -1363,10 +1420,11 @@ discard block |
||
1363 | 1420 | { |
1364 | 1421 | // Line feed; default value is the last cell height |
1365 | 1422 | $this->x = $this->lMargin; |
1366 | - if($h===null) |
|
1367 | - $this->y += $this->lasth; |
|
1368 | - else |
|
1369 | - $this->y += $h; |
|
1423 | + if($h===null) { |
|
1424 | + $this->y += $this->lasth; |
|
1425 | + } else { |
|
1426 | + $this->y += $h; |
|
1427 | + } |
|
1370 | 1428 | } |
1371 | 1429 | |
1372 | 1430 | /** |
@@ -1418,30 +1476,34 @@ discard block |
||
1418 | 1476 | public function Image(string $file, ?float $x=null, ?float $y=null, float $w=0, float $h=0, string $type='', $link='') : void |
1419 | 1477 | { |
1420 | 1478 | // Put an image on the page |
1421 | - if($file=='') |
|
1422 | - $this->Error('Image file name is empty'); |
|
1479 | + if($file=='') { |
|
1480 | + $this->Error('Image file name is empty'); |
|
1481 | + } |
|
1423 | 1482 | if(!isset($this->images[$file])) |
1424 | 1483 | { |
1425 | 1484 | // First use of this image, get info |
1426 | 1485 | if($type=='') |
1427 | 1486 | { |
1428 | 1487 | $pos = strrpos($file,'.'); |
1429 | - if(!$pos) |
|
1430 | - $this->Error('Image file has no extension and no type was specified: '.$file); |
|
1488 | + if(!$pos) { |
|
1489 | + $this->Error('Image file has no extension and no type was specified: '.$file); |
|
1490 | + } |
|
1431 | 1491 | $type = substr($file,$pos+1); |
1432 | 1492 | } |
1433 | 1493 | $type = strtolower($type); |
1434 | - if($type=='jpeg') |
|
1435 | - $type = 'jpg'; |
|
1494 | + if($type=='jpeg') { |
|
1495 | + $type = 'jpg'; |
|
1496 | + } |
|
1436 | 1497 | $mtd = '_parse'.$type; |
1437 | - if(!method_exists($this,$mtd)) |
|
1438 | - $this->Error('Unsupported image type: '.$type); |
|
1498 | + if(!method_exists($this,$mtd)) { |
|
1499 | + $this->Error('Unsupported image type: '.$type); |
|
1500 | + } |
|
1439 | 1501 | $info = $this->$mtd($file); |
1440 | 1502 | $info['i'] = count($this->images)+1; |
1441 | 1503 | $this->images[$file] = $info; |
1504 | + } else { |
|
1505 | + $info = $this->images[$file]; |
|
1442 | 1506 | } |
1443 | - else |
|
1444 | - $info = $this->images[$file]; |
|
1445 | 1507 | |
1446 | 1508 | // Automatic width and height calculation if needed |
1447 | 1509 | if($w==0 && $h==0) |
@@ -1450,14 +1512,18 @@ discard block |
||
1450 | 1512 | $w = -96; |
1451 | 1513 | $h = -96; |
1452 | 1514 | } |
1453 | - if($w<0) |
|
1454 | - $w = -$info['w']*72/$w/$this->k; |
|
1455 | - if($h<0) |
|
1456 | - $h = -$info['h']*72/$h/$this->k; |
|
1457 | - if($w==0) |
|
1458 | - $w = $h*$info['w']/$info['h']; |
|
1459 | - if($h==0) |
|
1460 | - $h = $w*$info['h']/$info['w']; |
|
1515 | + if($w<0) { |
|
1516 | + $w = -$info['w']*72/$w/$this->k; |
|
1517 | + } |
|
1518 | + if($h<0) { |
|
1519 | + $h = -$info['h']*72/$h/$this->k; |
|
1520 | + } |
|
1521 | + if($w==0) { |
|
1522 | + $w = $h*$info['w']/$info['h']; |
|
1523 | + } |
|
1524 | + if($h==0) { |
|
1525 | + $h = $w*$info['h']/$info['w']; |
|
1526 | + } |
|
1461 | 1527 | |
1462 | 1528 | // Flowing mode |
1463 | 1529 | if($y===null) |
@@ -1473,11 +1539,13 @@ discard block |
||
1473 | 1539 | $this->y += $h; |
1474 | 1540 | } |
1475 | 1541 | |
1476 | - if($x===null) |
|
1477 | - $x = $this->x; |
|
1542 | + if($x===null) { |
|
1543 | + $x = $this->x; |
|
1544 | + } |
|
1478 | 1545 | $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q',$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i'])); |
1479 | - if($link) |
|
1480 | - $this->Link($x,$y,$w,$h,$link); |
|
1546 | + if($link) { |
|
1547 | + $this->Link($x,$y,$w,$h,$link); |
|
1548 | + } |
|
1481 | 1549 | } |
1482 | 1550 | |
1483 | 1551 | /** |
@@ -1518,10 +1586,11 @@ discard block |
||
1518 | 1586 | public function SetX(float $x) : void |
1519 | 1587 | { |
1520 | 1588 | // Set x position |
1521 | - if($x>=0) |
|
1522 | - $this->x = $x; |
|
1523 | - else |
|
1524 | - $this->x = $this->w+$x; |
|
1589 | + if($x>=0) { |
|
1590 | + $this->x = $x; |
|
1591 | + } else { |
|
1592 | + $this->x = $this->w+$x; |
|
1593 | + } |
|
1525 | 1594 | } |
1526 | 1595 | |
1527 | 1596 | /** |
@@ -1543,12 +1612,14 @@ discard block |
||
1543 | 1612 | public function SetY(float $y, bool $resetX=true) : void |
1544 | 1613 | { |
1545 | 1614 | // Set y position and optionally reset x |
1546 | - if($y>=0) |
|
1547 | - $this->y = $y; |
|
1548 | - else |
|
1549 | - $this->y = $this->h+$y; |
|
1550 | - if($resetX) |
|
1551 | - $this->x = $this->lMargin; |
|
1615 | + if($y>=0) { |
|
1616 | + $this->y = $y; |
|
1617 | + } else { |
|
1618 | + $this->y = $this->h+$y; |
|
1619 | + } |
|
1620 | + if($resetX) { |
|
1621 | + $this->x = $this->lMargin; |
|
1622 | + } |
|
1552 | 1623 | } |
1553 | 1624 | |
1554 | 1625 | /** |
@@ -1593,10 +1664,12 @@ discard block |
||
1593 | 1664 | $dest = $name; |
1594 | 1665 | $name = $tmp; |
1595 | 1666 | } |
1596 | - if($dest=='') |
|
1597 | - $dest = 'I'; |
|
1598 | - if($name=='') |
|
1599 | - $name = 'doc.pdf'; |
|
1667 | + if($dest=='') { |
|
1668 | + $dest = 'I'; |
|
1669 | + } |
|
1670 | + if($name=='') { |
|
1671 | + $name = 'doc.pdf'; |
|
1672 | + } |
|
1600 | 1673 | switch(strtoupper($dest)) |
1601 | 1674 | { |
1602 | 1675 | case 'I': |
@@ -1623,8 +1696,9 @@ discard block |
||
1623 | 1696 | break; |
1624 | 1697 | case 'F': |
1625 | 1698 | // Save to local file |
1626 | - if(!file_put_contents($name,$this->buffer)) |
|
1627 | - $this->Error('Unable to create output file: '.$name); |
|
1699 | + if(!file_put_contents($name,$this->buffer)) { |
|
1700 | + $this->Error('Unable to create output file: '.$name); |
|
1701 | + } |
|
1628 | 1702 | break; |
1629 | 1703 | case 'S': |
1630 | 1704 | // Return as a string |
@@ -1641,8 +1715,9 @@ discard block |
||
1641 | 1715 | protected function _dochecks() : void |
1642 | 1716 | { |
1643 | 1717 | // Check mbstring overloading |
1644 | - if(ini_get('mbstring.func_overload') & 2) |
|
1645 | - $this->Error('mbstring overloading must be disabled'); |
|
1718 | + if(ini_get('mbstring.func_overload') & 2) { |
|
1719 | + $this->Error('mbstring overloading must be disabled'); |
|
1720 | + } |
|
1646 | 1721 | } |
1647 | 1722 | |
1648 | 1723 | /** |
@@ -1654,8 +1729,9 @@ discard block |
||
1654 | 1729 | { |
1655 | 1730 | $file = ''; |
1656 | 1731 | $line = 0; |
1657 | - if(headers_sent($file,$line)) |
|
1658 | - $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)"); |
|
1732 | + if(headers_sent($file,$line)) { |
|
1733 | + $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)"); |
|
1734 | + } |
|
1659 | 1735 | } |
1660 | 1736 | if(ob_get_length()) |
1661 | 1737 | { |
@@ -1664,9 +1740,9 @@ discard block |
||
1664 | 1740 | { |
1665 | 1741 | // It contains only a UTF-8 BOM and/or whitespace, let's clean it |
1666 | 1742 | ob_clean(); |
1743 | + } else { |
|
1744 | + $this->Error("Some data has already been output, can't send PDF file"); |
|
1667 | 1745 | } |
1668 | - else |
|
1669 | - $this->Error("Some data has already been output, can't send PDF file"); |
|
1670 | 1746 | } |
1671 | 1747 | } |
1672 | 1748 | |
@@ -1680,17 +1756,18 @@ discard block |
||
1680 | 1756 | if(is_string($size)) |
1681 | 1757 | { |
1682 | 1758 | $size = strtolower($size); |
1683 | - if(!isset($this->StdPageSizes[$size])) |
|
1684 | - $this->Error('Unknown page size: '.$size); |
|
1759 | + if(!isset($this->StdPageSizes[$size])) { |
|
1760 | + $this->Error('Unknown page size: '.$size); |
|
1761 | + } |
|
1685 | 1762 | $a = $this->StdPageSizes[$size]; |
1686 | 1763 | return array($a[0]/$this->k, $a[1]/$this->k); |
1687 | - } |
|
1688 | - else |
|
1764 | + } else |
|
1689 | 1765 | { |
1690 | - if($size[0]>$size[1]) |
|
1691 | - return array($size[1], $size[0]); |
|
1692 | - else |
|
1693 | - return $size; |
|
1766 | + if($size[0]>$size[1]) { |
|
1767 | + return array($size[1], $size[0]); |
|
1768 | + } else { |
|
1769 | + return $size; |
|
1770 | + } |
|
1694 | 1771 | } |
1695 | 1772 | } |
1696 | 1773 | |
@@ -1709,14 +1786,16 @@ discard block |
||
1709 | 1786 | $this->y = $this->tMargin; |
1710 | 1787 | $this->FontFamily = ''; |
1711 | 1788 | // Check page size and orientation |
1712 | - if($orientation=='') |
|
1713 | - $orientation = $this->DefOrientation; |
|
1714 | - else |
|
1715 | - $orientation = strtoupper($orientation[0]); |
|
1716 | - if($size=='') |
|
1717 | - $size = $this->DefPageSize; |
|
1718 | - else |
|
1719 | - $size = $this->_getpagesize($size); |
|
1789 | + if($orientation=='') { |
|
1790 | + $orientation = $this->DefOrientation; |
|
1791 | + } else { |
|
1792 | + $orientation = strtoupper($orientation[0]); |
|
1793 | + } |
|
1794 | + if($size=='') { |
|
1795 | + $size = $this->DefPageSize; |
|
1796 | + } else { |
|
1797 | + $size = $this->_getpagesize($size); |
|
1798 | + } |
|
1720 | 1799 | if($orientation!=$this->CurOrientation || $size[0]!=$this->CurPageSize[0] || $size[1]!=$this->CurPageSize[1]) |
1721 | 1800 | { |
1722 | 1801 | // New size or orientation |
@@ -1724,8 +1803,7 @@ discard block |
||
1724 | 1803 | { |
1725 | 1804 | $this->w = $size[0]; |
1726 | 1805 | $this->h = $size[1]; |
1727 | - } |
|
1728 | - else |
|
1806 | + } else |
|
1729 | 1807 | { |
1730 | 1808 | $this->w = $size[1]; |
1731 | 1809 | $this->h = $size[0]; |
@@ -1736,12 +1814,14 @@ discard block |
||
1736 | 1814 | $this->CurOrientation = $orientation; |
1737 | 1815 | $this->CurPageSize = $size; |
1738 | 1816 | } |
1739 | - if($orientation!=$this->DefOrientation || $size[0]!=$this->DefPageSize[0] || $size[1]!=$this->DefPageSize[1]) |
|
1740 | - $this->PageInfo[$this->page]['size'] = array($this->wPt, $this->hPt); |
|
1817 | + if($orientation!=$this->DefOrientation || $size[0]!=$this->DefPageSize[0] || $size[1]!=$this->DefPageSize[1]) { |
|
1818 | + $this->PageInfo[$this->page]['size'] = array($this->wPt, $this->hPt); |
|
1819 | + } |
|
1741 | 1820 | if($rotation!=0) |
1742 | 1821 | { |
1743 | - if($rotation%90!=0) |
|
1744 | - $this->Error('Incorrect rotation value: '.$rotation); |
|
1822 | + if($rotation%90!=0) { |
|
1823 | + $this->Error('Incorrect rotation value: '.$rotation); |
|
1824 | + } |
|
1745 | 1825 | $this->CurRotation = $rotation; |
1746 | 1826 | $this->PageInfo[$this->page]['rotation'] = $rotation; |
1747 | 1827 | } |
@@ -1796,8 +1876,9 @@ discard block |
||
1796 | 1876 | $nb = strlen($s); |
1797 | 1877 | for($i=0;$i<$nb;$i++) |
1798 | 1878 | { |
1799 | - if(ord($s[$i])>127) |
|
1800 | - return false; |
|
1879 | + if(ord($s[$i])>127) { |
|
1880 | + return false; |
|
1881 | + } |
|
1801 | 1882 | } |
1802 | 1883 | return true; |
1803 | 1884 | } |
@@ -1811,14 +1892,17 @@ discard block |
||
1811 | 1892 | protected function _httpencode(string $param, string $value, bool $isUTF8) : string |
1812 | 1893 | { |
1813 | 1894 | // Encode HTTP header field parameter |
1814 | - if($this->_isascii($value)) |
|
1815 | - return $param.'="'.$value.'"'; |
|
1816 | - if(!$isUTF8) |
|
1817 | - $value = utf8_encode($value); |
|
1818 | - if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==false) |
|
1819 | - return $param.'="'.rawurlencode($value).'"'; |
|
1820 | - else |
|
1821 | - return $param."*=UTF-8''".rawurlencode($value); |
|
1895 | + if($this->_isascii($value)) { |
|
1896 | + return $param.'="'.$value.'"'; |
|
1897 | + } |
|
1898 | + if(!$isUTF8) { |
|
1899 | + $value = utf8_encode($value); |
|
1900 | + } |
|
1901 | + if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==false) { |
|
1902 | + return $param.'="'.rawurlencode($value).'"'; |
|
1903 | + } else { |
|
1904 | + return $param."*=UTF-8''".rawurlencode($value); |
|
1905 | + } |
|
1822 | 1906 | } |
1823 | 1907 | |
1824 | 1908 | /** |
@@ -1842,15 +1926,13 @@ discard block |
||
1842 | 1926 | $c3 = ord($s[$i++]); |
1843 | 1927 | $res .= chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2)); |
1844 | 1928 | $res .= chr((($c2 & 0x03)<<6) + ($c3 & 0x3F)); |
1845 | - } |
|
1846 | - elseif($c1>=192) |
|
1929 | + } elseif($c1>=192) |
|
1847 | 1930 | { |
1848 | 1931 | // 2-byte character |
1849 | 1932 | $c2 = ord($s[$i++]); |
1850 | 1933 | $res .= chr(($c1 & 0x1C)>>2); |
1851 | 1934 | $res .= chr((($c1 & 0x03)<<6) + ($c2 & 0x3F)); |
1852 | - } |
|
1853 | - else |
|
1935 | + } else |
|
1854 | 1936 | { |
1855 | 1937 | // Single-byte character |
1856 | 1938 | $res .= "\0".chr($c1); |
@@ -1867,10 +1949,11 @@ discard block |
||
1867 | 1949 | protected function _escape(string $s) : string |
1868 | 1950 | { |
1869 | 1951 | // Escape special characters |
1870 | - if(strpos($s,'(')!==false || strpos($s,')')!==false || strpos($s,'\\')!==false || strpos($s,"\r")!==false) |
|
1871 | - return str_replace(array('\\','(',')',"\r"), array('\\\\','\\(','\\)','\\r'), $s); |
|
1872 | - else |
|
1873 | - return $s; |
|
1952 | + if(strpos($s,'(')!==false || strpos($s,')')!==false || strpos($s,'\\')!==false || strpos($s,"\r")!==false) { |
|
1953 | + return str_replace(array('\\','(',')',"\r"), array('\\\\','\\(','\\)','\\r'), $s); |
|
1954 | + } else { |
|
1955 | + return $s; |
|
1956 | + } |
|
1874 | 1957 | } |
1875 | 1958 | |
1876 | 1959 | /** |
@@ -1881,8 +1964,9 @@ discard block |
||
1881 | 1964 | protected function _textstring(string $s) : string |
1882 | 1965 | { |
1883 | 1966 | // Format a text string |
1884 | - if(!$this->_isascii($s)) |
|
1885 | - $s = $this->_UTF8toUTF16($s); |
|
1967 | + if(!$this->_isascii($s)) { |
|
1968 | + $s = $this->_UTF8toUTF16($s); |
|
1969 | + } |
|
1886 | 1970 | return '('.$this->_escape($s).')'; |
1887 | 1971 | } |
1888 | 1972 | |
@@ -1911,16 +1995,19 @@ discard block |
||
1911 | 1995 | { |
1912 | 1996 | // Extract info from a JPEG file |
1913 | 1997 | $a = getimagesize($file); |
1914 | - if(!$a) |
|
1915 | - $this->Error('Missing or incorrect image file: '.$file); |
|
1916 | - if($a[2]!=2) |
|
1917 | - $this->Error('Not a JPEG file: '.$file); |
|
1918 | - if(!isset($a['channels']) || $a['channels']==3) |
|
1919 | - $colspace = 'DeviceRGB'; |
|
1920 | - elseif($a['channels']==4) |
|
1921 | - $colspace = 'DeviceCMYK'; |
|
1922 | - else |
|
1923 | - $colspace = 'DeviceGray'; |
|
1998 | + if(!$a) { |
|
1999 | + $this->Error('Missing or incorrect image file: '.$file); |
|
2000 | + } |
|
2001 | + if($a[2]!=2) { |
|
2002 | + $this->Error('Not a JPEG file: '.$file); |
|
2003 | + } |
|
2004 | + if(!isset($a['channels']) || $a['channels']==3) { |
|
2005 | + $colspace = 'DeviceRGB'; |
|
2006 | + } elseif($a['channels']==4) { |
|
2007 | + $colspace = 'DeviceCMYK'; |
|
2008 | + } else { |
|
2009 | + $colspace = 'DeviceGray'; |
|
2010 | + } |
|
1924 | 2011 | $bpc = isset($a['bits']) ? $a['bits'] : 8; |
1925 | 2012 | $data = file_get_contents($file); |
1926 | 2013 | return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data); |
@@ -1952,34 +2039,41 @@ discard block |
||
1952 | 2039 | protected function _parsepngstream($f, string $file) : array |
1953 | 2040 | { |
1954 | 2041 | // Check signature |
1955 | - if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) |
|
1956 | - $this->Error('Not a PNG file: '.$file); |
|
2042 | + if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) { |
|
2043 | + $this->Error('Not a PNG file: '.$file); |
|
2044 | + } |
|
1957 | 2045 | |
1958 | 2046 | // Read header chunk |
1959 | 2047 | $this->_readstream($f,4); |
1960 | - if($this->_readstream($f,4)!='IHDR') |
|
1961 | - $this->Error('Incorrect PNG file: '.$file); |
|
2048 | + if($this->_readstream($f,4)!='IHDR') { |
|
2049 | + $this->Error('Incorrect PNG file: '.$file); |
|
2050 | + } |
|
1962 | 2051 | $w = $this->_readint($f); |
1963 | 2052 | $h = $this->_readint($f); |
1964 | 2053 | $bpc = ord($this->_readstream($f,1)); |
1965 | - if($bpc>8) |
|
1966 | - $this->Error('16-bit depth not supported: '.$file); |
|
2054 | + if($bpc>8) { |
|
2055 | + $this->Error('16-bit depth not supported: '.$file); |
|
2056 | + } |
|
1967 | 2057 | $ct = ord($this->_readstream($f,1)); |
1968 | 2058 | $colspace = ''; |
1969 | - if($ct==0 || $ct==4) |
|
1970 | - $colspace = 'DeviceGray'; |
|
1971 | - elseif($ct==2 || $ct==6) |
|
1972 | - $colspace = 'DeviceRGB'; |
|
1973 | - elseif($ct==3) |
|
1974 | - $colspace = 'Indexed'; |
|
1975 | - else |
|
1976 | - $this->Error('Unknown color type: '.$file); |
|
1977 | - if(ord($this->_readstream($f,1))!=0) |
|
1978 | - $this->Error('Unknown compression method: '.$file); |
|
1979 | - if(ord($this->_readstream($f,1))!=0) |
|
1980 | - $this->Error('Unknown filter method: '.$file); |
|
1981 | - if(ord($this->_readstream($f,1))!=0) |
|
1982 | - $this->Error('Interlacing not supported: '.$file); |
|
2059 | + if($ct==0 || $ct==4) { |
|
2060 | + $colspace = 'DeviceGray'; |
|
2061 | + } elseif($ct==2 || $ct==6) { |
|
2062 | + $colspace = 'DeviceRGB'; |
|
2063 | + } elseif($ct==3) { |
|
2064 | + $colspace = 'Indexed'; |
|
2065 | + } else { |
|
2066 | + $this->Error('Unknown color type: '.$file); |
|
2067 | + } |
|
2068 | + if(ord($this->_readstream($f,1))!=0) { |
|
2069 | + $this->Error('Unknown compression method: '.$file); |
|
2070 | + } |
|
2071 | + if(ord($this->_readstream($f,1))!=0) { |
|
2072 | + $this->Error('Unknown filter method: '.$file); |
|
2073 | + } |
|
2074 | + if(ord($this->_readstream($f,1))!=0) { |
|
2075 | + $this->Error('Interlacing not supported: '.$file); |
|
2076 | + } |
|
1983 | 2077 | $this->_readstream($f,4); |
1984 | 2078 | $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w; |
1985 | 2079 | |
@@ -1996,44 +2090,45 @@ discard block |
||
1996 | 2090 | // Read palette |
1997 | 2091 | $pal = $this->_readstream($f,$n); |
1998 | 2092 | $this->_readstream($f,4); |
1999 | - } |
|
2000 | - elseif($type=='tRNS') |
|
2093 | + } elseif($type=='tRNS') |
|
2001 | 2094 | { |
2002 | 2095 | // Read transparency info |
2003 | 2096 | $t = $this->_readstream($f,$n); |
2004 | - if($ct==0) |
|
2005 | - $trns = array(ord(substr($t,1,1))); |
|
2006 | - elseif($ct==2) |
|
2007 | - $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); |
|
2008 | - else |
|
2097 | + if($ct==0) { |
|
2098 | + $trns = array(ord(substr($t,1,1))); |
|
2099 | + } elseif($ct==2) { |
|
2100 | + $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); |
|
2101 | + } else |
|
2009 | 2102 | { |
2010 | 2103 | $pos = strpos($t,chr(0)); |
2011 | - if($pos!==false) |
|
2012 | - $trns = array($pos); |
|
2104 | + if($pos!==false) { |
|
2105 | + $trns = array($pos); |
|
2106 | + } |
|
2013 | 2107 | } |
2014 | 2108 | $this->_readstream($f,4); |
2015 | - } |
|
2016 | - elseif($type=='IDAT') |
|
2109 | + } elseif($type=='IDAT') |
|
2017 | 2110 | { |
2018 | 2111 | // Read image data block |
2019 | 2112 | $data .= $this->_readstream($f,$n); |
2020 | 2113 | $this->_readstream($f,4); |
2114 | + } elseif($type=='IEND') { |
|
2115 | + break; |
|
2116 | + } else { |
|
2117 | + $this->_readstream($f,$n+4); |
|
2021 | 2118 | } |
2022 | - elseif($type=='IEND') |
|
2023 | - break; |
|
2024 | - else |
|
2025 | - $this->_readstream($f,$n+4); |
|
2026 | 2119 | } |
2027 | 2120 | while($n); |
2028 | 2121 | |
2029 | - if($colspace=='Indexed' && empty($pal)) |
|
2030 | - $this->Error('Missing palette in '.$file); |
|
2122 | + if($colspace=='Indexed' && empty($pal)) { |
|
2123 | + $this->Error('Missing palette in '.$file); |
|
2124 | + } |
|
2031 | 2125 | $info = array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns); |
2032 | 2126 | if($ct>=4) |
2033 | 2127 | { |
2034 | 2128 | // Extract alpha channel |
2035 | - if(!function_exists('gzuncompress')) |
|
2036 | - $this->Error('Zlib not available, can\'t handle alpha channel: '.$file); |
|
2129 | + if(!function_exists('gzuncompress')) { |
|
2130 | + $this->Error('Zlib not available, can\'t handle alpha channel: '.$file); |
|
2131 | + } |
|
2037 | 2132 | $data = gzuncompress($data); |
2038 | 2133 | $color = ''; |
2039 | 2134 | $alpha = ''; |
@@ -2050,8 +2145,7 @@ discard block |
||
2050 | 2145 | $color .= preg_replace('/(.)./s','$1',$line); |
2051 | 2146 | $alpha .= preg_replace('/.(.)/s','$1',$line); |
2052 | 2147 | } |
2053 | - } |
|
2054 | - else |
|
2148 | + } else |
|
2055 | 2149 | { |
2056 | 2150 | // RGB image |
2057 | 2151 | $len = 4*$w; |
@@ -2069,8 +2163,9 @@ discard block |
||
2069 | 2163 | $data = gzcompress($color); |
2070 | 2164 | $info['smask'] = gzcompress($alpha); |
2071 | 2165 | $this->WithAlpha = true; |
2072 | - if($this->PDFVersion<'1.4') |
|
2073 | - $this->PDFVersion = '1.4'; |
|
2166 | + if($this->PDFVersion<'1.4') { |
|
2167 | + $this->PDFVersion = '1.4'; |
|
2168 | + } |
|
2074 | 2169 | } |
2075 | 2170 | $info['data'] = $data; |
2076 | 2171 | return $info; |
@@ -2089,13 +2184,15 @@ discard block |
||
2089 | 2184 | while($n>0 && !feof($f)) |
2090 | 2185 | { |
2091 | 2186 | $s = fread($f,$n); |
2092 | - if($s===false) |
|
2093 | - $this->Error('Error while reading stream'); |
|
2187 | + if($s===false) { |
|
2188 | + $this->Error('Error while reading stream'); |
|
2189 | + } |
|
2094 | 2190 | $n -= strlen($s); |
2095 | 2191 | $res .= $s; |
2096 | 2192 | } |
2097 | - if($n>0) |
|
2098 | - $this->Error('Unexpected end of stream'); |
|
2193 | + if($n>0) { |
|
2194 | + $this->Error('Unexpected end of stream'); |
|
2195 | + } |
|
2099 | 2196 | return $res; |
2100 | 2197 | } |
2101 | 2198 | |
@@ -2152,14 +2249,15 @@ discard block |
||
2152 | 2249 | protected function _out(string $s) : void |
2153 | 2250 | { |
2154 | 2251 | // Add a line to the document |
2155 | - if($this->state==2) |
|
2156 | - $this->pages[$this->page] .= $s."\n"; |
|
2157 | - elseif($this->state==1) |
|
2158 | - $this->_put($s); |
|
2159 | - elseif($this->state==0) |
|
2160 | - $this->Error('No page has been added yet'); |
|
2161 | - elseif($this->state==3) |
|
2162 | - $this->Error('The document is closed'); |
|
2252 | + if($this->state==2) { |
|
2253 | + $this->pages[$this->page] .= $s."\n"; |
|
2254 | + } elseif($this->state==1) { |
|
2255 | + $this->_put($s); |
|
2256 | + } elseif($this->state==0) { |
|
2257 | + $this->Error('No page has been added yet'); |
|
2258 | + } elseif($this->state==3) { |
|
2259 | + $this->Error('The document is closed'); |
|
2260 | + } |
|
2163 | 2261 | } |
2164 | 2262 | |
2165 | 2263 | /** |
@@ -2187,8 +2285,9 @@ discard block |
||
2187 | 2285 | protected function _newobj(?int $n=null) : void |
2188 | 2286 | { |
2189 | 2287 | // Begin a new object |
2190 | - if($n===null) |
|
2191 | - $n = ++$this->n; |
|
2288 | + if($n===null) { |
|
2289 | + $n = ++$this->n; |
|
2290 | + } |
|
2192 | 2291 | $this->offsets[$n] = $this->_getoffset(); |
2193 | 2292 | $this->_put($n.' 0 obj'); |
2194 | 2293 | } |
@@ -2214,9 +2313,9 @@ discard block |
||
2214 | 2313 | { |
2215 | 2314 | $entries = '/Filter /FlateDecode '; |
2216 | 2315 | $data = gzcompress($data); |
2316 | + } else { |
|
2317 | + $entries = ''; |
|
2217 | 2318 | } |
2218 | - else |
|
2219 | - $entries = ''; |
|
2220 | 2319 | $entries .= '/Length '.strlen($data); |
2221 | 2320 | $this->_newobj(); |
2222 | 2321 | $this->_put('<<'.$entries.'>>'); |
@@ -2233,10 +2332,12 @@ discard block |
||
2233 | 2332 | $this->_newobj(); |
2234 | 2333 | $this->_put('<</Type /Page'); |
2235 | 2334 | $this->_put('/Parent 1 0 R'); |
2236 | - if(isset($this->PageInfo[$n]['size'])) |
|
2237 | - $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo[$n]['size'][0],$this->PageInfo[$n]['size'][1])); |
|
2238 | - if(isset($this->PageInfo[$n]['rotation'])) |
|
2239 | - $this->_put('/Rotate '.$this->PageInfo[$n]['rotation']); |
|
2335 | + if(isset($this->PageInfo[$n]['size'])) { |
|
2336 | + $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo[$n]['size'][0],$this->PageInfo[$n]['size'][1])); |
|
2337 | + } |
|
2338 | + if(isset($this->PageInfo[$n]['rotation'])) { |
|
2339 | + $this->_put('/Rotate '.$this->PageInfo[$n]['rotation']); |
|
2340 | + } |
|
2240 | 2341 | $this->_put('/Resources 2 0 R'); |
2241 | 2342 | if(isset($this->PageLinks[$n])) |
2242 | 2343 | { |
@@ -2246,27 +2347,30 @@ discard block |
||
2246 | 2347 | { |
2247 | 2348 | $rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); |
2248 | 2349 | $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
2249 | - if(is_string($pl[4])) |
|
2250 | - $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
|
2251 | - else |
|
2350 | + if(is_string($pl[4])) { |
|
2351 | + $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
|
2352 | + } else |
|
2252 | 2353 | { |
2253 | 2354 | $l = $this->links[$pl[4]]; |
2254 | - if(isset($this->PageInfo[$l[0]]['size'])) |
|
2255 | - $h = $this->PageInfo[$l[0]]['size'][1]; |
|
2256 | - else |
|
2257 | - $h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k; |
|
2355 | + if(isset($this->PageInfo[$l[0]]['size'])) { |
|
2356 | + $h = $this->PageInfo[$l[0]]['size'][1]; |
|
2357 | + } else { |
|
2358 | + $h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k; |
|
2359 | + } |
|
2258 | 2360 | $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[$l[0]]['n'],$h-$l[1]*$this->k); |
2259 | 2361 | } |
2260 | 2362 | } |
2261 | 2363 | $this->_put($annots.']'); |
2262 | 2364 | } |
2263 | - if($this->WithAlpha) |
|
2264 | - $this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>'); |
|
2365 | + if($this->WithAlpha) { |
|
2366 | + $this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>'); |
|
2367 | + } |
|
2265 | 2368 | $this->_put('/Contents '.($this->n+1).' 0 R>>'); |
2266 | 2369 | $this->_put('endobj'); |
2267 | 2370 | // Page content |
2268 | - if(!empty($this->AliasNbPages)) |
|
2269 | - $this->pages[$n] = str_replace($this->AliasNbPages, strval($this->page), $this->pages[$n]); |
|
2371 | + if(!empty($this->AliasNbPages)) { |
|
2372 | + $this->pages[$n] = str_replace($this->AliasNbPages, strval($this->page), $this->pages[$n]); |
|
2373 | + } |
|
2270 | 2374 | $this->_putstreamobject($this->pages[$n]); |
2271 | 2375 | } |
2272 | 2376 | |
@@ -2276,24 +2380,26 @@ discard block |
||
2276 | 2380 | protected function _putpages() : void |
2277 | 2381 | { |
2278 | 2382 | $nb = $this->page; |
2279 | - for($n=1;$n<=$nb;$n++) |
|
2280 | - $this->PageInfo[$n]['n'] = $this->n+1+2*($n-1); |
|
2281 | - for($n=1;$n<=$nb;$n++) |
|
2282 | - $this->_putpage($n); |
|
2383 | + for($n=1;$n<=$nb;$n++) { |
|
2384 | + $this->PageInfo[$n]['n'] = $this->n+1+2*($n-1); |
|
2385 | + } |
|
2386 | + for($n=1;$n<=$nb;$n++) { |
|
2387 | + $this->_putpage($n); |
|
2388 | + } |
|
2283 | 2389 | // Pages root |
2284 | 2390 | $this->_newobj(1); |
2285 | 2391 | $this->_put('<</Type /Pages'); |
2286 | 2392 | $kids = '/Kids ['; |
2287 | - for($n=1;$n<=$nb;$n++) |
|
2288 | - $kids .= $this->PageInfo[$n]['n'].' 0 R '; |
|
2393 | + for($n=1;$n<=$nb;$n++) { |
|
2394 | + $kids .= $this->PageInfo[$n]['n'].' 0 R '; |
|
2395 | + } |
|
2289 | 2396 | $this->_put($kids.']'); |
2290 | 2397 | $this->_put('/Count '.$nb); |
2291 | 2398 | if($this->DefOrientation=='P') |
2292 | 2399 | { |
2293 | 2400 | $w = $this->DefPageSize[0]; |
2294 | 2401 | $h = $this->DefPageSize[1]; |
2295 | - } |
|
2296 | - else |
|
2402 | + } else |
|
2297 | 2403 | { |
2298 | 2404 | $w = $this->DefPageSize[1]; |
2299 | 2405 | $h = $this->DefPageSize[0]; |
@@ -2443,8 +2549,7 @@ discard block |
||
2443 | 2549 | { |
2444 | 2550 | $ranges .= sprintf("<%02X> <%02X> <%04X>\n",$c,$c+$v[1]-1,$v[0]); |
2445 | 2551 | $nbr++; |
2446 | - } |
|
2447 | - else |
|
2552 | + } else |
|
2448 | 2553 | { |
2449 | 2554 | $chars .= sprintf("<%02X> <%04X>\n",$c,$v); |
2450 | 2555 | $nbc++; |
@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | class XPDF extends FPDF |
31 | 31 | { |
32 | 32 | /** predifined Col-ID for automated row number */ |
33 | - const COL_ROW_NR = 1000; |
|
33 | + const COL_ROW_NR = 1000; |
|
34 | 34 | |
35 | 35 | /** Bottom margin for trigger of the auto pagebreak */ |
36 | - const BOTTOM_MARGIN = 12; |
|
36 | + const BOTTOM_MARGIN = 12; |
|
37 | 37 | |
38 | 38 | /** totals info */ |
39 | 39 | const FLAG_TOTALS = 0x0007; |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | /** @var int index of last totals col */ |
162 | 162 | protected int $iMaxColTotals = -1; |
163 | 163 | /** @var array calculated totals */ |
164 | - protected array $aTotals = Array(); |
|
164 | + protected array $aTotals = Array(); |
|
165 | 165 | /** @var array calculated subtotals */ |
166 | - protected array $aSubTotals = Array(); |
|
166 | + protected array $aSubTotals = Array(); |
|
167 | 167 | /** @var array colspan of the totals */ |
168 | - protected array $aTotalsColSpan = Array(); |
|
168 | + protected array $aTotalsColSpan = Array(); |
|
169 | 169 | /** @var int current rownumber */ |
170 | 170 | protected int $iRow; |
171 | 171 | /** @var float lineheight in mm */ |
@@ -203,11 +203,11 @@ discard block |
||
203 | 203 | * @param string|array $size |
204 | 204 | * @see FPDF::__construct() |
205 | 205 | */ |
206 | - public function __construct(string $orientation='P', string $unit='mm', $size='A4') |
|
206 | + public function __construct(string $orientation = 'P', string $unit = 'mm', $size = 'A4') |
|
207 | 207 | { |
208 | 208 | parent::__construct($orientation, $unit, $size); |
209 | 209 | |
210 | - $this->SetDisplayMode('fullpage','single'); |
|
210 | + $this->SetDisplayMode('fullpage', 'single'); |
|
211 | 211 | $this->SetAutoPageBreak(true, self::BOTTOM_MARGIN); |
212 | 212 | $this->AliasNbPages('{NP}'); |
213 | 213 | $this->SetLocale("en_US.utf8, en_US"); |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * @param string $strKeywords |
233 | 233 | * @param bool $isUTF8 Indicates if the strings encoded in ISO-8859-1 (false) or UTF-8 (true). (Default: false) |
234 | 234 | */ |
235 | - public function SetInfo(string $strTitle, string $strSubject, string $strAuthor, string $strKeywords='', bool $isUTF8=false) : void |
|
235 | + public function SetInfo(string $strTitle, string $strSubject, string $strAuthor, string $strKeywords = '', bool $isUTF8 = false) : void |
|
236 | 236 | { |
237 | 237 | $this->SetTitle($strTitle, $isUTF8); |
238 | 238 | $this->SetSubject($strSubject, $isUTF8); |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * @see XPDF:SetSubject() |
299 | 299 | * @see XPDF:SetLogo() |
300 | 300 | */ |
301 | - public function SetPageHeader(string $strTitle, string $strHeaderSubject='', string $strLogo='') : void |
|
301 | + public function SetPageHeader(string $strTitle, string $strHeaderSubject = '', string $strLogo = '') : void |
|
302 | 302 | { |
303 | 303 | $this->strPageTitle = $strTitle; |
304 | 304 | if (strlen($strLogo) > 0) { |
@@ -371,11 +371,11 @@ discard block |
||
371 | 371 | public function InitGrid(string $strFilename = '') : void |
372 | 372 | { |
373 | 373 | $this->fontHeader = new XPDFFont('Arial', 'B', 12); |
374 | - $this->fontSubject = new XPDFFont('Arial', 'I', 8); |
|
375 | - $this->fontFooter = new XPDFFont('Arial', 'I', 8); |
|
376 | - $this->fontColHeader= new XPDFFont('Arial', 'B', 10); |
|
377 | - $this->fontSubHeader= new XPDFFont('Arial', 'B', 10); |
|
378 | - $this->fontRows = new XPDFFont('Arial', '', 10); |
|
374 | + $this->fontSubject = new XPDFFont('Arial', 'I', 8); |
|
375 | + $this->fontFooter = new XPDFFont('Arial', 'I', 8); |
|
376 | + $this->fontColHeader = new XPDFFont('Arial', 'B', 10); |
|
377 | + $this->fontSubHeader = new XPDFFont('Arial', 'B', 10); |
|
378 | + $this->fontRows = new XPDFFont('Arial', '', 10); |
|
379 | 379 | |
380 | 380 | $this->fltLineHeight = 8.0; |
381 | 381 | |
@@ -407,27 +407,27 @@ discard block |
||
407 | 407 | if ($jsonData) { |
408 | 408 | if (property_exists($jsonData, 'fontHeader')) { |
409 | 409 | $oFont = $jsonData->fontHeader; |
410 | - $this->fontHeader = new XPDFFont($oFont->name, $oFont->style, $oFont->size); |
|
410 | + $this->fontHeader = new XPDFFont($oFont->name, $oFont->style, $oFont->size); |
|
411 | 411 | } |
412 | 412 | if (property_exists($jsonData, 'fontSubject')) { |
413 | 413 | $oFont = $jsonData->fontSubject; |
414 | - $this->fontSubject = new XPDFFont($oFont->name, $oFont->style, $oFont->size); |
|
414 | + $this->fontSubject = new XPDFFont($oFont->name, $oFont->style, $oFont->size); |
|
415 | 415 | } |
416 | 416 | if (property_exists($jsonData, 'fontFooter')) { |
417 | 417 | $oFont = $jsonData->fontFooter; |
418 | - $this->fontFooter = new XPDFFont($oFont->name, $oFont->style, $oFont->size); |
|
418 | + $this->fontFooter = new XPDFFont($oFont->name, $oFont->style, $oFont->size); |
|
419 | 419 | } |
420 | 420 | if (property_exists($jsonData, 'fontColHeader')) { |
421 | 421 | $oFont = $jsonData->fontColHeader; |
422 | - $this->fontColHeader= new XPDFFont($oFont->name, $oFont->style, $oFont->size); |
|
422 | + $this->fontColHeader = new XPDFFont($oFont->name, $oFont->style, $oFont->size); |
|
423 | 423 | } |
424 | 424 | if (property_exists($jsonData, 'fontSubHeader')) { |
425 | 425 | $oFont = $jsonData->fontSubHeader; |
426 | - $this->fontSubHeader= new XPDFFont($oFont->name, $oFont->style, $oFont->size); |
|
426 | + $this->fontSubHeader = new XPDFFont($oFont->name, $oFont->style, $oFont->size); |
|
427 | 427 | } |
428 | 428 | if (property_exists($jsonData, 'fontRows')) { |
429 | 429 | $oFont = $jsonData->fontRows; |
430 | - $this->fontRows = new XPDFFont($oFont->name, $oFont->style, $oFont->size); |
|
430 | + $this->fontRows = new XPDFFont($oFont->name, $oFont->style, $oFont->size); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | $this->fltLineHeight = $this->_Property($jsonData, 'dblLineHeight', $this->fltLineHeight); |
@@ -451,9 +451,9 @@ discard block |
||
451 | 451 | $this->bStripped = $this->_Property($jsonData, 'bStripped', $this->bStripped); |
452 | 452 | $this->border = $this->_Property($jsonData, 'border', $this->border); |
453 | 453 | |
454 | - $this->bCalcTotals = $this->_Property($jsonData, 'bCalcTotals', $this->bCalcTotals); |
|
455 | - $this->bPageTotals = $this->_Property($jsonData, 'bPageTotals', $this->bPageTotals); |
|
456 | - $this->bCarryOver = $this->_Property($jsonData, 'bCarryOver', $this->bCarryOver); |
|
454 | + $this->bCalcTotals = $this->_Property($jsonData, 'bCalcTotals', $this->bCalcTotals); |
|
455 | + $this->bPageTotals = $this->_Property($jsonData, 'bPageTotals', $this->bPageTotals); |
|
456 | + $this->bCarryOver = $this->_Property($jsonData, 'bCarryOver', $this->bCarryOver); |
|
457 | 457 | |
458 | 458 | $this->strTotals = $this->_Property($jsonData, 'strTotals', $this->strTotals); |
459 | 459 | $this->strPageTotals = $this->_Property($jsonData, 'strPageTotals', $this->strPageTotals); |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | * @param string $strSuffix |
523 | 523 | * @see XPDF::InitGrid() |
524 | 524 | */ |
525 | - public function SetNumberFormat(int $iDecimals, string $strPrefix='', string $strSuffix='') : void |
|
525 | + public function SetNumberFormat(int $iDecimals, string $strPrefix = '', string $strSuffix = '') : void |
|
526 | 526 | { |
527 | 527 | $this->iNumberDecimals = $iDecimals; |
528 | 528 | $this->strNumberPrefix = $strPrefix; |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | */ |
579 | 579 | public function SetColHeaderFont(string $strFontname, string $strStyle, int $iSize) : void |
580 | 580 | { |
581 | - $this->fontColHeader= new XPDFFont($strFontname, $strStyle, $iSize); |
|
581 | + $this->fontColHeader = new XPDFFont($strFontname, $strStyle, $iSize); |
|
582 | 582 | } |
583 | 583 | |
584 | 584 | /** |
@@ -591,7 +591,7 @@ discard block |
||
591 | 591 | */ |
592 | 592 | public function SetSubHeaderFont(string $strFontname, string $strStyle, int $iSize) : void |
593 | 593 | { |
594 | - $this->fontSubHeader= new XPDFFont($strFontname, $strStyle, $iSize); |
|
594 | + $this->fontSubHeader = new XPDFFont($strFontname, $strStyle, $iSize); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | /** |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | */ |
605 | 605 | public function SetRowFont(string $strFontname, string $strStyle, int $iSize) : void |
606 | 606 | { |
607 | - $this->fontRows = new XPDFFont($strFontname, $strStyle, $iSize); |
|
607 | + $this->fontRows = new XPDFFont($strFontname, $strStyle, $iSize); |
|
608 | 608 | $this->SelectFont($this->fontRows); |
609 | 609 | } |
610 | 610 | |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | * @param string $strFillColor |
655 | 655 | * @param bool $bStripped |
656 | 656 | */ |
657 | - public function SetRowColors(string $strTextColor, string $strDrawColor, string $strFillColor, bool $bStripped=true) : void |
|
657 | + public function SetRowColors(string $strTextColor, string $strDrawColor, string $strFillColor, bool $bStripped = true) : void |
|
658 | 658 | { |
659 | 659 | $this->strRowTextColor = $strTextColor; |
660 | 660 | $this->strRowDrawColor = $strDrawColor; |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | * @see XPDF::InitGrid() |
686 | 686 | * @param int $iTotals combination of |
687 | 687 | */ |
688 | - public function EnableTotals(int $iTotals=self::TOTALS) : void |
|
688 | + public function EnableTotals(int $iTotals = self::TOTALS) : void |
|
689 | 689 | { |
690 | 690 | $this->bCalcTotals = ($iTotals & self::TOTALS) != 0; |
691 | 691 | $this->bPageTotals = ($iTotals & self::PAGE_TOTALS) != 0; |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | * @param string $strPageTotals |
708 | 708 | * @param string $strCarryOver |
709 | 709 | */ |
710 | - public function SetTotalsText(string $strTotals, string $strPageTotals='', string $strCarryOver='') : void |
|
710 | + public function SetTotalsText(string $strTotals, string $strPageTotals = '', string $strCarryOver = '') : void |
|
711 | 711 | { |
712 | 712 | $this->strTotals = $strTotals; |
713 | 713 | if (strlen($strPageTotals) > 0) { |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | * @param int $wFlags Flags to define behaviour for column |
729 | 729 | * @return int Index of the inserted col |
730 | 730 | */ |
731 | - public function AddCol(string $strColHeader, float $fltWidth, string $strAlign, string $strField, int $wFlags=0) : int |
|
731 | + public function AddCol(string $strColHeader, float $fltWidth, string $strAlign, string $strField, int $wFlags = 0) : int |
|
732 | 732 | { |
733 | 733 | $this->iMaxCol++; |
734 | 734 | $this->aColWidth[$this->iMaxCol] = $fltWidth; |
@@ -831,11 +831,11 @@ discard block |
||
831 | 831 | * @param string $strTotals |
832 | 832 | * @param string $strHeader |
833 | 833 | */ |
834 | - public function StartGroup(string $strTotals, ?string $strHeader=null) : void |
|
834 | + public function StartGroup(string $strTotals, ?string $strHeader = null) : void |
|
835 | 835 | { |
836 | 836 | $this->strSubTotals = $strTotals; |
837 | 837 | $iCount = count($this->aSubTotals); |
838 | - for ($i=0; $i < $iCount; $i++) { |
|
838 | + for ($i = 0; $i < $iCount; $i++) { |
|
839 | 839 | $this->aSubTotals[$i] = 0.0; |
840 | 840 | } |
841 | 841 | if ($strHeader) { |
@@ -860,7 +860,7 @@ discard block |
||
860 | 860 | * @param int $level |
861 | 861 | * @param int $y |
862 | 862 | */ |
863 | - public function Bookmark(string $txt, bool $isUTF8=false, int $level=0, int $y=0) : void |
|
863 | + public function Bookmark(string $txt, bool $isUTF8 = false, int $level = 0, int $y = 0) : void |
|
864 | 864 | { |
865 | 865 | if (!$isUTF8) { |
866 | 866 | $txt = utf8_encode($txt); |
@@ -888,7 +888,7 @@ discard block |
||
888 | 888 | */ |
889 | 889 | public function SelectTextColor(string $strColor) : void |
890 | 890 | { |
891 | - $r=0; $g=0; $b=0; |
|
891 | + $r = 0; $g = 0; $b = 0; |
|
892 | 892 | $this->_GetRGB($strColor, $r, $g, $b); |
893 | 893 | $this->SetTextColor($r, $g, $b); |
894 | 894 | } |
@@ -899,7 +899,7 @@ discard block |
||
899 | 899 | */ |
900 | 900 | public function SelectDrawColor(string $strColor) : void |
901 | 901 | { |
902 | - $r=0; $g=0; $b=0; |
|
902 | + $r = 0; $g = 0; $b = 0; |
|
903 | 903 | $this->_GetRGB($strColor, $r, $g, $b); |
904 | 904 | $this->SetDrawColor($r, $g, $b); |
905 | 905 | } |
@@ -910,7 +910,7 @@ discard block |
||
910 | 910 | */ |
911 | 911 | public function SelectFillColor(string $strColor) : void |
912 | 912 | { |
913 | - $r=0; $g=0; $b=0; |
|
913 | + $r = 0; $g = 0; $b = 0; |
|
914 | 914 | $this->_GetRGB($strColor, $r, $g, $b); |
915 | 915 | $this->SetFillColor($r, $g, $b); |
916 | 916 | } |
@@ -1136,7 +1136,7 @@ discard block |
||
1136 | 1136 | $bFill = $this->bStripped && (($this->iRow % 2) == 0); |
1137 | 1137 | |
1138 | 1138 | // calc totals if enabled |
1139 | - if ($this->bCalcTotals && ($wFlags & self::FLAG_TOTALS_CALC) != 0) { |
|
1139 | + if ($this->bCalcTotals && ($wFlags & self::FLAG_TOTALS_CALC) != 0) { |
|
1140 | 1140 | if (is_numeric($row[$field]) || is_float($row[$field])) { |
1141 | 1141 | $this->aTotals[$i] += $row[$field]; |
1142 | 1142 | $this->aSubTotals[$i] += $row[$field]; |
@@ -1161,7 +1161,7 @@ discard block |
||
1161 | 1161 | $link = ''; |
1162 | 1162 | if (($wFlags & self::FLAG_INT_LINK) != 0) { |
1163 | 1163 | $link = $this->InternalLink($i, $row); |
1164 | - $this->SetFont('','U'); |
|
1164 | + $this->SetFont('', 'U'); |
|
1165 | 1165 | $this->SelectTextColor($this->strLinkTextColor); |
1166 | 1166 | } |
1167 | 1167 | |
@@ -1175,7 +1175,7 @@ discard block |
||
1175 | 1175 | if (isset($this->aImgInfo[$i])) { |
1176 | 1176 | $fltTop += $this->aImgInfo[$i]['fltTop']; |
1177 | 1177 | $fltLeft += $this->aImgInfo[$i]['fltLeft']; |
1178 | - if ($this->aImgInfo[$i]['fltHeight'] > 0 ) { |
|
1178 | + if ($this->aImgInfo[$i]['fltHeight'] > 0) { |
|
1179 | 1179 | $fltHeight = $this->aImgInfo[$i]['fltHeight']; |
1180 | 1180 | } |
1181 | 1181 | if ($this->aImgInfo[$i]['fltWidth'] > 0) { |
@@ -1215,7 +1215,7 @@ discard block |
||
1215 | 1215 | $this->SetLineWidth(0.2); |
1216 | 1216 | $this->SelectFont($this->fontSubHeader); |
1217 | 1217 | } |
1218 | - $aTotals = $this->aTotals; |
|
1218 | + $aTotals = $this->aTotals; |
|
1219 | 1219 | $strText = ''; |
1220 | 1220 | switch ($iTotals) { |
1221 | 1221 | case self::TOTALS: |
@@ -1229,7 +1229,7 @@ discard block |
||
1229 | 1229 | break; |
1230 | 1230 | case self::SUB_TOTALS: |
1231 | 1231 | $strText = $this->strSubTotals; |
1232 | - $aTotals = $this->aSubTotals; |
|
1232 | + $aTotals = $this->aSubTotals; |
|
1233 | 1233 | break; |
1234 | 1234 | default: |
1235 | 1235 | break; |
@@ -1311,8 +1311,8 @@ discard block |
||
1311 | 1311 | */ |
1312 | 1312 | protected function Col(int $iCol, array $row, /** @scrutinizer ignore-unused */ bool &$bFill) : string |
1313 | 1313 | { |
1314 | - $strCol =''; |
|
1315 | - switch($iCol) { |
|
1314 | + $strCol = ''; |
|
1315 | + switch ($iCol) { |
|
1316 | 1316 | case self::COL_ROW_NR: |
1317 | 1317 | $strCol = $this->iRow; |
1318 | 1318 | break; |
@@ -1342,14 +1342,14 @@ discard block |
||
1342 | 1342 | protected function _GetRGB(string $strColor, int &$r, int &$g, int &$b) : void |
1343 | 1343 | { |
1344 | 1344 | if ($strColor[0] == '#') { |
1345 | - if (strlen( $strColor ) == 7) { |
|
1346 | - $r = intval( substr( $strColor, 1, 2 ), 16); |
|
1347 | - $g = intval( substr( $strColor, 3, 2 ), 16); |
|
1348 | - $b = intval( substr( $strColor, 5, 2 ), 16); |
|
1349 | - } elseif (strlen( $strColor ) == 4) { |
|
1350 | - $r = intval( substr( $strColor, 1, 1 ), 16); |
|
1351 | - $g = intval( substr( $strColor, 2, 1 ), 16); |
|
1352 | - $b = intval( substr( $strColor, 3, 1 ), 16); |
|
1345 | + if (strlen($strColor) == 7) { |
|
1346 | + $r = intval(substr($strColor, 1, 2), 16); |
|
1347 | + $g = intval(substr($strColor, 3, 2), 16); |
|
1348 | + $b = intval(substr($strColor, 5, 2), 16); |
|
1349 | + } elseif (strlen($strColor) == 4) { |
|
1350 | + $r = intval(substr($strColor, 1, 1), 16); |
|
1351 | + $g = intval(substr($strColor, 2, 1), 16); |
|
1352 | + $b = intval(substr($strColor, 3, 1), 16); |
|
1353 | 1353 | $r = $r + (16 * $r); |
1354 | 1354 | $g = $g + (16 * $g); |
1355 | 1355 | $b = $b + (16 * $b); |
@@ -1388,12 +1388,12 @@ discard block |
||
1388 | 1388 | // Restore line width |
1389 | 1389 | if ($this->LineWidth != $a['lw']) { |
1390 | 1390 | $this->LineWidth = $a['lw']; |
1391 | - $this->_out(sprintf( '%.2F w', $a['lw'] * $this->k )); |
|
1391 | + $this->_out(sprintf('%.2F w', $a['lw'] * $this->k)); |
|
1392 | 1392 | } |
1393 | 1393 | // Restore font |
1394 | 1394 | if (($a['family'] != $this->FontFamily) || |
1395 | - $a['style'] != $this->FontStyle || |
|
1396 | - $a['size'] != $this->FontSizePt) { |
|
1395 | + $a['style'] != $this->FontStyle || |
|
1396 | + $a['size'] != $this->FontSizePt) { |
|
1397 | 1397 | $this->SetFont($a['family'], $a['style'], $a['size']); |
1398 | 1398 | } |
1399 | 1399 | $this->underline = $a['ul']; |
@@ -1401,11 +1401,11 @@ discard block |
||
1401 | 1401 | // Restore colors |
1402 | 1402 | if ($this->DrawColor != $a['dc']) { |
1403 | 1403 | $this->DrawColor = $a['dc']; |
1404 | - $this->_out( $a['dc']); |
|
1404 | + $this->_out($a['dc']); |
|
1405 | 1405 | } |
1406 | 1406 | if ($this->FillColor != $a['fc']) { |
1407 | 1407 | $this->FillColor = $a['fc']; |
1408 | - $this->_out( $a['fc']); |
|
1408 | + $this->_out($a['fc']); |
|
1409 | 1409 | } |
1410 | 1410 | $this->TextColor = $a['tc']; |
1411 | 1411 | $this->ColorFlag = $a['cf']; |
@@ -1419,7 +1419,7 @@ discard block |
||
1419 | 1419 | * @param mixed $default |
1420 | 1420 | * @return mixed |
1421 | 1421 | */ |
1422 | - protected function _Property(\stdClass $obj, string $strName, $default='') |
|
1422 | + protected function _Property(\stdClass $obj, string $strName, $default = '') |
|
1423 | 1423 | { |
1424 | 1424 | $value = $default; |
1425 | 1425 | if (property_exists($obj, $strName)) { |
@@ -1438,7 +1438,7 @@ discard block |
||
1438 | 1438 | if ($this->strCharset != 'UTF-8') { |
1439 | 1439 | $strText = iconv('UTF-8', $this->strCharset, $strText); |
1440 | 1440 | } |
1441 | - return html_entity_decode( $strText, ENT_QUOTES, 'UTF-8'); |
|
1441 | + return html_entity_decode($strText, ENT_QUOTES, 'UTF-8'); |
|
1442 | 1442 | } |
1443 | 1443 | |
1444 | 1444 | /** |
@@ -1513,7 +1513,7 @@ discard block |
||
1513 | 1513 | * @param bool $bSymbol |
1514 | 1514 | * @return string |
1515 | 1515 | */ |
1516 | - protected function _FormatCurrency(float $fltValue, bool $bSymbol=true) : string |
|
1516 | + protected function _FormatCurrency(float $fltValue, bool $bSymbol = true) : string |
|
1517 | 1517 | { |
1518 | 1518 | if (!$this->bInvalidLocale) { |
1519 | 1519 | $li = localeconv(); |
@@ -1613,13 +1613,13 @@ discard block |
||
1613 | 1613 | protected function _putbookmarks() : void |
1614 | 1614 | { |
1615 | 1615 | $nb = count($this->outlines); |
1616 | - if( $nb==0 ) { |
|
1616 | + if ($nb == 0) { |
|
1617 | 1617 | return; |
1618 | 1618 | } |
1619 | 1619 | $lru = array(); |
1620 | 1620 | $level = 0; |
1621 | 1621 | foreach ($this->outlines as $i => $o) { |
1622 | - if ($o['l']>0) { |
|
1622 | + if ($o['l'] > 0) { |
|
1623 | 1623 | $parent = $lru[$o['l'] - 1]; |
1624 | 1624 | // Set parent and last pointers |
1625 | 1625 | $this->outlines[$i]['parent'] = $parent; |
@@ -1641,7 +1641,7 @@ discard block |
||
1641 | 1641 | $level = $o['l']; |
1642 | 1642 | } |
1643 | 1643 | // Outline items |
1644 | - $n = $this->n+1; |
|
1644 | + $n = $this->n + 1; |
|
1645 | 1645 | foreach ($this->outlines as $i=>$o) { |
1646 | 1646 | $this->_newobj(); |
1647 | 1647 | $this->_put('<</Title ' . $this->_textstring($o['t'])); |
@@ -1666,7 +1666,7 @@ discard block |
||
1666 | 1666 | $this->_newobj(); |
1667 | 1667 | $this->outlineRoot = $this->n; |
1668 | 1668 | $this->_put('<</Type /Outlines /First ' . $n . ' 0 R'); |
1669 | - $this->_put('/Last ' . ($n+$lru[0]) . ' 0 R>>'); |
|
1669 | + $this->_put('/Last ' . ($n + $lru[0]) . ' 0 R>>'); |
|
1670 | 1670 | $this->_put('endobj'); |
1671 | 1671 | } |
1672 | 1672 | |
@@ -1680,7 +1680,7 @@ discard block |
||
1680 | 1680 | { |
1681 | 1681 | parent::_putcatalog(); |
1682 | 1682 | if (count($this->outlines) > 0) { |
1683 | - $this->_put('/Outlines '.$this->outlineRoot.' 0 R'); |
|
1683 | + $this->_put('/Outlines ' . $this->outlineRoot . ' 0 R'); |
|
1684 | 1684 | $this->_put('/PageMode /UseOutlines'); |
1685 | 1685 | } |
1686 | 1686 | } |