Skip to content

Commit 1d84c1d

Browse files
committed
#151 Small caps, all caps, and double strikethrough; #199 Ability to use measurement unit other than twips
1 parent 1a1356a commit 1d84c1d

File tree

15 files changed

+197
-43
lines changed

15 files changed

+197
-43
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ This release marked heavy refactorings on internal code structure with the creat
3939
- ODT Writer: Basic image writing - @ivanlanin
4040
- ODT Writer: Link writing - @ivanlanin
4141
- ODT Reader: Basic ODText Reader - @ivanlanin GH-71
42-
- Section: Ability to define gutter and line numbering
42+
- Section: Ability to define gutter and line numbering - @ivanlanin
43+
- Font: Small caps, all caps, and double strikethrough - @ivanlanin GH-151
44+
- Settings: Ability to use measurement unit other than twips with `setMeasurementUnit` - @ivanlanin GH-199
4345

4446
### Bugfixes
4547

docs/elements.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,12 @@ Available font styles:
112112
- ``subScript`` Subscript, *true* or *false*
113113
- ``underline`` Underline, *dash*, *dotted*, etc.
114114
- ``strikethrough`` Strikethrough, *true* or *false*
115+
- ``doubleStrikethrough`` Double strikethrough, *true* or *false*
115116
- ``color`` Font color, e.g. *FF0000*
116117
- ``fgColor`` Font highlight color, e.g. *yellow*, *green*, *blue*
117118
- ``bgColor`` Font background color, e.g. *FF0000*
119+
- ``smallCaps`` Small caps, *true* or *false*
120+
- ``allCaps`` All caps, *true* or *false*
118121

119122
Paragraph style
120123
^^^^^^^^^^^^^^^

docs/src/documentation.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,12 @@ Available font styles:
515515
- `subScript` Subscript, *true* or *false*
516516
- `underline` Underline, *dash*, *dotted*, etc.
517517
- `strikethrough` Strikethrough, *true* or *false*
518+
- `doubleStrikethrough` Double strikethrough, *true* or *false*
518519
- `color` Font color, e.g. *FF0000*
519520
- `fgColor` Font highlight color, e.g. *yellow*, *green*, *blue*
520521
- `bgColor` Font background color, e.g. *FF0000*
522+
- `smallCaps` Small caps, *true* or *false*
523+
- `allCaps` All caps, *true* or *false*
521524

522525
#### Paragraph style
523526

samples/Sample_01_SimpleText.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// New Word Document
55
echo date('H:i:s') , " Create new PhpWord object" , EOL;
66
$phpWord = new \PhpOffice\PhpWord\PhpWord();
7-
$phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16));
7+
$phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true));
88
$phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100));
99
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
1010

@@ -34,6 +34,7 @@
3434
$fontStyle['superScript'] = true;
3535
$fontStyle['color'] = 'FF0000';
3636
$fontStyle['fgColor'] = 'yellow';
37+
$fontStyle['smallCaps'] = true;
3738
$section->addText('I am inline styled.', $fontStyle);
3839
$section->addTextBreak();
3940

src/PhpWord/Style/Font.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
*/
1818
class Font extends AbstractStyle
1919
{
20+
/**
21+
* Underline types
22+
*
23+
* @const string
24+
*/
2025
const UNDERLINE_NONE = 'none';
2126
const UNDERLINE_DASH = 'dash';
2227
const UNDERLINE_DASHHEAVY = 'dashHeavy';
@@ -35,6 +40,12 @@ class Font extends AbstractStyle
3540
const UNDERLINE_WAVYDOUBLE = 'wavyDbl';
3641
const UNDERLINE_WAVYHEAVY = 'wavyHeavy';
3742
const UNDERLINE_WORDS = 'words';
43+
44+
/**
45+
* Foreground colors
46+
*
47+
* @const string
48+
*/
3849
const FGCOLOR_YELLOW = 'yellow';
3950
const FGCOLOR_LIGHTGREEN = 'green';
4051
const FGCOLOR_CYAN = 'cyan';
@@ -121,6 +132,13 @@ class Font extends AbstractStyle
121132
*/
122133
private $strikethrough = false;
123134

135+
/**
136+
* Double strikethrough
137+
*
138+
* @var bool
139+
*/
140+
private $doubleStrikethrough = false;
141+
124142
/**
125143
* Font color
126144
*
@@ -161,6 +179,22 @@ class Font extends AbstractStyle
161179
*/
162180
private $hint = PhpWord::DEFAULT_FONT_CONTENT_TYPE;
163181

182+
/**
183+
* Small caps
184+
*
185+
* @var bool
186+
* @link http://www.schemacentral.com/sc/ooxml/e-w_smallCaps-1.html
187+
*/
188+
private $smallCaps = false;
189+
190+
/**
191+
* All caps
192+
*
193+
* @var bool
194+
* @link http://www.schemacentral.com/sc/ooxml/e-w_caps-1.html
195+
*/
196+
private $allCaps = false;
197+
164198
/**
165199
* Create new font style
166200
*
@@ -387,6 +421,35 @@ public function getStrikethrough()
387421
public function setStrikethrough($value = false)
388422
{
389423
$this->strikethrough = $this->setBoolVal($value, $this->strikethrough);
424+
if ($this->strikethrough) {
425+
$this->doubleStrikethrough = false;
426+
}
427+
428+
return $this;
429+
}
430+
431+
/**
432+
* Get double strikethrough
433+
*
434+
* @return bool
435+
*/
436+
public function getDoubleStrikethrough()
437+
{
438+
return $this->doubleStrikethrough;
439+
}
440+
441+
/**
442+
* Set double strikethrough
443+
*
444+
* @param bool $value
445+
* @return self
446+
*/
447+
public function setDoubleStrikethrough($value = false)
448+
{
449+
$this->doubleStrikethrough = $this->setBoolVal($value, $this->doubleStrikethrough);
450+
if ($this->doubleStrikethrough) {
451+
$this->strikethrough = false;
452+
}
390453

391454
return $this;
392455
}
@@ -534,4 +597,56 @@ public function setHint($value = PhpWord::DEFAULT_FONT_CONTENT_TYPE)
534597

535598
return $this;
536599
}
600+
601+
/**
602+
* Get small caps
603+
*
604+
* @return bool
605+
*/
606+
public function getSmallCaps()
607+
{
608+
return $this->smallCaps;
609+
}
610+
611+
/**
612+
* Set small caps
613+
*
614+
* @param bool $value
615+
* @return self
616+
*/
617+
public function setSmallCaps($value = false)
618+
{
619+
$this->smallCaps = $this->setBoolVal($value, $this->smallCaps);
620+
if ($this->smallCaps) {
621+
$this->allCaps = false;
622+
}
623+
624+
return $this;
625+
}
626+
627+
/**
628+
* Get all caps
629+
*
630+
* @return bool
631+
*/
632+
public function getAllCaps()
633+
{
634+
return $this->allCaps;
635+
}
636+
637+
/**
638+
* Set all caps
639+
*
640+
* @param bool $value
641+
* @return self
642+
*/
643+
public function setAllCaps($value = false)
644+
{
645+
$this->allCaps = $this->setBoolVal($value, $this->allCaps);
646+
if ($this->allCaps) {
647+
$this->smallCaps = false;
648+
}
649+
650+
return $this;
651+
}
537652
}

