QA: Scrutinizer dedup
This commit is contained in:
parent
1c3735fc08
commit
4d9e4062c3
|
|
@ -54,47 +54,47 @@ abstract class AbstractReader implements ReaderInterface
|
|||
/**
|
||||
* Set read data only
|
||||
*
|
||||
* @param bool $pValue
|
||||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setReadDataOnly($pValue = true)
|
||||
public function setReadDataOnly($value = true)
|
||||
{
|
||||
$this->readDataOnly = $pValue;
|
||||
$this->readDataOnly = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open file for reading
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param string $filename
|
||||
* @return resource
|
||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
||||
*/
|
||||
protected function openFile($pFilename)
|
||||
protected function openFile($filename)
|
||||
{
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename) || !is_readable($pFilename)) {
|
||||
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
if (!file_exists($filename) || !is_readable($filename)) {
|
||||
throw new Exception("Could not open " . $filename . " for reading! File does not exist.");
|
||||
}
|
||||
|
||||
// Open file
|
||||
$this->fileHandle = fopen($pFilename, 'r');
|
||||
$this->fileHandle = fopen($filename, 'r');
|
||||
if ($this->fileHandle === false) {
|
||||
throw new Exception("Could not open file " . $pFilename . " for reading.");
|
||||
throw new Exception("Could not open file " . $filename . " for reading.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the current ReaderInterface read the file?
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param string $filename
|
||||
* @return bool
|
||||
*/
|
||||
public function canRead($pFilename)
|
||||
public function canRead($filename)
|
||||
{
|
||||
// Check if file exists
|
||||
try {
|
||||
$this->openFile($pFilename);
|
||||
$this->openFile($filename);
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,12 @@
|
|||
namespace PhpOffice\PhpWord\Reader\ODText;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\XMLReader;
|
||||
use PhpOffice\PhpWord\Reader\Word2007\AbstractPart as Word2007AbstractPart;
|
||||
|
||||
/**
|
||||
* Abstract part reader
|
||||
*/
|
||||
abstract class AbstractPart extends \PhpOffice\PhpWord\Reader\Word2007\AbstractPart
|
||||
abstract class AbstractPart extends Word2007AbstractPart
|
||||
{
|
||||
/**
|
||||
* Read w:r (override)
|
||||
|
|
|
|||
|
|
@ -25,15 +25,15 @@ interface ReaderInterface
|
|||
/**
|
||||
* Can the current ReaderInterface read the file?
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param string $filename
|
||||
* @return boolean
|
||||
*/
|
||||
public function canRead($pFilename);
|
||||
public function canRead($filename);
|
||||
|
||||
/**
|
||||
* Loads PhpWord from file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param string $filename
|
||||
*/
|
||||
public function load($pFilename);
|
||||
public function load($filename);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -633,7 +633,7 @@ class Font extends AbstractStyle
|
|||
* Set $property value and set $pairProperty = false when $value = true
|
||||
*
|
||||
* @param bool $property
|
||||
* @param bool $pair
|
||||
* @param bool $pairProperty
|
||||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -29,12 +29,19 @@ class Table extends Border
|
|||
const WIDTH_PERCENT = 'pct'; // Width in fiftieths (1/50) of a percent (1% = 50 unit)
|
||||
const WIDTH_TWIP = 'dxa'; // Width in twentieths (1/20) of a point (twip)
|
||||
|
||||
/**
|
||||
* Is this a first row style?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $isFirstRow = false;
|
||||
|
||||
/**
|
||||
* Style for first row
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Table
|
||||
*/
|
||||
private $firstRow;
|
||||
private $firstRowStyle;
|
||||
|
||||
/**
|
||||
* Cell margin top
|
||||
|
|
@ -126,17 +133,18 @@ class Table extends Border
|
|||
|
||||
// Clone first row from table style, but with certain properties disabled
|
||||
if ($firstRowStyle !== null && is_array($firstRowStyle)) {
|
||||
$this->firstRow = clone $this;
|
||||
unset($this->firstRow->firstRow);
|
||||
unset($this->firstRow->borderInsideHSize);
|
||||
unset($this->firstRow->borderInsideHColor);
|
||||
unset($this->firstRow->borderInsideVSize);
|
||||
unset($this->firstRow->borderInsideVColor);
|
||||
unset($this->firstRow->cellMarginTop);
|
||||
unset($this->firstRow->cellMarginLeft);
|
||||
unset($this->firstRow->cellMarginRight);
|
||||
unset($this->firstRow->cellMarginBottom);
|
||||
$this->firstRow->setStyleByArray($firstRowStyle);
|
||||
$this->firstRowStyle = clone $this;
|
||||
$this->firstRowStyle->isFirstRow = true;
|
||||
unset($this->firstRowStyle->firstRowStyle);
|
||||
unset($this->firstRowStyle->borderInsideHSize);
|
||||
unset($this->firstRowStyle->borderInsideHColor);
|
||||
unset($this->firstRowStyle->borderInsideVSize);
|
||||
unset($this->firstRowStyle->borderInsideVColor);
|
||||
unset($this->firstRowStyle->cellMarginTop);
|
||||
unset($this->firstRowStyle->cellMarginLeft);
|
||||
unset($this->firstRowStyle->cellMarginRight);
|
||||
unset($this->firstRowStyle->cellMarginBottom);
|
||||
$this->firstRowStyle->setStyleByArray($firstRowStyle);
|
||||
}
|
||||
|
||||
if ($tableStyle !== null && is_array($tableStyle)) {
|
||||
|
|
@ -145,13 +153,13 @@ class Table extends Border
|
|||
}
|
||||
|
||||
/**
|
||||
* Get First Row Style
|
||||
* Set first row
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Table
|
||||
*/
|
||||
public function getFirstRow()
|
||||
{
|
||||
return $this->firstRow;
|
||||
return $this->firstRowStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -556,7 +564,7 @@ class Table extends Border
|
|||
}
|
||||
|
||||
/**
|
||||
* Get table style only property by checking if firstRow is set
|
||||
* Get table style only property by checking if it's a firstRow
|
||||
*
|
||||
* This is necessary since firstRow style is cloned from table style but
|
||||
* without certain properties activated, e.g. margins
|
||||
|
|
@ -566,7 +574,7 @@ class Table extends Border
|
|||
*/
|
||||
private function getTableOnlyProperty($property)
|
||||
{
|
||||
if (isset($this->firstRow)) {
|
||||
if ($this->isFirstRow === false) {
|
||||
return $this->$property;
|
||||
}
|
||||
|
||||
|
|
@ -574,7 +582,7 @@ class Table extends Border
|
|||
}
|
||||
|
||||
/**
|
||||
* Set table style only property by checking if firstRow is set
|
||||
* Set table style only property by checking if it's a firstRow
|
||||
*
|
||||
* This is necessary since firstRow style is cloned from table style but
|
||||
* without certain properties activated, e.g. margins
|
||||
|
|
@ -586,8 +594,8 @@ class Table extends Border
|
|||
*/
|
||||
private function setTableOnlyProperty($property, $value, $isNumeric = true)
|
||||
{
|
||||
if (isset($this->firstRow)) {
|
||||
if ($isNumeric) {
|
||||
if ($this->isFirstRow === false) {
|
||||
if ($isNumeric === true) {
|
||||
$this->$property = $this->setNumericVal($value, $this->$property);
|
||||
} else {
|
||||
$this->$property = $value;
|
||||
|
|
|
|||
|
|
@ -335,7 +335,7 @@ abstract class AbstractWriter implements WriterInterface
|
|||
$source = substr($source, 6);
|
||||
list($zipFilename, $imageFilename) = explode('#', $source);
|
||||
|
||||
$zipClass = \PhpOffice\PhpWord\Settings::getZipClass();
|
||||
$zipClass = Settings::getZipClass();
|
||||
$zip = new $zipClass();
|
||||
if ($zip->open($zipFilename) !== false) {
|
||||
if ($zip->locateName($imageFilename)) {
|
||||
|
|
|
|||
|
|
@ -62,14 +62,10 @@ class HTML extends AbstractWriter implements WriterInterface
|
|||
* Save PhpWord to file
|
||||
*
|
||||
* @param string $filename
|
||||
* @throws Exception
|
||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
||||
*/
|
||||
public function save($filename = null)
|
||||
{
|
||||
if (is_null($this->phpWord)) {
|
||||
throw new Exception('PhpWord object unassigned.');
|
||||
}
|
||||
|
||||
$this->setTempDir(sys_get_temp_dir() . '/PHPWordWriter/');
|
||||
$hFile = fopen($filename, 'w');
|
||||
if ($hFile !== false) {
|
||||
|
|
@ -111,7 +107,8 @@ class HTML extends AbstractWriter implements WriterInterface
|
|||
*/
|
||||
private function writeHead()
|
||||
{
|
||||
$properties = $this->getPhpWord()->getDocumentProperties();
|
||||
$phpWord = $this->getPhpWord();
|
||||
$properties = $phpWord->getDocumentProperties();
|
||||
$propertiesMapping = array(
|
||||
'creator' => 'author',
|
||||
'title' => '',
|
||||
|
|
@ -171,13 +168,14 @@ class HTML extends AbstractWriter implements WriterInterface
|
|||
*/
|
||||
private function writeStyles()
|
||||
{
|
||||
$phpWord = $this->getPhpWord();
|
||||
$css = '<style>' . PHP_EOL;
|
||||
|
||||
// Default styles
|
||||
$defaultStyles = array(
|
||||
'*' => array(
|
||||
'font-family' => $this->getPhpWord()->getDefaultFontName(),
|
||||
'font-size' => $this->getPhpWord()->getDefaultFontSize() . 'pt',
|
||||
'font-family' => $phpWord->getDefaultFontName(),
|
||||
'font-size' => $phpWord->getDefaultFontSize() . 'pt',
|
||||
),
|
||||
'a.NoteRef' => array(
|
||||
'text-decoration' => 'none',
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Writer\HTML\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Element\AbstractContainer as ContainerElement;
|
||||
|
||||
/**
|
||||
* Container element HTML writer
|
||||
*
|
||||
|
|
@ -39,7 +41,7 @@ class Container extends AbstractElement
|
|||
public function write()
|
||||
{
|
||||
$container = $this->element;
|
||||
if (!$container instanceof \PhpOffice\PhpWord\Element\AbstractContainer) {
|
||||
if (!$container instanceof ContainerElement) {
|
||||
return '';
|
||||
}
|
||||
$containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
namespace PhpOffice\PhpWord\Writer\HTML\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Element\Image as ImageElement;
|
||||
use PhpOffice\PhpWord\Settings;
|
||||
use PhpOffice\PhpWord\Writer\HTML\Style\Image as ImageStyleWriter;
|
||||
|
||||
/**
|
||||
|
|
@ -34,7 +35,7 @@ class Image extends Text
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Image) {
|
||||
if (!$this->element instanceof ImageElement) {
|
||||
return '';
|
||||
}
|
||||
/** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */
|
||||
|
|
@ -76,7 +77,7 @@ class Image extends Text
|
|||
$source = substr($source, 6);
|
||||
list($zipFilename, $imageFilename) = explode('#', $source);
|
||||
|
||||
$zipClass = \PhpOffice\PhpWord\Settings::getZipClass();
|
||||
$zipClass = Settings::getZipClass();
|
||||
$zip = new $zipClass();
|
||||
if ($zip->open($zipFilename) !== false) {
|
||||
if ($zip->locateName($imageFilename)) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class Font extends AbstractStyle
|
|||
public function write()
|
||||
{
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
|
||||
if (!$style instanceof FontStyle) {
|
||||
return '';
|
||||
}
|
||||
$css = array();
|
||||
|
|
|
|||
|
|
@ -67,10 +67,6 @@ class ODText extends AbstractWriter implements WriterInterface
|
|||
*/
|
||||
public function save($filename = null)
|
||||
{
|
||||
if (is_null($this->phpWord)) {
|
||||
throw new Exception('PhpWord object unassigned.');
|
||||
}
|
||||
|
||||
$filename = $this->getTempFile($filename);
|
||||
$objZip = $this->getZipArchive($filename);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,11 +17,13 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Writer\ODText\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement as Word2007AbstractElement;
|
||||
|
||||
/**
|
||||
* Abstract element writer
|
||||
*
|
||||
* @since 0.11.0
|
||||
*/
|
||||
abstract class AbstractElement extends \PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement
|
||||
abstract class AbstractElement extends Word2007AbstractElement
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,12 +17,14 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Writer\ODText\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Writer\Word2007\Element\Container as Word2007Container;
|
||||
|
||||
/**
|
||||
* Container element writer (section, textrun, header, footnote, cell, etc.)
|
||||
*
|
||||
* @since 0.11.0
|
||||
*/
|
||||
class Container extends \PhpOffice\PhpWord\Writer\Word2007\Element\Container
|
||||
class Container extends Word2007Container
|
||||
{
|
||||
/**
|
||||
* Namespace; Can't use __NAMESPACE__ in inherited class (ODText)
|
||||
|
|
|
|||
|
|
@ -21,11 +21,12 @@ use PhpOffice\PhpWord\PhpWord;
|
|||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
use PhpOffice\PhpWord\Style;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart as Word2007AbstractPart;
|
||||
|
||||
/**
|
||||
* ODText writer part abstract
|
||||
*/
|
||||
abstract class AbstractPart extends \PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart
|
||||
abstract class AbstractPart extends Word2007AbstractPart
|
||||
{
|
||||
/**
|
||||
* Write common root attributes
|
||||
|
|
|
|||
|
|
@ -17,11 +17,13 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Writer\ODText\Style;
|
||||
|
||||
use PhpOffice\PhpWord\Writer\Word2007\Style\AbstractStyle as Word2007AbstractStyle;
|
||||
|
||||
/**
|
||||
* Style writer
|
||||
*
|
||||
* @since 0.10.0
|
||||
*/
|
||||
abstract class AbstractStyle extends \PhpOffice\PhpWord\Writer\Word2007\Style\AbstractStyle
|
||||
abstract class AbstractStyle extends Word2007AbstractStyle
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,12 @@ namespace PhpOffice\PhpWord\Writer\PDF;
|
|||
|
||||
use PhpOffice\PhpWord\Exception\Exception;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Writer\HTML;
|
||||
|
||||
/**
|
||||
* Abstract PDF renderer
|
||||
*/
|
||||
abstract class AbstractRenderer extends \PhpOffice\PhpWord\Writer\HTML
|
||||
abstract class AbstractRenderer extends HTML
|
||||
{
|
||||
/**
|
||||
* Temporary storage directory
|
||||
|
|
@ -112,12 +113,12 @@ abstract class AbstractRenderer extends \PhpOffice\PhpWord\Writer\HTML
|
|||
/**
|
||||
* Set Paper Size
|
||||
*
|
||||
* @param int $pValue Paper size = PAPERSIZE_A4
|
||||
* @param int $value Paper size = PAPERSIZE_A4
|
||||
* @return self
|
||||
*/
|
||||
public function setPaperSize($pValue = 9)
|
||||
public function setPaperSize($value = 9)
|
||||
{
|
||||
$this->paperSize = $pValue;
|
||||
$this->paperSize = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
@ -134,27 +135,27 @@ abstract class AbstractRenderer extends \PhpOffice\PhpWord\Writer\HTML
|
|||
/**
|
||||
* Set Orientation
|
||||
*
|
||||
* @param string $pValue Page orientation ORIENTATION_DEFAULT
|
||||
* @param string $value Page orientation ORIENTATION_DEFAULT
|
||||
* @return self
|
||||
*/
|
||||
public function setOrientation($pValue = 'default')
|
||||
public function setOrientation($value = 'default')
|
||||
{
|
||||
$this->orientation = $pValue;
|
||||
$this->orientation = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save PhpWord to PDF file, pre-save
|
||||
*
|
||||
* @param string $pFilename Name of the file to save as
|
||||
* @param string $filename Name of the file to save as
|
||||
* @return resource
|
||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
||||
*/
|
||||
protected function prepareForSave($pFilename = null)
|
||||
protected function prepareForSave($filename = null)
|
||||
{
|
||||
$fileHandle = fopen($pFilename, 'w');
|
||||
$fileHandle = fopen($filename, 'w');
|
||||
if ($fileHandle === false) {
|
||||
throw new Exception("Could not open file $pFilename for writing.");
|
||||
throw new Exception("Could not open file $filename for writing.");
|
||||
}
|
||||
$this->isPdf = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,11 +20,12 @@ namespace PhpOffice\PhpWord\Writer\PDF;
|
|||
use PhpOffice\PhpWord\Exception\Exception;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Settings;
|
||||
use PhpOffice\PhpWord\Writer\WriterInterface;
|
||||
|
||||
/**
|
||||
* DomPDF writer
|
||||
*/
|
||||
class DomPDF extends AbstractRenderer implements \PhpOffice\PhpWord\Writer\WriterInterface
|
||||
class DomPDF extends AbstractRenderer implements WriterInterface
|
||||
{
|
||||
/**
|
||||
* Create new instance
|
||||
|
|
@ -46,12 +47,12 @@ class DomPDF extends AbstractRenderer implements \PhpOffice\PhpWord\Writer\Write
|
|||
/**
|
||||
* Save PhpWord to file
|
||||
*
|
||||
* @param string $pFilename Name of the file to save as
|
||||
* @param string $filename Name of the file to save as
|
||||
* @throws Exception
|
||||
*/
|
||||
public function save($pFilename = null)
|
||||
public function save($filename = null)
|
||||
{
|
||||
$fileHandle = parent::prepareForSave($pFilename);
|
||||
$fileHandle = parent::prepareForSave($filename);
|
||||
|
||||
// Default PDF paper size
|
||||
$paperSize = 'A4';
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ class RTF extends AbstractWriter implements WriterInterface
|
|||
*/
|
||||
public function __construct(PhpWord $phpWord = null)
|
||||
{
|
||||
// Assign PhpWord
|
||||
$this->setPhpWord($phpWord);
|
||||
}
|
||||
|
||||
|
|
@ -70,10 +69,6 @@ class RTF extends AbstractWriter implements WriterInterface
|
|||
*/
|
||||
public function save($filename = null)
|
||||
{
|
||||
if (is_null($this->phpWord)) {
|
||||
throw new Exception('PhpWord object unassigned.');
|
||||
}
|
||||
|
||||
$filename = $this->getTempFile($filename);
|
||||
$hFile = fopen($filename, 'w');
|
||||
if ($hFile !== false) {
|
||||
|
|
@ -194,12 +189,9 @@ class RTF extends AbstractWriter implements WriterInterface
|
|||
*/
|
||||
private function populateFontTable()
|
||||
{
|
||||
$phpWord = $this->phpWord;
|
||||
|
||||
$arrFonts = array();
|
||||
// Default font : PhpWord::DEFAULT_FONT_NAME
|
||||
$arrFonts[] = PhpWord::DEFAULT_FONT_NAME;
|
||||
// PhpWord object : $this->phpWord
|
||||
$phpWord = $this->getPhpWord();
|
||||
$fontTable = array();
|
||||
$fontTable[] = PhpWord::DEFAULT_FONT_NAME;
|
||||
|
||||
// Browse styles
|
||||
$styles = Style::getStyles();
|
||||
|
|
@ -207,8 +199,8 @@ class RTF extends AbstractWriter implements WriterInterface
|
|||
foreach ($styles as $style) {
|
||||
// Font
|
||||
if ($style instanceof Font) {
|
||||
if (in_array($style->getName(), $arrFonts) == false) {
|
||||
$arrFonts[] = $style->getName();
|
||||
if (in_array($style->getName(), $fontTable) == false) {
|
||||
$fontTable[] = $style->getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -218,19 +210,14 @@ class RTF extends AbstractWriter implements WriterInterface
|
|||
$sections = $phpWord->getSections();
|
||||
$countSections = count($sections);
|
||||
if ($countSections > 0) {
|
||||
$pSection = 0;
|
||||
|
||||
foreach ($sections as $section) {
|
||||
$pSection++;
|
||||
$elements = $section->getElements();
|
||||
|
||||
foreach ($elements as $element) {
|
||||
if (method_exists($element, 'getFontStyle')) {
|
||||
$fontStyle = $element->getFontStyle();
|
||||
|
||||
if ($fontStyle instanceof Font) {
|
||||
if (in_array($fontStyle->getName(), $arrFonts) == false) {
|
||||
$arrFonts[] = $fontStyle->getName();
|
||||
if (in_array($fontStyle->getName(), $fontTable) == false) {
|
||||
$fontTable[] = $fontStyle->getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -238,7 +225,7 @@ class RTF extends AbstractWriter implements WriterInterface
|
|||
}
|
||||
}
|
||||
|
||||
return $arrFonts;
|
||||
return $fontTable;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -248,11 +235,9 @@ class RTF extends AbstractWriter implements WriterInterface
|
|||
*/
|
||||
private function populateColorTable()
|
||||
{
|
||||
$phpWord = $this->phpWord;
|
||||
$phpWord = $this->getPhpWord();
|
||||
$defaultFontColor = PhpWord::DEFAULT_FONT_COLOR;
|
||||
|
||||
$arrColors = array();
|
||||
// PhpWord object : $this->phpWord
|
||||
$colorTable = array();
|
||||
|
||||
// Browse styles
|
||||
$styles = Style::getStyles();
|
||||
|
|
@ -262,11 +247,11 @@ class RTF extends AbstractWriter implements WriterInterface
|
|||
if ($style instanceof Font) {
|
||||
$color = $style->getColor();
|
||||
$fgcolor = $style->getFgColor();
|
||||
if (!in_array($color, $arrColors) && $color != $defaultFontColor && !empty($color)) {
|
||||
$arrColors[] = $color;
|
||||
if (!in_array($color, $colorTable) && $color != $defaultFontColor && !empty($color)) {
|
||||
$colorTable[] = $color;
|
||||
}
|
||||
if (!in_array($fgcolor, $arrColors) && $fgcolor != $defaultFontColor && !empty($fgcolor)) {
|
||||
$arrColors[] = $fgcolor;
|
||||
if (!in_array($fgcolor, $colorTable) && $fgcolor != $defaultFontColor && !empty($fgcolor)) {
|
||||
$colorTable[] = $fgcolor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -276,22 +261,17 @@ class RTF extends AbstractWriter implements WriterInterface
|
|||
$sections = $phpWord->getSections();
|
||||
$countSections = count($sections);
|
||||
if ($countSections > 0) {
|
||||
$pSection = 0;
|
||||
|
||||
foreach ($sections as $section) {
|
||||
$pSection++;
|
||||
$elements = $section->getElements();
|
||||
|
||||
foreach ($elements as $element) {
|
||||
if (method_exists($element, 'getFontStyle')) {
|
||||
$fontStyle = $element->getFontStyle();
|
||||
|
||||
if ($fontStyle instanceof Font) {
|
||||
if (in_array($fontStyle->getColor(), $arrColors) == false) {
|
||||
$arrColors[] = $fontStyle->getColor();
|
||||
if (in_array($fontStyle->getColor(), $colorTable) == false) {
|
||||
$colorTable[] = $fontStyle->getColor();
|
||||
}
|
||||
if (in_array($fontStyle->getFgColor(), $arrColors) == false) {
|
||||
$arrColors[] = $fontStyle->getFgColor();
|
||||
if (in_array($fontStyle->getFgColor(), $colorTable) == false) {
|
||||
$colorTable[] = $fontStyle->getFgColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -299,6 +279,6 @@ class RTF extends AbstractWriter implements WriterInterface
|
|||
}
|
||||
}
|
||||
|
||||
return $arrColors;
|
||||
return $colorTable;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,13 +23,14 @@ use PhpOffice\PhpWord\Style;
|
|||
use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle;
|
||||
use PhpOffice\PhpWord\Writer\RTF\Style\Font as FontStyleWriter;
|
||||
use PhpOffice\PhpWord\Writer\RTF\Style\Paragraph as ParagraphStyleWriter;
|
||||
use PhpOffice\PhpWord\Writer\HTML\Element\AbstractElement as HTMLAbstractElement;
|
||||
|
||||
/**
|
||||
* Abstract RTF element writer
|
||||
*
|
||||
* @since 0.11.0
|
||||
*/
|
||||
class AbstractElement extends \PhpOffice\PhpWord\Writer\HTML\Element\AbstractElement
|
||||
class AbstractElement extends HTMLAbstractElement
|
||||
{
|
||||
/**
|
||||
* Font style
|
||||
|
|
|
|||
|
|
@ -17,12 +17,14 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Writer\RTF\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Writer\HTML\Element\Container as HTMLContainer;
|
||||
|
||||
/**
|
||||
* Container element RTF writer
|
||||
*
|
||||
* @since 0.11.0
|
||||
*/
|
||||
class Container extends \PhpOffice\PhpWord\Writer\HTML\Element\Container
|
||||
class Container extends HTMLContainer
|
||||
{
|
||||
/**
|
||||
* Namespace; Can't use __NAMESPACE__ in inherited class (RTF)
|
||||
|
|
|
|||
|
|
@ -17,11 +17,13 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Writer\RTF\Style;
|
||||
|
||||
use PhpOffice\PhpWord\Writer\HTML\Style\AbstractStyle as HTMLAbstractStyle;
|
||||
|
||||
/**
|
||||
* Abstract RTF style writer
|
||||
*
|
||||
* @since 0.11.0
|
||||
*/
|
||||
abstract class AbstractStyle extends \PhpOffice\PhpWord\Writer\HTML\Style\AbstractStyle
|
||||
abstract class AbstractStyle extends HTMLAbstractStyle
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class Font extends AbstractStyle
|
|||
public function write()
|
||||
{
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
|
||||
if (!$style instanceof FontStyle) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,10 +92,7 @@ class Word2007 extends AbstractWriter implements WriterInterface
|
|||
*/
|
||||
public function save($filename = null)
|
||||
{
|
||||
if (is_null($this->phpWord)) {
|
||||
throw new Exception('PhpWord object unassigned.');
|
||||
}
|
||||
|
||||
$phpWord = $this->getPhpWord();
|
||||
$filename = $this->getTempFile($filename);
|
||||
$objZip = $this->getZipArchive($filename);
|
||||
|
||||
|
|
@ -121,7 +118,7 @@ class Word2007 extends AbstractWriter implements WriterInterface
|
|||
|
||||
// Add header/footer contents
|
||||
$rId = Media::countElements('section') + 6; // @see Rels::writeDocRels for 6 first elements
|
||||
$sections = $this->phpWord->getSections();
|
||||
$sections = $phpWord->getSections();
|
||||
foreach ($sections as $section) {
|
||||
$this->addHeaderFooterContent($section, $objZip, 'header', $rId);
|
||||
$this->addHeaderFooterContent($section, $objZip, 'footer', $rId);
|
||||
|
|
@ -223,10 +220,11 @@ class Word2007 extends AbstractWriter implements WriterInterface
|
|||
*/
|
||||
private function addNotes($objZip, &$rId, $noteType = 'footnote')
|
||||
{
|
||||
$phpWord = $this->getPhpWord();
|
||||
$noteType = ($noteType == 'endnote') ? 'endnote' : 'footnote';
|
||||
$partName = "{$noteType}s";
|
||||
$method = 'get' . $partName;
|
||||
$collection = $this->phpWord->$method();
|
||||
$collection = $phpWord->$method();
|
||||
|
||||
// Add footnotes media files, relations, and contents
|
||||
if ($collection->countItems() > 0) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Element\TextBreak as TextBreakElement;
|
||||
use PhpOffice\PhpWord\Element\AbstractContainer as ContainerElement;
|
||||
|
||||
/**
|
||||
* Container element writer (section, textrun, header, footnote, cell, etc.)
|
||||
|
|
@ -39,7 +40,7 @@ class Container extends AbstractElement
|
|||
public function write()
|
||||
{
|
||||
$container = $this->getElement();
|
||||
if (!$container instanceof \PhpOffice\PhpWord\Element\AbstractContainer) {
|
||||
if (!$container instanceof ContainerElement) {
|
||||
return;
|
||||
}
|
||||
$containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class Image extends AbstractElement
|
|||
{
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
$element = $this->getElement();
|
||||
if (!$element instanceof \PhpOffice\PhpWord\Element\Image) {
|
||||
if (!$element instanceof ImageElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class TOC extends AbstractElement
|
|||
{
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
$element = $this->getElement();
|
||||
if (!$element instanceof \PhpOffice\PhpWord\Element\TOC) {
|
||||
if (!$element instanceof TOCElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Table extends AbstractElement
|
|||
{
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
$element = $this->getElement();
|
||||
if (!$element instanceof \PhpOffice\PhpWord\Element\Table) {
|
||||
if (!$element instanceof TableElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Cell extends AbstractStyle
|
|||
public function write()
|
||||
{
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Cell) {
|
||||
if (!$style instanceof CellStyle) {
|
||||
return;
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class Image extends AbstractStyle
|
|||
public function write()
|
||||
{
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) {
|
||||
if (!$style instanceof ImageStyle) {
|
||||
return;
|
||||
}
|
||||
$this->writeStyle($style);
|
||||
|
|
@ -107,7 +107,7 @@ class Image extends AbstractStyle
|
|||
public function writeAlignment()
|
||||
{
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) {
|
||||
if (!$style instanceof ImageStyle) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class Section extends AbstractStyle
|
|||
public function write()
|
||||
{
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Section) {
|
||||
if (!$style instanceof SectionStyle) {
|
||||
return;
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Table extends AbstractStyle
|
|||
$style = $this->getStyle();
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
if ($style instanceof \PhpOffice\PhpWord\Style\Table) {
|
||||
if ($style instanceof TableStyle) {
|
||||
$this->writeStyle($xmlWriter, $style);
|
||||
} elseif (is_string($style)) {
|
||||
$xmlWriter->startElement('w:tblPr');
|
||||
|
|
@ -77,7 +77,7 @@ class Table extends AbstractStyle
|
|||
|
||||
// First row style
|
||||
$firstRow = $style->getFirstRow();
|
||||
if ($firstRow instanceof \PhpOffice\PhpWord\Style\Table) {
|
||||
if ($firstRow instanceof TableStyle) {
|
||||
$this->writeFirstRow($xmlWriter, $firstRow);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class TextBox extends Image
|
|||
public function write()
|
||||
{
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox) {
|
||||
if (!$style instanceof TextBoxStyle) {
|
||||
return;
|
||||
}
|
||||
$this->writeStyle($style);
|
||||
|
|
@ -50,7 +50,7 @@ class TextBox extends Image
|
|||
return;
|
||||
}
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox) {
|
||||
if (!$style instanceof TextBoxStyle) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ class TextBox extends Image
|
|||
public function writeInnerMargin()
|
||||
{
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox || !$style->hasInnerMargins()) {
|
||||
if (!$style instanceof TextBoxStyle || !$style->hasInnerMargins()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ interface WriterInterface
|
|||
/**
|
||||
* Save PhpWord to file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param string $filename
|
||||
*/
|
||||
public function save($pFilename = null);
|
||||
public function save($filename = null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,18 +109,6 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
$writer->save('php://output');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save with no PhpWord object assigned
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exception\Exception
|
||||
* @expectedExceptionMessage PhpWord object unassigned.
|
||||
*/
|
||||
public function testSaveException()
|
||||
{
|
||||
$writer = new ODText();
|
||||
$writer->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get writer part return null value
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -98,16 +98,4 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
|||
$writer = new RTF($phpWord);
|
||||
$writer->save('php://output');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save with no PhpWord object assigned
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exception\Exception
|
||||
* @expectedExceptionMessage PhpWord object unassigned.
|
||||
*/
|
||||
public function testSaveException()
|
||||
{
|
||||
$writer = new RTF();
|
||||
$writer->save();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,18 +122,6 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||
unlink($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save with no PhpWord object assigned
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exception\Exception
|
||||
* @expectedExceptionMessage PhpWord object unassigned.
|
||||
*/
|
||||
public function testSaveException()
|
||||
{
|
||||
$writer = new Word2007();
|
||||
$writer->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check content types
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue