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
|
||||
- Media: Add `Media::resetElements()` to reset all media data - @juzi GH-19
|
||||
- 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
|
||||
- ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198
|
||||
- ODT Writer: Basic table writing support - @ivanlanin
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ use PhpOffice\PhpWord\Element\Section;
|
|||
* Reader for Word2007
|
||||
*
|
||||
* @since 0.8.0
|
||||
* @todo title, list, watermark, checkbox, toc
|
||||
* @todo watermark, checkbox, toc
|
||||
* @todo Partly done: image, object
|
||||
*/
|
||||
class Word2007 extends AbstractReader implements ReaderInterface
|
||||
|
|
@ -216,11 +216,14 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||
switch ($node->nodeName) {
|
||||
|
||||
case 'w:p': // Paragraph
|
||||
// Page break
|
||||
// @todo <w:lastRenderedPageBreak>
|
||||
if ($xmlReader->getAttribute('w:type', $node, 'w:r/w:br') == 'page') {
|
||||
$section->addPageBreak(); // PageBreak
|
||||
} else {
|
||||
$this->readParagraph($xmlReader, $node, $section, 'document');
|
||||
}
|
||||
|
||||
// Paragraph
|
||||
$this->readParagraph($xmlReader, $node, $section, 'document');
|
||||
// Section properties
|
||||
if ($xmlReader->elementExists('w:pPr/w:sectPr', $node)) {
|
||||
$settingsNode = $xmlReader->getElement('w:pPr/w:sectPr', $node);
|
||||
|
|
@ -269,12 +272,16 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||
if (is_null($name)) {
|
||||
$name = $xmlReader->getAttribute('w:val', $node, 'w:name');
|
||||
}
|
||||
preg_match('/Heading(\d)/', $name, $headingMatches);
|
||||
// $default = ($xmlReader->getAttribute('w:default', $node) == 1);
|
||||
switch ($type) {
|
||||
|
||||
case 'paragraph':
|
||||
$pStyle = $this->readParagraphStyle($xmlReader, $node);
|
||||
$fStyle = $this->readFontStyle($xmlReader, $node);
|
||||
if (!empty($headingMatches)) {
|
||||
$this->phpWord->addTitleStyle($headingMatches[1], $fStyle, $pStyle);
|
||||
} else {
|
||||
if (empty($fStyle)) {
|
||||
if (is_array($pStyle)) {
|
||||
$this->phpWord->addParagraphStyle($name, $pStyle);
|
||||
|
|
@ -282,6 +289,7 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||
} else {
|
||||
$this->phpWord->addFontStyle($name, $fStyle, $pStyle);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'character':
|
||||
|
|
@ -477,8 +485,12 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||
{
|
||||
// Paragraph style
|
||||
$pStyle = null;
|
||||
$headingMatches = array();
|
||||
if ($xmlReader->elementExists('w:pPr', $domNode)) {
|
||||
$pStyle = $this->readParagraphStyle($xmlReader, $domNode);
|
||||
if (is_string($pStyle)) {
|
||||
preg_match('/Heading(\d)/', $pStyle, $headingMatches);
|
||||
}
|
||||
}
|
||||
|
||||
// PreserveText
|
||||
|
|
@ -518,6 +530,15 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||
}
|
||||
$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
|
||||
} else {
|
||||
$runCount = $xmlReader->countElements('w:r', $domNode);
|
||||
|
|
|
|||
Loading…
Reference in New Issue