Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Do Not Install #2567

Draft
wants to merge 40 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5e147c4
WIP Do Not Install
oleibman Feb 6, 2024
446c464
Merge branch 'master' into wordunimplemented2
oleibman Feb 6, 2024
0ac841e
Update Html.php
oleibman Feb 7, 2024
39fbabc
Load Html as Html Not Xml
oleibman May 9, 2024
cf1fd2a
Permit Some Backwards Compatibility
oleibman May 10, 2024
e0e98dd
Merge branch 'master' into wordunimplemented2
oleibman Aug 9, 2024
14cad6a
Merge branch 'master' into wordunimplemented2
oleibman Aug 16, 2024
2f799c2
Phpstan False Positives
oleibman Aug 16, 2024
d9120c7
Improve Resolution of Phpstan Problem
oleibman Aug 16, 2024
41fabcc
Merge branch 'master' into wordunimplemented2
oleibman Sep 3, 2024
920f305
Merge branch 'master' into wordunimplemented2
oleibman Sep 4, 2024
1093a3b
Update Sample_45_RTLTitles.php
oleibman Sep 4, 2024
74918d0
Update Sample_45_RTLTitles.php
oleibman Sep 4, 2024
28b1b08
Update Sample_45_RTLTitles.php
oleibman Sep 4, 2024
90ee6a9
Merge branch 'master' into wordunimplemented2
oleibman Sep 5, 2024
63e9fd1
Merge branch 'master' into wordunimplemented2
oleibman Sep 13, 2024
86b939f
Merge branch 'master' into wordunimplemented2
oleibman Sep 13, 2024
8b01436
Merge branch 'master' into wordunimplemented2
oleibman Sep 14, 2024
91d95f1
Merge branch 'master' into wordunimplemented2
oleibman Oct 14, 2024
32a7350
Update HTMLTest.php
oleibman Jan 9, 2025
69faae1
Move One Test to Avoid Merge Conflict
oleibman Jan 9, 2025
e9316c0
Try to Correct Merge Conflicts in Writer/HTML/FontTest
oleibman Jan 9, 2025
3dd5da5
Trying FontTest One More Time Before Giving Up
oleibman Jan 10, 2025
1bcee8e
Merge branch 'master' into wordunimplemented2
oleibman Jan 10, 2025
8e6726c
Try to Catch Up
oleibman Jan 10, 2025
0e3eb2b
Experiment with Different Phpunit Xml Dists
oleibman Jan 12, 2025
737cb37
Remove Logging from 7.8 Config
oleibman Jan 12, 2025
5084642
More Phpunit Tweaking
oleibman Jan 12, 2025
4280dab
Merge branch 'master' into wordunimplemented2
oleibman Jan 15, 2025
d1a16fe
Update HtmlTest.php
oleibman Jan 15, 2025
93daccb
Merge branch 'master' into wordunimplemented2
oleibman Jan 25, 2025
870c827
Merge branch 'master' into wordunimplemented2
oleibman Jan 29, 2025
5271a02
Merge branch 'master' into wordunimplemented2
oleibman Jan 30, 2025
f82eb47
Eliminate JSON Dependency
oleibman Jan 30, 2025
3ace770
Improve Test Coverage
oleibman Jan 31, 2025
b1720b9
A Bit More Coverage
oleibman Jan 31, 2025
346ac92
Merge branch 'master' into wordunimplemented2
oleibman Jan 31, 2025
56ea8c0
Merge branch 'master' into wordunimplemented2
oleibman Feb 6, 2025
16904a2
Catch Up
oleibman Feb 6, 2025
92a4c5e
Html Writer Duplicate Header Styles in Style Tags
oleibman Feb 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,21 @@ jobs:
- name: Composer Install
run: composer install --ansi --prefer-dist --no-interaction --no-progress

- name: Run phpunit
if: matrix.php != '7.3'
run: ./vendor/bin/phpunit -c phpunit.xml.dist --no-coverage
- name: Run phpunit 7.1 7.2
if: matrix.php == '7.1' || matrix.php == '7.2'
run: ./vendor/bin/phpunit -c phpunit.7.8.xml.dist --no-coverage

