function add_frame_to_line(Frame $frame) { // Handle inline frames (which are effectively wrappers) if ($frame instanceof Inline_Frame_Decorator) { // Handle line breaks if ($frame->get_node()->nodeName == "br") { $this->maximize_line_height($frame->get_style()->length_in_pt($frame->get_style()->line_height)); $this->add_line(); return; } // Add each child of the inline frame to the line individually foreach ($frame->get_children() as $child) { $this->add_frame_to_line($child); } return; } // Trim leading text if this is an empty line. Kinda a hack to put it here, // but what can you do... if ($this->_lines[$this->_cl]["w"] == 0 && $frame->get_node()->nodeName == "#text" && ($frame->get_style()->white_space != "pre" || $frame->get_style()->white_space != "pre-wrap")) { $frame->set_text(ltrim($frame->get_text())); $frame->recalculate_width(); } $w = $frame->get_margin_width(); if ($w == 0) { return; } // Debugging code: /* pre_r("\nAdding frame to line:"); // pre_r("Me: " . $this->get_node()->nodeName . " (" . (string)$this->get_node() . ")"); // pre_r("Node: " . $frame->get_node()->nodeName . " (" . (string)$frame->get_node() . ")"); if ( $frame->get_node()->nodeName == "#text" ) pre_r($frame->get_node()->nodeValue); pre_r("Line width: " . $this->_lines[$this->_cl]["w"]); pre_r("Frame: " . get_class($frame)); pre_r("Frame width: " . $w); pre_r("Frame height: " . $frame->get_margin_height()); pre_r("Containing block width: " . $this->get_containing_block("w")); */ // End debugging if ($this->_lines[$this->_cl]["w"] + $w > $this->get_containing_block("w")) { $this->add_line(); } $frame->position(); $this->_lines[$this->_cl]["frames"][] = $frame; if ($frame->get_node()->nodeName == "#text") { $this->_lines[$this->_cl]["wc"] += count(preg_split("/\\s+/", $frame->get_text())); } $this->_lines[$this->_cl]["w"] += $w; $this->_lines[$this->_cl]["h"] = max($this->_lines[$this->_cl]["h"], $frame->get_margin_height()); }