本文整理汇总了PHP中Zend_Pdf_Cmap::getCoveredCharacters方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Pdf_Cmap::getCoveredCharacters方法的具体用法?PHP Zend_Pdf_Cmap::getCoveredCharacters怎么用?PHP Zend_Pdf_Cmap::getCoveredCharacters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Pdf_Cmap
的用法示例。
在下文中一共展示了Zend_Pdf_Cmap::getCoveredCharacters方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCoveredPercentage
/**
* Returns a number between 0 and 1 inclusive that indicates the percentage
* of characters in the string which are covered by glyphs in this font.
*
* Since no one font will contain glyphs for the entire Unicode character
* range, this method can be used to help locate a suitable font when the
* actual contents of the string are not known.
*
* Note that some fonts lie about the characters they support. Additionally,
* fonts don't usually contain glyphs for control characters such as tabs
* and line breaks, so it is rare that you will get back a full 1.0 score.
* The resulting value should be considered informational only.
*
* @param string $string
* @param string $charEncoding (optional) Character encoding of source text.
* If omitted, uses 'current locale'.
* @return float
*/
public function getCoveredPercentage($string, $charEncoding = '')
{
/* Convert the string to UTF-16BE encoding so we can match the string's
* character codes to those found in the cmap.
*/
if ($charEncoding != 'UTF-16BE') {
$string = iconv($charEncoding, 'UTF-16BE', $string);
}
$charCount = iconv_strlen($string, 'UTF-16BE');
if ($charCount == 0) {
return 0;
}
/* Fetch the covered character code list from the font's cmap.
*/
$coveredCharacters = $this->cmap->getCoveredCharacters();
/* Calculate the score by doing a lookup for each character.
*/
$score = 0;
$maxIndex = strlen($string);
for ($i = 0; $i < $maxIndex; $i++) {
/**
* @todo Properly handle characters encoded as surrogate pairs.
*/
$charCode = ord($string[$i]) << 8 | ord($string[++$i]);
/* This could probably be optimized a bit with a binary search...
*/
if (in_array($charCode, $coveredCharacters)) {
$score++;
}
}
return $score / $charCount;
}