Overview

Packages

  • PHP
  • PHPWord

Classes

  • PHPWord
  • PHPWord_Autoloader
  • PHPWord_DocumentProperties
  • PHPWord_HashTable
  • PHPWord_IOFactory
  • PHPWord_Media
  • PHPWord_Section
  • PHPWord_Section_Footer
  • PHPWord_Section_Footer_PreserveText
  • PHPWord_Section_Header
  • PHPWord_Section_Image
  • PHPWord_Section_Link
  • PHPWord_Section_ListItem
  • PHPWord_Section_MemoryImage
  • PHPWord_Section_Object
  • PHPWord_Section_PageBreak
  • PHPWord_Section_Settings
  • PHPWord_Section_Table
  • PHPWord_Section_Table_Cell
  • PHPWord_Section_Table_Row
  • PHPWord_Section_Text
  • PHPWord_Section_TextBreak
  • PHPWord_Section_TextRun
  • PHPWord_Section_Title
  • PHPWord_Shared_Drawing
  • PHPWord_Shared_File
  • PHPWord_Shared_Font
  • PHPWord_Shared_String
  • PHPWord_Shared_XMLWriter
  • PHPWord_Shared_ZipStreamWrapper
  • PHPWord_Style
  • PHPWord_Style_Cell
  • PHPWord_Style_Font
  • PHPWord_Style_Image
  • PHPWord_Style_ListItem
  • PHPWord_Style_Paragraph
  • PHPWord_Style_Row
  • PHPWord_Style_Tab
  • PHPWord_Style_Table
  • PHPWord_Style_TableFull
  • PHPWord_Style_Tabs
  • PHPWord_Style_TOC
  • PHPWord_Template
  • PHPWord_TOC
  • PHPWord_Writer_ODText
  • PHPWord_Writer_ODText_Content
  • PHPWord_Writer_ODText_Manifest
  • PHPWord_Writer_ODText_Meta
  • PHPWord_Writer_ODText_Mimetype
  • PHPWord_Writer_ODText_Styles
  • PHPWord_Writer_ODText_WriterPart
  • PHPWord_Writer_RTF
  • PHPWord_Writer_Word2007
  • PHPWord_Writer_Word2007_Base
  • PHPWord_Writer_Word2007_ContentTypes
  • PHPWord_Writer_Word2007_DocProps
  • PHPWord_Writer_Word2007_Document
  • PHPWord_Writer_Word2007_DocumentRels
  • PHPWord_Writer_Word2007_Footer
  • PHPWord_Writer_Word2007_Header
  • PHPWord_Writer_Word2007_Rels
  • PHPWord_Writer_Word2007_Styles
  • PHPWord_Writer_Word2007_WriterPart

Interfaces

  • PHPWord_Writer_IWriter

