Type checking
This commit is contained in:
parent
c4e8fdac84
commit
0c1e47d7a7
|
|
@ -38,6 +38,10 @@ class Footnote extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Footnote) {
|
||||
return;
|
||||
}
|
||||
|
||||
$noteId = count($this->parentWriter->getNotes()) + 1;
|
||||
$noteMark = $this->noteType . '-' . $this->element->getRelationId();
|
||||
$this->parentWriter->addNote($noteId, $noteMark);
|
||||
|
|
|
|||
|
|
@ -34,10 +34,11 @@ class Image extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
$html = '';
|
||||
if (!$this->element instanceof ImageElement) {
|
||||
return $html;
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Text) {
|
||||
return;
|
||||
}
|
||||
|
||||
$html = '';
|
||||
if (!$this->parentWriter->isPdf()) {
|
||||
$imageData = $this->getBase64ImageData($this->element);
|
||||
if (!is_null($imageData)) {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ class Link extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Link) {
|
||||
return;
|
||||
}
|
||||
|
||||
$html = "<a href=\"{$this->element->getTarget()}\">{$this->element->getText()}</a>" . PHP_EOL;
|
||||
if (!$this->withoutP) {
|
||||
$html = '<p>' . $html . '</p>' . PHP_EOL;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ class ListItem extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\ListItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
$text = htmlspecialchars($this->element->getTextObject()->getText());
|
||||
$html = '<p>' . $text . '</p>' . PHP_EOL;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ class Table extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Table) {
|
||||
return;
|
||||
}
|
||||
|
||||
$html = '';
|
||||
$rows = $this->element->getRows();
|
||||
$rowCount = count($rows);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ class Text extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Text) {
|
||||
return;
|
||||
}
|
||||
|
||||
$html = '';
|
||||
// Paragraph style
|
||||
$paragraphStyle = $this->element->getParagraphStyle();
|
||||
|
|
@ -44,6 +48,8 @@ class Text extends Element
|
|||
$styleWriter = new ParagraphStyleWriter($paragraphStyle);
|
||||
$paragraphStyle = $styleWriter->write();
|
||||
}
|
||||
$hasParagraphStyle = $paragraphStyle && !$this->withoutP;
|
||||
|
||||
// Font style
|
||||
$fontStyle = $this->element->getFontStyle();
|
||||
$fontStyleIsObject = ($fontStyle instanceof Font);
|
||||
|
|
@ -52,7 +58,7 @@ class Text extends Element
|
|||
$fontStyle = $styleWriter->write();
|
||||
}
|
||||
|
||||
if ($paragraphStyle && !$this->withoutP) {
|
||||
if ($hasParagraphStyle) {
|
||||
$attribute = $pStyleIsObject ? 'style' : 'class';
|
||||
$html .= "<p {$attribute}=\"{$paragraphStyle}\">";
|
||||
}
|
||||
|
|
@ -64,7 +70,7 @@ class Text extends Element
|
|||
if ($fontStyle) {
|
||||
$html .= '</span>';
|
||||
}
|
||||
if ($paragraphStyle && !$this->withoutP) {
|
||||
if ($hasParagraphStyle) {
|
||||
$html .= '</p>' . PHP_EOL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ class TextRun extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\TextRun) {
|
||||
return;
|
||||
}
|
||||
|
||||
$html = '';
|
||||
$elements = $this->element->getElements();
|
||||
if (count($elements) > 0) {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ class Title extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Title) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tag = 'h' . $this->element->getDepth();
|
||||
$text = htmlspecialchars($this->element->getText());
|
||||
$html = "<{$tag}>{$text}</{$tag}>" . PHP_EOL;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ class Image extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Image) {
|
||||
return;
|
||||
}
|
||||
|
||||
$mediaIndex = $this->element->getMediaIndex();
|
||||
$target = 'Pictures/' . $this->element->getTarget();
|
||||
$style = $this->element->getStyle();
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ class Link extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Link) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->withoutP) {
|
||||
$this->xmlWriter->startElement('text:p'); // text:p
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ class Table extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Table) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rows = $this->element->getRows();
|
||||
$rowCount = count($rows);
|
||||
$colCount = $this->element->countColumns();
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ class Text extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Text) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fontStyle = $this->element->getFontStyle();
|
||||
$paragraphStyle = $this->element->getParagraphStyle();
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Writer\ODText\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Element\Link as LinkElement;
|
||||
use PhpOffice\PhpWord\Element\Text as TextElement;
|
||||
|
||||
/**
|
||||
|
|
@ -31,6 +32,10 @@ class TextRun extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\TextRun) {
|
||||
return;
|
||||
}
|
||||
|
||||
$elements = $this->element->getElements();
|
||||
$this->xmlWriter->startElement('text:p');
|
||||
if (count($elements) > 0) {
|
||||
|
|
@ -38,7 +43,7 @@ class TextRun extends Element
|
|||
if ($element instanceof TextElement) {
|
||||
$elementWriter = new Text($this->xmlWriter, $this->parentWriter, $element, true);
|
||||
$elementWriter->write();
|
||||
} elseif ($element instanceof Link) {
|
||||
} elseif ($element instanceof LinkElement) {
|
||||
$elementWriter = new Link($this->xmlWriter, $this->parentWriter, $element, true);
|
||||
$elementWriter->write();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ class Text extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Text) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rtfText = '';
|
||||
|
||||
$fontStyle = $this->element->getFontStyle();
|
||||
|
|
|
|||
|
|
@ -33,7 +33,12 @@ class TextRun extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\TextRun) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rtfText = '';
|
||||
|
||||
$elements = $this->element->getElements();
|
||||
if (count($elements) > 0) {
|
||||
$rtfText .= '\pard\nowidctlpar' . PHP_EOL;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,12 @@ class Title extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Title) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rtfText = '';
|
||||
|
||||
$rtfText .= '\pard\nowidctlpar' . PHP_EOL;
|
||||
$rtfText .= $this->element->getText();
|
||||
$rtfText .= '\par' . PHP_EOL;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ class CheckBox extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\CheckBox) {
|
||||
return;
|
||||
}
|
||||
|
||||
$name = htmlspecialchars($this->element->getName());
|
||||
$name = String::controlCharacterPHP2OOXML($name);
|
||||
$text = htmlspecialchars($this->element->getText());
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ class Footnote extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Footnote) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->withoutP) {
|
||||
$this->xmlWriter->startElement('w:p');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,10 @@ class Image extends Element
|
|||
*/
|
||||
private function writeImage()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Image) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rId = $this->element->getRelationId() + ($this->element->isInSection() ? 6 : 0);
|
||||
$style = $this->element->getStyle();
|
||||
$styleWriter = new ImageStyleWriter($this->xmlWriter, $style);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ class Link extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Link) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rId = $this->element->getRelationId() + ($this->element->isInSection() ? 6 : 0);
|
||||
$fontStyle = $this->element->getFontStyle();
|
||||
$paragraphStyle = $this->element->getParagraphStyle();
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ class ListItem extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\ListItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
$textObject = $this->element->getTextObject();
|
||||
$depth = $this->element->getDepth();
|
||||
$numId = $this->element->getStyle()->getNumId();
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ class Object extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Object) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rIdObject = $this->element->getRelationId() + ($this->element->isInSection() ? 6 : 0);
|
||||
$rIdImage = $this->element->getImageRelationId() + ($this->element->isInSection() ? 6 : 0);
|
||||
$shapeId = md5($rIdObject . '_' . $rIdImage);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ class PreserveText extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\PreserveText) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fontStyle = $this->element->getFontStyle();
|
||||
$paragraphStyle = $this->element->getParagraphStyle();
|
||||
$texts = $this->element->getText();
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ class TOC extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\TOC) {
|
||||
return;
|
||||
}
|
||||
|
||||
$titles = $this->element->getTitles();
|
||||
$writeFieldMark = true;
|
||||
|
||||
|
|
@ -55,6 +59,9 @@ class TOC extends Element
|
|||
|
||||
/**
|
||||
* Write title
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Element\Title $title
|
||||
* @param bool $writeFieldMark
|
||||
*/
|
||||
private function writeTitle($title, $writeFieldMark)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ class Table extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Table) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rows = $this->element->getRows();
|
||||
$rowCount = count($rows);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ class Text extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Text) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fontStyle = $this->element->getFontStyle();
|
||||
$paragraphStyle = $this->element->getParagraphStyle();
|
||||
$text = htmlspecialchars($this->element->getText());
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ class TextRun extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\TextRun) {
|
||||
return;
|
||||
}
|
||||
|
||||
$paragraphStyle = $this->element->getParagraphStyle();
|
||||
$styleWriter = new ParagraphStyleWriter($this->xmlWriter, $paragraphStyle);
|
||||
$styleWriter->setIsInline(true);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ class Title extends Element
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Title) {
|
||||
return;
|
||||
}
|
||||
|
||||
$bookmarkId = $this->element->getBookmarkId();
|
||||
$anchor = '_Toc' . ($bookmarkId + 252634154);
|
||||
$style = $this->element->getStyle();
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class Rels extends AbstractPart
|
|||
}
|
||||
|
||||
// Media relationships
|
||||
if (!is_null($mediaRels) && is_array($mediaRels)) {
|
||||
if (is_array($mediaRels)) {
|
||||
$mapping = array('image' => 'image', 'object' => 'oleObject', 'link' => 'hyperlink');
|
||||
$targetPaths = array('image' => 'media/', 'object' => 'embeddings/');
|
||||
foreach ($mediaRels as $mediaRel) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue