16
16
*/
17
17
class Settings
18
18
{
19
- /** Available Zip library classes */
19
+ /**
20
+ * Zip libraries
21
+ */
20
22
const PCLZIP = 'PhpOffice \\PhpWord \\Shared \\ZipArchive ' ;
21
23
const ZIPARCHIVE = 'ZipArchive ' ;
22
24
23
- /** Optional PDF Rendering libraries */
25
+ /**
26
+ * PDF rendering libraries
27
+ */
24
28
const PDF_RENDERER_DOMPDF = 'DomPDF ' ;
25
29
30
+ /**
31
+ * Measurement units multiplication factor
32
+ *
33
+ * Applied to:
34
+ * - Section: margins, header/footer height, gutter, column spacing
35
+ * - Tab: position
36
+ *
37
+ * @const int|float
38
+ */
39
+ const UNIT_TWIP = 1 ; // = 1/20 point
40
+ const UNIT_CM = 567 ;
41
+ const UNIT_MM = 56.7 ;
42
+ const UNIT_INCH = 1440 ;
43
+ const UNIT_POINT = 20 ; // = 1/72 inch
44
+ const UNIT_PICA = 240 ; // = 1/6 inch = 12 points
45
+
26
46
/**
27
47
* Compatibility option for XMLWriter
28
48
*
29
- * @var boolean
49
+ * @var bool
30
50
*/
31
51
private static $ xmlWriterCompatibility = true ;
32
52
@@ -58,37 +78,46 @@ class Settings
58
78
*/
59
79
private static $ pdfRendererPath = null ;
60
80
81
+ /**
82
+ * Measurement unit
83
+ *
84
+ * @var string
85
+ */
86
+ private static $ measurementUnit = self ::UNIT_TWIP ;
87
+
61
88
/**
62
89
* Set the compatibility option used by the XMLWriter
63
90
*
64
- * @param boolean $compatibility This sets the setIndent and setIndentString for better compatibility
65
- * @return boolean Success or failure
91
+ * This sets the setIndent and setIndentString for better compatibility
92
+ *
93
+ * @param bool $compatibility
94
+ * @return bool
66
95
*/
67
96
public static function setCompatibility ($ compatibility )
68
97
{
69
98
if (is_bool ($ compatibility )) {
70
99
self ::$ xmlWriterCompatibility = $ compatibility ;
71
100
return true ;
72
101
}
102
+
73
103
return false ;
74
104
}
75
105
76
106
/**
77
107
* Return the compatibility option used by the XMLWriter
78
108
*
79
- * @return boolean Compatibility
109
+ * @return bool Compatibility
80
110
*/
81
111
public static function getCompatibility ()
82
112
{
83
113
return self ::$ xmlWriterCompatibility ;
84
114
}
85
115
86
116
/**
87
- * Set the Zip handler Class that PHPWord should use for Zip file management (PCLZip or ZipArchive)
117
+ * Set zip handler class
88
118
*
89
- * @param string $zipClass The Zip handler class that PHPWord should use for Zip file management
90
- * e.g. Settings::PCLZip or Settings::ZipArchive
91
- * @return boolean Success or failure
119
+ * @param string $zipClass
120
+ * @return bool
92
121
*/
93
122
public static function setZipClass ($ zipClass )
94
123
{
@@ -97,16 +126,14 @@ public static function setZipClass($zipClass)
97
126
self ::$ zipClass = $ zipClass ;
98
127
return true ;
99
128
}
129
+
100
130
return false ;
101
131
}
102
132
103
133
/**
104
- * Return the name of the Zip handler Class that PHPWord is configured to use (PCLZip or ZipArchive)
105
- * or Zip file management
134
+ * Get zip handler class
106
135
*
107
- * @return string Name of the Zip handler Class that PHPWord is configured to use
108
- * for Zip file management
109
- * e.g. Settings::PCLZip or Settings::ZipArchive
136
+ * @return string
110
137
*/
111
138
public static function getZipClass ()
112
139
{
@@ -118,7 +145,7 @@ public static function getZipClass()
118
145
*
119
146
* @param string $libraryName
120
147
* @param string $libraryBaseDir
121
- * @return boolean Success or failure
148
+ * @return bool Success or failure
122
149
*/
123
150
public static function setPdfRenderer ($ libraryName , $ libraryBaseDir )
124
151
{
@@ -141,14 +168,13 @@ public static function getPdfRendererName()
141
168
* Identify the external library to use for rendering PDF files
142
169
*
143
170
* @param string $libraryName
144
- * @return boolean Success or failure
171
+ * @return bool
145
172
*/
146
173
public static function setPdfRendererName ($ libraryName )
147
174
{
148
175
if (!in_array ($ libraryName , self ::$ pdfRenderers )) {
149
176
return false ;
150
177
}
151
-
152
178
self ::$ pdfRendererName = $ libraryName ;
153
179
154
180
return true ;
@@ -167,7 +193,7 @@ public static function getPdfRendererPath()
167
193
* Location of external library to use for rendering PDF files
168
194
*
169
195
* @param string $libraryBaseDir Directory path to the library's base folder
170
- * @return boolean Success or failure
196
+ * @return bool Success or failure
171
197
*/
172
198
public static function setPdfRendererPath ($ libraryBaseDir )
173
199
{
@@ -178,4 +204,31 @@ public static function setPdfRendererPath($libraryBaseDir)
178
204
179
205
return true ;
180
206
}
207
+
208
+ /**
209
+ * Get measurement unit
210
+ *
211
+ * @return int|float
212
+ */
213
+ public static function getMeasurementUnit ()
214
+ {
215
+ return self ::$ measurementUnit ;
216
+ }
217
+
218
+ /**
219
+ * Set measurement unit
220
+ *
221
+ * @param int|float $value
222
+ * @return bool
223
+ */
224
+ public static function setMeasurementUnit ($ value )
225
+ {
226
+ $ units = array (self ::UNIT_TWIP , self ::UNIT_CM , self ::UNIT_MM , self ::UNIT_INCH , self ::UNIT_POINT , self ::UNIT_PICA );
227
+ if (!in_array ($ value , $ units )) {
228
+ return false ;
229
+ }
230
+ self ::$ measurementUnit = $ value ;
231
+
232
+ return true ;
233
+ }
181
234
}
0 commit comments