@@ -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 */
0 commit comments