|
20 | 20 | * Reader for Word2007
|
21 | 21 | *
|
22 | 22 | * @since 0.8.0
|
23 |
| - * @todo title, list, watermark, checkbox, toc |
| 23 | + * @todo watermark, checkbox, toc |
24 | 24 | * @todo Partly done: image, object
|
25 | 25 | */
|
26 | 26 | class Word2007 extends AbstractReader implements ReaderInterface
|
@@ -216,11 +216,14 @@ private function readDocument($xmlFile)
|
216 | 216 | switch ($node->nodeName) {
|
217 | 217 |
|
218 | 218 | case 'w:p': // Paragraph
|
| 219 | + // Page break |
| 220 | + // @todo <w:lastRenderedPageBreak> |
219 | 221 | if ($xmlReader->getAttribute('w:type', $node, 'w:r/w:br') == 'page') {
|
220 | 222 | $section->addPageBreak(); // PageBreak
|
221 |
| - } else { |
222 |
| - $this->readParagraph($xmlReader, $node, $section, 'document'); |
223 | 223 | }
|
| 224 | + |
| 225 | + // Paragraph |
| 226 | + $this->readParagraph($xmlReader, $node, $section, 'document'); |
224 | 227 | // Section properties
|
225 | 228 | if ($xmlReader->elementExists('w:pPr/w:sectPr', $node)) {
|
226 | 229 | $settingsNode = $xmlReader->getElement('w:pPr/w:sectPr', $node);
|
@@ -269,18 +272,23 @@ private function readStyles($xmlFile)
|
269 | 272 | if (is_null($name)) {
|
270 | 273 | $name = $xmlReader->getAttribute('w:val', $node, 'w:name');
|
271 | 274 | }
|
| 275 | + preg_match('/Heading(\d)/', $name, $headingMatches); |
272 | 276 | // $default = ($xmlReader->getAttribute('w:default', $node) == 1);
|
273 | 277 | switch ($type) {
|
274 | 278 |
|
275 | 279 | case 'paragraph':
|
276 | 280 | $pStyle = $this->readParagraphStyle($xmlReader, $node);
|
277 | 281 | $fStyle = $this->readFontStyle($xmlReader, $node);
|
278 |
| - if (empty($fStyle)) { |
279 |
| - if (is_array($pStyle)) { |
280 |
| - $this->phpWord->addParagraphStyle($name, $pStyle); |
281 |
| - } |
| 282 | + if (!empty($headingMatches)) { |
| 283 | + $this->phpWord->addTitleStyle($headingMatches[1], $fStyle, $pStyle); |
282 | 284 | } else {
|
283 |
| - $this->phpWord->addFontStyle($name, $fStyle, $pStyle); |
| 285 | + if (empty($fStyle)) { |
| 286 | + if (is_array($pStyle)) { |
| 287 | + $this->phpWord->addParagraphStyle($name, $pStyle); |
| 288 | + } |
| 289 | + } else { |
| 290 | + $this->phpWord->addFontStyle($name, $fStyle, $pStyle); |
| 291 | + } |
284 | 292 | }
|
285 | 293 | break;
|
286 | 294 |
|
@@ -477,8 +485,12 @@ private function readParagraph(XMLReader $xmlReader, \DOMElement $domNode, &$par
|
477 | 485 | {
|
478 | 486 | // Paragraph style
|
479 | 487 | $pStyle = null;
|
| 488 | + $headingMatches = array(); |
480 | 489 | if ($xmlReader->elementExists('w:pPr', $domNode)) {
|
481 | 490 | $pStyle = $this->readParagraphStyle($xmlReader, $domNode);
|
| 491 | + if (is_string($pStyle)) { |
| 492 | + preg_match('/Heading(\d)/', $pStyle, $headingMatches); |
| 493 | + } |
482 | 494 | }
|
483 | 495 |
|
484 | 496 | // PreserveText
|
@@ -518,6 +530,15 @@ private function readParagraph(XMLReader $xmlReader, \DOMElement $domNode, &$par
|
518 | 530 | }
|
519 | 531 | $parent->addListItem($textContent, $levelId, null, "PHPWordList{$numId}", $pStyle);
|
520 | 532 |
|
| 533 | + // Heading |
| 534 | + } elseif (!empty($headingMatches)) { |
| 535 | + $textContent = ''; |
| 536 | + $nodes = $xmlReader->getElements('w:r', $domNode); |
| 537 | + foreach ($nodes as $node) { |
| 538 | + $textContent .= $xmlReader->getValue('w:t', $node); |
| 539 | + } |
| 540 | + $parent->addTitle($textContent, $headingMatches[1]); |
| 541 | + |
521 | 542 | // Text and TextRun
|
522 | 543 | } else {
|
523 | 544 | $runCount = $xmlReader->countElements('w:r', $domNode);
|
|
0 commit comments