diff --git a/docs/changes/1.1.0.md b/docs/changes/1.1.0.md index 748e67dee..1f58c72c3 100644 --- a/docs/changes/1.1.0.md +++ b/docs/changes/1.1.0.md @@ -11,6 +11,11 @@ - PowerPoint2007 Writer - Added support for PHP 8.2 & 8.3 - [@Progi1984](https://github.com/Progi1984) in [#769](https://github.com/PHPOffice/PHPPresentation/pull/769) - PowerPoint 2007 Writer : Added support to Font for Axis tick label & chinese font support - [@zhengwhizz](https://github.com/zhengwhizz) in [#774](https://github.com/PHPOffice/PHPPresentation/pull/774) +- Support for Capitalization for Font - [@CxRxExO](https://github.com/CxRxExO) & [@Progi1984](https://github.com/Progi1984) in [#779](https://github.com/PHPOffice/PHPPresentation/pull/779) + - ODPresentation Reader + - ODPresentation Writer + - PowerPoint2007 Reader + - PowerPoint2007 Writer ## Improvements - Slide : Raised max value for identifier rand call - [@Scheissy](https://github.com/Scheissy) in [#777](https://github.com/PHPOffice/PHPPresentation/pull/777) diff --git a/docs/usage/styles.md b/docs/usage/styles.md index ba2147985..e9ff72c60 100644 --- a/docs/usage/styles.md +++ b/docs/usage/styles.md @@ -102,6 +102,28 @@ echo $alignment->isRTL(); - `underline` - `strikethrough` - `color` +- `capitalization` + +### Capitalization + +Some formats are available : + +* `Font::CAPITALIZATION_NONE` +* `Font::CAPITALIZATION_ALL` +* `Font::CAPITALIZATION_SMALL` + +``` php +setCapitalization(Font::CAPITALIZATION_ALL); +// Get capitalization of font +echo $font->getCapitalization(); +``` ### Format diff --git a/src/PhpPresentation/Exception/NotAllowedValueException.php b/src/PhpPresentation/Exception/NotAllowedValueException.php new file mode 100644 index 000000000..9c0da31cf --- /dev/null +++ b/src/PhpPresentation/Exception/NotAllowedValueException.php @@ -0,0 +1,35 @@ + $value + */ + public function __construct(string $parameter, array $value) + { + parent::__construct(sprintf( + 'The value "%s" is not in allowed values ("%s")', + $parameter, + implode('", "', $value) + )); + } +} diff --git a/src/PhpPresentation/Reader/ODPresentation.php b/src/PhpPresentation/Reader/ODPresentation.php index 65bcac461..0261b3689 100644 --- a/src/PhpPresentation/Reader/ODPresentation.php +++ b/src/PhpPresentation/Reader/ODPresentation.php @@ -332,6 +332,22 @@ protected function loadStyle(DOMElement $nodeStyle): bool if ($nodeTextProperties->hasAttribute('fo:color')) { $oFont->getColor()->setRGB(substr($nodeTextProperties->getAttribute('fo:color'), -6)); } + if ($nodeTextProperties->hasAttribute('fo:text-transform')) { + switch ($nodeTextProperties->getAttribute('fo:text-transform')) { + case 'none': + $oFont->setCapitalization(Font::CAPITALIZATION_NONE); + + break; + case 'lowercase': + $oFont->setCapitalization(Font::CAPITALIZATION_SMALL); + + break; + case 'uppercase': + $oFont->setCapitalization(Font::CAPITALIZATION_ALL); + + break; + } + } // Font Latin if ($nodeTextProperties->hasAttribute('fo:font-family')) { $oFont diff --git a/src/PhpPresentation/Reader/PowerPoint2007.php b/src/PhpPresentation/Reader/PowerPoint2007.php index 779009e35..985b63fbf 100644 --- a/src/PhpPresentation/Reader/PowerPoint2007.php +++ b/src/PhpPresentation/Reader/PowerPoint2007.php @@ -1206,6 +1206,9 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh if ($oElementrPr->hasAttribute('u')) { $oText->getFont()->setUnderline($oElementrPr->getAttribute('u')); } + if ($oElementrPr->hasAttribute('cap')) { + $oText->getFont()->setCapitalization($oElementrPr->getAttribute('cap')); + } // Color $oElementSrgbClr = $document->getElement('a:solidFill/a:srgbClr', $oElementrPr); if (is_object($oElementSrgbClr) && $oElementSrgbClr->hasAttribute('val')) { diff --git a/src/PhpPresentation/Style/Font.php b/src/PhpPresentation/Style/Font.php index 9010aa273..2ba0bca7c 100644 --- a/src/PhpPresentation/Style/Font.php +++ b/src/PhpPresentation/Style/Font.php @@ -20,6 +20,7 @@ namespace PhpOffice\PhpPresentation\Style; use PhpOffice\PhpPresentation\ComparableInterface; +use PhpOffice\PhpPresentation\Exception\NotAllowedValueException; /** * \PhpOffice\PhpPresentation\Style\Font. @@ -50,6 +51,10 @@ class Font implements ComparableInterface public const FORMAT_EAST_ASIAN = 'ea'; public const FORMAT_COMPLEX_SCRIPT = 'cs'; + public const CAPITALIZATION_NONE = 'none'; + public const CAPITALIZATION_SMALL = 'small'; + public const CAPITALIZATION_ALL = 'all'; + /** * Name. * @@ -92,6 +97,13 @@ class Font implements ComparableInterface */ private $subScript = false; + /** + * Capitalization. + * + * @var string + */ + private $capitalization = self::CAPITALIZATION_NONE; + /** * Underline. * @@ -273,6 +285,31 @@ public function setSubScript(bool $pValue = false): self return $this; } + /** + * Get Capitalization. + */ + public function getCapitalization(): string + { + return $this->capitalization; + } + + /** + * Set Capitalization. + */ + public function setCapitalization(string $pValue = self::CAPITALIZATION_NONE): self + { + if (!in_array( + $pValue, + [self::CAPITALIZATION_NONE, self::CAPITALIZATION_ALL, self::CAPITALIZATION_SMALL] + )) { + throw new NotAllowedValueException($pValue, [self::CAPITALIZATION_NONE, self::CAPITALIZATION_ALL, self::CAPITALIZATION_SMALL]); + } + + $this->capitalization = $pValue; + + return $this; + } + /** * Get Underline. */ diff --git a/src/PhpPresentation/Writer/ODPresentation/Content.php b/src/PhpPresentation/Writer/ODPresentation/Content.php index 4cd604b42..c12a2fc11 100644 --- a/src/PhpPresentation/Writer/ODPresentation/Content.php +++ b/src/PhpPresentation/Writer/ODPresentation/Content.php @@ -276,6 +276,20 @@ protected function writeContent(): string // style:style > style:text-properties $objWriter->startElement('style:text-properties'); $objWriter->writeAttribute('fo:color', '#' . $item->getFont()->getColor()->getRGB()); + switch ($item->getFont()->getCapitalization()) { + case Font::CAPITALIZATION_NONE: + $objWriter->writeAttribute('fo:text-transform', 'none'); + + break; + case Font::CAPITALIZATION_ALL: + $objWriter->writeAttribute('fo:text-transform', 'uppercase'); + + break; + case Font::CAPITALIZATION_SMALL: + $objWriter->writeAttribute('fo:text-transform', 'lowercase'); + + break; + } switch ($item->getFont()->getFormat()) { case Font::FORMAT_LATIN: $objWriter->writeAttribute('fo:font-family', $item->getFont()->getName()); diff --git a/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php b/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php index e6426c4b1..8b6a41400 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php @@ -605,9 +605,9 @@ protected function writeParagraphs(XMLWriter $objWriter, array $paragraphs, bool $objWriter->writeAttribute('sz', ($element->getFont()->getSize() * 100)); $objWriter->writeAttribute('spc', $element->getFont()->getCharacterSpacing()); $objWriter->writeAttribute('u', $element->getFont()->getUnderline()); + $objWriter->writeAttribute('cap', $element->getFont()->getCapitalization()); $objWriter->writeAttributeIf($element->getFont()->isSuperScript(), 'baseline', '300000'); $objWriter->writeAttributeIf($element->getFont()->isSubScript(), 'baseline', '-250000'); - // Color - a:solidFill $objWriter->startElement('a:solidFill'); $this->writeColor($objWriter, $element->getFont()->getColor()); diff --git a/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php b/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php index 627cf925a..d2cd90410 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php @@ -452,6 +452,7 @@ protected function writeTitle(XMLWriter $objWriter, Title $subject): void $objWriter->writeAttribute('u', $subject->getFont()->getUnderline()); $objWriter->writeAttributeIf($subject->getFont()->isSuperScript(), 'baseline', '300000'); $objWriter->writeAttributeIf($subject->getFont()->isSubScript(), 'baseline', '-250000'); + $objWriter->writeAttribute('cap', $subject->getFont()->getCapitalization()); // Font - a:solidFill $objWriter->startElement('a:solidFill'); diff --git a/tests/PhpPresentation/Tests/Reader/ODPresentationTest.php b/tests/PhpPresentation/Tests/Reader/ODPresentationTest.php index 62fb2d0e7..2b50861db 100644 --- a/tests/PhpPresentation/Tests/Reader/ODPresentationTest.php +++ b/tests/PhpPresentation/Tests/Reader/ODPresentationTest.php @@ -156,6 +156,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 1 : Shape 2 : Paragraph 2 $oRichText = $arrayRichText[1]; self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\BreakElement', $oRichText); @@ -168,6 +169,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 2 $oSlide2 = $oPhpPresentation->getSlide(1); @@ -234,6 +236,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 2 : Shape 3 : Paragraph 2 $oParagraph = $arrayParagraphs[1]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -250,6 +253,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 2 : Shape 3 : Paragraph 3 $oParagraph = $arrayParagraphs[2]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -266,6 +270,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 2 : Shape 3 : Paragraph 4 $oParagraph = $arrayParagraphs[3]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -282,6 +287,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 $oSlide2 = $oPhpPresentation->getSlide(2); @@ -328,6 +334,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 2 /** @var RichText $oShape */ $oShape = $arrayShape[2]; @@ -355,6 +362,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 3 : Paragraph 2 $oParagraph = $arrayParagraphs[1]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -372,6 +380,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 3 : Paragraph 3 $oParagraph = $arrayParagraphs[2]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -389,6 +398,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 3 : Paragraph 4 $oParagraph = $arrayParagraphs[3]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -406,6 +416,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 3 : Paragraph 5 $oParagraph = $arrayParagraphs[4]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -423,6 +434,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 3 : Paragraph 6 $oParagraph = $arrayParagraphs[5]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -440,6 +452,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 3 : Paragraph 7 $oParagraph = $arrayParagraphs[6]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -457,6 +470,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 3 : Paragraph 8 $oParagraph = $arrayParagraphs[7]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -474,6 +488,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 4 $oSlide3 = $oPhpPresentation->getSlide(3); @@ -520,6 +535,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 4 : Shape 3 /** @var RichText $oShape */ $oShape = $arrayShape[2]; @@ -548,6 +564,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 4 : Shape 3 : Paragraph 2 $oRichText = $arrayRichText[1]; self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\BreakElement', $oRichText); @@ -561,6 +578,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); self::assertTrue($oRichText->hasHyperlink()); self::assertEquals('https://github.com/PHPOffice/PHPPresentation/', $oRichText->getHyperlink()->getUrl()); //$this->assertEquals('PHPPresentation', $oRichText->getHyperlink()->getTooltip()); diff --git a/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php b/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php index c97b2e37e..b718eebae 100644 --- a/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php +++ b/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php @@ -159,6 +159,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 1 : Shape 2 : Paragraph 2 $oRichText = $arrayRichText[1]; self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\BreakElement', $oRichText); @@ -171,6 +172,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 2 $oSlide2 = $oPhpPresentation->getSlide(1); @@ -213,6 +215,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 2 : Shape 3 /** @var RichText $oShape */ $oShape = $arrayShape[2]; @@ -239,6 +242,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 2 : Shape 3 : Paragraph 2 $oParagraph = $arrayParagraphs[1]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -255,6 +259,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 2 : Shape 3 : Paragraph 3 $oParagraph = $arrayParagraphs[2]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -271,6 +276,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 2 : Shape 3 : Paragraph 4 $oParagraph = $arrayParagraphs[3]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -287,6 +293,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 $oSlide2 = $oPhpPresentation->getSlide(2); @@ -333,6 +340,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 2 /** @var RichText $oShape */ $oShape = $arrayShape[2]; @@ -360,6 +368,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 3 : Paragraph 2 $oParagraph = $arrayParagraphs[1]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -377,6 +386,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 3 : Paragraph 3 $oParagraph = $arrayParagraphs[2]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -394,6 +404,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 3 : Paragraph 4 $oParagraph = $arrayParagraphs[3]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -411,6 +422,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 3 : Paragraph 5 $oParagraph = $arrayParagraphs[4]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -428,6 +440,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 3 : Paragraph 6 $oParagraph = $arrayParagraphs[5]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -445,6 +458,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 3 : Paragraph 7 $oParagraph = $arrayParagraphs[6]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -462,6 +476,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 3 : Shape 3 : Paragraph 8 $oParagraph = $arrayParagraphs[7]; self::assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal()); @@ -479,6 +494,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 4 $oSlide3 = $oPhpPresentation->getSlide(3); @@ -525,6 +541,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 4 : Shape 3 /** @var RichText $oShape */ $oShape = $arrayShape[2]; @@ -553,6 +570,7 @@ public function testLoadFile01(): void self::assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); // Slide 4 : Shape 3 : Paragraph 2 $oRichText = $arrayRichText[1]; self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\BreakElement', $oRichText); @@ -570,6 +588,7 @@ public function testLoadFile01(): void self::assertFalse($oRichText->getHyperlink()->isTextColorUsed()); self::assertEquals('Calibri', $oRichText->getFont()->getName()); self::assertEquals(Font::FORMAT_LATIN, $oRichText->getFont()->getFormat()); + self::assertEquals(Font::CAPITALIZATION_NONE, $oRichText->getFont()->getCapitalization()); } public function testMarkAsFinal(): void diff --git a/tests/PhpPresentation/Tests/Style/FontTest.php b/tests/PhpPresentation/Tests/Style/FontTest.php index 1237238a3..711c2da53 100644 --- a/tests/PhpPresentation/Tests/Style/FontTest.php +++ b/tests/PhpPresentation/Tests/Style/FontTest.php @@ -19,6 +19,7 @@ namespace PhpOffice\PhpPresentation\Tests\Style; +use PhpOffice\PhpPresentation\Exception\NotAllowedValueException; use PhpOffice\PhpPresentation\Style\Color; use PhpOffice\PhpPresentation\Style\Font; use PHPUnit\Framework\TestCase; @@ -45,10 +46,36 @@ public function testConstruct(): void self::assertFalse($object->isStrikethrough()); self::assertEquals(Font::UNDERLINE_NONE, $object->getUnderline()); self::assertEquals(0, $object->getCharacterSpacing()); + self::assertEquals(Font::CAPITALIZATION_NONE, $object->getCapitalization()); self::assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Color', $object->getColor()); self::assertEquals(Color::COLOR_BLACK, $object->getColor()->getARGB()); } + /** + * Test get/set Capitalization. + */ + public function testCapitalization(): void + { + $object = new Font(); + self::assertEquals(Font::CAPITALIZATION_NONE, $object->getCapitalization()); + self::assertInstanceOf(Font::class, $object->setCapitalization(Font::CAPITALIZATION_ALL)); + self::assertEquals(Font::CAPITALIZATION_ALL, $object->getCapitalization()); + self::assertInstanceOf(Font::class, $object->setCapitalization()); + self::assertEquals(Font::CAPITALIZATION_NONE, $object->getCapitalization()); + } + + /** + * Test get/set Capitalization exception. + */ + public function testCapitalizationException(): void + { + $this->expectException(NotAllowedValueException::class); + $this->expectExceptionMessage('The value "Invalid" is not in allowed values ("none", "all", "small")'); + + $object = new Font(); + $object->setCapitalization('Invalid'); + } + /** * Test get/set Character Spacing. */ diff --git a/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php b/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php index 6aa970cd2..1e6f95324 100644 --- a/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php +++ b/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php @@ -763,6 +763,40 @@ public function testStyleFontFormat(): void $this->assertIsSchemaOpenDocumentValid('1.2'); } + public function testStyleFontCapitalization(): void + { + $oRichText = $this->oPresentation->getActiveSlide()->createRichTextShape(); + $oRun = $oRichText->createTextRun('Run1'); + $oRun->getFont()->setCapitalization(Font::CAPITALIZATION_ALL); + + $expectedHashCode = $oRun->getHashCode(); + $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'T_' . $expectedHashCode . '\']/style:text-properties'; + $this->assertZipXmlElementExists('content.xml', $element); + $this->assertZipXmlAttributeExists('content.xml', $element, 'fo:text-transform'); + $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:text-transform', 'uppercase'); + $this->assertIsSchemaOpenDocumentValid('1.2'); + + $oRun->getFont()->setCapitalization(Font::CAPITALIZATION_SMALL); + $this->resetPresentationFile(); + + $expectedHashCode = $oRun->getHashCode(); + $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'T_' . $expectedHashCode . '\']/style:text-properties'; + $this->assertZipXmlElementExists('content.xml', $element); + $this->assertZipXmlAttributeExists('content.xml', $element, 'fo:text-transform'); + $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:text-transform', 'lowercase'); + $this->assertIsSchemaOpenDocumentValid('1.2'); + + $oRun->getFont()->setCapitalization(Font::CAPITALIZATION_NONE); + $this->resetPresentationFile(); + + $expectedHashCode = $oRun->getHashCode(); + $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'T_' . $expectedHashCode . '\']/style:text-properties'; + $this->assertZipXmlElementExists('content.xml', $element); + $this->assertZipXmlAttributeExists('content.xml', $element, 'fo:text-transform'); + $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:text-transform', 'none'); + $this->assertIsSchemaOpenDocumentValid('1.2'); + } + public function testStyleFontName(): void { $oRichText = $this->oPresentation->getActiveSlide()->createRichTextShape(); diff --git a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php index e4bd28646..8cd2c7f3a 100644 --- a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php +++ b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php @@ -875,6 +875,27 @@ public function testSlideLayoutExists(): void $this->assertIsSchemaECMA376Valid(); } + public function testStyleCapitalization(): void + { + $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:rPr'; + + $oSlide = $this->oPresentation->getActiveSlide(); + $oRichText = $oSlide->createRichTextShape(); + $oRun = $oRichText->createTextRun('pText'); + // Default : $oRun->getFont()->setCapitalization(Font::CAPITALIZATION_NONE); + + $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element); + $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'cap', 'none'); + $this->assertIsSchemaECMA376Valid(); + + $oRun->getFont()->setCapitalization(Font::CAPITALIZATION_ALL); + $this->resetPresentationFile(); + + $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element); + $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'cap', 'all'); + $this->assertIsSchemaECMA376Valid(); + } + public function testStyleCharacterSpacing(): void { $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:rPr';