コード例 #1
0
 function FrameBox(&$root, &$pipeline)
 {
     // Inherit 'border' CSS value from parent (FRAMESET tag), if current FRAME
     // has no FRAMEBORDER attribute, and FRAMESET has one
     $parent = $root->parent();
     if (!$root->has_attribute('frameborder') && $parent->has_attribute('frameborder')) {
         pop_border();
         push_border(get_border());
     }
     $this->GenericContainerBox($root);
     // If NO src attribute specified, just return.
     if (!$root->has_attribute('src')) {
         return;
     }
     // Determine the fullly qualified URL of the frame content
     $src = $root->get_attribute('src');
     $url = $pipeline->guess_url($src);
     $data = $pipeline->fetch($url);
     /**
      * If framed page could not be fetched return immediately
      */
     if (is_null($data)) {
         return;
     }
     /**
      * Render only iframes containing HTML only
      *
      * Note that content-type header may contain additional information after the ';' sign
      */
     $content_type = $data->get_additional_data('Content-Type');
     $content_type_array = explode(';', $content_type);
     if ($content_type_array[0] != "text/html") {
         return;
     }
     $html = $data->get_content();
     // Remove control symbols if any
     $html = preg_replace('/[\\x00-\\x07]/', "", $html);
     $converter = Converter::create();
     $html = $converter->to_utf8($html, $data->detect_encoding());
     $html = html2xhtml($html);
     $tree = TreeBuilder::build($html);
     // Save current stylesheet, as each frame may load its own stylesheets
     //
     global $g_css;
     $old_css = $g_css;
     global $g_css_obj;
     $old_obj = $g_css_obj;
     scan_styles($tree, $pipeline);
     // Temporary hack: convert CSS rule array to CSS object
     $g_css_obj = new CSSObject();
     foreach ($g_css as $rule) {
         $g_css_obj->add_rule($rule, $pipeline);
     }
     // TODO: stinks. Rewrite
     //
     $frame_root = traverse_dom_tree_pdf($tree);
     $box_child =& create_pdf_box($frame_root, $pipeline);
     $this->add_child($box_child);
     // Restore old stylesheet
     //
     $g_css = $old_css;
     $g_css_obj = $old_obj;
     $pipeline->pop_base_url();
 }
