Skip to content

Commit 31d2178

Browse files
committed
add file options
1 parent ed0823b commit 31d2178

7 files changed

Lines changed: 60 additions & 12 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.6.42
1+
2.7.0

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"ext-json": "*",
2626
"ext-pcre": "*",
2727
"ext-zlib": "*",
28-
"tecnickcom/tc-lib-file": "^2.4",
28+
"tecnickcom/tc-lib-file": "^2.5",
2929
"tecnickcom/tc-lib-unicode-data": "^2.0",
3030
"tecnickcom/tc-lib-pdf-encrypt": "^2.2"
3131
},

resources/debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ Vcs-Browser: https://github.com/~#VENDOR#~/~#PROJECT#~
1212
Package: ~#PKGNAME#~
1313
Provides: php-~#PROJECT#~
1414
Architecture: all
15-
Depends: php (>= 8.1.0), php-json, php-zip, php-tecnickcom-tc-lib-file (<< 3.0.0), php-tecnickcom-tc-lib-file (>= 2.4.0), php-tecnickcom-tc-lib-unicode-data (<< 3.0.0), php-tecnickcom-tc-lib-unicode-data (>= 2.0.51), php-tecnickcom-tc-lib-pdf-encrypt (<< 3.0.0), php-tecnickcom-tc-lib-pdf-encrypt (>= 2.2.0), php-tecnickcom-tc-lib-pdf-font-core (<< 2.0.0), php-tecnickcom-tc-lib-pdf-font-data-core (>= 1.8.7), ${misc:Depends}
15+
Depends: php (>= 8.1.0), php-json, php-zip, php-tecnickcom-tc-lib-file (<< 3.0.0), php-tecnickcom-tc-lib-file (>= 2.5.0), php-tecnickcom-tc-lib-unicode-data (<< 3.0.0), php-tecnickcom-tc-lib-unicode-data (>= 2.0.51), php-tecnickcom-tc-lib-pdf-encrypt (<< 3.0.0), php-tecnickcom-tc-lib-pdf-encrypt (>= 2.2.0), php-tecnickcom-tc-lib-pdf-font-core (<< 2.0.0), php-tecnickcom-tc-lib-pdf-font-data-core (>= 1.8.7), ${misc:Depends}
1616
Description: PHP PDF Fonts Library
1717
PHP library containing PDF font methods and utilities.

resources/rpm/rpm.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Requires: php-json
1919
Requires: php-pcre
2020
Requires: php-zlib
2121
Requires: php-composer(%{c_vendor}/tc-lib-file) < 3.0.0
22-
Requires: php-composer(%{c_vendor}/tc-lib-file) >= 2.4.0
22+
Requires: php-composer(%{c_vendor}/tc-lib-file) >= 2.5.0
2323
Requires: php-composer(%{c_vendor}/tc-lib-unicode-data) < 3.0.0
2424
Requires: php-composer(%{c_vendor}/tc-lib-unicode-data) >= 2.0.51
2525
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) < 3.0.0

src/Buffer.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
3030
* @link https://github.com/tecnickcom/tc-lib-pdf-font
3131
*
32+
* @phpstan-type TFileOptions array{
33+
* allowedHosts?: array<string>,
34+
* maxRemoteSize?: int,
35+
* curlopts?: array<int, bool|int|string>,
36+
* defaultCurlOpts?: array<int, bool|int|string>,
37+
* fixedCurlOpts?: array<int, bool|int|string>
38+
* }
39+
*
3240
* @phpstan-import-type TFontData from Load
3341
*/
3442
abstract class Buffer
@@ -70,6 +78,13 @@ abstract class Buffer
7078
*/
7179
protected array $file = [];
7280

81+
/**
82+
* Optional configuration forwarded to the file helper.
83+
*
84+
* @var TFileOptions|null
85+
*/
86+
protected ?array $fileOptions = null;
87+
7388
/**
7489
* Initialize fonts buffer
7590
*
@@ -91,13 +106,16 @@ abstract class Buffer
91106
* intensive.
92107
* @param bool $unicode True if we are in Unicode mode, False otherwise.
93108
* @param bool $pdfa True if we are in PDF/A mode, False otherwise.
109+
* @param TFileOptions|null $fileOptions Optional configuration for the font file helper.
94110
*/
95111
public function __construct(
96112
protected float $kunit,
97113
protected bool $subset = false,
98114
protected bool $unicode = true,
99-
protected bool $pdfa = false
115+
protected bool $pdfa = false,
116+
?array $fileOptions = null
100117
) {
118+
$this->fileOptions = $fileOptions;
101119
}
102120

