Skip to content

Commit 02c59fd

Browse files
committed
dependencies, documentation and testing
1 parent 0789633 commit 02c59fd

9 files changed

Lines changed: 175 additions & 11 deletions

File tree

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,3 @@ require_once '/usr/share/php/Com/Tecnick/Pdf/Graph/autoload.php';
110110

111111
Contributions are welcome. Please review [CONTRIBUTING.md](CONTRIBUTING.md), [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md), and [SECURITY.md](SECURITY.md).
112112

113-
---
114-
115-
## Contact
116-
117-
Nicola Asuni - <info@tecnick.com>

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.5.0
1+
2.6.0

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"require": {
2828
"php": ">=8.2",
2929
"ext-zlib": "*",
30-
"tecnickcom/tc-lib-color": "^2.6",
31-
"tecnickcom/tc-lib-pdf-encrypt": "^2.3"
30+
"tecnickcom/tc-lib-color": "^2.7",
31+
"tecnickcom/tc-lib-pdf-encrypt": "^2.4"
3232
},
3333
"minimum-stability": "dev",
3434
"prefer-stable": true,

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.2.0), php-zip, php-tecnickcom-tc-lib-color (<< 3.0.0), php-tecnickcom-tc-lib-color (>= 2.6.0), php-tecnickcom-tc-lib-pdf-encrypt (<< 3.0.0), php-tecnickcom-tc-lib-pdf-encrypt (>= 2.3.0), ${misc:Depends}
15+
Depends: php (>= 8.2.0), php-zip, php-tecnickcom-tc-lib-color (<< 3.0.0), php-tecnickcom-tc-lib-color (>= 2.7.0), php-tecnickcom-tc-lib-pdf-encrypt (<< 3.0.0), php-tecnickcom-tc-lib-pdf-encrypt (>= 2.4.0), ${misc:Depends}
1616
Description: PHP PDF Graph Library
1717
PHP library containing PDF graphic and geometric methods.

resources/rpm/rpm.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ BuildArch: noarch
1717
Requires: php(language) >= 8.2.0
1818
Requires: php-zlib
1919
Requires: php-composer(%{c_vendor}/tc-lib-color) < 3.0.0
20-
Requires: php-composer(%{c_vendor}/tc-lib-color) >= 2.6.0
20+
Requires: php-composer(%{c_vendor}/tc-lib-color) >= 2.7.0
2121
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) < 3.0.0
22-
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) >= 2.3.0
22+
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) >= 2.4.0
2323

2424
Provides: php-composer(%{c_vendor}/%{gh_project}) = %{version}
2525
Provides: php-%{gh_project} = %{version}

test/BaseTest.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,110 @@ protected function getTestObject(): \Com\Tecnick\Pdf\Graph\Draw
4141
);
4242
}
4343

44+
/**
45+
* @throws \Com\Tecnick\Pdf\Graph\Exception
46+
*/
47+
public function testGetOutResourcesByKeysSkipInvalidEntries(): void
48+
{
49+
$draw = $this->getTestObject();
50+
51+
$draw->getOverprint();
52+
$draw->getGradient(
53+
2,
54+
[0, 0, 1, 0],
55+
[
56+
['color' => 'red', 'offset' => 0.0],
57+
['color' => 'blue', 'offset' => 1.0],
58+
],
59+
'',
60+
false,
61+
);
62+
63+
$this->assertSame(' /ExtGState << >>' . "\n", $draw->getOutExtGStateResourcesByKeys([999]));
64+
$this->assertSame('', $draw->getOutGradientResourcesByKeys([999]));
65+
}
66+
67+
/**
68+
* @throws \Com\Tecnick\Pdf\Graph\Exception
69+
* @throws \Com\Tecnick\Pdf\Encrypt\Exception
70+
*/
71+
public function testGradientShadersHandleMalformedStopsAndFloatExponent(): void
72+
{
73+
$draw = $this->getTestObject();
74+
$draw->getGradient(
75+
2,
76+
[0, 0, 1, 0],
77+
[
78+
['color' => 'red', 'offset' => 0.0, 'opacity' => 0.5],
79+
['color' => 'blue', 'offset' => 1.0, 'opacity' => 0.6, 'exponent' => 1.5],
80+
],
81+
'',
82+
false,
83+
);
84+
85+
$outFloatExponent = $draw->getOutGradientShaders($draw->getObjectNumber());
86+
$this->assertStringContainsString('/N 1.5', $outFloatExponent);
87+
}
88+
89+
/**
90+
* @throws \Com\Tecnick\Pdf\Graph\Exception
91+
* @throws \Com\Tecnick\Pdf\Encrypt\Exception
92+
*/
93+
public function testGetOutGradientShadersSkipsMissingOpacityPattern(): void
94+
{
95+
$draw = new class(0.75, 80, 100, new \Com\Tecnick\Color\Pdf(), $this->getEncryptObject(), false) extends
96+
\Com\Tecnick\Pdf\Graph\Draw {
97+
/**
98+
* @param array<int, array{
99+
* antialias: bool,
100+
* background: ?\Com\Tecnick\Color\Model,
101+
* colors: array<int, array{color: string, exponent?: float, offset?: float, opacity?: float}>,
102+
* colspace: string,
103+
* coords: array<float>,
104+
* id: int,
105+
* pattern: int,
106+
* stream: string,
107+
* transparency: bool,
108+
* type: int,
109+
* }> $grads
110+
*/
111+
public function setGradientsForTest(array $grads): void
112+
{
113+
$this->gradients = $grads;
114+
}
115+
116+
protected function getOutGradientCols(array $grad, string $type): string
117+
{
118+
if ($type === 'opacity') {
119+
return '';
120+
}
121+
122+
return parent::getOutGradientCols($grad, $type);
123+
}
124+
};
125+
126+
$draw->setGradientsForTest([
127+
1 => [
128+
'antialias' => false,
129+
'background' => null,
130+
'colors' => [
131+
0 => ['color' => 'red', 'offset' => 0.0, 'opacity' => 0.5, 'exponent' => 1.0],
132+
1 => ['color' => 'blue', 'offset' => 1.0, 'opacity' => 0.6, 'exponent' => 1.0],
133+
],
134+
'colspace' => 'DeviceRGB',
135+
'coords' => [0.0, 0.0, 1.0, 0.0],
136+
'id' => 0,
137+
'pattern' => 0,
138+
'stream' => '',
139+
'transparency' => true,
140+
'type' => 2,
141+
],
142+
]);
143+
144+
$out = $draw->getOutGradientShaders(10);
145+
$this->assertNotSame('', $out);
146+
}
147+
44148
/**
45149
* @throws \Com\Tecnick\Pdf\Graph\Exception
46150
*/

