Skip to content

Commit 03d4a36

Browse files
committed
fixed HTML superscript, and added allcaps, smallcaps, and letter-spacing
1 parent 601a2b6 commit 03d4a36

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/PhpWord/Writer/HTML/Element/Text.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ private function getParagraphStyle()
164164
if ($pStyleIsObject) {
165165
$styleWriter = new ParagraphStyleWriter($paragraphStyle);
166166
$style = $styleWriter->write();
167+
} elseif (is_string($paragraphStyle)) {
168+
$style = $paragraphStyle;
167169
}
168170
if ($style) {
169171
$attribute = $pStyleIsObject ? 'style' : 'class';
@@ -186,6 +188,8 @@ private function getFontStyle()
186188
if ($fStyleIsObject) {
187189
$styleWriter = new FontStyleWriter($fontStyle);
188190
$style = $styleWriter->write();
191+
} elseif (is_string($fontStyle)) {
192+
$style = $fontStyle;
189193
}
190194
if ($style) {
191195
$attribute = $fStyleIsObject ? 'style' : 'class';

src/PhpWord/Writer/HTML/Style/Font.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,17 @@ public function write()
5252
$css['background'] = $this->getValueIf($fgColor != '', $fgColor);
5353
$css['font-weight'] = $this->getValueIf($style->isBold(), 'bold');
5454
$css['font-style'] = $this->getValueIf($style->isItalic(), 'italic');
55-
$css['vertical-align'] = $this->getValueIf($style->isSuperScript(), 'italic');
56-
$css['vertical-align'] = $this->getValueIf($style->isSuperScript(), 'super');
57-
$css['vertical-align'] = $this->getValueIf($style->isSubScript(), 'sub');
55+
$css['vertical-align'] = '';
56+
$css['vertical-align'] .= $this->getValueIf($style->isSuperScript(), 'super');
57+
$css['vertical-align'] .= $this->getValueIf($style->isSubScript(), 'sub');
5858
$css['text-decoration'] = '';
5959
$css['text-decoration'] .= $this->getValueIf($underline, 'underline ');
6060
$css['text-decoration'] .= $this->getValueIf($lineThrough, 'line-through ');
61+
$css['text-transform'] = $this->getValueIf($style->isAllCaps(), 'uppercase');
62+
$css['font-variant'] = $this->getValueIf($style->isSmallCaps(), 'small-caps');
63+
64+
$spacing = $style->getSpacing();
65+
$css['letter-spacing'] = $this->getValueIf(!is_null($spacing), ($spacing / 20) . 'pt');
6166

6267
return $this->assembleCss($css);
6368
}

src/PhpWord/Writer/HTML/Style/Paragraph.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ public function write()
8080
$after = $spacing->getAfter();
8181
$css['margin-top'] = $this->getValueIf(!is_null($before), ($before / 20) . 'pt');
8282
$css['margin-bottom'] = $this->getValueIf(!is_null($after), ($after / 20) . 'pt');
83+
} else {
84+
$css['margin-top'] = '0';
85+
$css['margin-bottom'] = '0';
8386
}
8487

8588
return $this->assembleCss($css);

0 commit comments

Comments
 (0)