Skip to content

Commit 0fcea82

Browse files
committed
Merge pull request #252 from ivanlanin/rtf
Passed Travis. Merged.
2 parents e81d92e + 4bb3ffe commit 0fcea82

File tree

19 files changed

+593
-45
lines changed

19 files changed

+593
-45
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
44

55
## 0.11.0 - Not yet released
66

7-
This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3. Three new elements were added: TextBox, ListItemRun, and Field. Relative and absolute positioning for images and textboxes were added. Writer classes were refactored into parts, elements, and styles. ODT and RTF features were enhanced. Ability to add elements to PHPWord object via HTML were implemeted.
7+
This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3. Three new elements were added: TextBox, ListItemRun, and Field. Relative and absolute positioning for images and textboxes were added. Writer classes were refactored into parts, elements, and styles. ODT and RTF features were enhanced. Ability to add elements to PHPWord object via HTML were implemeted. RTF reader were initiated.
88

99
### Features
1010

@@ -30,6 +30,7 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3. Three
3030
- RTF Writer: Ability to write document properties - @ivanlanin
3131
- RTF Writer: Ability to write image - @ivanlanin
3232
- Element: New `Field` element - @basjan GH-251
33+
- RTF Reader: Basic RTF reader - @ivanlanin GH-72
3334

3435
### Bugfixes
3536

docs/elements.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Inline style examples:
8888
$textrun = $section->addTextRun();
8989
$textrun->addText('I am bold', array('bold' => true));
9090
$textrun->addText('I am italic', array('italic' => true));
91-
$textrun->addText('I am colored, array('color' => 'AACC00'));
91+
$textrun->addText('I am colored', array('color' => 'AACC00'));
9292
9393
Defined style examples:
9494

docs/intro.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Readers
124124
+---------------------------+----------------------+--------+-------+-------+
125125
| | Custom || | |
126126
+---------------------------+----------------------+--------+-------+-------+
127-
| **Element Type** | Text ||| |
127+
| **Element Type** | Text ||| |
128128
+---------------------------+----------------------+--------+-------+-------+
129129
| | Text Run || | |
130130
+---------------------------+----------------------+--------+-------+-------+

docs/src/documentation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Below are the supported features for each file formats.
114114
|-------------------------|--------------------|------|-----|-----|
115115
| **Document Properties** | Standard || | |
116116
| | Custom || | |
117-
| **Element Type** | Text ||| |
117+
| **Element Type** | Text ||| |
118118
| | Text Run || | |
119119
| | Title ||| |
120120
| | Link || | |
@@ -495,7 +495,7 @@ $section->addText('I am simple paragraph', $fontStyle, $paragraphStyle);
495495
$textrun = $section->addTextRun();
496496
$textrun->addText('I am bold', array('bold' => true));
497497
$textrun->addText('I am italic', array('italic' => true));
498-
$textrun->addText('I am colored, array('color' => 'AACC00'));
498+
$textrun->addText('I am colored', array('color' => 'AACC00'));
499499
```
500500

501501
Defined style examples:

samples/Sample_11_ReadWord2007.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
// Read contents
55
$name = basename(__FILE__, '.php');
6-
$source = "resources/{$name}.docx";
6+
$source = __DIR__ . "/resources/{$name}.docx";
7+
78
echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
89
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
910

samples/Sample_24_ReadODText.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
// Read contents
55
$name = basename(__FILE__, '.php');
6-
$source = "resources/{$name}.odt";
6+
$source = __DIR__ . "/resources/{$name}.odt";
7+
78
echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
89
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source, 'ODText');
910

samples/Sample_28_ReadRTF.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
include_once 'Sample_Header.php';
3+
4+
// Read contents
5+
$name = basename(__FILE__, '.php');
6+
$source = __DIR__ . "/resources/{$name}.rtf";
7+
8+
echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
9+
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source, 'RTF');
10+
11+
// Save file
12+
echo write($phpWord, basename(__FILE__, '.php'), $writers);
13+
if (!CLI) {
14+
include_once 'Sample_Footer.php';
15+
}

samples/Sample_Header.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ function write($phpWord, $filename, $writers)
6363
$result .= date('H:i:s') . " Write to {$writer} format";
6464
if (!is_null($extension)) {
6565
$xmlWriter = IOFactory::createWriter($phpWord, $writer);
66-
$xmlWriter->save("{$filename}.{$extension}");
67-
rename("{$filename}.{$extension}", "results/{$filename}.{$extension}");
66+
$xmlWriter->save(__DIR__ . "/{$filename}.{$extension}");
67+
rename(__DIR__ . "/{$filename}.{$extension}", __DIR__ . "/results/{$filename}.{$extension}");
6868
} else {
6969
$result .= ' ... NOT DONE!';
7070
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{\rtf1
2+
\ansi\ansicpg1252
3+
\deff0
4+
{\fonttbl{\f0\fnil\fcharset0 Arial;}{\f1\fnil\fcharset0 Times New Roman;}}
5+
{\colortbl;\red255\green0\blue0;\red14\green0\blue0}
6+
{\*\generator PhpWord;}
7+
8+
{\info{\title }{\subject }{\category }{\keywords }{\comment }{\author }{\operator }{\creatim \yr2014\mo05\dy27\hr23\min36\sec45}{\revtim \yr2014\mo05\dy27\hr23\min36\sec45}{\company }{\manager }}
9+
\deftab720\viewkind1\uc1\pard\nowidctlpar\lang1036\kerning1\fs20
10+
{Welcome to PhpWord}\par
11+
\pard\nowidctlpar{\cf0\f0 Hello World!}\par
12+
\par
13+
\par
14+
\pard\nowidctlpar{\cf0\f0\fs32\b\i I am styled by a font style definition.}\par
15+
\pard\nowidctlpar{\cf0\f0 I am styled by a paragraph style definition.}\par
16+
\pard\nowidctlpar\qc\sa100{\cf0\f0\fs32\b\i I am styled by both font and paragraph style.}\par
17+
\pard\nowidctlpar{\cf1\f1\fs40\b\i\ul\strike\super I am inline styled.}\par
18+
\par
19+
{\field {\*\fldinst {HYPERLINK "http://www.google.com"}}{\fldrslt {Google}}}\par
20+
\par
21+
}

src/PhpWord/IOFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
5151
*/
5252
public static function createReader($name = 'Word2007')
5353
{
54-
if (!in_array($name, array('ReaderInterface', 'Word2007', 'ODText'))) {
54+
if (!in_array($name, array('ReaderInterface', 'Word2007', 'ODText', 'RTF'))) {
5555
throw new Exception("\"{$name}\" is not a valid reader.");
5656
}
5757

0 commit comments

Comments
 (0)