Skip to content

Commit 2a5c667

Browse files
author
Roman Syroeshko
committed
#51 (updated tests, refactored a little).
1 parent 2b9111f commit 2a5c667

File tree

104 files changed

+1171
-1142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+1171
-1142
lines changed

docs/general.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
2828
htmlspecialchars(
2929
'"Learn from yesterday, live for today, hope for tomorrow. '
3030
. 'The important thing is not to stop questioning." '
31-
. '(Albert Einstein)'
31+
. '(Albert Einstein)',
32+
ENT_COMPAT,
33+
'UTF-8'
3234
)
3335
);
3436
@@ -44,7 +46,9 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
4446
htmlspecialchars(
4547
'"Great achievement is usually born of great sacrifice, '
4648
. 'and is never the result of selfishness." '
47-
. '(Napoleon Hill)'
49+
. '(Napoleon Hill)',
50+
ENT_COMPAT,
51+
'UTF-8'
4852
),
4953
array('name' => 'Tahoma', 'size' => 10)
5054
);
@@ -59,7 +63,9 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
5963
htmlspecialchars(
6064
'"The greatest accomplishment is not in never falling, '
6165
. 'but in rising again after you fall." '
62-
. '(Vince Lombardi)'
66+
. '(Vince Lombardi)',
67+
ENT_COMPAT,
68+
'UTF-8'
6369
),
6470
$fontStyleName
6571
);
@@ -70,7 +76,7 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
7076
$fontStyle->setName('Tahoma');
7177
$fontStyle->setSize(13);
7278
$myTextElement = $section->addText(
73-
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)')
79+
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)', ENT_COMPAT, 'UTF-8')
7480
);
7581
$myTextElement->setFontStyle($fontStyle);
7682

docs/src/documentation.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ $section->addText(
228228
htmlspecialchars(
229229
'"Learn from yesterday, live for today, hope for tomorrow. '
230230
. 'The important thing is not to stop questioning." '
231-
. '(Albert Einstein)'
231+
. '(Albert Einstein)',
232+
ENT_COMPAT,
233+
'UTF-8'
232234
)
233235
);
234236

@@ -244,7 +246,9 @@ $section->addText(
244246
htmlspecialchars(
245247
'"Great achievement is usually born of great sacrifice, '
246248
. 'and is never the result of selfishness." '
247-
. '(Napoleon Hill)'
249+
. '(Napoleon Hill)',
250+
ENT_COMPAT,
251+
'UTF-8'
248252
),
249253
array('name' => 'Tahoma', 'size' => 10)
250254
);
@@ -259,7 +263,9 @@ $section->addText(
259263
htmlspecialchars(
260264
'"The greatest accomplishment is not in never falling, '
261265
. 'but in rising again after you fall." '
262-
. '(Vince Lombardi)'
266+
. '(Vince Lombardi)',
267+
ENT_COMPAT,
268+
'UTF-8'
263269
),
264270
$fontStyleName
265271
);
@@ -270,7 +276,7 @@ $fontStyle->setBold(true);
270276
$fontStyle->setName('Tahoma');
271277
$fontStyle->setSize(13);
272278
$myTextElement = $section->addText(
273-
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)')
279+
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)', ENT_COMPAT, 'UTF-8')
274280
);
275281
$myTextElement->setFontStyle($fontStyle);
276282

samples/Sample_01_SimpleText.php

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
$section = $phpWord->addSection();
1313

1414
// Simple text
15-
$section->addTitle(htmlspecialchars('Welcome to PhpWord'), 1);
16-
$section->addText(htmlspecialchars('Hello World!'));
15+
$section->addTitle(htmlspecialchars('Welcome to PhpWord', ENT_COMPAT, 'UTF-8'), 1);
16+
$section->addText(htmlspecialchars('Hello World!', ENT_COMPAT, 'UTF-8'));
1717

1818
// Two text break
1919
$section->addTextBreak(2);
2020

