强制提交

This commit is contained in:
wyn
2026-06-29 10:36:38 +08:00
147 changed files with 2437 additions and 886 deletions

View File

@@ -57,7 +57,9 @@ nav:
- Writers: 'usage/writers.md'
- Credits: 'credits.md'
- Releases:
- '0.1.0 (WIP)': 'changes/0.1.0.md'
- '0.3.0 (WIP)': 'changes/0.3.0.md'
- '0.2.0': 'changes/0.2.0.md'
- '0.1.0': 'changes/0.1.0.md'
- Developers:
- 'Coveralls': 'https://coveralls.io/github/PHPOffice/Math'
- 'Code Coverage': 'coverage/index.html'

View File

@@ -7,6 +7,7 @@ namespace Tests\PhpOffice\Math\Reader;
use PhpOffice\Math\Element;
use PhpOffice\Math\Exception\InvalidInputException;
use PhpOffice\Math\Exception\NotImplementedException;
use PhpOffice\Math\Exception\SecurityException;
use PhpOffice\Math\Math;
use PhpOffice\Math\Reader\MathML;
use PHPUnit\Framework\TestCase;
@@ -294,4 +295,15 @@ class MathMLTest extends TestCase
$reader = new MathML();
$math = $reader->read($content);
}
public function testReadSecurity(): void
{
$this->expectException(SecurityException::class);
$this->expectExceptionMessage('Detected use of ENTITY in XML, loading aborted to prevent XXE/XEE attacks');
$content = '<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE x SYSTEM "php://filter/convert.base64-decode/zlib.inflate/resource=data:,7Ztdb9owFIbv%2bRVZJ9armNjOZ2k7QUaL%2bRYO2nqFUnBFNQaMptP272cnNFuTsBbSskg1iATZzvGxn/ccX3A4fdfoecS7UsrK1A98hV5Rr9FVjlaz1UmlcnM7D9i6MlkufrB1AK79O2bqKltMllMWt96KL6ADwci7sJ4Yu0vr9/tlwKbqan27CPzrOXvevFGrbRvOGIseaCa7TAxok1x44xahXzQEcdKPKZPevap3RZw920I0VscWGLlU1efPsy0c5cbV1AoI7ZuOMCZW12nkcP9Q2%2bQObBNmL6ajg8s6xJqmJTrq5NIArX6zVk8Zcwwt4fPuLvHnbeBSvpdIQ6g93MvUv3CHqKNrmtEW4EYmCr5gDT5QzyNWE4x6xO1/aqQmgMhGYgaVDFUnScKltbFnaJoKHRuHK0L1pIkuaYselMe9cPUqRmm5C51u00kkhy1S3aBougkl7e4d6RGaTYeSehdCjAG/O/p%2bYfKyQsoLmgdlmsFYQFDjh6GWJyGE0ZfMX08EZtwNTdAYud7nLcksnwppA2UnqpCzgyDo1QadAU3vLOQZ82EHMxAi0KVcq7rzas5xD6AQoeqkYkgk02abukkJ/z%2bNvkj%2bjUy16Ba5d/S8anhBLwt44EgGkoFkIBlIBpKBZCAZSAaSgWQgGUgGkoFkIBlIBpKBZCAZSAaSgWQgGUgGxWOwW2nF7kt%2by7/Kb3ag2GUTUgBvXAAxiKxt4Is3sB4WniVrOvhwzB0CXerg5GN9esGRQv7RgQdMmMO9sIwtc/sIJUOCsY4ee7f7FIWu2Si4euKan8wg58nFsEIXxYGntgZqMog3Z2FrgPhgyzIOlsmijowqwb0jyMqMoGEbarqdOpP/iqFISMkSVFG1Z5p8f3OK%2bxAZ7gClpgUPg70rq0T2RIkcup/0newQ7NbcUXv/DPl4LL/N7hdfn2dp07pmd8v79YSdVVgwqcyWd8HC/8aOzkunf6r%2b2c8bpSxK/6uPmlf%2br/nSnyrHcduH99iqKiz7HwLxTLMgEM0QWUDjb3ji8NdHPslZmV%2bqR%2bfH56Xyxni1VGbV0m8=" []><foo></foo>M';
$reader = new MathML();
$math = $reader->read($content);
}
}

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

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

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

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.

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

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.
@@ -293,8 +294,10 @@ class ZipArchive
// Write $contents to a temp file
$handle = fopen($this->tempDir . DIRECTORY_SEPARATOR . $filenameParts['basename'], 'wb');
fwrite($handle, $contents);
fclose($handle);
if ($handle) {
fwrite($handle, $contents);
fclose($handle);
}
// Add temp file to zip
$filename = $this->tempDir . DIRECTORY_SEPARATOR . $filenameParts['basename'];
@@ -420,4 +423,15 @@ class ZipArchive
return ($listIndex > -1) ? $listIndex : false;
}
/**
* Add an empty directory to the zip archive (emulate \ZipArchive).
*
* @param string $dirname Directory name to add to the zip archive
*/
public function addEmptyDir(string $dirname): bool
{
// Create a directory entry by adding an empty file with trailing slash
return $this->addFromString(rtrim($dirname, '/') . '/', '');
}
}

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.
@@ -108,7 +109,7 @@ class Font extends AbstractStyle
/**
* Font color.
*
* @var string
* @var null|string
*/
private $color;
@@ -219,14 +220,14 @@ class Font extends AbstractStyle
/**
* Paragraph style.
*
* @var \PhpOffice\PhpWord\Style\Paragraph
* @var Paragraph
*/
private $paragraph;
/**
* Shading.
*
* @var \PhpOffice\PhpWord\Style\Shading
* @var Shading
*/
private $shading;
@@ -248,7 +249,7 @@ class Font extends AbstractStyle
/**
* Languages.
*
* @var null|\PhpOffice\PhpWord\Style\Language
* @var null|Language
*/
private $lang;
@@ -288,7 +289,7 @@ class Font extends AbstractStyle
* Create new font style.
*
* @param string $type Type of font
* @param array|\PhpOffice\PhpWord\Style\AbstractStyle|string $paragraph Paragraph styles definition
* @param AbstractStyle|array|string $paragraph Paragraph styles definition
*/
public function __construct($type = 'text', $paragraph = null)
{
@@ -425,10 +426,8 @@ class Font extends AbstractStyle
/**
* Get font color.
*
* @return string
*/
public function getColor()
public function getColor(): ?string
{
return $this->color;
}
@@ -682,7 +681,7 @@ class Font extends AbstractStyle
*
* @param string $value
*
* @return \PhpOffice\PhpWord\Style\Table
* @return Table
*/
public function setBgColor($value = null)
{
@@ -812,7 +811,7 @@ class Font extends AbstractStyle
/**
* Get paragraph style.
*
* @return \PhpOffice\PhpWord\Style\Paragraph
* @return Paragraph
*/
public function getParagraph()
{
@@ -860,7 +859,7 @@ class Font extends AbstractStyle
/**
* Get shading.
*
* @return \PhpOffice\PhpWord\Style\Shading
* @return Shading
*/
public function getShading()
{
@@ -884,7 +883,7 @@ class Font extends AbstractStyle
/**
* Get language.
*
* @return null|\PhpOffice\PhpWord\Style\Language
* @return null|Language
*/
public function getLang()
{

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.
@@ -28,30 +29,37 @@ class Indentation extends AbstractStyle
/**
* Left indentation (twip).
*
* @var float|int
* @var null|float
*/
private $left = 0;
/**
* Right indentation (twip).
*
* @var float|int
* @var null|float
*/
private $right = 0;
/**
* Additional first line indentation (twip).
*
* @var float|int
* @var null|float
*/
private $firstLine = 0;
/**
* Additional first line chars indentation (twip).
*
* @var int
*/
private $firstLineChars = 0;
/**
* Indentation removed from first line (twip).
*
* @var float|int
* @var null|float
*/
private $hanging;
private $hanging = 0;
/**
* Create a new instance.
@@ -65,96 +73,90 @@ class Indentation extends AbstractStyle
/**
* Get left.
*
* @return float|int
*/
public function getLeft()
public function getLeft(): ?float
{
return $this->left;
}
/**
* Set left.
*
* @param float|int $value
*
* @return self
*/
public function setLeft($value)
public function setLeft(?float $value): self
{
$this->left = $this->setNumericVal($value, $this->left);
$this->left = $this->setNumericVal($value);
return $this;
}
/**
* Get right.
*
* @return float|int
*/
public function getRight()
public function getRight(): ?float
{
return $this->right;
}
/**
* Set right.
*
* @param float|int $value
*
* @return self
*/
public function setRight($value)
public function setRight(?float $value): self
{
$this->right = $this->setNumericVal($value, $this->right);
$this->right = $this->setNumericVal($value);
return $this;
}
/**
* Get first line.
*
* @return float|int
*/
public function getFirstLine()
public function getFirstLine(): ?float
{
return $this->firstLine;
}
/**
* Set first line.
*
* @param float|int $value
*
* @return self
*/
public function setFirstLine($value)
public function setFirstLine(?float $value): self
{
$this->firstLine = $this->setNumericVal($value, $this->firstLine);
$this->firstLine = $this->setNumericVal($value);
return $this;
}
/**
* Get first line chars.
*/
public function getFirstLineChars(): int
{
return $this->firstLineChars;
}
/**
* Set first line chars.
*/
public function setFirstLineChars(int $value): self
{
$this->firstLineChars = $this->setIntVal($value, $this->firstLineChars);
return $this;
}
/**
* Get hanging.
*
* @return float|int
*/
public function getHanging()
public function getHanging(): ?float
{
return $this->hanging;
}
/**
* Set hanging.
*
* @param float|int $value
*
* @return self
*/
public function setHanging($value = null)
public function setHanging(?float $value = null): self
{
$this->hanging = $this->setNumericVal($value, $this->hanging);
$this->hanging = $this->setNumericVal($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.
@@ -54,22 +55,16 @@ class Numbering extends AbstractStyle
/**
* Get Id.
*
* @return int
*/
public function getNumId()
public function getNumId(): ?int
{
return $this->numId;
}
/**
* Set Id.
*
* @param int $value
*
* @return self
*/
public function setNumId($value)
public function setNumId(int $value): self
{
$this->numId = $this->setIntVal($value, $this->numId);
@@ -78,22 +73,16 @@ class Numbering extends AbstractStyle
/**
* Get multilevel type.
*
* @return string
*/
public function getType()
public function getType(): ?string
{
return $this->type;
}
/**
* Set multilevel type.
*
* @param string $value
*
* @return self
*/
public function setType($value)
public function setType(string $value): self
{
$enum = ['singleLevel', 'multilevel', 'hybridMultilevel'];
$this->type = $this->setEnumVal($value, $enum, $this->type);
@@ -106,19 +95,15 @@ class Numbering extends AbstractStyle
*
* @return NumberingLevel[]
*/
public function getLevels()
public function getLevels(): array
{
return $this->levels;
}
/**
* Set multilevel type.
*
* @param array $values
*
* @return self
*/
public function setLevels($values)
public function setLevels(array $values): self
{
if (is_array($values)) {
foreach ($values as $key => $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.
@@ -86,14 +87,14 @@ class Paragraph extends Border
/**
* Indentation.
*
* @var null|\PhpOffice\PhpWord\Style\Indentation
* @var null|Indentation
*/
private $indentation;
/**
* Spacing.
*
* @var \PhpOffice\PhpWord\Style\Spacing
* @var Spacing
*/
private $spacing;
@@ -149,14 +150,14 @@ class Paragraph extends Border
/**
* Set of Custom Tab Stops.
*
* @var \PhpOffice\PhpWord\Style\Tab[]
* @var Tab[]
*/
private $tabs = [];
/**
* Shading.
*
* @var \PhpOffice\PhpWord\Style\Shading
* @var Shading
*/
private $shading;
@@ -321,78 +322,144 @@ class Paragraph extends Border
return $this;
}
/**
* Get hanging.
*/
public function getHanging(): ?float
{
return $this->getChildStyleValue($this->indentation, 'hanging');
}
/**
* Get indentation.
*
* @return null|\PhpOffice\PhpWord\Style\Indentation
* @deprecated 1.4.0 Use getIndentLeft
*/
public function getIndentation()
public function getIndent(): ?float
{
return $this->getChildStyleValue($this->indentation, 'left');
}
/**
* Get indentation.
*/
public function getIndentation(): ?Indentation
{
return $this->indentation;
}
/**
* Set shading.
*
* @param mixed $value
*
* @return self
* Get firstLine.
*/
public function setIndentation($value = null)
public function getIndentFirstLine(): ?float
{
return $this->getChildStyleValue($this->indentation, 'firstLine');
}
/**
* Get left indentation.
*/
public function getIndentLeft(): ?float
{
return $this->getChildStyleValue($this->indentation, 'left');
}
/**
* Get right indentation.
*/
public function getIndentRight(): ?float
{
return $this->getChildStyleValue($this->indentation, 'right');
}
/**
* Set hanging.
*
* @deprecated 1.4.0 Use setIndentHanging
*/
public function setHanging(?float $value = null): self
{
return $this->setIndentation(['hanging' => $value]);
}
/**
* Set indentation.
*
* @deprecated 1.4.0 Use setIndentLeft
*/
public function setIndent(?float $value = null): self
{
return $this->setIndentation(['left' => $value]);
}
/**
* Set indentation.
*
* @param array{
* left?:null|float|int|numeric-string,
* right?:null|float|int|numeric-string,
* hanging?:null|float|int|numeric-string,
* firstLine?:null|float|int|numeric-string
* } $value
*/
public function setIndentation(array $value = []): self
{
$value = array_map(function ($indent) {
if (is_string($indent) || is_numeric($indent)) {
$indent = $this->setFloatVal($indent);
}
return $indent;
}, $value);
$this->setObjectVal($value, 'Indentation', $this->indentation);
return $this;
}
/**
* Get indentation.
*
* @return int
* Set hanging indentation.
*/
public function getIndent()
{
return $this->getChildStyleValue($this->indentation, 'left');
}
/**
* Set indentation.
*
* @param int $value
*
* @return self
*/
public function setIndent($value = null)
{
return $this->setIndentation(['left' => $value]);
}
/**
* Get hanging.
*
* @return int
*/
public function getHanging()
{
return $this->getChildStyleValue($this->indentation, 'hanging');
}
/**
* Set hanging.
*
* @param int $value
*
* @return self
*/
public function setHanging($value = null)
public function setIndentHanging(?float $value = null): self
{
return $this->setIndentation(['hanging' => $value]);
}
/**
* Set firstline indentation.
*/
public function setIndentFirstLine(?float $value = null): self
{
return $this->setIndentation(['firstLine' => $value]);
}
/**
* Set firstlineChars indentation.
*/
public function setIndentFirstLineChars(int $value = 0): self
{
return $this->setIndentation(['firstLineChars' => $value]);
}
/**
* Set left indentation.
*/
public function setIndentLeft(?float $value = null): self
{
return $this->setIndentation(['left' => $value]);
}
/**
* Set right indentation.
*/
public function setIndentRight(?float $value = null): self
{
return $this->setIndentation(['right' => $value]);
}
/**
* Get spacing.
*
* @return \PhpOffice\PhpWord\Style\Spacing
* @return Spacing
*
* @todo Rename to getSpacing in 1.0
*/
@@ -498,7 +565,7 @@ class Paragraph extends Border
*
* @param string $value Possible values are defined in LineSpacingRule
*
* @return \PhpOffice\PhpWord\Style\Paragraph
* @return Paragraph
*/
public function setSpacingLineRule($value)
{
@@ -686,7 +753,7 @@ class Paragraph extends Border
/**
* Get tabs.
*
* @return \PhpOffice\PhpWord\Style\Tab[]
* @return Tab[]
*/
public function getTabs()
{
@@ -712,7 +779,7 @@ class Paragraph extends Border
/**
* Get shading.
*
* @return \PhpOffice\PhpWord\Style\Shading
* @return Shading
*/
public function getShading()
{

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
@@ -58,7 +59,7 @@ class Section extends Border
/**
* Paper size.
*
* @var \PhpOffice\PhpWord\Style\Paper
* @var Paper
*/
private $paper;
@@ -137,7 +138,7 @@ class Section extends Border
/**
* Line numbering.
*
* @var \PhpOffice\PhpWord\Style\LineNumbering
* @var LineNumbering
*
* @see http://www.schemacentral.com/sc/ooxml/e-w_lnNumType-1.html
*/
@@ -278,7 +279,7 @@ class Section extends Border
/**
* @param null|float|int $value
*
* @return \PhpOffice\PhpWord\Style\Section
* @return Section
*
* @since 0.12.0
*/
@@ -304,7 +305,7 @@ class Section extends Border
/**
* @param null|float|int $value
*
* @return \PhpOffice\PhpWord\Style\Section
* @return Section
*
* @since 0.12.0
*/
@@ -486,7 +487,7 @@ class Section extends Border
/**
* Get line numbering.
*
* @return \PhpOffice\PhpWord\Style\LineNumbering
* @return LineNumbering
*/
public function getLineNumbering()
{

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.
@@ -51,35 +52,35 @@ class Shape extends AbstractStyle
/**
* Frame.
*
* @var \PhpOffice\PhpWord\Style\Frame
* @var Frame
*/
private $frame;
/**
* Fill.
*
* @var \PhpOffice\PhpWord\Style\Fill
* @var Fill
*/
private $fill;
/**
* Outline.
*
* @var \PhpOffice\PhpWord\Style\Outline
* @var Outline
*/
private $outline;
/**
* Shadow.
*
* @var \PhpOffice\PhpWord\Style\Shadow
* @var Shadow
*/
private $shadow;
/**
* 3D extrusion.
*
* @var \PhpOffice\PhpWord\Style\Extrusion
* @var Extrusion
*/
private $extrusion;
@@ -144,7 +145,7 @@ class Shape extends AbstractStyle
/**
* Get frame.
*
* @return \PhpOffice\PhpWord\Style\Frame
* @return Frame
*/
public function getFrame()
{
@@ -168,7 +169,7 @@ class Shape extends AbstractStyle
/**
* Get fill.
*
* @return \PhpOffice\PhpWord\Style\Fill
* @return Fill
*/
public function getFill()
{
@@ -192,7 +193,7 @@ class Shape extends AbstractStyle
/**
* Get outline.
*
* @return \PhpOffice\PhpWord\Style\Outline
* @return Outline
*/
public function getOutline()
{
@@ -216,7 +217,7 @@ class Shape extends AbstractStyle
/**
* Get shadow.
*
* @return \PhpOffice\PhpWord\Style\Shadow
* @return Shadow
*/
public function getShadow()
{
@@ -240,7 +241,7 @@ class Shape extends AbstractStyle
/**
* Get 3D extrusion.
*
* @return \PhpOffice\PhpWord\Style\Extrusion
* @return Extrusion
*/
public function getExtrusion()
{

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 @@ abstract class AbstractWriter implements WriterInterface
/**
* PHPWord object.
*
* @var \PhpOffice\PhpWord\PhpWord
* @var PhpWord
*/
protected $phpWord;
@@ -96,7 +97,7 @@ abstract class AbstractWriter implements WriterInterface
/**
* Get PhpWord object.
*
* @return \PhpOffice\PhpWord\PhpWord
* @return PhpWord
*/
public function getPhpWord()
{
@@ -110,8 +111,6 @@ abstract class AbstractWriter implements WriterInterface
/**
* Set PhpWord object.
*
* @param \PhpOffice\PhpWord\PhpWord
*
* @return self
*/
public function setPhpWord(?PhpWord $phpWord = null)
@@ -267,7 +266,7 @@ abstract class AbstractWriter implements WriterInterface
*
* @param string $filename
*
* @return \PhpOffice\PhpWord\Shared\ZipArchive
* @return ZipArchive
*/
protected function getZipArchive($filename)
{
@@ -360,7 +359,7 @@ abstract class AbstractWriter implements WriterInterface
*
* Get the actual source from an archive image.
*
* @param \PhpOffice\PhpWord\Shared\ZipArchive $zipPackage
* @param ZipArchive $zipPackage
* @param string $source
* @param string $target
*/

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.
@@ -72,7 +73,7 @@ class Text extends AbstractElement
/** @var \PhpOffice\PhpWord\Element\Text $element Type hint */
$element = $this->element;
$text = $this->parentWriter->escapeHTML($element->getText());
$text = $this->parentWriter->escapeHTML($element->getText() ?? '');
if (!$this->withoutP && !trim($text)) {
$text = '&nbsp;';
}

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.
@@ -22,7 +23,7 @@ use PhpOffice\PhpWord\Writer\HTML\Element\TextRun as TextRunWriter;
use PhpOffice\PhpWord\Writer\PDF\TCPDF;
/**
* RTF body part writer.
* HTML body part writer.
*
* @since 0.11.0
*/

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.
@@ -55,7 +56,7 @@ class ODText extends AbstractWriter implements WriterInterface
foreach (array_keys($this->parts) as $partName) {
$partClass = static::class . '\\Part\\' . $partName;
if (class_exists($partClass)) {
/** @var \PhpOffice\PhpWord\Writer\ODText\Part\AbstractPart $partObject Type hint */
/** @var AbstractPart $partObject Type hint */
$partObject = new $partClass();
$partObject->setParentWriter($this);
$this->writerParts[strtolower($partName)] = $partObject;

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.
@@ -57,37 +58,29 @@ class Text extends AbstractElement
$xmlWriter->writeAttribute('text:change-id', $element->getTrackChange()->getElementId());
$xmlWriter->endElement();
} else {
if (empty($fontStyle)) {
if (empty($paragraphStyle)) {
if (!$this->withoutP) {
$xmlWriter->writeAttribute('text:style-name', 'Normal');
}
} elseif (is_string($paragraphStyle)) {
if (!$this->withoutP) {
$xmlWriter->writeAttribute('text:style-name', $paragraphStyle);
}
if (empty($paragraphStyle)) {
if (!$this->withoutP) {
$xmlWriter->writeAttribute('text:style-name', 'Normal');
}
$this->writeChangeInsertion(true, $element->getTrackChange());
$this->replaceTabs($element->getText(), $xmlWriter);
$this->writeChangeInsertion(false, $element->getTrackChange());
} else {
if (empty($paragraphStyle)) {
if (!$this->withoutP) {
$xmlWriter->writeAttribute('text:style-name', 'Normal');
}
} elseif (is_string($paragraphStyle)) {
if (!$this->withoutP) {
$xmlWriter->writeAttribute('text:style-name', $paragraphStyle);
}
} elseif (is_string($paragraphStyle)) {
if (!$this->withoutP) {
$xmlWriter->writeAttribute('text:style-name', $paragraphStyle);
}
}
if (!empty($fontStyle)) {
// text:span
$xmlWriter->startElement('text:span');
if (is_string($fontStyle)) {
$xmlWriter->writeAttribute('text:style-name', $fontStyle);
}
$this->writeChangeInsertion(true, $element->getTrackChange());
$this->replaceTabs($element->getText(), $xmlWriter);
$this->writeChangeInsertion(false, $element->getTrackChange());
}
$this->writeChangeInsertion(true, $element->getTrackChange());
$this->replaceTabs($element->getText(), $xmlWriter);
$this->writeChangeInsertion(false, $element->getTrackChange());
if (!empty($fontStyle)) {
$xmlWriter->endElement();
}
}
@@ -96,35 +89,6 @@ class Text extends AbstractElement
}
}
private function replacetabs($text, $xmlWriter): void
{
if (preg_match('/^ +/', $text, $matches)) {
$num = strlen($matches[0]);
$xmlWriter->startElement('text:s');
$xmlWriter->writeAttributeIf($num > 1, 'text:c', "$num");
$xmlWriter->endElement();
$text = preg_replace('/^ +/', '', $text);
}
preg_match_all('/([\\s\\S]*?)(\\t| +| ?$)/', $text, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$this->writeText($match[1]);
if ($match[2] === '') {
break;
} elseif ($match[2] === "\t") {
$xmlWriter->writeElement('text:tab');
} elseif ($match[2] === ' ') {
$xmlWriter->writeElement('text:s');
break;
} else {
$num = strlen($match[2]);
$xmlWriter->startElement('text:s');
$xmlWriter->writeAttributeIf($num > 1, 'text:c', "$num");
$xmlWriter->endElement();
}
}
}
private function writeChangeInsertion($start = true, ?TrackChange $trackChange = null): void
{
if ($trackChange == null || $trackChange->getChangeType() != TrackChange::INSERTED) {

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.
@@ -91,11 +92,12 @@ class Styles extends AbstractPart
// Font
$xmlWriter->startElement('style:text-properties');
$xmlWriter->writeAttribute('style:use-window-font-color', 'true');
$xmlWriter->writeAttribute('style:use-window-font-color', 'false');
$xmlWriter->writeAttribute('style:font-name', Settings::getDefaultFontName());
$xmlWriter->writeAttribute('fo:font-size', Settings::getDefaultFontSize() . 'pt');
$xmlWriter->writeAttribute('fo:language', $latinLang[0]);
$xmlWriter->writeAttribute('fo:country', $latinLang[1]);
$xmlWriter->writeAttribute('fo:color', '#' . Settings::getDefaultFontColor());
$xmlWriter->writeAttribute('style:letter-kerning', 'true');
$xmlWriter->writeAttribute('style:font-name-asian', Settings::getDefaultFontName() . '2');
$xmlWriter->writeAttribute('style:font-size-asian', Settings::getDefaultFontSize() . 'pt');

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.
@@ -58,10 +59,15 @@ class Title extends Text
/** @var \PhpOffice\PhpWord\Element\Title $element Type hint */
$element = $this->element;
$elementClass = str_replace('\\Writer\\RTF', '', static::class);
if (!$element instanceof $elementClass || !is_string($element->getText())) {
if (!$element instanceof $elementClass) {
return '';
}
$textToWrite = $element->getText();
if ($textToWrite instanceof \PhpOffice\PhpWord\Element\TextRun) {
$textToWrite = $textToWrite->getText(); // gets text from TextRun
}
$this->getStyles();
$content = '';
@@ -82,7 +88,7 @@ class Title extends Text
$content .= '{';
$content .= $this->writeFontStyle();
$content .= $this->writeText($element->getText());
$content .= $this->writeText($textToWrite);
$content .= '}';
$content .= $this->writeClosing();
$content .= $endout;

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.
@@ -33,14 +34,14 @@ abstract class AbstractElement
/**
* XML writer.
*
* @var \PhpOffice\PhpWord\Shared\XMLWriter
* @var XMLWriter
*/
private $xmlWriter;
/**
* Element.
*
* @var \PhpOffice\PhpWord\Element\AbstractElement
* @var Element
*/
private $element;
@@ -63,10 +64,8 @@ abstract class AbstractElement
/**
* Create new instance.
*
* @param bool $withoutP
*/
public function __construct(XMLWriter $xmlWriter, Element $element, $withoutP = false)
public function __construct(XMLWriter $xmlWriter, Element $element, bool $withoutP = false)
{
$this->xmlWriter = $xmlWriter;
$this->element = $element;
@@ -76,7 +75,7 @@ abstract class AbstractElement
/**
* Get XML Writer.
*
* @return \PhpOffice\PhpWord\Shared\XMLWriter
* @return XMLWriter
*/
protected function getXmlWriter()
{
@@ -86,7 +85,7 @@ abstract class AbstractElement
/**
* Get element.
*
* @return \PhpOffice\PhpWord\Element\AbstractElement
* @return Element
*/
protected function getElement()
{

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,6 +37,11 @@ class Container extends AbstractElement
*/
protected $namespace = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element';
/**
* @var array<string>
*/
protected $containerWithoutP = ['TextRun', 'Footnote', 'Endnote', 'ListItemRun'];
/**
* Write element.
*/
@@ -46,7 +52,7 @@ class Container extends AbstractElement
return;
}
$containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1);
$withoutP = in_array($containerClass, ['TextRun', 'Footnote', 'Endnote', 'ListItemRun']);
$withoutP = in_array($containerClass, $this->containerWithoutP);
$xmlWriter = $this->getXmlWriter();
// Loop through elements
@@ -62,7 +68,7 @@ class Container extends AbstractElement
$writeLastTextBreak = ($containerClass == 'Cell') && ($elementClass == '' || $elementClass == 'Table');
if ($writeLastTextBreak) {
$writerClass = $this->namespace . '\\TextBreak';
/** @var \PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement $writer Type hint */
/** @var AbstractElement $writer Type hint */
$writer = new $writerClass($xmlWriter, new TextBreakElement(), $withoutP);
$writer->write();
}
@@ -70,18 +76,14 @@ class Container extends AbstractElement
/**
* Write individual element.
*
* @param bool $withoutP
*
* @return string
*/
private function writeElement(XMLWriter $xmlWriter, Element $element, $withoutP)
private function writeElement(XMLWriter $xmlWriter, Element $element, bool $withoutP): string
{
$elementClass = substr(get_class($element), strrpos(get_class($element), '\\') + 1);
$writerClass = $this->namespace . '\\' . $elementClass;
if (class_exists($writerClass)) {
/** @var \PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement $writer Type hint */
/** @var AbstractElement $writer Type hint */
$writer = new $writerClass($xmlWriter, $element, $withoutP);
$writer->setPart($this->getPart());
$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.

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.
@@ -113,7 +114,7 @@ class TOC extends AbstractElement
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:instrText');
$xmlWriter->writeAttribute('xml:space', 'preserve');
$xmlWriter->text("PAGEREF _Toc{$rId} \\h");
$xmlWriter->text("PAGEREF $rId \\h");
$xmlWriter->endElement();
$xmlWriter->endElement();

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.
@@ -196,7 +197,7 @@ class Settings extends AbstractPart
];
} else {
if ($documentProtection->getSalt() == null) {
$documentProtection->setSalt(openssl_random_pseudo_bytes(16));
$documentProtection->setSalt((string) openssl_random_pseudo_bytes(16));
}
$passwordHash = PasswordEncoder::hashPassword($documentProtection->getPassword(), $documentProtection->getAlgorithm(), $documentProtection->getSalt(), $documentProtection->getSpinCount());
$this->settings['w:documentProtection'] = [

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,13 +78,15 @@ class Styles extends AbstractPart
/**
* Write default font and other default styles.
*
* @param \PhpOffice\PhpWord\Style\AbstractStyle[] $styles
* @param Style\AbstractStyle[] $styles
*/
private function writeDefaultStyles(XMLWriter $xmlWriter, $styles): void
{
$phpWord = $this->getParentWriter()->getPhpWord();
$fontName = $phpWord->getDefaultFontName();
$asianFontName = $phpWord->getDefaultAsianFontName();
$fontSize = $phpWord->getDefaultFontSize();
$fontColor = $phpWord->getDefaultFontColor();
$language = $phpWord->getSettings()->getThemeFontLang();
$latinLanguage = ($language == null || $language->getLatin() === null) ? 'en-US' : $language->getLatin();
@@ -94,9 +97,12 @@ class Styles extends AbstractPart
$xmlWriter->startElement('w:rFonts');
$xmlWriter->writeAttribute('w:ascii', $fontName);
$xmlWriter->writeAttribute('w:hAnsi', $fontName);
$xmlWriter->writeAttribute('w:eastAsia', $fontName);
$xmlWriter->writeAttribute('w:eastAsia', $asianFontName);
$xmlWriter->writeAttribute('w:cs', $fontName);
$xmlWriter->endElement(); // w:rFonts
$xmlWriter->startElement('w:color');
$xmlWriter->writeAttribute('w:val', $fontColor);
$xmlWriter->endElement();
$xmlWriter->startElement('w:sz');
$xmlWriter->writeAttribute('w:val', $fontSize * 2);
$xmlWriter->endElement(); // w:sz
@@ -125,7 +131,7 @@ class Styles extends AbstractPart
if (isset($styles['Normal'])) {
$normalStyle = $styles['Normal'];
// w:pPr
if ($normalStyle instanceof Fontstyle && $normalStyle->getParagraph() != null) {
if ($normalStyle instanceof FontStyle && $normalStyle->getParagraph() != null) {
$styleWriter = new ParagraphStyleWriter($xmlWriter, $normalStyle->getParagraph());
$styleWriter->write();
} elseif ($normalStyle instanceof ParagraphStyle) {

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