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
|
||||
- Test: Add some samples and tests for image wrapping style - @brunocasado GH-59
|
||||
- Refactor: Remove Style\Tabs
|
||||
- Refactor: Apply composite pattern for writers
|
||||
|
||||
## 0.9.1 - 27 Mar 2014
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use PhpOffice\PhpWord\Endnotes;
|
|||
use PhpOffice\PhpWord\Footnotes;
|
||||
use PhpOffice\PhpWord\Media;
|
||||
use PhpOffice\PhpWord\Style;
|
||||
use PhpOffice\PhpWord\TOC;
|
||||
use PhpOffice\PhpWord\TOC as Titles;
|
||||
use PhpOffice\PhpWord\Exception\InvalidObjectException;
|
||||
use PhpOffice\PhpWord\Shared\String;
|
||||
|
||||
|
|
@ -174,7 +174,7 @@ abstract class AbstractElement
|
|||
$text = String::toUTF8($text);
|
||||
$title = new Title($text, $depth, $style);
|
||||
$title->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||
$data = TOC::addTitle($text, $depth);
|
||||
$data = Titles::addTitle($text, $depth);
|
||||
$anchor = $data[0];
|
||||
$bookmarkId = $data[1];
|
||||
$title->setAnchor($anchor);
|
||||
|
|
|
|||
|
|
@ -150,8 +150,7 @@ class HTML extends AbstractWriter implements WriterInterface
|
|||
$elements = $section->getElements();
|
||||
foreach ($elements as $element) {
|
||||
if ($element instanceof AbstractElement) {
|
||||
$elementWriter = new ElementWriter($element, false);
|
||||
$elementWriter->setParentWriter($this);
|
||||
$elementWriter = new ElementWriter($this, $element, false);
|
||||
$html .= $elementWriter->write();
|
||||
}
|
||||
}
|
||||
|
|
@ -176,8 +175,7 @@ class HTML extends AbstractWriter implements WriterInterface
|
|||
$collection = $collectionObject::getElements();
|
||||
if (array_key_exists($noteTypeId, $collection)) {
|
||||
$element = $collection[$noteTypeId];
|
||||
$elmWriter = new TextRunWriter($element, true);
|
||||
$elmWriter->setParentWriter($this);
|
||||
$elmWriter = new TextRunWriter($this, $element, true);
|
||||
$content = "<a href=\"#{$noteMark}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>" . $elmWriter->write();
|
||||
$html .= "<p><a name=\"{$noteAnchor}\" />{$content}</p>" . PHP_EOL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,8 +49,9 @@ class Element
|
|||
*
|
||||
* @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->withoutP = $withoutP;
|
||||
}
|
||||
|
|
@ -66,36 +67,10 @@ class Element
|
|||
$elmName = str_replace('PhpOffice\\PhpWord\\Element\\', '', get_class($this->element));
|
||||
$elmWriterClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element\\' . $elmName;
|
||||
if (class_exists($elmWriterClass) === true) {
|
||||
$elmWriter = new $elmWriterClass($this->element, $this->withoutP);
|
||||
$elmWriter->setParentWriter($this->parentWriter);
|
||||
$elmWriter = new $elmWriterClass($this->parentWriter, $this->element, $this->withoutP);
|
||||
$html = $elmWriter->write();
|
||||
}
|
||||
|
||||
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) {
|
||||
return $html;
|
||||
}
|
||||
if (!$this->getParentWriter()->isPdf()) {
|
||||
if (!$this->parentWriter->isPdf()) {
|
||||
$imageData = $this->getBase64ImageData($this->element);
|
||||
if (!is_null($imageData)) {
|
||||
$styleWriter = new StyleWriter();
|
||||
|
|
@ -71,8 +71,8 @@ class Image extends Element
|
|||
$zip = new $zipClass();
|
||||
if ($zip->open($zipFilename) !== false) {
|
||||
if ($zip->locateName($imageFilename)) {
|
||||
$zip->extractTo($this->getParentWriter()->getTempDir(), $imageFilename);
|
||||
$actualSource = $this->getParentWriter()->getTempDir() . DIRECTORY_SEPARATOR . $imageFilename;
|
||||
$zip->extractTo($this->parentWriter->getTempDir(), $imageFilename);
|
||||
$actualSource = $this->parentWriter->getTempDir() . DIRECTORY_SEPARATOR . $imageFilename;
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ class Note extends Element
|
|||
*/
|
||||
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';
|
||||
$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>";
|
||||
|
||||
return $html;
|
||||
|
|
|
|||
|
|
@ -39,13 +39,11 @@ class Table extends Element
|
|||
$html .= "<{$cellTag}>" . PHP_EOL;
|
||||
if (count($cellContents) > 0) {
|
||||
foreach ($cellContents as $content) {
|
||||
$writer = new Element($content, false);
|
||||
$writer->setParentWriter($this->parentWriter);
|
||||
$writer = new Element($this->parentWriter, $content, false);
|
||||
$html .= $writer->write();
|
||||
}
|
||||
} else {
|
||||
$writer = new Element(new \PhpOffice\PhpWord\Element\TextBreak(), false);
|
||||
$writer->setParentWriter($this->parentWriter);
|
||||
$writer = new Element($this->parentWriter, new \PhpOffice\PhpWord\Element\TextBreak(), false);
|
||||
$html .= $writer->write();
|
||||
}
|
||||
$html .= '</td>' . PHP_EOL;
|
||||
|
|
|
|||
|
|
@ -40,8 +40,7 @@ class TextRun extends Element
|
|||
$attribute = $pStyleIsObject ? 'style' : 'class';
|
||||
$html .= "<{$tag} {$attribute}=\"{$pStyle}\">";
|
||||
foreach ($elements as $element) {
|
||||
$elementWriter = new Element($element, true);
|
||||
$elementWriter->setParentWriter($this->parentWriter);
|
||||
$elementWriter = new Element($this->parentWriter, $element, true);
|
||||
$html .= $elementWriter->write();
|
||||
}
|
||||
$html .= "</{$tag}>";
|
||||
|
|
|
|||
Loading…
Reference in New Issue