Esempio n. 1
0
 public function parseHeaderTableCell($stdRow)
 {
     $stdCellContainer = new HTMLElement(HTMLElement::TD);
     $tdStyle = new StyleClass();
     $wsdt = $stdRow->xpath('wsdtPr/walias');
     $wtcBorders = $stdRow->xpath('wsdtContent/wtc/wtcPr/wtcBorders');
     if ($wtcBorders) {
         $st = empty(!$wtcBorders) ? $wtcBorders[0] : null;
     }
     $borders = $this->getBorderProperties($st);
     if (!is_null($borders) and is_array($borders)) {
         if (array_key_exists('bottom', $borders)) {
             $tdStyle->setAttribute("border-bottom", "1px " . HWPFWrapper::getBorder($borders['bottom']['val']) . " #" . $borders['bottom']['color']);
         }
         if (array_key_exists('top', $borders)) {
             $tdStyle->setAttribute("border-top", "1px " . HWPFWrapper::getBorder($borders['top']['val']) . " #" . $borders['top']['color']);
         }
         if (array_key_exists('right', $borders)) {
             $tdStyle->setAttribute("border-right", "1px " . HWPFWrapper::getBorder($borders['right']['val']) . " #" . $borders['right']['color']);
         }
         if (array_key_exists('left', $borders)) {
             $tdStyle->setAttribute("border-left", "1px " . HWPFWrapper::getBorder($borders['left']['val']) . " #" . $borders['left']['color']);
         }
     }
     $backgroundColor = $stdRow->xpath('wsdtContent/wtc/wtcPr/wshd')[0]['wfill'];
     if ($backgroundColor == "FFFFFF") {
         $tdStyle->setAttribute('background-color', "#" . $borders['bottom']['color']);
     } else {
         $tdStyle->setAttribute('background-color', "#" . $backgroundColor);
     }
     $textBox = "";
     foreach ($wsdt as $walias) {
         $charText = $walias[0]['wval'];
         $textBox .= (string) $charText;
     }
     $stdCellContainer->setInnerText($textBox);
     //Add class to style sheet
     if (isset($this->mainStyleSheet)) {
         $cnm = $this->mainStyleSheet->getClassName($tdStyle);
         $stdCellContainer->setClass($cnm);
     }
     $stdCellContainer->setAttribute('colspan', '2');
     return $stdCellContainer;
 }
Esempio n. 2
0
 /**
  * @param $run
  * @return mixed
  */
 private function processRunStyle($run)
 {
     $xml = $this->getXMLRun();
     // Get color
     $color = java_values($run->getColor());
     $color = is_null($color) ? 'black' : '#' . $color;
     //Get background highlight color
     $runCharShadows = $xml->xpath("wrPr/wshd");
     $backgroundColor = !empty($runCharShadows) ? $runCharShadows[0]['wfill'] : null;
     // Get StrikeThrough
     $runStrike = $xml->xpath("wrPr/wstrike");
     $isStrikeThrough = !empty($runStrike) ? true : false;
     // Get style
     $isItalic = java_values($run->isItalic());
     $fontStyle = $isItalic ? 'italic' : 'normal';
     // Get weight
     $isBold = java_values($run->isBold());
     $fontWeight = $isBold ? 'bold' : 'normal';
     // Get char font family and size
     $fontFamily = java_values($run->getFontFamily());
     $fontSize = floor(java_values($run->getFontSize()));
     // Get underline
     $underlined_type = java_values($run->getUnderline()->getValue());
     //Default underline set to none
     if (!is_int($underlined_type)) {
         $underlined_type = 12;
     }
     $underlined = HWPFWrapper::getUnderline($underlined_type);
     // Create empty class, and attach it to span element
     $styleClass = new StyleClass();
     // Set style attributes
     if ($color != 'black' and $color != '#000000') {
         $styleClass->setAttribute("color", $color);
     }
     if ($fontWeight != 'normal') {
         $styleClass->setAttribute("font-weight", $fontWeight);
     }
     if ($fontStyle != 'normal') {
         $styleClass->setAttribute("font-style", $fontStyle);
     }
     if ($fontSize) {
         $styleClass->setAttribute("font-size", (string) $fontSize . "pt");
     }
     if ($underlined != 'none') {
         $styleClass->setAttribute("text-decoration", $underlined);
     }
     if (!is_null($backgroundColor)) {
         $styleClass->setAttribute("background-color", "#" . $backgroundColor->__toString());
     }
     if ($fontFamily) {
         $styleFont = HWPFWrapper::getFontFamily($fontFamily);
         $styleClass->setAttribute("font-family", $styleFont);
     }
     if ($isStrikeThrough) {
         $styleClass->setAttribute("text-decoration", "line-through");
     }
     $className = $this->mainStyleSheet->getClassName($styleClass);
     return $className;
 }
