Skip to content

Commit

Permalink
Draft xobject support + refactor bbox (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni authored Aug 17, 2024
1 parent fd36760 commit 967cd0e
Show file tree
Hide file tree
Showing 10 changed files with 468 additions and 232 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.0.66
8.0.68
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"tecnickcom/tc-lib-barcode": "^2.2",
"tecnickcom/tc-lib-color": "^2.0",
"tecnickcom/tc-lib-pdf-image": "^2.0",
"tecnickcom/tc-lib-pdf-font": "^2.2",
"tecnickcom/tc-lib-pdf-font": "^2.3",
"tecnickcom/tc-lib-file": "^2.0",
"tecnickcom/tc-lib-pdf-encrypt": "^2.1",
"tecnickcom/tc-lib-unicode-data": "^2.0",
Expand Down
11 changes: 5 additions & 6 deletions examples/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,6 @@
$pdf->graph->add($styletxt);



$bfont2 = $pdf->font->insert($pdf->pon, 'times', 'BI', 24);

$pdf->page->addContent($bfont2['out']);
Expand All @@ -1043,13 +1042,13 @@

$pdf->page->addContent($txt);

$bbox = $pdf->getLastTextBBox();
$bbox = $pdf->getLastBBox();

// Add text
$txt2 = $pdf->getTextLine(
'Link to https://tcpdf.org',
15,
($bbox['y'] + $bbox['height'] + $pdf->toUnit($bfont2['ascent'])),
($bbox['y'] + $bbox['h'] + $pdf->toUnit($bfont2['ascent'])),
0,
0,
0,
Expand All @@ -1071,13 +1070,13 @@
$pdf->page->addContent($txt2);

// get the coordinates of the box containing the last added text string.
$bbox = $pdf->getLastTextBBox();
$bbox = $pdf->getLastBBox();

$aoid = $pdf->setAnnotation(
$bbox['x'],
$bbox['y'],
$bbox['width'],
$bbox['height'],
$bbox['w'],
$bbox['h'],
'https://tcpdf.org',
[
'subtype' => 'Link',
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 (<< 2.0.0), php-tecnickcom-tc-lib-barcode (>= 2.2.1), php-tecnickcom-tc-lib-color (<< 2.0.0), php-tecnickcom-tc-lib-color (>= 2.0.8), php-tecnickcom-tc-lib-pdf-image (<< 2.0.0), php-tecnickcom-tc-lib-pdf-image (>= 2.0.12), php-tecnickcom-tc-lib-pdf-font (<< 2.0.0), php-tecnickcom-tc-lib-pdf-font (>= 2.2.3), php-tecnickcom-tc-lib-file (<< 2.0.0), php-tecnickcom-tc-lib-file (>= 2.0.11), php-tecnickcom-tc-lib-pdf-encrypt (<< 2.0.0), php-tecnickcom-tc-lib-pdf-encrypt (>= 2.1.2), php-tecnickcom-tc-lib-unicode-data (<< 2.0.0), php-tecnickcom-tc-lib-unicode-data (>= 2.0.11), php-tecnickcom-tc-lib-unicode (<< 2.0.0), php-tecnickcom-tc-lib-unicode (>= 2.0.11), php-tecnickcom-tc-lib-pdf-page (<< 3.0.0), php-tecnickcom-tc-lib-pdf-page (>= 4.0.8), php-tecnickcom-tc-lib-pdf-graph (<< 2.0.0), php-tecnickcom-tc-lib-pdf-graph (>= 2.0.12), ${misc:Depends}
Depends: php (>= 8.0.0), php-date, php-tecnickcom-tc-lib-barcode (<< 3.0.0), php-tecnickcom-tc-lib-barcode (>= 2.2.2), php-tecnickcom-tc-lib-color (<< 3.0.0), php-tecnickcom-tc-lib-color (>= 2.0.9), php-tecnickcom-tc-lib-pdf-image (<< 3.0.0), php-tecnickcom-tc-lib-pdf-image (>= 2.0.15), php-tecnickcom-tc-lib-pdf-font (<< 3.0.0), php-tecnickcom-tc-lib-pdf-font (>= 2.3.1), php-tecnickcom-tc-lib-file (<< 3.0.0), php-tecnickcom-tc-lib-file (>= 2.0.12), php-tecnickcom-tc-lib-pdf-encrypt (<< 3.0.0), php-tecnickcom-tc-lib-pdf-encrypt (>= 2.1.3), php-tecnickcom-tc-lib-unicode-data (<< 3.0.0), php-tecnickcom-tc-lib-unicode-data (>= 2.0.12), php-tecnickcom-tc-lib-unicode (<< 3.0.0), php-tecnickcom-tc-lib-unicode (>= 2.0.12), php-tecnickcom-tc-lib-pdf-page (<< 5.0.0), php-tecnickcom-tc-lib-pdf-page (>= 4.0.10), php-tecnickcom-tc-lib-pdf-graph (<< 3.0.0), php-tecnickcom-tc-lib-pdf-graph (>= 2.0.13), ${misc:Depends}
Description: PHP Barcode library
This library includes PHP classes to generate PDF documents.
40 changes: 20 additions & 20 deletions resources/rpm/rpm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ BuildArch: noarch
Requires: php(language) >= 8.0.0
Requires: php-date
Requires: php-pcre
Requires: php-composer(%{c_vendor}/tc-lib-barcode) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-barcode) >= 2.2.1
Requires: php-composer(%{c_vendor}/tc-lib-color) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-color) >= 2.0.8
Requires: php-composer(%{c_vendor}/tc-lib-pdf-image) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-image) >= 2.0.12
Requires: php-composer(%{c_vendor}/tc-lib-pdf-font) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-font) >= 2.2.3
Requires: php-composer(%{c_vendor}/tc-lib-file) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-file) >= 2.0.11
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) >= 2.1.2
Requires: php-composer(%{c_vendor}/tc-lib-unicode-data) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-unicode-data) >= 2.0.11
Requires: php-composer(%{c_vendor}/tc-lib-unicode) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-unicode) >= 2.0.11
Requires: php-composer(%{c_vendor}/tc-lib-pdf-page) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-page) >= 4.0.8
Requires: php-composer(%{c_vendor}/tc-lib-pdf-graph) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-graph) >= 2.0.12
Requires: php-composer(%{c_vendor}/tc-lib-barcode) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-barcode) >= 2.2.2
Requires: php-composer(%{c_vendor}/tc-lib-color) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-color) >= 2.0.9
Requires: php-composer(%{c_vendor}/tc-lib-pdf-image) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-image) >= 2.0.15
Requires: php-composer(%{c_vendor}/tc-lib-pdf-font) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-font) >= 2.3.1
Requires: php-composer(%{c_vendor}/tc-lib-file) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-file) >= 2.0.12
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) >= 2.1.3
Requires: php-composer(%{c_vendor}/tc-lib-unicode-data) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-unicode-data) >= 2.0.12
Requires: php-composer(%{c_vendor}/tc-lib-unicode) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-unicode) >= 2.0.12
Requires: php-composer(%{c_vendor}/tc-lib-pdf-page) < 5.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-page) >= 4.0.10
Requires: php-composer(%{c_vendor}/tc-lib-pdf-graph) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-graph) >= 2.0.13