103121
/**
@@ -225,7 +243,7 @@ public function add(
225243
$subset = $this->subset;
226244
}
227245

228-
$fobj = new Font($font, $style, $ifile, $subset, $this->unicode, $this->pdfa);
246+
$fobj = new Font($font, $style, $ifile, $subset, $this->unicode, $this->pdfa, true, $this->fileOptions);
229247
$key = $fobj->getFontkey();
230248

231249
if (isset($this->font[$key])) {

src/Font.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
3131
* @link https://github.com/tecnickcom/tc-lib-pdf-font
3232
*
33+
* @phpstan-import-type TFileOptions from Load
34+
*
3335
* @phpstan-import-type TFontData from Load
3436
*/
3537
class Font extends \Com\Tecnick\Pdf\Font\Load
@@ -68,6 +70,7 @@ class Font extends \Com\Tecnick\Pdf\Font\Load
6870
* @param bool $unicode True in Unicode mode, False otherwise.
6971
* @param bool $pdfa True in PDF/A mode, False otherwise.
7072
* @param bool $compress Set to false to disable stream compression.
73+
* @param TFileOptions|null $fileOptions Optional configuration for the font file helper.
7174
*
7275
* @throws FontException in case of error
7376
*/
@@ -78,8 +81,11 @@ public function __construct(
7881
bool $subset = false,
7982
bool $unicode = true,
8083
bool $pdfa = false,
81-
bool $compress = true
84+
bool $compress = true,
85+
?array $fileOptions = null
8286
) {
87+
parent::__construct($fileOptions);
88+
8389
if ($font === '') {
8490
throw new FontException('empty font family name');
8591
}

src/Load.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
namespace Com\Tecnick\Pdf\Font;
1818

1919
use Com\Tecnick\File\Dir;
20+
use Com\Tecnick\File\File as ObjFile;
2021
use Com\Tecnick\Pdf\Font\Exception as FontException;
2122

2223
/**
@@ -30,6 +31,14 @@
3031
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
3132
* @link https://github.com/tecnickcom/tc-lib-pdf-font
3233
*
34+
* @phpstan-type TFileOptions array{
35+
* allowedHosts?: array<string>,
36+
* maxRemoteSize?: int,
37+
* curlopts?: array<int, bool|int|string>,
38+
* defaultCurlOpts?: array<int, bool|int|string>,
39+
* fixedCurlOpts?: array<int, bool|int|string>
40+
* }
41+
*
3342
* @phpstan-type TFontDataCidInfo array{
3443
* 'Ordering': string,
3544
* 'Registry': string,
@@ -166,6 +175,11 @@
166175
*/
167176
abstract class Load
168177
{
178+
/**
179+
* File helper used to load font definition files.
180+
*/
181+
protected ObjFile $file;
182+
169183
/**
170184
* Valid Font types
171185
*
@@ -299,6 +313,20 @@ abstract class Load
299313
'weight' => '',
300314
];
301315

316+
/**
317+
* @param TFileOptions|null $fileOptions Optional configuration for the font file helper.
318+
*/
319+
public function __construct(?array $fileOptions = null)
320+
{
321+
$this->file = new ObjFile(
322+
$fileOptions['allowedHosts'] ?? [],
323+
$fileOptions['maxRemoteSize'] ?? 52428800,
324+
$fileOptions['curlopts'] ?? [],
325+
$fileOptions['defaultCurlOpts'] ?? null,
326+
$fileOptions['fixedCurlOpts'] ?? null
327+
);
328+
}
329+
302330
/**
303331
* Load the font data
304332
*
@@ -329,11 +357,7 @@ protected function getFontInfo(): void
329357
$this->findFontFile();
330358

331359
// read the font definition file
332-
if (! @\is_readable($this->data['ifile'])) {
333-
throw new FontException('unable to read file: ' . $this->data['ifile']);
334-
}
335-
336-
$fdt = @\file_get_contents($this->data['ifile']);
360+
$fdt = $this->file->getFileData($this->data['ifile']);
337361
if ($fdt === false) {
338362
throw new FontException('unable to read file: ' . $this->data['ifile']);
339363
}

0 commit comments

Comments
 (0)