#200: Ability to use a config file to store various common settings

This commit is contained in:
Ivan Lanin 2014-05-15 22:13:03 +07:00
parent f1b2243e15
commit 5511378eca
31 changed files with 1476 additions and 154 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@ Thumbs.db
Desktop.ini Desktop.ini
composer.phar composer.phar
phpunit.xml phpunit.xml
phpword.yml
/.buildpath /.buildpath
/.idea /.idea
/.project /.project

View File

@ -1,5 +1,5 @@
filter: filter:
excluded_paths: [ 'vendor/*', 'tests/*', 'samples/*', 'src/PhpWord/Shared/PCLZip/*' ] excluded_paths: [ 'vendor/*', 'tests/*', 'samples/*', 'src/PhpWord/Shared/PCLZip/*', 'src/PhpWord/Shared/Spyc/*' ]
before_commands: before_commands:
- "composer install --prefer-source --dev" - "composer install --prefer-source --dev"

View File

@ -44,17 +44,17 @@ before_script:
script: script:
## PHP_CodeSniffer ## PHP_CodeSniffer
- ./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip - ./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip --ignore=src/PhpWord/Shared/Spyc
## PHP Copy/Paste Detector ## PHP Copy/Paste Detector
- php phpcpd.phar src/ tests/ --verbose - php phpcpd.phar src/ tests/ --verbose
## PHP Mess Detector ## PHP Mess Detector
- phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php - phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php,Spyc.php
## PHPLOC ## PHPLOC
#- php phploc.phar src/ #- php phploc.phar src/
## PHPUnit ## PHPUnit
- phpunit -c ./ --coverage-text --coverage-html ./build/coverage - phpunit -c ./ --coverage-text --coverage-html ./build/coverage
## PHPDocumentor ## PHPDocumentor
- vendor/bin/phpdoc.php -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/PCLZip/*" --template="responsive-twig" - vendor/bin/phpdoc.php -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/*/*" --template="responsive-twig"
after_script: after_script:
## PHPDocumentor ## PHPDocumentor

View File

@ -19,6 +19,7 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3; new r
- Table: Ability to define table width (in percent and twip) and position - @ivanlanin GH-237 - Table: Ability to define table width (in percent and twip) and position - @ivanlanin GH-237
- RTF: Ability to add links and page breaks in RTF - @ivanlanin GH-196 - RTF: Ability to add links and page breaks in RTF - @ivanlanin GH-196
- ListItemRun: Remove fontStyle parameter because ListItemRun is inherited from TextRun and TextRun doesn't have fontStyle - @ivanlanin - ListItemRun: Remove fontStyle parameter because ListItemRun is inherited from TextRun and TextRun doesn't have fontStyle - @ivanlanin
- Config: Ability to use a config file to store various common settings - @ivanlanin GH-200
### Bugfixes ### Bugfixes

View File

@ -10,7 +10,7 @@
syntaxCheck="false"> syntaxCheck="false">
<testsuites> <testsuites>
<testsuite name="PhpWord Test Suite"> <testsuite name="PhpWord Test Suite">
<directory>./tests/PhpWord/</directory> <directory>./tests/PhpWord</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<filter> <filter>
@ -18,13 +18,11 @@
<directory suffix=".php">./src</directory> <directory suffix=".php">./src</directory>
<exclude> <exclude>
<directory suffix=".php">./src/PhpWord/Shared/PCLZip</directory> <directory suffix=".php">./src/PhpWord/Shared/PCLZip</directory>
<directory suffix=".php">./src/PhpWord/Shared/Spyc</directory>
</exclude> </exclude>
</whitelist> </whitelist>
</filter> </filter>
<logging> <logging>
<!--
For http://phpoffice.github.io/PHPWord/coverage/ and Scrutinizer
-->
<log type="coverage-html" target="./build/coverage" charset="UTF-8" highlight="true" /> <log type="coverage-html" target="./build/coverage" charset="UTF-8" highlight="true" />
<log type="coverage-clover" target="./build/logs/clover.xml" /> <log type="coverage-clover" target="./build/logs/clover.xml" />
</logging> </logging>

9
phpword.yml.dist Normal file
View File

@ -0,0 +1,9 @@
# Default config file for PHPWord
# Copy and this file into phpword.yml and use Settings::loadConfig to load
compatibility: true
zipClass: ZipArchive
pdfRendererName: DomPDF
pdfRendererPath:
defaultFontName: "Arial"
defaultFontSize: 10

View File

