protected function _build_tree_r(DomNode $node)
 {
     $frame = new Frame($node);
     $id = $frame->get_id();
     $this->_registry[$id] = $frame;
     if (!$node->hasChildNodes()) {
         return $frame;
     }
     $children = array();
     for ($i = 0; $i < $node->childNodes->length; $i++) {
         $children[] = $node->childNodes->item($i);
     }
     foreach ($children as $child) {
         $node_name = mb_strtolower($child->nodeName);
         if (in_array($node_name, self::$_HIDDEN_TAGS)) {
             if ($node_name !== "head" && $node_name !== "style") {
                 $child->parentNode->removeChild($child);
             }
             continue;
         }
         if ($node_name === "#text" && $child->nodeValue == "") {
             $child->parentNode->removeChild($child);
             continue;
         }
         if ($node_name === "img" && $child->getAttribute("src") == "") {
             $child->parentNode->removeChild($child);
             continue;
         }
         $frame->append_child($this->_build_tree_r($child), false);
     }
     return $frame;
 }
 function get_id()
 {
     return $this->_frame->get_id();
 }
Exemplo n.º 3
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;
     }
     // Fixes 'cannot access undefined property for object with
     // overloaded access', fix by Stefan radulian
     // <*****@*****.**>
     //foreach ($node->childNodes as $child) {
     // Store the children in an array so that the tree can be modified
     $children = array();
     for ($i = 0; $i < $node->childNodes->length; $i++) {
         $children[] = $node->childNodes->item($i);
     }
     foreach ($children as $child) {
         $node_name = mb_strtolower($child->nodeName);
         // Skip non-displaying nodes
         if (in_array($node_name, self::$_HIDDEN_TAGS)) {
             if ($node_name !== "head" && $node_name !== "style") {
                 $child->parentNode->removeChild($child);
             }
             continue;
         }
         // Skip empty text nodes
         if ($node_name === "#text" && $child->nodeValue == "") {
             $child->parentNode->removeChild($child);
             continue;
         }
         // Skip empty image nodes
         if ($node_name === "img" && $child->getAttribute("src") == "") {
             $child->parentNode->removeChild($child);
             continue;
         }
         $frame->append_child($this->_build_tree_r($child), false);
     }
     return $frame;
 }
Exemplo n.º 4
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
  */
 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));
 }
Exemplo n.º 5
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;

    // Fixes 'cannot access undefined property for object with
    // overloaded access', fix by Stefan radulian
    // <*****@*****.**>    
    //foreach ($node->childNodes as $child) {

    // Store the children in an array so that the tree can be modified
    $children = array();
    for ($i = 0; $i < $node->childNodes->length; $i++)
      $children[] = $node->childNodes->item($i);

    foreach ($children as $child) {
      // Skip non-displaying nodes
      if ( in_array( mb_strtolower($child->nodeName), self::$_HIDDEN_TAGS) )  {
        if ( mb_strtolower($child->nodeName) != "head" &&
             mb_strtolower($child->nodeName) != "style" ) 
          $child->parentNode->removeChild($child);
        continue;
      }

      // Skip empty text nodes
      if ( $child->nodeName == "#text" && $child->nodeValue == "" ) {
        $child->parentNode->removeChild($child);
        continue;
      }
      
      // Add a container frame for images
      if ( $child->nodeName == "img" ) {
        $img_node = $child->ownerDocument->createElement("img_inner");
     
        // Move attributes to inner node        
        foreach ( $child->attributes as $attr => $attr_node ) {
          // Skip style, but move all other attributes
          if ( $attr == "style" )
            continue;
       
          $img_node->setAttribute($attr, $attr_node->value);
        }

        foreach ( $child->attributes as $attr => $node ) {
          if ( $attr == "style" )
            continue;
          $child->removeAttribute($attr);
        }

        $child->appendChild($img_node);
      }
   
      $frame->append_child($this->_build_tree_r($child), false);

    }
    
    return $frame;
  }
Exemplo n.º 6
0
 /**
  * Remove a row from the cellmap.
  *
  * @param Frame
  */
 function remove_row(Frame $row)
 {
     // FIXME: handle row-groups
     $key = $row->get_id();
     if (!isset($this->_frames[$key])) {
         return;
     }
     // Presumably this row has alredy been removed
     $this->_row = $this->_num_rows--;
     $rows = $this->_frames[$key]["rows"];
     $columns = $this->_frames[$key]["columns"];
     // Remove all frames from this row
     foreach ($rows as $row) {
         foreach ($columns as $col) {
             $frame = $this->_cells[$row][$col];
             unset($this->_frames[$frame->get_id()]);
             unset($this->_cells[$row][$col]);
         }
     }
     unset($this->_frames[$key]);
 }
Exemplo n.º 7
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)
 {
     $node_name = mb_strtolower($node->nodeName);
     switch ($node_name) {
         // Let's dump inner svg elements into src attribute so the image renderer could take care of it
         case 'svg':
             /** @var DOMElement $node; */
             if ($node->hasChildNodes()) {
                 $node->setAttribute('src', 'data:image/svg+xml,' . self::exportOuterXML($node));
             }
             $frame = new Frame($node);
             $id = $frame->get_id();
             $this->_registry[$id] = $frame;
             return $frame;
         default:
             $frame = new Frame($node);
             $id = $frame->get_id();
             $this->_registry[$id] = $frame;
             if (!$node->hasChildNodes()) {
                 return $frame;
             }
             // Fixes 'cannot access undefined property for object with
             // overloaded access', fix by Stefan radulian
             // <*****@*****.**>
             //foreach ($node->childNodes as $child) {
             // Store the children in an array so that the tree can be modified
             $children = array();
             for ($i = 0; $i < $node->childNodes->length; $i++) {
                 $children[] = $node->childNodes->item($i);
             }
             foreach ($children as $child) {
                 $node_name = mb_strtolower($child->nodeName);
                 // Skip non-displaying nodes
                 if (in_array($node_name, self::$_HIDDEN_TAGS)) {
                     if ($node_name !== "head" && $node_name !== "style") {
                         $child->parentNode->removeChild($child);
                     }
                     continue;
                 }
                 // Skip empty text nodes
                 if ($node_name === "#text" && $child->nodeValue == "") {
                     $child->parentNode->removeChild($child);
                     continue;
                 }
                 // Skip empty image nodes
                 if ($node_name === "img" && $child->getAttribute("src") == "") {
                     $child->parentNode->removeChild($child);
                     continue;
                 }
                 $frame->append_child($this->_build_tree_r($child), false);
             }
             return $frame;
     }
 }