强制提交

This commit is contained in:
wyn
2026-06-29 10:43:07 +08:00
parent 5860f78f6d
commit 9c8f7cc3b6
220 changed files with 1360 additions and 857 deletions

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

@@ -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

@@ -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.

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.
@@ -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.
@@ -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.
@@ -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.
@@ -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.

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.
@@ -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.

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.

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.
@@ -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.
@@ -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.
@@ -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;

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.
@@ -26,7 +27,7 @@ use PhpOffice\PhpWord\Shared\AbstractEnum;
* Since ISO/IEC-29500:2008 the type must not be used for table alignment.
*
* @since 0.13.0
* @see \PhpOffice\PhpWord\SimpleType\JcTable For table alignment modes available since ISO/IEC-29500:2008.
* @see JcTable For table alignment modes available since ISO/IEC-29500:2008.
* @see http://www.datypic.com/sc/ooxml/t-w_ST_Jc.html
*/
final class Jc extends AbstractEnum

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.
@@ -41,7 +42,7 @@ class Style
* @param string $styleName
* @param AbstractStyle|array $styles
*
* @return \PhpOffice\PhpWord\Style\Paragraph
* @return Paragraph
*/
public static function addParagraphStyle($styleName, $styles)
{
@@ -55,7 +56,7 @@ class Style
* @param AbstractStyle|array $fontStyle
* @param AbstractStyle|array $paragraphStyle
*
* @return \PhpOffice\PhpWord\Style\Font
* @return Font
*/
public static function addFontStyle($styleName, $fontStyle, $paragraphStyle = null)
{
@@ -68,7 +69,7 @@ class Style
* @param string $styleName
* @param AbstractStyle|array $styles
*
* @return \PhpOffice\PhpWord\Style\Font
* @return Font
*/
public static function addLinkStyle($styleName, $styles)
{
@@ -81,7 +82,7 @@ class Style
* @param string $styleName
* @param AbstractStyle|array $styleValues
*
* @return \PhpOffice\PhpWord\Style\Numbering
* @return Numbering
*
* @since 0.10.0
*/
@@ -97,7 +98,7 @@ class Style
* @param AbstractStyle|array $fontStyle
* @param AbstractStyle|array $paragraphStyle
*
* @return \PhpOffice\PhpWord\Style\Font
* @return Font
*/
public static function addTitleStyle($depth, $fontStyle, $paragraphStyle = null)
{
@@ -117,7 +118,7 @@ class Style
* @param array $styleTable
* @param null|array $styleFirstRow
*
* @return \PhpOffice\PhpWord\Style\Table
* @return Table
*/
public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
{
@@ -151,7 +152,7 @@ class Style
*
* @param AbstractStyle|array $styles Paragraph style definition
*
* @return \PhpOffice\PhpWord\Style\Paragraph
* @return Paragraph
*/
public static function setDefaultParagraphStyle($styles)
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -134,7 +135,7 @@ abstract class AbstractStyle
/**
* Return style value of child style object, e.g. `left` from `Indentation` child style of `Paragraph`.
*
* @param \PhpOffice\PhpWord\Style\AbstractStyle $substyleObject
* @param AbstractStyle $substyleObject
* @param string $substyleProperty
*
* @return mixed
@@ -316,16 +317,15 @@ abstract class AbstractStyle
* Set object value.
*
* @param mixed $value
* @param string $styleName
* @param mixed &$style
*
* @return mixed
*/
protected function setObjectVal($value, $styleName, &$style)
protected function setObjectVal($value, string $styleName, &$style)
{
$styleClass = substr(static::class, 0, strrpos(static::class, '\\')) . '\\' . $styleName;
$styleClass = substr(static::class, 0, (int) strrpos(static::class, '\\')) . '\\' . $styleName;
if (is_array($value)) {
/** @var \PhpOffice\PhpWord\Style\AbstractStyle $style Type hint */
/** @var AbstractStyle $style Type hint */
if (!$style instanceof $styleClass) {
$style = new $styleClass();
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -69,10 +70,30 @@ class Cell extends Border
/**
* Vertical align (top, center, both, bottom).
*
* @var string
* @var null|string
*/
private $vAlign;
/**
* @var null|int
*/
private $paddingTop;
/**
* @var null|int
*/
private $paddingBottom;
/**
* @var null|int
*/
private $paddingLeft;
/**
* @var null|int
*/
private $paddingRight;
/**
* Text Direction.
*
@@ -93,14 +114,14 @@ class Cell extends Border
* - restart: Start/restart merged region
* - continue: Continue merged region
*
* @var string
* @var null|string
*/
private $vMerge;
/**
* Shading.
*
* @var \PhpOffice\PhpWord\Style\Shading
* @var Shading
*/
private $shading;
@@ -128,7 +149,7 @@ class Cell extends Border
/**
* Get vertical align.
*
* @return string
* @return null|string
*/
public function getVAlign()
{
@@ -138,12 +159,18 @@ class Cell extends Border
/**
* Set vertical align.
*
* @param string $value
* @param null|string $value
*
* @return self
*/
public function setVAlign($value = null)
{
if ($value === null) {
$this->vAlign = null;
return $this;
}
VerticalJc::validate($value);
$this->vAlign = $this->setEnumVal($value, VerticalJc::values(), $this->vAlign);
@@ -235,7 +262,7 @@ class Cell extends Border
/**
* Get vertical merge (rowspan).
*
* @return string
* @return null|string
*/
public function getVMerge()
{
@@ -245,12 +272,18 @@ class Cell extends Border
/**
* Set vertical merge (rowspan).
*
* @param string $value
* @param null|string $value
*
* @return self
*/
public function setVMerge($value = null)
{
if ($value === null) {
$this->vMerge = null;
return $this;
}
$enum = [self::VMERGE_RESTART, self::VMERGE_CONTINUE];
$this->vMerge = $this->setEnumVal($value, $enum, $this->vMerge);
@@ -260,7 +293,7 @@ class Cell extends Border
/**
* Get shading.
*
* @return \PhpOffice\PhpWord\Style\Shading
* @return Shading
*/
public function getShading()
{
@@ -344,4 +377,84 @@ class Cell extends Border
{
return $this->noWrap;
}
/**
* Get style padding-top.
*/
public function getPaddingTop(): ?int
{
return $this->paddingTop;
}
/**
* Set style padding-top.
*
* @return $this
*/
public function setPaddingTop(int $value): self
{
$this->paddingTop = $value;
return $this;
}
/**
* Get style padding-bottom.
*/
public function getPaddingBottom(): ?int
{
return $this->paddingBottom;
}
/**
* Set style padding-bottom.
*
* @return $this
*/
public function setPaddingBottom(int $value): self
{
$this->paddingBottom = $value;
return $this;
}
/**
* Get style padding-left.
*/
public function getPaddingLeft(): ?int
{
return $this->paddingLeft;
}
/**
* Set style padding-left.
*
* @return $this
*/
public function setPaddingLeft(int $value): self
{
$this->paddingLeft = $value;
return $this;
}
/**
* Get style padding-right.
*/
public function getPaddingRight(): ?int
{
return $this->paddingRight;
}
/**
* Set style padding-right.
*
* @return $this
*/
public function setPaddingRight(int $value): self
{
$this->paddingRight = $value;
return $this;
}
}

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.
@@ -50,7 +51,7 @@ class Table extends Border
/**
* Style for first row.
*
* @var \PhpOffice\PhpWord\Style\Table
* @var Table
*/
private $firstRowStyle;
@@ -113,7 +114,7 @@ class Table extends Border
/**
* Shading.
*
* @var \PhpOffice\PhpWord\Style\Shading
* @var Shading
*/
private $shading;
@@ -145,7 +146,7 @@ class Table extends Border
/**
* Position.
*
* @var ?\PhpOffice\PhpWord\Style\TablePosition
* @var ?TablePosition
*/
private $position;
@@ -208,7 +209,7 @@ class Table extends Border
/**
* Set first row.
*
* @return \PhpOffice\PhpWord\Style\Table
* @return Table
*/
public function getFirstRow()
{
@@ -538,7 +539,7 @@ class Table extends Border
/**
* Get shading.
*
* @return \PhpOffice\PhpWord\Style\Shading
* @return Shading
*/
public function getShading()
{
@@ -706,7 +707,7 @@ class Table extends Border
/**
* Get position.
*
* @return ?\PhpOffice\PhpWord\Style\TablePosition
* @return ?TablePosition
*/
public function getPosition()
{

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

@@ -154,7 +154,7 @@ class TemplateProcessor
* To replace an image: $templateProcessor->zip()->AddFromString("word/media/image1.jpg", file_get_contents($file));<br>
* To read a file: $templateProcessor->zip()->getFromName("word/media/image1.jpg");
*
* @return \PhpOffice\PhpWord\Shared\ZipArchive
* @return ZipArchive
*/
public function zip()
{
@@ -269,7 +269,7 @@ class TemplateProcessor
*/
protected static function ensureUtf8Encoded($subject)
{
return $subject ? Text::toUTF8($subject) : '';
return (null !== $subject) ? Text::toUTF8($subject) : '';
}
/**
@@ -281,7 +281,7 @@ class TemplateProcessor
$objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element\\' . $elementName;
$xmlWriter = new XMLWriter();
/** @var \PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement $elementWriter */
/** @var Writer\Word2007\Element\AbstractElement $elementWriter */
$elementWriter = new $objectClass($xmlWriter, $complexType, true);
$elementWriter->write();
@@ -308,7 +308,7 @@ class TemplateProcessor
$objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element\\' . $elementName;
$xmlWriter = new XMLWriter();
/** @var \PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement $elementWriter */
/** @var Writer\Word2007\Element\AbstractElement $elementWriter */
$elementWriter = new $objectClass($xmlWriter, $complexType, false);
$elementWriter->write();
@@ -362,10 +362,10 @@ class TemplateProcessor
/**
* Set values from a one-dimensional array of "variable => value"-pairs.
*/
public function setValues(array $values): void
public function setValues(array $values, int $limit = self::MAXIMUM_REPLACEMENTS_DEFAULT): void
{
foreach ($values as $macro => $replace) {
$this->setValue($macro, $replace);
$this->setValue($macro, $replace, $limit);
}
}
@@ -406,7 +406,7 @@ class TemplateProcessor
$filename = "charts/chart{$rId}.xml";
// Get the part writer
$writerPart = new \PhpOffice\PhpWord\Writer\Word2007\Part\Chart();
$writerPart = new Writer\Word2007\Part\Chart();
$writerPart->setElement($chart);
// ContentTypes.xml
@@ -499,20 +499,22 @@ class TemplateProcessor
$widthFloat = $heightFloat * $imageRatio;
$matches = [];
preg_match('/\\d([a-z%]+)$/', $height, $matches);
$width = $widthFloat . $matches[1];
$width = $widthFloat . (!empty($matches) ? $matches[1] : 'px');
} elseif ($height === '') { // defined height is empty
$widthFloat = (float) $width;
$heightFloat = $widthFloat / $imageRatio;
$matches = [];
preg_match('/\\d([a-z%]+)$/', $width, $matches);
$height = $heightFloat . $matches[1];
$height = $heightFloat . (!empty($matches) ? $matches[1] : 'px');
} else { // we have defined size, but we need also check it aspect ratio
$widthMatches = [];
preg_match('/\\d([a-z%]+)$/', $width, $widthMatches);
$heightMatches = [];
preg_match('/\\d([a-z%]+)$/', $height, $heightMatches);
// try to fix only if dimensions are same
if ($widthMatches[1] == $heightMatches[1]) {
if (!empty($widthMatches)
&& !empty($heightMatches)
&& $widthMatches[1] == $heightMatches[1]) {
$dimention = $widthMatches[1];
$widthFloat = (float) $width;
$heightFloat = (float) $height;
@@ -1287,7 +1289,7 @@ class TemplateProcessor
* @param int $count
* @param string $xmlBlock
*
* @return string
* @return array<string>
*/
protected function indexClonedVariables($count, $xmlBlock)
{
@@ -1339,7 +1341,7 @@ class TemplateProcessor
* @param string $block New block content
* @param string $blockType XML tag type of block
*
* @return \PhpOffice\PhpWord\TemplateProcessor Fluent interface
* @return TemplateProcessor Fluent interface
*/
public function replaceXmlBlock($macro, $block, $blockType = 'w:p')
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -77,7 +78,7 @@ class HTML extends AbstractWriter implements WriterInterface
foreach ($this->parts as $partName) {
$partClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Part\\' . $partName;
if (class_exists($partClass)) {
/** @var \PhpOffice\PhpWord\Writer\HTML\Part\AbstractPart $part Type hint */
/** @var HTML\Part\AbstractPart $part Type hint */
$part = new $partClass();
$part->setParentWriter($this);
$this->writerParts[strtolower($partName)] = $part;

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -37,7 +38,7 @@ abstract class AbstractElement
/**
* Element.
*
* @var \PhpOffice\PhpWord\Element\AbstractElement
* @var Element
*/
protected $element;

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.
@@ -53,7 +54,7 @@ class Container extends AbstractElement
$elementClass = get_class($element);
$writerClass = str_replace('PhpOffice\\PhpWord\\Element', $this->namespace, $elementClass);
if (class_exists($writerClass)) {
/** @var \PhpOffice\PhpWord\Writer\HTML\Element\AbstractElement $writer Type hint */
/** @var AbstractElement $writer Type hint */
$writer = new $writerClass($this->parentWriter, $element, $withoutP);
$content .= $writer->write();
}

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.

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