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