Skip to content

Commit

Permalink
PDFObject: fixed introduced syntax errors in older PHP versions; refi…
Browse files Browse the repository at this point in the history
…ned comment in Font.php
  • Loading branch information
k00ni committed Oct 24, 2024
1 parent 304cd3d commit eb4e47a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/Smalot/PdfParser/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,12 @@ public function calculateTextWidth(string $text, ?array &$missing = null): ?floa
// Usually, Widths key is set in $details array, but if it isn't use an empty array instead.
$widths = $details['Widths'] ?? [];

// Widths array is zero indexed but table is not. We must map them based on FirstChar and LastChar
// note: in some cases the values for FirstChar or LastChar are null here
/*
* Widths array is zero indexed but table is not. We must map them based on FirstChar and LastChar
*
* Note: Without the change you would see warnings in PHP 8.4 because the values of FirstChar or LastChar
* can be null sometimes.
*/
$width_map = array_flip(range((int) $details['FirstChar'], (int) $details['LastChar']));

$width = null;
Expand Down
4 changes: 2 additions & 2 deletions src/Smalot/PdfParser/PDFObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(
Document $document,
?Header $header = null,
?string $content = null,
?Config $config = null,
?Config $config = null
) {
$this->document = $document;
$this->header = $header ?? new Header();
Expand Down Expand Up @@ -1144,7 +1144,7 @@ public static function factory(
Document $document,
Header $header,
?string $content,
?Config $config = null,
?Config $config = null
): self {
switch ($header->get('Type')->getContent()) {
case 'XObject':
Expand Down

0 comments on commit eb4e47a

Please sign in to comment.