* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ namespace Dompdf\FrameDecorator; use Dompdf\Dompdf; use Dompdf\Frame; use Dompdf\LineBox; /** * Decorates frames for block layout * * @access private * @package dompdf */ class Block extends AbstractFrameDecorator { /** * Current line index * * @var int */ protected $_cl; /** * The block's line boxes * * @var LineBox[] */ protected $_line_boxes; /** * Block constructor. * @param Frame $frame * @param Dompdf $dompdf */ function __construct(Frame $frame, Dompdf $dompdf) { parent::__construct($frame, $dompdf); $this->_line_boxes = array(new LineBox($this)); $this->_cl = 0; } /** * */ function reset() { parent::reset(); $this->_line_boxes = array(new LineBox($this)); $this->_cl = 0; } /** * @return LineBox */ function get_current_line_box() { return $this->_line_boxes[$this->_cl]; } /** * @return integer */ function get_current_line_number() { return $this->_cl; } /** * @return LineBox[] */ function get_line_boxes() { return $this->_line_boxes; } /** * @param integer $line_number * @return integer */ function set_current_line_number($line_number) { $line_boxes_count = count($this->_line_boxes); $cl = max(min($line_number, $line_boxes_count), 0); return ($this->_cl = $cl); } /** * @param integer $i */ function clear_line($i) { if (isset($this->_line_boxes[$i])) { unset($this->_line_boxes[$i]); } } /** * @param Frame $frame */ function add_frame_to_line(Frame $frame) { if (!$frame->is_in_flow()) { return; } $style = $frame->get_style(); $frame->set_containing_line($this->_line_boxes[$this->_cl]); /* // Adds a new line after a block, only if certain conditions are met if ((($frame instanceof Inline && $frame->get_node()->nodeName !== "br") || $frame instanceof Text && trim($frame->get_text())) && ($frame->get_prev_sibling() && $frame->get_prev_sibling()->get_style()->display === "block" && $this->_line_boxes[$this->_cl]->w > 0 )) { $this->maximize_line_height( $style->length_in_pt($style->line_height), $frame ); $this->add_line(); // Add each child of the inline frame to the line individually foreach ($frame->get_children() as $child) $this->add_frame_to_line( $child ); } else*/ // Handle inline frames (which are effectively wrappers) if ($frame instanceof Inline) { // Handle line breaks if ($frame->get_node()->nodeName === "br") { $this->maximize_line_height($style->length_in_pt($style->line_height), $frame); $this->add_line(true); } return; } // Trim leading text if this is an empty line. Kinda a hack to put it here, // but what can you do... if ($this->get_current_line_box()->w == 0 && $frame->is_text_node() && !$frame->is_pre() ) { $frame->set_text(ltrim($frame->get_text())); $frame->recalculate_width(); } $w = $frame->get_margin_width(); // FIXME: Why? Doesn't quite seem to be the correct thing to do, // but does appear to be necessary. Hack to handle wrapped white space? if ($w == 0 && $frame->get_node()->nodeName !== "hr") { return; } // Debugging code: /* Helpers::pre_r("\n