2121
// Defined style
22-
$section->addText(htmlspecialchars('I am styled by a font style definition.'), 'rStyle');
23-
$section->addText(htmlspecialchars('I am styled by a paragraph style definition.'), null, 'pStyle');
24-
$section->addText(htmlspecialchars('I am styled by both font and paragraph style.'), 'rStyle', 'pStyle');
22+
$section->addText(htmlspecialchars('I am styled by a font style definition.', ENT_COMPAT, 'UTF-8'), 'rStyle');
23+
$section->addText(htmlspecialchars('I am styled by a paragraph style definition.', ENT_COMPAT, 'UTF-8'), null, 'pStyle');
24+
$section->addText(htmlspecialchars('I am styled by both font and paragraph style.', ENT_COMPAT, 'UTF-8'), 'rStyle', 'pStyle');
2525

2626
$section->addTextBreak();
2727

@@ -30,39 +30,39 @@
3030
$fontStyle['size'] = 20;
3131

3232
$textrun = $section->addTextRun();
33-
$textrun->addText(htmlspecialchars('I am inline styled '), $fontStyle);
34-
$textrun->addText(htmlspecialchars('with '));
35-
$textrun->addText(htmlspecialchars('color'), array('color' => '996699'));
36-
$textrun->addText(htmlspecialchars(', '));
37-
$textrun->addText(htmlspecialchars('bold'), array('bold' => true));
38-
$textrun->addText(htmlspecialchars(', '));
39-
$textrun->addText(htmlspecialchars('italic'), array('italic' => true));
40-
$textrun->addText(htmlspecialchars(', '));
41-
$textrun->addText(htmlspecialchars('underline'), array('underline' => 'dash'));
42-
$textrun->addText(htmlspecialchars(', '));
43-
$textrun->addText(htmlspecialchars('strikethrough'), array('strikethrough' => true));
44-
$textrun->addText(htmlspecialchars(', '));
45-
$textrun->addText(htmlspecialchars('doubleStrikethrough'), array('doubleStrikethrough' => true));
46-
$textrun->addText(htmlspecialchars(', '));
47-
$textrun->addText(htmlspecialchars('superScript'), array('superScript' => true));
48-
$textrun->addText(htmlspecialchars(', '));
49-
$textrun->addText(htmlspecialchars('subScript'), array('subScript' => true));
50-
$textrun->addText(htmlspecialchars(', '));
51-
$textrun->addText(htmlspecialchars('smallCaps'), array('smallCaps' => true));
52-
$textrun->addText(htmlspecialchars(', '));
53-
$textrun->addText(htmlspecialchars('allCaps'), array('allCaps' => true));
54-
$textrun->addText(htmlspecialchars(', '));
55-
$textrun->addText(htmlspecialchars('fgColor'), array('fgColor' => 'yellow'));
56-
$textrun->addText(htmlspecialchars(', '));
57-
$textrun->addText(htmlspecialchars('scale'), array('scale' => 200));
58-
$textrun->addText(htmlspecialchars(', '));
59-
$textrun->addText(htmlspecialchars('spacing'), array('spacing' => 120));
60-
$textrun->addText(htmlspecialchars(', '));
61-
$textrun->addText(htmlspecialchars('kerning'), array('kerning' => 10));
62-
$textrun->addText(htmlspecialchars('. '));
33+
$textrun->addText(htmlspecialchars('I am inline styled ', ENT_COMPAT, 'UTF-8'), $fontStyle);
34+
$textrun->addText(htmlspecialchars('with ', ENT_COMPAT, 'UTF-8'));
35+
$textrun->addText(htmlspecialchars('color', ENT_COMPAT, 'UTF-8'), array('color' => '996699'));
36+
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
37+
$textrun->addText(htmlspecialchars('bold', ENT_COMPAT, 'UTF-8'), array('bold' => true));
38+
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
39+
$textrun->addText(htmlspecialchars('italic', ENT_COMPAT, 'UTF-8'), array('italic' => true));
40+
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
41+
$textrun->addText(htmlspecialchars('underline', ENT_COMPAT, 'UTF-8'), array('underline' => 'dash'));
42+
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
43+
$textrun->addText(htmlspecialchars('strikethrough', ENT_COMPAT, 'UTF-8'), array('strikethrough' => true));
44+
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
45+
$textrun->addText(htmlspecialchars('doubleStrikethrough', ENT_COMPAT, 'UTF-8'), array('doubleStrikethrough' => true));
46+
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
47+
$textrun->addText(htmlspecialchars('superScript', ENT_COMPAT, 'UTF-8'), array('superScript' => true));
48+
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
49+
$textrun->addText(htmlspecialchars('subScript', ENT_COMPAT, 'UTF-8'), array('subScript' => true));
50+
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
51+
$textrun->addText(htmlspecialchars('smallCaps', ENT_COMPAT, 'UTF-8'), array('smallCaps' => true));
52+
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
53+
$textrun->addText(htmlspecialchars('allCaps', ENT_COMPAT, 'UTF-8'), array('allCaps' => true));
54+
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
55+
$textrun->addText(htmlspecialchars('fgColor', ENT_COMPAT, 'UTF-8'), array('fgColor' => 'yellow'));
56+
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
57+
$textrun->addText(htmlspecialchars('scale', ENT_COMPAT, 'UTF-8'), array('scale' => 200));
58+
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
59+
$textrun->addText(htmlspecialchars('spacing', ENT_COMPAT, 'UTF-8'), array('spacing' => 120));
60+
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
61+
$textrun->addText(htmlspecialchars('kerning', ENT_COMPAT, 'UTF-8'), array('kerning' => 10));
62+
$textrun->addText(htmlspecialchars('. ', ENT_COMPAT, 'UTF-8'));
6363

