diff --git a/src/PhpWord/Style/Paragraph.php b/src/PhpWord/Style/Paragraph.php index 72f0f809..580ef54a 100644 --- a/src/PhpWord/Style/Paragraph.php +++ b/src/PhpWord/Style/Paragraph.php @@ -85,7 +85,7 @@ class Paragraph extends Border /** * Indentation * - * @var \PhpOffice\PhpWord\Style\Indentation + * @var \PhpOffice\PhpWord\Style\Indentation|null */ private $indentation; diff --git a/src/PhpWord/Writer/ODText/Element/Field.php b/src/PhpWord/Writer/ODText/Element/Field.php index c95139ac..f7a74c1d 100644 --- a/src/PhpWord/Writer/ODText/Element/Field.php +++ b/src/PhpWord/Writer/ODText/Element/Field.php @@ -41,7 +41,7 @@ class Field extends Text $type = strtolower($element->getType()); switch ($type) { - case 'date': // Owen 2020-01-02 + case 'date': case 'page': case 'numpages': $this->writeDefault($element, $type); @@ -61,7 +61,7 @@ class Field extends Text } } switch ($type) { - case 'date': // Owen 2019-01-02 + case 'date': $xmlWriter->startElement('text:date'); $xmlWriter->writeAttribute('text:fixed', 'false'); $xmlWriter->endElement(); diff --git a/src/PhpWord/Writer/ODText/Part/Content.php b/src/PhpWord/Writer/ODText/Part/Content.php index 8eaad40f..ea4c87d2 100644 --- a/src/PhpWord/Writer/ODText/Part/Content.php +++ b/src/PhpWord/Writer/ODText/Part/Content.php @@ -186,7 +186,8 @@ class Content extends AbstractPart $styleWriter->write(); $sects = $this->getParentWriter()->getPhpWord()->getSections(); - for ($i = 0; $i < count($sects); ++$i) { + $countsects = count($sects); + for ($i = 0; $i < $countsects; ++$i) { $iplus1 = $i + 1; $style = new Paragraph(); $style->setStyleName("SB$iplus1"); @@ -297,7 +298,7 @@ class Content extends AbstractPart /** * Get style of individual element * - * @param \PhpOffice\PhpWord\Element\Text $element + * @param \PhpOffice\PhpWord\Element\Text|\PhpOffice\PhpWord\Element\TextRun $element * @param int $paragraphStyleCount * @param int $fontStyleCount */ @@ -331,7 +332,7 @@ class Content extends AbstractPart } else { $element->setParagraphStyle($name); } - } elseif (is_string($paragraphStyle)) { + } else { $paragraphStyleCount++; $parstylename = "P$paragraphStyleCount" . "_$paragraphStyle"; $style = $phpWord->addParagraphStyle($parstylename, $paragraphStyle); diff --git a/src/PhpWord/Writer/ODText/Part/Styles.php b/src/PhpWord/Writer/ODText/Part/Styles.php index 862f4b2a..bcd57ad5 100644 --- a/src/PhpWord/Writer/ODText/Part/Styles.php +++ b/src/PhpWord/Writer/ODText/Part/Styles.php @@ -140,16 +140,12 @@ class Styles extends AbstractPart /** * Convert int in twips to inches/cm then to string and append unit * - * @param int $twips - * @param string $dflt + * @param int|float $twips * @param float $factor * return string */ - private static function cvttwiptostr($twips, $dflt, $factor = 1.0) // Owen 2019-08-06 + private static function cvttwiptostr($twips, $factor = 1.0) { - if ($twips === null) { - return $dflt; - } $ins = (string) ($twips * $factor / Converter::INCH_TO_TWIP) . 'in'; $cms = (string) ($twips * $factor * Converter::INCH_TO_CM / Converter::INCH_TO_TWIP) . 'cm'; @@ -161,10 +157,11 @@ class Styles extends AbstractPart * * @param \PhpOffice\Common\XMLWriter $xmlWriter */ - private function writePageLayout(XMLWriter $xmlWriter) // Owen 2019-06-19 + private function writePageLayout(XMLWriter $xmlWriter) { $sections = $this->getParentWriter()->getPhpWord()->getSections(); - for ($i = 0; $i < count($sections); ++$i) { + $countsects = count($sections); + for ($i = 0; $i < $countsects; ++$i) { $this->writePageLayoutIndiv($xmlWriter, $sections[$i], $i + 1); } } @@ -189,23 +186,13 @@ class Styles extends AbstractPart } else { $botfactor = 1.0; } - $pwidth = '21.001cm'; - $pheight = '29.7cm'; - $orient = 'portrait'; - $mtop = $mleft = $mright = '2.501cm'; - $mbottom = '2cm'; - if ($sty instanceof \PhpOffice\PhpWord\Style\Section) { - $ori = $sty->getOrientation(); - if ($ori !== null) { - $orient = $ori; - } - $pwidth = self::cvttwiptostr($sty->getPageSizeW(), $pwidth); - $pheight = self::cvttwiptostr($sty->getPageSizeH(), $pheight); - $mtop = self::cvttwiptostr($sty->getMarginTop(), $mtop, $topfactor); - $mbottom = self::cvttwiptostr($sty->getMarginBottom(), $mbottom, $botfactor); - $mleft = self::cvttwiptostr($sty->getMarginRight(), $mleft); - $mright = self::cvttwiptostr($sty->getMarginLeft(), $mright); - } + $orient = $sty->getOrientation(); + $pwidth = self::cvttwiptostr($sty->getPageSizeW()); + $pheight = self::cvttwiptostr($sty->getPageSizeH()); + $mtop = self::cvttwiptostr($sty->getMarginTop(), $topfactor); + $mbottom = self::cvttwiptostr($sty->getMarginBottom(), $botfactor); + $mleft = self::cvttwiptostr($sty->getMarginRight()); + $mright = self::cvttwiptostr($sty->getMarginLeft()); $xmlWriter->startElement('style:page-layout'); $xmlWriter->writeAttribute('style:name', "Mpm$sectionNbr"); @@ -253,7 +240,7 @@ class Styles extends AbstractPart $xmlWriter->endElement(); // style:header-style $xmlWriter->startElement('style:footer-style'); - if ($botfactor < 1.0) { // Owen 2019-08-03 + if ($botfactor < 1.0) { $xmlWriter->startElement('style:header-footer-properties'); $xmlWriter->writeAttribute('fo:min-height', $mbottom); $xmlWriter->writeAttribute('fo:margin-top', $mbottom); @@ -275,7 +262,8 @@ class Styles extends AbstractPart $xmlWriter->startElement('office:master-styles'); $sections = $this->getParentWriter()->getPhpWord()->getSections(); - for ($i = 0; $i < count($sections); ++$i) { + $countsects = count($sections); + for ($i = 0; $i < $countsects; ++$i) { $iplus1 = $i + 1; $xmlWriter->startElement('style:master-page'); $xmlWriter->writeAttribute('style:name', "Standard$iplus1"); diff --git a/src/PhpWord/Writer/ODText/Style/Paragraph.php b/src/PhpWord/Writer/ODText/Style/Paragraph.php index 555a4825..be974e72 100644 --- a/src/PhpWord/Writer/ODText/Style/Paragraph.php +++ b/src/PhpWord/Writer/ODText/Style/Paragraph.php @@ -56,9 +56,7 @@ class Paragraph extends AbstractStyle $styleAuto = true; $mpm = 'Standard' . substr($styleName, 2); $psn = $style->getNumLevel(); - if (is_numeric($psn)) { - $pagestart = (int) $psn; - } + $pagestart = $psn; } elseif (substr($styleName, 0, 2) === 'HD') { $styleAuto = true; $psm = 'Heading_' . substr($styleName, 2); @@ -117,7 +115,7 @@ class Paragraph extends AbstractStyle $xmlWriter->writeAttributeIf($temp !== '', 'fo:text-align', $temp); $temp = $style->getLineHeight(); $xmlWriter->writeAttributeIf($temp !== null, 'fo:line-height', ((string) ($temp * 100) . '%')); - $xmlWriter->writeAttributeIf($style->getPageBreakBefore() === true, 'fo:break-before', 'page'); + $xmlWriter->writeAttributeIf($style->hasPageBreakBefore() === true, 'fo:break-before', 'page'); $tabs = $style->getTabs(); if ($tabs !== null && count($tabs) > 0) {