/** * Set Style value * * @param string $key * @param mixed $value * @return self */ public function setStyleValue($key, $value) { $key = String::removeUnderscorePrefix($key); if ($key == 'indent' || $key == 'hanging') { $value = $value * 720; } elseif ($key == 'spacing') { $value += 240; // because line height of 1 matches 240 twips } return parent::setStyleValue($key, $value); }
/** * Test remove underscore prefix */ public function testRemoveUnderscorePrefix() { $this->assertEquals('item', String::removeUnderscorePrefix('_item')); }
/** * Set style value template method * * Some child classes have their own specific overrides. * Backward compability check for versions < 0.10.0 which use underscore * prefix for their private properties. * Check if the set method is exists. Throws an exception? * * @param string $key * @param string $value * @return self */ public function setStyleValue($key, $value) { if (isset($this->aliases[$key])) { $key = $this->aliases[$key]; } $method = 'set' . String::removeUnderscorePrefix($key); if (method_exists($this, $method)) { $this->{$method}($value); } return $this; }
/** * Set Style value * * @param string $key * @param mixed $value */ public function setStyleValue($key, $value) { $key = String::removeUnderscorePrefix($key); if ($key == 'indent' || $key == 'hanging') { $value = $value * 720; } elseif ($key == 'spacing') { $value += 240; // because line height of 1 matches 240 twips } elseif ($key === 'line-height') { $this->setLineHeight($value); return; } $method = 'set' . $key; if (method_exists($this, $method)) { $this->{$method}($value); } }