1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpPresentation\Writer\PowerPoint2007; |
4
|
|
|
|
5
|
|
|
use PhpOffice\Common\Drawing as CommonDrawing; |
6
|
|
|
use PhpOffice\Common\XMLWriter; |
7
|
|
|
use PhpOffice\PhpPresentation\Slide; |
8
|
|
|
use PhpOffice\PhpPresentation\Slide\SlideLayout; |
9
|
|
|
use PhpOffice\PhpPresentation\Style\ColorMap; |
10
|
|
|
use PhpOffice\PhpPresentation\Slide\Background\Image; |
11
|
|
|
|
12
|
|
|
class PptSlideLayouts extends AbstractSlide |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @return \PhpOffice\Common\Adapter\Zip\ZipInterface |
16
|
|
|
* @throws \Exception |
17
|
|
|
*/ |
18
|
112 |
|
public function render() |
19
|
|
|
{ |
20
|
112 |
|
foreach ($this->oPresentation->getAllMasterSlides() as $oSlideMaster) { |
21
|
112 |
|
foreach ($oSlideMaster->getAllSlideLayouts() as $oSlideLayout) { |
22
|
112 |
|
$this->oZip->addFromString('ppt/slideLayouts/_rels/slideLayout' . $oSlideLayout->layoutNr . '.xml.rels', $this->writeSlideLayoutRelationships($oSlideLayout)); |
23
|
112 |
|
$this->oZip->addFromString('ppt/slideLayouts/slideLayout' . $oSlideLayout->layoutNr . '.xml', $this->writeSlideLayout($oSlideLayout)); |
24
|
|
|
|
25
|
|
|
// Add background image slide |
26
|
112 |
|
$oBkgImage = $oSlideLayout->getBackground(); |
27
|
112 |
|
if ($oBkgImage instanceof Image) { |
28
|
|
|
$this->oZip->addFromString('ppt/media/' . $oBkgImage->getIndexedFilename($oSlideLayout->getRelsIndex()), file_get_contents($oBkgImage->getPath())); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
112 |
|
return $this->oZip; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Write slide layout relationships to XML format |
38
|
|
|
* |
39
|
|
|
* @param \PhpOffice\PhpPresentation\Slide\SlideLayout $oSlideLayout |
40
|
|
|
* @return string XML Output |
41
|
|
|
* @throws \Exception |
42
|
|
|
*/ |
43
|
112 |
|
public function writeSlideLayoutRelationships(SlideLayout $oSlideLayout) |
44
|
|
|
{ |
45
|
|
|
// Create XML writer |
46
|
112 |
|
$objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); |
47
|
|
|
|
48
|
|
|
// XML header |
49
|
112 |
|
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
50
|
|
|
|
51
|
|
|
// Relationships |
52
|
112 |
|
$objWriter->startElement('Relationships'); |
53
|
112 |
|
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
54
|
|
|
|
55
|
112 |
|
$relId = 0; |
56
|
|
|
|
57
|
|
|
// Write slideMaster relationship |
58
|
112 |
|
$this->writeRelationship($objWriter, ++$relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster', '../slideMasters/slideMaster' . $oSlideLayout->getSlideMaster()->getRelsIndex() . '.xml'); |
59
|
|
|
|
60
|
|
|
// Write drawing relationships? |
61
|
112 |
|
$relId = $this->writeDrawingRelations($oSlideLayout, $objWriter, ++$relId); |
62
|
|
|
|
63
|
|
|
// Write background relationships? |
64
|
112 |
|
$oBackground = $oSlideLayout->getBackground(); |
65
|
112 |
|
if ($oBackground instanceof Image) { |
66
|
|
|
$this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $oBackground->getIndexedFilename($oSlideLayout->getRelsIndex())); |
67
|
|
|
$oBackground->relationId = 'rId' . $relId; |
68
|
|
|
|
69
|
|
|
$relId++; |
70
|
|
|
} |
71
|
|
|
|
72
|
112 |
|
$objWriter->endElement(); |
73
|
|
|
|
74
|
|
|
// Return |
75
|
112 |
|
return $objWriter->getData(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Write slide to XML format |
80
|
|
|
* |
81
|
|
|
* @param \PhpOffice\PhpPresentation\Slide\SlideLayout $pSlideLayout |
82
|
|
|
* @return string XML Output |
83
|
|
|
* @throws \Exception |
84
|
|
|
*/ |
85
|
112 |
|
public function writeSlideLayout(SlideLayout $pSlideLayout) |
86
|
|
|
{ |
87
|
|
|
// Create XML writer |
88
|
112 |
|
$objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); |
89
|
|
|
// XML header |
90
|
112 |
|
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
91
|
|
|
// p:sldLayout |
92
|
112 |
|
$objWriter->startElement('p:sldLayout'); |
93
|
112 |
|
$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); |
94
|
112 |
|
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); |
95
|
112 |
|
$objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main'); |
96
|
112 |
|
$objWriter->writeAttribute('preserve', 1); |
97
|
|
|
// p:sldLayout\p:cSld |
98
|
112 |
|
$objWriter->startElement('p:cSld'); |
99
|
112 |
|
$objWriter->writeAttributeIf($pSlideLayout->getLayoutName() != '', 'name', $pSlideLayout->getLayoutName()); |
100
|
|
|
// Background |
101
|
112 |
|
$this->writeSlideBackground($pSlideLayout, $objWriter); |
102
|
|
|
// p:sldLayout\p:cSld\p:spTree |
103
|
112 |
|
$objWriter->startElement('p:spTree'); |
104
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr |
105
|
112 |
|
$objWriter->startElement('p:nvGrpSpPr'); |
106
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr\p:cNvPr |
107
|
112 |
|
$objWriter->startElement('p:cNvPr'); |
108
|
112 |
|
$objWriter->writeAttribute('id', '1'); |
109
|
112 |
|
$objWriter->writeAttribute('name', ''); |
110
|
112 |
|
$objWriter->endElement(); |
111
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr\p:cNvGrpSpPr |
112
|
112 |
|
$objWriter->writeElement('p:cNvGrpSpPr', null); |
113
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr\p:nvPr |
114
|
112 |
|
$objWriter->writeElement('p:nvPr', null); |
115
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:nvGrpSpPr |
116
|
112 |
|
$objWriter->endElement(); |
117
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr |
118
|
112 |
|
$objWriter->startElement('p:grpSpPr'); |
119
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm |
120
|
112 |
|
$objWriter->startElement('a:xfrm'); |
121
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:off |
122
|
112 |
|
$objWriter->startElement('a:off'); |
123
|
112 |
|
$objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetX())); |
124
|
112 |
|
$objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetY())); |
125
|
112 |
|
$objWriter->endElement(); |
126
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:ext |
127
|
112 |
|
$objWriter->startElement('a:ext'); |
128
|
112 |
|
$objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentX())); |
129
|
112 |
|
$objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentY())); |
130
|
112 |
|
$objWriter->endElement(); |
131
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:chOff |
132
|
112 |
|
$objWriter->startElement('a:chOff'); |
133
|
112 |
|
$objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetX())); |
134
|
112 |
|
$objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pSlideLayout->getOffsetY())); |
135
|
112 |
|
$objWriter->endElement(); |
136
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:chExt |
137
|
112 |
|
$objWriter->startElement('a:chExt'); |
138
|
112 |
|
$objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentX())); |
139
|
112 |
|
$objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pSlideLayout->getExtentY())); |
140
|
112 |
|
$objWriter->endElement(); |
141
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr\a:xfrm\ |
142
|
112 |
|
$objWriter->endElement(); |
143
|
|
|
// p:sldLayout\p:cSld\p:spTree\p:grpSpPr\ |
144
|
112 |
|
$objWriter->endElement(); |
145
|
|
|
|
146
|
|
|
// Loop shapes |
147
|
112 |
|
$this->writeShapeCollection($objWriter, $pSlideLayout->getShapeCollection()); |
148
|
|
|
// p:sldLayout\p:cSld\p:spTree\ |
149
|
112 |
|
$objWriter->endElement(); |
150
|
|
|
// p:sldLayout\p:cSld\ |
151
|
112 |
|
$objWriter->endElement(); |
152
|
|
|
|
153
|
|
|
// p:sldLayout\p:clrMapOvr |
154
|
112 |
|
$objWriter->startElement('p:clrMapOvr'); |
155
|
112 |
|
$arrayDiff = array_diff_assoc(ColorMap::$mappingDefault, $pSlideLayout->colorMap->getMapping()); |
156
|
112 |
|
if (!empty($arrayDiff)) { |
157
|
|
|
// p:sldLayout\p:clrMapOvr\a:overrideClrMapping |
158
|
|
|
$objWriter->startElement('a:overrideClrMapping'); |
159
|
|
|
foreach ($pSlideLayout->colorMap->getMapping() as $n => $v) { |
160
|
|
|
$objWriter->writeAttribute($n, $v); |
161
|
|
|
} |
162
|
|
|
$objWriter->endElement(); |
163
|
|
|
} else { |
164
|
|
|
// p:sldLayout\p:clrMapOvr\a:masterClrMapping |
165
|
112 |
|
$objWriter->writeElement('a:masterClrMapping'); |
166
|
|
|
} |
167
|
|
|
// p:sldLayout\p:clrMapOvr\ |
168
|
112 |
|
$objWriter->endElement(); |
169
|
|
|
|
170
|
112 |
|
if (!is_null($pSlideLayout->getTransition())) { |
171
|
|
|
$this->writeSlideTransition($objWriter, $pSlideLayout->getTransition()); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
// p:sldLayout\ |
175
|
112 |
|
$objWriter->endElement(); |
176
|
|
|
|
177
|
112 |
|
return $objWriter->getData(); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|