src/PhpWord/Style/LineNumbering.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class LineNumbering extends AbstractStyle
5252

5353
/**
5454
* Create a new instance
55+
*
56+
* @param array $style
5557
*/
5658
public function __construct($style = null)
5759
{

src/PhpWord/Style/Section.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ public function setSettingValue($key, $value)
162162

163163
/**
164164
* Set orientation
165+
*
166+
* @param string $value
167+
* @return self
165168
*/
166169
public function setOrientation($value = null)
167170
{
@@ -177,6 +180,8 @@ public function setOrientation($value = null)
177180
$this->pageSizeW = $longSize;
178181
$this->pageSizeH = $shortSize;
179182
}
183+
184+
return $this;
180185
}
181186

182187
/**
@@ -191,18 +196,22 @@ public function getOrientation()
191196

192197
/**
193198
* Set Portrait Orientation
199+
*
200+
* @return self
194201
*/
195202
public function setPortrait()
196203
{
197-
$this->setOrientation(self::ORIENTATION_PORTRAIT);
204+
return $this->setOrientation(self::ORIENTATION_PORTRAIT);
198205
}
199206

200207
/**
201208
* Set Landscape Orientation
209+
*
210+
* @return self
202211
*/
203212
public function setLandscape()
204213
{
205-
$this->setOrientation(self::ORIENTATION_LANDSCAPE);
214+
return $this->setOrientation(self::ORIENTATION_LANDSCAPE);
206215
}
207216

208217
/**

src/PhpWord/Writer/HTML/Element/Text.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function write()
3131
$html = '';
3232
// Paragraph style
3333
$paragraphStyle = $this->element->getParagraphStyle();
34-
$paragraphStyleIsObject = ($paragraphStyle instanceof Paragraph);
35-
if ($paragraphStyleIsObject) {
34+
$pStyleIsObject = ($paragraphStyle instanceof Paragraph);
35+
if ($pStyleIsObject) {
3636
$styleWriter = new ParagraphStyleWriter($paragraphStyle);
3737
$paragraphStyle = $styleWriter->write();
3838
}
@@ -45,7 +45,7 @@ public function write()
4545
}
4646

4747
if ($paragraphStyle && !$this->withoutP) {
48-
$attribute = $paragraphStyleIsObject ? 'style' : 'class';
48+
$attribute = $pStyleIsObject ? 'style' : 'class';
4949
$html .= "<p {$attribute}=\"{$paragraphStyle}\">";
5050
}
5151
if ($fontStyle) {

src/PhpWord/Writer/HTML/Element/TextRun.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public function write()
3131
if (count($elements) > 0) {
3232
// Paragraph style
3333
$paragraphStyle = $this->element->getParagraphStyle();
34-
$paragraphStyleIsObject = ($paragraphStyle instanceof Paragraph);
35-
if ($paragraphStyleIsObject) {
34+
$pStyleIsObject = ($paragraphStyle instanceof Paragraph);
35+
if ($pStyleIsObject) {
3636
$styleWriter = new ParagraphStyleWriter($paragraphStyle);
3737
$paragraphStyle = $styleWriter->write();
3838
}
3939
$tag = $this->withoutP ? 'span' : 'p';
40-
$attribute = $paragraphStyleIsObject ? 'style' : 'class';
40+
$attribute = $pStyleIsObject ? 'style' : 'class';
4141
$html .= "<{$tag} {$attribute}=\"{$paragraphStyle}\">";
4242
foreach ($elements as $element) {
4343
$elementWriter = new Element($this->parentWriter, $element, true);

0 commit comments

Comments
 (0)