Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Thumbs.db
Desktop.ini
composer.phar
phpunit.xml
phpword.ini
/.buildpath
/.idea
/.project
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ script:
## PHPUnit
- phpunit -c ./ --coverage-text --coverage-html ./build/coverage
## 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:
## PHPDocumentor
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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
- Config: Ability to use a config file to store various common settings - @ivanlanin GH-200

### Bugfixes

Expand Down
6 changes: 2 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@
syntaxCheck="false">
<testsuites>
<testsuite name="PhpWord Test Suite">
<directory>./tests/PhpWord/</directory>
<directory>./tests/PhpWord</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">./src/PhpWord/Shared/PCLZip</directory>
<directory suffix=".php">./src/PhpWord/Shared/Spyc</directory>
</exclude>
</whitelist>
</filter>
<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-clover" target="./build/logs/clover.xml" />
</logging>
Expand Down
14 changes: 14 additions & 0 deletions phpword.ini.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; Default config file for PHPWord
; Copy this file into phpword.ini and use Settings::loadConfig to load

[General]

compatibility = true
zipClass = ZipArchive
pdfRendererName = DomPDF
pdfRendererPath =

[Font]

defaultFontName = Arial
defaultFontSize = 10
14 changes: 8 additions & 6 deletions samples/Sample_Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@
/**
* Header file
*/
use PhpOffice\PhpWord\Autoloader;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\IOFactory;

error_reporting(E_ALL);
define('CLI', (PHP_SAPI == 'cli') ? true : false);
define('EOL', CLI ? PHP_EOL : '<br />');
define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php'));
define('IS_INDEX', SCRIPT_FILENAME == 'index');

require_once '../src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
Autoloader::register();
Settings::loadConfig();

// Set writers
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html', 'PDF' => 'pdf');

// Set PDF renderer
$rendererName = \PhpOffice\PhpWord\Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = ''; // DomPDF library path

if (!\PhpOffice\PhpWord\Settings::setPdfRenderer($rendererName, $rendererLibraryPath)) {
if (Settings::getPdfRendererPath() === null) {
$writers['PDF'] = null;
}

Expand Down Expand Up @@ -60,7 +62,7 @@ function write($phpWord, $filename, $writers)
foreach ($writers as $writer => $extension) {
$result .= date('H:i:s') . " Write to {$writer} format";
if (!is_null($extension)) {
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter = IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$filename}.{$extension}");
rename("{$filename}.{$extension}", "results/{$filename}.{$extension}");
} else {
Expand Down
39 changes: 11 additions & 28 deletions src/PhpWord/PhpWord.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,22 @@
use PhpOffice\PhpWord\Collection\Titles;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Style;

/**
* PHPWord main class
*/
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
* use, and the conversion will be conducted during XML writing.
* @const string|int
* @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
Expand Down Expand Up @@ -76,19 +74,6 @@ class PhpWord
*/
private $endnotes;

/**
* Default font name
*
* @var string
*/
private $defaultFontName;

/**
* Default font size
* @var int
*/
private $defaultFontSize;

/**
* Create new
*/
Expand All @@ -98,8 +83,6 @@ public function __construct()
$this->titles = new Titles();
$this->footnotes = new Footnotes();
$this->endnotes = new Endnotes();
$this->defaultFontName = self::DEFAULT_FONT_NAME;
$this->defaultFontSize = self::DEFAULT_FONT_SIZE;
}

/**
Expand Down Expand Up @@ -220,7 +203,7 @@ public function addEndnote($endnote)
*/
public function getDefaultFontName()
{
return $this->defaultFontName;
return Settings::getDefaultFontName();
}

/**
Expand All @@ -230,7 +213,7 @@ public function getDefaultFontName()
*/
public function setDefaultFontName($fontName)
{
$this->defaultFontName = $fontName;
Settings::setDefaultFontName($fontName);
}

/**
Expand All @@ -240,7 +223,7 @@ public function setDefaultFontName($fontName)
*/
public function getDefaultFontSize()
{
return $this->defaultFontSize;
return Settings::getDefaultFontSize();
}

/**
Expand All @@ -250,7 +233,7 @@ public function getDefaultFontSize()
*/
public function setDefaultFontSize($fontSize)
{
$this->defaultFontSize = $fontSize;
Settings::setDefaultFontSize($fontSize);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Reader/ODText/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

namespace PhpOffice\PhpWord\Reader\ODText;

use PhpOffice\PhpWord\Shared\XMLReader;
use PhpOffice\PhpWord\Reader\Word2007\AbstractPart as Word2007AbstractPart;
use PhpOffice\PhpWord\Shared\XMLReader;

/**
* Abstract part reader
Expand Down
Loading