Skip to content

Commit

Permalink
PHPOffice#151 Small caps, all caps, and double strikethrough; PHPOffi…
Browse files Browse the repository at this point in the history
…ce#199 Ability to use measurement unit other than twips
  • Loading branch information
ivanlanin committed May 1, 2014
1 parent 1a1356a commit 1d84c1d
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 43 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ This release marked heavy refactorings on internal code structure with the creat
- ODT Writer: Basic image writing - @ivanlanin
- ODT Writer: Link writing - @ivanlanin
- ODT Reader: Basic ODText Reader - @ivanlanin GH-71
- Section: Ability to define gutter and line numbering
- Section: Ability to define gutter and line numbering - @ivanlanin
- Font: Small caps, all caps, and double strikethrough - @ivanlanin GH-151
- Settings: Ability to use measurement unit other than twips with `setMeasurementUnit` - @ivanlanin GH-199

### Bugfixes

Expand Down
3 changes: 3 additions & 0 deletions docs/elements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,12 @@ Available font styles:
- ``subScript`` Subscript, *true* or *false*
- ``underline`` Underline, *dash*, *dotted*, etc.
- ``strikethrough`` Strikethrough, *true* or *false*
- ``doubleStrikethrough`` Double strikethrough, *true* or *false*
- ``color`` Font color, e.g. *FF0000*
- ``fgColor`` Font highlight color, e.g. *yellow*, *green*, *blue*
- ``bgColor`` Font background color, e.g. *FF0000*
- ``smallCaps`` Small caps, *true* or *false*
- ``allCaps`` All caps, *true* or *false*

Paragraph style
^^^^^^^^^^^^^^^
Expand Down
3 changes: 3 additions & 0 deletions docs/src/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,12 @@ Available font styles:
- `subScript` Subscript, *true* or *false*
- `underline` Underline, *dash*, *dotted*, etc.
- `strikethrough` Strikethrough, *true* or *false*
- `doubleStrikethrough` Double strikethrough, *true* or *false*
- `color` Font color, e.g. *FF0000*
- `fgColor` Font highlight color, e.g. *yellow*, *green*, *blue*
- `bgColor` Font background color, e.g. *FF0000*
- `smallCaps` Small caps, *true* or *false*
- `allCaps` All caps, *true* or *false*

#### Paragraph style

Expand Down
3 changes: 2 additions & 1 deletion samples/Sample_01_SimpleText.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// New Word Document
echo date('H:i:s') , " Create new PhpWord object" , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16));
$phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true));
$phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100));
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));

Expand Down Expand Up @@ -34,6 +34,7 @@
$fontStyle['superScript'] = true;
$fontStyle['color'] = 'FF0000';
$fontStyle['fgColor'] = 'yellow';
$fontStyle['smallCaps'] = true;
$section->addText('I am inline styled.', $fontStyle);
$section->addTextBreak();

Expand Down
115 changes: 115 additions & 0 deletions src/PhpWord/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/
class Font extends AbstractStyle
{
/**
* Underline types
*
* @const string
*/
const UNDERLINE_NONE = 'none';
const UNDERLINE_DASH = 'dash';
const UNDERLINE_DASHHEAVY = 'dashHeavy';
Expand All @@ -35,6 +40,12 @@ class Font extends AbstractStyle
const UNDERLINE_WAVYDOUBLE = 'wavyDbl';
const UNDERLINE_WAVYHEAVY = 'wavyHeavy';
const UNDERLINE_WORDS = 'words';

/**
* Foreground colors
*
* @const string
*/
const FGCOLOR_YELLOW = 'yellow';
const FGCOLOR_LIGHTGREEN = 'green';
const FGCOLOR_CYAN = 'cyan';
Expand Down Expand Up @@ -121,6 +132,13 @@ class Font extends AbstractStyle
*/
private $strikethrough = false;

/**
* Double strikethrough
*
* @var bool
*/
private $doubleStrikethrough = false;

/**
* Font color
*
Expand Down Expand Up @@ -161,6 +179,22 @@ class Font extends AbstractStyle
*/
private $hint = PhpWord::DEFAULT_FONT_CONTENT_TYPE;

/**
* Small caps
*
* @var bool
* @link http:https://www.schemacentral.com/sc/ooxml/e-w_smallCaps-1.html
*/
private $smallCaps = false;

/**
* All caps
*
* @var bool
* @link http:https://www.schemacentral.com/sc/ooxml/e-w_caps-1.html
*/
private $allCaps = false;

/**
* Create new font style
*
Expand Down Expand Up @@ -387,6 +421,35 @@ public function getStrikethrough()
public function setStrikethrough($value = false)
{
$this->strikethrough = $this->setBoolVal($value, $this->strikethrough);
if ($this->strikethrough) {
$this->doubleStrikethrough = false;
}

return $this;
}

/**
* Get double strikethrough
*
* @return bool
*/
public function getDoubleStrikethrough()
{
return $this->doubleStrikethrough;
}

/**
* Set double strikethrough
*
* @param bool $value
* @return self
*/
public function setDoubleStrikethrough($value = false)
{
$this->doubleStrikethrough = $this->setBoolVal($value, $this->doubleStrikethrough);
if ($this->doubleStrikethrough) {
$this->strikethrough = false;
}

return $this;
}
Expand Down Expand Up @@ -534,4 +597,56 @@ public function setHint($value = PhpWord::DEFAULT_FONT_CONTENT_TYPE)

return $this;
}

