예제 #1
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;
 }
예제 #2
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;
 }