1
|
|
|
<?php |
2
|
|
|
namespace PhpOffice\PhpPresentation\Writer\PowerPoint2007; |
3
|
|
|
|
4
|
|
|
use PhpOffice\Common\Drawing as CommonDrawing; |
5
|
|
|
use PhpOffice\Common\XMLWriter; |
6
|
|
|
use PhpOffice\PhpPresentation\Shape\AbstractDrawing; |
7
|
|
|
use PhpOffice\PhpPresentation\Shape\Chart as ShapeChart; |
8
|
|
|
use PhpOffice\PhpPresentation\Shape\Comment; |
9
|
|
|
use PhpOffice\PhpPresentation\Shape\RichText; |
10
|
|
|
use PhpOffice\PhpPresentation\Shape\Table as ShapeTable; |
11
|
|
|
use PhpOffice\PhpPresentation\Slide; |
12
|
|
|
use PhpOffice\PhpPresentation\Slide\SlideMaster; |
13
|
|
|
use PhpOffice\PhpPresentation\Style\SchemeColor; |
14
|
|
|
use PhpOffice\PhpPresentation\Slide\Background\Image; |
15
|
|
|
|
16
|
|
|
class PptSlideMasters extends AbstractSlide |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @return \PhpOffice\Common\Adapter\Zip\ZipInterface |
20
|
|
|
*/ |
21
|
114 |
|
public function render() |
22
|
|
|
{ |
23
|
114 |
|
foreach ($this->oPresentation->getAllMasterSlides() as $oMasterSlide) { |
24
|
|
|
// Add the relations from the masterSlide to the ZIP file |
25
|
114 |
|
$this->oZip->addFromString('ppt/slideMasters/_rels/slideMaster' . $oMasterSlide->getRelsIndex() . '.xml.rels', $this->writeSlideMasterRelationships($oMasterSlide)); |
26
|
|
|
// Add the information from the masterSlide to the ZIP file |
27
|
114 |
|
$this->oZip->addFromString('ppt/slideMasters/slideMaster' . $oMasterSlide->getRelsIndex() . '.xml', $this->writeSlideMaster($oMasterSlide)); |
28
|
|
|
|
29
|
|
|
// Add background image slide |
30
|
114 |
|
$oBkgImage = $oMasterSlide->getBackground(); |
31
|
114 |
|
if ($oBkgImage instanceof Image) { |
32
|
|
|
$this->oZip->addFromString('ppt/media/' . $oBkgImage->getIndexedFilename($oMasterSlide->getRelsIndex()), file_get_contents($oBkgImage->getPath())); |
33
|
|
|
} |
34
|
114 |
|
} |
35
|
|
|
|
36
|
114 |
|
return $this->oZip; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Write slide master relationships to XML format |
41
|
|
|
* |
42
|
|
|
* @param SlideMaster $oMasterSlide |
43
|
|
|
* @return string XML Output |
44
|
|
|
* @throws \Exception |
45
|
|
|
* @internal param int $masterId Master slide id |
46
|
|
|
*/ |
47
|
115 |
|
public function writeSlideMasterRelationships(SlideMaster $oMasterSlide) |
48
|
|
|
{ |
49
|
|
|
// Create XML writer |
50
|
115 |
|
$objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); |
51
|
|
|
// XML header |
52
|
115 |
|
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
53
|
|
|
// Relationships |
54
|
115 |
|
$objWriter->startElement('Relationships'); |
55
|
115 |
|
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
56
|
|
|
// Starting relation id |
57
|
115 |
|
$relId = 0; |
58
|
|
|
// Write all the relations to the Layout Slides |
59
|
115 |
|
foreach ($oMasterSlide->getAllSlideLayouts() as $slideLayout) { |
60
|
115 |
|
$this->writeRelationship($objWriter, ++$relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout', '../slideLayouts/slideLayout' . $slideLayout->layoutNr . '.xml'); |
61
|
|
|
// Save the used relationId |
62
|
115 |
|
$slideLayout->relationId = 'rId' . $relId; |
63
|
115 |
|
} |
64
|
|
|
|
65
|
|
|
// Write drawing relationships? |
66
|
115 |
|
$relId = $this->writeDrawingRelations($oMasterSlide, $objWriter, ++$relId); |
67
|
|
|
|
68
|
|
|
// Write background relationships? |
69
|
115 |
|
$oBackground = $oMasterSlide->getBackground(); |
70
|
115 |
|
if ($oBackground instanceof Image) { |
71
|
|
|
$this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $oBackground->getIndexedFilename($oMasterSlide->getRelsIndex())); |
72
|
|
|
$oBackground->relationId = 'rId' . $relId; |
73
|
|
|
|
74
|
|
|
$relId++; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
// TODO: Write hyperlink relationships? |
78
|
|
|
// TODO: Write comment relationships |
79
|
|
|
// Relationship theme/theme1.xml |
80
|
115 |
|
$this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme', '../theme/theme' . $oMasterSlide->getRelsIndex() . '.xml'); |
81
|
115 |
|
$objWriter->endElement(); |
82
|
|
|
// Return |
83
|
115 |
|
return $objWriter->getData(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Write slide to XML format |
88
|
|
|
* |
89
|
|
|
* @param \PhpOffice\PhpPresentation\Slide\SlideMaster $pSlide |
90
|
|
|
* @return string XML Output |
91
|
|
|
* @throws \Exception |
92
|
|
|
*/ |
93
|
114 |
|
public function writeSlideMaster(SlideMaster $pSlide) |
94
|
|
|
{ |
95
|
|
|
// Create XML writer |
96
|
114 |
|
$objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); |
97
|
|
|
// XML header |
98
|
114 |
|
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
99
|
|
|
// p:sldMaster |
100
|
114 |
|
$objWriter->startElement('p:sldMaster'); |
101
|
114 |
|
$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); |
102
|
114 |
|
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); |
103
|
114 |
|
$objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main'); |
104
|
|
|
// p:sldMaster\p:cSld |
105
|
114 |
|
$objWriter->startElement('p:cSld'); |
106
|
|
|
// Background |
107
|
114 |
|
$this->writeSlideBackground($pSlide, $objWriter); |
108
|
|
|
// p:sldMaster\p:cSld\p:spTree |
109
|
114 |
|
$objWriter->startElement('p:spTree'); |
110
|
|
|
// p:sldMaster\p:cSld\p:spTree\p:nvGrpSpPr |
111
|
114 |
|
$objWriter->startElement('p:nvGrpSpPr'); |
112
|
|
|
// p:sldMaster\p:cSld\p:spTree\p:nvGrpSpPr\p:cNvPr |
113
|
114 |
|
$objWriter->startElement('p:cNvPr'); |
114
|
114 |
|
$objWriter->writeAttribute('id', '1'); |
115
|
114 |
|
$objWriter->writeAttribute('name', ''); |
116
|
114 |
|
$objWriter->endElement(); |
117
|
|
|
// p:sldMaster\p:cSld\p:spTree\p:nvGrpSpPr\p:cNvGrpSpPr |
118
|
114 |
|
$objWriter->writeElement('p:cNvGrpSpPr', null); |
119
|
|
|
// p:sldMaster\p:cSld\p:spTree\p:nvGrpSpPr\p:nvPr |
120
|
114 |
|
$objWriter->writeElement('p:nvPr', null); |
121
|
|
|
// p:sldMaster\p:cSld\p:spTree\p:nvGrpSpPr |
122
|
114 |
|
$objWriter->endElement(); |
123
|
|
|
// p:sldMaster\p:cSld\p:spTree\p:grpSpPr |
124
|
114 |
|
$objWriter->startElement('p:grpSpPr'); |
125
|
|
|
// p:sldMaster\p:cSld\p:spTree\p:grpSpPr\a:xfrm |
126
|
114 |
|
$objWriter->startElement('a:xfrm'); |
127
|
|
|
// p:sldMaster\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:off |
128
|
114 |
|
$objWriter->startElement('a:off'); |
129
|
114 |
|
$objWriter->writeAttribute('x', 0); |
130
|
114 |
|
$objWriter->writeAttribute('y', 0); |
131
|
114 |
|
$objWriter->endElement(); |
132
|
|
|
// p:sldMaster\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:ext |
133
|
114 |
|
$objWriter->startElement('a:ext'); |
134
|
114 |
|
$objWriter->writeAttribute('cx', 0); |
135
|
114 |
|
$objWriter->writeAttribute('cy', 0); |
136
|
114 |
|
$objWriter->endElement(); |
137
|
|
|
// p:sldMaster\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:chOff |
138
|
114 |
|
$objWriter->startElement('a:chOff'); |
139
|
114 |
|
$objWriter->writeAttribute('x', 0); |
140
|
114 |
|
$objWriter->writeAttribute('y', 0); |
141
|
114 |
|
$objWriter->endElement(); |
142
|
|
|
// p:sldMaster\p:cSld\p:spTree\p:grpSpPr\a:xfrm\a:chExt |
143
|
114 |
|
$objWriter->startElement('a:chExt'); |
144
|
114 |
|
$objWriter->writeAttribute('cx', 0); |
145
|
114 |
|
$objWriter->writeAttribute('cy', 0); |
146
|
114 |
|
$objWriter->endElement(); |
147
|
|
|
// p:sldMaster\p:cSld\p:spTree\p:grpSpPr\a:xfrm\ |
148
|
114 |
|
$objWriter->endElement(); |
149
|
|
|
// p:sldMaster\p:cSld\p:spTree\p:grpSpPr\ |
150
|
114 |
|
$objWriter->endElement(); |
151
|
|
|
// Loop shapes |
152
|
114 |
|
$this->writeShapeCollection($objWriter, $pSlide->getShapeCollection()); |
153
|
|
|
// p:sldMaster\p:cSld\p:spTree\ |
154
|
114 |
|
$objWriter->endElement(); |
155
|
|
|
// p:sldMaster\p:cSld\ |
156
|
114 |
|
$objWriter->endElement(); |
157
|
|
|
|
158
|
|
|
// p:sldMaster\p:clrMap |
159
|
114 |
|
$objWriter->startElement('p:clrMap'); |
160
|
114 |
|
foreach ($pSlide->colorMap->getMapping() as $n => $v) { |
161
|
114 |
|
$objWriter->writeAttribute($n, $v); |
162
|
114 |
|
} |
163
|
114 |
|
$objWriter->endElement(); |
164
|
|
|
// p:sldMaster\p:clrMap\ |
165
|
|
|
|
166
|
|
|
// p:sldMaster\p:sldLayoutIdLst |
167
|
114 |
|
$objWriter->startElement('p:sldLayoutIdLst'); |
168
|
114 |
|
foreach ($pSlide->getAllSlideLayouts() as $layout) { |
169
|
|
|
/* @var $layout Slide\SlideLayout */ |
170
|
114 |
|
$objWriter->startElement('p:sldLayoutId'); |
171
|
114 |
|
$objWriter->writeAttribute('id', $layout->layoutId); |
172
|
114 |
|
$objWriter->writeAttribute('r:id', $layout->relationId); |
173
|
114 |
|
$objWriter->endElement(); |
174
|
114 |
|
} |
175
|
114 |
|
$objWriter->endElement(); |
176
|
|
|
// p:sldMaster\p:sldLayoutIdLst\ |
177
|
|
|
|
178
|
|
|
// p:sldMaster\p:txStyles |
179
|
114 |
|
$objWriter->startElement('p:txStyles'); |
180
|
|
|
foreach (array( |
181
|
114 |
|
'p:titleStyle' => $pSlide->getTextStyles()->getTitleStyle(), |
182
|
114 |
|
'p:bodyStyle' => $pSlide->getTextStyles()->getBodyStyle(), |
183
|
114 |
|
'p:otherStyle' => $pSlide->getTextStyles()->getOtherStyle() |
184
|
114 |
|
) as $startElement => $stylesArray) { |
185
|
|
|
// titleStyle |
186
|
114 |
|
$objWriter->startElement($startElement); |
187
|
114 |
|
foreach ($stylesArray as $lvl => $oParagraph) { |
188
|
|
|
/** @var RichText\Paragraph $oParagraph */ |
189
|
114 |
|
$elementName = ($lvl == 0 ? 'a:defPPr' : 'a:lvl' . $lvl . 'pPr'); |
190
|
114 |
|
$objWriter->startElement($elementName); |
191
|
114 |
|
$objWriter->writeAttribute('algn', $oParagraph->getAlignment()->getHorizontal()); |
192
|
114 |
|
$objWriter->writeAttributeIf( |
193
|
114 |
|
$oParagraph->getAlignment()->getMarginLeft() != 0, |
194
|
114 |
|
'marL', |
195
|
114 |
|
CommonDrawing::pixelsToEmu($oParagraph->getAlignment()->getMarginLeft()) |
196
|
114 |
|
); |
197
|
114 |
|
$objWriter->writeAttributeIf( |
198
|
114 |
|
$oParagraph->getAlignment()->getMarginRight() != 0, |
199
|
114 |
|
'marR', |
200
|
114 |
|
CommonDrawing::pixelsToEmu($oParagraph->getAlignment()->getMarginRight()) |
201
|
114 |
|
); |
202
|
114 |
|
$objWriter->writeAttributeIf( |
203
|
114 |
|
$oParagraph->getAlignment()->getIndent() != 0, |
204
|
114 |
|
'indent', |
205
|
114 |
|
CommonDrawing::pixelsToEmu($oParagraph->getAlignment()->getIndent()) |
206
|
114 |
|
); |
207
|
114 |
|
$objWriter->startElement('a:defRPr'); |
208
|
114 |
|
$objWriter->writeAttributeIf($oParagraph->getFont()->getSize() != 10, 'sz', $oParagraph->getFont()->getSize() * 100); |
209
|
114 |
|
$objWriter->writeAttributeIf($oParagraph->getFont()->isBold(), 'b', 1); |
210
|
114 |
|
$objWriter->writeAttributeIf($oParagraph->getFont()->isItalic(), 'i', 1); |
211
|
114 |
|
$objWriter->writeAttribute('kern', '1200'); |
212
|
114 |
|
if ($oParagraph->getFont()->getColor() instanceof SchemeColor) { |
213
|
114 |
|
$objWriter->startElement('a:solidFill'); |
214
|
114 |
|
$objWriter->startElement('a:schemeClr'); |
215
|
114 |
|
$objWriter->writeAttribute('val', $oParagraph->getFont()->getColor()->getValue()); |
216
|
114 |
|
$objWriter->endElement(); |
217
|
114 |
|
$objWriter->endElement(); |
218
|
114 |
|
} |
219
|
114 |
|
$objWriter->endElement(); |
220
|
114 |
|
$objWriter->endElement(); |
221
|
114 |
|
} |
222
|
114 |
|
$objWriter->writeElement('a:extLst'); |
223
|
114 |
|
$objWriter->endElement(); |
224
|
114 |
|
} |
225
|
114 |
|
$objWriter->endElement(); |
226
|
|
|
// p:sldMaster\p:txStyles\ |
227
|
|
|
|
228
|
114 |
|
if (!is_null($pSlide->getTransition())) { |
229
|
|
|
$this->writeSlideTransition($objWriter, $pSlide->getTransition()); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
// p:sldMaster\ |
233
|
114 |
|
$objWriter->endElement(); |
234
|
|
|
|
235
|
114 |
|
return $objWriter->getData(); |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|