1+ <?php
2+ /**
3+ * PHPWord
4+ *
5+ * Copyright (c) 2011 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) 010 PHPWord
24+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25+ * @version {something}
26+ */
27+
28+ /**
29+ * PHPWord_Style_Tabs
30+ *
31+ * @category PHPWord
32+ * @package PHPWord_Style_Paragraph
33+ * @copyright Copyright (c) 2011 PHPWord
34+ * @link http://www.schemacentral.com/sc/ooxml/e-w_tab-1.html w:tab
35+ */
36+ class PHPWord_Style_Tab {
37+
38+ /**
39+ * Tab Stop Type
40+ *
41+ * @var string
42+ */
43+ private $ _val ;
44+
45+ /**
46+ * Tab Leader Character
47+ *
48+ * @var string
49+ */
50+ private $ _leader ;
51+
52+ /**
53+ * Tab Stop Position
54+ *
55+ * @var int
56+ */
57+ private $ _position ;
58+
59+ /**
60+ * Tab Stop Type
61+ *
62+ * @var array
63+ * @link http://www.schemacentral.com/sc/ooxml/a-w_val-26.html Tab Stop Type
64+ */
65+ private static $ _possibleStopTypes = array (
66+ 'clear ' , // No Tab Stop
67+ 'left ' , // Left Tab Stop
68+ 'center ' , // Center Tab Stop
69+ 'right ' , // Right Tab Stop
70+ 'decimal ' , // Decimal Tab
71+ 'bar ' , // Bar Tab
72+ 'num ' // List tab
73+ );
74+
75+ /**
76+ * Tab Leader Character
77+ *
78+ * @var array
79+ * @link http://www.schemacentral.com/sc/ooxml/a-w_leader-1.html Tab Leader Character
80+ */
81+ private static $ _possibleLeaders = array (
82+ 'none ' , // No tab stop leader
83+ 'dot ' , // Dotted leader line
84+ 'hyphen ' , // Dashed tab stop leader line
85+ 'underscore ' , // Solid leader line
86+ 'heavy ' , // Heavy solid leader line
87+ 'middleDot ' // Middle dot leader line
88+ );
89+
90+ /**
91+ * Create a new instance of PHPWord_Style_Tab. Both $val and $leader
92+ * must conform to the values put forth in the schema. If they do not
93+ * they will be changed to default values.
94+ *
95+ * @param string $val Defaults to 'clear' if value is not possible.
96+ * @param int $position Must be an integer; otherwise defaults to 0.
97+ * @param string $leader Defaults to NULL if value is not possible.
98+ */
99+ public function __construct ($ val = NULL , $ position = 0 , $ leader = NULL ) {
100+ // Default to clear if the stop type is not matched
101+ $ this ->_val = (self ::isStopType ($ val )) ? $ val : 'clear ' ;
102+
103+ // Default to 0 if the position is non-numeric
104+ $ this ->_position = (is_numeric ($ position )) ? intval ($ position ) : 0 ;
105+
106+ // Default to NULL if no tab leader
107+ $ this ->_leader = (self ::isLeaderType ($ leader )) ? $ leader : NULL ;
108+ }
109+
110+ /**
111+ * Creates the XML DOM for the instance of PHPWord_Style_Tab.
112+ *
113+ * @param PHPWord_Shared_XMLWriter $objWriter
114+ */
115+ public function toXml (PHPWord_Shared_XMLWriter &$ objWriter = NULL ) {
116+ if (isset ($ objWriter )) {
117+ $ objWriter ->startElement ("w:tab " );
118+ $ objWriter ->writeAttribute ("w:val " , $ this ->_val );
119+ if (!is_null ($ this ->_leader )) {
120+ $ objWriter ->writeAttribute ("w:leader " , $ this ->_leader );
121+ }
122+ $ objWriter ->writeAttribute ("w:pos " , $ this ->_position );
123+ $ objWriter ->endElement ();
124+ }
125+ }
126+
127+ /**
128+ * Test if attribute is a valid stop type.
129+ *
130+ * @param string $attribute
131+ * @return bool True if it is; false otherwise.
132+ */
133+ private static function isStopType ($ attribute ) {
134+ return in_array ($ attribute , self ::$ _possibleStopTypes );
135+ }
136+
137+ /**
138+ * Test if attribute is a valid leader type.
139+ *
140+ * @param string $attribute
141+ * @return bool True if it is; false otherwise.
142+ */
143+ private static function isLeaderType ($ attribute ) {
144+ return in_array ($ attribute , self ::$ _possibleLeaders );
145+ }
146+ }
147+ ?>
0 commit comments