- name: Run phpunit
- name: Run phpunit 7.4 8.0
if: matrix.php == '7.4' || matrix.php == '8.0'
run: ./vendor/bin/phpunit -c phpunit9.xml.dist --no-coverage

- name: Run phpunit 8.1 8.2 8.3 8.4
if: matrix.php == '8.1' || matrix.php == '8.2' || matrix.php == '8.3' || matrix.php == '8.4'
run: ./vendor/bin/phpunit -c phpunit10.xml.dist --no-coverage

- name: Run phpunit 7.3
if: matrix.php == '7.3'
run: ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover build/clover.xml
run: ./vendor/bin/phpunit -c phpunit9.xml.dist --coverage-clover build/clover.xml

- name: Upload coverage results to Coveralls
if: matrix.php == '7.3'
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ phpword.ini
/nbproject
/.php_cs.cache
/.phpunit.result.cache
/public
/.phpunit.cache
/public
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@
"require": {
"php": "^7.1|^8.0",
"ext-dom": "*",
"ext-gd": "*",
"ext-gd": "*",
"ext-zip": "*",
"ext-json": "*",
"ext-xml": "*",
"phpoffice/math": "^0.2"
},
Expand All @@ -122,7 +121,7 @@
"phpmd/phpmd": "^2.13",
"phpstan/phpstan": "^0.12.88 || ^1.0.0",
"phpstan/phpstan-phpunit": "^1.0 || ^2.0",
"phpunit/phpunit": ">=7.0",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0 || ^10.0",
"symfony/process": "^4.4 || ^5.0",
"tecnickcom/tcpdf": "^6.5"
},
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,6 @@ parameters:
count: 1
path: src/PhpWord/Shared/Html.php

-
message: "#^Cannot call method setBorderSize\\(\\) on PhpOffice\\\\PhpWord\\\\Style\\\\Table\\|string\\.$#"
count: 1
path: src/PhpWord/Shared/Html.php

-
message: "#^Cannot call method setStyleName\\(\\) on PhpOffice\\\\PhpWord\\\\Style\\\\Table\\|string\\.$#"
count: 1
Expand Down
11 changes: 11 additions & 0 deletions phpunit.7.8.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="./tests/bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" convertDeprecationsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<php>
<ini name="error_reporting" value="E_ALL"/>
</php>
<testsuites>
<testsuite name="PhpWord Test Suite">
<directory>./tests/PhpWordTests</directory>
</testsuite>
</testsuites>
</phpunit>
22 changes: 9 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="./tests/bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" convertDeprecationsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./src/PhpWord/Shared/PCLZip</directory>
</exclude>
<report>
<clover outputFile="./build/logs/clover.xml"/>
<html outputDirectory="./build/coverage"/>
</report>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="./tests/bootstrap.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<php>
<ini name="error_reporting" value="E_ALL"/>
</php>
Expand All @@ -21,4 +9,12 @@
</testsuite>
</testsuites>
<logging/>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./src/PhpWord/Shared/PCLZip</directory>
</exclude>
</source>
</phpunit>
20 changes: 20 additions & 0 deletions phpunit10.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="./tests/bootstrap.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<php>
<ini name="error_reporting" value="E_ALL"/>
</php>
<testsuites>
<testsuite name="PhpWord Test Suite">
<directory>./tests/PhpWordTests</directory>
</testsuite>
</testsuites>
<logging/>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./src/PhpWord/Shared/PCLZip</directory>
</exclude>
</source>
</phpunit>
24 changes: 24 additions & 0 deletions phpunit9.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="./tests/bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" convertDeprecationsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./src/PhpWord/Shared/PCLZip</directory>
</exclude>
<!--report>
<clover outputFile="./build/logs/clover.xml"/>
<html outputDirectory="./build/coverage"/>
</report-->
</coverage>
<php>
<ini name="error_reporting" value="E_ALL"/>
</php>
<testsuites>
<testsuite name="PhpWord Test Suite">
<directory>./tests/PhpWordTests</directory>
</testsuite>
</testsuites>
<logging/>
</phpunit>
35 changes: 35 additions & 0 deletions samples/Sample_45_RTLTitles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

