Skip to content

Commit c0f8cae

Browse files
committed
Fixing RTF writers : numbers should be printed as integers and not float.
This is specified in the spec, for example here : http://www.biblioscape.com/rtf15_spec.htm#Heading2 « The delimiter marks the end of an RTF control word, and can be one of the following : [...] * A digit or a hyphen (-), which indicates that a numeric parameter follows. The subsequent digital sequence is then delimited by a space or any character other than a letter or a digit. »
1 parent 0db21ae commit c0f8cae

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

src/PhpWord/Writer/RTF/Style/Border.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private function writeSide($side, $width, $color = '')
9292

9393
$content .= '\pgbrdr' . substr($side, 0, 1);
9494
$content .= '\brdrs'; // Single-thickness border; @todo Get other type of border
95-
$content .= '\brdrw' . $width; // Width
95+
$content .= '\brdrw' . round($width); // Width
9696
$content .= '\brdrcf' . $colorIndex; // Color
9797
$content .= '\brsp480'; // Space in twips between borders and the paragraph (24pt, following OOXML)
9898
$content .= ' ';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function write()
5353
$content .= '\f' . $this->nameIndex;
5454

5555
$size = $style->getSize();
56-
$content .= $this->getValueIf(is_numeric($size), '\fs' . ($size * 2));
56+
$content .= $this->getValueIf(is_numeric($size), '\fs' . round($size * 2));
5757

5858
$content .= $this->getValueIf($style->isBold(), '\b');
5959
$content .= $this->getValueIf($style->isItalic(), '\i');

src/PhpWord/Writer/RTF/Style/Indentation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public function write()
3636
return '';
3737
}
3838

39-
$content = '\fi' . $style->getFirstLine();
40-
$content .= '\li' . $style->getLeft();
41-
$content .= '\ri' . $style->getRight();
39+
$content = '\fi' . round($style->getFirstLine());
40+
$content .= '\li' . round($style->getLeft());
41+
$content .= '\ri' . round($style->getRight());
4242

4343
return $content . ' ';
4444
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public function write()
6565
$content .= $alignments[$style->getAlignment()];
6666
}
6767
$content .= $this->writeIndentation($style->getIndentation());
68-
$content .= $this->getValueIf($spaceBefore !== null, '\sb' . $spaceBefore);
69-
$content .= $this->getValueIf($spaceAfter !== null, '\sa' . $spaceAfter);
68+
$content .= $this->getValueIf($spaceBefore !== null, '\sb' . round($spaceBefore));
69+
$content .= $this->getValueIf($spaceAfter !== null, '\sa' . round($spaceAfter));
7070

7171
$styles = $style->getStyleValues();
7272
$content .= $this->writeTabs($styles['tabs']);

src/PhpWord/Writer/RTF/Style/Section.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ public function write()
4646
$content .= $this->getValueIf($style->getPageSizeW() !== null, '\pgwsxn' . round($style->getPageSizeW()));
4747
$content .= $this->getValueIf($style->getPageSizeH() !== null, '\pghsxn' . round($style->getPageSizeH()));
4848
$content .= ' ';
49-
$content .= $this->getValueIf($style->getMarginTop() !== null, '\margtsxn' . $style->getMarginTop());
50-
$content .= $this->getValueIf($style->getMarginRight() !== null, '\margrsxn' . $style->getMarginRight());
51-
$content .= $this->getValueIf($style->getMarginBottom() !== null, '\margbsxn' . $style->getMarginBottom());
52-
$content .= $this->getValueIf($style->getMarginLeft() !== null, '\marglsxn' . $style->getMarginLeft());
53-
$content .= $this->getValueIf($style->getHeaderHeight() !== null, '\headery' . $style->getHeaderHeight());
54-
$content .= $this->getValueIf($style->getFooterHeight() !== null, '\footery' . $style->getFooterHeight());
55-
$content .= $this->getValueIf($style->getGutter() !== null, '\guttersxn' . $style->getGutter());
49+
$content .= $this->getValueIf($style->getMarginTop() !== null, '\margtsxn' . round($style->getMarginTop()));
50+
$content .= $this->getValueIf($style->getMarginRight() !== null, '\margrsxn' . round($style->getMarginRight()));
51+
$content .= $this->getValueIf($style->getMarginBottom() !== null, '\margbsxn' . round($style->getMarginBottom()));
52+
$content .= $this->getValueIf($style->getMarginLeft() !== null, '\marglsxn' . round($style->getMarginLeft()));
53+
$content .= $this->getValueIf($style->getHeaderHeight() !== null, '\headery' . round($style->getHeaderHeight()));
54+
$content .= $this->getValueIf($style->getFooterHeight() !== null, '\footery' . round($style->getFooterHeight()));
55+
$content .= $this->getValueIf($style->getGutter() !== null, '\guttersxn' . round($style->getGutter()));
5656
$content .= ' ';
5757

5858
// Borders

src/PhpWord/Writer/RTF/Style/Tab.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function write()
4242
if (isset($tabs[$style->getType()])) {
4343
$content .= $tabs[$style->getType()];
4444
}
45-
$content .= '\tx' . $style->getPosition();
45+
$content .= '\tx' . round($style->getPosition());
4646

4747
return $content;
4848
}

0 commit comments

Comments
 (0)