PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/application/helpers/dompdf/include/style.cls.php

https://bitbucket.org/hlevine/myclientbase-south-african-version
PHP | 1948 lines | 1518 code | 124 blank | 306 comment | 91 complexity | da452342010fcdee2ac6c103b7592cc1 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * DOMPDF - PHP5 HTML to PDF renderer
  4. *
  5. * File: $RCSfile: style.cls.php,v $
  6. * Created on: 2004-06-01
  7. *
  8. * Copyright (c) 2004 - Benj Carson <benjcarson@digitaljunkies.ca>
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this library in the file LICENSE.LGPL; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  23. * 02111-1307 USA
  24. *
  25. * Alternatively, you may distribute this software under the terms of the
  26. * PHP License, version 3.0 or later. A copy of this license should have
  27. * been distributed with this file in the file LICENSE.PHP . If this is not
  28. * the case, you can obtain a copy at http://www.php.net/license/3_0.txt.
  29. *
  30. * The latest version of DOMPDF might be available at:
  31. * http://www.digitaljunkies.ca/dompdf
  32. *
  33. * @link http://www.digitaljunkies.ca/dompdf
  34. * @copyright 2004 Benj Carson
  35. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  36. * @contributor Helmut Tischer <htischer@weihenstephan.org>
  37. * @package dompdf
  38. * @version 0.5.1
  39. *
  40. * Changes
  41. * @contributor Helmut Tischer <htischer@weihenstephan.org>
  42. * @version 0.5.1.htischer.20090507
  43. * - Fix px to pt conversion according to DOMPDF_DPI
  44. * - Recognize css styles with !important attribute, and store !important attribute within style
  45. * - Propagate !important by inherit and sequences of styles with merge.
  46. * - Add missing style property cache flushes for consistent rendering, e.g. on explicte assignments
  47. * - Add important set/get for access from outside of class
  48. * - Fix font_family search path with multiple fonts list in css attribute:
  49. * On missing font, do not immediately fall back to default font,
  50. * but try subsequent fonts in search chain. Only when none found, explicitely
  51. * refer to default font.
  52. * - Allow read of background individual properties
  53. * - Add support for individual styles background-position, background-attachment, background-repeat
  54. * - Complete style components of list-style
  55. * - Add support for combined styles in addition to individual styles
  56. * like {border: red 1px solid;}, { border-width: 1px;}, { border-right-color: red; } ...
  57. * for font, background
  58. * - Propagate attributes including !important from combined style to individual component
  59. * for border, background, padding, margin, font, list_style
  60. * - Refactor common code of border, background, padding, margin, font, list_style
  61. * - Refactor common code of list-style-image and background-image
  62. * - special treatment of css images "none" instead of url(...), otherwise would prepend string "none" with path name
  63. * - Added comments
  64. * - Added debug output
  65. * @contributor Helmut Tischer <htischer@weihenstephan.org>
  66. * @version dompdf_trunk_with_helmut_mods.20090524
  67. * - Allow superflous white space and string delimiter in font search path.
  68. * - Restore lost change of default font of above
  69. * @version 20090610
  70. * - Allow absolute path from web server root as html image reference
  71. * - More accurate handling of css property cache consistency
  72. */
  73. /* $Id: style.cls.php,v 1.22 2008-03-12 06:35:43 benjcarson Exp $ */
  74. /**
  75. * Represents CSS properties.
  76. *
  77. * The Style class is responsible for handling and storing CSS properties.
  78. * It includes methods to resolve colours and lengths, as well as getters &
  79. * setters for many CSS properites.
  80. *
  81. * Actual CSS parsing is performed in the {@link Stylesheet} class.
  82. *
  83. * @package dompdf
  84. */
  85. class Style {
  86. /**
  87. * Default font size, in points.
  88. *
  89. * @var float
  90. */
  91. static $default_font_size = 12;
  92. /**
  93. * Default line height, as a fraction of the font size.
  94. *
  95. * @var float
  96. */
  97. static $default_line_height = 1.2;
  98. /**
  99. * List of all inline types. Should really be a constant.
  100. *
  101. * @var array
  102. */
  103. static $INLINE_TYPES = array("inline");
  104. /**
  105. * List of all block types. Should really be a constant.
  106. *
  107. * @var array
  108. */
  109. static $BLOCK_TYPES = array("block","inline-block", "table-cell", "list-item");
  110. /**
  111. * List of all table types. Should really be a constant.
  112. *
  113. * @var array;
  114. */
  115. static $TABLE_TYPES = array("table", "inline-table");
  116. /**
  117. * List of valid border styles. Should also really be a constant.
  118. *
  119. * @var array
  120. */
  121. static $BORDER_STYLES = array("none", "hidden", "dotted", "dashed", "solid",
  122. "double", "groove", "ridge", "inset", "outset");
  123. /**
  124. * Default style values.
  125. *
  126. * @link http://www.w3.org/TR/CSS21/propidx.html
  127. *
  128. * @var array
  129. */
  130. static protected $_defaults = null;
  131. /**
  132. * List of inherited properties
  133. *
  134. * @link http://www.w3.org/TR/CSS21/propidx.html
  135. *
  136. * @var array
  137. */
  138. static protected $_inherited = null;
  139. /**
  140. * The stylesheet this style belongs to
  141. *
  142. * @see Stylesheet
  143. * @var Stylesheet
  144. */
  145. protected $_stylesheet; // stylesheet this style is attached to
  146. /**
  147. * Main array of all CSS properties & values
  148. *
  149. * @var array
  150. */
  151. protected $_props;
  152. /* var instead of protected would allow access outside of class */
  153. protected $_important_props;
  154. /**
  155. * Cached property values
  156. *
  157. * @var array
  158. */
  159. protected $_prop_cache;
  160. /**
  161. * Font size of parent element in document tree. Used for relative font
  162. * size resolution.
  163. *
  164. * @var float
  165. */
  166. protected $_parent_font_size; // Font size of parent element
  167. // private members
  168. /**
  169. * True once the font size is resolved absolutely
  170. *
  171. * @var bool
  172. */
  173. private $__font_size_calculated; // Cache flag
  174. /**
  175. * Class constructor
  176. *
  177. * @param Stylesheet $stylesheet the stylesheet this Style is associated with.
  178. */
  179. function __construct(Stylesheet $stylesheet) {
  180. $this->_props = array();
  181. $this->_important_props = array();
  182. $this->_stylesheet = $stylesheet;
  183. $this->_parent_font_size = null;
  184. $this->__font_size_calculated = false;
  185. if ( !isset(self::$_defaults) ) {
  186. // Shorthand
  187. $d =& self::$_defaults;
  188. // All CSS 2.1 properties, and their default values
  189. $d["azimuth"] = "center";
  190. $d["background_attachment"] = "scroll";
  191. $d["background_color"] = "transparent";
  192. $d["background_image"] = "none";
  193. $d["background_position"] = "0% 0%";
  194. $d["background_repeat"] = "repeat";
  195. $d["background"] = "";
  196. $d["border_collapse"] = "separate";
  197. $d["border_color"] = "";
  198. $d["border_spacing"] = "0";
  199. $d["border_style"] = "";
  200. $d["border_top"] = "";
  201. $d["border_right"] = "";
  202. $d["border_bottom"] = "";
  203. $d["border_left"] = "";
  204. $d["border_top_color"] = "";
  205. $d["border_right_color"] = "";
  206. $d["border_bottom_color"] = "";
  207. $d["border_left_color"] = "";
  208. $d["border_top_style"] = "none";
  209. $d["border_right_style"] = "none";
  210. $d["border_bottom_style"] = "none";
  211. $d["border_left_style"] = "none";
  212. $d["border_top_width"] = "medium";
  213. $d["border_right_width"] = "medium";
  214. $d["border_bottom_width"] = "medium";
  215. $d["border_left_width"] = "medium";
  216. $d["border_width"] = "medium";
  217. $d["border"] = "";
  218. $d["bottom"] = "auto";
  219. $d["caption_side"] = "top";
  220. $d["clear"] = "none";
  221. $d["clip"] = "auto";
  222. $d["color"] = "#000000";
  223. $d["content"] = "normal";
  224. $d["counter_increment"] = "none";
  225. $d["counter_reset"] = "none";
  226. $d["cue_after"] = "none";
  227. $d["cue_before"] = "none";
  228. $d["cue"] = "";
  229. $d["cursor"] = "auto";
  230. $d["direction"] = "ltr";
  231. $d["display"] = "inline";
  232. $d["elevation"] = "level";
  233. $d["empty_cells"] = "show";
  234. $d["float"] = "none";
  235. $d["font_family"] = "serif";
  236. $d["font_size"] = "medium";
  237. $d["font_style"] = "normal";
  238. $d["font_variant"] = "normal";
  239. $d["font_weight"] = "normal";
  240. $d["font"] = "";
  241. $d["height"] = "auto";
  242. $d["left"] = "auto";
  243. $d["letter_spacing"] = "normal";
  244. $d["line_height"] = "normal";
  245. $d["list_style_image"] = "none";
  246. $d["list_style_position"] = "outside";
  247. $d["list_style_type"] = "disc";
  248. $d["list_style"] = "";
  249. $d["margin_right"] = "0";
  250. $d["margin_left"] = "0";
  251. $d["margin_top"] = "0";
  252. $d["margin_bottom"] = "0";
  253. $d["margin"] = "";
  254. $d["max_height"] = "none";
  255. $d["max_width"] = "none";
  256. $d["min_height"] = "0";
  257. $d["min_width"] = "0";
  258. $d["orphans"] = "2";
  259. $d["outline_color"] = "invert";
  260. $d["outline_style"] = "none";
  261. $d["outline_width"] = "medium";
  262. $d["outline"] = "";
  263. $d["overflow"] = "visible";
  264. $d["padding_top"] = "0";
  265. $d["padding_right"] = "0";
  266. $d["padding_bottom"] = "0";
  267. $d["padding_left"] = "0";
  268. $d["padding"] = "";
  269. $d["page_break_after"] = "auto";
  270. $d["page_break_before"] = "auto";
  271. $d["page_break_inside"] = "auto";
  272. $d["pause_after"] = "0";
  273. $d["pause_before"] = "0";
  274. $d["pause"] = "";
  275. $d["pitch_range"] = "50";
  276. $d["pitch"] = "medium";
  277. $d["play_during"] = "auto";
  278. $d["position"] = "static";
  279. $d["quotes"] = "";
  280. $d["richness"] = "50";
  281. $d["right"] = "auto";
  282. $d["speak_header"] = "once";
  283. $d["speak_numeral"] = "continuous";
  284. $d["speak_punctuation"] = "none";
  285. $d["speak"] = "normal";
  286. $d["speech_rate"] = "medium";
  287. $d["stress"] = "50";
  288. $d["table_layout"] = "auto";
  289. $d["text_align"] = "left";
  290. $d["text_decoration"] = "none";
  291. $d["text_indent"] = "0";
  292. $d["text_transform"] = "none";
  293. $d["top"] = "auto";
  294. $d["unicode_bidi"] = "normal";
  295. $d["vertical_align"] = "baseline";
  296. $d["visibility"] = "visible";
  297. $d["voice_family"] = "";
  298. $d["volume"] = "medium";
  299. $d["white_space"] = "normal";
  300. $d["widows"] = "2";
  301. $d["width"] = "auto";
  302. $d["word_spacing"] = "normal";
  303. $d["z_index"] = "auto";
  304. // Properties that inherit by default
  305. self::$_inherited = array("azimuth",
  306. "border_collapse",
  307. "border_spacing",
  308. "caption_side",
  309. "color",
  310. "cursor",
  311. "direction",
  312. "elevation",
  313. "empty_cells",
  314. "font_family",
  315. "font_size",
  316. "font_style",
  317. "font_variant",
  318. "font_weight",
  319. "font",
  320. "letter_spacing",
  321. "line_height",
  322. "list_style_image",
  323. "list_style_position",
  324. "list_style_type",
  325. "list_style",
  326. "orphans",
  327. "page_break_inside",
  328. "pitch_range",
  329. "pitch",
  330. "quotes",
  331. "richness",
  332. "speak_header",
  333. "speak_numeral",
  334. "speak_punctuation",
  335. "speak",
  336. "speech_rate",
  337. "stress",
  338. "text_align",
  339. "text_indent",
  340. "text_transform",
  341. "visibility",
  342. "voice_family",
  343. "volume",
  344. "white_space",
  345. "widows",
  346. "word_spacing");
  347. }
  348. }
  349. /**
  350. * "Destructor": forcibly free all references held by this object
  351. */
  352. function dispose() {
  353. unset($this->_stylesheet);
  354. }
  355. /**
  356. * returns the {@link Stylesheet} this Style is associated with.
  357. *
  358. * @return Stylesheet
  359. */
  360. function get_stylesheet() { return $this->_stylesheet; }
  361. /**
  362. * Converts any CSS length value into an absolute length in points.
  363. *
  364. * length_in_pt() takes a single length (e.g. '1em') or an array of
  365. * lengths and returns an absolute length. If an array is passed, then
  366. * the return value is the sum of all elements.
  367. *
  368. * If a reference size is not provided, the default font size is used
  369. * ({@link Style::$default_font_size}).
  370. *
  371. * @param float|array $length the length or array of lengths to resolve
  372. * @param float $ref_size an absolute reference size to resolve percentage lengths
  373. * @return float
  374. */
  375. function length_in_pt($length, $ref_size = null) {
  376. if ( !is_array($length) )
  377. $length = array($length);
  378. if ( !isset($ref_size) )
  379. $ref_size = self::$default_font_size;
  380. $ret = 0;
  381. foreach ($length as $l) {
  382. if ( $l === "auto" )
  383. return "auto";
  384. if ( $l === "none" )
  385. return "none";
  386. // Assume numeric values are already in points
  387. if ( is_numeric($l) ) {
  388. $ret += $l;
  389. continue;
  390. }
  391. if ( $l === "normal" ) {
  392. $ret += $ref_size;
  393. continue;
  394. }
  395. // Border lengths
  396. if ( $l === "thin" ) {
  397. $ret += 0.5;
  398. continue;
  399. }
  400. if ( $l === "medium" ) {
  401. $ret += 1.5;
  402. continue;
  403. }
  404. if ( $l === "thick" ) {
  405. $ret += 2.5;
  406. continue;
  407. }
  408. if ( ($i = mb_strpos($l, "pt")) !== false ) {
  409. $ret += mb_substr($l, 0, $i);
  410. continue;
  411. }
  412. if ( ($i = mb_strpos($l, "px")) !== false ) {
  413. $ret += ( mb_substr($l, 0, $i) * 72 ) / DOMPDF_DPI;
  414. continue;
  415. }
  416. if ( ($i = mb_strpos($l, "em")) !== false ) {
  417. $ret += mb_substr($l, 0, $i) * $this->__get("font_size");
  418. continue;
  419. }
  420. // FIXME: em:ex ratio?
  421. if ( ($i = mb_strpos($l, "ex")) !== false ) {
  422. $ret += mb_substr($l, 0, $i) * $this->__get("font_size");
  423. continue;
  424. }
  425. if ( ($i = mb_strpos($l, "%")) !== false ) {
  426. $ret += mb_substr($l, 0, $i)/100 * $ref_size;
  427. continue;
  428. }
  429. if ( ($i = mb_strpos($l, "in")) !== false ) {
  430. $ret += mb_substr($l, 0, $i) * 72;
  431. continue;
  432. }
  433. if ( ($i = mb_strpos($l, "cm")) !== false ) {
  434. $ret += mb_substr($l, 0, $i) * 72 / 2.54;
  435. continue;
  436. }
  437. if ( ($i = mb_strpos($l, "mm")) !== false ) {
  438. $ret += mb_substr($l, 0, $i) * 72 / 25.4;
  439. continue;
  440. }
  441. if ( ($i = mb_strpos($l, "pc")) !== false ) {
  442. $ret += mb_substr($l, 0, $i) / 12;
  443. continue;
  444. }
  445. // Bogus value
  446. $ret += $ref_size;
  447. }
  448. return $ret;
  449. }
  450. /**
  451. * Set inherited properties in this style using values in $parent
  452. *
  453. * @param Style $parent
  454. */
  455. function inherit(Style $parent) {
  456. // Set parent font size
  457. $this->_parent_font_size = $parent->get_font_size();
  458. foreach (self::$_inherited as $prop) {
  459. //inherit the !important property also.
  460. //if local property is also !important, don't inherit.
  461. if ( isset($parent->_props[$prop]) &&
  462. ( !isset($this->_props[$prop]) ||
  463. ( isset($parent->_important_props[$prop]) && !isset($this->_important_props[$prop]) )
  464. )
  465. ) {
  466. if ( isset($parent->_important_props[$prop]) ) {
  467. $this->_important_props[$prop] = true;
  468. }
  469. //see __set and __get, on all assignments clear cache!
  470. $this->_prop_cache[$prop] = null;
  471. $this->_props[$prop] = $parent->_props[$prop];
  472. }
  473. }
  474. foreach (array_keys($this->_props) as $prop) {
  475. if ( $this->_props[$prop] == "inherit" ) {
  476. if ( isset($parent->_important_props[$prop]) ) {
  477. $this->_important_props[$prop] = true;
  478. }
  479. //do not assign direct, but
  480. //implicite assignment through __set, redirect to specialized, get value with __get
  481. //This is for computing defaults if the parent setting is also missing.
  482. //Therefore do not directly assign the value without __set
  483. //set _important_props before that to be able to propagate.
  484. //see __set and __get, on all assignments clear cache!
  485. //$this->_prop_cache[$prop] = null;
  486. //$this->_props[$prop] = $parent->_props[$prop];
  487. //props_set for more obvious explicite assignment not implemented, because
  488. //too many implicite uses.
  489. // $this->props_set($prop, $parent->$prop);
  490. $this->$prop = $parent->$prop;
  491. }
  492. }
  493. return $this;
  494. }
  495. /**
  496. * Override properties in this style with those in $style
  497. *
  498. * @param Style $style
  499. */
  500. function merge(Style $style) {
  501. //treat the !important attribute
  502. //if old rule has !important attribute, override with new rule only if
  503. //the new rule is also !important
  504. foreach($style->_props as $prop => $val ) {
  505. if (isset($style->_important_props[$prop])) {
  506. $this->_important_props[$prop] = true;
  507. //see __set and __get, on all assignments clear cache!
  508. $this->_prop_cache[$prop] = null;
  509. $this->_props[$prop] = $val;
  510. } else if ( !isset($this->_important_props[$prop]) ) {
  511. //see __set and __get, on all assignments clear cache!
  512. $this->_prop_cache[$prop] = null;
  513. $this->_props[$prop] = $val;
  514. }
  515. }
  516. if ( isset($style->_props["font_size"]) )
  517. $this->__font_size_calculated = false;
  518. }
  519. /**
  520. * Returns an array(r, g, b, "r"=> r, "g"=>g, "b"=>b, "hex"=>"#rrggbb")
  521. * based on the provided CSS colour value.
  522. *
  523. * @param string $colour
  524. * @return array
  525. */
  526. function munge_colour($colour) {
  527. if ( is_array($colour) )
  528. // Assume the array has the right format...
  529. // FIXME: should/could verify this.
  530. return $colour;
  531. $r = 0;
  532. $g = 0;
  533. $b = 0;
  534. // Handle colour names
  535. switch ($colour) {
  536. case "maroon":
  537. $r = 0x80;
  538. break;
  539. case "red":
  540. $r = 0xff;
  541. break;
  542. case "orange":
  543. $r = 0xff;
  544. $g = 0xa5;
  545. break;
  546. case "yellow":
  547. $r = 0xff;
  548. $g = 0xff;
  549. break;
  550. case "olive":
  551. $r = 0x80;
  552. $g = 0x80;
  553. break;
  554. case "purple":
  555. $r = 0x80;
  556. $b = 0x80;
  557. break;
  558. case "fuchsia":
  559. $r = 0xff;
  560. $b = 0xff;
  561. break;
  562. case "white":
  563. $r = $g = $b = 0xff;
  564. break;
  565. case "lime":
  566. $g = 0xff;
  567. break;
  568. case "green":
  569. $g = 0x80;
  570. break;
  571. case "navy":
  572. $b = 0x80;
  573. break;
  574. case "blue":
  575. $b = 0xff;
  576. break;
  577. case "aqua":
  578. $g = 0xff;
  579. $b = 0xff;
  580. break;
  581. case "teal":
  582. $g = 0x80;
  583. $b = 0x80;
  584. break;
  585. case "black":
  586. break;
  587. case "sliver":
  588. $r = $g = $b = 0xc0;
  589. break;
  590. case "gray":
  591. case "grey":
  592. $r = $g = $b = 0x80;
  593. break;
  594. case "transparent":
  595. return "transparent";
  596. default:
  597. if ( mb_strlen($colour) == 4 && $colour{0} == "#" ) {
  598. // #rgb format
  599. $r = hexdec($colour{1} . $colour{1});
  600. $g = hexdec($colour{2} . $colour{2});
  601. $b = hexdec($colour{3} . $colour{3});
  602. } else if ( mb_strlen($colour) == 7 && $colour{0} == "#" ) {
  603. // #rrggbb format
  604. $r = hexdec(mb_substr($colour, 1, 2));
  605. $g = hexdec(mb_substr($colour, 3, 2));
  606. $b = hexdec(mb_substr($colour, 5, 2));
  607. } else if ( mb_strpos($colour, "rgb") !== false ) {
  608. // rgb( r,g,b ) format
  609. $i = mb_strpos($colour, "(");
  610. $j = mb_strpos($colour, ")");
  611. // Bad colour value
  612. if ($i === false || $j === false)
  613. return null;
  614. $triplet = explode(",", mb_substr($colour, $i+1, $j-$i-1));
  615. if (count($triplet) != 3)
  616. return null;
  617. foreach (array_keys($triplet) as $c) {
  618. $triplet[$c] = trim($triplet[$c]);
  619. if ( $triplet[$c]{mb_strlen($triplet[$c]) - 1} == "%" )
  620. $triplet[$c] = round($triplet[$c] * 0.255);
  621. }
  622. list($r, $g, $b) = $triplet;
  623. } else {
  624. // Who knows?
  625. return null;
  626. }
  627. // Clip to 0 - 1
  628. $r = $r < 0 ? 0 : ($r > 255 ? 255 : $r);
  629. $g = $g < 0 ? 0 : ($g > 255 ? 255 : $g);
  630. $b = $b < 0 ? 0 : ($b > 255 ? 255 : $b);
  631. break;
  632. }
  633. // Form array
  634. $arr = array(0 => $r / 0xff, 1 => $g / 0xff, 2 => $b / 0xff,
  635. "r"=>$r / 0xff, "g"=>$g / 0xff, "b"=>$b / 0xff,
  636. "hex" => sprintf("#%02X%02X%02X", $r, $g, $b));
  637. return $arr;
  638. }
  639. /**
  640. * Alias for {@link Style::munge_colour()}
  641. *
  642. * @param string $color
  643. * @return array
  644. */
  645. function munge_color($color) { return $this->munge_colour($color); }
  646. /* direct access to _important_props array from outside would work only when declared as
  647. * 'var $_important_props;' instead of 'protected $_important_props;'
  648. * Don't call _set/__get on missing attribute. Therefore need a special access.
  649. * Assume that __set will be also called when this is called, so do not check validity again.
  650. * Only created, if !important exists -> always set true.
  651. */
  652. function important_set($prop) {
  653. $prop = str_replace("-", "_", $prop);
  654. $this->_important_props[$prop] = true;
  655. }
  656. function important_get($prop) {
  657. isset($this->_important_props[$prop]);
  658. }
  659. /**
  660. * PHP5 overloaded setter
  661. *
  662. * This function along with {@link Style::__get()} permit a user of the
  663. * Style class to access any (CSS) property using the following syntax:
  664. * <code>
  665. * Style->margin_top = "1em";
  666. * echo (Style->margin_top);
  667. * </code>
  668. *
  669. * __set() automatically calls the provided set function, if one exists,
  670. * otherwise it sets the property directly. Typically, __set() is not
  671. * called directly from outside of this class.
  672. *
  673. * On each modification clear cache to return accurate setting.
  674. * Also affects direct settings not using __set
  675. * For easier finding all assignments, attempted to allowing only explicite assignment:
  676. * Very many uses, e.g. frame_reflower.cls.php -> for now leave as it is
  677. * function __set($prop, $val) {
  678. * throw new DOMPDF_Exception("Implicite replacement of assignment by __set. Not good.");
  679. * }
  680. * function props_set($prop, $val) { ... }
  681. *
  682. * @param string $prop the property to set
  683. * @param mixed $val the value of the property
  684. *
  685. */
  686. function __set($prop, $val) {
  687. global $_dompdf_warnings;
  688. $prop = str_replace("-", "_", $prop);
  689. $this->_prop_cache[$prop] = null;
  690. if ( !isset(self::$_defaults[$prop]) ) {
  691. $_dompdf_warnings[] = "'$prop' is not a valid CSS2 property.";
  692. return;
  693. }
  694. if ( $prop !== "content" && is_string($val) && mb_strpos($val, "url") === false ) {
  695. $val = mb_strtolower(trim(str_replace(array("\n", "\t"), array(" "), $val)));
  696. $val = preg_replace("/([0-9]+) (pt|px|pc|em|ex|in|cm|mm|%)/S", "\\1\\2", $val);
  697. }
  698. $method = "set_$prop";
  699. if ( method_exists($this, $method) )
  700. $this->$method($val);
  701. else
  702. $this->_props[$prop] = $val;
  703. }
  704. /**
  705. * PHP5 overloaded getter
  706. *
  707. * Along with {@link Style::__set()} __get() provides access to all CSS
  708. * properties directly. Typically __get() is not called directly outside
  709. * of this class.
  710. *
  711. * On each modification clear cache to return accurate setting.
  712. * Also affects direct settings not using __set
  713. *
  714. * @param string $prop
  715. * @return mixed
  716. */
  717. function __get($prop) {
  718. if ( !isset(self::$_defaults[$prop]) )
  719. throw new DOMPDF_Exception("'$prop' is not a valid CSS2 property.");
  720. if ( isset($this->_prop_cache[$prop]) && $this->_prop_cache[$prop] != null)
  721. return $this->_prop_cache[$prop];
  722. $method = "get_$prop";
  723. // Fall back on defaults if property is not set
  724. if ( !isset($this->_props[$prop]) )
  725. $this->_props[$prop] = self::$_defaults[$prop];
  726. if ( method_exists($this, $method) )
  727. return $this->_prop_cache[$prop] = $this->$method();
  728. return $this->_prop_cache[$prop] = $this->_props[$prop];
  729. }
  730. /**
  731. * Getter for the 'font-family' CSS property.
  732. *
  733. * Uses the {@link Font_Metrics} class to resolve the font family into an
  734. * actual font file.
  735. *
  736. * @link http://www.w3.org/TR/CSS21/fonts.html#propdef-font-family
  737. * @return string
  738. */
  739. function get_font_family() {
  740. $DEBUGCSS=DEBUGCSS; //=DEBUGCSS; Allow override of global setting for ad hoc debug
  741. // Select the appropriate font. First determine the subtype, then check
  742. // the specified font-families for a candidate.
  743. // Resolve font-weight
  744. $weight = $this->__get("font_weight");
  745. if ( is_numeric($weight) ) {
  746. if ( $weight < 600 )
  747. $weight = "normal";
  748. else
  749. $weight = "bold";
  750. } else if ( $weight == "bold" || $weight == "bolder" ) {
  751. $weight = "bold";
  752. } else {
  753. $weight = "normal";
  754. }
  755. // Resolve font-style
  756. $font_style = $this->__get("font_style");
  757. if ( $weight == "bold" && ($font_style == "italic" || $font_style == "oblique") )
  758. $subtype = "bold_italic";
  759. else if ( $weight == "bold" && $font_style != "italic" && $font_style != "oblique" )
  760. $subtype = "bold";
  761. else if ( $weight != "bold" && ($font_style == "italic" || $font_style == "oblique") )
  762. $subtype = "italic";
  763. else
  764. $subtype = "normal";
  765. // Resolve the font family
  766. if ($DEBUGCSS) {
  767. print "<pre>[get_font_family:";
  768. print '('.$this->_props["font_family"].'.'.$font_style.'.'.$this->__get("font_weight").'.'.$weight.'.'.$subtype.')';
  769. }
  770. $families = explode(",", $this->_props["font_family"]);
  771. $families = array_map('trim',$families);
  772. reset($families);
  773. $font = null;
  774. while ( current($families) ) {
  775. list(,$family) = each($families);
  776. //remove leading and trailing string delimiters, e.g. on font names with spaces;
  777. //remove leading and trailing whitespace
  778. $family=trim($family," \t\n\r\x0B\"'");
  779. if ($DEBUGCSS) print '('.$family.')';
  780. $font = Font_Metrics::get_font($family, $subtype);
  781. if ( $font ) {
  782. if ($DEBUGCSS) print '('.$font.")get_font_family]\n</pre>";
  783. return $font;
  784. }
  785. }
  786. $family = null;
  787. if ($DEBUGCSS) print '(default)';
  788. $font = Font_Metrics::get_font($family, $subtype);
  789. if ( $font ) {
  790. if ($DEBUGCSS) print '('.$font.")get_font_family]\n</pre>";
  791. return $font;
  792. }
  793. throw new DOMPDF_Exception("Unable to find a suitable font replacement for: '" . $this->_props["font_family"] ."'");
  794. }
  795. /**
  796. * Returns the resolved font size, in points
  797. *
  798. * @link http://www.w3.org/TR/CSS21/fonts.html#propdef-font-size
  799. * @return float
  800. */
  801. function get_font_size() {
  802. if ( $this->__font_size_calculated )
  803. return $this->_props["font_size"];
  804. if ( !isset($this->_props["font_size"]) )
  805. $fs = self::$_defaults["font_size"];
  806. else
  807. $fs = $this->_props["font_size"];
  808. if ( !isset($this->_parent_font_size) )
  809. $this->_parent_font_size = self::$default_font_size;
  810. switch ($fs) {
  811. case "xx-small":
  812. $fs = 3/5 * $this->_parent_font_size;
  813. break;
  814. case "x-small":
  815. $fs = 3/4 * $this->_parent_font_size;
  816. break;
  817. case "smaller":
  818. case "small":
  819. $fs = 8/9 * $this->_parent_font_size;
  820. break;
  821. case "medium":
  822. $fs = $this->_parent_font_size;
  823. break;
  824. case "larger":
  825. case "large":
  826. $fs = 6/5 * $this->_parent_font_size;
  827. break;
  828. case "x-large":
  829. $fs = 3/2 * $this->_parent_font_size;
  830. break;
  831. case "xx-large":
  832. $fs = 2/1 * $this->_parent_font_size;
  833. break;
  834. default:
  835. break;
  836. }
  837. // Ensure relative sizes resolve to something
  838. if ( ($i = mb_strpos($fs, "em")) !== false )
  839. $fs = mb_substr($fs, 0, $i) * $this->_parent_font_size;
  840. else if ( ($i = mb_strpos($fs, "ex")) !== false )
  841. $fs = mb_substr($fs, 0, $i) * $this->_parent_font_size;
  842. else
  843. $fs = $this->length_in_pt($fs);
  844. //see __set and __get, on all assignments clear cache!
  845. $this->_prop_cache["font_size"] = null;
  846. $this->_props["font_size"] = $fs;
  847. $this->__font_size_calculated = true;
  848. return $this->_props["font_size"];
  849. }
  850. /**
  851. * @link http://www.w3.org/TR/CSS21/text.html#propdef-word-spacing
  852. * @return float
  853. */
  854. function get_word_spacing() {
  855. if ( $this->_props["word_spacing"] === "normal" )
  856. return 0;
  857. return $this->_props["word_spacing"];
  858. }
  859. /**
  860. * @link http://www.w3.org/TR/CSS21/visudet.html#propdef-line-height
  861. * @return float
  862. */
  863. function get_line_height() {
  864. if ( $this->_props["line_height"] === "normal" )
  865. return self::$default_line_height * $this->get_font_size();
  866. if ( is_numeric($this->_props["line_height"]) )
  867. return $this->length_in_pt( $this->_props["line_height"] . "%", $this->get_font_size());
  868. return $this->length_in_pt( $this->_props["line_height"], $this->get_font_size() );
  869. }
  870. /**
  871. * Returns the colour as an array
  872. *
  873. * The array has the following format:
  874. * <code>array(r,g,b, "r" => r, "g" => g, "b" => b, "hex" => "#rrggbb")</code>
  875. *
  876. * @link http://www.w3.org/TR/CSS21/colors.html#propdef-color
  877. * @return array
  878. */
  879. function get_color() {
  880. return $this->munge_color( $this->_props["color"] );
  881. }
  882. /**
  883. * Returns the background colour as an array
  884. *
  885. * The returned array has the same format as {@link Style::get_color()}
  886. *
  887. * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-color
  888. * @return array
  889. */
  890. function get_background_color() {
  891. return $this->munge_color( $this->_props["background_color"] );
  892. }
  893. /**
  894. * Returns the background position as an array
  895. *
  896. * The returned array has the following format:
  897. * <code>array(x,y, "x" => x, "y" => y)</code>
  898. *
  899. * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-position
  900. * @return array
  901. */
  902. function get_background_position() {
  903. $tmp = explode(" ", $this->_props["background_position"]);
  904. switch ($tmp[0]) {
  905. case "left":
  906. $x = "0%";
  907. break;
  908. case "right":
  909. $x = "100%";
  910. break;
  911. case "top":
  912. $y = "0%";
  913. break;
  914. case "bottom":
  915. $y = "100%";
  916. break;
  917. case "center":
  918. $x = "50%";
  919. $y = "50%";
  920. break;
  921. default:
  922. $x = $tmp[0];
  923. break;
  924. }
  925. if ( isset($tmp[1]) ) {
  926. switch ($tmp[1]) {
  927. case "left":
  928. $x = "0%";
  929. break;
  930. case "right":
  931. $x = "100%";
  932. break;
  933. case "top":
  934. $y = "0%";
  935. break;
  936. case "bottom":
  937. $y = "100%";
  938. break;
  939. case "center":
  940. if ( $tmp[0] == "left" || $tmp[0] == "right" || $tmp[0] == "center" )
  941. $y = "50%";
  942. else
  943. $x = "50%";
  944. break;
  945. default:
  946. $y = $tmp[1];
  947. break;
  948. }
  949. } else {
  950. $y = "50%";
  951. }
  952. if ( !isset($x) )
  953. $x = "0%";
  954. if ( !isset($y) )
  955. $y = "0%";
  956. return array( 0 => $x, "x" => $x,
  957. 1 => $y, "y" => $y );
  958. }
  959. /**
  960. * Returns the background as it is currently stored
  961. *
  962. * (currently anyway only for completeness.
  963. * not used for further processing)
  964. *
  965. * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-attachment
  966. * @return string
  967. */
  968. function get_background_attachment() {
  969. return $this->_props["background_attachment"];
  970. }
  971. /**
  972. * Returns the background_repeat as it is currently stored
  973. *
  974. * (currently anyway only for completeness.
  975. * not used for further processing)
  976. *
  977. * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-repeat
  978. * @return string
  979. */
  980. function get_background_repeat() {
  981. return $this->_props["background_repeat"];
  982. }
  983. /**
  984. * Returns the background as it is currently stored
  985. *
  986. * (currently anyway only for completeness.
  987. * not used for further processing, but the individual get_background_xxx)
  988. *
  989. * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background
  990. * @return string
  991. */
  992. function get_background() {
  993. return $this->_props["background"];
  994. }
  995. /**#@+
  996. * Returns the border colour as an array
  997. *
  998. * See {@link Style::get_color()}
  999. *
  1000. * @link http://www.w3.org/TR/CSS21/box.html#border-color-properties
  1001. * @return array
  1002. */
  1003. function get_border_top_color() {
  1004. if ( $this->_props["border_top_color"] === "" ) {
  1005. //see __set and __get, on all assignments clear cache!
  1006. $this->_prop_cache["border_top_color"] = null;
  1007. $this->_props["border_top_color"] = $this->__get("color");
  1008. }
  1009. return $this->munge_color($this->_props["border_top_color"]);
  1010. }
  1011. function get_border_right_color() {
  1012. if ( $this->_props["border_right_color"] === "" ) {
  1013. //see __set and __get, on all assignments clear cache!
  1014. $this->_prop_cache["border_right_color"] = null;
  1015. $this->_props["border_right_color"] = $this->__get("color");
  1016. }
  1017. return $this->munge_color($this->_props["border_right_color"]);
  1018. }
  1019. function get_border_bottom_color() {
  1020. if ( $this->_props["border_bottom_color"] === "" ) {
  1021. //see __set and __get, on all assignments clear cache!
  1022. $this->_prop_cache["border_bottom_color"] = null;
  1023. $this->_props["border_bottom_color"] = $this->__get("color");
  1024. }
  1025. return $this->munge_color($this->_props["border_bottom_color"]);;
  1026. }
  1027. function get_border_left_color() {
  1028. if ( $this->_props["border_left_color"] === "" ) {
  1029. //see __set and __get, on all assignments clear cache!
  1030. $this->_prop_cache["border_left_color"] = null;
  1031. $this->_props["border_left_color"] = $this->__get("color");
  1032. }
  1033. return $this->munge_color($this->_props["border_left_color"]);
  1034. }
  1035. /**#@-*/
  1036. /**#@+
  1037. * Returns the border width, as it is currently stored
  1038. *
  1039. * @link http://www.w3.org/TR/CSS21/box.html#border-width-properties
  1040. * @return float|string
  1041. */
  1042. function get_border_top_width() {
  1043. $style = $this->__get("border_top_style");
  1044. return $style !== "none" && $style !== "hidden" ? $this->length_in_pt($this->_props["border_top_width"]) : 0;
  1045. }
  1046. function get_border_right_width() {
  1047. $style = $this->__get("border_right_style");
  1048. return $style !== "none" && $style !== "hidden" ? $this->length_in_pt($this->_props["border_right_width"]) : 0;
  1049. }
  1050. function get_border_bottom_width() {
  1051. $style = $this->__get("border_bottom_style");
  1052. return $style !== "none" && $style !== "hidden" ? $this->length_in_pt($this->_props["border_bottom_width"]) : 0;
  1053. }
  1054. function get_border_left_width() {
  1055. $style = $this->__get("border_left_style");
  1056. return $style !== "none" && $style !== "hidden" ? $this->length_in_pt($this->_props["border_left_width"]) : 0;
  1057. }
  1058. /**#@-*/
  1059. /**
  1060. * Return an array of all border properties.
  1061. *
  1062. * The returned array has the following structure:
  1063. * <code>
  1064. * array("top" => array("width" => [border-width],
  1065. * "style" => [border-style],
  1066. * "color" => [border-color (array)]),
  1067. * "bottom" ... )
  1068. * </code>
  1069. *
  1070. * @return array
  1071. */
  1072. function get_border_properties() {
  1073. return array("top" => array("width" => $this->__get("border_top_width"),
  1074. "style" => $this->__get("border_top_style"),
  1075. "color" => $this->__get("border_top_color")),
  1076. "bottom" => array("width" => $this->__get("border_bottom_width"),
  1077. "style" => $this->__get("border_bottom_style"),
  1078. "color" => $this->__get("border_bottom_color")),
  1079. "right" => array("width" => $this->__get("border_right_width"),
  1080. "style" => $this->__get("border_right_style"),
  1081. "color" => $this->__get("border_right_color")),
  1082. "left" => array("width" => $this->__get("border_left_width"),
  1083. "style" => $this->__get("border_left_style"),
  1084. "color" => $this->__get("border_left_color")));
  1085. }
  1086. /**
  1087. * Return a single border property
  1088. *
  1089. * @return mixed
  1090. */
  1091. protected function _get_border($side) {
  1092. $color = $this->__get("border_" . $side . "_color");
  1093. return $this->__get("border_" . $side . "_width") . " " .
  1094. $this->__get("border_" . $side . "_style") . " " . $color["hex"];
  1095. }
  1096. /**#@+
  1097. * Return full border properties as a string
  1098. *
  1099. * Border properties are returned just as specified in CSS:
  1100. * <pre>[width] [style] [color]</pre>
  1101. * e.g. "1px solid blue"
  1102. *
  1103. * @link http://www.w3.org/TR/CSS21/box.html#border-shorthand-properties
  1104. * @return string
  1105. */
  1106. function get_border_top() { return $this->_get_border("top"); }
  1107. function get_border_right() { return $this->_get_border("right"); }
  1108. function get_border_bottom() { return $this->_get_border("bottom"); }
  1109. function get_border_left() { return $this->_get_border("left"); }
  1110. /**#@-*/
  1111. /**
  1112. * Returns border spacing as an array
  1113. *
  1114. * The array has the format (h_space,v_space)
  1115. *
  1116. * @link http://www.w3.org/TR/CSS21/tables.html#propdef-border-spacing
  1117. * @return array
  1118. */
  1119. function get_border_spacing() {
  1120. return explode(" ", $this->_props["border_spacing"]);
  1121. }
  1122. /*==============================*/
  1123. /*
  1124. !important attribute
  1125. For basic functionality of the !important attribute with overloading
  1126. of several styles of an element, changes in inherit(), merge() and _parse_properties()
  1127. are sufficient [helpers var $_important_props, __construct(), important_set(), important_get()]
  1128. Only for combined attributes extra treatment needed. See below.
  1129. div { border: 1px red; }
  1130. div { border: solid; } // Not combined! Only one occurence of same style per context
  1131. //
  1132. div { border: 1px red; }
  1133. div a { border: solid; } // Adding to border style ok by inheritance
  1134. //
  1135. div { border-style: solid; } // Adding to border style ok because of different styles
  1136. div { border: 1px red; }
  1137. //
  1138. div { border-style: solid; !important} // border: overrides, even though not !important
  1139. div { border: 1px dashed red; }
  1140. //
  1141. div { border: 1px red; !important }
  1142. div a { border-style: solid; } // Need to override because not set
  1143. Special treatment:
  1144. At individual property like border-top-width need to check whether overriding value is also !important.
  1145. Also store the !important condition for later overrides.
  1146. Since not known who is initiating the override, need to get passed !importan as parameter.
  1147. !important Paramter taken as in the original style in the css file.
  1148. When poperty border !important given, do not mark subsets like border_style as important. Only
  1149. individual properties.
  1150. Note:
  1151. Setting individual property directly from css with e.g. set_border_top_style() is not needed, because
  1152. missing set funcions handled by a generic handler __set(), including the !important.
  1153. Setting individual property of as sub-property is handled below.
  1154. Implementation see at _set_style_side_type()
  1155. Callers _set_style_sides_type(), _set_style_type, _set_style_type_important()
  1156. Related functionality for background, padding, margin, font, list_style
  1157. */
  1158. /* Generalized set function for individual attribute of combined style.
  1159. * With check for !important
  1160. * Applicable for background, border, padding, margin, font, list_style
  1161. * Note: $type has a leading underscore (or is empty), the others not.
  1162. */
  1163. protected function _set_style_side_type($style,$side,$type,$val,$important) {
  1164. if ( !isset($this->_important_props[$style.'_'.$side.$type]) || $important) {
  1165. //see __set and __get, on all assignments clear cache!
  1166. $this->_prop_cache[$style.'_'.$side.$type] = null;
  1167. if ($important) {
  1168. $this->_important_props[$style.'_'.$side.$type] = true;
  1169. }
  1170. $this->_props[$style.'_'.$side.$type] = $val;
  1171. }
  1172. }
  1173. protected function _set_style_sides_type($style,$top,$right,$bottom,$left,$type,$important) {
  1174. $this->_set_style_side_type($style,'top',$type,$top,$important);
  1175. $this->_set_style_side_type($style,'right',$type,$right,$important);
  1176. $this->_set_style_side_type($style,'bottom',$type,$bottom,$important);
  1177. $this->_set_style_side_type($style,'left',$type,$left,$important);
  1178. }
  1179. protected function _set_style_type($style,$type,$val,$important) {
  1180. $arr = explode(" ", $val);
  1181. switch (count($arr)) {
  1182. case 1:
  1183. $this->_set_style_sides_type($style,$arr[0],$arr[0],$arr[0],$arr[0],$type,$important);
  1184. break;
  1185. case 2:
  1186. $this->_set_style_sides_type($style,$arr[0],$arr[1],$arr[0],$arr[1],$type,$important);
  1187. break;
  1188. case 3:
  1189. $this->_set_style_sides_type($style,$arr[0],$arr[1],$arr[1],$arr[2],$type,$important);
  1190. break;
  1191. case 4:
  1192. $this->_set_style_sides_type($style,$arr[0],$arr[1],$arr[2],$arr[3],$type,$important);
  1193. break;
  1194. default:
  1195. break;
  1196. }
  1197. //see __set and __get, on all assignments clear cache!
  1198. $this->_prop_cache[$style.$type] = null;
  1199. $this->_props[$style.$type] = $val;
  1200. }
  1201. protected function _set_style_type_important($style,$type,$val) {
  1202. $this->_set_style_type($style,$type,$val,isset($this->_important_props[$style.$type]));
  1203. }
  1204. /* Anyway only called if _important matches and is assigned
  1205. * E.g. _set_style_side_type($style,$side,'',str_replace("none", "0px", $val),isset($this->_important_props[$style.'_'.$side]));
  1206. */
  1207. protected function _set_style_side_width_important($style,$side,$val) {
  1208. //see __set and __get, on all assignments clear cache!
  1209. $this->_prop_cache[$style.'_'.$side] = null;
  1210. $this->_props[$style.'_'.$side] = str_replace("none", "0px", $val);
  1211. }
  1212. protected function _set_style($style,$val,$important) {
  1213. if ( !isset($this->_important_props[$style]) || $important) {
  1214. if ($important) {
  1215. $this->_important_props[$style] = true;
  1216. }
  1217. //see __set and __get, on all assignments clear cache!
  1218. $this->_prop_cache[$style] = null;
  1219. $this->_props[$style] = $val;
  1220. }
  1221. }
  1222. protected function _image($val) {
  1223. $DEBUGCSS=DEBUGCSS;
  1224. if ( mb_strpos($val, "url") === false ) {
  1225. $path = "none"; //Don't resolve no image -> otherwise would prefix path and no longer recognize as none
  1226. }
  1227. else {
  1228. $val = preg_replace("/url\(['\"]?([^'\")]+)['\"]?\)/","\\1", trim($val));
  1229. // Resolve the url now in the context of the current stylesheet
  1230. $parsed_url = explode_url($val);
  1231. if ( $parsed_url["protocol"] == "" && $this->_stylesheet->get_protocol() == "" ) {
  1232. if ($parsed_url["path"]{0} == '/' || $parsed_url["path"]{0} == '\\' ) {
  1233. $path = $_SERVER["DOCUMENT_ROOT"].'/';
  1234. } else {
  1235. $path = $this->_stylesheet->get_base_path();
  1236. }
  1237. $path .= $parsed_url["path"] . $parsed_url["file"];
  1238. $path = dompdf_realpath($path);
  1239. } else {
  1240. $path = build_url($this->_stylesheet->get_protocol(),
  1241. $this->_stylesheet->get_host(),
  1242. $this->_stylesheet->get_base_path(),
  1243. $val);
  1244. }
  1245. }
  1246. if ($DEBUGCSS) {
  1247. print "<pre>[_image\n";
  1248. print_r($parsed_url);
  1249. print $this->_stylesheet->get_protocol()."\n".$this->_stylesheet->get_base_path()."\n".$path."\n";
  1250. print "_image]</pre>";;
  1251. }
  1252. return $path;
  1253. }
  1254. /*======================*/
  1255. /**
  1256. * Sets colour
  1257. *
  1258. * The colour parameter can be any valid CSS colour value
  1259. *
  1260. * @link http://www.w3.org/TR/CSS21/colors.html#propdef-color
  1261. * @param string $colour
  1262. */
  1263. function set_color($colour) {
  1264. $col = $this->munge_colour($colour);
  1265. if ( is_null($col) )
  1266. $col = self::$_defaults["color"];
  1267. //see __set and __get, on all assignments clear cache, not needed on direct set through __set
  1268. $this->_prop_cache["color"] = null;
  1269. $this->_props["color"] = $col["hex"];
  1270. }
  1271. /**
  1272. * Sets the background colour
  1273. *
  1274. * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-color
  1275. * @param string $colour
  1276. */
  1277. function set_background_color($colour) {
  1278. $col = $this->munge_colour($colour);
  1279. if ( is_null($col) )
  1280. $col = self::$_defaults["background_color"];
  1281. //see __set and __get, on all assignments clear cache, not needed on direct set through __set
  1282. $this->_prop_cache["background_color"] = null;
  1283. $this->_props["background_color"] = is_array($col) ? $col["hex"] : $col;
  1284. }
  1285. /**
  1286. * Set the background image url
  1287. *
  1288. * @link http://www.w3.org/TR/CSS21/colors.html#background-properties
  1289. * @param string $url
  1290. */
  1291. function set_background_image($val) {
  1292. //see __set and __get, on all assignments clear cache, not needed on direct set through __set
  1293. $this->_prop_cache["background_image"] = null;
  1294. $this->_props["background_image"] = $this->_image($val);
  1295. }
  1296. /**
  1297. * Sets the background repeat
  1298. *
  1299. * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-repeat
  1300. * @param string $val
  1301. */
  1302. function set_background_repeat($val) {
  1303. if ( is_null($val) )
  1304. $val = self::$_defaults["background_repeat"];
  1305. //see __set and __get, on all assignments clear cache, not needed on direct set through __set
  1306. $this->_prop_cache["background_repeat"] = null;
  1307. $this->_props["background_repeat"] = $val;
  1308. }
  1309. /**
  1310. * Sets the background attachment
  1311. *
  1312. * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-attachment
  1313. * @param string $val
  1314. */
  1315. function set_background_attachment($val) {
  1316. if ( is_null($val) )
  1317. $val = self::$_defaults["background_attachment"];
  1318. //see __set and __get, on all assignments clear cache, not needed on direct set through __set
  1319. $this->_prop_cache["background_attachment"] = null;
  1320. $this->_props["background_attachment"] = $val;
  1321. }
  1322. /**
  1323. * Sets the background position
  1324. *
  1325. * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-position
  1326. * @param string $val
  1327. */
  1328. function set_background_position($val) {
  1329. if ( is_null($val) )
  1330. $val = self::$_defaults["background_position"];
  1331. //see __set and __get, on all assignments clear cache, not needed on direct set through __set
  1332. $this->_prop_cache["background_position"] = null;
  1333. $this->_props["background_position"] = $val;
  1334. }
  1335. /**
  1336. * Sets the background - combined options
  1337. *
  1338. * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background
  1339. * @param string $val
  1340. */
  1341. function set_background($val) {
  1342. $col = null;
  1343. $pos = array();
  1344. $tmp = explode(" ", $val);
  1345. $important = isset($this->_important_props["background"]);
  1346. foreach($tmp as $attr) {
  1347. if (mb_substr($attr, 0, 3) == "url" || $attr == "none") {
  1348. $this->_set_style("background_image", $this->_image($attr), $important);
  1349. } else if ($attr == "fixed" || $attr == "scroll") {
  1350. $this->_set_style("background_attachment", $attr, $important);
  1351. } else if ($attr == "repeat" || $attr == "repeat-x" || $attr == "repeat-y" || $attr == "no-repeat") {
  1352. $this->_set_style("background_repeat", $attr, $important);
  1353. } else if (($col = $this->munge_color($attr)) != null ) {
  1354. $this->_set_style("background_color", is_a

Large files files are truncated, but you can click here to view the full file