当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Pdf_Cmap::getCoveredCharacters方法代码示例

本文整理汇总了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;
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:50,代码来源:Font.php


注:本文中的Zend_Pdf_Cmap::getCoveredCharacters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。