PageRenderTime 57ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/app/protected/extensions/pdf/dompdf/include/abstract_renderer.cls.php

https://bitbucket.org/sanbrar/zurmo_invoice
PHP | 865 lines | 548 code | 174 blank | 143 comment | 111 complexity | 66594a8086eb2a8a2499491f45872b5e MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, LGPL-3.0, BSD-2-Clause, GPL-3.0
  1. <?php
  2. /**
  3. * @package dompdf
  4. * @link http://www.dompdf.com/
  5. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  6. * @author Helmut Tischer <htischer@weihenstephan.org>
  7. * @author Fabien Ménager <fabien.menager@gmail.com>
  8. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  9. * @version $Id: abstract_renderer.cls.php 448 2011-11-13 13:00:03Z fabien.menager $
  10. */
  11. /**
  12. * Base renderer class
  13. *
  14. * @access private
  15. * @package dompdf
  16. */
  17. abstract class Abstract_Renderer {
  18. /**
  19. * Rendering backend
  20. *
  21. * @var Canvas
  22. */
  23. protected $_canvas;
  24. /**
  25. * Current dompdf instance
  26. *
  27. * @var DOMPDF
  28. */
  29. protected $_dompdf;
  30. /**
  31. * Class constructor
  32. *
  33. * @param DOMPDF $dompdf The current dompdf instance
  34. */
  35. function __construct(DOMPDF $dompdf) {
  36. $this->_dompdf = $dompdf;
  37. $this->_canvas = $dompdf->get_canvas();
  38. }
  39. /**
  40. * Render a frame.
  41. *
  42. * Specialized in child classes
  43. *
  44. * @param Frame $frame The frame to render
  45. */
  46. abstract function render(Frame $frame);
  47. //........................................................................
  48. /**
  49. * Render a background image over a rectangular area
  50. *
  51. * @param string $img The background image to load
  52. * @param float $x The left edge of the rectangular area
  53. * @param float $y The top edge of the rectangular area
  54. * @param float $width The width of the rectangular area
  55. * @param float $height The height of the rectangular area
  56. * @param Style $style The associated Style object
  57. */
  58. protected function _background_image($url, $x, $y, $width, $height, $style) {
  59. $sheet = $style->get_stylesheet();
  60. // Skip degenerate cases
  61. if ( $width == 0 || $height == 0 )
  62. return;
  63. $box_width = $width;
  64. $box_height = $height;
  65. //debugpng
  66. if (DEBUGPNG) print '[_background_image '.$url.']';
  67. list($img, $type, $msg) = Image_Cache::resolve_url($url,
  68. $sheet->get_protocol(),
  69. $sheet->get_host(),
  70. $sheet->get_base_path());
  71. // Bail if the image is no good
  72. if ( Image_Cache::is_broken($img) )
  73. return;
  74. //Try to optimize away reading and composing of same background multiple times
  75. //Postponing read with imagecreatefrom ...()
  76. //final composition paramters and name not known yet
  77. //Therefore read dimension directly from file, instead of creating gd object first.
  78. //$img_w = imagesx($src); $img_h = imagesy($src);
  79. list($img_w, $img_h) = dompdf_getimagesize($img);
  80. if (!isset($img_w) || $img_w == 0 || !isset($img_h) || $img_h == 0) {
  81. return;
  82. }
  83. $repeat = $style->background_repeat;
  84. $bg_color = $style->background_color;
  85. //Increase background resolution and dependent box size according to image resolution to be placed in
  86. //Then image can be copied in without resize
  87. $bg_width = round((float)($width * DOMPDF_DPI) / 72);
  88. $bg_height = round((float)($height * DOMPDF_DPI) / 72);
  89. //Need %bg_x, $bg_y as background pos, where img starts, converted to pixel
  90. list($bg_x, $bg_y) = $style->background_position;
  91. if ( is_percent($bg_x) ) {
  92. // The point $bg_x % from the left edge of the image is placed
  93. // $bg_x % from the left edge of the background rectangle
  94. $p = ((float)$bg_x)/100.0;
  95. $x1 = $p * $img_w;
  96. $x2 = $p * $bg_width;
  97. $bg_x = $x2 - $x1;
  98. } else {
  99. $bg_x = (float)($style->length_in_pt($bg_x)*DOMPDF_DPI) / 72;
  100. }
  101. $bg_x = round($bg_x + $style->length_in_pt($style->border_left_width)*DOMPDF_DPI / 72);
  102. if ( is_percent($bg_y) ) {
  103. // The point $bg_y % from the left edge of the image is placed
  104. // $bg_y % from the left edge of the background rectangle
  105. $p = ((float)$bg_y)/100.0;
  106. $y1 = $p * $img_h;
  107. $y2 = $p * $bg_height;
  108. $bg_y = $y2 - $y1;
  109. } else {
  110. $bg_y = (float)($style->length_in_pt($bg_y)*DOMPDF_DPI) / 72;
  111. }
  112. $bg_y = round($bg_y + $style->length_in_pt($style->border_top_width)*DOMPDF_DPI / 72);
  113. //clip background to the image area on partial repeat. Nothing to do if img off area
  114. //On repeat, normalize start position to the tile at immediate left/top or 0/0 of area
  115. //On no repeat with positive offset: move size/start to have offset==0
  116. //Handle x/y Dimensions separately
  117. if ( $repeat !== "repeat" && $repeat !== "repeat-x" ) {
  118. //No repeat x
  119. if ($bg_x < 0) {
  120. $bg_width = $img_w + $bg_x;
  121. } else {
  122. $x += ($bg_x * 72)/DOMPDF_DPI;
  123. $bg_width = $bg_width - $bg_x;
  124. if ($bg_width > $img_w) {
  125. $bg_width = $img_w;
  126. }
  127. $bg_x = 0;
  128. }
  129. if ($bg_width <= 0) {
  130. return;
  131. }
  132. $width = (float)($bg_width * 72)/DOMPDF_DPI;
  133. } else {
  134. //repeat x
  135. if ($bg_x < 0) {
  136. $bg_x = - ((-$bg_x) % $img_w);
  137. } else {
  138. $bg_x = $bg_x % $img_w;
  139. if ($bg_x > 0) {
  140. $bg_x -= $img_w;
  141. }
  142. }
  143. }
  144. if ( $repeat !== "repeat" && $repeat !== "repeat-y" ) {
  145. //no repeat y
  146. if ($bg_y < 0) {
  147. $bg_height = $img_h + $bg_y;
  148. } else {
  149. $y += ($bg_y * 72)/DOMPDF_DPI;
  150. $bg_height = $bg_height - $bg_y;
  151. if ($bg_height > $img_h) {
  152. $bg_height = $img_h;
  153. }
  154. $bg_y = 0;
  155. }
  156. if ($bg_height <= 0) {
  157. return;
  158. }
  159. $height = (float)($bg_height * 72)/DOMPDF_DPI;
  160. } else {
  161. //repeat y
  162. if ($bg_y < 0) {
  163. $bg_y = - ((-$bg_y) % $img_h);
  164. } else {
  165. $bg_y = $bg_y % $img_h;
  166. if ($bg_y > 0) {
  167. $bg_y -= $img_h;
  168. }
  169. }
  170. }
  171. //Optimization, if repeat has no effect
  172. if ( $repeat === "repeat" && $bg_y <= 0 && $img_h+$bg_y >= $bg_height ) {
  173. $repeat = "repeat-x";
  174. }
  175. if ( $repeat === "repeat" && $bg_x <= 0 && $img_w+$bg_x >= $bg_width ) {
  176. $repeat = "repeat-y";
  177. }
  178. if ( ($repeat === "repeat-x" && $bg_x <= 0 && $img_w+$bg_x >= $bg_width) ||
  179. ($repeat === "repeat-y" && $bg_y <= 0 && $img_h+$bg_y >= $bg_height) ) {
  180. $repeat = "no-repeat";
  181. }
  182. //Use filename as indicator only
  183. //different names for different variants to have different copies in the pdf
  184. //This is not dependent of background color of box! .'_'.(is_array($bg_color) ? $bg_color["hex"] : $bg_color)
  185. //Note: Here, bg_* are the start values, not end values after going through the tile loops!
  186. $filedummy = $img;
  187. /*
  188. //Make shorter strings with limited characters for cache associative array index - needed?
  189. //Strip common base path - server root, explicite temp, default temp; remove unwanted characters;
  190. $filedummy = strtr($filedummy,"\\:","//");
  191. $p = strtr($_SERVER["DOCUMENT_ROOT"],"\\:","//");
  192. $l = strlen($p);
  193. if ( substr($filedummy,0,$l) == $p) {
  194. $filedummy = substr($filedummy,$l);
  195. } else {
  196. $p = strtr(DOMPDF_TEMP_DIR,"\\:","//");
  197. $l = strlen($p);
  198. if ( substr($filedummy,0,$l) == $p) {
  199. $filedummy = substr($filedummy,$l);
  200. } else {
  201. $p = strtr(sys_get_temp_dir(),"\\:","//");
  202. $l = strlen($p);
  203. if ( substr($filedummy,0,$l) == $p) {
  204. $filedummy = substr($filedummy,$l);
  205. }
  206. }
  207. }
  208. */
  209. $is_png = false;
  210. $filedummy .= '_'.$bg_width.'_'.$bg_height.'_'.$bg_x.'_'.$bg_y.'_'.$repeat;
  211. //debugpng
  212. //if (DEBUGPNG) print '<pre>[_background_image name '.$filedummy.']</pre>';
  213. //Optimization to avoid multiple times rendering the same image.
  214. //If check functions are existing and identical image already cached,
  215. //then skip creation of duplicate, because it is not needed by addImagePng
  216. if ( method_exists( $this->_canvas, "get_cpdf" ) &&
  217. method_exists( $this->_canvas->get_cpdf(), "addImagePng" ) &&
  218. method_exists( $this->_canvas->get_cpdf(), "image_iscached" ) &&
  219. $this->_canvas->get_cpdf()->image_iscached($filedummy) ) {
  220. $bg = null;
  221. //debugpng
  222. //if (DEBUGPNG) print '[_background_image skip]';
  223. }
  224. else {
  225. // Create a new image to fit over the background rectangle
  226. $bg = imagecreatetruecolor($bg_width, $bg_height);
  227. switch (strtolower($type)) {
  228. case IMAGETYPE_PNG:
  229. $is_png = true;
  230. imagesavealpha($bg, true);
  231. imagealphablending($bg, false);
  232. $src = imagecreatefrompng($img);
  233. break;
  234. case IMAGETYPE_JPEG:
  235. $src = imagecreatefromjpeg($img);
  236. break;
  237. case IMAGETYPE_GIF:
  238. $src = imagecreatefromgif($img);
  239. break;
  240. case IMAGETYPE_BMP:
  241. $src = imagecreatefrombmp($img);
  242. break;
  243. default: return; // Unsupported image type
  244. }
  245. if ($src == null) {
  246. return;
  247. }
  248. //Background color if box is not relevant here
  249. //Non transparent image: box clipped to real size. Background non relevant.
  250. //Transparent image: The image controls the transparency and lets shine through whatever background.
  251. //However on transparent imaage preset the composed image with the transparency color,
  252. //to keep the transparency when copying over the non transparent parts of the tiles.
  253. $ti = imagecolortransparent($src);
  254. if ($ti >= 0) {
  255. $tc = imagecolorsforindex($src,$ti);
  256. $ti = imagecolorallocate($bg,$tc['red'],$tc['green'],$tc['blue']);
  257. imagefill($bg,0,0,$ti);
  258. imagecolortransparent($bg, $ti);
  259. }
  260. //This has only an effect for the non repeatable dimension.
  261. //compute start of src and dest coordinates of the single copy
  262. if ( $bg_x < 0 ) {
  263. $dst_x = 0;
  264. $src_x = -$bg_x;
  265. } else {
  266. $src_x = 0;
  267. $dst_x = $bg_x;
  268. }
  269. if ( $bg_y < 0 ) {
  270. $dst_y = 0;
  271. $src_y = -$bg_y;
  272. } else {
  273. $src_y = 0;
  274. $dst_y = $bg_y;
  275. }
  276. //For historical reasons exchange meanings of variables:
  277. //start_* will be the start values, while bg_* will be the temporary start values in the loops
  278. $start_x = $bg_x;
  279. $start_y = $bg_y;
  280. // Copy regions from the source image to the background
  281. if ( $repeat === "no-repeat" ) {
  282. // Simply place the image on the background
  283. imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $img_w, $img_h);
  284. } else if ( $repeat === "repeat-x" ) {
  285. for ( $bg_x = $start_x; $bg_x < $bg_width; $bg_x += $img_w ) {
  286. if ( $bg_x < 0 ) {
  287. $dst_x = 0;
  288. $src_x = -$bg_x;
  289. $w = $img_w + $bg_x;
  290. } else {
  291. $dst_x = $bg_x;
  292. $src_x = 0;
  293. $w = $img_w;
  294. }
  295. imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $w, $img_h);
  296. }
  297. } else if ( $repeat === "repeat-y" ) {
  298. for ( $bg_y = $start_y; $bg_y < $bg_height; $bg_y += $img_h ) {
  299. if ( $bg_y < 0 ) {
  300. $dst_y = 0;
  301. $src_y = -$bg_y;
  302. $h = $img_h + $bg_y;
  303. } else {
  304. $dst_y = $bg_y;
  305. $src_y = 0;
  306. $h = $img_h;
  307. }
  308. imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $img_w, $h);
  309. }
  310. } else if ( $repeat === "repeat" ) {
  311. for ( $bg_y = $start_y; $bg_y < $bg_height; $bg_y += $img_h ) {
  312. for ( $bg_x = $start_x; $bg_x < $bg_width; $bg_x += $img_w ) {
  313. if ( $bg_x < 0 ) {
  314. $dst_x = 0;
  315. $src_x = -$bg_x;
  316. $w = $img_w + $bg_x;
  317. } else {
  318. $dst_x = $bg_x;
  319. $src_x = 0;
  320. $w = $img_w;
  321. }
  322. if ( $bg_y < 0 ) {
  323. $dst_y = 0;
  324. $src_y = -$bg_y;
  325. $h = $img_h + $bg_y;
  326. } else {
  327. $dst_y = $bg_y;
  328. $src_y = 0;
  329. $h = $img_h;
  330. }
  331. imagecopy($bg, $src, $dst_x, $dst_y, $src_x, $src_y, $w, $h);
  332. }
  333. }
  334. }
  335. else {
  336. print 'Unknown repeat!';
  337. }
  338. imagedestroy($src);
  339. } /* End optimize away creation of duplicates */
  340. $this->_canvas->clipping_rectangle($x, $y, $box_width, $box_height);
  341. //img: image url string
  342. //img_w, img_h: original image size in px
  343. //width, height: box size in pt
  344. //bg_width, bg_height: box size in px
  345. //x, y: left/top edge of box on page in pt
  346. //start_x, start_y: placement of image relativ to pattern
  347. //$repeat: repeat mode
  348. //$bg: GD object of result image
  349. //$src: GD object of original image
  350. //When using cpdf and optimization to direct png creation from gd object is available,
  351. //don't create temp file, but place gd object directly into the pdf
  352. if ( !$is_png && method_exists( $this->_canvas, "get_cpdf" ) &&
  353. method_exists( $this->_canvas->get_cpdf(), "addImagePng" ) ) {
  354. // Note: CPDF_Adapter image converts y position
  355. $this->_canvas->get_cpdf()->addImagePng($filedummy, $x, $this->_canvas->get_height() - $y - $height, $width, $height, $bg);
  356. }
  357. else {
  358. $tmp_name = tempnam(DOMPDF_TEMP_DIR, "bg_dompdf_img_");
  359. @unlink($tmp_name);
  360. $tmp_file = "$tmp_name.png";
  361. //debugpng
  362. if (DEBUGPNG) print '[_background_image '.$tmp_file.']';
  363. imagepng($bg, $tmp_file);
  364. $this->_canvas->image($tmp_file, $x, $y, $width, $height);
  365. imagedestroy($bg);
  366. //debugpng
  367. if (DEBUGPNG) print '[_background_image unlink '.$tmp_file.']';
  368. if (!DEBUGKEEPTEMP)
  369. unlink($tmp_file);
  370. }
  371. $this->_canvas->clipping_end();
  372. }
  373. protected function _get_dash_pattern($style, $width) {
  374. $pattern = array();
  375. switch ($style) {
  376. default:
  377. /*case "solid":
  378. case "double":
  379. case "groove":
  380. case "inset":
  381. case "outset":
  382. case "ridge":*/
  383. case "none": break;
  384. case "dotted":
  385. if ( $width <= 1 )
  386. $pattern = array($width, $width*2);
  387. else
  388. $pattern = array($width);
  389. break;
  390. case "dashed":
  391. $pattern = array(3 * $width);
  392. break;
  393. }
  394. return $pattern;
  395. }
  396. protected function _border_none($x, $y, $length, $color, $widths, $side, $corner_style = "bevel") {
  397. return;
  398. }
  399. protected function _border_hidden($x, $y, $length, $color, $widths, $side, $corner_style = "bevel") {
  400. return;
  401. }
  402. // Border rendering functions
  403. protected function _border_dotted($x, $y, $length, $color, $widths, $side, $corner_style = "bevel") {
  404. list($top, $right, $bottom, $left) = $widths;
  405. $pattern = $this->_get_dash_pattern("dotted", $$side);
  406. switch ($side) {
  407. case "top":
  408. $delta = $top / 2;
  409. case "bottom":
  410. $delta = isset($delta) ? $delta : -$bottom / 2;
  411. $this->_canvas->line($x, $y + $delta, $x + $length, $y + $delta, $color, $$side, $pattern);
  412. break;
  413. case "left":
  414. $delta = $left / 2;
  415. case "right":
  416. $delta = isset($delta) ? $delta : - $right / 2;
  417. $this->_canvas->line($x + $delta, $y, $x + $delta, $y + $length, $color, $$side, $pattern);
  418. break;
  419. default:
  420. return;
  421. }
  422. }
  423. protected function _border_dashed($x, $y, $length, $color, $widths, $side, $corner_style = "bevel") {
  424. list($top, $right, $bottom, $left) = $widths;
  425. $pattern = $this->_get_dash_pattern("dashed", $$side);
  426. switch ($side) {
  427. case "top":
  428. $delta = $top / 2;
  429. case "bottom":
  430. $delta = isset($delta) ? $delta : -$bottom / 2;
  431. $this->_canvas->line($x, $y + $delta, $x + $length, $y + $delta, $color, $$side, $pattern);
  432. break;
  433. case "left":
  434. $delta = $left / 2;
  435. case "right":
  436. $delta = isset($delta) ? $delta : - $right / 2;
  437. $this->_canvas->line($x + $delta, $y, $x + $delta, $y + $length, $color, $$side, $pattern);
  438. break;
  439. default:
  440. return;
  441. }
  442. }
  443. protected function _border_solid($x, $y, $length, $color, $widths, $side, $corner_style = "bevel") {
  444. list($top, $right, $bottom, $left) = $widths;
  445. // All this polygon business is for beveled corners...
  446. switch ($side) {
  447. case "top":
  448. if ( $corner_style === "bevel" ) {
  449. $points = array($x, $y,
  450. $x + $length, $y,
  451. $x + $length - $right, $y + $top,
  452. $x + $left, $y + $top);
  453. $this->_canvas->polygon($points, $color, null, null, true);
  454. } else
  455. $this->_canvas->filled_rectangle($x, $y, $length, $top, $color);
  456. break;
  457. case "bottom":
  458. if ( $corner_style === "bevel" ) {
  459. $points = array($x, $y,
  460. $x + $length, $y,
  461. $x + $length - $right, $y - $bottom,
  462. $x + $left, $y - $bottom);
  463. $this->_canvas->polygon($points, $color, null, null, true);
  464. } else
  465. $this->_canvas->filled_rectangle($x, $y - $bottom, $length, $bottom, $color);
  466. break;
  467. case "left":
  468. if ( $corner_style === "bevel" ) {
  469. $points = array($x, $y,
  470. $x, $y + $length,
  471. $x + $left, $y + $length - $bottom,
  472. $x + $left, $y + $top);
  473. $this->_canvas->polygon($points, $color, null, null, true);
  474. } else
  475. $this->_canvas->filled_rectangle($x, $y, $left, $length, $color);
  476. break;
  477. case "right":
  478. if ( $corner_style === "bevel" ) {
  479. $points = array($x, $y,
  480. $x, $y + $length,
  481. $x - $right, $y + $length - $bottom,
  482. $x - $right, $y + $top);
  483. $this->_canvas->polygon($points, $color, null, null, true);
  484. } else
  485. $this->_canvas->filled_rectangle($x - $right, $y, $right, $length, $color);
  486. break;
  487. default:
  488. return;
  489. }
  490. }
  491. protected function _border_double($x, $y, $length, $color, $widths, $side, $corner_style = "bevel") {
  492. list($top, $right, $bottom, $left) = $widths;
  493. $line_width = $$side / 3;
  494. // We draw the outermost edge first. Points are ordered: outer left,
  495. // outer right, inner right, inner left, or outer top, outer bottom,
  496. // inner bottom, inner top.
  497. switch ($side) {
  498. case "top":
  499. if ( $corner_style === "bevel" ) {
  500. $left_line_width = $left / 3;
  501. $right_line_width = $right / 3;
  502. $points = array($x, $y,
  503. $x + $length, $y,
  504. $x + $length - $right_line_width, $y + $line_width,
  505. $x + $left_line_width, $y + $line_width,);
  506. $this->_canvas->polygon($points, $color, null, null, true);
  507. $points = array($x + $left - $left_line_width, $y + $top - $line_width,
  508. $x + $length - $right + $right_line_width, $y + $top - $line_width,
  509. $x + $length - $right, $y + $top,
  510. $x + $left, $y + $top);
  511. $this->_canvas->polygon($points, $color, null, null, true);
  512. } else {
  513. $this->_canvas->filled_rectangle($x, $y, $length, $line_width, $color);
  514. $this->_canvas->filled_rectangle($x, $y + $top - $line_width, $length, $line_width, $color);
  515. }
  516. break;
  517. case "bottom":
  518. if ( $corner_style === "bevel" ) {
  519. $left_line_width = $left / 3;
  520. $right_line_width = $right / 3;
  521. $points = array($x, $y,
  522. $x + $length, $y,
  523. $x + $length - $right_line_width, $y - $line_width,
  524. $x + $left_line_width, $y - $line_width);
  525. $this->_canvas->polygon($points, $color, null, null, true);
  526. $points = array($x + $left - $left_line_width, $y - $bottom + $line_width,
  527. $x + $length - $right + $right_line_width, $y - $bottom + $line_width,
  528. $x + $length - $right, $y - $bottom,
  529. $x + $left, $y - $bottom);
  530. $this->_canvas->polygon($points, $color, null, null, true);
  531. } else {
  532. $this->_canvas->filled_rectangle($x, $y - $line_width, $length, $line_width, $color);
  533. $this->_canvas->filled_rectangle($x, $y - $bottom, $length, $line_width, $color);
  534. }
  535. break;
  536. case "left":
  537. if ( $corner_style === "bevel" ) {
  538. $top_line_width = $top / 3;
  539. $bottom_line_width = $bottom / 3;
  540. $points = array($x, $y,
  541. $x, $y + $length,
  542. $x + $line_width, $y + $length - $bottom_line_width,
  543. $x + $line_width, $y + $top_line_width);
  544. $this->_canvas->polygon($points, $color, null, null, true);
  545. $points = array($x + $left - $line_width, $y + $top - $top_line_width,
  546. $x + $left - $line_width, $y + $length - $bottom + $bottom_line_width,
  547. $x + $left, $y + $length - $bottom,
  548. $x + $left, $y + $top);
  549. $this->_canvas->polygon($points, $color, null, null, true);
  550. } else {
  551. $this->_canvas->filled_rectangle($x, $y, $line_width, $length, $color);
  552. $this->_canvas->filled_rectangle($x + $left - $line_width, $y, $line_width, $length, $color);
  553. }
  554. break;
  555. case "right":
  556. if ( $corner_style === "bevel" ) {
  557. $top_line_width = $top / 3;
  558. $bottom_line_width = $bottom / 3;
  559. $points = array($x, $y,
  560. $x, $y + $length,
  561. $x - $line_width, $y + $length - $bottom_line_width,
  562. $x - $line_width, $y + $top_line_width);
  563. $this->_canvas->polygon($points, $color, null, null, true);
  564. $points = array($x - $right + $line_width, $y + $top - $top_line_width,
  565. $x - $right + $line_width, $y + $length - $bottom + $bottom_line_width,
  566. $x - $right, $y + $length - $bottom,
  567. $x - $right, $y + $top);
  568. $this->_canvas->polygon($points, $color, null, null, true);
  569. } else {
  570. $this->_canvas->filled_rectangle($x - $line_width, $y, $line_width, $length, $color);
  571. $this->_canvas->filled_rectangle($x - $right, $y, $line_width, $length, $color);
  572. }
  573. break;
  574. default:
  575. return;
  576. }
  577. }
  578. protected function _border_groove($x, $y, $length, $color, $widths, $side, $corner_style = "bevel") {
  579. list($top, $right, $bottom, $left) = $widths;
  580. $half_widths = array($top / 2, $right / 2, $bottom / 2, $left / 2);
  581. $this->_border_inset($x, $y, $length, $color, $half_widths, $side);
  582. switch ($side) {
  583. case "top":
  584. $x += $left / 2;
  585. $y += $top / 2;
  586. $length -= $left / 2 + $right / 2;
  587. break;
  588. case "bottom":
  589. $x += $left / 2;
  590. $y -= $bottom / 2;
  591. $length -= $left / 2 + $right / 2;
  592. break;
  593. case "left":
  594. $x += $left / 2;
  595. $y += $top / 2;
  596. $length -= $top / 2 + $bottom / 2;
  597. break;
  598. case "right":
  599. $x -= $right / 2;
  600. $y += $top / 2;
  601. $length -= $top / 2 + $bottom / 2;
  602. break;
  603. default:
  604. return;
  605. }
  606. $this->_border_outset($x, $y, $length, $color, $half_widths, $side);
  607. }
  608. protected function _border_ridge($x, $y, $length, $color, $widths, $side, $corner_style = "bevel") {
  609. list($top, $right, $bottom, $left) = $widths;
  610. $half_widths = array($top / 2, $right / 2, $bottom / 2, $left / 2);
  611. $this->_border_outset($x, $y, $length, $color, $half_widths, $side);
  612. switch ($side) {
  613. case "top":
  614. $x += $left / 2;
  615. $y += $top / 2;
  616. $length -= $left / 2 + $right / 2;
  617. break;
  618. case "bottom":
  619. $x += $left / 2;
  620. $y -= $bottom / 2;
  621. $length -= $left / 2 + $right / 2;
  622. break;
  623. case "left":
  624. $x += $left / 2;
  625. $y += $top / 2;
  626. $length -= $top / 2 + $bottom / 2;
  627. break;
  628. case "right":
  629. $x -= $right / 2;
  630. $y += $top / 2;
  631. $length -= $top / 2 + $bottom / 2;
  632. break;
  633. default:
  634. return;
  635. }
  636. $this->_border_inset($x, $y, $length, $color, $half_widths, $side);
  637. }
  638. protected function _tint($c) {
  639. if ( !is_numeric($c) )
  640. return $c;
  641. return min(1, $c + 0.16);
  642. }
  643. protected function _shade($c) {
  644. if ( !is_numeric($c) )
  645. return $c;
  646. return max(0, $c - 0.33);
  647. }
  648. protected function _border_inset($x, $y, $length, $color, $widths, $side, $corner_style = "bevel") {
  649. list($top, $right, $bottom, $left) = $widths;
  650. switch ($side) {
  651. case "top":
  652. case "left":
  653. $shade = array_map(array($this, "_shade"), $color);
  654. $this->_border_solid($x, $y, $length, $shade, $widths, $side);
  655. break;
  656. case "bottom":
  657. case "right":
  658. $tint = array_map(array($this, "_tint"), $color);
  659. $this->_border_solid($x, $y, $length, $tint, $widths, $side);
  660. break;
  661. default:
  662. return;
  663. }
  664. }
  665. protected function _border_outset($x, $y, $length, $color, $widths, $side, $corner_style = "bevel") {
  666. list($top, $right, $bottom, $left) = $widths;
  667. switch ($side) {
  668. case "top":
  669. case "left":
  670. $tint = array_map(array($this, "_tint"), $color);
  671. $this->_border_solid($x, $y, $length, $tint, $widths, $side);
  672. break;
  673. case "bottom":
  674. case "right":
  675. $shade = array_map(array($this, "_shade"), $color);
  676. $this->_border_solid($x, $y, $length, $shade, $widths, $side);
  677. break;
  678. default:
  679. return;
  680. }
  681. }
  682. protected function _set_opacity($opacity) {
  683. if ( is_numeric($opacity) && $opacity <= 1.0 && $opacity >= 0.0 ) {
  684. $this->_canvas->set_opacity( $opacity );
  685. }
  686. }
  687. protected function _debug_layout($box, $color = "red", $style = array()) {
  688. $this->_canvas->rectangle($box[0], $box[1], $box[2], $box[3], CSS_Color::parse($color), 0.1, $style);
  689. }
  690. //........................................................................
  691. }