Skip to content

Reorganize samples and write unsupported element to ODText and RTF #115

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 12 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: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ vendor
*.docx
*.rtf
*.txt
*.xml
nbproject
*.xml
4 changes: 2 additions & 2 deletions Classes/PHPWord/Reader/Word2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ public function load($pFilename)
if ($elm->getName() != 'style') {
continue;
}
unset($pStyle);
unset($fStyle);
$pStyle = null;
$fStyle = null;
$hasParagraphStyle = isset($elm->pPr);
$hasFontStyle = isset($elm->rPr);
$styleName = (string)$elm->name['val'];
Expand Down
12 changes: 9 additions & 3 deletions Classes/PHPWord/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ public function addObject($src, $style = null)
$this->_elementCollection[] = $object;
return $object;
} else {
trigger_error('Source does not exist or unsupported object type.');
throw new PHPWord_Exception(
'Source does not exist or unsupported object type.'
);
}
}

Expand All @@ -265,7 +267,9 @@ public function addImage($src, $style = null)
$this->_elementCollection[] = $image;
return $image;
} else {
trigger_error('Source does not exist or unsupported image type.');
throw new PHPWord_Exception(
'Source does not exist or unsupported image type.'
);
}
}

Expand All @@ -286,7 +290,9 @@ public function addMemoryImage($link, $style = null)
$this->_elementCollection[] = $memoryImage;
return $memoryImage;
} else {
trigger_error('Unsupported image type.');
throw new PHPWord_Exception(
'Unsupported image type.'
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Classes/PHPWord/Section/Footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function addImage($src, $style = null)
$this->_elementCollection[] = $image;
return $image;
} else {
trigger_error('Src does not exist or invalid image type.', E_USER_ERROR);
throw new Exception('Src does not exist or invalid image type.');
}
}

Expand All @@ -154,7 +154,7 @@ public function addMemoryImage($link, $style = null)
$this->_elementCollection[] = $memoryImage;
return $memoryImage;
} else {
trigger_error('Unsupported image type.');
throw new Exception('Unsupported image type.');
}
}

Expand Down
6 changes: 3 additions & 3 deletions Classes/PHPWord/Section/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function addImage($src, $style = null)
$this->_elementCollection[] = $image;
return $image;
} else {
trigger_error('Src does not exist or invalid image type.', E_USER_ERROR);
throw new Exception('Src does not exist or invalid image type.');
}
}

Expand All @@ -183,7 +183,7 @@ public function addMemoryImage($link, $style = null)
$this->_elementCollection[] = $memoryImage;
return $memoryImage;
} else {
trigger_error('Unsupported image type.');
throw new Exception('Unsupported image type.');
}
}

Expand Down Expand Up @@ -223,7 +223,7 @@ public function addWatermark($src, $style = null)
$this->_elementCollection[] = $image;
return $image;
} else {
trigger_error('Src does not exist or invalid image type.', E_USER_ERROR);
throw new Exception('Src does not exist or invalid image type.');
}
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/PHPWord/Section/MemoryImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,4 @@ public function getImageExtension()
{
return $this->_imageExtension;
}
}
}
10 changes: 5 additions & 5 deletions Classes/PHPWord/Section/Table/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function addLink($linkSrc, $linkName = null, $style = null)
$this->_elementCollection[] = $link;
return $link;
} else {
trigger_error('Unsupported Link header / footer reference');
throw new Exception('Unsupported Link header / footer reference');
return false;
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ public function addImage($src, $style = null)
$this->_elementCollection[] = $image;
return $image;
} else {
trigger_error('Source does not exist or unsupported image type.');
throw new Exception('Source does not exist or unsupported image type.');
}
}

Expand All @@ -225,7 +225,7 @@ public function addMemoryImage($link, $style = null)
$this->_elementCollection[] = $memoryImage;
return $memoryImage;
} else {
trigger_error('Unsupported image type.');
throw new Exception('Unsupported image type.');
}
}

Expand Down Expand Up @@ -266,7 +266,7 @@ public function addObject($src, $style = null)
$this->_elementCollection[] = $object;
return $object;
} else {
trigger_error('Source does not exist or unsupported object type.');
throw new Exception('Source does not exist or unsupported object type.');
}
}

Expand All @@ -288,7 +288,7 @@ public function addPreserveText($text, $styleFont = null, $styleParagraph = null
$this->_elementCollection[] = $ptext;
return $ptext;
} else {
trigger_error('addPreserveText only supported in footer/header.');
throw new Exception('addPreserveText only supported in footer/header.');
}
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/PHPWord/Section/TextRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function addImage($imageSrc, $style = null)
$this->_elementCollection[] = $image;
return $image;
} else {
trigger_error('Source does not exist or unsupported image type.');
throw new Exception('Source does not exist or unsupported image type.');
}
}

