Exemplo n.º 1
0
 /**
  * Calculate the rendered width of the current word
  *
  * Calculate the width of the passed word, using the currently set text
  * formatting options.
  *
  * @param string $word
  * @return float
  */
 public function calculateWordWidth($word)
 {
     if ($this->document === null) {
         $this->initialize();
     }
     // @todo: This removes a lot of valid characters, obviously. Haru
     // cannot handle any Unicode encode, so we need to transform our input
     // string in some single-byte-encoding. We use ISO-8859-1 for now,
     // since it is common. We can either make this configurable (not kiss),
     // or add support for Unicode in haru.
     $word = iconv('UTF-8', 'iso-8859-1//TRANSLIT', $word);
     // Ensure font is initialized
     if ($this->currentFont['font'] === null) {
         $this->trySetFont($this->currentFont['name'], $this->currentFont['style']);
     }
     if ($this->currentPage) {
         return ezcDocumentPcssMeasure::create($this->currentPage->getTextWidth($word) . 'pt')->get();
     } else {
         return ezcDocumentPcssMeasure::create($this->dummyDoc->getCurrentPage()->getTextWidth($word) . 'pt')->get();
     }
 }