Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start SVG #113

Merged
merged 5 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.0.77
8.0.79
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"tecnickcom/tc-lib-unicode-data": "^2.0",
"tecnickcom/tc-lib-unicode": "^2.0",
"tecnickcom/tc-lib-pdf-page": "^4.2",
"tecnickcom/tc-lib-pdf-graph": "^2.1"
"tecnickcom/tc-lib-pdf-graph": "^2.2"
},
"require-dev": {
"pdepend/pdepend": "2.13.0",
Expand Down
2 changes: 1 addition & 1 deletion resources/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Vcs-Git: https://github.com/~#VENDOR#~/~#PROJECT#~.git
Package: ~#PKGNAME#~
Provides: php-~#PROJECT#~
Architecture: all
Depends: php (>= 8.0.0), php-date, php-tecnickcom-tc-lib-barcode (<< 3.0.0), php-tecnickcom-tc-lib-barcode (>= 2.2.3), php-tecnickcom-tc-lib-color (<< 3.0.0), php-tecnickcom-tc-lib-color (>= 2.2.2), php-tecnickcom-tc-lib-pdf-image (<< 3.0.0), php-tecnickcom-tc-lib-pdf-image (>= 2.1.1), php-tecnickcom-tc-lib-pdf-font (<< 3.0.0), php-tecnickcom-tc-lib-pdf-font (>= 2.5.0), php-tecnickcom-tc-lib-file (<< 3.0.0), php-tecnickcom-tc-lib-file (>= 2.0.13), php-tecnickcom-tc-lib-pdf-encrypt (<< 3.0.0), php-tecnickcom-tc-lib-pdf-encrypt (>= 2.1.4), php-tecnickcom-tc-lib-unicode-data (<< 3.0.0), php-tecnickcom-tc-lib-unicode-data (>= 2.0.13), php-tecnickcom-tc-lib-unicode (<< 3.0.0), php-tecnickcom-tc-lib-unicode (>= 2.0.13), php-tecnickcom-tc-lib-pdf-page (<< 5.0.0), php-tecnickcom-tc-lib-pdf-page (>= 4.2.0), php-tecnickcom-tc-lib-pdf-graph (<< 3.0.0), php-tecnickcom-tc-lib-pdf-graph (>= 2.1.1), ${misc:Depends}
Depends: php (>= 8.0.0), php-date, php-tecnickcom-tc-lib-barcode (<< 3.0.0), php-tecnickcom-tc-lib-barcode (>= 2.2.3), php-tecnickcom-tc-lib-color (<< 3.0.0), php-tecnickcom-tc-lib-color (>= 2.2.2), php-tecnickcom-tc-lib-pdf-image (<< 3.0.0), php-tecnickcom-tc-lib-pdf-image (>= 2.1.1), php-tecnickcom-tc-lib-pdf-font (<< 3.0.0), php-tecnickcom-tc-lib-pdf-font (>= 2.5.0), php-tecnickcom-tc-lib-file (<< 3.0.0), php-tecnickcom-tc-lib-file (>= 2.0.13), php-tecnickcom-tc-lib-pdf-encrypt (<< 3.0.0), php-tecnickcom-tc-lib-pdf-encrypt (>= 2.1.5), php-tecnickcom-tc-lib-unicode-data (<< 3.0.0), php-tecnickcom-tc-lib-unicode-data (>= 2.0.13), php-tecnickcom-tc-lib-unicode (<< 3.0.0), php-tecnickcom-tc-lib-unicode (>= 2.0.13), php-tecnickcom-tc-lib-pdf-page (<< 5.0.0), php-tecnickcom-tc-lib-pdf-page (>= 4.2.0), php-tecnickcom-tc-lib-pdf-graph (<< 3.0.0), php-tecnickcom-tc-lib-pdf-graph (>= 2.2.0), ${misc:Depends}
Description: PHP Barcode library
This library includes PHP classes to generate PDF documents.
4 changes: 2 additions & 2 deletions resources/rpm/rpm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ Requires: php-composer(%{c_vendor}/tc-lib-pdf-font) >= 2.5.0
Requires: php-composer(%{c_vendor}/tc-lib-file) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-file) >= 2.0.13
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) >= 2.1.4
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) >= 2.1.5
Requires: php-composer(%{c_vendor}/tc-lib-unicode-data) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-unicode-data) >= 2.0.13
Requires: php-composer(%{c_vendor}/tc-lib-unicode) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-unicode) >= 2.0.13
Requires: php-composer(%{c_vendor}/tc-lib-pdf-page) < 5.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-page) >= 4.2.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-graph) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-graph) >= 2.1.1
Requires: php-composer(%{c_vendor}/tc-lib-pdf-graph) >= 2.2.0

Provides: php-composer(%{c_vendor}/%{gh_project}) = %{version}
Provides: php-%{gh_project} = %{version}
Expand Down
132 changes: 131 additions & 1 deletion src/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace Com\Tecnick\Pdf;

