DOCX Reader: Read titles
This commit is contained in:
parent
0060e4316c
commit
43d5aa345e
@ -27,7 +27,7 @@ This release marked heavy refactorings on internal code structure with the creat
|
|||||||
- Object: Ability to add object in header, footer, textrun, and footnote - @ivanlanin GH-187
|
- Object: Ability to add object in header, footer, textrun, and footnote - @ivanlanin GH-187
|
||||||
- Media: Add `Media::resetElements()` to reset all media data - @juzi GH-19
|
- Media: Add `Media::resetElements()` to reset all media data - @juzi GH-19
|
||||||
- General: Add `Style::resetStyles()`, `Footnote::resetElements()`, and `TOC::resetTitles()` - @ivanlanin GH-187
|
- General: Add `Style::resetStyles()`, `Footnote::resetElements()`, and `TOC::resetTitles()` - @ivanlanin GH-187
|
||||||
- DOCX Reader: Ability to read header, footer, footnotes, link, preservetext, textbreak, pagebreak, table, list, image - @ivanlanin
|
- DOCX Reader: Ability to read header, footer, footnotes, link, preservetext, textbreak, pagebreak, table, list, image, and title - @ivanlanin
|
||||||
- Endnote: Ability to add endnotes - @ivanlanin
|
- Endnote: Ability to add endnotes - @ivanlanin
|
||||||
- ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198
|
- ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198
|
||||||
- ODT Writer: Basic table writing support - @ivanlanin
|
- ODT Writer: Basic table writing support - @ivanlanin
|
||||||
|
|||||||
@ -20,7 +20,7 @@ use PhpOffice\PhpWord\Element\Section;
|
|||||||
* Reader for Word2007
|
* Reader for Word2007
|
||||||
*
|
*
|
||||||
* @since 0.8.0
|
* @since 0.8.0
|
||||||
* @todo title, list, watermark, checkbox, toc
|
* @todo watermark, checkbox, toc
|
||||||
* @todo Partly done: image, object
|
* @todo Partly done: image, object
|
||||||
*/
|
*/
|
||||||
class Word2007 extends AbstractReader implements ReaderInterface
|
class Word2007 extends AbstractReader implements ReaderInterface
|
||||||
@ -216,11 +216,14 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||||||
switch ($node->nodeName) {
|
switch ($node->nodeName) {
|
||||||
|
|
||||||
case 'w:p': // Paragraph
|
case 'w:p': // Paragraph
|
||||||
|
// Page break
|
||||||
|
// @todo <w:lastRenderedPageBreak>
|
||||||
if ($xmlReader->getAttribute('w:type', $node, 'w:r/w:br') == 'page') {
|
if ($xmlReader->getAttribute('w:type', $node, 'w:r/w:br') == 'page') {
|
||||||
$section->addPageBreak(); // PageBreak
|
$section->addPageBreak(); // PageBreak
|
||||||
} else {
|
|
||||||
$this->readParagraph($xmlReader, $node, $section, 'document');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paragraph
|
||||||
|
$this->readParagraph($xmlReader, $node, $section, 'document');
|
||||||
// Section properties
|
// Section properties
|
||||||
if ($xmlReader->elementExists('w:pPr/w:sectPr', $node)) {
|
if ($xmlReader->elementExists('w:pPr/w:sectPr', $node)) {
|
||||||
$settingsNode = $xmlReader->getElement('w:pPr/w:sectPr', $node);
|
$settingsNode = $xmlReader->getElement('w:pPr/w:sectPr', $node);
|
||||||
@ -269,18 +272,23 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||||||
if (is_null($name)) {
|
if (is_null($name)) {
|
||||||
$name = $xmlReader->getAttribute('w:val', $node, 'w:name');
|
$name = $xmlReader->getAttribute('w:val', $node, 'w:name');
|
||||||
}
|
}
|
||||||
|
preg_match('/Heading(\d)/', $name, $headingMatches);
|
||||||
// $default = ($xmlReader->getAttribute('w:default', $node) == 1);
|
// $default = ($xmlReader->getAttribute('w:default', $node) == 1);
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
|
||||||
case 'paragraph':
|
case 'paragraph':
|
||||||
$pStyle = $this->readParagraphStyle($xmlReader, $node);
|
$pStyle = $this->readParagraphStyle($xmlReader, $node);
|
||||||
$fStyle = $this->readFontStyle($xmlReader, $node);
|
$fStyle = $this->readFontStyle($xmlReader, $node);
|
||||||
if (empty($fStyle)) {
|
if (!empty($headingMatches)) {
|
||||||
if (is_array($pStyle)) {
|
$this->phpWord->addTitleStyle($headingMatches[1], $fStyle, $pStyle);
|
||||||
$this->phpWord->addParagraphStyle($name, $pStyle);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$this->phpWord->addFontStyle($name, $fStyle, $pStyle);
|
if (empty($fStyle)) {
|
||||||
|
if (is_array($pStyle)) {
|
||||||
|
$this->phpWord->addParagraphStyle($name, $pStyle);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->phpWord->addFontStyle($name, $fStyle, $pStyle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -477,8 +485,12 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||||||
{
|
{
|
||||||
// Paragraph style
|
// Paragraph style
|
||||||
$pStyle = null;
|
$pStyle = null;
|
||||||
|
$headingMatches = array();
|
||||||
if ($xmlReader->elementExists('w:pPr', $domNode)) {
|
if ($xmlReader->elementExists('w:pPr', $domNode)) {
|
||||||
$pStyle = $this->readParagraphStyle($xmlReader, $domNode);
|
$pStyle = $this->readParagraphStyle($xmlReader, $domNode);
|
||||||
|
if (is_string($pStyle)) {
|
||||||
|
preg_match('/Heading(\d)/', $pStyle, $headingMatches);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreserveText
|
// PreserveText
|
||||||
@ -518,6 +530,15 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||||||
}
|
}
|
||||||
$parent->addListItem($textContent, $levelId, null, "PHPWordList{$numId}", $pStyle);
|
$parent->addListItem($textContent, $levelId, null, "PHPWordList{$numId}", $pStyle);
|
||||||
|
|
||||||
|
// Heading
|
||||||
|
} elseif (!empty($headingMatches)) {
|
||||||
|
$textContent = '';
|
||||||
|
$nodes = $xmlReader->getElements('w:r', $domNode);
|
||||||
|
foreach ($nodes as $node) {
|
||||||
|
$textContent .= $xmlReader->getValue('w:t', $node);
|
||||||
|
}
|
||||||
|
$parent->addTitle($textContent, $headingMatches[1]);
|
||||||
|
|
||||||
// Text and TextRun
|
// Text and TextRun
|
||||||
} else {
|
} else {
|
||||||
$runCount = $xmlReader->countElements('w:r', $domNode);
|
$runCount = $xmlReader->countElements('w:r', $domNode);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user