6464
// Link
65-
$section->addLink('http://www.google.com', htmlspecialchars('Google'));
65+
$section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
6666
$section->addTextBreak();
6767

6868
// Image

samples/Sample_02_TabStops.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
$section = $phpWord->addSection();
3030

3131
// Add listitem elements
32-
$section->addText(htmlspecialchars("Multiple Tabs:\tOne\tTwo\tThree"), null, 'multipleTab');
33-
$section->addText(htmlspecialchars("Left Aligned\tRight Aligned"), null, 'rightTab');
34-
$section->addText(htmlspecialchars("\tCenter Aligned"), null, 'centerTab');
32+
$section->addText(htmlspecialchars("Multiple Tabs:\tOne\tTwo\tThree", ENT_COMPAT, 'UTF-8'), null, 'multipleTab');
33+
$section->addText(htmlspecialchars("Left Aligned\tRight Aligned", ENT_COMPAT, 'UTF-8'), null, 'rightTab');
34+
$section->addText(htmlspecialchars("\tCenter Aligned", ENT_COMPAT, 'UTF-8'), null, 'centerTab');
3535

3636
// Save file
3737
echo write($phpWord, basename(__FILE__, '.php'), $writers);

samples/Sample_03_Sections.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77

88
// New portrait section
99
$section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12));
10-
$section->addText(htmlspecialchars('I am placed on a default section.'));
10+
$section->addText(htmlspecialchars('I am placed on a default section.', ENT_COMPAT, 'UTF-8'));
1111

1212
// New landscape section
1313
$section = $phpWord->addSection(array('orientation' => 'landscape'));
1414
$section->addText(
1515
htmlspecialchars(
16-
'I am placed on a landscape section. Every page starting from this section will be landscape style.'
16+
'I am placed on a landscape section. Every page starting from this section will be landscape style.',
17+
ENT_COMPAT,
18+
'UTF-8'
1719
)
1820
);
1921
$section->addPageBreak();
@@ -23,7 +25,7 @@
2325
$section = $phpWord->addSection(
2426
array('paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
2527
);
26-
$section->addText(htmlspecialchars('This section uses other margins with folio papersize.'));
28+
$section->addText(htmlspecialchars('This section uses other margins with folio papersize.', ENT_COMPAT, 'UTF-8'));
2729

2830
// New portrait section with Header & Footer
2931
$section = $phpWord->addSection(
@@ -36,9 +38,9 @@
3638
'footerHeight' => 50,
3739
)
3840
);
39-
$section->addText(htmlspecialchars('This section and we play with header/footer height.'));
40-
$section->addHeader()->addText(htmlspecialchars('Header'));
41-
$section->addFooter()->addText(htmlspecialchars('Footer'));
41+
$section->addText(htmlspecialchars('This section and we play with header/footer height.', ENT_COMPAT, 'UTF-8'));
42+
$section->addHeader()->addText(htmlspecialchars('Header', ENT_COMPAT, 'UTF-8'));
43+
$section->addFooter()->addText(htmlspecialchars('Footer', ENT_COMPAT, 'UTF-8'));
4244

