當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Font::addGlyph方法代碼示例

本文整理匯總了PHP中Font::addGlyph方法的典型用法代碼示例。如果您正苦於以下問題:PHP Font::addGlyph方法的具體用法?PHP Font::addGlyph怎麽用?PHP Font::addGlyph使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Font的用法示例。


在下文中一共展示了Font::addGlyph方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: generateFromDir

 /**
  * generate a font from a directory containing svg files (one file per glyph)
  * by naming convention the file name can specify which character should be mapped to the glyph
  * - my-icon.png       => creates a glyph with the name 'my-icon' mapped to a character in the Unicode Private Use Area
  * - my-icon-x263a.png => creates a glyph with the name 'my-icon' mapped to the unicode character U+263A "☺"
  *
  * @param  string  $path              SVG path definition (consider the font coordinate system has an inverted y axis)
  * @param  array   $fontOptions       font options for the Font object
  * @param  boolean $renameSourceFiles if true, files without mapping information will be renamed
  * @return static                     this
  */
 public function generateFromDir($path, $fontOptions = array(), $renameSourceFiles = false)
 {
     $this->font = new Font($fontOptions);
     $this->mapping = array();
     $fontOptions = $this->font->getOptions();
     $files = scandir($path);
     foreach ($files as $fileName) {
         if (strtolower(substr($fileName, -4)) === '.svg') {
             if (preg_match('(^(.*)-x([0-9a-f]{2,6})\\.svg$)i', $fileName, $matches)) {
                 $iconName = strtolower($matches[1]);
                 $iconCode = static::hexToUnicode(strtolower($matches[2]));
                 if (isset($this->mapping[$iconCode])) {
                     throw new \Exception('Duplicate glyph ' . $iconCode . ' ' . $iconName);
                 }
                 $this->mapping[$iconCode] = array('path' => $path . DIRECTORY_SEPARATOR . $fileName, 'name' => $iconName);
             }
         }
     }
     foreach ($files as $fileName) {
         if (strtolower(substr($fileName, -4)) === '.svg') {
             if (!preg_match('(^(.*)-x([0-9a-f]{2,6})\\.svg$)i', $fileName)) {
                 $iconName = strtolower(substr($fileName, 0, -4));
                 $code = hexdec('e001');
                 while (isset($this->mapping[static::hexToUnicode(dechex($code))])) {
                     $code++;
                 }
                 if ($renameSourceFiles) {
                     if (!rename($path . DIRECTORY_SEPARATOR . $fileName, $path . DIRECTORY_SEPARATOR . $iconName . '-x' . dechex($code) . '.svg')) {
                         throw new \Exception('unable to rename "' . $path . DIRECTORY_SEPARATOR . $fileName . '"');
                     }
                     $fileName = $iconName . '-x' . dechex($code) . '.svg';
                 }
                 $this->mapping[static::hexToUnicode(dechex($code))] = array('path' => $path . DIRECTORY_SEPARATOR . $fileName, 'name' => $iconName);
             }
         }
     }
     foreach ($this->mapping as $code => $icon) {
         try {
             $iconDoc = new Document(file_get_contents($icon['path']));
             $viewBox = $iconDoc->getViewBox();
             $this->font->addGlyph($code, $iconDoc->getPath($fontOptions['units-per-em'] / $viewBox['height'], null, 'vertical', true, 0, $fontOptions['descent']), $icon['name'], round($viewBox['width'] * $fontOptions['units-per-em'] / $viewBox['height']));
         } catch (\Exception $e) {
             throw new \Exception(basename($icon['path']) . ': ' . $e->getMessage());
         }
     }
     return $this;
 }
開發者ID:nofilenamed,項目名稱:SVG-Icon-Font-Generator,代碼行數:58,代碼來源:IconFontGenerator.php


注:本文中的Font::addGlyph方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。