/**
  * CSS 2.1 p.16.6
  * white-space: normal
  * This value directs user agents to collapse sequences of whitespace, and break lines as necessary to fill line boxes.
  */
 function build(&$box, $text, &$pipeline)
 {
     $text = $this->remove_leading_linefeeds($text);
     $text = $this->remove_trailing_linefeeds($text);
     $content = $this->collapse_whitespace($text);
     // Whitespace-only text nodes sill result on only one whitespace box
     if (trim($content) === '') {
         $whitespace =& WhitespaceBox::create($pipeline);
         $box->add_child($whitespace);
         return;
     }
     // Add leading whispace box, if content stars with a space
     if (preg_match('/ /u', substr($content, 0, 1))) {
         $whitespace =& WhitespaceBox::create($pipeline);
         $box->add_child($whitespace);
     }
     $words = $this->break_into_words($content);
     $size = count($words);
     $pos = 0;
     // Check if text content has trailing whitespace
     $last_whitespace = substr($content, strlen($content) - 1, 1) == ' ';
     foreach ($words as $word) {
         $box->process_word($word, $pipeline);
         $pos++;
         $is_last_word = $pos == $size;
         // Whitespace boxes should be added
         // 1) between words
         // 2) after the last word IF there was a space at the content end
         if (!$is_last_word || $last_whitespace) {
             $whitespace =& WhitespaceBox::create($pipeline);
             $box->add_child($whitespace);
         }
     }
 }
 /**
  * CSS 2.1 p.16.6
  * white-space: normal
  * This value directs user agents to collapse sequences of whitespace, and break lines as necessary to fill line boxes.
  */
 function build(&$box, $text, &$pipeline)
 {
     $text = $this->remove_leading_linefeeds($text);
     $text = $this->remove_trailing_linefeeds($text);
     $lines = $this->break_into_lines($text);
     foreach ($lines as $line) {
         $words = $this->break_into_words($this->collapse_whitespace($line));
         foreach ($words as $word) {
             $box->process_word($word, $pipeline);
             $whitespace =& WhitespaceBox::create($pipeline);
             $box->add_child($whitespace);
         }
         $this->add_line_break($box, $pipeline);
     }
 }
 /**
  * CSS 2.1 16.6 Whitespace: the 'white-space' property
  *
  * pre-wrap:
  *
  * This  value prevents  user  agents from  collapsing sequences  of
  * whitespace.   Lines are  broken  at newlines  in  the source,  at
  * occurrences  of "\A" in  generated content,  and as  necessary to
  * fill line boxes.
  */
 function build(&$box, $text, &$pipeline)
 {
     $text = $this->remove_trailing_linefeeds($text);
     $parent =& $box->get_parent_node();
     $lines = $this->break_into_lines($text);
     for ($i = 0, $size = count($lines); $i < $size; $i++) {
         $line = $lines[$i];
         $words = $this->break_into_words($line);
         foreach ($words as $word) {
             $word .= ' ';
             $box->process_word($word, $pipeline);
             $whitespace =& WhitespaceBox::create($pipeline);
             $box->add_child($whitespace);
         }
         if ((!$parent || $parent->isBlockLevel()) && $i < $size - 1) {
             $this->add_line_break($box, $pipeline);
         }
     }
 }
 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;
 }
Exemplo n.º 5
0
 function init_white_space_normal($raw_content)
 {
     $content = preg_replace("/[\r\n\t ]/", ' ', $raw_content);
     // Whitespace-only text nodes sill result on only one whitespace box
     if (trim($content) === "") {
         $this->add_child(WhitespaceBox::create());
         return;
     }
     if (preg_match("# #", substr($content, 0, 1))) {
         $this->add_child(WhitespaceBox::create());
     }
     $words = preg_split("/ /", $content);
     $prefix = "";
     for ($i = 0; $i < count($words); $i++) {
         $word = $prefix . $words[$i];
         // Skip zero-length words
         if (strlen($word) == 0) {
             continue;
         }
         // Check if this word is terminated by a partially-completed
         // unicode symbol; in this case we've made a break here incorrectly on
         // the non-breaking space
         //
         // So, we'll concatenate whis with with the next word
         // dropping partially parsed unicode symbol and replacing it by a space
         //
         if ($word[strlen($word) - 1] == chr(0xc2)) {
             $prefix = substr($word, 0, strlen($word) - 1) . " ";
             continue;
         }
         $prefix = "";
         if ($word !== "") {
             $this->process_word($word);
             // we need to make space between words in 2 cases:
             // 1. if there will be another words in the same text node
             // 2. if it is the last words AND there's space(s) at the end of the text content.
             //    e.g.: text<b>xxx </font>some more text
             if ($i < count($words) - 1 || preg_match("#\\s#", substr($content, strlen($content) - 1, 1))) {
                 $this->add_child(WhitespaceBox::create());
             }
         }
     }
 }