Skip to content

Commit

Permalink
PowerPoint 2007 Writer : Added support to Font for Axis tick label & …
Browse files Browse the repository at this point in the history
…chinese font support
  • Loading branch information
zhengwhizz authored and Progi1984 committed Dec 5, 2023
1 parent 0016a93 commit 0dffb29
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changes/1.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- PowerPoint2007 Reader
- 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)

## Bugfixes

Expand Down
28 changes: 27 additions & 1 deletion src/PhpPresentation/Shape/Chart/Axis.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ class Axis implements ComparableInterface
private $font;

/**
* @var null|Gridlines
* Tick lable font.
*
* @var Font
*/
protected $tickLabelFont;

/**
* @var Gridlines|null
*/
protected $majorGridlines;

Expand Down Expand Up @@ -144,6 +151,7 @@ public function __construct(string $title = 'Axis Title')
$this->title = $title;
$this->outline = new Outline();
$this->font = new Font();
$this->tickLabelFont = new Font();
}

/**
Expand Down Expand Up @@ -172,6 +180,24 @@ public function getFont(): ?Font
return $this->font;
}

/**
* Set tick label font.
*/
public function setTickLabelFont(?Font $font = null): self
{
$this->tickLabelFont = $font;

return $this;
}

/**
* Get tick label font.
*/
public function getTickLabelFont(): ?Font
{
return $this->tickLabelFont;
}

/**
* Set font.
*/
Expand Down
94 changes: 94 additions & 0 deletions src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,10 @@ protected function writeTypeBar(XMLWriter $objWriter, Bar $subject, bool $includ
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
// >a:latin
$objWriter->endElement();
// a:ea
$objWriter->startElement('a:ea');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();

// >a:defRPr
$objWriter->endElement();
Expand Down Expand Up @@ -1106,6 +1110,10 @@ protected function writeTypeBar3D(XMLWriter $objWriter, Bar3D $subject, bool $in
$objWriter->startElement('a:latin');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();
// a:ea
$objWriter->startElement('a:ea');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();

$objWriter->endElement();

Expand Down Expand Up @@ -1309,6 +1317,10 @@ protected function writeTypeDoughnut(XMLWriter $objWriter, Doughnut $subject, bo
$objWriter->startElement('a:latin');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();
// a:ea
$objWriter->startElement('a:ea');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();

// c:dLbls\c:txPr\a:p\a:pPr\a:defRPr\
$objWriter->endElement();
Expand Down Expand Up @@ -1450,6 +1462,10 @@ protected function writeTypePie(XMLWriter $objWriter, Pie $subject, bool $includ
$objWriter->startElement('a:latin');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();
// a:ea
$objWriter->startElement('a:ea');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();

$objWriter->endElement();

Expand Down Expand Up @@ -1610,6 +1626,10 @@ protected function writeTypePie3D(XMLWriter $objWriter, Pie3D $subject, bool $in
$objWriter->startElement('a:latin');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();
// a:ea
$objWriter->startElement('a:ea');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();

$objWriter->endElement();

Expand Down Expand Up @@ -1759,6 +1779,10 @@ protected function writeTypeLine(XMLWriter $objWriter, Line $subject, bool $incl
$objWriter->startElement('a:latin');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();
// a:ea
$objWriter->startElement('a:ea');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();

$objWriter->endElement();

Expand Down Expand Up @@ -1931,6 +1955,10 @@ protected function writeTypeRadar(XMLWriter $objWriter, Radar $subject, bool $in
$objWriter->startElement('a:latin');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();
// a:ea
$objWriter->startElement('a:ea');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();

$objWriter->endElement();

Expand Down Expand Up @@ -2093,6 +2121,10 @@ protected function writeTypeScatter(XMLWriter $objWriter, Scatter $subject, bool
$objWriter->startElement('a:latin');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();
// a:ea
$objWriter->startElement('a:ea');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();

$objWriter->endElement();

Expand Down Expand Up @@ -2366,6 +2398,10 @@ protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, string $ty
$objWriter->startElement('a:latin');
$objWriter->writeAttribute('typeface', $oAxis->getFont()->getName());
$objWriter->endElement();
// a:ea
$objWriter->startElement('a:ea');
$objWriter->writeAttribute('typeface', $oAxis->getFont()->getName());
$objWriter->endElement();

$objWriter->endElement();

Expand Down Expand Up @@ -2434,6 +2470,64 @@ protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, string $ty
// ##c:spPr
$objWriter->endElement();

// c:txPr
$objWriter->startElement('c:txPr');

// a:bodyPr
$objWriter->writeElement('a:bodyPr', null);

// a:lstStyle
$objWriter->writeElement('a:lstStyle', null);

// a:p
$objWriter->startElement('a:p');

// a:pPr
$objWriter->startElement('a:pPr');

// a:defRPr
$objWriter->startElement('a:defRPr');
$objWriter->writeAttribute('b', ($oAxis->getTickLabelFont()->isBold() ? 'true' : 'false'));
$objWriter->writeAttribute('i', ($oAxis->getTickLabelFont()->isItalic() ? 'true' : 'false'));
$objWriter->writeAttribute('strike', ($oAxis->getTickLabelFont()->isStrikethrough() ? 'sngStrike' : 'noStrike'));
$objWriter->writeAttribute('sz', ($oAxis->getTickLabelFont()->getSize() * 100));
$objWriter->writeAttribute('u', $oAxis->getTickLabelFont()->getUnderline());
$objWriter->writeAttributeIf($oAxis->getTickLabelFont()->isSuperScript(), 'baseline', '300000');
$objWriter->writeAttributeIf($oAxis->getTickLabelFont()->isSubScript(), 'baseline', '-250000');

// Font - a:solidFill
$objWriter->startElement('a:solidFill');
$this->writeColor($objWriter, $oAxis->getTickLabelFont()->getColor());
$objWriter->endElement();

// Font - a:latin
$objWriter->startElement('a:latin');
$objWriter->writeAttribute('typeface', $oAxis->getTickLabelFont()->getName());
$objWriter->endElement();

// Font - a:ea
$objWriter->startElement('a:ea');
$objWriter->writeAttribute('typeface', $oAxis->getTickLabelFont()->getName());
$objWriter->endElement();

## a:defRPr
$objWriter->endElement();

## a:pPr
$objWriter->endElement();

// a:endParaRPr
$objWriter->startElement('a:endParaRPr');
$objWriter->writeAttribute('lang', 'en-US');
$objWriter->writeAttribute('dirty', '0');
$objWriter->endElement();

## a:p
$objWriter->endElement();

## c:txPr
$objWriter->endElement();

// c:crossAx
$objWriter->startElement('c:crossAx');
$objWriter->writeAttribute('val', $crossAxVal);
Expand Down

0 comments on commit 0dffb29

Please sign in to comment.