Esempio n. 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();
 }
Esempio n. 2
0
function &create_pdf_pseudoelement($root, $pe_type, &$pipeline)
{
    // Store initial values to CSS stack
    $css_state =& $pipeline->get_current_css_state();
    $css_state->pushDefaultState();
    // Initially generated boxes do not require block wrappers
    // Block wrappers are required in following cases:
    // - float property is specified for non-block box which cannot be directly converted to block box
    //   (a button, for example)
    // - display set to block for such box
    $need_block_wrapper = false;
    $css =& $pipeline->get_current_css();
    $css->apply_pseudoelement($pe_type, $root, $css_state, $pipeline);
    // Now, if no content found, just return
    //
    $content_obj = $css_state->get_property(CSS_CONTENT);
    if ($content_obj === CSS_PROPERTY_INHERIT) {
        $content_obj = $css_state->getInheritedProperty(CSS_CONTENT);
    }
    $content = $content_obj->render($pipeline->get_counters());
    if ($content === '') {
        $css_state->popState();
        $dummy = null;
        return $dummy;
    }
    // CSS 2.1:
    // 9.7 Relationships between 'display', 'position', and 'float'
    // The three properties that affect box generation and layout —
    // 'display', 'position', and 'float' — interact as follows:
    // 1. If 'display' has the value 'none', then 'position' and 'float' do not apply.
    //    In this case, the element generates no box.
    // 2. Otherwise, if 'position' has the value 'absolute' or 'fixed', the box is absolutely positioned,
    //    the computed value of 'float' is 'none', and display is set according to the table below.
    //    The position of the box will be determined by the 'top', 'right', 'bottom' and 'left' properties and
    //    the box's containing block.
    $position_handler =& CSS::get_handler(CSS_POSITION);
    $float_handler =& CSS::get_handler(CSS_FLOAT);
    $position = $position_handler->get($css_state->getState());
    if ($position === CSS_PROPERTY_INHERIT) {
        $position = $css_state->getInheritedProperty(CSS_POSITION);
    }
    if ($position === POSITION_ABSOLUTE || $position === POSITION_FIXED) {
        $float_handler->replace(FLOAT_NONE);
        $need_block_wrapper |= _fix_display_position_float($css_state);
    }
    // 3. Otherwise, if 'float' has a value other than 'none', the box is floated and 'display' is set
    //    according to the table below.
    $float = $float_handler->get($css_state->getState());
    if ($float != FLOAT_NONE) {
        $need_block_wrapper |= _fix_display_position_float($css_state);
    }
    // 4. Otherwise, if the element is the root element, 'display' is set according to the table below.
    // 5. Otherwise, the remaining 'display' property values apply as specified. (see _fix_display_position_float)
    // Note that pseudoelements may get only standard display values
    $display_handler =& CSS::get_handler(CSS_DISPLAY);
    $display = $display_handler->get($css_state->getState());
    switch ($display) {
        case 'block':
            $box =& BlockBox::create_from_text($content, $pipeline);
            break;
        case 'inline':
            $ws_handler =& CSS::get_handler(CSS_WHITE_SPACE);
            $box =& InlineBox::create_from_text($content, $ws_handler->get($css_state->getState()), $pipeline);
            break;
        default:
            die('Unsupported "display" value: ' . $display_handler->get($css_state->getState()));
    }
    // Check if this box needs a block wrapper (for example, floating button)
    // Note that to keep float/position information, we clear the CSS stack only
    // AFTER the wrapper box have been created; BUT we should clear the following CSS properties
    // to avoid the fake wrapper box actually affect the layout:
    // - margin
    // - border
    // - padding
    // - background
    //
    if ($need_block_wrapper) {
        $handler =& CSS::get_handler(CSS_MARGIN);
        $handler->css("0", $pipeline);
        pop_border();
        push_border(default_border());
        pop_padding();
        push_padding(default_padding());
        $handler =& CSS::get_handler(CSS_BACKGROUND);
        $handler->css('transparent', $pipeline);
        // Create "clean" block box
        $wrapper =& new BlockBox();
        $wrapper->readCSS($pipeline->get_current_css_state());
        $wrapper->add_child($box);
        $css_state->popState();
        return $wrapper;
    } else {
        $css_state->popState();
        return $box;
    }
}
Esempio n. 3
0
function push_css_text_defaults()
{
    // No borders for pure text boxes; border can be controlled via SPANs
    push_border(default_border());
    push_font_family(get_font_family());
    //  push_font_size(get_font_size());
    push_font_size("1em");
    push_font_style(get_font_style());
    push_font_weight(get_font_weight());
    push_line_height(get_line_height());
    global $g_css_handlers;
    $keys = array_keys($g_css_handlers);
    foreach ($keys as $key) {
        $g_css_handlers[$key]->inherit_text();
    }
}
Esempio n. 4
0
function &create_pdf_pseudoelement($root, $pe_type, &$pipeline)
{
    // Store initial values to CSS stack
    //
    push_css_defaults();
    // Apply default stylesheet rules (using base element)
    global $g_css_defaults_obj;
    $g_css_defaults_obj->apply($root, $pipeline);
    // Initially generated boxes do not require block wrappers
    // Block wrappers are required in following cases:
    // - float property is specified for non-block box which cannot be directly converted to block box
    //   (a button, for example)
    // - display set to block for such box
    $need_block_wrapper = false;
    // Order is important. Items with most priority should be applied last
    // Tag attributes
    execute_attrs_before($root, $pipeline);
    // CSS stylesheet
    global $g_css_obj;
    $g_css_obj->apply($root, $pipeline);
    // values from 'style' attribute
    if ($root->has_attribute("style")) {
        parse_style_attr(null, $root, $pipeline);
    }
    // Pseudoelement-specific rules; be default, it should flow inline
    //
    $handler =& get_css_handler('display');
    $handler->css('inline', $pipeline);
    $handler =& get_css_handler('content');
    $handler->css("", $pipeline);
    $handler =& get_css_handler('float');
    $handler->css("none", $pipeline);
    $handler =& get_css_handler('position');
    $handler->css("static", $pipeline);
    $handler =& get_css_handler('margin');
    $handler->css("0", $pipeline);
    $handler =& get_css_handler('width');
    $handler->css("auto", $pipeline);
    $handler =& get_css_handler('height');
    $handler->css("auto", $pipeline);
    $g_css_obj->apply_pseudoelement($pe_type, $root, $pipeline);
    // Now, if no content found, just return
    //
    $handler =& get_css_handler('content');
    $content = $handler->get();
    if ($content === "") {
        pop_css_defaults();
        $dummy = null;
        return $dummy;
    }
    // CSS 2.1:
    // 9.7 Relationships between 'display', 'position', and 'float'
    // The three properties that affect box generation and layout —
    // 'display', 'position', and 'float' — interact as follows:
    // 1. If 'display' has the value 'none', then 'position' and 'float' do not apply.
    //    In this case, the element generates no box.
    $position_handler =& get_css_handler('position');
    $float_handler =& get_css_handler('float');
    // 2. Otherwise, if 'position' has the value 'absolute' or 'fixed', the box is absolutely positioned,
    //    the computed value of 'float' is 'none', and display is set according to the table below.
    //    The position of the box will be determined by the 'top', 'right', 'bottom' and 'left' properties and
    //    the box's containing block.
    $position = $position_handler->get();
    if ($position === POSITION_ABSOLUTE || $position === POSITION_FIXED) {
        $float_handler->replace(FLOAT_NONE);
        $need_block_wrapper |= _fix_display_position_float();
    }
    // 3. Otherwise, if 'float' has a value other than 'none', the box is floated and 'display' is set
    //    according to the table below.
    $float = $float_handler->get();
    if ($float != FLOAT_NONE) {
        $need_block_wrapper |= _fix_display_position_float();
    }
    // 4. Otherwise, if the element is the root element, 'display' is set according to the table below.
    // 5. Otherwise, the remaining 'display' property values apply as specified. (see _fix_display_position_float)
    // Note that pseudoelements may get only standard display values
    $display_handler =& get_css_handler('display');
    switch (trim($display_handler->get())) {
        case "block":
            $box =& BlockBox::create_from_text($content);
            break;
        case "inline":
            $ws_handler =& get_css_handler('white-space');
            $box =& InlineBox::create_from_text($content, $ws_handler->get());
            break;
        default:
            die("Unsupported 'display' value: " . $display_handler->get());
    }
    // Check if this box needs a block wrapper (for example, floating button)
    // Note that to keep float/position information, we clear the CSS stack only
    // AFTER the wrapper box have been created; BUT we should clear the following CSS properties
    // to avoid the fake wrapper box actually affect the layout:
    // - margin
    // - border
    // - padding
    // - background
    //
    if ($need_block_wrapper) {
        $handler =& get_css_handler('margin');
        $handler->css("0", $pipeline);
        pop_border();
        push_border(default_border());
        pop_padding();
        push_padding(default_padding());
        $handler =& get_css_handler('background');
        $handler->css('transparent', $pipeline);
        // Create "clean" block box
        $wrapper =& new BlockBox();
        $wrapper->add_child($box);
        // Remove CSS propery values from stack
        execute_attrs_after($root, $pipeline);
        pop_css_defaults();
        return $wrapper;
    } else {
        // Remove CSS propery values from stack
        execute_attrs_after($root, $pipeline);
        pop_css_defaults();
        return $box;
    }
}
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);
}
 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();
 }