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_Style_Font
30: */
31: class PHPWord_Style_Font
32: {
33:
34: const UNDERLINE_NONE = 'none';
35: const UNDERLINE_DASH = 'dash';
36: const UNDERLINE_DASHHEAVY = 'dashHeavy';
37: const UNDERLINE_DASHLONG = 'dashLong';
38: const UNDERLINE_DASHLONGHEAVY = 'dashLongHeavy';
39: const UNDERLINE_DOUBLE = 'dbl';
40: const UNDERLINE_DOTHASH = 'dotDash';
41: const UNDERLINE_DOTHASHHEAVY = 'dotDashHeavy';
42: const UNDERLINE_DOTDOTDASH = 'dotDotDash';
43: const UNDERLINE_DOTDOTDASHHEAVY = 'dotDotDashHeavy';
44: const UNDERLINE_DOTTED = 'dotted';
45: const UNDERLINE_DOTTEDHEAVY = 'dottedHeavy';
46: const UNDERLINE_HEAVY = 'heavy';
47: const UNDERLINE_SINGLE = 'single';
48: const UNDERLINE_WAVY = 'wavy';
49: const UNDERLINE_WAVYDOUBLE = 'wavyDbl';
50: const UNDERLINE_WAVYHEAVY = 'wavyHeavy';
51: const UNDERLINE_WORDS = 'words';
52:
53: const FGCOLOR_YELLOW = 'yellow';
54: const FGCOLOR_LIGHTGREEN = 'green';
55: const FGCOLOR_CYAN = 'cyan';
56: const FGCOLOR_MAGENTA = 'magenta';
57: const FGCOLOR_BLUE = 'blue';
58: const FGCOLOR_RED = 'red';
59: const FGCOLOR_DARKBLUE = 'darkBlue';
60: const FGCOLOR_DARKCYAN = 'darkCyan';
61: const FGCOLOR_DARKGREEN = 'darkGreen';
62: const FGCOLOR_DARKMAGENTA = 'darkMagenta';
63: const FGCOLOR_DARKRED = 'darkRed';
64: const FGCOLOR_DARKYELLOW = 'darkYellow';
65: const FGCOLOR_DARKGRAY = 'darkGray';
66: const FGCOLOR_LIGHTGRAY = 'lightGray';
67: const FGCOLOR_BLACK = 'black';
68:
69: /**
70: * Font style type
71: *
72: * @var string
73: */
74: private $_type;
75:
76: /**
77: * Paragraph Style
78: *
79: * @var PHPWord_Style_Paragraph
80: */
81: private $_paragraphStyle;
82:
83: private $_size;
84: private $_name;
85: private $_bold;
86: private $_italic;
87: private $_superScript;
88: private $_subScript;
89: private $_underline;
90: private $_strikethrough;
91: private $_color;
92: private $_fgColor;
93:
94: public function __construct($type = 'text', $styleParagraph = null)
95: {
96: $this->_type = $type;
97: $this->_name = PHPWord::DEFAULT_FONT_NAME;
98: $this->_size = PHPWord::DEFAULT_FONT_SIZE;
99: $this->_bold = false;
100: $this->_italic = false;
101: $this->_superScript = false;
102: $this->_subScript = false;
103: $this->_underline = PHPWord_Style_Font::UNDERLINE_NONE;
104: $this->_strikethrough = false;
105: $this->_color = '000000';
106: $this->_fgColor = null;
107:
108: if (!is_null($styleParagraph)) {
109: $paragraph = new PHPWord_Style_Paragraph();
110: foreach ($styleParagraph as $key => $value) {
111: if (substr($key, 0, 1) != '_') {
112: $key = '_' . $key;
113: }
114: $paragraph->setStyleValue($key, $value);
115: }
116: $this->_paragraphStyle = $paragraph;
117: } else {
118: $this->_paragraphStyle = null;
119: }
120: }
121:
122: public function getName()
123: {
124: return $this->_name;
125: }
126:
127: public function setStyleValue($key, $value)
128: {
129: if ($key == '_size') {
130: $value *= 2;
131: }
132: $this->$key = $value;
133: }
134:
135: public function setName($pValue = PHPWord::DEFAULT_FONT_NAME)
136: {
137: if ($pValue == '') {
138: $pValue = PHPWord::DEFAULT_FONT_NAME;
139: }
140: $this->_name = $pValue;
141: return $this;
142: }
143:
144: public function getSize()
145: {
146: return $this->_size;
147: }
148:
149: public function setSize($pValue = PHPWord::DEFAULT_FONT_SIZE)
150: {
151: if ($pValue == '') {
152: $pValue = PHPWord::DEFAULT_FONT_SIZE;
153: }
154: $this->_size = ($pValue * 2);
155: return $this;
156: }
157:
158: public function getBold()
159: {
160: return $this->_bold;
161: }
162:
163: public function setBold($pValue = false)
164: {
165: if ($pValue == '') {
166: $pValue = false;
167: }
168: $this->_bold = $pValue;
169: return $this;
170: }
171:
172: public function getItalic()
173: {
174: return $this->_italic;
175: }
176:
177: public function setItalic($pValue = false)
178: {
179: if ($pValue == '') {
180: $pValue = false;
181: }
182: $this->_italic = $pValue;
183: return $this;
184: }
185:
186: public function getSuperScript()
187: {
188: return $this->_superScript;
189: }
190:
191: public function setSuperScript($pValue = false)
192: {
193: if ($pValue == '') {
194: $pValue = false;
195: }
196: $this->_superScript = $pValue;
197: $this->_subScript = !$pValue;
198: return $this;
199: }
200:
201: public function getSubScript()
202: {
203: return $this->_subScript;
204: }
205:
206: public function setSubScript($pValue = false)
207: {
208: if ($pValue == '') {
209: $pValue = false;
210: }
211: $this->_subScript = $pValue;
212: $this->_superScript = !$pValue;
213: return $this;
214: }
215:
216: public function getUnderline()
217: {
218: return $this->_underline;
219: }
220:
221: public function setUnderline($pValue = PHPWord_Style_Font::UNDERLINE_NONE)
222: {
223: if ($pValue == '') {
224: $pValue = PHPWord_Style_Font::UNDERLINE_NONE;
225: }
226: $this->_underline = $pValue;
227: return $this;
228: }
229:
230: public function getStrikethrough()
231: {
232: return $this->_strikethrough;
233: }
234:
235: public function setStrikethrough($pValue = false)
236: {
237: if ($pValue == '') {
238: $pValue = false;
239: }
240: $this->_strikethrough = $pValue;
241: return $this;
242: }
243:
244: public function getColor()
245: {
246: return $this->_color;
247: }
248:
249: public function setColor($pValue = '000000')
250: {
251: $this->_color = $pValue;
252: return $this;
253: }
254:
255: public function getFgColor()
256: {
257: return $this->_fgColor;
258: }
259:
260: public function setFgColor($pValue = null)
261: {
262: $this->_fgColor = $pValue;
263: return $this;
264: }
265:
266: public function getStyleType()
267: {
268: return $this->_type;
269: }
270:
271: /**
272: * Get Paragraph style
273: *
274: * @return PHPWord_Style_Paragraph
275: */
276: public function getParagraphStyle()
277: {
278: return $this->_paragraphStyle;
279: }
280: }
281: