CSS_Color

The WooCommerce PDF Invoices & Packing Slips CSS Color class.

Defined (1)

The class is defined in the following location(s).

/lib/dompdf/include/css_color.cls.php  
  1. class CSS_Color { 
  2. static $cssColorNames = array( 
  3. "aliceblue" => "F0F8FF",  
  4. "antiquewhite" => "FAEBD7",  
  5. "aqua" => "00FFFF",  
  6. "aquamarine" => "7FFFD4",  
  7. "azure" => "F0FFFF",  
  8. "beige" => "F5F5DC",  
  9. "bisque" => "FFE4C4",  
  10. "black" => "000000",  
  11. "blanchedalmond" => "FFEBCD",  
  12. "blue" => "0000FF",  
  13. "blueviolet" => "8A2BE2",  
  14. "brown" => "A52A2A",  
  15. "burlywood" => "DEB887",  
  16. "cadetblue" => "5F9EA0",  
  17. "chartreuse" => "7FFF00",  
  18. "chocolate" => "D2691E",  
  19. "coral" => "FF7F50",  
  20. "cornflowerblue" => "6495ED",  
  21. "cornsilk" => "FFF8DC",  
  22. "crimson" => "DC143C",  
  23. "cyan" => "00FFFF",  
  24. "darkblue" => "00008B",  
  25. "darkcyan" => "008B8B",  
  26. "darkgoldenrod" => "B8860B",  
  27. "darkgray" => "A9A9A9",  
  28. "darkgreen" => "006400",  
  29. "darkgrey" => "A9A9A9",  
  30. "darkkhaki" => "BDB76B",  
  31. "darkmagenta" => "8B008B",  
  32. "darkolivegreen" => "556B2F",  
  33. "darkorange" => "FF8C00",  
  34. "darkorchid" => "9932CC",  
  35. "darkred" => "8B0000",  
  36. "darksalmon" => "E9967A",  
  37. "darkseagreen" => "8FBC8F",  
  38. "darkslateblue" => "483D8B",  
  39. "darkslategray" => "2F4F4F",  
  40. "darkslategrey" => "2F4F4F",  
  41. "darkturquoise" => "00CED1",  
  42. "darkviolet" => "9400D3",  
  43. "deeppink" => "FF1493",  
  44. "deepskyblue" => "00BFFF",  
  45. "dimgray" => "696969",  
  46. "dimgrey" => "696969",  
  47. "dodgerblue" => "1E90FF",  
  48. "firebrick" => "B22222",  
  49. "floralwhite" => "FFFAF0",  
  50. "forestgreen" => "228B22",  
  51. "fuchsia" => "FF00FF",  
  52. "gainsboro" => "DCDCDC",  
  53. "ghostwhite" => "F8F8FF",  
  54. "gold" => "FFD700",  
  55. "goldenrod" => "DAA520",  
  56. "gray" => "808080",  
  57. "green" => "008000",  
  58. "greenyellow" => "ADFF2F",  
  59. "grey" => "808080",  
  60. "honeydew" => "F0FFF0",  
  61. "hotpink" => "FF69B4",  
  62. "indianred" => "CD5C5C",  
  63. "indigo" => "4B0082",  
  64. "ivory" => "FFFFF0",  
  65. "khaki" => "F0E68C",  
  66. "lavender" => "E6E6FA",  
  67. "lavenderblush" => "FFF0F5",  
  68. "lawngreen" => "7CFC00",  
  69. "lemonchiffon" => "FFFACD",  
  70. "lightblue" => "ADD8E6",  
  71. "lightcoral" => "F08080",  
  72. "lightcyan" => "E0FFFF",  
  73. "lightgoldenrodyellow" => "FAFAD2",  
  74. "lightgray" => "D3D3D3",  
  75. "lightgreen" => "90EE90",  
  76. "lightgrey" => "D3D3D3",  
  77. "lightpink" => "FFB6C1",  
  78. "lightsalmon" => "FFA07A",  
  79. "lightseagreen" => "20B2AA",  
  80. "lightskyblue" => "87CEFA",  
  81. "lightslategray" => "778899",  
  82. "lightslategrey" => "778899",  
  83. "lightsteelblue" => "B0C4DE",  
  84. "lightyellow" => "FFFFE0",  
  85. "lime" => "00FF00",  
  86. "limegreen" => "32CD32",  
  87. "linen" => "FAF0E6",  
  88. "magenta" => "FF00FF",  
  89. "maroon" => "800000",  
  90. "mediumaquamarine" => "66CDAA",  
  91. "mediumblue" => "0000CD",  
  92. "mediumorchid" => "BA55D3",  
  93. "mediumpurple" => "9370DB",  
  94. "mediumseagreen" => "3CB371",  
  95. "mediumslateblue" => "7B68EE",  
  96. "mediumspringgreen" => "00FA9A",  
  97. "mediumturquoise" => "48D1CC",  
  98. "mediumvioletred" => "C71585",  
  99. "midnightblue" => "191970",  
  100. "mintcream" => "F5FFFA",  
  101. "mistyrose" => "FFE4E1",  
  102. "moccasin" => "FFE4B5",  
  103. "navajowhite" => "FFDEAD",  
  104. "navy" => "000080",  
  105. "oldlace" => "FDF5E6",  
  106. "olive" => "808000",  
  107. "olivedrab" => "6B8E23",  
  108. "orange" => "FFA500",  
  109. "orangered" => "FF4500",  
  110. "orchid" => "DA70D6",  
  111. "palegoldenrod" => "EEE8AA",  
  112. "palegreen" => "98FB98",  
  113. "paleturquoise" => "AFEEEE",  
  114. "palevioletred" => "DB7093",  
  115. "papayawhip" => "FFEFD5",  
  116. "peachpuff" => "FFDAB9",  
  117. "peru" => "CD853F",  
  118. "pink" => "FFC0CB",  
  119. "plum" => "DDA0DD",  
  120. "powderblue" => "B0E0E6",  
  121. "purple" => "800080",  
  122. "red" => "FF0000",  
  123. "rosybrown" => "BC8F8F",  
  124. "royalblue" => "4169E1",  
  125. "saddlebrown" => "8B4513",  
  126. "salmon" => "FA8072",  
  127. "sandybrown" => "F4A460",  
  128. "seagreen" => "2E8B57",  
  129. "seashell" => "FFF5EE",  
  130. "sienna" => "A0522D",  
  131. "silver" => "C0C0C0",  
  132. "skyblue" => "87CEEB",  
  133. "slateblue" => "6A5ACD",  
  134. "slategray" => "708090",  
  135. "slategrey" => "708090",  
  136. "snow" => "FFFAFA",  
  137. "springgreen" => "00FF7F",  
  138. "steelblue" => "4682B4",  
  139. "tan" => "D2B48C",  
  140. "teal" => "008080",  
  141. "thistle" => "D8BFD8",  
  142. "tomato" => "FF6347",  
  143. "turquoise" => "40E0D0",  
  144. "violet" => "EE82EE",  
  145. "wheat" => "F5DEB3",  
  146. "white" => "FFFFFF",  
  147. "whitesmoke" => "F5F5F5",  
  148. "yellow" => "FFFF00",  
  149. "yellowgreen" => "9ACD32",  
  150. ); 
  151.  
  152. static function parse($color) { 
  153. if ( is_array($color) ) { 
  154. // Assume the array has the right format... 
  155. // FIXME: should/could verify this. 
  156. return $color; 
  157.  
  158. static $cache = array(); 
  159.  
  160. $color = strtolower($color); 
  161.  
  162. if ( isset($cache[$color]) ) { 
  163. return $cache[$color]; 
  164.  
  165. if ( in_array($color, array("transparent", "inherit")) ) { 
  166. return $cache[$color] = $color; 
  167.  
  168. if ( isset(self::$cssColorNames[$color]) ) { 
  169. return $cache[$color] = self::getArray(self::$cssColorNames[$color]); 
  170.  
  171. $length = mb_strlen($color); 
  172.  
  173. // #rgb format 
  174. if ( $length == 4 && $color[0] === "#" ) { 
  175. return $cache[$color] = self::getArray($color[1].$color[1].$color[2].$color[2].$color[3].$color[3]); 
  176.  
  177. // #rrggbb format 
  178. else if ( $length == 7 && $color[0] === "#" ) { 
  179. return $cache[$color] = self::getArray(mb_substr($color, 1, 6)); 
  180.  
  181. // rgb( r, g, b ) / rgbaa( r, g, b, * ) format 
  182. else if ( mb_strpos($color, "rgb") !== false ) { 
  183. $i = mb_strpos($color, "("); 
  184. $j = mb_strpos($color, ")"); 
  185.  
  186. // Bad color value 
  187. if ( $i === false || $j === false ) { 
  188. return null; 
  189.  
  190. $triplet = explode(", ", mb_substr($color, $i+1, $j-$i-1)); 
  191.  
  192. // alpha transparency 
  193. // FIXME: not currently using transparency 
  194. $alpha = 1; 
  195. if ( count( $triplet ) == 4 ) { 
  196. $alpha = (float) ( trim( array_pop( $triplet ) ) ); 
  197. // bad value, set to fully opaque 
  198. if ( $alpha > 1 || $alpha < 0 ) { 
  199. $alpha = 1; 
  200.  
  201. if ( count($triplet) != 3 ) { 
  202. return null; 
  203.  
  204. foreach (array_keys($triplet) as $c) { 
  205. $triplet[$c] = trim($triplet[$c]); 
  206.  
  207. if ( $triplet[$c][mb_strlen($triplet[$c]) - 1] === "%" ) { 
  208. $triplet[$c] = round($triplet[$c] * 2.55); 
  209.  
  210. return $cache[$color] = self::getArray(vsprintf("%02X%02X%02X", $triplet)); 
  211.  
  212.  
  213. // cmyk( c, m, y, k ) format 
  214. // http://www.w3.org/TR/css3-gcpm/#cmyk-colors 
  215. else if ( mb_strpos($color, "cmyk") !== false ) { 
  216. $i = mb_strpos($color, "("); 
  217. $j = mb_strpos($color, ")"); 
  218.  
  219. // Bad color value 
  220. if ( $i === false || $j === false ) { 
  221. return null; 
  222.  
  223. $values = explode(", ", mb_substr($color, $i+1, $j-$i-1)); 
  224.  
  225. if ( count($values) != 4 ) { 
  226. return null; 
  227.  
  228. foreach ($values as &$c) { 
  229. $c = floatval(trim($c)); 
  230. if ($c > 1.0) $c = 1.0; 
  231. if ($c < 0.0) $c = 0.0; 
  232.  
  233. return $cache[$color] = self::getArray($values); 
  234.  
  235. return null; 
  236.  
  237. static function getArray($color) { 
  238. $c = array(null, null, null, null, "hex" => null); 
  239.  
  240. if (is_array($color)) { 
  241. $c = $color; 
  242. $c["c"] = $c[0]; 
  243. $c["m"] = $c[1]; 
  244. $c["y"] = $c[2]; 
  245. $c["k"] = $c[3]; 
  246. $c["hex"] = "cmyk($c[0], $c[1], $c[2], $c[3])"; 
  247. else { 
  248. $c[0] = hexdec(mb_substr($color, 0, 2)) / 0xff; 
  249. $c[1] = hexdec(mb_substr($color, 2, 2)) / 0xff; 
  250. $c[2] = hexdec(mb_substr($color, 4, 2)) / 0xff; 
  251. $c["r"] = $c[0]; 
  252. $c["g"] = $c[1]; 
  253. $c["b"] = $c[2]; 
  254. $c["hex"] = "#$color"; 
  255.  
  256. return $c;