Provides: php-composer(%{c_vendor}/%{gh_project}) = %{version}
Provides: php-%{gh_project} = %{version}
Expand Down
155 changes: 92 additions & 63 deletions src/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

namespace Com\Tecnick\Pdf;

use Com\Tecnick\Barcode\Barcode;
use Com\Tecnick\Color\Pdf;
use Com\Tecnick\File\Cache;
use Com\Tecnick\File\File;
use Com\Tecnick\Pdf\Encrypt\Encrypt;
use Com\Tecnick\Pdf\Font\Stack;
use Com\Tecnick\Pdf\Graph\Draw;
use Com\Tecnick\Pdf\Image\Import;
use Com\Tecnick\Pdf\Page\Page;
use Com\Tecnick\Unicode\Convert;
use Com\Tecnick\Barcode\Barcode as ObjBarcode;
use Com\Tecnick\Color\Pdf as ObjColor;
use Com\Tecnick\File\Cache as ObjCache;
use Com\Tecnick\File\File as ObjFile;
use Com\Tecnick\Pdf\Encrypt\Encrypt as ObjEncrypt;
use Com\Tecnick\Pdf\Font\Stack as ObjFont;
use Com\Tecnick\Pdf\Graph\Draw as ObjGraph;
use Com\Tecnick\Pdf\Image\Import as ObjImage;
use Com\Tecnick\Pdf\Page\Page as ObjPage;
use Com\Tecnick\Unicode\Convert as ObjUniConvert;

