Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion docs/changes/1.x/1.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Bug fixes

- Set writeAttribute return type by [@radarhere](https://github.com/radarhere) fixing [#2204](https://github.com/PHPOffice/PHPWord/issues/2204) in [#2776](https://github.com/PHPOffice/PHPWord/pull/2776)
- Writer RTF: Improve Indentation and add missing commands by [@rasamassen](https://github.com/rasamassen) in [#2836](https://github.com/PHPOffice/PHPWord/pull/2836)

### Miscellaneous

Expand All @@ -16,4 +17,4 @@

### BC Breaks

### Notes
### Notes
10 changes: 7 additions & 3 deletions src/PhpWord/Writer/RTF/Style/Indentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ public function write()
return '';
}

$content = '\fi' . round($style->getFirstLine());
$content .= '\li' . round($style->getLeft());
$content .= '\ri' . round($style->getRight());
$content = '';

$content .= $this->getValueIf($style->getFirstLine() != 0, '\fi' . round($style->getFirstLine()));
$content .= $this->getValueIf($style->getFirstLineChars() != 0, '\cufi' . round($style->getFirstLineChars()));
$content .= $this->getValueIf($style->getHanging() != 0, '\fi-' . round($style->getHanging()));
$content .= $this->getValueIf($style->getLeft() != 0, '\li' . round($style->getLeft()));
$content .= $this->getValueIf($style->getRight() != 0, '\ri' . round($style->getRight()));

return $content . ' ';
}
Expand Down
73 changes: 73 additions & 0 deletions tests/PhpWordTests/Writer/RTF/Style/IndentationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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
*
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWordTests\Writer\RTF\Style;

use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Style\Indentation as IndentationStyle;
use PhpOffice\PhpWord\Writer\RTF;
use PhpOffice\PhpWord\Writer\RTF\Style\Indentation as IndentationWriter;
use PHPUnit\Framework\TestCase;

class IndentationTest extends TestCase
{
protected function tearDown(): void
{
Settings::setDefaultRtl(null);
}

/**
* @param IndentationWriter $field
*/
public function removeCr($field): string
{
return str_replace("\r\n", "\n", $field->write());
}

/**
* Test indentation.
* See page 79 of RTF Specification 1.9.1 for Indentation.
*/
public function testIndentation(): void
{
$parentWriter = new RTF();
$style = new IndentationStyle();
$writer = new IndentationWriter($style);
$writer->setParentWriter($parentWriter);

$expect = ' ';
self::assertEquals($expect, $this->removeCr($writer));

$style->setLeft(1440);
$style->setRight(720);
$style->setFirstLine(360);
$style->setFirstLineChars(180);
$expect = '\fi360\cufi180\li1440\ri720 ';
self::assertEquals($expect, $this->removeCr($writer));

$style = new IndentationStyle();
$writer = new IndentationWriter($style);
$writer->setParentWriter($parentWriter);

$style->setLeft(1440);
$style->setRight(720);
$style->setHanging(360);
$expect = '\fi-360\li1440\ri720 ';
self::assertEquals($expect, $this->removeCr($writer));
}
}
14 changes: 0 additions & 14 deletions tests/PhpWordTests/Writer/RTF/StyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,6 @@ public function testBorderWithNonRegisteredColors(): void
self::assertEquals($expected, $content);
}

public function testIndentation(): void
{
$indentation = new \PhpOffice\PhpWord\Style\Indentation();
$indentation->setLeft(1);
$indentation->setRight(2);
$indentation->setFirstLine(3);

$indentWriter = new RTF\Style\Indentation($indentation);
$indentWriter->setParentWriter(new RTF());
$result = $indentWriter->write();

Assert::assertEquals('\fi3\li1\ri2 ', $result);
}

public function testRightTab(): void
{
$tabRight = new \PhpOffice\PhpWord\Style\Tab();
Expand Down
Loading