function &create(&$root, &$pipeline) { // Create contents of this inline box if ($root->node_type() == XML_TEXT_NODE) { $css_state =& $pipeline->getCurrentCSSState(); return InlineBox::create_from_text($root->content, $css_state->getProperty(CSS_WHITE_SPACE), $pipeline); } else { $box =& new InlineBox(); $css_state =& $pipeline->getCurrentCSSState(); $box->readCSS($css_state); // Initialize content $child = $root->first_child(); while ($child) { $child_box =& create_pdf_box($child, $pipeline); $box->add_child($child_box); $child = $child->next_sibling(); } // Add fake whitespace box with zero size for the anchor spans // We need this, as "reflow" functions will automatically remove empty inline boxes from the // document tree // if ($box->is_null()) { $css_state->pushState(); $css_state->setProperty(CSS_FONT_SIZE, Value::fromData(0.01, UNIT_PT)); $whitespace = WhitespaceBox::create($pipeline); $whitespace->readCSS($css_state); $box->add_child($whitespace); $css_state->popState(); } } return $box; }
/** * Create new block element and automatically initialize its contents * with the given text string * * @param string $content The text string to be put inside the block box * * @return BlockBox new BlockBox object (with contents filled) * * @see InlineBox * @see InlineBox::create_from_text() */ function &create_from_text($content, &$pipeline) { $box = new BlockBox(); $box->readCSS($pipeline->get_current_css_state()); $box->add_child(InlineBox::create_from_text($content, $box->get_css_property(CSS_WHITE_SPACE), $pipeline)); return $box; }
function BoxNoteCall(&$content, &$pipeline) { $this->GenericInlineBox(); $this->_note_content =& $content; $this->copy_style($content); $this->put_height_constraint(new HCConstraint(null, null, null)); /** * Prepare ::note-call box */ $this->_note_call_box = InlineBox::create_from_text(CSSListStyleType::format_number(LST_DECIMAL, 99), WHITESPACE_NORMAL, $pipeline); $this->_note_call_box->copy_style($content); $this->_note_call_box->content[0]->copy_style($content); $font = $this->_note_call_box->content[0]->getCSSProperty(CSS_FONT); $font = $font->copy(); $font->size->scale(0.75); $this->_note_call_box->content[0]->setCSSProperty(CSS_FONT, $font); $this->_note_call_box->content[0]->setCSSProperty(CSS_VERTICAL_ALIGN, VA_SUPER); $this->_note_call_box->content[0]->setCSSProperty(CSS_LINE_HEIGHT, CSS::getDefaultValue(CSS_LINE_HEIGHT)); /** * Prepare ::marker box */ $this->_note_marker_box = InlineBox::create_from_text(CSSListStyleType::format_number(LST_DECIMAL, 99), WHITESPACE_NORMAL, $pipeline); $this->_note_marker_box->copy_style($content); $this->_note_marker_box->content[0]->copy_style($content); $font = $this->_note_marker_box->content[0]->getCSSProperty(CSS_FONT); $font = $font->copy(); $font->size->scale(0.5); $this->_note_marker_box->content[0]->setCSSProperty(CSS_FONT, $font); $margin = $this->_note_marker_box->content[0]->getCSSProperty(CSS_MARGIN); $margin = $margin->copy(); $margin->right = Value::fromData(FOOTNOTE_MARKER_MARGIN, UNIT_PT); $this->_note_marker_box->content[0]->setCSSProperty(CSS_MARGIN, $margin); $this->_note_marker_box->content[0]->setCSSProperty(CSS_VERTICAL_ALIGN, VA_SUPER); $this->_note_marker_box->content[0]->setCSSProperty(CSS_LINE_HEIGHT, CSS::getDefaultValue(CSS_LINE_HEIGHT)); }
function _setup($text, &$pipeline) { /** * Contents of the text box are somewhat similar to the inline box: * a sequence of the text and whitespace boxes; we generate this sequence using * the InlineBox, then copy contents of the created inline box to our button. * * @todo probably, create_from_text() function should be extracted to the common parent * of inline boxes. */ $ibox = InlineBox::create_from_text($text, WHITESPACE_PRE, $pipeline); $size = count($ibox->content); for ($i = 0; $i < $size; $i++) { $this->add_child($ibox->content[$i]); } /** * Button height includes vertical padding (e.g. the following two buttons * <input type="button" value="test" style="padding: 10px; height: 50px;"/> * <input type="button" value="test" style="padding: 0px; height: 30px;"/> * are render by browsers with the same height!), so we'll need to adjust the * height constraint, subtracting the vertical padding value from the constraint * height value. */ $hc = $this->get_height_constraint(); if (!is_null($hc->constant)) { $hc->constant[0] -= $this->get_padding_top() + $this->get_padding_bottom(); } $this->put_height_constraint($hc); }
function &create(&$root, &$pipeline) { // Create contents of this inline box if ($root->node_type() == XML_TEXT_NODE) { $handler = get_css_handler('white-space'); return InlineBox::create_from_text($root->content, $handler->get()); } else { $box =& new InlineBox(); // Initialize content $child = $root->first_child(); while ($child) { $child_box =& create_pdf_box($child, $pipeline); $box->add_child($child_box); $child = $child->next_sibling(); } // Add fake whitespace box with zero size for the anchor spans // We need this, as "reflow" functions will automatically remove empty inline boxes from the // document tree // if ($box->is_null()) { push_css_defaults(); pop_font_size(); push_font_size('0.01pt'); $whitespace = new WhitespaceBox(); $box->add_child($whitespace); pop_css_defaults(); } } return $box; }
function &create(&$root, &$pipeline) { // Text to be displayed if ($root->has_attribute('value')) { $text = trim($root->get_attribute("value")); } else { $text = ""; } /** * Input field name */ $name = $root->get_attribute('name'); $box =& new TextInputBox($root->get_attribute("value"), $name); $box->readCSS($pipeline->getCurrentCSSState()); /** * Contents of the text box are somewhat similar to the inline box: * a sequence of the text and whitespace boxes; we generate this sequence using * the InlineBox, then copy contents of the created inline box to our button. * * @todo probably, create_from_text() function should be extracted to the common parent * of inline boxes. */ $ibox = InlineBox::create_from_text($text, WHITESPACE_PRE, $pipeline); for ($i = 0, $size = count($ibox->content); $i < $size; $i++) { $box->add_child($ibox->content[$i]); } return $box; }
function &create(&$root, &$pipeline) { $name = $root->get_attribute('name'); $value = ""; $options = array(); // Get option list $child = $root->first_child(); $content = ""; $size = 0; while ($child) { if ($child->node_type() == XML_ELEMENT_NODE) { $size = max($size, strlen($child->get_content())); if (empty($content) || $child->has_attribute("selected")) { $content = preg_replace("/\\s/", " ", $child->get_content()); $value = trim($child->get_content()); } if ($child->has_attribute('value')) { $options[] = array($child->get_attribute('value'), $child->get_content()); } else { $options[] = array($child->get_content(), $child->get_content()); } } $child = $child->next_sibling(); } $content = str_pad($content, $size * SIZE_SPACE_KOEFF + SELECT_SPACE_PADDING, " "); $box =& new SelectBox($name, $value, $options); $box->readCSS($pipeline->getCurrentCSSState()); // Add text to be rendered in non-interactive mode $ibox = InlineBox::create_from_text($content, WHITESPACE_PRE, $pipeline); for ($i = 0, $size = count($ibox->content); $i < $size; $i++) { $box->add_child($ibox->content[$i]); } return $box; }
function SelectBox($name, $value, $options, $content) { // Call parent constructor $this->InlineBox(); $this->_name = $name; $this->_value = $value; $this->_options = $options; // Add text to be rendered in non-interactive mode $ibox = InlineBox::create_from_text($content, WHITESPACE_PRE); $size = count($ibox->content); for ($i = 0; $i < $size; $i++) { $this->add_child($ibox->content[$i]); } }
function setup_content($text, &$pipeline) { /** * Contents of the text box are somewhat similar to the inline box: * a sequence of the text and whitespace boxes; we generate this sequence using * the InlineBox, then copy contents of the created inline box to our button. * * @todo probably, create_from_text() function should be extracted to the common parent * of inline boxes. */ $ibox = InlineBox::create_from_text($text, WHITESPACE_PRE, $pipeline); if (count($ibox->content) == 0) { $this->append_child(TextBox::create(' ', 'iso-8859-1', $pipeline)); } else { for ($i = 0, $size = count($ibox->content); $i < $size; $i++) { $this->append_child($ibox->content[$i]); } } }
function &create(&$root, &$pipeline) { // Text to be displayed if ($root->has_attribute('value')) { $text = str_repeat("*", strlen($root->get_attribute("value"))); } else { $text = ""; } /** * Input field name */ $name = $root->get_attribute('name'); $box =& new PasswordInputBox($text, $root->get_attribute("value"), $name); $box->readCSS($pipeline->get_current_css_state()); $ibox = InlineBox::create_from_text(" ", WHITESPACE_PRE, $pipeline); for ($i = 0, $size = count($ibox->content); $i < $size; $i++) { $box->add_child($ibox->content[$i]); } return $box; }
function TextInputBox($size, $text, $value, $name) { // Call parent constructor $this->InlineBox(); $this->_value = $value; $this->_field_name = $name; /** * Contents of the text box are somewhat similar to the inline box: * a sequence of the text and whitespace boxes; we generate this sequence using * the InlineBox, then copy contents of the created inline box to our button. * * @todo probably, create_from_text() function should be extracted to the common parent * of inline boxes. */ $ibox = InlineBox::create_from_text($text, WHITESPACE_PRE); $size = count($ibox->content); for ($i = 0; $i < $size; $i++) { $this->add_child($ibox->content[$i]); } }
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; } }
/** * Create new block element and automatically initialize its contents * with the given text string * * @param string $content The text string to be put inside the block box * * @return BlockBox new BlockBox object (with contents filled) * * @see InlineBox * @see InlineBox::create_from_text() */ function &create_from_text($content) { $box = new BlockBox(); $box->add_child(InlineBox::create_from_text($content, $box->white_space)); return $box; }
function BoxPageMargin(&$pipeline, $at_rule) { $state =& $pipeline->get_current_css_state(); $state->pushDefaultState(); $root = null; $at_rule->css->apply($root, $state, $pipeline); $this->GenericContainerBox(); $this->readCSS($state); $state->pushDefaultstate(); /** * Check whether 'content' or '-html2ps-html-content' properties had been defined * (if both properties are defined, -html2ps-html-content takes precedence) */ $raw_html_content =& $at_rule->get_css_property(CSS_HTML2PS_HTML_CONTENT); $html_content = $raw_html_content->render($pipeline->get_counters()); if ($html_content !== '') { // We should wrap html_content in DIV tag, // as we treat only the very first box of the resulting DOM tree as margin box content $html_content = html2xhtml("<div>" . $html_content . "</div>"); $tree = TreeBuilder::build($html_content); $tree_root = traverse_dom_tree_pdf($tree); $body_box =& create_pdf_box($tree_root, $pipeline); $box =& $body_box->content[0]; } else { $raw_content =& $at_rule->get_css_property(CSS_CONTENT); $content = $raw_content->render($pipeline->get_counters()); $box =& InlineBox::create_from_text($content, WHITESPACE_PRE_LINE, $pipeline); } $this->add_child($box); $state->popState(); $state->popState(); }
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; } }