Skip to content

Commit

Permalink
Remove duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni committed Aug 17, 2024
1 parent c7e197c commit 87dc7ee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.0
2.4.1
29 changes: 22 additions & 7 deletions src/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,36 @@ public function getFontsBlock(): string
/**
* Get the PDF output string for Font resources dictionary.
*
* @param array<string, array{'i': int, 'n': int}> $data Font data.
*
* @return string
*/
public function getOutFontDict(): string
private function getOutFontResources(array $data): string
{
if (empty($this->fonts)) {
if (empty($data)) {
return '';
}

$out = ' /Font <<';

foreach ($this->fonts as $font) {
foreach ($data as $font) {
$out .= ' /F' . $font['i'] . ' ' . $font['n'] . ' 0 R';
}

return $out . ' >>';
}


/**
* Get the PDF output string for Font resources dictionary.
*
* @return string
*/
public function getOutFontDict(): string
{
return $this->getOutFontResources($this->fonts);
}

/**
* Get the PDF output string for XOBject Font resources dictionary.
*
Expand All @@ -115,13 +128,15 @@ public function getOutFontDictByKeys(array $keys): string
return '';
}

$out = ' /Font <<';

$data = [];
foreach ($keys as $key) {
$out .= ' /F' . $this->fonts[$key]['i'] . ' ' . $this->fonts[$key]['n'] . ' 0 R';
$data[$key] = [
'i' => $this->fonts[$key]['i'],
'n' => $this->fonts[$key]['n'],
];
}

return $out . ' >>';
return $this->getOutFontResources($data);
}

/**
Expand Down

0 comments on commit 87dc7ee

Please sign in to comment.