use Com\Tecnick\Pdf\Exception as PdfException;
use Com\Tecnick\Barcode\Barcode as ObjBarcode;
use Com\Tecnick\Color\Pdf as ObjColor;
use Com\Tecnick\File\Cache as ObjCache;
Expand Down Expand Up @@ -87,6 +88,21 @@
* 'borderpos': float,
* }
*
*
* @phpstan-type TRefUnitValues array{
* 'parent': float,
* 'font': array{
* 'rootsize': float,
* 'size': float,
* 'xheight': float,
* 'zerowidth': float,
* },
* 'viewport': array{
* 'width': float,
* 'height': float,
* },
* }
*
* @phpstan-type TStackBBox array<int, TBBox>
*
* @phpstan-import-type TAnnot from Output
Expand Down Expand Up @@ -156,7 +172,7 @@ abstract class Base
/**
* TCPDF version.
*/
protected string $version = '8.0.77';
protected string $version = '8.0.79';

/**
* Time is seconds since EPOCH when the document was created.
Expand Down Expand Up @@ -238,11 +254,33 @@ abstract class Base
*/
protected string $unit = 'mm';

/**
* Valid HTML/CSS/SVG units.
*
* @var array<string>
*/
protected const VALIDUNITS = [
'%', 'ch', 'cm', 'em', 'ex',
'in', 'mm', 'pc', 'pt', 'px',
'rem', 'vh', 'vmax', 'vmin', 'vw',
];

/**
* DPI (Dot Per Inch) Document Resolution (do not change).
* 1pt = 1/72 of 1in.
*/
protected float $dpi = 72.0;

/**
* Unit of measure conversion ratio.
*/
protected float $kunit = 1.0;

/**
* Ratio between an internal point and pixel size.
*/
protected float $pointtopixelratio = 1.0;

/**
* Version of the PDF/A mode or 0 otherwise.
*/
Expand Down Expand Up @@ -596,4 +634,96 @@ public function enableDefaultPageContent(bool $enable = true): void
{
$this->defPageContentEnabled = $enable;
}

/**
* Set the pixel/point ratio used to convert pixel values to points.
*
* @param float $val
*
* @return void
*/
public function setPointToPixelRatio(float $val): void
{
$this->pointtopixelratio = $val;
}

/**
* Converts a string containing value and unit of measure to internal points.
* This is used to convert values for SVG, CSS, HTML.
*
* @param string|float|int $val String containing values and unit.
* @param TRefUnitValues $ref Reference values in points.
* @param string $defunit Default unit (can be one of the VALIDUNITS).
*
* @return float Internal points value.
*/
public function getUnitValuePoints(
string|float|int $val,
array $ref = [
'parent' => 1.0,
'font' => [
'rootsize' => 10.0,
'size' => 10.0,
'xheight' => 5.0,
'zerowidth' => 3.0,
],
'viewport' => [
'width' => 1000.0,
'height' => 1000.0,
],
],
string $defunit = 'px',
): float {
$unit = 'px';
if (in_array($defunit, self::VALIDUNITS)) {
$unit = $defunit;
}

$value = 0.0;
if (is_numeric($val)) {
$value = floatval($val);
} elseif (preg_match('/([0-9\.\-\+]+)([a-z%]{0,4})/', $val, $match)) {
$value = floatval($match[1]);
if (in_array($match[2], self::VALIDUNITS)) {
$unit = $match[2];
}
} else {
throw new PdfException('Invalid value: ' . $val);
}

return match ($unit) {
// Percentage relative to the parent element.
'%' => (($value * $ref['parent']) / 100),
// Relative to the width of the "0" (zero)
'ch' => ($value * $ref['font']['zerowidth']),
// Centimeters.
'cm' => (($value * $this->dpi) / 2.54),
// Relative to the font-size of the element.
'em' => ($value * $ref['font']['size']),
// Relative to the x-height of the current font.
'ex' => ($value * $ref['font']['xheight']),
// Inches.
'in' => ($value * $this->dpi),
// Millimeters.
'mm' => (($value * $this->dpi) / 25.4),
// One pica is 12 points.
'pc' => ($value * 12),
// Points.
'pt' => $value,
// Pixels.
'px' => ($value * $this->pointtopixelratio),
// Relative to font-size of the root element.
'rem' => ($value * $ref['font']['rootsize']),
// Relative to 1% of the height of the viewport.
'vh' => (($value * $ref['viewport']['height']) / 100),
// Relative to 1% of viewport's* larger dimension.
'vmax' => (($value * max($ref['viewport']['height'], $ref['viewport']['width'])) / 100),
// Relative to 1% of viewport's smaller dimension.
'vmin' => (($value * min($ref['viewport']['height'], $ref['viewport']['width'])) / 100),
// Relative to 1% of the width of the viewport.
'vw' => (($value * $ref['viewport']['width']) / 100),
// Default to pixels.
default => ($value * $this->pointtopixelratio),
};
}
}
36 changes: 36 additions & 0 deletions src/CSS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* CSS.php
*
* @since 2002-08-03
* @category Library
* @package Pdf
* @author Nicola Asuni <[email protected]>
* @copyright 2002-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf
*
* This file is part of tc-lib-pdf software library.
*/