コード例 #2
0
 function GenericFormattedBox()
 {
     $this->GenericBox();
     $base_font_size = get_base_font_size();
     // 'background'
     $handler = get_css_handler('background');
     $this->background = $handler->get();
     $this->background = $this->background->copy();
     $this->background->units2pt($base_font_size);
     // 'border'
     $this->border = new BorderPDF(get_border());
     // '-cellpadding'
     $handler = get_css_handler('-cellpadding');
     $this->cellpadding = units2pt($handler->get(), $base_font_size);
     // '-cellspacing'
     $handler = get_css_handler('-cellspacing');
     $this->cellspacing = units2pt($handler->get(), $base_font_size);
     // 'clear'
     $handler = get_css_handler('clear');
     $this->clear = $handler->get();
     // 'content'
     $handler = get_css_handler('content');
     $this->content_pseudoelement = $handler->get();
     // 'display'
     $handler = get_css_handler('display');
     $this->display = $handler->get();
     // 'float'
     $handler = get_css_handler('float');
     $this->float = $handler->get();
     // 'height'
     $this->_height_constraint = HCConstraint::create($this);
     $this->_height_constraint->units2pt($base_font_size);
     // $this->height = $this->_height_constraint->apply(0, $this);
     $this->height = 0;
     // 'line-height'
     $this->line_height = get_line_height();
     $this->line_height = $this->line_height->copy();
     $this->line_height->units2pt($base_font_size);
     // 'list-style'
     $handler = get_css_handler('list-style');
     $this->list_style = $handler->get();
     $this->list_style = $this->list_style->copy();
     // 'margin'
     $handler = get_css_handler('margin');
     $this->margin = $handler->get();
     $this->margin = $this->margin->copy();
     $this->margin->units2pt($base_font_size);
     // 'overflow'
     $handler = get_css_handler('overflow');
     $this->overflow = $handler->get();
     // 'padding'
     $handler = get_css_handler('padding');
     $this->padding = $handler->get();
     $this->padding = $this->padding->copy();
     $this->padding->units2pt($base_font_size);
     // 'page-break-after'
     $handler = get_css_handler('page-break-after');
     $this->page_break_after = $handler->get();
     // 'position'
     $handler = get_css_handler('position');
     $this->position = $handler->get();
     // 'text-align'
     $handler = get_css_handler('text-align');
     $this->text_align = $handler->get();
     // 'text-indent'
     $handler = get_css_handler('text-indent');
     $this->text_indent = $handler->get();
     $this->text_indent = $this->text_indent->copy();
     $this->text_indent->units2pt($base_font_size);
     // 'vertical-align'
     $handler = get_css_handler('vertical-align');
     $this->vertical_align = $handler->get();
     // 'visibility'
     $handler = get_css_handler('visibility');
     $this->visibility = $handler->get();
     // 'width'
     $handler = get_css_handler('width');
     $this->_width_constraint = $handler->get();
     $this->_width_constraint = $this->_width_constraint->copy();
     $this->_width_constraint->units2pt($base_font_size);
     $this->width = $this->_width_constraint->apply(0, 0);
     // 'white-space'
     $handler = get_css_handler('white-space');
     $this->white_space = $handler->get();
     // CSS positioning properties
     // 'left'
     $handler = get_css_handler('left');
     $value = $handler->get();
     $this->left = $value;
     // 'top'
     $handler = get_css_handler('top');
     $this->top = $handler->get();
     // 'bottom'
     // TODO: automatic height calculation
     $handler = get_css_handler('bottom');
     $this->bottom = $handler->get();
     if (!is_null($this->bottom)) {
         $this->bottom = units2pt($this->bottom, $base_font_size);
     }
     // 'right'
     // TODO: automatic width calculation
     $handler = get_css_handler('right');
     $this->right = $handler->get();
     $handler = get_css_handler('z-index');
     $this->z_index = $handler->get();
     // 'PSEUDO-CSS' properties
     // '-align'
     $handler = get_css_handler('-align');
     $this->pseudo_align = $handler->get();
     // '-html2ps-link-destination'
     global $g_config;
     if ($g_config["renderlinks"]) {
         $handler = get_css_handler('-html2ps-link-destination');
         $this->pseudo_link_destination = $handler->get();
     } else {
         $this->pseudo_link_destination = "";
     }
     // '-html2ps-link-target'
     global $g_config;
     if ($g_config["renderlinks"]) {
         $handler = get_css_handler('-html2ps-link-target');
         $this->pseudo_link_target = $handler->get();
     } else {
         $this->pseudo_link_target = "";
     }
     // '-localalign'
     $handler = get_css_handler('-localalign');
     switch ($handler->get()) {
         case LA_LEFT:
             break;
         case LA_RIGHT:
             $this->margin->left->auto = true;
             break;
         case LA_CENTER:
             $this->margin->left->auto = true;
             $this->margin->right->auto = true;
             break;
     }
     // '-nowrap'
     $handler = get_css_handler('-nowrap');
     $this->pseudo_nowrap = $handler->get();
     // Layout data
     $this->baseline = 0;
     $this->parent = null;
     // Unique box identifier
     global $g_box_uid;
     $g_box_uid++;
     $this->uid = $g_box_uid;
     // As PHP in most cases passes a copy of an object instead
     // of reference and it is pretty hard to track (especially between different versions
     // of PHP), we'll keep references to all boxes in the global array
     //     global $g_boxes;
     //     $g_boxes[$this->uid] =& $this;
 }
