Exemplo n.º 1
0
 /**
  * @return StyleClass
  */
 public function processRowStyle()
 {
     $rowStyle = new StyleClass();
     $rowXml = $this->getXMLRowObject();
     $height = $rowXml->xpath('wtrPr/wtrHeight');
     $height = isset($height[0]['wval']) ? round(intval($height[0]['wval']) / 15.1) . 'px' : 'auto';
     $rowStyle->setAttribute('height', $height);
     return $rowStyle;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 public function testMergeClass()
 {
     $styleToMerge = new StyleClass();
     $styleToMerge->setAttribute('font-family', 'Arial');
     $styleToMerge->setAttribute('display', 'inline');
     $styleToMerge->setAttribute('background-color', '#FFFFFF');
     $styleToMerge->setAttribute('color', 'white');
     $styleToMerge->setAttribute('font-weight', 'italic');
     $mergedStyle = $this->style->mergeStyleClass($styleToMerge);
     $numAttributes = count($mergedStyle->getAttributes());
     $this->assertEquals(6, $numAttributes);
     $color = $mergedStyle->getAttributeValue('color');
     $fontWeight = $mergedStyle->getAttributeValue('font-weight');
     $this->assertEquals($color, 'black');
     $this->assertEquals($fontWeight, 'bold');
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 /**
  * Process element style
  * @param   object  Style class
  * @param   string  Style XML
  * @return  object
  */
 public function processParagraphStyle()
 {
     $styleClass = new StyleClass();
     $xml = $this->getXMLObject();
     // TODO: Check what this is being used for (currently not in use)
     $based = $xml->xpath('*/wbasedOn');
     if ($based) {
         $based = (string) $based[0]['wval'];
     }
     // Get font
     $font = $xml->xpath('*/wrFonts');
     $font = $font ? (string) $font[0]['wascii'] : '';
     // Get background color
     $wshd = $xml->xpath('*/wshd');
     if ($wshd) {
         $wshd = (string) $wshd[0]['wfill'];
     }
     // Get text color
     $color = $xml->xpath('*/wcolor');
     $color = $color ? (string) $color[0]['wval'] : false;
     if ($color == 'auto') {
         $color = '000000';
     }
     // Get font size
     $sz = $xml->xpath('*/wsz');
     $sz = $sz ? floor((string) $sz[0]['wval'] / 2) : '';
     // Get first line indentation
     $ident = $xml->xpath('*/wind');
     if ($ident) {
         $identNum = round((string) $ident[0]['wfirstLine'] / 11) . 'px';
         if ($identNum == '0px') {
             $identNum = round((string) $ident[0]['wleft'] / 11) . 'px';
         }
         $ident = $identNum;
     } else {
         $ident = '';
     }
     // Get top and bottom margins
     $spacing = $xml->xpath('*/wspacing');
     if ($spacing) {
         $spacingBefore = (string) $spacing[0]['wbefore'];
         $spacingAfter = (string) $spacing[0]['wafter'];
     } else {
         $spacingBefore = 0;
         $spacingAfter = 0;
     }
     // Get font weight
     $bold = $xml->xpath('*/wb');
     $weight = $bold ? 'bold' : 'normal';
     // Get font style
     $italic = $xml->xpath('*/wi');
     $italic = $italic ? true : false;
     // Get text transformation
     $allcaps = $xml->xpath('*/wcaps');
     $allcaps = $allcaps ? true : false;
     // Set margins
     $styleClass->setAttribute("margin-top", round((string) $spacingBefore / 11) . 'px');
     $styleClass->setAttribute("margin-bottom", round((string) $spacingAfter / 11) . 'px');
     // Set font styles
     $styleClass->setAttribute("font-family", $font);
     if ($color) {
         $styleClass->setAttribute("color", '#' . $color);
     }
     if (@$wshd) {
         $styleClass->setAttribute("background-color", '#' . $wshd);
     }
     if ($sz > '') {
         $styleClass->setAttribute("font-size", $sz . 'pt');
     }
     if ($weight != 'normal') {
         $styleClass->setAttribute("font-weight", $weight);
     }
     if ($italic) {
         $styleClass->setAttribute("font-style", 'italic');
     }
     if ($allcaps) {
         $styleClass->setAttribute("text-transform", 'uppercase');
     }
     if ($ident > '') {
         $styleClass->setAttribute("text-indent", $ident);
     }
     // Return styled class
     return $styleClass;
 }
Exemplo n.º 6
0
 /**
  * @return StyleClass
  */
 private function extractParagraphStyles()
 {
     $paragraphStyle = new StyleClass();
     $textOrientation = $this->getTextOrientationRules();
     if (!empty($textOrientation)) {
         $paragraphStyle->setAttribute("transform", $textOrientation['transform']);
         $paragraphStyle->setAttribute("float", $textOrientation['float']);
         $paragraphStyle->setAttribute("display", "inline-block");
     }
     return $paragraphStyle;
 }
Exemplo n.º 7
0
 /**
  * @return StyleClass
  */
 public function processParagraphStyle()
 {
     $paragraphStyle = new StyleClass();
     $lineSpacing = $this->getLineSpacing();
     $alignment = $this->getAlignment();
     $indentation = java_values($this->paragraph->getIndentationFirstLine());
     if ($indentation > 0) {
         $paragraphStyle->setAttribute("text-indent", round($indentation / 11) . 'px');
     }
     $paragraphStyle->setAttribute("line-height", $lineSpacing . "%");
     $paragraphStyle->setAttribute("text-align", $alignment);
     $paragraphStyle->setAttribute("text-indent", round($indentation / 11) . 'px');
     if ($this->getStyleID() != null) {
         $style = $this->getDocumentStyles()->getStyle($this->paragraph->getStyleID());
         $styleXML = java_values($style->getCTStyle()->toString());
         //var_dump($styleXML);
         //var_dump($this->getText());
     } else {
         $paragraphStyle->setAttribute("margin-bottom", '0.14in');
     }
     //$styleXML = java_values($this->paragraph->getCTP()->toString());
     //var_dump($styleXML);
     //var_dump($styleXML);
     //var_dump($this->paragraph->getText());
     return $paragraphStyle;
 }
Exemplo n.º 8
0
 /**
  * @param $styleToMerge
  * @return StyleClass
  */
 public function mergeStyleClass($styleToMerge)
 {
     if (is_a($styleToMerge, 'StyleClass')) {
         $mergedStyle = new StyleClass();
         $attributes = $this->getAttributes();
         if (count($attributes) > 0) {
             foreach ($attributes as $key => $attribute) {
                 $mergedStyle->setAttribute($key, $attribute);
             }
         }
         $mergeAttributes = $styleToMerge->getAttributes();
         if (!is_null($mergeAttributes)) {
             foreach ($mergeAttributes as $merge_key => $mergeAttribute) {
                 if (!$this->attributeExists($merge_key)) {
                     $mergedStyle->setAttribute($merge_key, $mergeAttribute);
                 }
             }
         }
     } else {
         $mergedStyle = new StyleClass();
     }
     return $mergedStyle;
 }
Exemplo n.º 9
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;
 }
Exemplo n.º 10
0
 /**
  * @param $name
  * @return HTMLElement
  */
 private function returnUnssuportedImageMessage($name)
 {
     $messageBox = new HTMLElement(HTMLElement::DIV);
     $boxStyleClass = new StyleClass();
     $messageText = "This image could not be imported. It's not supported format.";
     $messageParagraph = new HTMLElement(HTMLElement::P);
     $messageParagraph->setInnerText($messageText);
     $messageParagraph->setAttribute('style', "font-weight: bold");
     $messageBox->addInnerElement($messageParagraph);
     $imageName = (string) $name;
     $nameParagraph = new HTMLElement(HTMLElement::P);
     $nameParagraph->setInnerText($imageName);
     $messageBox->addInnerElement($nameParagraph);
     $boxStyleClass->setAttribute('width', '75%');
     $boxStyleClass->setAttribute('margin', '0 auto');
     $boxStyleClass->setAttribute('background-color', '#ffcfba');
     $boxStyleClass->setAttribute('color', '#d91c24');
     $boxStyleClass->setAttribute('font-size', '14px');
     $boxStyleClass->setAttribute('font-family', 'Roboto, sans-serif');
     $boxStyleClass->setAttribute('padding-bottom', '25px');
     $boxStyleClass->setAttribute('padding-top', '25px');
     $boxStyleClass->setAttribute('padding-right', '25px');
     $boxStyleClass->setAttribute('padding-left', '25px');
     $boxStyleClass->setAttribute('text-align', 'center');
     $className = $this->mainStyleSheet->getClassName($boxStyleClass);
     $messageBox->setClass($className);
     return $messageBox;
 }
Exemplo n.º 11
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;
 }