4345
// Save file
4446
echo write($phpWord, basename(__FILE__, '.php'), $writers);

samples/Sample_04_Textrun.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@
2020
// Add text run
2121
$textrun = $section->addTextRun('pStyle');
2222

23-
$textrun->addText(htmlspecialchars('Each textrun can contain native text, link elements or an image.'));
24-
$textrun->addText(htmlspecialchars(' No break is placed after adding an element.'), 'BoldText');
25-
$textrun->addText(htmlspecialchars(' Both '));
26-
$textrun->addText(htmlspecialchars('superscript'), array('superScript' => true));
27-
$textrun->addText(htmlspecialchars(' and '));
28-
$textrun->addText(htmlspecialchars('subscript'), array('subScript' => true));
29-
$textrun->addText(htmlspecialchars(' are also available.'));
23+
$textrun->addText(htmlspecialchars('Each textrun can contain native text, link elements or an image.', ENT_COMPAT, 'UTF-8'));
24+
$textrun->addText(htmlspecialchars(' No break is placed after adding an element.', ENT_COMPAT, 'UTF-8'), 'BoldText');
25+
$textrun->addText(htmlspecialchars(' Both ', ENT_COMPAT, 'UTF-8'));
26+
$textrun->addText(htmlspecialchars('superscript', ENT_COMPAT, 'UTF-8'), array('superScript' => true));
27+
$textrun->addText(htmlspecialchars(' and ', ENT_COMPAT, 'UTF-8'));
28+
$textrun->addText(htmlspecialchars('subscript', ENT_COMPAT, 'UTF-8'), array('subScript' => true));
29+
$textrun->addText(htmlspecialchars(' are also available.', ENT_COMPAT, 'UTF-8'));
3030
$textrun->addText(
31-
htmlspecialchars(' All elements are placed inside a paragraph with the optionally given p-Style.'),
31+
htmlspecialchars(' All elements are placed inside a paragraph with the optionally given p-Style.', ENT_COMPAT, 'UTF-8'),
3232
'ColoredText'
3333
);
34-
$textrun->addText(htmlspecialchars(' Sample Link: '));
35-
$textrun->addLink('http://www.google.com', null, 'NLink');
36-
$textrun->addText(htmlspecialchars(' Sample Image: '));
34+
$textrun->addText(htmlspecialchars(' Sample Link: ', ENT_COMPAT, 'UTF-8'));
35+
$textrun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), 'NLink');
36+
$textrun->addText(htmlspecialchars(' Sample Image: ', ENT_COMPAT, 'UTF-8'));
3737
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
38-
$textrun->addText(htmlspecialchars(' Sample Object: '));
38+
$textrun->addText(htmlspecialchars(' Sample Object: ', ENT_COMPAT, 'UTF-8'));
3939
$textrun->addObject('resources/_sheet.xls');
40-
$textrun->addText(htmlspecialchars(' Here is some more text. '));
40+
$textrun->addText(htmlspecialchars(' Here is some more text. ', ENT_COMPAT, 'UTF-8'));
4141

4242
// Save file
4343
echo write($phpWord, basename(__FILE__, '.php'), $writers);

samples/Sample_05_Multicolumn.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
// Normal
1313
$section = $phpWord->addSection();
14-
$section->addText(htmlspecialchars("Normal paragraph. {$filler}"));
14+
$section->addText(htmlspecialchars("Normal paragraph. {$filler}", ENT_COMPAT, 'UTF-8'));
1515

1616
// Two columns
1717
$section = $phpWord->addSection(
@@ -21,11 +21,11 @@
2121
'breakType' => 'continuous',
2222
)
2323
);
24-
$section->addText(htmlspecialchars("Two columns, one inch (1440 twips) spacing. {$filler}"));
24+
$section->addText(htmlspecialchars("Two columns, one inch (1440 twips) spacing. {$filler}", ENT_COMPAT, 'UTF-8'));
2525

2626
// Normal
2727
$section = $phpWord->addSection(array('breakType' => 'continuous'));
28-
$section->addText(htmlspecialchars("Normal paragraph again. {$filler}"));
28+
$section->addText(htmlspecialchars("Normal paragraph again. {$filler}", ENT_COMPAT, 'UTF-8'));
2929

