예제 #1
0
 /**
  * @return string
  */
 private function getAlignment()
 {
     $alignment = java_values($this->paragraph->getAlignment()->getValue());
     $justification = HWPFWrapper::getAlignment($alignment);
     return $justification;
 }
예제 #2
0
 /**
  * Parses a paragraph element of HWPF document
  * @param   object  Paragraph
  * @param   string  Element key
  * @return  HTMLElement
  */
 private function parseParagraph($paragraph, $parIterator)
 {
     // Create new HTML element and its style class
     $container = new HTMLElement(HTMLElement::P);
     $styleClass = new StyleClass();
     // Get styles
     $this->styles = $this->document->getStyles();
     // Get character runs
     $charRuns = java_values($paragraph->getIRuns());
     //Check paragraph numbering
     $numberingInfo = $this->paragraphExtractNumbering($paragraph);
     if (java_values($paragraph->getStyleID()) != null) {
         // Get style class
         $style = $this->styles->getStyle($paragraph->getStyleID());
         $styleXML = java_values($style->getCTStyle()->toString());
         //Check section numbering
         if (strpos($styleXML, '<w:ilvl') !== false) {
             $sectionContainer = $this->processSectionNumberingToc($styleXML);
         }
         //Check if paragraph has custom style list
         if (strpos($styleXML, '<w:numId') !== false and strpos($styleXML, 'w:customStyle="1"') !== false and !$numberingInfo) {
             //Parse Custom List
             $this->parseCustomStyleList($paragraph, $styleXML);
             return self::CUSTOMLIST;
         }
         //Get style name
         $styleName = java_values($style->getName());
         //Apply heading html tag and section numbering if exists
         if (strpos(strtolower($styleName), 'heading') !== false) {
             //Create headline container
             $container = $this->selectHeadlineContainer($styleName);
         }
         //Process paragraph style
         $styleClass = $this->processStyle($styleClass, $styleXML);
     } else {
         // Normal style (margin bottom 0.14in)
         $styleClass->setAttribute("margin-bottom", '0.14in');
     }
     //Reset list level for custom lists
     if (!$numberingInfo) {
         $this->customListLevel = 0;
         $this->auxList = "";
     }
     // Set indentation
     $indentation = java_values($paragraph->getIndentationFirstLine());
     // Check if is list indentation
     $numberingInfo = $this->paragraphExtractNumbering($paragraph);
     //Set indentation to paragraphs except for list items
     if ($indentation > 0 and !$numberingInfo) {
         $styleClass->setAttribute("text-indent", round($indentation / 11) . 'px');
     }
     // Get xml of this paragraph
     $paragraph_xml = java_values($paragraph->getCTP()->toString());
     //var_dump($paragraph_xml);
     //Check for book mark links to TOC
     if (strpos($paragraph_xml, '<w:bookmarkStart') !== false) {
         //Parse numbering bookmark
         $this->parseTocBookmarks($paragraph, $container);
     }
     //Check if is a table of contents
     if (strpos($paragraph_xml, '<w:fldChar w:fldCharType="begin"/>') !== false and $this->currentProcessedPart == "BODY") {
         $tocContainer = $this->parseToc($paragraph);
         $this->hasTOC = true;
         return $tocContainer;
     }
     $this->setLineSpace($paragraph, $styleClass);
     // Iterate through paragraph characters
     $this->parseRuns($charRuns, $container);
     // Get alignment
     $alignment = java_values($paragraph->getAlignment()->getValue());
     $justification = HWPFWrapper::getAlignment($alignment);
     // Set alignment on paragraph
     $styleClass->setAttribute("text-align", $justification);
     //Set class to html element
     $className = $this->mainStyleSheet->getClassName($styleClass);
     $container->setClass('textframe horizontal common_style1 ' . $className);
     // Add id attribute to container for this paragraph
     $container->setAttribute('id', 'div_' . $parIterator);
     // Wrap inside header tag if is a headlines
     if (in_array($container->getTagName(), $this->headlineElements)) {
         $headline = $container;
         $container = new HTMLElement(HTMLElement::HEADER);
         $exists = $styleClass->attributeExists('font-size');
         if (!$exists) {
             $styleClass->setAttribute("font-size", 'medium');
         }
         $container->addInnerElement($headline);
     }
     // Return container
     return $container;
 }