test/DrawTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ public function testGetPolycurve(): void
203203
. "\n",
204204
$res,
205205
);
206+
207+
$res = $draw->getPolycurve(3, 5, [[7, 11, 13], [29, 31, 37, 41, 43, 47]]);
208+
$this->assertEquals(
209+
'2.250000 71.250000 m'
210+
. "\n"
211+
. '21.750000 51.750000 27.750000 44.250000 32.250000 39.750000 c'
212+
. "\n"
213+
. 'S'
214+
. "\n",
215+
$res,
216+
);
206217
}
207218

208219
/**
@@ -451,6 +462,9 @@ public function testGetBasicPolygon(): void
451462
. "\n",
452463
$res,
453464
);
465+
466+
$res = $draw->getBasicPolygon([3, 5, 7, 11, 13]);
467+
$this->assertEquals('2.250000 71.250000 m' . "\n" . '5.250000 66.750000 l' . "\n" . 'S' . "\n", $res);
454468
}
455469

456470
/**
@@ -552,6 +566,9 @@ public function testGetPolygon(): void
552566
. "\n",
553567
$res,
554568
);
569+
570+
$res = $draw->getPolygon([0 => 3, 1 => 5, 2 => 7, 3 => 11, 4 => 13, 6 => 19, 7 => 23, 8 => 29]);
571+
$this->assertEquals('2.250000 71.250000 m' . "\n" . '5.250000 66.750000 l' . "\n" . 'S' . "\n", $res);
555572
}
556573

557574
/**
@@ -935,6 +952,8 @@ public function testGetStarPolygon(): void
935952
. "\n",
936953
$res,
937954
);
955+
956+
$this->assertSame('', $draw->getStarPolygon(3, 5, 7, 4, -1));
938957
}
939958

940959
/**

test/GradientTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,26 @@ public function testGetGradient(): void
230230
$this->assertEquals(1, $draw->getLastGradientID());
231231
}
232232

233+
/**
234+
* @throws \Com\Tecnick\Pdf\Graph\Exception
235+
*/
236+
public function testGetGradientInvalidStops(): void
237+
{
238+
$this->bcExpectException(\Com\Tecnick\Pdf\Graph\Exception::class);
239+
$draw = $this->getTestObject();
240+
$draw->getGradient(2, [0, 0, 1, 0], [], '', false);
241+
}
242+
243+
/**
244+
* @throws \Com\Tecnick\Pdf\Graph\Exception
245+
*/
246+
public function testGetAlphaStringNonstrokingConversion(): void
247+
{
248+
$draw = $this->getTestObject();
249+
$this->assertSame('/GS1 gs' . "\n", $draw->getAlpha(0.5, 'Normal', '0.4'));
250+
$this->assertSame('/GS2 gs' . "\n", $draw->getAlpha(0.5, 'Normal', 'bad'));
251+
}
252+
233253
/**
234254
* @throws \Com\Tecnick\Pdf\Graph\Exception
235255
*/

test/StyleTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,32 @@ public function testRestoreStyleStatusNull(): void
467467
$this->assertEquals('butt', $draw->getCurrentStyleItem('lineCap'));
468468
}
469469

470+
/**
471+
* @throws \Com\Tecnick\Pdf\Graph\Exception
472+
*/
473+
public function testGetCurrentStyleArrayDefaultFallback(): void
474+
{
475+
$draw = new class(1, 0, 0, new \Com\Tecnick\Color\Pdf(), $this->getEncryptObject(), false) extends
476+
\Com\Tecnick\Pdf\Graph\Draw {
477+
public function setStyleIdForTest(int $styleid): void
478+
{
479+
$this->styleid = $styleid;
480+
}
481+
};
482+
483+
$draw->setStyleIdForTest(999);
484+
$this->assertSame('butt', $draw->getCurrentStyleArray()['lineCap'] ?? null);
485+
}
486+
487+
/**
488+
* @throws \Com\Tecnick\Pdf\Graph\Exception
489+
*/
490+
public function testIsClippingModeInvalid(): void
491+
{
492+
$draw = $this->getTestObject();
493+
$this->assertFalse($draw->isClippingMode('invalid'));
494+
}
495+
470496
/**
471497
* @throws \Com\Tecnick\Pdf\Graph\Exception
472498
*/

0 commit comments

Comments
 (0)