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

Patch 1 #1798

Closed
wants to merge 24 commits into from
Closed

Patch 1 #1798

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5e93950
Update templates processing docs
hcdias Oct 3, 2019
b0de8e7
Improve unit test
Manunchik Oct 23, 2019
cb7ffd0
Improve unit test
Manunchik Oct 23, 2019
21db2d4
Improve unit test
Manunchik Oct 23, 2019
b230242
fixed List item fail #1711
Nov 5, 2019
a10fe82
Errors in RTF Escaping
Nov 17, 2019
2513e54
Errors in RTF Escaping
Nov 17, 2019
00f9bb5
Formatting changes in source code.
Nov 17, 2019
1451fad
Add List for docx to html writer #1717
Nov 28, 2019
aa44594
fix: PHPUnit test Process() format
Dec 2, 2019
f51811b
fix: documentation about paragraph indentation
Nov 28, 2019
6381549
Merge pull request #1771 from mdupont/fix-tests
troosan Dec 8, 2019
3583cfe
Merge pull request #1742 from Manunchik/Manunchik-patch-2
troosan Dec 8, 2019
777b48f
Merge pull request #1743 from Manunchik/Manunchik-patch-3
troosan Dec 8, 2019
3834504
Merge pull request #1744 from Manunchik/Manunchik-patch-4
troosan Dec 8, 2019
9020e67
Merge pull request #1764 from mdupont/358-paragraph-indent
troosan Dec 8, 2019
5a7a11a
Merge pull request #1729 from hcdias/patch-1
troosan Dec 8, 2019
9fe6a58
Merge remote-tracking branch 'upstream/master' into develop
Dec 8, 2019
5940d18
Merge pull request #1755 from oleibman/master
troosan Dec 8, 2019
dfea4e1
Merge pull request #1766 from stefan-91/develop
troosan Dec 8, 2019
4852028
fix: typo in getFootnoteProperties() method name
Dec 9, 2019
cb3e211
fix(documentation): snippet for FootnoteProperties
Dec 9, 2019
733f845
Merge pull request #1776 from mdupont/footnotes-typo
troosan Dec 9, 2019
431b11b
Changing from zendframework to laminas
Houbsi Jan 6, 2020
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"require": {
"php": "^5.3.3 || ^7.0",
"ext-xml": "*",
"zendframework/zend-escaper": "^2.2",
"laminas/laminas-escaper": "^2.6",
"phpoffice/common": "^0.2.9"
},
"require-dev": {
Expand Down
10 changes: 5 additions & 5 deletions docs/elements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,17 @@ The footnote numbering can be controlled by setting the FootnoteProperties on th

.. code-block:: php

$fp = new PhpWord\SimpleType\FootnoteProperties();
$fp = new \PhpOffice\PhpWord\ComplexType\FootnoteProperties();
//sets the position of the footnote (pageBottom (default), beneathText, sectEnd, docEnd)
$fp->setPos(FootnoteProperties::POSITION_DOC_END);
$fp->setPos(\PhpOffice\PhpWord\ComplexType\FootnoteProperties::POSITION_BENEATH_TEXT);
//set the number format to use (decimal (default), upperRoman, upperLetter, ...)
$fp->setNumFmt(FootnoteProperties::NUMBER_FORMAT_LOWER_ROMAN);
$fp->setNumFmt(\PhpOffice\PhpWord\SimpleType\NumberFormat::LOWER_ROMAN);
//force starting at other than 1
$fp->setNumStart(2);
//when to restart counting (continuous (default), eachSect, eachPage)
$fp->setNumRestart(FootnoteProperties::RESTART_NUMBER_EACH_PAGE);
$fp->setNumRestart(\PhpOffice\PhpWord\ComplexType\FootnoteProperties::RESTART_NUMBER_EACH_PAGE);
//And finaly, set it on the Section
$section->setFootnoteProperties($properties);
$section->setFootnoteProperties($fp);

Checkboxes
----------
Expand Down
6 changes: 4 additions & 2 deletions docs/styles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ Available Paragraph style options:
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class constants for possible values.
- ``basedOn``. Parent style.
- ``hanging``. Hanging in *twip*.
- ``indent``. Indent in *twip*.
- ``hanging``. Hanging indentation in *half inches*.
- ``indent``. Indent (left indentation) in *half inches*.
- ``indentation``. An array of indentation key => value pairs in *twip*. Supports *left*, *right*, *firstLine* and *hanging* indentation.
See ``\PhpOffice\PhpWord\Style\Indentation`` for possible identation types.
- ``keepLines``. Keep all lines on one page, *true* or *false*.
- ``keepNext``. Keep paragraph with next paragraph, *true* or *false*.
- ``lineHeight``. Text line height, e.g. *1.0*, *1.5*, etc.
Expand Down
17 changes: 17 additions & 0 deletions docs/templates-processing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,20 @@ See ``Sample_40_TemplateSetComplexValue.php`` for examples.
$table->addCell(150)->addText('Cell B2');
$table->addCell(150)->addText('Cell B3');
$templateProcessor->setComplexBlock('table', $table);

save
"""""""""
Saves the loaded template within the current directory. Returns the file path.

.. code-block:: php

$filepath = $templateProcessor->save();

saveAs
"""""""""
Saves a copy of the loaded template in the indicated path.

.. code-block:: php

$pathToSave = 'path/to/save/file.ext';
$templateProcessor->saveAs($pathToSave);
12 changes: 12 additions & 0 deletions src/PhpWord/Element/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ public function getFooters()
*
* @return FootnoteProperties
*/
public function getFootnoteProperties()
{
return $this->footnoteProperties;
}

/**
* Get the footnote properties
*
* @deprecated Use the `getFootnoteProperties` method instead
*
* @return FootnoteProperties
*/
public function getFootnotePropoperties()
{
return $this->footnoteProperties;
Expand Down
12 changes: 9 additions & 3 deletions src/PhpWord/Escaper/Rtf.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ class Rtf extends AbstractEscaper
{
protected function escapeAsciiCharacter($code)
{
if (20 > $code || $code >= 80) {
return '{\u' . $code . '}';
if ($code == 9) {
return '{\\tab}';
}
if (0x20 > $code || $code >= 0x80) {
return '{\\u' . $code . '}';
}
if ($code == 123 || $code == 125 || $code == 92) { // open or close brace or backslash
return '\\' . chr($code);
}

return chr($code);
}

protected function escapeMultibyteCharacter($code)
{
return '\uc0{\u' . $code . '}';
return '\\uc0{\\u' . $code . '}';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Style/Paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function setStyleValue($key, $value)
{
$key = Text::removeUnderscorePrefix($key);
if ('indent' == $key || 'hanging' == $key) {
$value = $value * 720;
$value = $value * 720; // 720 twips is 0.5 inch
}

return parent::setStyleValue($key, $value);
Expand Down
43 changes: 43 additions & 0 deletions src/PhpWord/Writer/HTML/Element/ListItemRun.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Writer\HTML\Element;

/**
* ListItem element HTML writer
*
* @since 0.10.0
*/
class ListItemRun extends TextRun
{
/**
* Write list item
*
* @return string
*/
public function write()
{
if (!$this->element instanceof \PhpOffice\PhpWord\Element\ListItemRun) {
return '';
}

$writer = new Container($this->parentWriter, $this->element);
$content = $writer->write() . PHP_EOL;

return $content;
}
}
20 changes: 10 additions & 10 deletions src/PhpWord/Writer/Word2007/Part/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,27 @@ private function writeSectionSettings(XMLWriter $xmlWriter, Section $section)
$xmlWriter->endElement();
}

//footnote properties
if ($section->getFootnotePropoperties() !== null) {
// Footnote properties
if ($section->getFootnoteProperties() !== null) {
$xmlWriter->startElement('w:footnotePr');
if ($section->getFootnotePropoperties()->getPos() != null) {
if ($section->getFootnoteProperties()->getPos() != null) {
$xmlWriter->startElement('w:pos');
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getPos());
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getPos());
$xmlWriter->endElement();
}
if ($section->getFootnotePropoperties()->getNumFmt() != null) {
if ($section->getFootnoteProperties()->getNumFmt() != null) {
$xmlWriter->startElement('w:numFmt');
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumFmt());
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumFmt());
$xmlWriter->endElement();
}
if ($section->getFootnotePropoperties()->getNumStart() != null) {
if ($section->getFootnoteProperties()->getNumStart() != null) {
$xmlWriter->startElement('w:numStart');
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumStart());
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumStart());
$xmlWriter->endElement();
}
if ($section->getFootnotePropoperties()->getNumRestart() != null) {
if ($section->getFootnoteProperties()->getNumRestart() != null) {
$xmlWriter->startElement('w:numRestart');
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumRestart());
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumRestart());
$xmlWriter->endElement();
}
$xmlWriter->endElement();
Expand Down
83 changes: 83 additions & 0 deletions tests/PhpWord/Escaper/RtfEscaper2Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Escaper;

/**
* Test class for PhpOffice\PhpWord\Escaper\RTF
*/
class RtfEscaper2Test extends \PHPUnit\Framework\TestCase
{
const HEADER = '\\pard\\nowidctlpar {\\cf0\\f0 ';
const TRAILER = '}\\par';

public function escapestring($str)
{
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
$parentWriter = new \PhpOffice\PhpWord\Writer\RTF();
$element = new \PhpOffice\PhpWord\Element\Text($str);
$txt = new \PhpOffice\PhpWord\Writer\RTF\Element\Text($parentWriter, $element);
$txt2 = trim($txt->write());

return $txt2;
}

public function expect($str)
{
return self::HEADER . $str . self::TRAILER;
}

/**
* Test special characters which require escaping
*/
public function testSpecial()
{
$str = 'Special characters { open brace } close brace \\ backslash';
$expect = $this->expect('Special characters \\{ open brace \\} close brace \\\\ backslash');
$this->assertEquals($expect, $this->escapestring($str));
}

/**
* Test accented character
*/
public function testAccent()
{
$str = 'Voilà - string with accented char';
$expect = $this->expect('Voil\\uc0{\\u224} - string with accented char');
$this->assertEquals($expect, $this->escapestring($str));
}

/**
* Test Hebrew
*/
public function testHebrew()
{
$str = 'Hebrew - שלום';
$expect = $this->expect('Hebrew - \\uc0{\\u1513}\\uc0{\\u1500}\\uc0{\\u1493}\\uc0{\\u1501}');
$this->assertEquals($expect, $this->escapestring($str));
}

/**
* Test tab
*/
public function testTab()
{
$str = "Here's a tab\tfollowed by more characters.";
$expect = $this->expect("Here's a tab{\\tab}followed by more characters.");
$this->assertEquals($expect, $this->escapestring($str));
}
}
16 changes: 16 additions & 0 deletions tests/PhpWord/MediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ public function testGetSectionMediaElementsWithNull()
$this->assertEquals(array(), Media::getElements('section'));
}

/**
* Get header media elements
*/
public function testGetHeaderMediaElementsWithNull()
{
$this->assertEquals(array(), Media::getElements('header'));
}

/**
* Get footer media elements
*/
public function testGetFooterMediaElementsWithNull()
{
$this->assertEquals(array(), Media::getElements('footer'));
}

/**
* Count section media elements
*/
Expand Down
9 changes: 9 additions & 0 deletions tests/PhpWord/PhpWordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,13 @@ public function testSortSections()
$this->assertEquals(2, $phpWord->getSection(0)->countElements());
$this->assertEquals(1, $phpWord->getSection(1)->countElements());
}

/**
* @covers \PhpOffice\PhpWord\PhpWord::getSettings
*/
public function testGetSettings()
{
$phpWord = new PhpWord();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Metadata\\Settings', $phpWord->getSettings());
}
}
18 changes: 17 additions & 1 deletion tests/PhpWord/StyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class StyleTest extends \PHPUnit\Framework\TestCase
* @covers ::addParagraphStyle
* @covers ::addFontStyle
* @covers ::addLinkStyle
* @covers ::addNumberingStyle
* @covers ::addTitleStyle
* @covers ::addTableStyle
* @covers ::setDefaultParagraphStyle
Expand All @@ -47,19 +48,34 @@ public function testStyles()
$paragraph = array('alignment' => Jc::CENTER);
$font = array('italic' => true, '_bold' => true);
$table = array('bgColor' => 'CCCCCC');
$numbering = array(
'type' => 'multilevel',
'levels' => array(
array(
'start' => 1,
'format' => 'decimal',
'restart' => 1,
'suffix' => 'space',
'text' => '%1.',
'alignment' => Jc::START,
),
),
);

$styles = array(
'Paragraph' => 'Paragraph',
'Font' => 'Font',
'Link' => 'Font',
'Table' => 'Table',
'Heading_1' => 'Font',
'Normal' => 'Paragraph',
'Numbering' => 'Numbering',
);

Style::addParagraphStyle('Paragraph', $paragraph);
Style::addFontStyle('Font', $font);
Style::addLinkStyle('Link', $font);
// @todo Style::addNumberingStyle
Style::addNumberingStyle('Numbering', $numbering);
Style::addTitleStyle(1, $font);
Style::addTableStyle('Table', $table);
Style::setDefaultParagraphStyle($paragraph);
Expand Down
Loading