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


PHP Font::getGlyphs方法代码示例

本文整理汇总了PHP中Font::getGlyphs方法的典型用法代码示例。如果您正苦于以下问题:PHP Font::getGlyphs方法的具体用法?PHP Font::getGlyphs怎么用?PHP Font::getGlyphs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Font的用法示例。


在下文中一共展示了Font::getGlyphs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveGlyphsToDir

 /**
  * save the current font as single svg files in a directory (counterpart of generateFromDir)
  *
  * @param  string $dir directory path
  * @return static      this
  */
 public function saveGlyphsToDir($dir)
 {
     $fontOptions = $this->font->getOptions();
     $svgTemplate = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' . "\n" . '<svg' . "\n" . '	version="1.1"' . "\n" . '	id="Layer_1"' . "\n" . '	xmlns="http://www.w3.org/2000/svg"' . "\n" . '	xmlns:xlink="http://www.w3.org/1999/xlink"' . "\n" . '	x="0px"' . "\n" . '	y="0px"' . "\n" . '	width="%%%WIDTH%%%px"' . "\n" . '	height="512px"' . "\n" . '	viewBox="0 0 %%%WIDTH%%% 512"' . "\n" . '	enable-background="new 0 0 512 512"' . "\n" . '	xml:space="preserve"' . "\n" . '>' . "\n" . '	<g id="Grid">' . "\n" . '		<rect x="0" fill="none" stroke="#A9CCDB" stroke-miterlimit="10" width="512" height="512"/>' . "\n";
     for ($i = 32; $i < 512; $i += 32) {
         $color = 'A9CCDB';
         if ($i === 448) {
             $color = 'FF0000';
         }
         $svgTemplate .= '		<line fill="none" stroke="#' . $color . '" stroke-miterlimit="10" x1="0" y1="' . $i . '" x2="512" y2="' . $i . '"/>' . "\n";
     }
     for ($i = 32; $i < 512; $i += 32) {
         $svgTemplate .= '		<line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="' . $i . '" y1="0" x2="' . $i . '" y2="512"/>' . "\n";
     }
     $svgTemplate .= '	</g>' . "\n" . '	<path d="%%%PATH%%%"/>' . "\n" . '</svg>' . "\n";
     if (!is_dir($dir)) {
         throw new \InvalidArgumentException('$dir must be a writable directory');
     }
     foreach ($this->font->getGlyphs() as $glyph) {
         $targetPath = $dir . DIRECTORY_SEPARATOR . (empty($glyph['name']) ? 'icon' : preg_replace('([^a-z0-9]+)i', '-', $glyph['name'])) . '-x' . static::unicodeToHex($glyph['char']) . '.svg';
         if (isset($this->mapping[$glyph['char']])) {
             if (!copy($this->mapping[$glyph['char']]['path'], $targetPath)) {
                 throw new \Exception('unable to copy "' . $this->mapping[$glyph['char']]['path'] . '" to "' . $targetPath . '"');
             }
         } else {
             $glyphDocument = Document::createFromPath($glyph['path'], $fontOptions['horiz-adv-x'], $fontOptions['units-per-em']);
             if (file_put_contents($targetPath, str_replace(array('%%%PATH%%%', '%%%WIDTH%%%'), array($glyphDocument->getPath(512 / $fontOptions['units-per-em'], null, 'vertical', true, 0, -64), empty($glyph['width']) ? 512 : $glyph['width'] * 512 / $fontOptions['units-per-em']), $svgTemplate)) === false) {
                 throw new \Exception('unable to write to "' . $targetPath . '"');
             }
         }
     }
     return $this;
 }
开发者ID:nofilenamed,项目名称:SVG-Icon-Font-Generator,代码行数:39,代码来源:IconFontGenerator.php


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