Skip to content

suport for eastAsia fontstyle #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 13, 2014
Merged
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ vendor
*.docx
*.rtf
*.txt
*.xml
*.xml
nbproject
6 changes: 5 additions & 1 deletion Classes/PHPWord.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ class PHPWord
* Default font name (Arial)
*/
const DEFAULT_FONT_NAME = 'Arial';

/**
* Default Font Content Type(default)
* default|eastAsia|cs
*/
const DEFAULT_FONT_CONTENT_TYPE='default';
/**
* Default font size in points (10pt)
*
Expand Down
118 changes: 59 additions & 59 deletions Classes/PHPWord/Style/Font.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHPWord
*
Expand All @@ -24,14 +25,13 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.7.0
*/

use PhpOffice\PhpWord\Exceptions\InvalidStyleException;

/**
* Class PHPWord_Style_Font
*/
class PHPWord_Style_Font
{
class PHPWord_Style_Font {

const UNDERLINE_NONE = 'none';
const UNDERLINE_DASH = 'dash';
const UNDERLINE_DASHHEAVY = 'dashHeavy';
Expand All @@ -50,7 +50,6 @@ class PHPWord_Style_Font
const UNDERLINE_WAVYDOUBLE = 'wavyDbl';
const UNDERLINE_WAVYHEAVY = 'wavyHeavy';
const UNDERLINE_WORDS = 'words';

const FGCOLOR_YELLOW = 'yellow';
const FGCOLOR_LIGHTGREEN = 'green';
const FGCOLOR_CYAN = 'cyan';
Expand Down Expand Up @@ -158,14 +157,20 @@ class PHPWord_Style_Font
*/
private $lineHeight = 1.0;

/**
* Font Content Type
*
* @var string
*/
private $_hint = PHPWord::DEFAULT_FONT_CONTENT_TYPE;

/**
* New font style
*
* @param string $type Type of font
* @param array $paragraphStyle Paragraph styles definition
*/
public function __construct($type = 'text', $paragraphStyle = null)
{
public function __construct($type = 'text', $paragraphStyle = null) {
$this->_type = $type;

if ($paragraphStyle instanceof PHPWord_Style_Paragraph) {
Expand All @@ -184,8 +189,7 @@ public function __construct($type = 'text', $paragraphStyle = null)
* @param array $style
* @return $this
*/
public function setArrayStyle(array $style = array())
{
public function setArrayStyle(array $style = array()) {
foreach ($style as $key => $value) {
if ($key === 'line-height') {
$this->setLineHeight($value);
Expand All @@ -205,8 +209,7 @@ public function setArrayStyle(array $style = array())
* @param string $key
* @param mixed $value
*/
public function setStyleValue($key, $value)
{
public function setStyleValue($key, $value) {
$method = 'set' . substr($key, 1);
if (method_exists($this, $method)) {
$this->$method($value);
Expand All @@ -218,8 +221,7 @@ public function setStyleValue($key, $value)
*
* @return bool
*/
public function getName()
{
public function getName() {
return $this->_name;
}

Expand All @@ -229,22 +231,21 @@ public function getName()
* @param string $pValue
* @return PHPWord_Style_Font
*/
public function setName($pValue = PHPWord::DEFAULT_FONT_NAME)
{
public function setName($pValue = PHPWord::DEFAULT_FONT_NAME) {
if (is_null($pValue) || $pValue == '') {
$pValue = PHPWord::DEFAULT_FONT_NAME;
}
$this->_name = $pValue;
return $this;
}


/**
* Get font size
*
* @return int|float
*/
public function getSize()
{
public function getSize() {
return $this->_size;
}

Expand All @@ -254,8 +255,7 @@ public function getSize()
* @param int|float $pValue
* @return PHPWord_Style_Font
*/
public function setSize($pValue = PHPWord::DEFAULT_FONT_SIZE)
{
public function setSize($pValue = PHPWord::DEFAULT_FONT_SIZE) {
if (!is_numeric($pValue)) {
$pValue = PHPWord::DEFAULT_FONT_SIZE;
}
Expand All @@ -268,8 +268,7 @@ public function setSize($pValue = PHPWord::DEFAULT_FONT_SIZE)
*
* @return bool
*/
public function getBold()
{
public function getBold() {
return $this->_bold;
}

Expand All @@ -279,8 +278,7 @@ public function getBold()
* @param bool $pValue
* @return PHPWord_Style_Font
*/
public function setBold($pValue = false)
{
public function setBold($pValue = false) {
if (!is_bool($pValue)) {
$pValue = false;
}
Expand All @@ -293,8 +291,7 @@ public function setBold($pValue = false)
*
* @return bool
*/
public function getItalic()
{
public function getItalic() {
return $this->_italic;
}

Expand All @@ -304,8 +301,7 @@ public function getItalic()
* @param bool $pValue
* @return PHPWord_Style_Font
*/
public function setItalic($pValue = false)
{
public function setItalic($pValue = false) {
if (!is_bool($pValue)) {
$pValue = false;
}
Expand All @@ -318,8 +314,7 @@ public function setItalic($pValue = false)
*
* @return bool
*/
public function getSuperScript()
{
public function getSuperScript() {
return $this->_superScript;
}

Expand All @@ -329,8 +324,7 @@ public function getSuperScript()
* @param bool $pValue
* @return PHPWord_Style_Font
*/
public function setSuperScript($pValue = false)
{
public function setSuperScript($pValue = false) {
if (!is_bool($pValue)) {
$pValue = false;
}
Expand All @@ -344,8 +338,7 @@ public function setSuperScript($pValue = false)
*
* @return bool
*/
public function getSubScript()
{
public function getSubScript() {
return $this->_subScript;
}

Expand All @@ -355,8 +348,7 @@ public function getSubScript()
* @param bool $pValue
* @return PHPWord_Style_Font
*/
public function setSubScript($pValue = false)
{
public function setSubScript($pValue = false) {
if (!is_bool($pValue)) {
$pValue = false;
}
Expand All @@ -370,8 +362,7 @@ public function setSubScript($pValue = false)
*
* @return string
*/
public function getUnderline()
{
public function getUnderline() {
return $this->_underline;
}

Expand All @@ -381,8 +372,7 @@ public function getUnderline()
* @param string $pValue
* @return PHPWord_Style_Font
*/
public function setUnderline($pValue = PHPWord_Style_Font::UNDERLINE_NONE)
{
public function setUnderline($pValue = PHPWord_Style_Font::UNDERLINE_NONE) {
if ($pValue == '') {
$pValue = PHPWord_Style_Font::UNDERLINE_NONE;
}
Expand All @@ -395,8 +385,7 @@ public function setUnderline($pValue = PHPWord_Style_Font::UNDERLINE_NONE)
*
* @return bool
*/
public function getStrikethrough()
{
public function getStrikethrough() {
return $this->_strikethrough;
}

Expand All @@ -406,8 +395,7 @@ public function getStrikethrough()
* @param bool $pValue
* @return PHPWord_Style_Font
*/
public function setStrikethrough($pValue = false)
{
public function setStrikethrough($pValue = false) {
if (!is_bool($pValue)) {
$pValue = false;
}
Expand All @@ -420,8 +408,7 @@ public function setStrikethrough($pValue = false)
*
* @return string
*/
public function getColor()
{
public function getColor() {
return $this->_color;
}

Expand All @@ -431,8 +418,7 @@ public function getColor()
* @param string $pValue
* @return PHPWord_Style_Font
*/
public function setColor($pValue = PHPWord::DEFAULT_FONT_COLOR)
{
public function setColor($pValue = PHPWord::DEFAULT_FONT_COLOR) {
if (is_null($pValue) || $pValue == '') {
$pValue = PHPWord::DEFAULT_FONT_COLOR;
}
Expand All @@ -445,8 +431,7 @@ public function setColor($pValue = PHPWord::DEFAULT_FONT_COLOR)
*
* @return bool
*/
public function getFgColor()
{
public function getFgColor() {
return $this->_fgColor;
}

Expand All @@ -456,8 +441,7 @@ public function getFgColor()
* @param string $pValue
* @return PHPWord_Style_Font
*/
public function setFgColor($pValue = null)
{
public function setFgColor($pValue = null) {
$this->_fgColor = $pValue;
return $this;
}
Expand All @@ -467,8 +451,7 @@ public function setFgColor($pValue = null)
*
* @return string
*/
public function getStyleType()
{
public function getStyleType() {
return $this->_type;
}

Expand All @@ -477,21 +460,18 @@ public function getStyleType()
*
* @return PHPWord_Style_Paragraph
*/
public function getParagraphStyle()
{
public function getParagraphStyle() {
return $this->_paragraphStyle;
}


/**
* Set the line height
*
* @param int|float|string $lineHeight
* @return $this
* @throws InvalidStyleException
*/
public function setLineHeight($lineHeight)
{
public function setLineHeight($lineHeight) {
if (is_string($lineHeight)) {
$lineHeight = floatval(preg_replace('/[^0-9\.\,]/', '', $lineHeight));
}
Expand All @@ -508,8 +488,28 @@ public function setLineHeight($lineHeight)
/**
* @return int|float
*/
public function getLineHeight()
{
public function getLineHeight() {
return $this->lineHeight;
}
/**
* Get Font Content Type
*
* @return bool
*/
public function getHint() {
return $this->_hint;
}
/**
* Set Font Content Type
*
* @param string $pValue
* @return PHPWord_Style_Font
*/
public function setHint($pValue = PHPWord::DEFAULT_FONT_CONTENT_TYPE) {
if (is_null($pValue) || $pValue == '') {
$pValue = PHPWord::DEFAULT_FONT_CONTENT_TYPE;
}
$this->_hint = $pValue;
return $this;
}
}
Loading