function bestColor($bg, $lt = '#ffffff', $dk = '#000000') { if (empty($bg)) { $bg = $lt; } $bg = str_replace('#', '', $bg); $dk = str_replace('#', '', $dk); $base = new CSS_Color($bg); return '#' . $base->calcFG($bg, $dk); }
function render(Frame $frame) { $style = $frame->get_style(); $node = $frame->get_node(); list($x, $y, $w, $h) = $frame->get_border_box(); $this->_set_opacity($frame->get_opacity($style->opacity)); if ($node->nodeName === "html") { die('a'); } if ($node->nodeName === "body") { $h = $frame->get_containing_block("h") - $style->length_in_pt(array($style->margin_top, $style->border_top_width, $style->border_bottom_width, $style->margin_bottom), $style->width); if (($bg = $style->_dompdf_paper_color) !== "white") { $ph = $this->_canvas->get_height(); $pw = $this->_canvas->get_width(); $this->_canvas->filled_rectangle(0, 0, $pw, $ph, CSS_Color::parse($bg)); } } // Handle anchors & links if ($node->nodeName === "a" && ($href = $node->getAttribute("href"))) { $this->_canvas->add_link($href, $x, $y, $w, $h); } // Draw our background, border and content list($tl, $tr, $br, $bl) = $style->get_computed_border_radius($w, $h); if ($tl + $tr + $br + $bl > 0) { $this->_canvas->clipping_roundrectangle($x, $y, $w, $h, $tl, $tr, $br, $bl); } if (($bg = $style->background_color) !== "transparent") { $this->_canvas->filled_rectangle($x, $y, $w, $h, $bg); } if (($url = $style->background_image) && $url !== "none") { $this->_background_image($url, $x, $y, $w, $h, $style); } if ($tl + $tr + $br + $bl > 0) { $this->_canvas->clipping_end(); } $border_box = array($x, $y, $w, $h); $this->_render_border($frame, $border_box); $this->_render_outline($frame, $border_box); if (DEBUG_LAYOUT && DEBUG_LAYOUT_BLOCKS) { $this->_debug_layout($frame->get_border_box(), "red"); if (DEBUG_LAYOUT_PADDINGBOX) { $this->_debug_layout($frame->get_padding_box(), "red", array(0.5, 0.5)); } } if (DEBUG_LAYOUT && DEBUG_LAYOUT_LINES && $frame->get_decorator()) { foreach ($frame->get_decorator()->get_line_boxes() as $line) { $frame->_debug_layout(array($line->x, $line->y, $line->w, $line->h), "orange"); } } }
/** * Returns an array(r, g, b, "r"=> r, "g"=>g, "b"=>b, "hex"=>"#rrggbb") * based on the provided CSS color value. * * @param string $color * @return array */ function munge_color($color) { return CSS_Color::parse($color); }
protected function _debug_layout($box, $color = "red", $style = array()) { $this->_canvas->rectangle($box[0], $box[1], $box[2], $box[3], CSS_Color::parse($color), 0.1, $style); }