Skip to content

Commit 3221a5b

Browse files
authored
draft CSS/HTMl methods (WIP) (#128)
* draft CSS functions * add tidyHTML method * PHP6616: optimize native function invocation
1 parent a02a138 commit 3221a5b

File tree

15 files changed

+1062
-630
lines changed

15 files changed

+1062
-630
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.2.2
1+
8.2.3

examples/index.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
require(__DIR__ . '/../vendor/autoload.php');
2020

2121

22-
define('OUTPUT_FILE', realpath(__DIR__ . '/../target') . '/example.pdf');
22+
\define('OUTPUT_FILE', \realpath(__DIR__ . '/../target') . '/example.pdf');
2323

2424
// define fonts directory
25-
define('K_PATH_FONTS', realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-font/target/fonts'));
25+
\define('K_PATH_FONTS', \realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-font/target/fonts'));
2626

2727
// autoloader when using RPM or DEB package installation
2828
//require ('/usr/share/php/Com/Tecnick/Pdf/autoload.php');
@@ -58,7 +58,7 @@
5858

5959

6060
// test images directory
61-
$imgdir = realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-image/test/images/');
61+
$imgdir = \realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-image/test/images/');
6262

6363

6464
// ----------
@@ -1662,7 +1662,7 @@
16621662

16631663
// Various output modes:
16641664

1665-
//$pdf->savePDF(dirname(__DIR__).'/target', $rawpdf);
1665+
//$pdf->savePDF(\dirname(__DIR__).'/target', $rawpdf);
16661666
$pdf->renderPDF($rawpdf);
16671667
//$pdf->downloadPDF($rawpdf);
16681668
//echo $pdf->getMIMEAttachmentPDF($rawpdf);

examples/invoice.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
require(__DIR__ . '/../vendor/autoload.php');
2020

2121

22-
define('OUTPUT_FILE', realpath(__DIR__ . '/../target') . '/example_invoice.pdf');
22+
\define('OUTPUT_FILE', \realpath(__DIR__ . '/../target') . '/example_invoice.pdf');
2323

2424
// define fonts directory
25-
define('K_PATH_FONTS', realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-font/target/fonts'));
25+
\define('K_PATH_FONTS', \realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-font/target/fonts'));
2626

2727
// autoloader when using RPM or DEB package installation
2828
//require ('/usr/share/php/Com/Tecnick/Pdf/autoload.php');
@@ -302,7 +302,7 @@
302302

303303
// Various output modes:
304304

305-
//$pdf->savePDF(dirname(__DIR__).'/target', $rawpdf);
305+
//$pdf->savePDF(\dirname(__DIR__).'/target', $rawpdf);
306306
$pdf->renderPDF($rawpdf);
307307
//$pdf->downloadPDF($rawpdf);
308308
//echo $pdf->getMIMEAttachmentPDF($rawpdf);

resources/autoload.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
*
1515
* This file is part of tc-lib-pdf software library.
1616
*/
17-
spl_autoload_register(
17+
\spl_autoload_register(
1818
function ($class) {
1919
$prefix = 'Com\\Tecnick\\';
20-
$len = strlen($prefix);
21-
if (strncmp($prefix, $class, $len) !== 0) {
20+
$len = \strlen($prefix);
21+
if (\strncmp($prefix, $class, $len) !== 0) {
2222
return;
2323
}
24-
$relative_class = substr($class, $len);
25-
$file = dirname(__DIR__).'/'.str_replace('\\', '/', $relative_class).'.php';
26-
if (file_exists($file)) {
24+
$relative_class = \substr($class, $len);
25+
$file = \dirname(__DIR__).'/'.\str_replace('\\', '/', $relative_class).'.php';
26+
if (\file_exists($file)) {
2727
require $file;
2828
}
2929
}

resources/debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ Vcs-Git: https://github.com/~#VENDOR#~/~#PROJECT#~.git
1010
Package: ~#PKGNAME#~
1111
Provides: php-~#PROJECT#~
1212
Architecture: all
13-
Depends: php (>= 8.1.0), php-date, php-tecnickcom-tc-lib-barcode (<< 3.0.0), php-tecnickcom-tc-lib-barcode (>= 2.4.12), php-tecnickcom-tc-lib-color (<< 3.0.0), php-tecnickcom-tc-lib-color (>= 2.2.17), php-tecnickcom-tc-lib-pdf-image (<< 3.0.0), php-tecnickcom-tc-lib-pdf-image (>= 2.1.18), php-tecnickcom-tc-lib-pdf-font (<< 3.0.0), php-tecnickcom-tc-lib-pdf-font (>= 2.6.16), php-tecnickcom-tc-lib-file (<< 3.0.0), php-tecnickcom-tc-lib-file (>= 2.2.6), php-tecnickcom-tc-lib-pdf-encrypt (<< 3.0.0), php-tecnickcom-tc-lib-pdf-encrypt (>= 2.1.20), php-tecnickcom-tc-lib-unicode-data (<< 3.0.0), php-tecnickcom-tc-lib-unicode-data (>= 2.0.28), php-tecnickcom-tc-lib-unicode (<< 3.0.0), php-tecnickcom-tc-lib-unicode (>= 2.0.29), php-tecnickcom-tc-lib-pdf-page (<< 5.0.0), php-tecnickcom-tc-lib-pdf-page (>= 4.2.16), php-tecnickcom-tc-lib-pdf-graph (<< 3.0.0), php-tecnickcom-tc-lib-pdf-graph (>= 2.3.7), ${misc:Depends}
13+
Depends: php (>= 8.1.0), php-date, php-tecnickcom-tc-lib-barcode (<< 3.0.0), php-tecnickcom-tc-lib-barcode (>= 2.4.14), php-tecnickcom-tc-lib-color (<< 3.0.0), php-tecnickcom-tc-lib-color (>= 2.2.19), php-tecnickcom-tc-lib-pdf-image (<< 3.0.0), php-tecnickcom-tc-lib-pdf-image (>= 2.1.20), php-tecnickcom-tc-lib-pdf-font (<< 3.0.0), php-tecnickcom-tc-lib-pdf-font (>= 2.6.18), php-tecnickcom-tc-lib-file (<< 3.0.0), php-tecnickcom-tc-lib-file (>= 2.2.8), php-tecnickcom-tc-lib-pdf-encrypt (<< 3.0.0), php-tecnickcom-tc-lib-pdf-encrypt (>= 2.1.22), php-tecnickcom-tc-lib-unicode-data (<< 3.0.0), php-tecnickcom-tc-lib-unicode-data (>= 2.0.30), php-tecnickcom-tc-lib-unicode (<< 3.0.0), php-tecnickcom-tc-lib-unicode (>= 2.0.31), php-tecnickcom-tc-lib-pdf-page (<< 5.0.0), php-tecnickcom-tc-lib-pdf-page (>= 4.2.18), php-tecnickcom-tc-lib-pdf-graph (<< 3.0.0), php-tecnickcom-tc-lib-pdf-graph (>= 2.3.9), ${misc:Depends}
1414
Description: PHP Barcode library
1515
This library includes PHP classes to generate PDF documents.

resources/rpm/rpm.spec

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ Requires: php(language) >= 8.1.0
2020
Requires: php-date
2121
Requires: php-pcre
2222
Requires: php-composer(%{c_vendor}/tc-lib-barcode) < 3.0.0
23-
Requires: php-composer(%{c_vendor}/tc-lib-barcode) >= 2.4.12
23+
Requires: php-composer(%{c_vendor}/tc-lib-barcode) >= 2.4.14
2424
Requires: php-composer(%{c_vendor}/tc-lib-color) < 3.0.0
25-
Requires: php-composer(%{c_vendor}/tc-lib-color) >= 2.2.17
25+
Requires: php-composer(%{c_vendor}/tc-lib-color) >= 2.2.19
2626
Requires: php-composer(%{c_vendor}/tc-lib-pdf-image) < 3.0.0
27-
Requires: php-composer(%{c_vendor}/tc-lib-pdf-image) >= 2.1.18
27+
Requires: php-composer(%{c_vendor}/tc-lib-pdf-image) >= 2.1.20
2828
Requires: php-composer(%{c_vendor}/tc-lib-pdf-font) < 3.0.0
29-
Requires: php-composer(%{c_vendor}/tc-lib-pdf-font) >= 2.6.16
29+
Requires: php-composer(%{c_vendor}/tc-lib-pdf-font) >= 2.6.18
3030
Requires: php-composer(%{c_vendor}/tc-lib-file) < 3.0.0
31-
Requires: php-composer(%{c_vendor}/tc-lib-file) >= 2.2.6
31+
Requires: php-composer(%{c_vendor}/tc-lib-file) >= 2.2.8
3232
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) < 3.0.0
33-
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) >= 2.1.20
33+
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) >= 2.1.22
3434
Requires: php-composer(%{c_vendor}/tc-lib-unicode-data) < 3.0.0
35-
Requires: php-composer(%{c_vendor}/tc-lib-unicode-data) >= 2.0.28
35+
Requires: php-composer(%{c_vendor}/tc-lib-unicode-data) >= 2.0.30
3636
Requires: php-composer(%{c_vendor}/tc-lib-unicode) < 3.0.0
37-
Requires: php-composer(%{c_vendor}/tc-lib-unicode) >= 2.0.29
37+
Requires: php-composer(%{c_vendor}/tc-lib-unicode) >= 2.0.31
3838
Requires: php-composer(%{c_vendor}/tc-lib-pdf-page) < 5.0.0
39-
Requires: php-composer(%{c_vendor}/tc-lib-pdf-page) >= 4.2.16
39+
Requires: php-composer(%{c_vendor}/tc-lib-pdf-page) >= 4.2.18
4040
Requires: php-composer(%{c_vendor}/tc-lib-pdf-graph) < 3.0.0
41-
Requires: php-composer(%{c_vendor}/tc-lib-pdf-graph) >= 2.3.7
41+
Requires: php-composer(%{c_vendor}/tc-lib-pdf-graph) >= 2.3.9
4242

4343
Provides: php-composer(%{c_vendor}/%{gh_project}) = %{version}
4444
Provides: php-%{gh_project} = %{version}

src/Base.php

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,17 @@
7272
* 'h': float,
7373
* }
7474
*
75+
* @phpstan-type TCellBound array{
76+
* 'T': float,
77+
* 'R': float,
78+
* 'B': float,
79+
* 'L': float,
80+
* }
81+
*
7582
* @phpstan-type TCellDef array{
76-
* 'margin': array{
77-
* 'T': float,
78-
* 'R': float,
79-
* 'B': float,
80-
* 'L': float,
81-
* },
82-
* 'padding': array{
83-
* 'T': float,
84-
* 'R': float,
85-
* 'B': float,
86-
* 'L': float,
87-
* },
88-
* 'borderpos': float,
83+
* 'margin': TCellBound,
84+
* 'padding': TCellBound,
85+
* 'borderpos': float,
8986
* }
9087
*
9188
* @phpstan-type TRefUnitValues array{
@@ -183,7 +180,7 @@ abstract class Base
183180
/**
184181
* TCPDF version.
185182
*/
186-
protected string $version = '8.2.2';
183+
protected string $version = '8.2.3';
187184

188185
/**
189186
* Time is seconds since EPOCH when the document was created.
@@ -292,8 +289,8 @@ abstract class Base
292289
'small' => -2.0,
293290
'medium' => 0.0,
294291
'large' => 2.0,
295-
'x-large' => 4.0,
296292
'larger' => 3.0,
293+
'x-large' => 4.0,
297294
'xx-large' => 6.0,
298295
];
299296

@@ -611,24 +608,26 @@ abstract class Base
611608
*/
612609
public const BORDERPOS_INTERNAL = 0.5; // 1/2
613610

611+
/**
612+
* Default values for cell boundaries.
613+
*
614+
* @const TCellBound
615+
*/
616+
public const ZEROCELLBOUND = [
617+
'T' => 0,
618+
'R' => 0,
619+
'B' => 0,
620+
'L' => 0,
621+
];
622+
614623
/**
615624
* Default values for cell.
616625
*
617626
* @const TCellDef
618627
*/
619628
public const ZEROCELL = [
620-
'margin' => [
621-
'T' => 0,
622-
'R' => 0,
623-
'B' => 0,
624-
'L' => 0,
625-
],
626-
'padding' => [
627-
'T' => 0,
628-
'R' => 0,
629-
'B' => 0,
630-
'L' => 0,
631-
],
629+
'margin' => self::ZEROCELLBOUND,
630+
'padding' => self::ZEROCELLBOUND,
632631
'borderpos' => self::BORDERPOS_DEFAULT,
633632
];
634633

@@ -713,16 +712,16 @@ protected function getUnitValuePoints(
713712
string $defunit = 'px',
714713
): float {
715714
$unit = 'px';
716-
if (in_array($defunit, self::VALIDUNITS)) {
715+
if (\in_array($defunit, self::VALIDUNITS)) {
717716
$unit = $defunit;
718717
}
719718

720719
$value = 0.0;
721-
if (is_numeric($val)) {
722-
$value = floatval($val);
723-
} elseif (preg_match('/([0-9\.\-\+]+)([a-z%]{0,4})/', $val, $match)) {
724-
$value = floatval($match[1]);
725-
if (in_array($match[2], self::VALIDUNITS)) {
720+
if (\is_numeric($val)) {
721+
$value = \floatval($val);
722+
} elseif (\preg_match('/([0-9\.\-\+]+)([a-z%]{0,4})/', $val, $match)) {
723+
$value = \floatval($match[1]);
724+
if (\in_array($match[2], self::VALIDUNITS)) {
726725
$unit = $match[2];
727726
}
728727
} else {
@@ -755,9 +754,9 @@ protected function getUnitValuePoints(
755754
// Relative to 1% of the height of the viewport.
756755
'vh' => (($value * $ref['viewport']['height']) / 100),
757756
// Relative to 1% of viewport's* larger dimension.
758-
'vmax' => (($value * max($ref['viewport']['height'], $ref['viewport']['width'])) / 100),
757+
'vmax' => (($value * \max($ref['viewport']['height'], $ref['viewport']['width'])) / 100),
759758
// Relative to 1% of viewport's smaller dimension.
760-
'vmin' => (($value * min($ref['viewport']['height'], $ref['viewport']['width'])) / 100),
759+
'vmin' => (($value * \min($ref['viewport']['height'], $ref['viewport']['width'])) / 100),
761760
// Relative to 1% of the width of the viewport.
762761
'vw' => (($value * $ref['viewport']['width']) / 100),
763762
};
@@ -778,7 +777,7 @@ protected function getFontValuePoints(
778777
array $ref = self::REFUNITVAL,
779778
string $defunit = 'pt',
780779
): float {
781-
if (is_string($val) && isset(self::FONTRELSIZE[$val])) {
780+
if (\is_string($val) && isset(self::FONTRELSIZE[$val])) {
782781
return ($ref['parent'] + self::FONTRELSIZE[$val]);
783782
}
784783

0 commit comments

Comments
 (0)