]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/mpdf/classes/grad.php
7 function grad (& $mpdf ) {
12 function CoonsPatchMesh ( $x , $y , $w , $h , $patch_array = array (), $x_min = 0 , $x_max = 1 , $y_min = 0 , $y_max = 1 , $colspace = 'RGB' , $return = false ){
14 $s .= sprintf ( ' %.3F %.3F %.3F %.3F re W n ' , $x * _MPDFK
, ( $this- > mpdf
-> h
- $y )* _MPDFK
, $w * _MPDFK
, - $h * _MPDFK
);
15 $s .= sprintf ( ' %.3F 0 0 %.3F %.3F %.3F cm ' , $w * _MPDFK
, $h * _MPDFK
, $x * _MPDFK
, ( $this- > mpdf
-> h
-( $y +
$h ))* _MPDFK
);
16 $n = count ( $this- > mpdf
-> gradients
) +
1 ;
17 $this- > mpdf
-> gradients
[ $n ][ 'type' ] = 6 ; //coons patch mesh
18 $this- > mpdf
-> gradients
[ $n ][ 'colorspace' ] = $colspace ; //coons patch mesh
19 $bpcd = 65535 ; //16 BitsPerCoordinate
21 $this- > mpdf
-> gradients
[ $n ][ 'stream' ]= '' ;
22 for ( $i = 0 ; $i < count ( $patch_array ); $i ++
){
23 $this- > mpdf
-> gradients
[ $n ][ 'stream' ].= chr ( $patch_array [ $i ][ 'f' ]); //start with the edge flag as 8 bit
24 for ( $j = 0 ; $j < count ( $patch_array [ $i ][ 'points' ]); $j ++
){
25 //each point as 16 bit
26 if (( $j %
2 ) == 1 ) { // Y coordinate (adjusted as input is From top left)
27 $patch_array [ $i ][ 'points' ][ $j ]=(( $patch_array [ $i ][ 'points' ][ $j ]- $y_min )/( $y_max-$y_min ))* $bpcd ;
28 $patch_array [ $i ][ 'points' ][ $j ]= $bpcd-$patch_array [ $i ][ 'points' ][ $j ];
31 $patch_array [ $i ][ 'points' ][ $j ]=(( $patch_array [ $i ][ 'points' ][ $j ]- $x_min )/( $x_max-$x_min ))* $bpcd ;
33 if ( $patch_array [ $i ][ 'points' ][ $j ]< 0 ) $patch_array [ $i ][ 'points' ][ $j ]= 0 ;
34 if ( $patch_array [ $i ][ 'points' ][ $j ]> $bpcd ) $patch_array [ $i ][ 'points' ][ $j ]= $bpcd ;
35 $this- > mpdf
-> gradients
[ $n ][ 'stream' ].= chr ( floor ( $patch_array [ $i ][ 'points' ][ $j ]/ 256 ));
36 $this- > mpdf
-> gradients
[ $n ][ 'stream' ].= chr ( floor ( $patch_array [ $i ][ 'points' ][ $j ] %
256 ));
38 for ( $j = 0 ; $j < count ( $patch_array [ $i ][ 'colors' ]); $j ++
){
39 //each color component as 8 bit
40 if ( $colspace == 'RGB' ) {
41 $this- > mpdf
-> gradients
[ $n ][ 'stream' ].=( $patch_array [ $i ][ 'colors' ][ $j ][ 1 ]);
42 $this- > mpdf
-> gradients
[ $n ][ 'stream' ].=( $patch_array [ $i ][ 'colors' ][ $j ][ 2 ]);
43 $this- > mpdf
-> gradients
[ $n ][ 'stream' ].=( $patch_array [ $i ][ 'colors' ][ $j ][ 3 ]);
44 if ( isset ( $patch_array [ $i ][ 'colors' ][ $j ][ 4 ]) && ord ( $patch_array [ $i ][ 'colors' ][ $j ][ 4 ])< 100 ) { $trans
= true ; }
46 else if ( $colspace == 'CMYK' ) {
47 $this- > mpdf
-> gradients
[ $n ][ 'stream' ].= chr ( ord ( $patch_array [ $i ][ 'colors' ][ $j ][ 1 ])* 2.55 );
48 $this- > mpdf
-> gradients
[ $n ][ 'stream' ].= chr ( ord ( $patch_array [ $i ][ 'colors' ][ $j ][ 2 ])* 2.55 );
49 $this- > mpdf
-> gradients
[ $n ][ 'stream' ].= chr ( ord ( $patch_array [ $i ][ 'colors' ][ $j ][ 3 ])* 2.55 );
50 $this- > mpdf
-> gradients
[ $n ][ 'stream' ].= chr ( ord ( $patch_array [ $i ][ 'colors' ][ $j ][ 4 ])* 2.55 );
51 if ( isset ( $patch_array [ $i ][ 'colors' ][ $j ][ 5 ]) && ord ( $patch_array [ $i ][ 'colors' ][ $j ][ 5 ])< 100 ) { $trans
= true ; }
53 else if ( $colspace == 'Gray' ) {
54 $this- > mpdf
-> gradients
[ $n ][ 'stream' ].=( $patch_array [ $i ][ 'colors' ][ $j ][ 1 ]);
55 if ( $patch_array [ $i ][ 'colors' ][ $j ][ 2 ]== 1 ) { $trans
= true ; } // transparency converted from rgba or cmyka()
61 $this- > mpdf
-> gradients
[ $n ][ 'stream_trans' ]= '' ;
62 for ( $i = 0 ; $i < count ( $patch_array ); $i ++
){
63 $this- > mpdf
-> gradients
[ $n ][ 'stream_trans' ].= chr ( $patch_array [ $i ][ 'f' ]);
64 for ( $j = 0 ; $j < count ( $patch_array [ $i ][ 'points' ]); $j ++
){
65 //each point as 16 bit
66 $this- > mpdf
-> gradients
[ $n ][ 'stream_trans' ].= chr ( floor ( $patch_array [ $i ][ 'points' ][ $j ]/ 256 ));
67 $this- > mpdf
-> gradients
[ $n ][ 'stream_trans' ].= chr ( floor ( $patch_array [ $i ][ 'points' ][ $j ] %
256 ));
69 for ( $j = 0 ; $j < count ( $patch_array [ $i ][ 'colors' ]); $j ++
){
70 //each color component as 8 bit // OPACITY
71 if ( $colspace == 'RGB' ) {
72 $this- > mpdf
-> gradients
[ $n ][ 'stream_trans' ].= chr ( intval ( ord ( $patch_array [ $i ][ 'colors' ][ $j ][ 4 ])* 2.55 ));
74 else if ( $colspace == 'CMYK' ) {
75 $this- > mpdf
-> gradients
[ $n ][ 'stream_trans' ].= chr ( intval ( ord ( $patch_array [ $i ][ 'colors' ][ $j ][ 5 ])* 2.55 ));
77 else if ( $colspace == 'Gray' ) {
78 $this- > mpdf
-> gradients
[ $n ][ 'stream_trans' ].= chr ( intval ( ord ( $patch_array [ $i ][ 'colors' ][ $j ][ 3 ])* 2.55 ));
82 $this- > mpdf
-> gradients
[ $n ][ 'trans' ] = true ;
83 $s .= ' /TGS' . $n . ' gs ' ;
86 $s .= '/Sh' . $n . ' sh' . " \n " ;
87 //restore previous Graphic State
89 if ( $return ) { return $s
; }
90 else { $this
-> mpdf
-> _out ( $s
); }
94 // type = linear:2; radial: 3;
95 // Linear: $coords - array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg).
96 // The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
97 // Radial: $coords - array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1,
98 // (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg).
99 // (fx, fy) should be inside the circle, otherwise some areas will not be defined
100 // $col = array(R,G,B/255); or array(G/255); or array(C,M,Y,K/100)
101 // $stops = array('col'=>$col [, 'opacity'=>0-1] [, 'offset'=>0-1])
102 function Gradient ( $x , $y , $w , $h , $type , $stops = array (), $colorspace = 'RGB' , $coords = '' , $extend = '' , $return = false , $is_mask = false ) {
103 if ( strtoupper ( substr ( $type , 0 , 1 )) == 'L' ) { $type
= 2 ; } // linear
104 else if ( strtoupper ( substr ( $type , 0 , 1 )) == 'R' ) { $type
= 3 ; } // radial
105 if ( $colorspace != 'CMYK' && $colorspace != 'Gray' ) {
114 if ( $type < 1 ) { $type
= 2 ; }
115 if ( $coords [ 0 ]!== false && preg_match ( '/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i' , $coords [ 0 ], $m )) {
116 $tmp = $this- > mpdf
-> ConvertSize ( $m [ 1 ], $this- > mpdf
-> w
, $this- > mpdf
-> FontSize
, false );
117 if ( $tmp ) { $coords
[ 0 ] = $tmp
/ $w
; }
119 if ( $coords [ 1 ]!== false && preg_match ( '/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i' , $coords [ 1 ], $m )) {
120 $tmp = $this- > mpdf
-> ConvertSize ( $m [ 1 ], $this- > mpdf
-> w
, $this- > mpdf
-> FontSize
, false );
121 if ( $tmp ) { $coords
[ 1 ] = 1 -( $tmp
/ $h
); }
126 $repeat = $coords [ 5 ];
127 // ALL POINTS SET (default for custom mPDF linear gradient) - no -moz
128 if ( $coords [ 0 ]!== false && $coords [ 1 ]!== false && $coords [ 2 ]!== false && $coords [ 3 ]!== false ) {
129 // do nothing - coords used as they are
132 // If both a <point> and <angle> are defined, the gradient axis starts from the point and runs along the angle. The end point is
133 // defined as before - in this case start points may not be in corners, and axis may not correctly fall in the right quadrant.
134 // NO end points (Angle defined & Start points)
135 else if ( $angle !== false && $coords [ 0 ]!== false && $coords [ 1 ]!== false && $coords [ 2 ]=== false && $coords [ 3 ]=== false ) {
136 if ( $angle == 0 || $angle == 360 ) { $coords
[ 3 ]= $coords
[ 1 ]; if ( $coords
[ 0 ]== 1 ) $coords
[ 2 ]= 2 ; else $coords
[ 2 ]= 1 ; }
137 else if ( $angle == 90 ) { $coords
[ 2 ]= $coords
[ 0 ]; $coords
[ 3 ]= 1 ; if ( $coords
[ 1 ]== 1 ) $coords
[ 3 ]= 2 ; else $coords
[ 3 ]= 1 ; }
138 else if ( $angle == 180 ) { if ( $coords
[ 4 ]== 0 ) $coords
[ 2 ]=- 1 ; else $coords
[ 2 ]= 0 ; $coords
[ 3 ]= $coords
[ 1 ]; }
139 else if ( $angle == 270 ) { $coords
[ 2 ]= $coords
[ 0 ]; if ( $coords
[ 1 ]== 0 ) $coords
[ 3 ]=- 1 ; else $coords
[ 3 ]= 0 ; }
143 if ( $angle <= 45 ) { $endy
= tan ( deg2rad ( $angle
)); }
144 else { $endx
= tan ( deg2rad ( 90 - $angle
)); }
145 $b = atan2 (( $endy * $bboxh ), ( $endx * $bboxw ));
146 $ny = 1 - $coords [ 1 ] - ( tan ( $b ) * ( 1 - $coords [ 0 ]));
147 $tx = sin ( $b ) * cos ( $b ) * $ny ;
148 $ty = cos ( $b ) * cos ( $b ) * $ny ;
149 $coords [ 2 ] = 1 +
$tx ; $coords [ 3 ] = 1 - $ty ;
151 else if ( $angle <= 180 ) {
152 if ( $angle <= 135 ) { $endx
= tan ( deg2rad ( $angle
- 90 )); }
153 else { $endy
= tan ( deg2rad ( 180 - $angle
)); }
154 $b = atan2 (( $endy * $bboxh ), ( $endx * $bboxw ));
155 $ny = 1 - $coords [ 1 ] - ( tan ( $b ) * ( $coords [ 0 ]));
156 $tx = sin ( $b ) * cos ( $b ) * $ny ;
157 $ty = cos ( $b ) * cos ( $b ) * $ny ;
158 $coords [ 2 ] = - $tx ; $coords [ 3 ] = 1 - $ty ;
160 else if ( $angle <= 270 ) {
161 if ( $angle <= 225 ) { $endy
= tan ( deg2rad ( $angle
- 180 )); }
162 else { $endx
= tan ( deg2rad ( 270 - $angle
)); }
163 $b = atan2 (( $endy * $bboxh ), ( $endx * $bboxw ));
164 $ny = $coords [ 1 ] - ( tan ( $b ) * ( $coords [ 0 ]));
165 $tx = sin ( $b ) * cos ( $b ) * $ny ;
166 $ty = cos ( $b ) * cos ( $b ) * $ny ;
167 $coords [ 2 ] = - $tx ; $coords [ 3 ] = $ty ;
170 if ( $angle <= 315 ) { $endx
= tan ( deg2rad ( $angle
- 270 )); }
171 else { $endy
= tan ( deg2rad ( 360 - $angle
)); }
172 $b = atan2 (( $endy * $bboxh ), ( $endx * $bboxw ));
173 $ny = $coords [ 1 ] - ( tan ( $b ) * ( 1 - $coords [ 0 ]));
174 $tx = sin ( $b ) * cos ( $b ) * $ny ;
175 $ty = cos ( $b ) * cos ( $b ) * $ny ;
176 $coords [ 2 ] = 1 +
$tx ; $coords [ 3 ] = $ty ;
182 // -moz If the first parameter is only an <angle>, the gradient axis starts from the box's corner that would ensure the
183 // axis goes through the box. The axis runs along the specified angle. The end point of the axis is defined such that the
184 // farthest corner of the box from the starting point is perpendicular to the gradient axis at that point.
185 // NO end points or Start points (Angle defined)
186 else if ( $angle !== false && $coords [ 0 ]=== false && $coords [ 1 ]=== false ) {
187 if ( $angle == 0 || $angle == 360 ) { $coords
[ 0 ]= 0 ; $coords
[ 1 ]= 0 ; $coords
[ 2 ]= 1 ; $coords
[ 3 ]= 0 ; }
188 else if ( $angle == 90 ) { $coords
[ 0 ]= 0 ; $coords
[ 1 ]= 0 ; $coords
[ 2 ]= 0 ; $coords
[ 3 ]= 1 ; }
189 else if ( $angle == 180 ) { $coords
[ 0 ]= 1 ; $coords
[ 1 ]= 0 ; $coords
[ 2 ]= 0 ; $coords
[ 3 ]= 0 ; }
190 else if ( $angle == 270 ) { $coords
[ 0 ]= 0 ; $coords
[ 1 ]= 1 ; $coords
[ 2 ]= 0 ; $coords
[ 3 ]= 0 ; }
193 $coords [ 0 ]= 0 ; $coords [ 1 ]= 0 ;
194 if ( $angle <= 45 ) { $endx
= 1 ; $endy
= tan ( deg2rad ( $angle
)); }
195 else { $endx
= tan ( deg2rad ( 90 - $angle
)); $endy
= 1 ; }
197 else if ( $angle <= 180 ) {
198 $coords [ 0 ]= 1 ; $coords [ 1 ]= 0 ;
199 if ( $angle <= 135 ) { $endx
= tan ( deg2rad ( $angle
- 90 )); $endy
= 1 ; }
200 else { $endx
= 1 ; $endy
= tan ( deg2rad ( 180 - $angle
)); }
202 else if ( $angle <= 270 ) {
203 $coords [ 0 ]= 1 ; $coords [ 1 ]= 1 ;
204 if ( $angle <= 225 ) { $endx
= 1 ; $endy
= tan ( deg2rad ( $angle
- 180 )); }
205 else { $endx
= tan ( deg2rad ( 270 - $angle
)); $endy
= 1 ; }
208 $coords [ 0 ]= 0 ; $coords [ 1 ]= 1 ;
209 if ( $angle <= 315 ) { $endx
= tan ( deg2rad ( $angle
- 270 )); $endy
= 1 ; }
210 else { $endx
= 1 ; $endy
= tan ( deg2rad ( 360 - $angle
)); }
212 $b = atan2 (( $endy * $bboxh ), ( $endx * $bboxw ));
213 $h2 = $bboxh - ( $bboxh * tan ( $b ));
214 $px = $bboxh +
( $h2 * sin ( $b ) * cos ( $b ));
215 $py = ( $bboxh * tan ( $b )) +
( $h2 * sin ( $b ) * sin ( $b ));
218 if ( $angle <= 90 ) { $coords
[ 2 ] = $x1
; $coords
[ 3 ] = $y1
; }
219 else if ( $angle <= 180 ) { $coords
[ 2 ] = 1 - $x1
; $coords
[ 3 ] = $y1
; }
220 else if ( $angle <= 270 ) { $coords
[ 2 ] = 1 - $x1
; $coords
[ 3 ] = 1 - $y1
; }
221 else { $coords
[ 2 ] = $x1
; $coords
[ 3 ] = 1 - $y1
; }
224 // -moz If the first parameter to the gradient function is only a <point>, the gradient axis starts from the specified point,
225 // and ends at the point you would get if you rotated the starting point by 180 degrees about the center of the box that the
226 // gradient is to be applied to.
227 // NO angle and NO end points (Start points defined)
228 else if ((! isset ( $angle ) || $angle === false ) && $coords [ 0 ]!== false && $coords [ 1 ]!== false ) { // should have start and end defined
229 $coords [ 2 ] = 1 - $coords [ 0 ]; $coords [ 3 ] = 1 - $coords [ 1 ];
230 $angle = rad2deg ( atan2 ( $coords [ 3 ]- $coords [ 1 ], $coords [ 2 ]- $coords [ 0 ]));
231 if ( $angle < 0 ) { $angle +
= 360 ; }
232 else if ( $angle > 360 ) { $angle
-= 360 ; }
233 if ( $angle != 0 && $angle != 360 && $angle != 90 && $angle != 180 && $angle != 270 ) {
235 $coords [ 1 ] *= $h / $w ;
236 $coords [ 3 ] *= $h / $w ;
237 $usew = $useh = $bboxw ;
241 $coords [ 0 ] *= $w / $h ;
242 $coords [ 2 ] *= $w / $h ;
243 $usew = $useh = $bboxh ;
248 // -moz If neither a <point> or <angle> is specified, i.e. the entire function consists of only <stop> values, the gradient
249 // axis starts from the top of the box and runs vertically downwards, ending at the bottom of the box.
250 else { // default values T2B
251 // All values are set in parseMozGradient - so won't appear here
252 $coords = array ( 0 , 0 , 1 , 0 ); // default for original linear gradient (L2R)
255 $s .= sprintf ( ' %.3F %.3F %.3F %.3F re W n' , $x * _MPDFK
, ( $this- > mpdf
-> h
- $y )* _MPDFK
, $w * _MPDFK
, - $h * _MPDFK
). " \n " ;
256 $s .= sprintf ( ' %.3F 0 0 %.3F %.3F %.3F cm' , $usew * _MPDFK
, $useh * _MPDFK
, $usex * _MPDFK
, ( $this- > mpdf
-> h
-( $usey +
$useh ))* _MPDFK
). " \n " ;
260 else if ( $type == 3 ) {
261 $radius = $coords [ 4 ];
262 $angle = $coords [ 5 ]; // ?? no effect
265 $repeat = $coords [ 8 ];
266 // ALL POINTS AND RADIUS SET (default for custom mPDF radial gradient) - no -moz
267 if ( $coords [ 0 ]!== false && $coords [ 1 ]!== false && $coords [ 2 ]!== false && $coords [ 3 ]!== false && $coords [ 4 ]!== false ) {
268 // do nothing - coords used as they are
270 // If a <point> is defined
271 else if ( $shape !== false && $size !== false ) {
272 if ( $coords [ 2 ]== false ) { $coords
[ 2 ] = $coords
[ 0 ]; }
273 if ( $coords [ 3 ]== false ) { $coords
[ 3 ] = $coords
[ 1 ]; }
275 if ( $shape == 'ellipse' ) {
276 $corner1 = sqrt ( pow ( $coords [ 0 ], 2 ) +
pow ( $coords [ 1 ], 2 ));
277 $corner2 = sqrt ( pow ( $coords [ 0 ], 2 ) +
pow (( 1 - $coords [ 1 ]), 2 ));
278 $corner3 = sqrt ( pow (( 1 - $coords [ 0 ]), 2 ) +
pow ( $coords [ 1 ], 2 ));
279 $corner4 = sqrt ( pow (( 1 - $coords [ 0 ]), 2 ) +
pow (( 1 - $coords [ 1 ]), 2 ));
280 if ( $size == 'closest-side' ) { $radius
= min ( $coords
[ 0 ], $coords
[ 1 ], ( 1 - $coords
[ 0 ]), ( 1 - $coords
[ 1 ])); }
281 else if ( $size == 'closest-corner' ) { $radius
= min ( $corner1
, $corner2
, $corner3
, $corner4
); }
282 else if ( $size == 'farthest-side' ) { $radius
= max ( $coords
[ 0 ], $coords
[ 1 ], ( 1 - $coords
[ 0 ]), ( 1 - $coords
[ 1 ])); }
283 else { $radius
= max ( $corner1
, $corner2
, $corner3
, $corner4
); } // farthest corner (default)
286 else if ( $shape == 'circle' ) {
288 $coords [ 1 ] = $coords [ 3 ] = ( $coords [ 1 ] * $h / $w ) ;
289 $corner1 = sqrt ( pow ( $coords [ 0 ], 2 ) +
pow ( $coords [ 1 ], 2 ));
290 $corner2 = sqrt ( pow ( $coords [ 0 ], 2 ) +
pow ((( $h / $w )- $coords [ 1 ]), 2 ));
291 $corner3 = sqrt ( pow (( 1 - $coords [ 0 ]), 2 ) +
pow ( $coords [ 1 ], 2 ));
292 $corner4 = sqrt ( pow (( 1 - $coords [ 0 ]), 2 ) +
pow ((( $h / $w )- $coords [ 1 ]), 2 ));
293 if ( $size == 'closest-side' ) { $radius
= min ( $coords
[ 0 ], $coords
[ 1 ], ( 1 - $coords
[ 0 ]), (( $h
/ $w
)- $coords
[ 1 ])); }
294 else if ( $size == 'closest-corner' ) { $radius
= min ( $corner1
, $corner2
, $corner3
, $corner4
); }
295 else if ( $size == 'farthest-side' ) { $radius
= max ( $coords
[ 0 ], $coords
[ 1 ], ( 1 - $coords
[ 0 ]), (( $h
/ $w
)- $coords
[ 1 ])); }
296 else if ( $size == 'farthest-corner' ) { $radius
= max ( $corner1
, $corner2
, $corner3
, $corner4
); } // farthest corner (default)
297 $usew = $useh = $bboxw ;
301 $coords [ 0 ] = $coords [ 2 ] = ( $coords [ 0 ] * $w / $h ) ;
302 $corner1 = sqrt ( pow ( $coords [ 0 ], 2 ) +
pow ( $coords [ 1 ], 2 ));
303 $corner2 = sqrt ( pow ( $coords [ 0 ], 2 ) +
pow (( 1 - $coords [ 1 ]), 2 ));
304 $corner3 = sqrt ( pow ((( $w / $h )- $coords [ 0 ]), 2 ) +
pow ( $coords [ 1 ], 2 ));
305 $corner4 = sqrt ( pow ((( $w / $h )- $coords [ 0 ]), 2 ) +
pow (( 1 - $coords [ 1 ]), 2 ));
306 if ( $size == 'closest-side' ) { $radius
= min ( $coords
[ 0 ], $coords
[ 1 ], (( $w
/ $h
)- $coords
[ 0 ]), ( 1 - $coords
[ 1 ])); }
307 else if ( $size == 'closest-corner' ) { $radius
= min ( $corner1
, $corner2
, $corner3
, $corner4
); }
308 else if ( $size == 'farthest-side' ) { $radius
= max ( $coords
[ 0 ], $coords
[ 1 ], (( $w
/ $h
)- $coords
[ 0 ]), ( 1 - $coords
[ 1 ])); }
309 else if ( $size == 'farthest-corner' ) { $radius
= max ( $corner1
, $corner2
, $corner3
, $corner4
); } // farthest corner (default)
310 $usew = $useh = $bboxh ;
313 if ( $radius == 0 ) { $radius
= 0.001 ; } // to prevent error
314 $coords [ 4 ] = $radius ;
317 // -moz If entire function consists of only <stop> values
318 else { // default values
319 // All values are set in parseMozGradient - so won't appear here
320 $coords = array ( 0.5 , 0.5 , 0.5 , 0.5 ); // default for radial gradient (centred)
323 $s .= sprintf ( ' %.3F %.3F %.3F %.3F re W n' , $x * _MPDFK
, ( $this- > mpdf
-> h
- $y )* _MPDFK
, $w * _MPDFK
, - $h * _MPDFK
). " \n " ;
324 $s .= sprintf ( ' %.3F 0 0 %.3F %.3F %.3F cm' , $usew * _MPDFK
, $useh * _MPDFK
, $usex * _MPDFK
, ( $this- > mpdf
-> h
-( $usey +
$useh ))* _MPDFK
). " \n " ;
327 $n = count ( $this- > mpdf
-> gradients
) +
1 ;
328 $this- > mpdf
-> gradients
[ $n ][ 'type' ] = $type ;
329 $this- > mpdf
-> gradients
[ $n ][ 'colorspace' ] = $colorspace ;
331 $this- > mpdf
-> gradients
[ $n ][ 'is_mask' ] = $is_mask ;
332 if ( $is_mask ) { $trans
= true ; }
333 if ( count ( $stops ) == 1 ) { $stops
[ 1 ] = $stops
[ 0 ]; }
334 if (! isset ( $stops [ 0 ][ 'offset' ])) { $stops
[ 0 ][ 'offset' ] = 0 ; }
335 if (! isset ( $stops [( count ( $stops )- 1 )][ 'offset' ])) { $stops
[( count ( $stops
)- 1 )][ 'offset' ] = 1 ; }
337 // Fix stop-offsets set as absolute lengths
339 $axisx = ( $coords [ 2 ]- $coords [ 0 ])* $usew ;
340 $axisy = ( $coords [ 3 ]- $coords [ 1 ])* $useh ;
341 $axis_length = sqrt ( pow ( $axisx , 2 ) +
pow ( $axisy , 2 ));
343 else { $axis_length
= $coords
[ 4 ]* $usew
; } // Absolute lengths are meaningless for an ellipse - Firefox uses Width as reference
345 for ( $i = 0 ; $i < count ( $stops ); $i ++
) {
346 if ( isset ( $stops [ $i ][ 'offset' ]) && preg_match ( '/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i' , $stops [ $i ][ 'offset' ], $m )) {
347 $tmp = $this- > mpdf
-> ConvertSize ( $m [ 1 ], $this- > mpdf
-> w
, $this- > mpdf
-> FontSize
, false );
348 $stops [ $i ][ 'offset' ] = $tmp / $axis_length ;
353 if ( isset ( $stops [ 0 ][ 'offset' ]) && $stops [ 0 ][ 'offset' ]> 0 ) {
354 $firststop = $stops [ 0 ];
355 $firststop [ 'offset' ] = 0 ;
356 array_unshift ( $stops , $firststop );
358 if (! $repeat && isset ( $stops [( count ( $stops )- 1 )][ 'offset' ]) && $stops [( count ( $stops )- 1 )][ 'offset' ]< 1 ) {
359 $endstop = $stops [( count ( $stops )- 1 )];
360 $endstop [ 'offset' ] = 1 ;
363 if ( $stops [ 0 ][ 'offset' ] > $stops [( count ( $stops )- 1 )][ 'offset' ]) {
364 $stops [ 0 ][ 'offset' ] = 0 ;
365 $stops [( count ( $stops )- 1 )][ 'offset' ] = 1 ;
368 for ( $i = 0 ; $i < count ( $stops ); $i ++
) {
370 if ( $colorspace == 'CMYK' ) {
371 $this- > mpdf
-> gradients
[ $n ][ 'stops' ][ $i ][ 'col' ] = sprintf ( '%.3F %.3F %.3F %.3F' , ( ord ( $stops [ $i ][ 'col' ]{ 1 })/ 100 ), ( ord ( $stops [ $i ][ 'col' ]{ 2 })/ 100 ), ( ord ( $stops [ $i ][ 'col' ]{ 3 })/ 100 ), ( ord ( $stops [ $i ][ 'col' ]{ 4 })/ 100 ));
373 else if ( $colorspace == 'Gray' ) {
374 $this- > mpdf
-> gradients
[ $n ][ 'stops' ][ $i ][ 'col' ] = sprintf ( '%.3F' , ( ord ( $stops [ $i ][ 'col' ]{ 1 })/ 255 ));
377 $this- > mpdf
-> gradients
[ $n ][ 'stops' ][ $i ][ 'col' ] = sprintf ( '%.3F %.3F %.3F' , ( ord ( $stops [ $i ][ 'col' ]{ 1 })/ 255 ), ( ord ( $stops [ $i ][ 'col' ]{ 2 })/ 255 ), ( ord ( $stops [ $i ][ 'col' ]{ 3 })/ 255 ));
379 if (! isset ( $stops [ $i ][ 'opacity' ])) { $stops
[ $i
][ 'opacity' ] = 1 ; }
380 else if ( $stops [ $i ][ 'opacity' ] > 1 || $stops [ $i ][ 'opacity' ] < 0 ) { $stops
[ $i
][ 'opacity' ] = 1 ; }
381 else if ( $stops [ $i ][ 'opacity' ] < 1 ) {
384 $this- > mpdf
-> gradients
[ $n ][ 'stops' ][ $i ][ 'opacity' ] = $stops [ $i ][ 'opacity' ];
386 if ( $i > 0 && $i <( count ( $stops )- 1 )) {
387 if (! isset ( $stops [ $i ][ 'offset' ]) || ( isset ( $stops [ $i +
1 ][ 'offset' ]) && $stops [ $i ][ 'offset' ]> $stops [ $i +
1 ][ 'offset' ]) || $stops [ $i ][ 'offset' ]< $stops [ $i-1 ][ 'offset' ]) {
388 if ( isset ( $stops [ $i-1 ][ 'offset' ]) && isset ( $stops [ $i +
1 ][ 'offset' ])) {
389 $stops [ $i ][ 'offset' ] = ( $stops [ $i-1 ][ 'offset' ] +
$stops [ $i +
1 ][ 'offset' ])/ 2 ;
392 for ( $j =( $i +
1 ); $j < count ( $stops ); $j ++
) {
393 if ( isset ( $stops [ $j ][ 'offset' ])) { break ; }
395 $int = ( $stops [ $j ][ 'offset' ] - $stops [( $i-1 )][ 'offset' ])/( $j-$i +
1 );
396 for ( $f = 0 ; $f <( $j-$i-1 ); $f ++
) {
397 $stops [( $i +
$f )][ 'offset' ] = $stops [( $i +
$f-1 )][ 'offset' ] +
( $int );
402 $this- > mpdf
-> gradients
[ $n ][ 'stops' ][ $i ][ 'offset' ] = $stops [ $i ][ 'offset' ];
403 $this- > mpdf
-> gradients
[ $n ][ 'stops' ][ $i ][ 'offset' ] = $stops [ $i ][ 'offset' ];
407 $ns = count ( $this- > mpdf
-> gradients
[ $n ][ 'stops' ]);
409 for ( $i = 0 ; $i < $ns ; $i ++
) {
410 $offs [ $i ] = $this- > mpdf
-> gradients
[ $n ][ 'stops' ][ $i ][ 'offset' ];
416 for ( $i = 0 ; $i < $ns ; $i ++
) {
417 $this- > mpdf
-> gradients
[ $n ][ 'stops' ][(( $ns * $gp ) +
$i )] = $this- > mpdf
-> gradients
[ $n ][ 'stops' ][(( $ns *( $gp-1 )) +
$i )];
418 $tmp = $this- > mpdf
-> gradients
[ $n ][ 'stops' ][(( $ns *( $gp-1 )) +
( $ns-1 ))][ 'offset' ] +
$offs [ $i ] ;
419 if ( $tmp < 1 ) { $this
-> mpdf
-> gradients
[ $n
][ 'stops' ][(( $ns
* $gp
) +$i
)][ 'offset' ] = $tmp
; }
421 $this- > mpdf
-> gradients
[ $n ][ 'stops' ][(( $ns * $gp ) +
$i )][ 'offset' ] = 1 ;
430 $this- > mpdf
-> gradients
[ $n ][ 'trans' ] = true ;
431 $s .= ' /TGS' . $n . ' gs ' ;
433 if (! is_array ( $extend ) || count ( $extend ) < 1 ) {
434 $extend = array ( 'true' , 'true' ); // These are supposed to be quoted - appear in PDF file as text
436 $this- > mpdf
-> gradients
[ $n ][ 'coords' ] = $coords ;
437 $this- > mpdf
-> gradients
[ $n ][ 'extend' ] = $extend ;
439 $s .= '/Sh' . $n . ' sh ' . " \n " ;
440 //restore previous Graphic State
442 if ( $return ) { return $s
; }
443 else { $this
-> mpdf
-> _out ( $s
); }
447 function parseMozGradient ( $bg ) {
448 // background[-image]: -moz-linear-gradient(left, #c7Fdde 20%, #FF0000 );
449 // background[-image]: linear-gradient(left, #c7Fdde 20%, #FF0000 ); // CSS3
450 if ( preg_match ( '/repeating-/' , $bg )) { $repeat
= true ; }
451 else { $repeat
= false ; }
452 if ( preg_match ( '/linear-gradient\((.*)\)/' , $bg , $m )) {
455 $g [ 'colorspace' ] = 'RGB' ;
456 $g [ 'extend' ] = array ( 'true' , 'true' );
458 // Change commas inside e.g. rgb(x,x,x)
459 while ( preg_match ( '/(\([^\)]*?),/' , $v )) { $v
= preg_replace ( '/(\([^\)]*?),/' , ' \\ 1@' , $v
); }
460 // Remove spaces inside e.g. rgb(x, x, x)
461 while ( preg_match ( '/(\([^\)]*?)[ ]/' , $v )) { $v
= preg_replace ( '/(\([^\)]*?)[ ]/' , ' \\ 1' , $v
); }
462 $bgr = preg_split ( '/\s*,\s*/' , $v );
463 for ( $i = 0 ; $i < count ( $bgr ); $i ++
) { $bgr
[ $i
] = preg_replace ( '/@/' , ',' , $bgr
[ $i
]); }
464 // Is first part $bgr[0] a valid point/angle?
465 $first = preg_split ( '/\s+/' , trim ( $bgr [ 0 ]));
466 if ( preg_match ( '/(left|center|right|bottom|top|deg|grad|rad)/i' , $bgr [ 0 ]) && ! preg_match ( '/(<#|rgb|rgba|hsl|hsla)/i' , $bgr [ 0 ])) {
469 else if ( trim ( $first [( count ( $first )- 1 )]) === "0" ) {
473 $check = $this- > mpdf
-> ConvertColor ( $first [ 0 ]);
474 if ( $check ) $startStops = 0 ;
475 else $startStops = 1 ;
477 // first part a valid point/angle?
478 if ( $startStops == 1 ) { // default values
479 // [<point> || <angle>,] = [<% em px left center right bottom top> || <deg grad rad 0>,]
480 if ( preg_match ( '/([\-]*[0-9\.]+)(deg|grad|rad)/i' , $bgr [ 0 ], $m )) {
482 if ( strtolower ( $m [ 2 ])== 'deg' ) { $angle
= $angle
; }
483 else if ( strtolower ( $m [ 2 ])== 'grad' ) { $angle
*= ( 360 / 400 ); }
484 else if ( strtolower ( $m [ 2 ])== 'rad' ) { $angle
= rad2deg ( $angle
); }
485 while ( $angle < 0 ) { $angle +
= 360 ; }
486 $angle = ( $angle %
360 );
488 else if ( trim ( $first [( count ( $first )- 1 )]) === "0" ) { $angle
= 0 ; }
489 if ( preg_match ( '/left/i' , $bgr [ 0 ])) { $startx
= 0 ; }
490 else if ( preg_match ( '/right/i' , $bgr [ 0 ])) { $startx
= 1 ; }
491 if ( preg_match ( '/top/i' , $bgr [ 0 ])) { $starty
= 1 ; }
492 else if ( preg_match ( '/bottom/i' , $bgr [ 0 ])) { $starty
= 0 ; }
493 // Check for %? ?% or %%
494 if ( preg_match ( '/(\d+)[%]/i' , $first [ 0 ], $m )) { $startx
= $m
[ 1 ]/ 100 ; }
495 else if (! isset ( $startx ) && preg_match ( '/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i' , $first [ 0 ], $m )) {
496 $tmp = $this- > mpdf
-> ConvertSize ( $m [ 1 ], $this- > mpdf
-> w
, $this- > mpdf
-> FontSize
, false );
497 if ( $tmp ) { $startx
= $m
[ 1 ]; }
499 if ( isset ( $first [ 1 ]) && preg_match ( '/(\d+)[%]/i' , $first [ 1 ], $m )) { $starty
= 1 - ( $m
[ 1 ]/ 100 ); }
500 else if (! isset ( $starty ) && preg_match ( '/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i' , $first [ 1 ], $m )) {
501 $tmp = $this- > mpdf
-> ConvertSize ( $m [ 1 ], $this- > mpdf
-> w
, $this- > mpdf
-> FontSize
, false );
502 if ( $tmp ) { $starty
= $m
[ 1 ]; }
504 if ( isset ( $startx ) && ! isset ( $starty )) { $starty
= 0.5 ; }
505 if (! isset ( $startx ) && isset ( $starty )) { $startx
= 0.5 ; }
508 // If neither a <point> or <angle> is specified, i.e. the entire function consists of only <stop> values, the gradient axis starts from the top of the box and runs vertically downwards, ending at the bottom of the box.
509 else { // default values T2B
510 $starty = 1 ; $startx = 0.5 ;
511 $endy = 0 ; $endx = 0.5 ;
514 if (! isset ( $startx )) { $startx
= false ; }
515 if (! isset ( $starty )) { $starty
= false ; }
516 if (! isset ( $endx )) { $endx
= false ; }
517 if (! isset ( $endy )) { $endy
= false ; }
518 if (! isset ( $angle )) { $angle
= false ; }
519 $g [ 'coords' ] = array ( $startx , $starty , $endx , $endy , $angle , $repeat );
520 $g [ 'stops' ] = array ();
521 for ( $i = $startStops ; $i < count ( $bgr ); $i ++
) {
524 $el = preg_split ( '/\s+/' , trim ( $bgr [ $i ]));
526 $col = $this- > mpdf
-> ConvertColor ( $el [ 0 ]);
527 if ( $col ) { $stop
[ 'col' ] = $col
; }
528 else { $stop
[ 'col' ] = $col
= $this
-> mpdf
-> ConvertColor ( 255 ); }
529 if ( $col{ 0 }== 1 ) $g [ 'colorspace' ] = 'Gray' ;
530 else if ( $col{ 0 }== 4 || $col{ 0 }== 6 ) $g [ 'colorspace' ] = 'CMYK' ;
531 if ( $col{ 0 }== 5 ) { $stop
[ 'opacity' ] = ord ( $col
{ 4 })/ 100 ; } // transparency from rgba()
532 else if ( $col{ 0 }== 6 ) { $stop
[ 'opacity' ] = ord ( $col
{ 5 })/ 100 ; } // transparency from cmyka()
533 else if ( $col{ 0 }== 1 && $col{ 2 }== 1 ) { $stop
[ 'opacity' ] = ord ( $col
{ 3 })/ 100 ; } // transparency converted from rgba or cmyka()
535 if ( isset ( $el [ 1 ]) && preg_match ( '/(\d+)[%]/' , $el [ 1 ], $m )) {
536 $stop [ 'offset' ] = $m [ 1 ]/ 100 ;
537 if ( $stop [ 'offset' ]> 1 ) { unset ( $stop
[ 'offset' ]); }
539 else if ( isset ( $el [ 1 ]) && preg_match ( '/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i' , $el [ 1 ], $m )) {
540 $tmp = $this- > mpdf
-> ConvertSize ( $m [ 1 ], $this- > mpdf
-> w
, $this- > mpdf
-> FontSize
, false );
541 if ( $tmp ) { $stop
[ 'offset' ] = $m
[ 1 ]; }
543 $g [ 'stops' ][] = $stop ;
545 if ( count ( $g [ 'stops' ] )) { return $g
; }
547 else if ( preg_match ( '/radial-gradient\((.*)\)/' , $bg , $m )) {
550 $g [ 'colorspace' ] = 'RGB' ;
551 $g [ 'extend' ] = array ( 'true' , 'true' );
553 // Change commas inside e.g. rgb(x,x,x)
554 while ( preg_match ( '/(\([^\)]*?),/' , $v )) { $v
= preg_replace ( '/(\([^\)]*?),/' , ' \\ 1@' , $v
); }
555 // Remove spaces inside e.g. rgb(x, x, x)
556 while ( preg_match ( '/(\([^\)]*?)[ ]/' , $v )) { $v
= preg_replace ( '/(\([^\)]*?)[ ]/' , ' \\ 1' , $v
); }
557 $bgr = preg_split ( '/\s*,\s*/' , $v );
558 for ( $i = 0 ; $i < count ( $bgr ); $i ++
) { $bgr
[ $i
] = preg_replace ( '/@/' , ',' , $bgr
[ $i
]); }
560 // Is first part $bgr[0] a valid point/angle?
564 $first = preg_split ( '/\s+/' , trim ( $bgr [ 0 ]));
565 $checkCol = $this- > mpdf
-> ConvertColor ( $first [ 0 ]);
566 if ( preg_match ( '/(left|center|right|bottom|top|deg|grad|rad)/i' , $bgr [ 0 ]) && ! preg_match ( '/(<#|rgb|rgba|hsl|hsla)/i' , $bgr [ 0 ])) {
568 $pos_angle = $bgr [ 0 ];
570 else if ( trim ( $first [( count ( $first )- 1 )]) === "0" ) {
572 $pos_angle = $bgr [ 0 ];
574 else if ( preg_match ( '/(circle|ellipse|closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i' , $bgr [ 0 ])) {
576 $shape_size = $bgr [ 0 ];
578 else if (! $checkCol ) {
580 $pos_angle = $bgr [ 0 ];
582 if ( preg_match ( '/(circle|ellipse|closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i' , $bgr [ 1 ])) {
584 $shape_size = $bgr [ 1 ];
587 // If valid point/angle?
588 if ( $pos_angle ) { // default values
589 // [<point> || <angle>,] = [<% em px left center right bottom top> || <deg grad rad 0>,]
590 if ( preg_match ( '/left/i' , $pos_angle )) { $startx
= 0 ; }
591 else if ( preg_match ( '/right/i' , $pos_angle )) { $startx
= 1 ; }
592 if ( preg_match ( '/top/i' , $pos_angle )) { $starty
= 1 ; }
593 else if ( preg_match ( '/bottom/i' , $pos_angle )) { $starty
= 0 ; }
594 // Check for %? ?% or %%
595 if ( preg_match ( '/(\d+)[%]/i' , $first [ 0 ], $m )) { $startx
= $m
[ 1 ]/ 100 ; }
596 else if (! isset ( $startx ) && preg_match ( '/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i' , $first [ 0 ], $m )) {
597 $tmp = $this- > mpdf
-> ConvertSize ( $m [ 1 ], $this- > mpdf
-> w
, $this- > mpdf
-> FontSize
, false );
598 if ( $tmp ) { $startx
= $m
[ 1 ]; }
600 if ( isset ( $first [ 1 ]) && preg_match ( '/(\d+)[%]/i' , $first [ 1 ], $m )) { $starty
= 1 - ( $m
[ 1 ]/ 100 ); }
601 else if (! isset ( $starty ) && preg_match ( '/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i' , $first [ 1 ], $m )) {
602 $tmp = $this- > mpdf
-> ConvertSize ( $m [ 1 ], $this- > mpdf
-> w
, $this- > mpdf
-> FontSize
, false );
603 if ( $tmp ) { $starty
= $m
[ 1 ]; }
607 // ?? Angle has no effect in radial gradient (does not exist in CSS3 spec.)
608 if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$pos_angle,$m)) {
610 if (strtolower($m[2])=='deg') { $angle = $angle; }
611 else if (strtolower($m[2])=='grad') { $angle *= (360/400); }
612 else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); }
613 while($angle < 0) { $angle += 360; }
614 $angle = ($angle % 360);
617 if (! isset ( $starty )) { $starty
= 0.5 ; }
618 if (! isset ( $startx )) { $startx
= 0.5 ; }
621 // If neither a <point> or <angle> is specified, i.e. the entire function consists of only <stop> values, the gradient axis starts from the top of the box and runs vertically downwards, ending at the bottom of the box.
622 else { // default values Center
623 $starty = 0.5 ; $startx = 0.5 ;
624 $endy = 0.5 ; $endx = 0.5 ;
627 // If valid shape/size?
628 $shape = 'ellipse' ; // default
629 $size = 'farthest-corner' ; // default
630 if ( $shape_size ) { // default values
631 if ( preg_match ( '/(circle|ellipse)/i' , $shape_size , $m )) {
634 if ( preg_match ( '/(closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i' , $shape_size , $m )) {
636 if ( $size == 'contain' ) { $size
= 'closest-side' ; }
637 else if ( $size == 'cover' ) { $size
= 'farthest-corner' ; }
642 if (! isset ( $startx )) { $startx
= false ; }
643 if (! isset ( $starty )) { $starty
= false ; }
644 if (! isset ( $endx )) { $endx
= false ; }
645 if (! isset ( $endy )) { $endy
= false ; }
646 if (! isset ( $radius )) { $radius
= false ; }
647 if (! isset ( $angle )) { $angle
= 0 ; }
648 $g [ 'coords' ] = array ( $startx , $starty , $endx , $endy , $radius , $angle , $shape , $size , $repeat );
650 $g [ 'stops' ] = array ();
651 for ( $i = $startStops ; $i < count ( $bgr ); $i ++
) {
654 $el = preg_split ( '/\s+/' , trim ( $bgr [ $i ]));
656 $col = $this- > mpdf
-> ConvertColor ( $el [ 0 ]);
657 if ( $col ) { $stop
[ 'col' ] = $col
; }
658 else { $stop
[ 'col' ] = $col
= $this
-> mpdf
-> ConvertColor ( 255 ); }
659 if ( $col{ 0 }== 1 ) $g [ 'colorspace' ] = 'Gray' ;
660 else if ( $col{ 0 }== 4 || $col{ 0 }== 6 ) $g [ 'colorspace' ] = 'CMYK' ;
661 if ( $col{ 0 }== 5 ) { $stop
[ 'opacity' ] = ord ( $col
{ 4 })/ 100 ; } // transparency from rgba()
662 else if ( $col{ 0 }== 6 ) { $stop
[ 'opacity' ] = ord ( $col
{ 5 })/ 100 ; } // transparency from cmyka()
663 else if ( $col{ 0 }== 1 && $col{ 2 }== 1 ) { $stop
[ 'opacity' ] = ord ( $col
{ 3 })/ 100 ; } // transparency converted from rgba or cmyka()
665 if ( isset ( $el [ 1 ]) && preg_match ( '/(\d+)[%]/' , $el [ 1 ], $m )) {
666 $stop [ 'offset' ] = $m [ 1 ]/ 100 ;
667 if ( $stop [ 'offset' ]> 1 ) { unset ( $stop
[ 'offset' ]); }
669 else if ( isset ( $el [ 1 ]) && preg_match ( '/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i' , $el [ 1 ], $m )) {
670 $tmp = $this- > mpdf
-> ConvertSize ( $m [ 1 ], $this- > mpdf
-> w
, $this- > mpdf
-> FontSize
, false );
671 $stop [ 'offset' ] = $el [ 1 ];
673 $g [ 'stops' ][] = $stop ;
675 if ( count ( $g [ 'stops' ] )) { return $g
; }
680 function parseBackgroundGradient ( $bg ) {
681 // background-gradient: linear #00FFFF #FFFF00 0 0.5 1 0.5; or
682 // background-gradient: radial #00FFFF #FFFF00 0.5 0.5 1 1 1.2;
685 $bgr = preg_split ( '/\s+/' , $v );
687 if ( count ( $bgr )> 6 ) {
688 if ( strtoupper ( substr ( $bgr [ 0 ], 0 , 1 )) == 'L' && count ( $bgr )== 7 ) { // linear
690 //$coords = array(0,0,1,1 ); // 0 0 1 0 or 0 1 1 1 is L 2 R; 1,1,0,1 is R2L; 1,1,1,0 is T2B; 1,0,1,1 is B2T
691 // Linear: $coords - array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg).
692 // The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
693 $g [ 'coords' ] = array ( $bgr [ 3 ], $bgr [ 4 ], $bgr [ 5 ], $bgr [ 6 ]);
695 else if ( count ( $bgr )== 8 ) { // radial
697 // Radial: $coords - array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1,
698 // (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg).
699 // (fx, fy) should be inside the circle, otherwise some areas will not be defined
700 $g [ 'coords' ] = array ( $bgr [ 3 ], $bgr [ 4 ], $bgr [ 5 ], $bgr [ 6 ], $bgr [ 7 ]);
702 $g [ 'colorspace' ] = 'RGB' ;
704 $cor = $this- > mpdf
-> ConvertColor ( $bgr [ 1 ]);
705 if ( $cor{ 0 }== 1 ) $g [ 'colorspace' ] = 'Gray' ;
706 else if ( $cor{ 0 }== 4 || $cor{ 0 }== 6 ) $g [ 'colorspace' ] = 'CMYK' ;
707 if ( $cor ) { $g
[ 'col' ] = $cor
; }
708 else { $g
[ 'col' ] = $this
-> mpdf
-> ConvertColor ( 255 ); }
709 $cor = $this- > mpdf
-> ConvertColor ( $bgr [ 2 ]);
710 if ( $cor ) { $g
[ 'col2' ] = $cor
; }
711 else { $g
[ 'col2' ] = $this
-> mpdf
-> ConvertColor ( 255 ); }
712 $g [ 'extend' ] = array ( 'true' , 'true' );
713 $g [ 'stops' ] = array ( array ( 'col' => $g [ 'col' ], 'opacity' => 1 , 'offset' => 0 ), array ( 'col' => $g [ 'col2' ], 'opacity' => 1 , 'offset' => 1 ));