| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package dompdf |
| 4 |
* @link https://github.com/dompdf/dompdf |
| 5 |
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
| 6 |
*/ |
| 7 |
namespace Dompdf\Renderer; |
| 8 |
|
| 9 |
use Dompdf\Frame; |
| 10 |
use Dompdf\FrameDecorator\Block as BlockFrameDecorator; |
| 11 |
use Dompdf\Helpers; |
| 12 |
|
| 13 |
/** |
| 14 |
* Renders block frames |
| 15 |
* |
| 16 |
* @package dompdf |
| 17 |
*/ |
| 18 |
class Block extends AbstractRenderer |
| 19 |
{ |
| 20 |
|
| 21 |
/** |
| 22 |
* @param Frame $frame |
| 23 |
*/ |
| 24 |
function render(Frame $frame) |
| 25 |
{ |
| 26 |
$style = $frame->get_style(); |
| 27 |
$node = $frame->get_node(); |
| 28 |
$dompdf = $this->_dompdf; |
| 29 |
|
| 30 |
$this->_set_opacity($frame->get_opacity($style->opacity)); |
| 31 |
|
| 32 |
[$x, $y, $w, $h] = $frame->get_border_box(); |
| 33 |
|
| 34 |
if ($node->nodeName === "body") { |
| 35 |
// Margins should be fully resolved at this point |
| 36 |
$mt = $style->margin_top; |
| 37 |
$mb = $style->margin_bottom; |
| 38 |
$h = $frame->get_containing_block("h") - $mt - $mb; |
| 39 |
} |
| 40 |
|
| 41 |
$border_box = [$x, $y, $w, $h]; |
| 42 |
|
| 43 |
// Draw our background, border and content |
| 44 |
$this->_render_background($frame, $border_box); |
| 45 |
$this->_render_border($frame, $border_box); |
| 46 |
$this->_render_outline($frame, $border_box); |
| 47 |
|
| 48 |
// Handle anchors & links |
| 49 |
if ($node->nodeName === "a" && $href = $node->getAttribute("href")) { |
| 50 |
$href = Helpers::build_url($dompdf->getProtocol(), $dompdf->getBaseHost(), $dompdf->getBasePath(), $href) ?? $href; |
| 51 |
$this->_canvas->add_link($href, $x, $y, $w, $h); |
| 52 |
} |
| 53 |
|
| 54 |
$id = $frame->get_node()->getAttribute("id"); |
| 55 |
if (strlen($id) > 0) { |
| 56 |
$this->_canvas->add_named_dest($id); |
| 57 |
} |
| 58 |
|
| 59 |
$this->debugBlockLayout($frame, "red", false); |
| 60 |
} |
| 61 |
|
| 62 |
protected function debugBlockLayout(Frame $frame, ?string $color, bool $lines = false): void |
| 63 |
{ |
| 64 |
$options = $this->_dompdf->getOptions(); |
| 65 |
$debugLayout = $options->getDebugLayout(); |
| 66 |
|
| 67 |
if (!$debugLayout) { |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
if ($color && $options->getDebugLayoutBlocks()) { |
| 72 |
$this->_debug_layout($frame->get_border_box(), $color); |
| 73 |
|
| 74 |
if ($options->getDebugLayoutPaddingBox()) { |
| 75 |
$this->_debug_layout($frame->get_padding_box(), $color, [0.5, 0.5]); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
if ($lines && $options->getDebugLayoutLines() && $frame instanceof BlockFrameDecorator) { |
| 80 |
[$cx, , $cw] = $frame->get_content_box(); |
| 81 |
|
| 82 |
foreach ($frame->get_line_boxes() as $line) { |
| 83 |
$lw = $cw - $line->left - $line->right; |
| 84 |
$this->_debug_layout([$cx + $line->left, $line->y, $lw, $line->h], "orange"); |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
|