namespace Com\Tecnick\Pdf;

use Com\Tecnick\Pdf\Exception as PdfException;

/**
* Com\Tecnick\Pdf\CSS
*
* CSS PDF class
*
* @since 2002-08-03
* @category Library
* @package Pdf
* @author Nicola Asuni <[email protected]>
* @copyright 2002-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf
*/
abstract class CSS extends \Com\Tecnick\Pdf\SVG
{
}
1 change: 1 addition & 0 deletions src/ClassObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf
*
* @SuppressWarnings(PHPMD.DepthOfInheritance)
*/
abstract class ClassObjects extends \Com\Tecnick\Pdf\Output
{
Expand Down
36 changes: 36 additions & 0 deletions src/HTML.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* HTML.php
*
* @since 2002-08-03
* @category Library
* @package Pdf
* @author Nicola Asuni <[email protected]>
* @copyright 2002-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf
*
* This file is part of tc-lib-pdf software library.
*/

namespace Com\Tecnick\Pdf;

use Com\Tecnick\Pdf\Exception as PdfException;

/**
* Com\Tecnick\Pdf\HTML
*
* HTML PDF class
*
* @since 2002-08-03
* @category Library
* @package Pdf
* @author Nicola Asuni <[email protected]>
* @copyright 2002-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf
*/
abstract class HTML extends \Com\Tecnick\Pdf\CSS
{
}
38 changes: 38 additions & 0 deletions src/JavaScript.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* JavaScript.php
*
* @since 2002-08-03
* @category Library
* @package Pdf
* @author Nicola Asuni <[email protected]>
* @copyright 2002-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf
*
* This file is part of tc-lib-pdf software library.
*/

namespace Com\Tecnick\Pdf;

use Com\Tecnick\Pdf\Exception as PdfException;

/**
* Com\Tecnick\Pdf\JavaScript
*
* JavaScript PDF class
*
* @since 2002-08-03
* @category Library
* @package Pdf
* @author Nicola Asuni <[email protected]>
* @copyright 2002-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf
*
* @SuppressWarnings(PHPMD.DepthOfInheritance)
*/
abstract class JavaScript extends \Com\Tecnick\Pdf\HTML
{
}
4 changes: 3 additions & 1 deletion src/MetaInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
* @link https://github.com/tecnickcom/tc-lib-pdf
*
* @phpstan-import-type TViewerPref from Base
*
* @SuppressWarnings(PHPMD.DepthOfInheritance)
*/
abstract class MetaInfo extends \Com\Tecnick\Pdf\Text
abstract class MetaInfo extends \Com\Tecnick\Pdf\JavaScript
{
/**
* Valid document zoom modes
Expand Down
11 changes: 6 additions & 5 deletions src/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ protected function getOutCatalog(): string
}

$font = $this->font->getFont('helvetica');
$out .= ' /DA (/F' . $font['i'] . ' 0 Tf 0 g)';
$out .= ' /DA ' . $this->encrypt->escapeDataString('/F' . $font['i'] . ' 0 Tf 0 g', $oid);
$out .= ' /Q ' . (($this->rtl) ? '2' : '0');
//$out .= ' /XFA ';
$out .= ' >>';
Expand Down Expand Up @@ -1657,7 +1657,7 @@ protected function getOutAnnotationOptSubtype(array $annot, int $pagenum, int $o
'caret' => $this->getOutAnnotationOptSubtypeCaret($annot),
'circle' => $this->getOutAnnotationOptSubtypeCircle($annot),
'fileattachment' => $this->getOutAnnotationOptSubtypeFileattachment($annot, $key),
'freetext' => $this->getOutAnnotationOptSubtypeFreetext($annot),
'freetext' => $this->getOutAnnotationOptSubtypeFreetext($annot, $oid),
'highlight' => $this->getOutAnnotationOptSubtypeHighlight($annot),
'ink' => $this->getOutAnnotationOptSubtypeInk($annot),
'line' => $this->getOutAnnotationOptSubtypeLine($annot),
Expand Down Expand Up @@ -1827,12 +1827,13 @@ protected function getOutAnnotationOptSubtypeLink(
* Returns the output code associated with the annotation opt.subtype.freetext.
*
* @param TAnnot $annot Array containing page annotations.
* @param int $oid Annotation Object ID.
*/
protected function getOutAnnotationOptSubtypeFreetext(array $annot): string
protected function getOutAnnotationOptSubtypeFreetext(array $annot, int $oid): string
{
$out = '';
if (! empty($annot['opt']['da'])) {
$out .= ' /DA (' . $annot['opt']['da'] . ')';
$out .= ' /DA ' . $this->encrypt->escapeDataString($annot['opt']['da'], $oid);
}

if (
Expand Down Expand Up @@ -2304,7 +2305,7 @@ protected function getOutAnnotationOptSubtypeWidget(
}

if (! empty($annot['opt']['da'])) {
$out .= ' /DA (' . $annot['opt']['da'] . ')';
$out .= ' /DA ' . $this->encrypt->escapeDataString($annot['opt']['da'], $oid);
}

if (
Expand Down
Loading
Loading