Ejemplo n.º 1
0
 function &create($text, $encoding, &$pipeline)
 {
     $box =& TextBox::create_empty($pipeline);
     $box->add_subword($text, $encoding, array());
     return $box;
 }
 function process_word($raw_content, &$pipeline)
 {
     if ($raw_content === '') {
         return false;
     }
     $ptr = 0;
     $word = '';
     $hyphens = array();
     $encoding = 'iso-8859-1';
     $manager_encoding =& ManagerEncoding::get();
     $text_box =& TextBox::create_empty($pipeline);
     $len = strlen($raw_content);
     while ($ptr < $len) {
         $char = $manager_encoding->getNextUTF8Char($raw_content, $ptr);
         // Check if current  char is a soft hyphen  character. It it is,
         // remove it from the word  (as it should not be drawn normally)
         // and store its location
         if ($char == SYMBOL_SHY) {
             $hyphens[] = strlen($word);
         } else {
             $mapping = $manager_encoding->getMapping($char);
             /**
              * If this character is not found in predefined encoding vectors,
              * we'll use "Custom" encoding and add single-character TextBox
              *
              * @TODO: handle characters without known glyph names
              */
             if (is_null($mapping)) {
                 /**
                  * No mapping to default encoding vectors found for this character
                  */
                 /**
                  * Add last word
                  */
                 if ($word !== '') {
                     $text_box->add_subword($word, $encoding, $hyphens);
                 }
                 /**
                  * Add current symbol
                  */
                 $custom_char = $manager_encoding->addCustomChar(utf8_to_code($char));
                 $text_box->add_subword($custom_char, $manager_encoding->getCustomEncodingName(), $hyphens);
                 $word = '';
             } else {
                 if (isset($mapping[$encoding])) {
                     $word .= $mapping[$encoding];
                 } else {
                     // This condition prevents empty text boxes from appearing; say, if word starts with a national
                     // character, an () - text box with no letters will be generated, in rare case causing a random line
                     // wraps, if container is narrow
                     if ($word !== '') {
                         $text_box->add_subword($word, $encoding, $hyphens);
                     }
                     reset($mapping);
                     list($encoding, $add) = each($mapping);
                     $word = $mapping[$encoding];
                     $hyphens = array();
                 }
             }
         }
     }
     if ($word !== '') {
         $text_box->add_subword($word, $encoding, $hyphens);
     }
     $this->add_child($text_box);
     return true;
 }