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 @@ -11,9 +11,10 @@
### Miscellaneous

- Update phpstan/phpstan requirement from ^0.12.88 || ^1.0.0 to ^0.12.88 || ^1.0.0 || ^2.0.0 by [@dependabot](https://github.com/dependabot) & [@Progi1984](https://github.com/Progi1984) in [#2736](https://github.com/PHPOffice/PHPWord/pull/2736)
- Created visual test suite to ensure all parts of styles are working as expected, by [@rasamassen](https://github.com/rasamassen) in [#2849](https://github.com/PHPOffice/PHPWord/pull/2849)

### Deprecations

### BC Breaks

### Notes
### Notes
11 changes: 11 additions & 0 deletions samples/Sample_Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

// Populate samples
$files = '';
$testFiles = '';
if ($handle = opendir('.')) {
$sampleFiles = [];
while (false !== ($sampleFile = readdir($handle))) {
Expand All @@ -67,6 +68,10 @@
$name = str_replace('_', ' ', preg_replace('/(Sample_|\.php)/', '', $file));
$files .= "<li><a href='{$file}'>{$name}</a></li>";
}
if (preg_match('/^TestSuite_/', $file)) {
$name = str_replace('_', ' ', preg_replace('/(TestSuite_|\.php)/', '', $file));
$testFiles .= "<li><a href='{$file}'>{$name}</a></li>";
}
}
}

Expand Down Expand Up @@ -164,6 +169,12 @@ function getEndingNotes(array $writers, string $filename): string
<ul class="dropdown-menu"><?php echo $files; ?></ul>
</li>
</ul>
<ul class="nav navbar-nav">
<li class="dropdown active">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-code fa-lg"></i>&nbsp;Test Suite<strong class="caret"></strong></a>
<ul class="dropdown-menu"><?php echo $testFiles; ?></ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="https://github.com/PHPOffice/PHPWord"><i class="fa fa-github fa-lg" title="GitHub"></i>&nbsp;</a></li>
<li><a href="https://phpoffice.github.io/PHPWord/"><i class="fa fa-book fa-lg" title="Docs"></i>&nbsp;</a></li>
Expand Down
95 changes: 95 additions & 0 deletions samples/TestSuite_Style_Border.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

use PhpOffice\PhpWord\SimpleType\Border;
use PhpOffice\PhpWord\Style\Font;

include_once 'Sample_Header.php';

// New Word Document
echo date('H:i:s') , ' Create new PhpWord object' , EOL;

$languageEnGb = new PhpOffice\PhpWord\Style\Language(PhpOffice\PhpWord\Style\Language::EN_GB);

$phpWord = new PhpOffice\PhpWord\PhpWord();
$phpWord->getSettings()->setThemeFontLang($languageEnGb);
$phpWord->addTitleStyle(1, ['bold' => true, 'underline' => 'single', 'size' => 18]);
$phpWord->addTitleStyle(2, ['bold' => true, 'underline' => 'single']);
$section = $phpWord->addSection(['borderColor' => '00FF00', 'borderSize' => 12, 'marginLeft' => 1000, 'marginRight' => 400, 'marginTop' => 800, 'marginBottom' => 200]);

$section->addTitle('Testing All Border Styles', 1);
$section->addTextBreak();

// Section Border.
$section->addTitle('Section Border', 2);
$section->addText('This section has a green border 12 twip thick, with a left margin of 1000, right margin of 400, top margin of 800, and bottom margin of 200');
$section->addTextBreak();

// Paragraph Border.
$section->addTitle('Paragraph Border', 2);
$section->addText('Border red, 40 twip thick.', null, ['borderColor' => Font::FGCOLOR_RED, 'borderSize' => 40]);
$section->addText('Top cyan border, double line 20 twip thick', null, ['borderTopColor' => Font::FGCOLOR_CYAN, 'borderTopSize' => 20, 'borderTopStyle' => Border::DOUBLE]);
$section->addText('Left cyan border, double line 20 twip thick', null, ['borderLeftColor' => Font::FGCOLOR_CYAN, 'borderLeftSize' => 20, 'borderLeftStyle' => Border::DOUBLE]);
$section->addText('Right cyan border, double line 20 twip thick', null, ['borderRightColor' => Font::FGCOLOR_CYAN, 'borderRightSize' => 20, 'borderRightStyle' => Border::DOUBLE]);
$section->addText('Bottom cyan border, double line 20 twip thick', null, ['borderBottomColor' => Font::FGCOLOR_CYAN, 'borderBottomSize' => 20, 'borderBottomStyle' => Border::DOUBLE]);
$section->addText('Paragraphs don\'t have margins.');
$section->addTextBreak();

// Table Border.
$section->addTitle('Table Border', 2);
$section->addText('TODO');
$section->addTextBreak();

// Row Border.
$section->addTitle('Row Border', 2);
$section->addText('Not Yet Implemented in Row Style');
$section->addTextBreak();

// Cell Border.
$section->addTitle('Cell Border', 2);
$section->addText('TODO');
$section->addTextBreak();

// Font Border.
$section->addTitle('Font Border, aka Character Border', 2);
$section->addText('Not Yet Implemented in Font Style');
$section->addTextBreak();

// Border Styles.
$section->addTitle('Border Styles', 2);
$section->addText('Top border single line, bottom border dash dot stroke', null, ['borderTopStyle' => Border::SINGLE, 'borderBottomStyle' => Border::DASH_DOT_STROKED, 'borderTopColor' => Font::FGCOLOR_BLACK, 'borderTopSize' => 20, 'borderBottomColor' => Font::FGCOLOR_BLUE, 'borderBottomSize' => 20]);
$section->addText('Top border dashed, bottom border dash small gap', null, ['borderTopStyle' => Border::DASHED, 'borderBottomStyle' => Border::DASH_SMALL_GAP, 'borderTopColor' => Font::FGCOLOR_BLACK, 'borderTopSize' => 20, 'borderBottomColor' => Font::FGCOLOR_BLUE, 'borderBottomSize' => 20]);
$section->addText('Top border dot dash, bottom border dot dot dash', null, ['borderTopStyle' => Border::DOT_DASH, 'borderBottomStyle' => Border::DOT_DOT_DASH, 'borderTopColor' => Font::FGCOLOR_BLACK, 'borderTopSize' => 20, 'borderBottomColor' => Font::FGCOLOR_BLUE, 'borderBottomSize' => 20]);
$section->addText('Top border dotted, bottom border double line', null, ['borderTopStyle' => Border::DOTTED, 'borderBottomStyle' => Border::DOUBLE, 'borderTopColor' => Font::FGCOLOR_BLACK, 'borderTopSize' => 20, 'borderBottomColor' => Font::FGCOLOR_BLUE, 'borderBottomSize' => 20]);
$section->addText('Top border double wave, bottom border inset', null, ['borderTopStyle' => Border::DOUBLE_WAVE, 'borderBottomStyle' => Border::INSET, 'borderTopColor' => Font::FGCOLOR_BLACK, 'borderTopSize' => 20, 'borderBottomColor' => Font::FGCOLOR_BLUE, 'borderBottomSize' => 20]);
$section->addTextBreak();
$section->addText('No borders. Border set to nil and none.', null, ['borderTopStyle' => Border::NIL, 'borderBottomStyle' => Border::NONE, 'borderTopColor' => Font::FGCOLOR_BLACK, 'borderTopSize' => 20, 'borderBottomColor' => Font::FGCOLOR_BLUE, 'borderBottomSize' => 20]);
$section->addTextBreak();
$section->addText('Top border outset, bottom border thick', null, ['borderTopStyle' => Border::OUTSET, 'borderBottomStyle' => Border::THICK, 'borderTopColor' => Font::FGCOLOR_BLACK, 'borderTopSize' => 20, 'borderBottomColor' => Font::FGCOLOR_BLUE, 'borderBottomSize' => 20]);
$section->addText('Top border thick thin large gap, bottom border thick thin medium gap', null, ['borderTopStyle' => Border::THICK_THIN_LARGE_GAP, 'borderBottomStyle' => Border::THICK_THIN_MEDIUM_GAP, 'borderTopColor' => Font::FGCOLOR_BLACK, 'borderTopSize' => 20, 'borderBottomColor' => Font::FGCOLOR_BLUE, 'borderBottomSize' => 20]);
$section->addText('Top border thick thin small gap, bottom border thin thick large gap', null, ['borderTopStyle' => Border::THICK_THIN_SMALL_GAP, 'borderBottomStyle' => Border::THIN_THICK_LARGE_GAP, 'borderTopColor' => Font::FGCOLOR_BLACK, 'borderTopSize' => 20, 'borderBottomColor' => Font::FGCOLOR_BLUE, 'borderBottomSize' => 20]);
$section->addText('Top border tin thick medium gap, bottom border thin thick small gap', null, ['borderTopStyle' => Border::THIN_THICK_MEDIUM_GAP, 'borderBottomStyle' => Border::THIN_THICK_SMALL_GAP, 'borderTopColor' => Font::FGCOLOR_BLACK, 'borderTopSize' => 20, 'borderBottomColor' => Font::FGCOLOR_BLUE, 'borderBottomSize' => 20]);
$section->addText('Top border thin thick thin large gap, bottom border thin thick thin medium gap', null, ['borderTopStyle' => Border::THIN_THICK_THINLARGE_GAP, 'borderBottomStyle' => Border::THIN_THICK_THIN_MEDIUM_GAP, 'borderTopColor' => Font::FGCOLOR_BLACK, 'borderTopSize' => 20, 'borderBottomColor' => Font::FGCOLOR_BLUE, 'borderBottomSize' => 20]);
$section->addText('Top border thin thick thin small gap, bottom border three d emboss', null, ['borderTopStyle' => Border::THIN_THICK_THIN_SMALL_GAP, 'borderBottomStyle' => Border::THREE_D_EMBOSS, 'borderTopColor' => Font::FGCOLOR_BLACK, 'borderTopSize' => 20, 'borderBottomColor' => Font::FGCOLOR_BLUE, 'borderBottomSize' => 20]);
$section->addText('Top border three d engrave, bottom border triple line', null, ['borderTopStyle' => Border::THREE_D_ENGRAVE, 'borderBottomStyle' => Border::TRIPLE, 'borderTopColor' => Font::FGCOLOR_BLACK, 'borderTopSize' => 20, 'borderBottomColor' => Font::FGCOLOR_BLUE, 'borderBottomSize' => 20]);
$section->addText('Top border wave, bottom border single line', null, ['borderTopStyle' => Border::WAVE, 'borderBottomStyle' => Border::SINGLE, 'borderTopColor' => Font::FGCOLOR_BLACK, 'borderTopSize' => 20, 'borderBottomColor' => Font::FGCOLOR_BLUE, 'borderBottomSize' => 20]);

// Section Border.
$section = $phpWord->addSection(['borderLeftColor' => Font::FGCOLOR_MAGENTA, 'borderLeftSize' => 100, 'borderLeftStyle' => Border::DOUBLE_WAVE]);
$section->addTitle('Section Border', 2);
$section->addText('This is just a left border, magenta, double wave, 100 twip thick. Default margins.');

// Section Border.
$section = $phpWord->addSection(['borderRightColor' => Font::FGCOLOR_MAGENTA, 'borderRightSize' => 50, 'borderRightStyle' => Border::DOUBLE_WAVE, 'borderBottomColor' => Font::FGCOLOR_MAGENTA, 'borderBottomSize' => 50, 'borderBottomStyle' => Border::DOUBLE_WAVE]);
$section->addTitle('Section Border', 2);
$section->addText('This is just a right and bottom border, magenta, double wave, 50 twip thick. Default margins.');

// Section Border.
$section = $phpWord->addSection(['borderTopColor' => Font::FGCOLOR_MAGENTA, 'borderTopSize' => 400, 'borderTopStyle' => Border::TRIPLE]);
$section->addTitle('Section Border', 2);
$section->addText('This is top border, magenta, triple line, 400 twip thick. Default margins.');

// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}
155 changes: 155 additions & 0 deletions samples/TestSuite_Style_Font.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?php

use PhpOffice\PhpWord\Style\Font;

include_once 'Sample_Header.php';

// New Word Document
echo date('H:i:s') , ' Create new PhpWord object' , EOL;

$languageEnGb = new PhpOffice\PhpWord\Style\Language(PhpOffice\PhpWord\Style\Language::EN_GB);

$phpWord = new PhpOffice\PhpWord\PhpWord();
$phpWord->getSettings()->setThemeFontLang($languageEnGb);
$phpWord->addTitleStyle(1, ['bold' => true, 'underline' => 'single', 'size' => 18]);
$phpWord->addTitleStyle(2, ['bold' => true, 'underline' => 'single']);
$section = $phpWord->addSection();

$section->addTitle('Testing All Font Styles', 1);
$section->addText('See also: Style > Language');
$section->addText('See also: Style > Shading');
$section->addText('See also: Style > Spacing');
$section->addTextBreak();

// Default Font.
$phpWord->setDefaultFontName('Verdana');
$phpWord->setDefaultFontColor('341539');
$phpWord->setDefaultFontSize(11);
$section->addTitle('Default Font', 2);
$section->addText('Default font is Verdana, dark purple (#341539 or rgb 52,21,57), size 11');
$section->addTextBreak();

// Name.
$section->addTitle('Name', 2);
$section->addText('Arial', ['name' => 'Arial']);
$section->addText('Times New Roman', ['name' => 'Times New Roman']);
$section->addText('monospace', ['name' => 'monospace']);
$section->addText('Fallback aka Font Family set to serif', ['name' => 'Junkmail Garbage', 'fallback' => 'serif']);
$section->addText('Fallback aka Font Family set to sans-serif', ['name' => 'Junkmail Garbage', 'fallback' => 'sans-serif']);
$section->addText('Todo: Test Hint, Ascii, Ansi, and EastAsia, and CS');
$section->addTextBreak();

// RTL.
$section->addTitle('Right-to-Left', 2);
$section->addText('Hey, this font is going the other way!', ['rtl' => true]);
$section->addText('!yaw rehto eht gniog si tnof siht ,yeH', ['rtl' => true]);
$section->addTextBreak();

// Language.
$section->addTitle('Language', 2);
$section->addText('C\'est du français.', ['lang' => 'fr-FR']);
$section->addText('זה עברית.', ['lang' => 'he-IL']);
$section->addText('이것은 한국어입니다', ['name' => 'ko-KR']);
$section->addTextBreak();

// Color.
$section->addTitle('Color', 2);
$section->addText('Dark Green', ['color' => Font::FGCOLOR_DARKGREEN]);
$section->addText('Red', ['color' => Font::FGCOLOR_RED]);
$section->addText('Blue', ['color' => Font::FGCOLOR_BLUE]);
$section->addTextBreak();

// Size.
$section->addTitle('Size', 2);
$section->addText('8 point font', ['size' => 8]);
$section->addText('14 point font', ['size' => 14]);
$section->addText('24 point font', ['size' => 24]);
$section->addTextBreak();

// Bold, italic.
$section->addTitle('Bold/Italic', 2);
$section->addText('Bold', ['bold' => true]);
$section->addText('Italic', ['italic' => true]);
$section->addTextBreak();

// Strikethrough, double strikethrough.
$section->addTitle('Strikethrough', 2);
$section->addText('Strikethrough', ['strikethrough' => true]);
$section->addText('Double Strikethrough', ['doubleStrikethrough' => true]);
$section->addTextBreak();

// Small caps, all caps.
$section->addTitle('Caps', 2);
$section->addText('This Is A Small Caps Sentence.', ['smallCaps' => true]);
$section->addText('This Is An All-Caps Sentence.', ['allCaps' => true]);
$section->addTextBreak();

// Hidden.
$section->addTitle('Hidden Text (you should not be able to see the next line)', 2);
$section->addText('This sentence is hidden.', ['hidden' => true]);
$section->addTextBreak();

// Underline.
$section->addTitle('Underline', 2);
$textrun = $section->addTextRun();
$textrun->addText('This text is ');
$textrun->addText('underline none, ', ['underline' => Font::UNDERLINE_NONE]);
$textrun->addText('underline dash, ', ['underline' => Font::UNDERLINE_DASH]);
$textrun->addText('underline dash heavy, ', ['underline' => Font::UNDERLINE_DASHHEAVY]);
$textrun->addText('underline dash long, ', ['underline' => Font::UNDERLINE_DASHLONG]);
$textrun->addText('underline dash long heavy, ', ['underline' => Font::UNDERLINE_DASHLONGHEAVY]);
$textrun->addText('underline single, ', ['underline' => Font::UNDERLINE_SINGLE]);
$textrun->addText('underline double, ', ['underline' => Font::UNDERLINE_DOUBLE]);
$textrun->addText('underline heavy, ', ['underline' => Font::UNDERLINE_HEAVY]);
$textrun->addText('underline dot dash, ', ['underline' => Font::UNDERLINE_DOTDASH]);
$textrun->addText('underline dot dash heavy, ', ['underline' => Font::UNDERLINE_DOTDASHHEAVY]);
$textrun->addText('underline dot dot dash, ', ['underline' => Font::UNDERLINE_DOTDOTDASH]);
$textrun->addText('underline dot dot dash heavy, ', ['underline' => Font::UNDERLINE_DOTDOTDASHHEAVY]);
$textrun->addText('underline dotted, ', ['underline' => Font::UNDERLINE_DOTTED]);
$textrun->addText('underline dotted heavy, ', ['underline' => Font::UNDERLINE_DOTTEDHEAVY]);
$textrun->addText('underline wavy, ', ['underline' => Font::UNDERLINE_WAVY]);
$textrun->addText('underline wavy double, ', ['underline' => Font::UNDERLINE_WAVYDOUBLE]);
$textrun->addText('underline wavy heavy, ', ['underline' => Font::UNDERLINE_WAVYHEAVY]);
$textrun->addText('only the words are underlined and not the spaces.', ['underline' => Font::UNDERLINE_WORDS]);
$section->addTextBreak();

// Foreground Color.
$section->addTitle('Foreground Color, aka Highlight', 2);
$section->addText('Highlight yellow', ['fgColor' => Font::FGCOLOR_YELLOW]);
$section->addText('Highlight cyan', ['fgColor' => Font::FGCOLOR_CYAN]);
$section->addText('Highlight light gray', ['fgColor' => Font::FGCOLOR_LIGHTGRAY]);
$section->addTextBreak();

// Superscript, subscript, position.
$section->addTitle('Super/subscript', 2);
$textrun = $section->addTextRun();
$textrun->addText('This text is ');
$textrun->addText('superscript', ['superScript' => true]);
$textrun->addText(' and ');
$textrun->addText('subscript', ['subScript' => true]);
$textrun = $section->addTextRun();
$textrun->addText('This text is ');
$textrun->addText('raised half a step', ['position' => 8]);
$textrun->addText(' and ');
$textrun->addText('lowered half a step', ['position' => -8]);
$section->addTextBreak();

// noProof.
$section->addTitle('No Proof', 2);
$section->addText('Even thoughdffds pthispdsentence spdfi is full of tyhpeing errors, there should be no proofing.', ['noProof' => true]);
$section->addTextBreak();

// Whitespace.
$section->addTitle('For HTML Only', 2);
$section->addText('Lots of whitespace here.', ['whiteSpace' => 'pre-wrap']);
$section->addTextBreak();

// Contains Paragraph.
$section->addTitle('Font with embedded Paragraph Style', 2);
$section->addText('This text should be centered.', ['paragraph' => ['align' => 'center']]);

// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}
Loading
Loading