include_once 'Sample_Header.php';

use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\Html as SharedHtml;

// Suggested by issue #2427.
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new PhpWord();
Settings::setDefaultRtl(true);
$phpWord->setDefaultFontName('DejaVu Sans'); // for good rendition of PDF
$rendererName = Settings::PDF_RENDERER_MPDF;
$rendererLibraryPath = $vendorDirPath . '/mpdf/mpdf';
Settings::setPdfRenderer($rendererName, $rendererLibraryPath);

// Define styles for headers
$phpWord->addTitleStyle(1, ['bold' => true, 'name' => 'Arial', 'size' => 16], []);
//var_dump($x);
$phpWord->addTitleStyle(2, ['bold' => true, 'name' => 'Arial', 'size' => 14], []);
$phpWord->addTitleStyle(3, ['bold' => true, 'name' => 'Arial', 'size' => 12], []);
$phpWord->addTitleStyle(4, ['bold' => true, 'name' => 'Arial', 'size' => 10], []);

// New section
$section = $phpWord->addSection();
$htmlContent = '<h1>مرحبا 1</h1><h2>تجربة 2</h2><h3>تجربة تجربة</h3><h4 dir="rtl">هناك hello هنا 4</h4><p>مرحبا here كلمة انجليزي.</p>';
SharedHtml::addHtml($section, $htmlContent, false, false);

// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}
Settings::setDefaultRtl(false);
5 changes: 3 additions & 2 deletions src/PhpWord/PhpWord.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use BadMethodCallException;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Style\Font;

/**
* PHPWord main class.
Expand Down Expand Up @@ -318,9 +319,9 @@ public function setDefaultFontSize($fontSize): void
*
* @return Style\Paragraph
*/
public function setDefaultParagraphStyle($styles)
public function setDefaultParagraphStyle($styles, ?Font $fontStyles = null)
{
return Style::setDefaultParagraphStyle($styles);
return Style::setDefaultParagraphStyle($styles, $fontStyles);
}

