This commit is contained in:
wyn
2026-05-26 18:01:32 +08:00
parent fa878334cd
commit 7a3a1ed8c9
651 changed files with 4599 additions and 32312 deletions

View File

@@ -1,6 +1,6 @@
PHPWord, a pure PHP library for reading and writing word processing documents.
Copyright (c) 2010-2016 PHPWord.
Copyright (c) 2010-2025 PHPWord.
PHPWord is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3 as published by

View File

@@ -1,11 +1,11 @@
# ![PHPWord](https://rawgit.com/PHPOffice/PHPWord/develop/docs/images/phpword.svg "PHPWord")
[![Latest Stable Version](https://poser.pugx.org/phpoffice/phpword/v/stable.png)](https://packagist.org/packages/phpoffice/phpword)
[![Latest Stable Version](https://poser.pugx.org/phpoffice/phpword/v)](https://packagist.org/packages/phpoffice/phpword)
[![Coverage Status](https://coveralls.io/repos/github/PHPOffice/PHPWord/badge.svg?branch=master)](https://coveralls.io/github/PHPOffice/PHPWord?branch=master)
[![Total Downloads](https://poser.pugx.org/phpoffice/phpword/downloads.png)](https://packagist.org/packages/phpoffice/phpword)
[![License](https://poser.pugx.org/phpoffice/phpword/license.png)](https://packagist.org/packages/phpoffice/phpword)
[![CI](https://github.com/PHPOffice/PHPWord/actions/workflows/ci.yml/badge.svg)](https://github.com/PHPOffice/PHPWord/actions/workflows/ci.yml)
[![Join the chat at https://gitter.im/PHPOffice/PHPWord](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](https://gitter.im/PHPOffice/PHPWord)
[![Total Downloads](https://poser.pugx.org/phpoffice/phpword/downloads)](https://packagist.org/packages/phpoffice/phpword)
[![License](https://poser.pugx.org/phpoffice/phpword/license)](https://packagist.org/packages/phpoffice/phpword)
Branch Master : [![PHPWord](https://github.com/PHPOffice/PHPWord/actions/workflows/php.yml/badge.svg?branch=master)](https://github.com/PHPOffice/PHPWord/actions/workflows/php.yml)
PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF), HTML, and PDF.
@@ -81,7 +81,6 @@ The following is a basic usage example of the PHPWord library.
```php
<?php
require_once 'bootstrap.php';
// Creating the new document...
$phpWord = new \PhpOffice\PhpWord\PhpWord();

View File

@@ -1,28 +0,0 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. test bootstrap
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
$vendorDirPath = realpath(__DIR__ . '/vendor');
if (file_exists($vendorDirPath . '/autoload.php')) {
require $vendorDirPath . '/autoload.php';
} else {
throw new Exception(
sprintf(
'Could not find file \'%s\'. It is generated by Composer. Use \'install --prefer-source\' or \'update --prefer-source\' Composer commands to move forward.',
$vendorDirPath . '/autoload.php'
)
);
}

View File

@@ -8,7 +8,7 @@
],
"homepage": "https://phpoffice.github.io/PHPWord/",
"type": "library",
"license": "LGPL-3.0",
"license": "LGPL-3.0-only",
"authors": [
{
"name": "Mark Baker"
@@ -36,20 +36,67 @@
],
"scripts": {
"test": [
"phpunit --color=always"
"@php vendor/bin/phpunit --color=always"
],
"test-no-coverage": [
"phpunit --color=always --no-coverage"
"@php vendor/bin/phpunit --color=always --no-coverage"
],
"check": [
"php-cs-fixer fix --ansi --dry-run --diff",
"phpcs --report-width=200 --report-summary --report-full samples/ src/ tests/ --ignore=src/PhpWord/Shared/PCLZip --standard=PSR2 -n",
"phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php",
"@php vendor/bin/php-cs-fixer fix --ansi --dry-run --diff",
"@php vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php",
"@test-no-coverage",
"phpstan analyse --ansi"
"@php vendor/bin/phpstan analyse --ansi"
],
"fix": [
"php-cs-fixer fix --ansi"
"@php vendor/bin/php-cs-fixer fix --ansi"
],
"samples": [
"php samples/Sample_01_SimpleText.php",
"php samples/Sample_02_TabStops.php",
"php samples/Sample_03_Sections.php",
"php samples/Sample_04_Textrun.php",
"php samples/Sample_05_Multicolumn.php",
"php samples/Sample_06_Footnote.php",
"php samples/Sample_07_TemplateCloneRow.php",
"php samples/Sample_08_ParagraphPagination.php",
"php samples/Sample_09_Tables.php",
"php samples/Sample_10_EastAsianFontStyle.php",
"php samples/Sample_11_ReadWord97.php",
"php samples/Sample_11_ReadWord2007.php",
"php samples/Sample_12_HeaderFooter.php",
"php samples/Sample_13_Images.php",
"php samples/Sample_14_ListItem.php",
"php samples/Sample_15_Link.php",
"php samples/Sample_16_Object.php",
"php samples/Sample_17_TitleTOC.php",
"php samples/Sample_18_Watermark.php",
"php samples/Sample_19_TextBreak.php",
"php samples/Sample_20_BGColor.php",
"php samples/Sample_21_TableRowRules.php",
"php samples/Sample_22_CheckBox.php",
"php samples/Sample_23_TemplateBlock.php",
"php samples/Sample_24_ReadODText.php",
"php samples/Sample_25_TextBox.php",
"php samples/Sample_26_Html.php",
"php samples/Sample_27_Field.php",
"php samples/Sample_28_ReadRTF.php",
"php samples/Sample_29_Line.php",
"php samples/Sample_30_ReadHTML.php",
"php samples/Sample_31_Shape.php",
"php samples/Sample_32_Chart.php",
"php samples/Sample_33_FormField.php",
"php samples/Sample_34_SDT.php",
"php samples/Sample_35_InternalLink.php",
"php samples/Sample_36_RTL.php",
"php samples/Sample_37_Comments.php",
"php samples/Sample_38_Protection.php",
"php samples/Sample_39_TrackChanges.php",
"php samples/Sample_40_TemplateSetComplexValue.php",
"php samples/Sample_41_TemplateSetChart.php",
"php samples/Sample_42_TemplateSetCheckbox.php",
"php samples/Sample_43_RTLDefault.php",
"php samples/Sample_44_ExtractVariablesFromReaderWord2007.php",
"php samples/Sample_45_Autoloader.php"
]
},
"scripts-descriptions": {
@@ -58,34 +105,28 @@
"check": "Runs PHP CheckStyle and PHP Mess detector",
"fix": "Fixes issues found by PHP-CS"
},
"config": {
"platform": {
"php": "8.0"
}
},
"require": {
"php": "^7.1|^8.0",
"ext-dom": "*",
"ext-gd": "*",
"ext-zip": "*",
"ext-json": "*",
"ext-xml": "*",
"phpoffice/math": "^0.2"
"phpoffice/math": "^0.3"
},
"require-dev": {
"ext-zip": "*",
"ext-gd": "*",
"ext-libxml": "*",
"dompdf/dompdf": "^2.0",
"mpdf/mpdf": "^8.1",
"phpmd/phpmd": "^2.13",
"phpunit/phpunit": ">=7.0",
"tecnickcom/tcpdf": "^6.5",
"symfony/process": "^4.4 || ^5.0",
"dompdf/dompdf": "^2.0 || ^3.0",
"friendsofphp/php-cs-fixer": "^3.3",
"phpstan/phpstan-phpunit": "@stable"
"mpdf/mpdf": "^7.0 || ^8.0",
"phpmd/phpmd": "^2.13",
"phpstan/phpstan": "^0.12.88 || ^1.0.0",
"phpstan/phpstan-phpunit": "^1.0 || ^2.0",
"phpunit/phpunit": ">=7.0",
"symfony/process": "^4.4 || ^5.0",
"tecnickcom/tcpdf": "^6.5"
},
"suggest": {
"ext-zip": "Allows writing OOXML and ODF",
"ext-gd2": "Allows adding images",
"ext-xmlwriter": "Allows writing OOXML and ODF",
"ext-xsl": "Allows applying XSL style sheet to headers, to main document part, and to footers of an OOXML template",
"dompdf/dompdf": "Allows writing PDF"

View File

@@ -63,6 +63,7 @@ nav:
- OLE Object: 'usage/elements/oleobject.md'
- Page Break: 'usage/elements/pagebreak.md'
- Preserve Text: 'usage/elements/preservetext.md'
- Ruby: 'usage/elements/ruby.md'
- Text: 'usage/elements/text.md'
- TextBox: 'usage/elements/textbox.md'
- Text Break: 'usage/elements/textbreak.md'
@@ -87,7 +88,9 @@ nav:
- Credits: 'credits.md'
- Releases:
- '1.x':
- '1.3.0 (WIP)': 'changes/1.x/1.3.0.md'
- '1.5.0 (WIP)': 'changes/1.x/1.5.0.md'
- '1.4.0': 'changes/1.x/1.4.0.md'
- '1.3.0': 'changes/1.x/1.3.0.md'
- '1.2.0': 'changes/1.x/1.2.0.md'
- '1.1.0': 'changes/1.x/1.1.0.md'
- '1.0.0': 'changes/1.x/1.0.0.md'

View File

@@ -375,11 +375,6 @@ parameters:
count: 1
path: src/PhpWord/Shared/Drawing.php
-
message: "#^Binary operation \"\\*\" between string and 50 results in an error\\.$#"
count: 1
path: src/PhpWord/Shared/Html.php
-
message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#"
count: 1
@@ -435,6 +430,11 @@ parameters:
count: 1
path: src/PhpWord/Shared/Html.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Shared\\\\Html\\:\\:parseRuby\\(\\) has no return type specified\\.$#"
count: 1
path: src/PhpWord/Shared/Html.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Shared\\\\Html\\:\\:parseStyleDeclarations\\(\\) has no return type specified\\.$#"
count: 1
@@ -447,7 +447,7 @@ parameters:
-
message: "#^Parameter \\#1 \\$attribute of static method PhpOffice\\\\PhpWord\\\\Shared\\\\Html\\:\\:parseStyle\\(\\) expects DOMAttr, DOMNode given\\.$#"
count: 1
count: 3
path: src/PhpWord/Shared/Html.php
-
@@ -685,11 +685,6 @@ parameters:
count: 1
path: src/PhpWord/Style/Cell.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Cell\\:\\:\\$shading is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Cell.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Style\\\\Chart\\:\\:getMajorTickPosition\\(\\) has no return type specified\\.$#"
count: 1
@@ -760,41 +755,6 @@ parameters:
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Font\\:\\:\\$allCaps is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Font\\:\\:\\$doubleStrikethrough is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Font\\:\\:\\$lang is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Font\\:\\:\\$paragraph is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Font\\:\\:\\$shading is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Font\\:\\:\\$smallCaps is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Font\\:\\:\\$strikethrough is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Font.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Line\\:\\:\\$weight \\(int\\) does not accept float\\|int\\|null\\.$#"
count: 1
@@ -815,21 +775,6 @@ parameters:
count: 1
path: src/PhpWord/Style/Paragraph.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Paragraph\\:\\:\\$indentation is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Paragraph.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Paragraph\\:\\:\\$shading is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Paragraph.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Paragraph\\:\\:\\$spacing is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Paragraph.php
-
message: "#^Result of && is always false\\.$#"
count: 1
@@ -840,36 +785,6 @@ parameters:
count: 1
path: src/PhpWord/Style/Section.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Section\\:\\:\\$lineNumbering is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Section.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Shape\\:\\:\\$extrusion is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Shape.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Shape\\:\\:\\$fill is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Shape.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Shape\\:\\:\\$frame is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Shape.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Shape\\:\\:\\$outline is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Shape.php
-
message: "#^Property PhpOffice\\\\PhpWord\\\\Style\\\\Shape\\:\\:\\$shadow is never written, only read\\.$#"
count: 1
path: src/PhpWord/Style/Shape.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Style\\\\TOC\\:\\:setTabLeader\\(\\) should return PhpOffice\\\\PhpWord\\\\Style\\\\TOC but returns PhpOffice\\\\PhpWord\\\\Style\\\\Tab\\.$#"
count: 1
@@ -1120,11 +1035,6 @@ parameters:
count: 1
path: src/PhpWord/Writer/AbstractWriter.php
-
message: "#^PHPDoc tag @param has invalid value \\(\\\\PhpOffice\\\\PhpWord\\\\PhpWord\\)\\: Unexpected token \"\\\\n \\*\", expected variable at offset 78$#"
count: 1
path: src/PhpWord/Writer/AbstractWriter.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\HTML\\\\Element\\\\AbstractElement\\:\\:write\\(\\) has no return type specified\\.$#"
count: 1
@@ -1146,14 +1056,14 @@ parameters:
path: src/PhpWord/Writer/ODText/Element/Table.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\Text\\:\\:replacetabs\\(\\) has parameter \\$text with no type specified\\.$#"
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\AbstractElement\\:\\:replaceTabs\\(\\) has parameter \\$text with no type specified\\.$#"
count: 1
path: src/PhpWord/Writer/ODText/Element/Text.php
path: src/PhpWord/Writer/ODText/Element/AbstractElement.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\Text\\:\\:replacetabs\\(\\) has parameter \\$xmlWriter with no type specified\\.$#"
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\AbstractElement\\:\\:replaceTabs\\(\\) has parameter \\$xmlWriter with no type specified\\.$#"
count: 1
path: src/PhpWord/Writer/ODText/Element/Text.php
path: src/PhpWord/Writer/ODText/Element/AbstractElement.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\Text\\:\\:writeChangeInsertion\\(\\) has parameter \\$start with no type specified\\.$#"
@@ -1315,11 +1225,6 @@ parameters:
count: 1
path: src/PhpWord/Writer/RTF/Style/Border.php
-
message: "#^PHPDoc tag @param has invalid value \\(\\\\PhpOffice\\\\PhpWord\\\\PhpWord\\)\\: Unexpected token \"\\\\n \", expected variable at offset 86$#"
count: 1
path: src/PhpWord/Writer/Word2007.php
-
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\Word2007\\\\Element\\\\AbstractElement\\:\\:write\\(\\) has no return type specified\\.$#"
count: 1
@@ -1426,29 +1331,29 @@ parameters:
path: tests/PhpWordTests/AbstractTestReader.php
-
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbeddedTest\\:\\:getBaseUrl\\(\\) has no return type specified\\.$#"
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbedded\\:\\:getBaseUrl\\(\\) has no return type specified\\.$#"
count: 1
path: tests/PhpWordTests/AbstractWebServerEmbeddedTest.php
path: tests/PhpWordTests/AbstractWebServerEmbedded.php
-
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbeddedTest\\:\\:getRemoteBmpImageUrl\\(\\) has no return type specified\\.$#"
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbedded\\:\\:getRemoteBmpImageUrl\\(\\) has no return type specified\\.$#"
count: 1
path: tests/PhpWordTests/AbstractWebServerEmbeddedTest.php
path: tests/PhpWordTests/AbstractWebServerEmbedded.php
-
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbeddedTest\\:\\:getRemoteGifImageUrl\\(\\) has no return type specified\\.$#"
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbedded\\:\\:getRemoteGifImageUrl\\(\\) has no return type specified\\.$#"
count: 1
path: tests/PhpWordTests/AbstractWebServerEmbeddedTest.php
path: tests/PhpWordTests/AbstractWebServerEmbedded.php
-
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbeddedTest\\:\\:getRemoteImageUrl\\(\\) has no return type specified\\.$#"
message: "#^Method PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbedded\\:\\:getRemoteImageUrl\\(\\) has no return type specified\\.$#"
count: 1
path: tests/PhpWordTests/AbstractWebServerEmbeddedTest.php
path: tests/PhpWordTests/AbstractWebServerEmbedded.php
-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbeddedTest\\:\\:\\$httpServer has no type specified\\.$#"
message: "#^Property PhpOffice\\\\PhpWordTests\\\\AbstractWebServerEmbedded\\:\\:\\$httpServer has no type specified\\.$#"
count: 1
path: tests/PhpWordTests/AbstractWebServerEmbeddedTest.php
path: tests/PhpWordTests/AbstractWebServerEmbedded.php
-
message: "#^Parameter \\#1 \\$width of class PhpOffice\\\\PhpWord\\\\Element\\\\Cell constructor expects int\\|null, string given\\.$#"
@@ -1789,6 +1694,11 @@ parameters:
message: "#^Cannot access property \\$length on DOMNodeList\\<DOMNode\\>\\|false\\.$#"
count: 9
path: tests/PhpWordTests/Writer/HTML/ElementTest.php
-
message: "#^Cannot access property \\$length on DOMNodeList\\<DOMNode\\>\\|false\\.$#"
count: 2
path: tests/PhpWordTests/Writer/HTML/Element/RubyTest.php
-
message: "#^Cannot call method item\\(\\) on DOMNodeList\\<DOMNode\\>\\|false\\.$#"

View File

@@ -14,6 +14,7 @@ outputEscapingEnabled = false
defaultFontName = Arial
defaultFontSize = 10
defaultFontColor = 000000
[Paper]

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -21,6 +22,7 @@ namespace PhpOffice\PhpWord\Collection;
* Collection abstract class.
*
* @since 0.10.0
*
* @template T
*/
abstract class AbstractCollection

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -23,6 +24,7 @@ use PhpOffice\PhpWord\Element\Bookmark;
* Bookmarks collection.
*
* @since 0.12.0
*
* @extends AbstractCollection<Bookmark>
*/
class Bookmarks extends AbstractCollection

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -23,6 +24,7 @@ use PhpOffice\PhpWord\Element\Chart;
* Charts collection.
*
* @since 0.12.0
*
* @extends AbstractCollection<Chart>
*/
class Charts extends AbstractCollection

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -23,6 +24,7 @@ use PhpOffice\PhpWord\Element\Comment;
* Comments collection.
*
* @since 0.12.0
*
* @extends AbstractCollection<Comment>
*/
class Comments extends AbstractCollection

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -23,6 +24,7 @@ use PhpOffice\PhpWord\Element\Endnote;
* Endnotes collection.
*
* @since 0.10.0
*
* @extends AbstractCollection<Endnote>
*/
class Endnotes extends AbstractCollection

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -23,6 +24,7 @@ use PhpOffice\PhpWord\Element\Footnote;
* Footnotes collection.
*
* @since 0.10.0
*
* @extends AbstractCollection<Footnote>
*/
class Footnotes extends AbstractCollection

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -23,6 +24,7 @@ use PhpOffice\PhpWord\Element\Title;
* Titles collection.
*
* @since 0.10.0
*
* @extends AbstractCollection<Title>
*/
class Titles extends AbstractCollection

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -49,6 +50,7 @@ use ReflectionClass;
* @method FormField addFormField(string $type, mixed $fStyle = null, mixed $pStyle = null)
* @method SDT addSDT(string $type)
* @method Formula addFormula(Math $math)
* @method Ruby addRuby(TextRun $baseText, TextRun $rubyText, \PhpOffice\PhpWord\ComplexType\RubyProperties $properties)
* @method \PhpOffice\PhpWord\Element\OLEObject addObject(string $source, mixed $style = null) deprecated, use addOLEObject instead
*
* @since 0.10.0
@@ -58,7 +60,7 @@ abstract class AbstractContainer extends AbstractElement
/**
* Elements collection.
*
* @var \PhpOffice\PhpWord\Element\AbstractElement[]
* @var AbstractElement[]
*/
protected $elements = [];
@@ -80,7 +82,7 @@ abstract class AbstractContainer extends AbstractElement
* @param mixed $function
* @param mixed $args
*
* @return \PhpOffice\PhpWord\Element\AbstractElement
* @return AbstractElement
*/
public function __call($function, $args)
{
@@ -90,7 +92,7 @@ abstract class AbstractContainer extends AbstractElement
'Footnote', 'Endnote', 'CheckBox', 'TextBox', 'Field',
'Line', 'Shape', 'Title', 'TOC', 'PageBreak',
'Chart', 'FormField', 'SDT', 'Comment',
'Formula',
'Formula', 'Ruby',
];
$functions = [];
foreach ($elements as $element) {
@@ -130,7 +132,7 @@ abstract class AbstractContainer extends AbstractElement
*
* @param string $elementName
*
* @return \PhpOffice\PhpWord\Element\AbstractElement
* @return AbstractElement
*/
protected function addElement($elementName)
{
@@ -149,7 +151,7 @@ abstract class AbstractContainer extends AbstractElement
$elementArgs = $args;
array_shift($elementArgs); // Shift the $elementName off the beginning of array
/** @var \PhpOffice\PhpWord\Element\AbstractElement $element Type hint */
/** @var AbstractElement $element Type hint */
$element = $reflection->newInstanceArgs($elementArgs);
// Set parent container
@@ -165,7 +167,7 @@ abstract class AbstractContainer extends AbstractElement
/**
* Get all elements.
*
* @return \PhpOffice\PhpWord\Element\AbstractElement[]
* @return AbstractElement[]
*/
public function getElements()
{
@@ -177,7 +179,7 @@ abstract class AbstractContainer extends AbstractElement
*
* @param int $index
*
* @return null|\PhpOffice\PhpWord\Element\AbstractElement
* @return null|AbstractElement
*/
public function getElement($index)
{
@@ -191,13 +193,13 @@ abstract class AbstractContainer extends AbstractElement
/**
* Removes the element at requested index.
*
* @param int|\PhpOffice\PhpWord\Element\AbstractElement $toRemove
* @param AbstractElement|int $toRemove
*/
public function removeElement($toRemove): void
{
if (is_int($toRemove) && array_key_exists($toRemove, $this->elements)) {
unset($this->elements[$toRemove]);
} elseif ($toRemove instanceof \PhpOffice\PhpWord\Element\AbstractElement) {
} elseif ($toRemove instanceof AbstractElement) {
foreach ($this->elements as $key => $element) {
if ($element->getElementId() === $toRemove->getElementId()) {
unset($this->elements[$key]);
@@ -253,7 +255,7 @@ abstract class AbstractContainer extends AbstractElement
'Footnote' => ['Section', 'TextRun', 'Cell', 'ListItemRun'],
'Endnote' => ['Section', 'TextRun', 'Cell'],
'PreserveText' => ['Section', 'Header', 'Footer', 'Cell'],
'Title' => ['Section', 'Cell'],
'Title' => ['Section', 'Cell', 'Header'],
'TOC' => ['Section'],
'PageBreak' => ['Section'],
'Chart' => ['Section', 'Cell'],

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -148,8 +149,6 @@ abstract class AbstractElement
/**
* Get PhpWord.
*
* @return ?PhpWord
*/
public function getPhpWord(): ?PhpWord
{
@@ -256,7 +255,7 @@ abstract class AbstractElement
*/
public function setElementId(): void
{
$this->elementId = substr(md5(mt_rand()), 0, 6);
$this->elementId = substr(md5((string) mt_rand()), 0, 6);
}
/**
@@ -291,8 +290,6 @@ abstract class AbstractElement
/**
* Get comments start.
*
* @return Comments
*/
public function getCommentsRangeStart(): ?Comments
{
@@ -301,8 +298,6 @@ abstract class AbstractElement
/**
* Get comment start.
*
* @return Comment
*/
public function getCommentRangeStart(): ?Comment
{
@@ -339,8 +334,6 @@ abstract class AbstractElement
/**
* Get comments end.
*
* @return Comments
*/
public function getCommentsRangeEnd(): ?Comments
{
@@ -349,8 +342,6 @@ abstract class AbstractElement
/**
* Get comment end.
*
* @return Comment
*/
public function getCommentRangeEnd(): ?Comment
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -39,7 +40,7 @@ class Cell extends AbstractContainer
/**
* Cell style.
*
* @var ?\PhpOffice\PhpWord\Style\Cell
* @var ?CellStyle
*/
private $style;
@@ -47,7 +48,7 @@ class Cell extends AbstractContainer
* Create new instance.
*
* @param null|int $width
* @param array|\PhpOffice\PhpWord\Style\Cell $style
* @param array|CellStyle $style
*/
public function __construct($width = null, $style = null)
{
@@ -58,7 +59,7 @@ class Cell extends AbstractContainer
/**
* Get cell style.
*
* @return ?\PhpOffice\PhpWord\Style\Cell
* @return ?CellStyle
*/
public function getStyle()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -50,7 +51,7 @@ class Chart extends AbstractElement
/**
* Chart style.
*
* @var ?\PhpOffice\PhpWord\Style\Chart
* @var ?ChartStyle
*/
private $style;
@@ -120,7 +121,7 @@ class Chart extends AbstractElement
/**
* Get chart style.
*
* @return ?\PhpOffice\PhpWord\Style\Chart
* @return ?ChartStyle
*/
public function getStyle()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -89,7 +90,7 @@ class Comment extends TrackChange
/**
* Get the element where this comment starts.
*
* @return \PhpOffice\PhpWord\Element\AbstractElement
* @return AbstractElement
*/
public function getStartElement()
{
@@ -108,7 +109,7 @@ class Comment extends TrackChange
/**
* Get the element where this comment ends.
*
* @return \PhpOffice\PhpWord\Element\AbstractElement
* @return AbstractElement
*/
public function getEndElement()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -128,16 +129,16 @@ class Field extends AbstractElement
/**
* Font style.
*
* @var \PhpOffice\PhpWord\Style\Font|string
* @var Font|string
*/
protected $fontStyle;
/**
* Set Font style.
*
* @param array|\PhpOffice\PhpWord\Style\Font|string $style
* @param array|Font|string $style
*
* @return \PhpOffice\PhpWord\Style\Font|string
* @return Font|string
*/
public function setFontStyle($style = null)
{
@@ -158,7 +159,7 @@ class Field extends AbstractElement
/**
* Get Font style.
*
* @return \PhpOffice\PhpWord\Style\Font|string
* @return Font|string
*/
public function getFontStyle()
{
@@ -172,7 +173,7 @@ class Field extends AbstractElement
* @param array $properties
* @param array $options
* @param null|string|TextRun $text
* @param array|\PhpOffice\PhpWord\Style\Font|string $fontStyle
* @param array|Font|string $fontStyle
*/
public function __construct($type = null, $properties = [], $options = [], $text = null, $fontStyle = null)
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -29,7 +30,7 @@ class Footnote extends AbstractContainer
/**
* Paragraph style.
*
* @var null|\PhpOffice\PhpWord\Style\Paragraph|string
* @var null|Paragraph|string
*/
protected $paragraphStyle;
@@ -43,7 +44,7 @@ class Footnote extends AbstractContainer
/**
* Create new instance.
*
* @param array|\PhpOffice\PhpWord\Style\Paragraph|string $paragraphStyle
* @param array|Paragraph|string $paragraphStyle
*/
public function __construct($paragraphStyle = null)
{
@@ -54,7 +55,7 @@ class Footnote extends AbstractContainer
/**
* Get paragraph style.
*
* @return null|\PhpOffice\PhpWord\Style\Paragraph|string
* @return null|Paragraph|string
*/
public function getParagraphStyle()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -27,7 +28,7 @@ class Line extends AbstractElement
/**
* Line style.
*
* @var ?\PhpOffice\PhpWord\Style\Line
* @var ?LineStyle
*/
private $style;
@@ -44,7 +45,7 @@ class Line extends AbstractElement
/**
* Get line style.
*
* @return ?\PhpOffice\PhpWord\Style\Line
* @return ?LineStyle
*/
public function getStyle()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -43,14 +44,14 @@ class Link extends AbstractElement
/**
* Font style.
*
* @var null|\PhpOffice\PhpWord\Style\Font|string
* @var null|Font|string
*/
private $fontStyle;
/**
* Paragraph style.
*
* @var null|\PhpOffice\PhpWord\Style\Paragraph|string
* @var null|Paragraph|string
*/
private $paragraphStyle;
@@ -98,10 +99,8 @@ class Link extends AbstractElement
/**
* Get link text.
*
* @return string
*/
public function getText()
public function getText(): string
{
return $this->text;
}
@@ -109,7 +108,7 @@ class Link extends AbstractElement
/**
* Get Text style.
*
* @return null|\PhpOffice\PhpWord\Style\Font|string
* @return null|Font|string
*/
public function getFontStyle()
{
@@ -119,7 +118,7 @@ class Link extends AbstractElement
/**
* Get Paragraph style.
*
* @return null|\PhpOffice\PhpWord\Style\Paragraph|string
* @return null|Paragraph|string
*/
public function getParagraphStyle()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -28,14 +29,14 @@ class ListItem extends AbstractElement
/**
* Element style.
*
* @var ?\PhpOffice\PhpWord\Style\ListItem
* @var ?ListItemStyle
*/
private $style;
/**
* Text object.
*
* @var \PhpOffice\PhpWord\Element\Text
* @var Text
*/
private $textObject;
@@ -71,7 +72,7 @@ class ListItem extends AbstractElement
/**
* Get style.
*
* @return ?\PhpOffice\PhpWord\Style\ListItem
* @return ?ListItemStyle
*/
public function getStyle()
{
@@ -81,7 +82,7 @@ class ListItem extends AbstractElement
/**
* Get Text object.
*
* @return \PhpOffice\PhpWord\Element\Text
* @return Text
*/
public function getTextObject()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -32,7 +33,7 @@ class ListItemRun extends TextRun
/**
* ListItem Style.
*
* @var ?\PhpOffice\PhpWord\Style\ListItem
* @var ?ListItemStyle
*/
private $style;
@@ -66,7 +67,7 @@ class ListItemRun extends TextRun
/**
* Get ListItem style.
*
* @return ?\PhpOffice\PhpWord\Style\ListItem
* @return ?ListItemStyle
*/
public function getStyle()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -35,7 +36,7 @@ class OLEObject extends AbstractElement
/**
* Image Style.
*
* @var ?\PhpOffice\PhpWord\Style\Image
* @var ?ImageStyle
*/
private $style;
@@ -100,7 +101,7 @@ class OLEObject extends AbstractElement
/**
* Get object style.
*
* @return ?\PhpOffice\PhpWord\Style\Image
* @return ?ImageStyle
*/
public function getStyle()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -36,14 +37,14 @@ class PreserveText extends AbstractElement
/**
* Text style.
*
* @var null|\PhpOffice\PhpWord\Style\Font|string
* @var null|Font|string
*/
private $fontStyle;
/**
* Paragraph style.
*
* @var null|\PhpOffice\PhpWord\Style\Paragraph|string
* @var null|Paragraph|string
*/
private $paragraphStyle;
@@ -69,7 +70,7 @@ class PreserveText extends AbstractElement
/**
* Get Text style.
*
* @return null|\PhpOffice\PhpWord\Style\Font|string
* @return null|Font|string
*/
public function getFontStyle()
{
@@ -79,7 +80,7 @@ class PreserveText extends AbstractElement
/**
* Get Paragraph style.
*
* @return null|\PhpOffice\PhpWord\Style\Paragraph|string
* @return null|Paragraph|string
*/
public function getParagraphStyle()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -36,14 +37,14 @@ class Row extends AbstractElement
/**
* Row style.
*
* @var ?\PhpOffice\PhpWord\Style\Row
* @var ?RowStyle
*/
private $style;
/**
* Row cells.
*
* @var \PhpOffice\PhpWord\Element\Cell[]
* @var Cell[]
*/
private $cells = [];
@@ -65,7 +66,7 @@ class Row extends AbstractElement
* @param int $width
* @param mixed $style
*
* @return \PhpOffice\PhpWord\Element\Cell
* @return Cell
*/
public function addCell($width = null, $style = null)
{
@@ -79,7 +80,7 @@ class Row extends AbstractElement
/**
* Get all cells.
*
* @return \PhpOffice\PhpWord\Element\Cell[]
* @return Cell[]
*/
public function getCells()
{
@@ -89,7 +90,7 @@ class Row extends AbstractElement
/**
* Get row style.
*
* @return ?\PhpOffice\PhpWord\Style\Row
* @return ?RowStyle
*/
public function getStyle()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -31,7 +32,7 @@ class Section extends AbstractContainer
/**
* Section style.
*
* @var ?\PhpOffice\PhpWord\Style\Section
* @var ?SectionStyle
*/
private $style;
@@ -87,7 +88,7 @@ class Section extends AbstractContainer
/**
* Get section style.
*
* @return ?\PhpOffice\PhpWord\Style\Section
* @return ?SectionStyle
*/
public function getStyle()
{
@@ -196,14 +197,14 @@ class Section extends AbstractContainer
*/
private function addHeaderFooter($type = Header::AUTO, $header = true)
{
$containerClass = substr(static::class, 0, strrpos(static::class, '\\')) . '\\' .
$containerClass = substr(static::class, 0, strrpos(static::class, '\\') ?: 0) . '\\' .
($header ? 'Header' : 'Footer');
$collectionArray = $header ? 'headers' : 'footers';
$collection = &$this->$collectionArray;
if (in_array($type, [Header::AUTO, Header::FIRST, Header::EVEN])) {
$index = count($collection);
/** @var \PhpOffice\PhpWord\Element\AbstractContainer $container Type hint */
/** @var AbstractContainer $container Type hint */
$container = new $containerClass($this->sectionId, ++$index, $type);
$container->setPhpWord($this->phpWord);

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -36,7 +37,7 @@ class Shape extends AbstractElement
/**
* Shape style.
*
* @var ?\PhpOffice\PhpWord\Style\Shape
* @var ?ShapeStyle
*/
private $style;
@@ -80,7 +81,7 @@ class Shape extends AbstractElement
/**
* Get shape style.
*
* @return ?\PhpOffice\PhpWord\Style\Shape
* @return ?ShapeStyle
*/
public function getStyle()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -29,14 +30,14 @@ class TOC extends AbstractElement
/**
* TOC style.
*
* @var \PhpOffice\PhpWord\Style\TOC
* @var TOCStyle
*/
private $tocStyle;
/**
* Font style.
*
* @var \PhpOffice\PhpWord\Style\Font|string
* @var Font|string
*/
private $fontStyle;
@@ -94,7 +95,7 @@ class TOC extends AbstractElement
$titles = $this->phpWord->getTitles()->getItems();
foreach ($titles as $i => $title) {
/** @var \PhpOffice\PhpWord\Element\Title $title Type hint */
/** @var Title $title Type hint */
$depth = $title->getDepth();
if ($this->minDepth > $depth) {
unset($titles[$i]);
@@ -110,7 +111,7 @@ class TOC extends AbstractElement
/**
* Get TOC Style.
*
* @return \PhpOffice\PhpWord\Style\TOC
* @return TOCStyle
*/
public function getStyleTOC()
{
@@ -120,7 +121,7 @@ class TOC extends AbstractElement
/**
* Get Font Style.
*
* @return \PhpOffice\PhpWord\Style\Font|string
* @return Font|string
*/
public function getStyleFont()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -27,14 +28,14 @@ class Table extends AbstractElement
/**
* Table style.
*
* @var ?\PhpOffice\PhpWord\Style\Table
* @var ?TableStyle
*/
private $style;
/**
* Table rows.
*
* @var \PhpOffice\PhpWord\Element\Row[]
* @var Row[]
*/
private $rows = [];
@@ -61,7 +62,7 @@ class Table extends AbstractElement
* @param int $height
* @param mixed $style
*
* @return \PhpOffice\PhpWord\Element\Row
* @return Row
*/
public function addRow($height = null, $style = null)
{
@@ -78,7 +79,7 @@ class Table extends AbstractElement
* @param int $width
* @param mixed $style
*
* @return \PhpOffice\PhpWord\Element\Cell
* @return Cell
*/
public function addCell($width = null, $style = null)
{
@@ -92,7 +93,7 @@ class Table extends AbstractElement
/**
* Get all rows.
*
* @return \PhpOffice\PhpWord\Element\Row[]
* @return Row[]
*/
public function getRows()
{
@@ -102,7 +103,7 @@ class Table extends AbstractElement
/**
* Get table style.
*
* @return null|\PhpOffice\PhpWord\Style\Table|string
* @return null|string|TableStyle
*/
public function getStyle()
{
@@ -140,7 +141,7 @@ class Table extends AbstractElement
$rowCount = count($this->rows);
for ($i = 0; $i < $rowCount; ++$i) {
/** @var \PhpOffice\PhpWord\Element\Row $row Type hint */
/** @var Row $row Type hint */
$row = $this->rows[$i];
$cellCount = count($row->getCells());
if ($columnCount < $cellCount) {

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -36,14 +37,14 @@ class Text extends AbstractElement
/**
* Text style.
*
* @var \PhpOffice\PhpWord\Style\Font|string
* @var Font|string
*/
protected $fontStyle;
/**
* Paragraph style.
*
* @var \PhpOffice\PhpWord\Style\Paragraph|string
* @var Paragraph|string
*/
protected $paragraphStyle;
@@ -64,10 +65,10 @@ class Text extends AbstractElement
/**
* Set Text style.
*
* @param array|\PhpOffice\PhpWord\Style\Font|string $style
* @param array|\PhpOffice\PhpWord\Style\Paragraph|string $paragraphStyle
* @param array|Font|string $style
* @param array|Paragraph|string $paragraphStyle
*
* @return \PhpOffice\PhpWord\Style\Font|string
* @return Font|string
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
@@ -90,7 +91,7 @@ class Text extends AbstractElement
/**
* Get Text style.
*
* @return \PhpOffice\PhpWord\Style\Font|string
* @return Font|string
*/
public function getFontStyle()
{
@@ -100,9 +101,9 @@ class Text extends AbstractElement
/**
* Set Paragraph style.
*
* @param array|\PhpOffice\PhpWord\Style\Paragraph|string $style
* @param array|Paragraph|string $style
*
* @return \PhpOffice\PhpWord\Style\Paragraph|string
* @return Paragraph|string
*/
public function setParagraphStyle($style = null)
{
@@ -123,7 +124,7 @@ class Text extends AbstractElement
/**
* Get Paragraph style.
*
* @return \PhpOffice\PhpWord\Style\Paragraph|string
* @return Paragraph|string
*/
public function getParagraphStyle()
{
@@ -146,10 +147,8 @@ class Text extends AbstractElement
/**
* Get Text content.
*
* @return ?string
*/
public function getText()
public function getText(): ?string
{
return $this->text;
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -34,7 +35,7 @@ class TextBox extends AbstractContainer
/**
* TextBox style.
*
* @var ?\PhpOffice\PhpWord\Style\TextBox
* @var ?TextBoxStyle
*/
private $style;
@@ -51,7 +52,7 @@ class TextBox extends AbstractContainer
/**
* Get textbox style.
*
* @return ?\PhpOffice\PhpWord\Style\TextBox
* @return ?TextBoxStyle
*/
public function getStyle()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -28,14 +29,14 @@ class TextBreak extends AbstractElement
/**
* Paragraph style.
*
* @var null|\PhpOffice\PhpWord\Style\Paragraph|string
* @var null|Paragraph|string
*/
private $paragraphStyle;
/**
* Text style.
*
* @var null|\PhpOffice\PhpWord\Style\Font|string
* @var null|Font|string
*/
private $fontStyle;
@@ -61,7 +62,7 @@ class TextBreak extends AbstractElement
* @param mixed $style
* @param mixed $paragraphStyle
*
* @return \PhpOffice\PhpWord\Style\Font|string
* @return Font|string
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
@@ -82,7 +83,7 @@ class TextBreak extends AbstractElement
/**
* Get Text style.
*
* @return null|\PhpOffice\PhpWord\Style\Font|string
* @return null|Font|string
*/
public function getFontStyle()
{
@@ -92,9 +93,9 @@ class TextBreak extends AbstractElement
/**
* Set Paragraph style.
*
* @param array|\PhpOffice\PhpWord\Style\Paragraph|string $style
* @param array|Paragraph|string $style
*
* @return \PhpOffice\PhpWord\Style\Paragraph|string
* @return Paragraph|string
*/
public function setParagraphStyle($style = null)
{
@@ -113,7 +114,7 @@ class TextBreak extends AbstractElement
/**
* Get Paragraph style.
*
* @return null|\PhpOffice\PhpWord\Style\Paragraph|string
* @return null|Paragraph|string
*/
public function getParagraphStyle()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -85,6 +86,9 @@ class TextRun extends AbstractContainer
foreach ($this->getElements() as $element) {
if ($element instanceof Text) {
$outstr .= $element->getText();
} elseif ($element instanceof Ruby) {
$outstr .= $element->getBaseTextRun()->getText() .
' (' . $element->getRubyTextRun()->getText() . ')';
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -35,7 +36,7 @@ abstract class IOFactory
*/
public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
{
if ($name !== 'WriterInterface' && !in_array($name, ['ODText', 'RTF', 'Word2007', 'HTML', 'PDF'], true)) {
if ($name !== 'WriterInterface' && !in_array($name, ['ODText', 'RTF', 'Word2007', 'HTML', 'PDF', 'EPub3'], true)) {
throw new Exception("\"{$name}\" is not a valid writer.");
}
@@ -61,9 +62,9 @@ abstract class IOFactory
*
* @param string $type
* @param string $name
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param PhpWord $phpWord
*
* @return \PhpOffice\PhpWord\Reader\ReaderInterface|\PhpOffice\PhpWord\Writer\WriterInterface
* @return ReaderInterface|WriterInterface
*/
private static function createObject($type, $name, $phpWord = null)
{
@@ -81,11 +82,11 @@ abstract class IOFactory
* @param string $filename The name of the file
* @param string $readerName
*
* @return \PhpOffice\PhpWord\PhpWord $phpWord
* @return PhpWord $phpWord
*/
public static function load($filename, $readerName = 'Word2007')
{
/** @var \PhpOffice\PhpWord\Reader\ReaderInterface $reader */
/** @var ReaderInterface $reader */
$reader = self::createReader($readerName);
return $reader->load($filename);
@@ -100,7 +101,7 @@ abstract class IOFactory
*/
public static function extractVariables(string $filename, string $readerName = 'Word2007'): array
{
/** @var \PhpOffice\PhpWord\Reader\ReaderInterface $reader */
/** @var ReaderInterface $reader */
$reader = self::createReader($readerName);
$document = $reader->load($filename);
$extractedVariables = [];

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -93,14 +94,14 @@ class Settings
/**
* Spelling and Grammatical Checking State.
*
* @var \PhpOffice\PhpWord\ComplexType\ProofState
* @var ProofState
*/
private $proofState;
/**
* Document Editing Restrictions.
*
* @var \PhpOffice\PhpWord\Metadata\Protection
* @var Protection
*/
private $documentProtection;
@@ -266,7 +267,7 @@ class Settings
/**
* Get the Visibility of Annotation Types.
*
* @return \PhpOffice\PhpWord\ComplexType\TrackChangesView
* @return TrackChangesView
*/
public function getRevisionView()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -47,7 +48,7 @@ class PhpWord
/**
* Collection of sections.
*
* @var \PhpOffice\PhpWord\Element\Section[]
* @var Section[]
*/
private $sections = [];
@@ -151,7 +152,7 @@ class PhpWord
/**
* Get document properties object.
*
* @return \PhpOffice\PhpWord\Metadata\DocInfo
* @return Metadata\DocInfo
*/
public function getDocInfo()
{
@@ -161,7 +162,7 @@ class PhpWord
/**
* Get compatibility.
*
* @return \PhpOffice\PhpWord\Metadata\Compatibility
* @return Metadata\Compatibility
*
* @since 0.12.0
*/
@@ -173,7 +174,7 @@ class PhpWord
/**
* Get compatibility.
*
* @return \PhpOffice\PhpWord\Metadata\Settings
* @return Metadata\Settings
*
* @since 0.14.0
*/
@@ -185,7 +186,7 @@ class PhpWord
/**
* Get all sections.
*
* @return \PhpOffice\PhpWord\Element\Section[]
* @return Section[]
*/
public function getSections()
{
@@ -197,7 +198,7 @@ class PhpWord
*
* @param int $index
*
* @return null|\PhpOffice\PhpWord\Element\Section
* @return null|Section
*/
public function getSection($index)
{
@@ -213,7 +214,7 @@ class PhpWord
*
* @param null|array|string $style
*
* @return \PhpOffice\PhpWord\Element\Section
* @return Section
*/
public function addSection($style = null)
{
@@ -256,6 +257,40 @@ class PhpWord
Settings::setDefaultFontName($fontName);
}
/**
* Get default asian font name.
*/
public function getDefaultAsianFontName(): string
{
return Settings::getDefaultAsianFontName();
}
/**
* Set default asian font name.
*
* @param string $fontName
*/
public function setDefaultAsianFontName($fontName): void
{
Settings::setDefaultAsianFontName($fontName);
}
/**
* Set default font color.
*/
public function setDefaultFontColor(string $fontColor): void
{
Settings::setDefaultFontColor($fontColor);
}
/**
* Get default font color.
*/
public function getDefaultFontColor(): string
{
return Settings::getDefaultFontColor();
}
/**
* Get default font size.
*
@@ -281,7 +316,7 @@ class PhpWord
*
* @param array $styles Paragraph style definition
*
* @return \PhpOffice\PhpWord\Style\Paragraph
* @return Style\Paragraph
*/
public function setDefaultParagraphStyle($styles)
{
@@ -333,7 +368,7 @@ class PhpWord
*
* @param array $settings
*
* @return \PhpOffice\PhpWord\Element\Section
* @return Section
*
* @codeCoverageIgnore
*/
@@ -347,7 +382,7 @@ class PhpWord
*
* @deprecated 0.12.0
*
* @return \PhpOffice\PhpWord\Metadata\DocInfo
* @return Metadata\DocInfo
*
* @codeCoverageIgnore
*/
@@ -361,7 +396,7 @@ class PhpWord
*
* @deprecated 0.12.0
*
* @param \PhpOffice\PhpWord\Metadata\DocInfo $documentProperties
* @param Metadata\DocInfo $documentProperties
*
* @return self
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -33,7 +34,7 @@ class HTML extends AbstractReader implements ReaderInterface
*
* @param string $docFile
*
* @return \PhpOffice\PhpWord\PhpWord
* @return PhpWord
*/
public function load($docFile)
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -32,7 +33,7 @@ class ODText extends AbstractReader implements ReaderInterface
*
* @param string $docFile
*
* @return \PhpOffice\PhpWord\PhpWord
* @return PhpWord
*/
public function load($docFile)
{
@@ -58,7 +59,7 @@ class ODText extends AbstractReader implements ReaderInterface
{
$partClass = "PhpOffice\\PhpWord\\Reader\\ODText\\{$partName}";
if (class_exists($partClass)) {
/** @var \PhpOffice\PhpWord\Reader\ODText\AbstractPart $part Type hint */
/** @var ODText\AbstractPart $part Type hint */
$part = new $partClass($docFile, $xmlFile);
$part->setRels($relationships);
$part->read($phpWord);

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -33,7 +34,7 @@ class RTF extends AbstractReader implements ReaderInterface
*
* @param string $docFile
*
* @return \PhpOffice\PhpWord\PhpWord
* @return PhpWord
*/
public function load($docFile)
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -42,7 +43,7 @@ class Document
/**
* PhpWord object.
*
* @var \PhpOffice\PhpWord\PhpWord
* @var PhpWord
*/
private $phpWord;

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -39,7 +40,7 @@ class Word2007 extends AbstractReader implements ReaderInterface
*
* @param string $docFile
*
* @return \PhpOffice\PhpWord\PhpWord
* @return PhpWord
*/
public function load($docFile)
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -21,10 +22,13 @@ use DateTime;
use DOMElement;
use InvalidArgumentException;
use PhpOffice\Math\Reader\OfficeMathML;
use PhpOffice\PhpWord\ComplexType\RubyProperties;
use PhpOffice\PhpWord\ComplexType\TblWidth as TblWidthComplexType;
use PhpOffice\PhpWord\Element\AbstractContainer;
use PhpOffice\PhpWord\Element\AbstractElement;
use PhpOffice\PhpWord\Element\FormField;
use PhpOffice\PhpWord\Element\Ruby;
use PhpOffice\PhpWord\Element\Text;
use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Element\TrackChange;
use PhpOffice\PhpWord\PhpWord;
@@ -183,7 +187,7 @@ abstract class AbstractPart
/**
* Read w:p.
*
* @param \PhpOffice\PhpWord\Element\AbstractContainer $parent
* @param AbstractContainer $parent
* @param string $docPart
*
* @todo Get font style for preserve text
@@ -296,7 +300,8 @@ abstract class AbstractPart
if ($headingDepth !== null) {
$textContent = null;
$nodes = $xmlReader->getElements('w:r|w:hyperlink', $domNode);
if ($nodes->length === 1) {
$hasRubyElement = $xmlReader->elementExists('w:r/w:ruby', $domNode);
if ($nodes->length === 1 && !$hasRubyElement) {
$textContent = htmlspecialchars($xmlReader->getValue('w:t', $nodes->item(0)), ENT_QUOTES, 'UTF-8');
} else {
$textContent = new TextRun($paragraphStyle);
@@ -450,7 +455,7 @@ abstract class AbstractPart
/**
* Read w:r.
*
* @param \PhpOffice\PhpWord\Element\AbstractContainer $parent
* @param AbstractContainer $parent
* @param string $docPart
* @param mixed $paragraphStyle
*
@@ -584,9 +589,47 @@ abstract class AbstractPart
}
} elseif ($node->nodeName == 'w:softHyphen') {
$element = $parent->addText("\u{200c}", $fontStyle, $paragraphStyle);
} elseif ($node->nodeName == 'w:ruby') {
$rubyPropertiesNode = $xmlReader->getElement('w:rubyPr', $node);
$properties = $this->readRubyProperties($xmlReader, $rubyPropertiesNode);
// read base text node
$baseText = new TextRun($paragraphStyle);
$baseTextNode = $xmlReader->getElement('w:rubyBase/w:r', $node);
$this->readRun($xmlReader, $baseTextNode, $baseText, $docPart, $paragraphStyle);
// read the actual ruby text (e.g. furigana in Japanese)
$rubyText = new TextRun($paragraphStyle);
$rubyTextNode = $xmlReader->getElement('w:rt/w:r', $node);
$this->readRun($xmlReader, $rubyTextNode, $rubyText, $docPart, $paragraphStyle);
// add element to parent
$parent->addRuby($baseText, $rubyText, $properties);
}
}
/**
* Read w:rubyPr element.
*
* @param XMLReader $xmlReader reader for XML
* @param DOMElement $domNode w:RubyPr element
*
* @return RubyProperties ruby properties from element
*/
protected function readRubyProperties(XMLReader $xmlReader, DOMElement $domNode): RubyProperties
{
$rubyAlignment = $xmlReader->getElement('w:rubyAlign', $domNode)->getAttribute('w:val');
$rubyHps = $xmlReader->getElement('w:hps', $domNode)->getAttribute('w:val'); // font face
$rubyHpsRaise = $xmlReader->getElement('w:hpsRaise', $domNode)->getAttribute('w:val'); // pts above base text
$rubyHpsBaseText = $xmlReader->getElement('w:hpsBaseText', $domNode)->getAttribute('w:val'); // base text size
$rubyLid = $xmlReader->getElement('w:lid', $domNode)->getAttribute('w:val'); // type of ruby
$properties = new RubyProperties();
$properties->setAlignment($rubyAlignment);
$properties->setFontFaceSize((float) $rubyHps);
$properties->setFontPointsAboveBaseText((float) $rubyHpsRaise);
$properties->setFontSizeForBaseText((float) $rubyHpsBaseText);
$properties->setLanguageId($rubyLid);
return $properties;
}
/**
* Read w:tbl.
*
@@ -661,8 +704,11 @@ abstract class AbstractPart
'alignment' => [self::READ_VALUE, 'w:jc'],
'basedOn' => [self::READ_VALUE, 'w:basedOn'],
'next' => [self::READ_VALUE, 'w:next'],
'indent' => [self::READ_VALUE, 'w:ind', 'w:left'],
'hanging' => [self::READ_VALUE, 'w:ind', 'w:hanging'],
'indentLeft' => [self::READ_VALUE, 'w:ind', 'w:left'],
'indentRight' => [self::READ_VALUE, 'w:ind', 'w:right'],
'indentHanging' => [self::READ_VALUE, 'w:ind', 'w:hanging'],
'indentFirstLine' => [self::READ_VALUE, 'w:ind', 'w:firstLine'],
'indentFirstLineChars' => [self::READ_VALUE, 'w:ind', 'w:firstLineChars'],
'spaceAfter' => [self::READ_VALUE, 'w:spacing', 'w:after'],
'spaceBefore' => [self::READ_VALUE, 'w:spacing', 'w:before'],
'widowControl' => [self::READ_FALSE, 'w:widowControl'],

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -34,7 +35,7 @@ class Document extends AbstractPart
/**
* PhpWord object.
*
* @var \PhpOffice\PhpWord\PhpWord
* @var PhpWord
*/
private $phpWord;

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -46,6 +47,9 @@ class Styles extends AbstractPart
if (array_key_exists('size', $fontDefaultStyle)) {
$phpWord->setDefaultFontSize($fontDefaultStyle['size']);
}
if (array_key_exists('color', $fontDefaultStyle)) {
$phpWord->setDefaultFontColor($fontDefaultStyle['color']);
}
if (array_key_exists('lang', $fontDefaultStyle)) {
$phpWord->getSettings()->setThemeFontLang(new Language($fontDefaultStyle['lang']));
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -29,7 +30,7 @@ class Settings
*/
public const ZIPARCHIVE = 'ZipArchive';
public const PCLZIP = 'PclZip';
public const OLD_LIB = \PhpOffice\PhpWord\Shared\ZipArchive::class; // @deprecated 0.11
public const OLD_LIB = Shared\ZipArchive::class; // @deprecated 0.11
/**
* PDF rendering libraries.
@@ -117,6 +118,20 @@ class Settings
*/
private static $defaultFontName = self::DEFAULT_FONT_NAME;
/**
* Default asian font name.
*
* @var string
*/
private static $defaultAsianFontName = self::DEFAULT_FONT_NAME;
/**
* Default font color.
*
* @var string
*/
private static $defaultFontColor = self::DEFAULT_FONT_COLOR;
/**
* Default font size.
*
@@ -354,6 +369,14 @@ class Settings
return self::$defaultFontName;
}
/**
* Get default font name.
*/
public static function getDefaultAsianFontName(): string
{
return self::$defaultAsianFontName;
}
/**
* Set default font name.
*/
@@ -368,6 +391,39 @@ class Settings
return false;
}
public static function setDefaultAsianFontName(string $value): bool
{
if (trim($value) !== '') {
self::$defaultAsianFontName = $value;
return true;
}
return false;
}
/**
* Get default font color.
*/
public static function getDefaultFontColor(): string
{
return self::$defaultFontColor;
}
/**
* Set default font color.
*/
public static function setDefaultFontColor(string $value): bool
{
if (trim($value) !== '') {
self::$defaultFontColor = $value;
return true;
}
return false;
}
/**
* Get default font size.
*

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -39,10 +40,6 @@ class Css
{
$cssContent = str_replace(["\r", "\n"], '', $this->cssContent);
preg_match_all('/(.+?)\s?\{\s?(.+?)\s?\}/', $cssContent, $cssExtracted);
// Check the number of extracted
if (count($cssExtracted) != 3) {
return;
}
// Check if there are x selectors and x rules
if (count($cssExtracted[1]) != count($cssExtracted[2])) {
return;

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -22,9 +23,11 @@ use DOMDocument;
use DOMNode;
use DOMXPath;
use Exception;
use PhpOffice\PhpWord\ComplexType\RubyProperties;
use PhpOffice\PhpWord\Element\AbstractContainer;
use PhpOffice\PhpWord\Element\Row;
use PhpOffice\PhpWord\Element\Table;
use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\SimpleType\NumberFormat;
@@ -57,7 +60,7 @@ class Html
* Warning: Do not pass user-generated HTML here, as that would allow an attacker to read arbitrary
* files or perform server-side request forgery by passing local file paths or URLs in <img>.
*
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element Where the parts need to be added
* @param AbstractContainer $element Where the parts need to be added
* @param string $html The code to parse
* @param bool $fullHTML If it's a full HTML, no need to add 'body' tag
* @param bool $preserveWhiteSpace If false, the whitespaces between nodes will be removed
@@ -127,21 +130,21 @@ class Html
break;
case 'width':
// tables, cells
$val = $val === 'auto' ? '100%' : $val;
if (false !== strpos($val, '%')) {
// e.g. <table width="100%"> or <td width="50%">
$styles['width'] = (int) $val * 50;
$styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::PERCENT;
} else {
// e.g. <table width="250> where "250" = 250px (always pixels)
$styles['width'] = Converter::pixelToTwip($val);
$styles['width'] = Converter::pixelToTwip(self::convertHtmlSize($val));
$styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::TWIP;
}
break;
case 'cellspacing':
// tables e.g. <table cellspacing="2">, where "2" = 2px (always pixels)
$val = (int) $val . 'px';
$styles['cellSpacing'] = Converter::cssToTwip($val);
$styles['cellSpacing'] = Converter::pixelToTwip(self::convertHtmlSize($val));
break;
case 'bgcolor':
@@ -185,7 +188,7 @@ class Html
* Parse a node and add a corresponding element to the parent element.
*
* @param DOMNode $node node to parse
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element object to add an element corresponding with the node
* @param AbstractContainer $element object to add an element corresponding with the node
* @param array $styles Array with all styles
* @param array $data Array to transport data to a next level in the DOM tree, for example level of listitems
*/
@@ -208,16 +211,16 @@ class Html
// Node mapping table
$nodes = [
// $method $node $element $styles $data $argument1 $argument2
'p' => ['Paragraph', $node, $element, $styles, null, null, null],
'h1' => ['Heading', null, $element, $styles, null, 'Heading1', null],
'h2' => ['Heading', null, $element, $styles, null, 'Heading2', null],
'h3' => ['Heading', null, $element, $styles, null, 'Heading3', null],
'h4' => ['Heading', null, $element, $styles, null, 'Heading4', null],
'h5' => ['Heading', null, $element, $styles, null, 'Heading5', null],
'h6' => ['Heading', null, $element, $styles, null, 'Heading6', null],
'#text' => ['Text', $node, $element, $styles, null, null, null],
'strong' => ['Property', null, null, $styles, null, 'bold', true],
// $method $node $element $styles $data $argument1 $argument2
'p' => ['Paragraph', $node, $element, $styles, null, null, null],
'h1' => ['Heading', $node, $element, $styles, null, 'Heading1', null],
'h2' => ['Heading', $node, $element, $styles, null, 'Heading2', null],
'h3' => ['Heading', $node, $element, $styles, null, 'Heading3', null],
'h4' => ['Heading', $node, $element, $styles, null, 'Heading4', null],
'h5' => ['Heading', $node, $element, $styles, null, 'Heading5', null],
'h6' => ['Heading', $node, $element, $styles, null, 'Heading6', null],
'#text' => ['Text', $node, $element, $styles, null, null, null],
'strong' => ['Property', null, null, $styles, null, 'bold', true],
'b' => ['Property', null, null, $styles, null, 'bold', true],
'em' => ['Property', null, null, $styles, null, 'italic', true],
'i' => ['Property', null, null, $styles, null, 'italic', true],
@@ -238,6 +241,7 @@ class Html
'a' => ['Link', $node, $element, $styles, null, null, null],
'input' => ['Input', $node, $element, $styles, null, null, null],
'hr' => ['HorizRule', $node, $element, $styles, null, null, null],
'ruby' => ['Ruby', $node, $element, $styles, null, null, null],
];
$newElement = null;
@@ -276,7 +280,7 @@ class Html
* Parse child nodes.
*
* @param DOMNode $node
* @param \PhpOffice\PhpWord\Element\AbstractContainer|Row|Table $element
* @param AbstractContainer|Row|Table $element
* @param array $styles
* @param array $data
*/
@@ -298,10 +302,10 @@ class Html
* Parse paragraph node.
*
* @param DOMNode $node
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
* @param AbstractContainer $element
* @param array &$styles
*
* @return \PhpOffice\PhpWord\Element\PageBreak|\PhpOffice\PhpWord\Element\TextRun
* @return \PhpOffice\PhpWord\Element\PageBreak|TextRun
*/
protected static function parseParagraph($node, $element, &$styles)
{
@@ -317,7 +321,7 @@ class Html
* Parse input node.
*
* @param DOMNode $node
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
* @param AbstractContainer $element
* @param array &$styles
*/
protected static function parseInput($node, $element, &$styles): void
@@ -341,28 +345,25 @@ class Html
/**
* Parse heading node.
*
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
* @param array &$styles
* @param string $argument1 Name of heading style
*
* @return \PhpOffice\PhpWord\Element\TextRun
*
* @todo Think of a clever way of defining header styles, now it is only based on the assumption, that
* Heading1 - Heading6 are already defined somewhere
*/
protected static function parseHeading($element, &$styles, $argument1)
protected static function parseHeading(DOMNode $node, AbstractContainer $element, array &$styles, string $argument1): TextRun
{
$styles['paragraph'] = $argument1;
$newElement = $element->addTextRun($styles['paragraph']);
$style = new Paragraph();
$style->setStyleName($argument1);
$style->setStyleByArray(self::parseInlineStyle($node, $styles['paragraph']));
return $newElement;
return $element->addTextRun($style);
}
/**
* Parse text node.
*
* @param DOMNode $node
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
* @param AbstractContainer $element
* @param array &$styles
*/
protected static function parseText($node, $element, &$styles): void
@@ -406,7 +407,7 @@ class Html
* Parse table node.
*
* @param DOMNode $node
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
* @param AbstractContainer $element
* @param array &$styles
*
* @return Table $element
@@ -437,7 +438,7 @@ class Html
* Parse a table row.
*
* @param DOMNode $node
* @param \PhpOffice\PhpWord\Element\Table $element
* @param Table $element
* @param array &$styles
*
* @return Row $element
@@ -460,10 +461,10 @@ class Html
* Parse table cell.
*
* @param DOMNode $node
* @param \PhpOffice\PhpWord\Element\Table $element
* @param Table $element
* @param array &$styles
*
* @return \PhpOffice\PhpWord\Element\Cell|\PhpOffice\PhpWord\Element\TextRun $element
* @return \PhpOffice\PhpWord\Element\Cell|TextRun $element
*/
protected static function parseCell($node, $element, &$styles)
{
@@ -554,7 +555,7 @@ class Html
* Parse list node.
*
* @param DOMNode $node
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
* @param AbstractContainer $element
* @param array &$styles
* @param array &$data
*/
@@ -627,15 +628,15 @@ class Html
return [
'type' => 'hybridMultilevel',
'levels' => [
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 720, 'left' => 720, 'hanging' => 360, 'font' => 'Symbol', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => 'o', 'alignment' => 'left', 'tabPos' => 1440, 'left' => 1440, 'hanging' => 360, 'font' => 'Courier New', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 2160, 'left' => 2160, 'hanging' => 360, 'font' => 'Wingdings', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 2880, 'left' => 2880, 'hanging' => 360, 'font' => 'Symbol', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => 'o', 'alignment' => 'left', 'tabPos' => 3600, 'left' => 3600, 'hanging' => 360, 'font' => 'Courier New', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 4320, 'left' => 4320, 'hanging' => 360, 'font' => 'Wingdings', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 5040, 'left' => 5040, 'hanging' => 360, 'font' => 'Symbol', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => 'o', 'alignment' => 'left', 'tabPos' => 5760, 'left' => 5760, 'hanging' => 360, 'font' => 'Courier New', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 6480, 'left' => 6480, 'hanging' => 360, 'font' => 'Wingdings', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 720, 'left' => 720, 'hanging' => 360, 'font' => 'Symbol', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 1440, 'left' => 1440, 'hanging' => 360, 'font' => 'Courier New', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 2160, 'left' => 2160, 'hanging' => 360, 'font' => 'Wingdings', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 2880, 'left' => 2880, 'hanging' => 360, 'font' => 'Symbol', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 3600, 'left' => 3600, 'hanging' => 360, 'font' => 'Courier New', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 4320, 'left' => 4320, 'hanging' => 360, 'font' => 'Wingdings', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 5040, 'left' => 5040, 'hanging' => 360, 'font' => 'Symbol', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 5760, 'left' => 5760, 'hanging' => 360, 'font' => 'Courier New', 'hint' => 'default'],
['format' => NumberFormat::BULLET, 'text' => '', 'alignment' => 'left', 'tabPos' => 6480, 'left' => 6480, 'hanging' => 360, 'font' => 'Wingdings', 'hint' => 'default'],
],
];
}
@@ -644,7 +645,7 @@ class Html
* Parse list item node.
*
* @param DOMNode $node
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
* @param AbstractContainer $element
* @param array &$styles
* @param array $data
*
@@ -704,6 +705,10 @@ class Html
case 'text-align':
$styles['alignment'] = self::mapAlign($value, $bidi);
break;
case 'ruby-align':
$styles['rubyAlignment'] = self::mapRubyAlign($value);
break;
case 'display':
$styles['hidden'] = $value === 'none' || $value === 'hidden';
@@ -733,7 +738,7 @@ class Html
break;
case 'line-height':
$matches = [];
if ($value === 'normal') {
if ($value === 'normal' || $value === 'inherit') {
$spacingLineRule = \PhpOffice\PhpWord\SimpleType\LineSpacingRule::AUTO;
$spacing = 0;
} elseif (preg_match('/([0-9]+\.?[0-9]*[a-z]+)/', $value, $matches)) {
@@ -803,6 +808,58 @@ class Html
$styles['spaceAfter'] = Converter::cssToTwip($value);
break;
case 'padding':
$valueTop = $valueRight = $valueBottom = $valueLeft = null;
$cValue = preg_replace('# +#', ' ', trim($value));
$paddingArr = explode(' ', $cValue);
$countParams = count($paddingArr);
if ($countParams == 1) {
$valueTop = $valueRight = $valueBottom = $valueLeft = $paddingArr[0];
} elseif ($countParams == 2) {
$valueTop = $valueBottom = $paddingArr[0];
$valueRight = $valueLeft = $paddingArr[1];
} elseif ($countParams == 3) {
$valueTop = $paddingArr[0];
$valueRight = $valueLeft = $paddingArr[1];
$valueBottom = $paddingArr[2];
} elseif ($countParams == 4) {
$valueTop = $paddingArr[0];
$valueRight = $paddingArr[1];
$valueBottom = $paddingArr[2];
$valueLeft = $paddingArr[3];
}
if ($valueTop !== null) {
$styles['paddingTop'] = Converter::cssToTwip($valueTop);
}
if ($valueRight !== null) {
$styles['paddingRight'] = Converter::cssToTwip($valueRight);
}
if ($valueBottom !== null) {
$styles['paddingBottom'] = Converter::cssToTwip($valueBottom);
}
if ($valueLeft !== null) {
$styles['paddingLeft'] = Converter::cssToTwip($valueLeft);
}
break;
case 'padding-top':
$styles['paddingTop'] = Converter::cssToTwip($value);
break;
case 'padding-right':
$styles['paddingRight'] = Converter::cssToTwip($value);
break;
case 'padding-bottom':
$styles['paddingBottom'] = Converter::cssToTwip($value);
break;
case 'padding-left':
$styles['paddingLeft'] = Converter::cssToTwip($value);
break;
case 'border-color':
self::mapBorderColor($styles, $value);
@@ -886,7 +943,7 @@ class Html
* Parse image node.
*
* @param DOMNode $node
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
* @param AbstractContainer $element
*
* @return \PhpOffice\PhpWord\Element\Image
*/
@@ -901,36 +958,12 @@ class Html
break;
case 'width':
$width = $attribute->value;
// pt
if (false !== strpos($width, 'pt')) {
$width = Converter::pointToPixel((float) str_replace('pt', '', $width));
}
// px
if (false !== strpos($width, 'px')) {
$width = str_replace('px', '', $width);
}
$style['width'] = $width;
$style['width'] = self::convertHtmlSize($attribute->value);
$style['unit'] = \PhpOffice\PhpWord\Style\Image::UNIT_PX;
break;
case 'height':
$height = $attribute->value;
// pt
if (false !== strpos($height, 'pt')) {
$height = Converter::pointToPixel((float) str_replace('pt', '', $height));
}
// px
if (false !== strpos($height, 'px')) {
$height = str_replace('px', '', $height);
}
$style['height'] = $height;
$style['height'] = self::convertHtmlSize($attribute->value);
$style['unit'] = \PhpOffice\PhpWord\Style\Image::UNIT_PX;
break;
@@ -970,14 +1003,15 @@ class Html
$match = [];
preg_match('/data:image\/(\w+);base64,(.+)/', $src, $match);
if (!empty($match)) {
$src = $imgFile = $tmpDir . uniqid() . '.' . $match[1];
$src = $imgFile = $tmpDir . uniqid() . '.' . $match[1];
$ifp = fopen($imgFile, 'wb');
$ifp = fopen($imgFile, 'wb');
if ($ifp !== false) {
fwrite($ifp, base64_decode($match[2]));
fclose($ifp);
if ($ifp !== false) {
fwrite($ifp, base64_decode($match[2]));
fclose($ifp);
}
}
}
$src = urldecode($src);
@@ -1073,6 +1107,23 @@ class Html
}
}
/**
* Transforms a HTML/CSS ruby alignment into a \PhpOffice\PhpWord\SimpleType\Jc.
*/
protected static function mapRubyAlign(string $cssRubyAlignment): string
{
switch ($cssRubyAlignment) {
case 'center':
return RubyProperties::ALIGNMENT_CENTER;
case 'start':
return RubyProperties::ALIGNMENT_LEFT;
case 'space-between':
return RubyProperties::ALIGNMENT_DISTRIBUTE_SPACE;
default:
return '';
}
}
/**
* Transforms a HTML/CSS vertical alignment.
*
@@ -1129,7 +1180,7 @@ class Html
/**
* Parse line break.
*
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
* @param AbstractContainer $element
*/
protected static function parseLineBreak($element): void
{
@@ -1140,7 +1191,7 @@ class Html
* Parse link node.
*
* @param DOMNode $node
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
* @param AbstractContainer $element
* @param array $styles
*/
protected static function parseLink($node, $element, &$styles)
@@ -1172,7 +1223,7 @@ class Html
* Note: Word rule is not the same as HTML's <hr> since it does not support width and thus neither alignment.
*
* @param DOMNode $node
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
* @param AbstractContainer $element
*/
protected static function parseHorizRule($node, $element): void
{
@@ -1201,6 +1252,59 @@ class Html
// - repeated text, e.g. underline "_", because of unpredictable line wrapping
}
/**
* Parse ruby node.
*
* @param DOMNode $node
* @param AbstractContainer $element
* @param array $styles
*/
protected static function parseRuby($node, $element, &$styles)
{
$rubyProperties = new RubyProperties();
$baseTextRun = new TextRun($styles['paragraph']);
$rubyTextRun = new TextRun(null);
if ($node->hasAttributes()) {
$langAttr = $node->attributes->getNamedItem('lang');
if ($langAttr !== null) {
$rubyProperties->setLanguageId($langAttr->textContent);
}
$styleAttr = $node->attributes->getNamedItem('style');
if ($styleAttr !== null) {
$styles = self::parseStyle($styleAttr, $styles['paragraph']);
if (isset($styles['rubyAlignment']) && $styles['rubyAlignment'] !== '') {
$rubyProperties->setAlignment($styles['rubyAlignment']);
}
if (isset($styles['size']) && $styles['size'] !== '') {
$rubyProperties->setFontSizeForBaseText($styles['size']);
}
$baseTextRun->setParagraphStyle($styles);
}
}
foreach ($node->childNodes as $child) {
if ($child->nodeName === '#text') {
$content = trim($child->textContent);
if ($content !== '') {
$baseTextRun->addText($content);
}
} elseif ($child->nodeName === 'rt') {
$rubyTextRun->addText(trim($child->textContent));
if ($child->hasAttributes()) {
$styleAttr = $child->attributes->getNamedItem('style');
if ($styleAttr !== null) {
$styles = self::parseStyle($styleAttr, []);
if (isset($styles['size']) && $styles['size'] !== '') {
$rubyProperties->setFontFaceSize($styles['size']);
}
$rubyTextRun->setParagraphStyle($styles);
}
}
}
}
return $element->addRuby($baseTextRun, $rubyTextRun, $rubyProperties);
}
private static function convertRgb(string $rgb): string
{
if (preg_match(self::RGB_REGEXP, $rgb, $matches) === 1) {
@@ -1209,4 +1313,22 @@ class Html
return trim($rgb, '# ');
}
/**
* Transform HTML sizes (pt, px) in pixels.
*/
protected static function convertHtmlSize(string $size): float
{
// pt
if (false !== strpos($size, 'pt')) {
return Converter::pointToPixel((float) str_replace('pt', '', $size));
}
// px
if (false !== strpos($size, 'px')) {
return (float) str_replace('px', '', $size);
}
return (float) $size;
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -17,6 +18,8 @@
namespace PhpOffice\PhpWord\Shared\Microsoft;
use PhpOffice\PhpWord\Exception\Exception;
/**
* Password encoder for microsoft office applications.
*/
@@ -118,8 +121,11 @@ class PasswordEncoder
// Get the single-byte values by iterating through the Unicode characters of the truncated password.
// For each character, if the low byte is not equal to 0, take it. Otherwise, take the high byte.
$passUtf8 = mb_convert_encoding($password, 'UCS-2LE', 'UTF-8');
$byteChars = [];
if (!is_string($passUtf8)) {
throw new Exception('Failed to convert password to UCS-2LE');
}
$byteChars = [];
for ($i = 0; $i < mb_strlen($password); ++$i) {
$byteChars[$i] = ord(substr($passUtf8, $i * 2, 1));

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -17,6 +18,8 @@
namespace PhpOffice\PhpWord\Shared;
use PhpOffice\PhpWord\Exception\Exception;
/**
* Text.
*/
@@ -147,6 +150,9 @@ class Text
if (null !== $value && !self::isUTF8($value)) {
// PHP8.2 : utf8_encode is deprecated, but mb_convert_encoding always usable
$value = (function_exists('mb_convert_encoding')) ? mb_convert_encoding($value, 'UTF-8', 'ISO-8859-1') : utf8_encode($value);
if ($value === false) {
throw new Exception('Unable to convert text to UTF-8');
}
}
return $value;

Some files were not shown because too many files have changed in this diff Show More