Esempio n. 3
0
 /**
  * @return StyleClass
  */
 public function processTableCellStyle()
 {
     $tableCellStyleClass = new StyleClass();
     $cellBorders = $this->getCellStyleBorders();
     if (!is_null($cellBorders)) {
         $tableBorders = array('right' => 'insideV', 'bottom' => 'insideH');
         foreach ($cellBorders as $key => $border) {
             if (in_array($key, $tableBorders)) {
                 $direction = $key == "insideH" ? "bottom" : "right";
                 $tableCellStyleClass->setAttribute("border-" . $direction, $border['size'] . "px " . HWPFWrapper::getBorder($border['val']) . " #" . $border['color']);
             }
         }
     }
     return $tableCellStyleClass;
 }
Esempio n. 4
0
 /**
  * @return StyleClass
  */
 public function processTableCellStyle()
 {
     $cellClass = new StyleClass();
     $cell_width = $this->getCellWidht();
     if (!empty($cell_width)) {
         $cellClass->setAttribute('width', $cell_width['value'] . 'px');
     }
     $color = $this->getColor();
     if (!is_null($color) && $color != "auto") {
         $cellClass->setAttribute("background-color", "#" . "{$color}");
     }
     $result = $this->getXMLCellObject()->xpath("wtcPr/wtcBorders");
     $tcBorders = count($result) > 0 ? $result[0] : array();
     $cellBorders = $this->getBorderProperties($tcBorders);
     //Assign border styles
     if (!is_null($cellBorders)) {
         $tableBorders = array('left', 'right', 'top', 'bottom');
         foreach ($cellBorders as $key => $border) {
             if (in_array($key, $tableBorders)) {
                 $cellClass->setAttribute("border-" . $key, $border['size'] . "px " . HWPFWrapper::getBorder($border['val']) . " #" . $border['color']);
             }
         }
     }
     return $cellClass;
 }
Esempio n. 5
0
 /**
  * @return string
  */
 private function getAlignment()
 {
     $alignment = java_values($this->paragraph->getAlignment()->getValue());
     $justification = HWPFWrapper::getAlignment($alignment);
     return $justification;
 }
Esempio n. 6
0
 /**
  * parses a characterRun element of HWPF document
  * @param HWPFSection $characterRun
  * @return HTMLElement
  */
 private function parseCharacterRun($characterRun)
 {
     $container = null;
     // Even non text elements will have a text property
     $text = nl2br(java_values($characterRun->text()));
     // in case the picture table contains that particular character run, then it is a picture, which needs to be parced seperately
     if (java_values($this->document->getPicturesTable()->hasPicture($characterRun))) {
         $isPicture = ord(substr($text, 0, 1)) == HWPFWrapper::SPECCHAR_IMAGE;
         $picture = $this->document->getPicturesTable()->extractPicture($characterRun, true);
         if (java_values($picture) != null) {
             // if it is proven to be picture, then let's parse it
             $container = $this->processPicture($picture, $isPicture);
             return $container;
         } else {
             //TODO: what to do here?
         }
     }
     // Some other types of character runs, can be a drawn object, hyperlink, note e.g.
     if (java_values($characterRun->isSpecialCharacter())) {
         // TODO: add all type parsings
         if (ord(substr($text, 0, 1)) == HWPFWrapper::SPECCHAR_DRAWN_OBJECT) {
         }
     }
     // in every other case, if we got here we do simple text parsing
     //create empty span element
     $container = new HTMLElement(HTMLElement::SPAN);
     $color = HWPFWrapper::getColor(java_values($characterRun->getColor()));
     $isItalic = java_values($characterRun->isItalic());
     if ($isItalic) {
         $fontStyle = 'italic';
     } else {
         $fontStyle = 'normal';
     }
     $isBold = java_values($characterRun->isBold());
     if ($isBold) {
         $fontWeight = 'bold';
     } else {
         $fontWeight = 'normal';
     }
     $fontSize = java_values($characterRun->getFontSize()) / 2;
     $fontFamily = java_values($characterRun->getFontName());
     // create empty class, and attach it to span element
     $styleClass = new StyleClass();
     $styleClass->setAttribute("color", $color);
     $styleClass->setAttribute("font-weight", $fontWeight);
     $styleClass->setAttribute("font-style", $fontStyle);
     $styleClass->setAttribute("font-size", $fontSize . "pt");
     $styleClass->setAttribute("font-family", $fontFamily);
     $className = $this->htmlDocument->styleSheet->getClassName($styleClass);
     $container->setClass($className);
     if (strlen($text) == 1 && (substr($text, -1, 1) == "\r" || ord(substr($text, -1, 1)) == HWPFWrapper::BEL_MARK)) {
         $text = $text . '<br />';
     }
     // set span inner text
     $container->setInnerText($text);
     return $container;
 }
