本文整理汇总了PHP中Canvas::get_text_width方法的典型用法代码示例。如果您正苦于以下问题:PHP Canvas::get_text_width方法的具体用法?PHP Canvas::get_text_width怎么用?PHP Canvas::get_text_width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Canvas
的用法示例。
在下文中一共展示了Canvas::get_text_width方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
/**
* 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;
}
示例2:
/**
* 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);
}