コード例 #1
0
ファイル: Block.php プロジェクト: BrunoDeBarros/dompdf
 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 === "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);
     }
     // Handle anchors & links
     if ($node->nodeName === "a" && ($href = $node->getAttribute("href"))) {
         $href = Helpers::build_url($this->_dompdf->getProtocol(), $this->_dompdf->getBaseHost(), $this->_dompdf->getBasePath(), $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 ($this->_dompdf->getOptions()->getDebugLayout() && $this->_dompdf->getOptions()->getDebugLayoutBlocks()) {
         $this->_debug_layout($frame->get_border_box(), "red");
         if ($this->_dompdf->getOptions()->getDebugLayoutPaddingBox()) {
             $this->_debug_layout($frame->get_padding_box(), "red", array(0.5, 0.5));
         }
     }
     if ($this->_dompdf->getOptions()->getDebugLayout() && $this->_dompdf->getOptions()->getDebugLayoutLines() && $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");
         }
     }
 }
コード例 #2
0
ファイル: TableCell.php プロジェクト: AlexandreSGV/siteentec
 function render(Frame $frame)
 {
     $style = $frame->get_style();
     if (trim($frame->get_node()->nodeValue) === "" && $style->empty_cells === "hide") {
         return;
     }
     $this->_set_opacity($frame->get_opacity($style->opacity));
     list($x, $y, $w, $h) = $frame->get_border_box();
     // Draw our background, border and content
     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);
     }
     $table = Table::find_parent_table($frame);
     if ($table->get_style()->border_collapse !== "collapse") {
         $this->_render_border($frame);
         $this->_render_outline($frame);
         return;
     }
     // The collapsed case is slightly complicated...
     // @todo Add support for outlines here
     $cellmap = $table->get_cellmap();
     $cells = $cellmap->get_spanned_cells($frame);
     $num_rows = $cellmap->get_num_rows();
     $num_cols = $cellmap->get_num_cols();
     // Determine the top row spanned by this cell
     $i = $cells["rows"][0];
     $top_row = $cellmap->get_row($i);
     // Determine if this cell borders on the bottom of the table.  If so,
     // then we draw its bottom border.  Otherwise the next row down will
     // draw its top border instead.
     if (in_array($num_rows - 1, $cells["rows"])) {
         $draw_bottom = true;
         $bottom_row = $cellmap->get_row($num_rows - 1);
     } else {
         $draw_bottom = false;
     }
     // Draw the horizontal borders
     foreach ($cells["columns"] as $j) {
         $bp = $cellmap->get_border_properties($i, $j);
         $y = $top_row["y"] - $bp["top"]["width"] / 2;
         $col = $cellmap->get_column($j);
         $x = $col["x"] - $bp["left"]["width"] / 2;
         $w = $col["used-width"] + ($bp["left"]["width"] + $bp["right"]["width"]) / 2;
         if ($bp["top"]["style"] !== "none" && $bp["top"]["width"] > 0) {
             $widths = array($bp["top"]["width"], $bp["right"]["width"], $bp["bottom"]["width"], $bp["left"]["width"]);
             $method = "_border_" . $bp["top"]["style"];
             $this->{$method}($x, $y, $w, $bp["top"]["color"], $widths, "top", "square");
         }
         if ($draw_bottom) {
             $bp = $cellmap->get_border_properties($num_rows - 1, $j);
             if ($bp["bottom"]["style"] === "none" || $bp["bottom"]["width"] <= 0) {
                 continue;
             }
             $y = $bottom_row["y"] + $bottom_row["height"] + $bp["bottom"]["width"] / 2;
             $widths = array($bp["top"]["width"], $bp["right"]["width"], $bp["bottom"]["width"], $bp["left"]["width"]);
             $method = "_border_" . $bp["bottom"]["style"];
             $this->{$method}($x, $y, $w, $bp["bottom"]["color"], $widths, "bottom", "square");
         }
     }
     $j = $cells["columns"][0];
     $left_col = $cellmap->get_column($j);
     if (in_array($num_cols - 1, $cells["columns"])) {
         $draw_right = true;
         $right_col = $cellmap->get_column($num_cols - 1);
     } else {
         $draw_right = false;
     }
     // Draw the vertical borders
     foreach ($cells["rows"] as $i) {
         $bp = $cellmap->get_border_properties($i, $j);
         $x = $left_col["x"] - $bp["left"]["width"] / 2;
         $row = $cellmap->get_row($i);
         $y = $row["y"] - $bp["top"]["width"] / 2;
         $h = $row["height"] + ($bp["top"]["width"] + $bp["bottom"]["width"]) / 2;
         if ($bp["left"]["style"] !== "none" && $bp["left"]["width"] > 0) {
             $widths = array($bp["top"]["width"], $bp["right"]["width"], $bp["bottom"]["width"], $bp["left"]["width"]);
             $method = "_border_" . $bp["left"]["style"];
             $this->{$method}($x, $y, $h, $bp["left"]["color"], $widths, "left", "square");
         }
         if ($draw_right) {
             $bp = $cellmap->get_border_properties($i, $num_cols - 1);
             if ($bp["right"]["style"] === "none" || $bp["right"]["width"] <= 0) {
                 continue;
             }
             $x = $right_col["x"] + $right_col["used-width"] + $bp["right"]["width"] / 2;
             $widths = array($bp["top"]["width"], $bp["right"]["width"], $bp["bottom"]["width"], $bp["left"]["width"]);
             $method = "_border_" . $bp["right"]["style"];
             $this->{$method}($x, $y, $h, $bp["right"]["color"], $widths, "right", "square");
         }
     }
 }
