Update changelog and fine tune changes
This commit is contained in:
parent
2be4cbf131
commit
2567a2223c
|
|
@ -73,6 +73,7 @@ This release marked heavy refactorings on internal code structure with the creat
|
||||||
- General: Add some unit tests for Shared & Element (100%!) - @Progi1984
|
- General: Add some unit tests for Shared & Element (100%!) - @Progi1984
|
||||||
- Test: Add some samples and tests for image wrapping style - @brunocasado GH-59
|
- Test: Add some samples and tests for image wrapping style - @brunocasado GH-59
|
||||||
- Refactor: Remove Style\Tabs
|
- Refactor: Remove Style\Tabs
|
||||||
|
- Refactor: Apply composite pattern for writers
|
||||||
|
|
||||||
## 0.9.1 - 27 Mar 2014
|
## 0.9.1 - 27 Mar 2014
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ use PhpOffice\PhpWord\Endnotes;
|
||||||
use PhpOffice\PhpWord\Footnotes;
|
use PhpOffice\PhpWord\Footnotes;
|
||||||
use PhpOffice\PhpWord\Media;
|
use PhpOffice\PhpWord\Media;
|
||||||
use PhpOffice\PhpWord\Style;
|
use PhpOffice\PhpWord\Style;
|
||||||
use PhpOffice\PhpWord\TOC;
|
use PhpOffice\PhpWord\TOC as Titles;
|
||||||
use PhpOffice\PhpWord\Exception\InvalidObjectException;
|
use PhpOffice\PhpWord\Exception\InvalidObjectException;
|
||||||
use PhpOffice\PhpWord\Shared\String;
|
use PhpOffice\PhpWord\Shared\String;
|
||||||
|
|
||||||
|
|
@ -174,7 +174,7 @@ abstract class AbstractElement
|
||||||
$text = String::toUTF8($text);
|
$text = String::toUTF8($text);
|
||||||
$title = new Title($text, $depth, $style);
|
$title = new Title($text, $depth, $style);
|
||||||
$title->setDocPart($this->getDocPart(), $this->getDocPartId());
|
$title->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||||
$data = TOC::addTitle($text, $depth);
|
$data = Titles::addTitle($text, $depth);
|
||||||
$anchor = $data[0];
|
$anchor = $data[0];
|
||||||
$bookmarkId = $data[1];
|
$bookmarkId = $data[1];
|
||||||
$title->setAnchor($anchor);
|
$title->setAnchor($anchor);
|
||||||
|
|
|
||||||
|
|
@ -150,8 +150,7 @@ class HTML extends AbstractWriter implements WriterInterface
|
||||||
$elements = $section->getElements();
|
$elements = $section->getElements();
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
if ($element instanceof AbstractElement) {
|
if ($element instanceof AbstractElement) {
|
||||||
$elementWriter = new ElementWriter($element, false);
|
$elementWriter = new ElementWriter($this, $element, false);
|
||||||
$elementWriter->setParentWriter($this);
|
|
||||||
$html .= $elementWriter->write();
|
$html .= $elementWriter->write();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -176,8 +175,7 @@ class HTML extends AbstractWriter implements WriterInterface
|
||||||
$collection = $collectionObject::getElements();
|
$collection = $collectionObject::getElements();
|
||||||
if (array_key_exists($noteTypeId, $collection)) {
|
if (array_key_exists($noteTypeId, $collection)) {
|
||||||
$element = $collection[$noteTypeId];
|
$element = $collection[$noteTypeId];
|
||||||
$elmWriter = new TextRunWriter($element, true);
|
$elmWriter = new TextRunWriter($this, $element, true);
|
||||||
$elmWriter->setParentWriter($this);
|
|
||||||
$content = "<a href=\"#{$noteMark}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>" . $elmWriter->write();
|
$content = "<a href=\"#{$noteMark}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>" . $elmWriter->write();
|
||||||
$html .= "<p><a name=\"{$noteAnchor}\" />{$content}</p>" . PHP_EOL;
|
$html .= "<p><a name=\"{$noteAnchor}\" />{$content}</p>" . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,9 @@ class Element
|
||||||
*
|
*
|
||||||
* @param bool $withoutP
|
* @param bool $withoutP
|
||||||
*/
|
*/
|
||||||
public function __construct(AbstractElement $element, $withoutP = false)
|
public function __construct(HTML $parentWriter, AbstractElement $element, $withoutP = false)
|
||||||
{
|
{
|
||||||
|
$this->parentWriter = $parentWriter;
|
||||||
$this->element = $element;
|
$this->element = $element;
|
||||||
$this->withoutP = $withoutP;
|
$this->withoutP = $withoutP;
|
||||||
}
|
}
|
||||||
|
|
@ -66,36 +67,10 @@ class Element
|
||||||
$elmName = str_replace('PhpOffice\\PhpWord\\Element\\', '', get_class($this->element));
|
$elmName = str_replace('PhpOffice\\PhpWord\\Element\\', '', get_class($this->element));
|
||||||
$elmWriterClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element\\' . $elmName;
|
$elmWriterClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element\\' . $elmName;
|
||||||
if (class_exists($elmWriterClass) === true) {
|
if (class_exists($elmWriterClass) === true) {
|
||||||
$elmWriter = new $elmWriterClass($this->element, $this->withoutP);
|
$elmWriter = new $elmWriterClass($this->parentWriter, $this->element, $this->withoutP);
|
||||||
$elmWriter->setParentWriter($this->parentWriter);
|
|
||||||
$html = $elmWriter->write();
|
$html = $elmWriter->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set parent writer
|
|
||||||
*
|
|
||||||
* @param \PhpOffice\PhpWord\Writer\HTML $writer
|
|
||||||
*/
|
|
||||||
public function setParentWriter(HTML $writer)
|
|
||||||
{
|
|
||||||
$this->parentWriter = $writer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get parent writer
|
|
||||||
*
|
|
||||||
* @return \PhpOffice\PhpWord\Writer\HTML
|
|
||||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
|
||||||
*/
|
|
||||||
public function getParentWriter()
|
|
||||||
{
|
|
||||||
if (!is_null($this->parentWriter)) {
|
|
||||||
return $this->parentWriter;
|
|
||||||
} else {
|
|
||||||
throw new Exception("No parent HTML Writer assigned.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class Image extends Element
|
||||||
if (!$this->element instanceof ImageElement) {
|
if (!$this->element instanceof ImageElement) {
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
if (!$this->getParentWriter()->isPdf()) {
|
if (!$this->parentWriter->isPdf()) {
|
||||||
$imageData = $this->getBase64ImageData($this->element);
|
$imageData = $this->getBase64ImageData($this->element);
|
||||||
if (!is_null($imageData)) {
|
if (!is_null($imageData)) {
|
||||||
$styleWriter = new StyleWriter();
|
$styleWriter = new StyleWriter();
|
||||||
|
|
@ -71,8 +71,8 @@ class Image extends Element
|
||||||
$zip = new $zipClass();
|
$zip = new $zipClass();
|
||||||
if ($zip->open($zipFilename) !== false) {
|
if ($zip->open($zipFilename) !== false) {
|
||||||
if ($zip->locateName($imageFilename)) {
|
if ($zip->locateName($imageFilename)) {
|
||||||
$zip->extractTo($this->getParentWriter()->getTempDir(), $imageFilename);
|
$zip->extractTo($this->parentWriter->getTempDir(), $imageFilename);
|
||||||
$actualSource = $this->getParentWriter()->getTempDir() . DIRECTORY_SEPARATOR . $imageFilename;
|
$actualSource = $this->parentWriter->getTempDir() . DIRECTORY_SEPARATOR . $imageFilename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,10 @@ class Note extends Element
|
||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
$noteId = count($this->getParentWriter()->getNotes()) + 1;
|
$noteId = count($this->parentWriter->getNotes()) + 1;
|
||||||
$prefix = ($this->element instanceof \PhpOffice\PhpWord\Element\Endnote) ? 'endnote' : 'footnote';
|
$prefix = ($this->element instanceof \PhpOffice\PhpWord\Element\Endnote) ? 'endnote' : 'footnote';
|
||||||
$noteMark = $prefix . '-' . $this->element->getRelationId();
|
$noteMark = $prefix . '-' . $this->element->getRelationId();
|
||||||
$this->getParentWriter()->addNote($noteId, $noteMark);
|
$this->parentWriter->addNote($noteId, $noteMark);
|
||||||
$html = "<a name=\"{$noteMark}\"><a href=\"#note-{$noteId}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>";
|
$html = "<a name=\"{$noteMark}\"><a href=\"#note-{$noteId}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>";
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
|
|
|
||||||
|
|
@ -39,13 +39,11 @@ class Table extends Element
|
||||||
$html .= "<{$cellTag}>" . PHP_EOL;
|
$html .= "<{$cellTag}>" . PHP_EOL;
|
||||||
if (count($cellContents) > 0) {
|
if (count($cellContents) > 0) {
|
||||||
foreach ($cellContents as $content) {
|
foreach ($cellContents as $content) {
|
||||||
$writer = new Element($content, false);
|
$writer = new Element($this->parentWriter, $content, false);
|
||||||
$writer->setParentWriter($this->parentWriter);
|
|
||||||
$html .= $writer->write();
|
$html .= $writer->write();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$writer = new Element(new \PhpOffice\PhpWord\Element\TextBreak(), false);
|
$writer = new Element($this->parentWriter, new \PhpOffice\PhpWord\Element\TextBreak(), false);
|
||||||
$writer->setParentWriter($this->parentWriter);
|
|
||||||
$html .= $writer->write();
|
$html .= $writer->write();
|
||||||
}
|
}
|
||||||
$html .= '</td>' . PHP_EOL;
|
$html .= '</td>' . PHP_EOL;
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,7 @@ class TextRun extends Element
|
||||||
$attribute = $pStyleIsObject ? 'style' : 'class';
|
$attribute = $pStyleIsObject ? 'style' : 'class';
|
||||||
$html .= "<{$tag} {$attribute}=\"{$pStyle}\">";
|
$html .= "<{$tag} {$attribute}=\"{$pStyle}\">";
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
$elementWriter = new Element($element, true);
|
$elementWriter = new Element($this->parentWriter, $element, true);
|
||||||
$elementWriter->setParentWriter($this->parentWriter);
|
|
||||||
$html .= $elementWriter->write();
|
$html .= $elementWriter->write();
|
||||||
}
|
}
|
||||||
$html .= "</{$tag}>";
|
$html .= "</{$tag}>";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue