Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed fonts in the generated file after usiong a reader #793

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/PhpPresentation/Reader/PowerPoint2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ protected function loadSlide(string $sPart, string $baseFile): void
// Background
$oBackground = new Slide\Background\Image();
$oBackground->setPath($tmpBkgImg);
$extension = pathinfo( $pathImage, PATHINFO_EXTENSION );
$oBackground->setExtension($extension);
// Slide Background
$oSlide = $this->oPhpPresentation->getActiveSlide();
$oSlide->setBackground($oBackground);
Expand Down Expand Up @@ -1312,18 +1314,21 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh
$this->loadHyperlink($document, $oElementHlinkClick, $oText->getHyperlink())
);
}

$oElementFontFormatEastAsian = $document->getElement('a:ea', $oElementrPr);
if (is_object($oElementFontFormatEastAsian)) {
$oText->getFont()->setFormat(Font::FORMAT_EAST_ASIAN);
$oElementFontFormat = $oElementFontFormatEastAsian;
}

// Font
$oElementFontFormat = null;
$oElementFontFormatLatin = $document->getElement('a:latin', $oElementrPr);
if (is_object($oElementFontFormatLatin)) {
$oText->getFont()->setFormat(Font::FORMAT_LATIN);
$oElementFontFormat = $oElementFontFormatLatin;
}
$oElementFontFormatEastAsian = $document->getElement('a:ea', $oElementrPr);
if (is_object($oElementFontFormatEastAsian)) {
$oText->getFont()->setFormat(Font::FORMAT_EAST_ASIAN);
$oElementFontFormat = $oElementFontFormatEastAsian;
}

$oElementFontFormatComplexScript = $document->getElement('a:cs', $oElementrPr);
if (is_object($oElementFontFormatComplexScript)) {
$oText->getFont()->setFormat(Font::FORMAT_COMPLEX_SCRIPT);
Expand Down
23 changes: 22 additions & 1 deletion src/PhpPresentation/Slide/Background/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class Image extends AbstractBackground
*/
protected $width;

/**
* @var string
*/
protected $extension;

/**
* Get Path.
*/
Expand Down Expand Up @@ -79,6 +84,19 @@ public function setPath(string $pValue = '', bool $pVerifyFile = true)
return $this;
}

/**
* Set Extension.
*
* @param string $pValue File Extension
*
* @return self
*/
public function setExtension(string $pValue)
{
$this->extension = $pValue;
return $this;
}

/**
* Get Filename.
*/
Expand All @@ -92,9 +110,12 @@ public function getFilename(): string
*/
public function getExtension(): string
{
if($this->extension){
return $this->extension;
}
$exploded = explode('.', $this->getFilename());

return $exploded[count($exploded) - 1];

}

/**
Expand Down
4 changes: 0 additions & 4 deletions src/PhpPresentation/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ public function getPanose(): string
*/
public function setPanose(string $pValue): self
{
if (mb_strlen($pValue) !== 10) {
throw new InvalidParameterException('pValue', $pValue, 'The length is not equals to 10');
}

$allowedChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
foreach (mb_str_split($pValue) as $char) {
if (!in_array($char, $allowedChars)) {
Expand Down
9 changes: 3 additions & 6 deletions src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,21 +677,18 @@ protected function writeRunStyles(XMLWriter $objWriter, Run $element): void
$objWriter->startElement('a:' . $element->getFont()->getFormat());
$objWriter->writeAttribute('typeface', $element->getFont()->getName());
if ($element->getFont()->getPanose() !== '') {
$panose = array_map(function (string $value) {
return '0' . $value;
}, str_split($element->getFont()->getPanose()));

$objWriter->writeAttribute('panose', implode('', $panose));
$objWriter->writeAttribute('panose', $element->getFont()->getPanose());
}
$objWriter->writeAttributeIf(
$element->getFont()->getPitchFamily() !== 0,
'pitchFamily',
$element->getFont()->getPitchFamily()
);
$charset = $element->getFont()->getCharset();
$objWriter->writeAttributeIf(
$element->getFont()->getCharset() !== Font::CHARSET_DEFAULT,
'charset',
dechex($element->getFont()->getCharset())
$charset
);
$objWriter->endElement();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ public function testRichTextRunFontCharset(): void
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $latinElement, 'typeface');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $latinElement, 'typeface', 'Calibri');
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $latinElement, 'charset');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $latinElement, 'charset', '12');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $latinElement, 'charset', '18');
$this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $eastAsianElement);
$this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $complexScriptElement);
$this->assertIsSchemaECMA376Valid();
Expand All @@ -898,7 +898,7 @@ public function testRichTextRunFontCharset(): void
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $eastAsianElement, 'typeface');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $eastAsianElement, 'typeface', 'Calibri');
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $eastAsianElement, 'charset');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $eastAsianElement, 'charset', '12');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $eastAsianElement, 'charset', '18');
$this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $complexScriptElement);
$this->assertIsSchemaECMA376Valid();

Expand All @@ -911,7 +911,7 @@ public function testRichTextRunFontCharset(): void
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $complexScriptElement, 'typeface');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $complexScriptElement, 'typeface', 'Calibri');
$this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $complexScriptElement, 'charset');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $complexScriptElement, 'charset', '12');
$this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $complexScriptElement, 'charset', '18');
$this->assertIsSchemaECMA376Valid();
}

Expand Down
Loading