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

#266 : PowerPoint2007 Writer : Fix for Need repair #303

Merged
merged 2 commits into from
Jan 9, 2017
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Bugfix
- PowerPoint2007 Writer : The presentation need repairs on Mac @jrking4 GH-266 GH-276
- PowerPoint2007 Writer : Fix for PowerPoint2007 Writer (Need repair) @Progi1984 GH-266 GH-274 GH-276 GH-282 GH-302

## 0.7.0 - 2016-09-12

Expand Down
9 changes: 4 additions & 5 deletions samples/Sample_05_Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Fill;
use PhpOffice\PhpPresentation\Style\Shadow;
use PhpOffice\PhpPresentation\Style\PhpOffice\PhpPresentation\Style;

function fnSlide_Area(PhpPresentation $objPHPPresentation) {
global $oFill;
global $oShadow;

// Generate sample data for chart
echo date('H:i:s') . ' Generate sample data for chart' . EOL;
$seriesData = array(
Expand All @@ -33,11 +32,11 @@ function fnSlide_Area(PhpPresentation $objPHPPresentation) {
'Saturday' => 9,
'Sunday' => 7
);

// Create templated slide
echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
$currentSlide = createTemplatedSlide($objPHPPresentation);

// Create a line chart (that should be inserted in a shape)
echo date('H:i:s') . ' Create a area chart (that should be inserted in a chart shape)' . EOL;
$areaChart = new Area();
Expand All @@ -47,7 +46,7 @@ function fnSlide_Area(PhpPresentation $objPHPPresentation) {
$series->getFill()->setStartColor(new Color('FF93A9CE'));
$series->setLabelPosition(Series::LABEL_INSIDEEND);
$areaChart->addSeries($series);

// Create a shape (chart)
echo date('H:i:s') . ' Create a shape (chart)' . EOL;
$shape = $currentSlide->createChartShape();
Expand Down
1 change: 1 addition & 0 deletions src/PhpPresentation/Shape/Drawing/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function getExtension()
}

/**
* @throws \Exception
* @return string
*/
public function getMimeType()
Expand Down
12 changes: 10 additions & 2 deletions src/PhpPresentation/Slide.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Slide extends AbstractSlide implements ComparableInterface, ShapeContainer
* @var \PhpOffice\PhpPresentation\Slide\Note
*/
private $slideNote;

/**
*
* @var \PhpOffice\PhpPresentation\Slide\Animation[]
Expand All @@ -81,6 +81,14 @@ public function __construct(PhpPresentation $pParent = null)
$this->shapeCollection = new \ArrayObject();
// Set identifier
$this->identifier = md5(rand(0, 9999) . time());
// Set Slide Layout
if ($this->parent instanceof PhpPresentation) {
$arrayMasterSlides = $this->parent->getAllMasterSlides();
$oMasterSlide = reset($arrayMasterSlides);
$arraySlideLayouts = $oMasterSlide->getAllSlideLayouts();
$oSlideLayout = reset($arraySlideLayouts);
$this->setSlideLayout($oSlideLayout);
}
}

/**
Expand Down Expand Up @@ -118,7 +126,7 @@ public function getSlideMasterId()
/**
* Set slide master id
*
* @param int $masterId
* @param int $masterId
* @return \PhpOffice\PhpPresentation\Slide
*/
public function setSlideMasterId($masterId = 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ protected function writeShapeCollection(XMLWriter $objWriter, $shapes = array(),
} elseif ($shape instanceof Group) {
$this->writeShapeGroup($objWriter, $shape, $shapeId);
} elseif ($shape instanceof Comment) {
return;
} else {
throw new \Exception("Unknown Shape type: {get_class($shape)}");
}
Expand Down
16 changes: 15 additions & 1 deletion src/PhpPresentation/Writer/PowerPoint2007/ContentTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace PhpOffice\PhpPresentation\Writer\PowerPoint2007;

use PhpOffice\PhpPresentation\Shape\Chart as ShapeChart;
use PhpOffice\PhpPresentation\Shape\Comment;
use PhpOffice\PhpPresentation\Shape\Drawing as ShapeDrawing;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpPresentation\Writer\PowerPoint2007;
Expand Down Expand Up @@ -77,12 +78,25 @@ public function render()
}

// Slides
$hasComments = false;
$slideCount = $this->oPresentation->getSlideCount();
for ($i = 0; $i < $slideCount; ++$i) {
$oSlide = $this->oPresentation->getSlide($i);
$this->writeOverrideContentType($objWriter, '/ppt/slides/slide' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slide+xml');
if ($this->oPresentation->getSlide($i)->getNote()->getShapeCollection()->count() > 0) {
if ($oSlide->getNote()->getShapeCollection()->count() > 0) {
$this->writeOverrideContentType($objWriter, '/ppt/notesSlides/notesSlide' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml');
}
foreach ($oSlide->getShapeCollection() as $oShape) {
if ($oShape instanceof Comment) {
$this->writeOverrideContentType($objWriter, '/ppt/comments/comment' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.comments+xml');
$hasComments = true;
break;
}
}
}

if ($hasComments) {
$this->writeOverrideContentType($objWriter, '/ppt/commentAuthors.xml', 'application/vnd.openxmlformats-officedocument.presentationml.commentAuthors+xml');
}

// Add media content-types
Expand Down
91 changes: 13 additions & 78 deletions src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,12 @@ protected function writePlotArea(XMLWriter $objWriter, PlotArea $subject, Chart

// Write X axis?
if ($chartType->hasAxisX()) {
$this->writeAxis($objWriter, $subject->getAxisX(), Chart\Axis::AXIS_X);
$this->writeAxis($objWriter, $subject->getAxisX(), Chart\Axis::AXIS_X, $chartType);
}

// Write Y axis?
if ($chartType->hasAxisY()) {
$this->writeAxis($objWriter, $subject->getAxisY(), Chart\Axis::AXIS_Y);
$this->writeAxis($objWriter, $subject->getAxisY(), Chart\Axis::AXIS_Y, $chartType);
}

$objWriter->endElement();
Expand Down Expand Up @@ -715,68 +715,9 @@ protected function writeTypeArea(XMLWriter $objWriter, Area $subject, $includeSh
$objWriter->endElement();

// c:ser > c:dLbls
// @link : https://msdn.microsoft.com/en-us/library/documentformat.openxml.drawing.charts.areachartseries.aspx
$objWriter->startElement('c:dLbls');

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

// c:ser > c:dLbls > c:txPr > a:bodyPr
$objWriter->writeElement('a:bodyPr', null);

// c:ser > c:dLbls > c:txPr > a:lstStyle
$objWriter->writeElement('a:lstStyle', null);

// c:ser > c:dLbls > c:txPr > a:p
$objWriter->startElement('a:p');

// c:ser > c:dLbls > c:txPr > a:p > a:pPr
$objWriter->startElement('a:pPr');

// c:ser > c:dLbls > c:txPr > a:p > a:pPr > a:defRPr
$objWriter->startElement('a:defRPr');

$objWriter->writeAttribute('b', ($series->getFont()->isBold() ? 'true' : 'false'));
$objWriter->writeAttribute('i', ($series->getFont()->isItalic() ? 'true' : 'false'));
$objWriter->writeAttribute('strike', ($series->getFont()->isStrikethrough() ? 'sngStrike' : 'noStrike'));
$objWriter->writeAttribute('sz', ($series->getFont()->getSize() * 100));
$objWriter->writeAttribute('u', $series->getFont()->getUnderline());
$objWriter->writeAttributeIf($series->getFont()->isSuperScript(), 'baseline', '30000');
$objWriter->writeAttributeIf($series->getFont()->isSubScript(), 'baseline', '-25000');

// c:ser > c:dLbls > c:txPr > a:p > a:pPr > a:defRPr > a:solidFill
$objWriter->startElement('a:solidFill');

$this->writeColor($objWriter, $series->getFont()->getColor());

// c:ser > c:dLbls > c:txPr > a:p > a:pPr > a:defRPr > ## a:solidFill
$objWriter->endElement();

// c:ser > c:dLbls > c:txPr > a:p > a:pPr > a:defRPr > a:latin
$objWriter->startElement('a:latin');
$objWriter->writeAttribute('typeface', $series->getFont()->getName());
$objWriter->endElement();

// c:ser > c:dLbls > c:txPr > a:p > a:pPr > ##a:defRPr
$objWriter->endElement();

// c:ser > c:dLbls > c:txPr > a:p > ##a:pPr
$objWriter->endElement();

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

// c:ser > c:dLbls > c:txPr > ##a:p
$objWriter->endElement();

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

// c:ser > c:dLbls > c:dLblPos
$this->writeElementWithValAttribute($objWriter, 'c:dLblPos', $series->getLabelPosition());

// c:ser > c:dLbls > c:showVal
$this->writeElementWithValAttribute($objWriter, 'c:showVal', $series->hasShowValue() ? '1' : '0');

Expand All @@ -789,9 +730,6 @@ protected function writeTypeArea(XMLWriter $objWriter, Area $subject, $includeSh
// c:ser > c:dLbls > c:showPercent
$this->writeElementWithValAttribute($objWriter, 'c:showPercent', $series->hasShowPercentage() ? '1' : '0');

// c:ser > c:dLbls > c:showLeaderLines
$this->writeElementWithValAttribute($objWriter, 'c:showLeaderLines', $series->hasShowLeaderLines() ? '1' : '0');

// c:ser > ##c:dLbls
$objWriter->endElement();

Expand Down Expand Up @@ -826,16 +764,6 @@ protected function writeTypeArea(XMLWriter $objWriter, Area $subject, $includeSh
++$seriesIndex;
}

// c:marker
$objWriter->startElement('c:marker');
$objWriter->writeAttribute('val', '1');
$objWriter->endElement();

// c:smooth
$objWriter->startElement('c:smooth');
$objWriter->writeAttribute('val', '0');
$objWriter->endElement();

// c:axId
$objWriter->startElement('c:axId');
$objWriter->writeAttribute('val', '52743552');
Expand Down Expand Up @@ -1999,8 +1927,9 @@ protected function writeSeriesMarker(XMLWriter $objWriter, Chart\Marker $oMarker
* @param XMLWriter $objWriter
* @param Chart\Axis $oAxis
* @param $typeAxis
* @param Chart\Type\AbstractType $typeChart
*/
protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, $typeAxis)
protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, $typeAxis, Chart\Type\AbstractType $typeChart)
{
if ($typeAxis != Chart\Axis::AXIS_X && $typeAxis != Chart\Axis::AXIS_Y) {
return;
Expand Down Expand Up @@ -2063,7 +1992,7 @@ protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, $typeAxis)
// c:numFmt
$objWriter->startElement('c:numFmt');
$objWriter->writeAttribute('formatCode', $oAxis->getFormatCode());
$objWriter->writeAttribute('sourceLinked', '0');
$objWriter->writeAttribute('sourceLinked', '1');
$objWriter->endElement();

// c:majorTickMark
Expand Down Expand Up @@ -2171,7 +2100,13 @@ protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, $typeAxis)
if ($typeAxis == Chart\Axis::AXIS_Y) {
// c:crossBetween
$objWriter->startElement('c:crossBetween');
$objWriter->writeAttribute('val', 'between');
// midCat : Position Axis On Tick Marks
// between : Between Tick Marks
if ($typeChart instanceof Area) {
$objWriter->writeAttribute('val', 'midCat');
} else {
$objWriter->writeAttribute('val', 'between');
}
$objWriter->endElement();
}

Expand Down
40 changes: 24 additions & 16 deletions src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ protected function writeSlideRelationships(Slide $pSlide)
$layoutId = $pSlide->getSlideLayout()->layoutNr;
}
$this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout', '../slideLayouts/slideLayout' . $layoutId . '.xml');
++$relId;

// Write drawing relationships?
if ($pSlide->getShapeCollection()->count() > 0) {
Expand All @@ -92,8 +93,10 @@ protected function writeSlideRelationships(Slide $pSlide)
while ($iterator->valid()) {
if ($iterator->current() instanceof Media) {
// Write relationship for image drawing
$this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $iterator->current()->getIndexedFilename());
$iterator->current()->relationId = 'rId' . $relId;
$this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/video', '../media/' . $iterator->current()->getIndexedFilename());
++$relId;
$this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $iterator->current()->getIndexedFilename());
++$relId;
} elseif ($iterator->current() instanceof ShapeDrawing\AbstractDrawingAdapter) {
// Write relationship for image drawing
Expand All @@ -110,12 +113,14 @@ protected function writeSlideRelationships(Slide $pSlide)
} elseif ($iterator->current() instanceof Group) {
$iterator2 = $iterator->current()->getShapeCollection()->getIterator();
while ($iterator2->valid()) {
if ($iterator->current() instanceof Media) {
if ($iterator2->current() instanceof Media) {
// Write relationship for image drawing
$iterator2->current()->relationId = 'rId' . $relId;
$this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/video', '../media/' . $iterator->current()->getIndexedFilename());
++$relId;
$this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $iterator->current()->getIndexedFilename());
$iterator->current()->relationId = 'rId' . $relId;
++$relId;
} elseif ($iterator->current() instanceof ShapeDrawing\AbstractDrawingAdapter) {
} elseif ($iterator2->current() instanceof ShapeDrawing\AbstractDrawingAdapter) {
// Write relationship for image drawing
$this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $iterator2->current()->getIndexedFilename());
$iterator2->current()->relationId = 'rId' . $relId;
Expand Down Expand Up @@ -953,7 +958,7 @@ protected function writeShapeDrawing(XMLWriter $objWriter, ShapeDrawing\Abstract
$objWriter->writeAttribute('uri', '{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}');
// p:nvPr > p:extLst > p:ext > p14:media
$objWriter->startElement('p14:media');
$objWriter->writeAttribute('r:embed', $shape->relationId);
$objWriter->writeAttribute('r:embed', ($shape->relationId + 1));
$objWriter->writeAttribute('xmlns:p14', 'http://schemas.microsoft.com/office/powerpoint/2010/main');
// p:nvPr > p:extLst > p:ext > ##p14:media
$objWriter->endElement();
Expand Down Expand Up @@ -1416,8 +1421,22 @@ protected function writeParagraphs(XMLWriter $objWriter, $paragraphs, $bIsPlaceh
$objWriter->writeAttribute('indent', CommonDrawing::pixelsToEmu($paragraph->getAlignment()->getIndent()));
$objWriter->writeAttribute('lvl', $paragraph->getAlignment()->getLevel());

$objWriter->startElement('a:lnSpc');
$objWriter->startElement('a:spcPct');
$objWriter->writeAttribute('val', $paragraph->getLineSpacing() * 1000);
$objWriter->endElement();
$objWriter->endElement();

// Bullet type specified?
if ($paragraph->getBulletStyle()->getBulletType() != Bullet::TYPE_NONE) {
// Color
// a:buClr must be before a:buFont (else PowerPoint crashes at launch)
if ($paragraph->getBulletStyle()->getBulletColor() instanceof Color) {
$objWriter->startElement('a:buClr');
$this->writeColor($objWriter, $paragraph->getBulletStyle()->getBulletColor());
$objWriter->endElement();
}

// a:buFont
$objWriter->startElement('a:buFont');
$objWriter->writeAttribute('typeface', $paragraph->getBulletStyle()->getBulletFont());
Expand All @@ -1437,19 +1456,8 @@ protected function writeParagraphs(XMLWriter $objWriter, $paragraphs, $bIsPlaceh
}
$objWriter->endElement();
}
if ($paragraph->getBulletStyle()->getBulletColor() instanceof Color) {
$objWriter->startElement('a:buClr');
$this->writeColor($objWriter, $paragraph->getBulletStyle()->getBulletColor());
$objWriter->endElement();
}
}

$objWriter->startElement('a:lnSpc');
$objWriter->startElement('a:spcPct');
$objWriter->writeAttribute('val', $paragraph->getLineSpacing() * 1000);
$objWriter->endElement();
$objWriter->endElement();

$objWriter->endElement();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*
* @coversDefaultClass PowerPoint2007
*/
class SlideTest extends \PHPUnit_Framework_TestCase
class PptSlideTest extends \PHPUnit_Framework_TestCase
{
/**
* Executed before each method of the class
Expand Down Expand Up @@ -188,7 +188,7 @@ public function testDrawingWithHyperlink()

$element = '/p:sld/p:cSld/p:spTree/p:pic/p:nvPicPr/p:cNvPr/a:hlinkClick';
$this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml'));
$this->assertEquals('rId2', $pres->getElementAttribute($element, 'r:id', 'ppt/slides/slide1.xml'));
$this->assertEquals('rId3', $pres->getElementAttribute($element, 'r:id', 'ppt/slides/slide1.xml'));
}

public function testDrawingShapeBorder()
Expand Down Expand Up @@ -864,7 +864,7 @@ public function testTableWithHyperlink()

$element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc/a:txBody/a:p/a:r/a:rPr/a:hlinkClick';
$this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml'));
$this->assertEquals('rId1', $pres->getElementAttribute($element, 'r:id', 'ppt/slides/slide1.xml'));
$this->assertEquals('rId2', $pres->getElementAttribute($element, 'r:id', 'ppt/slides/slide1.xml'));
}

public function testTransition()
Expand Down