/**
* Get small caps
*
* @return bool
*/
public function getSmallCaps()
{
return $this->smallCaps;
}

/**
* Set small caps
*
* @param bool $value
* @return self
*/
public function setSmallCaps($value = false)
{
$this->smallCaps = $this->setBoolVal($value, $this->smallCaps);
if ($this->smallCaps) {
$this->allCaps = false;
}

return $this;
}

/**
* Get all caps
*
* @return bool
*/
public function getAllCaps()
{
return $this->allCaps;
}

/**
* Set all caps
*
* @param bool $value
* @return self
*/
public function setAllCaps($value = false)
{
$this->allCaps = $this->setBoolVal($value, $this->allCaps);
if ($this->allCaps) {
$this->smallCaps = false;
}

return $this;
}
}
2 changes: 2 additions & 0 deletions src/PhpWord/Style/LineNumbering.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class LineNumbering extends AbstractStyle

/**
* Create a new instance
*
* @param array $style
*/
public function __construct($style = null)
{
Expand Down
13 changes: 11 additions & 2 deletions src/PhpWord/Style/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ public function setSettingValue($key, $value)

/**
* Set orientation
*
* @param string $value
* @return self
*/
public function setOrientation($value = null)
{
Expand All @@ -177,6 +180,8 @@ public function setOrientation($value = null)
$this->pageSizeW = $longSize;
$this->pageSizeH = $shortSize;
}

return $this;
}

/**
Expand All @@ -191,18 +196,22 @@ public function getOrientation()

/**
* Set Portrait Orientation
*
* @return self
*/
public function setPortrait()
{
$this->setOrientation(self::ORIENTATION_PORTRAIT);
return $this->setOrientation(self::ORIENTATION_PORTRAIT);
}

/**
* Set Landscape Orientation
*
* @return self
*/
public function setLandscape()
{
$this->setOrientation(self::ORIENTATION_LANDSCAPE);
return $this->setOrientation(self::ORIENTATION_LANDSCAPE);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/PhpWord/Writer/HTML/Element/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function write()
$html = '';
// Paragraph style
$paragraphStyle = $this->element->getParagraphStyle();
$paragraphStyleIsObject = ($paragraphStyle instanceof Paragraph);
if ($paragraphStyleIsObject) {
$pStyleIsObject = ($paragraphStyle instanceof Paragraph);
if ($pStyleIsObject) {
$styleWriter = new ParagraphStyleWriter($paragraphStyle);
$paragraphStyle = $styleWriter->write();
}
Expand All @@ -45,7 +45,7 @@ public function write()
}

if ($paragraphStyle && !$this->withoutP) {
$attribute = $paragraphStyleIsObject ? 'style' : 'class';
$attribute = $pStyleIsObject ? 'style' : 'class';
$html .= "<p {$attribute}=\"{$paragraphStyle}\">";
}
if ($fontStyle) {
Expand Down
6 changes: 3 additions & 3 deletions src/PhpWord/Writer/HTML/Element/TextRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public function write()
if (count($elements) > 0) {
// Paragraph style
$paragraphStyle = $this->element->getParagraphStyle();
$paragraphStyleIsObject = ($paragraphStyle instanceof Paragraph);
if ($paragraphStyleIsObject) {
$pStyleIsObject = ($paragraphStyle instanceof Paragraph);
if ($pStyleIsObject) {
$styleWriter = new ParagraphStyleWriter($paragraphStyle);
$paragraphStyle = $styleWriter->write();
}
$tag = $this->withoutP ? 'span' : 'p';
$attribute = $paragraphStyleIsObject ? 'style' : 'class';
$attribute = $pStyleIsObject ? 'style' : 'class';
$html .= "<{$tag} {$attribute}=\"{$paragraphStyle}\">";
foreach ($elements as $element) {
$elementWriter = new Element($this->parentWriter, $element, true);
Expand Down
Loading

0 comments on commit 1d84c1d

Please sign in to comment.