Esempio n. 1
1
 /**
  * Get styles
  *
  * @return string
  */
 private function writeStyles()
 {
     $css = '<style>' . PHP_EOL;
     // Default styles
     $defaultStyles = array('*' => array('font-family' => Settings::getDefaultFontName(), 'font-size' => Settings::getDefaultFontSize() . 'pt'), 'a.NoteRef' => array('text-decoration' => 'none'), 'hr' => array('height' => '1px', 'padding' => '0', 'margin' => '1em 0', 'border' => '0', 'border-top' => '1px solid #CCC'));
     foreach ($defaultStyles as $selector => $style) {
         $styleWriter = new GenericStyleWriter($style);
         $css .= $selector . ' {' . $styleWriter->write() . '}' . PHP_EOL;
     }
     // Custom styles
     $customStyles = Style::getStyles();
     if (is_array($customStyles)) {
         foreach ($customStyles as $name => $style) {
             if ($style instanceof Font) {
                 $styleWriter = new FontStyleWriter($style);
                 if ($style->getStyleType() == 'title') {
                     $name = str_replace('Heading_', 'h', $name);
                 } else {
                     $name = '.' . $name;
                 }
                 $css .= "{$name} {" . $styleWriter->write() . '}' . PHP_EOL;
             } elseif ($style instanceof Paragraph) {
                 $styleWriter = new ParagraphStyleWriter($style);
                 $name = '.' . $name;
                 $css .= "{$name} {" . $styleWriter->write() . '}' . PHP_EOL;
             }
         }
     }
     $css .= '</style>' . PHP_EOL;
     return $css;
 }
Esempio n. 2
0
 /**
  * Write text
  *
  * @return string
  */
 public function write()
 {
     $html = '';
     // Paragraph style
     $paragraphStyle = $this->element->getParagraphStyle();
     $pStyleIsObject = $paragraphStyle instanceof Paragraph;
     if ($pStyleIsObject) {
         $styleWriter = new ParagraphStyleWriter($paragraphStyle);
         $paragraphStyle = $styleWriter->write();
     }
     // Font style
     $fontStyle = $this->element->getFontStyle();
     $fontStyleIsObject = $fontStyle instanceof Font;
     if ($fontStyleIsObject) {
         $styleWriter = new FontStyleWriter($fontStyle);
         $fontStyle = $styleWriter->write();
     }
     if ($paragraphStyle && !$this->withoutP) {
         $attribute = $pStyleIsObject ? 'style' : 'class';
         $html .= "<p {$attribute}=\"{$paragraphStyle}\">";
     }
     if ($fontStyle) {
         $attribute = $fontStyleIsObject ? 'style' : 'class';
         $html .= "<span {$attribute}=\"{$fontStyle}\">";
     }
     $html .= htmlspecialchars($this->element->getText());
     if ($fontStyle) {
         $html .= '</span>';
     }
     if ($paragraphStyle && !$this->withoutP) {
         $html .= '</p>' . PHP_EOL;
     }
     return $html;
 }
Esempio n. 3
0
 /**
  * Get font style.
  *
  * @return void
  */
 private function getFontStyle()
 {
     /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */
     $element = $this->element;
     $style = '';
     $fontStyle = $element->getFontStyle();
     $fStyleIsObject = $fontStyle instanceof Font;
     if ($fStyleIsObject) {
         $styleWriter = new FontStyleWriter($fontStyle);
         $style = $styleWriter->write();
     }
     if ($style) {
         $attribute = $fStyleIsObject ? 'style' : 'class';
         $this->openingTags = "<span {$attribute}=\"{$style}\">";
         $this->closingTags = "</span>";
     }
 }