private function setLineHeight($numLines = 1)
 {
     if (empty($numLines)) {
         $numLines = 1;
     }
     $lineLeading = intval($this->_font->getLineHeight() / $this->_font->getUnitsPerEm());
     $this->_currentHeight = $this->getHeight() * $numLines + $lineLeading;
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Returns the total width in points of the string using the specified font and
  * size.
  *
  * This is not the most efficient way to perform this calculation. I'm
  * concentrating optimization efforts on the upcoming layout manager class.
  * Similar calculations exist inside the layout manager class, but widths are
  * generally calculated only after determining line fragments.
  *
  * @param string $string
  * @param Zend_Pdf_Resource_Font $font
  * @param float $fontSize Font size in points
  * @return float
  */
 public function widthForStringUsingFontSize($string, $font, $fontSize)
 {
     $drawingString = '"libiconv"' == ICONV_IMPL ? iconv('UTF-8', 'UTF-16BE//IGNORE', $string) : @iconv('UTF-8', 'UTF-16BE', $string);
     $characters = array();
     for ($i = 0; $i < strlen($drawingString); $i++) {
         $characters[] = ord($drawingString[$i++]) << 8 | ord($drawingString[$i]);
     }
     $glyphs = $font->glyphNumbersForCharacters($characters);
     $widths = $font->widthsForGlyphs($glyphs);
     $stringWidth = array_sum($widths) / $font->getUnitsPerEm() * $fontSize;
     return $stringWidth;
 }
Exemplo n.º 3
0
 /**
  * Calculate the width of given text in points taking into account current font and font-size
  *
  * @param string $text
  * @param Zend_Pdf_Resource_Font $font
  * @param float $font_size
  * @return float
  */
 public function getTextWidth($text, Zend_Pdf_Resource_Font $font, $font_size)
 {
     $drawing_text = iconv('', 'UTF-16BE', $text);
     $characters = array();
     for ($i = 0; $i < strlen($drawing_text); $i++) {
         $characters[] = ord($drawing_text[$i++]) << 8 | ord($drawing_text[$i]);
     }
     $glyphs = $font->glyphNumbersForCharacters($characters);
     $widths = $font->widthsForGlyphs($glyphs);
     $text_width = array_sum($widths) / $font->getUnitsPerEm() * $font_size;
     return $text_width;
 }
Exemplo n.º 4
0
 /**
  * Returns the total width in points of the string using the specified font and
  * size.
  *
  * This is not the most efficient way to perform this calculation. I'm
  * concentrating optimization efforts on the upcoming layout manager class.
  * Similar calculations exist inside the layout manager class, but widths are
  * generally calculated only after determining line fragments.
  * 
  * @link http://devzone.zend.com/article/2525-Zend_Pdf-tutorial#comments-2535 
  * @param string $string
  * @param Zend_Pdf_Resource_Font $font
  * @param float $fontSize Font size in points
  * @return float
  */
 protected function width_to_points($string, $font, $fontSize)
 {
     try {
         $drawingString = iconv('UTF-8', 'UTF-16BE//IGNORE', $string);
         $characters = array();
         for ($i = 0; $i < strlen($drawingString); $i++) {
             $characters[] = ord($drawingString[$i++]) << 8 | ord($drawingString[$i]);
         }
         $glyphs = $font->glyphNumbersForCharacters($characters);
         $widths = $font->widthsForGlyphs($glyphs);
         $stringWidth = array_sum($widths) / $font->getUnitsPerEm() * $fontSize;
     } catch (Exception $e) {
         die($e->getMessage);
     }
     return $stringWidth;
 }