Skip to content

Commit 1a1356a

Browse files
committed
Section: Ability to define gutter and line numbering
1 parent 9b1f2f2 commit 1a1356a

File tree

18 files changed

+874
-415
lines changed

18 files changed

+874
-415
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ This release marked heavy refactorings on internal code structure with the creat
3939
- ODT Writer: Basic image writing - @ivanlanin
4040
- ODT Writer: Link writing - @ivanlanin
4141
- ODT Reader: Basic ODText Reader - @ivanlanin GH-71
42+
- Section: Ability to define gutter and line numbering
4243

4344
### Bugfixes
4445

docs/containers.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Below are the available settings for section:
5050
- ``borderBottomColor`` Border bottom color
5151
- ``headerHeight`` Spacing to top of header
5252
- ``footerHeight`` Spacing to bottom of footer
53+
- ``gutter`` Page gutter spacing
5354
- ``colsNum`` Number of columns
5455
- ``colsSpace`` Spacing between columns
5556
- ``breakType`` Section break type (nextPage, nextColumn, continuous,
@@ -92,6 +93,28 @@ using the ``breakType`` and ``colsNum`` property of the section.
9293
$section->getSettings()->setBreakType('continuous');
9394
$section->getSettings()->setColsNum(2);
9495
96+
97+
### Line numbering
98+
99+
You can apply line numbering to a section by using the ``lineNumbering``
100+
property of the section.
101+
102+
.. code-block:: php
103+
104+
// Method 1
105+
$section = $phpWord->addSection(array('lineNumbering' => array()));
106+
107+
// Method 2
108+
$section = $phpWord->addSection();
109+
$section->getSettings()->setLineNumbering(array());
110+
111+
Below are the properties of the line numbering style.
112+
113+
- ``start`` Line numbering starting value
114+
- ``increment`` Line number increments
115+
- ``distance`` Distance between text and line numbering in twip
116+
- ``restart`` Line numbering restart setting continuous|newPage|newSection
117+
95118
Headers
96119
-------
97120

docs/src/documentation.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ Below are the available settings for section:
344344
- `borderBottomColor` Border bottom color
345345
- `headerHeight` Spacing to top of header
346346
- `footerHeight` Spacing to bottom of footer
347+
- `gutter` Page gutter spacing
347348
- `colsNum` Number of columns
348349
- `colsSpace` Spacing between columns
349350
- `breakType` Section break type (nextPage, nextColumn, continuous, evenPage, oddPage)
@@ -380,6 +381,26 @@ $section->getSettings()->setBreakType('continuous');
380381
$section->getSettings()->setColsNum(2);
381382
```
382383

384+
### Line numbering
385+
386+
You can apply line numbering to a section by using the `lineNumbering` property of the section.
387+
388+
```php
389+
// Method 1
390+
$section = $phpWord->addSection(array('lineNumbering' => array()));
391+
392+
// Method 2
393+
$section = $phpWord->addSection();
394+
$section->getSettings()->setLineNumbering(array());
395+
```
396+
397+
Below are the properties of the line numbering style.
398+
399+
- `start` Line numbering starting value
400+
- `increment` Line number increments
401+
- `distance` Distance between text and line numbering in twip
402+
- `restart` Line numbering restart setting continuous|newPage|newSection
403+
383404
## Headers
384405

385406
Each section can have its own header reference. To create a header use the `addHeader` method:

src/PhpWord/Settings.php

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,37 @@
1616
*/
1717
class Settings
1818
{
19-
/** Available Zip library classes */
19+
/**
20+
* Zip libraries
21+
*/
2022
const PCLZIP = 'PhpOffice\\PhpWord\\Shared\\ZipArchive';
2123
const ZIPARCHIVE = 'ZipArchive';
2224

23-
/** Optional PDF Rendering libraries */
25+
/**
26+
* PDF rendering libraries
27+
*/
2428
const PDF_RENDERER_DOMPDF = 'DomPDF';
2529

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+
2646
/**
2747
* Compatibility option for XMLWriter
2848
*
29-
* @var boolean
49+
* @var bool
3050
*/
3151
private static $xmlWriterCompatibility = true;
3252

@@ -58,37 +78,46 @@ class Settings
5878
*/
5979
private static $pdfRendererPath = null;
6080

81+
/**
82+
* Measurement unit
83+
*
84+
* @var string
85+
*/
86+
private static $measurementUnit = self::UNIT_TWIP;
87+
6188
/**
6289
* Set the compatibility option used by the XMLWriter
6390
*
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
6695
*/
6796
public static function setCompatibility($compatibility)
6897
{
6998
if (is_bool($compatibility)) {
7099
self::$xmlWriterCompatibility = $compatibility;
71100
return true;
72101
}
102+
73103
return false;
74104
}
75105

76106
/**
77107
* Return the compatibility option used by the XMLWriter
78108
*
79-
* @return boolean Compatibility
109+
* @return bool Compatibility
80110
*/
81111
public static function getCompatibility()
82112
{
83113
return self::$xmlWriterCompatibility;
84114
}
85115

86116
/**
87-
* Set the Zip handler Class that PHPWord should use for Zip file management (PCLZip or ZipArchive)
117+
* Set zip handler class
88118
*
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
92121
*/
93122
public static function setZipClass($zipClass)
94123
{
@@ -97,16 +126,14 @@ public static function setZipClass($zipClass)
97126
self::$zipClass = $zipClass;
98127
return true;
99128
}
129+
100130
return false;
101131
}
102132

103133
/**
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
106135
*
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
110137
*/
111138
public static function getZipClass()
112139
{
@@ -118,7 +145,7 @@ public static function getZipClass()
118145
*
119146
* @param string $libraryName
120147
* @param string $libraryBaseDir
121-
* @return boolean Success or failure
148+
* @return bool Success or failure
122149
*/
123150
public static function setPdfRenderer($libraryName, $libraryBaseDir)
124151
{
@@ -141,14 +168,13 @@ public static function getPdfRendererName()
141168
* Identify the external library to use for rendering PDF files
142169
*
143170
* @param string $libraryName
144-
* @return boolean Success or failure
171+
* @return bool
145172
*/
146173
public static function setPdfRendererName($libraryName)
147174
{
148175
if (!in_array($libraryName, self::$pdfRenderers)) {
149176
return false;
150177
}
151-
152178
self::$pdfRendererName = $libraryName;
153179

154180
return true;
@@ -167,7 +193,7 @@ public static function getPdfRendererPath()
167193
* Location of external library to use for rendering PDF files
168194
*
169195
* @param string $libraryBaseDir Directory path to the library's base folder
170-
* @return boolean Success or failure
196+
* @return bool Success or failure
171197
*/
172198
public static function setPdfRendererPath($libraryBaseDir)
173199
{
@@ -178,4 +204,31 @@ public static function setPdfRendererPath($libraryBaseDir)
178204

179205
return true;
180206
}
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+
}
181234
}

0 commit comments

Comments
 (0)