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