Skip to content

Commit 27deefb

Browse files
committed
Changes by @Progi1984
1 parent 942f148 commit 27deefb

File tree

31 files changed

+551
-450
lines changed

31 files changed

+551
-450
lines changed

docs/changes/1.x/1.2.0.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@
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+
- HTML Writer : Added ability to specify generic fallback font
20+
- HTML Writer : Added ability to specify handling of whitespace
21+
- PDF Writer : Added support for PageBreak
22+
- PDF Writer : Added callback for modifying the HTML
23+
<!---
24+
Use css @page and page declarations for sections.
25+
Wrap sections in div, with page break before each (except first).
26+
Support for Language, both for document overall and individual text elements.
27+
Support for Table Border style, color, and size.
28+
Support for empty paragraphs (Word writer permits, browsers generally suppress).
29+
Default paragraph style should apply to all paragraphs, as well as class Normal.
30+
Paragraph style should support line-height.
31+
Paragraph style should support indentation.
32+
Paragraph style should support page-break-before.
33+
Paragraph style should not specify margin-top/bottom when spacing is null.
34+
Fixed Bug while transforming html to word document with addHtml method. #2467 - text-align:right in html is not handled correctly.
35+
-->
1836

1937
### Bug fixes
2038

@@ -41,4 +59,8 @@
4159
- 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)
4260
- 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)
4361
- 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)
62+
- 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)
63+
64+
65+
### BC Breaks
66+
- 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 :

src/PhpWord/PhpWord.php

Lines changed: 48 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -256,68 +256,6 @@ public function setDefaultFontName($fontName): void
256256
Settings::setDefaultFontName($fontName);
257257
}
258258

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-
321259
/**
322260
* Get default font size.
323261
*
@@ -387,4 +325,52 @@ public function save($filename, $format = 'Word2007', $download = false)
387325

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

src/PhpWord/Shared/Validate.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* This file is part of PHPWord - A pure PHP library for reading and writing
4+
* word processing documents.
5+
*
6+
* PHPWord is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPWord
14+
*
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace PhpOffice\PhpWord\Shared;
20+
21+
class Validate
22+
{
23+
public const CSS_WHITESPACE = [
24+
'pre-wrap',
25+
'normal',
26+
'nowrap',
27+
'pre',
28+
'pre-line',
29+
'initial',
30+
'inherit',
31+
];
32+
33+
public const CSS_GENERICFONT = [
34+
'serif',
35+
'sans-serif',
36+
'monospace',
37+
'cursive',
38+
'fantasy',
39+
'system-ui',
40+
'math',
41+
'emoji',
42+
'fangsong',
43+
];
44+
45+
/**
46+
* Validate html css white-space value. It is expected that only pre-wrap and normal (default) are useful.
47+
*
48+
* @param string $value CSS White space
49+
*
50+
* @return string value if valid, empty string if not
51+
*/
52+
public static function validateCSSWhiteSpace(?string $value): string
53+
{
54+
if (in_array($value, self::CSS_WHITESPACE)) {
55+
return $value;
56+
}
57+
58+
return '';
59+
}
60+
61+
/**
62+
* Validate generic font for fallback for html.
63+
*
64+
* @param string $value Generic font name
65+
*
66+
* @return string Value if legitimate, empty string if not
67+
*/
68+
public static function validateCSSGenericFont(?string $value): string
69+
{
70+
if (in_array($value, self::CSS_GENERICFONT)) {
71+
return $value;
72+
}
73+
74+
return '';
75+
}
76+
}

0 commit comments

Comments
 (0)