@@ -175,101 +175,101 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | public function __construct(string $orientation='P', string $unit='mm', $size='A4') |
| 177 | 177 | {
|
| 178 | - // Some checks |
|
| 179 | - $this->_dochecks(); |
|
| 180 | - // Initialization of properties |
|
| 181 | - $this->state = 0; |
|
| 182 | - $this->page = 0; |
|
| 183 | - $this->n = 2; |
|
| 184 | - $this->buffer = ''; |
|
| 185 | - $this->pages = array(); |
|
| 186 | - $this->PageInfo = array(); |
|
| 187 | - $this->fonts = array(); |
|
| 188 | - $this->FontFiles = array(); |
|
| 189 | - $this->encodings = array(); |
|
| 190 | - $this->cmaps = array(); |
|
| 191 | - $this->images = array(); |
|
| 192 | - $this->links = array(); |
|
| 193 | - $this->InHeader = false; |
|
| 194 | - $this->InFooter = false; |
|
| 195 | - $this->lasth = 0; |
|
| 196 | - $this->FontFamily = ''; |
|
| 197 | - $this->FontStyle = ''; |
|
| 198 | - $this->FontSizePt = 12; |
|
| 199 | - $this->underline = false; |
|
| 200 | - $this->DrawColor = '0 G'; |
|
| 201 | - $this->FillColor = '0 g'; |
|
| 202 | - $this->TextColor = '0 g'; |
|
| 203 | - $this->ColorFlag = false; |
|
| 204 | - $this->WithAlpha = false; |
|
| 205 | - $this->ws = 0; |
|
| 206 | - // Font path |
|
| 207 | - if (defined('FPDF_FONTPATH')) {
|
|
| 208 | - $this->fontpath = FPDF_FONTPATH; |
|
| 209 | - if (substr($this->fontpath, -1) != '/' && substr($this->fontpath, -1) != '\\') {
|
|
| 210 | - $this->fontpath .= '/'; |
|
| 211 | - } |
|
| 212 | - } elseif (is_dir(dirname(__FILE__) . '/font')) {
|
|
| 213 | - $this->fontpath = dirname(__FILE__) . '/font/'; |
|
| 214 | - } else {
|
|
| 215 | - $this->fontpath = ''; |
|
| 216 | - } |
|
| 217 | - // Core fonts |
|
| 218 | - $this->CoreFonts = array('courier', 'helvetica', 'times', 'symbol', 'zapfdingbats');
|
|
| 219 | - // Scale factor |
|
| 220 | - if($unit == 'pt') {
|
|
| 221 | - $this->k = 1; |
|
| 222 | - } elseif($unit == 'mm') {
|
|
| 223 | - $this->k = 72/25.4; |
|
| 224 | - } elseif($unit == 'cm') {
|
|
| 225 | - $this->k = 72/2.54; |
|
| 226 | - } elseif($unit == 'in') {
|
|
| 227 | - $this->k = 72; |
|
| 228 | - } else {
|
|
| 229 | - $this->Error('Incorrect unit: ' . $unit);
|
|
| 230 | - } |
|
| 231 | - // Page sizes |
|
| 232 | - $this->StdPageSizes = array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28),
|
|
| 233 | - 'letter'=>array(612,792), 'legal'=>array(612,1008)); |
|
| 234 | - $size = $this->_getpagesize($size); |
|
| 235 | - $this->DefPageSize = $size; |
|
| 236 | - $this->CurPageSize = $size; |
|
| 237 | - // Page orientation |
|
| 238 | - $orientation = strtolower($orientation); |
|
| 239 | - if($orientation=='p' || $orientation=='portrait') |
|
| 240 | - {
|
|
| 241 | - $this->DefOrientation = 'P'; |
|
| 242 | - $this->w = $size[0]; |
|
| 243 | - $this->h = $size[1]; |
|
| 244 | - } |
|
| 245 | - elseif($orientation=='l' || $orientation=='landscape') |
|
| 246 | - {
|
|
| 247 | - $this->DefOrientation = 'L'; |
|
| 248 | - $this->w = $size[1]; |
|
| 249 | - $this->h = $size[0]; |
|
| 250 | - } |
|
| 251 | - else |
|
| 252 | - $this->Error('Incorrect orientation: '.$orientation);
|
|
| 253 | - $this->CurOrientation = $this->DefOrientation; |
|
| 254 | - $this->wPt = $this->w*$this->k; |
|
| 255 | - $this->hPt = $this->h*$this->k; |
|
| 256 | - // Page rotation |
|
| 257 | - $this->CurRotation = 0; |
|
| 258 | - // Page margins (1 cm) |
|
| 259 | - $margin = 28.35/$this->k; |
|
| 260 | - $this->setMargins($margin,$margin); |
|
| 261 | - // Interior cell margin (1 mm) |
|
| 262 | - $this->cMargin = $margin/10; |
|
| 263 | - // Line width (0.2 mm) |
|
| 264 | - $this->LineWidth = .567/$this->k; |
|
| 265 | - // Automatic page break |
|
| 266 | - $this->setAutoPageBreak(true,2*$margin); |
|
| 267 | - // Default display mode |
|
| 268 | - $this->setDisplayMode('default');
|
|
| 269 | - // Enable compression |
|
| 270 | - $this->setCompression(true); |
|
| 271 | - // Set default PDF version number |
|
| 272 | - $this->PDFVersion = '1.3'; |
|
| 178 | + // Some checks |
|
| 179 | + $this->_dochecks(); |
|
| 180 | + // Initialization of properties |
|
| 181 | + $this->state = 0; |
|
| 182 | + $this->page = 0; |
|
| 183 | + $this->n = 2; |
|
| 184 | + $this->buffer = ''; |
|
| 185 | + $this->pages = array(); |
|
| 186 | + $this->PageInfo = array(); |
|
| 187 | + $this->fonts = array(); |
|
| 188 | + $this->FontFiles = array(); |
|
| 189 | + $this->encodings = array(); |
|
| 190 | + $this->cmaps = array(); |
|
| 191 | + $this->images = array(); |
|
| 192 | + $this->links = array(); |
|
| 193 | + $this->InHeader = false; |
|
| 194 | + $this->InFooter = false; |
|
| 195 | + $this->lasth = 0; |
|
| 196 | + $this->FontFamily = ''; |
|
| 197 | + $this->FontStyle = ''; |
|
| 198 | + $this->FontSizePt = 12; |
|
| 199 | + $this->underline = false; |
|
| 200 | + $this->DrawColor = '0 G'; |
|
| 201 | + $this->FillColor = '0 g'; |
|
| 202 | + $this->TextColor = '0 g'; |
|
| 203 | + $this->ColorFlag = false; |
|
| 204 | + $this->WithAlpha = false; |
|
| 205 | + $this->ws = 0; |
|
| 206 | + // Font path |
|
| 207 | + if (defined('FPDF_FONTPATH')) {
|
|
| 208 | + $this->fontpath = FPDF_FONTPATH; |
|
| 209 | + if (substr($this->fontpath, -1) != '/' && substr($this->fontpath, -1) != '\\') {
|
|
| 210 | + $this->fontpath .= '/'; |
|
| 211 | + } |
|
| 212 | + } elseif (is_dir(dirname(__FILE__) . '/font')) {
|
|
| 213 | + $this->fontpath = dirname(__FILE__) . '/font/'; |
|
| 214 | + } else {
|
|
| 215 | + $this->fontpath = ''; |
|
| 216 | + } |
|
| 217 | + // Core fonts |
|
| 218 | + $this->CoreFonts = array('courier', 'helvetica', 'times', 'symbol', 'zapfdingbats');
|
|
| 219 | + // Scale factor |
|
| 220 | + if($unit == 'pt') {
|
|
| 221 | + $this->k = 1; |
|
| 222 | + } elseif($unit == 'mm') {
|
|
| 223 | + $this->k = 72/25.4; |
|
| 224 | + } elseif($unit == 'cm') {
|
|
| 225 | + $this->k = 72/2.54; |
|
| 226 | + } elseif($unit == 'in') {
|
|
| 227 | + $this->k = 72; |
|
| 228 | + } else {
|
|
| 229 | + $this->Error('Incorrect unit: ' . $unit);
|
|
| 230 | + } |
|
| 231 | + // Page sizes |
|
| 232 | + $this->StdPageSizes = array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28),
|
|
| 233 | + 'letter'=>array(612,792), 'legal'=>array(612,1008)); |
|
| 234 | + $size = $this->_getpagesize($size); |
|
| 235 | + $this->DefPageSize = $size; |
|
| 236 | + $this->CurPageSize = $size; |
|
| 237 | + // Page orientation |
|
| 238 | + $orientation = strtolower($orientation); |
|
| 239 | + if($orientation=='p' || $orientation=='portrait') |
|
| 240 | + {
|
|
| 241 | + $this->DefOrientation = 'P'; |
|
| 242 | + $this->w = $size[0]; |
|
| 243 | + $this->h = $size[1]; |
|
| 244 | + } |
|
| 245 | + elseif($orientation=='l' || $orientation=='landscape') |
|
| 246 | + {
|
|
| 247 | + $this->DefOrientation = 'L'; |
|
| 248 | + $this->w = $size[1]; |
|
| 249 | + $this->h = $size[0]; |
|
| 250 | + } |
|
| 251 | + else |
|
| 252 | + $this->Error('Incorrect orientation: '.$orientation);
|
|
| 253 | + $this->CurOrientation = $this->DefOrientation; |
|
| 254 | + $this->wPt = $this->w*$this->k; |
|
| 255 | + $this->hPt = $this->h*$this->k; |
|
| 256 | + // Page rotation |
|
| 257 | + $this->CurRotation = 0; |
|
| 258 | + // Page margins (1 cm) |
|
| 259 | + $margin = 28.35/$this->k; |
|
| 260 | + $this->setMargins($margin,$margin); |
|
| 261 | + // Interior cell margin (1 mm) |
|
| 262 | + $this->cMargin = $margin/10; |
|
| 263 | + // Line width (0.2 mm) |
|
| 264 | + $this->LineWidth = .567/$this->k; |
|
| 265 | + // Automatic page break |
|
| 266 | + $this->setAutoPageBreak(true,2*$margin); |
|
| 267 | + // Default display mode |
|
| 268 | + $this->setDisplayMode('default');
|
|
| 269 | + // Enable compression |
|
| 270 | + $this->setCompression(true); |
|
| 271 | + // Set default PDF version number |
|
| 272 | + $this->PDFVersion = '1.3'; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -281,12 +281,12 @@ discard block |
||
| 281 | 281 | */ |
| 282 | 282 | public function SetMargins(float $left, float $top, ?float $right=null) : void |
| 283 | 283 | {
|
| 284 | - // Set left, top and right margins |
|
| 285 | - $this->lMargin = $left; |
|
| 286 | - $this->tMargin = $top; |
|
| 287 | - if($right===null) |
|
| 288 | - $right = $left; |
|
| 289 | - $this->rMargin = $right; |
|
| 284 | + // Set left, top and right margins |
|
| 285 | + $this->lMargin = $left; |
|
| 286 | + $this->tMargin = $top; |
|
| 287 | + if($right===null) |
|
| 288 | + $right = $left; |
|
| 289 | + $this->rMargin = $right; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -297,10 +297,10 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | public function SetLeftMargin(float $margin) : void |
| 299 | 299 | {
|
| 300 | - // Set left margin |
|
| 301 | - $this->lMargin = $margin; |
|
| 302 | - if($this->page>0 && $this->x<$margin) |
|
| 303 | - $this->x = $margin; |
|
| 300 | + // Set left margin |
|
| 301 | + $this->lMargin = $margin; |
|
| 302 | + if($this->page>0 && $this->x<$margin) |
|
| 303 | + $this->x = $margin; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -310,8 +310,8 @@ discard block |
||
| 310 | 310 | */ |
| 311 | 311 | public function SetTopMargin(float $margin) : void |
| 312 | 312 | {
|
| 313 | - // Set top margin |
|
| 314 | - $this->tMargin = $margin; |
|
| 313 | + // Set top margin |
|
| 314 | + $this->tMargin = $margin; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -321,8 +321,8 @@ discard block |
||
| 321 | 321 | */ |
| 322 | 322 | public function SetRightMargin(float $margin) : void |
| 323 | 323 | {
|
| 324 | - // Set right margin |
|
| 325 | - $this->rMargin = $margin; |
|
| 324 | + // Set right margin |
|
| 325 | + $this->rMargin = $margin; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -335,10 +335,10 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | public function SetAutoPageBreak(bool $auto, float $margin=0) : void |
| 337 | 337 | {
|
| 338 | - // Set auto page break mode and triggering margin |
|
| 339 | - $this->AutoPageBreak = $auto; |
|
| 340 | - $this->bMargin = $margin; |
|
| 341 | - $this->PageBreakTrigger = $this->h-$margin; |
|
| 338 | + // Set auto page break mode and triggering margin |
|
| 339 | + $this->AutoPageBreak = $auto; |
|
| 340 | + $this->bMargin = $margin; |
|
| 341 | + $this->PageBreakTrigger = $this->h-$margin; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -371,15 +371,15 @@ discard block |
||
| 371 | 371 | */ |
| 372 | 372 | public function SetDisplayMode($zoom, string $layout='default') : void |
| 373 | 373 | {
|
| 374 | - // Set display mode in viewer |
|
| 375 | - if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) |
|
| 376 | - $this->ZoomMode = $zoom; |
|
| 377 | - else |
|
| 378 | - $this->Error('Incorrect zoom display mode: '.$zoom);
|
|
| 379 | - if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') |
|
| 380 | - $this->LayoutMode = $layout; |
|
| 381 | - else |
|
| 382 | - $this->Error('Incorrect layout display mode: '.$layout);
|
|
| 374 | + // Set display mode in viewer |
|
| 375 | + if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) |
|
| 376 | + $this->ZoomMode = $zoom; |
|
| 377 | + else |
|
| 378 | + $this->Error('Incorrect zoom display mode: '.$zoom);
|
|
| 379 | + if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') |
|
| 380 | + $this->LayoutMode = $layout; |
|
| 381 | + else |
|
| 382 | + $this->Error('Incorrect layout display mode: '.$layout);
|
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -393,11 +393,11 @@ discard block |
||
| 393 | 393 | */ |
| 394 | 394 | public function SetCompression(bool $compress) : void |
| 395 | 395 | {
|
| 396 | - // Set page compression |
|
| 397 | - if(function_exists('gzcompress'))
|
|
| 398 | - $this->compress = $compress; |
|
| 399 | - else |
|
| 400 | - $this->compress = false; |
|
| 396 | + // Set page compression |
|
| 397 | + if(function_exists('gzcompress'))
|
|
| 398 | + $this->compress = $compress; |
|
| 399 | + else |
|
| 400 | + $this->compress = false; |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | /** |
@@ -407,8 +407,8 @@ discard block |
||
| 407 | 407 | */ |
| 408 | 408 | public function SetTitle(string $title, bool $isUTF8=false) : void |
| 409 | 409 | {
|
| 410 | - // Title of document |
|
| 411 | - $this->metadata['Title'] = $isUTF8 ? $title : utf8_encode($title); |
|
| 410 | + // Title of document |
|
| 411 | + $this->metadata['Title'] = $isUTF8 ? $title : utf8_encode($title); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | /** |
@@ -418,8 +418,8 @@ discard block |
||
| 418 | 418 | */ |
| 419 | 419 | public function SetAuthor(string $author, bool $isUTF8=false) : void |
| 420 | 420 | {
|
| 421 | - // Author of document |
|
| 422 | - $this->metadata['Author'] = $isUTF8 ? $author : utf8_encode($author); |
|
| 421 | + // Author of document |
|
| 422 | + $this->metadata['Author'] = $isUTF8 ? $author : utf8_encode($author); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | /** |
@@ -429,8 +429,8 @@ discard block |
||
| 429 | 429 | */ |
| 430 | 430 | public function SetSubject(string $subject, bool $isUTF8=false) : void |
| 431 | 431 | {
|
| 432 | - // Subject of document |
|
| 433 | - $this->metadata['Subject'] = $isUTF8 ? $subject : utf8_encode($subject); |
|
| 432 | + // Subject of document |
|
| 433 | + $this->metadata['Subject'] = $isUTF8 ? $subject : utf8_encode($subject); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -440,8 +440,8 @@ discard block |
||
| 440 | 440 | */ |
| 441 | 441 | public function SetKeywords(string $keywords, bool $isUTF8=false) : void |
| 442 | 442 | {
|
| 443 | - // Keywords of document |
|
| 444 | - $this->metadata['Keywords'] = $isUTF8 ? $keywords : utf8_encode($keywords); |
|
| 443 | + // Keywords of document |
|
| 444 | + $this->metadata['Keywords'] = $isUTF8 ? $keywords : utf8_encode($keywords); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
@@ -451,8 +451,8 @@ discard block |
||
| 451 | 451 | */ |
| 452 | 452 | public function SetCreator(string $creator, bool $isUTF8=false) : void |
| 453 | 453 | {
|
| 454 | - // Creator of document |
|
| 455 | - $this->metadata['Creator'] = $isUTF8 ? $creator : utf8_encode($creator); |
|
| 454 | + // Creator of document |
|
| 455 | + $this->metadata['Creator'] = $isUTF8 ? $creator : utf8_encode($creator); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | /** |
@@ -461,8 +461,8 @@ discard block |
||
| 461 | 461 | */ |
| 462 | 462 | public function AliasNbPages(string $alias='{nb}') : void
|
| 463 | 463 | {
|
| 464 | - // Define an alias for total number of pages |
|
| 465 | - $this->AliasNbPages = $alias; |
|
| 464 | + // Define an alias for total number of pages |
|
| 465 | + $this->AliasNbPages = $alias; |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
@@ -475,8 +475,8 @@ discard block |
||
| 475 | 475 | */ |
| 476 | 476 | public function Error(string $msg) : void |
| 477 | 477 | {
|
| 478 | - // Fatal error |
|
| 479 | - throw new \Exception('FPDF error: '.$msg);
|
|
| 478 | + // Fatal error |
|
| 479 | + throw new \Exception('FPDF error: '.$msg);
|
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | /** |
@@ -487,19 +487,19 @@ discard block |
||
| 487 | 487 | */ |
| 488 | 488 | public function Close() : void |
| 489 | 489 | {
|
| 490 | - // Terminate document |
|
| 491 | - if($this->state==3) |
|
| 492 | - return; |
|
| 493 | - if($this->page==0) |
|
| 494 | - $this->addPage(); |
|
| 495 | - // Page footer |
|
| 496 | - $this->InFooter = true; |
|
| 497 | - $this->Footer(); |
|
| 498 | - $this->InFooter = false; |
|
| 499 | - // Close page |
|
| 500 | - $this->_endpage(); |
|
| 501 | - // Close document |
|
| 502 | - $this->_enddoc(); |
|
| 490 | + // Terminate document |
|
| 491 | + if($this->state==3) |
|
| 492 | + return; |
|
| 493 | + if($this->page==0) |
|
| 494 | + $this->addPage(); |
|
| 495 | + // Page footer |
|
| 496 | + $this->InFooter = true; |
|
| 497 | + $this->Footer(); |
|
| 498 | + $this->InFooter = false; |
|
| 499 | + // Close page |
|
| 500 | + $this->_endpage(); |
|
| 501 | + // Close document |
|
| 502 | + $this->_enddoc(); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | /** |
@@ -532,71 +532,71 @@ discard block |
||
| 532 | 532 | */ |
| 533 | 533 | public function AddPage(string $orientation='', $size='', int $rotation=0) : void |
| 534 | 534 | {
|
| 535 | - // Start a new page |
|
| 536 | - if($this->state==3) |
|
| 537 | - $this->Error('The document is closed');
|
|
| 538 | - $family = $this->FontFamily; |
|
| 539 | - $style = $this->FontStyle.($this->underline ? 'U' : ''); |
|
| 540 | - $fontsize = $this->FontSizePt; |
|
| 541 | - $lw = $this->LineWidth; |
|
| 542 | - $dc = $this->DrawColor; |
|
| 543 | - $fc = $this->FillColor; |
|
| 544 | - $tc = $this->TextColor; |
|
| 545 | - $cf = $this->ColorFlag; |
|
| 546 | - if($this->page>0) |
|
| 547 | - {
|
|
| 548 | - // Page footer |
|
| 549 | - $this->InFooter = true; |
|
| 550 | - $this->Footer(); |
|
| 551 | - $this->InFooter = false; |
|
| 552 | - // Close page |
|
| 553 | - $this->_endpage(); |
|
| 554 | - } |
|
| 555 | - // Start new page |
|
| 556 | - $this->_beginpage($orientation,$size,$rotation); |
|
| 557 | - // Set line cap style to square |
|
| 558 | - $this->_out('2 J');
|
|
| 559 | - // Set line width |
|
| 560 | - $this->LineWidth = $lw; |
|
| 561 | - $this->_out(sprintf('%.2F w',$lw*$this->k));
|
|
| 562 | - // Set font |
|
| 563 | - if($family) |
|
| 564 | - $this->setFont($family,$style,$fontsize); |
|
| 565 | - // Set colors |
|
| 566 | - $this->DrawColor = $dc; |
|
| 567 | - if($dc!='0 G') |
|
| 568 | - $this->_out($dc); |
|
| 569 | - $this->FillColor = $fc; |
|
| 570 | - if($fc!='0 g') |
|
| 571 | - $this->_out($fc); |
|
| 572 | - $this->TextColor = $tc; |
|
| 573 | - $this->ColorFlag = $cf; |
|
| 574 | - // Page header |
|
| 575 | - $this->InHeader = true; |
|
| 576 | - $this->Header(); |
|
| 577 | - $this->InHeader = false; |
|
| 578 | - // Restore line width |
|
| 579 | - if($this->LineWidth!=$lw) |
|
| 580 | - {
|
|
| 581 | - $this->LineWidth = $lw; |
|
| 582 | - $this->_out(sprintf('%.2F w',$lw*$this->k));
|
|
| 583 | - } |
|
| 584 | - // Restore font |
|
| 585 | - if($family) |
|
| 586 | - $this->setFont($family,$style,$fontsize); |
|
| 587 | - // Restore colors |
|
| 588 | - if($this->DrawColor!=$dc) |
|
| 589 | - {
|
|
| 590 | - $this->DrawColor = $dc; |
|
| 591 | - $this->_out($dc); |
|
| 592 | - } |
|
| 593 | - if($this->FillColor!=$fc) |
|
| 594 | - {
|
|
| 595 | - $this->FillColor = $fc; |
|
| 596 | - $this->_out($fc); |
|
| 597 | - } |
|
| 598 | - $this->TextColor = $tc; |
|
| 599 | - $this->ColorFlag = $cf; |
|
| 535 | + // Start a new page |
|
| 536 | + if($this->state==3) |
|
| 537 | + $this->Error('The document is closed');
|
|
| 538 | + $family = $this->FontFamily; |
|
| 539 | + $style = $this->FontStyle.($this->underline ? 'U' : ''); |
|
| 540 | + $fontsize = $this->FontSizePt; |
|
| 541 | + $lw = $this->LineWidth; |
|
| 542 | + $dc = $this->DrawColor; |
|
| 543 | + $fc = $this->FillColor; |
|
| 544 | + $tc = $this->TextColor; |
|
| 545 | + $cf = $this->ColorFlag; |
|
| 546 | + if($this->page>0) |
|
| 547 | + {
|
|
| 548 | + // Page footer |
|
| 549 | + $this->InFooter = true; |
|
| 550 | + $this->Footer(); |
|
| 551 | + $this->InFooter = false; |
|
| 552 | + // Close page |
|
| 553 | + $this->_endpage(); |
|
| 554 | + } |
|
| 555 | + // Start new page |
|
| 556 | + $this->_beginpage($orientation,$size,$rotation); |
|
| 557 | + // Set line cap style to square |
|
| 558 | + $this->_out('2 J');
|
|
| 559 | + // Set line width |
|
| 560 | + $this->LineWidth = $lw; |
|
| 561 | + $this->_out(sprintf('%.2F w',$lw*$this->k));
|
|
| 562 | + // Set font |
|
| 563 | + if($family) |
|
| 564 | + $this->setFont($family,$style,$fontsize); |
|
| 565 | + // Set colors |
|
| 566 | + $this->DrawColor = $dc; |
|
| 567 | + if($dc!='0 G') |
|
| 568 | + $this->_out($dc); |
|
| 569 | + $this->FillColor = $fc; |
|
| 570 | + if($fc!='0 g') |
|
| 571 | + $this->_out($fc); |
|
| 572 | + $this->TextColor = $tc; |
|
| 573 | + $this->ColorFlag = $cf; |
|
| 574 | + // Page header |
|
| 575 | + $this->InHeader = true; |
|
| 576 | + $this->Header(); |
|
| 577 | + $this->InHeader = false; |
|
| 578 | + // Restore line width |
|
| 579 | + if($this->LineWidth!=$lw) |
|
| 580 | + {
|
|
| 581 | + $this->LineWidth = $lw; |
|
| 582 | + $this->_out(sprintf('%.2F w',$lw*$this->k));
|
|
| 583 | + } |
|
| 584 | + // Restore font |
|
| 585 | + if($family) |
|
| 586 | + $this->setFont($family,$style,$fontsize); |
|
| 587 | + // Restore colors |
|
| 588 | + if($this->DrawColor!=$dc) |
|
| 589 | + {
|
|
| 590 | + $this->DrawColor = $dc; |
|
| 591 | + $this->_out($dc); |
|
| 592 | + } |
|
| 593 | + if($this->FillColor!=$fc) |
|
| 594 | + {
|
|
| 595 | + $this->FillColor = $fc; |
|
| 596 | + $this->_out($fc); |
|
| 597 | + } |
|
| 598 | + $this->TextColor = $tc; |
|
| 599 | + $this->ColorFlag = $cf; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | /** |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | */ |
| 608 | 608 | public function Header() : void |
| 609 | 609 | {
|
| 610 | - // To be implemented in your own inherited class |
|
| 610 | + // To be implemented in your own inherited class |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -618,7 +618,7 @@ discard block |
||
| 618 | 618 | */ |
| 619 | 619 | public function Footer() : void |
| 620 | 620 | {
|
| 621 | - // To be implemented in your own inherited class |
|
| 621 | + // To be implemented in your own inherited class |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | /** |
@@ -627,8 +627,8 @@ discard block |
||
| 627 | 627 | */ |
| 628 | 628 | public function PageNo() : int |
| 629 | 629 | {
|
| 630 | - // Get current page number |
|
| 631 | - return $this->page; |
|
| 630 | + // Get current page number |
|
| 631 | + return $this->page; |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | /** |
@@ -641,14 +641,14 @@ discard block |
||
| 641 | 641 | */ |
| 642 | 642 | public function SetDrawColor(int $r, ?int $g=null, ?int $b=null) : void |
| 643 | 643 | {
|
| 644 | - // Set color for all stroking operations |
|
| 644 | + // Set color for all stroking operations |
|
| 645 | 645 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) {
|
| 646 | - $this->DrawColor = sprintf('%.3F G', $r / 255);
|
|
| 646 | + $this->DrawColor = sprintf('%.3F G', $r / 255);
|
|
| 647 | 647 | } else {
|
| 648 | - $this->DrawColor = sprintf('%.3F %.3F %.3F RG', $r / 255, $g / 255, $b / 255);
|
|
| 648 | + $this->DrawColor = sprintf('%.3F %.3F %.3F RG', $r / 255, $g / 255, $b / 255);
|
|
| 649 | 649 | } |
| 650 | 650 | if ($this->page > 0) {
|
| 651 | - $this->_out($this->DrawColor); |
|
| 651 | + $this->_out($this->DrawColor); |
|
| 652 | 652 | } |
| 653 | 653 | } |
| 654 | 654 | |
@@ -662,16 +662,16 @@ discard block |
||
| 662 | 662 | */ |
| 663 | 663 | public function SetFillColor(int $r, ?int $g=null, ?int $b=null) : void |
| 664 | 664 | {
|
| 665 | - // Set color for all filling operations |
|
| 665 | + // Set color for all filling operations |
|
| 666 | 666 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) {
|
| 667 | - $this->FillColor = sprintf('%.3F g', $r / 255);
|
|
| 667 | + $this->FillColor = sprintf('%.3F g', $r / 255);
|
|
| 668 | 668 | } else {
|
| 669 | - $this->FillColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255);
|
|
| 669 | + $this->FillColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255);
|
|
| 670 | + } |
|
| 671 | + $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
| 672 | + if ($this->page > 0) {
|
|
| 673 | + $this->_out($this->FillColor); |
|
| 670 | 674 | } |
| 671 | - $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
| 672 | - if ($this->page > 0) {
|
|
| 673 | - $this->_out($this->FillColor); |
|
| 674 | - } |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | /** |
@@ -684,13 +684,13 @@ discard block |
||
| 684 | 684 | */ |
| 685 | 685 | public function SetTextColor(int $r, ?int $g=null, ?int $b=null) : void |
| 686 | 686 | {
|
| 687 | - // Set color for text |
|
| 687 | + // Set color for text |
|
| 688 | 688 | if (($r === 0 && $g === 0 && $b === 0) || $g === null) {
|
| 689 | - $this->TextColor = sprintf('%.3F g', $r / 255);
|
|
| 689 | + $this->TextColor = sprintf('%.3F g', $r / 255);
|
|
| 690 | 690 | } else {
|
| 691 | - $this->TextColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255);
|
|
| 691 | + $this->TextColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255);
|
|
| 692 | 692 | } |
| 693 | - $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
| 693 | + $this->ColorFlag = ($this->FillColor != $this->TextColor); |
|
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | /** |
@@ -701,14 +701,14 @@ discard block |
||
| 701 | 701 | */ |
| 702 | 702 | public function GetStringWidth(string $s) : float |
| 703 | 703 | {
|
| 704 | - // Get width of a string in the current font |
|
| 705 | - $s = (string)$s; |
|
| 706 | - $cw = &$this->CurrentFont['cw']; |
|
| 707 | - $w = 0; |
|
| 708 | - $l = strlen($s); |
|
| 709 | - for($i=0;$i<$l;$i++) |
|
| 710 | - $w += $cw[$s[$i]]; |
|
| 711 | - return $w*$this->FontSize/1000; |
|
| 704 | + // Get width of a string in the current font |
|
| 705 | + $s = (string)$s; |
|
| 706 | + $cw = &$this->CurrentFont['cw']; |
|
| 707 | + $w = 0; |
|
| 708 | + $l = strlen($s); |
|
| 709 | + for($i=0;$i<$l;$i++) |
|
| 710 | + $w += $cw[$s[$i]]; |
|
| 711 | + return $w*$this->FontSize/1000; |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | /** |
@@ -719,10 +719,10 @@ discard block |
||
| 719 | 719 | */ |
| 720 | 720 | public function SetLineWidth(float $width) : void |
| 721 | 721 | {
|
| 722 | - // Set line width |
|
| 723 | - $this->LineWidth = $width; |
|
| 724 | - if($this->page>0) |
|
| 725 | - $this->_out(sprintf('%.2F w',$width*$this->k));
|
|
| 722 | + // Set line width |
|
| 723 | + $this->LineWidth = $width; |
|
| 724 | + if($this->page>0) |
|
| 725 | + $this->_out(sprintf('%.2F w',$width*$this->k));
|
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | /** |
@@ -736,8 +736,8 @@ discard block |
||
| 736 | 736 | */ |
| 737 | 737 | public function Line(float $x1, float $y1, float $x2, float $y2) : void |
| 738 | 738 | {
|
| 739 | - // Draw a line |
|
| 740 | - $this->_out(sprintf('%.2F %.2F m %.2F %.2F l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k));
|
|
| 739 | + // Draw a line |
|
| 740 | + $this->_out(sprintf('%.2F %.2F m %.2F %.2F l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k));
|
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | /** |
@@ -757,14 +757,14 @@ discard block |
||
| 757 | 757 | */ |
| 758 | 758 | public function Rect(float $x, float $y, float $w, float $h, string $style='') : void |
| 759 | 759 | {
|
| 760 | - // Draw a rectangle |
|
| 761 | - if($style=='F') |
|
| 762 | - $op = 'f'; |
|
| 763 | - elseif($style=='FD' || $style=='DF') |
|
| 764 | - $op = 'B'; |
|
| 765 | - else |
|
| 766 | - $op = 'S'; |
|
| 767 | - $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
|
|
| 760 | + // Draw a rectangle |
|
| 761 | + if($style=='F') |
|
| 762 | + $op = 'f'; |
|
| 763 | + elseif($style=='FD' || $style=='DF') |
|
| 764 | + $op = 'B'; |
|
| 765 | + else |
|
| 766 | + $op = 'S'; |
|
| 767 | + $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
|
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
@@ -786,27 +786,27 @@ discard block |
||
| 786 | 786 | */ |
| 787 | 787 | public function AddFont(string $family, string $style='', string $file='') : void |
| 788 | 788 | {
|
| 789 | - // Add a TrueType, OpenType or Type1 font |
|
| 790 | - $family = strtolower($family); |
|
| 791 | - if($file=='') |
|
| 792 | - $file = str_replace(' ','',$family).strtolower($style).'.php';
|
|
| 793 | - $style = strtoupper($style); |
|
| 794 | - if($style=='IB') |
|
| 795 | - $style = 'BI'; |
|
| 796 | - $fontkey = $family.$style; |
|
| 797 | - if(isset($this->fonts[$fontkey])) |
|
| 798 | - return; |
|
| 799 | - $info = $this->_loadfont($file); |
|
| 800 | - $info['i'] = count($this->fonts)+1; |
|
| 801 | - if(!empty($info['file'])) |
|
| 802 | - {
|
|
| 803 | - // Embedded font |
|
| 804 | - if($info['type']=='TrueType') |
|
| 805 | - $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']);
|
|
| 806 | - else |
|
| 807 | - $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']);
|
|
| 808 | - } |
|
| 809 | - $this->fonts[$fontkey] = $info; |
|
| 789 | + // Add a TrueType, OpenType or Type1 font |
|
| 790 | + $family = strtolower($family); |
|
| 791 | + if($file=='') |
|
| 792 | + $file = str_replace(' ','',$family).strtolower($style).'.php';
|
|
| 793 | + $style = strtoupper($style); |
|
| 794 | + if($style=='IB') |
|
| 795 | + $style = 'BI'; |
|
| 796 | + $fontkey = $family.$style; |
|
| 797 | + if(isset($this->fonts[$fontkey])) |
|
| 798 | + return; |
|
| 799 | + $info = $this->_loadfont($file); |
|
| 800 | + $info['i'] = count($this->fonts)+1; |
|
| 801 | + if(!empty($info['file'])) |
|
| 802 | + {
|
|
| 803 | + // Embedded font |
|
| 804 | + if($info['type']=='TrueType') |
|
| 805 | + $this->FontFiles[$info['file']] = array('length1'=>$info['originalsize']);
|
|
| 806 | + else |
|
| 807 | + $this->FontFiles[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']);
|
|
| 808 | + } |
|
| 809 | + $this->fonts[$fontkey] = $info; |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | /** |
@@ -846,52 +846,52 @@ discard block |
||
| 846 | 846 | */ |
| 847 | 847 | public function SetFont(string $family, string $style='', float $size=0) : void |
| 848 | 848 | {
|
| 849 | - // Select a font; size given in points |
|
| 850 | - if($family=='') |
|
| 851 | - $family = $this->FontFamily; |
|
| 852 | - else |
|
| 853 | - $family = strtolower($family); |
|
| 854 | - $style = strtoupper($style); |
|
| 855 | - if(strpos($style,'U')!==false) |
|
| 856 | - {
|
|
| 857 | - $this->underline = true; |
|
| 858 | - $style = str_replace('U','',$style);
|
|
| 859 | - } |
|
| 860 | - else |
|
| 861 | - $this->underline = false; |
|
| 862 | - if($style=='IB') |
|
| 863 | - $style = 'BI'; |
|
| 864 | - if($size==0) |
|
| 865 | - $size = $this->FontSizePt; |
|
| 866 | - // Test if font is already selected |
|
| 867 | - if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) |
|
| 868 | - return; |
|
| 869 | - // Test if font is already loaded |
|
| 870 | - $fontkey = $family.$style; |
|
| 871 | - if(!isset($this->fonts[$fontkey])) |
|
| 872 | - {
|
|
| 873 | - // Test if one of the core fonts |
|
| 874 | - if($family=='arial') |
|
| 875 | - $family = 'helvetica'; |
|
| 876 | - if(in_array($family,$this->CoreFonts)) |
|
| 877 | - {
|
|
| 878 | - if($family=='symbol' || $family=='zapfdingbats') |
|
| 879 | - $style = ''; |
|
| 880 | - $fontkey = $family.$style; |
|
| 881 | - if(!isset($this->fonts[$fontkey])) |
|
| 882 | - $this->addFont($family,$style); |
|
| 883 | - } |
|
| 884 | - else |
|
| 885 | - $this->Error('Undefined font: '.$family.' '.$style);
|
|
| 886 | - } |
|
| 887 | - // Select it |
|
| 888 | - $this->FontFamily = $family; |
|
| 889 | - $this->FontStyle = $style; |
|
| 890 | - $this->FontSizePt = $size; |
|
| 891 | - $this->FontSize = $size/$this->k; |
|
| 892 | - $this->CurrentFont = &$this->fonts[$fontkey]; |
|
| 893 | - if($this->page>0) |
|
| 894 | - $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
|
|
| 849 | + // Select a font; size given in points |
|
| 850 | + if($family=='') |
|
| 851 | + $family = $this->FontFamily; |
|
| 852 | + else |
|
| 853 | + $family = strtolower($family); |
|
| 854 | + $style = strtoupper($style); |
|
| 855 | + if(strpos($style,'U')!==false) |
|
| 856 | + {
|
|
| 857 | + $this->underline = true; |
|
| 858 | + $style = str_replace('U','',$style);
|
|
| 859 | + } |
|
| 860 | + else |
|
| 861 | + $this->underline = false; |
|
| 862 | + if($style=='IB') |
|
| 863 | + $style = 'BI'; |
|
| 864 | + if($size==0) |
|
| 865 | + $size = $this->FontSizePt; |
|
| 866 | + // Test if font is already selected |
|
| 867 | + if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) |
|
| 868 | + return; |
|
| 869 | + // Test if font is already loaded |
|
| 870 | + $fontkey = $family.$style; |
|
| 871 | + if(!isset($this->fonts[$fontkey])) |
|
| 872 | + {
|
|
| 873 | + // Test if one of the core fonts |
|
| 874 | + if($family=='arial') |
|
| 875 | + $family = 'helvetica'; |
|
| 876 | + if(in_array($family,$this->CoreFonts)) |
|
| 877 | + {
|
|
| 878 | + if($family=='symbol' || $family=='zapfdingbats') |
|
| 879 | + $style = ''; |
|
| 880 | + $fontkey = $family.$style; |
|
| 881 | + if(!isset($this->fonts[$fontkey])) |
|
| 882 | + $this->addFont($family,$style); |
|
| 883 | + } |
|
| 884 | + else |
|
| 885 | + $this->Error('Undefined font: '.$family.' '.$style);
|
|
| 886 | + } |
|
| 887 | + // Select it |
|
| 888 | + $this->FontFamily = $family; |
|
| 889 | + $this->FontStyle = $style; |
|
| 890 | + $this->FontSizePt = $size; |
|
| 891 | + $this->FontSize = $size/$this->k; |
|
| 892 | + $this->CurrentFont = &$this->fonts[$fontkey]; |
|
| 893 | + if($this->page>0) |
|
| 894 | + $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
|
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | /** |
@@ -900,13 +900,13 @@ discard block |
||
| 900 | 900 | */ |
| 901 | 901 | public function SetFontSize(float $size) : void |
| 902 | 902 | {
|
| 903 | - // Set font size in points |
|
| 904 | - if($this->FontSizePt==$size) |
|
| 905 | - return; |
|
| 906 | - $this->FontSizePt = $size; |
|
| 907 | - $this->FontSize = $size/$this->k; |
|
| 908 | - if($this->page>0) |
|
| 909 | - $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
|
|
| 903 | + // Set font size in points |
|
| 904 | + if($this->FontSizePt==$size) |
|
| 905 | + return; |
|
| 906 | + $this->FontSizePt = $size; |
|
| 907 | + $this->FontSize = $size/$this->k; |
|
| 908 | + if($this->page>0) |
|
| 909 | + $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
|
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | /** |
@@ -918,10 +918,10 @@ discard block |
||
| 918 | 918 | */ |
| 919 | 919 | public function AddLink() : int |
| 920 | 920 | {
|
| 921 | - // Create a new internal link |
|
| 922 | - $n = count($this->links)+1; |
|
| 923 | - $this->links[$n] = array(0, 0); |
|
| 924 | - return $n; |
|
| 921 | + // Create a new internal link |
|
| 922 | + $n = count($this->links)+1; |
|
| 923 | + $this->links[$n] = array(0, 0); |
|
| 924 | + return $n; |
|
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | /** |
@@ -932,12 +932,12 @@ discard block |
||
| 932 | 932 | */ |
| 933 | 933 | public function SetLink(int $link, float $y=0, int $page=-1) : void |
| 934 | 934 | {
|
| 935 | - // Set destination of internal link |
|
| 936 | - if($y==-1) |
|
| 937 | - $y = $this->y; |
|
| 938 | - if($page==-1) |
|
| 939 | - $page = $this->page; |
|
| 940 | - $this->links[$link] = array($page, $y); |
|
| 935 | + // Set destination of internal link |
|
| 936 | + if($y==-1) |
|
| 937 | + $y = $this->y; |
|
| 938 | + if($page==-1) |
|
| 939 | + $page = $this->page; |
|
| 940 | + $this->links[$link] = array($page, $y); |
|
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | /** |
@@ -953,8 +953,8 @@ discard block |
||
| 953 | 953 | */ |
| 954 | 954 | public function Link(float $x, float $y, float $w, float $h, $link) : void |
| 955 | 955 | {
|
| 956 | - // Put a link on the page |
|
| 957 | - $this->PageLinks[$this->page][] = array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link); |
|
| 956 | + // Put a link on the page |
|
| 957 | + $this->PageLinks[$this->page][] = array($x*$this->k, $this->hPt-$y*$this->k, $w*$this->k, $h*$this->k, $link); |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | /** |
@@ -969,15 +969,15 @@ discard block |
||
| 969 | 969 | */ |
| 970 | 970 | public function Text(float $x, float $y, string $txt) : void |
| 971 | 971 | {
|
| 972 | - // Output a string |
|
| 973 | - if(!isset($this->CurrentFont)) |
|
| 974 | - $this->Error('No font has been set');
|
|
| 975 | - $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
|
|
| 976 | - if($this->underline && $txt!='') |
|
| 977 | - $s .= ' '.$this->_dounderline($x,$y,$txt); |
|
| 978 | - if($this->ColorFlag) |
|
| 979 | - $s = 'q '.$this->TextColor.' '.$s.' Q'; |
|
| 980 | - $this->_out($s); |
|
| 972 | + // Output a string |
|
| 973 | + if(!isset($this->CurrentFont)) |
|
| 974 | + $this->Error('No font has been set');
|
|
| 975 | + $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
|
|
| 976 | + if($this->underline && $txt!='') |
|
| 977 | + $s .= ' '.$this->_dounderline($x,$y,$txt); |
|
| 978 | + if($this->ColorFlag) |
|
| 979 | + $s = 'q '.$this->TextColor.' '.$s.' Q'; |
|
| 980 | + $this->_out($s); |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | /** |
@@ -993,8 +993,8 @@ discard block |
||
| 993 | 993 | */ |
| 994 | 994 | public function AcceptPageBreak() : bool |
| 995 | 995 | {
|
| 996 | - // Accept automatic page break or not |
|
| 997 | - return $this->AutoPageBreak; |
|
| 996 | + // Accept automatic page break or not |
|
| 997 | + return $this->AutoPageBreak; |
|
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | 1000 | /** |
@@ -1036,82 +1036,82 @@ discard block |
||
| 1036 | 1036 | */ |
| 1037 | 1037 | public function Cell(float $w, float $h=0, string $txt='', $border=0, float $ln=0, $align='', $fill=false, $link='') : void |
| 1038 | 1038 | {
|
| 1039 | - // Output a cell |
|
| 1040 | - $k = $this->k; |
|
| 1041 | - if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
| 1042 | - {
|
|
| 1043 | - // Automatic page break |
|
| 1044 | - $x = $this->x; |
|
| 1045 | - $ws = $this->ws; |
|
| 1046 | - if($ws>0) |
|
| 1047 | - {
|
|
| 1048 | - $this->ws = 0; |
|
| 1049 | - $this->_out('0 Tw');
|
|
| 1050 | - } |
|
| 1051 | - $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
| 1052 | - $this->x = $x; |
|
| 1053 | - if($ws>0) |
|
| 1054 | - {
|
|
| 1055 | - $this->ws = $ws; |
|
| 1056 | - $this->_out(sprintf('%.3F Tw',$ws*$k));
|
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - if($w==0) |
|
| 1060 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1061 | - $s = ''; |
|
| 1062 | - if($fill || $border==1) |
|
| 1063 | - {
|
|
| 1064 | - if($fill) |
|
| 1065 | - $op = ($border==1) ? 'B' : 'f'; |
|
| 1066 | - else |
|
| 1067 | - $op = 'S'; |
|
| 1068 | - $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);
|
|
| 1069 | - } |
|
| 1070 | - if(is_string($border)) |
|
| 1071 | - {
|
|
| 1072 | - $x = $this->x; |
|
| 1073 | - $y = $this->y; |
|
| 1074 | - if(strpos($border,'L')!==false) |
|
| 1075 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
|
|
| 1076 | - if(strpos($border,'T')!==false) |
|
| 1077 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
|
|
| 1078 | - if(strpos($border,'R')!==false) |
|
| 1079 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
|
|
| 1080 | - if(strpos($border,'B')!==false) |
|
| 1081 | - $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
|
|
| 1082 | - } |
|
| 1083 | - if($txt!=='') |
|
| 1084 | - {
|
|
| 1085 | - if(!isset($this->CurrentFont)) |
|
| 1086 | - $this->Error('No font has been set');
|
|
| 1087 | - if($align=='R') |
|
| 1088 | - $dx = $w-$this->cMargin-$this->getStringWidth($txt); |
|
| 1089 | - elseif($align=='C') |
|
| 1090 | - $dx = ($w-$this->getStringWidth($txt))/2; |
|
| 1091 | - else |
|
| 1092 | - $dx = $this->cMargin; |
|
| 1093 | - if($this->ColorFlag) |
|
| 1094 | - $s .= 'q '.$this->TextColor.' '; |
|
| 1095 | - $s .= sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$this->_escape($txt));
|
|
| 1096 | - if($this->underline) |
|
| 1097 | - $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); |
|
| 1098 | - if($this->ColorFlag) |
|
| 1099 | - $s .= ' Q'; |
|
| 1100 | - if($link) |
|
| 1101 | - $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->getStringWidth($txt),$this->FontSize,$link); |
|
| 1102 | - } |
|
| 1103 | - if($s) |
|
| 1104 | - $this->_out($s); |
|
| 1105 | - $this->lasth = $h; |
|
| 1106 | - if($ln>0) |
|
| 1107 | - {
|
|
| 1108 | - // Go to next line |
|
| 1109 | - $this->y += $h; |
|
| 1110 | - if($ln==1) |
|
| 1111 | - $this->x = $this->lMargin; |
|
| 1112 | - } |
|
| 1113 | - else |
|
| 1114 | - $this->x += $w; |
|
| 1039 | + // Output a cell |
|
| 1040 | + $k = $this->k; |
|
| 1041 | + if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
| 1042 | + {
|
|
| 1043 | + // Automatic page break |
|
| 1044 | + $x = $this->x; |
|
| 1045 | + $ws = $this->ws; |
|
| 1046 | + if($ws>0) |
|
| 1047 | + {
|
|
| 1048 | + $this->ws = 0; |
|
| 1049 | + $this->_out('0 Tw');
|
|
| 1050 | + } |
|
| 1051 | + $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
| 1052 | + $this->x = $x; |
|
| 1053 | + if($ws>0) |
|
| 1054 | + {
|
|
| 1055 | + $this->ws = $ws; |
|
| 1056 | + $this->_out(sprintf('%.3F Tw',$ws*$k));
|
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + if($w==0) |
|
| 1060 | + $w = $this->w-$this->rMargin-$this->x; |
|
| 1061 | + $s = ''; |
|
| 1062 | + if($fill || $border==1) |
|
| 1063 | + {
|
|
| 1064 | + if($fill) |
|
| 1065 | + $op = ($border==1) ? 'B' : 'f'; |
|
| 1066 | + else |
|
| 1067 | + $op = 'S'; |
|
| 1068 | + $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);
|
|
| 1069 | + } |
|
| 1070 | + if(is_string($border)) |
|
| 1071 | + {
|
|
| 1072 | + $x = $this->x; |
|
| 1073 | + $y = $this->y; |
|
| 1074 | + if(strpos($border,'L')!==false) |
|
| 1075 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
|
|
| 1076 | + if(strpos($border,'T')!==false) |
|
| 1077 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
|
|
| 1078 | + if(strpos($border,'R')!==false) |
|
| 1079 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
|
|
| 1080 | + if(strpos($border,'B')!==false) |
|
| 1081 | + $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
|
|
| 1082 | + } |
|
| 1083 | + if($txt!=='') |
|
| 1084 | + {
|
|
| 1085 | + if(!isset($this->CurrentFont)) |
|
| 1086 | + $this->Error('No font has been set');
|
|
| 1087 | + if($align=='R') |
|
| 1088 | + $dx = $w-$this->cMargin-$this->getStringWidth($txt); |
|
| 1089 | + elseif($align=='C') |
|
| 1090 | + $dx = ($w-$this->getStringWidth($txt))/2; |
|
| 1091 | + else |
|
| 1092 | + $dx = $this->cMargin; |
|
| 1093 | + if($this->ColorFlag) |
|
| 1094 | + $s .= 'q '.$this->TextColor.' '; |
|
| 1095 | + $s .= sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$this->_escape($txt));
|
|
| 1096 | + if($this->underline) |
|
| 1097 | + $s .= ' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); |
|
| 1098 | + if($this->ColorFlag) |
|
| 1099 | + $s .= ' Q'; |
|
| 1100 | + if($link) |
|
| 1101 | + $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->getStringWidth($txt),$this->FontSize,$link); |
|
| 1102 | + } |
|
| 1103 | + if($s) |
|
| 1104 | + $this->_out($s); |
|
| 1105 | + $this->lasth = $h; |
|
| 1106 | + if($ln>0) |
|
| 1107 | + {
|
|
| 1108 | + // Go to next line |
|
| 1109 | + $this->y += $h; |
|
| 1110 | + if($ln==1) |
|
| 1111 | + $this->x = $this->lMargin; |
|
| 1112 | + } |
|
| 1113 | + else |
|
| 1114 | + $this->x += $w; |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | /** |
@@ -1144,119 +1144,119 @@ discard block |
||
| 1144 | 1144 | */ |
| 1145 | 1145 | public function MultiCell(float $w, float $h, string $txt, $border=0, string $align='J', bool $fill=false) : void |
| 1146 | 1146 | {
|
| 1147 | - // Output text with automatic or explicit line breaks |
|
| 1148 | - if(!isset($this->CurrentFont)) |
|
| 1149 | - $this->Error('No font has been set');
|
|
| 1150 | - $cw = &$this->CurrentFont['cw']; |
|
| 1151 | - if($w==0) |
|
| 1152 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1153 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1154 | - $s = str_replace("\r",'',$txt);
|
|
| 1155 | - $nb = strlen($s); |
|
| 1156 | - if($nb>0 && $s[$nb-1]=="\n") |
|
| 1157 | - $nb--; |
|
| 1158 | - $b = 0; |
|
| 1159 | - $b2 = ''; |
|
| 1160 | - if($border) |
|
| 1161 | - {
|
|
| 1162 | - if($border==1) |
|
| 1163 | - {
|
|
| 1164 | - $border = 'LTRB'; |
|
| 1165 | - $b = 'LRT'; |
|
| 1166 | - $b2 = 'LR'; |
|
| 1167 | - } |
|
| 1168 | - else |
|
| 1169 | - {
|
|
| 1170 | - $b2 = ''; |
|
| 1171 | - if(strpos($border,'L')!==false) |
|
| 1172 | - $b2 .= 'L'; |
|
| 1173 | - if(strpos($border,'R')!==false) |
|
| 1174 | - $b2 .= 'R'; |
|
| 1175 | - $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; |
|
| 1176 | - } |
|
| 1177 | - } |
|
| 1178 | - $sep = -1; |
|
| 1179 | - $i = 0; |
|
| 1180 | - $j = 0; |
|
| 1181 | - $l = 0; |
|
| 1182 | - $ns = 0; |
|
| 1183 | - $nl = 1; |
|
| 1184 | - $ls = 0; |
|
| 1185 | - while($i<$nb) |
|
| 1186 | - {
|
|
| 1187 | - // Get next character |
|
| 1188 | - $c = $s[$i]; |
|
| 1189 | - if($c=="\n") |
|
| 1190 | - {
|
|
| 1191 | - // Explicit line break |
|
| 1192 | - if($this->ws>0) |
|
| 1193 | - {
|
|
| 1194 | - $this->ws = 0; |
|
| 1195 | - $this->_out('0 Tw');
|
|
| 1196 | - } |
|
| 1197 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1198 | - $i++; |
|
| 1199 | - $sep = -1; |
|
| 1200 | - $j = $i; |
|
| 1201 | - $l = 0; |
|
| 1202 | - $ns = 0; |
|
| 1203 | - $nl++; |
|
| 1204 | - if($border && $nl==2) |
|
| 1205 | - $b = $b2; |
|
| 1206 | - continue; |
|
| 1207 | - } |
|
| 1208 | - if($c==' ') |
|
| 1209 | - {
|
|
| 1210 | - $sep = $i; |
|
| 1211 | - $ls = $l; |
|
| 1212 | - $ns++; |
|
| 1213 | - } |
|
| 1214 | - $l += $cw[$c]; |
|
| 1215 | - if($l>$wmax) |
|
| 1216 | - {
|
|
| 1217 | - // Automatic line break |
|
| 1218 | - if($sep==-1) |
|
| 1219 | - {
|
|
| 1220 | - if($i==$j) |
|
| 1221 | - $i++; |
|
| 1222 | - if($this->ws>0) |
|
| 1223 | - {
|
|
| 1224 | - $this->ws = 0; |
|
| 1225 | - $this->_out('0 Tw');
|
|
| 1226 | - } |
|
| 1227 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1228 | - } |
|
| 1229 | - else |
|
| 1230 | - {
|
|
| 1231 | - if($align=='J') |
|
| 1232 | - {
|
|
| 1233 | - $this->ws = ($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; |
|
| 1234 | - $this->_out(sprintf('%.3F Tw',$this->ws*$this->k));
|
|
| 1235 | - } |
|
| 1236 | - $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); |
|
| 1237 | - $i = $sep+1; |
|
| 1238 | - } |
|
| 1239 | - $sep = -1; |
|
| 1240 | - $j = $i; |
|
| 1241 | - $l = 0; |
|
| 1242 | - $ns = 0; |
|
| 1243 | - $nl++; |
|
| 1244 | - if($border && $nl==2) |
|
| 1245 | - $b = $b2; |
|
| 1246 | - } |
|
| 1247 | - else |
|
| 1248 | - $i++; |
|
| 1249 | - } |
|
| 1250 | - // Last chunk |
|
| 1251 | - if($this->ws>0) |
|
| 1252 | - {
|
|
| 1253 | - $this->ws = 0; |
|
| 1254 | - $this->_out('0 Tw');
|
|
| 1255 | - } |
|
| 1256 | - if($border && strpos($border,'B')!==false) |
|
| 1257 | - $b .= 'B'; |
|
| 1258 | - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1259 | - $this->x = $this->lMargin; |
|
| 1147 | + // Output text with automatic or explicit line breaks |
|
| 1148 | + if(!isset($this->CurrentFont)) |
|
| 1149 | + $this->Error('No font has been set');
|
|
| 1150 | + $cw = &$this->CurrentFont['cw']; |
|
| 1151 | + if($w==0) |
|
| 1152 | + $w = $this->w-$this->rMargin-$this->x; |
|
| 1153 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1154 | + $s = str_replace("\r",'',$txt);
|
|
| 1155 | + $nb = strlen($s); |
|
| 1156 | + if($nb>0 && $s[$nb-1]=="\n") |
|
| 1157 | + $nb--; |
|
| 1158 | + $b = 0; |
|
| 1159 | + $b2 = ''; |
|
| 1160 | + if($border) |
|
| 1161 | + {
|
|
| 1162 | + if($border==1) |
|
| 1163 | + {
|
|
| 1164 | + $border = 'LTRB'; |
|
| 1165 | + $b = 'LRT'; |
|
| 1166 | + $b2 = 'LR'; |
|
| 1167 | + } |
|
| 1168 | + else |
|
| 1169 | + {
|
|
| 1170 | + $b2 = ''; |
|
| 1171 | + if(strpos($border,'L')!==false) |
|
| 1172 | + $b2 .= 'L'; |
|
| 1173 | + if(strpos($border,'R')!==false) |
|
| 1174 | + $b2 .= 'R'; |
|
| 1175 | + $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; |
|
| 1176 | + } |
|
| 1177 | + } |
|
| 1178 | + $sep = -1; |
|
| 1179 | + $i = 0; |
|
| 1180 | + $j = 0; |
|
| 1181 | + $l = 0; |
|
| 1182 | + $ns = 0; |
|
| 1183 | + $nl = 1; |
|
| 1184 | + $ls = 0; |
|
| 1185 | + while($i<$nb) |
|
| 1186 | + {
|
|
| 1187 | + // Get next character |
|
| 1188 | + $c = $s[$i]; |
|
| 1189 | + if($c=="\n") |
|
| 1190 | + {
|
|
| 1191 | + // Explicit line break |
|
| 1192 | + if($this->ws>0) |
|
| 1193 | + {
|
|
| 1194 | + $this->ws = 0; |
|
| 1195 | + $this->_out('0 Tw');
|
|
| 1196 | + } |
|
| 1197 | + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1198 | + $i++; |
|
| 1199 | + $sep = -1; |
|
| 1200 | + $j = $i; |
|
| 1201 | + $l = 0; |
|
| 1202 | + $ns = 0; |
|
| 1203 | + $nl++; |
|
| 1204 | + if($border && $nl==2) |
|
| 1205 | + $b = $b2; |
|
| 1206 | + continue; |
|
| 1207 | + } |
|
| 1208 | + if($c==' ') |
|
| 1209 | + {
|
|
| 1210 | + $sep = $i; |
|
| 1211 | + $ls = $l; |
|
| 1212 | + $ns++; |
|
| 1213 | + } |
|
| 1214 | + $l += $cw[$c]; |
|
| 1215 | + if($l>$wmax) |
|
| 1216 | + {
|
|
| 1217 | + // Automatic line break |
|
| 1218 | + if($sep==-1) |
|
| 1219 | + {
|
|
| 1220 | + if($i==$j) |
|
| 1221 | + $i++; |
|
| 1222 | + if($this->ws>0) |
|
| 1223 | + {
|
|
| 1224 | + $this->ws = 0; |
|
| 1225 | + $this->_out('0 Tw');
|
|
| 1226 | + } |
|
| 1227 | + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1228 | + } |
|
| 1229 | + else |
|
| 1230 | + {
|
|
| 1231 | + if($align=='J') |
|
| 1232 | + {
|
|
| 1233 | + $this->ws = ($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; |
|
| 1234 | + $this->_out(sprintf('%.3F Tw',$this->ws*$this->k));
|
|
| 1235 | + } |
|
| 1236 | + $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); |
|
| 1237 | + $i = $sep+1; |
|
| 1238 | + } |
|
| 1239 | + $sep = -1; |
|
| 1240 | + $j = $i; |
|
| 1241 | + $l = 0; |
|
| 1242 | + $ns = 0; |
|
| 1243 | + $nl++; |
|
| 1244 | + if($border && $nl==2) |
|
| 1245 | + $b = $b2; |
|
| 1246 | + } |
|
| 1247 | + else |
|
| 1248 | + $i++; |
|
| 1249 | + } |
|
| 1250 | + // Last chunk |
|
| 1251 | + if($this->ws>0) |
|
| 1252 | + {
|
|
| 1253 | + $this->ws = 0; |
|
| 1254 | + $this->_out('0 Tw');
|
|
| 1255 | + } |
|
| 1256 | + if($border && strpos($border,'B')!==false) |
|
| 1257 | + $b .= 'B'; |
|
| 1258 | + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
|
| 1259 | + $this->x = $this->lMargin; |
|
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | 1262 | /** |
@@ -1271,85 +1271,85 @@ discard block |
||
| 1271 | 1271 | */ |
| 1272 | 1272 | public function Write(float $h, string $txt, $link='') : void |
| 1273 | 1273 | {
|
| 1274 | - // Output text in flowing mode |
|
| 1275 | - if(!isset($this->CurrentFont)) |
|
| 1276 | - $this->Error('No font has been set');
|
|
| 1277 | - $cw = &$this->CurrentFont['cw']; |
|
| 1278 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1279 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1280 | - $s = str_replace("\r",'',$txt);
|
|
| 1281 | - $nb = strlen($s); |
|
| 1282 | - $sep = -1; |
|
| 1283 | - $i = 0; |
|
| 1284 | - $j = 0; |
|
| 1285 | - $l = 0; |
|
| 1286 | - $nl = 1; |
|
| 1287 | - while($i<$nb) |
|
| 1288 | - {
|
|
| 1289 | - // Get next character |
|
| 1290 | - $c = $s[$i]; |
|
| 1291 | - if($c=="\n") |
|
| 1292 | - {
|
|
| 1293 | - // Explicit line break |
|
| 1294 | - $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
| 1295 | - $i++; |
|
| 1296 | - $sep = -1; |
|
| 1297 | - $j = $i; |
|
| 1298 | - $l = 0; |
|
| 1299 | - if($nl==1) |
|
| 1300 | - {
|
|
| 1301 | - $this->x = $this->lMargin; |
|
| 1302 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1303 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1304 | - } |
|
| 1305 | - $nl++; |
|
| 1306 | - continue; |
|
| 1307 | - } |
|
| 1308 | - if($c==' ') |
|
| 1309 | - $sep = $i; |
|
| 1310 | - $l += $cw[$c]; |
|
| 1311 | - if($l>$wmax) |
|
| 1312 | - {
|
|
| 1313 | - // Automatic line break |
|
| 1314 | - if($sep==-1) |
|
| 1315 | - {
|
|
| 1316 | - if($this->x>$this->lMargin) |
|
| 1317 | - {
|
|
| 1318 | - // Move to next line |
|
| 1319 | - $this->x = $this->lMargin; |
|
| 1320 | - $this->y += $h; |
|
| 1321 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1322 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1323 | - $i++; |
|
| 1324 | - $nl++; |
|
| 1325 | - continue; |
|
| 1326 | - } |
|
| 1327 | - if($i==$j) |
|
| 1328 | - $i++; |
|
| 1329 | - $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
| 1330 | - } |
|
| 1331 | - else |
|
| 1332 | - {
|
|
| 1333 | - $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link); |
|
| 1334 | - $i = $sep+1; |
|
| 1335 | - } |
|
| 1336 | - $sep = -1; |
|
| 1337 | - $j = $i; |
|
| 1338 | - $l = 0; |
|
| 1339 | - if($nl==1) |
|
| 1340 | - {
|
|
| 1341 | - $this->x = $this->lMargin; |
|
| 1342 | - $w = $this->w-$this->rMargin-$this->x; |
|
| 1343 | - $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1344 | - } |
|
| 1345 | - $nl++; |
|
| 1346 | - } |
|
| 1347 | - else |
|
| 1348 | - $i++; |
|
| 1349 | - } |
|
| 1350 | - // Last chunk |
|
| 1351 | - if($i!=$j) |
|
| 1352 | - $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link); |
|
| 1274 | + // Output text in flowing mode |
|
| 1275 | + if(!isset($this->CurrentFont)) |
|
| 1276 | + $this->Error('No font has been set');
|
|
| 1277 | + $cw = &$this->CurrentFont['cw']; |
|
| 1278 | + $w = $this->w-$this->rMargin-$this->x; |
|
| 1279 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1280 | + $s = str_replace("\r",'',$txt);
|
|
| 1281 | + $nb = strlen($s); |
|
| 1282 | + $sep = -1; |
|
| 1283 | + $i = 0; |
|
| 1284 | + $j = 0; |
|
| 1285 | + $l = 0; |
|
| 1286 | + $nl = 1; |
|
| 1287 | + while($i<$nb) |
|
| 1288 | + {
|
|
| 1289 | + // Get next character |
|
| 1290 | + $c = $s[$i]; |
|
| 1291 | + if($c=="\n") |
|
| 1292 | + {
|
|
| 1293 | + // Explicit line break |
|
| 1294 | + $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
| 1295 | + $i++; |
|
| 1296 | + $sep = -1; |
|
| 1297 | + $j = $i; |
|
| 1298 | + $l = 0; |
|
| 1299 | + if($nl==1) |
|
| 1300 | + {
|
|
| 1301 | + $this->x = $this->lMargin; |
|
| 1302 | + $w = $this->w-$this->rMargin-$this->x; |
|
| 1303 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1304 | + } |
|
| 1305 | + $nl++; |
|
| 1306 | + continue; |
|
| 1307 | + } |
|
| 1308 | + if($c==' ') |
|
| 1309 | + $sep = $i; |
|
| 1310 | + $l += $cw[$c]; |
|
| 1311 | + if($l>$wmax) |
|
| 1312 | + {
|
|
| 1313 | + // Automatic line break |
|
| 1314 | + if($sep==-1) |
|
| 1315 | + {
|
|
| 1316 | + if($this->x>$this->lMargin) |
|
| 1317 | + {
|
|
| 1318 | + // Move to next line |
|
| 1319 | + $this->x = $this->lMargin; |
|
| 1320 | + $this->y += $h; |
|
| 1321 | + $w = $this->w-$this->rMargin-$this->x; |
|
| 1322 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1323 | + $i++; |
|
| 1324 | + $nl++; |
|
| 1325 | + continue; |
|
| 1326 | + } |
|
| 1327 | + if($i==$j) |
|
| 1328 | + $i++; |
|
| 1329 | + $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link); |
|
| 1330 | + } |
|
| 1331 | + else |
|
| 1332 | + {
|
|
| 1333 | + $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link); |
|
| 1334 | + $i = $sep+1; |
|
| 1335 | + } |
|
| 1336 | + $sep = -1; |
|
| 1337 | + $j = $i; |
|
| 1338 | + $l = 0; |
|
| 1339 | + if($nl==1) |
|
| 1340 | + {
|
|
| 1341 | + $this->x = $this->lMargin; |
|
| 1342 | + $w = $this->w-$this->rMargin-$this->x; |
|
| 1343 | + $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; |
|
| 1344 | + } |
|
| 1345 | + $nl++; |
|
| 1346 | + } |
|
| 1347 | + else |
|
| 1348 | + $i++; |
|
| 1349 | + } |
|
| 1350 | + // Last chunk |
|
| 1351 | + if($i!=$j) |
|
| 1352 | + $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',false,$link); |
|
| 1353 | 1353 | } |
| 1354 | 1354 | |
| 1355 | 1355 | /** |
@@ -1361,12 +1361,12 @@ discard block |
||
| 1361 | 1361 | */ |
| 1362 | 1362 | public function Ln(float $h=null) : void |
| 1363 | 1363 | {
|
| 1364 | - // Line feed; default value is the last cell height |
|
| 1365 | - $this->x = $this->lMargin; |
|
| 1366 | - if($h===null) |
|
| 1367 | - $this->y += $this->lasth; |
|
| 1368 | - else |
|
| 1369 | - $this->y += $h; |
|
| 1364 | + // Line feed; default value is the last cell height |
|
| 1365 | + $this->x = $this->lMargin; |
|
| 1366 | + if($h===null) |
|
| 1367 | + $this->y += $this->lasth; |
|
| 1368 | + else |
|
| 1369 | + $this->y += $h; |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | 1372 | /** |
@@ -1417,67 +1417,67 @@ discard block |
||
| 1417 | 1417 | */ |
| 1418 | 1418 | public function Image(string $file, ?float $x=null, ?float $y=null, float $w=0, float $h=0, string $type='', $link='') : void |
| 1419 | 1419 | {
|
| 1420 | - // Put an image on the page |
|
| 1421 | - if($file=='') |
|
| 1422 | - $this->Error('Image file name is empty');
|
|
| 1423 | - if(!isset($this->images[$file])) |
|
| 1424 | - {
|
|
| 1425 | - // First use of this image, get info |
|
| 1426 | - if($type=='') |
|
| 1427 | - {
|
|
| 1428 | - $pos = strrpos($file,'.'); |
|
| 1429 | - if(!$pos) |
|
| 1430 | - $this->Error('Image file has no extension and no type was specified: '.$file);
|
|
| 1431 | - $type = substr($file,$pos+1); |
|
| 1432 | - } |
|
| 1433 | - $type = strtolower($type); |
|
| 1434 | - if($type=='jpeg') |
|
| 1435 | - $type = 'jpg'; |
|
| 1436 | - $mtd = '_parse'.$type; |
|
| 1437 | - if(!method_exists($this,$mtd)) |
|
| 1438 | - $this->Error('Unsupported image type: '.$type);
|
|
| 1439 | - $info = $this->$mtd($file); |
|
| 1440 | - $info['i'] = count($this->images)+1; |
|
| 1441 | - $this->images[$file] = $info; |
|
| 1442 | - } |
|
| 1443 | - else |
|
| 1444 | - $info = $this->images[$file]; |
|
| 1445 | - |
|
| 1446 | - // Automatic width and height calculation if needed |
|
| 1447 | - if($w==0 && $h==0) |
|
| 1448 | - {
|
|
| 1449 | - // Put image at 96 dpi |
|
| 1450 | - $w = -96; |
|
| 1451 | - $h = -96; |
|
| 1452 | - } |
|
| 1453 | - if($w<0) |
|
| 1454 | - $w = -$info['w']*72/$w/$this->k; |
|
| 1455 | - if($h<0) |
|
| 1456 | - $h = -$info['h']*72/$h/$this->k; |
|
| 1457 | - if($w==0) |
|
| 1458 | - $w = $h*$info['w']/$info['h']; |
|
| 1459 | - if($h==0) |
|
| 1460 | - $h = $w*$info['h']/$info['w']; |
|
| 1461 | - |
|
| 1462 | - // Flowing mode |
|
| 1463 | - if($y===null) |
|
| 1464 | - {
|
|
| 1465 | - if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
| 1466 | - {
|
|
| 1467 | - // Automatic page break |
|
| 1468 | - $x2 = $this->x; |
|
| 1469 | - $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
| 1470 | - $this->x = $x2; |
|
| 1471 | - } |
|
| 1472 | - $y = $this->y; |
|
| 1473 | - $this->y += $h; |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - if($x===null) |
|
| 1477 | - $x = $this->x; |
|
| 1478 | - $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q',$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i']));
|
|
| 1479 | - if($link) |
|
| 1480 | - $this->Link($x,$y,$w,$h,$link); |
|
| 1420 | + // Put an image on the page |
|
| 1421 | + if($file=='') |
|
| 1422 | + $this->Error('Image file name is empty');
|
|
| 1423 | + if(!isset($this->images[$file])) |
|
| 1424 | + {
|
|
| 1425 | + // First use of this image, get info |
|
| 1426 | + if($type=='') |
|
| 1427 | + {
|
|
| 1428 | + $pos = strrpos($file,'.'); |
|
| 1429 | + if(!$pos) |
|
| 1430 | + $this->Error('Image file has no extension and no type was specified: '.$file);
|
|
| 1431 | + $type = substr($file,$pos+1); |
|
| 1432 | + } |
|
| 1433 | + $type = strtolower($type); |
|
| 1434 | + if($type=='jpeg') |
|
| 1435 | + $type = 'jpg'; |
|
| 1436 | + $mtd = '_parse'.$type; |
|
| 1437 | + if(!method_exists($this,$mtd)) |
|
| 1438 | + $this->Error('Unsupported image type: '.$type);
|
|
| 1439 | + $info = $this->$mtd($file); |
|
| 1440 | + $info['i'] = count($this->images)+1; |
|
| 1441 | + $this->images[$file] = $info; |
|
| 1442 | + } |
|
| 1443 | + else |
|
| 1444 | + $info = $this->images[$file]; |
|
| 1445 | + |
|
| 1446 | + // Automatic width and height calculation if needed |
|
| 1447 | + if($w==0 && $h==0) |
|
| 1448 | + {
|
|
| 1449 | + // Put image at 96 dpi |
|
| 1450 | + $w = -96; |
|
| 1451 | + $h = -96; |
|
| 1452 | + } |
|
| 1453 | + if($w<0) |
|
| 1454 | + $w = -$info['w']*72/$w/$this->k; |
|
| 1455 | + if($h<0) |
|
| 1456 | + $h = -$info['h']*72/$h/$this->k; |
|
| 1457 | + if($w==0) |
|
| 1458 | + $w = $h*$info['w']/$info['h']; |
|
| 1459 | + if($h==0) |
|
| 1460 | + $h = $w*$info['h']/$info['w']; |
|
| 1461 | + |
|
| 1462 | + // Flowing mode |
|
| 1463 | + if($y===null) |
|
| 1464 | + {
|
|
| 1465 | + if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) |
|
| 1466 | + {
|
|
| 1467 | + // Automatic page break |
|
| 1468 | + $x2 = $this->x; |
|
| 1469 | + $this->addPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation); |
|
| 1470 | + $this->x = $x2; |
|
| 1471 | + } |
|
| 1472 | + $y = $this->y; |
|
| 1473 | + $this->y += $h; |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + if($x===null) |
|
| 1477 | + $x = $this->x; |
|
| 1478 | + $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q',$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i']));
|
|
| 1479 | + if($link) |
|
| 1480 | + $this->Link($x,$y,$w,$h,$link); |
|
| 1481 | 1481 | } |
| 1482 | 1482 | |
| 1483 | 1483 | /** |
@@ -1486,8 +1486,8 @@ discard block |
||
| 1486 | 1486 | */ |
| 1487 | 1487 | public function GetPageWidth() : float |
| 1488 | 1488 | {
|
| 1489 | - // Get current page width |
|
| 1490 | - return $this->w; |
|
| 1489 | + // Get current page width |
|
| 1490 | + return $this->w; |
|
| 1491 | 1491 | } |
| 1492 | 1492 | |
| 1493 | 1493 | /** |
@@ -1496,8 +1496,8 @@ discard block |
||
| 1496 | 1496 | */ |
| 1497 | 1497 | public function GetPageHeight() : float |
| 1498 | 1498 | {
|
| 1499 | - // Get current page height |
|
| 1500 | - return $this->h; |
|
| 1499 | + // Get current page height |
|
| 1500 | + return $this->h; |
|
| 1501 | 1501 | } |
| 1502 | 1502 | |
| 1503 | 1503 | /** |
@@ -1506,8 +1506,8 @@ discard block |
||
| 1506 | 1506 | */ |
| 1507 | 1507 | public function GetX() : float |
| 1508 | 1508 | {
|
| 1509 | - // GetX position |
|
| 1510 | - return $this->x; |
|
| 1509 | + // GetX position |
|
| 1510 | + return $this->x; |
|
| 1511 | 1511 | } |
| 1512 | 1512 | |
| 1513 | 1513 | /** |
@@ -1517,11 +1517,11 @@ discard block |
||
| 1517 | 1517 | */ |
| 1518 | 1518 | public function SetX(float $x) : void |
| 1519 | 1519 | {
|
| 1520 | - // Set x position |
|
| 1521 | - if($x>=0) |
|
| 1522 | - $this->x = $x; |
|
| 1523 | - else |
|
| 1524 | - $this->x = $this->w+$x; |
|
| 1520 | + // Set x position |
|
| 1521 | + if($x>=0) |
|
| 1522 | + $this->x = $x; |
|
| 1523 | + else |
|
| 1524 | + $this->x = $this->w+$x; |
|
| 1525 | 1525 | } |
| 1526 | 1526 | |
| 1527 | 1527 | /** |
@@ -1530,8 +1530,8 @@ discard block |
||
| 1530 | 1530 | */ |
| 1531 | 1531 | public function GetY() : float |
| 1532 | 1532 | {
|
| 1533 | - // Get y position |
|
| 1534 | - return $this->y; |
|
| 1533 | + // Get y position |
|
| 1534 | + return $this->y; |
|
| 1535 | 1535 | } |
| 1536 | 1536 | |
| 1537 | 1537 | /** |
@@ -1542,13 +1542,13 @@ discard block |
||
| 1542 | 1542 | */ |
| 1543 | 1543 | public function SetY(float $y, bool $resetX=true) : void |
| 1544 | 1544 | {
|
| 1545 | - // Set y position and optionally reset x |
|
| 1546 | - if($y>=0) |
|
| 1547 | - $this->y = $y; |
|
| 1548 | - else |
|
| 1549 | - $this->y = $this->h+$y; |
|
| 1550 | - if($resetX) |
|
| 1551 | - $this->x = $this->lMargin; |
|
| 1545 | + // Set y position and optionally reset x |
|
| 1546 | + if($y>=0) |
|
| 1547 | + $this->y = $y; |
|
| 1548 | + else |
|
| 1549 | + $this->y = $this->h+$y; |
|
| 1550 | + if($resetX) |
|
| 1551 | + $this->x = $this->lMargin; |
|
| 1552 | 1552 | } |
| 1553 | 1553 | |
| 1554 | 1554 | /** |
@@ -1559,9 +1559,9 @@ discard block |
||
| 1559 | 1559 | */ |
| 1560 | 1560 | public function SetXY(float $x, float $y) : void |
| 1561 | 1561 | {
|
| 1562 | - // Set x and y positions |
|
| 1563 | - $this->setX($x); |
|
| 1564 | - $this->setY($y,false); |
|
| 1562 | + // Set x and y positions |
|
| 1563 | + $this->setX($x); |
|
| 1564 | + $this->setY($y,false); |
|
| 1565 | 1565 | } |
| 1566 | 1566 | |
| 1567 | 1567 | /** |
@@ -1584,55 +1584,55 @@ discard block |
||
| 1584 | 1584 | */ |
| 1585 | 1585 | public function Output(string $dest='', string $name='', bool $isUTF8=false) : string |
| 1586 | 1586 | {
|
| 1587 | - // Output PDF to some destination |
|
| 1588 | - $this->Close(); |
|
| 1589 | - if(strlen($name)==1 && strlen($dest)!=1) |
|
| 1590 | - {
|
|
| 1591 | - // Fix parameter order |
|
| 1592 | - $tmp = $dest; |
|
| 1593 | - $dest = $name; |
|
| 1594 | - $name = $tmp; |
|
| 1595 | - } |
|
| 1596 | - if($dest=='') |
|
| 1597 | - $dest = 'I'; |
|
| 1598 | - if($name=='') |
|
| 1599 | - $name = 'doc.pdf'; |
|
| 1600 | - switch(strtoupper($dest)) |
|
| 1601 | - {
|
|
| 1602 | - case 'I': |
|
| 1603 | - // Send to standard output |
|
| 1604 | - $this->_checkoutput(); |
|
| 1605 | - if(PHP_SAPI!='cli') |
|
| 1606 | - {
|
|
| 1607 | - // We send to a browser |
|
| 1608 | - header('Content-Type: application/pdf; charset=UTF-8');
|
|
| 1609 | - header('Content-Disposition: inline; '.$this->_httpencode('filename',$name,$isUTF8));
|
|
| 1610 | - header('Cache-Control: private, max-age=0, must-revalidate');
|
|
| 1611 | - header('Pragma: public');
|
|
| 1612 | - } |
|
| 1613 | - echo $this->buffer; |
|
| 1614 | - break; |
|
| 1615 | - case 'D': |
|
| 1616 | - // Download file |
|
| 1617 | - $this->_checkoutput(); |
|
| 1618 | - header('Content-Type: application/x-download');
|
|
| 1619 | - header('Content-Disposition: attachment; '.$this->_httpencode('filename',$name,$isUTF8));
|
|
| 1620 | - header('Cache-Control: private, max-age=0, must-revalidate');
|
|
| 1621 | - header('Pragma: public');
|
|
| 1622 | - echo $this->buffer; |
|
| 1623 | - break; |
|
| 1624 | - case 'F': |
|
| 1625 | - // Save to local file |
|
| 1626 | - if(!file_put_contents($name,$this->buffer)) |
|
| 1627 | - $this->Error('Unable to create output file: '.$name);
|
|
| 1628 | - break; |
|
| 1629 | - case 'S': |
|
| 1630 | - // Return as a string |
|
| 1631 | - return $this->buffer; |
|
| 1632 | - default: |
|
| 1633 | - $this->Error('Incorrect output destination: '.$dest);
|
|
| 1634 | - } |
|
| 1635 | - return ''; |
|
| 1587 | + // Output PDF to some destination |
|
| 1588 | + $this->Close(); |
|
| 1589 | + if(strlen($name)==1 && strlen($dest)!=1) |
|
| 1590 | + {
|
|
| 1591 | + // Fix parameter order |
|
| 1592 | + $tmp = $dest; |
|
| 1593 | + $dest = $name; |
|
| 1594 | + $name = $tmp; |
|
| 1595 | + } |
|
| 1596 | + if($dest=='') |
|
| 1597 | + $dest = 'I'; |
|
| 1598 | + if($name=='') |
|
| 1599 | + $name = 'doc.pdf'; |
|
| 1600 | + switch(strtoupper($dest)) |
|
| 1601 | + {
|
|
| 1602 | + case 'I': |
|
| 1603 | + // Send to standard output |
|
| 1604 | + $this->_checkoutput(); |
|
| 1605 | + if(PHP_SAPI!='cli') |
|
| 1606 | + {
|
|
| 1607 | + // We send to a browser |
|
| 1608 | + header('Content-Type: application/pdf; charset=UTF-8');
|
|
| 1609 | + header('Content-Disposition: inline; '.$this->_httpencode('filename',$name,$isUTF8));
|
|
| 1610 | + header('Cache-Control: private, max-age=0, must-revalidate');
|
|
| 1611 | + header('Pragma: public');
|
|
| 1612 | + } |
|
| 1613 | + echo $this->buffer; |
|
| 1614 | + break; |
|
| 1615 | + case 'D': |
|
| 1616 | + // Download file |
|
| 1617 | + $this->_checkoutput(); |
|
| 1618 | + header('Content-Type: application/x-download');
|
|
| 1619 | + header('Content-Disposition: attachment; '.$this->_httpencode('filename',$name,$isUTF8));
|
|
| 1620 | + header('Cache-Control: private, max-age=0, must-revalidate');
|
|
| 1621 | + header('Pragma: public');
|
|
| 1622 | + echo $this->buffer; |
|
| 1623 | + break; |
|
| 1624 | + case 'F': |
|
| 1625 | + // Save to local file |
|
| 1626 | + if(!file_put_contents($name,$this->buffer)) |
|
| 1627 | + $this->Error('Unable to create output file: '.$name);
|
|
| 1628 | + break; |
|
| 1629 | + case 'S': |
|
| 1630 | + // Return as a string |
|
| 1631 | + return $this->buffer; |
|
| 1632 | + default: |
|
| 1633 | + $this->Error('Incorrect output destination: '.$dest);
|
|
| 1634 | + } |
|
| 1635 | + return ''; |
|
| 1636 | 1636 | } |
| 1637 | 1637 | |
| 1638 | 1638 | /** |
@@ -1640,9 +1640,9 @@ discard block |
||
| 1640 | 1640 | */ |
| 1641 | 1641 | protected function _dochecks() : void |
| 1642 | 1642 | {
|
| 1643 | - // Check mbstring overloading |
|
| 1644 | - if(ini_get('mbstring.func_overload') & 2)
|
|
| 1645 | - $this->Error('mbstring overloading must be disabled');
|
|
| 1643 | + // Check mbstring overloading |
|
| 1644 | + if(ini_get('mbstring.func_overload') & 2)
|
|
| 1645 | + $this->Error('mbstring overloading must be disabled');
|
|
| 1646 | 1646 | } |
| 1647 | 1647 | |
| 1648 | 1648 | /** |
@@ -1650,24 +1650,24 @@ discard block |
||
| 1650 | 1650 | */ |
| 1651 | 1651 | protected function _checkoutput() : void |
| 1652 | 1652 | {
|
| 1653 | - if(PHP_SAPI!='cli') |
|
| 1654 | - {
|
|
| 1655 | - $file = ''; |
|
| 1656 | - $line = 0; |
|
| 1657 | - if(headers_sent($file,$line)) |
|
| 1658 | - $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)");
|
|
| 1659 | - } |
|
| 1660 | - if(ob_get_length()) |
|
| 1661 | - {
|
|
| 1662 | - // The output buffer is not empty |
|
| 1663 | - if(preg_match('/^(\xEF\xBB\xBF)?\s*$/',ob_get_contents()))
|
|
| 1664 | - {
|
|
| 1665 | - // It contains only a UTF-8 BOM and/or whitespace, let's clean it |
|
| 1666 | - ob_clean(); |
|
| 1667 | - } |
|
| 1668 | - else |
|
| 1669 | - $this->Error("Some data has already been output, can't send PDF file");
|
|
| 1670 | - } |
|
| 1653 | + if(PHP_SAPI!='cli') |
|
| 1654 | + {
|
|
| 1655 | + $file = ''; |
|
| 1656 | + $line = 0; |
|
| 1657 | + if(headers_sent($file,$line)) |
|
| 1658 | + $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)");
|
|
| 1659 | + } |
|
| 1660 | + if(ob_get_length()) |
|
| 1661 | + {
|
|
| 1662 | + // The output buffer is not empty |
|
| 1663 | + if(preg_match('/^(\xEF\xBB\xBF)?\s*$/',ob_get_contents()))
|
|
| 1664 | + {
|
|
| 1665 | + // It contains only a UTF-8 BOM and/or whitespace, let's clean it |
|
| 1666 | + ob_clean(); |
|
| 1667 | + } |
|
| 1668 | + else |
|
| 1669 | + $this->Error("Some data has already been output, can't send PDF file");
|
|
| 1670 | + } |
|
| 1671 | 1671 | } |
| 1672 | 1672 | |
| 1673 | 1673 | /** |
@@ -1677,21 +1677,21 @@ discard block |
||
| 1677 | 1677 | */ |
| 1678 | 1678 | protected function _getpagesize($size) : array |
| 1679 | 1679 | {
|
| 1680 | - if(is_string($size)) |
|
| 1681 | - {
|
|
| 1682 | - $size = strtolower($size); |
|
| 1683 | - if(!isset($this->StdPageSizes[$size])) |
|
| 1684 | - $this->Error('Unknown page size: '.$size);
|
|
| 1685 | - $a = $this->StdPageSizes[$size]; |
|
| 1686 | - return array($a[0]/$this->k, $a[1]/$this->k); |
|
| 1687 | - } |
|
| 1688 | - else |
|
| 1689 | - {
|
|
| 1690 | - if($size[0]>$size[1]) |
|
| 1691 | - return array($size[1], $size[0]); |
|
| 1692 | - else |
|
| 1693 | - return $size; |
|
| 1694 | - } |
|
| 1680 | + if(is_string($size)) |
|
| 1681 | + {
|
|
| 1682 | + $size = strtolower($size); |
|
| 1683 | + if(!isset($this->StdPageSizes[$size])) |
|
| 1684 | + $this->Error('Unknown page size: '.$size);
|
|
| 1685 | + $a = $this->StdPageSizes[$size]; |
|
| 1686 | + return array($a[0]/$this->k, $a[1]/$this->k); |
|
| 1687 | + } |
|
| 1688 | + else |
|
| 1689 | + {
|
|
| 1690 | + if($size[0]>$size[1]) |
|
| 1691 | + return array($size[1], $size[0]); |
|
| 1692 | + else |
|
| 1693 | + return $size; |
|
| 1694 | + } |
|
| 1695 | 1695 | } |
| 1696 | 1696 | |
| 1697 | 1697 | /** |
@@ -1702,49 +1702,49 @@ discard block |
||
| 1702 | 1702 | */ |
| 1703 | 1703 | protected function _beginpage(string $orientation, $size, int $rotation) : void |
| 1704 | 1704 | {
|
| 1705 | - $this->page++; |
|
| 1706 | - $this->pages[$this->page] = ''; |
|
| 1707 | - $this->state = 2; |
|
| 1708 | - $this->x = $this->lMargin; |
|
| 1709 | - $this->y = $this->tMargin; |
|
| 1710 | - $this->FontFamily = ''; |
|
| 1711 | - // Check page size and orientation |
|
| 1712 | - if($orientation=='') |
|
| 1713 | - $orientation = $this->DefOrientation; |
|
| 1714 | - else |
|
| 1715 | - $orientation = strtoupper($orientation[0]); |
|
| 1716 | - if($size=='') |
|
| 1717 | - $size = $this->DefPageSize; |
|
| 1718 | - else |
|
| 1719 | - $size = $this->_getpagesize($size); |
|
| 1720 | - if($orientation!=$this->CurOrientation || $size[0]!=$this->CurPageSize[0] || $size[1]!=$this->CurPageSize[1]) |
|
| 1721 | - {
|
|
| 1722 | - // New size or orientation |
|
| 1723 | - if($orientation=='P') |
|
| 1724 | - {
|
|
| 1725 | - $this->w = $size[0]; |
|
| 1726 | - $this->h = $size[1]; |
|
| 1727 | - } |
|
| 1728 | - else |
|
| 1729 | - {
|
|
| 1730 | - $this->w = $size[1]; |
|
| 1731 | - $this->h = $size[0]; |
|
| 1732 | - } |
|
| 1733 | - $this->wPt = $this->w*$this->k; |
|
| 1734 | - $this->hPt = $this->h*$this->k; |
|
| 1735 | - $this->PageBreakTrigger = $this->h-$this->bMargin; |
|
| 1736 | - $this->CurOrientation = $orientation; |
|
| 1737 | - $this->CurPageSize = $size; |
|
| 1738 | - } |
|
| 1739 | - if($orientation!=$this->DefOrientation || $size[0]!=$this->DefPageSize[0] || $size[1]!=$this->DefPageSize[1]) |
|
| 1740 | - $this->PageInfo[$this->page]['size'] = array($this->wPt, $this->hPt); |
|
| 1741 | - if($rotation!=0) |
|
| 1742 | - {
|
|
| 1743 | - if($rotation%90!=0) |
|
| 1744 | - $this->Error('Incorrect rotation value: '.$rotation);
|
|
| 1745 | - $this->CurRotation = $rotation; |
|
| 1746 | - $this->PageInfo[$this->page]['rotation'] = $rotation; |
|
| 1747 | - } |
|
| 1705 | + $this->page++; |
|
| 1706 | + $this->pages[$this->page] = ''; |
|
| 1707 | + $this->state = 2; |
|
| 1708 | + $this->x = $this->lMargin; |
|
| 1709 | + $this->y = $this->tMargin; |
|
| 1710 | + $this->FontFamily = ''; |
|
| 1711 | + // Check page size and orientation |
|
| 1712 | + if($orientation=='') |
|
| 1713 | + $orientation = $this->DefOrientation; |
|
| 1714 | + else |
|
| 1715 | + $orientation = strtoupper($orientation[0]); |
|
| 1716 | + if($size=='') |
|
| 1717 | + $size = $this->DefPageSize; |
|
| 1718 | + else |
|
| 1719 | + $size = $this->_getpagesize($size); |
|
| 1720 | + if($orientation!=$this->CurOrientation || $size[0]!=$this->CurPageSize[0] || $size[1]!=$this->CurPageSize[1]) |
|
| 1721 | + {
|
|
| 1722 | + // New size or orientation |
|
| 1723 | + if($orientation=='P') |
|
| 1724 | + {
|
|
| 1725 | + $this->w = $size[0]; |
|
| 1726 | + $this->h = $size[1]; |
|
| 1727 | + } |
|
| 1728 | + else |
|
| 1729 | + {
|
|
| 1730 | + $this->w = $size[1]; |
|
| 1731 | + $this->h = $size[0]; |
|
| 1732 | + } |
|
| 1733 | + $this->wPt = $this->w*$this->k; |
|
| 1734 | + $this->hPt = $this->h*$this->k; |
|
| 1735 | + $this->PageBreakTrigger = $this->h-$this->bMargin; |
|
| 1736 | + $this->CurOrientation = $orientation; |
|
| 1737 | + $this->CurPageSize = $size; |
|
| 1738 | + } |
|
| 1739 | + if($orientation!=$this->DefOrientation || $size[0]!=$this->DefPageSize[0] || $size[1]!=$this->DefPageSize[1]) |
|
| 1740 | + $this->PageInfo[$this->page]['size'] = array($this->wPt, $this->hPt); |
|
| 1741 | + if($rotation!=0) |
|
| 1742 | + {
|
|
| 1743 | + if($rotation%90!=0) |
|
| 1744 | + $this->Error('Incorrect rotation value: '.$rotation);
|
|
| 1745 | + $this->CurRotation = $rotation; |
|
| 1746 | + $this->PageInfo[$this->page]['rotation'] = $rotation; |
|
| 1747 | + } |
|
| 1748 | 1748 | } |
| 1749 | 1749 | |
| 1750 | 1750 | /** |
@@ -1752,7 +1752,7 @@ discard block |
||
| 1752 | 1752 | */ |
| 1753 | 1753 | protected function _endpage() : void |
| 1754 | 1754 | {
|
| 1755 | - $this->state = 1; |
|
| 1755 | + $this->state = 1; |
|
| 1756 | 1756 | } |
| 1757 | 1757 | |
| 1758 | 1758 | /** |
@@ -1762,27 +1762,27 @@ discard block |
||
| 1762 | 1762 | */ |
| 1763 | 1763 | protected function _loadfont(string $font) : array |
| 1764 | 1764 | {
|
| 1765 | - // Load a font definition file from the font directory |
|
| 1765 | + // Load a font definition file from the font directory |
|
| 1766 | 1766 | if(strpos($font,'/')!==false || strpos($font,"\\")!==false) {
|
| 1767 | - $this->Error('Incorrect font definition file name: '.$font);
|
|
| 1767 | + $this->Error('Incorrect font definition file name: '.$font);
|
|
| 1768 | 1768 | } |
| 1769 | 1769 | // following vars must be initialized in the font definition file beeing included |
| 1770 | - $name = null; |
|
| 1771 | - $enc = null; |
|
| 1772 | - $subsetted = null; |
|
| 1773 | - include($this->fontpath.$font); |
|
| 1770 | + $name = null; |
|
| 1771 | + $enc = null; |
|
| 1772 | + $subsetted = null; |
|
| 1773 | + include($this->fontpath.$font); |
|
| 1774 | 1774 | |
| 1775 | - // phpstan can't see the code dynamicly included before so assuming $name, $enc, $subsetted always set to null! |
|
| 1776 | - if(!isset($name)) { /* @phpstan-ignore-line */
|
|
| 1777 | - $this->Error('Could not include font definition file');
|
|
| 1778 | - } |
|
| 1779 | - if(isset($enc)) { /* @phpstan-ignore-line */
|
|
| 1780 | - $enc = strtolower($enc); |
|
| 1781 | - } |
|
| 1782 | - if(!isset($subsetted)) { /* @phpstan-ignore-line */
|
|
| 1783 | - $subsetted = false; |
|
| 1784 | - } |
|
| 1785 | - return get_defined_vars(); |
|
| 1775 | + // phpstan can't see the code dynamicly included before so assuming $name, $enc, $subsetted always set to null! |
|
| 1776 | + if(!isset($name)) { /* @phpstan-ignore-line */
|
|
| 1777 | + $this->Error('Could not include font definition file');
|
|
| 1778 | + } |
|
| 1779 | + if(isset($enc)) { /* @phpstan-ignore-line */
|
|
| 1780 | + $enc = strtolower($enc); |
|
| 1781 | + } |
|
| 1782 | + if(!isset($subsetted)) { /* @phpstan-ignore-line */
|
|
| 1783 | + $subsetted = false; |
|
| 1784 | + } |
|
| 1785 | + return get_defined_vars(); |
|
| 1786 | 1786 | } |
| 1787 | 1787 | |
| 1788 | 1788 | /** |
@@ -1792,14 +1792,14 @@ discard block |
||
| 1792 | 1792 | */ |
| 1793 | 1793 | protected function _isascii(string $s) : bool |
| 1794 | 1794 | {
|
| 1795 | - // Test if string is ASCII |
|
| 1796 | - $nb = strlen($s); |
|
| 1797 | - for($i=0;$i<$nb;$i++) |
|
| 1798 | - {
|
|
| 1799 | - if(ord($s[$i])>127) |
|
| 1800 | - return false; |
|
| 1801 | - } |
|
| 1802 | - return true; |
|
| 1795 | + // Test if string is ASCII |
|
| 1796 | + $nb = strlen($s); |
|
| 1797 | + for($i=0;$i<$nb;$i++) |
|
| 1798 | + {
|
|
| 1799 | + if(ord($s[$i])>127) |
|
| 1800 | + return false; |
|
| 1801 | + } |
|
| 1802 | + return true; |
|
| 1803 | 1803 | } |
| 1804 | 1804 | |
| 1805 | 1805 | /** |
@@ -1810,15 +1810,15 @@ discard block |
||
| 1810 | 1810 | */ |
| 1811 | 1811 | protected function _httpencode(string $param, string $value, bool $isUTF8) : string |
| 1812 | 1812 | {
|
| 1813 | - // Encode HTTP header field parameter |
|
| 1814 | - if($this->_isascii($value)) |
|
| 1815 | - return $param.'="'.$value.'"'; |
|
| 1816 | - if(!$isUTF8) |
|
| 1817 | - $value = utf8_encode($value); |
|
| 1818 | - if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==false) |
|
| 1819 | - return $param.'="'.rawurlencode($value).'"'; |
|
| 1820 | - else |
|
| 1821 | - return $param."*=UTF-8''".rawurlencode($value); |
|
| 1813 | + // Encode HTTP header field parameter |
|
| 1814 | + if($this->_isascii($value)) |
|
| 1815 | + return $param.'="'.$value.'"'; |
|
| 1816 | + if(!$isUTF8) |
|
| 1817 | + $value = utf8_encode($value); |
|
| 1818 | + if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==false) |
|
| 1819 | + return $param.'="'.rawurlencode($value).'"'; |
|
| 1820 | + else |
|
| 1821 | + return $param."*=UTF-8''".rawurlencode($value); |
|
| 1822 | 1822 | } |
| 1823 | 1823 | |
| 1824 | 1824 | /** |
@@ -1828,35 +1828,35 @@ discard block |
||
| 1828 | 1828 | */ |
| 1829 | 1829 | protected function _UTF8toUTF16(string $s) : string |
| 1830 | 1830 | {
|
| 1831 | - // Convert UTF-8 to UTF-16BE with BOM |
|
| 1832 | - $res = "\xFE\xFF"; |
|
| 1833 | - $nb = strlen($s); |
|
| 1834 | - $i = 0; |
|
| 1835 | - while($i<$nb) |
|
| 1836 | - {
|
|
| 1837 | - $c1 = ord($s[$i++]); |
|
| 1838 | - if($c1>=224) |
|
| 1839 | - {
|
|
| 1840 | - // 3-byte character |
|
| 1841 | - $c2 = ord($s[$i++]); |
|
| 1842 | - $c3 = ord($s[$i++]); |
|
| 1843 | - $res .= chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2)); |
|
| 1844 | - $res .= chr((($c2 & 0x03)<<6) + ($c3 & 0x3F)); |
|
| 1845 | - } |
|
| 1846 | - elseif($c1>=192) |
|
| 1847 | - {
|
|
| 1848 | - // 2-byte character |
|
| 1849 | - $c2 = ord($s[$i++]); |
|
| 1850 | - $res .= chr(($c1 & 0x1C)>>2); |
|
| 1851 | - $res .= chr((($c1 & 0x03)<<6) + ($c2 & 0x3F)); |
|
| 1852 | - } |
|
| 1853 | - else |
|
| 1854 | - {
|
|
| 1855 | - // Single-byte character |
|
| 1856 | - $res .= "\0".chr($c1); |
|
| 1857 | - } |
|
| 1858 | - } |
|
| 1859 | - return $res; |
|
| 1831 | + // Convert UTF-8 to UTF-16BE with BOM |
|
| 1832 | + $res = "\xFE\xFF"; |
|
| 1833 | + $nb = strlen($s); |
|
| 1834 | + $i = 0; |
|
| 1835 | + while($i<$nb) |
|
| 1836 | + {
|
|
| 1837 | + $c1 = ord($s[$i++]); |
|
| 1838 | + if($c1>=224) |
|
| 1839 | + {
|
|
| 1840 | + // 3-byte character |
|
| 1841 | + $c2 = ord($s[$i++]); |
|
| 1842 | + $c3 = ord($s[$i++]); |
|
| 1843 | + $res .= chr((($c1 & 0x0F)<<4) + (($c2 & 0x3C)>>2)); |
|
| 1844 | + $res .= chr((($c2 & 0x03)<<6) + ($c3 & 0x3F)); |
|
| 1845 | + } |
|
| 1846 | + elseif($c1>=192) |
|
| 1847 | + {
|
|
| 1848 | + // 2-byte character |
|
| 1849 | + $c2 = ord($s[$i++]); |
|
| 1850 | + $res .= chr(($c1 & 0x1C)>>2); |
|
| 1851 | + $res .= chr((($c1 & 0x03)<<6) + ($c2 & 0x3F)); |
|
| 1852 | + } |
|
| 1853 | + else |
|
| 1854 | + {
|
|
| 1855 | + // Single-byte character |
|
| 1856 | + $res .= "\0".chr($c1); |
|
| 1857 | + } |
|
| 1858 | + } |
|
| 1859 | + return $res; |
|
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | 1862 | /** |
@@ -1866,11 +1866,11 @@ discard block |
||
| 1866 | 1866 | */ |
| 1867 | 1867 | protected function _escape(string $s) : string |
| 1868 | 1868 | {
|
| 1869 | - // Escape special characters |
|
| 1870 | - if(strpos($s,'(')!==false || strpos($s,')')!==false || strpos($s,'\\')!==false || strpos($s,"\r")!==false)
|
|
| 1871 | - return str_replace(array('\\','(',')',"\r"), array('\\\\','\\(','\\)','\\r'), $s);
|
|
| 1872 | - else |
|
| 1873 | - return $s; |
|
| 1869 | + // Escape special characters |
|
| 1870 | + if(strpos($s,'(')!==false || strpos($s,')')!==false || strpos($s,'\\')!==false || strpos($s,"\r")!==false)
|
|
| 1871 | + return str_replace(array('\\','(',')',"\r"), array('\\\\','\\(','\\)','\\r'), $s);
|
|
| 1872 | + else |
|
| 1873 | + return $s; |
|
| 1874 | 1874 | } |
| 1875 | 1875 | |
| 1876 | 1876 | /** |
@@ -1880,10 +1880,10 @@ discard block |
||
| 1880 | 1880 | */ |
| 1881 | 1881 | protected function _textstring(string $s) : string |
| 1882 | 1882 | {
|
| 1883 | - // Format a text string |
|
| 1884 | - if(!$this->_isascii($s)) |
|
| 1885 | - $s = $this->_UTF8toUTF16($s); |
|
| 1886 | - return '('.$this->_escape($s).')';
|
|
| 1883 | + // Format a text string |
|
| 1884 | + if(!$this->_isascii($s)) |
|
| 1885 | + $s = $this->_UTF8toUTF16($s); |
|
| 1886 | + return '('.$this->_escape($s).')';
|
|
| 1887 | 1887 | } |
| 1888 | 1888 | |
| 1889 | 1889 | /** |
@@ -1895,11 +1895,11 @@ discard block |
||
| 1895 | 1895 | */ |
| 1896 | 1896 | protected function _dounderline(float $x, float $y, string $txt) : string |
| 1897 | 1897 | {
|
| 1898 | - // Underline text |
|
| 1899 | - $up = $this->CurrentFont['up']; |
|
| 1900 | - $ut = $this->CurrentFont['ut']; |
|
| 1901 | - $w = $this->getStringWidth($txt)+$this->ws*substr_count($txt,' '); |
|
| 1902 | - return sprintf('%.2F %.2F %.2F %.2F re f',$x*$this->k,($this->h-($y-$up/1000*$this->FontSize))*$this->k,$w*$this->k,-$ut/1000*$this->FontSizePt);
|
|
| 1898 | + // Underline text |
|
| 1899 | + $up = $this->CurrentFont['up']; |
|
| 1900 | + $ut = $this->CurrentFont['ut']; |
|
| 1901 | + $w = $this->getStringWidth($txt)+$this->ws*substr_count($txt,' '); |
|
| 1902 | + return sprintf('%.2F %.2F %.2F %.2F re f',$x*$this->k,($this->h-($y-$up/1000*$this->FontSize))*$this->k,$w*$this->k,-$ut/1000*$this->FontSizePt);
|
|
| 1903 | 1903 | } |
| 1904 | 1904 | |
| 1905 | 1905 | /** |
@@ -1909,21 +1909,21 @@ discard block |
||
| 1909 | 1909 | */ |
| 1910 | 1910 | protected function _parsejpg(string $file) : array |
| 1911 | 1911 | {
|
| 1912 | - // Extract info from a JPEG file |
|
| 1913 | - $a = getimagesize($file); |
|
| 1914 | - if(!$a) |
|
| 1915 | - $this->Error('Missing or incorrect image file: '.$file);
|
|
| 1916 | - if($a[2]!=2) |
|
| 1917 | - $this->Error('Not a JPEG file: '.$file);
|
|
| 1918 | - if(!isset($a['channels']) || $a['channels']==3) |
|
| 1919 | - $colspace = 'DeviceRGB'; |
|
| 1920 | - elseif($a['channels']==4) |
|
| 1921 | - $colspace = 'DeviceCMYK'; |
|
| 1922 | - else |
|
| 1923 | - $colspace = 'DeviceGray'; |
|
| 1924 | - $bpc = isset($a['bits']) ? $a['bits'] : 8; |
|
| 1925 | - $data = file_get_contents($file); |
|
| 1926 | - return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data);
|
|
| 1912 | + // Extract info from a JPEG file |
|
| 1913 | + $a = getimagesize($file); |
|
| 1914 | + if(!$a) |
|
| 1915 | + $this->Error('Missing or incorrect image file: '.$file);
|
|
| 1916 | + if($a[2]!=2) |
|
| 1917 | + $this->Error('Not a JPEG file: '.$file);
|
|
| 1918 | + if(!isset($a['channels']) || $a['channels']==3) |
|
| 1919 | + $colspace = 'DeviceRGB'; |
|
| 1920 | + elseif($a['channels']==4) |
|
| 1921 | + $colspace = 'DeviceCMYK'; |
|
| 1922 | + else |
|
| 1923 | + $colspace = 'DeviceGray'; |
|
| 1924 | + $bpc = isset($a['bits']) ? $a['bits'] : 8; |
|
| 1925 | + $data = file_get_contents($file); |
|
| 1926 | + return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data);
|
|
| 1927 | 1927 | } |
| 1928 | 1928 | |
| 1929 | 1929 | /** |
@@ -1933,14 +1933,14 @@ discard block |
||
| 1933 | 1933 | */ |
| 1934 | 1934 | protected function _parsepng(string $file) : array |
| 1935 | 1935 | {
|
| 1936 | - // Extract info from a PNG file |
|
| 1937 | - $f = fopen($file, 'rb'); |
|
| 1938 | - if ($f === false) {
|
|
| 1939 | - $this->Error('Can\'t open image file: ' . $file);
|
|
| 1940 | - } |
|
| 1941 | - $info = $this->_parsepngstream($f, $file); |
|
| 1942 | - fclose($f); |
|
| 1943 | - return $info; |
|
| 1936 | + // Extract info from a PNG file |
|
| 1937 | + $f = fopen($file, 'rb'); |
|
| 1938 | + if ($f === false) {
|
|
| 1939 | + $this->Error('Can\'t open image file: ' . $file);
|
|
| 1940 | + } |
|
| 1941 | + $info = $this->_parsepngstream($f, $file); |
|
| 1942 | + fclose($f); |
|
| 1943 | + return $info; |
|
| 1944 | 1944 | } |
| 1945 | 1945 | |
| 1946 | 1946 | /** |
@@ -1951,129 +1951,129 @@ discard block |
||
| 1951 | 1951 | */ |
| 1952 | 1952 | protected function _parsepngstream($f, string $file) : array |
| 1953 | 1953 | {
|
| 1954 | - // Check signature |
|
| 1955 | - if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) |
|
| 1956 | - $this->Error('Not a PNG file: '.$file);
|
|
| 1957 | - |
|
| 1958 | - // Read header chunk |
|
| 1959 | - $this->_readstream($f,4); |
|
| 1960 | - if($this->_readstream($f,4)!='IHDR') |
|
| 1961 | - $this->Error('Incorrect PNG file: '.$file);
|
|
| 1962 | - $w = $this->_readint($f); |
|
| 1963 | - $h = $this->_readint($f); |
|
| 1964 | - $bpc = ord($this->_readstream($f,1)); |
|
| 1965 | - if($bpc>8) |
|
| 1966 | - $this->Error('16-bit depth not supported: '.$file);
|
|
| 1967 | - $ct = ord($this->_readstream($f,1)); |
|
| 1968 | - $colspace = ''; |
|
| 1969 | - if($ct==0 || $ct==4) |
|
| 1970 | - $colspace = 'DeviceGray'; |
|
| 1971 | - elseif($ct==2 || $ct==6) |
|
| 1972 | - $colspace = 'DeviceRGB'; |
|
| 1973 | - elseif($ct==3) |
|
| 1974 | - $colspace = 'Indexed'; |
|
| 1975 | - else |
|
| 1976 | - $this->Error('Unknown color type: '.$file);
|
|
| 1977 | - if(ord($this->_readstream($f,1))!=0) |
|
| 1978 | - $this->Error('Unknown compression method: '.$file);
|
|
| 1979 | - if(ord($this->_readstream($f,1))!=0) |
|
| 1980 | - $this->Error('Unknown filter method: '.$file);
|
|
| 1981 | - if(ord($this->_readstream($f,1))!=0) |
|
| 1982 | - $this->Error('Interlacing not supported: '.$file);
|
|
| 1983 | - $this->_readstream($f,4); |
|
| 1984 | - $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w; |
|
| 1985 | - |
|
| 1986 | - // Scan chunks looking for palette, transparency and image data |
|
| 1987 | - $pal = ''; |
|
| 1988 | - $trns = ''; |
|
| 1989 | - $data = ''; |
|
| 1990 | - do |
|
| 1991 | - {
|
|
| 1992 | - $n = $this->_readint($f); |
|
| 1993 | - $type = $this->_readstream($f,4); |
|
| 1994 | - if($type=='PLTE') |
|
| 1995 | - {
|
|
| 1996 | - // Read palette |
|
| 1997 | - $pal = $this->_readstream($f,$n); |
|
| 1998 | - $this->_readstream($f,4); |
|
| 1999 | - } |
|
| 2000 | - elseif($type=='tRNS') |
|
| 2001 | - {
|
|
| 2002 | - // Read transparency info |
|
| 2003 | - $t = $this->_readstream($f,$n); |
|
| 2004 | - if($ct==0) |
|
| 2005 | - $trns = array(ord(substr($t,1,1))); |
|
| 2006 | - elseif($ct==2) |
|
| 2007 | - $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); |
|
| 2008 | - else |
|
| 2009 | - {
|
|
| 2010 | - $pos = strpos($t,chr(0)); |
|
| 2011 | - if($pos!==false) |
|
| 2012 | - $trns = array($pos); |
|
| 2013 | - } |
|
| 2014 | - $this->_readstream($f,4); |
|
| 2015 | - } |
|
| 2016 | - elseif($type=='IDAT') |
|
| 2017 | - {
|
|
| 2018 | - // Read image data block |
|
| 2019 | - $data .= $this->_readstream($f,$n); |
|
| 2020 | - $this->_readstream($f,4); |
|
| 2021 | - } |
|
| 2022 | - elseif($type=='IEND') |
|
| 2023 | - break; |
|
| 2024 | - else |
|
| 2025 | - $this->_readstream($f,$n+4); |
|
| 2026 | - } |
|
| 2027 | - while($n); |
|
| 2028 | - |
|
| 2029 | - if($colspace=='Indexed' && empty($pal)) |
|
| 2030 | - $this->Error('Missing palette in '.$file);
|
|
| 2031 | - $info = array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns);
|
|
| 2032 | - if($ct>=4) |
|
| 2033 | - {
|
|
| 2034 | - // Extract alpha channel |
|
| 2035 | - if(!function_exists('gzuncompress'))
|
|
| 2036 | - $this->Error('Zlib not available, can\'t handle alpha channel: '.$file);
|
|
| 2037 | - $data = gzuncompress($data); |
|
| 2038 | - $color = ''; |
|
| 2039 | - $alpha = ''; |
|
| 2040 | - if($ct==4) |
|
| 2041 | - {
|
|
| 2042 | - // Gray image |
|
| 2043 | - $len = 2*$w; |
|
| 2044 | - for($i=0;$i<$h;$i++) |
|
| 2045 | - {
|
|
| 2046 | - $pos = (1+$len)*$i; |
|
| 2047 | - $color .= $data[$pos]; |
|
| 2048 | - $alpha .= $data[$pos]; |
|
| 2049 | - $line = substr($data,$pos+1,$len); |
|
| 2050 | - $color .= preg_replace('/(.)./s','$1',$line);
|
|
| 2051 | - $alpha .= preg_replace('/.(.)/s','$1',$line);
|
|
| 2052 | - } |
|
| 2053 | - } |
|
| 2054 | - else |
|
| 2055 | - {
|
|
| 2056 | - // RGB image |
|
| 2057 | - $len = 4*$w; |
|
| 2058 | - for($i=0;$i<$h;$i++) |
|
| 2059 | - {
|
|
| 2060 | - $pos = (1+$len)*$i; |
|
| 2061 | - $color .= $data[$pos]; |
|
| 2062 | - $alpha .= $data[$pos]; |
|
| 2063 | - $line = substr($data,$pos+1,$len); |
|
| 2064 | - $color .= preg_replace('/(.{3})./s','$1',$line);
|
|
| 2065 | - $alpha .= preg_replace('/.{3}(.)/s','$1',$line);
|
|
| 2066 | - } |
|
| 2067 | - } |
|
| 2068 | - unset($data); |
|
| 2069 | - $data = gzcompress($color); |
|
| 2070 | - $info['smask'] = gzcompress($alpha); |
|
| 2071 | - $this->WithAlpha = true; |
|
| 2072 | - if($this->PDFVersion<'1.4') |
|
| 2073 | - $this->PDFVersion = '1.4'; |
|
| 2074 | - } |
|
| 2075 | - $info['data'] = $data; |
|
| 2076 | - return $info; |
|
| 1954 | + // Check signature |
|
| 1955 | + if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) |
|
| 1956 | + $this->Error('Not a PNG file: '.$file);
|
|
| 1957 | + |
|
| 1958 | + // Read header chunk |
|
| 1959 | + $this->_readstream($f,4); |
|
| 1960 | + if($this->_readstream($f,4)!='IHDR') |
|
| 1961 | + $this->Error('Incorrect PNG file: '.$file);
|
|
| 1962 | + $w = $this->_readint($f); |
|
| 1963 | + $h = $this->_readint($f); |
|
| 1964 | + $bpc = ord($this->_readstream($f,1)); |
|
| 1965 | + if($bpc>8) |
|
| 1966 | + $this->Error('16-bit depth not supported: '.$file);
|
|
| 1967 | + $ct = ord($this->_readstream($f,1)); |
|
| 1968 | + $colspace = ''; |
|
| 1969 | + if($ct==0 || $ct==4) |
|
| 1970 | + $colspace = 'DeviceGray'; |
|
| 1971 | + elseif($ct==2 || $ct==6) |
|
| 1972 | + $colspace = 'DeviceRGB'; |
|
| 1973 | + elseif($ct==3) |
|
| 1974 | + $colspace = 'Indexed'; |
|
| 1975 | + else |
|
| 1976 | + $this->Error('Unknown color type: '.$file);
|
|
| 1977 | + if(ord($this->_readstream($f,1))!=0) |
|
| 1978 | + $this->Error('Unknown compression method: '.$file);
|
|
| 1979 | + if(ord($this->_readstream($f,1))!=0) |
|
| 1980 | + $this->Error('Unknown filter method: '.$file);
|
|
| 1981 | + if(ord($this->_readstream($f,1))!=0) |
|
| 1982 | + $this->Error('Interlacing not supported: '.$file);
|
|
| 1983 | + $this->_readstream($f,4); |
|
| 1984 | + $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w; |
|
| 1985 | + |
|
| 1986 | + // Scan chunks looking for palette, transparency and image data |
|
| 1987 | + $pal = ''; |
|
| 1988 | + $trns = ''; |
|
| 1989 | + $data = ''; |
|
| 1990 | + do |
|
| 1991 | + {
|
|
| 1992 | + $n = $this->_readint($f); |
|
| 1993 | + $type = $this->_readstream($f,4); |
|
| 1994 | + if($type=='PLTE') |
|
| 1995 | + {
|
|
| 1996 | + // Read palette |
|
| 1997 | + $pal = $this->_readstream($f,$n); |
|
| 1998 | + $this->_readstream($f,4); |
|
| 1999 | + } |
|
| 2000 | + elseif($type=='tRNS') |
|
| 2001 | + {
|
|
| 2002 | + // Read transparency info |
|
| 2003 | + $t = $this->_readstream($f,$n); |
|
| 2004 | + if($ct==0) |
|
| 2005 | + $trns = array(ord(substr($t,1,1))); |
|
| 2006 | + elseif($ct==2) |
|
| 2007 | + $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1))); |
|
| 2008 | + else |
|
| 2009 | + {
|
|
| 2010 | + $pos = strpos($t,chr(0)); |
|
| 2011 | + if($pos!==false) |
|
| 2012 | + $trns = array($pos); |
|
| 2013 | + } |
|
| 2014 | + $this->_readstream($f,4); |
|
| 2015 | + } |
|
| 2016 | + elseif($type=='IDAT') |
|
| 2017 | + {
|
|
| 2018 | + // Read image data block |
|
| 2019 | + $data .= $this->_readstream($f,$n); |
|
| 2020 | + $this->_readstream($f,4); |
|
| 2021 | + } |
|
| 2022 | + elseif($type=='IEND') |
|
| 2023 | + break; |
|
| 2024 | + else |
|
| 2025 | + $this->_readstream($f,$n+4); |
|
| 2026 | + } |
|
| 2027 | + while($n); |
|
| 2028 | + |
|
| 2029 | + if($colspace=='Indexed' && empty($pal)) |
|
| 2030 | + $this->Error('Missing palette in '.$file);
|
|
| 2031 | + $info = array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns);
|
|
| 2032 | + if($ct>=4) |
|
| 2033 | + {
|
|
| 2034 | + // Extract alpha channel |
|
| 2035 | + if(!function_exists('gzuncompress'))
|
|
| 2036 | + $this->Error('Zlib not available, can\'t handle alpha channel: '.$file);
|
|
| 2037 | + $data = gzuncompress($data); |
|
| 2038 | + $color = ''; |
|
| 2039 | + $alpha = ''; |
|
| 2040 | + if($ct==4) |
|
| 2041 | + {
|
|
| 2042 | + // Gray image |
|
| 2043 | + $len = 2*$w; |
|
| 2044 | + for($i=0;$i<$h;$i++) |
|
| 2045 | + {
|
|
| 2046 | + $pos = (1+$len)*$i; |
|
| 2047 | + $color .= $data[$pos]; |
|
| 2048 | + $alpha .= $data[$pos]; |
|
| 2049 | + $line = substr($data,$pos+1,$len); |
|
| 2050 | + $color .= preg_replace('/(.)./s','$1',$line);
|
|
| 2051 | + $alpha .= preg_replace('/.(.)/s','$1',$line);
|
|
| 2052 | + } |
|
| 2053 | + } |
|
| 2054 | + else |
|
| 2055 | + {
|
|
| 2056 | + // RGB image |
|
| 2057 | + $len = 4*$w; |
|
| 2058 | + for($i=0;$i<$h;$i++) |
|
| 2059 | + {
|
|
| 2060 | + $pos = (1+$len)*$i; |
|
| 2061 | + $color .= $data[$pos]; |
|
| 2062 | + $alpha .= $data[$pos]; |
|
| 2063 | + $line = substr($data,$pos+1,$len); |
|
| 2064 | + $color .= preg_replace('/(.{3})./s','$1',$line);
|
|
| 2065 | + $alpha .= preg_replace('/.{3}(.)/s','$1',$line);
|
|
| 2066 | + } |
|
| 2067 | + } |
|
| 2068 | + unset($data); |
|
| 2069 | + $data = gzcompress($color); |
|
| 2070 | + $info['smask'] = gzcompress($alpha); |
|
| 2071 | + $this->WithAlpha = true; |
|
| 2072 | + if($this->PDFVersion<'1.4') |
|
| 2073 | + $this->PDFVersion = '1.4'; |
|
| 2074 | + } |
|
| 2075 | + $info['data'] = $data; |
|
| 2076 | + return $info; |
|
| 2077 | 2077 | } |
| 2078 | 2078 | |
| 2079 | 2079 | /** |
@@ -2084,19 +2084,19 @@ discard block |
||
| 2084 | 2084 | */ |
| 2085 | 2085 | protected function _readstream($f, int $n) : string |
| 2086 | 2086 | {
|
| 2087 | - // Read n bytes from stream |
|
| 2088 | - $res = ''; |
|
| 2089 | - while($n>0 && !feof($f)) |
|
| 2090 | - {
|
|
| 2091 | - $s = fread($f,$n); |
|
| 2092 | - if($s===false) |
|
| 2093 | - $this->Error('Error while reading stream');
|
|
| 2094 | - $n -= strlen($s); |
|
| 2095 | - $res .= $s; |
|
| 2096 | - } |
|
| 2097 | - if($n>0) |
|
| 2098 | - $this->Error('Unexpected end of stream');
|
|
| 2099 | - return $res; |
|
| 2087 | + // Read n bytes from stream |
|
| 2088 | + $res = ''; |
|
| 2089 | + while($n>0 && !feof($f)) |
|
| 2090 | + {
|
|
| 2091 | + $s = fread($f,$n); |
|
| 2092 | + if($s===false) |
|
| 2093 | + $this->Error('Error while reading stream');
|
|
| 2094 | + $n -= strlen($s); |
|
| 2095 | + $res .= $s; |
|
| 2096 | + } |
|
| 2097 | + if($n>0) |
|
| 2098 | + $this->Error('Unexpected end of stream');
|
|
| 2099 | + return $res; |
|
| 2100 | 2100 | } |
| 2101 | 2101 | |
| 2102 | 2102 | /** |
@@ -2106,9 +2106,9 @@ discard block |
||
| 2106 | 2106 | */ |
| 2107 | 2107 | protected function _readint($f) : int |
| 2108 | 2108 | {
|
| 2109 | - // Read a 4-byte integer from stream |
|
| 2110 | - $a = unpack('Ni',$this->_readstream($f,4));
|
|
| 2111 | - return $a['i']; |
|
| 2109 | + // Read a 4-byte integer from stream |
|
| 2110 | + $a = unpack('Ni',$this->_readstream($f,4));
|
|
| 2111 | + return $a['i']; |
|
| 2112 | 2112 | } |
| 2113 | 2113 | |
| 2114 | 2114 | /** |
@@ -2118,31 +2118,31 @@ discard block |
||
| 2118 | 2118 | */ |
| 2119 | 2119 | protected function _parsegif(string $file) : array |
| 2120 | 2120 | {
|
| 2121 | - // Extract info from a GIF file (via PNG conversion) |
|
| 2121 | + // Extract info from a GIF file (via PNG conversion) |
|
| 2122 | 2122 | if (!function_exists('imagepng')) {
|
| 2123 | - $this->Error('GD extension is required for GIF support');
|
|
| 2123 | + $this->Error('GD extension is required for GIF support');
|
|
| 2124 | 2124 | } |
| 2125 | 2125 | if (!function_exists('imagecreatefromgif')) {
|
| 2126 | - $this->Error('GD has no GIF read support');
|
|
| 2127 | - } |
|
| 2128 | - $im = imagecreatefromgif($file); |
|
| 2129 | - if ($im === false) {
|
|
| 2130 | - $this->Error('Missing or incorrect image file: ' . $file);
|
|
| 2131 | - } |
|
| 2132 | - imageinterlace($im, 0); |
|
| 2133 | - ob_start(); |
|
| 2134 | - imagepng($im); |
|
| 2135 | - $data = ob_get_clean(); |
|
| 2136 | - imagedestroy($im); |
|
| 2137 | - $f = fopen('php://temp', 'rb+');
|
|
| 2138 | - if ($f === false) {
|
|
| 2139 | - $this->Error('Unable to create memory stream');
|
|
| 2140 | - } |
|
| 2141 | - fwrite($f, $data); |
|
| 2142 | - rewind($f); |
|
| 2143 | - $info = $this->_parsepngstream($f, $file); |
|
| 2144 | - fclose($f); |
|
| 2145 | - return $info; |
|
| 2126 | + $this->Error('GD has no GIF read support');
|
|
| 2127 | + } |
|
| 2128 | + $im = imagecreatefromgif($file); |
|
| 2129 | + if ($im === false) {
|
|
| 2130 | + $this->Error('Missing or incorrect image file: ' . $file);
|
|
| 2131 | + } |
|
| 2132 | + imageinterlace($im, 0); |
|
| 2133 | + ob_start(); |
|
| 2134 | + imagepng($im); |
|
| 2135 | + $data = ob_get_clean(); |
|
| 2136 | + imagedestroy($im); |
|
| 2137 | + $f = fopen('php://temp', 'rb+');
|
|
| 2138 | + if ($f === false) {
|
|
| 2139 | + $this->Error('Unable to create memory stream');
|
|
| 2140 | + } |
|
| 2141 | + fwrite($f, $data); |
|
| 2142 | + rewind($f); |
|
| 2143 | + $info = $this->_parsepngstream($f, $file); |
|
| 2144 | + fclose($f); |
|
| 2145 | + return $info; |
|
| 2146 | 2146 | } |
| 2147 | 2147 | |
| 2148 | 2148 | /** |
@@ -2151,15 +2151,15 @@ discard block |
||
| 2151 | 2151 | */ |
| 2152 | 2152 | protected function _out(string $s) : void |
| 2153 | 2153 | {
|
| 2154 | - // Add a line to the document |
|
| 2155 | - if($this->state==2) |
|
| 2156 | - $this->pages[$this->page] .= $s."\n"; |
|
| 2157 | - elseif($this->state==1) |
|
| 2158 | - $this->_put($s); |
|
| 2159 | - elseif($this->state==0) |
|
| 2160 | - $this->Error('No page has been added yet');
|
|
| 2161 | - elseif($this->state==3) |
|
| 2162 | - $this->Error('The document is closed');
|
|
| 2154 | + // Add a line to the document |
|
| 2155 | + if($this->state==2) |
|
| 2156 | + $this->pages[$this->page] .= $s."\n"; |
|
| 2157 | + elseif($this->state==1) |
|
| 2158 | + $this->_put($s); |
|
| 2159 | + elseif($this->state==0) |
|
| 2160 | + $this->Error('No page has been added yet');
|
|
| 2161 | + elseif($this->state==3) |
|
| 2162 | + $this->Error('The document is closed');
|
|
| 2163 | 2163 | } |
| 2164 | 2164 | |
| 2165 | 2165 | /** |
@@ -2168,7 +2168,7 @@ discard block |
||
| 2168 | 2168 | */ |
| 2169 | 2169 | protected function _put(string $s) : void |
| 2170 | 2170 | {
|
| 2171 | - $this->buffer .= $s."\n"; |
|
| 2171 | + $this->buffer .= $s."\n"; |
|
| 2172 | 2172 | } |
| 2173 | 2173 | |
| 2174 | 2174 | /** |
@@ -2177,7 +2177,7 @@ discard block |
||
| 2177 | 2177 | */ |
| 2178 | 2178 | protected function _getoffset() : int |
| 2179 | 2179 | {
|
| 2180 | - return strlen($this->buffer); |
|
| 2180 | + return strlen($this->buffer); |
|
| 2181 | 2181 | } |
| 2182 | 2182 | |
| 2183 | 2183 | /** |
@@ -2186,11 +2186,11 @@ discard block |
||
| 2186 | 2186 | */ |
| 2187 | 2187 | protected function _newobj(?int $n=null) : void |
| 2188 | 2188 | {
|
| 2189 | - // Begin a new object |
|
| 2190 | - if($n===null) |
|
| 2191 | - $n = ++$this->n; |
|
| 2192 | - $this->offsets[$n] = $this->_getoffset(); |
|
| 2193 | - $this->_put($n.' 0 obj'); |
|
| 2189 | + // Begin a new object |
|
| 2190 | + if($n===null) |
|
| 2191 | + $n = ++$this->n; |
|
| 2192 | + $this->offsets[$n] = $this->_getoffset(); |
|
| 2193 | + $this->_put($n.' 0 obj'); |
|
| 2194 | 2194 | } |
| 2195 | 2195 | |
| 2196 | 2196 | /** |
@@ -2199,9 +2199,9 @@ discard block |
||
| 2199 | 2199 | */ |
| 2200 | 2200 | protected function _putstream(string $data) : void |
| 2201 | 2201 | {
|
| 2202 | - $this->_put('stream');
|
|
| 2203 | - $this->_put($data); |
|
| 2204 | - $this->_put('endstream');
|
|
| 2202 | + $this->_put('stream');
|
|
| 2203 | + $this->_put($data); |
|
| 2204 | + $this->_put('endstream');
|
|
| 2205 | 2205 | } |
| 2206 | 2206 | |
| 2207 | 2207 | /** |
@@ -2210,18 +2210,18 @@ discard block |
||
| 2210 | 2210 | */ |
| 2211 | 2211 | protected function _putstreamobject(string $data) : void |
| 2212 | 2212 | {
|
| 2213 | - if($this->compress) |
|
| 2214 | - {
|
|
| 2215 | - $entries = '/Filter /FlateDecode '; |
|
| 2216 | - $data = gzcompress($data); |
|
| 2217 | - } |
|
| 2218 | - else |
|
| 2219 | - $entries = ''; |
|
| 2220 | - $entries .= '/Length '.strlen($data); |
|
| 2221 | - $this->_newobj(); |
|
| 2222 | - $this->_put('<<'.$entries.'>>');
|
|
| 2223 | - $this->_putstream($data); |
|
| 2224 | - $this->_put('endobj');
|
|
| 2213 | + if($this->compress) |
|
| 2214 | + {
|
|
| 2215 | + $entries = '/Filter /FlateDecode '; |
|
| 2216 | + $data = gzcompress($data); |
|
| 2217 | + } |
|
| 2218 | + else |
|
| 2219 | + $entries = ''; |
|
| 2220 | + $entries .= '/Length '.strlen($data); |
|
| 2221 | + $this->_newobj(); |
|
| 2222 | + $this->_put('<<'.$entries.'>>');
|
|
| 2223 | + $this->_putstream($data); |
|
| 2224 | + $this->_put('endobj');
|
|
| 2225 | 2225 | } |
| 2226 | 2226 | |
| 2227 | 2227 | /** |
@@ -2230,44 +2230,44 @@ discard block |
||
| 2230 | 2230 | */ |
| 2231 | 2231 | protected function _putpage(int $n) : void |
| 2232 | 2232 | {
|
| 2233 | - $this->_newobj(); |
|
| 2234 | - $this->_put('<</Type /Page');
|
|
| 2235 | - $this->_put('/Parent 1 0 R');
|
|
| 2236 | - if(isset($this->PageInfo[$n]['size'])) |
|
| 2237 | - $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo[$n]['size'][0],$this->PageInfo[$n]['size'][1]));
|
|
| 2238 | - if(isset($this->PageInfo[$n]['rotation'])) |
|
| 2239 | - $this->_put('/Rotate '.$this->PageInfo[$n]['rotation']);
|
|
| 2240 | - $this->_put('/Resources 2 0 R');
|
|
| 2241 | - if(isset($this->PageLinks[$n])) |
|
| 2242 | - {
|
|
| 2243 | - // Links |
|
| 2244 | - $annots = '/Annots ['; |
|
| 2245 | - foreach($this->PageLinks[$n] as $pl) |
|
| 2246 | - {
|
|
| 2247 | - $rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
|
|
| 2248 | - $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
|
| 2249 | - if(is_string($pl[4])) |
|
| 2250 | - $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
|
| 2251 | - else |
|
| 2252 | - {
|
|
| 2253 | - $l = $this->links[$pl[4]]; |
|
| 2254 | - if(isset($this->PageInfo[$l[0]]['size'])) |
|
| 2255 | - $h = $this->PageInfo[$l[0]]['size'][1]; |
|
| 2256 | - else |
|
| 2257 | - $h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k; |
|
| 2258 | - $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[$l[0]]['n'],$h-$l[1]*$this->k);
|
|
| 2259 | - } |
|
| 2260 | - } |
|
| 2261 | - $this->_put($annots.']'); |
|
| 2262 | - } |
|
| 2263 | - if($this->WithAlpha) |
|
| 2264 | - $this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>');
|
|
| 2265 | - $this->_put('/Contents '.($this->n+1).' 0 R>>');
|
|
| 2266 | - $this->_put('endobj');
|
|
| 2267 | - // Page content |
|
| 2268 | - if(!empty($this->AliasNbPages)) |
|
| 2269 | - $this->pages[$n] = str_replace($this->AliasNbPages, strval($this->page), $this->pages[$n]); |
|
| 2270 | - $this->_putstreamobject($this->pages[$n]); |
|
| 2233 | + $this->_newobj(); |
|
| 2234 | + $this->_put('<</Type /Page');
|
|
| 2235 | + $this->_put('/Parent 1 0 R');
|
|
| 2236 | + if(isset($this->PageInfo[$n]['size'])) |
|
| 2237 | + $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo[$n]['size'][0],$this->PageInfo[$n]['size'][1]));
|
|
| 2238 | + if(isset($this->PageInfo[$n]['rotation'])) |
|
| 2239 | + $this->_put('/Rotate '.$this->PageInfo[$n]['rotation']);
|
|
| 2240 | + $this->_put('/Resources 2 0 R');
|
|
| 2241 | + if(isset($this->PageLinks[$n])) |
|
| 2242 | + {
|
|
| 2243 | + // Links |
|
| 2244 | + $annots = '/Annots ['; |
|
| 2245 | + foreach($this->PageLinks[$n] as $pl) |
|
| 2246 | + {
|
|
| 2247 | + $rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
|
|
| 2248 | + $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
|
| 2249 | + if(is_string($pl[4])) |
|
| 2250 | + $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
|
| 2251 | + else |
|
| 2252 | + {
|
|
| 2253 | + $l = $this->links[$pl[4]]; |
|
| 2254 | + if(isset($this->PageInfo[$l[0]]['size'])) |
|
| 2255 | + $h = $this->PageInfo[$l[0]]['size'][1]; |
|
| 2256 | + else |
|
| 2257 | + $h = ($this->DefOrientation=='P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k; |
|
| 2258 | + $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[$l[0]]['n'],$h-$l[1]*$this->k);
|
|
| 2259 | + } |
|
| 2260 | + } |
|
| 2261 | + $this->_put($annots.']'); |
|
| 2262 | + } |
|
| 2263 | + if($this->WithAlpha) |
|
| 2264 | + $this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>');
|
|
| 2265 | + $this->_put('/Contents '.($this->n+1).' 0 R>>');
|
|
| 2266 | + $this->_put('endobj');
|
|
| 2267 | + // Page content |
|
| 2268 | + if(!empty($this->AliasNbPages)) |
|
| 2269 | + $this->pages[$n] = str_replace($this->AliasNbPages, strval($this->page), $this->pages[$n]); |
|
| 2270 | + $this->_putstreamobject($this->pages[$n]); |
|
| 2271 | 2271 | } |
| 2272 | 2272 | |
| 2273 | 2273 | /** |
@@ -2275,32 +2275,32 @@ discard block |
||
| 2275 | 2275 | */ |
| 2276 | 2276 | protected function _putpages() : void |
| 2277 | 2277 | {
|
| 2278 | - $nb = $this->page; |
|
| 2279 | - for($n=1;$n<=$nb;$n++) |
|
| 2280 | - $this->PageInfo[$n]['n'] = $this->n+1+2*($n-1); |
|
| 2281 | - for($n=1;$n<=$nb;$n++) |
|
| 2282 | - $this->_putpage($n); |
|
| 2283 | - // Pages root |
|
| 2284 | - $this->_newobj(1); |
|
| 2285 | - $this->_put('<</Type /Pages');
|
|
| 2286 | - $kids = '/Kids ['; |
|
| 2287 | - for($n=1;$n<=$nb;$n++) |
|
| 2288 | - $kids .= $this->PageInfo[$n]['n'].' 0 R '; |
|
| 2289 | - $this->_put($kids.']'); |
|
| 2290 | - $this->_put('/Count '.$nb);
|
|
| 2291 | - if($this->DefOrientation=='P') |
|
| 2292 | - {
|
|
| 2293 | - $w = $this->DefPageSize[0]; |
|
| 2294 | - $h = $this->DefPageSize[1]; |
|
| 2295 | - } |
|
| 2296 | - else |
|
| 2297 | - {
|
|
| 2298 | - $w = $this->DefPageSize[1]; |
|
| 2299 | - $h = $this->DefPageSize[0]; |
|
| 2300 | - } |
|
| 2301 | - $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$w*$this->k,$h*$this->k));
|
|
| 2302 | - $this->_put('>>');
|
|
| 2303 | - $this->_put('endobj');
|
|
| 2278 | + $nb = $this->page; |
|
| 2279 | + for($n=1;$n<=$nb;$n++) |
|
| 2280 | + $this->PageInfo[$n]['n'] = $this->n+1+2*($n-1); |
|
| 2281 | + for($n=1;$n<=$nb;$n++) |
|
| 2282 | + $this->_putpage($n); |
|
| 2283 | + // Pages root |
|
| 2284 | + $this->_newobj(1); |
|
| 2285 | + $this->_put('<</Type /Pages');
|
|
| 2286 | + $kids = '/Kids ['; |
|
| 2287 | + for($n=1;$n<=$nb;$n++) |
|
| 2288 | + $kids .= $this->PageInfo[$n]['n'].' 0 R '; |
|
| 2289 | + $this->_put($kids.']'); |
|
| 2290 | + $this->_put('/Count '.$nb);
|
|
| 2291 | + if($this->DefOrientation=='P') |
|
| 2292 | + {
|
|
| 2293 | + $w = $this->DefPageSize[0]; |
|
| 2294 | + $h = $this->DefPageSize[1]; |
|
| 2295 | + } |
|
| 2296 | + else |
|
| 2297 | + {
|
|
| 2298 | + $w = $this->DefPageSize[1]; |
|
| 2299 | + $h = $this->DefPageSize[0]; |
|
| 2300 | + } |
|
| 2301 | + $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$w*$this->k,$h*$this->k));
|
|
| 2302 | + $this->_put('>>');
|
|
| 2303 | + $this->_put('endobj');
|
|
| 2304 | 2304 | } |
| 2305 | 2305 | |
| 2306 | 2306 | /** |
@@ -2308,123 +2308,123 @@ discard block |
||
| 2308 | 2308 | */ |
| 2309 | 2309 | protected function _putfonts() : void |
| 2310 | 2310 | {
|
| 2311 | - foreach ($this->FontFiles as $file => $info) {
|
|
| 2312 | - // Font file embedding |
|
| 2313 | - $this->_newobj(); |
|
| 2314 | - $this->FontFiles[$file]['n'] = $this->n; |
|
| 2315 | - $font = file_get_contents($this->fontpath . $file, true); |
|
| 2316 | - if (!$font) {
|
|
| 2317 | - $this->Error('Font file not found: ' . $file);
|
|
| 2318 | - } |
|
| 2319 | - $compressed = (substr($file, -2) == '.z'); |
|
| 2320 | - if (!$compressed && isset($info['length2'])) {
|
|
| 2321 | - $font = substr($font, 6, $info['length1']) . substr($font, 6 + $info['length1'] + 6, $info['length2']); |
|
| 2322 | - } |
|
| 2323 | - $this->_put('<</Length ' . strlen($font));
|
|
| 2324 | - if ($compressed) {
|
|
| 2325 | - $this->_put('/Filter /FlateDecode');
|
|
| 2326 | - } |
|
| 2327 | - $this->_put('/Length1 ' . $info['length1']);
|
|
| 2328 | - if (isset($info['length2'])) {
|
|
| 2329 | - $this->_put('/Length2 '.$info['length2'].' /Length3 0');
|
|
| 2330 | - } |
|
| 2331 | - $this->_put('>>');
|
|
| 2332 | - $this->_putstream($font); |
|
| 2333 | - $this->_put('endobj');
|
|
| 2334 | - } |
|
| 2335 | - foreach ($this->fonts as $k => $font) {
|
|
| 2336 | - // Encoding |
|
| 2337 | - if (isset($font['diff'])) {
|
|
| 2338 | - if (!isset($this->encodings[$font['enc']])) {
|
|
| 2339 | - $this->_newobj(); |
|
| 2340 | - $this->_put('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' . $font['diff'] . ']>>');
|
|
| 2341 | - $this->_put('endobj');
|
|
| 2342 | - $this->encodings[$font['enc']] = $this->n; |
|
| 2343 | - } |
|
| 2344 | - } |
|
| 2345 | - // ToUnicode CMap |
|
| 2346 | - $cmapkey = ''; |
|
| 2347 | - if (isset($font['uv'])) {
|
|
| 2348 | - if (isset($font['enc'])) {
|
|
| 2349 | - $cmapkey = $font['enc']; |
|
| 2350 | - } else {
|
|
| 2351 | - $cmapkey = $font['name']; |
|
| 2352 | - } |
|
| 2353 | - if (!isset($this->cmaps[$cmapkey])) {
|
|
| 2354 | - $cmap = $this->_tounicodecmap($font['uv']); |
|
| 2355 | - $this->_putstreamobject($cmap); |
|
| 2356 | - $this->cmaps[$cmapkey] = $this->n; |
|
| 2357 | - } |
|
| 2358 | - } |
|
| 2359 | - // Font object |
|
| 2360 | - $this->fonts[$k]['n'] = $this->n + 1; |
|
| 2361 | - $type = $font['type']; |
|
| 2362 | - $name = $font['name']; |
|
| 2363 | - if ($font['subsetted']) {
|
|
| 2364 | - $name = 'AAAAAA+' . $name; |
|
| 2365 | - } |
|
| 2366 | - if ($type=='Core') {
|
|
| 2367 | - // Core font |
|
| 2368 | - $this->_newobj(); |
|
| 2369 | - $this->_put('<</Type /Font');
|
|
| 2370 | - $this->_put('/BaseFont /' . $name);
|
|
| 2371 | - $this->_put('/Subtype /Type1');
|
|
| 2372 | - if ($name != 'Symbol' && $name != 'ZapfDingbats') {
|
|
| 2373 | - $this->_put('/Encoding /WinAnsiEncoding');
|
|
| 2374 | - } |
|
| 2375 | - if (isset($font['uv'])) {
|
|
| 2376 | - $this->_put('/ToUnicode ' . $this->cmaps[$cmapkey] . ' 0 R');
|
|
| 2377 | - } |
|
| 2378 | - $this->_put('>>');
|
|
| 2379 | - $this->_put('endobj');
|
|
| 2380 | - } elseif ($type == 'Type1' || $type == 'TrueType') {
|
|
| 2381 | - // Additional Type1 or TrueType/OpenType font |
|
| 2382 | - $this->_newobj(); |
|
| 2383 | - $this->_put('<</Type /Font');
|
|
| 2384 | - $this->_put('/BaseFont /' . $name);
|
|
| 2385 | - $this->_put('/Subtype /' . $type);
|
|
| 2386 | - $this->_put('/FirstChar 32 /LastChar 255');
|
|
| 2387 | - $this->_put('/Widths ' . ($this->n + 1) . ' 0 R');
|
|
| 2388 | - $this->_put('/FontDescriptor ' . ($this->n + 2) . ' 0 R');
|
|
| 2389 | - if (isset($font['diff'])) {
|
|
| 2390 | - $this->_put('/Encoding ' . $this->encodings[$font['enc']] . ' 0 R');
|
|
| 2391 | - } else {
|
|
| 2392 | - $this->_put('/Encoding /WinAnsiEncoding');
|
|
| 2393 | - } |
|
| 2394 | - if (isset($font['uv'])) {
|
|
| 2395 | - $this->_put('/ToUnicode ' . $this->cmaps[$cmapkey] . ' 0 R');
|
|
| 2396 | - } |
|
| 2397 | - $this->_put('>>');
|
|
| 2398 | - $this->_put('endobj');
|
|
| 2399 | - // Widths |
|
| 2400 | - $this->_newobj(); |
|
| 2401 | - $cw = &$font['cw']; |
|
| 2402 | - $s = '['; |
|
| 2403 | - for ($i = 32; $i <= 255; $i++) {
|
|
| 2404 | - $s .= $cw[chr($i)] . ' '; |
|
| 2405 | - } |
|
| 2406 | - $this->_put($s . ']'); |
|
| 2407 | - $this->_put('endobj');
|
|
| 2408 | - // Descriptor |
|
| 2409 | - $this->_newobj(); |
|
| 2410 | - $s = '<</Type /FontDescriptor /FontName /' . $name; |
|
| 2411 | - foreach ($font['desc'] as $k2 => $v) {
|
|
| 2412 | - $s .= ' /' . $k2 . ' ' . $v; |
|
| 2413 | - } |
|
| 2414 | - if (!empty($font['file'])) {
|
|
| 2415 | - $s .= ' /FontFile' . ($type == 'Type1' ? '' : '2') . ' ' . $this->FontFiles[$font['file']]['n'] . ' 0 R'; |
|
| 2416 | - } |
|
| 2417 | - $this->_put($s . '>>'); |
|
| 2418 | - $this->_put('endobj');
|
|
| 2419 | - } else {
|
|
| 2420 | - // Allow for additional types |
|
| 2421 | - $mtd = '_put' . strtolower($type); |
|
| 2422 | - if (!method_exists($this, $mtd)) {
|
|
| 2423 | - $this->Error('Unsupported font type: ' . $type);
|
|
| 2424 | - } |
|
| 2425 | - $this->$mtd($font); |
|
| 2426 | - } |
|
| 2427 | - } |
|
| 2311 | + foreach ($this->FontFiles as $file => $info) {
|
|
| 2312 | + // Font file embedding |
|
| 2313 | + $this->_newobj(); |
|
| 2314 | + $this->FontFiles[$file]['n'] = $this->n; |
|
| 2315 | + $font = file_get_contents($this->fontpath . $file, true); |
|
| 2316 | + if (!$font) {
|
|
| 2317 | + $this->Error('Font file not found: ' . $file);
|
|
| 2318 | + } |
|
| 2319 | + $compressed = (substr($file, -2) == '.z'); |
|
| 2320 | + if (!$compressed && isset($info['length2'])) {
|
|
| 2321 | + $font = substr($font, 6, $info['length1']) . substr($font, 6 + $info['length1'] + 6, $info['length2']); |
|
| 2322 | + } |
|
| 2323 | + $this->_put('<</Length ' . strlen($font));
|
|
| 2324 | + if ($compressed) {
|
|
| 2325 | + $this->_put('/Filter /FlateDecode');
|
|
| 2326 | + } |
|
| 2327 | + $this->_put('/Length1 ' . $info['length1']);
|
|
| 2328 | + if (isset($info['length2'])) {
|
|
| 2329 | + $this->_put('/Length2 '.$info['length2'].' /Length3 0');
|
|
| 2330 | + } |
|
| 2331 | + $this->_put('>>');
|
|
| 2332 | + $this->_putstream($font); |
|
| 2333 | + $this->_put('endobj');
|
|
| 2334 | + } |
|
| 2335 | + foreach ($this->fonts as $k => $font) {
|
|
| 2336 | + // Encoding |
|
| 2337 | + if (isset($font['diff'])) {
|
|
| 2338 | + if (!isset($this->encodings[$font['enc']])) {
|
|
| 2339 | + $this->_newobj(); |
|
| 2340 | + $this->_put('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' . $font['diff'] . ']>>');
|
|
| 2341 | + $this->_put('endobj');
|
|
| 2342 | + $this->encodings[$font['enc']] = $this->n; |
|
| 2343 | + } |
|
| 2344 | + } |
|
| 2345 | + // ToUnicode CMap |
|
| 2346 | + $cmapkey = ''; |
|
| 2347 | + if (isset($font['uv'])) {
|
|
| 2348 | + if (isset($font['enc'])) {
|
|
| 2349 | + $cmapkey = $font['enc']; |
|
| 2350 | + } else {
|
|
| 2351 | + $cmapkey = $font['name']; |
|
| 2352 | + } |
|
| 2353 | + if (!isset($this->cmaps[$cmapkey])) {
|
|
| 2354 | + $cmap = $this->_tounicodecmap($font['uv']); |
|
| 2355 | + $this->_putstreamobject($cmap); |
|
| 2356 | + $this->cmaps[$cmapkey] = $this->n; |
|
| 2357 | + } |
|
| 2358 | + } |
|
| 2359 | + // Font object |
|
| 2360 | + $this->fonts[$k]['n'] = $this->n + 1; |
|
| 2361 | + $type = $font['type']; |
|
| 2362 | + $name = $font['name']; |
|
| 2363 | + if ($font['subsetted']) {
|
|
| 2364 | + $name = 'AAAAAA+' . $name; |
|
| 2365 | + } |
|
| 2366 | + if ($type=='Core') {
|
|
| 2367 | + // Core font |
|
| 2368 | + $this->_newobj(); |
|
| 2369 | + $this->_put('<</Type /Font');
|
|
| 2370 | + $this->_put('/BaseFont /' . $name);
|
|
| 2371 | + $this->_put('/Subtype /Type1');
|
|
| 2372 | + if ($name != 'Symbol' && $name != 'ZapfDingbats') {
|
|
| 2373 | + $this->_put('/Encoding /WinAnsiEncoding');
|
|
| 2374 | + } |
|
| 2375 | + if (isset($font['uv'])) {
|
|
| 2376 | + $this->_put('/ToUnicode ' . $this->cmaps[$cmapkey] . ' 0 R');
|
|
| 2377 | + } |
|
| 2378 | + $this->_put('>>');
|
|
| 2379 | + $this->_put('endobj');
|
|
| 2380 | + } elseif ($type == 'Type1' || $type == 'TrueType') {
|
|
| 2381 | + // Additional Type1 or TrueType/OpenType font |
|
| 2382 | + $this->_newobj(); |
|
| 2383 | + $this->_put('<</Type /Font');
|
|
| 2384 | + $this->_put('/BaseFont /' . $name);
|
|
| 2385 | + $this->_put('/Subtype /' . $type);
|
|
| 2386 | + $this->_put('/FirstChar 32 /LastChar 255');
|
|
| 2387 | + $this->_put('/Widths ' . ($this->n + 1) . ' 0 R');
|
|
| 2388 | + $this->_put('/FontDescriptor ' . ($this->n + 2) . ' 0 R');
|
|
| 2389 | + if (isset($font['diff'])) {
|
|
| 2390 | + $this->_put('/Encoding ' . $this->encodings[$font['enc']] . ' 0 R');
|
|
| 2391 | + } else {
|
|
| 2392 | + $this->_put('/Encoding /WinAnsiEncoding');
|
|
| 2393 | + } |
|
| 2394 | + if (isset($font['uv'])) {
|
|
| 2395 | + $this->_put('/ToUnicode ' . $this->cmaps[$cmapkey] . ' 0 R');
|
|
| 2396 | + } |
|
| 2397 | + $this->_put('>>');
|
|
| 2398 | + $this->_put('endobj');
|
|
| 2399 | + // Widths |
|
| 2400 | + $this->_newobj(); |
|
| 2401 | + $cw = &$font['cw']; |
|
| 2402 | + $s = '['; |
|
| 2403 | + for ($i = 32; $i <= 255; $i++) {
|
|
| 2404 | + $s .= $cw[chr($i)] . ' '; |
|
| 2405 | + } |
|
| 2406 | + $this->_put($s . ']'); |
|
| 2407 | + $this->_put('endobj');
|
|
| 2408 | + // Descriptor |
|
| 2409 | + $this->_newobj(); |
|
| 2410 | + $s = '<</Type /FontDescriptor /FontName /' . $name; |
|
| 2411 | + foreach ($font['desc'] as $k2 => $v) {
|
|
| 2412 | + $s .= ' /' . $k2 . ' ' . $v; |
|
| 2413 | + } |
|
| 2414 | + if (!empty($font['file'])) {
|
|
| 2415 | + $s .= ' /FontFile' . ($type == 'Type1' ? '' : '2') . ' ' . $this->FontFiles[$font['file']]['n'] . ' 0 R'; |
|
| 2416 | + } |
|
| 2417 | + $this->_put($s . '>>'); |
|
| 2418 | + $this->_put('endobj');
|
|
| 2419 | + } else {
|
|
| 2420 | + // Allow for additional types |
|
| 2421 | + $mtd = '_put' . strtolower($type); |
|
| 2422 | + if (!method_exists($this, $mtd)) {
|
|
| 2423 | + $this->Error('Unsupported font type: ' . $type);
|
|
| 2424 | + } |
|
| 2425 | + $this->$mtd($font); |
|
| 2426 | + } |
|
| 2427 | + } |
|
| 2428 | 2428 | } |
| 2429 | 2429 | |
| 2430 | 2430 | /** |
@@ -2433,53 +2433,53 @@ discard block |
||
| 2433 | 2433 | */ |
| 2434 | 2434 | protected function _tounicodecmap(array $uv) : string |
| 2435 | 2435 | {
|
| 2436 | - $ranges = ''; |
|
| 2437 | - $nbr = 0; |
|
| 2438 | - $chars = ''; |
|
| 2439 | - $nbc = 0; |
|
| 2440 | - foreach($uv as $c=>$v) |
|
| 2441 | - {
|
|
| 2442 | - if(is_array($v)) |
|
| 2443 | - {
|
|
| 2444 | - $ranges .= sprintf("<%02X> <%02X> <%04X>\n",$c,$c+$v[1]-1,$v[0]);
|
|
| 2445 | - $nbr++; |
|
| 2446 | - } |
|
| 2447 | - else |
|
| 2448 | - {
|
|
| 2449 | - $chars .= sprintf("<%02X> <%04X>\n",$c,$v);
|
|
| 2450 | - $nbc++; |
|
| 2451 | - } |
|
| 2452 | - } |
|
| 2453 | - $s = "/CIDInit /ProcSet findresource begin\n"; |
|
| 2454 | - $s .= "12 dict begin\n"; |
|
| 2455 | - $s .= "begincmap\n"; |
|
| 2456 | - $s .= "/CIDSystemInfo\n"; |
|
| 2457 | - $s .= "<</Registry (Adobe)\n"; |
|
| 2458 | - $s .= "/Ordering (UCS)\n"; |
|
| 2459 | - $s .= "/Supplement 0\n"; |
|
| 2460 | - $s .= ">> def\n"; |
|
| 2461 | - $s .= "/CMapName /Adobe-Identity-UCS def\n"; |
|
| 2462 | - $s .= "/CMapType 2 def\n"; |
|
| 2463 | - $s .= "1 begincodespacerange\n"; |
|
| 2464 | - $s .= "<00> <FF>\n"; |
|
| 2465 | - $s .= "endcodespacerange\n"; |
|
| 2466 | - if($nbr>0) |
|
| 2467 | - {
|
|
| 2468 | - $s .= "$nbr beginbfrange\n"; |
|
| 2469 | - $s .= $ranges; |
|
| 2470 | - $s .= "endbfrange\n"; |
|
| 2471 | - } |
|
| 2472 | - if($nbc>0) |
|
| 2473 | - {
|
|
| 2474 | - $s .= "$nbc beginbfchar\n"; |
|
| 2475 | - $s .= $chars; |
|
| 2476 | - $s .= "endbfchar\n"; |
|
| 2477 | - } |
|
| 2478 | - $s .= "endcmap\n"; |
|
| 2479 | - $s .= "CMapName currentdict /CMap defineresource pop\n"; |
|
| 2480 | - $s .= "end\n"; |
|
| 2481 | - $s .= "end"; |
|
| 2482 | - return $s; |
|
| 2436 | + $ranges = ''; |
|
| 2437 | + $nbr = 0; |
|
| 2438 | + $chars = ''; |
|
| 2439 | + $nbc = 0; |
|
| 2440 | + foreach($uv as $c=>$v) |
|
| 2441 | + {
|
|
| 2442 | + if(is_array($v)) |
|
| 2443 | + {
|
|
| 2444 | + $ranges .= sprintf("<%02X> <%02X> <%04X>\n",$c,$c+$v[1]-1,$v[0]);
|
|
| 2445 | + $nbr++; |
|
| 2446 | + } |
|
| 2447 | + else |
|
| 2448 | + {
|
|
| 2449 | + $chars .= sprintf("<%02X> <%04X>\n",$c,$v);
|
|
| 2450 | + $nbc++; |
|
| 2451 | + } |
|
| 2452 | + } |
|
| 2453 | + $s = "/CIDInit /ProcSet findresource begin\n"; |
|
| 2454 | + $s .= "12 dict begin\n"; |
|
| 2455 | + $s .= "begincmap\n"; |
|
| 2456 | + $s .= "/CIDSystemInfo\n"; |
|
| 2457 | + $s .= "<</Registry (Adobe)\n"; |
|
| 2458 | + $s .= "/Ordering (UCS)\n"; |
|
| 2459 | + $s .= "/Supplement 0\n"; |
|
| 2460 | + $s .= ">> def\n"; |
|
| 2461 | + $s .= "/CMapName /Adobe-Identity-UCS def\n"; |
|
| 2462 | + $s .= "/CMapType 2 def\n"; |
|
| 2463 | + $s .= "1 begincodespacerange\n"; |
|
| 2464 | + $s .= "<00> <FF>\n"; |
|
| 2465 | + $s .= "endcodespacerange\n"; |
|
| 2466 | + if($nbr>0) |
|
| 2467 | + {
|
|
| 2468 | + $s .= "$nbr beginbfrange\n"; |
|
| 2469 | + $s .= $ranges; |
|
| 2470 | + $s .= "endbfrange\n"; |
|
| 2471 | + } |
|
| 2472 | + if($nbc>0) |
|
| 2473 | + {
|
|
| 2474 | + $s .= "$nbc beginbfchar\n"; |
|
| 2475 | + $s .= $chars; |
|
| 2476 | + $s .= "endbfchar\n"; |
|
| 2477 | + } |
|
| 2478 | + $s .= "endcmap\n"; |
|
| 2479 | + $s .= "CMapName currentdict /CMap defineresource pop\n"; |
|
| 2480 | + $s .= "end\n"; |
|
| 2481 | + $s .= "end"; |
|
| 2482 | + return $s; |
|
| 2483 | 2483 | } |
| 2484 | 2484 | |
| 2485 | 2485 | /** |
@@ -2487,12 +2487,12 @@ discard block |
||
| 2487 | 2487 | */ |
| 2488 | 2488 | protected function _putimages() : void |
| 2489 | 2489 | {
|
| 2490 | - foreach(array_keys($this->images) as $file) |
|
| 2491 | - {
|
|
| 2492 | - $this->_putimage($this->images[$file]); |
|
| 2493 | - unset($this->images[$file]['data']); |
|
| 2494 | - unset($this->images[$file]['smask']); |
|
| 2495 | - } |
|
| 2490 | + foreach(array_keys($this->images) as $file) |
|
| 2491 | + {
|
|
| 2492 | + $this->_putimage($this->images[$file]); |
|
| 2493 | + unset($this->images[$file]['data']); |
|
| 2494 | + unset($this->images[$file]['smask']); |
|
| 2495 | + } |
|
| 2496 | 2496 | } |
| 2497 | 2497 | |
| 2498 | 2498 | /** |
@@ -2501,59 +2501,59 @@ discard block |
||
| 2501 | 2501 | */ |
| 2502 | 2502 | protected function _putimage(array &$info) : void |
| 2503 | 2503 | {
|
| 2504 | - $this->_newobj(); |
|
| 2505 | - $info['n'] = $this->n; |
|
| 2506 | - $this->_put('<</Type /XObject');
|
|
| 2507 | - $this->_put('/Subtype /Image');
|
|
| 2508 | - $this->_put('/Width ' . $info['w']);
|
|
| 2509 | - $this->_put('/Height ' . $info['h']);
|
|
| 2510 | - if ($info['cs'] == 'Indexed') {
|
|
| 2511 | - $this->_put('/ColorSpace [/Indexed /DeviceRGB ' . (strlen($info['pal']) / 3 - 1) . ' ' . ($this->n + 1) . ' 0 R]');
|
|
| 2512 | - } else {
|
|
| 2513 | - $this->_put('/ColorSpace /' . $info['cs']);
|
|
| 2514 | - if($info['cs']=='DeviceCMYK') {
|
|
| 2515 | - $this->_put('/Decode [1 0 1 0 1 0 1 0]');
|
|
| 2516 | - } |
|
| 2517 | - } |
|
| 2518 | - $this->_put('/BitsPerComponent ' . $info['bpc']);
|
|
| 2519 | - if (isset($info['f'])) {
|
|
| 2520 | - $this->_put('/Filter /' . $info['f']);
|
|
| 2521 | - } |
|
| 2522 | - if (isset($info['dp'])) {
|
|
| 2523 | - $this->_put('/DecodeParms <<' . $info['dp'] . '>>');
|
|
| 2524 | - } |
|
| 2525 | - if (isset($info['trns']) && is_array($info['trns'])) {
|
|
| 2526 | - $trns = ''; |
|
| 2527 | - $cnt = count($info['trns']); |
|
| 2528 | - for ($i = 0; $i < $cnt; $i++) {
|
|
| 2529 | - $trns .= $info['trns'][$i] . ' ' . $info['trns'][$i] . ' '; |
|
| 2530 | - } |
|
| 2531 | - $this->_put('/Mask [' . $trns . ']');
|
|
| 2532 | - } |
|
| 2533 | - if (isset($info['smask'])) {
|
|
| 2534 | - $this->_put('/SMask ' . ($this->n+1) . ' 0 R');
|
|
| 2535 | - } |
|
| 2536 | - $this->_put('/Length ' . strlen($info['data']) . '>>');
|
|
| 2537 | - $this->_putstream($info['data']); |
|
| 2538 | - $this->_put('endobj');
|
|
| 2539 | - // Soft mask |
|
| 2540 | - if (isset($info['smask'])) {
|
|
| 2541 | - $dp = '/Predictor 15 /Colors 1 /BitsPerComponent 8 /Columns ' . $info['w']; |
|
| 2542 | - $smask = array( |
|
| 2543 | - 'w'=>$info['w'], |
|
| 2544 | - 'h'=>$info['h'], |
|
| 2545 | - 'cs'=>'DeviceGray', |
|
| 2546 | - 'bpc'=>8, |
|
| 2547 | - 'f'=>$info['f'], |
|
| 2548 | - 'dp'=>$dp, |
|
| 2549 | - 'data'=>$info['smask'] |
|
| 2550 | - ); |
|
| 2551 | - $this->_putimage($smask); |
|
| 2552 | - } |
|
| 2553 | - // Palette |
|
| 2554 | - if ($info['cs'] == 'Indexed') {
|
|
| 2555 | - $this->_putstreamobject($info['pal']); |
|
| 2556 | - } |
|
| 2504 | + $this->_newobj(); |
|
| 2505 | + $info['n'] = $this->n; |
|
| 2506 | + $this->_put('<</Type /XObject');
|
|
| 2507 | + $this->_put('/Subtype /Image');
|
|
| 2508 | + $this->_put('/Width ' . $info['w']);
|
|
| 2509 | + $this->_put('/Height ' . $info['h']);
|
|
| 2510 | + if ($info['cs'] == 'Indexed') {
|
|
| 2511 | + $this->_put('/ColorSpace [/Indexed /DeviceRGB ' . (strlen($info['pal']) / 3 - 1) . ' ' . ($this->n + 1) . ' 0 R]');
|
|
| 2512 | + } else {
|
|
| 2513 | + $this->_put('/ColorSpace /' . $info['cs']);
|
|
| 2514 | + if($info['cs']=='DeviceCMYK') {
|
|
| 2515 | + $this->_put('/Decode [1 0 1 0 1 0 1 0]');
|
|
| 2516 | + } |
|
| 2517 | + } |
|
| 2518 | + $this->_put('/BitsPerComponent ' . $info['bpc']);
|
|
| 2519 | + if (isset($info['f'])) {
|
|
| 2520 | + $this->_put('/Filter /' . $info['f']);
|
|
| 2521 | + } |
|
| 2522 | + if (isset($info['dp'])) {
|
|
| 2523 | + $this->_put('/DecodeParms <<' . $info['dp'] . '>>');
|
|
| 2524 | + } |
|
| 2525 | + if (isset($info['trns']) && is_array($info['trns'])) {
|
|
| 2526 | + $trns = ''; |
|
| 2527 | + $cnt = count($info['trns']); |
|
| 2528 | + for ($i = 0; $i < $cnt; $i++) {
|
|
| 2529 | + $trns .= $info['trns'][$i] . ' ' . $info['trns'][$i] . ' '; |
|
| 2530 | + } |
|
| 2531 | + $this->_put('/Mask [' . $trns . ']');
|
|
| 2532 | + } |
|
| 2533 | + if (isset($info['smask'])) {
|
|
| 2534 | + $this->_put('/SMask ' . ($this->n+1) . ' 0 R');
|
|
| 2535 | + } |
|
| 2536 | + $this->_put('/Length ' . strlen($info['data']) . '>>');
|
|
| 2537 | + $this->_putstream($info['data']); |
|
| 2538 | + $this->_put('endobj');
|
|
| 2539 | + // Soft mask |
|
| 2540 | + if (isset($info['smask'])) {
|
|
| 2541 | + $dp = '/Predictor 15 /Colors 1 /BitsPerComponent 8 /Columns ' . $info['w']; |
|
| 2542 | + $smask = array( |
|
| 2543 | + 'w'=>$info['w'], |
|
| 2544 | + 'h'=>$info['h'], |
|
| 2545 | + 'cs'=>'DeviceGray', |
|
| 2546 | + 'bpc'=>8, |
|
| 2547 | + 'f'=>$info['f'], |
|
| 2548 | + 'dp'=>$dp, |
|
| 2549 | + 'data'=>$info['smask'] |
|
| 2550 | + ); |
|
| 2551 | + $this->_putimage($smask); |
|
| 2552 | + } |
|
| 2553 | + // Palette |
|
| 2554 | + if ($info['cs'] == 'Indexed') {
|
|
| 2555 | + $this->_putstreamobject($info['pal']); |
|
| 2556 | + } |
|
| 2557 | 2557 | } |
| 2558 | 2558 | |
| 2559 | 2559 | /** |
@@ -2562,7 +2562,7 @@ discard block |
||
| 2562 | 2562 | protected function _putxobjectdict() : void |
| 2563 | 2563 | {
|
| 2564 | 2564 | foreach ($this->images as $image) {
|
| 2565 | - $this->_put('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R');
|
|
| 2565 | + $this->_put('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R');
|
|
| 2566 | 2566 | } |
| 2567 | 2567 | } |
| 2568 | 2568 | |
@@ -2571,15 +2571,15 @@ discard block |
||
| 2571 | 2571 | */ |
| 2572 | 2572 | protected function _putresourcedict() : void |
| 2573 | 2573 | {
|
| 2574 | - $this->_put('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
|
|
| 2575 | - $this->_put('/Font <<');
|
|
| 2576 | - foreach ($this->fonts as $font) {
|
|
| 2577 | - $this->_put('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R');
|
|
| 2578 | - } |
|
| 2579 | - $this->_put('>>');
|
|
| 2580 | - $this->_put('/XObject <<');
|
|
| 2581 | - $this->_putxobjectdict(); |
|
| 2582 | - $this->_put('>>');
|
|
| 2574 | + $this->_put('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
|
|
| 2575 | + $this->_put('/Font <<');
|
|
| 2576 | + foreach ($this->fonts as $font) {
|
|
| 2577 | + $this->_put('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R');
|
|
| 2578 | + } |
|
| 2579 | + $this->_put('>>');
|
|
| 2580 | + $this->_put('/XObject <<');
|
|
| 2581 | + $this->_putxobjectdict(); |
|
| 2582 | + $this->_put('>>');
|
|
| 2583 | 2583 | } |
| 2584 | 2584 | |
| 2585 | 2585 | /** |
@@ -2587,14 +2587,14 @@ discard block |
||
| 2587 | 2587 | */ |
| 2588 | 2588 | protected function _putresources() : void |
| 2589 | 2589 | {
|
| 2590 | - $this->_putfonts(); |
|
| 2591 | - $this->_putimages(); |
|
| 2592 | - // Resource dictionary |
|
| 2593 | - $this->_newobj(2); |
|
| 2594 | - $this->_put('<<');
|
|
| 2595 | - $this->_putresourcedict(); |
|
| 2596 | - $this->_put('>>');
|
|
| 2597 | - $this->_put('endobj');
|
|
| 2590 | + $this->_putfonts(); |
|
| 2591 | + $this->_putimages(); |
|
| 2592 | + // Resource dictionary |
|
| 2593 | + $this->_newobj(2); |
|
| 2594 | + $this->_put('<<');
|
|
| 2595 | + $this->_putresourcedict(); |
|
| 2596 | + $this->_put('>>');
|
|
| 2597 | + $this->_put('endobj');
|
|
| 2598 | 2598 | } |
| 2599 | 2599 | |
| 2600 | 2600 | /** |
@@ -2602,11 +2602,11 @@ discard block |
||
| 2602 | 2602 | */ |
| 2603 | 2603 | protected function _putinfo() : void |
| 2604 | 2604 | {
|
| 2605 | - $this->metadata['Producer'] = 'FPDF '.FPDF_VERSION; |
|
| 2606 | - $this->metadata['CreationDate'] = 'D:' . @date('YmdHis');
|
|
| 2607 | - foreach ($this->metadata as $key=>$value) {
|
|
| 2608 | - $this->_put('/' . $key . ' ' . $this->_textstring($value));
|
|
| 2609 | - } |
|
| 2605 | + $this->metadata['Producer'] = 'FPDF '.FPDF_VERSION; |
|
| 2606 | + $this->metadata['CreationDate'] = 'D:' . @date('YmdHis');
|
|
| 2607 | + foreach ($this->metadata as $key=>$value) {
|
|
| 2608 | + $this->_put('/' . $key . ' ' . $this->_textstring($value));
|
|
| 2609 | + } |
|
| 2610 | 2610 | } |
| 2611 | 2611 | |
| 2612 | 2612 | /** |
@@ -2614,25 +2614,25 @@ discard block |
||
| 2614 | 2614 | */ |
| 2615 | 2615 | protected function _putcatalog() : void |
| 2616 | 2616 | {
|
| 2617 | - $n = $this->PageInfo[1]['n']; |
|
| 2618 | - $this->_put('/Type /Catalog');
|
|
| 2619 | - $this->_put('/Pages 1 0 R');
|
|
| 2620 | - if($this->ZoomMode=='fullpage') {
|
|
| 2621 | - $this->_put('/OpenAction [' . $n . ' 0 R /Fit]');
|
|
| 2622 | - } elseif ($this->ZoomMode=='fullwidth') {
|
|
| 2623 | - $this->_put('/OpenAction [' . $n . ' 0 R /FitH null]');
|
|
| 2624 | - } elseif($this->ZoomMode=='real') {
|
|
| 2625 | - $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null 1]');
|
|
| 2626 | - } elseif(!is_string($this->ZoomMode)) {
|
|
| 2627 | - $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null ' . sprintf('%.2F', $this->ZoomMode / 100) . ']');
|
|
| 2628 | - } |
|
| 2629 | - if($this->LayoutMode=='single') {
|
|
| 2630 | - $this->_put('/PageLayout /SinglePage');
|
|
| 2631 | - } elseif($this->LayoutMode=='continuous') {
|
|
| 2632 | - $this->_put('/PageLayout /OneColumn');
|
|
| 2633 | - } elseif($this->LayoutMode=='two') {
|
|
| 2634 | - $this->_put('/PageLayout /TwoColumnLeft');
|
|
| 2635 | - } |
|
| 2617 | + $n = $this->PageInfo[1]['n']; |
|
| 2618 | + $this->_put('/Type /Catalog');
|
|
| 2619 | + $this->_put('/Pages 1 0 R');
|
|
| 2620 | + if($this->ZoomMode=='fullpage') {
|
|
| 2621 | + $this->_put('/OpenAction [' . $n . ' 0 R /Fit]');
|
|
| 2622 | + } elseif ($this->ZoomMode=='fullwidth') {
|
|
| 2623 | + $this->_put('/OpenAction [' . $n . ' 0 R /FitH null]');
|
|
| 2624 | + } elseif($this->ZoomMode=='real') {
|
|
| 2625 | + $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null 1]');
|
|
| 2626 | + } elseif(!is_string($this->ZoomMode)) {
|
|
| 2627 | + $this->_put('/OpenAction [' . $n . ' 0 R /XYZ null null ' . sprintf('%.2F', $this->ZoomMode / 100) . ']');
|
|
| 2628 | + } |
|
| 2629 | + if($this->LayoutMode=='single') {
|
|
| 2630 | + $this->_put('/PageLayout /SinglePage');
|
|
| 2631 | + } elseif($this->LayoutMode=='continuous') {
|
|
| 2632 | + $this->_put('/PageLayout /OneColumn');
|
|
| 2633 | + } elseif($this->LayoutMode=='two') {
|
|
| 2634 | + $this->_put('/PageLayout /TwoColumnLeft');
|
|
| 2635 | + } |
|
| 2636 | 2636 | } |
| 2637 | 2637 | |
| 2638 | 2638 | /** |
@@ -2640,7 +2640,7 @@ discard block |
||
| 2640 | 2640 | */ |
| 2641 | 2641 | protected function _putheader() : void |
| 2642 | 2642 | {
|
| 2643 | - $this->_put('%PDF-' . $this->PDFVersion);
|
|
| 2643 | + $this->_put('%PDF-' . $this->PDFVersion);
|
|
| 2644 | 2644 | } |
| 2645 | 2645 | |
| 2646 | 2646 | /** |
@@ -2648,9 +2648,9 @@ discard block |
||
| 2648 | 2648 | */ |
| 2649 | 2649 | protected function _puttrailer() : void |
| 2650 | 2650 | {
|
| 2651 | - $this->_put('/Size ' . ($this->n + 1));
|
|
| 2652 | - $this->_put('/Root ' . $this->n . ' 0 R');
|
|
| 2653 | - $this->_put('/Info ' . ($this->n - 1) . ' 0 R');
|
|
| 2651 | + $this->_put('/Size ' . ($this->n + 1));
|
|
| 2652 | + $this->_put('/Root ' . $this->n . ' 0 R');
|
|
| 2653 | + $this->_put('/Info ' . ($this->n - 1) . ' 0 R');
|
|
| 2654 | 2654 | } |
| 2655 | 2655 | |
| 2656 | 2656 | /** |
@@ -2658,37 +2658,37 @@ discard block |
||
| 2658 | 2658 | */ |
| 2659 | 2659 | protected function _enddoc() : void |
| 2660 | 2660 | {
|
| 2661 | - $this->_putheader(); |
|
| 2662 | - $this->_putpages(); |
|
| 2663 | - $this->_putresources(); |
|
| 2664 | - // Info |
|
| 2665 | - $this->_newobj(); |
|
| 2666 | - $this->_put('<<');
|
|
| 2667 | - $this->_putinfo(); |
|
| 2668 | - $this->_put('>>');
|
|
| 2669 | - $this->_put('endobj');
|
|
| 2670 | - // Catalog |
|
| 2671 | - $this->_newobj(); |
|
| 2672 | - $this->_put('<<');
|
|
| 2673 | - $this->_putcatalog(); |
|
| 2674 | - $this->_put('>>');
|
|
| 2675 | - $this->_put('endobj');
|
|
| 2676 | - // Cross-ref |
|
| 2677 | - $offset = $this->_getoffset(); |
|
| 2678 | - $this->_put('xref');
|
|
| 2679 | - $this->_put('0 ' . ($this->n + 1));
|
|
| 2680 | - $this->_put('0000000000 65535 f ');
|
|
| 2681 | - for ($i = 1; $i <= $this->n; $i++) {
|
|
| 2682 | - $this->_put(sprintf('%010d 00000 n ', $this->offsets[$i]));
|
|
| 2683 | - } |
|
| 2684 | - // Trailer |
|
| 2685 | - $this->_put('trailer');
|
|
| 2686 | - $this->_put('<<');
|
|
| 2687 | - $this->_puttrailer(); |
|
| 2688 | - $this->_put('>>');
|
|
| 2689 | - $this->_put('startxref');
|
|
| 2690 | - $this->_put(strval($offset)); |
|
| 2691 | - $this->_put('%%EOF');
|
|
| 2692 | - $this->state = 3; |
|
| 2661 | + $this->_putheader(); |
|
| 2662 | + $this->_putpages(); |
|
| 2663 | + $this->_putresources(); |
|
| 2664 | + // Info |
|
| 2665 | + $this->_newobj(); |
|
| 2666 | + $this->_put('<<');
|
|
| 2667 | + $this->_putinfo(); |
|
| 2668 | + $this->_put('>>');
|
|
| 2669 | + $this->_put('endobj');
|
|
| 2670 | + // Catalog |
|
| 2671 | + $this->_newobj(); |
|
| 2672 | + $this->_put('<<');
|
|
| 2673 | + $this->_putcatalog(); |
|
| 2674 | + $this->_put('>>');
|
|
| 2675 | + $this->_put('endobj');
|
|
| 2676 | + // Cross-ref |
|
| 2677 | + $offset = $this->_getoffset(); |
|
| 2678 | + $this->_put('xref');
|
|
| 2679 | + $this->_put('0 ' . ($this->n + 1));
|
|
| 2680 | + $this->_put('0000000000 65535 f ');
|
|
| 2681 | + for ($i = 1; $i <= $this->n; $i++) {
|
|
| 2682 | + $this->_put(sprintf('%010d 00000 n ', $this->offsets[$i]));
|
|
| 2683 | + } |
|
| 2684 | + // Trailer |
|
| 2685 | + $this->_put('trailer');
|
|
| 2686 | + $this->_put('<<');
|
|
| 2687 | + $this->_puttrailer(); |
|
| 2688 | + $this->_put('>>');
|
|
| 2689 | + $this->_put('startxref');
|
|
| 2690 | + $this->_put(strval($offset)); |
|
| 2691 | + $this->_put('%%EOF');
|
|
| 2692 | + $this->state = 3; |
|
| 2693 | 2693 | } |
| 2694 | 2694 | } |