grad.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  1. <?php
  2. class grad
  3. {
  4. var $mpdf = null;
  5. public function __construct(mPDF $mpdf)
  6. {
  7. $this->mpdf = $mpdf;
  8. }
  9. // mPDF 5.3.A1
  10. 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)
  11. {
  12. $s = ' q ';
  13. $s.=sprintf(' %.3F %.3F %.3F %.3F re W n ', $x * _MPDFK, ($this->mpdf->h - $y) * _MPDFK, $w * _MPDFK, -$h * _MPDFK);
  14. $s.=sprintf(' %.3F 0 0 %.3F %.3F %.3F cm ', $w * _MPDFK, $h * _MPDFK, $x * _MPDFK, ($this->mpdf->h - ($y + $h)) * _MPDFK);
  15. $n = count($this->mpdf->gradients) + 1;
  16. $this->mpdf->gradients[$n]['type'] = 6; //coons patch mesh
  17. $this->mpdf->gradients[$n]['colorspace'] = $colspace; //coons patch mesh
  18. $bpcd = 65535; //16 BitsPerCoordinate
  19. $trans = false;
  20. $this->mpdf->gradients[$n]['stream'] = '';
  21. for ($i = 0; $i < count($patch_array); $i++) {
  22. $this->mpdf->gradients[$n]['stream'].=chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
  23. for ($j = 0; $j < count($patch_array[$i]['points']); $j++) {
  24. //each point as 16 bit
  25. if (($j % 2) == 1) { // Y coordinate (adjusted as input is From top left)
  26. $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $y_min) / ($y_max - $y_min)) * $bpcd;
  27. $patch_array[$i]['points'][$j] = $bpcd - $patch_array[$i]['points'][$j];
  28. } else {
  29. $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $x_min) / ($x_max - $x_min)) * $bpcd;
  30. }
  31. if ($patch_array[$i]['points'][$j] < 0)
  32. $patch_array[$i]['points'][$j] = 0;
  33. if ($patch_array[$i]['points'][$j] > $bpcd)
  34. $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));
  37. }
  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) {
  45. $trans = true;
  46. }
  47. } else if ($colspace == 'CMYK') {
  48. $this->mpdf->gradients[$n]['stream'].=chr(ord($patch_array[$i]['colors'][$j][1]) * 2.55);
  49. $this->mpdf->gradients[$n]['stream'].=chr(ord($patch_array[$i]['colors'][$j][2]) * 2.55);
  50. $this->mpdf->gradients[$n]['stream'].=chr(ord($patch_array[$i]['colors'][$j][3]) * 2.55);
  51. $this->mpdf->gradients[$n]['stream'].=chr(ord($patch_array[$i]['colors'][$j][4]) * 2.55);
  52. if (isset($patch_array[$i]['colors'][$j][5]) && ord($patch_array[$i]['colors'][$j][5]) < 100) {
  53. $trans = true;
  54. }
  55. } else if ($colspace == 'Gray') {
  56. $this->mpdf->gradients[$n]['stream'].=($patch_array[$i]['colors'][$j][1]);
  57. if ($patch_array[$i]['colors'][$j][2] == 1) {
  58. $trans = true;
  59. } // transparency converted from rgba or cmyka()
  60. }
  61. }
  62. }
  63. // TRANSPARENCY
  64. if ($trans) {
  65. $this->mpdf->gradients[$n]['stream_trans'] = '';
  66. for ($i = 0; $i < count($patch_array); $i++) {
  67. $this->mpdf->gradients[$n]['stream_trans'].=chr($patch_array[$i]['f']);
  68. for ($j = 0; $j < count($patch_array[$i]['points']); $j++) {
  69. //each point as 16 bit
  70. $this->mpdf->gradients[$n]['stream_trans'].=chr(floor($patch_array[$i]['points'][$j] / 256));
  71. $this->mpdf->gradients[$n]['stream_trans'].=chr(floor($patch_array[$i]['points'][$j] % 256));
  72. }
  73. for ($j = 0; $j < count($patch_array[$i]['colors']); $j++) {
  74. //each color component as 8 bit // OPACITY
  75. if ($colspace == 'RGB') {
  76. $this->mpdf->gradients[$n]['stream_trans'].=chr(intval(ord($patch_array[$i]['colors'][$j][4]) * 2.55));
  77. } else if ($colspace == 'CMYK') {
  78. $this->mpdf->gradients[$n]['stream_trans'].=chr(intval(ord($patch_array[$i]['colors'][$j][5]) * 2.55));
  79. } else if ($colspace == 'Gray') {
  80. $this->mpdf->gradients[$n]['stream_trans'].=chr(intval(ord($patch_array[$i]['colors'][$j][3]) * 2.55));
  81. }
  82. }
  83. }
  84. $this->mpdf->gradients[$n]['trans'] = true;
  85. $s .= ' /TGS' . $n . ' gs ';
  86. }
  87. //paint the gradient
  88. $s .= '/Sh' . $n . ' sh' . "\n";
  89. //restore previous Graphic State
  90. $s .= 'Q' . "\n";
  91. if ($return) {
  92. return $s;
  93. } else {
  94. $this->mpdf->_out($s);
  95. }
  96. }
  97. // type = linear:2; radial: 3;
  98. // Linear: $coords - array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg).
  99. // The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
  100. // Radial: $coords - array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1,
  101. // (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg).
  102. // (fx, fy) should be inside the circle, otherwise some areas will not be defined
  103. // $col = array(R,G,B/255); or array(G/255); or array(C,M,Y,K/100)
  104. // $stops = array('col'=>$col [, 'opacity'=>0-1] [, 'offset'=>0-1])
  105. function Gradient($x, $y, $w, $h, $type, $stops = array(), $colorspace = 'RGB', $coords = '', $extend = '', $return = false, $is_mask = false)
  106. {
  107. if (strtoupper(substr($type, 0, 1)) == 'L') {
  108. $type = 2;
  109. } // linear
  110. else if (strtoupper(substr($type, 0, 1)) == 'R') {
  111. $type = 3;
  112. } // radial
  113. if ($colorspace != 'CMYK' && $colorspace != 'Gray') {
  114. $colorspace = 'RGB';
  115. }
  116. $bboxw = $w;
  117. $bboxh = $h;
  118. $usex = $x;
  119. $usey = $y;
  120. $usew = $bboxw;
  121. $useh = $bboxh;
  122. if ($type < 1) {
  123. $type = 2;
  124. }
  125. if ($coords[0] !== false && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i', $coords[0], $m)) {
  126. $tmp = $this->mpdf->ConvertSize($m[1], $this->mpdf->w, $this->mpdf->FontSize, false);
  127. if ($tmp) {
  128. $coords[0] = $tmp / $w;
  129. }
  130. }
  131. if ($coords[1] !== false && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i', $coords[1], $m)) {
  132. $tmp = $this->mpdf->ConvertSize($m[1], $this->mpdf->w, $this->mpdf->FontSize, false);
  133. if ($tmp) {
  134. $coords[1] = 1 - ($tmp / $h);
  135. }
  136. }
  137. // LINEAR
  138. if ($type == 2) {
  139. $angle = (isset($coords[4]) ? $coords[4] : false);
  140. $repeat = (isset($coords[5]) ? $coords[5] : false);
  141. // ALL POINTS SET (default for custom mPDF linear gradient) - no -moz
  142. if ($coords[0] !== false && $coords[1] !== false && $coords[2] !== false && $coords[3] !== false) {
  143. // do nothing - coords used as they are
  144. }
  145. // If both a <point> and <angle> are defined, the gradient axis starts from the point and runs along the angle. The end point is
  146. // defined as before - in this case start points may not be in corners, and axis may not correctly fall in the right quadrant.
  147. // NO end points (Angle defined & Start points)
  148. else if ($angle !== false && $coords[0] !== false && $coords[1] !== false && $coords[2] === false && $coords[3] === false) {
  149. if ($angle == 0 || $angle == 360) {
  150. $coords[3] = $coords[1];
  151. if ($coords[0] == 1)
  152. $coords[2] = 2;
  153. else
  154. $coords[2] = 1;
  155. }
  156. else if ($angle == 90) {
  157. $coords[2] = $coords[0];
  158. $coords[3] = 1;
  159. if ($coords[1] == 1)
  160. $coords[3] = 2;
  161. else
  162. $coords[3] = 1;
  163. }
  164. else if ($angle == 180) {
  165. if ($coords[4] == 0)
  166. $coords[2] = -1;
  167. else
  168. $coords[2] = 0;
  169. $coords[3] = $coords[1];
  170. }
  171. else if ($angle == 270) {
  172. $coords[2] = $coords[0];
  173. if ($coords[1] == 0)
  174. $coords[3] = -1;
  175. else
  176. $coords[3] = 0;
  177. }
  178. else {
  179. $endx = 1;
  180. $endy = 1;
  181. if ($angle <= 90) {
  182. if ($angle <= 45) {
  183. $endy = tan(deg2rad($angle));
  184. } else {
  185. $endx = tan(deg2rad(90 - $angle));
  186. }
  187. $b = atan2(($endy * $bboxh), ($endx * $bboxw));
  188. $ny = 1 - $coords[1] - (tan($b) * (1 - $coords[0]));
  189. $tx = sin($b) * cos($b) * $ny;
  190. $ty = cos($b) * cos($b) * $ny;
  191. $coords[2] = 1 + $tx;
  192. $coords[3] = 1 - $ty;
  193. } else if ($angle <= 180) {
  194. if ($angle <= 135) {
  195. $endx = tan(deg2rad($angle - 90));
  196. } else {
  197. $endy = tan(deg2rad(180 - $angle));
  198. }
  199. $b = atan2(($endy * $bboxh), ($endx * $bboxw));
  200. $ny = 1 - $coords[1] - (tan($b) * ($coords[0]));
  201. $tx = sin($b) * cos($b) * $ny;
  202. $ty = cos($b) * cos($b) * $ny;
  203. $coords[2] = -$tx;
  204. $coords[3] = 1 - $ty;
  205. } else if ($angle <= 270) {
  206. if ($angle <= 225) {
  207. $endy = tan(deg2rad($angle - 180));
  208. } else {
  209. $endx = tan(deg2rad(270 - $angle));
  210. }
  211. $b = atan2(($endy * $bboxh), ($endx * $bboxw));
  212. $ny = $coords[1] - (tan($b) * ($coords[0]));
  213. $tx = sin($b) * cos($b) * $ny;
  214. $ty = cos($b) * cos($b) * $ny;
  215. $coords[2] = -$tx;
  216. $coords[3] = $ty;
  217. } else {
  218. if ($angle <= 315) {
  219. $endx = tan(deg2rad($angle - 270));
  220. } else {
  221. $endy = tan(deg2rad(360 - $angle));
  222. }
  223. $b = atan2(($endy * $bboxh), ($endx * $bboxw));
  224. $ny = $coords[1] - (tan($b) * (1 - $coords[0]));
  225. $tx = sin($b) * cos($b) * $ny;
  226. $ty = cos($b) * cos($b) * $ny;
  227. $coords[2] = 1 + $tx;
  228. $coords[3] = $ty;
  229. }
  230. }
  231. }
  232. // -moz If the first parameter is only an <angle>, the gradient axis starts from the box's corner that would ensure the
  233. // axis goes through the box. The axis runs along the specified angle. The end point of the axis is defined such that the
  234. // farthest corner of the box from the starting point is perpendicular to the gradient axis at that point.
  235. // NO end points or Start points (Angle defined)
  236. else if ($angle !== false && $coords[0] === false && $coords[1] === false) {
  237. if ($angle == 0 || $angle == 360) {
  238. $coords[0] = 0;
  239. $coords[1] = 0;
  240. $coords[2] = 1;
  241. $coords[3] = 0;
  242. } else if ($angle == 90) {
  243. $coords[0] = 0;
  244. $coords[1] = 0;
  245. $coords[2] = 0;
  246. $coords[3] = 1;
  247. } else if ($angle == 180) {
  248. $coords[0] = 1;
  249. $coords[1] = 0;
  250. $coords[2] = 0;
  251. $coords[3] = 0;
  252. } else if ($angle == 270) {
  253. $coords[0] = 0;
  254. $coords[1] = 1;
  255. $coords[2] = 0;
  256. $coords[3] = 0;
  257. } else {
  258. if ($angle <= 90) {
  259. $coords[0] = 0;
  260. $coords[1] = 0;
  261. if ($angle <= 45) {
  262. $endx = 1;
  263. $endy = tan(deg2rad($angle));
  264. } else {
  265. $endx = tan(deg2rad(90 - $angle));
  266. $endy = 1;
  267. }
  268. } else if ($angle <= 180) {
  269. $coords[0] = 1;
  270. $coords[1] = 0;
  271. if ($angle <= 135) {
  272. $endx = tan(deg2rad($angle - 90));
  273. $endy = 1;
  274. } else {
  275. $endx = 1;
  276. $endy = tan(deg2rad(180 - $angle));
  277. }
  278. } else if ($angle <= 270) {
  279. $coords[0] = 1;
  280. $coords[1] = 1;
  281. if ($angle <= 225) {
  282. $endx = 1;
  283. $endy = tan(deg2rad($angle - 180));
  284. } else {
  285. $endx = tan(deg2rad(270 - $angle));
  286. $endy = 1;
  287. }
  288. } else {
  289. $coords[0] = 0;
  290. $coords[1] = 1;
  291. if ($angle <= 315) {
  292. $endx = tan(deg2rad($angle - 270));
  293. $endy = 1;
  294. } else {
  295. $endx = 1;
  296. $endy = tan(deg2rad(360 - $angle));
  297. }
  298. }
  299. $b = atan2(($endy * $bboxh), ($endx * $bboxw));
  300. $h2 = $bboxh - ($bboxh * tan($b));
  301. $px = $bboxh + ($h2 * sin($b) * cos($b));
  302. $py = ($bboxh * tan($b)) + ($h2 * sin($b) * sin($b));
  303. $x1 = $px / $bboxh;
  304. $y1 = $py / $bboxh;
  305. if ($angle <= 90) {
  306. $coords[2] = $x1;
  307. $coords[3] = $y1;
  308. } else if ($angle <= 180) {
  309. $coords[2] = 1 - $x1;
  310. $coords[3] = $y1;
  311. } else if ($angle <= 270) {
  312. $coords[2] = 1 - $x1;
  313. $coords[3] = 1 - $y1;
  314. } else {
  315. $coords[2] = $x1;
  316. $coords[3] = 1 - $y1;
  317. }
  318. }
  319. }
  320. // -moz If the first parameter to the gradient function is only a <point>, the gradient axis starts from the specified point,
  321. // 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
  322. // gradient is to be applied to.
  323. // NO angle and NO end points (Start points defined)
  324. else if ((!isset($angle) || $angle === false) && $coords[0] !== false && $coords[1] !== false) { // should have start and end defined
  325. $coords[2] = 1 - $coords[0];
  326. $coords[3] = 1 - $coords[1];
  327. $angle = rad2deg(atan2($coords[3] - $coords[1], $coords[2] - $coords[0]));
  328. if ($angle < 0) {
  329. $angle += 360;
  330. } else if ($angle > 360) {
  331. $angle -= 360;
  332. }
  333. if ($angle != 0 && $angle != 360 && $angle != 90 && $angle != 180 && $angle != 270) {
  334. if ($w >= $h) {
  335. $coords[1] *= $h / $w;
  336. $coords[3] *= $h / $w;
  337. $usew = $useh = $bboxw;
  338. $usey -= ($w - $h);
  339. } else {
  340. $coords[0] *= $w / $h;
  341. $coords[2] *= $w / $h;
  342. $usew = $useh = $bboxh;
  343. }
  344. }
  345. }
  346. // -moz If neither a <point> or <angle> is specified, i.e. the entire function consists of only <stop> values, the gradient
  347. // axis starts from the top of the box and runs vertically downwards, ending at the bottom of the box.
  348. else { // default values T2B
  349. // All values are set in parseMozGradient - so won't appear here
  350. $coords = array(0, 0, 1, 0); // default for original linear gradient (L2R)
  351. }
  352. $s = ' q';
  353. $s .= sprintf(' %.3F %.3F %.3F %.3F re W n', $x * _MPDFK, ($this->mpdf->h - $y) * _MPDFK, $w * _MPDFK, -$h * _MPDFK) . "\n";
  354. $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $usew * _MPDFK, $useh * _MPDFK, $usex * _MPDFK, ($this->mpdf->h - ($usey + $useh)) * _MPDFK) . "\n";
  355. }
  356. // RADIAL
  357. else if ($type == 3) {
  358. $radius = (isset($coords[4]) ? $coords[4] : false);
  359. $angle = (isset($coords[5]) ? $coords[5] : false); // ?? no effect
  360. $shape = (isset($coords[6]) ? $coords[6] : false);
  361. $size = (isset($coords[7]) ? $coords[7] : false);
  362. $repeat = (isset($coords[8]) ? $coords[8] : false);
  363. // ALL POINTS AND RADIUS SET (default for custom mPDF radial gradient) - no -moz
  364. if ($coords[0] !== false && $coords[1] !== false && $coords[2] !== false && $coords[3] !== false && $coords[4] !== false) {
  365. // do nothing - coords used as they are
  366. }
  367. // If a <point> is defined
  368. else if ($shape !== false && $size !== false) {
  369. if ($coords[2] == false) {
  370. $coords[2] = $coords[0];
  371. }
  372. if ($coords[3] == false) {
  373. $coords[3] = $coords[1];
  374. }
  375. // ELLIPSE
  376. if ($shape == 'ellipse') {
  377. $corner1 = sqrt(pow($coords[0], 2) + pow($coords[1], 2));
  378. $corner2 = sqrt(pow($coords[0], 2) + pow((1 - $coords[1]), 2));
  379. $corner3 = sqrt(pow((1 - $coords[0]), 2) + pow($coords[1], 2));
  380. $corner4 = sqrt(pow((1 - $coords[0]), 2) + pow((1 - $coords[1]), 2));
  381. if ($size == 'closest-side') {
  382. $radius = min($coords[0], $coords[1], (1 - $coords[0]), (1 - $coords[1]));
  383. } else if ($size == 'closest-corner') {
  384. $radius = min($corner1, $corner2, $corner3, $corner4);
  385. } else if ($size == 'farthest-side') {
  386. $radius = max($coords[0], $coords[1], (1 - $coords[0]), (1 - $coords[1]));
  387. } else {
  388. $radius = max($corner1, $corner2, $corner3, $corner4);
  389. } // farthest corner (default)
  390. }
  391. // CIRCLE
  392. else if ($shape == 'circle') {
  393. if ($w >= $h) {
  394. $coords[1] = $coords[3] = ($coords[1] * $h / $w);
  395. $corner1 = sqrt(pow($coords[0], 2) + pow($coords[1], 2));
  396. $corner2 = sqrt(pow($coords[0], 2) + pow((($h / $w) - $coords[1]), 2));
  397. $corner3 = sqrt(pow((1 - $coords[0]), 2) + pow($coords[1], 2));
  398. $corner4 = sqrt(pow((1 - $coords[0]), 2) + pow((($h / $w) - $coords[1]), 2));
  399. if ($size == 'closest-side') {
  400. $radius = min($coords[0], $coords[1], (1 - $coords[0]), (($h / $w) - $coords[1]));
  401. } else if ($size == 'closest-corner') {
  402. $radius = min($corner1, $corner2, $corner3, $corner4);
  403. } else if ($size == 'farthest-side') {
  404. $radius = max($coords[0], $coords[1], (1 - $coords[0]), (($h / $w) - $coords[1]));
  405. } else if ($size == 'farthest-corner') {
  406. $radius = max($corner1, $corner2, $corner3, $corner4);
  407. } // farthest corner (default)
  408. $usew = $useh = $bboxw;
  409. $usey -= ($w - $h);
  410. } else {
  411. $coords[0] = $coords[2] = ($coords[0] * $w / $h);
  412. $corner1 = sqrt(pow($coords[0], 2) + pow($coords[1], 2));
  413. $corner2 = sqrt(pow($coords[0], 2) + pow((1 - $coords[1]), 2));
  414. $corner3 = sqrt(pow((($w / $h) - $coords[0]), 2) + pow($coords[1], 2));
  415. $corner4 = sqrt(pow((($w / $h) - $coords[0]), 2) + pow((1 - $coords[1]), 2));
  416. if ($size == 'closest-side') {
  417. $radius = min($coords[0], $coords[1], (($w / $h) - $coords[0]), (1 - $coords[1]));
  418. } else if ($size == 'closest-corner') {
  419. $radius = min($corner1, $corner2, $corner3, $corner4);
  420. } else if ($size == 'farthest-side') {
  421. $radius = max($coords[0], $coords[1], (($w / $h) - $coords[0]), (1 - $coords[1]));
  422. } else if ($size == 'farthest-corner') {
  423. $radius = max($corner1, $corner2, $corner3, $corner4);
  424. } // farthest corner (default)
  425. $usew = $useh = $bboxh;
  426. }
  427. }
  428. if ($radius == 0) {
  429. $radius = 0.001;
  430. } // to prevent error
  431. $coords[4] = $radius;
  432. }
  433. // -moz If entire function consists of only <stop> values
  434. else { // default values
  435. // All values are set in parseMozGradient - so won't appear here
  436. $coords = array(0.5, 0.5, 0.5, 0.5); // default for radial gradient (centred)
  437. }
  438. $s = ' q';
  439. $s .= sprintf(' %.3F %.3F %.3F %.3F re W n', $x * _MPDFK, ($this->mpdf->h - $y) * _MPDFK, $w * _MPDFK, -$h * _MPDFK) . "\n";
  440. $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $usew * _MPDFK, $useh * _MPDFK, $usex * _MPDFK, ($this->mpdf->h - ($usey + $useh)) * _MPDFK) . "\n";
  441. }
  442. $n = count($this->mpdf->gradients) + 1;
  443. $this->mpdf->gradients[$n]['type'] = $type;
  444. $this->mpdf->gradients[$n]['colorspace'] = $colorspace;
  445. $trans = false;
  446. $this->mpdf->gradients[$n]['is_mask'] = $is_mask;
  447. if ($is_mask) {
  448. $trans = true;
  449. }
  450. if (count($stops) == 1) {
  451. $stops[1] = $stops[0];
  452. }
  453. if (!isset($stops[0]['offset'])) {
  454. $stops[0]['offset'] = 0;
  455. }
  456. if (!isset($stops[(count($stops) - 1)]['offset'])) {
  457. $stops[(count($stops) - 1)]['offset'] = 1;
  458. }
  459. // Fix stop-offsets set as absolute lengths
  460. if ($type == 2) {
  461. $axisx = ($coords[2] - $coords[0]) * $usew;
  462. $axisy = ($coords[3] - $coords[1]) * $useh;
  463. $axis_length = sqrt(pow($axisx, 2) + pow($axisy, 2));
  464. } else {
  465. $axis_length = $coords[4] * $usew;
  466. } // Absolute lengths are meaningless for an ellipse - Firefox uses Width as reference
  467. for ($i = 0; $i < count($stops); $i++) {
  468. if (isset($stops[$i]['offset']) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i', $stops[$i]['offset'], $m)) {
  469. $tmp = $this->mpdf->ConvertSize($m[1], $this->mpdf->w, $this->mpdf->FontSize, false);
  470. $stops[$i]['offset'] = $tmp / $axis_length;
  471. }
  472. }
  473. if (isset($stops[0]['offset']) && $stops[0]['offset'] > 0) {
  474. $firststop = $stops[0];
  475. $firststop['offset'] = 0;
  476. array_unshift($stops, $firststop);
  477. }
  478. if (!$repeat && isset($stops[(count($stops) - 1)]['offset']) && $stops[(count($stops) - 1)]['offset'] < 1) {
  479. $endstop = $stops[(count($stops) - 1)];
  480. $endstop['offset'] = 1;
  481. $stops[] = $endstop;
  482. }
  483. if ($stops[0]['offset'] > $stops[(count($stops) - 1)]['offset']) {
  484. $stops[0]['offset'] = 0;
  485. $stops[(count($stops) - 1)]['offset'] = 1;
  486. }
  487. for ($i = 0; $i < count($stops); $i++) {
  488. // mPDF 5.3.74
  489. if ($colorspace == 'CMYK') {
  490. $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));
  491. } else if ($colorspace == 'Gray') {
  492. $this->mpdf->gradients[$n]['stops'][$i]['col'] = sprintf('%.3F', (ord($stops[$i]['col']{1}) / 255));
  493. } else {
  494. $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));
  495. }
  496. if (!isset($stops[$i]['opacity'])) {
  497. $stops[$i]['opacity'] = 1;
  498. } else if ($stops[$i]['opacity'] > 1 || $stops[$i]['opacity'] < 0) {
  499. $stops[$i]['opacity'] = 1;
  500. } else if ($stops[$i]['opacity'] < 1) {
  501. $trans = true;
  502. }
  503. $this->mpdf->gradients[$n]['stops'][$i]['opacity'] = $stops[$i]['opacity'];
  504. // OFFSET
  505. if ($i > 0 && $i < (count($stops) - 1)) {
  506. if (!isset($stops[$i]['offset']) || (isset($stops[$i + 1]['offset']) && $stops[$i]['offset'] > $stops[$i + 1]['offset']) || $stops[$i]['offset'] < $stops[$i - 1]['offset']) {
  507. if (isset($stops[$i - 1]['offset']) && isset($stops[$i + 1]['offset'])) {
  508. $stops[$i]['offset'] = ($stops[$i - 1]['offset'] + $stops[$i + 1]['offset']) / 2;
  509. } else {
  510. for ($j = ($i + 1); $j < count($stops); $j++) {
  511. if (isset($stops[$j]['offset'])) {
  512. break;
  513. }
  514. }
  515. $int = ($stops[$j]['offset'] - $stops[($i - 1)]['offset']) / ($j - $i + 1);
  516. for ($f = 0; $f < ($j - $i - 1); $f++) {
  517. $stops[($i + $f)]['offset'] = $stops[($i + $f - 1)]['offset'] + ($int);
  518. }
  519. }
  520. }
  521. }
  522. $this->mpdf->gradients[$n]['stops'][$i]['offset'] = $stops[$i]['offset'];
  523. $this->mpdf->gradients[$n]['stops'][$i]['offset'] = $stops[$i]['offset'];
  524. }
  525. if ($repeat) {
  526. $ns = count($this->mpdf->gradients[$n]['stops']);
  527. $offs = array();
  528. for ($i = 0; $i < $ns; $i++) {
  529. $offs[$i] = $this->mpdf->gradients[$n]['stops'][$i]['offset'];
  530. }
  531. $gp = 0;
  532. $inside = true;
  533. while ($inside) {
  534. $gp++;
  535. for ($i = 0; $i < $ns; $i++) {
  536. $this->mpdf->gradients[$n]['stops'][(($ns * $gp) + $i)] = $this->mpdf->gradients[$n]['stops'][(($ns * ($gp - 1)) + $i)];
  537. $tmp = $this->mpdf->gradients[$n]['stops'][(($ns * ($gp - 1)) + ($ns - 1))]['offset'] + $offs[$i];
  538. if ($tmp < 1) {
  539. $this->mpdf->gradients[$n]['stops'][(($ns * $gp) + $i)]['offset'] = $tmp;
  540. } else {
  541. $this->mpdf->gradients[$n]['stops'][(($ns * $gp) + $i)]['offset'] = 1;
  542. $inside = false;
  543. break(2);
  544. }
  545. }
  546. }
  547. }
  548. if ($trans) {
  549. $this->mpdf->gradients[$n]['trans'] = true;
  550. $s .= ' /TGS' . $n . ' gs ';
  551. }
  552. if (!is_array($extend) || count($extend) < 1) {
  553. $extend = array('true', 'true'); // These are supposed to be quoted - appear in PDF file as text
  554. }
  555. $this->mpdf->gradients[$n]['coords'] = $coords;
  556. $this->mpdf->gradients[$n]['extend'] = $extend;
  557. //paint the gradient
  558. $s .= '/Sh' . $n . ' sh ' . "\n";
  559. //restore previous Graphic State
  560. $s .= ' Q ' . "\n";
  561. if ($return) {
  562. return $s;
  563. } else {
  564. $this->mpdf->_out($s);
  565. }
  566. }
  567. function parseMozGradient($bg)
  568. {
  569. // background[-image]: -moz-linear-gradient(left, #c7Fdde 20%, #FF0000 );
  570. // background[-image]: linear-gradient(left, #c7Fdde 20%, #FF0000 ); // CSS3
  571. if (preg_match('/repeating-/', $bg)) {
  572. $repeat = true;
  573. } else {
  574. $repeat = false;
  575. }
  576. if (preg_match('/linear-gradient\((.*)\)/', $bg, $m)) {
  577. $g = array();
  578. $g['type'] = 2;
  579. $g['colorspace'] = 'RGB';
  580. $g['extend'] = array('true', 'true');
  581. $v = trim($m[1]);
  582. // Change commas inside e.g. rgb(x,x,x)
  583. while (preg_match('/(\([^\)]*?),/', $v)) {
  584. $v = preg_replace('/(\([^\)]*?),/', '\\1@', $v);
  585. }
  586. // Remove spaces inside e.g. rgb(x, x, x)
  587. while (preg_match('/(\([^\)]*?)[ ]/', $v)) {
  588. $v = preg_replace('/(\([^\)]*?)[ ]/', '\\1', $v);
  589. }
  590. $bgr = preg_split('/\s*,\s*/', $v);
  591. for ($i = 0; $i < count($bgr); $i++) {
  592. $bgr[$i] = preg_replace('/@/', ',', $bgr[$i]);
  593. }
  594. // Is first part $bgr[0] a valid point/angle?
  595. $first = preg_split('/\s+/', trim($bgr[0]));
  596. if (preg_match('/(left|center|right|bottom|top|deg|grad|rad)/i', $bgr[0]) && !preg_match('/(<#|rgb|rgba|hsl|hsla)/i', $bgr[0])) {
  597. $startStops = 1;
  598. } else if (trim($first[(count($first) - 1)]) === "0") {
  599. $startStops = 1;
  600. } else {
  601. $check = $this->mpdf->ConvertColor($first[0]);
  602. if ($check)
  603. $startStops = 0;
  604. else
  605. $startStops = 1;
  606. }
  607. // first part a valid point/angle?
  608. if ($startStops == 1) { // default values
  609. // [<point> || <angle>,] = [<% em px left center right bottom top> || <deg grad rad 0>,]
  610. if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i', $bgr[0], $m)) {
  611. $angle = $m[1] + 0;
  612. if (strtolower($m[2]) == 'deg') {
  613. $angle = $angle;
  614. } else if (strtolower($m[2]) == 'grad') {
  615. $angle *= (360 / 400);
  616. } else if (strtolower($m[2]) == 'rad') {
  617. $angle = rad2deg($angle);
  618. }
  619. while ($angle < 0) {
  620. $angle += 360;
  621. }
  622. $angle = ($angle % 360);
  623. } else if (trim($first[(count($first) - 1)]) === "0") {
  624. $angle = 0;
  625. }
  626. if (preg_match('/left/i', $bgr[0])) {
  627. $startx = 0;
  628. } else if (preg_match('/right/i', $bgr[0])) {
  629. $startx = 1;
  630. }
  631. if (preg_match('/top/i', $bgr[0])) {
  632. $starty = 1;
  633. } else if (preg_match('/bottom/i', $bgr[0])) {
  634. $starty = 0;
  635. }
  636. // Check for %? ?% or %%
  637. if (preg_match('/(\d+)[%]/i', $first[0], $m)) {
  638. $startx = $m[1] / 100;
  639. } else if (!isset($startx) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i', $first[0], $m)) {
  640. $tmp = $this->mpdf->ConvertSize($m[1], $this->mpdf->w, $this->mpdf->FontSize, false);
  641. if ($tmp) {
  642. $startx = $m[1];
  643. }
  644. }
  645. if (isset($first[1]) && preg_match('/(\d+)[%]/i', $first[1], $m)) {
  646. $starty = 1 - ($m[1] / 100);
  647. } else if (!isset($starty) && isset($first[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i', $first[1], $m)) {
  648. $tmp = $this->mpdf->ConvertSize($m[1], $this->mpdf->w, $this->mpdf->FontSize, false);
  649. if ($tmp) {
  650. $starty = $m[1];
  651. }
  652. }
  653. if (isset($startx) && !isset($starty)) {
  654. $starty = 0.5;
  655. }
  656. if (!isset($startx) && isset($starty)) {
  657. $startx = 0.5;
  658. }
  659. }
  660. // 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.
  661. else { // default values T2B
  662. $starty = 1;
  663. $startx = 0.5;
  664. $endy = 0;
  665. $endx = 0.5;
  666. }
  667. $coords = array();
  668. if (!isset($startx)) {
  669. $startx = false;
  670. }
  671. if (!isset($starty)) {
  672. $starty = false;
  673. }
  674. if (!isset($endx)) {
  675. $endx = false;
  676. }
  677. if (!isset($endy)) {
  678. $endy = false;
  679. }
  680. if (!isset($angle)) {
  681. $angle = false;
  682. }
  683. $g['coords'] = array($startx, $starty, $endx, $endy, $angle, $repeat);
  684. $g['stops'] = array();
  685. for ($i = $startStops; $i < count($bgr); $i++) {
  686. $stop = array();
  687. // parse stops
  688. $el = preg_split('/\s+/', trim($bgr[$i]));
  689. // mPDF 5.3.74
  690. $col = $this->mpdf->ConvertColor($el[0]);
  691. if ($col) {
  692. $stop['col'] = $col;
  693. } else {
  694. $stop['col'] = $col = $this->mpdf->ConvertColor(255);
  695. }
  696. if ($col{0} == 1)
  697. $g['colorspace'] = 'Gray';
  698. else if ($col{0} == 4 || $col{0} == 6)
  699. $g['colorspace'] = 'CMYK';
  700. if ($col{0} == 5) {
  701. $stop['opacity'] = ord($col{4}) / 100;
  702. } // transparency from rgba()
  703. else if ($col{0} == 6) {
  704. $stop['opacity'] = ord($col{5}) / 100;
  705. } // transparency from cmyka()
  706. else if ($col{0} == 1 && $col{2} == 1) {
  707. $stop['opacity'] = ord($col{3}) / 100;
  708. } // transparency converted from rgba or cmyka()
  709. if (isset($el[1]) && preg_match('/(\d+)[%]/', $el[1], $m)) {
  710. $stop['offset'] = $m[1] / 100;
  711. if ($stop['offset'] > 1) {
  712. unset($stop['offset']);
  713. }
  714. } else if (isset($el[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i', $el[1], $m)) {
  715. $tmp = $this->mpdf->ConvertSize($m[1], $this->mpdf->w, $this->mpdf->FontSize, false);
  716. if ($tmp) {
  717. $stop['offset'] = $m[1];
  718. }
  719. }
  720. $g['stops'][] = $stop;
  721. }
  722. if (count($g['stops'])) {
  723. return $g;
  724. }
  725. } else if (preg_match('/radial-gradient\((.*)\)/', $bg, $m)) {
  726. $g = array();
  727. $g['type'] = 3;
  728. $g['colorspace'] = 'RGB';
  729. $g['extend'] = array('true', 'true');
  730. $v = trim($m[1]);
  731. // Change commas inside e.g. rgb(x,x,x)
  732. while (preg_match('/(\([^\)]*?),/', $v)) {
  733. $v = preg_replace('/(\([^\)]*?),/', '\\1@', $v);
  734. }
  735. // Remove spaces inside e.g. rgb(x, x, x)
  736. while (preg_match('/(\([^\)]*?)[ ]/', $v)) {
  737. $v = preg_replace('/(\([^\)]*?)[ ]/', '\\1', $v);
  738. }
  739. $bgr = preg_split('/\s*,\s*/', $v);
  740. for ($i = 0; $i < count($bgr); $i++) {
  741. $bgr[$i] = preg_replace('/@/', ',', $bgr[$i]);
  742. }
  743. // Is first part $bgr[0] a valid point/angle?
  744. $startStops = 0;
  745. $pos_angle = false;
  746. $shape_size = false;
  747. $first = preg_split('/\s+/', trim($bgr[0]));
  748. $checkCol = $this->mpdf->ConvertColor($first[0]);
  749. if (preg_match('/(left|center|right|bottom|top|deg|grad|rad)/i', $bgr[0]) && !preg_match('/(<#|rgb|rgba|hsl|hsla)/i', $bgr[0])) {
  750. $startStops = 1;
  751. $pos_angle = $bgr[0];
  752. } else if (trim($first[(count($first) - 1)]) === "0") {
  753. $startStops = 1;
  754. $pos_angle = $bgr[0];
  755. } else if (preg_match('/(circle|ellipse|closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i', $bgr[0])) {
  756. $startStops = 1;
  757. $shape_size = $bgr[0];
  758. } else if (!$checkCol) {
  759. $startStops = 1;
  760. $pos_angle = $bgr[0];
  761. }
  762. if (preg_match('/(circle|ellipse|closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i', $bgr[1])) {
  763. $startStops = 2;
  764. $shape_size = $bgr[1];
  765. }
  766. // If valid point/angle?
  767. if ($pos_angle) { // default values
  768. // [<point> || <angle>,] = [<% em px left center right bottom top> || <deg grad rad 0>,]
  769. if (preg_match('/left/i', $pos_angle)) {
  770. $startx = 0;
  771. } else if (preg_match('/right/i', $pos_angle)) {
  772. $startx = 1;
  773. }
  774. if (preg_match('/top/i', $pos_angle)) {
  775. $starty = 1;
  776. } else if (preg_match('/bottom/i', $pos_angle)) {
  777. $starty = 0;
  778. }
  779. // Check for %? ?% or %%
  780. if (preg_match('/(\d+)[%]/i', $first[0], $m)) {
  781. $startx = $m[1] / 100;
  782. } else if (!isset($startx) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i', $first[0], $m)) {
  783. $tmp = $this->mpdf->ConvertSize($m[1], $this->mpdf->w, $this->mpdf->FontSize, false);
  784. if ($tmp) {
  785. $startx = $m[1];
  786. }
  787. }
  788. if (isset($first[1]) && preg_match('/(\d+)[%]/i', $first[1], $m)) {
  789. $starty = 1 - ($m[1] / 100);
  790. } else if (!isset($starty) && isset($first[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i', $first[1], $m)) {
  791. $tmp = $this->mpdf->ConvertSize($m[1], $this->mpdf->w, $this->mpdf->FontSize, false);
  792. if ($tmp) {
  793. $starty = $m[1];
  794. }
  795. }
  796. /*
  797. // ?? Angle has no effect in radial gradient (does not exist in CSS3 spec.)
  798. if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$pos_angle,$m)) {
  799. $angle = $m[1] + 0;
  800. if (strtolower($m[2])=='deg') { $angle = $angle; }
  801. else if (strtolower($m[2])=='grad') { $angle *= (360/400); }
  802. else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); }
  803. while($angle < 0) { $angle += 360; }
  804. $angle = ($angle % 360);
  805. }
  806. */
  807. if (!isset($starty)) {
  808. $starty = 0.5;
  809. }
  810. if (!isset($startx)) {
  811. $startx = 0.5;
  812. }
  813. }
  814. // 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.
  815. else { // default values Center
  816. $starty = 0.5;
  817. $startx = 0.5;
  818. $endy = 0.5;
  819. $endx = 0.5;
  820. }
  821. // If valid shape/size?
  822. $shape = 'ellipse'; // default
  823. $size = 'farthest-corner'; // default
  824. if ($shape_size) { // default values
  825. if (preg_match('/(circle|ellipse)/i', $shape_size, $m)) {
  826. $shape = $m[1];
  827. }
  828. if (preg_match('/(closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i', $shape_size, $m)) {
  829. $size = $m[1];
  830. if ($size == 'contain') {
  831. $size = 'closest-side';
  832. } else if ($size == 'cover') {
  833. $size = 'farthest-corner';
  834. }
  835. }
  836. }
  837. $coords = array();
  838. if (!isset($startx)) {
  839. $startx = false;
  840. }
  841. if (!isset($starty)) {
  842. $starty = false;
  843. }
  844. if (!isset($endx)) {
  845. $endx = false;
  846. }
  847. if (!isset($endy)) {
  848. $endy = false;
  849. }
  850. if (!isset($radius)) {
  851. $radius = false;
  852. }
  853. if (!isset($angle)) {
  854. $angle = 0;
  855. }
  856. $g['coords'] = array($startx, $starty, $endx, $endy, $radius, $angle, $shape, $size, $repeat);
  857. $g['stops'] = array();
  858. for ($i = $startStops; $i < count($bgr); $i++) {
  859. $stop = array();
  860. // parse stops
  861. $el = preg_split('/\s+/', trim($bgr[$i]));
  862. // mPDF 5.3.74
  863. $col = $this->mpdf->ConvertColor($el[0]);
  864. if ($col) {
  865. $stop['col'] = $col;
  866. } else {
  867. $stop['col'] = $col = $this->mpdf->ConvertColor(255);
  868. }
  869. if ($col{0} == 1)
  870. $g['colorspace'] = 'Gray';
  871. else if ($col{0} == 4 || $col{0} == 6)
  872. $g['colorspace'] = 'CMYK';
  873. if ($col{0} == 5) {
  874. $stop['opacity'] = ord($col{4}) / 100;
  875. } // transparency from rgba()
  876. else if ($col{0} == 6) {
  877. $stop['opacity'] = ord($col{5}) / 100;
  878. } // transparency from cmyka()
  879. else if ($col{0} == 1 && $col{2} == 1) {
  880. $stop['opacity'] = ord($col{3}) / 100;
  881. } // transparency converted from rgba or cmyka()
  882. if (isset($el[1]) && preg_match('/(\d+)[%]/', $el[1], $m)) {
  883. $stop['offset'] = $m[1] / 100;
  884. if ($stop['offset'] > 1) {
  885. unset($stop['offset']);
  886. }
  887. } else if (isset($el[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i', $el[1], $m)) {
  888. $tmp = $this->mpdf->ConvertSize($m[1], $this->mpdf->w, $this->mpdf->FontSize, false);
  889. $stop['offset'] = $el[1];
  890. }
  891. $g['stops'][] = $stop;
  892. }
  893. if (count($g['stops'])) {
  894. return $g;
  895. }
  896. }
  897. return array();
  898. }
  899. function parseBackgroundGradient($bg)
  900. {
  901. // background-gradient: linear #00FFFF #FFFF00 0 0.5 1 0.5; or
  902. // background-gradient: radial #00FFFF #FFFF00 0.5 0.5 1 1 1.2;
  903. $v = trim($bg);
  904. $bgr = preg_split('/\s+/', $v);
  905. $g = array();
  906. if (count($bgr) > 6) {
  907. if (strtoupper(substr($bgr[0], 0, 1)) == 'L' && count($bgr) == 7) { // linear
  908. $g['type'] = 2;
  909. //$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
  910. // Linear: $coords - array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg).
  911. // The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
  912. $g['coords'] = array($bgr[3], $bgr[4], $bgr[5], $bgr[6]);
  913. } else if (count($bgr) == 8) { // radial
  914. $g['type'] = 3;
  915. // Radial: $coords - array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1,
  916. // (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg).
  917. // (fx, fy) should be inside the circle, otherwise some areas will not be defined
  918. $g['coords'] = array($bgr[3], $bgr[4], $bgr[5], $bgr[6], $bgr[7]);
  919. }
  920. $g['colorspace'] = 'RGB';
  921. // mPDF 5.3.74
  922. $cor = $this->mpdf->ConvertColor($bgr[1]);
  923. if ($cor{0} == 1)
  924. $g['colorspace'] = 'Gray';
  925. else if ($cor{0} == 4 || $cor{0} == 6)
  926. $g['colorspace'] = 'CMYK';
  927. if ($cor) {
  928. $g['col'] = $cor;
  929. } else {
  930. $g['col'] = $this->mpdf->ConvertColor(255);
  931. }
  932. $cor = $this->mpdf->ConvertColor($bgr[2]);
  933. if ($cor) {
  934. $g['col2'] = $cor;
  935. } else {
  936. $g['col2'] = $this->mpdf->ConvertColor(255);
  937. }
  938. $g['extend'] = array('true', 'true');
  939. $g['stops'] = array(array('col' => $g['col'], 'opacity' => 1, 'offset' => 0), array('col' => $g['col2'], 'opacity' => 1, 'offset' => 1));
  940. return $g;
  941. }
  942. return false;
  943. }
  944. }