Expand Down
15 changes: 9 additions & 6 deletions Classes/PHPWord/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
/**
* PHPWord_Settings
*/
class PHPWord_Settings {
class PHPWord_Settings
{
/**
* Compatibility option for XMLWriter
*
Expand All @@ -42,12 +43,13 @@ class PHPWord_Settings {
* @param boolean $compatibility This sets the setIndent and setIndentString for better compatibility
* @return boolean Success or failure
*/
public static function setCompatibility($compatibility) {
public static function setCompatibility($compatibility)
{
if (is_bool($compatibility)) {
self::$_xmlWriterCompatibility = $compatibility;
return TRUE;
return true;
}
return FALSE;
return false;
} // function setCompatibility()


Expand All @@ -56,7 +58,8 @@ public static function setCompatibility($compatibility) {
*
* @return boolean Compatibility
*/
public static function getCompatibility() {
public static function getCompatibility()
{
return self::$_xmlWriterCompatibility;
} // function getCompatibility()
}
}
2 changes: 0 additions & 2 deletions Classes/PHPWord/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ public function __construct($type = 'text', $paragraphStyle = null)
} elseif (is_array($paragraphStyle)) {
$this->_paragraphStyle = new PHPWord_Style_Paragraph;
$this->_paragraphStyle->setArrayStyle($paragraphStyle);
} elseif (null === $paragraphStyle) {
$this->_paragraphStyle = new PHPWord_Style_Paragraph;
} else {
$this->_paragraphStyle = $paragraphStyle;
}
Expand Down
22 changes: 14 additions & 8 deletions Classes/PHPWord/Style/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,20 @@ class PHPWord_Style_Row
*
* @var bool
*/
private $_tblHeader;
private $_tblHeader = false;

/**
* Table row cannot break across pages
*
* @var bool
*/
private $_cantSplit;
private $_cantSplit = false;

/**
* Create a new row style
*/
public function __construct()
{
$this->_tblHeader = null;
$this->_cantSplit = null;
}

/**
Expand All @@ -62,23 +60,31 @@ public function setStyleValue($key, $value)
$this->$key = $value;
}

public function setTblHeader($pValue = null)
public function setTblHeader($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_tblHeader = $pValue;
return $this;
}

public function getTblHeader()
{
return $this->_tblHeader ? 1 : 0;
return $this->_tblHeader;
}

public function setCantSplit($pValue = null)
public function setCantSplit($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_cantSplit = $pValue;
return $this;
}

public function getCantSplit()
{
return $this->_cantSplit ? 1 : 0;
return $this->_cantSplit;
}
}
4 changes: 2 additions & 2 deletions Classes/PHPWord/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private function _findRowStart($offset)
$rowStart = strrpos($this->_documentXML, "<w:tr>", ((strlen($this->_documentXML) - $offset) * -1));
}
if (!$rowStart) {
trigger_error("Can not find the start position of the row to clone.");
throw new Exception("Can not find the start position of the row to clone.");
return false;
}
return $rowStart;
Expand Down Expand Up @@ -208,7 +208,7 @@ public function cloneRow($search, $numberOfClones)

$tagPos = strpos($this->_documentXML, $search);
if (!$tagPos) {
trigger_error("Can not clone row, template variable not found or variable contains markup.");
throw new Exception("Can not clone row, template variable not found or variable contains markup.");
return false;
}

Expand Down
34 changes: 22 additions & 12 deletions Classes/PHPWord/Writer/ODText/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,28 +253,25 @@ public function writeContent(PHPWord $pPHPWord = null)
$this->_writeTextRun($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTextBreak($objWriter);
/*
} elseif ($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element);
$this->writeUnsupportedElement($objWriter, 'link');
} elseif ($element instanceof PHPWord_Section_Title) {
$this->_writeTitle($objWriter, $element);
$this->writeUnsupportedElement($objWriter, 'title');
} elseif ($element instanceof PHPWord_Section_PageBreak) {
$this->_writePageBreak($objWriter);
$this->writeUnsupportedElement($objWriter, 'page break');
} elseif ($element instanceof PHPWord_Section_Table) {
$this->_writeTable($objWriter, $element);
$this->writeUnsupportedElement($objWriter, 'table');
} elseif ($element instanceof PHPWord_Section_ListItem) {
$this->_writeListItem($objWriter, $element);
$this->writeUnsupportedElement($objWriter, 'list item');
} elseif ($element instanceof PHPWord_Section_Image ||
$element instanceof PHPWord_Section_MemoryImage) {
$this->_writeImage($objWriter, $element);
$this->writeUnsupportedElement($objWriter, 'image');
} elseif ($element instanceof PHPWord_Section_Object) {
$this->_writeObject($objWriter, $element);
$this->writeUnsupportedElement($objWriter, 'object');
} elseif ($element instanceof PHPWord_TOC) {
$this->_writeTOC($objWriter);
*/
$this->writeUnsupportedElement($objWriter, 'TOC');
} else {
print_r($element);
echo '<br />';
$this->writeUnsupportedElement($objWriter, 'other');
}
}

Expand Down Expand Up @@ -387,4 +384,17 @@ private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PH
private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null)
{
}

/**
* Write unsupported element
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param string $element
*/
private function writeUnsupportedElement($objWriter, $element)
{
$objWriter->startElement('text:p');
$objWriter->writeRaw("Cannot write content. This version of PHPWord has not supported {$element} element in ODText.");
$objWriter->endElement();
}
}
Loading