/** * Create a new Title Element * * @param string $text * @param int $depth */ public function __construct($text, $depth = 1) { $this->text = StringElement::toUTF8($text); $this->depth = $depth; if (array_key_exists("Heading_{$this->depth}", Style::getStyles())) { $this->style = "Heading{$this->depth}"; } return $this; }
/** * Create a new Link Element * * @param string $source * @param string $text * @param mixed $fontStyle * @param mixed $paragraphStyle */ public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null, $internal = false) { $this->source = StringElement::toUTF8($source); $this->text = is_null($text) ? $this->source : StringElement::toUTF8($text); $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle); $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); $this->internal = $internal; return $this; }
/** * Create a new ListItem * * @param string $text * @param int $depth * @param mixed $fontStyle * @param array|string|null $listStyle * @param mixed $paragraphStyle */ public function __construct($text, $depth = 0, $fontStyle = null, $listStyle = null, $paragraphStyle = null) { $this->textObject = new Text(StringElement::toUTF8($text), $fontStyle, $paragraphStyle); $this->depth = $depth; // Version >= 0.10.0 will pass numbering style name. Older version will use old method if (!is_null($listStyle) && is_string($listStyle)) { $this->style = new ListItemStyle($listStyle); } else { $this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true); } }
/** * Create a new Preserve Text Element * * @param string $text * @param mixed $fontStyle * @param mixed $paragraphStyle * @return self */ public function __construct($text = null, $fontStyle = null, $paragraphStyle = null) { $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle); $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); $this->text = StringElement::toUTF8($text); $matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); if (isset($matches[0])) { $this->text = $matches; } return $this; }
/** * Convert text to valid format * * @param string $text * @return string */ protected function getText($text) { return StringElement::controlCharacterPHP2OOXML($text); }
/** * Find and replace macros in the given XML section. * * @param string $documentPartXML * @param string $search * @param string $replace * @param integer $limit * * @return string */ protected function setValueForPart($documentPartXML, $search, $replace, $limit) { if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') { $search = '${' . $search . '}'; } if (!StringElement::isUTF8($replace)) { $replace = utf8_encode($replace); } // Note: we can't use the same function for both cases here, because of performance considerations. if (self::MAXIMUM_REPLACEMENTS_DEFAULT === $limit) { return str_replace($search, $replace, $documentPartXML); } else { $regExpDelim = '/'; $escapedSearch = preg_quote($search, $regExpDelim); return preg_replace("{$regExpDelim}{$escapedSearch}{$regExpDelim}u", $replace, $documentPartXML, $limit); } }
/** * Set text content * * @param string $text * @return self */ public function setText($text) { $this->text = StringElement::toUTF8($text); return $this; }
/** * Set Style value * * @param string $key * @param mixed $value * @return self */ public function setStyleValue($key, $value) { $key = StringElement::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); }
/** * Create a new Bookmark Element * * @param string $name */ public function __construct($name) { $this->name = StringElement::toUTF8($name); return $this; }
/** * Write text * * @param string $text * @return string */ protected function writeText($text) { return StringElement::toUnicode($text); }
/** * 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' . StringElement::removeUnderscorePrefix($key); if (method_exists($this, $method)) { $this->{$method}($value); } return $this; }
/** * Set name content * * @param string $name * @return self */ public function setName($name) { $this->name = StringElement::toUTF8($name); return $this; }
/** * Test remove underscore prefix */ public function testRemoveUnderscorePrefix() { $this->assertEquals('item', StringElement::removeUnderscorePrefix('_item')); }