コード例 #3
0
ファイル: Image.php プロジェクト: BrunoDeBarros/dompdf
 function render(Frame $frame)
 {
     // Render background & borders
     $style = $frame->get_style();
     $cb = $frame->get_containing_block();
     list($x, $y, $w, $h) = $frame->get_border_box();
     $this->_set_opacity($frame->get_opacity($style->opacity));
     list($tl, $tr, $br, $bl) = $style->get_computed_border_radius($w, $h);
     $has_border_radius = $tl + $tr + $br + $bl > 0;
     if ($has_border_radius) {
         $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 ($has_border_radius) {
         $this->_canvas->clipping_end();
     }
     $this->_render_border($frame);
     $this->_render_outline($frame);
     list($x, $y) = $frame->get_padding_box();
     $x += $style->length_in_pt($style->padding_left, $cb["w"]);
     $y += $style->length_in_pt($style->padding_top, $cb["h"]);
     $w = $style->length_in_pt($style->width, $cb["w"]);
     $h = $style->length_in_pt($style->height, $cb["h"]);
     if ($has_border_radius) {
         list($wt, $wr, $wb, $wl) = array($style->border_top_width, $style->border_right_width, $style->border_bottom_width, $style->border_left_width);
         // we have to get the "inner" radius
         if ($tl > 0) {
             $tl -= ($wt + $wl) / 2;
         }
         if ($tr > 0) {
             $tr -= ($wt + $wr) / 2;
         }
         if ($br > 0) {
             $br -= ($wb + $wr) / 2;
         }
         if ($bl > 0) {
             $bl -= ($wb + $wl) / 2;
         }
         $this->_canvas->clipping_roundrectangle($x, $y, $w, $h, $tl, $tr, $br, $bl);
     }
     $src = $frame->get_image_url();
     $alt = null;
     if (Cache::is_broken($src) && ($alt = $frame->get_node()->getAttribute("alt"))) {
         $font = $style->font_family;
         $size = $style->font_size;
         $spacing = $style->word_spacing;
         $this->_canvas->text($x, $y, $alt, $font, $size, $style->color, $spacing);
     } else {
         $this->_canvas->image($src, $x, $y, $w, $h, $style->image_resolution);
     }
     if ($has_border_radius) {
         $this->_canvas->clipping_end();
     }
     if ($msg = $frame->get_image_msg()) {
         $parts = preg_split("/\\s*\n\\s*/", $msg);
         $height = 10;
         $_y = $alt ? $y + $h - count($parts) * $height : $y;
         foreach ($parts as $i => $_part) {
             $this->_canvas->text($x, $_y + $i * $height, $_part, "times", $height * 0.8, array(0.5, 0.5, 0.5));
         }
     }
     if ($this->_dompdf->getOptions()->getDebugLayout() && $this->_dompdf->getOptions()->getDebugLayoutBlocks()) {
         $this->_debug_layout($frame->get_border_box(), "blue");
         if ($this->_dompdf->getOptions()->getDebugLayoutPaddingBox()) {
             $this->_debug_layout($frame->get_padding_box(), "blue", array(0.5, 0.5));
         }
     }
 }
コード例 #4
0
 /**
  * @return array
  */
 function get_border_box()
 {
     return $this->_frame->get_border_box();
 }