Skip to content

Commit a2294b4

Browse files
committed
Font: New scale, spacing, and kerning property of font style
1 parent 9c8620e commit a2294b4

File tree

9 files changed

+244
-87
lines changed

9 files changed

+244
-87
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
77
### Features
88

99
- Element: Ability to add drawing shapes (arc, curve, line, polyline, rect, oval) using new `Shape` element - @ivanlanin GH-123
10+
- Font: New `scale`, `spacing`, and `kerning` property of font style - @ivanlanin
1011

1112
### Bugfixes
1213

samples/Sample_01_SimpleText.php

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,43 @@
2323
$section->addText('I am styled by a paragraph style definition.', null, 'pStyle');
2424
$section->addText('I am styled by both font and paragraph style.', 'rStyle', 'pStyle');
2525

26-
$section->addPageBreak();
26+
$section->addTextBreak();
2727

2828
// Inline font style
2929
$fontStyle['name'] = 'Times New Roman';
3030
$fontStyle['size'] = 20;
31-
$fontStyle['bold'] = true;
32-
$fontStyle['italic'] = true;
33-
$fontStyle['underline'] = 'dash';
34-
$fontStyle['strikethrough'] = true;
35-
$fontStyle['superScript'] = true;
36-
$fontStyle['color'] = 'FF0000';
37-
$fontStyle['fgColor'] = 'yellow';
38-
$fontStyle['smallCaps'] = true;
39-
$section->addText('I am inline styled.', $fontStyle);
4031

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

4364
// Link
4465
$section->addLink('http://www.google.com', 'Google');

src/PhpWord/IOFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ private static function createObject($type, $name, $phpWord = null)
7575
*/
7676
public static function load($filename, $readerName = 'Word2007')
7777
{
78+
/** @var \PhpOffice\PhpWord\Reader\ReaderInterface $reader */
7879
$reader = self::createReader($readerName);
7980

8081
return $reader->load($filename);

src/PhpWord/Style/AbstractStyle.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ public function setAuto($value = true)
126126
return $this;
127127
}
128128

129+
/**
130+
* Return style value of child style object, e.g. `left` from `Indentation` child style of `Paragraph`
131+
*
132+
* @param \PhpOffice\PhpWord\Style\AbstractStyle $substyleObject
133+
* @param string $substyleProperty
134+
* @return mixed
135+
* @since 0.12.0
136+
*/
137+
public function getChildStyleValue($substyleObject, $substyleProperty)
138+
{
139+
if ($substyleObject !== null) {
140+
$method = "get{$substyleProperty}";
141+
return $substyleObject->$method();
142+
} else {
143+
return null;
144+
}
145+
}
146+
129147
/**
130148
* Set style value template method
131149
*
@@ -296,6 +314,24 @@ protected function setObjectVal($value, $styleName, &$style)
296314
return $style;
297315
}
298316

317+
/**
318+
* Set $property value and set $pairProperty = false when $value = true
319+
*
320+
* @param bool $property
321+
* @param bool $pairProperty
322+
* @param bool $value
323+
* @return self
324+
*/
325+
protected function setPairedVal(&$property, &$pairProperty, $value)
326+
{
327+
$property = $this->setBoolVal($value, $property);
328+
if ($value == true) {
329+
$pairProperty = false;
330+
}
331+
332+
return $this;
333+
}
334+
299335
/**
300336
* Set style using associative array
301337
*

0 commit comments

Comments
 (0)