当前位置: 首页>>代码示例>>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;未经允许,请勿转载。