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: /** PHPWORD_BASE_PATH */
29: if (!defined('PHPWORD_BASE_PATH')) {
30: define('PHPWORD_BASE_PATH', dirname(__FILE__) . '/');
31: require PHPWORD_BASE_PATH . 'PHPWord/Autoloader.php';
32: PHPWord_Autoloader::Register();
33: }
34:
35:
36: /**
37: * PHPWord
38: */
39: class PHPWord
40: {
41:
42: const DEFAULT_FONT_NAME = 'Arial';
43: const DEFAULT_FONT_SIZE = 20;
44:
45: /**
46: * Document properties
47: *
48: * @var PHPWord_DocumentProperties
49: */
50: private $_properties;
51:
52: /**
53: * Default Font Name
54: *
55: * @var string
56: */
57: private $_defaultFontName;
58:
59: /**
60: * Default Font Size
61: *
62: * @var int
63: */
64: private $_defaultFontSize;
65:
66: /**
67: * Collection of section elements
68: *
69: * @var array
70: */
71: private $_sectionCollection = array();
72:
73:
74: /**
75: * Create a new PHPWord Document
76: */
77: public function __construct()
78: {
79: $this->_properties = new PHPWord_DocumentProperties();
80: $this->_defaultFontName = PHPWord::DEFAULT_FONT_NAME;
81: $this->_defaultFontSize = PHPWord::DEFAULT_FONT_SIZE;
82: }
83:
84: /**
85: * Get properties
86: * @return PHPWord_DocumentProperties
87: */
88: public function getProperties()
89: {
90: return $this->_properties;
91: }
92:
93: /**
94: * Set properties
95: *
96: * @param PHPWord_DocumentProperties $value
97: * @return PHPWord
98: */
99: public function setProperties(PHPWord_DocumentProperties $value)
100: {
101: $this->_properties = $value;
102: return $this;
103: }
104:
105: /**
106: * Create a new Section
107: *
108: * @param PHPWord_Section_Settings $settings
109: * @return PHPWord_Section
110: */
111: public function createSection($settings = null)
112: {
113: $sectionCount = $this->_countSections() + 1;
114:
115: $section = new PHPWord_Section($sectionCount, $settings);
116: $this->_sectionCollection[] = $section;
117: return $section;
118: }
119:
120: /**
121: * Get default Font name
122: * @return string
123: */
124: public function getDefaultFontName()
125: {
126: return $this->_defaultFontName;
127: }
128:
129: /**
130: * Set default Font name
131: * @param string $pValue
132: */
133: public function setDefaultFontName($pValue)
134: {
135: $this->_defaultFontName = $pValue;
136: }
137:
138: /**
139: * Get default Font size
140: * @return string
141: */
142: public function getDefaultFontSize()
143: {
144: return $this->_defaultFontSize;
145: }
146:
147: /**
148: * Set default Font size
149: * @param int $pValue
150: */
151: public function setDefaultFontSize($pValue)
152: {
153: $pValue = $pValue * 2;
154: $this->_defaultFontSize = $pValue;
155: }
156:
157: /**
158: * Adds a paragraph style definition to styles.xml
159: *
160: * @param $styleName string
161: * @param $styles array
162: */
163: public function addParagraphStyle($styleName, $styles)
164: {
165: PHPWord_Style::addParagraphStyle($styleName, $styles);
166: }
167:
168: /**
169: * Adds a font style definition to styles.xml
170: *
171: * @param $styleName string
172: * @param $styles array
173: */
174: public function addFontStyle($styleName, $styleFont, $styleParagraph = null)
175: {
176: PHPWord_Style::addFontStyle($styleName, $styleFont, $styleParagraph);
177: }
178:
179: /**
180: * Adds a table style definition to styles.xml
181: *
182: * @param $styleName string
183: * @param $styles array
184: */
185: public function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
186: {
187: PHPWord_Style::addTableStyle($styleName, $styleTable, $styleFirstRow);
188: }
189:
190: /**
191: * Adds a heading style definition to styles.xml
192: *
193: * @param $titleCount int
194: * @param $styles array
195: */
196: public function addTitleStyle($titleCount, $styleFont, $styleParagraph = null)
197: {
198: PHPWord_Style::addTitleStyle($titleCount, $styleFont, $styleParagraph);
199: }
200:
201: /**
202: * Adds a hyperlink style to styles.xml
203: *
204: * @param $styleName string
205: * @param $styles array
206: */
207: public function addLinkStyle($styleName, $styles)
208: {
209: PHPWord_Style::addLinkStyle($styleName, $styles);
210: }
211:
212: /**
213: * Get sections
214: * @return PHPWord_Section[]
215: */
216: public function getSections()
217: {
218: return $this->_sectionCollection;
219: }
220:
221: /**
222: * Get section count
223: * @return int
224: */
225: private function _countSections()
226: {
227: return count($this->_sectionCollection);
228: }
229:
230: /**
231: * Load a Template File
232: *
233: * @param string $strFilename
234: * @return PHPWord_Template
235: */
236: public function loadTemplate($strFilename)
237: {
238: if (file_exists($strFilename)) {
239: $template = new PHPWord_Template($strFilename);
240: return $template;
241: } else {
242: trigger_error('Template file ' . $strFilename . ' not found.', E_USER_ERROR);
243: }
244: }
245: }