示例#1
0
 /**
  * Recursively adds {@link Frame} objects to the tree
  *
  * Recursively build a tree of Frame objects based on a dom tree.
  * No layout information is calculated at this time, although the
  * tree may be adjusted (i.e. nodes and frames for generated content
  * and images may be created).
  *
  * @param DOMNode $node the current DOMNode being considered
  *
  * @return Frame
  */
 protected function _build_tree_r(DOMNode $node)
 {
     $frame = new Frame($node);
     $id = $frame->get_id();
     $this->_registry[$id] = $frame;
     if (!$node->hasChildNodes()) {
         return $frame;
     }
     for ($i = 0; $i < $node->childNodes->length; $i++) {
         $child = $node->childNodes->item($i);
         if (in_array($child->nodeName, self::$HIDDEN_TAGS)) {
             if ($child->nodeName !== "head" && $child->nodeName !== "HEAD" && ($child->nodeName !== "style" && $child->nodeName !== "STYLE")) {
                 $child->parentNode->removeChild($child);
             }
         } elseif (($child->nodeName === "#text" || $child->nodeName === "#TEXT") && $child->nodeValue == "") {
             $child->parentNode->removeChild($child);
         } elseif (($child->nodeName === "img" || $child->nodeName === "IMG") && $child->getAttribute("src") == "") {
             $child->parentNode->removeChild($child);
         } elseif (is_object($child)) {
             $frame->append_child($this->_build_tree_r($child), false);
         }
     }
     return $frame;
 }
 function get_id()
 {
     return $this->_frame->get_id();
 }
示例#3
0
 /**
  * Update a row group after rows have been removed
  *
  * @param Frame $group    The group to update
  * @param Frame $last_row The last row in the row group
  */
 public function update_row_group(Frame $group, Frame $last_row)
 {
     $g_key = $group->get_id();
     $r_key = $last_row->get_id();
     $r_rows = $this->_frames[$r_key]["rows"];
     $this->_frames[$g_key]["rows"] = range($this->_frames[$g_key]["rows"][0], end($r_rows));
 }
示例#4
0
 /**
  * Recursively adds {@link Frame} objects to the tree
  *
  * Recursively build a tree of Frame objects based on a dom tree.
  * No layout information is calculated at this time, although the
  * tree may be adjusted (i.e. nodes and frames for generated content
  * and images may be created).
  *
  * @param DOMNode $node the current DOMNode being considered
  *
  * @return Frame
  */
 protected function _build_tree_r(DOMNode $node)
 {
     $frame = new Frame($node);
     $id = $frame->get_id();
     $this->_registry[$id] = $frame;
     if (!$node->hasChildNodes()) {
         return $frame;
     }
     // Store the children in an array so that the tree can be modified
     $children = array();
     $length = $node->childNodes->length;
     for ($i = 0; $i < $length; $i++) {
         $children[] = $node->childNodes->item($i);
     }
     $index = 0;
     // INFO: We don't advance $index if a node is removed to avoid skipping nodes
     while ($index < count($children)) {
         $child = $children[$index];
         $nodeName = strtolower($child->nodeName);
         // Skip non-displaying nodes
         if (in_array($nodeName, self::$HIDDEN_TAGS)) {
             if ($nodeName !== "head" && $nodeName !== "style") {
                 $this->_remove_node($node, $children, $index);
             } else {
                 $index++;
             }
             continue;
         }
         // Skip empty text nodes
         if ($nodeName === "#text" && $child->nodeValue === "") {
             $this->_remove_node($node, $children, $index);
             continue;
         }
         // Skip empty image nodes
         if ($nodeName === "img" && $child->getAttribute("src") === "") {
             $this->_remove_node($node, $children, $index);
             continue;
         }
         if (is_object($child)) {
             $frame->append_child($this->_build_tree_r($child), false);
         }
         $index++;
     }
     return $frame;
 }