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; } }
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; } }