Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * 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);
     }
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /**
  * Convert text to valid format
  *
  * @param string $text
  * @return string
  */
 protected function getText($text)
 {
     return StringElement::controlCharacterPHP2OOXML($text);
 }
Example #6
0
 /**
  * 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);
     }
 }
Example #7
0
 /**
  * Set text content
  *
  * @param string $text
  * @return self
  */
 public function setText($text)
 {
     $this->text = StringElement::toUTF8($text);
     return $this;
 }
Example #8
0
 /**
  * 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);
 }
Example #9
0
 /**
  * Create a new Bookmark Element
  *
  * @param string $name
  */
 public function __construct($name)
 {
     $this->name = StringElement::toUTF8($name);
     return $this;
 }
Example #10
0
 /**
  * Write text
  *
  * @param string $text
  * @return string
  */
 protected function writeText($text)
 {
     return StringElement::toUnicode($text);
 }
Example #11
0
 /**
  * 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;
 }
Example #12
0
 /**
  * Set name content
  *
  * @param string $name
  * @return self
  */
 public function setName($name)
 {
     $this->name = StringElement::toUTF8($name);
     return $this;
 }
Example #13
0
 /**
  * Test remove underscore prefix
  */
 public function testRemoveUnderscorePrefix()
 {
     $this->assertEquals('item', StringElement::removeUnderscorePrefix('_item'));
 }