Skip to content

Commit 51078b7

Browse files
committed
Changes by @Progi1984
1 parent 942f148 commit 51078b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1171
-1037
lines changed

docs/changes/1.x/1.2.0.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
- Word2007 Reader/Writer: Permit book-fold printing by [@potofcoffee](https://github.com/potofcoffee) in [#2225](https://github.com/PHPOffice/PHPWord/pull/2225) & [#2470](https://github.com/PHPOffice/PHPWord/pull/2470)
1616
- Word2007 Writer : Add PageNumber to TOC by [@jet-desk](https://github.com/jet-desk) in [#1652](https://github.com/PHPOffice/PHPWord/pull/1652) & [#2471](https://github.com/PHPOffice/PHPWord/pull/2471)
1717
- Word2007 Reader/Writer + ODText Reader/Writer : Add Element Formula in by [@Progi1984](https://github.com/Progi1984) in [#2477](https://github.com/PHPOffice/PHPWord/pull/2477)
18+
- Add Support for Various Missing Features in HTML Writer by [@oleibman](https://github.com/oleibman) in [#2475](https://github.com/PHPOffice/PHPWord/pull/2475)
19+
- Fixed addHTML (text-align:right in html is not handled correctly) in [#2467](https://github.com/PHPOffice/PHPWord/pull/2467)
20+
- HTML Writer : Added ability to specify generic fallback font
21+
- HTML Writer : Added ability to specify handling of whitespace
22+
- HTML Writer : Added support for Table Border style, color, and size
23+
- HTML Writer : Added support for empty paragraphs (Word writer permits, browsers generally suppress)
24+
- HTML Writer : Paragraph style should support indentation, line-height, page-break-before
25+
- HTML Writer : Removed margin-top/bottom when spacing is null in Paragraph style
26+
- HTML Writer : Added default paragraph style to all paragraphs, as well as class Normal
27+
- HTML Writer : Use css @page and page declarations for sections
28+
- HTML Writer : Wrap sections in div, with page break before each (except first)
29+
- PDF Writer : Added support for PageBreak
30+
- PDF Writer : Added callback for modifying the HTML
31+
- Added Support for Language, both for document overall and individual text elements
1832

1933
### Bug fixes
2034

@@ -41,4 +55,8 @@
4155
- Bump phpunit/phpunit from 9.6.11 to 9.6.13 by [@dependabot](https://github.com/dependabot) in [#2481](https://github.com/PHPOffice/PHPWord/pull/2481)
4256
- Bump tecnickcom/tcpdf from 6.6.2 to 6.6.5 by [@dependabot](https://github.com/dependabot) in [#2482](https://github.com/PHPOffice/PHPWord/pull/2482)
4357
- Bump phpmd/phpmd from 2.13.0 to 2.14.1 by [@dependabot](https://github.com/dependabot) in [#2483](https://github.com/PHPOffice/PHPWord/pull/2483)
44-
- Bump phpstan/phpstan-phpunit from 1.3.14 to 1.3.15 by [@dependabot](https://github.com/dependabot) in [#2494](https://github.com/PHPOffice/PHPWord/pull/2494)
58+
- Bump phpstan/phpstan-phpunit from 1.3.14 to 1.3.15 by [@dependabot](https://github.com/dependabot) in [#2494](https://github.com/PHPOffice/PHPWord/pull/2494)
59+
60+
61+
### BC Breaks
62+
- Removed dependency `laminas/laminas-escaper`

docs/usage/styles/font.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ Available Font style options:
2424
See ``\PhpOffice\PhpWord\Style\Language`` class for some language codes.
2525
- ``position``. The text position, raised or lowered, in half points
2626
- ``hidden``. Hidden text, *true* or *false*.
27-
`htmlWhiteSpace``. How white space is handled when generating html/pdf. Possible values are *pre-wrap* and *normal* (other css values for white space are accepted, but are not expected to be useful).
28-
- ``htmlGenericFont``. Fallback generic font for html/pdf. Possible values are *sans-serif*, *serif*, and *monospace* (other css values for generic fonts are accepted).
27+
- ``whiteSpace``. How white space is handled when generating html/pdf. Possible values are *pre-wrap* and *normal* (other css values for white space are accepted, but are not expected to be useful).
28+
- ``fallbackFont``. Fallback generic font for html/pdf. Possible values are *sans-serif*, *serif*, and *monospace* (other css values for generic fonts are accepted).

docs/usage/writers.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ $writer->save(__DIR__ . '/sample.html');
1111
```
1212

1313

14-
When generating html/pdf, you can alter the default handling of white space (normal),
15-
and/or supply a fallback generic font as follows:
14+
When generating html/pdf, you can alter the default handling of white space (normal), and/or supply a fallback generic font as follows:
1615

1716
```php
18-
$phpWord->setDefaultHtmlGenericFont('serif');
19-
$phpWord->setDefaultHtmlWhiteSpace('pre-wrap');
17+
$writer = IOFactory::createWriter($oPhpWord, 'HTML');
18+
$writer->setDefaultGenericFont('serif');
19+
$writer->setDefaultWhiteSpace('pre-wrap');
20+
$writer->save(__DIR__ . '/sample.html');
2021
```
2122

2223
## ODText
@@ -39,6 +40,33 @@ $writer = IOFactory::createWriter($oPhpWord, 'PDF');
3940
$writer->save(__DIR__ . '/sample.pdf');
4041
```
4142

43+
To generate a PDF, the PhpWord object passes through HTML before generating the PDF.
44+
This HTML can be modified using a callback.
45+
46+
``` php
47+
<?php
48+
49+
$writer = IOFactory::createWriter($oPhpWord, 'PDF');
50+
$writer->setEditCallback('cbEditHTML');
51+
$writer->save(__DIR__ . '/sample.pdf');
52+
53+
/**
54+
* Add a meta tag generator
55+
*/
56+
function cbEditHTML(string $inputHTML): string
57+
{
58+
$beforeBody = '<meta name="generator" content="PHPWord" />';
59+
$needle = '</head>';
60+
61+
$pos = strpos($inputHTML, $needle);
62+
if ($pos !== false) {
63+
$inputHTML = (string) substr_replace($inputHTML, "$beforeBody\n$needle", $pos, strlen($needle));
64+
}
65+
66+
return $inputHTML;
67+
}
68+
```
69+
4270
### Options
4371

4472
You can define options like :

phpstan-baseline.neon

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,11 @@ parameters:
18501850
count: 1
18511851
path: tests/PhpWordTests/Writer/HTML/ElementTest.php
18521852

1853+
-
1854+
message: "#^Parameter \\#2 \\$libraryBaseDir of static method PhpOffice\\\\PhpWord\\\\Settings\\:\\:setPdfRenderer\\(\\) expects string, string\\|false given\\.$#"
1855+
count: 3
1856+
path: tests/PhpWordTests/Writer/HTML/Element/PageBreakTest.php
1857+
18531858
-
18541859
message: "#^Method PhpOffice\\\\PhpWordTests\\\\Writer\\\\ODText\\\\Style\\\\FontTest\\:\\:providerAllNamedColors\\(\\) has no return type specified\\.$#"
18551860
count: 1
@@ -1905,6 +1910,11 @@ parameters:
19051910
count: 1
19061911
path: tests/PhpWordTests/Writer/PDF/MPDFTest.php
19071912

1913+
-
1914+
message: "#^Parameter \\#2 \\$libraryBaseDir of static method PhpOffice\\\\PhpWord\\\\Settings\\:\\:setPdfRenderer\\(\\) expects string, string\\|false given\\.$#"
1915+
count: 1
1916+
path: tests/PhpWordTests/Writer/PDF/MPDFTest.php
1917+
19081918
-
19091919
message: "#^Parameter \\#2 \\$libraryBaseDir of static method PhpOffice\\\\PhpWord\\\\Settings\\:\\:setPdfRenderer\\(\\) expects string, string\\|false given\\.$#"
19101920
count: 2
@@ -1915,6 +1925,11 @@ parameters:
19151925
count: 1
19161926
path: tests/PhpWordTests/Writer/PDF/TCPDFTest.php
19171927

1928+
-
1929+
message: "#^Parameter \\#2 \\$libraryBaseDir of static method PhpOffice\\\\PhpWord\\\\Settings\\:\\:setPdfRenderer\\(\\) expects string, string\\|false given\\.$#"
1930+
count: 1
1931+
path: tests/PhpWordTests/Writer/PDFTest.php
1932+
19181933
-
19191934
message: "#^Method PhpOffice\\\\PhpWordTests\\\\Writer\\\\RTF\\\\ElementTest\\:\\:removeCr\\(\\) has no return type specified\\.$#"
19201935
count: 1

samples/Sample_52_RTLDefault.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
use PhpOffice\PhpWord\PhpWord;
66
use PhpOffice\PhpWord\Settings;
77
use PhpOffice\PhpWord\Shared\Html as SharedHtml;
8-
use PhpOffice\PhpWord\Style;
98

109
// Suggested by issue 2427.
1110
echo date('H:i:s'), ' Create new PhpWord object', EOL;
1211
$phpWord = new PhpWord();
13-
Style::setDefaultRtl(true);
12+
Settings::setDefaultRtl(true);
1413
$phpWord->setDefaultFontName('DejaVu Sans'); // for good rendition of PDF
1514
$rendererName = Settings::PDF_RENDERER_MPDF;
1615
$rendererLibraryPath = $vendorDirPath . '/mpdf/mpdf';
@@ -31,4 +30,4 @@
3130
if (!CLI) {
3231
include_once 'Sample_Footer.php';
3332
}
34-
Style::setDefaultRtl(null);
33+
Settings::setDefaultRtl(false);

src/PhpWord/Metadata/Settings.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class Settings
114114
/**
115115
* Theme Font Languages.
116116
*
117-
* @var Language
117+
* @var ?Language
118118
*/
119119
private $themeFontLang;
120120

@@ -369,22 +369,20 @@ public function setMirrorMargins($mirrorMargins): void
369369

370370
/**
371371
* Returns the Language.
372-
*
373-
* @return Language
374372
*/
375-
public function getThemeFontLang()
373+
public function getThemeFontLang(): ?Language
376374
{
377375
return $this->themeFontLang;
378376
}
379377

380378
/**
381-
* sets the Language for this document.
382-
*
383-
* @param Language $themeFontLang
379+
* Sets the Language for this document.
384380
*/
385-
public function setThemeFontLang($themeFontLang): void
381+
public function setThemeFontLang(Language $themeFontLang): self
386382
{
387383
$this->themeFontLang = $themeFontLang;
384+
385+
return $this;
388386
}
389387

390388
/**

src/PhpWord/PhpWord.php

Lines changed: 49 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public function __construct()
7777
// Reset Media and styles
7878
Media::resetElements();
7979
Style::resetStyles();
80+
Settings::setDefaultRtl(null);
8081

8182
// Collection
8283
$collections = ['Bookmarks', 'Titles', 'Footnotes', 'Endnotes', 'Charts', 'Comments'];
@@ -256,68 +257,6 @@ public function setDefaultFontName($fontName): void
256257
Settings::setDefaultFontName($fontName);
257258
}
258259

259-
/**
260-
* Default generic name for default font for html.
261-
*
262-
* @var string
263-
*/
264-
private $defaultHtmlGenericFont = '';
265-
266-
/**
267-
* Get generic name for default font for html.
268-
*
269-
* @return string
270-
*/
271-
public function getDefaultHtmlGenericFont()
272-
{
273-
return $this->defaultHtmlGenericFont;
274-
}
275-
276-
/**
277-
* Set generic name for default font for html.
278-
*
279-
* @param string $value
280-
*
281-
* @return bool
282-
*/
283-
public function setDefaultHtmlGenericFont($value)
284-
{
285-
$this->defaultHtmlGenericFont = \PhpOffice\PhpWord\Style\Font::validateGenericFont($value);
286-
287-
return '' !== $this->defaultHtmlGenericFont;
288-
}
289-
290-
/**
291-
* Default white space style for html.
292-
*
293-
* @var string
294-
*/
295-
private $defaultHtmlWhiteSpace = '';
296-
297-
/**
298-
* Get default white space style for html.
299-
*
300-
* @return string
301-
*/
302-
public function getDefaultHtmlWhiteSpace()
303-
{
304-
return $this->defaultHtmlWhiteSpace;
305-
}
306-
307-
/**
308-
* Set default white space style for html.
309-
*
310-
* @param string $value
311-
*
312-
* @return bool
313-
*/
314-
public function setDefaultHtmlWhiteSpace($value)
315-
{
316-
$this->defaultHtmlWhiteSpace = \PhpOffice\PhpWord\Style\Font::validateWhiteSpace($value);
317-
318-
return '' !== $this->defaultHtmlWhiteSpace;
319-
}
320-
321260
/**
322261
* Get default font size.
323262
*
@@ -387,4 +326,52 @@ public function save($filename, $format = 'Word2007', $download = false)
387326

388327
return true;
389328
}
329+
330+
/**
331+
* Create new section.
332+
*
333+
* @deprecated 0.10.0
334+
*
335+
* @param array $settings
336+
*
337+
* @return \PhpOffice\PhpWord\Element\Section
338+
*
339+
* @codeCoverageIgnore
340+
*/
341+
public function createSection($settings = null)
342+
{
343+
return $this->addSection($settings);
344+
}
345+
346+
/**
347+
* Get document properties object.
348+
*
349+
* @deprecated 0.12.0
350+
*
351+
* @return \PhpOffice\PhpWord\Metadata\DocInfo
352+
*
353+
* @codeCoverageIgnore
354+
*/
355+
public function getDocumentProperties()
356+
{
357+
return $this->getDocInfo();
358+
}
359+
360+
/**
361+
* Set document properties object.
362+
*
363+
* @deprecated 0.12.0
364+
*
365+
* @param \PhpOffice\PhpWord\Metadata\DocInfo $documentProperties
366+
*
367+
* @return self
368+
*
369+
* @codeCoverageIgnore
370+
*/
371+
public function setDocumentProperties($documentProperties)
372+
{
373+
$this->metadata['Document'] = $documentProperties;
374+
375+
return $this;
376+
}
390377
}

src/PhpWord/Settings.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ class Settings
131131
*/
132132
private static $defaultPaper = self::DEFAULT_PAPER;
133133

134+
/**
135+
* Is RTL by default ?
136+
*
137+
* @var ?bool
138+
*/
139+
private static $defaultRtl;
140+
134141
/**
135142
* The user defined temporary directory.
136143
*
@@ -387,6 +394,16 @@ public static function setDefaultFontSize($value): bool
387394
return false;
388395
}
389396

397+
public static function setDefaultRtl(?bool $defaultRtl): void
398+
{
399+
self::$defaultRtl = $defaultRtl;
400+
}
401+
402+
public static function isDefaultRtl(): ?bool
403+
{
404+
return self::$defaultRtl;
405+
}
406+
390407
/**
391408
* Load setting from phpword.yml or phpword.yml.dist.
392409
*/

src/PhpWord/Shared/Handler.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)