示例#1
0
 /**
  * Parses a characterRun element of HWPF document
  * @param   object  Character run
  * @return  HTMLElement
  */
 private function parseCharacterRun($characterRun)
 {
     // Create null container
     $container = null;
     // Even non text elements will have a text property
     $text = nl2br(java_values($characterRun->getText(0)));
     // Get and process pictures if there are any
     $pictures = java_values($characterRun->getEmbeddedPictures());
     if (count($pictures) > 0) {
         foreach ($pictures as $key => $picture) {
             $path = XWPFToHTMLConverter::getDirectoryPath();
             $pictureContainer = new XWPFPicture($picture, $this->mainStyleSheet, $path);
             $container = $pictureContainer->processPicture();
             return $container;
         }
     }
     //Get Run xml
     $charXml = java_values($characterRun->getCTR()->ToString());
     //Check for section numbering
     $this->checkSectionNumbering($characterRun, $charXml);
     $charXml = str_replace('w:', 'w', $charXml);
     $xml = new SimpleXMLElement($charXml);
     //Get the value of hyperlink
     $link = $xml->xpath("wrPr/wrStyle");
     //Check if the hyperlink xml tag exists
     if (!empty($link)) {
         $linkValue = $link[0]['wval'];
     } else {
         $linkValue = "none";
     }
     //Check if is valid internet link
     if ($linkValue == 'InternetLink') {
         //Create empty A tag for the hyperlink and the text
         $container = new HTMLElement(HTMLElement::A);
         $container->setAttribute('href', java_values($characterRun->getText(0)));
     } else {
         /* In every other case, if we got here we do simple text parsing */
         // Create empty text element
         $container = new HTMLElement(HTMLElement::SPAN);
     }
     $styleClass = $this->processCharacterRunStyle($characterRun, $xml);
     if ($container->getTagName() != 'a') {
         $container = new HTMLElement(HTMLElement::SPAN);
     }
     $addNewLine = false;
     // Check for new line
     if (strlen($text) == 1 && (substr($text, -1, 1) == "\r" || ord(substr($text, -1, 1)) == HWPFWrapper::BEL_MARK)) {
         $addNewLine = true;
     }
     //escape text for xhtml
     $text = XhtmlEntityConverter::convertToNumericalEntities(htmlentities($text, ENT_COMPAT | ENT_XHTML));
     if ($addNewLine) {
         $text .= '<br />';
     }
     $boldContainer = $styleClass['containers']['bold'];
     $italicContainer = $styleClass['containers']['italic'];
     //TODO check why this fails with large documents
     //if($container->getTagName() == '') $container->setInnerElement($text);
     if ($boldContainer and $italicContainer) {
         //Set Bold and italic semantic tags
         $container->addInnerElement($boldContainer);
         $boldContainer->addInnerElement($italicContainer);
         $italicContainer->setInnerText($text);
     } elseif ($boldContainer) {
         //Set bold strong tag
         $container->addInnerElement($boldContainer);
         $boldContainer->setInnerText($text);
     } elseif ($italicContainer) {
         // Set italic em tag
         $container->addInnerElement($italicContainer);
         $italicContainer->setInnerText($text);
     } else {
         // Set inner text to span tag
         $container->setInnerText($text);
     }
     // Get and set class name on container
     $container->setClass($styleClass['style'] . ' textframe cke_focus');
     // Return container
     return $container;
 }