Esempio n. 7
0
 /**
  * @param $characterRun
  * @param $xml
  * @return array
  */
 private function processCharacterRunStyle($characterRun, $xml)
 {
     // Get color
     $color = java_values($characterRun->getColor());
     if (is_null($color)) {
         $color = 'black';
     } else {
         $color = '#' . $color;
     }
     //Get background highlight color
     $runCharShadows = $xml->xpath("wrPr/wshd");
     if (!empty($runCharShadows)) {
         $backgroundColor = $runCharShadows[0]['wfill'];
     } else {
         $backgroundColor = null;
     }
     // Get style
     $isItalic = java_values($characterRun->isItalic());
     $fontStyle = $isItalic ? 'italic' : 'normal';
     // Get weight
     $isBold = java_values($characterRun->isBold());
     $fontWeight = $isBold ? 'bold' : 'normal';
     // Get char font family and size
     $fontFamily = java_values($characterRun->getFontFamily());
     $fontSize = floor(java_values($characterRun->getFontSize()));
     // Get underline
     $underlined_type = java_values($characterRun->getUnderline()->getValue());
     //Default underline set to none
     if (!is_int($underlined_type)) {
         $underlined_type = 12;
     }
     $underlined = HWPFWrapper::getUnderline($underlined_type);
     // Create empty class, and attach it to span element
     $styleClass = new StyleClass();
     // Prepare ctrStyle
     $ctrStyle = $xml->xpath('*/wrStyle');
     if ($ctrStyle) {
         $ctrStyle = (string) $ctrStyle[0]['wval'];
     }
     // Get style class
     if (!is_array($ctrStyle)) {
         $style = $this->styles->getStyle($ctrStyle);
         $styleXML = java_values($style->getCTStyle()->toString());
         $styleClass = $this->processStyle($styleClass, $styleXML);
     }
     //Initiate semantic containers
     $boldContainer = null;
     $italicContainer = null;
     // Set style attributes
     if ($color != 'black' and $color != '#000000') {
         $styleClass->setAttribute("color", $color);
     }
     if ($fontWeight != 'normal') {
         $boldContainer = new HTMLElement(HTMLElement::STRONG);
     }
     if ($fontStyle != 'normal') {
         $styleClass->setAttribute("font-style", $fontStyle);
     }
     if ($fontSize) {
         $styleClass->setAttribute("font-size", (string) $fontSize . "pt");
     }
     if ($fontFamily) {
         $styleFont = HWPFWrapper::getFontFamily($fontFamily);
         $styleClass->setAttribute("font-family", $styleFont);
     }
     if ($underlined != 'none') {
         $styleClass->setAttribute("text-decoration", $underlined);
     }
     if (!is_null($backgroundColor)) {
         $styleClass->setAttribute("background-color", "#" . $backgroundColor->__toString());
     }
     $className = $this->mainStyleSheet->getClassName($styleClass);
     $runStyle = array("style" => $className, "containers" => array("bold" => $boldContainer, "italic" => $italicContainer));
     return $runStyle;
 }
Esempio n. 8
0
 /**
  * @param $format
  * @return StyleClass
  * @internal param $borders
  * @internal param $conditionalTableCellStyleClass
  * @internal param $backgroundColor
  */
 private function applyConditionalFormatStyles($format)
 {
     $conditionalTableCellStyleClass = new StyleClass();
     // Get internal values
     $borders = $format["borders"];
     $backgroundColor = $format["backgroundColor"];
     // Apply first row styles
     if (!empty($borders) && is_array($borders)) {
         $conditionalCellBorders = array('bottom', 'top', 'right', 'left');
         foreach ($borders as $key => $border) {
             if (in_array($key, $conditionalCellBorders)) {
                 $conditionalTableCellStyleClass->setAttribute("border-" . $key, $border['size'] . "px " . HWPFWrapper::getBorder($border['val']) . " #" . $border['color']);
             }
         }
     }
     if (strlen($backgroundColor)) {
         $conditionalTableCellStyleClass->setAttribute("background-color", '#' . $backgroundColor);
     }
     return $conditionalTableCellStyleClass;
 }
Esempio n. 9
0
 /**
  * @param $abstractNum
  * @param $numberingInfo
  * @return array
  */
 private function extractListProperties($abstractNum, $numberingInfo)
 {
     //Check if the object was created
     if (is_object($abstractNum)) {
         //get xml structure
         $stringNumbering = java_values($abstractNum->getCTAbstractNum()->ToString());
         $numberingXml = str_replace('w:', 'w', $stringNumbering);
         $numXml = new SimpleXMLElement($numberingXml);
         $ilvl = $numXml->xpath('wlvl/wnumFmt');
         $ilvlSymbol = $numXml->xpath('wlvl/wlvlText');
         $listSymbol = $ilvlSymbol[$numberingInfo['lvl']]["wval"];
         //Calculate list indentation
         $listIndentation = $this->calculateListIndentation($numXml, $numberingInfo);
         //check if the list type exist and get style rule
         if (is_array($ilvl)) {
             $enc = utf8_encode($listSymbol);
             $listType = utf8_encode($ilvl[$numberingInfo['lvl']]["wval"]);
             $listTypeStyle = HWPFWrapper::getListType($listType, $enc);
         }
         $listProperties = array('type' => $listTypeStyle, 'indentation' => $listIndentation);
     } else {
         //Default settings
         $listProperties = array('type' => '', 'indentation' => '');
     }
     return $listProperties;
 }