diff --git a/CHANGELOG.md b/CHANGELOG.md index 71dbb6d2..3c570431 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ This release marked heavy refactorings on internal code structure with the creat - ODT Writer: Basic image writing - @ivanlanin - ODT Writer: Link writing - @ivanlanin - ODT Reader: Basic ODText Reader - @ivanlanin GH-71 +- Section: Ability to define gutter and line numbering ### Bugfixes diff --git a/docs/containers.rst b/docs/containers.rst index 53579537..30566df6 100644 --- a/docs/containers.rst +++ b/docs/containers.rst @@ -50,6 +50,7 @@ Below are the available settings for section: - ``borderBottomColor`` Border bottom color - ``headerHeight`` Spacing to top of header - ``footerHeight`` Spacing to bottom of footer +- ``gutter`` Page gutter spacing - ``colsNum`` Number of columns - ``colsSpace`` Spacing between columns - ``breakType`` Section break type (nextPage, nextColumn, continuous, @@ -92,6 +93,28 @@ using the ``breakType`` and ``colsNum`` property of the section. $section->getSettings()->setBreakType('continuous'); $section->getSettings()->setColsNum(2); + +### Line numbering + +You can apply line numbering to a section by using the ``lineNumbering`` +property of the section. + +.. code-block:: php + + // Method 1 + $section = $phpWord->addSection(array('lineNumbering' => array())); + + // Method 2 + $section = $phpWord->addSection(); + $section->getSettings()->setLineNumbering(array()); + +Below are the properties of the line numbering style. + +- ``start`` Line numbering starting value +- ``increment`` Line number increments +- ``distance`` Distance between text and line numbering in twip +- ``restart`` Line numbering restart setting continuous|newPage|newSection + Headers ------- diff --git a/docs/src/documentation.md b/docs/src/documentation.md index 63963c6c..0aa27ed4 100644 --- a/docs/src/documentation.md +++ b/docs/src/documentation.md @@ -344,6 +344,7 @@ Below are the available settings for section: - `borderBottomColor` Border bottom color - `headerHeight` Spacing to top of header - `footerHeight` Spacing to bottom of footer +- `gutter` Page gutter spacing - `colsNum` Number of columns - `colsSpace` Spacing between columns - `breakType` Section break type (nextPage, nextColumn, continuous, evenPage, oddPage) @@ -380,6 +381,26 @@ $section->getSettings()->setBreakType('continuous'); $section->getSettings()->setColsNum(2); ``` +### Line numbering + +You can apply line numbering to a section by using the `lineNumbering` property of the section. + +```php +// Method 1 +$section = $phpWord->addSection(array('lineNumbering' => array())); + +// Method 2 +$section = $phpWord->addSection(); +$section->getSettings()->setLineNumbering(array()); +``` + +Below are the properties of the line numbering style. + +- `start` Line numbering starting value +- `increment` Line number increments +- `distance` Distance between text and line numbering in twip +- `restart` Line numbering restart setting continuous|newPage|newSection + ## Headers Each section can have its own header reference. To create a header use the `addHeader` method: diff --git a/src/PhpWord/Settings.php b/src/PhpWord/Settings.php index 1ded43c1..8daf238f 100644 --- a/src/PhpWord/Settings.php +++ b/src/PhpWord/Settings.php @@ -16,17 +16,37 @@ namespace PhpOffice\PhpWord; */ class Settings { - /** Available Zip library classes */ + /** + * Zip libraries + */ const PCLZIP = 'PhpOffice\\PhpWord\\Shared\\ZipArchive'; const ZIPARCHIVE = 'ZipArchive'; - /** Optional PDF Rendering libraries */ + /** + * PDF rendering libraries + */ const PDF_RENDERER_DOMPDF = 'DomPDF'; + /** + * Measurement units multiplication factor + * + * Applied to: + * - Section: margins, header/footer height, gutter, column spacing + * - Tab: position + * + * @const int|float + */ + const UNIT_TWIP = 1; // = 1/20 point + const UNIT_CM = 567; + const UNIT_MM = 56.7; + const UNIT_INCH = 1440; + const UNIT_POINT = 20; // = 1/72 inch + const UNIT_PICA = 240; // = 1/6 inch = 12 points + /** * Compatibility option for XMLWriter * - * @var boolean + * @var bool */ private static $xmlWriterCompatibility = true; @@ -58,11 +78,20 @@ class Settings */ private static $pdfRendererPath = null; + /** + * Measurement unit + * + * @var string + */ + private static $measurementUnit = self::UNIT_TWIP; + /** * Set the compatibility option used by the XMLWriter * - * @param boolean $compatibility This sets the setIndent and setIndentString for better compatibility - * @return boolean Success or failure + * This sets the setIndent and setIndentString for better compatibility + * + * @param bool $compatibility + * @return bool */ public static function setCompatibility($compatibility) { @@ -70,13 +99,14 @@ class Settings self::$xmlWriterCompatibility = $compatibility; return true; } + return false; } /** * Return the compatibility option used by the XMLWriter * - * @return boolean Compatibility + * @return bool Compatibility */ public static function getCompatibility() { @@ -84,11 +114,10 @@ class Settings } /** - * Set the Zip handler Class that PHPWord should use for Zip file management (PCLZip or ZipArchive) + * Set zip handler class * - * @param string $zipClass The Zip handler class that PHPWord should use for Zip file management - * e.g. Settings::PCLZip or Settings::ZipArchive - * @return boolean Success or failure + * @param string $zipClass + * @return bool */ public static function setZipClass($zipClass) { @@ -97,16 +126,14 @@ class Settings self::$zipClass = $zipClass; return true; } + return false; } /** - * Return the name of the Zip handler Class that PHPWord is configured to use (PCLZip or ZipArchive) - * or Zip file management + * Get zip handler class * - * @return string Name of the Zip handler Class that PHPWord is configured to use - * for Zip file management - * e.g. Settings::PCLZip or Settings::ZipArchive + * @return string */ public static function getZipClass() { @@ -118,7 +145,7 @@ class Settings * * @param string $libraryName * @param string $libraryBaseDir - * @return boolean Success or failure + * @return bool Success or failure */ public static function setPdfRenderer($libraryName, $libraryBaseDir) { @@ -141,14 +168,13 @@ class Settings * Identify the external library to use for rendering PDF files * * @param string $libraryName - * @return boolean Success or failure + * @return bool */ public static function setPdfRendererName($libraryName) { if (!in_array($libraryName, self::$pdfRenderers)) { return false; } - self::$pdfRendererName = $libraryName; return true; @@ -167,7 +193,7 @@ class Settings * Location of external library to use for rendering PDF files * * @param string $libraryBaseDir Directory path to the library's base folder - * @return boolean Success or failure + * @return bool Success or failure */ public static function setPdfRendererPath($libraryBaseDir) { @@ -178,4 +204,31 @@ class Settings return true; } + + /** + * Get measurement unit + * + * @return int|float + */ + public static function getMeasurementUnit() + { + return self::$measurementUnit; + } + + /** + * Set measurement unit + * + * @param int|float $value + * @return bool + */ + public static function setMeasurementUnit($value) + { + $units = array(self::UNIT_TWIP, self::UNIT_CM, self::UNIT_MM, self::UNIT_INCH, self::UNIT_POINT, self::UNIT_PICA); + if (!in_array($value, $units)) { + return false; + } + self::$measurementUnit = $value; + + return true; + } } diff --git a/src/PhpWord/Style/Border.php b/src/PhpWord/Style/Border.php index ce1d8e1e..3af10f79 100644 --- a/src/PhpWord/Style/Border.php +++ b/src/PhpWord/Style/Border.php @@ -17,7 +17,7 @@ class Border extends AbstractStyle /** * Border Top Size * - * @var int + * @var int|float */ protected $borderTopSize; @@ -31,7 +31,7 @@ class Border extends AbstractStyle /** * Border Left Size * - * @var int + * @var int|float */ protected $borderLeftSize; @@ -45,7 +45,7 @@ class Border extends AbstractStyle /** * Border Right Size * - * @var int + * @var int|float */ protected $borderRightSize; @@ -59,7 +59,7 @@ class Border extends AbstractStyle /** * Border Bottom Size * - * @var int + * @var int|float */ protected $borderBottomSize; @@ -73,67 +73,82 @@ class Border extends AbstractStyle /** * Set border size * - * @param int $pValue + * @param int|float $value + * @return self */ - public function setBorderSize($pValue = null) + public function setBorderSize($value = null) { - $this->borderTopSize = $pValue; - $this->borderLeftSize = $pValue; - $this->borderRightSize = $pValue; - $this->borderBottomSize = $pValue; + $this->setBorderTopSize($value); + $this->setBorderLeftSize($value); + $this->setBorderRightSize($value); + $this->setBorderBottomSize($value); + + return $this; } /** * Get border size + * + * @return array */ public function getBorderSize() { - $top = $this->getBorderTopSize(); - $left = $this->getBorderLeftSize(); - $right = $this->getBorderRightSize(); - $bottom = $this->getBorderBottomSize(); - - return array($top, $left, $right, $bottom); + return array( + $this->getBorderTopSize(), + $this->getBorderLeftSize(), + $this->getBorderRightSize(), + $this->getBorderBottomSize(), + ); } /** * Set border color * - * @param string $pValue + * @param string $value + * @return self */ - public function setBorderColor($pValue = null) + public function setBorderColor($value = null) { - $this->borderTopColor = $pValue; - $this->borderLeftColor = $pValue; - $this->borderRightColor = $pValue; - $this->borderBottomColor = $pValue; + $this->setBorderTopColor($value); + $this->setBorderLeftColor($value); + $this->setBorderRightColor($value); + $this->setBorderBottomColor($value); + + return $this; } /** * Get border color + * + * @return string[] */ public function getBorderColor() { - $top = $this->getBorderTopColor(); - $left = $this->getBorderLeftColor(); - $right = $this->getBorderRightColor(); - $bottom = $this->getBorderBottomColor(); - - return array($top, $left, $right, $bottom); + return array( + $this->getBorderTopColor(), + $this->getBorderLeftColor(), + $this->getBorderRightColor(), + $this->getBorderBottomColor(), + ); } /** * Set border top size * - * @param int $pValue + * @param int|float $value + * @return self */ - public function setBorderTopSize($pValue = null) + public function setBorderTopSize($value = null) { - $this->borderTopSize = $pValue; + $this->borderTopSize = $value; + + return $this; } /** * Get border top size + * + * @return int|float */ public function getBorderTopSize() { @@ -143,15 +158,20 @@ class Border extends AbstractStyle /** * Set border top color * - * @param string $pValue + * @param string $value + * @return self */ - public function setBorderTopColor($pValue = null) + public function setBorderTopColor($value = null) { - $this->borderTopColor = $pValue; + $this->borderTopColor = $value; + + return $this; } /** * Get border top color + * + * @return string */ public function getBorderTopColor() { @@ -161,15 +181,20 @@ class Border extends AbstractStyle /** * Set border left size * - * @param int $pValue + * @param int|float $value + * @return self */ - public function setBorderLeftSize($pValue = null) + public function setBorderLeftSize($value = null) { - $this->borderLeftSize = $pValue; + $this->borderLeftSize = $value; + + return $this; } /** * Get border left size + * + * @return int|float */ public function getBorderLeftSize() { @@ -179,15 +204,20 @@ class Border extends AbstractStyle /** * Set border left color * - * @param string $pValue + * @param string $value + * @return self */ - public function setBorderLeftColor($pValue = null) + public function setBorderLeftColor($value = null) { - $this->borderLeftColor = $pValue; + $this->borderLeftColor = $value; + + return $this; } /** * Get border left color + * + * @return string */ public function getBorderLeftColor() { @@ -197,15 +227,20 @@ class Border extends AbstractStyle /** * Set border right size * - * @param int $pValue + * @param int|float $value + * @return self */ - public function setBorderRightSize($pValue = null) + public function setBorderRightSize($value = null) { - $this->borderRightSize = $pValue; + $this->borderRightSize = $value; + + return $this; } /** * Get border right size + * + * @return int|float */ public function getBorderRightSize() { @@ -215,15 +250,20 @@ class Border extends AbstractStyle /** * Set border right color * - * @param string $pValue + * @param string $value + * @return self */ - public function setBorderRightColor($pValue = null) + public function setBorderRightColor($value = null) { - $this->borderRightColor = $pValue; + $this->borderRightColor = $value; + + return $this; } /** * Get border right color + * + * @return string */ public function getBorderRightColor() { @@ -233,15 +273,20 @@ class Border extends AbstractStyle /** * Set border bottom size * - * @param int $pValue + * @param int|float $value + * @return self */ - public function setBorderBottomSize($pValue = null) + public function setBorderBottomSize($value = null) { - $this->borderBottomSize = $pValue; + $this->borderBottomSize = $value; + + return $this; } /** * Get border bottom size + * + * @return int|float */ public function getBorderBottomSize() { @@ -251,15 +296,20 @@ class Border extends AbstractStyle /** * Set border bottom color * - * @param string $pValue + * @param string $value + * @return self */ - public function setBorderBottomColor($pValue = null) + public function setBorderBottomColor($value = null) { - $this->borderBottomColor = $pValue; + $this->borderBottomColor = $value; + + return $this; } /** * Get border bottom color + * + * @return string */ public function getBorderBottomColor() { diff --git a/src/PhpWord/Style/LineNumbering.php b/src/PhpWord/Style/LineNumbering.php new file mode 100644 index 00000000..cb0b2ee8 --- /dev/null +++ b/src/PhpWord/Style/LineNumbering.php @@ -0,0 +1,153 @@ +setStyleByArray($style); + } + + /** + * Get start + * + * @return int + */ + public function getStart() + { + return $this->start; + } + + /** + * Set start + * + * @param int $value + * @return self + */ + public function setStart($value = null) + { + $this->start = $this->setIntVal($value, $this->start); + + return $this; + } + + /** + * Get increment + * + * @return int + */ + public function getIncrement() + { + return $this->increment; + } + + /** + * Set increment + * + * @param int $value + * @return self + */ + public function setIncrement($value = null) + { + $this->increment = $this->setIntVal($value, $this->increment); + + return $this; + } + + /** + * Get distance + * + * @return int|float + */ + public function getDistance() + { + return $this->distance; + } + + /** + * Set distance + * + * @param int|float $value + * @return self + */ + public function setDistance($value = null) + { + $this->distance = $this->setNumericVal($value, $this->distance); + + return $this; + } + + /** + * Get restart + * + * @return string + */ + public function getRestart() + { + return $this->restart; + } + + /** + * Set distance + * + * @param int|float $value + * @return self + */ + public function setRestart($value = null) + { + $enum = array(self::LINE_NUMBERING_CONTINUOUS, self::LINE_NUMBERING_NEW_PAGE, self::LINE_NUMBERING_NEW_SECTION); + $this->restart = $this->setEnumVal($value, $enum, $this->restart); + + return $this; + } +} diff --git a/src/PhpWord/Style/Section.php b/src/PhpWord/Style/Section.php index 68318ad2..246a9199 100644 --- a/src/PhpWord/Style/Section.php +++ b/src/PhpWord/Style/Section.php @@ -17,67 +17,93 @@ use PhpOffice\PhpWord\Shared\String; class Section extends Border { /** - * Default Page Size Width - * - * @var int + * Page orientation */ - private $defaultPageSizeW = 11906; - + const ORIENTATION_PORTRAIT = 'portrait'; + const ORIENTATION_LANDSCAPE = 'landscape'; /** - * Default Page Size Height - * - * @var int + * Page default constants */ - private $defaultPageSizeH = 16838; + const DEFAULT_WIDTH = 11906; // In twip + const DEFAULT_HEIGHT = 16838; // In twip + const DEFAULT_MARGIN = 1440; // In twip + const DEFAULT_GUTTER = 0; // In twip + const DEFAULT_HEADER_HEIGHT = 720; // In twip + const DEFAULT_FOOTER_HEIGHT = 720; // In twip + const DEFAULT_COLUMN_COUNT = 1; + const DEFAULT_COLUMN_SPACING = 720; // In twip /** * Page Orientation * * @var string + * @link http://www.schemacentral.com/sc/ooxml/a-w_orient-1.html */ - private $orientation; - - /** - * Page Margin Top - * - * @var int - */ - private $marginTop; - - /** - * Page Margin Left - * - * @var int - */ - private $marginLeft; - - /** - * Page Margin Right - * - * @var int - */ - private $marginRight; - - /** - * Page Margin Bottom - * - * @var int - */ - private $marginBottom; + private $orientation = self::ORIENTATION_PORTRAIT; /** * Page Size Width * - * @var int + * @var int|float */ - private $pageSizeW; + private $pageSizeW = self::DEFAULT_WIDTH; /** * Page Size Height * - * @var int + * @var int|float */ - private $pageSizeH; + private $pageSizeH = self::DEFAULT_HEIGHT; + + /** + * Top margin spacing + * + * @var int|float + */ + private $marginTop = self::DEFAULT_MARGIN; + + /** + * Left margin spacing + * + * @var int|float + */ + private $marginLeft = self::DEFAULT_MARGIN; + + /** + * Right margin spacing + * + * @var int|float + */ + private $marginRight = self::DEFAULT_MARGIN; + + /** + * Bottom margin spacing + * + * @var int|float + */ + private $marginBottom = self::DEFAULT_MARGIN; + + /** + * Page gutter spacing + * + * @var int|float + * @link http://www.schemacentral.com/sc/ooxml/e-w_pgMar-1.html + */ + private $gutter = self::DEFAULT_GUTTER; + + /** + * Header height + * + * @var int|float + */ + private $headerHeight = self::DEFAULT_HEADER_HEIGHT; + + /** + * Footer height + * + * @var int|float + */ + private $footerHeight = self::DEFAULT_FOOTER_HEIGHT; /** * Page Numbering Start @@ -86,33 +112,19 @@ class Section extends Border */ private $pageNumberingStart; - /** - * Header height - * - * @var int - */ - private $headerHeight; - - /** - * Footer height - * - * @var int - */ - private $footerHeight; - /** * Section columns count * * @var int */ - private $colsNum; + private $colsNum = self::DEFAULT_COLUMN_COUNT; /** * Section spacing between columns * - * @var int + * @var int|float */ - private $colsSpace; + private $colsSpace = self::DEFAULT_COLUMN_SPACING; /** * Section break type @@ -129,181 +141,44 @@ class Section extends Border private $breakType; /** - * Create new Section Settings + * Line numbering + * + * @var array + * @link http://www.schemacentral.com/sc/ooxml/e-w_lnNumType-1.html */ - public function __construct() - { - $this->orientation = null; - $this->marginTop = 1418; - $this->marginLeft = 1418; - $this->marginRight = 1418; - $this->marginBottom = 1134; - $this->pageSizeW = $this->defaultPageSizeW; - $this->pageSizeH = $this->defaultPageSizeH; - $this->borderTopSize = null; - $this->borderTopColor = null; - $this->borderLeftSize = null; - $this->borderLeftColor = null; - $this->borderRightSize = null; - $this->borderRightColor = null; - $this->borderBottomSize = null; - $this->borderBottomColor = null; - $this->headerHeight = 720; // set default header and footer to 720 twips (.5 inches) - $this->footerHeight = 720; - $this->colsNum = 1; - $this->colsSpace = 720; - $this->breakType = null; - } + private $lineNumbering; /** * Set Setting Value * * @param string $key * @param string $value + * @return self */ public function setSettingValue($key, $value) { - $key = String::removeUnderscorePrefix($key); - if ($key == 'orientation' && $value == 'landscape') { - $this->setLandscape(); - } elseif ($key == 'orientation' && is_null($value)) { - $this->setPortrait(); - } elseif ($key == 'borderSize') { - $this->setBorderSize($value); - } elseif ($key == 'borderColor') { - $this->setBorderColor($value); + return $this->setStyleValue($key, $value); + } + + /** + * Set orientation + */ + public function setOrientation($value = null) + { + $enum = array(self::ORIENTATION_PORTRAIT, self::ORIENTATION_LANDSCAPE); + $this->orientation = $this->setEnumVal($value, $enum, $this->orientation); + $longSize = $this->pageSizeW >= $this->pageSizeH ? $this->pageSizeW : $this->pageSizeH; + $shortSize = $this->pageSizeW < $this->pageSizeH ? $this->pageSizeW : $this->pageSizeH; + + if ($this->orientation == self::ORIENTATION_PORTRAIT) { + $this->pageSizeW = $shortSize; + $this->pageSizeH = $longSize; } else { - $method = 'set' . $key; - if (method_exists($this, $method)) { - $this->$method($value); - } + $this->pageSizeW = $longSize; + $this->pageSizeH = $shortSize; } } - /** - * Get Margin Top - * - * @return int - */ - public function getMarginTop() - { - return $this->marginTop; - } - - /** - * Set Margin Top - * - * @param int $pValue - */ - public function setMarginTop($pValue = '') - { - $this->marginTop = $pValue; - return $this; - } - - /** - * Get Margin Left - * - * @return int - */ - public function getMarginLeft() - { - return $this->marginLeft; - } - - /** - * Set Margin Left - * - * @param int $pValue - */ - public function setMarginLeft($pValue = '') - { - $this->marginLeft = $pValue; - return $this; - } - - /** - * Get Margin Right - * - * @return int - */ - public function getMarginRight() - { - return $this->marginRight; - } - - /** - * Set Margin Right - * - * @param int $pValue - */ - public function setMarginRight($pValue = '') - { - $this->marginRight = $pValue; - return $this; - } - - /** - * Get Margin Bottom - * - * @return int - */ - public function getMarginBottom() - { - return $this->marginBottom; - } - - /** - * Set Margin Bottom - * - * @param int $pValue - */ - public function setMarginBottom($pValue = '') - { - $this->marginBottom = $pValue; - return $this; - } - - /** - * Set Landscape Orientation - */ - public function setLandscape() - { - $this->orientation = 'landscape'; - $this->pageSizeW = $this->defaultPageSizeH; - $this->pageSizeH = $this->defaultPageSizeW; - } - - /** - * Set Portrait Orientation - */ - public function setPortrait() - { - $this->orientation = null; - $this->pageSizeW = $this->defaultPageSizeW; - $this->pageSizeH = $this->defaultPageSizeH; - } - - /** - * Get Page Size Width - * - * @return int - */ - public function getPageSizeW() - { - return $this->pageSizeW; - } - - /** - * Get Page Size Height - * - * @return int - */ - public function getPageSizeH() - { - return $this->pageSizeH; - } - /** * Get Page Orientation * @@ -314,6 +189,213 @@ class Section extends Border return $this->orientation; } + /** + * Set Portrait Orientation + */ + public function setPortrait() + { + $this->setOrientation(self::ORIENTATION_PORTRAIT); + } + + /** + * Set Landscape Orientation + */ + public function setLandscape() + { + $this->setOrientation(self::ORIENTATION_LANDSCAPE); + } + + /** + * Get Page Size Width + * + * @return int|float + */ + public function getPageSizeW() + { + return $this->pageSizeW; + } + + /** + * Get Page Size Height + * + * @return int|float + */ + public function getPageSizeH() + { + return $this->pageSizeH; + } + + /** + * Get Margin Top + * + * @return int|float + */ + public function getMarginTop() + { + return $this->marginTop; + } + + /** + * Set Margin Top + * + * @param int|float $value + * @return self + */ + public function setMarginTop($value = '') + { + $this->marginTop = $this->setNumericVal($value, self::DEFAULT_MARGIN); + + return $this; + } + + /** + * Get Margin Left + * + * @return int|float + */ + public function getMarginLeft() + { + return $this->marginLeft; + } + + /** + * Set Margin Left + * + * @param int|float $value + * @return self + */ + public function setMarginLeft($value = '') + { + $this->marginLeft = $this->setNumericVal($value, self::DEFAULT_MARGIN); + + return $this; + } + + /** + * Get Margin Right + * + * @return int|float + */ + public function getMarginRight() + { + return $this->marginRight; + } + + /** + * Set Margin Right + * + * @param int|float $value + * @return self + */ + public function setMarginRight($value = '') + { + $this->marginRight = $this->setNumericVal($value, self::DEFAULT_MARGIN); + + return $this; + } + + /** + * Get Margin Bottom + * + * @return int|float + */ + public function getMarginBottom() + { + return $this->marginBottom; + } + + /** + * Set Margin Bottom + * + * @param int|float $value + * @return self + */ + public function setMarginBottom($value = '') + { + $this->marginBottom = $this->setNumericVal($value, self::DEFAULT_MARGIN); + + return $this; + } + + /** + * Get gutter + * + * @return int|float + */ + public function getGutter() + { + return $this->gutter; + } + + /** + * Set gutter + * + * @param int|float $value + * @return self + */ + public function setGutter($value = '') + { + $this->gutter = $this->setNumericVal($value, self::DEFAULT_GUTTER); + + return $this; + } + + /** + * Get Header Height + * + * @return int|float + */ + public function getHeaderHeight() + { + return $this->headerHeight; + } + + /** + * Set Header Height + * + * @param int|float $value + * @return self + */ + public function setHeaderHeight($value = '') + { + $this->headerHeight = $this->setNumericVal($value, self::DEFAULT_HEADER_HEIGHT); + + return $this; + } + + /** + * Get Footer Height + * + * @return int|float + */ + public function getFooterHeight() + { + return $this->footerHeight; + } + + /** + * Set Footer Height + * + * @param int|float $value + * @return self + */ + public function setFooterHeight($value = '') + { + $this->footerHeight = $this->setNumericVal($value, self::DEFAULT_FOOTER_HEIGHT); + + return $this; + } + + /** + * Get page numbering start + * + * @return null|int + */ + public function getPageNumberingStart() + { + return $this->pageNumberingStart; + } + /** * Set page numbering start * @@ -326,78 +408,6 @@ class Section extends Border return $this; } - /** - * Get page numbering start - * - * @return null|int - */ - public function getPageNumberingStart() - { - return $this->pageNumberingStart; - } - - /** - * Get Header Height - * - * @return int - */ - public function getHeaderHeight() - { - return $this->headerHeight; - } - - /** - * Set Header Height - * - * @param int $pValue - */ - public function setHeaderHeight($pValue = '') - { - if (!is_numeric($pValue)) { - $pValue = 720; - } - $this->headerHeight = $pValue; - return $this; - } - - /** - * Get Footer Height - * - * @return int - */ - public function getFooterHeight() - { - return $this->footerHeight; - } - - /** - * Set Footer Height - * - * @param int $pValue - */ - public function setFooterHeight($pValue = '') - { - if (!is_numeric($pValue)) { - $pValue = 720; - } - $this->footerHeight = $pValue; - return $this; - } - - /** - * Set Section Columns Count - * - * @param int $pValue - */ - public function setColsNum($pValue = '') - { - if (!is_numeric($pValue)) { - $pValue = 1; - } - $this->colsNum = $pValue; - return $this; - } - /** * Get Section Columns Count * @@ -409,23 +419,22 @@ class Section extends Border } /** - * Set Section Space Between Columns + * Set Section Columns Count * - * @param int $pValue + * @param int $value + * @return self */ - public function setColsSpace($pValue = '') + public function setColsNum($value = '') { - if (!is_numeric($pValue)) { - $pValue = 720; - } - $this->colsSpace = $pValue; + $this->colsNum = $this->setIntVal($value, self::DEFAULT_COLUMN_COUNT); + return $this; } /** * Get Section Space Between Columns * - * @return int + * @return int|float */ public function getColsSpace() { @@ -433,13 +442,15 @@ class Section extends Border } /** - * Set Break Type + * Set Section Space Between Columns * - * @param string $pValue + * @param int|float $value + * @return self */ - public function setBreakType($pValue = null) + public function setColsSpace($value = '') { - $this->breakType = $pValue; + $this->colsSpace = $this->setNumericVal($value, self::DEFAULT_COLUMN_SPACING); + return $this; } @@ -452,4 +463,51 @@ class Section extends Border { return $this->breakType; } + + /** + * Set Break Type + * + * @param string $value + * @return self + */ + public function setBreakType($value = null) + { + $this->breakType = $value; + return $this; + } + + /** + * Get line numbering + * + * @return self + */ + public function getLineNumbering() + { + return $this->lineNumbering; + } + + /** + * Set line numbering + * + * @param array $value + * @return self + */ + public function setLineNumbering($value = null) + { + if ($this->lineNumbering instanceof LineNumbering) { + $this->lineNumbering->setStyleByArray($value); + } else { + $this->lineNumbering = new LineNumbering($value); + } + + return $this; + } + + /** + * Remove line numbering + */ + public function removeLineNumbering() + { + $this->lineNumbering = null; + } } diff --git a/src/PhpWord/Style/Tab.php b/src/PhpWord/Style/Tab.php index eb721821..dfcb3b95 100644 --- a/src/PhpWord/Style/Tab.php +++ b/src/PhpWord/Style/Tab.php @@ -15,56 +15,50 @@ namespace PhpOffice\PhpWord\Style; class Tab extends AbstractStyle { /** - * Tab Stop Type + * Tab stop types + * + * @const string + */ + const TAB_STOP_CLEAR = 'clear'; + const TAB_STOP_LEFT = 'left'; + const TAB_STOP_CENTER = 'center'; + const TAB_STOP_RIGHT = 'right'; + const TAB_STOP_DECIMAL = 'decimal'; + const TAB_STOP_BAR = 'bar'; + const TAB_STOP_NUM = 'num'; + + /** + * Tab leader types + * + * @const string + */ + const TAB_LEADER_NONE = 'none'; + const TAB_LEADER_DOT = 'dot'; + const TAB_LEADER_HYPHEN = 'hyphen'; + const TAB_LEADER_UNDERSCORE = 'underscore'; + const TAB_LEADER_HEAVY = 'heavy'; + const TAB_LEADER_MIDDLEDOT = 'middleDot'; + + /** + * Tab stop type * * @var string */ - private $val; + private $val = self::TAB_STOP_CLEAR; /** - * Tab Leader Character + * Tab leader character * * @var string */ - private $leader; + private $leader = self::TAB_LEADER_NONE; /** - * Tab Stop Position + * Tab stop position * * @var int */ - private $position; - - /** - * Tab Stop Type - * - * @var array - * @link http://www.schemacentral.com/sc/ooxml/a-w_val-26.html Tab Stop Type - */ - private static $possibleStopTypes = array( - 'clear', // No Tab Stop - 'left', // Left Tab Stop - 'center', // Center Tab Stop - 'right', // Right Tab Stop - 'decimal', // Decimal Tab - 'bar', // Bar Tab - 'num' // List tab - ); - - /** - * Tab Leader Character - * - * @var array - * @link http://www.schemacentral.com/sc/ooxml/a-w_leader-1.html Tab Leader Character - */ - private static $possibleLeaders = array( - 'none', // No tab stop leader - 'dot', // Dotted leader line - 'hyphen', // Dashed tab stop leader line - 'underscore', // Solid leader line - 'heavy', // Heavy solid leader line - 'middleDot' // Middle dot leader line - ); + private $position = 0; /** * Create a new instance of Tab. Both $val and $leader @@ -72,19 +66,23 @@ class Tab extends AbstractStyle * they will be changed to default values. * * @param string $val Defaults to 'clear' if value is not possible. - * @param int $position Must be an integer; otherwise defaults to 0. + * @param int $position Must be numeric; otherwise defaults to 0. * @param string $leader Defaults to null if value is not possible. */ public function __construct($val = null, $position = 0, $leader = null) { - // Default to clear if the stop type is not matched - $this->val = (self::isStopType($val)) ? $val : 'clear'; + $stopTypes = array( + self::TAB_STOP_CLEAR, self::TAB_STOP_LEFT,self::TAB_STOP_CENTER, + self::TAB_STOP_RIGHT, self::TAB_STOP_DECIMAL, self::TAB_STOP_BAR, self::TAB_STOP_NUM + ); + $leaderTypes = array( + self::TAB_LEADER_NONE, self::TAB_LEADER_DOT, self::TAB_LEADER_HYPHEN, + self::TAB_LEADER_UNDERSCORE, self::TAB_LEADER_HEAVY, self::TAB_LEADER_MIDDLEDOT + ); - // Default to 0 if the position is non-numeric - $this->position = (is_numeric($position)) ? intval($position) : 0; - - // Default to null if no tab leader - $this->leader = (self::isLeaderType($leader)) ? $leader : null; + $this->val = $this->setEnumVal($val, $stopTypes, $this->val); + $this->position = $this->setNumericVal($position, $this->position); + $this->leader = $this->setEnumVal($leader, $leaderTypes, $this->leader); } /** @@ -116,26 +114,4 @@ class Tab extends AbstractStyle { return $this->position; } - - /** - * Test if attribute is a valid stop type. - * - * @param string $attribute - * @return bool True if it is; false otherwise. - */ - private static function isStopType($attribute) - { - return in_array($attribute, self::$possibleStopTypes); - } - - /** - * Test if attribute is a valid leader type. - * - * @param string $attribute - * @return bool True if it is; false otherwise. - */ - private static function isLeaderType($attribute) - { - return in_array($attribute, self::$possibleLeaders); - } } diff --git a/src/PhpWord/Writer/Word2007/Part/AbstractPart.php b/src/PhpWord/Writer/Word2007/Part/AbstractPart.php index afa84caf..51926b9e 100755 --- a/src/PhpWord/Writer/Word2007/Part/AbstractPart.php +++ b/src/PhpWord/Writer/Word2007/Part/AbstractPart.php @@ -10,6 +10,7 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Element\AbstractElement; use PhpOffice\PhpWord\Element\TextBreak; use PhpOffice\PhpWord\Exception\Exception; diff --git a/src/PhpWord/Writer/Word2007/Part/Document.php b/src/PhpWord/Writer/Word2007/Part/Document.php index 2b30ee54..535784b8 100644 --- a/src/PhpWord/Writer/Word2007/Part/Document.php +++ b/src/PhpWord/Writer/Word2007/Part/Document.php @@ -13,6 +13,7 @@ use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Element\Section; use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Shared\XMLWriter; +use PhpOffice\PhpWord\Writer\Word2007\Style\Section as SectionStyleWriter; /** * Word2007 document part writer @@ -32,6 +33,9 @@ class Document extends AbstractPart throw new Exception("No PhpWord assigned."); } $xmlWriter = $this->getXmlWriter(); + $sections = $phpWord->getSections(); + $sectionCount = count($sections); + $currentSection = 0; $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); $xmlWriter->startElement('w:document'); @@ -47,18 +51,13 @@ class Document extends AbstractPart $xmlWriter->startElement('w:body'); - $sections = $phpWord->getSections(); - $countSections = count($sections); - $pSection = 0; - if ($countSections > 0) { + if ($sectionCount > 0) { foreach ($sections as $section) { - $pSection++; - + $currentSection++; $this->writeContainerElements($xmlWriter, $section); - - if ($pSection == $countSections) { - $this->writeEndSection($xmlWriter, $section); + if ($currentSection == $sectionCount) { + $this->writeSectionSettings($xmlWriter, $section); } else { $this->writeSection($xmlWriter, $section); } @@ -66,10 +65,8 @@ class Document extends AbstractPart } $xmlWriter->endElement(); // w:body - $xmlWriter->endElement(); // w:document - // Return return $xmlWriter->getData(); } @@ -83,7 +80,7 @@ class Document extends AbstractPart { $xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:pPr'); - $this->writeEndSection($xmlWriter, $section); + $this->writeSectionSettings($xmlWriter, $section); $xmlWriter->endElement(); $xmlWriter->endElement(); } @@ -94,114 +91,38 @@ class Document extends AbstractPart * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Section $section */ - private function writeEndSection(XMLWriter $xmlWriter, Section $section) + private function writeSectionSettings(XMLWriter $xmlWriter, Section $section) { - $settings = $section->getSettings(); - $headers = $section->getHeaders(); - $footers = $section->getFooters(); - $pgSzW = $settings->getPageSizeW(); - $pgSzH = $settings->getPageSizeH(); - $orientation = $settings->getOrientation(); - - $marginTop = $settings->getMarginTop(); - $marginLeft = $settings->getMarginLeft(); - $marginRight = $settings->getMarginRight(); - $marginBottom = $settings->getMarginBottom(); - - $headerHeight = $settings->getHeaderHeight(); - $footerHeight = $settings->getFooterHeight(); - - $borders = $settings->getBorderSize(); - - $colsNum = $settings->getColsNum(); - $colsSpace = $settings->getColsSpace(); - $breakType = $settings->getBreakType(); - $xmlWriter->startElement('w:sectPr'); - // Section break - if (!is_null($breakType)) { - $xmlWriter->startElement('w:type'); - $xmlWriter->writeAttribute('w:val', $breakType); - $xmlWriter->endElement(); - } - // Header reference - foreach ($headers as &$header) { + foreach ($section->getHeaders() as $header) { $rId = $header->getRelationId(); $xmlWriter->startElement('w:headerReference'); $xmlWriter->writeAttribute('w:type', $header->getType()); $xmlWriter->writeAttribute('r:id', 'rId' . $rId); $xmlWriter->endElement(); } + // Footer reference - foreach ($footers as &$footer) { + foreach ($section->getFooters() as $footer) { $rId = $footer->getRelationId(); $xmlWriter->startElement('w:footerReference'); $xmlWriter->writeAttribute('w:type', $footer->getType()); $xmlWriter->writeAttribute('r:id', 'rId' . $rId); $xmlWriter->endElement(); } + // Different first page if ($section->hasDifferentFirstPage()) { $xmlWriter->startElement('w:titlePg'); $xmlWriter->endElement(); } - // Page size & orientation - $xmlWriter->startElement('w:pgSz'); - $xmlWriter->writeAttribute('w:w', $pgSzW); - $xmlWriter->writeAttribute('w:h', $pgSzH); - if (!is_null($orientation) && strtolower($orientation) != 'portrait') { - $xmlWriter->writeAttribute('w:orient', $orientation); - } - $xmlWriter->endElement(); // w:pgSz + // Section settings + $styleWriter = new SectionStyleWriter($xmlWriter, $section->getSettings()); + $styleWriter->write(); - // Margins - $xmlWriter->startElement('w:pgMar'); - $xmlWriter->writeAttribute('w:top', $marginTop); - $xmlWriter->writeAttribute('w:right', $marginRight); - $xmlWriter->writeAttribute('w:bottom', $marginBottom); - $xmlWriter->writeAttribute('w:left', $marginLeft); - $xmlWriter->writeAttribute('w:header', $headerHeight); - $xmlWriter->writeAttribute('w:footer', $footerHeight); - $xmlWriter->writeAttribute('w:gutter', '0'); - $xmlWriter->endElement(); - - // Borders - $hasBorders = false; - for ($i = 0; $i < 4; $i++) { - if (!is_null($borders[$i])) { - $hasBorders = true; - break; - } - } - if ($hasBorders) { - $borderColor = $settings->getBorderColor(); - $mbWriter = new \PhpOffice\PhpWord\Writer\Word2007\Style\MarginBorder($xmlWriter); - $mbWriter->setSizes($borders); - $mbWriter->setColors($borderColor); - $mbWriter->setAttributes(array('space' => '24')); - - $xmlWriter->startElement('w:pgBorders'); - $xmlWriter->writeAttribute('w:offsetFrom', 'page'); - $mbWriter->write(); - $xmlWriter->endElement(); - } - - // Page numbering - if (null !== $settings->getPageNumberingStart()) { - $xmlWriter->startElement('w:pgNumType'); - $xmlWriter->writeAttribute('w:start', $section->getSettings()->getPageNumberingStart()); - $xmlWriter->endElement(); - } - - // Columns - $xmlWriter->startElement('w:cols'); - $xmlWriter->writeAttribute('w:num', $colsNum); - $xmlWriter->writeAttribute('w:space', $colsSpace); - $xmlWriter->endElement(); - - $xmlWriter->endElement(); + $xmlWriter->endElement(); // w:sectPr } } diff --git a/src/PhpWord/Writer/Word2007/Style/AbstractStyle.php b/src/PhpWord/Writer/Word2007/Style/AbstractStyle.php index fd39e1a2..8bd82b34 100644 --- a/src/PhpWord/Writer/Word2007/Style/AbstractStyle.php +++ b/src/PhpWord/Writer/Word2007/Style/AbstractStyle.php @@ -9,6 +9,7 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Style; +use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Shared\XMLWriter; /** @@ -47,4 +48,21 @@ abstract class AbstractStyle $this->xmlWriter = $xmlWriter; $this->style = $style; } + + /** + * Convert twip value + * + * @param int|float $value + * @param int|float $default + * @return int|float + */ + protected function convertTwip($value, $default) + { + $unit = Settings::getMeasurementUnit(); + if ($unit == Settings::UNIT_TWIP || $value == $default) { + return $value; + } else { + return $value * $unit; + } + } } diff --git a/src/PhpWord/Writer/Word2007/Style/LineNumbering.php b/src/PhpWord/Writer/Word2007/Style/LineNumbering.php new file mode 100644 index 00000000..6167e329 --- /dev/null +++ b/src/PhpWord/Writer/Word2007/Style/LineNumbering.php @@ -0,0 +1,37 @@ +style instanceof \PhpOffice\PhpWord\Style\LineNumbering)) { + return; + } + + $this->xmlWriter->startElement('w:lnNumType'); + $this->xmlWriter->writeAttribute('w:start', $this->style->getStart() - 1); + $this->xmlWriter->writeAttribute('w:countBy', $this->style->getIncrement()); + $this->xmlWriter->writeAttribute('w:distance', $this->style->getDistance()); + $this->xmlWriter->writeAttribute('w:restart', $this->style->getRestart()); + $this->xmlWriter->endElement(); + } +} diff --git a/src/PhpWord/Writer/Word2007/Style/MarginBorder.php b/src/PhpWord/Writer/Word2007/Style/MarginBorder.php index db7cf57b..25fbfbdb 100644 --- a/src/PhpWord/Writer/Word2007/Style/MarginBorder.php +++ b/src/PhpWord/Writer/Word2007/Style/MarginBorder.php @@ -9,6 +9,8 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Style; +use PhpOffice\PhpWord\Settings; + /** * Margin border style writer * @@ -44,6 +46,8 @@ class MarginBorder extends AbstractStyle { $sides = array('top', 'left', 'right', 'bottom', 'insideH', 'insideV'); $sizeCount = count($this->sizes) - 1; + $unit = Settings::getMeasurementUnit(); + for ($i = 0; $i < $sizeCount; $i++) { if (!is_null($this->sizes[$i])) { $this->xmlWriter->startElement('w:' . $sides[$i]); @@ -58,7 +62,7 @@ class MarginBorder extends AbstractStyle $this->xmlWriter->writeAttribute('w:color', $this->colors[$i]); if (!empty($this->attributes)) { if (array_key_exists('space', $this->attributes)) { - $this->xmlWriter->writeAttribute('w:space', '24'); + $this->xmlWriter->writeAttribute('w:space', $this->attributes['space']); } } } else { diff --git a/src/PhpWord/Writer/Word2007/Style/Paragraph.php b/src/PhpWord/Writer/Word2007/Style/Paragraph.php index ffe8af92..831727d2 100644 --- a/src/PhpWord/Writer/Word2007/Style/Paragraph.php +++ b/src/PhpWord/Writer/Word2007/Style/Paragraph.php @@ -9,6 +9,8 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Style; +use PhpOffice\PhpWord\Writer\Word2007\Style\Tab; + /** * Paragraph style writer * @@ -139,17 +141,13 @@ class Paragraph extends AbstractStyle $this->xmlWriter->endElement(); } + // Tabs if (!empty($tabs)) { $this->xmlWriter->startElement("w:tabs"); foreach ($tabs as $tab) { - $this->xmlWriter->startElement("w:tab"); - $this->xmlWriter->writeAttribute("w:val", $tab->getStopType()); - if (!is_null($tab->getLeader())) { - $this->xmlWriter->writeAttribute("w:leader", $tab->getLeader()); - } - $this->xmlWriter->writeAttribute("w:pos", $tab->getPosition()); - $this->xmlWriter->endElement(); + $styleWriter = new Tab($this->xmlWriter, $tab); + $styleWriter->write(); } $this->xmlWriter->endElement(); } diff --git a/src/PhpWord/Writer/Word2007/Style/Section.php b/src/PhpWord/Writer/Word2007/Style/Section.php new file mode 100644 index 00000000..e00a3226 --- /dev/null +++ b/src/PhpWord/Writer/Word2007/Style/Section.php @@ -0,0 +1,95 @@ +style instanceof \PhpOffice\PhpWord\Style\Section)) { + return; + } + + // Section break + if (!is_null($this->style->getBreakType())) { + $this->xmlWriter->startElement('w:type'); + $this->xmlWriter->writeAttribute('w:val', $this->style->getBreakType()); + $this->xmlWriter->endElement(); + } + + // Page size & orientation + $this->xmlWriter->startElement('w:pgSz'); + $this->xmlWriter->writeAttribute('w:orient', $this->style->getOrientation()); + $this->xmlWriter->writeAttribute('w:w', $this->style->getPageSizeW()); + $this->xmlWriter->writeAttribute('w:h', $this->style->getPageSizeH()); + $this->xmlWriter->endElement(); // w:pgSz + + // Margins + $this->xmlWriter->startElement('w:pgMar'); + $this->xmlWriter->writeAttribute('w:top', $this->convertTwip($this->style->getMarginTop(), SectionStyle::DEFAULT_MARGIN)); + $this->xmlWriter->writeAttribute('w:right', $this->convertTwip($this->style->getMarginRight(), SectionStyle::DEFAULT_MARGIN)); + $this->xmlWriter->writeAttribute('w:bottom', $this->convertTwip($this->style->getMarginBottom(), SectionStyle::DEFAULT_MARGIN)); + $this->xmlWriter->writeAttribute('w:left', $this->convertTwip($this->style->getMarginLeft(), SectionStyle::DEFAULT_MARGIN)); + $this->xmlWriter->writeAttribute('w:header', $this->convertTwip($this->style->getHeaderHeight(), SectionStyle::DEFAULT_HEADER_HEIGHT)); + $this->xmlWriter->writeAttribute('w:footer', $this->convertTwip($this->style->getFooterHeight(), SectionStyle::DEFAULT_FOOTER_HEIGHT)); + $this->xmlWriter->writeAttribute('w:gutter', $this->convertTwip($this->style->getGutter(), SectionStyle::DEFAULT_GUTTER)); + $this->xmlWriter->endElement(); + + // Borders + $borders = $this->style->getBorderSize(); + $hasBorders = false; + for ($i = 0; $i < 4; $i++) { + if (!is_null($borders[$i])) { + $hasBorders = true; + break; + } + } + if ($hasBorders) { + $styleWriter = new MarginBorder($this->xmlWriter); + $styleWriter->setSizes($borders); + $styleWriter->setColors($this->style->getBorderColor()); + $styleWriter->setAttributes(array('space' => '24')); + + $this->xmlWriter->startElement('w:pgBorders'); + $this->xmlWriter->writeAttribute('w:offsetFrom', 'page'); + $styleWriter->write(); + $this->xmlWriter->endElement(); + } + + // Page numbering + if (!is_null($this->style->getPageNumberingStart())) { + $this->xmlWriter->startElement('w:pgNumType'); + $this->xmlWriter->writeAttribute('w:start', $this->style->getPageNumberingStart()); + $this->xmlWriter->endElement(); + } + + // Columns + $this->xmlWriter->startElement('w:cols'); + $this->xmlWriter->writeAttribute('w:num', $this->style->getColsNum()); + $this->xmlWriter->writeAttribute('w:space', $this->convertTwip($this->style->getColsSpace(), SectionStyle::DEFAULT_COLUMN_SPACING)); + $this->xmlWriter->endElement(); + + // Line numbering + $styleWriter = new LineNumbering($this->xmlWriter, $this->style->getLineNumbering()); + $styleWriter->write(); + } +} diff --git a/src/PhpWord/Writer/Word2007/Style/Tab.php b/src/PhpWord/Writer/Word2007/Style/Tab.php new file mode 100644 index 00000000..48cdcea6 --- /dev/null +++ b/src/PhpWord/Writer/Word2007/Style/Tab.php @@ -0,0 +1,34 @@ +style instanceof \PhpOffice\PhpWord\Style\Tab)) { + return; + } + + $this->xmlWriter->startElement("w:tab"); + $this->xmlWriter->writeAttribute("w:val", $this->style->getStopType()); + $this->xmlWriter->writeAttribute("w:leader", $this->style->getLeader()); + $this->xmlWriter->writeAttribute('w:pos', $this->convertTwip($this->style->getPosition(), 0)); + $this->xmlWriter->endElement(); + } +} diff --git a/tests/PhpWord/Tests/Style/SectionTest.php b/tests/PhpWord/Tests/Style/SectionTest.php index 542a0f25..ca75f7a2 100644 --- a/tests/PhpWord/Tests/Style/SectionTest.php +++ b/tests/PhpWord/Tests/Style/SectionTest.php @@ -27,25 +27,25 @@ class SettingsTest extends \PHPUnit_Framework_TestCase // Section Settings $oSettings = new Section(); - $oSettings->setSettingValue('_orientation', 'landscape'); + $oSettings->setSettingValue('orientation', 'landscape'); $this->assertEquals('landscape', $oSettings->getOrientation()); $this->assertEquals(16838, $oSettings->getPageSizeW()); $this->assertEquals(11906, $oSettings->getPageSizeH()); - $oSettings->setSettingValue('_orientation', null); - $this->assertNull($oSettings->getOrientation()); + $oSettings->setSettingValue('orientation', null); + $this->assertEquals('portrait', $oSettings->getOrientation()); $this->assertEquals(11906, $oSettings->getPageSizeW()); $this->assertEquals(16838, $oSettings->getPageSizeH()); $iVal = rand(1, 1000); - $oSettings->setSettingValue('_borderSize', $iVal); + $oSettings->setSettingValue('borderSize', $iVal); $this->assertEquals(array($iVal, $iVal, $iVal, $iVal), $oSettings->getBorderSize()); $this->assertEquals($iVal, $oSettings->getBorderBottomSize()); $this->assertEquals($iVal, $oSettings->getBorderLeftSize()); $this->assertEquals($iVal, $oSettings->getBorderRightSize()); $this->assertEquals($iVal, $oSettings->getBorderTopSize()); - $oSettings->setSettingValue('_borderColor', 'FF00AA'); + $oSettings->setSettingValue('borderColor', 'FF00AA'); $this->assertEquals(array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'), $oSettings->getBorderColor()); $this->assertEquals('FF00AA', $oSettings->getBorderBottomColor()); $this->assertEquals('FF00AA', $oSettings->getBorderLeftColor()); diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php b/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php index f84aff42..d13a3e8c 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php @@ -499,4 +499,20 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $this->assertEquals(5, $element->getAttribute('w:val')); } + + /** + * Test write gutter and line numbering + */ + public function testWriteGutterAndLineNumbering() + { + $pageMarginPath = '/w:document/w:body/w:sectPr/w:pgMar'; + $lineNumberingPath = '/w:document/w:body/w:sectPr/w:lnNumType'; + + $phpWord = new PhpWord(); + $section = $phpWord->addSection(array('gutter' => 240, 'lineNumbering' => array())); + $doc = TestHelperDOCX::getDocument($phpWord); + + $this->assertEquals(240, $doc->getElement($pageMarginPath)->getAttribute('w:gutter')); + $this->assertTrue($doc->elementExists($lineNumberingPath)); + } }