/**
Expand Down
65 changes: 38 additions & 27 deletions src/PhpWord/Reader/Word2007/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,35 +792,46 @@ protected function readTableStyle(XMLReader $xmlReader, DOMElement $domNode)
$borders = array_merge($margins, ['insideH', 'insideV']);

if ($xmlReader->elementExists('w:tblPr', $domNode)) {
$tblStyleName = '';
if ($xmlReader->elementExists('w:tblPr/w:tblStyle', $domNode)) {
$style = $xmlReader->getAttribute('w:val', $domNode, 'w:tblPr/w:tblStyle');
} else {
$styleNode = $xmlReader->getElement('w:tblPr', $domNode);
$styleDefs = [];
foreach ($margins as $side) {
$ucfSide = ucfirst($side);
$styleDefs["cellMargin$ucfSide"] = [self::READ_VALUE, "w:tblCellMar/w:$side", 'w:w'];
}
foreach ($borders as $side) {
$ucfSide = ucfirst($side);
$styleDefs["border{$ucfSide}Size"] = [self::READ_VALUE, "w:tblBorders/w:$side", 'w:sz'];
$styleDefs["border{$ucfSide}Color"] = [self::READ_VALUE, "w:tblBorders/w:$side", 'w:color'];
$styleDefs["border{$ucfSide}Style"] = [self::READ_VALUE, "w:tblBorders/w:$side", 'w:val'];
}
$styleDefs['layout'] = [self::READ_VALUE, 'w:tblLayout', 'w:type'];
$styleDefs['bidiVisual'] = [self::READ_TRUE, 'w:bidiVisual'];
$styleDefs['cellSpacing'] = [self::READ_VALUE, 'w:tblCellSpacing', 'w:w'];
$style = $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);

$tablePositionNode = $xmlReader->getElement('w:tblpPr', $styleNode);
if ($tablePositionNode !== null) {
$style['position'] = $this->readTablePosition($xmlReader, $tablePositionNode);
}
$tblStyleName = $xmlReader->getAttribute('w:val', $domNode, 'w:tblPr/w:tblStyle');
}
$styleNode = $xmlReader->getElement('w:tblPr', $domNode);
$styleDefs = [];

$indentNode = $xmlReader->getElement('w:tblInd', $styleNode);
if ($indentNode !== null) {
$style['indent'] = $this->readTableIndent($xmlReader, $indentNode);
}
foreach ($margins as $side) {
$ucfSide = ucfirst($side);
$styleDefs["cellMargin$ucfSide"] = [self::READ_VALUE, "w:tblCellMar/w:$side", 'w:w'];
}
foreach ($borders as $side) {
$ucfSide = ucfirst($side);
$styleDefs["border{$ucfSide}Size"] = [self::READ_VALUE, "w:tblBorders/w:$side", 'w:sz'];
$styleDefs["border{$ucfSide}Color"] = [self::READ_VALUE, "w:tblBorders/w:$side", 'w:color'];
$styleDefs["border{$ucfSide}Style"] = [self::READ_VALUE, "w:tblBorders/w:$side", 'w:val'];
}
$styleDefs['layout'] = [self::READ_VALUE, 'w:tblLayout', 'w:type'];
$styleDefs['bidiVisual'] = [self::READ_TRUE, 'w:bidiVisual'];
$styleDefs['cellSpacing'] = [self::READ_VALUE, 'w:tblCellSpacing', 'w:w'];
$style = $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);

$tablePositionNode = $xmlReader->getElement('w:tblpPr', $styleNode);
if ($tablePositionNode !== null) {
$style['position'] = $this->readTablePosition($xmlReader, $tablePositionNode);
}

$indentNode = $xmlReader->getElement('w:tblInd', $styleNode);
if ($indentNode !== null) {
$style['indent'] = $this->readTableIndent($xmlReader, $indentNode);
}
if ($xmlReader->elementExists('w:basedOn', $domNode)) {
$style['basedOn'] = $xmlReader->getAttribute('w:val', $domNode, 'w:basedOn');
}
if ($tblStyleName !== '') {
$style['tblStyle'] = $tblStyleName;
}
// this may be unneeded
if ($xmlReader->elementExists('w:name', $domNode)) {
$style['styleName'] = $xmlReader->getAttribute('w:val', $domNode, 'w:name');
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/PhpWord/Reader/Word2007/Styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public function read(PhpWord $phpWord): void
foreach ($nodes as $node) {
$type = $xmlReader->getAttribute('w:type', $node);
$name = $xmlReader->getAttribute('w:val', $node, 'w:name');
$styleId = $xmlReader->getAttribute('w:styleId', $node);
if (null === $name) {
$name = $xmlReader->getAttribute('w:styleId', $node);
$name = $styleId;
}
$headingMatches = [];
preg_match('/Heading\s*(\d)/i', $name, $headingMatches);
Expand Down Expand Up @@ -102,7 +103,8 @@ public function read(PhpWord $phpWord): void
case 'table':
$tStyle = $this->readTableStyle($xmlReader, $node);
if (!empty($tStyle)) {
$phpWord->addTableStyle($name, $tStyle);
$newTable = $phpWord->addTableStyle($styleId, $tStyle);
$newTable->setStyleName($name);
}

break;
Expand Down
5 changes: 5 additions & 0 deletions src/PhpWord/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace PhpOffice\PhpWord;

use PhpOffice\PhpWord\SimpleType\TextDirection;

/**
* PHPWord settings class.
*
Expand Down Expand Up @@ -453,6 +455,9 @@ public static function setDefaultFontSize($value): bool
public static function setDefaultRtl(?bool $defaultRtl): void
{
self::$defaultRtl = $defaultRtl;
if ($defaultRtl === true && Style::getStyle('Normal') === null) {
Style::setDefaultParagraphStyle(['bidi' => true, 'textDirection' => TextDirection::RLTB], ['rtl' => true]);
}
}

public static function isDefaultRtl(): ?bool
Expand Down
Loading