/**
* Com\Tecnick\Pdf\Base
Expand Down Expand Up @@ -60,73 +60,83 @@
* 'NumCopies'?: int,
* }
*
* @phpstan-type TBBox array{
* 'x': float,
* 'y': float,
* 'w': float,
* 'h': float,
* }
*
* @phpstan-type TStackBBox array<int, TBBox>
*
* @phpstan-import-type TAnnot from Output
* @phpstan-import-type TEmbeddedFile from Output
* @phpstan-import-type TObjID from Output
* @phpstan-import-type TOutline from Output
* @phpstan-import-type TAnnot from Output
* @phpstan-import-type TXOBject from Output
* @phpstan-import-type TSignature from Output
* @phpstan-import-type TSignTimeStamp from Output
* @phpstan-import-type TGTransparency from Output
* @phpstan-import-type TUserRights from Output
* @phpstan-import-type TObjID from Output
* @phpstan-import-type TXOBject from Output
*
* @SuppressWarnings(PHPMD)
*/
abstract class Base
{
/**
* Encrypt object
*/
public Encrypt $encrypt;

/**
* Color object
*/
public Pdf $color;

/**
* Barcode object
*/
public Barcode $barcode;

/**
* File object
*/
public File $file;

/**
* Cache object
*/
public Cache $cache;

/**
* Unicode Convert object
*/
public Convert $uniconv;

/**
* Page object
*/
public Page $page;

/**
* Graph object
*/
public Draw $graph;

/**
* Font object
*/
public Stack $font;

/**
* Image Import object
*/
public Import $image;
/**
* Encrypt object.
*/
public ObjEncrypt $encrypt;

/**
* Color object.
*/
public ObjColor $color;

/**
* Barcode object.
*/
public ObjBarcode $barcode;

/**
* File object.
*/
public ObjFile $file;

/**
* Cache object.
*/
public ObjCache $cache;

/**
* Unicode Convert object.
*/
public ObjUniConvert $uniconv;

/**
* Page object.
*/
public ObjPage $page;

/**
* Graph object.
*/
public ObjGraph $graph;

/**
* Font object.
*/
public ObjFont $font;

/**
* Image Import object.
*/
public ObjImage $image;

/**
* TCPDF version.
*/
protected string $version = '8.0.66';
protected string $version = '8.0.68';

/**
* Time is seconds since EPOCH when the document was created.
Expand Down Expand Up @@ -341,6 +351,13 @@ abstract class Base
*/
protected array $xobject = [];

/**
* Current XOBject template ID.
*
* @var string
*/
protected string $xobjtid = '';

/**
* Outlines Data.
*
Expand Down Expand Up @@ -438,6 +455,18 @@ abstract class Base
*/
protected array $xobjects = [];

/**
* Stack of bounding boxes [x, y, width, height] in user units.
*
* @var TStackBBox
*/
protected $bbox = [[
'x' => 0,
'y' => 0,
'w' => 0,
'h' => 0,
]];

/**
* Convert user units to internal points unit.
*
Expand Down
42 changes: 20 additions & 22 deletions src/ClassObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,39 @@
* @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 ClassObjects extends \Com\Tecnick\Pdf\Output
{
/**
* Initialize class objects
*/
protected function initClassObjects(): void
{
/**
* Initialize dependencies class objects.
*
* @param ?ObjEncrypt $objEncrypt Encryption object.
*/
public function initClassObjects(
?ObjEncrypt $objEncrypt = null
): void {
if ($objEncrypt instanceof ObjEncrypt) {
$this->encrypt = $objEncrypt;
} else {
$this->encrypt = new ObjEncrypt();
}

$this->color = new ObjColor();
$this->barcode = new ObjBarcode();
$this->file = new ObjFile();
$this->cache = new ObjCache();
$this->uniconv = new ObjUniConvert();
$this->encrypt = new ObjEncrypt();

$this->page = new ObjPage(
$this->unit,
$this->color,
$this->encrypt,
(bool) $this->pdfa,
$this->compress,
$this->sigapp
$this->sigapp,
);

$this->kunit = $this->page->getKUnit();

$this->graph = new ObjGraph(
Expand All @@ -71,33 +81,21 @@ protected function initClassObjects(): void
$this->color,
$this->encrypt,
(bool) $this->pdfa,
$this->compress
$this->compress,
);

$this->font = new ObjFont(
$this->kunit,
$this->subsetfont,
$this->isunicode,
(bool) $this->pdfa
(bool) $this->pdfa,
);

$this->image = new ObjImage(
$this->kunit,
$this->encrypt,
(bool) $this->pdfa,
$this->compress
$this->compress,
);
}

/**
* Enable or disable the the Signature Approval
*
* @param bool $enabled It true enable the Signature Approval
*/
protected function enableSignatureApproval(bool $enabled = true): static
{
$this->sigapp = $enabled;
$this->page->enableSignatureApproval($this->sigapp);
return $this;
}
}
Loading

0 comments on commit 967cd0e

Please sign in to comment.