17
17
18
18
namespace PhpOffice \PhpWord \Writer \ODText \Part ;
19
19
20
+ use PhpOffice \PhpWord \Settings ;
20
21
use PhpOffice \PhpWord \Shared \XMLWriter ;
22
+ use PhpOffice \PhpWord \Style ;
21
23
22
24
/**
23
- * ODText styloes part writer: styles.xml
25
+ * ODText styles part writer: styles.xml
24
26
*/
25
27
class Styles extends AbstractPart
26
28
{
@@ -43,14 +45,14 @@ public function write()
43
45
44
46
// Office styles
45
47
$ xmlWriter ->startElement ('office:styles ' );
46
- $ this ->writePart ($ xmlWriter, ' Default ' );
47
- $ this ->writePart ($ xmlWriter, ' Named ' );
48
+ $ this ->writeDefault ($ xmlWriter );
49
+ $ this ->writeNamed ($ xmlWriter );
48
50
$ xmlWriter ->endElement ();
49
51
50
52
// Automatic styles
51
53
$ xmlWriter ->startElement ('office:automatic-styles ' );
52
- $ this ->writePart ($ xmlWriter, ' PageLayout ' );
53
- $ this ->writePart ($ xmlWriter, ' Master ' );
54
+ $ this ->writePageLayout ($ xmlWriter );
55
+ $ this ->writeMaster ($ xmlWriter );
54
56
$ xmlWriter ->endElement ();
55
57
56
58
$ xmlWriter ->endElement (); // office:document-styles
@@ -59,15 +61,129 @@ public function write()
59
61
}
60
62
61
63
/**
62
- * Write style part
63
- *
64
- * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
65
- * @param string $subStyle
64
+ * Write default styles
65
+ */
66
+ private function writeDefault (XMLWriter $ xmlWriter )
67
+ {
68
+ $ xmlWriter ->startElement ('style:default-style ' );
69
+ $ xmlWriter ->writeAttribute ('style:family ' , 'paragraph ' );
70
+
71
+ // Paragraph
72
+ $ xmlWriter ->startElement ('style:paragraph-properties ' );
73
+ $ xmlWriter ->writeAttribute ('fo:hyphenation-ladder-count ' , 'no-limit ' );
74
+ $ xmlWriter ->writeAttribute ('style:text-autospace ' , 'ideograph-alpha ' );
75
+ $ xmlWriter ->writeAttribute ('style:punctuation-wrap ' , 'hanging ' );
76
+ $ xmlWriter ->writeAttribute ('style:line-break ' , 'strict ' );
77
+ $ xmlWriter ->writeAttribute ('style:tab-stop-distance ' , '1.249cm ' );
78
+ $ xmlWriter ->writeAttribute ('style:writing-mode ' , 'page ' );
79
+ $ xmlWriter ->endElement (); // style:paragraph-properties
80
+
81
+ // Font
82
+ $ xmlWriter ->startElement ('style:text-properties ' );
83
+ $ xmlWriter ->writeAttribute ('style:use-window-font-color ' , 'true ' );
84
+ $ xmlWriter ->writeAttribute ('style:font-name ' , Settings::getDefaultFontName ());
85
+ $ xmlWriter ->writeAttribute ('fo:font-size ' , Settings::getDefaultFontSize () . 'pt ' );
86
+ $ xmlWriter ->writeAttribute ('fo:language ' , 'fr ' );
87
+ $ xmlWriter ->writeAttribute ('fo:country ' , 'FR ' );
88
+ $ xmlWriter ->writeAttribute ('style:letter-kerning ' , 'true ' );
89
+ $ xmlWriter ->writeAttribute ('style:font-name-asian ' , Settings::getDefaultFontName () . '2 ' );
90
+ $ xmlWriter ->writeAttribute ('style:font-size-asian ' , Settings::getDefaultFontSize () . 'pt ' );
91
+ $ xmlWriter ->writeAttribute ('style:language-asian ' , 'zh ' );
92
+ $ xmlWriter ->writeAttribute ('style:country-asian ' , 'CN ' );
93
+ $ xmlWriter ->writeAttribute ('style:font-name-complex ' , Settings::getDefaultFontName () . '2 ' );
94
+ $ xmlWriter ->writeAttribute ('style:font-size-complex ' , Settings::getDefaultFontSize () . 'pt ' );
95
+ $ xmlWriter ->writeAttribute ('style:language-complex ' , 'hi ' );
96
+ $ xmlWriter ->writeAttribute ('style:country-complex ' , 'IN ' );
97
+ $ xmlWriter ->writeAttribute ('fo:hyphenate ' , 'false ' );
98
+ $ xmlWriter ->writeAttribute ('fo:hyphenation-remain-char-count ' , '2 ' );
99
+ $ xmlWriter ->writeAttribute ('fo:hyphenation-push-char-count ' , '2 ' );
100
+ $ xmlWriter ->endElement (); // style:text-properties
101
+
102
+ $ xmlWriter ->endElement (); // style:default-style
103
+ }
104
+
105
+ /**
106
+ * Write named styles
107
+ */
108
+ private function writeNamed (XMLWriter $ xmlWriter )
109
+ {
110
+ $ styles = Style::getStyles ();
111
+ if (count ($ styles ) > 0 ) {
112
+ foreach ($ styles as $ style ) {
113
+ if ($ style ->isAuto () === false ) {
114
+ $ styleClass = str_replace ('\\Style \\' , '\\Writer \\ODText \\Style \\' , get_class ($ style ));
115
+ if (class_exists ($ styleClass )) {
116
+ /** @var $styleWriter \PhpOffice\PhpWord\Writer\ODText\Style\AbstractStyle Type hint */
117
+ $ styleWriter = new $ styleClass ($ xmlWriter , $ style );
118
+ $ styleWriter ->write ();
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ /**
125
+ * Write page layout styles
126
+ */
127
+ private function writePageLayout (XMLWriter $ xmlWriter )
128
+ {
129
+ $ xmlWriter ->startElement ('style:page-layout ' );
130
+ $ xmlWriter ->writeAttribute ('style:name ' , 'Mpm1 ' );
131
+
132
+ $ xmlWriter ->startElement ('style:page-layout-properties ' );
133
+ $ xmlWriter ->writeAttribute ('fo:page-width ' , "21.001cm " );
134
+ $ xmlWriter ->writeAttribute ('fo:page-height ' , '29.7cm ' );
135
+ $ xmlWriter ->writeAttribute ('style:num-format ' , '1 ' );
136
+ $ xmlWriter ->writeAttribute ('style:print-orientation ' , 'portrait ' );
137
+ $ xmlWriter ->writeAttribute ('fo:margin-top ' , '2.501cm ' );
138
+ $ xmlWriter ->writeAttribute ('fo:margin-bottom ' , '2cm ' );
139
+ $ xmlWriter ->writeAttribute ('fo:margin-left ' , '2.501cm ' );
140
+ $ xmlWriter ->writeAttribute ('fo:margin-right ' , '2.501cm ' );
141
+ $ xmlWriter ->writeAttribute ('style:writing-mode ' , 'lr-tb ' );
142
+ $ xmlWriter ->writeAttribute ('style:layout-grid-color ' , '#c0c0c0 ' );
143
+ $ xmlWriter ->writeAttribute ('style:layout-grid-lines ' , '25199 ' );
144
+ $ xmlWriter ->writeAttribute ('style:layout-grid-base-height ' , '0.423cm ' );
145
+ $ xmlWriter ->writeAttribute ('style:layout-grid-ruby-height ' , '0cm ' );
146
+ $ xmlWriter ->writeAttribute ('style:layout-grid-mode ' , 'none ' );
147
+ $ xmlWriter ->writeAttribute ('style:layout-grid-ruby-below ' , 'false ' );
148
+ $ xmlWriter ->writeAttribute ('style:layout-grid-print ' , 'false ' );
149
+ $ xmlWriter ->writeAttribute ('style:layout-grid-display ' , 'false ' );
150
+ $ xmlWriter ->writeAttribute ('style:layout-grid-base-width ' , '0.37cm ' );
151
+ $ xmlWriter ->writeAttribute ('style:layout-grid-snap-to ' , 'true ' );
152
+ $ xmlWriter ->writeAttribute ('style:footnote-max-height ' , '0cm ' );
153
+
154
+ $ xmlWriter ->startElement ('style:footnote-sep ' );
155
+ $ xmlWriter ->writeAttribute ('style:width ' , '0.018cm ' );
156
+ $ xmlWriter ->writeAttribute ('style:line-style ' , 'solid ' );
157
+ $ xmlWriter ->writeAttribute ('style:adjustment ' , 'left ' );
158
+ $ xmlWriter ->writeAttribute ('style:rel-width ' , '25% ' );
159
+ $ xmlWriter ->writeAttribute ('style:color ' , '#000000 ' );
160
+ $ xmlWriter ->endElement (); //style:footnote-sep
161
+
162
+ $ xmlWriter ->endElement (); // style:page-layout-properties
163
+
164
+
165
+ $ xmlWriter ->startElement ('style:header-style ' );
166
+ $ xmlWriter ->endElement (); // style:header-style
167
+
168
+ $ xmlWriter ->startElement ('style:footer-style ' );
169
+ $ xmlWriter ->endElement (); // style:footer-style
170
+
171
+ $ xmlWriter ->endElement (); // style:page-layout
172
+ }
173
+ /**
174
+ * Write master style
66
175
*/
67
- private function writePart (XMLWriter $ xmlWriter, $ subStyle )
176
+ private function writeMaster (XMLWriter $ xmlWriter )
68
177
{
69
- $ writerClass = "PhpOffice \\PhpWord \\Writer \\ODText \\Style \\{$ subStyle }Style " ;
70
- $ styleWriter = new $ writerClass ($ xmlWriter );
71
- $ styleWriter ->write ();
178
+ $ xmlWriter = $ this ->getXmlWriter ();
179
+
180
+ $ xmlWriter ->startElement ('office:master-styles ' );
181
+
182
+ $ xmlWriter ->startElement ('style:master-page ' );
183
+ $ xmlWriter ->writeAttribute ('style:name ' , 'Standard ' );
184
+ $ xmlWriter ->writeAttribute ('style:page-layout-name ' , 'Mpm1 ' );
185
+ $ xmlWriter ->endElement (); // style:master-page
186
+
187
+ $ xmlWriter ->endElement (); // office:master-styles
72
188
}
73
189
}
0 commit comments