@@ -173,74 +173,74 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | public function __construct(string $orientation='P', string $unit='mm', $size='A4') |
| 175 | 175 | {
|
| 176 | - // Some checks |
|
| 177 | - $this->doChecks(); |
|
| 176 | + // Some checks |
|
| 177 | + $this->doChecks(); |
|
| 178 | 178 | |
| 179 | - $this->getFontPath(); |
|
| 179 | + $this->getFontPath(); |
|
| 180 | 180 | |
| 181 | - // Core fonts |
|
| 182 | - $this->CoreFonts = array('courier', 'helvetica', 'times', 'symbol', 'zapfdingbats');
|
|
| 181 | + // Core fonts |
|
| 182 | + $this->CoreFonts = array('courier', 'helvetica', 'times', 'symbol', 'zapfdingbats');
|
|
| 183 | 183 | |
| 184 | - // Scale factor |
|
| 185 | - switch ($unit) {
|
|
| 186 | - case 'pt': |
|
| 187 | - $this->k = 1; |
|
| 188 | - break; |
|
| 189 | - case 'mm': |
|
| 190 | - $this->k = 72/25.4; |
|
| 191 | - break; |
|
| 192 | - case 'cm': |
|
| 193 | - $this->k = 72/2.54; |
|
| 194 | - break; |
|
| 195 | - case 'in': |
|
| 196 | - $this->k = 72; |
|
| 197 | - break; |
|
| 198 | - default: |
|
| 199 | - $this->Error('Incorrect unit: ' . $unit);
|
|
| 200 | - break; |
|
| 201 | - } |
|
| 184 | + // Scale factor |
|
| 185 | + switch ($unit) {
|
|
| 186 | + case 'pt': |
|
| 187 | + $this->k = 1; |
|
| 188 | + break; |
|
| 189 | + case 'mm': |
|
| 190 | + $this->k = 72/25.4; |
|
| 191 | + break; |
|
| 192 | + case 'cm': |
|
| 193 | + $this->k = 72/2.54; |
|
| 194 | + break; |
|
| 195 | + case 'in': |
|
| 196 | + $this->k = 72; |
|
| 197 | + break; |
|
| 198 | + default: |
|
| 199 | + $this->Error('Incorrect unit: ' . $unit);
|
|
| 200 | + break; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - // Page sizes |
|
| 204 | - $size = $this->getPageSize($size); |
|
| 205 | - $this->DefPageSize = $size; |
|
| 206 | - $this->CurPageSize = $size; |
|
| 203 | + // Page sizes |
|
| 204 | + $size = $this->getPageSize($size); |
|
| 205 | + $this->DefPageSize = $size; |
|
| 206 | + $this->CurPageSize = $size; |
|
| 207 | 207 | |
| 208 | - // Page orientation |
|
| 209 | - $orientation = strtolower($orientation); |
|
| 210 | - if ($orientation == 'p' || $orientation == 'portrait') {
|
|
| 211 | - $this->DefOrientation = 'P'; |
|
| 212 | - $this->w = $size[0]; |
|
| 213 | - $this->h = $size[1]; |
|
| 214 | - } elseif ($orientation == 'l' || $orientation == 'landscape') {
|
|
| 215 | - $this->DefOrientation = 'L'; |
|
| 216 | - $this->w = $size[1]; |
|
| 217 | - $this->h = $size[0]; |
|
| 218 | - } else {
|
|
| 219 | - $this->Error('Incorrect orientation: ' . $orientation);
|
|
| 220 | - } |
|
| 221 | - $this->CurOrientation = $this->DefOrientation; |
|
| 222 | - $this->wPt = $this->w * $this->k; |
|
| 223 | - $this->hPt = $this->h * $this->k; |
|
| 208 | + // Page orientation |
|
| 209 | + $orientation = strtolower($orientation); |
|
| 210 | + if ($orientation == 'p' || $orientation == 'portrait') {
|
|
| 211 | + $this->DefOrientation = 'P'; |
|
| 212 | + $this->w = $size[0]; |
|
| 213 | + $this->h = $size[1]; |
|
| 214 | + } elseif ($orientation == 'l' || $orientation == 'landscape') {
|
|
| 215 | + $this->DefOrientation = 'L'; |
|
| 216 | + $this->w = $size[1]; |
|
| 217 | + $this->h = $size[0]; |
|
| 218 | + } else {
|
|
| 219 | + $this->Error('Incorrect orientation: ' . $orientation);
|
|
| 220 | + } |
|
| 221 | + $this->CurOrientation = $this->DefOrientation; |
|
| 222 | + $this->wPt = $this->w * $this->k; |
|
| 223 | + $this->hPt = $this->h * $this->k; |
|
| 224 | 224 | |
| 225 | - // set some default values |
|
| 226 | - // - no page rotation |
|
| 227 | - // - page margins 1cm |
|
| 228 | - // - interior cell margin 1mm |
|
| 229 | - // - line width 0.2mm |
|
| 230 | - // - automatic page break |
|
| 231 | - // - default display mode |
|
| 232 | - // - enable compression |
|
| 233 | - // - PDF version 1.3 |
|
| 234 | - $this->CurRotation = 0; |
|
| 225 | + // set some default values |
|
| 226 | + // - no page rotation |
|
| 227 | + // - page margins 1cm |
|
| 228 | + // - interior cell margin 1mm |
|
| 229 | + // - line width 0.2mm |
|
| 230 | + // - automatic page break |
|
| 231 | + // - default display mode |
|
| 232 | + // - enable compression |
|
| 233 | + // - PDF version 1.3 |
|
| 234 | + $this->CurRotation = 0; |
|
| 235 | 235 | |
| 236 | - $margin = 28.35 / $this->k; |
|
| 237 | - $this->setMargins($margin, $margin); |
|
| 238 | - $this->cMargin = $margin / 10; |
|
| 239 | - $this->LineWidth = 0.567 / $this->k; |
|
| 240 | - $this->setAutoPageBreak(true, 2 * $margin); |
|
| 241 | - $this->setDisplayMode('default');
|
|
| 242 | - $this->setCompression(true); |
|
| 243 | - $this->PDFVersion = '1.3'; |
|
| 236 | + $margin = 28.35 / $this->k; |
|
| 237 | + $this->setMargins($margin, $margin); |
|
| 238 | + $this->cMargin = $margin / 10; |
|
| 239 | + $this->LineWidth = 0.567 / $this->k; |
|
| 240 | + $this->setAutoPageBreak(true, 2 * $margin); |
|
| 241 | + $this->setDisplayMode('default');
|
|
| 242 | + $this->setCompression(true); |
|
| 243 | + $this->PDFVersion = '1.3'; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -252,12 +252,12 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | public function SetMargins(float $left, float $top, ?float $right=null) : void |
| 254 | 254 | {
|
| 255 | - // Set left, top and right margins |
|
| 256 | - $this->lMargin = $left; |
|
| 257 | - $this->tMargin = $top; |
|
| 258 | - if($right===null) |
|
| 259 | - $right = $left; |
|
| 260 | - $this->rMargin = $right; |
|
| 255 | + // Set left, top and right margins |
|
| 256 | + $this->lMargin = $left; |
|
| 257 | + $this->tMargin = $top; |
|
| 258 | + if($right===null) |
|
| 259 | + $right = $left; |
|
| 260 | + $this->rMargin = $right; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -268,10 +268,10 @@ discard block |
||
| 268 | 268 | */ |
| 269 | 269 | public function SetLeftMargin(float $margin) : void |
| 270 | 270 | {
|
| 271 | - // Set left margin |
|
| 272 | - $this->lMargin = $margin; |
|
| 273 | - if($this->page>0 && $this->x<$margin) |
|
| 274 | - $this->x = $margin; |
|
| 271 | + // Set left margin |
|
| 272 | + $this->lMargin = $margin; |
|
| 273 | + if($this->page>0 && $this->x<$margin) |
|
| 274 | + $this->x = $margin; |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -281,8 +281,8 @@ discard block |
||
| 281 | 281 | */ |
| 282 | 282 | public function SetTopMargin(float $margin) : void |
| 283 | 283 | {
|
| 284 | - // Set top margin |
|
| 285 | - $this->tMargin = $margin; |
|
| 284 | + // Set top margin |
|
| 285 | + $this->tMargin = $margin; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -292,8 +292,8 @@ discard block |
||
| 292 | 292 | */ |
| 293 | 293 | public function SetRightMargin(float $margin) : void |
| 294 | 294 | {
|
| 295 | - // Set right margin |
|
| 296 | - $this->rMargin = $margin; |
|
| 295 | + // Set right margin |
|
| 296 | + $this->rMargin = $margin; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
@@ -306,10 +306,10 @@ discard block |
||
| 306 | 306 | */ |
| 307 | 307 | public function SetAutoPageBreak(bool $auto, float $margin=0) : void |
| 308 | 308 | {
|
| 309 | - // Set auto page break mode and triggering margin |
|
| 310 | - $this->AutoPageBreak = $auto; |
|
| 311 | - $this->bMargin = $margin; |
|
| 312 | - $this->PageBreakTrigger = $this->h-$margin; |
|
| 309 | + // Set auto page break mode and triggering margin |
|
| 310 | + $this->AutoPageBreak = $auto; |
|
| 311 | + $this->bMargin = $margin; |
|
| 312 | + $this->PageBreakTrigger = $this->h-$margin; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | /** |
@@ -342,15 +342,15 @@ discard block |
||
| 342 | 342 | */ |
| 343 | 343 | public function SetDisplayMode($zoom, string $layout='default') : void |
| 344 | 344 | {
|
| 345 | - // Set display mode in viewer |
|
| 346 | - if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) |
|
| 347 | - $this->ZoomMode = $zoom; |
|
| 348 | - else |
|
| 349 | - $this->Error('Incorrect zoom display mode: '.$zoom);
|
|
| 350 | - if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') |
|
| 351 | - $this->LayoutMode = $layout; |
|
| 352 | - else |
|
| 353 | - $this->Error('Incorrect layout display mode: '.$layout);
|
|
| 345 | + // Set display mode in viewer |
|
| 346 | + if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) |
|
| 347 | + $this->ZoomMode = $zoom; |
|
| 348 | + else |
|
| 349 | + $this->Error('Incorrect zoom display mode: '.$zoom);
|
|
| 350 | + if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') |
|
| 351 | + $this->LayoutMode = $layout; |
|
| 352 | + else |
|
| 353 | + $this->Error('Incorrect layout display mode: '.$layout);
|
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -364,11 +364,11 @@ discard block |
||
| 364 | 364 | */ |
| 365 | 365 | public function SetCompression(bool $compress) : void |
| 366 | 366 | {
|
| 367 | - // Set page compression |
|
| 368 | - if(function_exists('gzcompress'))
|
|
| 369 | - $this->compress = $compress; |
|
| 370 | - else |
|
| 371 | - $this->compress = false; |
|
| 367 | + // Set page compression |
|
| 368 | + if(function_exists('gzcompress'))
|
|
| 369 | + $this->compress = $compress; |
|
| 370 | + else |
|
| 371 | + $this->compress = false; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -378,8 +378,8 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | public function SetTitle(string $title, bool $isUTF8=false) : void |
| 380 | 380 | {
|
| 381 | - // Title of document |
|
| 382 | - $this->metadata['Title'] = $isUTF8 ? $title : utf8_encode($title); |
|
| 381 | + // Title of document |
|
| 382 | + $this->metadata['Title'] = $isUTF8 ? $title : utf8_encode($title); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -389,8 +389,8 @@ discard block |
||
| 389 | 389 | */ |
| 390 | 390 | public function SetAuthor(string $author, bool $isUTF8=false) : void |
| 391 | 391 | {
|
| 392 | - // Author of document |
|
| 393 | - $this->metadata['Author'] = $isUTF8 ? $author : utf8_encode($author); |
|
| 392 | + // Author of document |
|
| 393 | + $this->metadata['Author'] = $isUTF8 ? $author : utf8_encode($author); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -400,8 +400,8 @@ discard block |
||
| 400 | 400 | */ |
| 401 | 401 | public function SetSubject(string $subject, bool $isUTF8=false) : void |
| 402 | 402 | {
|
| 403 | - // Subject of document |
|
| 404 | - $this->metadata['Subject'] = $isUTF8 ? $subject : utf8_encode($subject); |
|
| 403 | + // Subject of document |
|
| 404 | + $this->metadata['Subject'] = $isUTF8 ? $subject : utf8_encode($subject); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | /** |
@@ -411,8 +411,8 @@ discard block |
||
| 411 | 411 | */ |
| 412 | 412 | public function SetKeywords(string $keywords, bool $isUTF8=false) : void |
| 413 | 413 | {
|
| 414 | - // Keywords of document |
|
| 415 | - $this->metadata['Keywords'] = $isUTF8 ? $keywords : utf8_encode($keywords); |
|
| 414 | + // Keywords of document |
|
| 415 | + $this->metadata['Keywords'] = $isUTF8 ? $keywords : utf8_encode($keywords); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | /** |
@@ -422,8 +422,8 @@ discard block |
||
| 422 | 422 | */ |
| 423 | 423 | public function SetCreator(string $creator, bool $isUTF8=false) : void |
| 424 | 424 | {
|
| 425 | - // Creator of document |
|
| 426 | - $this->metadata['Creator'] = $isUTF8 ? $creator : utf8_encode($creator); |
|
| 425 | + // Creator of document |
|
| 426 | + $this->metadata['Creator'] = $isUTF8 ? $creator : utf8_encode($creator); |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | /** |
@@ -432,8 +432,8 @@ discard block |
||
| 432 | 432 | */ |
| 433 | 433 | public function AliasNbPages(string $alias='{nb}') : void
|
| 434 | 434 | {
|
| 435 | - // Define an alias for total number of pages |
|
| 436 | - $this->AliasNbPages = $alias; |
|
| 435 | + // Define an alias for total number of pages |
|
| 436 | + $this->AliasNbPages = $alias; |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | /** |
@@ -446,8 +446,8 @@ discard block |
||
| 446 | 446 | */ |
| 447 | 447 | public function Error(string $msg) : void |
| 448 | 448 | {
|
| 449 | - // Fatal error |
|
| 450 | - throw new \Exception('FPDF error: '.$msg);
|
|
| 449 | + // Fatal error |
|
| 450 | + throw new \Exception('FPDF error: '.$msg);
|
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | /** |
@@ -458,19 +458,19 @@ discard block |
||
| 458 | 458 | */ |
| 459 | 459 | public function Close() : void |
| 460 | 460 | {
|
| 461 | - // Terminate document |
|
| 462 | - if($this->state==3) |
|
| 463 | - return; |
|
| 464 | - if($this->page==0) |
|
| 465 | - $this->addPage(); |
|
| 466 | - // Page footer |
|
| 467 | - $this->InFooter = true; |
|
| 468 | - $this->Footer(); |
|
| 469 | - $this->InFooter = false; |
|
| 470 | - // Close page |
|
| 471 | - $this->_endpage(); |
|
| 472 | - // Close document |
|
| 473 | - $this->_enddoc(); |
|
| 461 | + // Terminate document |
|
| 462 | + if($this->state==3) |
|
| 463 | + return; |
|
| 464 | + if($this->page==0) |
|
| 465 | + $this->addPage(); |
|
| 466 | + // Page footer |
|
| 467 | + $this->InFooter = true; |
|
| 468 | + $this->Footer(); |
|
| 469 | + $this->InFooter = false; |
|
| 470 | + // Close page |
|
| 471 | + $this->_endpage(); |
|
| 472 | + // Close document |
|
| 473 | + $this->_enddoc(); |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | /** |
@@ -503,72 +503,72 @@ discard block |
||
| 503 | 503 | */ |
| 504 | 504 | public function AddPage(string $orientation='', $size='', int $rotation=0) : void |
| 505 | 505 | {
|
| 506 | - // Start a new page |
|
| 506 | + // Start a new page |
|
| 507 | 507 | if ($this->state == 3) {
|
| 508 | - $this->Error('The document is closed');
|
|
| 509 | - } |
|
| 510 | - $family = $this->FontFamily; |
|
| 511 | - $style = $this->FontStyle . ($this->underline ? 'U' : ''); |
|
| 512 | - $fontsize = $this->FontSizePt; |
|
| 513 | - $lw = $this->LineWidth; |
|
| 514 | - $dc = $this->DrawColor; |
|
| 515 | - $fc = $this->FillColor; |
|
| 516 | - $tc = $this->TextColor; |
|
| 517 | - $cf = $this->ColorFlag; |
|
| 518 | - if ($this->page > 0) {
|
|
| 519 | - // Page footer |
|
| 520 | - $this->InFooter = true; |
|
| 521 | - $this->Footer(); |
|
| 522 | - $this->InFooter = false; |
|
| 523 | - // Close page |
|
| 524 | - $this->_endpage(); |
|
| 525 | - } |
|
| 526 | - // Start new page |
|
| 527 | - $this->_beginpage($orientation, $size, $rotation); |
|
| 528 | - // Set line cap style to square |
|
| 529 | - $this->_out('2 J');
|
|
| 530 | - // Set line width |
|
| 531 | - $this->LineWidth = $lw; |
|
| 532 | - $this->_out(sprintf('%.2F w', $lw * $this->k));
|
|
| 533 | - // Set font |
|
| 534 | - if ($family) {
|
|
| 535 | - $this->setFont($family, $style, $fontsize); |
|
| 536 | - } |
|
| 537 | - // Set colors |
|
| 538 | - $this->DrawColor = $dc; |
|
| 539 | - if ($dc != '0 G') {
|
|
| 540 | - $this->_out($dc); |
|
| 541 | - } |
|
| 542 | - $this->FillColor = $fc; |
|
| 543 | - if ($fc != '0 g') {
|
|
| 544 | - $this->_out($fc); |
|
| 545 | - } |
|
| 546 | - $this->TextColor = $tc; |
|
| 547 | - $this->ColorFlag = $cf; |
|
| 548 | - // Page header |
|
| 549 | - $this->InHeader = true; |
|
| 550 | - $this->Header(); |
|
| 551 | - $this->InHeader = false; |
|
| 552 | - // Restore line width |
|
| 553 | - if ($this->LineWidth != $lw) {
|
|
| 554 | - $this->LineWidth = $lw; |
|
| 555 | - $this->_out(sprintf('%.2F w', $lw * $this->k));
|
|
| 556 | - } |
|
| 557 | - // Restore font |
|
| 558 | - if ($family) {
|
|
| 559 | - $this->setFont($family, $style, $fontsize); |
|
| 560 | - } |
|
| 561 | - // Restore colors |
|
| 562 | - if ($this->DrawColor != $dc) {
|
|
| 563 | - $this->DrawColor = $dc; |
|
| 564 | - $this->_out($dc); |
|
| 565 | - } |
|
| 566 | - if ($this->FillColor != $fc) {
|
|
| 567 | - $this->FillColor = $fc; |
|
| 568 | - $this->_out($fc); |
|
| 569 | - } |
|
| 570 | - $this->TextColor = $tc; |
|
| 571 | - $this->ColorFlag = $cf; |
|
| 508 | + $this->Error('The document is closed');
|
|
| 509 | + } |
|
| 510 | + $family = $this->FontFamily; |
|
| 511 | + $style = $this->FontStyle . ($this->underline ? 'U' : ''); |
|
| 512 | + $fontsize = $this->FontSizePt; |
|
| 513 | + $lw = $this->LineWidth; |
|
| 514 | + $dc = $this->DrawColor; |
|
| 515 | + $fc = $this->FillColor; |
|
| 516 | + $tc = $this->TextColor; |
|
| 517 | + $cf = $this->ColorFlag; |
|
| 518 | + if ($this->page > 0) {
|
|
| 519 | + // Page footer |
|
| 520 | + $this->InFooter = true; |
|
| 521 | + $this->Footer(); |
|
| 522 | + $this->InFooter = false; |
|
| 523 | + // Close page |
|
| 524 | + $this->_endpage(); |
|
| 525 | + } |
|
| 526 | + // Start new page |
|
| 527 | + $this->_beginpage($orientation, $size, $rotation); |
|
| 528 | + // Set line cap style to square |
|
| 529 | + $this->_out('2 J');
|
|
| 530 | + // Set line width |
|
| 531 | + $this->LineWidth = $lw; |
|
| 532 | + $this->_out(sprintf('%.2F w', $lw * $this->k));
|
|
| 533 | + // Set font |
|
| 534 | + if ($family) {
|
|
| 535 | + $this->setFont($family, $style, $fontsize); |
|
| 536 | + } |
|
| 537 | + // Set colors |
|
| 538 | + $this->DrawColor = $dc; |
|
| 539 | + if ($dc != '0 G') {
|
|
| 540 | + $this->_out($dc); |
|
| 541 | + } |
|
| 542 | + $this->FillColor = $fc; |
|
| 543 | + if ($fc != '0 g') {
|
|
| 544 | + $this->_out($fc); |
|
| 545 | + } |
|
| 546 | + $this->TextColor = $tc; |
|
| 547 | + $this->ColorFlag = $cf; |
|
| 548 | + // Page header |
|
| 549 | + $this->InHeader = true; |
|
| 550 | + $this->Header(); |
|
| 551 | + $this->InHeader = false; |
|
| 552 | + // Restore line width |
|
| 553 | + if ($this->LineWidth != $lw) {
|
|
| 554 | + $this->LineWidth = $lw; |
|
| 555 | + $this->_out(sprintf('%.2F w', $lw * $this->k));
|
|
| 556 | + } |
|
| 557 | + // Restore font |
|
| 558 | + if ($family) {
|
|
| 559 | + $this->setFont($family, $style, $fontsize); |
|
| 560 | + } |
|
| 561 | + // Restore colors |
|
| 562 | + if ($this->DrawColor != $dc) {
|
|
| 563 | + $this->DrawColor = $dc; |
|
| 564 | + $this->_out($dc); |
|
| 565 | + } |
|
| 566 | + if ($this->FillColor != $fc) {
|
|
| 567 | + $this->FillColor = $fc; |
|
| 568 | + $this->_out($fc); |
|
| 569 | + } |
|
| 570 | + $this->TextColor = $tc; |
|
| 571 | + $this->ColorFlag = $cf; |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | */ |
| 580 | 580 | public function Header() : void |
| 581 | 581 | {
|
| 582 | - // To be implemented in your own inherited class |
|
| 582 | + // To be implemented in your own inherited class |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | /** |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | */ |
| 591 | 591 | public function Footer() : void |
| 592 | 592 | {
|
| 593 | - // To be implemented in your own inherited class |
|
| 593 | + // To be implemented in your own inherited class |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -599,8 +599,8 @@ discard block |
||
| 599 | 599 | */ |
| 600 | 600 | public function PageNo() : int |
| 601 | 601 | {
|
| 602 | - // Get current page number |
|
| 603 | - return $this->page; |
|
| 602 | + // Get current page number |
|
| 603 | + return $this->page; |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | /** |
@@ -613,14 +613,14 @@ discard block |
||
| 613 | 613 | */ |
| 614 | 614 | public function SetDrawColor(int $r, ?int $g=null, ?int $b=null) : void |
| 615 | 615 | {
|
| 616 | - // Set color for all stroking operations |
|
| 616 | + // Set color for all stroking operations |
|
| 617 | 617 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) {
|
| 618 | - $this->DrawColor = sprintf('%.3F G', $r / 255);
|
|
| 618 | + $this->DrawColor = sprintf('%.3F G', $r / 255);
|
|
| 619 | 619 | } else {
|
| 620 | - $this->DrawColor = sprintf('%.3F %.3F %.3F RG', $r / 255, $g / 255, $b / 255);
|
|
| 620 | + $this->DrawColor = sprintf('%.3F %.3F %.3F RG', $r / 255, $g / 255, $b / 255);
|
|
| 621 | 621 | } |
| 622 | 622 | if ($this->page > 0) {
|
| 623 | - $this->_out($this->DrawColor); |
|
| 623 | + $this->_out($this->DrawColor); |
|
| 624 | 624 | } |
| 625 | 625 | } |
| 626 | 626 | |
@@ -634,16 +634,16 @@ discard block |
||
| 634 | 634 | */ |
| 635 | 635 | public function SetFillColor(int $r, ?int $g=null, ?int $b=null) : void |
| 636 | 636 | {
|
| 637 | - // Set color for all filling operations |
|
| 637 | + // Set color for all filling operations |
|
| 638 | 638 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) {
|
| 639 | - $this->FillColor = sprintf('%.3F g', $r / 255);
|
|
| 639 | + $this->FillColor = sprintf('%.3F g', $r / 255);
|
|
| 640 | 640 | } else {
|
| 641 | - $this->FillColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255);
|
|
| 641 | + $this->FillColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255);
|
|
| 642 | + } |
|
| 643 | + $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
| 644 | + if ($this->page > 0) {
|
|
| 645 | + $this->_out($this->FillColor); |
|
| 642 | 646 | } |
| 643 | - $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
| 644 | - if ($this->page > 0) {
|
|
| 645 | - $this->_out($this->FillColor); |
|
| 646 | - } |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | 649 | /** |
@@ -656,13 +656,13 @@ discard block |
||
| 656 | 656 | */ |
| 657 | 657 | public function SetTextColor(int $r, ?int $g=null, ?int $b=null) : void |
| 658 | 658 | {
|
| 659 | - // Set color for text |
|
| 659 | + // Set color for text |
|
| 660 | 660 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) {
|
| 661 | - $this->TextColor = sprintf('%.3F g', $r / 255);
|
|
| 661 | + $this->TextColor = sprintf('%.3F g', $r / 255);
|
|
| 662 | 662 | } else {
|
| 663 | - $this->TextColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255);
|
|
| 663 | + $this->TextColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255);
|
|
| 664 | 664 | } |
| 665 | - $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
| 665 | + $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | /** |
@@ -673,14 +673,14 @@ discard block |
||
| 673 | 673 | */ |
| 674 | 674 | public function GetStringWidth(string $s) : float |
| 675 | 675 | {
|
| 676 | - // Get width of a string in the current font |
|
| 677 | - $s = (string)$s; |
|
| 678 | - $cw = &$this->CurrentFont['cw']; |
|
| 679 | - $w = 0; |
|
| 680 | - $l = strlen($s); |
|
| 681 | - for($i=0;$i<$l;$i++) |
|
| 682 | - $w += $cw[$s[$i]]; |
|
| 683 | - return $w*$this->FontSize/1000; |
|
| 676 | + // Get width of a string in the current font |
|
| 677 | + $s = (string)$s; |
|
| 678 | + $cw = &$this->CurrentFont['cw']; |
|
| 679 | + $w = 0; |
|
| 680 | + $l = strlen($s); |
|
| 681 | + for($i=0;$i<$l;$i++) |
|
| 682 | + $w += $cw[$s[$i]]; |
|
| 683 | + return $w*$this->FontSize/1000; |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | /** |
@@ -691,10 +691,10 @@ discard block |
||
| 691 | 691 | */ |
| 692 | 692 | public function SetLineWidth(float $width) : void |
| 693 | 693 | {
|
| 694 | - // Set line width |
|
| 695 | - $this->LineWidth = $width; |
|
| 696 | - if($this->page>0) |
|
| 697 | - $this->_out(sprintf('%.2F w',$width*$this->k));
|
|
| 694 | + // Set line width |
|
| 695 | + $this->LineWidth = $width; |
|
| 696 | + if($this->page>0) |
|
| 697 | + $this->_out(sprintf('%.2F w',$width*$this->k));
|
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | /** |
@@ -708,8 +708,8 @@ discard block |
||
| 708 | 708 | */ |
| 709 | 709 | public function Line(float $x1, float $y1, float $x2, float $y2) : void |
| 710 | 710 | {
|
| 711 | - // Draw a line |
|
| 712 | - $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));
|
|
| 711 | + // Draw a line |
|
| 712 | + $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));
|
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | /** |
@@ -729,14 +729,14 @@ discard block |
||
| 729 | 729 | */ |
| 730 | 730 | public function Rect(float $x, float $y, float $w, float $h, string $style='') : void |
| 731 | 731 | {
|
| 732 | - // Draw a rectangle |
|
| 733 | - if($style=='F') |
|
| 734 | - $op = 'f'; |
|
| 735 | - elseif($style=='FD' || $style=='DF') |
|
| 736 | - $op = 'B'; |
|
| 737 | - else |
|
| 738 | - $op = 'S'; |
|
| 739 | - $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
|
|
| 732 | + // Draw a rectangle |
|
| 733 | + if($style=='F') |
|
| 734 | + $op = 'f'; |
|
| 735 | + elseif($style=='FD' || $style=='DF') |
|
| 736 | + $op = 'B'; |
|
| 737 | + else |
|
| 738 | + $op = 'S'; |
|
| 739 | + $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
|
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | /** |
@@ -758,27 +758,27 @@ discard block |
||
| 758 | 758 | */ |
| 759 | 759 | public function AddFont(string $family, string $style='', string $file='') : void |
| 760 | 760 | {
|
| 761 | - // Add a TrueType, OpenType or Type1 font |
|
| 762 | - $family = strtolower($family); |
|
| 763 | - if($file=='') |
|
| 764 | - $file = str_replace(' ','',$family).strtolower($style).'.php';
|
|
| 765 | - $style = strtoupper($style); |
|
| 766 | - if($style=='IB') |
|
| 767 | - $style = 'BI'; |
|
| 768 | - $fontkey = $family.$style; |
|
| 769 | - if(isset($this->fonts[$fontkey])) |
|
| 770 | - return; |
|
| 771 | - $info = $this->_loadfont($file); |
|
| 772 | - $info['i'] = count($this->fonts)+1; |
|
| 773 | - if(!empty($info['file'])) |
|
| 774 | - {
|
|
| 775 | - // Embedded font |
|
| 776 | - if($info['type']=='TrueType') |
|
| 777 | - $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']);
|
|
| 778 | - else |
|
| 779 | - $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']);
|
|
| 780 | - } |
|
| 781 | - $this->fonts[$fontkey] = $info; |
|
| 761 | + // Add a TrueType, OpenType or Type1 font |
|
| 762 | + $family = strtolower($family); |
|
| 763 | + if($file=='') |
|
| 764 | + $file = str_replace(' ','',$family).strtolower($style).'.php';
|
|
| 765 | + $style = strtoupper($style); |
|
| 766 | + if($style=='IB') |
|
| 767 | + $style = 'BI'; |
|
| 768 | + $fontkey = $family.$style; |
|
| 769 | + if(isset($this->fonts[$fontkey])) |
|
| 770 | + return; |
|
| 771 | + $info = $this->_loadfont($file); |
|
| 772 | + $info['i'] = count($this->fonts)+1; |
|
| 773 | + if(!empty($info['file'])) |
|
| 774 | + {
|
|
| 775 | + // Embedded font |
|
| 776 | + if($info['type']=='TrueType') |
|
| 777 | + $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']);
|
|
| 778 | + else |
|
| 779 | + $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']);
|
|
| 780 | + } |
|
| 781 | + $this->fonts[$fontkey] = $info; |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | /** |
@@ -818,52 +818,52 @@ discard block |
||
| 818 | 818 | */ |
| 819 | 819 | public function SetFont(string $family, string $style='', float $size=0) : void |
| 820 | 820 | {
|
| 821 | - // Select a font; size given in points |
|
| 822 | - if($family=='') |
|
| 823 | - $family = $this->FontFamily; |
|
| 824 | - else |
|
| 825 | - $family = strtolower($family); |
|
| 826 | - $style = strtoupper($style); |
|
| 827 | - if(strpos($style,'U')!==false) |
|
| 828 | - {
|
|
| 829 | - $this->underline = true; |
|
| 830 | - $style = str_replace('U','',$style);
|
|
| 831 | - } |
|
| 832 | - else |
|
| 833 | - $this->underline = false; |
|
| 834 | - if($style=='IB') |
|
| 835 | - $style = 'BI'; |
|
| 836 | - if($size==0) |
|
| 837 | - $size = $this->FontSizePt; |
|
| 838 | - // Test if font is already selected |
|
| 839 | - if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) |
|
| 840 | - return; |
|
| 841 | - // Test if font is already loaded |
|
| 842 | - $fontkey = $family.$style; |
|
| 843 | - if(!isset($this->fonts[$fontkey])) |
|
| 844 | - {
|
|
| 845 | - // Test if one of the core fonts |
|
| 846 | - if($family=='arial') |
|
| 847 | - $family = 'helvetica'; |
|
| 848 | - if(in_array($family,$this->CoreFonts)) |
|
| 849 | - {
|
|
| 850 | - if($family=='symbol' || $family=='zapfdingbats') |
|
| 851 | - $style = ''; |
|
| 852 | - $fontkey = $family.$style; |
|
| 853 | - if(!isset($this->fonts[$fontkey])) |
|
| 854 | - $this->addFont($family,$style); |
|
| 855 | - } |
|
| 856 | - else |
|
| 857 | - $this->Error('Undefined font: '.$family.' '.$style);
|
|
| 858 | - } |
|
| 859 | - // Select it |
|
| 860 | - $this->FontFamily = $family; |
|
| 861 | - $this->FontStyle = $style; |
|
| 862 | - $this->FontSizePt = $size; |
|
| 863 | - $this->FontSize = $size/$this->k; |
|
| 864 | - $this->CurrentFont = &$this->fonts[$fontkey]; |
|
| 865 | - if($this->page>0) |
|
| 866 | - $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
|
|
| 821 | + // Select a font; size given in points |
|
| 822 | + if($family=='') |
|
| 823 | + $family = $this->FontFamily; |
|
| 824 | + else |
|
| 825 | + $family = strtolower($family); |
|
| 826 | + $style = strtoupper($style); |
|
| 827 | + if(strpos($style,'U')!==false) |
|
| 828 | + {
|
|
| 829 | + $this->underline = true; |
|
| 830 | + $style = str_replace('U','',$style);
|
|
| 831 | + } |
|
| 832 | + else |
|
| 833 | + $this->underline = false; |
|
| 834 | + if($style=='IB') |
|
| 835 | + $style = 'BI'; |
|
| 836 | + if($size==0) |
|
| 837 | + $size = $this->FontSizePt; |
|
| 838 | + // Test if font is already selected |
|
| 839 | + if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) |
|
| 840 | + return; |
|
| 841 | + // Test if font is already loaded |
|
| 842 | + $fontkey = $family.$style; |
|
| 843 | + if(!isset($this->fonts[$fontkey])) |
|
| 844 | + {
|
|
| 845 | + // Test if one of the core fonts |
|
| 846 | + if($family=='arial') |
|
| 847 | + $family = 'helvetica'; |
|
| 848 | + if(in_array($family,$this->CoreFonts)) |
|
| 849 | + {
|
|
| 850 | + if($family=='symbol' || $family=='zapfdingbats') |
|
| 851 | + $style = ''; |
|
| 852 | + $fontkey = $family.$style; |
|
| 853 | + if(!isset($this->fonts[$fontkey])) |
|
| 854 | + $this->addFont($family,$style); |
|
| 855 | + } |
|
| 856 | + else |
|
| 857 | + $this->Error('Undefined font: '.$family.' '.$style);
|
|
| 858 | + } |
|
| 859 | + // Select it |
|
| 860 | + $this->FontFamily = $family; |
|
| 861 | + $this->FontStyle = $style; |
|
| 862 | + $this->FontSizePt = $size; |
|
| 863 | + $this->FontSize = $size/$this->k; |
|
| 864 | + $this->CurrentFont = &$this->fonts[$fontkey]; |
|
| 865 | + if($this->page>0) |
|
| 866 | + $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
|
|
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | /** |
@@ -872,13 +872,13 @@ discard block |
||
| 872 | 872 | */ |
| 873 | 873 | public function SetFontSize(float $size) : void |
| 874 | 874 | {
|
| 875 | - // Set font size in points |
|
| 876 | - if($this->FontSizePt==$size) |
|
| 877 | - return; |
|
| 878 | - $this->FontSizePt = $size; |
|
| 879 | - $this->FontSize = $size/$this->k; |
|
| 880 | - if($this->page>0) |
|
| 881 | - $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
|
|
| 875 | + // Set font size in points |
|
| 876 | + if($this->FontSizePt==$size) |
|
| 877 | + return; |
|
| 878 | + $this->FontSizePt = $size; |
|
| 879 | + $this->FontSize = $size/$this->k; |
|
| 880 | + if($this->page>0) |
|
| 881 | + $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
|
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | /** |
@@ -890,10 +890,10 @@ discard block |
||
| 890 | 890 | */ |
| 891 | 891 | public function AddLink() : int |
| 892 | 892 | {
|
| 893 | - // Create a new internal link |
|
| 894 | - $n = count($this->links)+1; |
|
| 895 | - $this->links[$n] = array(0, 0); |
|
| 896 | - return $n; |
|
| 893 | + // Create a new internal link |
|
| 894 | + $n = count($this->links)+1; |
|
| 895 | + $this->links[$n] = array(0, 0); |
|
| 896 | + return $n; |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | /** |
@@ -904,12 +904,12 @@ discard block |
||
| 904 | 904 | */ |
| 905 | 905 | public function SetLink(int $link, float $y=0, int $page=-1) : void |
| 906 | 906 | {
|
| 907 | - // Set destination of internal link |
|
| 908 | - if($y==-1) |
|
| 909 | - $y = $this->y; |
|
| 910 | - if($page==-1) |
|
| 911 | - $page = $this->page; |
|
| 912 | - $this->links[$link] = array($page, $y); |
|
| 907 | + // Set destination of internal link |
|
| 908 | + if($y==-1) |
|
| 909 | + $y = $this->y; |
|
| 910 | + if($page==-1) |
|
| 911 | + $page = $this->page; |
|
| 912 | + $this->links[$link] = array($page, $y); |
|
| 913 | 913 | } |
| 914 | 914 | |
| 915 | 915 | /** |
@@ -925,8 +925,8 @@ discard block |
||
| 925 | 925 | */ |
| 926 | 926 | public function Link(float $x, float $y, float $w, float $h, $link) : void |
| 927 | 927 | {
|
| 928 | - // Put a link on the page |
|
| 929 | - $this->PageLinks[$this->page][] = array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link); |
|
| 928 | + // Put a link on the page |
|
| 929 | + $this->PageLinks[$this->page][] = array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link); |
|
| 930 | 930 | } |
| 931 | 931 | |
| 932 | 932 | /** |
@@ -941,15 +941,15 @@ discard block |
||
| 941 | 941 | */ |
| 942 | 942 | public function Text(float $x, float $y, string $txt) : void |
| 943 | 943 | {
|
| 944 | - // Output a string |
|
| 945 | - if(!isset($this->CurrentFont)) |
|
| 946 | - $this->Error('No font has been set');
|
|
| 947 | - $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
|
|
| 948 | - if($this->underline && $txt!='') |
|
| 949 | - $s .= ' '.$this->_dounderline($x,$y,$txt); |
|
| 950 | - if($this->ColorFlag) |
|
| 951 | - $s = 'q '.$this->TextColor.' '.$s.' Q'; |
|
| 952 | - $this->_out($s); |
|
| 944 | + // Output a string |
|
| 945 | + if(!isset($this->CurrentFont)) |
|
| 946 | + $this->Error('No font has been set');
|
|
| 947 | + $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
|
|
| 948 | + if($this->underline && $txt!='') |
|
| 949 | + $s .= ' '.$this->_dounderline($x,$y,$txt); |
|
| 950 | + if($this->ColorFlag) |
|
| 951 | + $s = 'q '.$this->TextColor.' '.$s.' Q'; |
|
| 952 | + $this->_out($s); |
|
| 953 | 953 | } |
| 954 | 954 | |
| 955 | 955 | /** |
@@ -965,8 +965,8 @@ discard block |
||
| 965 | 965 | */ |
| 966 | 966 | public function AcceptPageBreak() : bool |
| 967 | 967 | {
|
| 968 | - // Accept automatic page break or not |
|
| 969 | - return $this->AutoPageBreak; |
|
| 968 | + // Accept automatic page break or not |
|
| 969 | + return $this->AutoPageBreak; |
|
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | /** |
@@ -1008,82 +1008,82 @@ discard block |
||
| 1008 | 1008 | */ |
| 1009 | 1009 | public function Cell(float $w, float $h=0, string $txt='', $border=0, float $ln=0, $align='', $fill=false, $link='') : void |
| 1010 | 1010 | {
|
| 1011 | - // Output a cell |
|
| 1012 | - $k = $this->k; |
|
| 1013 | - if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
| 1014 | - {
|
|
| 1015 | - // Automatic page break |
|
| 1016 | - $x = $this->x; |
|
| 1017 | - $ws = $this->ws; |
|
| 1018 | - if($ws>0) |
|
| 1019 | - {
|
|
| 1020 | - $this->ws = 0; |
|
| 1021 | - $this->_out('0 Tw');
|
|
| 1022 | - } |
|
| 1023 | - $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
| 1024 | - $this->x = $x; |
|
| 1025 | - if($ws>0) |
|
| 1026 | - {
|
|
| 1027 | - $this->ws = $ws; |
|
| 1028 | - $this->_out(sprintf('%.3F Tw',$ws*$k));
|
|
| 1029 | - } |
|
| 1030 | - } |
|
| 1031 | - if($w==0) |
|
| 1032 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1033 | - $s = ''; |
|
| 1034 | - if($fill || $border==1) |
|
| 1035 | - {
|
|
| 1036 | - if($fill) |
|
| 1037 | - $op = ($border==1) ? 'B' : 'f'; |
|
| 1038 | - else |
|
| 1039 | - $op = 'S'; |
|
| 1040 | - $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);
|
|
| 1041 | - } |
|
| 1042 | - if(is_string($border)) |
|
| 1043 | - {
|
|
| 1044 | - $x = $this->x; |
|
| 1045 | - $y = $this->y; |
|
| 1046 | - if(strpos($border,'L')!==false) |
|
| 1047 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
|
|
| 1048 | - if(strpos($border,'T')!==false) |
|
| 1049 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
|
|
| 1050 | - if(strpos($border,'R')!==false) |
|
| 1051 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
|
|
| 1052 | - if(strpos($border,'B')!==false) |
|
| 1053 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
|
|
| 1054 | - } |
|
| 1055 | - if($txt!=='') |
|
| 1056 | - {
|
|
| 1057 | - if(!isset($this->CurrentFont)) |
|
| 1058 | - $this->Error('No font has been set');
|
|
| 1059 | - if($align=='R') |
|
| 1060 | - $dx = $w-$this->cMargin-$this->getStringWidth($txt); |
|
| 1061 | - elseif($align=='C') |
|
| 1062 | - $dx = ($w-$this->getStringWidth($txt))/2; |
|
| 1063 | - else |
|
| 1064 | - $dx = $this->cMargin; |
|
| 1065 | - if($this->ColorFlag) |
|
| 1066 | - $s .= 'q '.$this->TextColor.' '; |
|
| 1067 | - $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));
|
|
| 1068 | - if($this->underline) |
|
| 1069 | - $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); |
|
| 1070 | - if($this->ColorFlag) |
|
| 1071 | - $s .= ' Q'; |
|
| 1072 | - if($link) |
|
| 1073 | - $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->getStringWidth($txt),$this->FontSize,$link); |
|
| 1074 | - } |
|
| 1075 | - if($s) |
|
| 1076 | - $this->_out($s); |
|
| 1077 | - $this->lasth = $h; |
|
| 1078 | - if($ln>0) |
|
| 1079 | - {
|
|
| 1080 | - // Go to next line |
|
| 1081 | - $this->y += $h; |
|
| 1082 | - if($ln==1) |
|
| 1083 | - $this->x = $this->lMargin; |
|
| 1084 | - } |
|
| 1085 | - else |
|
| 1086 | - $this->x += $w; |
|
| 1011 | + // Output a cell |
|
| 1012 | + $k = $this->k; |
|
| 1013 | + if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
| 1014 | + {
|
|
| 1015 | + // Automatic page break |
|
| 1016 | + $x = $this->x; |
|
| 1017 | + $ws = $this->ws; |
|
| 1018 | + if($ws>0) |
|
| 1019 | + {
|
|
| 1020 | + $this->ws = 0; |
|
| 1021 | + $this->_out('0 Tw');
|
|
| 1022 | + } |
|
| 1023 | + $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
| 1024 | + $this->x = $x; |
|
| 1025 | + if($ws>0) |
|
| 1026 | + {
|
|
| 1027 | + $this->ws = $ws; |
|
| 1028 | + $this->_out(sprintf('%.3F Tw',$ws*$k));
|
|
| 1029 | + } |
|
| 1030 | + } |
|
| 1031 | + if($w==0) |
|
| 1032 | + $w = $this->w-$this->rMargin-$this->x; |
|
| 1033 | + $s = ''; |
|
| 1034 | + if($fill || $border==1) |
|
| 1035 | + {
|
|
| 1036 | + if($fill) |
|
| 1037 | + $op = ($border==1) ? 'B' : 'f'; |
|
| 1038 | + else |
|
| 1039 | + $op = 'S'; |
|
| 1040 | + $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);
|
|
| 1041 | + } |
|
| 1042 | + if(is_string($border)) |
|
| 1043 | + {
|
|
| 1044 | + $x = $this->x; |
|
| 1045 | + $y = $this->y; |
|
| 1046 | + if(strpos($border,'L')!==false) |
|
| 1047 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
|
|
| 1048 | + if(strpos($border,'T')!==false) |
|
| 1049 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
|
|
| 1050 | + if(strpos($border,'R')!==false) |
|
| 1051 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
|
|
| 1052 | + if(strpos($border,'B')!==false) |
|
| 1053 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
|
|
| 1054 | + } |
|
| 1055 | + if($txt!=='') |
|
| 1056 | + {
|
|
| 1057 | + if(!isset($this->CurrentFont)) |
|
| 1058 | + $this->Error('No font has been set');
|
|
| 1059 | + if($align=='R') |
|
| 1060 | + $dx = $w-$this->cMargin-$this->getStringWidth($txt); |
|
| 1061 | + elseif($align=='C') |
|
| 1062 | + $dx = ($w-$this->getStringWidth($txt))/2; |
|
| 1063 | + else |
|
| 1064 | + $dx = $this->cMargin; |
|
| 1065 | + if($this->ColorFlag) |
|
| 1066 | + $s .= 'q '.$this->TextColor.' '; |
|
| 1067 | + $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));
|
|
| 1068 | + if($this->underline) |
|
| 1069 | + $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); |
|
| 1070 | + if($this->ColorFlag) |
|
| 1071 | + $s .= ' Q'; |
|
| 1072 | + if($link) |
|
| 1073 | + $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->getStringWidth($txt),$this->FontSize,$link); |
|
| 1074 | + } |
|
| 1075 | + if($s) |
|
| 1076 | + $this->_out($s); |
|
| 1077 | + $this->lasth = $h; |
|
| 1078 | + if($ln>0) |
|
| 1079 | + {
|
|
| 1080 | + // Go to next line |
|
| 1081 | + $this->y += $h; |
|
| 1082 | + if($ln==1) |
|
| 1083 | + $this->x = $this->lMargin; |
|
| 1084 | + } |
|
| 1085 | + else |
|
| 1086 | + $this->x += $w; |
|
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | /** |
@@ -1116,119 +1116,119 @@ discard block |
||
| 1116 | 1116 | */ |
| 1117 | 1117 | public function MultiCell(float $w, float $h, string $txt, $border=0, string $align='J', bool $fill=false) : void |
| 1118 | 1118 | {
|
| 1119 | - // Output text with automatic or explicit line breaks |
|
| 1120 | - if(!isset($this->CurrentFont)) |
|
| 1121 | - $this->Error('No font has been set');
|
|
| 1122 | - $cw = &$this->CurrentFont['cw']; |
|
| 1123 | - if($w==0) |
|
| 1124 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1125 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1126 | - $s = str_replace("\r",'',$txt);
|
|
| 1127 | - $nb = strlen($s); |
|
| 1128 | - if($nb>0 && $s[$nb-1]=="\n") |
|
| 1129 | - $nb--; |
|
| 1130 | - $b = 0; |
|
| 1131 | - $b2 = ''; |
|
| 1132 | - if($border) |
|
| 1133 | - {
|
|
| 1134 | - if($border==1) |
|
| 1135 | - {
|
|
| 1136 | - $border = 'LTRB'; |
|
| 1137 | - $b = 'LRT'; |
|
| 1138 | - $b2 = 'LR'; |
|
| 1139 | - } |
|
| 1140 | - else |
|
| 1141 | - {
|
|
| 1142 | - $b2 = ''; |
|
| 1143 | - if(strpos($border,'L')!==false) |
|
| 1144 | - $b2 .= 'L'; |
|
| 1145 | - if(strpos($border,'R')!==false) |
|
| 1146 | - $b2 .= 'R'; |
|
| 1147 | - $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; |
|
| 1148 | - } |
|
| 1149 | - } |
|
| 1150 | - $sep = -1; |
|
| 1151 | - $i = 0; |
|
| 1152 | - $j = 0; |
|
| 1153 | - $l = 0; |
|
| 1154 | - $ns = 0; |
|
| 1155 | - $nl = 1; |
|
| 1156 | - $ls = 0; |
|
| 1157 | - while($i<$nb) |
|
| 1158 | - {
|
|
| 1159 | - // Get next character |
|
| 1160 | - $c = $s[$i]; |
|
| 1161 | - if($c=="\n") |
|
| 1162 | - {
|
|
| 1163 | - // Explicit line break |
|
| 1164 | - if($this->ws>0) |
|
| 1165 | - {
|
|
| 1166 | - $this->ws = 0; |
|
| 1167 | - $this->_out('0 Tw');
|
|
| 1168 | - } |
|
| 1169 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1170 | - $i++; |
|
| 1171 | - $sep = -1; |
|
| 1172 | - $j = $i; |
|
| 1173 | - $l = 0; |
|
| 1174 | - $ns = 0; |
|
| 1175 | - $nl++; |
|
| 1176 | - if($border && $nl==2) |
|
| 1177 | - $b = $b2; |
|
| 1178 | - continue; |
|
| 1179 | - } |
|
| 1180 | - if($c==' ') |
|
| 1181 | - {
|
|
| 1182 | - $sep = $i; |
|
| 1183 | - $ls = $l; |
|
| 1184 | - $ns++; |
|
| 1185 | - } |
|
| 1186 | - $l += $cw[$c]; |
|
| 1187 | - if($l>$wmax) |
|
| 1188 | - {
|
|
| 1189 | - // Automatic line break |
|
| 1190 | - if($sep==-1) |
|
| 1191 | - {
|
|
| 1192 | - if($i==$j) |
|
| 1193 | - $i++; |
|
| 1194 | - if($this->ws>0) |
|
| 1195 | - {
|
|
| 1196 | - $this->ws = 0; |
|
| 1197 | - $this->_out('0 Tw');
|
|
| 1198 | - } |
|
| 1199 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1200 | - } |
|
| 1201 | - else |
|
| 1202 | - {
|
|
| 1203 | - if($align=='J') |
|
| 1204 | - {
|
|
| 1205 | - $this->ws = ($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; |
|
| 1206 | - $this->_out(sprintf('%.3F Tw',$this->ws*$this->k));
|
|
| 1207 | - } |
|
| 1208 | - $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); |
|
| 1209 | - $i = $sep+1; |
|
| 1210 | - } |
|
| 1211 | - $sep = -1; |
|
| 1212 | - $j = $i; |
|
| 1213 | - $l = 0; |
|
| 1214 | - $ns = 0; |
|
| 1215 | - $nl++; |
|
| 1216 | - if($border && $nl==2) |
|
| 1217 | - $b = $b2; |
|
| 1218 | - } |
|
| 1219 | - else |
|
| 1220 | - $i++; |
|
| 1221 | - } |
|
| 1222 | - // Last chunk |
|
| 1223 | - if($this->ws>0) |
|
| 1224 | - {
|
|
| 1225 | - $this->ws = 0; |
|
| 1226 | - $this->_out('0 Tw');
|
|
| 1227 | - } |
|
| 1228 | - if($border && strpos($border,'B')!==false) |
|
| 1229 | - $b .= 'B'; |
|
| 1230 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1231 | - $this->x = $this->lMargin; |
|
| 1119 | + // Output text with automatic or explicit line breaks |
|
| 1120 | + if(!isset($this->CurrentFont)) |
|
| 1121 | + $this->Error('No font has been set');
|
|
| 1122 | + $cw = &$this->CurrentFont['cw']; |
|
| 1123 | + if($w==0) |
|
| 1124 | + $w = $this->w-$this->rMargin-$this->x; |
|
| 1125 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1126 | + $s = str_replace("\r",'',$txt);
|
|
| 1127 | + $nb = strlen($s); |
|
| 1128 | + if($nb>0 && $s[$nb-1]=="\n") |
|
| 1129 | + $nb--; |
|
| 1130 | + $b = 0; |
|
| 1131 | + $b2 = ''; |
|
| 1132 | + if($border) |
|
| 1133 | + {
|
|
| 1134 | + if($border==1) |
|
| 1135 | + {
|
|
| 1136 | + $border = 'LTRB'; |
|
| 1137 | + $b = 'LRT'; |
|
| 1138 | + $b2 = 'LR'; |
|
| 1139 | + } |
|
| 1140 | + else |
|
| 1141 | + {
|
|
| 1142 | + $b2 = ''; |
|
| 1143 | + if(strpos($border,'L')!==false) |
|
| 1144 | + $b2 .= 'L'; |
|
| 1145 | + if(strpos($border,'R')!==false) |
|
| 1146 | + $b2 .= 'R'; |
|
| 1147 | + $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; |
|
| 1148 | + } |
|
| 1149 | + } |
|
| 1150 | + $sep = -1; |
|
| 1151 | + $i = 0; |
|
| 1152 | + $j = 0; |
|
| 1153 | + $l = 0; |
|
| 1154 | + $ns = 0; |
|
| 1155 | + $nl = 1; |
|
| 1156 | + $ls = 0; |
|
| 1157 | + while($i<$nb) |
|
| 1158 | + {
|
|
| 1159 | + // Get next character |
|
| 1160 | + $c = $s[$i]; |
|
| 1161 | + if($c=="\n") |
|
| 1162 | + {
|
|
| 1163 | + // Explicit line break |
|
| 1164 | + if($this->ws>0) |
|
| 1165 | + {
|
|
| 1166 | + $this->ws = 0; |
|
| 1167 | + $this->_out('0 Tw');
|
|
| 1168 | + } |
|
| 1169 | + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1170 | + $i++; |
|
| 1171 | + $sep = -1; |
|
| 1172 | + $j = $i; |
|
| 1173 | + $l = 0; |
|
| 1174 | + $ns = 0; |
|
| 1175 | + $nl++; |
|
| 1176 | + if($border && $nl==2) |
|
| 1177 | + $b = $b2; |
|
| 1178 | + continue; |
|
| 1179 | + } |
|
| 1180 | + if($c==' ') |
|
| 1181 | + {
|
|
| 1182 | + $sep = $i; |
|
| 1183 | + $ls = $l; |
|
| 1184 | + $ns++; |
|
| 1185 | + } |
|
| 1186 | + $l += $cw[$c]; |
|
| 1187 | + if($l>$wmax) |
|
| 1188 | + {
|
|
| 1189 | + // Automatic line break |
|
| 1190 | + if($sep==-1) |
|
| 1191 | + {
|
|
| 1192 | + if($i==$j) |
|
| 1193 | + $i++; |
|
| 1194 | + if($this->ws>0) |
|
| 1195 | + {
|
|
| 1196 | + $this->ws = 0; |
|
| 1197 | + $this->_out('0 Tw');
|
|
| 1198 | + } |
|
| 1199 | + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1200 | + } |
|
| 1201 | + else |
|
| 1202 | + {
|
|
| 1203 | + if($align=='J') |
|
| 1204 | + {
|
|
| 1205 | + $this->ws = ($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; |
|
| 1206 | + $this->_out(sprintf('%.3F Tw',$this->ws*$this->k));
|
|
| 1207 | + } |
|
| 1208 | + $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); |
|
| 1209 | + $i = $sep+1; |
|
| 1210 | + } |
|
| 1211 | + $sep = -1; |
|
| 1212 | + $j = $i; |
|
| 1213 | + $l = 0; |
|
| 1214 | + $ns = 0; |
|
| 1215 | + $nl++; |
|
| 1216 | + if($border && $nl==2) |
|
| 1217 | + $b = $b2; |
|
| 1218 | + } |
|
| 1219 | + else |
|
| 1220 | + $i++; |
|
| 1221 | + } |
|
| 1222 | + // Last chunk |
|
| 1223 | + if($this->ws>0) |
|
| 1224 | + {
|
|
| 1225 | + $this->ws = 0; |
|
| 1226 | + $this->_out('0 Tw');
|
|
| 1227 | + } |
|
| 1228 | + if($border && strpos($border,'B')!==false) |
|
| 1229 | + $b .= 'B'; |
|
| 1230 | + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1231 | + $this->x = $this->lMargin; |
|
| 1232 | 1232 | } |
| 1233 | 1233 | |
| 1234 | 1234 | /** |
@@ -1243,85 +1243,85 @@ discard block |
||
| 1243 | 1243 | */ |
| 1244 | 1244 | public function Write(float $h, string $txt, $link='') : void |
| 1245 | 1245 | {
|
| 1246 | - // Output text in flowing mode |
|
| 1247 | - if(!isset($this->CurrentFont)) |
|
| 1248 | - $this->Error('No font has been set');
|
|
| 1249 | - $cw = &$this->CurrentFont['cw']; |
|
| 1250 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1251 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1252 | - $s = str_replace("\r",'',$txt);
|
|
| 1253 | - $nb = strlen($s); |
|
| 1254 | - $sep = -1; |
|
| 1255 | - $i = 0; |
|
| 1256 | - $j = 0; |
|
| 1257 | - $l = 0; |
|
| 1258 | - $nl = 1; |
|
| 1259 | - while($i<$nb) |
|
| 1260 | - {
|
|
| 1261 | - // Get next character |
|
| 1262 | - $c = $s[$i]; |
|
| 1263 | - if($c=="\n") |
|
| 1264 | - {
|
|
| 1265 | - // Explicit line break |
|
| 1266 | - $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
| 1267 | - $i++; |
|
| 1268 | - $sep = -1; |
|
| 1269 | - $j = $i; |
|
| 1270 | - $l = 0; |
|
| 1271 | - if($nl==1) |
|
| 1272 | - {
|
|
| 1273 | - $this->x = $this->lMargin; |
|
| 1274 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1275 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1276 | - } |
|
| 1277 | - $nl++; |
|
| 1278 | - continue; |
|
| 1279 | - } |
|
| 1280 | - if($c==' ') |
|
| 1281 | - $sep = $i; |
|
| 1282 | - $l += $cw[$c]; |
|
| 1283 | - if($l>$wmax) |
|
| 1284 | - {
|
|
| 1285 | - // Automatic line break |
|
| 1286 | - if($sep==-1) |
|
| 1287 | - {
|
|
| 1288 | - if($this->x>$this->lMargin) |
|
| 1289 | - {
|
|
| 1290 | - // Move to next line |
|
| 1291 | - $this->x = $this->lMargin; |
|
| 1292 | - $this->y += $h; |
|
| 1293 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1294 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1295 | - $i++; |
|
| 1296 | - $nl++; |
|
| 1297 | - continue; |
|
| 1298 | - } |
|
| 1299 | - if($i==$j) |
|
| 1300 | - $i++; |
|
| 1301 | - $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
| 1302 | - } |
|
| 1303 | - else |
|
| 1304 | - {
|
|
| 1305 | - $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link); |
|
| 1306 | - $i = $sep+1; |
|
| 1307 | - } |
|
| 1308 | - $sep = -1; |
|
| 1309 | - $j = $i; |
|
| 1310 | - $l = 0; |
|
| 1311 | - if($nl==1) |
|
| 1312 | - {
|
|
| 1313 | - $this->x = $this->lMargin; |
|
| 1314 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1315 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1316 | - } |
|
| 1317 | - $nl++; |
|
| 1318 | - } |
|
| 1319 | - else |
|
| 1320 | - $i++; |
|
| 1321 | - } |
|
| 1322 | - // Last chunk |
|
| 1323 | - if($i!=$j) |
|
| 1324 | - $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link); |
|
| 1246 | + // Output text in flowing mode |
|
| 1247 | + if(!isset($this->CurrentFont)) |
|
| 1248 | + $this->Error('No font has been set');
|
|
| 1249 | + $cw = &$this->CurrentFont['cw']; |
|
| 1250 | + $w = $this->w-$this->rMargin-$this->x; |
|
| 1251 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1252 | + $s = str_replace("\r",'',$txt);
|
|
| 1253 | + $nb = strlen($s); |
|
| 1254 | + $sep = -1; |
|
| 1255 | + $i = 0; |
|
| 1256 | + $j = 0; |
|
| 1257 | + $l = 0; |
|
| 1258 | + $nl = 1; |
|
| 1259 | + while($i<$nb) |
|
| 1260 | + {
|
|
| 1261 | + // Get next character |
|
| 1262 | + $c = $s[$i]; |
|
| 1263 | + if($c=="\n") |
|
| 1264 | + {
|
|
| 1265 | + // Explicit line break |
|
| 1266 | + $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
| 1267 | + $i++; |
|
| 1268 | + $sep = -1; |
|
| 1269 | + $j = $i; |
|
| 1270 | + $l = 0; |
|
| 1271 | + if($nl==1) |
|
| 1272 | + {
|
|
| 1273 | + $this->x = $this->lMargin; |
|
| 1274 | + $w = $this->w-$this->rMargin-$this->x; |
|
| 1275 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1276 | + } |
|
| 1277 | + $nl++; |
|
| 1278 | + continue; |
|
| 1279 | + } |
|
| 1280 | + if($c==' ') |
|
| 1281 | + $sep = $i; |
|
| 1282 | + $l += $cw[$c]; |
|
| 1283 | + if($l>$wmax) |
|
| 1284 | + {
|
|
| 1285 | + // Automatic line break |
|
| 1286 | + if($sep==-1) |
|
| 1287 | + {
|
|
| 1288 | + if($this->x>$this->lMargin) |
|
| 1289 | + {
|
|
| 1290 | + // Move to next line |
|
| 1291 | + $this->x = $this->lMargin; |
|
| 1292 | + $this->y += $h; |
|
| 1293 | + $w = $this->w-$this->rMargin-$this->x; |
|
| 1294 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1295 | + $i++; |
|
| 1296 | + $nl++; |
|
| 1297 | + continue; |
|
| 1298 | + } |
|
| 1299 | + if($i==$j) |
|
| 1300 | + $i++; |
|
| 1301 | + $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
| 1302 | + } |
|
| 1303 | + else |
|
| 1304 | + {
|
|
| 1305 | + $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link); |
|
| 1306 | + $i = $sep+1; |
|
| 1307 | + } |
|
| 1308 | + $sep = -1; |
|
| 1309 | + $j = $i; |
|
| 1310 | + $l = 0; |
|
| 1311 | + if($nl==1) |
|
| 1312 | + {
|
|
| 1313 | + $this->x = $this->lMargin; |
|
| 1314 | + $w = $this->w-$this->rMargin-$this->x; |
|
| 1315 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1316 | + } |
|
| 1317 | + $nl++; |
|
| 1318 | + } |
|
| 1319 | + else |
|
| 1320 | + $i++; |
|
| 1321 | + } |
|
| 1322 | + // Last chunk |
|
| 1323 | + if($i!=$j) |
|
| 1324 | + $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link); |
|
| 1325 | 1325 | } |
| 1326 | 1326 | |
| 1327 | 1327 | /** |
@@ -1333,12 +1333,12 @@ discard block |
||
| 1333 | 1333 | */ |
| 1334 | 1334 | public function Ln(float $h=null) : void |
| 1335 | 1335 | {
|
| 1336 | - // Line feed; default value is the last cell height |
|
| 1337 | - $this->x = $this->lMargin; |
|
| 1338 | - if($h===null) |
|
| 1339 | - $this->y += $this->lasth; |
|
| 1340 | - else |
|
| 1341 | - $this->y += $h; |
|
| 1336 | + // Line feed; default value is the last cell height |
|
| 1337 | + $this->x = $this->lMargin; |
|
| 1338 | + if($h===null) |
|
| 1339 | + $this->y += $this->lasth; |
|
| 1340 | + else |
|
| 1341 | + $this->y += $h; |
|
| 1342 | 1342 | } |
| 1343 | 1343 | |
| 1344 | 1344 | /** |
@@ -1389,67 +1389,67 @@ discard block |
||
| 1389 | 1389 | */ |
| 1390 | 1390 | public function Image(string $file, ?float $x=null, ?float $y=null, float $w=0, float $h=0, string $type='', $link='') : void |
| 1391 | 1391 | {
|
| 1392 | - // Put an image on the page |
|
| 1393 | - if($file=='') |
|
| 1394 | - $this->Error('Image file name is empty');
|
|
| 1395 | - if(!isset($this->images[$file])) |
|
| 1396 | - {
|
|
| 1397 | - // First use of this image, get info |
|
| 1398 | - if($type=='') |
|
| 1399 | - {
|
|
| 1400 | - $pos = strrpos($file,'.'); |
|
| 1401 | - if(!$pos) |
|
| 1402 | - $this->Error('Image file has no extension and no type was specified: '.$file);
|
|
| 1403 | - $type = substr($file,$pos+1); |
|
| 1404 | - } |
|
| 1405 | - $type = strtolower($type); |
|
| 1406 | - if($type=='jpeg') |
|
| 1407 | - $type = 'jpg'; |
|
| 1408 | - $mtd = '_parse'.$type; |
|
| 1409 | - if(!method_exists($this,$mtd)) |
|
| 1410 | - $this->Error('Unsupported image type: '.$type);
|
|
| 1411 | - $info = $this->$mtd($file); |
|
| 1412 | - $info['i'] = count($this->images)+1; |
|
| 1413 | - $this->images[$file] = $info; |
|
| 1414 | - } |
|
| 1415 | - else |
|
| 1416 | - $info = $this->images[$file]; |
|
| 1417 | - |
|
| 1418 | - // Automatic width and height calculation if needed |
|
| 1419 | - if($w==0 && $h==0) |
|
| 1420 | - {
|
|
| 1421 | - // Put image at 96 dpi |
|
| 1422 | - $w = -96; |
|
| 1423 | - $h = -96; |
|
| 1424 | - } |
|
| 1425 | - if($w<0) |
|
| 1426 | - $w = -$info['w']*72/$w/$this->k; |
|
| 1427 | - if($h<0) |
|
| 1428 | - $h = -$info['h']*72/$h/$this->k; |
|
| 1429 | - if($w==0) |
|
| 1430 | - $w = $h*$info['w']/$info['h']; |
|
| 1431 | - if($h==0) |
|
| 1432 | - $h = $w*$info['h']/$info['w']; |
|
| 1433 | - |
|
| 1434 | - // Flowing mode |
|
| 1435 | - if($y===null) |
|
| 1436 | - {
|
|
| 1437 | - if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
| 1438 | - {
|
|
| 1439 | - // Automatic page break |
|
| 1440 | - $x2 = $this->x; |
|
| 1441 | - $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
| 1442 | - $this->x = $x2; |
|
| 1443 | - } |
|
| 1444 | - $y = $this->y; |
|
| 1445 | - $this->y += $h; |
|
| 1446 | - } |
|
| 1447 | - |
|
| 1448 | - if($x===null) |
|
| 1449 | - $x = $this->x; |
|
| 1450 | - $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']));
|
|
| 1451 | - if($link) |
|
| 1452 | - $this->Link($x,$y,$w,$h,$link); |
|
| 1392 | + // Put an image on the page |
|
| 1393 | + if($file=='') |
|
| 1394 | + $this->Error('Image file name is empty');
|
|
| 1395 | + if(!isset($this->images[$file])) |
|
| 1396 | + {
|
|
| 1397 | + // First use of this image, get info |
|
| 1398 | + if($type=='') |
|
| 1399 | + {
|
|
| 1400 | + $pos = strrpos($file,'.'); |
|
| 1401 | + if(!$pos) |
|
| 1402 | + $this->Error('Image file has no extension and no type was specified: '.$file);
|
|
| 1403 | + $type = substr($file,$pos+1); |
|
| 1404 | + } |
|
| 1405 | + $type = strtolower($type); |
|
| 1406 | + if($type=='jpeg') |
|
| 1407 | + $type = 'jpg'; |
|
| 1408 | + $mtd = '_parse'.$type; |
|
| 1409 | + if(!method_exists($this,$mtd)) |
|
| 1410 | + $this->Error('Unsupported image type: '.$type);
|
|
| 1411 | + $info = $this->$mtd($file); |
|
| 1412 | + $info['i'] = count($this->images)+1; |
|
| 1413 | + $this->images[$file] = $info; |
|
| 1414 | + } |
|
| 1415 | + else |
|
| 1416 | + $info = $this->images[$file]; |
|
| 1417 | + |
|
| 1418 | + // Automatic width and height calculation if needed |
|
| 1419 | + if($w==0 && $h==0) |
|
| 1420 | + {
|
|
| 1421 | + // Put image at 96 dpi |
|
| 1422 | + $w = -96; |
|
| 1423 | + $h = -96; |
|
| 1424 | + } |
|
| 1425 | + if($w<0) |
|
| 1426 | + $w = -$info['w']*72/$w/$this->k; |
|
| 1427 | + if($h<0) |
|
| 1428 | + $h = -$info['h']*72/$h/$this->k; |
|
| 1429 | + if($w==0) |
|
| 1430 | + $w = $h*$info['w']/$info['h']; |
|
| 1431 | + if($h==0) |
|
| 1432 | + $h = $w*$info['h']/$info['w']; |
|
| 1433 | + |
|
| 1434 | + // Flowing mode |
|
| 1435 | + if($y===null) |
|
| 1436 | + {
|
|
| 1437 | + if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
| 1438 | + {
|
|
| 1439 | + // Automatic page break |
|
| 1440 | + $x2 = $this->x; |
|
| 1441 | + $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
| 1442 | + $this->x = $x2; |
|
| 1443 | + } |
|
| 1444 | + $y = $this->y; |
|
| 1445 | + $this->y += $h; |
|
| 1446 | + } |
|
| 1447 | + |
|
| 1448 | + if($x===null) |
|
| 1449 | + $x = $this->x; |
|
| 1450 | + $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']));
|
|
| 1451 | + if($link) |
|
| 1452 | + $this->Link($x,$y,$w,$h,$link); |
|
| 1453 | 1453 | } |
| 1454 | 1454 | |
| 1455 | 1455 | /** |
@@ -1458,8 +1458,8 @@ discard block |
||
| 1458 | 1458 | */ |
| 1459 | 1459 | public function GetPageWidth() : float |
| 1460 | 1460 | {
|
| 1461 | - // Get current page width |
|
| 1462 | - return $this->w; |
|
| 1461 | + // Get current page width |
|
| 1462 | + return $this->w; |
|
| 1463 | 1463 | } |
| 1464 | 1464 | |
| 1465 | 1465 | /** |
@@ -1468,8 +1468,8 @@ discard block |
||
| 1468 | 1468 | */ |
| 1469 | 1469 | public function GetPageHeight() : float |
| 1470 | 1470 | {
|
| 1471 | - // Get current page height |
|
| 1472 | - return $this->h; |
|
| 1471 | + // Get current page height |
|
| 1472 | + return $this->h; |
|
| 1473 | 1473 | } |
| 1474 | 1474 | |
| 1475 | 1475 | /** |
@@ -1478,8 +1478,8 @@ discard block |
||
| 1478 | 1478 | */ |
| 1479 | 1479 | public function GetX() : float |
| 1480 | 1480 | {
|
| 1481 | - // GetX position |
|
| 1482 | - return $this->x; |
|
| 1481 | + // GetX position |
|
| 1482 | + return $this->x; |
|
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | /** |
@@ -1489,11 +1489,11 @@ discard block |
||
| 1489 | 1489 | */ |
| 1490 | 1490 | public function SetX(float $x) : void |
| 1491 | 1491 | {
|
| 1492 | - // Set x position |
|
| 1493 | - if($x>=0) |
|
| 1494 | - $this->x = $x; |
|
| 1495 | - else |
|
| 1496 | - $this->x = $this->w+$x; |
|
| 1492 | + // Set x position |
|
| 1493 | + if($x>=0) |
|
| 1494 | + $this->x = $x; |
|
| 1495 | + else |
|
| 1496 | + $this->x = $this->w+$x; |
|
| 1497 | 1497 | } |
| 1498 | 1498 | |
| 1499 | 1499 | /** |
@@ -1502,8 +1502,8 @@ discard block |
||
| 1502 | 1502 | */ |
| 1503 | 1503 | public function GetY() : float |
| 1504 | 1504 | {
|
| 1505 | - // Get y position |
|
| 1506 | - return $this->y; |
|
| 1505 | + // Get y position |
|
| 1506 | + return $this->y; |
|
| 1507 | 1507 | } |
| 1508 | 1508 | |
| 1509 | 1509 | /** |
@@ -1514,13 +1514,13 @@ discard block |
||
| 1514 | 1514 | */ |
| 1515 | 1515 | public function SetY(float $y, bool $resetX=true) : void |
| 1516 | 1516 | {
|
| 1517 | - // Set y position and optionally reset x |
|
| 1518 | - if($y>=0) |
|
| 1519 | - $this->y = $y; |
|
| 1520 | - else |
|
| 1521 | - $this->y = $this->h+$y; |
|
| 1522 | - if($resetX) |
|
| 1523 | - $this->x = $this->lMargin; |
|
| 1517 | + // Set y position and optionally reset x |
|
| 1518 | + if($y>=0) |
|
| 1519 | + $this->y = $y; |
|
| 1520 | + else |
|
| 1521 | + $this->y = $this->h+$y; |
|
| 1522 | + if($resetX) |
|
| 1523 | + $this->x = $this->lMargin; |
|
| 1524 | 1524 | } |
| 1525 | 1525 | |
| 1526 | 1526 | /** |
@@ -1531,9 +1531,9 @@ discard block |
||
| 1531 | 1531 | */ |
| 1532 | 1532 | public function SetXY(float $x, float $y) : void |
| 1533 | 1533 | {
|
| 1534 | - // Set x and y positions |
|
| 1535 | - $this->setX($x); |
|
| 1536 | - $this->setY($y,false); |
|
| 1534 | + // Set x and y positions |
|
| 1535 | + $this->setX($x); |
|
| 1536 | + $this->setY($y,false); |
|
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | 1539 | /** |
@@ -1556,55 +1556,55 @@ discard block |
||
| 1556 | 1556 | */ |
| 1557 | 1557 | public function Output(string $dest='', string $name='', bool $isUTF8=false) : string |
| 1558 | 1558 | {
|
| 1559 | - // Output PDF to some destination |
|
| 1560 | - $this->Close(); |
|
| 1561 | - if(strlen($name)==1 && strlen($dest)!=1) |
|
| 1562 | - {
|
|
| 1563 | - // Fix parameter order |
|
| 1564 | - $tmp = $dest; |
|
| 1565 | - $dest = $name; |
|
| 1566 | - $name = $tmp; |
|
| 1567 | - } |
|
| 1568 | - if($dest=='') |
|
| 1569 | - $dest = 'I'; |
|
| 1570 | - if($name=='') |
|
| 1571 | - $name = 'doc.pdf'; |
|
| 1572 | - switch(strtoupper($dest)) |
|
| 1573 | - {
|
|
| 1574 | - case 'I': |
|
| 1575 | - // Send to standard output |
|
| 1576 | - $this->_checkoutput(); |
|
| 1577 | - if(PHP_SAPI!='cli') |
|
| 1578 | - {
|
|
| 1579 | - // We send to a browser |
|
| 1580 | - header('Content-Type: application/pdf; charset=UTF-8');
|
|
| 1581 | - header('Content-Disposition: inline; '.$this->_httpencode('filename',$name,$isUTF8));
|
|
| 1582 | - header('Cache-Control: private, max-age=0, must-revalidate');
|
|
| 1583 | - header('Pragma: public');
|
|
| 1584 | - } |
|
| 1585 | - echo $this->buffer; |
|
| 1586 | - break; |
|
| 1587 | - case 'D': |
|
| 1588 | - // Download file |
|
| 1589 | - $this->_checkoutput(); |
|
| 1590 | - header('Content-Type: application/x-download');
|
|
| 1591 | - header('Content-Disposition: attachment; '.$this->_httpencode('filename',$name,$isUTF8));
|
|
| 1592 | - header('Cache-Control: private, max-age=0, must-revalidate');
|
|
| 1593 | - header('Pragma: public');
|
|
| 1594 | - echo $this->buffer; |
|
| 1595 | - break; |
|
| 1596 | - case 'F': |
|
| 1597 | - // Save to local file |
|
| 1598 | - if(!file_put_contents($name,$this->buffer)) |
|
| 1599 | - $this->Error('Unable to create output file: '.$name);
|
|
| 1600 | - break; |
|
| 1601 | - case 'S': |
|
| 1602 | - // Return as a string |
|
| 1603 | - return $this->buffer; |
|
| 1604 | - default: |
|
| 1605 | - $this->Error('Incorrect output destination: '.$dest);
|
|
| 1606 | - } |
|
| 1607 | - return ''; |
|
| 1559 | + // Output PDF to some destination |
|
| 1560 | + $this->Close(); |
|
| 1561 | + if(strlen($name)==1 && strlen($dest)!=1) |
|
| 1562 | + {
|
|
| 1563 | + // Fix parameter order |
|
| 1564 | + $tmp = $dest; |
|
| 1565 | + $dest = $name; |
|
| 1566 | + $name = $tmp; |
|
| 1567 | + } |
|
| 1568 | + if($dest=='') |
|
| 1569 | + $dest = 'I'; |
|
| 1570 | + if($name=='') |
|
| 1571 | + $name = 'doc.pdf'; |
|
| 1572 | + switch(strtoupper($dest)) |
|
| 1573 | + {
|
|
| 1574 | + case 'I': |
|
| 1575 | + // Send to standard output |
|
| 1576 | + $this->_checkoutput(); |
|
| 1577 | + if(PHP_SAPI!='cli') |
|
| 1578 | + {
|
|
| 1579 | + // We send to a browser |
|
| 1580 | + header('Content-Type: application/pdf; charset=UTF-8');
|
|
| 1581 | + header('Content-Disposition: inline; '.$this->_httpencode('filename',$name,$isUTF8));
|
|
| 1582 | + header('Cache-Control: private, max-age=0, must-revalidate');
|
|
| 1583 | + header('Pragma: public');
|
|
| 1584 | + } |
|
| 1585 | + echo $this->buffer; |
|
| 1586 | + break; |
|
| 1587 | + case 'D': |
|
| 1588 | + // Download file |
|
| 1589 | + $this->_checkoutput(); |
|
| 1590 | + header('Content-Type: application/x-download');
|
|
| 1591 | + header('Content-Disposition: attachment; '.$this->_httpencode('filename',$name,$isUTF8));
|
|
| 1592 | + header('Cache-Control: private, max-age=0, must-revalidate');
|
|
| 1593 | + header('Pragma: public');
|
|
| 1594 | + echo $this->buffer; |
|
| 1595 | + break; |
|
| 1596 | + case 'F': |
|
| 1597 | + // Save to local file |
|
| 1598 | + if(!file_put_contents($name,$this->buffer)) |
|
| 1599 | + $this->Error('Unable to create output file: '.$name);
|
|
| 1600 | + break; |
|
| 1601 | + case 'S': |
|
| 1602 | + // Return as a string |
|
| 1603 | + return $this->buffer; |
|
| 1604 | + default: |
|
| 1605 | + $this->Error('Incorrect output destination: '.$dest);
|
|
| 1606 | + } |
|
| 1607 | + return ''; |
|
| 1608 | 1608 | } |
| 1609 | 1609 | |
| 1610 | 1610 | /** |
@@ -1640,24 +1640,24 @@ discard block |
||
| 1640 | 1640 | */ |
| 1641 | 1641 | protected function _checkoutput() : void |
| 1642 | 1642 | {
|
| 1643 | - if(PHP_SAPI!='cli') |
|
| 1644 | - {
|
|
| 1645 | - $file = ''; |
|
| 1646 | - $line = 0; |
|
| 1647 | - if(headers_sent($file,$line)) |
|
| 1648 | - $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)");
|
|
| 1649 | - } |
|
| 1650 | - if(ob_get_length()) |
|
| 1651 | - {
|
|
| 1652 | - // The output buffer is not empty |
|
| 1653 | - if(preg_match('/^(\xEF\xBB\xBF)?\s*$/',ob_get_contents()))
|
|
| 1654 | - {
|
|
| 1655 | - // It contains only a UTF-8 BOM and/or whitespace, let's clean it |
|
| 1656 | - ob_clean(); |
|
| 1657 | - } |
|
| 1658 | - else |
|
| 1659 | - $this->Error("Some data has already been output, can't send PDF file");
|
|
| 1660 | - } |
|
| 1643 | + if(PHP_SAPI!='cli') |
|
| 1644 | + {
|
|
| 1645 | + $file = ''; |
|
| 1646 | + $line = 0; |
|
| 1647 | + if(headers_sent($file,$line)) |
|
| 1648 | + $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)");
|
|
| 1649 | + } |
|
| 1650 | + if(ob_get_length()) |
|
| 1651 | + {
|
|
| 1652 | + // The output buffer is not empty |
|
| 1653 | + if(preg_match('/^(\xEF\xBB\xBF)?\s*$/',ob_get_contents()))
|
|
| 1654 | + {
|
|
| 1655 | + // It contains only a UTF-8 BOM and/or whitespace, let's clean it |
|
| 1656 | + ob_clean(); |
|
| 1657 | + } |
|
| 1658 | + else |
|
| 1659 | + $this->Error("Some data has already been output, can't send PDF file");
|
|
| 1660 | + } |
|
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | 1663 | /** |
@@ -1700,49 +1700,49 @@ discard block |
||
| 1700 | 1700 | */ |
| 1701 | 1701 | protected function _beginpage(string $orientation, $size, int $rotation) : void |
| 1702 | 1702 | {
|
| 1703 | - $this->page++; |
|
| 1704 | - $this->pages[$this->page] = ''; |
|
| 1705 | - $this->state = 2; |
|
| 1706 | - $this->x = $this->lMargin; |
|
| 1707 | - $this->y = $this->tMargin; |
|
| 1708 | - $this->FontFamily = ''; |
|
| 1709 | - // Check page size and orientation |
|
| 1710 | - if($orientation=='') |
|
| 1711 | - $orientation = $this->DefOrientation; |
|
| 1712 | - else |
|
| 1713 | - $orientation = strtoupper($orientation[0]); |
|
| 1714 | - if($size=='') |
|
| 1715 | - $size = $this->DefPageSize; |
|
| 1716 | - else |
|
| 1717 | - $size = $this->getPageSize($size); |
|
| 1718 | - if($orientation!=$this->CurOrientation || $size[0]!=$this->CurPageSize[0] || $size[1]!=$this->CurPageSize[1]) |
|
| 1719 | - {
|
|
| 1720 | - // New size or orientation |
|
| 1721 | - if($orientation=='P') |
|
| 1722 | - {
|
|
| 1723 | - $this->w = $size[0]; |
|
| 1724 | - $this->h = $size[1]; |
|
| 1725 | - } |
|
| 1726 | - else |
|
| 1727 | - {
|
|
| 1728 | - $this->w = $size[1]; |
|
| 1729 | - $this->h = $size[0]; |
|
| 1730 | - } |
|
| 1731 | - $this->wPt = $this->w*$this->k; |
|
| 1732 | - $this->hPt = $this->h*$this->k; |
|
| 1733 | - $this->PageBreakTrigger = $this->h-$this->bMargin; |
|
| 1734 | - $this->CurOrientation = $orientation; |
|
| 1735 | - $this->CurPageSize = $size; |
|
| 1736 | - } |
|
| 1737 | - if($orientation!=$this->DefOrientation || $size[0]!=$this->DefPageSize[0] || $size[1]!=$this->DefPageSize[1]) |
|
| 1738 | - $this->PageInfo[$this->page]['size'] = array($this->wPt, $this->hPt); |
|
| 1739 | - if($rotation!=0) |
|
| 1740 | - {
|
|
| 1741 | - if($rotation%90!=0) |
|
| 1742 | - $this->Error('Incorrect rotation value: '.$rotation);
|
|
| 1743 | - $this->CurRotation = $rotation; |
|
| 1744 | - $this->PageInfo[$this->page]['rotation'] = $rotation; |
|
| 1745 | - } |
|
| 1703 | + $this->page++; |
|
| 1704 | + $this->pages[$this->page] = ''; |
|
| 1705 | + $this->state = 2; |
|
| 1706 | + $this->x = $this->lMargin; |
|
| 1707 | + $this->y = $this->tMargin; |
|
| 1708 | + $this->FontFamily = ''; |
|
| 1709 | + // Check page size and orientation |
|
| 1710 | + if($orientation=='') |
|
| 1711 | + $orientation = $this->DefOrientation; |
|
| 1712 | + else |
|
| 1713 | + $orientation = strtoupper($orientation[0]); |
|
| 1714 | + if($size=='') |
|
| 1715 | + $size = $this->DefPageSize; |
|
| 1716 | + else |
|
| 1717 | + $size = $this->getPageSize($size); |
|
| 1718 | + if($orientation!=$this->CurOrientation || $size[0]!=$this->CurPageSize[0] || $size[1]!=$this->CurPageSize[1]) |
|
| 1719 | + {
|
|
| 1720 | + // New size or orientation |
|
| 1721 | + if($orientation=='P') |
|
| 1722 | + {
|
|
| 1723 | + $this->w = $size[0]; |
|
| 1724 | + $this->h = $size[1]; |
|
| 1725 | + } |
|
| 1726 | + else |
|
| 1727 | + {
|
|
| 1728 | + $this->w = $size[1]; |
|
| 1729 | + $this->h = $size[0]; |
|
| 1730 | + } |
|
| 1731 | + $this->wPt = $this->w*$this->k; |
|
| 1732 | + $this->hPt = $this->h*$this->k; |
|
| 1733 | + $this->PageBreakTrigger = $this->h-$this->bMargin; |
|
| 1734 | + $this->CurOrientation = $orientation; |
|
| 1735 | + $this->CurPageSize = $size; |
|
| 1736 | + } |
|
| 1737 | + if($orientation!=$this->DefOrientation || $size[0]!=$this->DefPageSize[0] || $size[1]!=$this->DefPageSize[1]) |
|
| 1738 | + $this->PageInfo[$this->page]['size'] = array($this->wPt, $this->hPt); |
|
| 1739 | + if($rotation!=0) |
|
| 1740 | + {
|
|
| 1741 | + if($rotation%90!=0) |
|
| 1742 | + $this->Error('Incorrect rotation value: '.$rotation);
|
|
| 1743 | + $this->CurRotation = $rotation; |
|
| 1744 | + $this->PageInfo[$this->page]['rotation'] = $rotation; |
|
| 1745 | + } |
|
| 1746 | 1746 | } |
| 1747 | 1747 | |
| 1748 | 1748 | /** |
@@ -1750,7 +1750,7 @@ discard block |
||
| 1750 | 1750 | */ |
| 1751 | 1751 | protected function _endpage() : void |
| 1752 | 1752 | {
|
| 1753 | - $this->state = 1; |
|
| 1753 | + $this->state = 1; |
|
| 1754 | 1754 | } |
| 1755 | 1755 | |
| 1756 | 1756 | /** |
@@ -1760,27 +1760,27 @@ discard block |
||
| 1760 | 1760 | */ |
| 1761 | 1761 | protected function _loadfont(string $font) : array |
| 1762 | 1762 | {
|
| 1763 | - // Load a font definition file from the font directory |
|
| 1763 | + // Load a font definition file from the font directory |
|
| 1764 | 1764 | if(strpos($font,'/')!==false || strpos($font,"\\")!==false) {
|
| 1765 | - $this->Error('Incorrect font definition file name: '.$font);
|
|
| 1765 | + $this->Error('Incorrect font definition file name: '.$font);
|
|
| 1766 | 1766 | } |
| 1767 | 1767 | // following vars must be initialized in the font definition file beeing included |
| 1768 | - $name = null; |
|
| 1769 | - $enc = null; |
|
| 1770 | - $subsetted = null; |
|
| 1771 | - include($this->fontpath.$font); |
|
| 1768 | + $name = null; |
|
| 1769 | + $enc = null; |
|
| 1770 | + $subsetted = null; |
|
| 1771 | + include($this->fontpath.$font); |
|
| 1772 | 1772 | |
| 1773 | - // phpstan can't see the code dynamicly included before so assuming $name, $enc, $subsetted always set to null! |
|
| 1774 | - if(!isset($name)) { /* @phpstan-ignore-line */
|
|
| 1775 | - $this->Error('Could not include font definition file');
|
|
| 1776 | - } |
|
| 1777 | - if(isset($enc)) { /* @phpstan-ignore-line */
|
|
| 1778 | - $enc = strtolower($enc); |
|
| 1779 | - } |
|
| 1780 | - if(!isset($subsetted)) { /* @phpstan-ignore-line */
|
|
| 1781 | - $subsetted = false; |
|
| 1782 | - } |
|
| 1783 | - return get_defined_vars(); |
|
| 1773 | + // phpstan can't see the code dynamicly included before so assuming $name, $enc, $subsetted always set to null! |
|
| 1774 | + if(!isset($name)) { /* @phpstan-ignore-line */
|
|
| 1775 | + $this->Error('Could not include font definition file');
|
|
| 1776 | + } |
|
| 1777 | + if(isset($enc)) { /* @phpstan-ignore-line */
|
|
| 1778 | + $enc = strtolower($enc); |
|
| 1779 | + } |
|
| 1780 | + if(!isset($subsetted)) { /* @phpstan-ignore-line */
|
|
| 1781 | + $subsetted = false; |
|
| 1782 | + } |
|
| 1783 | + return get_defined_vars(); |
|
| 1784 | 1784 | } |
| 1785 | 1785 | |
| 1786 | 1786 | /** |
@@ -1790,14 +1790,14 @@ discard block |
||
| 1790 | 1790 | */ |
| 1791 | 1791 | protected function _isascii(string $s) : bool |
| 1792 | 1792 | {
|
| 1793 | - // Test if string is ASCII |
|
| 1794 | - $nb = strlen($s); |
|
| 1795 | - for($i=0;$i<$nb;$i++) |
|
| 1796 | - {
|
|
| 1797 | - if(ord($s[$i])>127) |
|
| 1798 | - return false; |
|
| 1799 | - } |
|
| 1800 | - return true; |
|
| 1793 | + // Test if string is ASCII |
|
| 1794 | + $nb = strlen($s); |
|
| 1795 | + for($i=0;$i<$nb;$i++) |
|
| 1796 | + {
|
|
| 1797 | + if(ord($s[$i])>127) |
|
| 1798 | + return false; |
|
| 1799 | + } |
|
| 1800 | + return true; |
|
| 1801 | 1801 | } |
| 1802 | 1802 | |
| 1803 | 1803 | /** |
@@ -1808,15 +1808,15 @@ discard block |
||
| 1808 | 1808 | */ |
| 1809 | 1809 | protected function _httpencode(string $param, string $value, bool $isUTF8) : string |
| 1810 | 1810 | {
|
| 1811 | - // Encode HTTP header field parameter |
|
| 1812 | - if($this->_isascii($value)) |
|
| 1813 | - return $param.'="'.$value.'"'; |
|
| 1814 | - if(!$isUTF8) |
|
| 1815 | - $value = utf8_encode($value); |
|
| 1816 | - if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==false) |
|
| 1817 | - return $param.'="'.rawurlencode($value).'"'; |
|
| 1818 | - else |
|
| 1819 | - return $param."*=UTF-8''".rawurlencode($value); |
|
| 1811 | + // Encode HTTP header field parameter |
|
| 1812 | + if($this->_isascii($value)) |
|
| 1813 | + return $param.'="'.$value.'"'; |
|
| 1814 | + if(!$isUTF8) |
|
| 1815 | + $value = utf8_encode($value); |
|
| 1816 | + if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==false) |
|
| 1817 | + return $param.'="'.rawurlencode($value).'"'; |
|
| 1818 | + else |
|
| 1819 | + return $param."*=UTF-8''".rawurlencode($value); |
|
| 1820 | 1820 | } |
| 1821 | 1821 | |
| 1822 | 1822 | /** |
@@ -1826,35 +1826,35 @@ discard block |
||
| 1826 | 1826 | */ |
| 1827 | 1827 | protected function _UTF8toUTF16(string $s) : string |
| 1828 | 1828 | {
|
| 1829 | - // Convert UTF-8 to UTF-16BE with BOM |
|
| 1830 | - $res = "\xFE\xFF"; |
|
| 1831 | - $nb = strlen($s); |
|
| 1832 | - $i = 0; |
|
| 1833 | - while($i<$nb) |
|
| 1834 | - {
|
|
| 1835 | - $c1 = ord($s[$i++]); |
|
| 1836 | - if($c1>=224) |
|
| 1837 | - {
|
|
| 1838 | - // 3-byte character |
|
| 1839 | - $c2 = ord($s[$i++]); |
|
| 1840 | - $c3 = ord($s[$i++]); |
|
| 1841 | - $res .= chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2)); |
|
| 1842 | - $res .= chr((($c2 & 0x03)<<6) + ($c3 & 0x3F)); |
|
| 1843 | - } |
|
| 1844 | - elseif($c1>=192) |
|
| 1845 | - {
|
|
| 1846 | - // 2-byte character |
|
| 1847 | - $c2 = ord($s[$i++]); |
|
| 1848 | - $res .= chr(($c1 & 0x1C)>>2); |
|
| 1849 | - $res .= chr((($c1 & 0x03)<<6) + ($c2 & 0x3F)); |
|
| 1850 | - } |
|
| 1851 | - else |
|
| 1852 | - {
|
|
| 1853 | - // Single-byte character |
|
| 1854 | - $res .= "\0".chr($c1); |
|
| 1855 | - } |
|
| 1856 | - } |
|
| 1857 | - return $res; |
|
| 1829 | + // Convert UTF-8 to UTF-16BE with BOM |
|
| 1830 | + $res = "\xFE\xFF"; |
|
| 1831 | + $nb = strlen($s); |
|
| 1832 | + $i = 0; |
|
| 1833 | + while($i<$nb) |
|
| 1834 | + {
|
|
| 1835 | + $c1 = ord($s[$i++]); |
|
| 1836 | + if($c1>=224) |
|
| 1837 | + {
|
|
| 1838 | + // 3-byte character |
|
| 1839 | + $c2 = ord($s[$i++]); |
|
| 1840 | + $c3 = ord($s[$i++]); |
|
| 1841 | + $res .= chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2)); |
|
| 1842 | + $res .= chr((($c2 & 0x03)<<6) + ($c3 & 0x3F)); |
|
| 1843 | + } |
|
| 1844 | + elseif($c1>=192) |
|
| 1845 | + {
|
|
| 1846 | + // 2-byte character |
|
| 1847 | + $c2 = ord($s[$i++]); |
|
| 1848 | + $res .= chr(($c1 & 0x1C)>>2); |
|
| 1849 | + $res .= chr((($c1 & 0x03)<<6) + ($c2 & 0x3F)); |
|
| 1850 | + } |
|
| 1851 | + else |
|
| 1852 | + {
|
|
| 1853 | + // Single-byte character |
|
| 1854 | + $res .= "\0".chr($c1); |
|
| 1855 | + } |
|
| 1856 | + } |
|
| 1857 | + return $res; |
|
| 1858 | 1858 | } |
| 1859 | 1859 | |
| 1860 | 1860 | /** |
@@ -1864,11 +1864,11 @@ discard block |
||
| 1864 | 1864 | */ |
| 1865 | 1865 | protected function _escape(string $s) : string |
| 1866 | 1866 | {
|
| 1867 | - // Escape special characters |
|
| 1868 | - if(strpos($s,'(')!==false || strpos($s,')')!==false || strpos($s,'\\')!==false || strpos($s,"\r")!==false)
|
|
| 1869 | - return str_replace(array('\\','(',')',"\r"), array('\\\\','\\(','\\)','\\r'), $s);
|
|
| 1870 | - else |
|
| 1871 | - return $s; |
|
| 1867 | + // Escape special characters |
|
| 1868 | + if(strpos($s,'(')!==false || strpos($s,')')!==false || strpos($s,'\\')!==false || strpos($s,"\r")!==false)
|
|
| 1869 | + return str_replace(array('\\','(',')',"\r"), array('\\\\','\\(','\\)','\\r'), $s);
|
|
| 1870 | + else |
|
| 1871 | + return $s; |
|
| 1872 | 1872 | } |
| 1873 | 1873 | |
| 1874 | 1874 | /** |
@@ -1878,10 +1878,10 @@ discard block |
||
| 1878 | 1878 | */ |
| 1879 | 1879 | protected function _textstring(string $s) : string |
| 1880 | 1880 | {
|
| 1881 | - // Format a text string |
|
| 1882 | - if(!$this->_isascii($s)) |
|
| 1883 | - $s = $this->_UTF8toUTF16($s); |
|
| 1884 | - return '('.$this->_escape($s).')';
|
|
| 1881 | + // Format a text string |
|
| 1882 | + if(!$this->_isascii($s)) |
|
| 1883 | + $s = $this->_UTF8toUTF16($s); |
|
| 1884 | + return '('.$this->_escape($s).')';
|
|
| 1885 | 1885 | } |
| 1886 | 1886 | |
| 1887 | 1887 | /** |
@@ -1893,11 +1893,11 @@ discard block |
||
| 1893 | 1893 | */ |
| 1894 | 1894 | protected function _dounderline(float $x, float $y, string $txt) : string |
| 1895 | 1895 | {
|
| 1896 | - // Underline text |
|
| 1897 | - $up = $this->CurrentFont['up']; |
|
| 1898 | - $ut = $this->CurrentFont['ut']; |
|
| 1899 | - $w = $this->getStringWidth($txt)+$this->ws*substr_count($txt,' '); |
|
| 1900 | - 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);
|
|
| 1896 | + // Underline text |
|
| 1897 | + $up = $this->CurrentFont['up']; |
|
| 1898 | + $ut = $this->CurrentFont['ut']; |
|
| 1899 | + $w = $this->getStringWidth($txt)+$this->ws*substr_count($txt,' '); |
|
| 1900 | + 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 | 1901 | } |
| 1902 | 1902 | |
| 1903 | 1903 | /** |
@@ -1907,21 +1907,21 @@ discard block |
||
| 1907 | 1907 | */ |
| 1908 | 1908 | protected function _parsejpg(string $file) : array |
| 1909 | 1909 | {
|
| 1910 | - // Extract info from a JPEG file |
|
| 1911 | - $a = getimagesize($file); |
|
| 1912 | - if(!$a) |
|
| 1913 | - $this->Error('Missing or incorrect image file: '.$file);
|
|
| 1914 | - if($a[2]!=2) |
|
| 1915 | - $this->Error('Not a JPEG file: '.$file);
|
|
| 1916 | - if(!isset($a['channels']) || $a['channels']==3) |
|
| 1917 | - $colspace = 'DeviceRGB'; |
|
| 1918 | - elseif($a['channels']==4) |
|
| 1919 | - $colspace = 'DeviceCMYK'; |
|
| 1920 | - else |
|
| 1921 | - $colspace = 'DeviceGray'; |
|
| 1922 | - $bpc = isset($a['bits']) ? $a['bits'] : 8; |
|
| 1923 | - $data = file_get_contents($file); |
|
| 1924 | - return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data);
|
|
| 1910 | + // Extract info from a JPEG file |
|
| 1911 | + $a = getimagesize($file); |
|
| 1912 | + if(!$a) |
|
| 1913 | + $this->Error('Missing or incorrect image file: '.$file);
|
|
| 1914 | + if($a[2]!=2) |
|
| 1915 | + $this->Error('Not a JPEG file: '.$file);
|
|
| 1916 | + if(!isset($a['channels']) || $a['channels']==3) |
|
| 1917 | + $colspace = 'DeviceRGB'; |
|
| 1918 | + elseif($a['channels']==4) |
|
| 1919 | + $colspace = 'DeviceCMYK'; |
|
| 1920 | + else |
|
| 1921 | + $colspace = 'DeviceGray'; |
|
| 1922 | + $bpc = isset($a['bits']) ? $a['bits'] : 8; |
|
| 1923 | + $data = file_get_contents($file); |
|
| 1924 | + return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data);
|
|
| 1925 | 1925 | } |
| 1926 | 1926 | |
| 1927 | 1927 | /** |
@@ -1931,14 +1931,14 @@ discard block |
||
| 1931 | 1931 | */ |
| 1932 | 1932 | protected function _parsepng(string $file) : array |
| 1933 | 1933 | {
|
| 1934 | - // Extract info from a PNG file |
|
| 1935 | - $f = fopen($file, 'rb'); |
|
| 1936 | - if ($f === false) {
|
|
| 1937 | - $this->Error('Can\'t open image file: ' . $file);
|
|
| 1938 | - } |
|
| 1939 | - $info = $this->_parsepngstream($f, $file); |
|
| 1940 | - fclose($f); |
|
| 1941 | - return $info; |
|
| 1934 | + // Extract info from a PNG file |
|
| 1935 | + $f = fopen($file, 'rb'); |
|
| 1936 | + if ($f === false) {
|
|
| 1937 | + $this->Error('Can\'t open image file: ' . $file);
|
|
| 1938 | + } |
|
| 1939 | + $info = $this->_parsepngstream($f, $file); |
|
| 1940 | + fclose($f); |
|
| 1941 | + return $info; |
|
| 1942 | 1942 | } |
| 1943 | 1943 | |
| 1944 | 1944 | /** |
@@ -1949,129 +1949,129 @@ discard block |
||
| 1949 | 1949 | */ |
| 1950 | 1950 | protected function _parsepngstream($f, string $file) : array |
| 1951 | 1951 | {
|
| 1952 | - // Check signature |
|
| 1953 | - if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) |
|
| 1954 | - $this->Error('Not a PNG file: '.$file);
|
|
| 1955 | - |
|
| 1956 | - // Read header chunk |
|
| 1957 | - $this->_readstream($f,4); |
|
| 1958 | - if($this->_readstream($f,4)!='IHDR') |
|
| 1959 | - $this->Error('Incorrect PNG file: '.$file);
|
|
| 1960 | - $w = $this->_readint($f); |
|
| 1961 | - $h = $this->_readint($f); |
|
| 1962 | - $bpc = ord($this->_readstream($f,1)); |
|
| 1963 | - if($bpc>8) |
|
| 1964 | - $this->Error('16-bit depth not supported: '.$file);
|
|
| 1965 | - $ct = ord($this->_readstream($f,1)); |
|
| 1966 | - $colspace = ''; |
|
| 1967 | - if($ct==0 || $ct==4) |
|
| 1968 | - $colspace = 'DeviceGray'; |
|
| 1969 | - elseif($ct==2 || $ct==6) |
|
| 1970 | - $colspace = 'DeviceRGB'; |
|
| 1971 | - elseif($ct==3) |
|
| 1972 | - $colspace = 'Indexed'; |
|
| 1973 | - else |
|
| 1974 | - $this->Error('Unknown color type: '.$file);
|
|
| 1975 | - if(ord($this->_readstream($f,1))!=0) |
|
| 1976 | - $this->Error('Unknown compression method: '.$file);
|
|
| 1977 | - if(ord($this->_readstream($f,1))!=0) |
|
| 1978 | - $this->Error('Unknown filter method: '.$file);
|
|
| 1979 | - if(ord($this->_readstream($f,1))!=0) |
|
| 1980 | - $this->Error('Interlacing not supported: '.$file);
|
|
| 1981 | - $this->_readstream($f,4); |
|
| 1982 | - $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w; |
|
| 1983 | - |
|
| 1984 | - // Scan chunks looking for palette, transparency and image data |
|
| 1985 | - $pal = ''; |
|
| 1986 | - $trns = ''; |
|
| 1987 | - $data = ''; |
|
| 1988 | - do |
|
| 1989 | - {
|
|
| 1990 | - $n = $this->_readint($f); |
|
| 1991 | - $type = $this->_readstream($f,4); |
|
| 1992 | - if($type=='PLTE') |
|
| 1993 | - {
|
|
| 1994 | - // Read palette |
|
| 1995 | - $pal = $this->_readstream($f,$n); |
|
| 1996 | - $this->_readstream($f,4); |
|
| 1997 | - } |
|
| 1998 | - elseif($type=='tRNS') |
|
| 1999 | - {
|
|
| 2000 | - // Read transparency info |
|
| 2001 | - $t = $this->_readstream($f,$n); |
|
| 2002 | - if($ct==0) |
|
| 2003 | - $trns = array(ord(substr($t,1,1))); |
|
| 2004 | - elseif($ct==2) |
|
| 2005 | - $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); |
|
| 2006 | - else |
|
| 2007 | - {
|
|
| 2008 | - $pos = strpos($t,chr(0)); |
|
| 2009 | - if($pos!==false) |
|
| 2010 | - $trns = array($pos); |
|
| 2011 | - } |
|
| 2012 | - $this->_readstream($f,4); |
|
| 2013 | - } |
|
| 2014 | - elseif($type=='IDAT') |
|
| 2015 | - {
|
|
| 2016 | - // Read image data block |
|
| 2017 | - $data .= $this->_readstream($f,$n); |
|
| 2018 | - $this->_readstream($f,4); |
|
| 2019 | - } |
|
| 2020 | - elseif($type=='IEND') |
|
| 2021 | - break; |
|
| 2022 | - else |
|
| 2023 | - $this->_readstream($f,$n+4); |
|
| 2024 | - } |
|
| 2025 | - while($n); |
|
| 2026 | - |
|
| 2027 | - if($colspace=='Indexed' && empty($pal)) |
|
| 2028 | - $this->Error('Missing palette in '.$file);
|
|
| 2029 | - $info = array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns);
|
|
| 2030 | - if($ct>=4) |
|
| 2031 | - {
|
|
| 2032 | - // Extract alpha channel |
|
| 2033 | - if(!function_exists('gzuncompress'))
|
|
| 2034 | - $this->Error('Zlib not available, can\'t handle alpha channel: '.$file);
|
|
| 2035 | - $data = gzuncompress($data); |
|
| 2036 | - $color = ''; |
|
| 2037 | - $alpha = ''; |
|
| 2038 | - if($ct==4) |
|
| 2039 | - {
|
|
| 2040 | - // Gray image |
|
| 2041 | - $len = 2*$w; |
|
| 2042 | - for($i=0;$i<$h;$i++) |
|
| 2043 | - {
|
|
| 2044 | - $pos = (1+$len)*$i; |
|
| 2045 | - $color .= $data[$pos]; |
|
| 2046 | - $alpha .= $data[$pos]; |
|
| 2047 | - $line = substr($data,$pos+1,$len); |
|
| 2048 | - $color .= preg_replace('/(.)./s','$1',$line);
|
|
| 2049 | - $alpha .= preg_replace('/.(.)/s','$1',$line);
|
|
| 2050 | - } |
|
| 2051 | - } |
|
| 2052 | - else |
|
| 2053 | - {
|
|
| 2054 | - // RGB image |
|
| 2055 | - $len = 4*$w; |
|
| 2056 | - for($i=0;$i<$h;$i++) |
|
| 2057 | - {
|
|
| 2058 | - $pos = (1+$len)*$i; |
|
| 2059 | - $color .= $data[$pos]; |
|
| 2060 | - $alpha .= $data[$pos]; |
|
| 2061 | - $line = substr($data,$pos+1,$len); |
|
| 2062 | - $color .= preg_replace('/(.{3})./s','$1',$line);
|
|
| 2063 | - $alpha .= preg_replace('/.{3}(.)/s','$1',$line);
|
|
| 2064 | - } |
|
| 2065 | - } |
|
| 2066 | - unset($data); |
|
| 2067 | - $data = gzcompress($color); |
|
| 2068 | - $info['smask'] = gzcompress($alpha); |
|
| 2069 | - $this->WithAlpha = true; |
|
| 2070 | - if($this->PDFVersion<'1.4') |
|
| 2071 | - $this->PDFVersion = '1.4'; |
|
| 2072 | - } |
|
| 2073 | - $info['data'] = $data; |
|
| 2074 | - return $info; |
|
| 1952 | + // Check signature |
|
| 1953 | + if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) |
|
| 1954 | + $this->Error('Not a PNG file: '.$file);
|
|
| 1955 | + |
|
| 1956 | + // Read header chunk |
|
| 1957 | + $this->_readstream($f,4); |
|
| 1958 | + if($this->_readstream($f,4)!='IHDR') |
|
| 1959 | + $this->Error('Incorrect PNG file: '.$file);
|
|
| 1960 | + $w = $this->_readint($f); |
|
| 1961 | + $h = $this->_readint($f); |
|
| 1962 | + $bpc = ord($this->_readstream($f,1)); |
|
| 1963 | + if($bpc>8) |
|
| 1964 | + $this->Error('16-bit depth not supported: '.$file);
|
|
| 1965 | + $ct = ord($this->_readstream($f,1)); |
|
| 1966 | + $colspace = ''; |
|
| 1967 | + if($ct==0 || $ct==4) |
|
| 1968 | + $colspace = 'DeviceGray'; |
|
| 1969 | + elseif($ct==2 || $ct==6) |
|
| 1970 | + $colspace = 'DeviceRGB'; |
|
| 1971 | + elseif($ct==3) |
|
| 1972 | + $colspace = 'Indexed'; |
|
| 1973 | + else |
|
| 1974 | + $this->Error('Unknown color type: '.$file);
|
|
| 1975 | + if(ord($this->_readstream($f,1))!=0) |
|
| 1976 | + $this->Error('Unknown compression method: '.$file);
|
|
| 1977 | + if(ord($this->_readstream($f,1))!=0) |
|
| 1978 | + $this->Error('Unknown filter method: '.$file);
|
|
| 1979 | + if(ord($this->_readstream($f,1))!=0) |
|
| 1980 | + $this->Error('Interlacing not supported: '.$file);
|
|
| 1981 | + $this->_readstream($f,4); |
|
| 1982 | + $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w; |
|
| 1983 | + |
|
| 1984 | + // Scan chunks looking for palette, transparency and image data |
|
| 1985 | + $pal = ''; |
|
| 1986 | + $trns = ''; |
|
| 1987 | + $data = ''; |
|
| 1988 | + do |
|
| 1989 | + {
|
|
| 1990 | + $n = $this->_readint($f); |
|
| 1991 | + $type = $this->_readstream($f,4); |
|
| 1992 | + if($type=='PLTE') |
|
| 1993 | + {
|
|
| 1994 | + // Read palette |
|
| 1995 | + $pal = $this->_readstream($f,$n); |
|
| 1996 | + $this->_readstream($f,4); |
|
| 1997 | + } |
|
| 1998 | + elseif($type=='tRNS') |
|
| 1999 | + {
|
|
| 2000 | + // Read transparency info |
|
| 2001 | + $t = $this->_readstream($f,$n); |
|
| 2002 | + if($ct==0) |
|
| 2003 | + $trns = array(ord(substr($t,1,1))); |
|
| 2004 | + elseif($ct==2) |
|
| 2005 | + $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); |
|
| 2006 | + else |
|
| 2007 | + {
|
|
| 2008 | + $pos = strpos($t,chr(0)); |
|
| 2009 | + if($pos!==false) |
|
| 2010 | + $trns = array($pos); |
|
| 2011 | + } |
|
| 2012 | + $this->_readstream($f,4); |
|
| 2013 | + } |
|
| 2014 | + elseif($type=='IDAT') |
|
| 2015 | + {
|
|
| 2016 | + // Read image data block |
|
| 2017 | + $data .= $this->_readstream($f,$n); |
|
| 2018 | + $this->_readstream($f,4); |
|
| 2019 | + } |
|
| 2020 | + elseif($type=='IEND') |
|
| 2021 | + break; |
|
| 2022 | + else |
|
| 2023 | + $this->_readstream($f,$n+4); |
|
| 2024 | + } |
|
| 2025 | + while($n); |
|
| 2026 | + |
|
| 2027 | + if($colspace=='Indexed' && empty($pal)) |
|
| 2028 | + $this->Error('Missing palette in '.$file);
|
|
| 2029 | + $info = array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns);
|
|
| 2030 | + if($ct>=4) |
|
| 2031 | + {
|
|
| 2032 | + // Extract alpha channel |
|
| 2033 | + if(!function_exists('gzuncompress'))
|
|
| 2034 | + $this->Error('Zlib not available, can\'t handle alpha channel: '.$file);
|
|
| 2035 | + $data = gzuncompress($data); |
|
| 2036 | + $color = ''; |
|
| 2037 | + $alpha = ''; |
|
| 2038 | + if($ct==4) |
|
| 2039 | + {
|
|
| 2040 | + // Gray image |
|
| 2041 | + $len = 2*$w; |
|
| 2042 | + for($i=0;$i<$h;$i++) |
|
| 2043 | + {
|
|
| 2044 | + $pos = (1+$len)*$i; |
|
| 2045 | + $color .= $data[$pos]; |
|
| 2046 | + $alpha .= $data[$pos]; |
|
| 2047 | + $line = substr($data,$pos+1,$len); |
|
| 2048 | + $color .= preg_replace('/(.)./s','$1',$line);
|
|
| 2049 | + $alpha .= preg_replace('/.(.)/s','$1',$line);
|
|
| 2050 | + } |
|
| 2051 | + } |
|
| 2052 | + else |
|
| 2053 | + {
|
|
| 2054 | + // RGB image |
|
| 2055 | + $len = 4*$w; |
|
| 2056 | + for($i=0;$i<$h;$i++) |
|
| 2057 | + {
|
|
| 2058 | + $pos = (1+$len)*$i; |
|
| 2059 | + $color .= $data[$pos]; |
|
| 2060 | + $alpha .= $data[$pos]; |
|
| 2061 | + $line = substr($data,$pos+1,$len); |
|
| 2062 | + $color .= preg_replace('/(.{3})./s','$1',$line);
|
|
| 2063 | + $alpha .= preg_replace('/.{3}(.)/s','$1',$line);
|
|
| 2064 | + } |
|
| 2065 | + } |
|
| 2066 | + unset($data); |
|
| 2067 | + $data = gzcompress($color); |
|
| 2068 | + $info['smask'] = gzcompress($alpha); |
|
| 2069 | + $this->WithAlpha = true; |
|
| 2070 | + if($this->PDFVersion<'1.4') |
|
| 2071 | + $this->PDFVersion = '1.4'; |
|
| 2072 | + } |
|
| 2073 | + $info['data'] = $data; |
|
| 2074 | + return $info; |
|
| 2075 | 2075 | } |
| 2076 | 2076 | |
| 2077 | 2077 | /** |
@@ -2082,19 +2082,19 @@ discard block |
||
| 2082 | 2082 | */ |
| 2083 | 2083 | protected function _readstream($f, int $n) : string |
| 2084 | 2084 | {
|
| 2085 | - // Read n bytes from stream |
|
| 2086 | - $res = ''; |
|
| 2087 | - while($n>0 && !feof($f)) |
|
| 2088 | - {
|
|
| 2089 | - $s = fread($f,$n); |
|
| 2090 | - if($s===false) |
|
| 2091 | - $this->Error('Error while reading stream');
|
|
| 2092 | - $n -= strlen($s); |
|
| 2093 | - $res .= $s; |
|
| 2094 | - } |
|
| 2095 | - if($n>0) |
|
| 2096 | - $this->Error('Unexpected end of stream');
|
|
| 2097 | - return $res; |
|
| 2085 | + // Read n bytes from stream |
|
| 2086 | + $res = ''; |
|
| 2087 | + while($n>0 && !feof($f)) |
|
| 2088 | + {
|
|
| 2089 | + $s = fread($f,$n); |
|
| 2090 | + if($s===false) |
|
| 2091 | + $this->Error('Error while reading stream');
|
|
| 2092 | + $n -= strlen($s); |
|
| 2093 | + $res .= $s; |
|
| 2094 | + } |
|
| 2095 | + if($n>0) |
|
| 2096 | + $this->Error('Unexpected end of stream');
|
|
| 2097 | + return $res; |
|
| 2098 | 2098 | } |
| 2099 | 2099 | |
| 2100 | 2100 | /** |
@@ -2104,9 +2104,9 @@ discard block |
||
| 2104 | 2104 | */ |
| 2105 | 2105 | protected function _readint($f) : int |
| 2106 | 2106 | {
|
| 2107 | - // Read a 4-byte integer from stream |
|
| 2108 | - $a = unpack('Ni',$this->_readstream($f,4));
|
|
| 2109 | - return $a['i']; |
|
| 2107 | + // Read a 4-byte integer from stream |
|
| 2108 | + $a = unpack('Ni',$this->_readstream($f,4));
|
|
| 2109 | + return $a['i']; |
|
| 2110 | 2110 | } |
| 2111 | 2111 | |
| 2112 | 2112 | /** |
@@ -2116,31 +2116,31 @@ discard block |
||
| 2116 | 2116 | */ |
| 2117 | 2117 | protected function _parsegif(string $file) : array |
| 2118 | 2118 | {
|
| 2119 | - // Extract info from a GIF file (via PNG conversion) |
|
| 2119 | + // Extract info from a GIF file (via PNG conversion) |
|
| 2120 | 2120 | if (!function_exists('imagepng')) {
|
| 2121 | - $this->Error('GD extension is required for GIF support');
|
|
| 2121 | + $this->Error('GD extension is required for GIF support');
|
|
| 2122 | 2122 | } |
| 2123 | 2123 | if (!function_exists('imagecreatefromgif')) {
|
| 2124 | - $this->Error('GD has no GIF read support');
|
|
| 2125 | - } |
|
| 2126 | - $im = imagecreatefromgif($file); |
|
| 2127 | - if ($im === false) {
|
|
| 2128 | - $this->Error('Missing or incorrect image file: ' . $file);
|
|
| 2129 | - } |
|
| 2130 | - imageinterlace($im, 0); |
|
| 2131 | - ob_start(); |
|
| 2132 | - imagepng($im); |
|
| 2133 | - $data = ob_get_clean(); |
|
| 2134 | - imagedestroy($im); |
|
| 2135 | - $f = fopen('php://temp', 'rb+');
|
|
| 2136 | - if ($f === false) {
|
|
| 2137 | - $this->Error('Unable to create memory stream');
|
|
| 2138 | - } |
|
| 2139 | - fwrite($f, $data); |
|
| 2140 | - rewind($f); |
|
| 2141 | - $info = $this->_parsepngstream($f, $file); |
|
| 2142 | - fclose($f); |
|
| 2143 | - return $info; |
|
| 2124 | + $this->Error('GD has no GIF read support');
|
|
| 2125 | + } |
|
| 2126 | + $im = imagecreatefromgif($file); |
|
| 2127 | + if ($im === false) {
|
|
| 2128 | + $this->Error('Missing or incorrect image file: ' . $file);
|
|
| 2129 | + } |
|
| 2130 | + imageinterlace($im, 0); |
|
| 2131 | + ob_start(); |
|
| 2132 | + imagepng($im); |
|
| 2133 | + $data = ob_get_clean(); |
|
| 2134 | + imagedestroy($im); |
|
| 2135 | + $f = fopen('php://temp', 'rb+');
|
|
| 2136 | + if ($f === false) {
|
|
| 2137 | + $this->Error('Unable to create memory stream');
|
|
| 2138 | + } |
|
| 2139 | + fwrite($f, $data); |
|
| 2140 | + rewind($f); |
|
| 2141 | + $info = $this->_parsepngstream($f, $file); |
|
| 2142 | + fclose($f); |
|
| 2143 | + return $info; |
|
| 2144 | 2144 | } |
| 2145 | 2145 | |
| 2146 | 2146 | /** |
@@ -2149,15 +2149,15 @@ discard block |
||
| 2149 | 2149 | */ |
| 2150 | 2150 | protected function _out(string $s) : void |
| 2151 | 2151 | {
|
| 2152 | - // Add a line to the document |
|
| 2153 | - if($this->state==2) |
|
| 2154 | - $this->pages[$this->page] .= $s."\n"; |
|
| 2155 | - elseif($this->state==1) |
|
| 2156 | - $this->_put($s); |
|
| 2157 | - elseif($this->state==0) |
|
| 2158 | - $this->Error('No page has been added yet');
|
|
| 2159 | - elseif($this->state==3) |
|
| 2160 | - $this->Error('The document is closed');
|
|
| 2152 | + // Add a line to the document |
|
| 2153 | + if($this->state==2) |
|
| 2154 | + $this->pages[$this->page] .= $s."\n"; |
|
| 2155 | + elseif($this->state==1) |
|
| 2156 | + $this->_put($s); |
|
| 2157 | + elseif($this->state==0) |
|
| 2158 | + $this->Error('No page has been added yet');
|
|
| 2159 | + elseif($this->state==3) |
|
| 2160 | + $this->Error('The document is closed');
|
|
| 2161 | 2161 | } |
| 2162 | 2162 | |
| 2163 | 2163 | /** |
@@ -2166,7 +2166,7 @@ discard block |
||
| 2166 | 2166 | */ |
| 2167 | 2167 | protected function _put(string $s) : void |
| 2168 | 2168 | {
|
| 2169 | - $this->buffer .= $s."\n"; |
|
| 2169 | + $this->buffer .= $s."\n"; |
|
| 2170 | 2170 | } |
| 2171 | 2171 | |
| 2172 | 2172 | /** |
@@ -2175,7 +2175,7 @@ discard block |
||
| 2175 | 2175 | */ |
| 2176 | 2176 | protected function _getoffset() : int |
| 2177 | 2177 | {
|
| 2178 | - return strlen($this->buffer); |
|
| 2178 | + return strlen($this->buffer); |
|
| 2179 | 2179 | } |
| 2180 | 2180 | |
| 2181 | 2181 | /** |
@@ -2184,11 +2184,11 @@ discard block |
||
| 2184 | 2184 | */ |
| 2185 | 2185 | protected function _newobj(?int $n=null) : void |
| 2186 | 2186 | {
|
| 2187 | - // Begin a new object |
|
| 2188 | - if($n===null) |
|
| 2189 | - $n = ++$this->n; |
|
| 2190 | - $this->offsets[$n] = $this->_getoffset(); |
|
| 2191 | - $this->_put($n.' 0 obj'); |
|
| 2187 | + // Begin a new object |
|
| 2188 | + if($n===null) |
|
| 2189 | + $n = ++$this->n; |
|
| 2190 | + $this->offsets[$n] = $this->_getoffset(); |
|
| 2191 | + $this->_put($n.' 0 obj'); |
|
| 2192 | 2192 | } |
| 2193 | 2193 | |
| 2194 | 2194 | /** |
@@ -2197,9 +2197,9 @@ discard block |
||
| 2197 | 2197 | */ |
| 2198 | 2198 | protected function _putstream(string $data) : void |
| 2199 | 2199 | {
|
| 2200 | - $this->_put('stream');
|
|
| 2201 | - $this->_put($data); |
|
| 2202 | - $this->_put('endstream');
|
|
| 2200 | + $this->_put('stream');
|
|
| 2201 | + $this->_put($data); |
|
| 2202 | + $this->_put('endstream');
|
|
| 2203 | 2203 | } |
| 2204 | 2204 | |
| 2205 | 2205 | /** |
@@ -2208,18 +2208,18 @@ discard block |
||
| 2208 | 2208 | */ |
| 2209 | 2209 | protected function _putstreamobject(string $data) : void |
| 2210 | 2210 | {
|
| 2211 | - if($this->compress) |
|
| 2212 | - {
|
|
| 2213 | - $entries = '/Filter /FlateDecode '; |
|
| 2214 | - $data = gzcompress($data); |
|
| 2215 | - } |
|
| 2216 | - else |
|
| 2217 | - $entries = ''; |
|
| 2218 | - $entries .= '/Length '.strlen($data); |
|
| 2219 | - $this->_newobj(); |
|
| 2220 | - $this->_put('<<'.$entries.'>>');
|
|
| 2221 | - $this->_putstream($data); |
|
| 2222 | - $this->_put('endobj');
|
|
| 2211 | + if($this->compress) |
|
| 2212 | + {
|
|
| 2213 | + $entries = '/Filter /FlateDecode '; |
|
| 2214 | + $data = gzcompress($data); |
|
| 2215 | + } |
|
| 2216 | + else |
|
| 2217 | + $entries = ''; |
|
| 2218 | + $entries .= '/Length '.strlen($data); |
|
| 2219 | + $this->_newobj(); |
|
| 2220 | + $this->_put('<<'.$entries.'>>');
|
|
| 2221 | + $this->_putstream($data); |
|
| 2222 | + $this->_put('endobj');
|
|
| 2223 | 2223 | } |
| 2224 | 2224 | |
| 2225 | 2225 | /** |
@@ -2228,44 +2228,44 @@ discard block |
||
| 2228 | 2228 | */ |
| 2229 | 2229 | protected function _putpage(int $n) : void |
| 2230 | 2230 | {
|
| 2231 | - $this->_newobj(); |
|
| 2232 | - $this->_put('<</Type /Page');
|
|
| 2233 | - $this->_put('/Parent 1 0 R');
|
|
| 2234 | - if(isset($this->PageInfo[$n]['size'])) |
|
| 2235 | - $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo[$n]['size'][0],$this->PageInfo[$n]['size'][1]));
|
|
| 2236 | - if(isset($this->PageInfo[$n]['rotation'])) |
|
| 2237 | - $this->_put('/Rotate '.$this->PageInfo[$n]['rotation']);
|
|
| 2238 | - $this->_put('/Resources 2 0 R');
|
|
| 2239 | - if(isset($this->PageLinks[$n])) |
|
| 2240 | - {
|
|
| 2241 | - // Links |
|
| 2242 | - $annots = '/Annots ['; |
|
| 2243 | - foreach($this->PageLinks[$n] as $pl) |
|
| 2244 | - {
|
|
| 2245 | - $rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
|
|
| 2246 | - $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
|
| 2247 | - if(is_string($pl[4])) |
|
| 2248 | - $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
|
| 2249 | - else |
|
| 2250 | - {
|
|
| 2251 | - $l = $this->links[$pl[4]]; |
|
| 2252 | - if(isset($this->PageInfo[$l[0]]['size'])) |
|
| 2253 | - $h = $this->PageInfo[$l[0]]['size'][1]; |
|
| 2254 | - else |
|
| 2255 | - $h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k; |
|
| 2256 | - $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[$l[0]]['n'],$h-$l[1]*$this->k);
|
|
| 2257 | - } |
|
| 2258 | - } |
|
| 2259 | - $this->_put($annots.']'); |
|
| 2260 | - } |
|
| 2261 | - if($this->WithAlpha) |
|
| 2262 | - $this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>');
|
|
| 2263 | - $this->_put('/Contents '.($this->n+1).' 0 R>>');
|
|
| 2264 | - $this->_put('endobj');
|
|
| 2265 | - // Page content |
|
| 2266 | - if(!empty($this->AliasNbPages)) |
|
| 2267 | - $this->pages[$n] = str_replace($this->AliasNbPages, strval($this->page), $this->pages[$n]); |
|
| 2268 | - $this->_putstreamobject($this->pages[$n]); |
|
| 2231 | + $this->_newobj(); |
|
| 2232 | + $this->_put('<</Type /Page');
|
|
| 2233 | + $this->_put('/Parent 1 0 R');
|
|
| 2234 | + if(isset($this->PageInfo[$n]['size'])) |
|
| 2235 | + $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo[$n]['size'][0],$this->PageInfo[$n]['size'][1]));
|
|
| 2236 | + if(isset($this->PageInfo[$n]['rotation'])) |
|
| 2237 | + $this->_put('/Rotate '.$this->PageInfo[$n]['rotation']);
|
|
| 2238 | + $this->_put('/Resources 2 0 R');
|
|
| 2239 | + if(isset($this->PageLinks[$n])) |
|
| 2240 | + {
|
|
| 2241 | + // Links |
|
| 2242 | + $annots = '/Annots ['; |
|
| 2243 | + foreach($this->PageLinks[$n] as $pl) |
|
| 2244 | + {
|
|
| 2245 | + $rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
|
|
| 2246 | + $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
|
| 2247 | + if(is_string($pl[4])) |
|
| 2248 | + $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
|
| 2249 | + else |
|
| 2250 | + {
|
|
| 2251 | + $l = $this->links[$pl[4]]; |
|
| 2252 | + if(isset($this->PageInfo[$l[0]]['size'])) |
|
| 2253 | + $h = $this->PageInfo[$l[0]]['size'][1]; |
|
| 2254 | + else |
|
| 2255 | + $h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k; |
|
| 2256 | + $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[$l[0]]['n'],$h-$l[1]*$this->k);
|
|
| 2257 | + } |
|
| 2258 | + } |
|
| 2259 | + $this->_put($annots.']'); |
|
| 2260 | + } |
|
| 2261 | + if($this->WithAlpha) |
|
| 2262 | + $this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>');
|
|
| 2263 | + $this->_put('/Contents '.($this->n+1).' 0 R>>');
|
|
| 2264 | + $this->_put('endobj');
|
|
| 2265 | + // Page content |
|
| 2266 | + if(!empty($this->AliasNbPages)) |
|
| 2267 | + $this->pages[$n] = str_replace($this->AliasNbPages, strval($this->page), $this->pages[$n]); |
|
| 2268 | + $this->_putstreamobject($this->pages[$n]); |
|
| 2269 | 2269 | } |
| 2270 | 2270 | |
| 2271 | 2271 | /** |
@@ -2273,32 +2273,32 @@ discard block |
||
| 2273 | 2273 | */ |
| 2274 | 2274 | protected function _putpages() : void |
| 2275 | 2275 | {
|
| 2276 | - $nb = $this->page; |
|
| 2277 | - for($n=1;$n<=$nb;$n++) |
|
| 2278 | - $this->PageInfo[$n]['n'] = $this->n+1+2*($n-1); |
|
| 2279 | - for($n=1;$n<=$nb;$n++) |
|
| 2280 | - $this->_putpage($n); |
|
| 2281 | - // Pages root |
|
| 2282 | - $this->_newobj(1); |
|
| 2283 | - $this->_put('<</Type /Pages');
|
|
| 2284 | - $kids = '/Kids ['; |
|
| 2285 | - for($n=1;$n<=$nb;$n++) |
|
| 2286 | - $kids .= $this->PageInfo[$n]['n'].' 0 R '; |
|
| 2287 | - $this->_put($kids.']'); |
|
| 2288 | - $this->_put('/Count '.$nb);
|
|
| 2289 | - if($this->DefOrientation=='P') |
|
| 2290 | - {
|
|
| 2291 | - $w = $this->DefPageSize[0]; |
|
| 2292 | - $h = $this->DefPageSize[1]; |
|
| 2293 | - } |
|
| 2294 | - else |
|
| 2295 | - {
|
|
| 2296 | - $w = $this->DefPageSize[1]; |
|
| 2297 | - $h = $this->DefPageSize[0]; |
|
| 2298 | - } |
|
| 2299 | - $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$w*$this->k,$h*$this->k));
|
|
| 2300 | - $this->_put('>>');
|
|
| 2301 | - $this->_put('endobj');
|
|
| 2276 | + $nb = $this->page; |
|
| 2277 | + for($n=1;$n<=$nb;$n++) |
|
| 2278 | + $this->PageInfo[$n]['n'] = $this->n+1+2*($n-1); |
|
| 2279 | + for($n=1;$n<=$nb;$n++) |
|
| 2280 | + $this->_putpage($n); |
|
| 2281 | + // Pages root |
|
| 2282 | + $this->_newobj(1); |
|
| 2283 | + $this->_put('<</Type /Pages');
|
|
| 2284 | + $kids = '/Kids ['; |
|
| 2285 | + for($n=1;$n<=$nb;$n++) |
|
| 2286 | + $kids .= $this->PageInfo[$n]['n'].' 0 R '; |
|
| 2287 | + $this->_put($kids.']'); |
|
| 2288 | + $this->_put('/Count '.$nb);
|
|
| 2289 | + if($this->DefOrientation=='P') |
|
| 2290 | + {
|
|
| 2291 | + $w = $this->DefPageSize[0]; |
|
| 2292 | + $h = $this->DefPageSize[1]; |
|
| 2293 | + } |
|
| 2294 | + else |
|
| 2295 | + {
|
|
| 2296 | + $w = $this->DefPageSize[1]; |
|
| 2297 | + $h = $this->DefPageSize[0]; |
|
| 2298 | + } |
|
| 2299 | + $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$w*$this->k,$h*$this->k));
|
|
| 2300 | + $this->_put('>>');
|
|
| 2301 | + $this->_put('endobj');
|
|
| 2302 | 2302 | } |
| 2303 | 2303 | |
| 2304 | 2304 | /** |
@@ -2306,123 +2306,123 @@ discard block |
||
| 2306 | 2306 | */ |
| 2307 | 2307 | protected function _putfonts() : void |
| 2308 | 2308 | {
|
| 2309 | - foreach ($this->FontFiles as $file => $info) {
|
|
| 2310 | - // Font file embedding |
|
| 2311 | - $this->_newobj(); |
|
| 2312 | - $this->FontFiles[$file]['n'] = $this->n; |
|
| 2313 | - $font = file_get_contents($this->fontpath . $file, true); |
|
| 2314 | - if (!$font) {
|
|
| 2315 | - $this->Error('Font file not found: ' . $file);
|
|
| 2316 | - } |
|
| 2317 | - $compressed = (substr($file, -2) == '.z'); |
|
| 2318 | - if (!$compressed && isset($info['length2'])) {
|
|
| 2319 | - $font = substr($font, 6, $info['length1']) . substr($font, 6 + $info['length1'] + 6, $info['length2']); |
|
| 2320 | - } |
|
| 2321 | - $this->_put('<</Length ' . strlen($font));
|
|
| 2322 | - if ($compressed) {
|
|
| 2323 | - $this->_put('/Filter /FlateDecode');
|
|
| 2324 | - } |
|
| 2325 | - $this->_put('/Length1 ' . $info['length1']);
|
|
| 2326 | - if (isset($info['length2'])) {
|
|
| 2327 | - $this->_put('/Length2 '.$info['length2'].' /Length3 0');
|
|
| 2328 | - } |
|
| 2329 | - $this->_put('>>');
|
|
| 2330 | - $this->_putstream($font); |
|
| 2331 | - $this->_put('endobj');
|
|
| 2332 | - } |
|
| 2333 | - foreach ($this->fonts as $k => $font) {
|
|
| 2334 | - // Encoding |
|
| 2335 | - if (isset($font['diff'])) {
|
|
| 2336 | - if (!isset($this->encodings[$font['enc']])) {
|
|
| 2337 | - $this->_newobj(); |
|
| 2338 | - $this->_put('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' . $font['diff'] . ']>>');
|
|
| 2339 | - $this->_put('endobj');
|
|
| 2340 | - $this->encodings[$font['enc']] = $this->n; |
|
| 2341 | - } |
|
| 2342 | - } |
|
| 2343 | - // ToUnicode CMap |
|
| 2344 | - $cmapkey = ''; |
|
| 2345 | - if (isset($font['uv'])) {
|
|
| 2346 | - if (isset($font['enc'])) {
|
|
| 2347 | - $cmapkey = $font['enc']; |
|
| 2348 | - } else {
|
|
| 2349 | - $cmapkey = $font['name']; |
|
| 2350 | - } |
|
| 2351 | - if (!isset($this->cmaps[$cmapkey])) {
|
|
| 2352 | - $cmap = $this->_tounicodecmap($font['uv']); |
|
| 2353 | - $this->_putstreamobject($cmap); |
|
| 2354 | - $this->cmaps[$cmapkey] = $this->n; |
|
| 2355 | - } |
|
| 2356 | - } |
|
| 2357 | - // Font object |
|
| 2358 | - $this->fonts[$k]['n'] = $this->n + 1; |
|
| 2359 | - $type = $font['type']; |
|
| 2360 | - $name = $font['name']; |
|
| 2361 | - if ($font['subsetted']) {
|
|
| 2362 | - $name = 'AAAAAA+' . $name; |
|
| 2363 | - } |
|
| 2364 | - if ($type=='Core') {
|
|
| 2365 | - // Core font |
|
| 2366 | - $this->_newobj(); |
|
| 2367 | - $this->_put('<</Type /Font');
|
|
| 2368 | - $this->_put('/BaseFont /' . $name);
|
|
| 2369 | - $this->_put('/Subtype /Type1');
|
|
| 2370 | - if ($name != 'Symbol' && $name != 'ZapfDingbats') {
|
|
| 2371 | - $this->_put('/Encoding /WinAnsiEncoding');
|
|
| 2372 | - } |
|
| 2373 | - if (isset($font['uv'])) {
|
|
| 2374 | - $this->_put('/ToUnicode ' . $this->cmaps[$cmapkey] . ' 0 R');
|
|
| 2375 | - } |
|
| 2376 | - $this->_put('>>');
|
|
| 2377 | - $this->_put('endobj');
|
|
| 2378 | - } elseif ($type == 'Type1' || $type == 'TrueType') {
|
|
| 2379 | - // Additional Type1 or TrueType/OpenType font |
|
| 2380 | - $this->_newobj(); |
|
| 2381 | - $this->_put('<</Type /Font');
|
|
| 2382 | - $this->_put('/BaseFont /' . $name);
|
|
| 2383 | - $this->_put('/Subtype /' . $type);
|
|
| 2384 | - $this->_put('/FirstChar 32 /LastChar 255');
|
|
| 2385 | - $this->_put('/Widths ' . ($this->n + 1) . ' 0 R');
|
|
| 2386 | - $this->_put('/FontDescriptor ' . ($this->n + 2) . ' 0 R');
|
|
| 2387 | - if (isset($font['diff'])) {
|
|
| 2388 | - $this->_put('/Encoding ' . $this->encodings[$font['enc']] . ' 0 R');
|
|
| 2389 | - } else {
|
|
| 2390 | - $this->_put('/Encoding /WinAnsiEncoding');
|
|
| 2391 | - } |
|
| 2392 | - if (isset($font['uv'])) {
|
|
| 2393 | - $this->_put('/ToUnicode ' . $this->cmaps[$cmapkey] . ' 0 R');
|
|
| 2394 | - } |
|
| 2395 | - $this->_put('>>');
|
|
| 2396 | - $this->_put('endobj');
|
|
| 2397 | - // Widths |
|
| 2398 | - $this->_newobj(); |
|
| 2399 | - $cw = &$font['cw']; |
|
| 2400 | - $s = '['; |
|
| 2401 | - for ($i = 32; $i <= 255; $i++) {
|
|
| 2402 | - $s .= $cw[chr($i)] . ' '; |
|
| 2403 | - } |
|
| 2404 | - $this->_put($s . ']'); |
|
| 2405 | - $this->_put('endobj');
|
|
| 2406 | - // Descriptor |
|
| 2407 | - $this->_newobj(); |
|
| 2408 | - $s = '<</Type /FontDescriptor /FontName /' . $name; |
|
| 2409 | - foreach ($font['desc'] as $k2 => $v) {
|
|
| 2410 | - $s .= ' /' . $k2 . ' ' . $v; |
|
| 2411 | - } |
|
| 2412 | - if (!empty($font['file'])) {
|
|
| 2413 | - $s .= ' /FontFile' . ($type == 'Type1' ? '' : '2') . ' ' . $this->FontFiles[$font['file']]['n'] . ' 0 R'; |
|
| 2414 | - } |
|
| 2415 | - $this->_put($s . '>>'); |
|
| 2416 | - $this->_put('endobj');
|
|
| 2417 | - } else {
|
|
| 2418 | - // Allow for additional types |
|
| 2419 | - $mtd = '_put' . strtolower($type); |
|
| 2420 | - if (!method_exists($this, $mtd)) {
|
|
| 2421 | - $this->Error('Unsupported font type: ' . $type);
|
|
| 2422 | - } |
|
| 2423 | - $this->$mtd($font); |
|
| 2424 | - } |
|
| 2425 | - } |
|
| 2309 | + foreach ($this->FontFiles as $file => $info) {
|
|
| 2310 | + // Font file embedding |
|
| 2311 | + $this->_newobj(); |
|
| 2312 | + $this->FontFiles[$file]['n'] = $this->n; |
|
| 2313 | + $font = file_get_contents($this->fontpath . $file, true); |
|
| 2314 | + if (!$font) {
|
|
| 2315 | + $this->Error('Font file not found: ' . $file);
|
|
| 2316 | + } |
|
| 2317 | + $compressed = (substr($file, -2) == '.z'); |
|
| 2318 | + if (!$compressed && isset($info['length2'])) {
|
|
| 2319 | + $font = substr($font, 6, $info['length1']) . substr($font, 6 + $info['length1'] + 6, $info['length2']); |
|
| 2320 | + } |
|
| 2321 | + $this->_put('<</Length ' . strlen($font));
|
|
| 2322 | + if ($compressed) {
|
|
| 2323 | + $this->_put('/Filter /FlateDecode');
|
|
| 2324 | + } |
|
| 2325 | + $this->_put('/Length1 ' . $info['length1']);
|
|
| 2326 | + if (isset($info['length2'])) {
|
|
| 2327 | + $this->_put('/Length2 '.$info['length2'].' /Length3 0');
|
|
| 2328 | + } |
|
| 2329 | + $this->_put('>>');
|
|
| 2330 | + $this->_putstream($font); |
|
| 2331 | + $this->_put('endobj');
|
|
| 2332 | + } |
|
| 2333 | + foreach ($this->fonts as $k => $font) {
|
|
| 2334 | + // Encoding |
|
| 2335 | + if (isset($font['diff'])) {
|
|
| 2336 | + if (!isset($this->encodings[$font['enc']])) {
|
|
| 2337 | + $this->_newobj(); |
|
| 2338 | + $this->_put('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' . $font['diff'] . ']>>');
|
|
| 2339 | + $this->_put('endobj');
|
|
| 2340 | + $this->encodings[$font['enc']] = $this->n; |
|
| 2341 | + } |
|
| 2342 | + } |
|
| 2343 | + // ToUnicode CMap |
|
| 2344 | + $cmapkey = ''; |
|
| 2345 | + if (isset($font['uv'])) {
|
|
| 2346 | + if (isset($font['enc'])) {
|
|
| 2347 | + $cmapkey = $font['enc']; |
|
| 2348 | + } else {
|
|
| 2349 | + $cmapkey = $font['name']; |
|
| 2350 | + } |
|
| 2351 | + if (!isset($this->cmaps[$cmapkey])) {
|
|
| 2352 | + $cmap = $this->_tounicodecmap($font['uv']); |
|
| 2353 | + $this->_putstreamobject($cmap); |
|
| 2354 | + $this->cmaps[$cmapkey] = $this->n; |
|
| 2355 | + } |
|
| 2356 | + } |
|
| 2357 | + // Font object |
|
| 2358 | + $this->fonts[$k]['n'] = $this->n + 1; |
|
| 2359 | + $type = $font['type']; |
|
| 2360 | + $name = $font['name']; |
|
| 2361 | + if ($font['subsetted']) {
|
|
| 2362 | + $name = 'AAAAAA+' . $name; |
|
| 2363 | + } |
|
| 2364 | + if ($type=='Core') {
|
|
| 2365 | + // Core font |
|
| 2366 | + $this->_newobj(); |
|
| 2367 | + $this->_put('<</Type /Font');
|
|
| 2368 | + $this->_put('/BaseFont /' . $name);
|
|
| 2369 | + $this->_put('/Subtype /Type1');
|
|
| 2370 | + if ($name != 'Symbol' && $name != 'ZapfDingbats') {
|
|
| 2371 | + $this->_put('/Encoding /WinAnsiEncoding');
|
|
| 2372 | + } |
|
| 2373 | + if (isset($font['uv'])) {
|
|
| 2374 | + $this->_put('/ToUnicode ' . $this->cmaps[$cmapkey] . ' 0 R');
|
|
| 2375 | + } |
|
| 2376 | + $this->_put('>>');
|
|
| 2377 | + $this->_put('endobj');
|
|
| 2378 | + } elseif ($type == 'Type1' || $type == 'TrueType') {
|
|
| 2379 | + // Additional Type1 or TrueType/OpenType font |
|
| 2380 | + $this->_newobj(); |
|
| 2381 | + $this->_put('<</Type /Font');
|
|
| 2382 | + $this->_put('/BaseFont /' . $name);
|
|
| 2383 | + $this->_put('/Subtype /' . $type);
|
|
| 2384 | + $this->_put('/FirstChar 32 /LastChar 255');
|
|
| 2385 | + $this->_put('/Widths ' . ($this->n + 1) . ' 0 R');
|
|
| 2386 | + $this->_put('/FontDescriptor ' . ($this->n + 2) . ' 0 R');
|
|
| 2387 | + if (isset($font['diff'])) {
|
|
| 2388 | + $this->_put('/Encoding ' . $this->encodings[$font['enc']] . ' 0 R');
|
|
| 2389 | + } else {
|
|
| 2390 | + $this->_put('/Encoding /WinAnsiEncoding');
|
|
| 2391 | + } |
|
| 2392 | + if (isset($font['uv'])) {
|
|
| 2393 | + $this->_put('/ToUnicode ' . $this->cmaps[$cmapkey] . ' 0 R');
|
|
| 2394 | + } |
|
| 2395 | + $this->_put('>>');
|
|
| 2396 | + $this->_put('endobj');
|
|
| 2397 | + // Widths |
|
| 2398 | + $this->_newobj(); |
|
| 2399 | + $cw = &$font['cw']; |
|
| 2400 | + $s = '['; |
|
| 2401 | + for ($i = 32; $i <= 255; $i++) {
|
|
| 2402 | + $s .= $cw[chr($i)] . ' '; |
|
| 2403 | + } |
|
| 2404 | + $this->_put($s . ']'); |
|
| 2405 | + $this->_put('endobj');
|
|
| 2406 | + // Descriptor |
|
| 2407 | + $this->_newobj(); |
|
| 2408 | + $s = '<</Type /FontDescriptor /FontName /' . $name; |
|
| 2409 | + foreach ($font['desc'] as $k2 => $v) {
|
|
| 2410 | + $s .= ' /' . $k2 . ' ' . $v; |
|
| 2411 | + } |
|
| 2412 | + if (!empty($font['file'])) {
|
|
| 2413 | + $s .= ' /FontFile' . ($type == 'Type1' ? '' : '2') . ' ' . $this->FontFiles[$font['file']]['n'] . ' 0 R'; |
|
| 2414 | + } |
|
| 2415 | + $this->_put($s . '>>'); |
|
| 2416 | + $this->_put('endobj');
|
|
| 2417 | + } else {
|
|
| 2418 | + // Allow for additional types |
|
| 2419 | + $mtd = '_put' . strtolower($type); |
|
| 2420 | + if (!method_exists($this, $mtd)) {
|
|
| 2421 | + $this->Error('Unsupported font type: ' . $type);
|
|
| 2422 | + } |
|
| 2423 | + $this->$mtd($font); |
|
| 2424 | + } |
|
| 2425 | + } |
|
| 2426 | 2426 | } |
| 2427 | 2427 | |
| 2428 | 2428 | /** |
@@ -2431,53 +2431,53 @@ discard block |
||
| 2431 | 2431 | */ |
| 2432 | 2432 | protected function _tounicodecmap(array $uv) : string |
| 2433 | 2433 | {
|
| 2434 | - $ranges = ''; |
|
| 2435 | - $nbr = 0; |
|
| 2436 | - $chars = ''; |
|
| 2437 | - $nbc = 0; |
|
| 2438 | - foreach($uv as $c=>$v) |
|
| 2439 | - {
|
|
| 2440 | - if(is_array($v)) |
|
| 2441 | - {
|
|
| 2442 | - $ranges .= sprintf("<%02X> <%02X> <%04X>\n",$c,$c+$v[1]-1,$v[0]);
|
|
| 2443 | - $nbr++; |
|
| 2444 | - } |
|
| 2445 | - else |
|
| 2446 | - {
|
|
| 2447 | - $chars .= sprintf("<%02X> <%04X>\n",$c,$v);
|
|
| 2448 | - $nbc++; |
|
| 2449 | - } |
|
| 2450 | - } |
|
| 2451 | - $s = "/CIDInit /ProcSet findresource begin\n"; |
|
| 2452 | - $s .= "12 dict begin\n"; |
|
| 2453 | - $s .= "begincmap\n"; |
|
| 2454 | - $s .= "/CIDSystemInfo\n"; |
|
| 2455 | - $s .= "<</Registry (Adobe)\n"; |
|
| 2456 | - $s .= "/Ordering (UCS)\n"; |
|
| 2457 | - $s .= "/Supplement 0\n"; |
|
| 2458 | - $s .= ">> def\n"; |
|
| 2459 | - $s .= "/CMapName /Adobe-Identity-UCS def\n"; |
|
| 2460 | - $s .= "/CMapType 2 def\n"; |
|
| 2461 | - $s .= "1 begincodespacerange\n"; |
|
| 2462 | - $s .= "<00> <FF>\n"; |
|
| 2463 | - $s .= "endcodespacerange\n"; |
|
| 2464 | - if($nbr>0) |
|
| 2465 | - {
|
|
| 2466 | - $s .= "$nbr beginbfrange\n"; |
|
| 2467 | - $s .= $ranges; |
|
| 2468 | - $s .= "endbfrange\n"; |
|
| 2469 | - } |
|
| 2470 | - if($nbc>0) |
|
| 2471 | - {
|
|
| 2472 | - $s .= "$nbc beginbfchar\n"; |
|
| 2473 | - $s .= $chars; |
|
| 2474 | - $s .= "endbfchar\n"; |
|
| 2475 | - } |
|
| 2476 | - $s .= "endcmap\n"; |
|
| 2477 | - $s .= "CMapName currentdict /CMap defineresource pop\n"; |
|
| 2478 | - $s .= "end\n"; |
|
| 2479 | - $s .= "end"; |
|
| 2480 | - return $s; |
|
| 2434 | + $ranges = ''; |
|
| 2435 | + $nbr = 0; |
|
| 2436 | + $chars = ''; |
|
| 2437 | + $nbc = 0; |
|
| 2438 | + foreach($uv as $c=>$v) |
|
| 2439 | + {
|
|
| 2440 | + if(is_array($v)) |
|
| 2441 | + {
|
|
| 2442 | + $ranges .= sprintf("<%02X> <%02X> <%04X>\n",$c,$c+$v[1]-1,$v[0]);
|
|
| 2443 | + $nbr++; |
|
| 2444 | + } |
|
| 2445 | + else |
|
| 2446 | + {
|
|
| 2447 | + $chars .= sprintf("<%02X> <%04X>\n",$c,$v);
|
|
| 2448 | + $nbc++; |
|
| 2449 | + } |
|
| 2450 | + } |
|
| 2451 | + $s = "/CIDInit /ProcSet findresource begin\n"; |
|
| 2452 | + $s .= "12 dict begin\n"; |
|
| 2453 | + $s .= "begincmap\n"; |
|
| 2454 | + $s .= "/CIDSystemInfo\n"; |
|
| 2455 | + $s .= "<</Registry (Adobe)\n"; |
|
| 2456 | + $s .= "/Ordering (UCS)\n"; |
|
| 2457 | + $s .= "/Supplement 0\n"; |
|
| 2458 | + $s .= ">> def\n"; |
|
| 2459 | + $s .= "/CMapName /Adobe-Identity-UCS def\n"; |
|
| 2460 | + $s .= "/CMapType 2 def\n"; |
|
| 2461 | + $s .= "1 begincodespacerange\n"; |
|
| 2462 | + $s .= "<00> <FF>\n"; |
|
| 2463 | + $s .= "endcodespacerange\n"; |
|
| 2464 | + if($nbr>0) |
|
| 2465 | + {
|
|
| 2466 | + $s .= "$nbr beginbfrange\n"; |
|
| 2467 | + $s .= $ranges; |
|
| 2468 | + $s .= "endbfrange\n"; |
|
| 2469 | + } |
|
| 2470 | + if($nbc>0) |
|
| 2471 | + {
|
|
| 2472 | + $s .= "$nbc beginbfchar\n"; |
|
| 2473 | + $s .= $chars; |
|
| 2474 | + $s .= "endbfchar\n"; |
|
| 2475 | + } |
|
| 2476 | + $s .= "endcmap\n"; |
|
| 2477 | + $s .= "CMapName currentdict /CMap defineresource pop\n"; |
|
| 2478 | + $s .= "end\n"; |
|
| 2479 | + $s .= "end"; |
|
| 2480 | + return $s; |
|
| 2481 | 2481 | } |
| 2482 | 2482 | |
| 2483 | 2483 | /** |
@@ -2485,12 +2485,12 @@ discard block |
||
| 2485 | 2485 | */ |
| 2486 | 2486 | protected function _putimages() : void |
| 2487 | 2487 | {
|
| 2488 | - foreach(array_keys($this->images) as $file) |
|
| 2489 | - {
|
|
| 2490 | - $this->_putimage($this->images[$file]); |
|
| 2491 | - unset($this->images[$file]['data']); |
|
| 2492 | - unset($this->images[$file]['smask']); |
|
| 2493 | - } |
|
| 2488 | + foreach(array_keys($this->images) as $file) |
|
| 2489 | + {
|
|
| 2490 | + $this->_putimage($this->images[$file]); |
|
| 2491 | + unset($this->images[$file]['data']); |
|
| 2492 | + unset($this->images[$file]['smask']); |
|
| 2493 | + } |
|
| 2494 | 2494 | } |
| 2495 | 2495 | |
| 2496 | 2496 | /** |
@@ -2499,59 +2499,59 @@ discard block |
||
| 2499 | 2499 | */ |
| 2500 | 2500 | protected function _putimage(array &$info) : void |
| 2501 | 2501 | {
|
| 2502 | - $this->_newobj(); |
|
| 2503 | - $info['n'] = $this->n; |
|
| 2504 | - $this->_put('<</Type /XObject');
|
|
| 2505 | - $this->_put('/Subtype /Image');
|
|
| 2506 | - $this->_put('/Width ' . $info['w']);
|
|
| 2507 | - $this->_put('/Height ' . $info['h']);
|
|
| 2508 | - if ($info['cs'] == 'Indexed') {
|
|
| 2509 | - $this->_put('/ColorSpace [/Indexed /DeviceRGB ' . (strlen($info['pal']) / 3 - 1) . ' ' . ($this->n + 1) . ' 0 R]');
|
|
| 2510 | - } else {
|
|
| 2511 | - $this->_put('/ColorSpace /' . $info['cs']);
|
|
| 2512 | - if($info['cs']=='DeviceCMYK') {
|
|
| 2513 | - $this->_put('/Decode [1 0 1 0 1 0 1 0]');
|
|
| 2514 | - } |
|
| 2515 | - } |
|
| 2516 | - $this->_put('/BitsPerComponent ' . $info['bpc']);
|
|
| 2517 | - if (isset($info['f'])) {
|
|
| 2518 | - $this->_put('/Filter /' . $info['f']);
|
|
| 2519 | - } |
|
| 2520 | - if (isset($info['dp'])) {
|
|
| 2521 | - $this->_put('/DecodeParms <<' . $info['dp'] . '>>');
|
|
| 2522 | - } |
|
| 2523 | - if (isset($info['trns']) && is_array($info['trns'])) {
|
|
| 2524 | - $trns = ''; |
|
| 2525 | - $cnt = count($info['trns']); |
|
| 2526 | - for ($i = 0; $i < $cnt; $i++) {
|
|
| 2527 | - $trns .= $info['trns'][$i] . ' ' . $info['trns'][$i] . ' '; |
|
| 2528 | - } |
|
| 2529 | - $this->_put('/Mask [' . $trns . ']');
|
|
| 2530 | - } |
|
| 2531 | - if (isset($info['smask'])) {
|
|
| 2532 | - $this->_put('/SMask ' . ($this->n+1) . ' 0 R');
|
|
| 2533 | - } |
|
| 2534 | - $this->_put('/Length ' . strlen($info['data']) . '>>');
|
|
| 2535 | - $this->_putstream($info['data']); |
|
| 2536 | - $this->_put('endobj');
|
|
| 2537 | - // Soft mask |
|
| 2538 | - if (isset($info['smask'])) {
|
|
| 2539 | - $dp = '/Predictor 15 /Colors 1 /BitsPerComponent 8 /Columns ' . $info['w']; |
|
| 2540 | - $smask = array( |
|
| 2541 | - 'w'=>$info['w'], |
|
| 2542 | - 'h'=>$info['h'], |
|
| 2543 | - 'cs'=>'DeviceGray', |
|
| 2544 | - 'bpc'=>8, |
|
| 2545 | - 'f'=>$info['f'], |
|
| 2546 | - 'dp'=>$dp, |
|
| 2547 | - 'data'=>$info['smask'] |
|
| 2548 | - ); |
|
| 2549 | - $this->_putimage($smask); |
|
| 2550 | - } |
|
| 2551 | - // Palette |
|
| 2552 | - if ($info['cs'] == 'Indexed') {
|
|
| 2553 | - $this->_putstreamobject($info['pal']); |
|
| 2554 | - } |
|
| 2502 | + $this->_newobj(); |
|
| 2503 | + $info['n'] = $this->n; |
|
| 2504 | + $this->_put('<</Type /XObject');
|
|
| 2505 | + $this->_put('/Subtype /Image');
|
|
| 2506 | + $this->_put('/Width ' . $info['w']);
|
|
| 2507 | + $this->_put('/Height ' . $info['h']);
|
|
| 2508 | + if ($info['cs'] == 'Indexed') {
|
|
| 2509 | + $this->_put('/ColorSpace [/Indexed /DeviceRGB ' . (strlen($info['pal']) / 3 - 1) . ' ' . ($this->n + 1) . ' 0 R]');
|
|
| 2510 | + } else {
|
|
| 2511 | + $this->_put('/ColorSpace /' . $info['cs']);
|
|
| 2512 | + if($info['cs']=='DeviceCMYK') {
|
|
| 2513 | + $this->_put('/Decode [1 0 1 0 1 0 1 0]');
|
|
| 2514 | + } |
|
| 2515 | + } |
|
| 2516 | + $this->_put('/BitsPerComponent ' . $info['bpc']);
|
|
| 2517 | + if (isset($info['f'])) {
|
|
| 2518 | + $this->_put('/Filter /' . $info['f']);
|
|
| 2519 | + } |
|
| 2520 | + if (isset($info['dp'])) {
|
|
| 2521 | + $this->_put('/DecodeParms <<' . $info['dp'] . '>>');
|
|
| 2522 | + } |
|
| 2523 | + if (isset($info['trns']) && is_array($info['trns'])) {
|
|
| 2524 | + $trns = ''; |
|
| 2525 | + $cnt = count($info['trns']); |
|
| 2526 | + for ($i = 0; $i < $cnt; $i++) {
|
|
| 2527 | + $trns .= $info['trns'][$i] . ' ' . $info['trns'][$i] . ' '; |
|
| 2528 | + } |
|
| 2529 | + $this->_put('/Mask [' . $trns . ']');
|
|
| 2530 | + } |
|
| 2531 | + if (isset($info['smask'])) {
|
|
| 2532 | + $this->_put('/SMask ' . ($this->n+1) . ' 0 R');
|
|
| 2533 | + } |
|
| 2534 | + $this->_put('/Length ' . strlen($info['data']) . '>>');
|
|
| 2535 | + $this->_putstream($info['data']); |
|
| 2536 | + $this->_put('endobj');
|
|
| 2537 | + // Soft mask |
|
| 2538 | + if (isset($info['smask'])) {
|
|
| 2539 | + $dp = '/Predictor 15 /Colors 1 /BitsPerComponent 8 /Columns ' . $info['w']; |
|
| 2540 | + $smask = array( |
|
| 2541 | + 'w'=>$info['w'], |
|
| 2542 | + 'h'=>$info['h'], |
|
| 2543 | + 'cs'=>'DeviceGray', |
|
| 2544 | + 'bpc'=>8, |
|
| 2545 | + 'f'=>$info['f'], |
|
| 2546 | + 'dp'=>$dp, |
|
| 2547 | + 'data'=>$info['smask'] |
|
| 2548 | + ); |
|
| 2549 | + $this->_putimage($smask); |
|
| 2550 | + } |
|
| 2551 | + // Palette |
|
| 2552 | + if ($info['cs'] == 'Indexed') {
|
|
| 2553 | + $this->_putstreamobject($info['pal']); |
|
| 2554 | + } |
|
| 2555 | 2555 | } |
| 2556 | 2556 | |
| 2557 | 2557 | /** |
@@ -2560,7 +2560,7 @@ discard block |
||
| 2560 | 2560 | protected function _putxobjectdict() : void |
| 2561 | 2561 | {
|
| 2562 | 2562 | foreach ($this->images as $image) {
|
| 2563 | - $this->_put('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R');
|
|
| 2563 | + $this->_put('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R');
|
|
| 2564 | 2564 | } |
| 2565 | 2565 | } |
| 2566 | 2566 | |
@@ -2569,15 +2569,15 @@ discard block |
||
| 2569 | 2569 | */ |
| 2570 | 2570 | protected function _putresourcedict() : void |
| 2571 | 2571 | {
|
| 2572 | - $this->_put('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
|
|
| 2573 | - $this->_put('/Font <<');
|
|
| 2574 | - foreach ($this->fonts as $font) {
|
|
| 2575 | - $this->_put('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R');
|
|
| 2576 | - } |
|
| 2577 | - $this->_put('>>');
|
|
| 2578 | - $this->_put('/XObject <<');
|
|
| 2579 | - $this->_putxobjectdict(); |
|
| 2580 | - $this->_put('>>');
|
|
| 2572 | + $this->_put('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
|
|
| 2573 | + $this->_put('/Font <<');
|
|
| 2574 | + foreach ($this->fonts as $font) {
|
|
| 2575 | + $this->_put('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R');
|
|
| 2576 | + } |
|
| 2577 | + $this->_put('>>');
|
|
| 2578 | + $this->_put('/XObject <<');
|
|
| 2579 | + $this->_putxobjectdict(); |
|
| 2580 | + $this->_put('>>');
|
|
| 2581 | 2581 | } |
| 2582 | 2582 | |
| 2583 | 2583 | /** |
@@ -2585,14 +2585,14 @@ discard block |
||
| 2585 | 2585 | */ |
| 2586 | 2586 | protected function _putresources() : void |
| 2587 | 2587 | {
|
| 2588 | - $this->_putfonts(); |
|
| 2589 | - $this->_putimages(); |
|
| 2590 | - // Resource dictionary |
|
| 2591 | - $this->_newobj(2); |
|
| 2592 | - $this->_put('<<');
|
|
| 2593 | - $this->_putresourcedict(); |
|
| 2594 | - $this->_put('>>');
|
|
| 2595 | - $this->_put('endobj');
|
|
| 2588 | + $this->_putfonts(); |
|
| 2589 | + $this->_putimages(); |
|
| 2590 | + // Resource dictionary |
|
| 2591 | + $this->_newobj(2); |
|
| 2592 | + $this->_put('<<');
|
|
| 2593 | + $this->_putresourcedict(); |
|
| 2594 | + $this->_put('>>');
|
|
| 2595 | + $this->_put('endobj');
|
|
| 2596 | 2596 | } |
| 2597 | 2597 | |
| 2598 | 2598 | /** |
@@ -2600,11 +2600,11 @@ discard block |
||
| 2600 | 2600 | */ |
| 2601 | 2601 | protected function _putinfo() : void |
| 2602 | 2602 | {
|
| 2603 | - $this->metadata['Producer'] = 'FPDF '.FPDF_VERSION; |
|
| 2604 | - $this->metadata['CreationDate'] = 'D:' . @date('YmdHis');
|
|
| 2605 | - foreach ($this->metadata as $key=>$value) {
|
|
| 2606 | - $this->_put('/' . $key . ' ' . $this->_textstring($value));
|
|
| 2607 | - } |
|
| 2603 | + $this->metadata['Producer'] = 'FPDF '.FPDF_VERSION; |
|
| 2604 | + $this->metadata['CreationDate'] = 'D:' . @date('YmdHis');
|
|
| 2605 | + foreach ($this->metadata as $key=>$value) {
|
|
| 2606 | + $this->_put('/' . $key . ' ' . $this->_textstring($value));
|
|
| 2607 | + } |
|
| 2608 | 2608 | } |
| 2609 | 2609 | |
| 2610 | 2610 | /** |
@@ -2612,25 +2612,25 @@ discard block |
||
| 2612 | 2612 | */ |
| 2613 | 2613 | protected function _putcatalog() : void |
| 2614 | 2614 | {
|
| 2615 | - $n = $this->PageInfo[1]['n']; |
|
| 2616 | - $this->_put('/Type /Catalog');
|
|
| 2617 | - $this->_put('/Pages 1 0 R');
|
|
| 2618 | - if($this->ZoomMode=='fullpage') {
|
|
| 2619 | - $this->_put('/OpenAction [' . $n . ' 0 R /Fit]');
|
|
| 2620 | - } elseif ($this->ZoomMode=='fullwidth') {
|
|
| 2621 | - $this->_put('/OpenAction [' . $n . ' 0 R /FitH null]');
|
|
| 2622 | - } elseif($this->ZoomMode=='real') {
|
|
| 2623 | - $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null 1]');
|
|
| 2624 | - } elseif(!is_string($this->ZoomMode)) {
|
|
| 2625 | - $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null ' . sprintf('%.2F', $this->ZoomMode / 100) . ']');
|
|
| 2626 | - } |
|
| 2627 | - if($this->LayoutMode=='single') {
|
|
| 2628 | - $this->_put('/PageLayout /SinglePage');
|
|
| 2629 | - } elseif($this->LayoutMode=='continuous') {
|
|
| 2630 | - $this->_put('/PageLayout /OneColumn');
|
|
| 2631 | - } elseif($this->LayoutMode=='two') {
|
|
| 2632 | - $this->_put('/PageLayout /TwoColumnLeft');
|
|
| 2633 | - } |
|
| 2615 | + $n = $this->PageInfo[1]['n']; |
|
| 2616 | + $this->_put('/Type /Catalog');
|
|
| 2617 | + $this->_put('/Pages 1 0 R');
|
|
| 2618 | + if($this->ZoomMode=='fullpage') {
|
|
| 2619 | + $this->_put('/OpenAction [' . $n . ' 0 R /Fit]');
|
|
| 2620 | + } elseif ($this->ZoomMode=='fullwidth') {
|
|
| 2621 | + $this->_put('/OpenAction [' . $n . ' 0 R /FitH null]');
|
|
| 2622 | + } elseif($this->ZoomMode=='real') {
|
|
| 2623 | + $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null 1]');
|
|
| 2624 | + } elseif(!is_string($this->ZoomMode)) {
|
|
| 2625 | + $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null ' . sprintf('%.2F', $this->ZoomMode / 100) . ']');
|
|
| 2626 | + } |
|
| 2627 | + if($this->LayoutMode=='single') {
|
|
| 2628 | + $this->_put('/PageLayout /SinglePage');
|
|
| 2629 | + } elseif($this->LayoutMode=='continuous') {
|
|
| 2630 | + $this->_put('/PageLayout /OneColumn');
|
|
| 2631 | + } elseif($this->LayoutMode=='two') {
|
|
| 2632 | + $this->_put('/PageLayout /TwoColumnLeft');
|
|
| 2633 | + } |
|
| 2634 | 2634 | } |
| 2635 | 2635 | |
| 2636 | 2636 | /** |
@@ -2638,7 +2638,7 @@ discard block |
||
| 2638 | 2638 | */ |
| 2639 | 2639 | protected function _putheader() : void |
| 2640 | 2640 | {
|
| 2641 | - $this->_put('%PDF-' . $this->PDFVersion);
|
|
| 2641 | + $this->_put('%PDF-' . $this->PDFVersion);
|
|
| 2642 | 2642 | } |
| 2643 | 2643 | |
| 2644 | 2644 | /** |
@@ -2646,9 +2646,9 @@ discard block |
||
| 2646 | 2646 | */ |
| 2647 | 2647 | protected function _puttrailer() : void |
| 2648 | 2648 | {
|
| 2649 | - $this->_put('/Size ' . ($this->n + 1));
|
|
| 2650 | - $this->_put('/Root ' . $this->n . ' 0 R');
|
|
| 2651 | - $this->_put('/Info ' . ($this->n - 1) . ' 0 R');
|
|
| 2649 | + $this->_put('/Size ' . ($this->n + 1));
|
|
| 2650 | + $this->_put('/Root ' . $this->n . ' 0 R');
|
|
| 2651 | + $this->_put('/Info ' . ($this->n - 1) . ' 0 R');
|
|
| 2652 | 2652 | } |
| 2653 | 2653 | |
| 2654 | 2654 | /** |
@@ -2656,37 +2656,37 @@ discard block |
||
| 2656 | 2656 | */ |
| 2657 | 2657 | protected function _enddoc() : void |
| 2658 | 2658 | {
|
| 2659 | - $this->_putheader(); |
|
| 2660 | - $this->_putpages(); |
|
| 2661 | - $this->_putresources(); |
|
| 2662 | - // Info |
|
| 2663 | - $this->_newobj(); |
|
| 2664 | - $this->_put('<<');
|
|
| 2665 | - $this->_putinfo(); |
|
| 2666 | - $this->_put('>>');
|
|
| 2667 | - $this->_put('endobj');
|
|
| 2668 | - // Catalog |
|
| 2669 | - $this->_newobj(); |
|
| 2670 | - $this->_put('<<');
|
|
| 2671 | - $this->_putcatalog(); |
|
| 2672 | - $this->_put('>>');
|
|
| 2673 | - $this->_put('endobj');
|
|
| 2674 | - // Cross-ref |
|
| 2675 | - $offset = $this->_getoffset(); |
|
| 2676 | - $this->_put('xref');
|
|
| 2677 | - $this->_put('0 ' . ($this->n + 1));
|
|
| 2678 | - $this->_put('0000000000 65535 f ');
|
|
| 2679 | - for ($i = 1; $i <= $this->n; $i++) {
|
|
| 2680 | - $this->_put(sprintf('%010d 00000 n ', $this->offsets[$i]));
|
|
| 2681 | - } |
|
| 2682 | - // Trailer |
|
| 2683 | - $this->_put('trailer');
|
|
| 2684 | - $this->_put('<<');
|
|
| 2685 | - $this->_puttrailer(); |
|
| 2686 | - $this->_put('>>');
|
|
| 2687 | - $this->_put('startxref');
|
|
| 2688 | - $this->_put(strval($offset)); |
|
| 2689 | - $this->_put('%%EOF');
|
|
| 2690 | - $this->state = 3; |
|
| 2659 | + $this->_putheader(); |
|
| 2660 | + $this->_putpages(); |
|
| 2661 | + $this->_putresources(); |
|
| 2662 | + // Info |
|
| 2663 | + $this->_newobj(); |
|
| 2664 | + $this->_put('<<');
|
|
| 2665 | + $this->_putinfo(); |
|
| 2666 | + $this->_put('>>');
|
|
| 2667 | + $this->_put('endobj');
|
|
| 2668 | + // Catalog |
|
| 2669 | + $this->_newobj(); |
|
| 2670 | + $this->_put('<<');
|
|
| 2671 | + $this->_putcatalog(); |
|
| 2672 | + $this->_put('>>');
|
|
| 2673 | + $this->_put('endobj');
|
|
| 2674 | + // Cross-ref |
|
| 2675 | + $offset = $this->_getoffset(); |
|
| 2676 | + $this->_put('xref');
|
|
| 2677 | + $this->_put('0 ' . ($this->n + 1));
|
|
| 2678 | + $this->_put('0000000000 65535 f ');
|
|
| 2679 | + for ($i = 1; $i <= $this->n; $i++) {
|
|
| 2680 | + $this->_put(sprintf('%010d 00000 n ', $this->offsets[$i]));
|
|
| 2681 | + } |
|
| 2682 | + // Trailer |
|
| 2683 | + $this->_put('trailer');
|
|
| 2684 | + $this->_put('<<');
|
|
| 2685 | + $this->_puttrailer(); |
|
| 2686 | + $this->_put('>>');
|
|
| 2687 | + $this->_put('startxref');
|
|
| 2688 | + $this->_put(strval($offset)); |
|
| 2689 | + $this->_put('%%EOF');
|
|
| 2690 | + $this->state = 3; |
|
| 2691 | 2691 | } |
| 2692 | 2692 | } |
@@ -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 | {
|
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * or an array containing the width and the height (expressed in the unit given by unit). <br/> |
| 172 | 172 | * Default value is 'A4'. |
| 173 | 173 | */ |
| 174 | - public function __construct(string $orientation='P', string $unit='mm', $size='A4') |
|
| 174 | + public function __construct(string $orientation = 'P', string $unit = 'mm', $size = 'A4') |
|
| 175 | 175 | {
|
| 176 | 176 | // Some checks |
| 177 | 177 | $this->doChecks(); |
@@ -187,10 +187,10 @@ discard block |
||
| 187 | 187 | $this->k = 1; |
| 188 | 188 | break; |
| 189 | 189 | case 'mm': |
| 190 | - $this->k = 72/25.4; |
|
| 190 | + $this->k = 72 / 25.4; |
|
| 191 | 191 | break; |
| 192 | 192 | case 'cm': |
| 193 | - $this->k = 72/2.54; |
|
| 193 | + $this->k = 72 / 2.54; |
|
| 194 | 194 | break; |
| 195 | 195 | case 'in': |
| 196 | 196 | $this->k = 72; |
@@ -250,12 +250,12 @@ discard block |
||
| 250 | 250 | * @param float $top Top margin. |
| 251 | 251 | * @param float $right Right margin. Default value is the left one. |
| 252 | 252 | */ |
| 253 | - public function SetMargins(float $left, float $top, ?float $right=null) : void |
|
| 253 | + public function SetMargins(float $left, float $top, ?float $right = null) : void |
|
| 254 | 254 | {
|
| 255 | 255 | // Set left, top and right margins |
| 256 | 256 | $this->lMargin = $left; |
| 257 | 257 | $this->tMargin = $top; |
| 258 | - if($right===null) |
|
| 258 | + if ($right === null) |
|
| 259 | 259 | $right = $left; |
| 260 | 260 | $this->rMargin = $right; |
| 261 | 261 | } |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | {
|
| 271 | 271 | // Set left margin |
| 272 | 272 | $this->lMargin = $margin; |
| 273 | - if($this->page>0 && $this->x<$margin) |
|
| 273 | + if ($this->page > 0 && $this->x < $margin) |
|
| 274 | 274 | $this->x = $margin; |
| 275 | 275 | } |
| 276 | 276 | |
@@ -304,12 +304,12 @@ discard block |
||
| 304 | 304 | * @param bool $auto indicating if mode should be on or off. |
| 305 | 305 | * @param float $margin Distance from the bottom of the page. |
| 306 | 306 | */ |
| 307 | - public function SetAutoPageBreak(bool $auto, float $margin=0) : void |
|
| 307 | + public function SetAutoPageBreak(bool $auto, float $margin = 0) : void |
|
| 308 | 308 | {
|
| 309 | 309 | // Set auto page break mode and triggering margin |
| 310 | 310 | $this->AutoPageBreak = $auto; |
| 311 | 311 | $this->bMargin = $margin; |
| 312 | - $this->PageBreakTrigger = $this->h-$margin; |
|
| 312 | + $this->PageBreakTrigger = $this->h - $margin; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | /** |
@@ -340,17 +340,17 @@ discard block |
||
| 340 | 340 | * <li> 'defaul't: uses viewer default mode </li></ul> |
| 341 | 341 | * Default value is default. |
| 342 | 342 | */ |
| 343 | - public function SetDisplayMode($zoom, string $layout='default') : void |
|
| 343 | + public function SetDisplayMode($zoom, string $layout = 'default') : void |
|
| 344 | 344 | {
|
| 345 | 345 | // Set display mode in viewer |
| 346 | - if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) |
|
| 346 | + if ($zoom == 'fullpage' || $zoom == 'fullwidth' || $zoom == 'real' || $zoom == 'default' || !is_string($zoom)) |
|
| 347 | 347 | $this->ZoomMode = $zoom; |
| 348 | 348 | else |
| 349 | - $this->Error('Incorrect zoom display mode: '.$zoom);
|
|
| 350 | - if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') |
|
| 349 | + $this->Error('Incorrect zoom display mode: ' . $zoom);
|
|
| 350 | + if ($layout == 'single' || $layout == 'continuous' || $layout == 'two' || $layout == 'default') |
|
| 351 | 351 | $this->LayoutMode = $layout; |
| 352 | 352 | else |
| 353 | - $this->Error('Incorrect layout display mode: '.$layout);
|
|
| 353 | + $this->Error('Incorrect layout display mode: ' . $layout);
|
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | public function SetCompression(bool $compress) : void |
| 366 | 366 | {
|
| 367 | 367 | // Set page compression |
| 368 | - if(function_exists('gzcompress'))
|
|
| 368 | + if (function_exists('gzcompress'))
|
|
| 369 | 369 | $this->compress = $compress; |
| 370 | 370 | else |
| 371 | 371 | $this->compress = false; |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | * @param string $title The title. |
| 377 | 377 | * @param bool $isUTF8 Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: false. |
| 378 | 378 | */ |
| 379 | - public function SetTitle(string $title, bool $isUTF8=false) : void |
|
| 379 | + public function SetTitle(string $title, bool $isUTF8 = false) : void |
|
| 380 | 380 | {
|
| 381 | 381 | // Title of document |
| 382 | 382 | $this->metadata['Title'] = $isUTF8 ? $title : utf8_encode($title); |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | * @param string $author |
| 388 | 388 | * @param bool $isUTF8 Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: false. |
| 389 | 389 | */ |
| 390 | - public function SetAuthor(string $author, bool $isUTF8=false) : void |
|
| 390 | + public function SetAuthor(string $author, bool $isUTF8 = false) : void |
|
| 391 | 391 | {
|
| 392 | 392 | // Author of document |
| 393 | 393 | $this->metadata['Author'] = $isUTF8 ? $author : utf8_encode($author); |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | * @param string $subject |
| 399 | 399 | * @param bool $isUTF8 Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: false. |
| 400 | 400 | */ |
| 401 | - public function SetSubject(string $subject, bool $isUTF8=false) : void |
|
| 401 | + public function SetSubject(string $subject, bool $isUTF8 = false) : void |
|
| 402 | 402 | {
|
| 403 | 403 | // Subject of document |
| 404 | 404 | $this->metadata['Subject'] = $isUTF8 ? $subject : utf8_encode($subject); |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | * @param string $keywords |
| 410 | 410 | * @param bool $isUTF8 Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: false. |
| 411 | 411 | */ |
| 412 | - public function SetKeywords(string $keywords, bool $isUTF8=false) : void |
|
| 412 | + public function SetKeywords(string $keywords, bool $isUTF8 = false) : void |
|
| 413 | 413 | {
|
| 414 | 414 | // Keywords of document |
| 415 | 415 | $this->metadata['Keywords'] = $isUTF8 ? $keywords : utf8_encode($keywords); |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | * @param string $creator |
| 421 | 421 | * @param bool $isUTF8 Indicates if the string is encoded in ISO-8859-1 (false) or UTF-8 (true). Default value: false. |
| 422 | 422 | */ |
| 423 | - public function SetCreator(string $creator, bool $isUTF8=false) : void |
|
| 423 | + public function SetCreator(string $creator, bool $isUTF8 = false) : void |
|
| 424 | 424 | {
|
| 425 | 425 | // Creator of document |
| 426 | 426 | $this->metadata['Creator'] = $isUTF8 ? $creator : utf8_encode($creator); |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | * Defines an alias for the total number of pages. It will be substituted as the document is closed. |
| 431 | 431 | * @param string $alias The alias. Default value: {nb}.
|
| 432 | 432 | */ |
| 433 | - public function AliasNbPages(string $alias='{nb}') : void
|
|
| 433 | + public function AliasNbPages(string $alias = '{nb}') : void
|
|
| 434 | 434 | {
|
| 435 | 435 | // Define an alias for total number of pages |
| 436 | 436 | $this->AliasNbPages = $alias; |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | public function Error(string $msg) : void |
| 448 | 448 | {
|
| 449 | 449 | // Fatal error |
| 450 | - throw new \Exception('FPDF error: '.$msg);
|
|
| 450 | + throw new \Exception('FPDF error: ' . $msg);
|
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | /** |
@@ -459,9 +459,9 @@ discard block |
||
| 459 | 459 | public function Close() : void |
| 460 | 460 | {
|
| 461 | 461 | // Terminate document |
| 462 | - if($this->state==3) |
|
| 462 | + if ($this->state == 3) |
|
| 463 | 463 | return; |
| 464 | - if($this->page==0) |
|
| 464 | + if ($this->page == 0) |
|
| 465 | 465 | $this->addPage(); |
| 466 | 466 | // Page footer |
| 467 | 467 | $this->InFooter = true; |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | * It must be a multiple of 90; positive values mean clockwise rotation. </br> |
| 502 | 502 | * The default value is 0. |
| 503 | 503 | */ |
| 504 | - public function AddPage(string $orientation='', $size='', int $rotation=0) : void |
|
| 504 | + public function AddPage(string $orientation = '', $size = '', int $rotation = 0) : void |
|
| 505 | 505 | {
|
| 506 | 506 | // Start a new page |
| 507 | 507 | if ($this->state == 3) {
|
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | * @param int $g Green component (between 0 and 255). |
| 612 | 612 | * @param int $b Blue component (between 0 and 255). |
| 613 | 613 | */ |
| 614 | - public function SetDrawColor(int $r, ?int $g=null, ?int $b=null) : void |
|
| 614 | + public function SetDrawColor(int $r, ?int $g = null, ?int $b = null) : void |
|
| 615 | 615 | {
|
| 616 | 616 | // Set color for all stroking operations |
| 617 | 617 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) {
|
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | * @param int $g Green component (between 0 and 255). |
| 633 | 633 | * @param int $b Blue component (between 0 and 255). |
| 634 | 634 | */ |
| 635 | - public function SetFillColor(int $r, ?int $g=null, ?int $b=null) : void |
|
| 635 | + public function SetFillColor(int $r, ?int $g = null, ?int $b = null) : void |
|
| 636 | 636 | {
|
| 637 | 637 | // Set color for all filling operations |
| 638 | 638 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) {
|
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | * @param int $g Green component (between 0 and 255). |
| 655 | 655 | * @param int $b Blue component (between 0 and 255). |
| 656 | 656 | */ |
| 657 | - public function SetTextColor(int $r, ?int $g=null, ?int $b=null) : void |
|
| 657 | + public function SetTextColor(int $r, ?int $g = null, ?int $b = null) : void |
|
| 658 | 658 | {
|
| 659 | 659 | // Set color for text |
| 660 | 660 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) {
|
@@ -674,13 +674,13 @@ discard block |
||
| 674 | 674 | public function GetStringWidth(string $s) : float |
| 675 | 675 | {
|
| 676 | 676 | // Get width of a string in the current font |
| 677 | - $s = (string)$s; |
|
| 677 | + $s = (string) $s; |
|
| 678 | 678 | $cw = &$this->CurrentFont['cw']; |
| 679 | 679 | $w = 0; |
| 680 | 680 | $l = strlen($s); |
| 681 | - for($i=0;$i<$l;$i++) |
|
| 681 | + for ($i = 0; $i < $l; $i++) |
|
| 682 | 682 | $w += $cw[$s[$i]]; |
| 683 | - return $w*$this->FontSize/1000; |
|
| 683 | + return $w * $this->FontSize / 1000; |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | /** |
@@ -693,8 +693,8 @@ discard block |
||
| 693 | 693 | {
|
| 694 | 694 | // Set line width |
| 695 | 695 | $this->LineWidth = $width; |
| 696 | - if($this->page>0) |
|
| 697 | - $this->_out(sprintf('%.2F w',$width*$this->k));
|
|
| 696 | + if ($this->page > 0) |
|
| 697 | + $this->_out(sprintf('%.2F w', $width * $this->k));
|
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | /** |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | public function Line(float $x1, float $y1, float $x2, float $y2) : void |
| 710 | 710 | {
|
| 711 | 711 | // Draw a line |
| 712 | - $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));
|
|
| 712 | + $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));
|
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | /** |
@@ -727,16 +727,16 @@ discard block |
||
| 727 | 727 | * <li> 'F': fill. </li> |
| 728 | 728 | * <li> 'DF' or 'FD': draw the shape and fill. </li></ul> |
| 729 | 729 | */ |
| 730 | - public function Rect(float $x, float $y, float $w, float $h, string $style='') : void |
|
| 730 | + public function Rect(float $x, float $y, float $w, float $h, string $style = '') : void |
|
| 731 | 731 | {
|
| 732 | 732 | // Draw a rectangle |
| 733 | - if($style=='F') |
|
| 733 | + if ($style == 'F') |
|
| 734 | 734 | $op = 'f'; |
| 735 | - elseif($style=='FD' || $style=='DF') |
|
| 735 | + elseif ($style == 'FD' || $style == 'DF') |
|
| 736 | 736 | $op = 'B'; |
| 737 | 737 | else |
| 738 | 738 | $op = 'S'; |
| 739 | - $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
|
|
| 739 | + $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, -$h * $this->k, $op));
|
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | /** |
@@ -756,24 +756,24 @@ discard block |
||
| 756 | 756 | * @param string $file The font definition file. <br/> |
| 757 | 757 | * By default, the name is built from the family and style, in lower case with no space. |
| 758 | 758 | */ |
| 759 | - public function AddFont(string $family, string $style='', string $file='') : void |
|
| 759 | + public function AddFont(string $family, string $style = '', string $file = '') : void |
|
| 760 | 760 | {
|
| 761 | 761 | // Add a TrueType, OpenType or Type1 font |
| 762 | 762 | $family = strtolower($family); |
| 763 | - if($file=='') |
|
| 764 | - $file = str_replace(' ','',$family).strtolower($style).'.php';
|
|
| 763 | + if ($file == '') |
|
| 764 | + $file = str_replace(' ', '', $family) . strtolower($style) . '.php';
|
|
| 765 | 765 | $style = strtoupper($style); |
| 766 | - if($style=='IB') |
|
| 766 | + if ($style == 'IB') |
|
| 767 | 767 | $style = 'BI'; |
| 768 | - $fontkey = $family.$style; |
|
| 769 | - if(isset($this->fonts[$fontkey])) |
|
| 768 | + $fontkey = $family . $style; |
|
| 769 | + if (isset($this->fonts[$fontkey])) |
|
| 770 | 770 | return; |
| 771 | 771 | $info = $this->_loadfont($file); |
| 772 | - $info['i'] = count($this->fonts)+1; |
|
| 773 | - if(!empty($info['file'])) |
|
| 772 | + $info['i'] = count($this->fonts) + 1; |
|
| 773 | + if (!empty($info['file'])) |
|
| 774 | 774 | {
|
| 775 | 775 | // Embedded font |
| 776 | - if($info['type']=='TrueType') |
|
| 776 | + if ($info['type'] == 'TrueType') |
|
| 777 | 777 | $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']);
|
| 778 | 778 | else |
| 779 | 779 | $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']);
|
@@ -816,54 +816,54 @@ discard block |
||
| 816 | 816 | * The default value is the current size. <br/> |
| 817 | 817 | * If no size has been specified since the beginning of the document, the value taken is 12. |
| 818 | 818 | */ |
| 819 | - public function SetFont(string $family, string $style='', float $size=0) : void |
|
| 819 | + public function SetFont(string $family, string $style = '', float $size = 0) : void |
|
| 820 | 820 | {
|
| 821 | 821 | // Select a font; size given in points |
| 822 | - if($family=='') |
|
| 822 | + if ($family == '') |
|
| 823 | 823 | $family = $this->FontFamily; |
| 824 | 824 | else |
| 825 | 825 | $family = strtolower($family); |
| 826 | 826 | $style = strtoupper($style); |
| 827 | - if(strpos($style,'U')!==false) |
|
| 827 | + if (strpos($style, 'U') !== false) |
|
| 828 | 828 | {
|
| 829 | 829 | $this->underline = true; |
| 830 | - $style = str_replace('U','',$style);
|
|
| 830 | + $style = str_replace('U', '', $style);
|
|
| 831 | 831 | } |
| 832 | 832 | else |
| 833 | 833 | $this->underline = false; |
| 834 | - if($style=='IB') |
|
| 834 | + if ($style == 'IB') |
|
| 835 | 835 | $style = 'BI'; |
| 836 | - if($size==0) |
|
| 836 | + if ($size == 0) |
|
| 837 | 837 | $size = $this->FontSizePt; |
| 838 | 838 | // Test if font is already selected |
| 839 | - if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) |
|
| 839 | + if ($this->FontFamily == $family && $this->FontStyle == $style && $this->FontSizePt == $size) |
|
| 840 | 840 | return; |
| 841 | 841 | // Test if font is already loaded |
| 842 | - $fontkey = $family.$style; |
|
| 843 | - if(!isset($this->fonts[$fontkey])) |
|
| 842 | + $fontkey = $family . $style; |
|
| 843 | + if (!isset($this->fonts[$fontkey])) |
|
| 844 | 844 | {
|
| 845 | 845 | // Test if one of the core fonts |
| 846 | - if($family=='arial') |
|
| 846 | + if ($family == 'arial') |
|
| 847 | 847 | $family = 'helvetica'; |
| 848 | - if(in_array($family,$this->CoreFonts)) |
|
| 848 | + if (in_array($family, $this->CoreFonts)) |
|
| 849 | 849 | {
|
| 850 | - if($family=='symbol' || $family=='zapfdingbats') |
|
| 850 | + if ($family == 'symbol' || $family == 'zapfdingbats') |
|
| 851 | 851 | $style = ''; |
| 852 | - $fontkey = $family.$style; |
|
| 853 | - if(!isset($this->fonts[$fontkey])) |
|
| 854 | - $this->addFont($family,$style); |
|
| 852 | + $fontkey = $family . $style; |
|
| 853 | + if (!isset($this->fonts[$fontkey])) |
|
| 854 | + $this->addFont($family, $style); |
|
| 855 | 855 | } |
| 856 | 856 | else |
| 857 | - $this->Error('Undefined font: '.$family.' '.$style);
|
|
| 857 | + $this->Error('Undefined font: ' . $family . ' ' . $style);
|
|
| 858 | 858 | } |
| 859 | 859 | // Select it |
| 860 | 860 | $this->FontFamily = $family; |
| 861 | 861 | $this->FontStyle = $style; |
| 862 | 862 | $this->FontSizePt = $size; |
| 863 | - $this->FontSize = $size/$this->k; |
|
| 863 | + $this->FontSize = $size / $this->k; |
|
| 864 | 864 | $this->CurrentFont = &$this->fonts[$fontkey]; |
| 865 | - if($this->page>0) |
|
| 866 | - $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
|
|
| 865 | + if ($this->page > 0) |
|
| 866 | + $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
|
|
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | /** |
@@ -873,12 +873,12 @@ discard block |
||
| 873 | 873 | public function SetFontSize(float $size) : void |
| 874 | 874 | {
|
| 875 | 875 | // Set font size in points |
| 876 | - if($this->FontSizePt==$size) |
|
| 876 | + if ($this->FontSizePt == $size) |
|
| 877 | 877 | return; |
| 878 | 878 | $this->FontSizePt = $size; |
| 879 | - $this->FontSize = $size/$this->k; |
|
| 880 | - if($this->page>0) |
|
| 881 | - $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
|
|
| 879 | + $this->FontSize = $size / $this->k; |
|
| 880 | + if ($this->page > 0) |
|
| 881 | + $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
|
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | /** |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | public function AddLink() : int |
| 892 | 892 | {
|
| 893 | 893 | // Create a new internal link |
| 894 | - $n = count($this->links)+1; |
|
| 894 | + $n = count($this->links) + 1; |
|
| 895 | 895 | $this->links[$n] = array(0, 0); |
| 896 | 896 | return $n; |
| 897 | 897 | } |
@@ -902,12 +902,12 @@ discard block |
||
| 902 | 902 | * @param float $y Y-position of target position; -1 indicates the current position. The default value is 0 (top of page). |
| 903 | 903 | * @param int $page Number of target page; -1 indicates the current page. This is the default value. |
| 904 | 904 | */ |
| 905 | - public function SetLink(int $link, float $y=0, int $page=-1) : void |
|
| 905 | + public function SetLink(int $link, float $y = 0, int $page = -1) : void |
|
| 906 | 906 | {
|
| 907 | 907 | // Set destination of internal link |
| 908 | - if($y==-1) |
|
| 908 | + if ($y == -1) |
|
| 909 | 909 | $y = $this->y; |
| 910 | - if($page==-1) |
|
| 910 | + if ($page == -1) |
|
| 911 | 911 | $page = $this->page; |
| 912 | 912 | $this->links[$link] = array($page, $y); |
| 913 | 913 | } |
@@ -926,7 +926,7 @@ discard block |
||
| 926 | 926 | public function Link(float $x, float $y, float $w, float $h, $link) : void |
| 927 | 927 | {
|
| 928 | 928 | // Put a link on the page |
| 929 | - $this->PageLinks[$this->page][] = array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link); |
|
| 929 | + $this->PageLinks[$this->page][] = array($x * $this->k, $this->hPt - $y * $this->k, $w * $this->k, $h * $this->k, $link); |
|
| 930 | 930 | } |
| 931 | 931 | |
| 932 | 932 | /** |
@@ -942,13 +942,13 @@ discard block |
||
| 942 | 942 | public function Text(float $x, float $y, string $txt) : void |
| 943 | 943 | {
|
| 944 | 944 | // Output a string |
| 945 | - if(!isset($this->CurrentFont)) |
|
| 945 | + if (!isset($this->CurrentFont)) |
|
| 946 | 946 | $this->Error('No font has been set');
|
| 947 | - $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
|
|
| 948 | - if($this->underline && $txt!='') |
|
| 949 | - $s .= ' '.$this->_dounderline($x,$y,$txt); |
|
| 950 | - if($this->ColorFlag) |
|
| 951 | - $s = 'q '.$this->TextColor.' '.$s.' Q'; |
|
| 947 | + $s = sprintf('BT %.2F %.2F Td (%s) Tj ET', $x * $this->k, ($this->h - $y) * $this->k, $this->_escape($txt));
|
|
| 948 | + if ($this->underline && $txt != '') |
|
| 949 | + $s .= ' ' . $this->_dounderline($x, $y, $txt); |
|
| 950 | + if ($this->ColorFlag) |
|
| 951 | + $s = 'q ' . $this->TextColor . ' ' . $s . ' Q'; |
|
| 952 | 952 | $this->_out($s); |
| 953 | 953 | } |
| 954 | 954 | |
@@ -1006,80 +1006,80 @@ discard block |
||
| 1006 | 1006 | * Default value: false. <br/> |
| 1007 | 1007 | * @param string|int $link URL or identifier for internal link created by AddLink(). |
| 1008 | 1008 | */ |
| 1009 | - public function Cell(float $w, float $h=0, string $txt='', $border=0, float $ln=0, $align='', $fill=false, $link='') : void |
|
| 1009 | + public function Cell(float $w, float $h = 0, string $txt = '', $border = 0, float $ln = 0, $align = '', $fill = false, $link = '') : void |
|
| 1010 | 1010 | {
|
| 1011 | 1011 | // Output a cell |
| 1012 | 1012 | $k = $this->k; |
| 1013 | - if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
| 1013 | + if ($this->y + $h > $this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
| 1014 | 1014 | {
|
| 1015 | 1015 | // Automatic page break |
| 1016 | 1016 | $x = $this->x; |
| 1017 | 1017 | $ws = $this->ws; |
| 1018 | - if($ws>0) |
|
| 1018 | + if ($ws > 0) |
|
| 1019 | 1019 | {
|
| 1020 | 1020 | $this->ws = 0; |
| 1021 | 1021 | $this->_out('0 Tw');
|
| 1022 | 1022 | } |
| 1023 | - $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
| 1023 | + $this->addPage($this->CurOrientation, $this->CurPageSize, $this->CurRotation); |
|
| 1024 | 1024 | $this->x = $x; |
| 1025 | - if($ws>0) |
|
| 1025 | + if ($ws > 0) |
|
| 1026 | 1026 | {
|
| 1027 | 1027 | $this->ws = $ws; |
| 1028 | - $this->_out(sprintf('%.3F Tw',$ws*$k));
|
|
| 1028 | + $this->_out(sprintf('%.3F Tw', $ws * $k));
|
|
| 1029 | 1029 | } |
| 1030 | 1030 | } |
| 1031 | - if($w==0) |
|
| 1032 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1031 | + if ($w == 0) |
|
| 1032 | + $w = $this->w - $this->rMargin - $this->x; |
|
| 1033 | 1033 | $s = ''; |
| 1034 | - if($fill || $border==1) |
|
| 1034 | + if ($fill || $border == 1) |
|
| 1035 | 1035 | {
|
| 1036 | - if($fill) |
|
| 1037 | - $op = ($border==1) ? 'B' : 'f'; |
|
| 1036 | + if ($fill) |
|
| 1037 | + $op = ($border == 1) ? 'B' : 'f'; |
|
| 1038 | 1038 | else |
| 1039 | 1039 | $op = 'S'; |
| 1040 | - $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);
|
|
| 1040 | + $s = sprintf('%.2F %.2F %.2F %.2F re %s ', $this->x * $k, ($this->h - $this->y) * $k, $w * $k, -$h * $k, $op);
|
|
| 1041 | 1041 | } |
| 1042 | - if(is_string($border)) |
|
| 1042 | + if (is_string($border)) |
|
| 1043 | 1043 | {
|
| 1044 | 1044 | $x = $this->x; |
| 1045 | 1045 | $y = $this->y; |
| 1046 | - if(strpos($border,'L')!==false) |
|
| 1047 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
|
|
| 1048 | - if(strpos($border,'T')!==false) |
|
| 1049 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
|
|
| 1050 | - if(strpos($border,'R')!==false) |
|
| 1051 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
|
|
| 1052 | - if(strpos($border,'B')!==false) |
|
| 1053 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
|
|
| 1054 | - } |
|
| 1055 | - if($txt!=='') |
|
| 1046 | + if (strpos($border, 'L') !== false) |
|
| 1047 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - $y) * $k, $x * $k, ($this->h - ($y + $h)) * $k);
|
|
| 1048 | + if (strpos($border, 'T') !== false) |
|
| 1049 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - $y) * $k, ($x + $w) * $k, ($this->h - $y) * $k);
|
|
| 1050 | + if (strpos($border, 'R') !== false) |
|
| 1051 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', ($x + $w) * $k, ($this->h - $y) * $k, ($x + $w) * $k, ($this->h - ($y + $h)) * $k);
|
|
| 1052 | + if (strpos($border, 'B') !== false) |
|
| 1053 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - ($y + $h)) * $k, ($x + $w) * $k, ($this->h - ($y + $h)) * $k);
|
|
| 1054 | + } |
|
| 1055 | + if ($txt !== '') |
|
| 1056 | 1056 | {
|
| 1057 | - if(!isset($this->CurrentFont)) |
|
| 1057 | + if (!isset($this->CurrentFont)) |
|
| 1058 | 1058 | $this->Error('No font has been set');
|
| 1059 | - if($align=='R') |
|
| 1060 | - $dx = $w-$this->cMargin-$this->getStringWidth($txt); |
|
| 1061 | - elseif($align=='C') |
|
| 1062 | - $dx = ($w-$this->getStringWidth($txt))/2; |
|
| 1059 | + if ($align == 'R') |
|
| 1060 | + $dx = $w - $this->cMargin - $this->getStringWidth($txt); |
|
| 1061 | + elseif ($align == 'C') |
|
| 1062 | + $dx = ($w - $this->getStringWidth($txt)) / 2; |
|
| 1063 | 1063 | else |
| 1064 | 1064 | $dx = $this->cMargin; |
| 1065 | - if($this->ColorFlag) |
|
| 1066 | - $s .= 'q '.$this->TextColor.' '; |
|
| 1067 | - $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));
|
|
| 1068 | - if($this->underline) |
|
| 1069 | - $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); |
|
| 1070 | - if($this->ColorFlag) |
|
| 1065 | + if ($this->ColorFlag) |
|
| 1066 | + $s .= 'q ' . $this->TextColor . ' '; |
|
| 1067 | + $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));
|
|
| 1068 | + if ($this->underline) |
|
| 1069 | + $s .= ' ' . $this->_dounderline($this->x + $dx, $this->y + .5 * $h + .3 * $this->FontSize, $txt); |
|
| 1070 | + if ($this->ColorFlag) |
|
| 1071 | 1071 | $s .= ' Q'; |
| 1072 | - if($link) |
|
| 1073 | - $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->getStringWidth($txt),$this->FontSize,$link); |
|
| 1072 | + if ($link) |
|
| 1073 | + $this->Link($this->x + $dx, $this->y + .5 * $h - .5 * $this->FontSize, $this->getStringWidth($txt), $this->FontSize, $link); |
|
| 1074 | 1074 | } |
| 1075 | - if($s) |
|
| 1075 | + if ($s) |
|
| 1076 | 1076 | $this->_out($s); |
| 1077 | 1077 | $this->lasth = $h; |
| 1078 | - if($ln>0) |
|
| 1078 | + if ($ln > 0) |
|
| 1079 | 1079 | {
|
| 1080 | 1080 | // Go to next line |
| 1081 | 1081 | $this->y += $h; |
| 1082 | - if($ln==1) |
|
| 1082 | + if ($ln == 1) |
|
| 1083 | 1083 | $this->x = $this->lMargin; |
| 1084 | 1084 | } |
| 1085 | 1085 | else |
@@ -1114,24 +1114,24 @@ discard block |
||
| 1114 | 1114 | * If set to true, current FillColor is used for the background. <br/> |
| 1115 | 1115 | * Default value: false. |
| 1116 | 1116 | */ |
| 1117 | - public function MultiCell(float $w, float $h, string $txt, $border=0, string $align='J', bool $fill=false) : void |
|
| 1117 | + public function MultiCell(float $w, float $h, string $txt, $border = 0, string $align = 'J', bool $fill = false) : void |
|
| 1118 | 1118 | {
|
| 1119 | 1119 | // Output text with automatic or explicit line breaks |
| 1120 | - if(!isset($this->CurrentFont)) |
|
| 1120 | + if (!isset($this->CurrentFont)) |
|
| 1121 | 1121 | $this->Error('No font has been set');
|
| 1122 | 1122 | $cw = &$this->CurrentFont['cw']; |
| 1123 | - if($w==0) |
|
| 1124 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1125 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1126 | - $s = str_replace("\r",'',$txt);
|
|
| 1123 | + if ($w == 0) |
|
| 1124 | + $w = $this->w - $this->rMargin - $this->x; |
|
| 1125 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
| 1126 | + $s = str_replace("\r", '', $txt);
|
|
| 1127 | 1127 | $nb = strlen($s); |
| 1128 | - if($nb>0 && $s[$nb-1]=="\n") |
|
| 1128 | + if ($nb > 0 && $s[$nb - 1] == "\n") |
|
| 1129 | 1129 | $nb--; |
| 1130 | 1130 | $b = 0; |
| 1131 | 1131 | $b2 = ''; |
| 1132 | - if($border) |
|
| 1132 | + if ($border) |
|
| 1133 | 1133 | {
|
| 1134 | - if($border==1) |
|
| 1134 | + if ($border == 1) |
|
| 1135 | 1135 | {
|
| 1136 | 1136 | $border = 'LTRB'; |
| 1137 | 1137 | $b = 'LRT'; |
@@ -1140,11 +1140,11 @@ discard block |
||
| 1140 | 1140 | else |
| 1141 | 1141 | {
|
| 1142 | 1142 | $b2 = ''; |
| 1143 | - if(strpos($border,'L')!==false) |
|
| 1143 | + if (strpos($border, 'L') !== false) |
|
| 1144 | 1144 | $b2 .= 'L'; |
| 1145 | - if(strpos($border,'R')!==false) |
|
| 1145 | + if (strpos($border, 'R') !== false) |
|
| 1146 | 1146 | $b2 .= 'R'; |
| 1147 | - $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; |
|
| 1147 | + $b = (strpos($border, 'T') !== false) ? $b2 . 'T' : $b2; |
|
| 1148 | 1148 | } |
| 1149 | 1149 | } |
| 1150 | 1150 | $sep = -1; |
@@ -1154,80 +1154,80 @@ discard block |
||
| 1154 | 1154 | $ns = 0; |
| 1155 | 1155 | $nl = 1; |
| 1156 | 1156 | $ls = 0; |
| 1157 | - while($i<$nb) |
|
| 1157 | + while ($i < $nb) |
|
| 1158 | 1158 | {
|
| 1159 | 1159 | // Get next character |
| 1160 | 1160 | $c = $s[$i]; |
| 1161 | - if($c=="\n") |
|
| 1161 | + if ($c == "\n") |
|
| 1162 | 1162 | {
|
| 1163 | 1163 | // Explicit line break |
| 1164 | - if($this->ws>0) |
|
| 1164 | + if ($this->ws > 0) |
|
| 1165 | 1165 | {
|
| 1166 | 1166 | $this->ws = 0; |
| 1167 | 1167 | $this->_out('0 Tw');
|
| 1168 | 1168 | } |
| 1169 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1169 | + $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); |
|
| 1170 | 1170 | $i++; |
| 1171 | 1171 | $sep = -1; |
| 1172 | 1172 | $j = $i; |
| 1173 | 1173 | $l = 0; |
| 1174 | 1174 | $ns = 0; |
| 1175 | 1175 | $nl++; |
| 1176 | - if($border && $nl==2) |
|
| 1176 | + if ($border && $nl == 2) |
|
| 1177 | 1177 | $b = $b2; |
| 1178 | 1178 | continue; |
| 1179 | 1179 | } |
| 1180 | - if($c==' ') |
|
| 1180 | + if ($c == ' ') |
|
| 1181 | 1181 | {
|
| 1182 | 1182 | $sep = $i; |
| 1183 | 1183 | $ls = $l; |
| 1184 | 1184 | $ns++; |
| 1185 | 1185 | } |
| 1186 | 1186 | $l += $cw[$c]; |
| 1187 | - if($l>$wmax) |
|
| 1187 | + if ($l > $wmax) |
|
| 1188 | 1188 | {
|
| 1189 | 1189 | // Automatic line break |
| 1190 | - if($sep==-1) |
|
| 1190 | + if ($sep == -1) |
|
| 1191 | 1191 | {
|
| 1192 | - if($i==$j) |
|
| 1192 | + if ($i == $j) |
|
| 1193 | 1193 | $i++; |
| 1194 | - if($this->ws>0) |
|
| 1194 | + if ($this->ws > 0) |
|
| 1195 | 1195 | {
|
| 1196 | 1196 | $this->ws = 0; |
| 1197 | 1197 | $this->_out('0 Tw');
|
| 1198 | 1198 | } |
| 1199 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1199 | + $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); |
|
| 1200 | 1200 | } |
| 1201 | 1201 | else |
| 1202 | 1202 | {
|
| 1203 | - if($align=='J') |
|
| 1203 | + if ($align == 'J') |
|
| 1204 | 1204 | {
|
| 1205 | - $this->ws = ($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; |
|
| 1206 | - $this->_out(sprintf('%.3F Tw',$this->ws*$this->k));
|
|
| 1205 | + $this->ws = ($ns > 1) ? ($wmax - $ls) / 1000 * $this->FontSize / ($ns - 1) : 0; |
|
| 1206 | + $this->_out(sprintf('%.3F Tw', $this->ws * $this->k));
|
|
| 1207 | 1207 | } |
| 1208 | - $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); |
|
| 1209 | - $i = $sep+1; |
|
| 1208 | + $this->Cell($w, $h, substr($s, $j, $sep - $j), $b, 2, $align, $fill); |
|
| 1209 | + $i = $sep + 1; |
|
| 1210 | 1210 | } |
| 1211 | 1211 | $sep = -1; |
| 1212 | 1212 | $j = $i; |
| 1213 | 1213 | $l = 0; |
| 1214 | 1214 | $ns = 0; |
| 1215 | 1215 | $nl++; |
| 1216 | - if($border && $nl==2) |
|
| 1216 | + if ($border && $nl == 2) |
|
| 1217 | 1217 | $b = $b2; |
| 1218 | 1218 | } |
| 1219 | 1219 | else |
| 1220 | 1220 | $i++; |
| 1221 | 1221 | } |
| 1222 | 1222 | // Last chunk |
| 1223 | - if($this->ws>0) |
|
| 1223 | + if ($this->ws > 0) |
|
| 1224 | 1224 | {
|
| 1225 | 1225 | $this->ws = 0; |
| 1226 | 1226 | $this->_out('0 Tw');
|
| 1227 | 1227 | } |
| 1228 | - if($border && strpos($border,'B')!==false) |
|
| 1228 | + if ($border && strpos($border, 'B') !== false) |
|
| 1229 | 1229 | $b .= 'B'; |
| 1230 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1230 | + $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); |
|
| 1231 | 1231 | $this->x = $this->lMargin; |
| 1232 | 1232 | } |
| 1233 | 1233 | |
@@ -1241,78 +1241,78 @@ discard block |
||
| 1241 | 1241 | * @param string $txt String to print. |
| 1242 | 1242 | * @param string|int $link URL or identifier for internal link created by AddLink(). |
| 1243 | 1243 | */ |
| 1244 | - public function Write(float $h, string $txt, $link='') : void |
|
| 1244 | + public function Write(float $h, string $txt, $link = '') : void |
|
| 1245 | 1245 | {
|
| 1246 | 1246 | // Output text in flowing mode |
| 1247 | - if(!isset($this->CurrentFont)) |
|
| 1247 | + if (!isset($this->CurrentFont)) |
|
| 1248 | 1248 | $this->Error('No font has been set');
|
| 1249 | 1249 | $cw = &$this->CurrentFont['cw']; |
| 1250 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1251 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1252 | - $s = str_replace("\r",'',$txt);
|
|
| 1250 | + $w = $this->w - $this->rMargin - $this->x; |
|
| 1251 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
| 1252 | + $s = str_replace("\r", '', $txt);
|
|
| 1253 | 1253 | $nb = strlen($s); |
| 1254 | 1254 | $sep = -1; |
| 1255 | 1255 | $i = 0; |
| 1256 | 1256 | $j = 0; |
| 1257 | 1257 | $l = 0; |
| 1258 | 1258 | $nl = 1; |
| 1259 | - while($i<$nb) |
|
| 1259 | + while ($i < $nb) |
|
| 1260 | 1260 | {
|
| 1261 | 1261 | // Get next character |
| 1262 | 1262 | $c = $s[$i]; |
| 1263 | - if($c=="\n") |
|
| 1263 | + if ($c == "\n") |
|
| 1264 | 1264 | {
|
| 1265 | 1265 | // Explicit line break |
| 1266 | - $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
| 1266 | + $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', false, $link); |
|
| 1267 | 1267 | $i++; |
| 1268 | 1268 | $sep = -1; |
| 1269 | 1269 | $j = $i; |
| 1270 | 1270 | $l = 0; |
| 1271 | - if($nl==1) |
|
| 1271 | + if ($nl == 1) |
|
| 1272 | 1272 | {
|
| 1273 | 1273 | $this->x = $this->lMargin; |
| 1274 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1275 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1274 | + $w = $this->w - $this->rMargin - $this->x; |
|
| 1275 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
| 1276 | 1276 | } |
| 1277 | 1277 | $nl++; |
| 1278 | 1278 | continue; |
| 1279 | 1279 | } |
| 1280 | - if($c==' ') |
|
| 1280 | + if ($c == ' ') |
|
| 1281 | 1281 | $sep = $i; |
| 1282 | 1282 | $l += $cw[$c]; |
| 1283 | - if($l>$wmax) |
|
| 1283 | + if ($l > $wmax) |
|
| 1284 | 1284 | {
|
| 1285 | 1285 | // Automatic line break |
| 1286 | - if($sep==-1) |
|
| 1286 | + if ($sep == -1) |
|
| 1287 | 1287 | {
|
| 1288 | - if($this->x>$this->lMargin) |
|
| 1288 | + if ($this->x > $this->lMargin) |
|
| 1289 | 1289 | {
|
| 1290 | 1290 | // Move to next line |
| 1291 | 1291 | $this->x = $this->lMargin; |
| 1292 | 1292 | $this->y += $h; |
| 1293 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1294 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1293 | + $w = $this->w - $this->rMargin - $this->x; |
|
| 1294 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
| 1295 | 1295 | $i++; |
| 1296 | 1296 | $nl++; |
| 1297 | 1297 | continue; |
| 1298 | 1298 | } |
| 1299 | - if($i==$j) |
|
| 1299 | + if ($i == $j) |
|
| 1300 | 1300 | $i++; |
| 1301 | - $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
| 1301 | + $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', false, $link); |
|
| 1302 | 1302 | } |
| 1303 | 1303 | else |
| 1304 | 1304 | {
|
| 1305 | - $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link); |
|
| 1306 | - $i = $sep+1; |
|
| 1305 | + $this->Cell($w, $h, substr($s, $j, $sep - $j), 0, 2, '', false, $link); |
|
| 1306 | + $i = $sep + 1; |
|
| 1307 | 1307 | } |
| 1308 | 1308 | $sep = -1; |
| 1309 | 1309 | $j = $i; |
| 1310 | 1310 | $l = 0; |
| 1311 | - if($nl==1) |
|
| 1311 | + if ($nl == 1) |
|
| 1312 | 1312 | {
|
| 1313 | 1313 | $this->x = $this->lMargin; |
| 1314 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1315 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1314 | + $w = $this->w - $this->rMargin - $this->x; |
|
| 1315 | + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; |
|
| 1316 | 1316 | } |
| 1317 | 1317 | $nl++; |
| 1318 | 1318 | } |
@@ -1320,8 +1320,8 @@ discard block |
||
| 1320 | 1320 | $i++; |
| 1321 | 1321 | } |
| 1322 | 1322 | // Last chunk |
| 1323 | - if($i!=$j) |
|
| 1324 | - $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link); |
|
| 1323 | + if ($i != $j) |
|
| 1324 | + $this->Cell($l / 1000 * $this->FontSize, $h, substr($s, $j), 0, 0, '', false, $link); |
|
| 1325 | 1325 | } |
| 1326 | 1326 | |
| 1327 | 1327 | /** |
@@ -1331,11 +1331,11 @@ discard block |
||
| 1331 | 1331 | * @param float $h The height of the break. <br/> |
| 1332 | 1332 | * By default, the value equals the height of the last printed cell. |
| 1333 | 1333 | */ |
| 1334 | - public function Ln(float $h=null) : void |
|
| 1334 | + public function Ln(float $h = null) : void |
|
| 1335 | 1335 | {
|
| 1336 | 1336 | // Line feed; default value is the last cell height |
| 1337 | 1337 | $this->x = $this->lMargin; |
| 1338 | - if($h===null) |
|
| 1338 | + if ($h === null) |
|
| 1339 | 1339 | $this->y += $this->lasth; |
| 1340 | 1340 | else |
| 1341 | 1341 | $this->y += $h; |
@@ -1387,69 +1387,69 @@ discard block |
||
| 1387 | 1387 | * If not specified, the type is inferred from the file extension. <br/> |
| 1388 | 1388 | * @param string|int $link URL or identifier for internal link created by AddLink(). |
| 1389 | 1389 | */ |
| 1390 | - public function Image(string $file, ?float $x=null, ?float $y=null, float $w=0, float $h=0, string $type='', $link='') : void |
|
| 1390 | + public function Image(string $file, ?float $x = null, ?float $y = null, float $w = 0, float $h = 0, string $type = '', $link = '') : void |
|
| 1391 | 1391 | {
|
| 1392 | 1392 | // Put an image on the page |
| 1393 | - if($file=='') |
|
| 1393 | + if ($file == '') |
|
| 1394 | 1394 | $this->Error('Image file name is empty');
|
| 1395 | - if(!isset($this->images[$file])) |
|
| 1395 | + if (!isset($this->images[$file])) |
|
| 1396 | 1396 | {
|
| 1397 | 1397 | // First use of this image, get info |
| 1398 | - if($type=='') |
|
| 1398 | + if ($type == '') |
|
| 1399 | 1399 | {
|
| 1400 | - $pos = strrpos($file,'.'); |
|
| 1401 | - if(!$pos) |
|
| 1402 | - $this->Error('Image file has no extension and no type was specified: '.$file);
|
|
| 1403 | - $type = substr($file,$pos+1); |
|
| 1400 | + $pos = strrpos($file, '.'); |
|
| 1401 | + if (!$pos) |
|
| 1402 | + $this->Error('Image file has no extension and no type was specified: ' . $file);
|
|
| 1403 | + $type = substr($file, $pos + 1); |
|
| 1404 | 1404 | } |
| 1405 | 1405 | $type = strtolower($type); |
| 1406 | - if($type=='jpeg') |
|
| 1406 | + if ($type == 'jpeg') |
|
| 1407 | 1407 | $type = 'jpg'; |
| 1408 | - $mtd = '_parse'.$type; |
|
| 1409 | - if(!method_exists($this,$mtd)) |
|
| 1410 | - $this->Error('Unsupported image type: '.$type);
|
|
| 1408 | + $mtd = '_parse' . $type; |
|
| 1409 | + if (!method_exists($this, $mtd)) |
|
| 1410 | + $this->Error('Unsupported image type: ' . $type);
|
|
| 1411 | 1411 | $info = $this->$mtd($file); |
| 1412 | - $info['i'] = count($this->images)+1; |
|
| 1412 | + $info['i'] = count($this->images) + 1; |
|
| 1413 | 1413 | $this->images[$file] = $info; |
| 1414 | 1414 | } |
| 1415 | 1415 | else |
| 1416 | 1416 | $info = $this->images[$file]; |
| 1417 | 1417 | |
| 1418 | 1418 | // Automatic width and height calculation if needed |
| 1419 | - if($w==0 && $h==0) |
|
| 1419 | + if ($w == 0 && $h == 0) |
|
| 1420 | 1420 | {
|
| 1421 | 1421 | // Put image at 96 dpi |
| 1422 | 1422 | $w = -96; |
| 1423 | 1423 | $h = -96; |
| 1424 | 1424 | } |
| 1425 | - if($w<0) |
|
| 1426 | - $w = -$info['w']*72/$w/$this->k; |
|
| 1427 | - if($h<0) |
|
| 1428 | - $h = -$info['h']*72/$h/$this->k; |
|
| 1429 | - if($w==0) |
|
| 1430 | - $w = $h*$info['w']/$info['h']; |
|
| 1431 | - if($h==0) |
|
| 1432 | - $h = $w*$info['h']/$info['w']; |
|
| 1425 | + if ($w < 0) |
|
| 1426 | + $w = -$info['w'] * 72 / $w / $this->k; |
|
| 1427 | + if ($h < 0) |
|
| 1428 | + $h = -$info['h'] * 72 / $h / $this->k; |
|
| 1429 | + if ($w == 0) |
|
| 1430 | + $w = $h * $info['w'] / $info['h']; |
|
| 1431 | + if ($h == 0) |
|
| 1432 | + $h = $w * $info['h'] / $info['w']; |
|
| 1433 | 1433 | |
| 1434 | 1434 | // Flowing mode |
| 1435 | - if($y===null) |
|
| 1435 | + if ($y === null) |
|
| 1436 | 1436 | {
|
| 1437 | - if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
| 1437 | + if ($this->y + $h > $this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
| 1438 | 1438 | {
|
| 1439 | 1439 | // Automatic page break |
| 1440 | 1440 | $x2 = $this->x; |
| 1441 | - $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
| 1441 | + $this->addPage($this->CurOrientation, $this->CurPageSize, $this->CurRotation); |
|
| 1442 | 1442 | $this->x = $x2; |
| 1443 | 1443 | } |
| 1444 | 1444 | $y = $this->y; |
| 1445 | 1445 | $this->y += $h; |
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | - if($x===null) |
|
| 1448 | + if ($x === null) |
|
| 1449 | 1449 | $x = $this->x; |
| 1450 | - $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']));
|
|
| 1451 | - if($link) |
|
| 1452 | - $this->Link($x,$y,$w,$h,$link); |
|
| 1450 | + $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']));
|
|
| 1451 | + if ($link) |
|
| 1452 | + $this->Link($x, $y, $w, $h, $link); |
|
| 1453 | 1453 | } |
| 1454 | 1454 | |
| 1455 | 1455 | /** |
@@ -1490,10 +1490,10 @@ discard block |
||
| 1490 | 1490 | public function SetX(float $x) : void |
| 1491 | 1491 | {
|
| 1492 | 1492 | // Set x position |
| 1493 | - if($x>=0) |
|
| 1493 | + if ($x >= 0) |
|
| 1494 | 1494 | $this->x = $x; |
| 1495 | 1495 | else |
| 1496 | - $this->x = $this->w+$x; |
|
| 1496 | + $this->x = $this->w + $x; |
|
| 1497 | 1497 | } |
| 1498 | 1498 | |
| 1499 | 1499 | /** |
@@ -1512,14 +1512,14 @@ discard block |
||
| 1512 | 1512 | * @param float $y |
| 1513 | 1513 | * @param bool $resetX |
| 1514 | 1514 | */ |
| 1515 | - public function SetY(float $y, bool $resetX=true) : void |
|
| 1515 | + public function SetY(float $y, bool $resetX = true) : void |
|
| 1516 | 1516 | {
|
| 1517 | 1517 | // Set y position and optionally reset x |
| 1518 | - if($y>=0) |
|
| 1518 | + if ($y >= 0) |
|
| 1519 | 1519 | $this->y = $y; |
| 1520 | 1520 | else |
| 1521 | - $this->y = $this->h+$y; |
|
| 1522 | - if($resetX) |
|
| 1521 | + $this->y = $this->h + $y; |
|
| 1522 | + if ($resetX) |
|
| 1523 | 1523 | $this->x = $this->lMargin; |
| 1524 | 1524 | } |
| 1525 | 1525 | |
@@ -1533,7 +1533,7 @@ discard block |
||
| 1533 | 1533 | {
|
| 1534 | 1534 | // Set x and y positions |
| 1535 | 1535 | $this->setX($x); |
| 1536 | - $this->setY($y,false); |
|
| 1536 | + $this->setY($y, false); |
|
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | 1539 | /** |
@@ -1554,31 +1554,31 @@ discard block |
||
| 1554 | 1554 | * The default value is false. <br/> |
| 1555 | 1555 | * @return string |
| 1556 | 1556 | */ |
| 1557 | - public function Output(string $dest='', string $name='', bool $isUTF8=false) : string |
|
| 1557 | + public function Output(string $dest = '', string $name = '', bool $isUTF8 = false) : string |
|
| 1558 | 1558 | {
|
| 1559 | 1559 | // Output PDF to some destination |
| 1560 | 1560 | $this->Close(); |
| 1561 | - if(strlen($name)==1 && strlen($dest)!=1) |
|
| 1561 | + if (strlen($name) == 1 && strlen($dest) != 1) |
|
| 1562 | 1562 | {
|
| 1563 | 1563 | // Fix parameter order |
| 1564 | 1564 | $tmp = $dest; |
| 1565 | 1565 | $dest = $name; |
| 1566 | 1566 | $name = $tmp; |
| 1567 | 1567 | } |
| 1568 | - if($dest=='') |
|
| 1568 | + if ($dest == '') |
|
| 1569 | 1569 | $dest = 'I'; |
| 1570 | - if($name=='') |
|
| 1570 | + if ($name == '') |
|
| 1571 | 1571 | $name = 'doc.pdf'; |
| 1572 | - switch(strtoupper($dest)) |
|
| 1572 | + switch (strtoupper($dest)) |
|
| 1573 | 1573 | {
|
| 1574 | 1574 | case 'I': |
| 1575 | 1575 | // Send to standard output |
| 1576 | 1576 | $this->_checkoutput(); |
| 1577 | - if(PHP_SAPI!='cli') |
|
| 1577 | + if (PHP_SAPI != 'cli') |
|
| 1578 | 1578 | {
|
| 1579 | 1579 | // We send to a browser |
| 1580 | 1580 | header('Content-Type: application/pdf; charset=UTF-8');
|
| 1581 | - header('Content-Disposition: inline; '.$this->_httpencode('filename',$name,$isUTF8));
|
|
| 1581 | + header('Content-Disposition: inline; ' . $this->_httpencode('filename', $name, $isUTF8));
|
|
| 1582 | 1582 | header('Cache-Control: private, max-age=0, must-revalidate');
|
| 1583 | 1583 | header('Pragma: public');
|
| 1584 | 1584 | } |
@@ -1588,21 +1588,21 @@ discard block |
||
| 1588 | 1588 | // Download file |
| 1589 | 1589 | $this->_checkoutput(); |
| 1590 | 1590 | header('Content-Type: application/x-download');
|
| 1591 | - header('Content-Disposition: attachment; '.$this->_httpencode('filename',$name,$isUTF8));
|
|
| 1591 | + header('Content-Disposition: attachment; ' . $this->_httpencode('filename', $name, $isUTF8));
|
|
| 1592 | 1592 | header('Cache-Control: private, max-age=0, must-revalidate');
|
| 1593 | 1593 | header('Pragma: public');
|
| 1594 | 1594 | echo $this->buffer; |
| 1595 | 1595 | break; |
| 1596 | 1596 | case 'F': |
| 1597 | 1597 | // Save to local file |
| 1598 | - if(!file_put_contents($name,$this->buffer)) |
|
| 1599 | - $this->Error('Unable to create output file: '.$name);
|
|
| 1598 | + if (!file_put_contents($name, $this->buffer)) |
|
| 1599 | + $this->Error('Unable to create output file: ' . $name);
|
|
| 1600 | 1600 | break; |
| 1601 | 1601 | case 'S': |
| 1602 | 1602 | // Return as a string |
| 1603 | 1603 | return $this->buffer; |
| 1604 | 1604 | default: |
| 1605 | - $this->Error('Incorrect output destination: '.$dest);
|
|
| 1605 | + $this->Error('Incorrect output destination: ' . $dest);
|
|
| 1606 | 1606 | } |
| 1607 | 1607 | return ''; |
| 1608 | 1608 | } |
@@ -1640,17 +1640,17 @@ discard block |
||
| 1640 | 1640 | */ |
| 1641 | 1641 | protected function _checkoutput() : void |
| 1642 | 1642 | {
|
| 1643 | - if(PHP_SAPI!='cli') |
|
| 1643 | + if (PHP_SAPI != 'cli') |
|
| 1644 | 1644 | {
|
| 1645 | 1645 | $file = ''; |
| 1646 | 1646 | $line = 0; |
| 1647 | - if(headers_sent($file,$line)) |
|
| 1647 | + if (headers_sent($file, $line)) |
|
| 1648 | 1648 | $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)");
|
| 1649 | 1649 | } |
| 1650 | - if(ob_get_length()) |
|
| 1650 | + if (ob_get_length()) |
|
| 1651 | 1651 | {
|
| 1652 | 1652 | // The output buffer is not empty |
| 1653 | - if(preg_match('/^(\xEF\xBB\xBF)?\s*$/',ob_get_contents()))
|
|
| 1653 | + if (preg_match('/^(\xEF\xBB\xBF)?\s*$/', ob_get_contents()))
|
|
| 1654 | 1654 | {
|
| 1655 | 1655 | // It contains only a UTF-8 BOM and/or whitespace, let's clean it |
| 1656 | 1656 | ob_clean(); |
@@ -1707,18 +1707,18 @@ discard block |
||
| 1707 | 1707 | $this->y = $this->tMargin; |
| 1708 | 1708 | $this->FontFamily = ''; |
| 1709 | 1709 | // Check page size and orientation |
| 1710 | - if($orientation=='') |
|
| 1710 | + if ($orientation == '') |
|
| 1711 | 1711 | $orientation = $this->DefOrientation; |
| 1712 | 1712 | else |
| 1713 | 1713 | $orientation = strtoupper($orientation[0]); |
| 1714 | - if($size=='') |
|
| 1714 | + if ($size == '') |
|
| 1715 | 1715 | $size = $this->DefPageSize; |
| 1716 | 1716 | else |
| 1717 | 1717 | $size = $this->getPageSize($size); |
| 1718 | - if($orientation!=$this->CurOrientation || $size[0]!=$this->CurPageSize[0] || $size[1]!=$this->CurPageSize[1]) |
|
| 1718 | + if ($orientation != $this->CurOrientation || $size[0] != $this->CurPageSize[0] || $size[1] != $this->CurPageSize[1]) |
|
| 1719 | 1719 | {
|
| 1720 | 1720 | // New size or orientation |
| 1721 | - if($orientation=='P') |
|
| 1721 | + if ($orientation == 'P') |
|
| 1722 | 1722 | {
|
| 1723 | 1723 | $this->w = $size[0]; |
| 1724 | 1724 | $this->h = $size[1]; |
@@ -1728,18 +1728,18 @@ discard block |
||
| 1728 | 1728 | $this->w = $size[1]; |
| 1729 | 1729 | $this->h = $size[0]; |
| 1730 | 1730 | } |
| 1731 | - $this->wPt = $this->w*$this->k; |
|
| 1732 | - $this->hPt = $this->h*$this->k; |
|
| 1733 | - $this->PageBreakTrigger = $this->h-$this->bMargin; |
|
| 1731 | + $this->wPt = $this->w * $this->k; |
|
| 1732 | + $this->hPt = $this->h * $this->k; |
|
| 1733 | + $this->PageBreakTrigger = $this->h - $this->bMargin; |
|
| 1734 | 1734 | $this->CurOrientation = $orientation; |
| 1735 | 1735 | $this->CurPageSize = $size; |
| 1736 | 1736 | } |
| 1737 | - if($orientation!=$this->DefOrientation || $size[0]!=$this->DefPageSize[0] || $size[1]!=$this->DefPageSize[1]) |
|
| 1737 | + if ($orientation != $this->DefOrientation || $size[0] != $this->DefPageSize[0] || $size[1] != $this->DefPageSize[1]) |
|
| 1738 | 1738 | $this->PageInfo[$this->page]['size'] = array($this->wPt, $this->hPt); |
| 1739 | - if($rotation!=0) |
|
| 1739 | + if ($rotation != 0) |
|
| 1740 | 1740 | {
|
| 1741 | - if($rotation%90!=0) |
|
| 1742 | - $this->Error('Incorrect rotation value: '.$rotation);
|
|
| 1741 | + if ($rotation % 90 != 0) |
|
| 1742 | + $this->Error('Incorrect rotation value: ' . $rotation);
|
|
| 1743 | 1743 | $this->CurRotation = $rotation; |
| 1744 | 1744 | $this->PageInfo[$this->page]['rotation'] = $rotation; |
| 1745 | 1745 | } |
@@ -1761,23 +1761,23 @@ discard block |
||
| 1761 | 1761 | protected function _loadfont(string $font) : array |
| 1762 | 1762 | {
|
| 1763 | 1763 | // Load a font definition file from the font directory |
| 1764 | - if(strpos($font,'/')!==false || strpos($font,"\\")!==false) {
|
|
| 1765 | - $this->Error('Incorrect font definition file name: '.$font);
|
|
| 1764 | + if (strpos($font, '/') !== false || strpos($font, "\\") !== false) {
|
|
| 1765 | + $this->Error('Incorrect font definition file name: ' . $font);
|
|
| 1766 | 1766 | } |
| 1767 | 1767 | // following vars must be initialized in the font definition file beeing included |
| 1768 | 1768 | $name = null; |
| 1769 | 1769 | $enc = null; |
| 1770 | 1770 | $subsetted = null; |
| 1771 | - include($this->fontpath.$font); |
|
| 1771 | + include($this->fontpath . $font); |
|
| 1772 | 1772 | |
| 1773 | 1773 | // phpstan can't see the code dynamicly included before so assuming $name, $enc, $subsetted always set to null! |
| 1774 | - if(!isset($name)) { /* @phpstan-ignore-line */
|
|
| 1774 | + if (!isset($name)) { /* @phpstan-ignore-line */
|
|
| 1775 | 1775 | $this->Error('Could not include font definition file');
|
| 1776 | 1776 | } |
| 1777 | - if(isset($enc)) { /* @phpstan-ignore-line */
|
|
| 1777 | + if (isset($enc)) { /* @phpstan-ignore-line */
|
|
| 1778 | 1778 | $enc = strtolower($enc); |
| 1779 | 1779 | } |
| 1780 | - if(!isset($subsetted)) { /* @phpstan-ignore-line */
|
|
| 1780 | + if (!isset($subsetted)) { /* @phpstan-ignore-line */
|
|
| 1781 | 1781 | $subsetted = false; |
| 1782 | 1782 | } |
| 1783 | 1783 | return get_defined_vars(); |
@@ -1792,9 +1792,9 @@ discard block |
||
| 1792 | 1792 | {
|
| 1793 | 1793 | // Test if string is ASCII |
| 1794 | 1794 | $nb = strlen($s); |
| 1795 | - for($i=0;$i<$nb;$i++) |
|
| 1795 | + for ($i = 0; $i < $nb; $i++) |
|
| 1796 | 1796 | {
|
| 1797 | - if(ord($s[$i])>127) |
|
| 1797 | + if (ord($s[$i]) > 127) |
|
| 1798 | 1798 | return false; |
| 1799 | 1799 | } |
| 1800 | 1800 | return true; |
@@ -1809,14 +1809,14 @@ discard block |
||
| 1809 | 1809 | protected function _httpencode(string $param, string $value, bool $isUTF8) : string |
| 1810 | 1810 | {
|
| 1811 | 1811 | // Encode HTTP header field parameter |
| 1812 | - if($this->_isascii($value)) |
|
| 1813 | - return $param.'="'.$value.'"'; |
|
| 1814 | - if(!$isUTF8) |
|
| 1812 | + if ($this->_isascii($value)) |
|
| 1813 | + return $param . '="' . $value . '"'; |
|
| 1814 | + if (!$isUTF8) |
|
| 1815 | 1815 | $value = utf8_encode($value); |
| 1816 | - if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==false) |
|
| 1817 | - return $param.'="'.rawurlencode($value).'"'; |
|
| 1816 | + if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) |
|
| 1817 | + return $param . '="' . rawurlencode($value) . '"'; |
|
| 1818 | 1818 | else |
| 1819 | - return $param."*=UTF-8''".rawurlencode($value); |
|
| 1819 | + return $param . "*=UTF-8''" . rawurlencode($value); |
|
| 1820 | 1820 | } |
| 1821 | 1821 | |
| 1822 | 1822 | /** |
@@ -1830,28 +1830,28 @@ discard block |
||
| 1830 | 1830 | $res = "\xFE\xFF"; |
| 1831 | 1831 | $nb = strlen($s); |
| 1832 | 1832 | $i = 0; |
| 1833 | - while($i<$nb) |
|
| 1833 | + while ($i < $nb) |
|
| 1834 | 1834 | {
|
| 1835 | 1835 | $c1 = ord($s[$i++]); |
| 1836 | - if($c1>=224) |
|
| 1836 | + if ($c1 >= 224) |
|
| 1837 | 1837 | {
|
| 1838 | 1838 | // 3-byte character |
| 1839 | 1839 | $c2 = ord($s[$i++]); |
| 1840 | 1840 | $c3 = ord($s[$i++]); |
| 1841 | - $res .= chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2)); |
|
| 1842 | - $res .= chr((($c2 & 0x03)<<6) + ($c3 & 0x3F)); |
|
| 1841 | + $res .= chr((($c1 & 0x0F) << 4) + (($c2 & 0x3C) >> 2)); |
|
| 1842 | + $res .= chr((($c2 & 0x03) << 6) + ($c3 & 0x3F)); |
|
| 1843 | 1843 | } |
| 1844 | - elseif($c1>=192) |
|
| 1844 | + elseif ($c1 >= 192) |
|
| 1845 | 1845 | {
|
| 1846 | 1846 | // 2-byte character |
| 1847 | 1847 | $c2 = ord($s[$i++]); |
| 1848 | - $res .= chr(($c1 & 0x1C)>>2); |
|
| 1849 | - $res .= chr((($c1 & 0x03)<<6) + ($c2 & 0x3F)); |
|
| 1848 | + $res .= chr(($c1 & 0x1C) >> 2); |
|
| 1849 | + $res .= chr((($c1 & 0x03) << 6) + ($c2 & 0x3F)); |
|
| 1850 | 1850 | } |
| 1851 | 1851 | else |
| 1852 | 1852 | {
|
| 1853 | 1853 | // Single-byte character |
| 1854 | - $res .= "\0".chr($c1); |
|
| 1854 | + $res .= "\0" . chr($c1); |
|
| 1855 | 1855 | } |
| 1856 | 1856 | } |
| 1857 | 1857 | return $res; |
@@ -1865,8 +1865,8 @@ discard block |
||
| 1865 | 1865 | protected function _escape(string $s) : string |
| 1866 | 1866 | {
|
| 1867 | 1867 | // Escape special characters |
| 1868 | - if(strpos($s,'(')!==false || strpos($s,')')!==false || strpos($s,'\\')!==false || strpos($s,"\r")!==false)
|
|
| 1869 | - return str_replace(array('\\','(',')',"\r"), array('\\\\','\\(','\\)','\\r'), $s);
|
|
| 1868 | + if (strpos($s, '(') !== false || strpos($s, ')') !== false || strpos($s, '\\') !== false || strpos($s, "\r") !== false)
|
|
| 1869 | + return str_replace(array('\\', '(', ')', "\r"), array('\\\\', '\\(', '\\)', '\\r'), $s);
|
|
| 1870 | 1870 | else |
| 1871 | 1871 | return $s; |
| 1872 | 1872 | } |
@@ -1879,9 +1879,9 @@ discard block |
||
| 1879 | 1879 | protected function _textstring(string $s) : string |
| 1880 | 1880 | {
|
| 1881 | 1881 | // Format a text string |
| 1882 | - if(!$this->_isascii($s)) |
|
| 1882 | + if (!$this->_isascii($s)) |
|
| 1883 | 1883 | $s = $this->_UTF8toUTF16($s); |
| 1884 | - return '('.$this->_escape($s).')';
|
|
| 1884 | + return '(' . $this->_escape($s) . ')';
|
|
| 1885 | 1885 | } |
| 1886 | 1886 | |
| 1887 | 1887 | /** |
@@ -1896,8 +1896,8 @@ discard block |
||
| 1896 | 1896 | // Underline text |
| 1897 | 1897 | $up = $this->CurrentFont['up']; |
| 1898 | 1898 | $ut = $this->CurrentFont['ut']; |
| 1899 | - $w = $this->getStringWidth($txt)+$this->ws*substr_count($txt,' '); |
|
| 1900 | - 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);
|
|
| 1899 | + $w = $this->getStringWidth($txt) + $this->ws * substr_count($txt, ' '); |
|
| 1900 | + 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 | 1901 | } |
| 1902 | 1902 | |
| 1903 | 1903 | /** |
@@ -1909,13 +1909,13 @@ discard block |
||
| 1909 | 1909 | {
|
| 1910 | 1910 | // Extract info from a JPEG file |
| 1911 | 1911 | $a = getimagesize($file); |
| 1912 | - if(!$a) |
|
| 1913 | - $this->Error('Missing or incorrect image file: '.$file);
|
|
| 1914 | - if($a[2]!=2) |
|
| 1915 | - $this->Error('Not a JPEG file: '.$file);
|
|
| 1916 | - if(!isset($a['channels']) || $a['channels']==3) |
|
| 1912 | + if (!$a) |
|
| 1913 | + $this->Error('Missing or incorrect image file: ' . $file);
|
|
| 1914 | + if ($a[2] != 2) |
|
| 1915 | + $this->Error('Not a JPEG file: ' . $file);
|
|
| 1916 | + if (!isset($a['channels']) || $a['channels'] == 3) |
|
| 1917 | 1917 | $colspace = 'DeviceRGB'; |
| 1918 | - elseif($a['channels']==4) |
|
| 1918 | + elseif ($a['channels'] == 4) |
|
| 1919 | 1919 | $colspace = 'DeviceCMYK'; |
| 1920 | 1920 | else |
| 1921 | 1921 | $colspace = 'DeviceGray'; |
@@ -1950,36 +1950,36 @@ discard block |
||
| 1950 | 1950 | protected function _parsepngstream($f, string $file) : array |
| 1951 | 1951 | {
|
| 1952 | 1952 | // Check signature |
| 1953 | - if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) |
|
| 1954 | - $this->Error('Not a PNG file: '.$file);
|
|
| 1953 | + if ($this->_readstream($f, 8) != chr(137) . 'PNG' . chr(13) . chr(10) . chr(26) . chr(10)) |
|
| 1954 | + $this->Error('Not a PNG file: ' . $file);
|
|
| 1955 | 1955 | |
| 1956 | 1956 | // Read header chunk |
| 1957 | - $this->_readstream($f,4); |
|
| 1958 | - if($this->_readstream($f,4)!='IHDR') |
|
| 1959 | - $this->Error('Incorrect PNG file: '.$file);
|
|
| 1957 | + $this->_readstream($f, 4); |
|
| 1958 | + if ($this->_readstream($f, 4) != 'IHDR') |
|
| 1959 | + $this->Error('Incorrect PNG file: ' . $file);
|
|
| 1960 | 1960 | $w = $this->_readint($f); |
| 1961 | 1961 | $h = $this->_readint($f); |
| 1962 | - $bpc = ord($this->_readstream($f,1)); |
|
| 1963 | - if($bpc>8) |
|
| 1964 | - $this->Error('16-bit depth not supported: '.$file);
|
|
| 1965 | - $ct = ord($this->_readstream($f,1)); |
|
| 1962 | + $bpc = ord($this->_readstream($f, 1)); |
|
| 1963 | + if ($bpc > 8) |
|
| 1964 | + $this->Error('16-bit depth not supported: ' . $file);
|
|
| 1965 | + $ct = ord($this->_readstream($f, 1)); |
|
| 1966 | 1966 | $colspace = ''; |
| 1967 | - if($ct==0 || $ct==4) |
|
| 1967 | + if ($ct == 0 || $ct == 4) |
|
| 1968 | 1968 | $colspace = 'DeviceGray'; |
| 1969 | - elseif($ct==2 || $ct==6) |
|
| 1969 | + elseif ($ct == 2 || $ct == 6) |
|
| 1970 | 1970 | $colspace = 'DeviceRGB'; |
| 1971 | - elseif($ct==3) |
|
| 1971 | + elseif ($ct == 3) |
|
| 1972 | 1972 | $colspace = 'Indexed'; |
| 1973 | 1973 | else |
| 1974 | - $this->Error('Unknown color type: '.$file);
|
|
| 1975 | - if(ord($this->_readstream($f,1))!=0) |
|
| 1976 | - $this->Error('Unknown compression method: '.$file);
|
|
| 1977 | - if(ord($this->_readstream($f,1))!=0) |
|
| 1978 | - $this->Error('Unknown filter method: '.$file);
|
|
| 1979 | - if(ord($this->_readstream($f,1))!=0) |
|
| 1980 | - $this->Error('Interlacing not supported: '.$file);
|
|
| 1981 | - $this->_readstream($f,4); |
|
| 1982 | - $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w; |
|
| 1974 | + $this->Error('Unknown color type: ' . $file);
|
|
| 1975 | + if (ord($this->_readstream($f, 1)) != 0) |
|
| 1976 | + $this->Error('Unknown compression method: ' . $file);
|
|
| 1977 | + if (ord($this->_readstream($f, 1)) != 0) |
|
| 1978 | + $this->Error('Unknown filter method: ' . $file);
|
|
| 1979 | + if (ord($this->_readstream($f, 1)) != 0) |
|
| 1980 | + $this->Error('Interlacing not supported: ' . $file);
|
|
| 1981 | + $this->_readstream($f, 4); |
|
| 1982 | + $dp = '/Predictor 15 /Colors ' . ($colspace == 'DeviceRGB' ? 3 : 1) . ' /BitsPerComponent ' . $bpc . ' /Columns ' . $w; |
|
| 1983 | 1983 | |
| 1984 | 1984 | // Scan chunks looking for palette, transparency and image data |
| 1985 | 1985 | $pal = ''; |
@@ -1988,86 +1988,86 @@ discard block |
||
| 1988 | 1988 | do |
| 1989 | 1989 | {
|
| 1990 | 1990 | $n = $this->_readint($f); |
| 1991 | - $type = $this->_readstream($f,4); |
|
| 1992 | - if($type=='PLTE') |
|
| 1991 | + $type = $this->_readstream($f, 4); |
|
| 1992 | + if ($type == 'PLTE') |
|
| 1993 | 1993 | {
|
| 1994 | 1994 | // Read palette |
| 1995 | - $pal = $this->_readstream($f,$n); |
|
| 1996 | - $this->_readstream($f,4); |
|
| 1995 | + $pal = $this->_readstream($f, $n); |
|
| 1996 | + $this->_readstream($f, 4); |
|
| 1997 | 1997 | } |
| 1998 | - elseif($type=='tRNS') |
|
| 1998 | + elseif ($type == 'tRNS') |
|
| 1999 | 1999 | {
|
| 2000 | 2000 | // Read transparency info |
| 2001 | - $t = $this->_readstream($f,$n); |
|
| 2002 | - if($ct==0) |
|
| 2003 | - $trns = array(ord(substr($t,1,1))); |
|
| 2004 | - elseif($ct==2) |
|
| 2005 | - $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); |
|
| 2001 | + $t = $this->_readstream($f, $n); |
|
| 2002 | + if ($ct == 0) |
|
| 2003 | + $trns = array(ord(substr($t, 1, 1))); |
|
| 2004 | + elseif ($ct == 2) |
|
| 2005 | + $trns = array(ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1))); |
|
| 2006 | 2006 | else |
| 2007 | 2007 | {
|
| 2008 | - $pos = strpos($t,chr(0)); |
|
| 2009 | - if($pos!==false) |
|
| 2008 | + $pos = strpos($t, chr(0)); |
|
| 2009 | + if ($pos !== false) |
|
| 2010 | 2010 | $trns = array($pos); |
| 2011 | 2011 | } |
| 2012 | - $this->_readstream($f,4); |
|
| 2012 | + $this->_readstream($f, 4); |
|
| 2013 | 2013 | } |
| 2014 | - elseif($type=='IDAT') |
|
| 2014 | + elseif ($type == 'IDAT') |
|
| 2015 | 2015 | {
|
| 2016 | 2016 | // Read image data block |
| 2017 | - $data .= $this->_readstream($f,$n); |
|
| 2018 | - $this->_readstream($f,4); |
|
| 2017 | + $data .= $this->_readstream($f, $n); |
|
| 2018 | + $this->_readstream($f, 4); |
|
| 2019 | 2019 | } |
| 2020 | - elseif($type=='IEND') |
|
| 2020 | + elseif ($type == 'IEND') |
|
| 2021 | 2021 | break; |
| 2022 | 2022 | else |
| 2023 | - $this->_readstream($f,$n+4); |
|
| 2023 | + $this->_readstream($f, $n + 4); |
|
| 2024 | 2024 | } |
| 2025 | - while($n); |
|
| 2025 | + while ($n); |
|
| 2026 | 2026 | |
| 2027 | - if($colspace=='Indexed' && empty($pal)) |
|
| 2028 | - $this->Error('Missing palette in '.$file);
|
|
| 2027 | + if ($colspace == 'Indexed' && empty($pal)) |
|
| 2028 | + $this->Error('Missing palette in ' . $file);
|
|
| 2029 | 2029 | $info = array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns);
|
| 2030 | - if($ct>=4) |
|
| 2030 | + if ($ct >= 4) |
|
| 2031 | 2031 | {
|
| 2032 | 2032 | // Extract alpha channel |
| 2033 | - if(!function_exists('gzuncompress'))
|
|
| 2034 | - $this->Error('Zlib not available, can\'t handle alpha channel: '.$file);
|
|
| 2033 | + if (!function_exists('gzuncompress'))
|
|
| 2034 | + $this->Error('Zlib not available, can\'t handle alpha channel: ' . $file);
|
|
| 2035 | 2035 | $data = gzuncompress($data); |
| 2036 | 2036 | $color = ''; |
| 2037 | 2037 | $alpha = ''; |
| 2038 | - if($ct==4) |
|
| 2038 | + if ($ct == 4) |
|
| 2039 | 2039 | {
|
| 2040 | 2040 | // Gray image |
| 2041 | - $len = 2*$w; |
|
| 2042 | - for($i=0;$i<$h;$i++) |
|
| 2041 | + $len = 2 * $w; |
|
| 2042 | + for ($i = 0; $i < $h; $i++) |
|
| 2043 | 2043 | {
|
| 2044 | - $pos = (1+$len)*$i; |
|
| 2044 | + $pos = (1 + $len) * $i; |
|
| 2045 | 2045 | $color .= $data[$pos]; |
| 2046 | 2046 | $alpha .= $data[$pos]; |
| 2047 | - $line = substr($data,$pos+1,$len); |
|
| 2048 | - $color .= preg_replace('/(.)./s','$1',$line);
|
|
| 2049 | - $alpha .= preg_replace('/.(.)/s','$1',$line);
|
|
| 2047 | + $line = substr($data, $pos + 1, $len); |
|
| 2048 | + $color .= preg_replace('/(.)./s', '$1', $line);
|
|
| 2049 | + $alpha .= preg_replace('/.(.)/s', '$1', $line);
|
|
| 2050 | 2050 | } |
| 2051 | 2051 | } |
| 2052 | 2052 | else |
| 2053 | 2053 | {
|
| 2054 | 2054 | // RGB image |
| 2055 | - $len = 4*$w; |
|
| 2056 | - for($i=0;$i<$h;$i++) |
|
| 2055 | + $len = 4 * $w; |
|
| 2056 | + for ($i = 0; $i < $h; $i++) |
|
| 2057 | 2057 | {
|
| 2058 | - $pos = (1+$len)*$i; |
|
| 2058 | + $pos = (1 + $len) * $i; |
|
| 2059 | 2059 | $color .= $data[$pos]; |
| 2060 | 2060 | $alpha .= $data[$pos]; |
| 2061 | - $line = substr($data,$pos+1,$len); |
|
| 2062 | - $color .= preg_replace('/(.{3})./s','$1',$line);
|
|
| 2063 | - $alpha .= preg_replace('/.{3}(.)/s','$1',$line);
|
|
| 2061 | + $line = substr($data, $pos + 1, $len); |
|
| 2062 | + $color .= preg_replace('/(.{3})./s', '$1', $line);
|
|
| 2063 | + $alpha .= preg_replace('/.{3}(.)/s', '$1', $line);
|
|
| 2064 | 2064 | } |
| 2065 | 2065 | } |
| 2066 | 2066 | unset($data); |
| 2067 | 2067 | $data = gzcompress($color); |
| 2068 | 2068 | $info['smask'] = gzcompress($alpha); |
| 2069 | 2069 | $this->WithAlpha = true; |
| 2070 | - if($this->PDFVersion<'1.4') |
|
| 2070 | + if ($this->PDFVersion < '1.4') |
|
| 2071 | 2071 | $this->PDFVersion = '1.4'; |
| 2072 | 2072 | } |
| 2073 | 2073 | $info['data'] = $data; |
@@ -2084,15 +2084,15 @@ discard block |
||
| 2084 | 2084 | {
|
| 2085 | 2085 | // Read n bytes from stream |
| 2086 | 2086 | $res = ''; |
| 2087 | - while($n>0 && !feof($f)) |
|
| 2087 | + while ($n > 0 && !feof($f)) |
|
| 2088 | 2088 | {
|
| 2089 | - $s = fread($f,$n); |
|
| 2090 | - if($s===false) |
|
| 2089 | + $s = fread($f, $n); |
|
| 2090 | + if ($s === false) |
|
| 2091 | 2091 | $this->Error('Error while reading stream');
|
| 2092 | 2092 | $n -= strlen($s); |
| 2093 | 2093 | $res .= $s; |
| 2094 | 2094 | } |
| 2095 | - if($n>0) |
|
| 2095 | + if ($n > 0) |
|
| 2096 | 2096 | $this->Error('Unexpected end of stream');
|
| 2097 | 2097 | return $res; |
| 2098 | 2098 | } |
@@ -2105,7 +2105,7 @@ discard block |
||
| 2105 | 2105 | protected function _readint($f) : int |
| 2106 | 2106 | {
|
| 2107 | 2107 | // Read a 4-byte integer from stream |
| 2108 | - $a = unpack('Ni',$this->_readstream($f,4));
|
|
| 2108 | + $a = unpack('Ni', $this->_readstream($f, 4));
|
|
| 2109 | 2109 | return $a['i']; |
| 2110 | 2110 | } |
| 2111 | 2111 | |
@@ -2150,13 +2150,13 @@ discard block |
||
| 2150 | 2150 | protected function _out(string $s) : void |
| 2151 | 2151 | {
|
| 2152 | 2152 | // Add a line to the document |
| 2153 | - if($this->state==2) |
|
| 2154 | - $this->pages[$this->page] .= $s."\n"; |
|
| 2155 | - elseif($this->state==1) |
|
| 2153 | + if ($this->state == 2) |
|
| 2154 | + $this->pages[$this->page] .= $s . "\n"; |
|
| 2155 | + elseif ($this->state == 1) |
|
| 2156 | 2156 | $this->_put($s); |
| 2157 | - elseif($this->state==0) |
|
| 2157 | + elseif ($this->state == 0) |
|
| 2158 | 2158 | $this->Error('No page has been added yet');
|
| 2159 | - elseif($this->state==3) |
|
| 2159 | + elseif ($this->state == 3) |
|
| 2160 | 2160 | $this->Error('The document is closed');
|
| 2161 | 2161 | } |
| 2162 | 2162 | |
@@ -2166,7 +2166,7 @@ discard block |
||
| 2166 | 2166 | */ |
| 2167 | 2167 | protected function _put(string $s) : void |
| 2168 | 2168 | {
|
| 2169 | - $this->buffer .= $s."\n"; |
|
| 2169 | + $this->buffer .= $s . "\n"; |
|
| 2170 | 2170 | } |
| 2171 | 2171 | |
| 2172 | 2172 | /** |
@@ -2182,13 +2182,13 @@ discard block |
||
| 2182 | 2182 | * Begin a new object. |
| 2183 | 2183 | * @param int $n |
| 2184 | 2184 | */ |
| 2185 | - protected function _newobj(?int $n=null) : void |
|
| 2185 | + protected function _newobj(?int $n = null) : void |
|
| 2186 | 2186 | {
|
| 2187 | 2187 | // Begin a new object |
| 2188 | - if($n===null) |
|
| 2188 | + if ($n === null) |
|
| 2189 | 2189 | $n = ++$this->n; |
| 2190 | 2190 | $this->offsets[$n] = $this->_getoffset(); |
| 2191 | - $this->_put($n.' 0 obj'); |
|
| 2191 | + $this->_put($n . ' 0 obj'); |
|
| 2192 | 2192 | } |
| 2193 | 2193 | |
| 2194 | 2194 | /** |
@@ -2208,16 +2208,16 @@ discard block |
||
| 2208 | 2208 | */ |
| 2209 | 2209 | protected function _putstreamobject(string $data) : void |
| 2210 | 2210 | {
|
| 2211 | - if($this->compress) |
|
| 2211 | + if ($this->compress) |
|
| 2212 | 2212 | {
|
| 2213 | 2213 | $entries = '/Filter /FlateDecode '; |
| 2214 | 2214 | $data = gzcompress($data); |
| 2215 | 2215 | } |
| 2216 | 2216 | else |
| 2217 | 2217 | $entries = ''; |
| 2218 | - $entries .= '/Length '.strlen($data); |
|
| 2218 | + $entries .= '/Length ' . strlen($data); |
|
| 2219 | 2219 | $this->_newobj(); |
| 2220 | - $this->_put('<<'.$entries.'>>');
|
|
| 2220 | + $this->_put('<<' . $entries . '>>');
|
|
| 2221 | 2221 | $this->_putstream($data); |
| 2222 | 2222 | $this->_put('endobj');
|
| 2223 | 2223 | } |
@@ -2231,39 +2231,39 @@ discard block |
||
| 2231 | 2231 | $this->_newobj(); |
| 2232 | 2232 | $this->_put('<</Type /Page');
|
| 2233 | 2233 | $this->_put('/Parent 1 0 R');
|
| 2234 | - if(isset($this->PageInfo[$n]['size'])) |
|
| 2235 | - $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo[$n]['size'][0],$this->PageInfo[$n]['size'][1]));
|
|
| 2236 | - if(isset($this->PageInfo[$n]['rotation'])) |
|
| 2237 | - $this->_put('/Rotate '.$this->PageInfo[$n]['rotation']);
|
|
| 2234 | + if (isset($this->PageInfo[$n]['size'])) |
|
| 2235 | + $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]', $this->PageInfo[$n]['size'][0], $this->PageInfo[$n]['size'][1]));
|
|
| 2236 | + if (isset($this->PageInfo[$n]['rotation'])) |
|
| 2237 | + $this->_put('/Rotate ' . $this->PageInfo[$n]['rotation']);
|
|
| 2238 | 2238 | $this->_put('/Resources 2 0 R');
|
| 2239 | - if(isset($this->PageLinks[$n])) |
|
| 2239 | + if (isset($this->PageLinks[$n])) |
|
| 2240 | 2240 | {
|
| 2241 | 2241 | // Links |
| 2242 | 2242 | $annots = '/Annots ['; |
| 2243 | - foreach($this->PageLinks[$n] as $pl) |
|
| 2243 | + foreach ($this->PageLinks[$n] as $pl) |
|
| 2244 | 2244 | {
|
| 2245 | - $rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
|
|
| 2246 | - $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
|
| 2247 | - if(is_string($pl[4])) |
|
| 2248 | - $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
|
| 2245 | + $rect = sprintf('%.2F %.2F %.2F %.2F', $pl[0], $pl[1], $pl[0] + $pl[2], $pl[1] - $pl[3]);
|
|
| 2246 | + $annots .= '<</Type /Annot /Subtype /Link /Rect [' . $rect . '] /Border [0 0 0] '; |
|
| 2247 | + if (is_string($pl[4])) |
|
| 2248 | + $annots .= '/A <</S /URI /URI ' . $this->_textstring($pl[4]) . '>>>>'; |
|
| 2249 | 2249 | else |
| 2250 | 2250 | {
|
| 2251 | 2251 | $l = $this->links[$pl[4]]; |
| 2252 | - if(isset($this->PageInfo[$l[0]]['size'])) |
|
| 2252 | + if (isset($this->PageInfo[$l[0]]['size'])) |
|
| 2253 | 2253 | $h = $this->PageInfo[$l[0]]['size'][1]; |
| 2254 | 2254 | else |
| 2255 | - $h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k; |
|
| 2256 | - $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[$l[0]]['n'],$h-$l[1]*$this->k);
|
|
| 2255 | + $h = ($this->DefOrientation == 'P') ? $this->DefPageSize[1] * $this->k : $this->DefPageSize[0] * $this->k; |
|
| 2256 | + $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>', $this->PageInfo[$l[0]]['n'], $h - $l[1] * $this->k);
|
|
| 2257 | 2257 | } |
| 2258 | 2258 | } |
| 2259 | - $this->_put($annots.']'); |
|
| 2259 | + $this->_put($annots . ']'); |
|
| 2260 | 2260 | } |
| 2261 | - if($this->WithAlpha) |
|
| 2261 | + if ($this->WithAlpha) |
|
| 2262 | 2262 | $this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>');
|
| 2263 | - $this->_put('/Contents '.($this->n+1).' 0 R>>');
|
|
| 2263 | + $this->_put('/Contents ' . ($this->n + 1) . ' 0 R>>');
|
|
| 2264 | 2264 | $this->_put('endobj');
|
| 2265 | 2265 | // Page content |
| 2266 | - if(!empty($this->AliasNbPages)) |
|
| 2266 | + if (!empty($this->AliasNbPages)) |
|
| 2267 | 2267 | $this->pages[$n] = str_replace($this->AliasNbPages, strval($this->page), $this->pages[$n]); |
| 2268 | 2268 | $this->_putstreamobject($this->pages[$n]); |
| 2269 | 2269 | } |
@@ -2274,19 +2274,19 @@ discard block |
||
| 2274 | 2274 | protected function _putpages() : void |
| 2275 | 2275 | {
|
| 2276 | 2276 | $nb = $this->page; |
| 2277 | - for($n=1;$n<=$nb;$n++) |
|
| 2278 | - $this->PageInfo[$n]['n'] = $this->n+1+2*($n-1); |
|
| 2279 | - for($n=1;$n<=$nb;$n++) |
|
| 2277 | + for ($n = 1; $n <= $nb; $n++) |
|
| 2278 | + $this->PageInfo[$n]['n'] = $this->n + 1 + 2 * ($n - 1); |
|
| 2279 | + for ($n = 1; $n <= $nb; $n++) |
|
| 2280 | 2280 | $this->_putpage($n); |
| 2281 | 2281 | // Pages root |
| 2282 | 2282 | $this->_newobj(1); |
| 2283 | 2283 | $this->_put('<</Type /Pages');
|
| 2284 | 2284 | $kids = '/Kids ['; |
| 2285 | - for($n=1;$n<=$nb;$n++) |
|
| 2286 | - $kids .= $this->PageInfo[$n]['n'].' 0 R '; |
|
| 2287 | - $this->_put($kids.']'); |
|
| 2288 | - $this->_put('/Count '.$nb);
|
|
| 2289 | - if($this->DefOrientation=='P') |
|
| 2285 | + for ($n = 1; $n <= $nb; $n++) |
|
| 2286 | + $kids .= $this->PageInfo[$n]['n'] . ' 0 R '; |
|
| 2287 | + $this->_put($kids . ']'); |
|
| 2288 | + $this->_put('/Count ' . $nb);
|
|
| 2289 | + if ($this->DefOrientation == 'P') |
|
| 2290 | 2290 | {
|
| 2291 | 2291 | $w = $this->DefPageSize[0]; |
| 2292 | 2292 | $h = $this->DefPageSize[1]; |
@@ -2296,7 +2296,7 @@ discard block |
||
| 2296 | 2296 | $w = $this->DefPageSize[1]; |
| 2297 | 2297 | $h = $this->DefPageSize[0]; |
| 2298 | 2298 | } |
| 2299 | - $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$w*$this->k,$h*$this->k));
|
|
| 2299 | + $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]', $w * $this->k, $h * $this->k));
|
|
| 2300 | 2300 | $this->_put('>>');
|
| 2301 | 2301 | $this->_put('endobj');
|
| 2302 | 2302 | } |
@@ -2324,7 +2324,7 @@ discard block |
||
| 2324 | 2324 | } |
| 2325 | 2325 | $this->_put('/Length1 ' . $info['length1']);
|
| 2326 | 2326 | if (isset($info['length2'])) {
|
| 2327 | - $this->_put('/Length2 '.$info['length2'].' /Length3 0');
|
|
| 2327 | + $this->_put('/Length2 ' . $info['length2'] . ' /Length3 0');
|
|
| 2328 | 2328 | } |
| 2329 | 2329 | $this->_put('>>');
|
| 2330 | 2330 | $this->_putstream($font); |
@@ -2361,7 +2361,7 @@ discard block |
||
| 2361 | 2361 | if ($font['subsetted']) {
|
| 2362 | 2362 | $name = 'AAAAAA+' . $name; |
| 2363 | 2363 | } |
| 2364 | - if ($type=='Core') {
|
|
| 2364 | + if ($type == 'Core') {
|
|
| 2365 | 2365 | // Core font |
| 2366 | 2366 | $this->_newobj(); |
| 2367 | 2367 | $this->_put('<</Type /Font');
|
@@ -2435,16 +2435,16 @@ discard block |
||
| 2435 | 2435 | $nbr = 0; |
| 2436 | 2436 | $chars = ''; |
| 2437 | 2437 | $nbc = 0; |
| 2438 | - foreach($uv as $c=>$v) |
|
| 2438 | + foreach ($uv as $c=>$v) |
|
| 2439 | 2439 | {
|
| 2440 | - if(is_array($v)) |
|
| 2440 | + if (is_array($v)) |
|
| 2441 | 2441 | {
|
| 2442 | - $ranges .= sprintf("<%02X> <%02X> <%04X>\n",$c,$c+$v[1]-1,$v[0]);
|
|
| 2442 | + $ranges .= sprintf("<%02X> <%02X> <%04X>\n", $c, $c + $v[1] - 1, $v[0]);
|
|
| 2443 | 2443 | $nbr++; |
| 2444 | 2444 | } |
| 2445 | 2445 | else |
| 2446 | 2446 | {
|
| 2447 | - $chars .= sprintf("<%02X> <%04X>\n",$c,$v);
|
|
| 2447 | + $chars .= sprintf("<%02X> <%04X>\n", $c, $v);
|
|
| 2448 | 2448 | $nbc++; |
| 2449 | 2449 | } |
| 2450 | 2450 | } |
@@ -2461,13 +2461,13 @@ discard block |
||
| 2461 | 2461 | $s .= "1 begincodespacerange\n"; |
| 2462 | 2462 | $s .= "<00> <FF>\n"; |
| 2463 | 2463 | $s .= "endcodespacerange\n"; |
| 2464 | - if($nbr>0) |
|
| 2464 | + if ($nbr > 0) |
|
| 2465 | 2465 | {
|
| 2466 | 2466 | $s .= "$nbr beginbfrange\n"; |
| 2467 | 2467 | $s .= $ranges; |
| 2468 | 2468 | $s .= "endbfrange\n"; |
| 2469 | 2469 | } |
| 2470 | - if($nbc>0) |
|
| 2470 | + if ($nbc > 0) |
|
| 2471 | 2471 | {
|
| 2472 | 2472 | $s .= "$nbc beginbfchar\n"; |
| 2473 | 2473 | $s .= $chars; |
@@ -2485,7 +2485,7 @@ discard block |
||
| 2485 | 2485 | */ |
| 2486 | 2486 | protected function _putimages() : void |
| 2487 | 2487 | {
|
| 2488 | - foreach(array_keys($this->images) as $file) |
|
| 2488 | + foreach (array_keys($this->images) as $file) |
|
| 2489 | 2489 | {
|
| 2490 | 2490 | $this->_putimage($this->images[$file]); |
| 2491 | 2491 | unset($this->images[$file]['data']); |
@@ -2509,7 +2509,7 @@ discard block |
||
| 2509 | 2509 | $this->_put('/ColorSpace [/Indexed /DeviceRGB ' . (strlen($info['pal']) / 3 - 1) . ' ' . ($this->n + 1) . ' 0 R]');
|
| 2510 | 2510 | } else {
|
| 2511 | 2511 | $this->_put('/ColorSpace /' . $info['cs']);
|
| 2512 | - if($info['cs']=='DeviceCMYK') {
|
|
| 2512 | + if ($info['cs'] == 'DeviceCMYK') {
|
|
| 2513 | 2513 | $this->_put('/Decode [1 0 1 0 1 0 1 0]');
|
| 2514 | 2514 | } |
| 2515 | 2515 | } |
@@ -2520,7 +2520,7 @@ discard block |
||
| 2520 | 2520 | if (isset($info['dp'])) {
|
| 2521 | 2521 | $this->_put('/DecodeParms <<' . $info['dp'] . '>>');
|
| 2522 | 2522 | } |
| 2523 | - if (isset($info['trns']) && is_array($info['trns'])) {
|
|
| 2523 | + if (isset($info['trns']) && is_array($info['trns'])) {
|
|
| 2524 | 2524 | $trns = ''; |
| 2525 | 2525 | $cnt = count($info['trns']); |
| 2526 | 2526 | for ($i = 0; $i < $cnt; $i++) {
|
@@ -2529,7 +2529,7 @@ discard block |
||
| 2529 | 2529 | $this->_put('/Mask [' . $trns . ']');
|
| 2530 | 2530 | } |
| 2531 | 2531 | if (isset($info['smask'])) {
|
| 2532 | - $this->_put('/SMask ' . ($this->n+1) . ' 0 R');
|
|
| 2532 | + $this->_put('/SMask ' . ($this->n + 1) . ' 0 R');
|
|
| 2533 | 2533 | } |
| 2534 | 2534 | $this->_put('/Length ' . strlen($info['data']) . '>>');
|
| 2535 | 2535 | $this->_putstream($info['data']); |
@@ -2600,7 +2600,7 @@ discard block |
||
| 2600 | 2600 | */ |
| 2601 | 2601 | protected function _putinfo() : void |
| 2602 | 2602 | {
|
| 2603 | - $this->metadata['Producer'] = 'FPDF '.FPDF_VERSION; |
|
| 2603 | + $this->metadata['Producer'] = 'FPDF ' . FPDF_VERSION; |
|
| 2604 | 2604 | $this->metadata['CreationDate'] = 'D:' . @date('YmdHis');
|
| 2605 | 2605 | foreach ($this->metadata as $key=>$value) {
|
| 2606 | 2606 | $this->_put('/' . $key . ' ' . $this->_textstring($value));
|
@@ -2615,20 +2615,20 @@ discard block |
||
| 2615 | 2615 | $n = $this->PageInfo[1]['n']; |
| 2616 | 2616 | $this->_put('/Type /Catalog');
|
| 2617 | 2617 | $this->_put('/Pages 1 0 R');
|
| 2618 | - if($this->ZoomMode=='fullpage') {
|
|
| 2618 | + if ($this->ZoomMode == 'fullpage') {
|
|
| 2619 | 2619 | $this->_put('/OpenAction [' . $n . ' 0 R /Fit]');
|
| 2620 | - } elseif ($this->ZoomMode=='fullwidth') {
|
|
| 2620 | + } elseif ($this->ZoomMode == 'fullwidth') {
|
|
| 2621 | 2621 | $this->_put('/OpenAction [' . $n . ' 0 R /FitH null]');
|
| 2622 | - } elseif($this->ZoomMode=='real') {
|
|
| 2622 | + } elseif ($this->ZoomMode == 'real') {
|
|
| 2623 | 2623 | $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null 1]');
|
| 2624 | - } elseif(!is_string($this->ZoomMode)) {
|
|
| 2624 | + } elseif (!is_string($this->ZoomMode)) {
|
|
| 2625 | 2625 | $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null ' . sprintf('%.2F', $this->ZoomMode / 100) . ']');
|
| 2626 | 2626 | } |
| 2627 | - if($this->LayoutMode=='single') {
|
|
| 2627 | + if ($this->LayoutMode == 'single') {
|
|
| 2628 | 2628 | $this->_put('/PageLayout /SinglePage');
|
| 2629 | - } elseif($this->LayoutMode=='continuous') {
|
|
| 2629 | + } elseif ($this->LayoutMode == 'continuous') {
|
|
| 2630 | 2630 | $this->_put('/PageLayout /OneColumn');
|
| 2631 | - } elseif($this->LayoutMode=='two') {
|
|
| 2631 | + } elseif ($this->LayoutMode == 'two') {
|
|
| 2632 | 2632 | $this->_put('/PageLayout /TwoColumnLeft');
|
| 2633 | 2633 | } |
| 2634 | 2634 | } |
@@ -255,8 +255,9 @@ discard block |
||
| 255 | 255 | // Set left, top and right margins |
| 256 | 256 | $this->lMargin = $left; |
| 257 | 257 | $this->tMargin = $top; |
| 258 | - if($right===null) |
|
| 259 | - $right = $left; |
|
| 258 | + if($right===null) {
|
|
| 259 | + $right = $left; |
|
| 260 | + } |
|
| 260 | 261 | $this->rMargin = $right; |
| 261 | 262 | } |
| 262 | 263 | |
@@ -270,8 +271,9 @@ discard block |
||
| 270 | 271 | {
|
| 271 | 272 | // Set left margin |
| 272 | 273 | $this->lMargin = $margin; |
| 273 | - if($this->page>0 && $this->x<$margin) |
|
| 274 | - $this->x = $margin; |
|
| 274 | + if($this->page>0 && $this->x<$margin) {
|
|
| 275 | + $this->x = $margin; |
|
| 276 | + } |
|
| 275 | 277 | } |
| 276 | 278 | |
| 277 | 279 | /** |
@@ -343,14 +345,16 @@ discard block |
||
| 343 | 345 | public function SetDisplayMode($zoom, string $layout='default') : void |
| 344 | 346 | {
|
| 345 | 347 | // Set display mode in viewer |
| 346 | - if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) |
|
| 347 | - $this->ZoomMode = $zoom; |
|
| 348 | - else |
|
| 349 | - $this->Error('Incorrect zoom display mode: '.$zoom);
|
|
| 350 | - if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') |
|
| 351 | - $this->LayoutMode = $layout; |
|
| 352 | - else |
|
| 353 | - $this->Error('Incorrect layout display mode: '.$layout);
|
|
| 348 | + if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) {
|
|
| 349 | + $this->ZoomMode = $zoom; |
|
| 350 | + } else {
|
|
| 351 | + $this->Error('Incorrect zoom display mode: '.$zoom);
|
|
| 352 | + } |
|
| 353 | + if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') {
|
|
| 354 | + $this->LayoutMode = $layout; |
|
| 355 | + } else {
|
|
| 356 | + $this->Error('Incorrect layout display mode: '.$layout);
|
|
| 357 | + } |
|
| 354 | 358 | } |
| 355 | 359 | |
| 356 | 360 | /** |
@@ -365,10 +369,11 @@ discard block |
||
| 365 | 369 | public function SetCompression(bool $compress) : void |
| 366 | 370 | {
|
| 367 | 371 | // Set page compression |
| 368 | - if(function_exists('gzcompress'))
|
|
| 369 | - $this->compress = $compress; |
|
| 370 | - else |
|
| 371 | - $this->compress = false; |
|
| 372 | + if(function_exists('gzcompress')) {
|
|
| 373 | + $this->compress = $compress; |
|
| 374 | + } else {
|
|
| 375 | + $this->compress = false; |
|
| 376 | + } |
|
| 372 | 377 | } |
| 373 | 378 | |
| 374 | 379 | /** |
@@ -459,10 +464,12 @@ discard block |
||
| 459 | 464 | public function Close() : void |
| 460 | 465 | {
|
| 461 | 466 | // Terminate document |
| 462 | - if($this->state==3) |
|
| 463 | - return; |
|
| 464 | - if($this->page==0) |
|
| 465 | - $this->addPage(); |
|
| 467 | + if($this->state==3) {
|
|
| 468 | + return; |
|
| 469 | + } |
|
| 470 | + if($this->page==0) {
|
|
| 471 | + $this->addPage(); |
|
| 472 | + } |
|
| 466 | 473 | // Page footer |
| 467 | 474 | $this->InFooter = true; |
| 468 | 475 | $this->Footer(); |
@@ -678,8 +685,9 @@ discard block |
||
| 678 | 685 | $cw = &$this->CurrentFont['cw']; |
| 679 | 686 | $w = 0; |
| 680 | 687 | $l = strlen($s); |
| 681 | - for($i=0;$i<$l;$i++) |
|
| 682 | - $w += $cw[$s[$i]]; |
|
| 688 | + for($i=0;$i<$l;$i++) {
|
|
| 689 | + $w += $cw[$s[$i]]; |
|
| 690 | + } |
|
| 683 | 691 | return $w*$this->FontSize/1000; |
| 684 | 692 | } |
| 685 | 693 | |
@@ -693,8 +701,9 @@ discard block |
||
| 693 | 701 | {
|
| 694 | 702 | // Set line width |
| 695 | 703 | $this->LineWidth = $width; |
| 696 | - if($this->page>0) |
|
| 697 | - $this->_out(sprintf('%.2F w',$width*$this->k));
|
|
| 704 | + if($this->page>0) {
|
|
| 705 | + $this->_out(sprintf('%.2F w',$width*$this->k));
|
|
| 706 | + } |
|
| 698 | 707 | } |
| 699 | 708 | |
| 700 | 709 | /** |
@@ -730,12 +739,13 @@ discard block |
||
| 730 | 739 | public function Rect(float $x, float $y, float $w, float $h, string $style='') : void |
| 731 | 740 | {
|
| 732 | 741 | // Draw a rectangle |
| 733 | - if($style=='F') |
|
| 734 | - $op = 'f'; |
|
| 735 | - elseif($style=='FD' || $style=='DF') |
|
| 736 | - $op = 'B'; |
|
| 737 | - else |
|
| 738 | - $op = 'S'; |
|
| 742 | + if($style=='F') {
|
|
| 743 | + $op = 'f'; |
|
| 744 | + } elseif($style=='FD' || $style=='DF') {
|
|
| 745 | + $op = 'B'; |
|
| 746 | + } else {
|
|
| 747 | + $op = 'S'; |
|
| 748 | + } |
|
| 739 | 749 | $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
|
| 740 | 750 | } |
| 741 | 751 | |
@@ -760,23 +770,27 @@ discard block |
||
| 760 | 770 | {
|
| 761 | 771 | // Add a TrueType, OpenType or Type1 font |
| 762 | 772 | $family = strtolower($family); |
| 763 | - if($file=='') |
|
| 764 | - $file = str_replace(' ','',$family).strtolower($style).'.php';
|
|
| 773 | + if($file=='') {
|
|
| 774 | + $file = str_replace(' ','',$family).strtolower($style).'.php';
|
|
| 775 | + } |
|
| 765 | 776 | $style = strtoupper($style); |
| 766 | - if($style=='IB') |
|
| 767 | - $style = 'BI'; |
|
| 777 | + if($style=='IB') {
|
|
| 778 | + $style = 'BI'; |
|
| 779 | + } |
|
| 768 | 780 | $fontkey = $family.$style; |
| 769 | - if(isset($this->fonts[$fontkey])) |
|
| 770 | - return; |
|
| 781 | + if(isset($this->fonts[$fontkey])) {
|
|
| 782 | + return; |
|
| 783 | + } |
|
| 771 | 784 | $info = $this->_loadfont($file); |
| 772 | 785 | $info['i'] = count($this->fonts)+1; |
| 773 | 786 | if(!empty($info['file'])) |
| 774 | 787 | {
|
| 775 | 788 | // Embedded font |
| 776 | - if($info['type']=='TrueType') |
|
| 777 | - $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']);
|
|
| 778 | - else |
|
| 779 | - $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']);
|
|
| 789 | + if($info['type']=='TrueType') {
|
|
| 790 | + $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']);
|
|
| 791 | + } else {
|
|
| 792 | + $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']);
|
|
| 793 | + } |
|
| 780 | 794 | } |
| 781 | 795 | $this->fonts[$fontkey] = $info; |
| 782 | 796 | } |
@@ -819,42 +833,49 @@ discard block |
||
| 819 | 833 | public function SetFont(string $family, string $style='', float $size=0) : void |
| 820 | 834 | {
|
| 821 | 835 | // Select a font; size given in points |
| 822 | - if($family=='') |
|
| 823 | - $family = $this->FontFamily; |
|
| 824 | - else |
|
| 825 | - $family = strtolower($family); |
|
| 836 | + if($family=='') {
|
|
| 837 | + $family = $this->FontFamily; |
|
| 838 | + } else {
|
|
| 839 | + $family = strtolower($family); |
|
| 840 | + } |
|
| 826 | 841 | $style = strtoupper($style); |
| 827 | 842 | if(strpos($style,'U')!==false) |
| 828 | 843 | {
|
| 829 | 844 | $this->underline = true; |
| 830 | 845 | $style = str_replace('U','',$style);
|
| 846 | + } else {
|
|
| 847 | + $this->underline = false; |
|
| 848 | + } |
|
| 849 | + if($style=='IB') {
|
|
| 850 | + $style = 'BI'; |
|
| 851 | + } |
|
| 852 | + if($size==0) {
|
|
| 853 | + $size = $this->FontSizePt; |
|
| 831 | 854 | } |
| 832 | - else |
|
| 833 | - $this->underline = false; |
|
| 834 | - if($style=='IB') |
|
| 835 | - $style = 'BI'; |
|
| 836 | - if($size==0) |
|
| 837 | - $size = $this->FontSizePt; |
|
| 838 | 855 | // Test if font is already selected |
| 839 | - if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) |
|
| 840 | - return; |
|
| 856 | + if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) {
|
|
| 857 | + return; |
|
| 858 | + } |
|
| 841 | 859 | // Test if font is already loaded |
| 842 | 860 | $fontkey = $family.$style; |
| 843 | 861 | if(!isset($this->fonts[$fontkey])) |
| 844 | 862 | {
|
| 845 | 863 | // Test if one of the core fonts |
| 846 | - if($family=='arial') |
|
| 847 | - $family = 'helvetica'; |
|
| 864 | + if($family=='arial') {
|
|
| 865 | + $family = 'helvetica'; |
|
| 866 | + } |
|
| 848 | 867 | if(in_array($family,$this->CoreFonts)) |
| 849 | 868 | {
|
| 850 | - if($family=='symbol' || $family=='zapfdingbats') |
|
| 851 | - $style = ''; |
|
| 869 | + if($family=='symbol' || $family=='zapfdingbats') {
|
|
| 870 | + $style = ''; |
|
| 871 | + } |
|
| 852 | 872 | $fontkey = $family.$style; |
| 853 | - if(!isset($this->fonts[$fontkey])) |
|
| 854 | - $this->addFont($family,$style); |
|
| 873 | + if(!isset($this->fonts[$fontkey])) {
|
|
| 874 | + $this->addFont($family,$style); |
|
| 875 | + } |
|
| 876 | + } else {
|
|
| 877 | + $this->Error('Undefined font: '.$family.' '.$style);
|
|
| 855 | 878 | } |
| 856 | - else |
|
| 857 | - $this->Error('Undefined font: '.$family.' '.$style);
|
|
| 858 | 879 | } |
| 859 | 880 | // Select it |
| 860 | 881 | $this->FontFamily = $family; |
@@ -862,8 +883,9 @@ discard block |
||
| 862 | 883 | $this->FontSizePt = $size; |
| 863 | 884 | $this->FontSize = $size/$this->k; |
| 864 | 885 | $this->CurrentFont = &$this->fonts[$fontkey]; |
| 865 | - if($this->page>0) |
|
| 866 | - $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
|
|
| 886 | + if($this->page>0) {
|
|
| 887 | + $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
|
|
| 888 | + } |
|
| 867 | 889 | } |
| 868 | 890 | |
| 869 | 891 | /** |
@@ -873,12 +895,14 @@ discard block |
||
| 873 | 895 | public function SetFontSize(float $size) : void |
| 874 | 896 | {
|
| 875 | 897 | // Set font size in points |
| 876 | - if($this->FontSizePt==$size) |
|
| 877 | - return; |
|
| 898 | + if($this->FontSizePt==$size) {
|
|
| 899 | + return; |
|
| 900 | + } |
|
| 878 | 901 | $this->FontSizePt = $size; |
| 879 | 902 | $this->FontSize = $size/$this->k; |
| 880 | - if($this->page>0) |
|
| 881 | - $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
|
|
| 903 | + if($this->page>0) {
|
|
| 904 | + $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
|
|
| 905 | + } |
|
| 882 | 906 | } |
| 883 | 907 | |
| 884 | 908 | /** |
@@ -905,10 +929,12 @@ discard block |
||
| 905 | 929 | public function SetLink(int $link, float $y=0, int $page=-1) : void |
| 906 | 930 | {
|
| 907 | 931 | // Set destination of internal link |
| 908 | - if($y==-1) |
|
| 909 | - $y = $this->y; |
|
| 910 | - if($page==-1) |
|
| 911 | - $page = $this->page; |
|
| 932 | + if($y==-1) {
|
|
| 933 | + $y = $this->y; |
|
| 934 | + } |
|
| 935 | + if($page==-1) {
|
|
| 936 | + $page = $this->page; |
|
| 937 | + } |
|
| 912 | 938 | $this->links[$link] = array($page, $y); |
| 913 | 939 | } |
| 914 | 940 | |
@@ -942,13 +968,16 @@ discard block |
||
| 942 | 968 | public function Text(float $x, float $y, string $txt) : void |
| 943 | 969 | {
|
| 944 | 970 | // Output a string |
| 945 | - if(!isset($this->CurrentFont)) |
|
| 946 | - $this->Error('No font has been set');
|
|
| 971 | + if(!isset($this->CurrentFont)) {
|
|
| 972 | + $this->Error('No font has been set');
|
|
| 973 | + } |
|
| 947 | 974 | $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
|
| 948 | - if($this->underline && $txt!='') |
|
| 949 | - $s .= ' '.$this->_dounderline($x,$y,$txt); |
|
| 950 | - if($this->ColorFlag) |
|
| 951 | - $s = 'q '.$this->TextColor.' '.$s.' Q'; |
|
| 975 | + if($this->underline && $txt!='') {
|
|
| 976 | + $s .= ' '.$this->_dounderline($x,$y,$txt); |
|
| 977 | + } |
|
| 978 | + if($this->ColorFlag) {
|
|
| 979 | + $s = 'q '.$this->TextColor.' '.$s.' Q'; |
|
| 980 | + } |
|
| 952 | 981 | $this->_out($s); |
| 953 | 982 | } |
| 954 | 983 | |
@@ -1028,62 +1057,76 @@ discard block |
||
| 1028 | 1057 | $this->_out(sprintf('%.3F Tw',$ws*$k));
|
| 1029 | 1058 | } |
| 1030 | 1059 | } |
| 1031 | - if($w==0) |
|
| 1032 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1060 | + if($w==0) {
|
|
| 1061 | + $w = $this->w-$this->rMargin-$this->x; |
|
| 1062 | + } |
|
| 1033 | 1063 | $s = ''; |
| 1034 | 1064 | if($fill || $border==1) |
| 1035 | 1065 | {
|
| 1036 | - if($fill) |
|
| 1037 | - $op = ($border==1) ? 'B' : 'f'; |
|
| 1038 | - else |
|
| 1039 | - $op = 'S'; |
|
| 1066 | + if($fill) {
|
|
| 1067 | + $op = ($border==1) ? 'B' : 'f'; |
|
| 1068 | + } else {
|
|
| 1069 | + $op = 'S'; |
|
| 1070 | + } |
|
| 1040 | 1071 | $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);
|
| 1041 | 1072 | } |
| 1042 | 1073 | if(is_string($border)) |
| 1043 | 1074 | {
|
| 1044 | 1075 | $x = $this->x; |
| 1045 | 1076 | $y = $this->y; |
| 1046 | - if(strpos($border,'L')!==false) |
|
| 1047 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
|
|
| 1048 | - if(strpos($border,'T')!==false) |
|
| 1049 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
|
|
| 1050 | - if(strpos($border,'R')!==false) |
|
| 1051 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
|
|
| 1052 | - if(strpos($border,'B')!==false) |
|
| 1053 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
|
|
| 1077 | + if(strpos($border,'L')!==false) {
|
|
| 1078 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
|
|
| 1079 | + } |
|
| 1080 | + if(strpos($border,'T')!==false) {
|
|
| 1081 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
|
|
| 1082 | + } |
|
| 1083 | + if(strpos($border,'R')!==false) {
|
|
| 1084 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
|
|
| 1085 | + } |
|
| 1086 | + if(strpos($border,'B')!==false) {
|
|
| 1087 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
|
|
| 1088 | + } |
|
| 1054 | 1089 | } |
| 1055 | 1090 | if($txt!=='') |
| 1056 | 1091 | {
|
| 1057 | - if(!isset($this->CurrentFont)) |
|
| 1058 | - $this->Error('No font has been set');
|
|
| 1059 | - if($align=='R') |
|
| 1060 | - $dx = $w-$this->cMargin-$this->getStringWidth($txt); |
|
| 1061 | - elseif($align=='C') |
|
| 1062 | - $dx = ($w-$this->getStringWidth($txt))/2; |
|
| 1063 | - else |
|
| 1064 | - $dx = $this->cMargin; |
|
| 1065 | - if($this->ColorFlag) |
|
| 1066 | - $s .= 'q '.$this->TextColor.' '; |
|
| 1092 | + if(!isset($this->CurrentFont)) {
|
|
| 1093 | + $this->Error('No font has been set');
|
|
| 1094 | + } |
|
| 1095 | + if($align=='R') {
|
|
| 1096 | + $dx = $w-$this->cMargin-$this->getStringWidth($txt); |
|
| 1097 | + } elseif($align=='C') {
|
|
| 1098 | + $dx = ($w-$this->getStringWidth($txt))/2; |
|
| 1099 | + } else {
|
|
| 1100 | + $dx = $this->cMargin; |
|
| 1101 | + } |
|
| 1102 | + if($this->ColorFlag) {
|
|
| 1103 | + $s .= 'q '.$this->TextColor.' '; |
|
| 1104 | + } |
|
| 1067 | 1105 | $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));
|
| 1068 | - if($this->underline) |
|
| 1069 | - $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); |
|
| 1070 | - if($this->ColorFlag) |
|
| 1071 | - $s .= ' Q'; |
|
| 1072 | - if($link) |
|
| 1073 | - $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->getStringWidth($txt),$this->FontSize,$link); |
|
| 1074 | - } |
|
| 1075 | - if($s) |
|
| 1076 | - $this->_out($s); |
|
| 1106 | + if($this->underline) {
|
|
| 1107 | + $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); |
|
| 1108 | + } |
|
| 1109 | + if($this->ColorFlag) {
|
|
| 1110 | + $s .= ' Q'; |
|
| 1111 | + } |
|
| 1112 | + if($link) {
|
|
| 1113 | + $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->getStringWidth($txt),$this->FontSize,$link); |
|
| 1114 | + } |
|
| 1115 | + } |
|
| 1116 | + if($s) {
|
|
| 1117 | + $this->_out($s); |
|
| 1118 | + } |
|
| 1077 | 1119 | $this->lasth = $h; |
| 1078 | 1120 | if($ln>0) |
| 1079 | 1121 | {
|
| 1080 | 1122 | // Go to next line |
| 1081 | 1123 | $this->y += $h; |
| 1082 | - if($ln==1) |
|
| 1083 | - $this->x = $this->lMargin; |
|
| 1124 | + if($ln==1) {
|
|
| 1125 | + $this->x = $this->lMargin; |
|
| 1126 | + } |
|
| 1127 | + } else {
|
|
| 1128 | + $this->x += $w; |
|
| 1084 | 1129 | } |
| 1085 | - else |
|
| 1086 | - $this->x += $w; |
|
| 1087 | 1130 | } |
| 1088 | 1131 | |
| 1089 | 1132 | /** |
@@ -1117,16 +1160,19 @@ discard block |
||
| 1117 | 1160 | public function MultiCell(float $w, float $h, string $txt, $border=0, string $align='J', bool $fill=false) : void |
| 1118 | 1161 | {
|
| 1119 | 1162 | // Output text with automatic or explicit line breaks |
| 1120 | - if(!isset($this->CurrentFont)) |
|
| 1121 | - $this->Error('No font has been set');
|
|
| 1163 | + if(!isset($this->CurrentFont)) {
|
|
| 1164 | + $this->Error('No font has been set');
|
|
| 1165 | + } |
|
| 1122 | 1166 | $cw = &$this->CurrentFont['cw']; |
| 1123 | - if($w==0) |
|
| 1124 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1167 | + if($w==0) {
|
|
| 1168 | + $w = $this->w-$this->rMargin-$this->x; |
|
| 1169 | + } |
|
| 1125 | 1170 | $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
| 1126 | 1171 | $s = str_replace("\r",'',$txt);
|
| 1127 | 1172 | $nb = strlen($s); |
| 1128 | - if($nb>0 && $s[$nb-1]=="\n") |
|
| 1129 | - $nb--; |
|
| 1173 | + if($nb>0 && $s[$nb-1]=="\n") {
|
|
| 1174 | + $nb--; |
|
| 1175 | + } |
|
| 1130 | 1176 | $b = 0; |
| 1131 | 1177 | $b2 = ''; |
| 1132 | 1178 | if($border) |
@@ -1136,14 +1182,15 @@ discard block |
||
| 1136 | 1182 | $border = 'LTRB'; |
| 1137 | 1183 | $b = 'LRT'; |
| 1138 | 1184 | $b2 = 'LR'; |
| 1139 | - } |
|
| 1140 | - else |
|
| 1185 | + } else |
|
| 1141 | 1186 | {
|
| 1142 | 1187 | $b2 = ''; |
| 1143 | - if(strpos($border,'L')!==false) |
|
| 1144 | - $b2 .= 'L'; |
|
| 1145 | - if(strpos($border,'R')!==false) |
|
| 1146 | - $b2 .= 'R'; |
|
| 1188 | + if(strpos($border,'L')!==false) {
|
|
| 1189 | + $b2 .= 'L'; |
|
| 1190 | + } |
|
| 1191 | + if(strpos($border,'R')!==false) {
|
|
| 1192 | + $b2 .= 'R'; |
|
| 1193 | + } |
|
| 1147 | 1194 | $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; |
| 1148 | 1195 | } |
| 1149 | 1196 | } |
@@ -1173,8 +1220,9 @@ discard block |
||
| 1173 | 1220 | $l = 0; |
| 1174 | 1221 | $ns = 0; |
| 1175 | 1222 | $nl++; |
| 1176 | - if($border && $nl==2) |
|
| 1177 | - $b = $b2; |
|
| 1223 | + if($border && $nl==2) {
|
|
| 1224 | + $b = $b2; |
|
| 1225 | + } |
|
| 1178 | 1226 | continue; |
| 1179 | 1227 | } |
| 1180 | 1228 | if($c==' ') |
@@ -1189,16 +1237,16 @@ discard block |
||
| 1189 | 1237 | // Automatic line break |
| 1190 | 1238 | if($sep==-1) |
| 1191 | 1239 | {
|
| 1192 | - if($i==$j) |
|
| 1193 | - $i++; |
|
| 1240 | + if($i==$j) {
|
|
| 1241 | + $i++; |
|
| 1242 | + } |
|
| 1194 | 1243 | if($this->ws>0) |
| 1195 | 1244 | {
|
| 1196 | 1245 | $this->ws = 0; |
| 1197 | 1246 | $this->_out('0 Tw');
|
| 1198 | 1247 | } |
| 1199 | 1248 | $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
| 1200 | - } |
|
| 1201 | - else |
|
| 1249 | + } else |
|
| 1202 | 1250 | {
|
| 1203 | 1251 | if($align=='J') |
| 1204 | 1252 | {
|
@@ -1213,11 +1261,12 @@ discard block |
||
| 1213 | 1261 | $l = 0; |
| 1214 | 1262 | $ns = 0; |
| 1215 | 1263 | $nl++; |
| 1216 | - if($border && $nl==2) |
|
| 1217 | - $b = $b2; |
|
| 1264 | + if($border && $nl==2) {
|
|
| 1265 | + $b = $b2; |
|
| 1266 | + } |
|
| 1267 | + } else {
|
|
| 1268 | + $i++; |
|
| 1218 | 1269 | } |
| 1219 | - else |
|
| 1220 | - $i++; |
|
| 1221 | 1270 | } |
| 1222 | 1271 | // Last chunk |
| 1223 | 1272 | if($this->ws>0) |
@@ -1225,8 +1274,9 @@ discard block |
||
| 1225 | 1274 | $this->ws = 0; |
| 1226 | 1275 | $this->_out('0 Tw');
|
| 1227 | 1276 | } |
| 1228 | - if($border && strpos($border,'B')!==false) |
|
| 1229 | - $b .= 'B'; |
|
| 1277 | + if($border && strpos($border,'B')!==false) {
|
|
| 1278 | + $b .= 'B'; |
|
| 1279 | + } |
|
| 1230 | 1280 | $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
| 1231 | 1281 | $this->x = $this->lMargin; |
| 1232 | 1282 | } |
@@ -1244,8 +1294,9 @@ discard block |
||
| 1244 | 1294 | public function Write(float $h, string $txt, $link='') : void |
| 1245 | 1295 | {
|
| 1246 | 1296 | // Output text in flowing mode |
| 1247 | - if(!isset($this->CurrentFont)) |
|
| 1248 | - $this->Error('No font has been set');
|
|
| 1297 | + if(!isset($this->CurrentFont)) {
|
|
| 1298 | + $this->Error('No font has been set');
|
|
| 1299 | + } |
|
| 1249 | 1300 | $cw = &$this->CurrentFont['cw']; |
| 1250 | 1301 | $w = $this->w-$this->rMargin-$this->x; |
| 1251 | 1302 | $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
@@ -1277,8 +1328,9 @@ discard block |
||
| 1277 | 1328 | $nl++; |
| 1278 | 1329 | continue; |
| 1279 | 1330 | } |
| 1280 | - if($c==' ') |
|
| 1281 | - $sep = $i; |
|
| 1331 | + if($c==' ') {
|
|
| 1332 | + $sep = $i; |
|
| 1333 | + } |
|
| 1282 | 1334 | $l += $cw[$c]; |
| 1283 | 1335 | if($l>$wmax) |
| 1284 | 1336 | {
|
@@ -1296,11 +1348,11 @@ discard block |
||
| 1296 | 1348 | $nl++; |
| 1297 | 1349 | continue; |
| 1298 | 1350 | } |
| 1299 | - if($i==$j) |
|
| 1300 | - $i++; |
|
| 1351 | + if($i==$j) {
|
|
| 1352 | + $i++; |
|
| 1353 | + } |
|
| 1301 | 1354 | $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
| 1302 | - } |
|
| 1303 | - else |
|
| 1355 | + } else |
|
| 1304 | 1356 | {
|
| 1305 | 1357 | $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link); |
| 1306 | 1358 | $i = $sep+1; |
@@ -1315,13 +1367,14 @@ discard block |
||
| 1315 | 1367 | $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
| 1316 | 1368 | } |
| 1317 | 1369 | $nl++; |
| 1370 | + } else {
|
|
| 1371 | + $i++; |
|
| 1318 | 1372 | } |
| 1319 | - else |
|
| 1320 | - $i++; |
|
| 1321 | 1373 | } |
| 1322 | 1374 | // Last chunk |
| 1323 | - if($i!=$j) |
|
| 1324 | - $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link); |
|
| 1375 | + if($i!=$j) {
|
|
| 1376 | + $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link); |
|
| 1377 | + } |
|
| 1325 | 1378 | } |
| 1326 | 1379 | |
| 1327 | 1380 | /** |
@@ -1335,10 +1388,11 @@ discard block |
||
| 1335 | 1388 | {
|
| 1336 | 1389 | // Line feed; default value is the last cell height |
| 1337 | 1390 | $this->x = $this->lMargin; |
| 1338 | - if($h===null) |
|
| 1339 | - $this->y += $this->lasth; |
|
| 1340 | - else |
|
| 1341 | - $this->y += $h; |
|
| 1391 | + if($h===null) {
|
|
| 1392 | + $this->y += $this->lasth; |
|
| 1393 | + } else {
|
|
| 1394 | + $this->y += $h; |
|
| 1395 | + } |
|
| 1342 | 1396 | } |
| 1343 | 1397 | |
| 1344 | 1398 | /** |
@@ -1390,30 +1444,34 @@ discard block |
||
| 1390 | 1444 | public function Image(string $file, ?float $x=null, ?float $y=null, float $w=0, float $h=0, string $type='', $link='') : void |
| 1391 | 1445 | {
|
| 1392 | 1446 | // Put an image on the page |
| 1393 | - if($file=='') |
|
| 1394 | - $this->Error('Image file name is empty');
|
|
| 1447 | + if($file=='') {
|
|
| 1448 | + $this->Error('Image file name is empty');
|
|
| 1449 | + } |
|
| 1395 | 1450 | if(!isset($this->images[$file])) |
| 1396 | 1451 | {
|
| 1397 | 1452 | // First use of this image, get info |
| 1398 | 1453 | if($type=='') |
| 1399 | 1454 | {
|
| 1400 | 1455 | $pos = strrpos($file,'.'); |
| 1401 | - if(!$pos) |
|
| 1402 | - $this->Error('Image file has no extension and no type was specified: '.$file);
|
|
| 1456 | + if(!$pos) {
|
|
| 1457 | + $this->Error('Image file has no extension and no type was specified: '.$file);
|
|
| 1458 | + } |
|
| 1403 | 1459 | $type = substr($file,$pos+1); |
| 1404 | 1460 | } |
| 1405 | 1461 | $type = strtolower($type); |
| 1406 | - if($type=='jpeg') |
|
| 1407 | - $type = 'jpg'; |
|
| 1462 | + if($type=='jpeg') {
|
|
| 1463 | + $type = 'jpg'; |
|
| 1464 | + } |
|
| 1408 | 1465 | $mtd = '_parse'.$type; |
| 1409 | - if(!method_exists($this,$mtd)) |
|
| 1410 | - $this->Error('Unsupported image type: '.$type);
|
|
| 1466 | + if(!method_exists($this,$mtd)) {
|
|
| 1467 | + $this->Error('Unsupported image type: '.$type);
|
|
| 1468 | + } |
|
| 1411 | 1469 | $info = $this->$mtd($file); |
| 1412 | 1470 | $info['i'] = count($this->images)+1; |
| 1413 | 1471 | $this->images[$file] = $info; |
| 1472 | + } else {
|
|
| 1473 | + $info = $this->images[$file]; |
|
| 1414 | 1474 | } |
| 1415 | - else |
|
| 1416 | - $info = $this->images[$file]; |
|
| 1417 | 1475 | |
| 1418 | 1476 | // Automatic width and height calculation if needed |
| 1419 | 1477 | if($w==0 && $h==0) |
@@ -1422,14 +1480,18 @@ discard block |
||
| 1422 | 1480 | $w = -96; |
| 1423 | 1481 | $h = -96; |
| 1424 | 1482 | } |
| 1425 | - if($w<0) |
|
| 1426 | - $w = -$info['w']*72/$w/$this->k; |
|
| 1427 | - if($h<0) |
|
| 1428 | - $h = -$info['h']*72/$h/$this->k; |
|
| 1429 | - if($w==0) |
|
| 1430 | - $w = $h*$info['w']/$info['h']; |
|
| 1431 | - if($h==0) |
|
| 1432 | - $h = $w*$info['h']/$info['w']; |
|
| 1483 | + if($w<0) {
|
|
| 1484 | + $w = -$info['w']*72/$w/$this->k; |
|
| 1485 | + } |
|
| 1486 | + if($h<0) {
|
|
| 1487 | + $h = -$info['h']*72/$h/$this->k; |
|
| 1488 | + } |
|
| 1489 | + if($w==0) {
|
|
| 1490 | + $w = $h*$info['w']/$info['h']; |
|
| 1491 | + } |
|
| 1492 | + if($h==0) {
|
|
| 1493 | + $h = $w*$info['h']/$info['w']; |
|
| 1494 | + } |
|
| 1433 | 1495 | |
| 1434 | 1496 | // Flowing mode |
| 1435 | 1497 | if($y===null) |
@@ -1445,11 +1507,13 @@ discard block |
||
| 1445 | 1507 | $this->y += $h; |
| 1446 | 1508 | } |
| 1447 | 1509 | |
| 1448 | - if($x===null) |
|
| 1449 | - $x = $this->x; |
|
| 1510 | + if($x===null) {
|
|
| 1511 | + $x = $this->x; |
|
| 1512 | + } |
|
| 1450 | 1513 | $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']));
|
| 1451 | - if($link) |
|
| 1452 | - $this->Link($x,$y,$w,$h,$link); |
|
| 1514 | + if($link) {
|
|
| 1515 | + $this->Link($x,$y,$w,$h,$link); |
|
| 1516 | + } |
|
| 1453 | 1517 | } |
| 1454 | 1518 | |
| 1455 | 1519 | /** |
@@ -1490,10 +1554,11 @@ discard block |
||
| 1490 | 1554 | public function SetX(float $x) : void |
| 1491 | 1555 | {
|
| 1492 | 1556 | // Set x position |
| 1493 | - if($x>=0) |
|
| 1494 | - $this->x = $x; |
|
| 1495 | - else |
|
| 1496 | - $this->x = $this->w+$x; |
|
| 1557 | + if($x>=0) {
|
|
| 1558 | + $this->x = $x; |
|
| 1559 | + } else {
|
|
| 1560 | + $this->x = $this->w+$x; |
|
| 1561 | + } |
|
| 1497 | 1562 | } |
| 1498 | 1563 | |
| 1499 | 1564 | /** |
@@ -1515,12 +1580,14 @@ discard block |
||
| 1515 | 1580 | public function SetY(float $y, bool $resetX=true) : void |
| 1516 | 1581 | {
|
| 1517 | 1582 | // Set y position and optionally reset x |
| 1518 | - if($y>=0) |
|
| 1519 | - $this->y = $y; |
|
| 1520 | - else |
|
| 1521 | - $this->y = $this->h+$y; |
|
| 1522 | - if($resetX) |
|
| 1523 | - $this->x = $this->lMargin; |
|
| 1583 | + if($y>=0) {
|
|
| 1584 | + $this->y = $y; |
|
| 1585 | + } else {
|
|
| 1586 | + $this->y = $this->h+$y; |
|
| 1587 | + } |
|
| 1588 | + if($resetX) {
|
|
| 1589 | + $this->x = $this->lMargin; |
|
| 1590 | + } |
|
| 1524 | 1591 | } |
| 1525 | 1592 | |
| 1526 | 1593 | /** |
@@ -1565,10 +1632,12 @@ discard block |
||
| 1565 | 1632 | $dest = $name; |
| 1566 | 1633 | $name = $tmp; |
| 1567 | 1634 | } |
| 1568 | - if($dest=='') |
|
| 1569 | - $dest = 'I'; |
|
| 1570 | - if($name=='') |
|
| 1571 | - $name = 'doc.pdf'; |
|
| 1635 | + if($dest=='') {
|
|
| 1636 | + $dest = 'I'; |
|
| 1637 | + } |
|
| 1638 | + if($name=='') {
|
|
| 1639 | + $name = 'doc.pdf'; |
|
| 1640 | + } |
|
| 1572 | 1641 | switch(strtoupper($dest)) |
| 1573 | 1642 | {
|
| 1574 | 1643 | case 'I': |
@@ -1595,8 +1664,9 @@ discard block |
||
| 1595 | 1664 | break; |
| 1596 | 1665 | case 'F': |
| 1597 | 1666 | // Save to local file |
| 1598 | - if(!file_put_contents($name,$this->buffer)) |
|
| 1599 | - $this->Error('Unable to create output file: '.$name);
|
|
| 1667 | + if(!file_put_contents($name,$this->buffer)) {
|
|
| 1668 | + $this->Error('Unable to create output file: '.$name);
|
|
| 1669 | + } |
|
| 1600 | 1670 | break; |
| 1601 | 1671 | case 'S': |
| 1602 | 1672 | // Return as a string |
@@ -1644,8 +1714,9 @@ discard block |
||
| 1644 | 1714 | {
|
| 1645 | 1715 | $file = ''; |
| 1646 | 1716 | $line = 0; |
| 1647 | - if(headers_sent($file,$line)) |
|
| 1648 | - $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)");
|
|
| 1717 | + if(headers_sent($file,$line)) {
|
|
| 1718 | + $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)");
|
|
| 1719 | + } |
|
| 1649 | 1720 | } |
| 1650 | 1721 | if(ob_get_length()) |
| 1651 | 1722 | {
|
@@ -1654,9 +1725,9 @@ discard block |
||
| 1654 | 1725 | {
|
| 1655 | 1726 | // It contains only a UTF-8 BOM and/or whitespace, let's clean it |
| 1656 | 1727 | ob_clean(); |
| 1728 | + } else {
|
|
| 1729 | + $this->Error("Some data has already been output, can't send PDF file");
|
|
| 1657 | 1730 | } |
| 1658 | - else |
|
| 1659 | - $this->Error("Some data has already been output, can't send PDF file");
|
|
| 1660 | 1731 | } |
| 1661 | 1732 | } |
| 1662 | 1733 | |
@@ -1707,14 +1778,16 @@ discard block |
||
| 1707 | 1778 | $this->y = $this->tMargin; |
| 1708 | 1779 | $this->FontFamily = ''; |
| 1709 | 1780 | // Check page size and orientation |
| 1710 | - if($orientation=='') |
|
| 1711 | - $orientation = $this->DefOrientation; |
|
| 1712 | - else |
|
| 1713 | - $orientation = strtoupper($orientation[0]); |
|
| 1714 | - if($size=='') |
|
| 1715 | - $size = $this->DefPageSize; |
|
| 1716 | - else |
|
| 1717 | - $size = $this->getPageSize($size); |
|
| 1781 | + if($orientation=='') {
|
|
| 1782 | + $orientation = $this->DefOrientation; |
|
| 1783 | + } else {
|
|
| 1784 | + $orientation = strtoupper($orientation[0]); |
|
| 1785 | + } |
|
| 1786 | + if($size=='') {
|
|
| 1787 | + $size = $this->DefPageSize; |
|
| 1788 | + } else {
|
|
| 1789 | + $size = $this->getPageSize($size); |
|
| 1790 | + } |
|
| 1718 | 1791 | if($orientation!=$this->CurOrientation || $size[0]!=$this->CurPageSize[0] || $size[1]!=$this->CurPageSize[1]) |
| 1719 | 1792 | {
|
| 1720 | 1793 | // New size or orientation |
@@ -1722,8 +1795,7 @@ discard block |
||
| 1722 | 1795 | {
|
| 1723 | 1796 | $this->w = $size[0]; |
| 1724 | 1797 | $this->h = $size[1]; |
| 1725 | - } |
|
| 1726 | - else |
|
| 1798 | + } else |
|
| 1727 | 1799 | {
|
| 1728 | 1800 | $this->w = $size[1]; |
| 1729 | 1801 | $this->h = $size[0]; |
@@ -1734,12 +1806,14 @@ discard block |
||
| 1734 | 1806 | $this->CurOrientation = $orientation; |
| 1735 | 1807 | $this->CurPageSize = $size; |
| 1736 | 1808 | } |
| 1737 | - if($orientation!=$this->DefOrientation || $size[0]!=$this->DefPageSize[0] || $size[1]!=$this->DefPageSize[1]) |
|
| 1738 | - $this->PageInfo[$this->page]['size'] = array($this->wPt, $this->hPt); |
|
| 1809 | + if($orientation!=$this->DefOrientation || $size[0]!=$this->DefPageSize[0] || $size[1]!=$this->DefPageSize[1]) {
|
|
| 1810 | + $this->PageInfo[$this->page]['size'] = array($this->wPt, $this->hPt); |
|
| 1811 | + } |
|
| 1739 | 1812 | if($rotation!=0) |
| 1740 | 1813 | {
|
| 1741 | - if($rotation%90!=0) |
|
| 1742 | - $this->Error('Incorrect rotation value: '.$rotation);
|
|
| 1814 | + if($rotation%90!=0) {
|
|
| 1815 | + $this->Error('Incorrect rotation value: '.$rotation);
|
|
| 1816 | + } |
|
| 1743 | 1817 | $this->CurRotation = $rotation; |
| 1744 | 1818 | $this->PageInfo[$this->page]['rotation'] = $rotation; |
| 1745 | 1819 | } |
@@ -1794,8 +1868,9 @@ discard block |
||
| 1794 | 1868 | $nb = strlen($s); |
| 1795 | 1869 | for($i=0;$i<$nb;$i++) |
| 1796 | 1870 | {
|
| 1797 | - if(ord($s[$i])>127) |
|
| 1798 | - return false; |
|
| 1871 | + if(ord($s[$i])>127) {
|
|
| 1872 | + return false; |
|
| 1873 | + } |
|
| 1799 | 1874 | } |
| 1800 | 1875 | return true; |
| 1801 | 1876 | } |
@@ -1809,14 +1884,17 @@ discard block |
||
| 1809 | 1884 | protected function _httpencode(string $param, string $value, bool $isUTF8) : string |
| 1810 | 1885 | {
|
| 1811 | 1886 | // Encode HTTP header field parameter |
| 1812 | - if($this->_isascii($value)) |
|
| 1813 | - return $param.'="'.$value.'"'; |
|
| 1814 | - if(!$isUTF8) |
|
| 1815 | - $value = utf8_encode($value); |
|
| 1816 | - if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==false) |
|
| 1817 | - return $param.'="'.rawurlencode($value).'"'; |
|
| 1818 | - else |
|
| 1819 | - return $param."*=UTF-8''".rawurlencode($value); |
|
| 1887 | + if($this->_isascii($value)) {
|
|
| 1888 | + return $param.'="'.$value.'"'; |
|
| 1889 | + } |
|
| 1890 | + if(!$isUTF8) {
|
|
| 1891 | + $value = utf8_encode($value); |
|
| 1892 | + } |
|
| 1893 | + if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==false) {
|
|
| 1894 | + return $param.'="'.rawurlencode($value).'"'; |
|
| 1895 | + } else {
|
|
| 1896 | + return $param."*=UTF-8''".rawurlencode($value); |
|
| 1897 | + } |
|
| 1820 | 1898 | } |
| 1821 | 1899 | |
| 1822 | 1900 | /** |
@@ -1840,15 +1918,13 @@ discard block |
||
| 1840 | 1918 | $c3 = ord($s[$i++]); |
| 1841 | 1919 | $res .= chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2)); |
| 1842 | 1920 | $res .= chr((($c2 & 0x03)<<6) + ($c3 & 0x3F)); |
| 1843 | - } |
|
| 1844 | - elseif($c1>=192) |
|
| 1921 | + } elseif($c1>=192) |
|
| 1845 | 1922 | {
|
| 1846 | 1923 | // 2-byte character |
| 1847 | 1924 | $c2 = ord($s[$i++]); |
| 1848 | 1925 | $res .= chr(($c1 & 0x1C)>>2); |
| 1849 | 1926 | $res .= chr((($c1 & 0x03)<<6) + ($c2 & 0x3F)); |
| 1850 | - } |
|
| 1851 | - else |
|
| 1927 | + } else |
|
| 1852 | 1928 | {
|
| 1853 | 1929 | // Single-byte character |
| 1854 | 1930 | $res .= "\0".chr($c1); |
@@ -1865,10 +1941,11 @@ discard block |
||
| 1865 | 1941 | protected function _escape(string $s) : string |
| 1866 | 1942 | {
|
| 1867 | 1943 | // Escape special characters |
| 1868 | - if(strpos($s,'(')!==false || strpos($s,')')!==false || strpos($s,'\\')!==false || strpos($s,"\r")!==false)
|
|
| 1869 | - return str_replace(array('\\','(',')',"\r"), array('\\\\','\\(','\\)','\\r'), $s);
|
|
| 1870 | - else |
|
| 1871 | - return $s; |
|
| 1944 | + if(strpos($s,'(')!==false || strpos($s,')')!==false || strpos($s,'\\')!==false || strpos($s,"\r")!==false) {
|
|
| 1945 | + return str_replace(array('\\','(',')',"\r"), array('\\\\','\\(','\\)','\\r'), $s);
|
|
| 1946 | + } else {
|
|
| 1947 | + return $s; |
|
| 1948 | + } |
|
| 1872 | 1949 | } |
| 1873 | 1950 | |
| 1874 | 1951 | /** |
@@ -1879,8 +1956,9 @@ discard block |
||
| 1879 | 1956 | protected function _textstring(string $s) : string |
| 1880 | 1957 | {
|
| 1881 | 1958 | // Format a text string |
| 1882 | - if(!$this->_isascii($s)) |
|
| 1883 | - $s = $this->_UTF8toUTF16($s); |
|
| 1959 | + if(!$this->_isascii($s)) {
|
|
| 1960 | + $s = $this->_UTF8toUTF16($s); |
|
| 1961 | + } |
|
| 1884 | 1962 | return '('.$this->_escape($s).')';
|
| 1885 | 1963 | } |
| 1886 | 1964 | |
@@ -1909,16 +1987,19 @@ discard block |
||
| 1909 | 1987 | {
|
| 1910 | 1988 | // Extract info from a JPEG file |
| 1911 | 1989 | $a = getimagesize($file); |
| 1912 | - if(!$a) |
|
| 1913 | - $this->Error('Missing or incorrect image file: '.$file);
|
|
| 1914 | - if($a[2]!=2) |
|
| 1915 | - $this->Error('Not a JPEG file: '.$file);
|
|
| 1916 | - if(!isset($a['channels']) || $a['channels']==3) |
|
| 1917 | - $colspace = 'DeviceRGB'; |
|
| 1918 | - elseif($a['channels']==4) |
|
| 1919 | - $colspace = 'DeviceCMYK'; |
|
| 1920 | - else |
|
| 1921 | - $colspace = 'DeviceGray'; |
|
| 1990 | + if(!$a) {
|
|
| 1991 | + $this->Error('Missing or incorrect image file: '.$file);
|
|
| 1992 | + } |
|
| 1993 | + if($a[2]!=2) {
|
|
| 1994 | + $this->Error('Not a JPEG file: '.$file);
|
|
| 1995 | + } |
|
| 1996 | + if(!isset($a['channels']) || $a['channels']==3) {
|
|
| 1997 | + $colspace = 'DeviceRGB'; |
|
| 1998 | + } elseif($a['channels']==4) {
|
|
| 1999 | + $colspace = 'DeviceCMYK'; |
|
| 2000 | + } else {
|
|
| 2001 | + $colspace = 'DeviceGray'; |
|
| 2002 | + } |
|
| 1922 | 2003 | $bpc = isset($a['bits']) ? $a['bits'] : 8; |
| 1923 | 2004 | $data = file_get_contents($file); |
| 1924 | 2005 | return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data);
|
@@ -1950,34 +2031,41 @@ discard block |
||
| 1950 | 2031 | protected function _parsepngstream($f, string $file) : array |
| 1951 | 2032 | {
|
| 1952 | 2033 | // Check signature |
| 1953 | - if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) |
|
| 1954 | - $this->Error('Not a PNG file: '.$file);
|
|
| 2034 | + if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
|
|
| 2035 | + $this->Error('Not a PNG file: '.$file);
|
|
| 2036 | + } |
|
| 1955 | 2037 | |
| 1956 | 2038 | // Read header chunk |
| 1957 | 2039 | $this->_readstream($f,4); |
| 1958 | - if($this->_readstream($f,4)!='IHDR') |
|
| 1959 | - $this->Error('Incorrect PNG file: '.$file);
|
|
| 2040 | + if($this->_readstream($f,4)!='IHDR') {
|
|
| 2041 | + $this->Error('Incorrect PNG file: '.$file);
|
|
| 2042 | + } |
|
| 1960 | 2043 | $w = $this->_readint($f); |
| 1961 | 2044 | $h = $this->_readint($f); |
| 1962 | 2045 | $bpc = ord($this->_readstream($f,1)); |
| 1963 | - if($bpc>8) |
|
| 1964 | - $this->Error('16-bit depth not supported: '.$file);
|
|
| 2046 | + if($bpc>8) {
|
|
| 2047 | + $this->Error('16-bit depth not supported: '.$file);
|
|
| 2048 | + } |
|
| 1965 | 2049 | $ct = ord($this->_readstream($f,1)); |
| 1966 | 2050 | $colspace = ''; |
| 1967 | - if($ct==0 || $ct==4) |
|
| 1968 | - $colspace = 'DeviceGray'; |
|
| 1969 | - elseif($ct==2 || $ct==6) |
|
| 1970 | - $colspace = 'DeviceRGB'; |
|
| 1971 | - elseif($ct==3) |
|
| 1972 | - $colspace = 'Indexed'; |
|
| 1973 | - else |
|
| 1974 | - $this->Error('Unknown color type: '.$file);
|
|
| 1975 | - if(ord($this->_readstream($f,1))!=0) |
|
| 1976 | - $this->Error('Unknown compression method: '.$file);
|
|
| 1977 | - if(ord($this->_readstream($f,1))!=0) |
|
| 1978 | - $this->Error('Unknown filter method: '.$file);
|
|
| 1979 | - if(ord($this->_readstream($f,1))!=0) |
|
| 1980 | - $this->Error('Interlacing not supported: '.$file);
|
|
| 2051 | + if($ct==0 || $ct==4) {
|
|
| 2052 | + $colspace = 'DeviceGray'; |
|
| 2053 | + } elseif($ct==2 || $ct==6) {
|
|
| 2054 | + $colspace = 'DeviceRGB'; |
|
| 2055 | + } elseif($ct==3) {
|
|
| 2056 | + $colspace = 'Indexed'; |
|
| 2057 | + } else {
|
|
| 2058 | + $this->Error('Unknown color type: '.$file);
|
|
| 2059 | + } |
|
| 2060 | + if(ord($this->_readstream($f,1))!=0) {
|
|
| 2061 | + $this->Error('Unknown compression method: '.$file);
|
|
| 2062 | + } |
|
| 2063 | + if(ord($this->_readstream($f,1))!=0) {
|
|
| 2064 | + $this->Error('Unknown filter method: '.$file);
|
|
| 2065 | + } |
|
| 2066 | + if(ord($this->_readstream($f,1))!=0) {
|
|
| 2067 | + $this->Error('Interlacing not supported: '.$file);
|
|
| 2068 | + } |
|
| 1981 | 2069 | $this->_readstream($f,4); |
| 1982 | 2070 | $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w; |
| 1983 | 2071 | |
@@ -1994,44 +2082,45 @@ discard block |
||
| 1994 | 2082 | // Read palette |
| 1995 | 2083 | $pal = $this->_readstream($f,$n); |
| 1996 | 2084 | $this->_readstream($f,4); |
| 1997 | - } |
|
| 1998 | - elseif($type=='tRNS') |
|
| 2085 | + } elseif($type=='tRNS') |
|
| 1999 | 2086 | {
|
| 2000 | 2087 | // Read transparency info |
| 2001 | 2088 | $t = $this->_readstream($f,$n); |
| 2002 | - if($ct==0) |
|
| 2003 | - $trns = array(ord(substr($t,1,1))); |
|
| 2004 | - elseif($ct==2) |
|
| 2005 | - $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); |
|
| 2006 | - else |
|
| 2089 | + if($ct==0) {
|
|
| 2090 | + $trns = array(ord(substr($t,1,1))); |
|
| 2091 | + } elseif($ct==2) {
|
|
| 2092 | + $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); |
|
| 2093 | + } else |
|
| 2007 | 2094 | {
|
| 2008 | 2095 | $pos = strpos($t,chr(0)); |
| 2009 | - if($pos!==false) |
|
| 2010 | - $trns = array($pos); |
|
| 2096 | + if($pos!==false) {
|
|
| 2097 | + $trns = array($pos); |
|
| 2098 | + } |
|
| 2011 | 2099 | } |
| 2012 | 2100 | $this->_readstream($f,4); |
| 2013 | - } |
|
| 2014 | - elseif($type=='IDAT') |
|
| 2101 | + } elseif($type=='IDAT') |
|
| 2015 | 2102 | {
|
| 2016 | 2103 | // Read image data block |
| 2017 | 2104 | $data .= $this->_readstream($f,$n); |
| 2018 | 2105 | $this->_readstream($f,4); |
| 2106 | + } elseif($type=='IEND') {
|
|
| 2107 | + break; |
|
| 2108 | + } else {
|
|
| 2109 | + $this->_readstream($f,$n+4); |
|
| 2019 | 2110 | } |
| 2020 | - elseif($type=='IEND') |
|
| 2021 | - break; |
|
| 2022 | - else |
|
| 2023 | - $this->_readstream($f,$n+4); |
|
| 2024 | 2111 | } |
| 2025 | 2112 | while($n); |
| 2026 | 2113 | |
| 2027 | - if($colspace=='Indexed' && empty($pal)) |
|
| 2028 | - $this->Error('Missing palette in '.$file);
|
|
| 2114 | + if($colspace=='Indexed' && empty($pal)) {
|
|
| 2115 | + $this->Error('Missing palette in '.$file);
|
|
| 2116 | + } |
|
| 2029 | 2117 | $info = array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns);
|
| 2030 | 2118 | if($ct>=4) |
| 2031 | 2119 | {
|
| 2032 | 2120 | // Extract alpha channel |
| 2033 | - if(!function_exists('gzuncompress'))
|
|
| 2034 | - $this->Error('Zlib not available, can\'t handle alpha channel: '.$file);
|
|
| 2121 | + if(!function_exists('gzuncompress')) {
|
|
| 2122 | + $this->Error('Zlib not available, can\'t handle alpha channel: '.$file);
|
|
| 2123 | + } |
|
| 2035 | 2124 | $data = gzuncompress($data); |
| 2036 | 2125 | $color = ''; |
| 2037 | 2126 | $alpha = ''; |
@@ -2048,8 +2137,7 @@ discard block |
||
| 2048 | 2137 | $color .= preg_replace('/(.)./s','$1',$line);
|
| 2049 | 2138 | $alpha .= preg_replace('/.(.)/s','$1',$line);
|
| 2050 | 2139 | } |
| 2051 | - } |
|
| 2052 | - else |
|
| 2140 | + } else |
|
| 2053 | 2141 | {
|
| 2054 | 2142 | // RGB image |
| 2055 | 2143 | $len = 4*$w; |
@@ -2067,8 +2155,9 @@ discard block |
||
| 2067 | 2155 | $data = gzcompress($color); |
| 2068 | 2156 | $info['smask'] = gzcompress($alpha); |
| 2069 | 2157 | $this->WithAlpha = true; |
| 2070 | - if($this->PDFVersion<'1.4') |
|
| 2071 | - $this->PDFVersion = '1.4'; |
|
| 2158 | + if($this->PDFVersion<'1.4') {
|
|
| 2159 | + $this->PDFVersion = '1.4'; |
|
| 2160 | + } |
|
| 2072 | 2161 | } |
| 2073 | 2162 | $info['data'] = $data; |
| 2074 | 2163 | return $info; |
@@ -2087,13 +2176,15 @@ discard block |
||
| 2087 | 2176 | while($n>0 && !feof($f)) |
| 2088 | 2177 | {
|
| 2089 | 2178 | $s = fread($f,$n); |
| 2090 | - if($s===false) |
|
| 2091 | - $this->Error('Error while reading stream');
|
|
| 2179 | + if($s===false) {
|
|
| 2180 | + $this->Error('Error while reading stream');
|
|
| 2181 | + } |
|
| 2092 | 2182 | $n -= strlen($s); |
| 2093 | 2183 | $res .= $s; |
| 2094 | 2184 | } |
| 2095 | - if($n>0) |
|
| 2096 | - $this->Error('Unexpected end of stream');
|
|
| 2185 | + if($n>0) {
|
|
| 2186 | + $this->Error('Unexpected end of stream');
|
|
| 2187 | + } |
|
| 2097 | 2188 | return $res; |
| 2098 | 2189 | } |
| 2099 | 2190 | |
@@ -2150,14 +2241,15 @@ discard block |
||
| 2150 | 2241 | protected function _out(string $s) : void |
| 2151 | 2242 | {
|
| 2152 | 2243 | // Add a line to the document |
| 2153 | - if($this->state==2) |
|
| 2154 | - $this->pages[$this->page] .= $s."\n"; |
|
| 2155 | - elseif($this->state==1) |
|
| 2156 | - $this->_put($s); |
|
| 2157 | - elseif($this->state==0) |
|
| 2158 | - $this->Error('No page has been added yet');
|
|
| 2159 | - elseif($this->state==3) |
|
| 2160 | - $this->Error('The document is closed');
|
|
| 2244 | + if($this->state==2) {
|
|
| 2245 | + $this->pages[$this->page] .= $s."\n"; |
|
| 2246 | + } elseif($this->state==1) {
|
|
| 2247 | + $this->_put($s); |
|
| 2248 | + } elseif($this->state==0) {
|
|
| 2249 | + $this->Error('No page has been added yet');
|
|
| 2250 | + } elseif($this->state==3) {
|
|
| 2251 | + $this->Error('The document is closed');
|
|
| 2252 | + } |
|
| 2161 | 2253 | } |
| 2162 | 2254 | |
| 2163 | 2255 | /** |
@@ -2185,8 +2277,9 @@ discard block |
||
| 2185 | 2277 | protected function _newobj(?int $n=null) : void |
| 2186 | 2278 | {
|
| 2187 | 2279 | // Begin a new object |
| 2188 | - if($n===null) |
|
| 2189 | - $n = ++$this->n; |
|
| 2280 | + if($n===null) {
|
|
| 2281 | + $n = ++$this->n; |
|
| 2282 | + } |
|
| 2190 | 2283 | $this->offsets[$n] = $this->_getoffset(); |
| 2191 | 2284 | $this->_put($n.' 0 obj'); |
| 2192 | 2285 | } |
@@ -2212,9 +2305,9 @@ discard block |
||
| 2212 | 2305 | {
|
| 2213 | 2306 | $entries = '/Filter /FlateDecode '; |
| 2214 | 2307 | $data = gzcompress($data); |
| 2308 | + } else {
|
|
| 2309 | + $entries = ''; |
|
| 2215 | 2310 | } |
| 2216 | - else |
|
| 2217 | - $entries = ''; |
|
| 2218 | 2311 | $entries .= '/Length '.strlen($data); |
| 2219 | 2312 | $this->_newobj(); |
| 2220 | 2313 | $this->_put('<<'.$entries.'>>');
|
@@ -2231,10 +2324,12 @@ discard block |
||
| 2231 | 2324 | $this->_newobj(); |
| 2232 | 2325 | $this->_put('<</Type /Page');
|
| 2233 | 2326 | $this->_put('/Parent 1 0 R');
|
| 2234 | - if(isset($this->PageInfo[$n]['size'])) |
|
| 2235 | - $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo[$n]['size'][0],$this->PageInfo[$n]['size'][1]));
|
|
| 2236 | - if(isset($this->PageInfo[$n]['rotation'])) |
|
| 2237 | - $this->_put('/Rotate '.$this->PageInfo[$n]['rotation']);
|
|
| 2327 | + if(isset($this->PageInfo[$n]['size'])) {
|
|
| 2328 | + $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo[$n]['size'][0],$this->PageInfo[$n]['size'][1]));
|
|
| 2329 | + } |
|
| 2330 | + if(isset($this->PageInfo[$n]['rotation'])) {
|
|
| 2331 | + $this->_put('/Rotate '.$this->PageInfo[$n]['rotation']);
|
|
| 2332 | + } |
|
| 2238 | 2333 | $this->_put('/Resources 2 0 R');
|
| 2239 | 2334 | if(isset($this->PageLinks[$n])) |
| 2240 | 2335 | {
|
@@ -2244,27 +2339,30 @@ discard block |
||
| 2244 | 2339 | {
|
| 2245 | 2340 | $rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
|
| 2246 | 2341 | $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
| 2247 | - if(is_string($pl[4])) |
|
| 2248 | - $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
|
| 2249 | - else |
|
| 2342 | + if(is_string($pl[4])) {
|
|
| 2343 | + $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
|
| 2344 | + } else |
|
| 2250 | 2345 | {
|
| 2251 | 2346 | $l = $this->links[$pl[4]]; |
| 2252 | - if(isset($this->PageInfo[$l[0]]['size'])) |
|
| 2253 | - $h = $this->PageInfo[$l[0]]['size'][1]; |
|
| 2254 | - else |
|
| 2255 | - $h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k; |
|
| 2347 | + if(isset($this->PageInfo[$l[0]]['size'])) {
|
|
| 2348 | + $h = $this->PageInfo[$l[0]]['size'][1]; |
|
| 2349 | + } else {
|
|
| 2350 | + $h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k; |
|
| 2351 | + } |
|
| 2256 | 2352 | $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[$l[0]]['n'],$h-$l[1]*$this->k);
|
| 2257 | 2353 | } |
| 2258 | 2354 | } |
| 2259 | 2355 | $this->_put($annots.']'); |
| 2260 | 2356 | } |
| 2261 | - if($this->WithAlpha) |
|
| 2262 | - $this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>');
|
|
| 2357 | + if($this->WithAlpha) {
|
|
| 2358 | + $this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>');
|
|
| 2359 | + } |
|
| 2263 | 2360 | $this->_put('/Contents '.($this->n+1).' 0 R>>');
|
| 2264 | 2361 | $this->_put('endobj');
|
| 2265 | 2362 | // Page content |
| 2266 | - if(!empty($this->AliasNbPages)) |
|
| 2267 | - $this->pages[$n] = str_replace($this->AliasNbPages, strval($this->page), $this->pages[$n]); |
|
| 2363 | + if(!empty($this->AliasNbPages)) {
|
|
| 2364 | + $this->pages[$n] = str_replace($this->AliasNbPages, strval($this->page), $this->pages[$n]); |
|
| 2365 | + } |
|
| 2268 | 2366 | $this->_putstreamobject($this->pages[$n]); |
| 2269 | 2367 | } |
| 2270 | 2368 | |
@@ -2274,24 +2372,26 @@ discard block |
||
| 2274 | 2372 | protected function _putpages() : void |
| 2275 | 2373 | {
|
| 2276 | 2374 | $nb = $this->page; |
| 2277 | - for($n=1;$n<=$nb;$n++) |
|
| 2278 | - $this->PageInfo[$n]['n'] = $this->n+1+2*($n-1); |
|
| 2279 | - for($n=1;$n<=$nb;$n++) |
|
| 2280 | - $this->_putpage($n); |
|
| 2375 | + for($n=1;$n<=$nb;$n++) {
|
|
| 2376 | + $this->PageInfo[$n]['n'] = $this->n+1+2*($n-1); |
|
| 2377 | + } |
|
| 2378 | + for($n=1;$n<=$nb;$n++) {
|
|
| 2379 | + $this->_putpage($n); |
|
| 2380 | + } |
|
| 2281 | 2381 | // Pages root |
| 2282 | 2382 | $this->_newobj(1); |
| 2283 | 2383 | $this->_put('<</Type /Pages');
|
| 2284 | 2384 | $kids = '/Kids ['; |
| 2285 | - for($n=1;$n<=$nb;$n++) |
|
| 2286 | - $kids .= $this->PageInfo[$n]['n'].' 0 R '; |
|
| 2385 | + for($n=1;$n<=$nb;$n++) {
|
|
| 2386 | + $kids .= $this->PageInfo[$n]['n'].' 0 R '; |
|
| 2387 | + } |
|
| 2287 | 2388 | $this->_put($kids.']'); |
| 2288 | 2389 | $this->_put('/Count '.$nb);
|
| 2289 | 2390 | if($this->DefOrientation=='P') |
| 2290 | 2391 | {
|
| 2291 | 2392 | $w = $this->DefPageSize[0]; |
| 2292 | 2393 | $h = $this->DefPageSize[1]; |
| 2293 | - } |
|
| 2294 | - else |
|
| 2394 | + } else |
|
| 2295 | 2395 | {
|
| 2296 | 2396 | $w = $this->DefPageSize[1]; |
| 2297 | 2397 | $h = $this->DefPageSize[0]; |
@@ -2441,8 +2541,7 @@ discard block |
||
| 2441 | 2541 | {
|
| 2442 | 2542 | $ranges .= sprintf("<%02X> <%02X> <%04X>\n",$c,$c+$v[1]-1,$v[0]);
|
| 2443 | 2543 | $nbr++; |
| 2444 | - } |
|
| 2445 | - else |
|
| 2544 | + } else |
|
| 2446 | 2545 | {
|
| 2447 | 2546 | $chars .= sprintf("<%02X> <%04X>\n",$c,$v);
|
| 2448 | 2547 | $nbc++; |