/** * Calculates text size, in points * * @param string $text the text to be sized * @param string $font the desired font * @param float $size the desired font size * @param float $word_spacing * @param float $char_spacing * * @internal param float $spacing word spacing, if any * @return float */ static function get_text_width($text, $font, $size, $word_spacing = 0.0, $char_spacing = 0.0) { //return self::$_pdf->get_text_width($text, $font, $size, $word_spacing, $char_spacing); // @todo Make sure this cache is efficient before enabling it static $cache = array(); if ( $text === "" ) { return 0; } // Don't cache long strings $use_cache = !isset($text[50]); // Faster than strlen $key = "$font/$size/$word_spacing/$char_spacing"; if ( $use_cache && isset($cache[$key][$text]) ) { return $cache[$key]["$text"]; } $width = self::$_pdf->get_text_width($text, $font, $size, $word_spacing, $char_spacing); if ( $use_cache ) { $cache[$key][$text] = $width; } return $width; }
/** * Calculates text size, in points * * @param string $text the text to be sized * @param string $font the desired font * @param float $size the desired font size * @param float $spacing word spacing, if any * @return float */ static function get_text_width($text, $font, $size, $word_spacing = 0, $char_spacing = 0) { return self::$_pdf->get_text_width($text, $font, $size, $word_spacing, $char_spacing); }