From c0f8cae55c3aeb6f212e79e87c4691e47f414162 Mon Sep 17 00:00:00 2001 From: Samuel BF <36996277+Samuel-BF@users.noreply.github.com> Date: Tue, 18 Dec 2018 15:04:25 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Fixing=20RTF=20writers=20:=20numbers=20shou?= =?UTF-8?q?ld=20be=20printed=20as=20integers=20and=20not=20float.=20This?= =?UTF-8?q?=20is=20specified=20in=20the=20spec,=20for=20example=20here=20:?= =?UTF-8?q?=20http://www.biblioscape.com/rtf15=5Fspec.htm#Heading2=20?= =?UTF-8?q?=C2=AB=20The=20delimiter=20marks=20the=20end=20of=20an=20RTF=20?= =?UTF-8?q?control=20word,=20and=20can=20be=20one=20of=20the=20following?= =?UTF-8?q?=20:=20[...]=20*=20A=20digit=20or=20a=20hyphen=20(-),=20which?= =?UTF-8?q?=20indicates=20that=20a=20numeric=20parameter=20follows.=20The?= =?UTF-8?q?=20subsequent=20digital=20sequence=20is=20then=20delimited=20by?= =?UTF-8?q?=20a=20space=20or=20any=20character=20other=20than=20a=20letter?= =?UTF-8?q?=20or=20a=20digit.=20=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/Writer/RTF/Style/Border.php | 2 +- src/PhpWord/Writer/RTF/Style/Font.php | 2 +- src/PhpWord/Writer/RTF/Style/Indentation.php | 6 +++--- src/PhpWord/Writer/RTF/Style/Paragraph.php | 4 ++-- src/PhpWord/Writer/RTF/Style/Section.php | 14 +++++++------- src/PhpWord/Writer/RTF/Style/Tab.php | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index 08dcf01810..db97c28d00 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -92,7 +92,7 @@ private function writeSide($side, $width, $color = '') $content .= '\pgbrdr' . substr($side, 0, 1); $content .= '\brdrs'; // Single-thickness border; @todo Get other type of border - $content .= '\brdrw' . $width; // Width + $content .= '\brdrw' . round($width); // Width $content .= '\brdrcf' . $colorIndex; // Color $content .= '\brsp480'; // Space in twips between borders and the paragraph (24pt, following OOXML) $content .= ' '; diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index 8c729425d1..b9001ea0ea 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -53,7 +53,7 @@ public function write() $content .= '\f' . $this->nameIndex; $size = $style->getSize(); - $content .= $this->getValueIf(is_numeric($size), '\fs' . ($size * 2)); + $content .= $this->getValueIf(is_numeric($size), '\fs' . round($size * 2)); $content .= $this->getValueIf($style->isBold(), '\b'); $content .= $this->getValueIf($style->isItalic(), '\i'); diff --git a/src/PhpWord/Writer/RTF/Style/Indentation.php b/src/PhpWord/Writer/RTF/Style/Indentation.php index dd52230ee8..50e8ad9940 100644 --- a/src/PhpWord/Writer/RTF/Style/Indentation.php +++ b/src/PhpWord/Writer/RTF/Style/Indentation.php @@ -36,9 +36,9 @@ public function write() return ''; } - $content = '\fi' . $style->getFirstLine(); - $content .= '\li' . $style->getLeft(); - $content .= '\ri' . $style->getRight(); + $content = '\fi' . round($style->getFirstLine()); + $content .= '\li' . round($style->getLeft()); + $content .= '\ri' . round($style->getRight()); return $content . ' '; } diff --git a/src/PhpWord/Writer/RTF/Style/Paragraph.php b/src/PhpWord/Writer/RTF/Style/Paragraph.php index cb50a31b02..8ef3e146d9 100644 --- a/src/PhpWord/Writer/RTF/Style/Paragraph.php +++ b/src/PhpWord/Writer/RTF/Style/Paragraph.php @@ -65,8 +65,8 @@ public function write() $content .= $alignments[$style->getAlignment()]; } $content .= $this->writeIndentation($style->getIndentation()); - $content .= $this->getValueIf($spaceBefore !== null, '\sb' . $spaceBefore); - $content .= $this->getValueIf($spaceAfter !== null, '\sa' . $spaceAfter); + $content .= $this->getValueIf($spaceBefore !== null, '\sb' . round($spaceBefore)); + $content .= $this->getValueIf($spaceAfter !== null, '\sa' . round($spaceAfter)); $styles = $style->getStyleValues(); $content .= $this->writeTabs($styles['tabs']); diff --git a/src/PhpWord/Writer/RTF/Style/Section.php b/src/PhpWord/Writer/RTF/Style/Section.php index ee6efcf3a0..190bb67036 100644 --- a/src/PhpWord/Writer/RTF/Style/Section.php +++ b/src/PhpWord/Writer/RTF/Style/Section.php @@ -46,13 +46,13 @@ public function write() $content .= $this->getValueIf($style->getPageSizeW() !== null, '\pgwsxn' . round($style->getPageSizeW())); $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pghsxn' . round($style->getPageSizeH())); $content .= ' '; - $content .= $this->getValueIf($style->getMarginTop() !== null, '\margtsxn' . $style->getMarginTop()); - $content .= $this->getValueIf($style->getMarginRight() !== null, '\margrsxn' . $style->getMarginRight()); - $content .= $this->getValueIf($style->getMarginBottom() !== null, '\margbsxn' . $style->getMarginBottom()); - $content .= $this->getValueIf($style->getMarginLeft() !== null, '\marglsxn' . $style->getMarginLeft()); - $content .= $this->getValueIf($style->getHeaderHeight() !== null, '\headery' . $style->getHeaderHeight()); - $content .= $this->getValueIf($style->getFooterHeight() !== null, '\footery' . $style->getFooterHeight()); - $content .= $this->getValueIf($style->getGutter() !== null, '\guttersxn' . $style->getGutter()); + $content .= $this->getValueIf($style->getMarginTop() !== null, '\margtsxn' . round($style->getMarginTop())); + $content .= $this->getValueIf($style->getMarginRight() !== null, '\margrsxn' . round($style->getMarginRight())); + $content .= $this->getValueIf($style->getMarginBottom() !== null, '\margbsxn' . round($style->getMarginBottom())); + $content .= $this->getValueIf($style->getMarginLeft() !== null, '\marglsxn' . round($style->getMarginLeft())); + $content .= $this->getValueIf($style->getHeaderHeight() !== null, '\headery' . round($style->getHeaderHeight())); + $content .= $this->getValueIf($style->getFooterHeight() !== null, '\footery' . round($style->getFooterHeight())); + $content .= $this->getValueIf($style->getGutter() !== null, '\guttersxn' . round($style->getGutter())); $content .= ' '; // Borders diff --git a/src/PhpWord/Writer/RTF/Style/Tab.php b/src/PhpWord/Writer/RTF/Style/Tab.php index fe1f9363eb..a21b13d39d 100644 --- a/src/PhpWord/Writer/RTF/Style/Tab.php +++ b/src/PhpWord/Writer/RTF/Style/Tab.php @@ -42,7 +42,7 @@ public function write() if (isset($tabs[$style->getType()])) { $content .= $tabs[$style->getType()]; } - $content .= '\tx' . $style->getPosition(); + $content .= '\tx' . round($style->getPosition()); return $content; } From 10b106ce05df74a57192094a9bcb8321af6eb96f Mon Sep 17 00:00:00 2001 From: troosan Date: Wed, 26 Dec 2018 17:20:15 +0100 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 220d2eeb20..1e21db067a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ v0.16.0 (xx dec 2018) - Fix loading of Sharepoint document @Garrcomm #1498 - RTF writer: Round getPageSizeW and getPageSizeH to avoid decimals @Patrick64 #1493 - Fix parsing of Office 365 documents @Timanx #1485 +- For RTF writers, sizes should should never have decimals @Samuel-BF #1536 v0.15.0 (14 Jul 2018) ----------------------