Skip to content

Commit 5aecc8d

Browse files
devX2712Progi1984
authored andcommitted
EVOL-Super script and sub script for paragraph
Using true/fasle and default value 300000 or -250000 are too mutch (in Office 365). So when reading, get values setted by PowerPoint and modify default values into the code to set values seen during my tests
1 parent cd9a17f commit 5aecc8d

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

src/PhpPresentation/Reader/PowerPoint2007.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,13 @@ protected function loadParagraph(XMLReader $document, DOMElement $oElement, $oSh
12491249
if ($oElementrPr->hasAttribute('lang')) {
12501250
$oText->setLanguage($oElementrPr->getAttribute('lang'));
12511251
}
1252+
if ($oElementrPr->hasAttribute('baseline')) {
1253+
if ((int)$oElementrPr->getAttribute('baseline')>0) {
1254+
$oText->getFont()->setSuperScript((int)$oElementrPr->getAttribute('baseline'));
1255+
} else if ((int)$oElementrPr->getAttribute('baseline')<0) {
1256+
$oText->getFont()->setSubScript((int)$oElementrPr->getAttribute('baseline'));
1257+
}
1258+
}
12521259
// Color
12531260
$oElementSrgbClr = $document->getElement('a:solidFill/a:srgbClr', $oElementrPr);
12541261
if (is_object($oElementSrgbClr) && $oElementSrgbClr->hasAttribute('val')) {

src/PhpPresentation/Style/Font.php

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class Font implements ComparableInterface
5959
public const CAPITALIZATION_NONE = 'none';
6060
public const CAPITALIZATION_SMALL = 'small';
6161
public const CAPITALIZATION_ALL = 'all';
62+
63+
/* Script sub and super values */
64+
const SCRIPT_SUPER = 30000;
65+
const SCRIPT_SUB = -25000;
6266

6367
/**
6468
* Name.
@@ -154,6 +158,8 @@ class Font implements ComparableInterface
154158
public function __construct()
155159
{
156160
$this->color = new Color(Color::COLOR_BLACK);
161+
$this->superScript = 0;
162+
$this->subScript = 0;
157163
$this->strikethrough = self::STRIKE_NONE;
158164
}
159165

@@ -254,38 +260,60 @@ public function setItalic(bool $pValue = false): self
254260
/**
255261
* Get SuperScript.
256262
*/
257-
public function isSuperScript(): bool
263+
public function isSuperScript(): int
258264
{
259265
return $this->superScript;
260266
}
261267

262268
/**
263-
* Set SuperScript.
269+
* Set SuperScript
270+
*
271+
* @param integer $pValue
272+
* @return \PhpOffice\PhpPresentation\Style\Font
264273
*/
265-
public function setSuperScript(bool $pValue = false): self
274+
public function setSuperScript($pValue = 0)
266275
{
276+
if ($pValue == '') {
277+
$pValue = 0;
278+
}
279+
267280
$this->superScript = $pValue;
268281

269282
// Set SubScript at false only if SuperScript is true
270-
if (true === $pValue) {
271-
$this->subScript = false;
283+
if ($pValue != 0) {
284+
$this->subScript = 0;
272285
}
273286

274287
return $this;
275288
}
276289

277-
public function isSubScript(): bool
290+
/**
291+
* Get SubScript
292+
*
293+
* @return integer
294+
*/
295+
public function isSubScript()
278296
{
279297
return $this->subScript;
280298
}
281299

282-
public function setSubScript(bool $pValue = false): self
300+
/**
301+
* Set SubScript
302+
*
303+
* @param integer $pValue
304+
* @return \PhpOffice\PhpPresentation\Style\Font
305+
*/
306+
public function setSubScript($pValue = 0)
283307
{
308+
if ($pValue == '') {
309+
$pValue = 0;
310+
}
311+
284312
$this->subScript = $pValue;
285313

286314
// Set SuperScript at false only if SubScript is true
287-
if (true === $pValue) {
288-
$this->superScript = false;
315+
if ($pValue != 0) {
316+
$this->superScript = 0;
289317
}
290318

291319
return $this;

src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,8 @@ protected function writeRunStyles(XMLWriter $objWriter, RichText\Run $element):
664664
$objWriter->writeAttribute('cap', $element->getFont()->getCapitalization());
665665

666666
// Superscript / subscript
667-
$objWriter->writeAttributeIf($element->getFont()->isSuperScript(), 'baseline', '300000');
668-
$objWriter->writeAttributeIf($element->getFont()->isSubScript(), 'baseline', '-250000');
667+
$objWriter->writeAttributeIf($element->getFont()->isSuperScript() != 0, 'baseline', (int)$element->getFont()->isSuperScript());
668+
$objWriter->writeAttributeIf($element->getFont()->isSubScript() != 0, 'baseline', (int)$element->getFont()->isSubScript());
669669

670670
// Color - a:solidFill
671671
$objWriter->startElement('a:solidFill');

0 commit comments

Comments
 (0)