Namespace alias

This commit is contained in:
Ivan Lanin 2014-03-30 22:53:47 +07:00
parent 41407825a2
commit f911f5ccbe
2 changed files with 31 additions and 42 deletions

View File

@ -10,6 +10,7 @@
namespace PhpOffice\PhpWord; namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\TOC as TOCStyle;
/** /**
* Table of contents * Table of contents
@ -26,14 +27,14 @@ class TOC
/** /**
* TOC style * TOC style
* *
* @var PhpOffice\PhpWord\Style\TOC * @var TOCStyle
*/ */
private static $_styleTOC; private static $_styleTOC;
/** /**
* Font style * Font style
* *
* @var PhpOffice\PhpWord\Style\Font|array|string * @var Font|array|string
*/ */
private static $_styleFont; private static $_styleFont;
@ -60,7 +61,7 @@ class TOC
*/ */
public function __construct($styleFont = null, $styleTOC = null) public function __construct($styleFont = null, $styleTOC = null)
{ {
self::$_styleTOC = new \PhpOffice\PhpWord\Style\TOC(); self::$_styleTOC = new TOCStyle();
if (!is_null($styleTOC) && is_array($styleTOC)) { if (!is_null($styleTOC) && is_array($styleTOC)) {
foreach ($styleTOC as $key => $value) { foreach ($styleTOC as $key => $value) {
@ -122,7 +123,7 @@ class TOC
/** /**
* Get TOC Style * Get TOC Style
* *
* @return \PhpOffice\PhpWord\Style\TOC * @return TOCStyle
*/ */
public static function getStyleTOC() public static function getStyleTOC()
{ {
@ -132,7 +133,7 @@ class TOC
/** /**
* Get Font Style * Get Font Style
* *
* @return \PhpOffice\PhpWord\Style\Font * @return Font
*/ */
public static function getStyleFont() public static function getStyleFont()
{ {

View File

@ -50,9 +50,7 @@ class Base extends WriterPart
$withoutP = false $withoutP = false
) { ) {
$styleFont = $text->getFontStyle(); $styleFont = $text->getFontStyle();
$sfIsObject = ($styleFont instanceof Font) ? true : false;
$styleParagraph = $text->getParagraphStyle(); $styleParagraph = $text->getParagraphStyle();
$spIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
$strText = htmlspecialchars($text->getText()); $strText = htmlspecialchars($text->getText());
$strText = String::controlCharacterPHP2OOXML($strText); $strText = String::controlCharacterPHP2OOXML($strText);
@ -84,7 +82,6 @@ class Base extends WriterPart
) { ) {
$elements = $textrun->getElements(); $elements = $textrun->getElements();
$styleParagraph = $textrun->getParagraphStyle(); $styleParagraph = $textrun->getParagraphStyle();
$spIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
$xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
$this->writeInlineParagraphStyle($xmlWriter, $styleParagraph); $this->writeInlineParagraphStyle($xmlWriter, $styleParagraph);
if (count($elements) > 0) { if (count($elements) > 0) {
@ -123,9 +120,7 @@ class Base extends WriterPart
$linkName = $link->getLinkSrc(); $linkName = $link->getLinkSrc();
} }
$styleFont = $link->getFontStyle(); $styleFont = $link->getFontStyle();
$sfIsObject = ($styleFont instanceof Font) ? true : false;
$styleParagraph = $link->getParagraphStyle(); $styleParagraph = $link->getParagraphStyle();
$spIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
if (!$withoutP) { if (!$withoutP) {
$xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
@ -206,9 +201,7 @@ class Base extends WriterPart
PreserveText $textrun PreserveText $textrun
) { ) {
$styleFont = $textrun->getFontStyle(); $styleFont = $textrun->getFontStyle();
$sfIsObject = ($styleFont instanceof Font) ? true : false;
$styleParagraph = $textrun->getParagraphStyle(); $styleParagraph = $textrun->getParagraphStyle();
$spIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
$arrText = $textrun->getText(); $arrText = $textrun->getText();
if (!is_array($arrText)) { if (!is_array($arrText)) {
@ -272,11 +265,11 @@ class Base extends WriterPart
protected function writeTextBreak($xmlWriter, TextBreak $element = null) protected function writeTextBreak($xmlWriter, TextBreak $element = null)
{ {
$hasStyle = false; $hasStyle = false;
$styleFont = null;
$styleParagraph = null;
if (!is_null($element)) { if (!is_null($element)) {
$styleFont = $element->getFontStyle(); $styleFont = $element->getFontStyle();
$sfIsObject = ($styleFont instanceof Font) ? true : false;
$styleParagraph = $element->getParagraphStyle(); $styleParagraph = $element->getParagraphStyle();
$spIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
$hasStyle = !is_null($styleFont) || !is_null($styleParagraph); $hasStyle = !is_null($styleFont) || !is_null($styleParagraph);
} }
if ($hasStyle) { if ($hasStyle) {
@ -303,11 +296,9 @@ class Base extends WriterPart
protected function writeListItem(XMLWriter $xmlWriter, ListItem $listItem) protected function writeListItem(XMLWriter $xmlWriter, ListItem $listItem)
{ {
$textObject = $listItem->getTextObject(); $textObject = $listItem->getTextObject();
$text = $textObject->getText();
$depth = $listItem->getDepth(); $depth = $listItem->getDepth();
$listType = $listItem->getStyle()->getListType(); $listType = $listItem->getStyle()->getListType();
$styleParagraph = $textObject->getParagraphStyle(); $styleParagraph = $textObject->getParagraphStyle();
$spIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
$xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:pPr'); $xmlWriter->startElement('w:pPr');
@ -619,8 +610,6 @@ class Base extends WriterPart
$shapeId = md5($rIdObject . '_' . $rIdImage); $shapeId = md5($rIdObject . '_' . $rIdImage);
$objectId = $object->getObjectId(); $objectId = $object->getObjectId();
$style = $object->getStyle(); $style = $object->getStyle();
$width = $style->getWidth();
$height = $style->getHeight();
$align = $style->getAlign(); $align = $style->getAlign();
$xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
@ -705,9 +694,7 @@ class Base extends WriterPart
$text = htmlspecialchars($checkbox->getText()); $text = htmlspecialchars($checkbox->getText());
$text = String::controlCharacterPHP2OOXML($text); $text = String::controlCharacterPHP2OOXML($text);
$styleFont = $checkbox->getFontStyle(); $styleFont = $checkbox->getFontStyle();
$sfIsObject = ($styleFont instanceof Font) ? true : false;
$styleParagraph = $checkbox->getParagraphStyle(); $styleParagraph = $checkbox->getParagraphStyle();
$spIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
if (!$withoutP) { if (!$withoutP) {
$xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:p');
@ -774,7 +761,7 @@ class Base extends WriterPart
*/ */
protected function writeParagraphStyle( protected function writeParagraphStyle(
XMLWriter $xmlWriter, XMLWriter $xmlWriter,
Paragraph $style = null, Paragraph $style,
$withoutPPR = false $withoutPPR = false
) { ) {
@ -1122,7 +1109,6 @@ class Base extends WriterPart
$bLeft = (!is_null($brdSz[1])) ? true : false; $bLeft = (!is_null($brdSz[1])) ? true : false;
$bRight = (!is_null($brdSz[2])) ? true : false; $bRight = (!is_null($brdSz[2])) ? true : false;
$bBottom = (!is_null($brdSz[3])) ? true : false; $bBottom = (!is_null($brdSz[3])) ? true : false;
$borders = ($bTop || $bLeft || $bRight || $bBottom) ? true : false;
$xmlWriter->startElement('w:tblStylePr'); $xmlWriter->startElement('w:tblStylePr');
$xmlWriter->writeAttribute('w:type', $type); $xmlWriter->writeAttribute('w:type', $type);
@ -1178,7 +1164,7 @@ class Base extends WriterPart
* @param XMLWriter $xmlWriter * @param XMLWriter $xmlWriter
* @param Cell $style * @param Cell $style
*/ */
protected function writeCellStyle(XMLWriter $xmlWriter, Cell $style = null) protected function writeCellStyle(XMLWriter $xmlWriter, Cell $style)
{ {
$bgColor = $style->getBgColor(); $bgColor = $style->getBgColor();
$valign = $style->getVAlign(); $valign = $style->getVAlign();
@ -1291,7 +1277,7 @@ class Base extends WriterPart
* @param string $pTargetMode Relationship target mode * @param string $pTargetMode Relationship target mode
*/ */
protected function writeRelationship( protected function writeRelationship(
XMLWriter $xmlWriter = null, XMLWriter $xmlWriter,
$pId = 1, $pId = 1,
$pType = '', $pType = '',
$pTarget = '', $pTarget = '',
@ -1330,18 +1316,19 @@ class Base extends WriterPart
$styleParagraph = null, $styleParagraph = null,
$withoutPPR = false $withoutPPR = false
) { ) {
$spIsObject = ($styleParagraph instanceof Paragraph) ? true : false; if ($styleParagraph instanceof Paragraph) {
if ($spIsObject) {
$this->writeParagraphStyle($xmlWriter, $styleParagraph, $withoutPPR); $this->writeParagraphStyle($xmlWriter, $styleParagraph, $withoutPPR);
} elseif (!$spIsObject && !is_null($styleParagraph)) { } else {
if (!$withoutPPR) { if (!is_null($styleParagraph)) {
$xmlWriter->startElement('w:pPr'); if (!$withoutPPR) {
} $xmlWriter->startElement('w:pPr');
$xmlWriter->startElement('w:pStyle'); }
$xmlWriter->writeAttribute('w:val', $styleParagraph); $xmlWriter->startElement('w:pStyle');
$xmlWriter->endElement(); $xmlWriter->writeAttribute('w:val', $styleParagraph);
if (!$withoutPPR) {
$xmlWriter->endElement(); $xmlWriter->endElement();
if (!$withoutPPR) {
$xmlWriter->endElement();
}
} }
} }
} }
@ -1356,15 +1343,16 @@ class Base extends WriterPart
XMLWriter $xmlWriter, XMLWriter $xmlWriter,
$styleFont = null $styleFont = null
) { ) {
$sfIsObject = ($styleFont instanceof Font) ? true : false; if ($styleFont instanceof Font) {
if ($sfIsObject) {
$this->writeFontStyle($xmlWriter, $styleFont); $this->writeFontStyle($xmlWriter, $styleFont);
} elseif (!$sfIsObject && !is_null($styleFont)) { } else {
$xmlWriter->startElement('w:rPr'); if (!is_null($styleFont)) {
$xmlWriter->startElement('w:rStyle'); $xmlWriter->startElement('w:rPr');
$xmlWriter->writeAttribute('w:val', $styleFont); $xmlWriter->startElement('w:rStyle');
$xmlWriter->endElement(); $xmlWriter->writeAttribute('w:val', $styleFont);
$xmlWriter->endElement(); $xmlWriter->endElement();
$xmlWriter->endElement();
}
} }
} }
} }