コード例 #3
0
function css_border_width($value, $root)
{
    $border = get_border();
    $subvalues = explode(" ", $value);
    switch (count($subvalues)) {
        case 1:
            $c1 = parse_border_width($subvalues[0], array(0, 0, 0));
            $border['top']['width'] = $c1;
            $border['right']['width'] = $c1;
            $border['bottom']['width'] = $c1;
            $border['left']['width'] = $c1;
            break;
        case 2:
            $c1 = parse_border_width($subvalues[0], array(0, 0, 0));
            $c2 = parse_border_width($subvalues[1], array(0, 0, 0));
            $border['top']['width'] = $c1;
            $border['right']['width'] = $c2;
            $border['bottom']['width'] = $c1;
            $border['left']['width'] = $c2;
            break;
        case 3:
            $c1 = parse_border_width($subvalues[0], array(0, 0, 0));
            $c2 = parse_border_width($subvalues[1], array(0, 0, 0));
            $c3 = parse_border_width($subvalues[2], array(0, 0, 0));
            $border['top']['width'] = $c1;
            $border['right']['width'] = $c2;
            $border['bottom']['width'] = $c3;
            $border['left']['width'] = $c2;
            break;
        case 4:
            $c1 = parse_border_width($subvalues[0], array(0, 0, 0));
            $c2 = parse_border_width($subvalues[1], array(0, 0, 0));
            $c3 = parse_border_width($subvalues[2], array(0, 0, 0));
            $c4 = parse_border_width($subvalues[3], array(0, 0, 0));
            $border['top']['width'] = $c1;
            $border['right']['width'] = $c2;
            $border['bottom']['width'] = $c3;
            $border['left']['width'] = $c4;
            break;
    }
    pop_border();
    push_border($border);
}
コード例 #4
0
 function TableCellBox(&$root, $pipeline)
 {
     $this->_suppress_first = false;
     $this->_suppress_last = false;
     $this->colspan = 1;
     $this->rowspan = 1;
     // This value will be overwritten in table 'normalize_parent' method
     //
     $this->column = 0;
     $this->row = 0;
     if ($root->tagname() === 'td' || $root->tagname() === 'th') {
         // Use cellspacing / cellpadding values from the containing table
         $handler =& get_css_handler('-cellspacing');
         $cellspacing = $handler->get();
         $cp_handler =& get_css_handler('-cellpadding');
         $cellpadding = $cp_handler->get();
         // FIXME: I'll need to resolve that issue with COLLAPSING border model. Now borders
         // are rendered separated
         // if not border set explicitly, inherit value set via border attribute of TABLE tag
         if (is_default_border(get_border())) {
             $border = get_table_border();
             pop_border();
             push_border($border);
         }
         $margin =& get_css_handler('margin');
         $margin->replace($margin->default_value());
         $handler =& get_css_handler('border-collapse');
         if ($handler->get() == BORDER_COLLAPSE) {
             $h_padding =& get_css_handler('padding');
             if ($h_padding->is_default($h_padding->get())) {
                 $h_padding->css($cellpadding, $pipeline);
             }
         } else {
             $h_padding =& get_css_handler('padding');
             if ($h_padding->is_default($h_padding->get())) {
                 $h_padding->css($cellpadding, $pipeline);
             }
             if ($margin->is_default($margin->get())) {
                 $margin->css(units_mul($cellspacing, 0.5), $pipeline);
             }
         }
         // Save colspan and rowspan information
         $this->colspan = max(1, (int) $root->get_attribute('colspan'));
         $this->rowspan = max(1, (int) $root->get_attribute('rowspan'));
     }
     // $root->tagname() == 'td'
     // Call parent constructor
     $this->GenericContainerBox();
     // 'vertical-align' CSS value is not inherited from the table cells
     $handler =& get_css_handler('vertical-align');
     $handler->push_default();
     $this->create_content($root, $pipeline);
     global $g_config;
     if ($g_config['mode'] == "quirks") {
         // QUIRKS MODE:
         // H1-H6 and P elements should have their top/bottom margin suppressed if they occur as the first/last table cell child
         // correspondingly; note that we cannot do it usung CSS rules, as there's no selectors for the last child.
         //
         $child = $root->first_child();
         if ($child) {
             while ($child && $child->node_type() != XML_ELEMENT_NODE) {
                 $child = $child->next_sibling();
             }
             if ($child) {
                 if (array_search(strtolower($child->tagname()), array("h1", "h2", "h3", "h4", "h5", "h6", "p"))) {
                     $this->_suppress_first = true;
                 }
             }
         }
         $child = $root->last_child();
         if ($child) {
             while ($child && $child->node_type() != XML_ELEMENT_NODE) {
                 $child = $child->previous_sibling();
             }
             if ($child) {
                 if (array_search(strtolower($child->tagname()), array("h1", "h2", "h3", "h4", "h5", "h6", "p"))) {
                     $this->_suppress_last = true;
                 }
             }
         }
     }
     // pop the default vertical-align value
     $handler->pop();
 }