3030
// Three columns
3131
$section = $phpWord->addSection(
@@ -35,11 +35,11 @@
3535
'breakType' => 'continuous',
3636
)
3737
);
38-
$section->addText(htmlspecialchars("Three columns, half inch (720 twips) spacing. {$filler}"));
38+
$section->addText(htmlspecialchars("Three columns, half inch (720 twips) spacing. {$filler}", ENT_COMPAT, 'UTF-8'));
3939

4040
// Normal
4141
$section = $phpWord->addSection(array('breakType' => 'continuous'));
42-
$section->addText(htmlspecialchars('Normal paragraph again.'));
42+
$section->addText(htmlspecialchars('Normal paragraph again.', ENT_COMPAT, 'UTF-8'));
4343

4444
// Save file
4545
echo write($phpWord, basename(__FILE__, '.php'), $writers);

samples/Sample_06_Footnote.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,32 @@
2020

2121
// Add text elements
2222
$textrun = $section->addTextRun('pStyle');
23-
$textrun->addText(htmlspecialchars('This is some lead text in a paragraph with a following footnote. '), 'pStyle');
23+
$textrun->addText(htmlspecialchars('This is some lead text in a paragraph with a following footnote. ', ENT_COMPAT, 'UTF-8'), 'pStyle');
2424

2525
$footnote = $textrun->addFootnote();
26-
$footnote->addText(htmlspecialchars('Just like a textrun, a footnote can contain native texts. '));
27-
$footnote->addText(htmlspecialchars('No break is placed after adding an element. '), 'BoldText');
28-
$footnote->addText(htmlspecialchars('All elements are placed inside a paragraph. '), 'ColoredText');
26+
$footnote->addText(htmlspecialchars('Just like a textrun, a footnote can contain native texts. ', ENT_COMPAT, 'UTF-8'));
27+
$footnote->addText(htmlspecialchars('No break is placed after adding an element. ', ENT_COMPAT, 'UTF-8'), 'BoldText');
28+
$footnote->addText(htmlspecialchars('All elements are placed inside a paragraph. ', ENT_COMPAT, 'UTF-8'), 'ColoredText');
2929
$footnote->addTextBreak();
30-
$footnote->addText(htmlspecialchars('But you can insert a manual text break like above, '));
31-
$footnote->addText(htmlspecialchars('links like '));
32-
$footnote->addLink('http://www.google.com', null, 'NLink');
33-
$footnote->addText(htmlspecialchars(', image like '));
30+
$footnote->addText(htmlspecialchars('But you can insert a manual text break like above, ', ENT_COMPAT, 'UTF-8'));
31+
$footnote->addText(htmlspecialchars('links like ', ENT_COMPAT, 'UTF-8'));
32+
$footnote->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), 'NLink');
33+
$footnote->addText(htmlspecialchars(', image like ', ENT_COMPAT, 'UTF-8'));
3434
$footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
35-
$footnote->addText(htmlspecialchars(', or object like '));
35+
$footnote->addText(htmlspecialchars(', or object like ', ENT_COMPAT, 'UTF-8'));
3636
$footnote->addObject('resources/_sheet.xls');
37-
$footnote->addText(htmlspecialchars('But you can only put footnote in section, not in header or footer.'));
37+
$footnote->addText(htmlspecialchars('But you can only put footnote in section, not in header or footer.', ENT_COMPAT, 'UTF-8'));
3838

3939
$section->addText(
4040
htmlspecialchars(
4141
'You can also create the footnote directly from the section making it wrap in a paragraph '
42-
. 'like the footnote below this paragraph. But is is best used from within a textrun.'
42+
. 'like the footnote below this paragraph. But is is best used from within a textrun.',
43+
ENT_COMPAT,
44+
'UTF-8'
4345
)
4446
);
4547
$footnote = $section->addFootnote();
46-
$footnote->addText(htmlspecialchars('The reference for this is wrapped in its own line'));
48+
$footnote->addText(htmlspecialchars('The reference for this is wrapped in its own line', ENT_COMPAT, 'UTF-8'));
4749

4850
// Save file
4951
echo write($phpWord, basename(__FILE__, '.php'), $writers);

0 commit comments

Comments
 (0)