Use constant instead of hardcoded 'Arial' name.

This commit is contained in:
Ivan Lanin 2014-02-22 22:52:19 +07:00
parent b0a24703f3
commit eb6b44ef85
6 changed files with 22 additions and 19 deletions

View File

@ -39,6 +39,9 @@ if (!defined('PHPWORD_BASE_PATH')) {
class PHPWord class PHPWord
{ {
const DEFAULT_FONT_NAME = 'Arial';
const DEFAULT_FONT_SIZE = 20;
/** /**
* Document properties * Document properties
* *
@ -74,8 +77,8 @@ class PHPWord
public function __construct() public function __construct()
{ {
$this->_properties = new PHPWord_DocumentProperties(); $this->_properties = new PHPWord_DocumentProperties();
$this->_defaultFontName = 'Arial'; $this->_defaultFontName = PHPWord::DEFAULT_FONT_NAME;
$this->_defaultFontSize = 20; $this->_defaultFontSize = PHPWord::DEFAULT_FONT_SIZE;
} }
/** /**

View File

@ -94,8 +94,8 @@ class PHPWord_Style_Font
public function __construct($type = 'text', $styleParagraph = null) public function __construct($type = 'text', $styleParagraph = null)
{ {
$this->_type = $type; $this->_type = $type;
$this->_name = 'Arial'; $this->_name = PHPWord::DEFAULT_FONT_NAME;
$this->_size = 20; $this->_size = PHPWord::DEFAULT_FONT_SIZE;
$this->_bold = false; $this->_bold = false;
$this->_italic = false; $this->_italic = false;
$this->_superScript = false; $this->_superScript = false;
@ -132,10 +132,10 @@ class PHPWord_Style_Font
$this->$key = $value; $this->$key = $value;
} }
public function setName($pValue = 'Arial') public function setName($pValue = PHPWord::DEFAULT_FONT_NAME)
{ {
if ($pValue == '') { if ($pValue == '') {
$pValue = 'Arial'; $pValue = PHPWord::DEFAULT_FONT_NAME;
} }
$this->_name = $pValue; $this->_name = $pValue;
return $this; return $this;
@ -146,10 +146,10 @@ class PHPWord_Style_Font
return $this->_size; return $this->_size;
} }
public function setSize($pValue = 20) public function setSize($pValue = PHPWord::DEFAULT_FONT_SIZE)
{ {
if ($pValue == '') { if ($pValue == '') {
$pValue = 20; $pValue = PHPWord::DEFAULT_FONT_SIZE;
} }
$this->_size = ($pValue * 2); $this->_size = ($pValue * 2);
return $this; return $this;

View File

@ -145,10 +145,10 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
} }
} }
} }
if (!in_array('Arial', $arrFonts)) { if (!in_array(PHPWord::DEFAULT_FONT_NAME, $arrFonts)) {
$objWriter->startElement('style:font-face'); $objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', 'Arial'); $objWriter->writeAttribute('style:name', PHPWord::DEFAULT_FONT_NAME);
$objWriter->writeAttribute('svg:font-family', 'Arial'); $objWriter->writeAttribute('svg:font-family', PHPWord::DEFAULT_FONT_NAME);
$objWriter->endElement(); $objWriter->endElement();
} }
} }

View File

@ -104,10 +104,10 @@ class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
} }
} }
} }
if (!in_array('Arial', $arrFonts)) { if (!in_array(PHPWord::DEFAULT_FONT_NAME, $arrFonts)) {
$objWriter->startElement('style:font-face'); $objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', 'Arial'); $objWriter->writeAttribute('style:name', PHPWord::DEFAULT_FONT_NAME);
$objWriter->writeAttribute('svg:font-family', 'Arial'); $objWriter->writeAttribute('svg:font-family', PHPWord::DEFAULT_FONT_NAME);
$objWriter->endElement(); $objWriter->endElement();
} }
$objWriter->endElement(); $objWriter->endElement();
@ -132,7 +132,7 @@ class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
// style:text-properties // style:text-properties
$objWriter->startElement('style:text-properties'); $objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('style:use-window-font-color', 'true'); $objWriter->writeAttribute('style:use-window-font-color', 'true');
$objWriter->writeAttribute('style:font-name', 'Arial'); $objWriter->writeAttribute('style:font-name', PHPWord::DEFAULT_FONT_NAME);
$objWriter->writeAttribute('fo:font-size', '10pt'); $objWriter->writeAttribute('fo:font-size', '10pt');
$objWriter->writeAttribute('fo:language', 'fr'); $objWriter->writeAttribute('fo:language', 'fr');
$objWriter->writeAttribute('fo:country', 'FR'); $objWriter->writeAttribute('fo:country', 'FR');

View File

@ -191,8 +191,8 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
$pPHPWord = $this->_document; $pPHPWord = $this->_document;
$arrFonts = array(); $arrFonts = array();
// Default font : Arial // Default font : PHPWord::DEFAULT_FONT_NAME
$arrFonts[] = 'Arial'; $arrFonts[] = PHPWord::DEFAULT_FONT_NAME;
// PHPWord object : $this->_document // PHPWord object : $this->_document
// Browse styles // Browse styles

View File

@ -334,7 +334,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
$objWriter->startElement('w:rPr'); $objWriter->startElement('w:rPr');
// Font // Font
if ($font != 'Arial') { if ($font != PHPWord::DEFAULT_FONT_NAME) {
$objWriter->startElement('w:rFonts'); $objWriter->startElement('w:rFonts');
$objWriter->writeAttribute('w:ascii', $font); $objWriter->writeAttribute('w:ascii', $font);
$objWriter->writeAttribute('w:hAnsi', $font); $objWriter->writeAttribute('w:hAnsi', $font);
@ -350,7 +350,7 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
} }
// Size // Size
if ($size != 20) { if ($size != PHPWord::DEFAULT_FONT_SIZE) {
$objWriter->startElement('w:sz'); $objWriter->startElement('w:sz');
$objWriter->writeAttribute('w:val', $size); $objWriter->writeAttribute('w:val', $size);
$objWriter->endElement(); $objWriter->endElement();