@ -2,6 +2,10 @@
/** /**
* Header file * Header file
*/ */
use PhpOffice\PhpWord\Autoloader;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
define('CLI', (PHP_SAPI == 'cli') ? true : false); define('CLI', (PHP_SAPI == 'cli') ? true : false);
define('EOL', CLI ? PHP_EOL : '<br />'); define('EOL', CLI ? PHP_EOL : '<br />');
@ -9,16 +13,14 @@ define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php'));
define('IS_INDEX', SCRIPT_FILENAME == 'index'); define('IS_INDEX', SCRIPT_FILENAME == 'index');
require_once '../src/PhpWord/Autoloader.php'; require_once '../src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register(); Autoloader::register();
Settings::loadConfig();
// Set writers // Set writers
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html', 'PDF' => 'pdf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html', 'PDF' => 'pdf');
// Set PDF renderer // Set PDF renderer
$rendererName = \PhpOffice\PhpWord\Settings::PDF_RENDERER_DOMPDF; if (Settings::getPdfRendererPath() === null) {
$rendererLibraryPath = ''; // DomPDF library path
if (!\PhpOffice\PhpWord\Settings::setPdfRenderer($rendererName, $rendererLibraryPath)) {
$writers['PDF'] = null; $writers['PDF'] = null;
} }
@ -60,7 +62,7 @@ function write($phpWord, $filename, $writers)
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
$result .= date('H:i:s') . " Write to {$writer} format"; $result .= date('H:i:s') . " Write to {$writer} format";
if (!is_null($extension)) { if (!is_null($extension)) {
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer); $xmlWriter = IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$filename}.{$extension}"); $xmlWriter->save("{$filename}.{$extension}");
rename("{$filename}.{$extension}", "results/{$filename}.{$extension}"); rename("{$filename}.{$extension}", "results/{$filename}.{$extension}");
} else { } else {

View File

@ -22,24 +22,22 @@ use PhpOffice\PhpWord\Collection\Footnotes;
use PhpOffice\PhpWord\Collection\Titles; use PhpOffice\PhpWord\Collection\Titles;
use PhpOffice\PhpWord\Element\Section; use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Style;
/** /**
* PHPWord main class * PHPWord main class
*/ */
class PhpWord class PhpWord
{ {
const DEFAULT_FONT_COLOR = '000000'; // HEX
const DEFAULT_FONT_CONTENT_TYPE = 'default'; // default|eastAsia|cs
const DEFAULT_FONT_NAME = 'Arial';
/** /**
* Default font size, in points. * Default font settings
* *
* OOXML defined font size values in halfpoints, i.e. twice of what PhpWord * @const string|int
* use, and the conversion will be conducted during XML writing. * @deprecated 0.11.0 Use Settings constants
*/ */
const DEFAULT_FONT_SIZE = 10; const DEFAULT_FONT_NAME = Settings::DEFAULT_FONT_NAME;
const DEFAULT_FONT_SIZE = Settings::DEFAULT_FONT_SIZE;
const DEFAULT_FONT_COLOR = Settings::DEFAULT_FONT_COLOR;
const DEFAULT_FONT_CONTENT_TYPE = Settings::DEFAULT_FONT_CONTENT_TYPE;
/** /**
* Document properties object * Document properties object
@ -76,19 +74,6 @@ class PhpWord
*/ */
private $endnotes; private $endnotes;
/**
* Default font name
*
* @var string
*/
private $defaultFontName;
/**
* Default font size
* @var int
*/
private $defaultFontSize;
/** /**
* Create new * Create new
*/ */
@ -98,8 +83,6 @@ class PhpWord
$this->titles = new Titles(); $this->titles = new Titles();
$this->footnotes = new Footnotes(); $this->footnotes = new Footnotes();
$this->endnotes = new Endnotes(); $this->endnotes = new Endnotes();
$this->defaultFontName = self::DEFAULT_FONT_NAME;
$this->defaultFontSize = self::DEFAULT_FONT_SIZE;
} }
/** /**
@ -220,7 +203,7 @@ class PhpWord
*/ */
public function getDefaultFontName() public function getDefaultFontName()
{ {
return $this->defaultFontName; return Settings::getDefaultFontName();
} }
/** /**
@ -230,7 +213,7 @@ class PhpWord
*/ */
public function setDefaultFontName($fontName) public function setDefaultFontName($fontName)
{ {
$this->defaultFontName = $fontName; Settings::setDefaultFontName($fontName);
} }
/** /**
@ -240,7 +223,7 @@ class PhpWord
*/ */
public function getDefaultFontSize() public function getDefaultFontSize()
{ {
return $this->defaultFontSize; return Settings::getDefaultFontSize();
} }
/** /**
@ -250,7 +233,7 @@ class PhpWord
*/ */
public function setDefaultFontSize($fontSize) public function setDefaultFontSize($fontSize)
{ {
$this->defaultFontSize = $fontSize; Settings::setDefaultFontSize($fontSize);
} }
/** /**

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Reader\ODText; namespace PhpOffice\PhpWord\Reader\ODText;
use PhpOffice\PhpWord\Shared\XMLReader;
use PhpOffice\PhpWord\Reader\Word2007\AbstractPart as Word2007AbstractPart; use PhpOffice\PhpWord\Reader\Word2007\AbstractPart as Word2007AbstractPart;
use PhpOffice\PhpWord\Shared\XMLReader;
/** /**
* Abstract part reader * Abstract part reader

View File

@ -48,14 +48,25 @@ class Settings
* - Indentation: left, right, firstLine, hanging * - Indentation: left, right, firstLine, hanging
* - Spacing: before, after * - Spacing: before, after
* *
* @const int|float * @const string
*/ */
const UNIT_TWIP = 1; // = 1/20 point const UNIT_TWIP = 'twip'; // = 1/20 point
const UNIT_CM = 567; const UNIT_CM = 'cm';
const UNIT_MM = 56.7; const UNIT_MM = 'mm';
const UNIT_INCH = 1440; const UNIT_INCH = 'inch';
const UNIT_POINT = 20; // = 1/72 inch const UNIT_POINT = 'point'; // = 1/72 inch
const UNIT_PICA = 240; // = 1/6 inch = 12 points const UNIT_PICA = 'pica'; // = 1/6 inch = 12 points
/**
* Default font settings
*
* OOXML defined font size values in halfpoints, i.e. twice of what PhpWord
* use, and the conversion will be conducted during XML writing.
*/
const DEFAULT_FONT_NAME = 'Arial';
const DEFAULT_FONT_SIZE = 10;
const DEFAULT_FONT_COLOR = '000000';
const DEFAULT_FONT_CONTENT_TYPE = 'default'; // default|eastAsia|cs
/** /**
* Compatibility option for XMLWriter * Compatibility option for XMLWriter
@ -71,13 +82,6 @@ class Settings
*/ */
private static $zipClass = self::ZIPARCHIVE; private static $zipClass = self::ZIPARCHIVE;
/**
* Name of the classes used for PDF renderer
*
* @var array
*/
private static $pdfRenderers = array(self::PDF_RENDERER_DOMPDF);
/** /**
* Name of the external Library used for rendering PDF files * Name of the external Library used for rendering PDF files
* *
@ -99,6 +103,19 @@ class Settings
*/ */
private static $measurementUnit = self::UNIT_TWIP; private static $measurementUnit = self::UNIT_TWIP;
/**
* Default font name
*
* @var string
*/
private static $defaultFontName = self::DEFAULT_FONT_NAME;
/**
* Default font size
* @var int
*/
private static $defaultFontSize = self::DEFAULT_FONT_SIZE;
/** /**
* Return the compatibility option used by the XMLWriter * Return the compatibility option used by the XMLWriter
* *
@ -145,8 +162,7 @@ class Settings
*/ */
public static function setZipClass($zipClass) public static function setZipClass($zipClass)
{ {
if (($zipClass === self::PCLZIP) || if (in_array($zipClass, array(self::PCLZIP, self::ZIPARCHIVE))) {
($zipClass === self::ZIPARCHIVE)) {
self::$zipClass = $zipClass; self::$zipClass = $zipClass;
return true; return true;
} }
@ -186,7 +202,8 @@ class Settings
*/ */
public static function setPdfRendererName($libraryName) public static function setPdfRendererName($libraryName)
{ {
if (!in_array($libraryName, self::$pdfRenderers)) { $pdfRenderers = array(self::PDF_RENDERER_DOMPDF);
if (!in_array($libraryName, $pdfRenderers)) {
return false; return false;
} }
self::$pdfRendererName = $libraryName; self::$pdfRendererName = $libraryName;
@ -222,7 +239,7 @@ class Settings
/** /**
* Get measurement unit * Get measurement unit
* *
* @return int|float * @return string
*/ */
public static function getMeasurementUnit() public static function getMeasurementUnit()
{ {
@ -232,7 +249,7 @@ class Settings
/** /**
* Set measurement unit * Set measurement unit
* *
* @param int|float $value * @param string $value
* @return bool * @return bool
*/ */
public static function setMeasurementUnit($value) public static function setMeasurementUnit($value)
@ -247,6 +264,97 @@ class Settings
return true; return true;
} }
/**
* Get default font name
*
* @return string
*/
public static function getDefaultFontName()
{
return self::$defaultFontName;
}
/**
* Set default font name
*
* @param string $value
* @return bool
*/
public static function setDefaultFontName($value)
{
if (is_string($value) && trim($value) !== '') {
self::$defaultFontName = $value;
return true;
}
return false;
}
/**
* Get default font size
*
* @return integer
*/
public static function getDefaultFontSize()
{
return self::$defaultFontSize;
}
/**
* Set default font size
*
* @param int $value
* @return bool
*/
public static function setDefaultFontSize($value)
{
$value = intval($value);
if ($value > 0) {
self::$defaultFontSize = $value;
return true;
}
return false;
}
/**
* Load setting from phpword.yml or phpword.yml.dist
*
* @param string $filename
* @return array
*/
public static function loadConfig($filename = null)
{
// Get config file
$configFile = null;
$configPath = __DIR__ . '/../../';
$files = array($filename, "{$configPath}phpword.yml", "{$configPath}phpword.yml.dist");
foreach ($files as $file) {
if (file_exists($file)) {
$configFile = realpath($file);
break;
}
}
// Use Spyc to load config file
$config = array();
$spycLibrary = realpath(__DIR__ . '/Shared/Spyc/Spyc.php');
if (file_exists($spycLibrary) && $configFile !== null) {
require_once $spycLibrary;
$config = spyc_load_file($configFile);
}
// Set config value
foreach ($config as $key => $value) {
$method = "set{$key}";
if (method_exists(__CLASS__, $method)) {
self::$method($value);
}
}
return $config;
}
/** /**
* Return the compatibility option used by the XMLWriter * Return the compatibility option used by the XMLWriter
* *

View File

@ -0,0 +1,21 @@
The MIT License
Copyright (c) 2011 Vladimir Andersen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,30 @@
**Spyc** is a YAML loader/dumper written in pure PHP. Given a YAML document, Spyc will return an array that
you can use however you see fit. Given an array, Spyc will return a string which contains a YAML document
built from your data.
**YAML** is an amazingly human friendly and strikingly versatile data serialization language which can be used
for log files, config files, custom protocols, the works. For more information, see http://www.yaml.org.
Spyc supports YAML 1.0 specification.
## Using Spyc
Using Spyc is trivial:
```
<?php
require_once "spyc.php";
$Data = Spyc::YAMLLoad('spyc.yaml');
```
or (if you prefer functional syntax)
```
<?php
require_once "spyc.php";
$Data = spyc_load_file('spyc.yaml');
```
## Donations, anyone?
If you find Spyc useful, I'm accepting Bitcoin donations (who doesn't these days?) at 193bEkLP7zMrNLZm9UdUet4puGD5mQiLai

File diff suppressed because it is too large Load Diff

View File

@ -135,21 +135,6 @@ class XMLWriter
} }
} }
/**
* Fallback method for writeRaw, introduced in PHP 5.2
*
* @param string $text
* @return bool
*/
public function writeRaw($text)
{
if (isset($this->xmlWriter) && is_object($this->xmlWriter) && (method_exists($this->xmlWriter, 'writeRaw'))) {
return $this->xmlWriter->writeRaw($text);
}
return $this->text($text);
}
/** /**
* Write element if ... * Write element if ...
* *

View File

@ -17,8 +17,6 @@
namespace PhpOffice\PhpWord\Style; namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\PhpWord;
/** /**
* Font style * Font style
*/ */
@ -86,30 +84,30 @@ class Font extends AbstractStyle
/** /**
* Font name * Font name
* *
* @var int|float * @var string
*/ */
private $name = PhpWord::DEFAULT_FONT_NAME; private $name;
/** /**
* Font Content Type * Font Content Type
* *
* @var string * @var string
*/ */
private $hint = PhpWord::DEFAULT_FONT_CONTENT_TYPE; private $hint;
/** /**
* Font size * Font size
* *
* @var int|float * @var int|float
*/ */
private $size = PhpWord::DEFAULT_FONT_SIZE; private $size;
/** /**
* Font color * Font color
* *
* @var string * @var string
*/ */
private $color = PhpWord::DEFAULT_FONT_COLOR; private $color;
/** /**
* Bold * Bold
@ -241,9 +239,9 @@ class Font extends AbstractStyle
* @param string $value * @param string $value
* @return self * @return self
*/ */
public function setName($value = PhpWord::DEFAULT_FONT_NAME) public function setName($value = null)
{ {
$this->name = $this->setNonEmptyVal($value, PhpWord::DEFAULT_FONT_NAME); $this->name = $value;
return $this; return $this;
} }
@ -264,9 +262,9 @@ class Font extends AbstractStyle
* @param string $value * @param string $value
* @return self * @return self
*/ */
public function setHint($value = PhpWord::DEFAULT_FONT_CONTENT_TYPE) public function setHint($value = null)
{ {
$this->hint = $this->setNonEmptyVal($value, PhpWord::DEFAULT_FONT_CONTENT_TYPE); $this->hint = $value;
return $this; return $this;
} }
@ -287,9 +285,9 @@ class Font extends AbstractStyle
* @param int|float $value * @param int|float $value
* @return self * @return self
*/ */
public function setSize($value = PhpWord::DEFAULT_FONT_SIZE) public function setSize($value = null)
{ {
$this->size = $this->setNumericVal($value, PhpWord::DEFAULT_FONT_SIZE); $this->size = $this->setNumericVal($value, $this->size);
return $this; return $this;
} }
@ -310,9 +308,9 @@ class Font extends AbstractStyle
* @param string $value * @param string $value
* @return self * @return self
*/ */
public function setColor($value = PhpWord::DEFAULT_FONT_COLOR) public function setColor($value = null)
{ {
$this->color = $this->setNonEmptyVal($value, PhpWord::DEFAULT_FONT_COLOR); $this->color = $value;
return $this; return $this;
} }

View File

@ -19,9 +19,10 @@ namespace PhpOffice\PhpWord\Writer;
use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Writer\HTML\Element\Container; use PhpOffice\PhpWord\Writer\HTML\Element\Container;
use PhpOffice\PhpWord\Writer\HTML\Element\TextRun as TextRunWriter; use PhpOffice\PhpWord\Writer\HTML\Element\TextRun as TextRunWriter;
use PhpOffice\PhpWord\Writer\HTML\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\HTML\Style\Font as FontStyleWriter;
@ -168,14 +169,13 @@ class HTML extends AbstractWriter implements WriterInterface
*/ */
private function writeStyles() private function writeStyles()
{ {
$phpWord = $this->getPhpWord();
$css = '<style>' . PHP_EOL; $css = '<style>' . PHP_EOL;
// Default styles // Default styles
$defaultStyles = array( $defaultStyles = array(
'*' => array( '*' => array(
'font-family' => $phpWord->getDefaultFontName(), 'font-family' => Settings::getDefaultFontName(),
'font-size' => $phpWord->getDefaultFontSize() . 'pt', 'font-size' => Settings::getDefaultFontSize() . 'pt',
), ),
'a.NoteRef' => array( 'a.NoteRef' => array(
'text-decoration' => 'none', 'text-decoration' => 'none',

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Writer\HTML\Style; namespace PhpOffice\PhpWord\Writer\HTML\Style;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Font as FontStyle;
/** /**
@ -47,9 +47,9 @@ class Font extends AbstractStyle
$underline = $style->getUnderline() != FontStyle::UNDERLINE_NONE; $underline = $style->getUnderline() != FontStyle::UNDERLINE_NONE;
$lineThrough = $style->isStrikethrough() || $style->isDoubleStrikethrough(); $lineThrough = $style->isStrikethrough() || $style->isDoubleStrikethrough();
$css['font-family'] = $this->getValueIf($font != PhpWord::DEFAULT_FONT_NAME, "'{$font}'"); $css['font-family'] = $this->getValueIf($font !== null, "'{$font}'");
$css['font-size'] = $this->getValueIf($size != PhpWord::DEFAULT_FONT_SIZE, "{$size}pt"); $css['font-size'] = $this->getValueIf($size !== null, "{$size}pt");
$css['color'] = $this->getValueIf($color != PhpWord::DEFAULT_FONT_COLOR, "#{$color}"); $css['color'] = $this->getValueIf($color != Settings::DEFAULT_FONT_COLOR, "#{$color}");
$css['background'] = $this->getValueIf($fgColor != '', $fgColor); $css['background'] = $this->getValueIf($fgColor != '', $fgColor);
$css['font-weight'] = $this->getValueIf($style->isBold(), 'bold'); $css['font-weight'] = $this->getValueIf($style->isBold(), 'bold');
$css['font-style'] = $this->getValueIf($style->isItalic(), 'italic'); $css['font-style'] = $this->getValueIf($style->isItalic(), 'italic');

View File

@ -17,8 +17,6 @@
namespace PhpOffice\PhpWord\Writer\HTML\Style; namespace PhpOffice\PhpWord\Writer\HTML\Style;
use PhpOffice\PhpWord\Settings;
/** /**
* Paragraph style HTML writer * Paragraph style HTML writer
* *
@ -48,8 +46,8 @@ class Paragraph extends AbstractStyle
if (!is_null($spacing)) { if (!is_null($spacing)) {
$before = $spacing->getBefore(); $before = $spacing->getBefore();
$after = $spacing->getAfter(); $after = $spacing->getAfter();
$css['margin-top'] = $this->getValueIf(!is_null($before), ($before / Settings::UNIT_POINT) . 'pt'); $css['margin-top'] = $this->getValueIf(!is_null($before), ($before / 20) . 'pt');
$css['margin-bottom'] = $this->getValueIf(!is_null($after), ($after / Settings::UNIT_POINT) . 'pt'); $css['margin-bottom'] = $this->getValueIf(!is_null($after), ($after / 20) . 'pt');
} }
return $this->assembleCss($css); return $this->assembleCss($css);

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Writer\ODText\Part; namespace PhpOffice\PhpWord\Writer\ODText\Part;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
@ -68,7 +68,7 @@ abstract class AbstractPart extends Word2007AbstractPart
protected function writeFontFaces(XMLWriter $xmlWriter) protected function writeFontFaces(XMLWriter $xmlWriter)
{ {
$xmlWriter->startElement('office:font-face-decls'); $xmlWriter->startElement('office:font-face-decls');
$arrFonts = array(); $fontTable = array();
$styles = Style::getStyles(); $styles = Style::getStyles();
$numFonts = 0; $numFonts = 0;
if (count($styles) > 0) { if (count($styles) > 0) {
@ -77,8 +77,8 @@ abstract class AbstractPart extends Word2007AbstractPart
if ($style instanceof Font) { if ($style instanceof Font) {
$numFonts++; $numFonts++;
$name = $style->getName(); $name = $style->getName();
if (!in_array($name, $arrFonts)) { if (!in_array($name, $fontTable)) {
$arrFonts[] = $name; $fontTable[] = $name;
// style:font-face // style:font-face
$xmlWriter->startElement('style:font-face'); $xmlWriter->startElement('style:font-face');
@ -89,10 +89,10 @@ abstract class AbstractPart extends Word2007AbstractPart
} }
} }
} }
if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) { if (!in_array(Settings::getDefaultFontName(), $fontTable)) {
$xmlWriter->startElement('style:font-face'); $xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME); $xmlWriter->writeAttribute('style:name', Settings::getDefaultFontName());
$xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME); $xmlWriter->writeAttribute('svg:font-family', Settings::getDefaultFontName());
$xmlWriter->endElement(); $xmlWriter->endElement();
} }
$xmlWriter->endElement(); $xmlWriter->endElement();

View File

@ -23,8 +23,8 @@ use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Writer\ODText\Element\Container; use PhpOffice\PhpWord\Writer\ODText\Element\Container;
/** /**

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Writer\ODText\Part; namespace PhpOffice\PhpWord\Writer\ODText\Part;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
/** /**
@ -64,17 +64,17 @@ class Styles extends AbstractPart
// style:text-properties // style:text-properties
$xmlWriter->startElement('style:text-properties'); $xmlWriter->startElement('style:text-properties');
$xmlWriter->writeAttribute('style:use-window-font-color', 'true'); $xmlWriter->writeAttribute('style:use-window-font-color', 'true');
$xmlWriter->writeAttribute('style:font-name', PhpWord::DEFAULT_FONT_NAME); $xmlWriter->writeAttribute('style:font-name', Settings::getDefaultFontName());
$xmlWriter->writeAttribute('fo:font-size', PhpWord::DEFAULT_FONT_SIZE . 'pt'); $xmlWriter->writeAttribute('fo:font-size', Settings::getDefaultFontSize() . 'pt');
$xmlWriter->writeAttribute('fo:language', 'fr'); $xmlWriter->writeAttribute('fo:language', 'fr');
$xmlWriter->writeAttribute('fo:country', 'FR'); $xmlWriter->writeAttribute('fo:country', 'FR');
$xmlWriter->writeAttribute('style:letter-kerning', 'true'); $xmlWriter->writeAttribute('style:letter-kerning', 'true');
$xmlWriter->writeAttribute('style:font-name-asian', PhpWord::DEFAULT_FONT_NAME . '2'); $xmlWriter->writeAttribute('style:font-name-asian', Settings::getDefaultFontName() . '2');
$xmlWriter->writeAttribute('style:font-size-asian', PhpWord::DEFAULT_FONT_SIZE . 'pt'); $xmlWriter->writeAttribute('style:font-size-asian', Settings::getDefaultFontSize() . 'pt');
$xmlWriter->writeAttribute('style:language-asian', 'zh'); $xmlWriter->writeAttribute('style:language-asian', 'zh');
$xmlWriter->writeAttribute('style:country-asian', 'CN'); $xmlWriter->writeAttribute('style:country-asian', 'CN');
$xmlWriter->writeAttribute('style:font-name-complex', PhpWord::DEFAULT_FONT_NAME . '2'); $xmlWriter->writeAttribute('style:font-name-complex', Settings::getDefaultFontName() . '2');
$xmlWriter->writeAttribute('style:font-size-complex', PhpWord::DEFAULT_FONT_SIZE . 'pt'); $xmlWriter->writeAttribute('style:font-size-complex', Settings::getDefaultFontSize() . 'pt');
$xmlWriter->writeAttribute('style:language-complex', 'hi'); $xmlWriter->writeAttribute('style:language-complex', 'hi');
$xmlWriter->writeAttribute('style:country-complex', 'IN'); $xmlWriter->writeAttribute('style:country-complex', 'IN');
$xmlWriter->writeAttribute('fo:hyphenate', 'false'); $xmlWriter->writeAttribute('fo:hyphenate', 'false');

View File

@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Writer;
use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\Drawing; use PhpOffice\PhpWord\Shared\Drawing;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
@ -153,7 +154,7 @@ class RTF extends AbstractWriter implements WriterInterface
$content .= '\nowidctlpar'; // No widow/orphan control $content .= '\nowidctlpar'; // No widow/orphan control
$content .= '\lang1036'; // Applies a language to a text run (1036 : French (France)) $content .= '\lang1036'; // Applies a language to a text run (1036 : French (France))
$content .= '\kerning1'; // Point size (in half-points) above which to kern character pairs $content .= '\kerning1'; // Point size (in half-points) above which to kern character pairs
$content .= '\fs' . (PhpWord::DEFAULT_FONT_SIZE * 2); // Set the font size in half-points $content .= '\fs' . (Settings::getDefaultFontSize() * 2); // Set the font size in half-points
$content .= PHP_EOL; $content .= PHP_EOL;
// Body // Body
@ -191,7 +192,7 @@ class RTF extends AbstractWriter implements WriterInterface
{ {
$phpWord = $this->getPhpWord(); $phpWord = $this->getPhpWord();
$fontTable = array(); $fontTable = array();
$fontTable[] = PhpWord::DEFAULT_FONT_NAME; $fontTable[] = Settings::getDefaultFontName();
// Browse styles // Browse styles
$styles = Style::getStyles(); $styles = Style::getStyles();
@ -236,7 +237,7 @@ class RTF extends AbstractWriter implements WriterInterface
private function populateColorTable() private function populateColorTable()
{ {
$phpWord = $this->getPhpWord(); $phpWord = $this->getPhpWord();
$defaultFontColor = PhpWord::DEFAULT_FONT_COLOR; $defaultFontColor = Settings::DEFAULT_FONT_COLOR;
$colorTable = array(); $colorTable = array();
// Browse styles // Browse styles

View File

@ -21,9 +21,9 @@ use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Font as FontStyle;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle;
use PhpOffice\PhpWord\Writer\HTML\Element\AbstractElement as HTMLAbstractElement;
use PhpOffice\PhpWord\Writer\RTF\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\RTF\Style\Font as FontStyleWriter;
use PhpOffice\PhpWord\Writer\RTF\Style\Paragraph as ParagraphStyleWriter; use PhpOffice\PhpWord\Writer\RTF\Style\Paragraph as ParagraphStyleWriter;
use PhpOffice\PhpWord\Writer\HTML\Element\AbstractElement as HTMLAbstractElement;
/** /**
* Abstract RTF element writer * Abstract RTF element writer

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Element; namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\PhpWord\Element\TextBreak as TextBreakElement;
use PhpOffice\PhpWord\Element\AbstractContainer as ContainerElement; use PhpOffice\PhpWord\Element\AbstractContainer as ContainerElement;
use PhpOffice\PhpWord\Element\TextBreak as TextBreakElement;
/** /**
* Container element writer (section, textrun, header, footnote, cell, etc.) * Container element writer (section, textrun, header, footnote, cell, etc.)

View File

@ -18,9 +18,9 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Numbering as NumberingStyle; use PhpOffice\PhpWord\Style\Numbering as NumberingStyle;
use PhpOffice\PhpWord\Style\NumberingLevel; use PhpOffice\PhpWord\Style\NumberingLevel;
use PhpOffice\PhpWord\Style;
/** /**
* Word2007 numbering part writer: word/numbering.xml * Word2007 numbering part writer: word/numbering.xml

View File

@ -17,11 +17,11 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Table; use PhpOffice\PhpWord\Style\Table;
use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter;
use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
@ -41,7 +41,6 @@ class Styles extends AbstractPart
*/ */
public function write() public function write()
{ {
$phpWord = $this->getParentWriter()->getPhpWord();
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
@ -51,7 +50,7 @@ class Styles extends AbstractPart
// Write default styles // Write default styles
$styles = Style::getStyles(); $styles = Style::getStyles();
$this->writeDefaultStyles($xmlWriter, $phpWord, $styles); $this->writeDefaultStyles($xmlWriter, $styles);
// Write styles // Write styles
if (count($styles) > 0) { if (count($styles) > 0) {
@ -155,13 +154,12 @@ class Styles extends AbstractPart
* Write default font and other default styles * Write default font and other default styles
* *
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param array $styles * @param array $styles
*/ */
private function writeDefaultStyles(XMLWriter $xmlWriter, PhpWord $phpWord, $styles) private function writeDefaultStyles(XMLWriter $xmlWriter, $styles)
{ {
$fontName = $phpWord->getDefaultFontName(); $fontName = Settings::getDefaultFontName();
$fontSize = $phpWord->getDefaultFontSize(); $fontSize = Settings::getDefaultFontSize();
// Default font // Default font
$xmlWriter->startElement('w:docDefaults'); $xmlWriter->startElement('w:docDefaults');

View File

@ -87,11 +87,18 @@ abstract class AbstractStyle
*/ */
protected function convertTwip($value, $default = 0) protected function convertTwip($value, $default = 0)
{ {
$conversions = array(
Settings::UNIT_CM => 567,
Settings::UNIT_MM => 56.7,
Settings::UNIT_INCH => 1440,
Settings::UNIT_POINT => 20,
Settings::UNIT_PICA => 240,
);
$unit = Settings::getMeasurementUnit(); $unit = Settings::getMeasurementUnit();
if ($unit == Settings::UNIT_TWIP || $value == $default) { if (in_array($unit, $conversions) && $value != $default) {
return $value; return $value * $conversions[$unit];
} else { } else {
return $value * $unit; return $value;
} }
} }
} }

View File

@ -17,8 +17,6 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Style; namespace PhpOffice\PhpWord\Writer\Word2007\Style;
use PhpOffice\PhpWord\PhpWord;
/** /**
* Font style writer * Font style writer
* *
@ -72,24 +70,24 @@ class Font extends AbstractStyle
// Font name/family // Font name/family
$font = $style->getName(); $font = $style->getName();
$hint = $style->getHint(); $hint = $style->getHint();
if ($font != PhpWord::DEFAULT_FONT_NAME) { if ($font !== null) {
$xmlWriter->startElement('w:rFonts'); $xmlWriter->startElement('w:rFonts');
$xmlWriter->writeAttribute('w:ascii', $font); $xmlWriter->writeAttribute('w:ascii', $font);
$xmlWriter->writeAttribute('w:hAnsi', $font); $xmlWriter->writeAttribute('w:hAnsi', $font);
$xmlWriter->writeAttribute('w:eastAsia', $font); $xmlWriter->writeAttribute('w:eastAsia', $font);
$xmlWriter->writeAttribute('w:cs', $font); $xmlWriter->writeAttribute('w:cs', $font);
$xmlWriter->writeAttributeIf($hint != PhpWord::DEFAULT_FONT_CONTENT_TYPE, 'w:hint', $hint); $xmlWriter->writeAttributeIf($hint !== null, 'w:hint', $hint);
$xmlWriter->endElement(); $xmlWriter->endElement();
} }
// Color // Color
$color = $style->getColor(); $color = $style->getColor();
$xmlWriter->writeElementIf($color != PhpWord::DEFAULT_FONT_COLOR, 'w:color', 'w:val', $color); $xmlWriter->writeElementIf($color !== null, 'w:color', 'w:val', $color);
// Size // Size
$size = $style->getSize(); $size = $style->getSize();
$xmlWriter->writeElementIf($size != PhpWord::DEFAULT_FONT_SIZE, 'w:sz', 'w:val', $size * 2); $xmlWriter->writeElementIf($size !== null, 'w:sz', 'w:val', $size * 2);
$xmlWriter->writeElementIf($size != PhpWord::DEFAULT_FONT_SIZE, 'w:szCs', 'w:val', $size * 2); $xmlWriter->writeElementIf($size !== null, 'w:szCs', 'w:val', $size * 2);
// Bold, italic // Bold, italic
$xmlWriter->writeElementIf($style->isBold(), 'w:b'); $xmlWriter->writeElementIf($style->isBold(), 'w:b');

View File

@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Tests;
use PhpOffice\PhpWord\DocumentProperties; use PhpOffice\PhpWord\DocumentProperties;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
/** /**
@ -35,8 +36,8 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
{ {
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$this->assertEquals(new DocumentProperties(), $phpWord->getDocumentProperties()); $this->assertEquals(new DocumentProperties(), $phpWord->getDocumentProperties());
$this->assertEquals(PhpWord::DEFAULT_FONT_NAME, $phpWord->getDefaultFontName()); $this->assertEquals(Settings::DEFAULT_FONT_NAME, $phpWord->getDefaultFontName());
$this->assertEquals(PhpWord::DEFAULT_FONT_SIZE, $phpWord->getDefaultFontSize()); $this->assertEquals(Settings::DEFAULT_FONT_SIZE, $phpWord->getDefaultFontSize());
} }
/** /**
@ -69,7 +70,7 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
{ {
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$fontName = 'Times New Roman'; $fontName = 'Times New Roman';
$this->assertEquals(PhpWord::DEFAULT_FONT_NAME, $phpWord->getDefaultFontName()); $this->assertEquals(Settings::DEFAULT_FONT_NAME, $phpWord->getDefaultFontName());
$phpWord->setDefaultFontName($fontName); $phpWord->setDefaultFontName($fontName);
$this->assertEquals($fontName, $phpWord->getDefaultFontName()); $this->assertEquals($fontName, $phpWord->getDefaultFontName());
} }
@ -81,7 +82,7 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
{ {
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$fontSize = 16; $fontSize = 16;
$this->assertEquals(PhpWord::DEFAULT_FONT_SIZE, $phpWord->getDefaultFontSize()); $this->assertEquals(Settings::DEFAULT_FONT_SIZE, $phpWord->getDefaultFontSize());
$phpWord->setDefaultFontSize($fontSize); $phpWord->setDefaultFontSize($fontSize);
$this->assertEquals($fontSize, $phpWord->getDefaultFontSize()); $this->assertEquals($fontSize, $phpWord->getDefaultFontSize());
} }

View File

@ -70,4 +70,40 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(Settings::setMeasurementUnit(Settings::UNIT_INCH)); $this->assertTrue(Settings::setMeasurementUnit(Settings::UNIT_INCH));
$this->assertFalse(Settings::setMeasurementUnit('foo')); $this->assertFalse(Settings::setMeasurementUnit('foo'));
} }
/**
* Test set/get default font name
*/
public function testSetGetDefaultFontName()
{
$this->assertEquals(Settings::DEFAULT_FONT_NAME, Settings::getDefaultFontName());
$this->assertTrue(Settings::setDefaultFontName('Times New Roman'));
$this->assertFalse(Settings::setDefaultFontName(' '));
}
/**
* Test set/get default font size
*/
public function testSetGetDefaultFontSize()
{
$this->assertEquals(Settings::DEFAULT_FONT_SIZE, Settings::getDefaultFontSize());
$this->assertTrue(Settings::setDefaultFontSize(12));
$this->assertFalse(Settings::setDefaultFontSize(null));
}
/**
* Test load config
*/
public function testLoadConfig()
{
$expected = array(
'compatibility' => true,
'zipClass' => 'ZipArchive',
'pdfRendererName' => 'DomPDF',
'pdfRendererPath' => '',
'defaultFontName' => 'Arial',
'defaultFontSize' => 10,
);
$this->assertEquals($expected, Settings::loadConfig(__DIR__ . '/../../../phpword.yml.dist'));
}
} }

View File

@ -18,6 +18,7 @@
namespace PhpOffice\PhpWord\Tests\Style; namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
@ -55,8 +56,10 @@ class FontTest extends \PHPUnit_Framework_TestCase
$object = new Font(); $object = new Font();
$attributes = array( $attributes = array(
'name' => PhpWord::DEFAULT_FONT_NAME, 'name' => null,
'size' => PhpWord::DEFAULT_FONT_SIZE, 'size' => null,
'hint' => null,
'color' => null,
'bold' => false, 'bold' => false,
'italic' => false, 'italic' => false,
'underline' => Font::UNDERLINE_NONE, 'underline' => Font::UNDERLINE_NONE,
@ -66,11 +69,8 @@ class FontTest extends \PHPUnit_Framework_TestCase
'doubleStrikethrough' => false, 'doubleStrikethrough' => false,
'smallCaps' => false, 'smallCaps' => false,
'allCaps' => false, 'allCaps' => false,
'doubleStrikethrough' => false,
'color' => PhpWord::DEFAULT_FONT_COLOR,
'fgColor' => null, 'fgColor' => null,
'bgColor' => null, 'bgColor' => null,
'hint' => PhpWord::DEFAULT_FONT_CONTENT_TYPE,
); );
foreach ($attributes as $key => $default) { foreach ($attributes as $key => $default) {
$get = is_bool($default) ? "is{$key}" : "get{$key}"; $get = is_bool($default) ? "is{$key}" : "get{$key}";
@ -91,6 +91,8 @@ class FontTest extends \PHPUnit_Framework_TestCase
$attributes = array( $attributes = array(
'name' => 'Times New Roman', 'name' => 'Times New Roman',
'size' => 9, 'size' => 9,
'color' => '999999',
'hint' => 'eastAsia',
'bold' => true, 'bold' => true,
'italic' => true, 'italic' => true,
'underline' => Font::UNDERLINE_HEAVY, 'underline' => Font::UNDERLINE_HEAVY,
@ -100,10 +102,8 @@ class FontTest extends \PHPUnit_Framework_TestCase
'doubleStrikethrough' => false, 'doubleStrikethrough' => false,
'smallCaps' => true, 'smallCaps' => true,
'allCaps' => false, 'allCaps' => false,
'color' => '999999',
'fgColor' => Font::FGCOLOR_YELLOW, 'fgColor' => Font::FGCOLOR_YELLOW,
'bgColor' => 'FFFF00', 'bgColor' => 'FFFF00',
'hint' => 'eastAsia',
'lineHeight' => 2, 'lineHeight' => 2,
); );
$object->setStyleByArray($attributes); $object->setStyleByArray($attributes);