Exceptions

  • PHPWord_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * PHPWord
  4:  *
  5:  * Copyright (c) 2013 PHPWord
  6:  *
  7:  * This library is free software; you can redistribute it and/or
  8:  * modify it under the terms of the GNU Lesser General Public
  9:  * License as published by the Free Software Foundation; either
 10:  * version 2.1 of the License, or (at your option) any later version.
 11:  *
 12:  * This library is distributed in the hope that it will be useful,
 13:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 15:  * Lesser General Public License for more details.
 16:  *
 17:  * You should have received a copy of the GNU Lesser General Public
 18:  * License along with this library; if not, write to the Free Software
 19:  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 20:  *
 21:  * @category   PHPWord
 22:  * @package    PHPWord
 23:  * @copyright  Copyright (c) 2013 PHPWord
 24:  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
 25:  * @version    0.7.0
 26:  */
 27: 
 28: /**
 29:  * Class PHPWord_Writer_ODText_Styles
 30:  */
 31: class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
 32: {
 33:     /**
 34:      * Write Styles file to XML format
 35:      *
 36:      * @param    PHPWord $pPHPWord
 37:      * @return    string                        XML Output
 38:      * @throws    Exception
 39:      */
 40:     public function writeStyles(PHPWord $pPHPWord = null)
 41:     {
 42:         // Create XML writer
 43:         $objWriter = null;
 44:         if ($this->getParentWriter()->getUseDiskCaching()) {
 45:             $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
 46:         } else {
 47:             $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
 48:         }
 49: 
 50:         // XML header
 51:         $objWriter->startDocument('1.0', 'UTF-8');
 52: 
 53:         // Styles:Styles
 54:         $objWriter->startElement('office:document-styles');
 55:         $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
 56:         $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
 57:         $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
 58:         $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
 59:         $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
 60:         $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
 61:         $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
 62:         $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
 63:         $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
 64:         $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
 65:         $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
 66:         $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
 67:         $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
 68:         $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
 69:         $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
 70:         $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
 71:         $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
 72:         $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
 73:         $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
 74:         $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
 75:         $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
 76:         $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
 77:         $objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
 78:         $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
 79:         $objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
 80:         $objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
 81:         $objWriter->writeAttribute('office:version', '1.2');
 82: 
 83: 
 84:         // office:font-face-decls
 85:         $objWriter->startElement('office:font-face-decls');
 86:         $arrFonts = array();
 87:         $styles = PHPWord_Style::getStyles();
 88:         $numFonts = 0;
 89:         if (count($styles) > 0) {
 90:             foreach ($styles as $styleName => $style) {
 91:                 // PHPWord_Style_Font
 92:                 if ($style instanceof PHPWord_Style_Font) {
 93:                     $numFonts++;
 94:                     $name = $style->getName();
 95:                     if (!in_array($name, $arrFonts)) {
 96:                         $arrFonts[] = $name;
 97: 
 98:                         // style:font-face
 99:                         $objWriter->startElement('style:font-face');
100:                         $objWriter->writeAttribute('style:name', $name);
101:                         $objWriter->writeAttribute('svg:font-family', $name);
102:                         $objWriter->endElement();
103:                     }
104:                 }
105:             }
106:         }
107:         if (!in_array(PHPWord::DEFAULT_FONT_NAME, $arrFonts)) {
108:             $objWriter->startElement('style:font-face');
109:             $objWriter->writeAttribute('style:name', PHPWord::DEFAULT_FONT_NAME);
110:             $objWriter->writeAttribute('svg:font-family', PHPWord::DEFAULT_FONT_NAME);
111:             $objWriter->endElement();
112:         }
113:         $objWriter->endElement();
114: 
115:         // office:styles
116:         $objWriter->startElement('office:styles');
117: 
118:         // style:default-style
119:         $objWriter->startElement('style:default-style');
120:         $objWriter->writeAttribute('style:family', 'paragraph');
121: 
122:         // style:paragraph-properties
123:         $objWriter->startElement('style:paragraph-properties');
124:         $objWriter->writeAttribute('fo:hyphenation-ladder-count', 'no-limit');
125:         $objWriter->writeAttribute('style:text-autospace', 'ideograph-alpha');
126:         $objWriter->writeAttribute('style:punctuation-wrap', 'hanging');
127:         $objWriter->writeAttribute('style:line-break', 'strict');
128:         $objWriter->writeAttribute('style:tab-stop-distance', '1.249cm');
129:         $objWriter->writeAttribute('style:writing-mode', 'page');
130:         $objWriter->endElement();
131: 
132:         // style:text-properties
133:         $objWriter->startElement('style:text-properties');
134:         $objWriter->writeAttribute('style:use-window-font-color', 'true');
135:         $objWriter->writeAttribute('style:font-name', PHPWord::DEFAULT_FONT_NAME);
136:         $objWriter->writeAttribute('fo:font-size', '10pt');
137:         $objWriter->writeAttribute('fo:language', 'fr');
138:         $objWriter->writeAttribute('fo:country', 'FR');
139:         $objWriter->writeAttribute('style:letter-kerning', 'true');
140:         $objWriter->writeAttribute('style:font-name-asian', 'Arial2');
141:         $objWriter->writeAttribute('style:font-size-asian', '10pt');
142:         $objWriter->writeAttribute('style:language-asian', 'zh');
143:         $objWriter->writeAttribute('style:country-asian', 'CN');
144:         $objWriter->writeAttribute('style:font-name-complex', 'Arial2');
145:         $objWriter->writeAttribute('style:font-size-complex', '10pt');
146:         $objWriter->writeAttribute('style:language-complex', 'hi');
147:         $objWriter->writeAttribute('style:country-complex', 'IN');
148:         $objWriter->writeAttribute('fo:hyphenate', 'false');
149:         $objWriter->writeAttribute('fo:hyphenation-remain-char-count', '2');
150:         $objWriter->writeAttribute('fo:hyphenation-push-char-count', '2');
151:         $objWriter->endElement();
152: 
153:         $objWriter->endElement();
154: 
155:         // Write Style Definitions
156:         $styles = PHPWord_Style::getStyles();
157:         if (count($styles) > 0) {
158:             foreach ($styles as $styleName => $style) {
159:                 if (preg_match('#^T[0-9]+$#', $styleName) == 0
160:                     && preg_match('#^P[0-9]+$#', $styleName) == 0
161:                 ) {
162:                     // PHPWord_Style_Font
163:                     if ($style instanceof PHPWord_Style_Font) {
164:                         // style:style
165:                         $objWriter->startElement('style:style');
166:                         $objWriter->writeAttribute('style:name', $styleName);
167:                         $objWriter->writeAttribute('style:family', 'text');
168: 
169:                         // style:text-properties
170:                         $objWriter->startElement('style:text-properties');
171:                         $objWriter->writeAttribute('fo:font-size', ($style->getSize() / 2) . 'pt');
172:                         $objWriter->writeAttribute('style:font-size-asian', ($style->getSize() / 2) . 'pt');
173:                         $objWriter->writeAttribute('style:font-size-complex', ($style->getSize() / 2) . 'pt');
174:                         if ($style->getItalic()) {
175:                             $objWriter->writeAttribute('fo:font-style', 'italic');
176:                             $objWriter->writeAttribute('style:font-style-asian', 'italic');
177:                             $objWriter->writeAttribute('style:font-style-complex', 'italic');
178:                         }
179:                         if ($style->getBold()) {
180:                             $objWriter->writeAttribute('fo:font-weight', 'bold');
181:                             $objWriter->writeAttribute('style:font-weight-asian', 'bold');
182:                         }
183:                         $objWriter->endElement();
184:                         $objWriter->endElement();
185:                     } // PHPWord_Style_Paragraph
186:                     elseif ($style instanceof PHPWord_Style_Paragraph) {
187:                         // style:style
188:                         $objWriter->startElement('style:style');
189:                         $objWriter->writeAttribute('style:name', $styleName);
190:                         $objWriter->writeAttribute('style:family', 'paragraph');
191: 
192:                         //style:paragraph-properties
193:                         $objWriter->startElement('style:paragraph-properties');
194:                         $objWriter->writeAttribute('fo:margin-top', ((is_null($style->getSpaceBefore())) ? '0' : round(17.6 / $style->getSpaceBefore(), 2)) . 'cm');
195:                         $objWriter->writeAttribute('fo:margin-bottom', ((is_null($style->getSpaceAfter())) ? '0' : round(17.6 / $style->getSpaceAfter(), 2)) . 'cm');
196:                         $objWriter->writeAttribute('fo:text-align', $style->getAlign());
197:                         $objWriter->endElement();
198: 
199:                         $objWriter->endElement();
200: 
201:                     } // PHPWord_Style_TableFull
202:                     elseif ($style instanceof PHPWord_Style_TableFull) {
203:                     }
204:                 }
205:             }
206:         }
207:         $objWriter->endElement();
208: 
209:         // office:automatic-styles
210:         $objWriter->startElement('office:automatic-styles');
211:         // style:page-layout
212:         $objWriter->startElement('style:page-layout');
213:         $objWriter->writeAttribute('style:name', 'Mpm1');
214:         // style:page-layout-properties
215:         $objWriter->startElement('style:page-layout-properties');
216:         $objWriter->writeAttribute('fo:page-width', "21.001cm");
217:         $objWriter->writeAttribute('fo:page-height', '29.7cm');
218:         $objWriter->writeAttribute('style:num-format', '1');
219:         $objWriter->writeAttribute('style:print-orientation', 'portrait');
220:         $objWriter->writeAttribute('fo:margin-top', '2.501cm');
221:         $objWriter->writeAttribute('fo:margin-bottom', '2cm');
222:         $objWriter->writeAttribute('fo:margin-left', '2.501cm');
223:         $objWriter->writeAttribute('fo:margin-right', '2.501cm');
224:         $objWriter->writeAttribute('style:writing-mode', 'lr-tb');
225:         $objWriter->writeAttribute('style:layout-grid-color', '#c0c0c0');
226:         $objWriter->writeAttribute('style:layout-grid-lines', '25199');
227:         $objWriter->writeAttribute('style:layout-grid-base-height', '0.423cm');
228:         $objWriter->writeAttribute('style:layout-grid-ruby-height', '0cm');
229:         $objWriter->writeAttribute('style:layout-grid-mode', 'none');
230:         $objWriter->writeAttribute('style:layout-grid-ruby-below', 'false');
231:         $objWriter->writeAttribute('style:layout-grid-print', 'false');
232:         $objWriter->writeAttribute('style:layout-grid-display', 'false');
233:         $objWriter->writeAttribute('style:layout-grid-base-width', '0.37cm');
234:         $objWriter->writeAttribute('style:layout-grid-snap-to', 'true');
235:         $objWriter->writeAttribute('style:footnote-max-height', '0cm');
236:         //style:footnote-sep
237:         $objWriter->startElement('style:footnote-sep');
238:         $objWriter->writeAttribute('style:width', '0.018cm');
239:         $objWriter->writeAttribute('style:line-style', 'solid');
240:         $objWriter->writeAttribute('style:adjustment', 'left');
241:         $objWriter->writeAttribute('style:rel-width', '25%');
242:         $objWriter->writeAttribute('style:color', '#000000');
243:         $objWriter->endElement();
244:         $objWriter->endElement();
245:         // style:header-style
246:         $objWriter->startElement('style:header-style');
247:         $objWriter->endElement();
248:         // style:footer-style
249:         $objWriter->startElement('style:footer-style');
250:         $objWriter->endElement();
251:         $objWriter->endElement();
252:         $objWriter->endElement();
253: 
254:         // office:master-styles
255:         $objWriter->startElement('office:master-styles');
256:         // style:master-page
257:         $objWriter->startElement('style:master-page');
258:         $objWriter->writeAttribute('style:name', 'Standard');
259:         $objWriter->writeAttribute('style:page-layout-name', 'Mpm1');
260:         $objWriter->endElement();
261:         $objWriter->endElement();
262: 
263:         $objWriter->endElement();
264: 
265:         // Return
266:         return $objWriter->getData();
267:     }
268: }
269: 
PHPWord API Docs API documentation generated by ApiGen 2.8.0