/** * Test setting style values with null or empty value */ public function testSetStyleValueWithNullOrEmpty() { $object = new Font(); $attributes = array('name' => PhpWord::DEFAULT_FONT_NAME, 'size' => PhpWord::DEFAULT_FONT_SIZE, 'bold' => false, 'italic' => false, 'superScript' => false, 'subScript' => false, 'underline' => Font::UNDERLINE_NONE, 'strikethrough' => false, 'color' => PhpWord::DEFAULT_FONT_COLOR, 'fgColor' => null, 'bgColor' => null, 'hint' => PhpWord::DEFAULT_FONT_CONTENT_TYPE); foreach ($attributes as $key => $default) { $get = "get{$key}"; $object->setStyleValue("{$key}", null); $this->assertEquals($default, $object->{$get}()); $object->setStyleValue("{$key}", ''); $this->assertEquals($default, $object->{$get}()); } }
/** * Test setting style values with null or empty value */ public function testSetStyleValueWithNullOrEmpty() { $object = new Font(); $attributes = array('name' => null, 'size' => null, 'hint' => null, 'color' => null, 'bold' => false, 'italic' => false, 'underline' => Font::UNDERLINE_NONE, 'superScript' => false, 'subScript' => false, 'strikethrough' => false, 'doubleStrikethrough' => false, 'smallCaps' => false, 'allCaps' => false, 'fgColor' => null, 'bgColor' => null, 'scale' => null, 'spacing' => null, 'kerning' => null); foreach ($attributes as $key => $default) { $get = is_bool($default) ? "is{$key}" : "get{$key}"; $this->assertEquals($default, $object->{$get}()); $object->setStyleValue($key, null); $this->assertEquals($default, $object->{$get}()); $object->setStyleValue($key, ''); $this->assertEquals($default, $object->{$get}()); } }
/** * Create a new Table-of-Contents Element * * @param mixed $fontStyle * @param array $tocStyle * @param integer $minDepth * @param integer $maxDepth */ public function __construct($fontStyle = null, $tocStyle = null, $minDepth = 1, $maxDepth = 9) { $this->TOCStyle = new TOCStyle(); if (!is_null($tocStyle) && is_array($tocStyle)) { foreach ($tocStyle as $key => $value) { $this->TOCStyle->setStyleValue($key, $value); } } if (!is_null($fontStyle)) { if (is_array($fontStyle)) { $this->fontStyle = new Font(); foreach ($fontStyle as $key => $value) { $this->fontStyle->setStyleValue($key, $value); } } else { $this->fontStyle = $fontStyle; } } $this->minDepth = $minDepth; $this->maxDepth = $maxDepth; }
/** * Set style values and put it to static style collection * * @param string $styleName * @param Paragraph|Font|Table|Numbering $styleObject * @param array|null $styleValues */ private static function setStyleValues($styleName, $styleObject, $styleValues = null) { if (!array_key_exists($styleName, self::$styles)) { if (!is_null($styleValues) && is_array($styleValues)) { foreach ($styleValues as $key => $value) { $styleObject->setStyleValue($key, $value); } } $styleObject->setStyleName($styleName); $styleObject->setIndex(self::countStyles() + 1); // One based index self::$styles[$styleName] = $styleObject; } }