<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>font &#8211; 萧邦的博客</title>
	<atom:link href="https://www.zlhlab.top/tag/font/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.zlhlab.top</link>
	<description>If not me who, If not now when</description>
	<lastBuildDate>Thu, 23 Nov 2017 10:07:15 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.6</generator>
	<item>
		<title>字蛛&#8211;一个中文字体压缩器</title>
		<link>https://www.zlhlab.top/%e5%ad%97%e8%9b%9b-%e4%b8%80%e4%b8%aa%e4%b8%ad%e6%96%87%e5%ad%97%e4%bd%93%e5%8e%8b%e7%bc%a9%e5%99%a8/</link>
		
		<dc:creator><![CDATA[萧邦]]></dc:creator>
		<pubDate>Thu, 23 Nov 2017 10:07:15 +0000</pubDate>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[font]]></category>
		<category><![CDATA[字蛛]]></category>
		<guid isPermaLink="false">https://www.zlhlab.top/?p=469</guid>

					<description><![CDATA[字蛛是一个中文 WebFont 自动化压缩工具，它能自动分析页面使用的 WebFont 并进行按需压缩，无需手工配置。]]></description>
										<content:encoded><![CDATA[<h3>字蛛 &#8211; gulp 插件</h3>
<hr>
<p>字蛛是一个中文 WebFont 自动化压缩工具，它能自动分析页面使用的 WebFont 并进行按需压缩，无需手工配置。</p>
<p>官方网站：<a href="http://font-spider.org" title="http://font-spider.org" target="_blank">http://font-spider.org</a></p>
<h4>特性</h4>
<hr>
<ol>
<li>按需压缩：从原字体中剔除没有用到的字符，可以将数 MB 大小的中文字体压缩成几十 KB</li>
<li>简单可靠：完全基于 HTML 与 CSS 分析进行本地处理，无需 js 与服务端辅助</li>
<li>自动转码：将字体转码成所有浏览器支持的格式，包括老旧的 IE6 与现代浏览器</li>
<li>图标字体：除了常规的字体支持外，还支持图标字体（字蛛 v1.0.0 新特性）</li>
</ol>
<h4>安装</h4>
<hr>
<pre class="line-numbers prism-highlight" data-start="1"><code class="language-erlang">npm install gulp-font-spider --save-dev
</code></pre>
<h4>使用</h4>
<hr>
<pre class="line-numbers prism-highlight" data-start="1"><code class="language-erlang">var gulp = require( 'gulp' );
var fontSpider = require( 'gulp-font-spider' );

gulp.task('fontspider', function() {
    return gulp.src('./index.html')
        .pipe(fontSpider());
});

gulp.task('defualt', ['fontspider']);
</code></pre>
<p>推荐的跨浏览器 <code>@font-face</code> CSS 写法：</p>
<pre class="line-numbers prism-highlight" data-start="1"><code class="language-css">/*声明 WebFont*/
@font-face {
  font-family: 'pinghei';
  src: url('../font/pinghei.eot');
  src:
    url('../font/pinghei.eot?#font-spider') format('embedded-opentype'),
    url('../font/pinghei.woff') format('woff'),
    url('../font/pinghei.ttf') format('truetype'),
    url('../font/pinghei.svg') format('svg');
  font-weight: normal;
  font-style: normal;
}

/*使用选择器指定字体*/
.home h1, .demo &gt; .test {
    font-family: 'pinghei';
}
</code></pre>
<blockquote><p>
  特别说明： <code>@font-face</code>中的 <code>src</code> 定义的 .ttf 文件必须存在，其余的格式将由工具自动生成
</p></blockquote>
<h4>API</h4>
<hr>
<h5>fontSpider(options)</h5>
<h5>options</h5>
<pre class="line-numbers prism-highlight" data-start="1"><code class="language-javascript">{
    /**
     * 忽略加载的文件规则（支持正则） - 与 `resourceIgnore` 参数互斥
     * @type    {Array&lt;String&gt;}
     */
    ignore: [],

    /**
     * 映射的文件规则（支持正则） - 与 `resourceMap` 参数互斥 - 可以将远程字体文件映射到本地来
     * @type    {Array&lt;Array&lt;String&gt;&gt;}
     * @example [['http://font-spider.org/font', __diranme + '/font'], ...]
     */
    map: [],

    /**
     * 是否支持备份原字体
     * @type    {Boolean}
     */
    backup: true,

    /**
     * 是否对查询到的文本进行去重处理
     * @type    {Boolean}
     */
    unique: true,

    /**
     * 是否排序查找到的文本
     * @type    {Boolean}
     */
    sort: true,

    /**
     * 是否支持加载外部 CSS 文件
     */
    loadCssFile: true,

    /**
     * 是否忽略内部解析错误-关闭它有利于开发调试
     * @type    {Boolean}
     */
    silent: true,

    /**
     * 请求超时限制
     * @type    {Number}    毫秒
     */
    resourceTimeout: 8000,

    /**
     * 最大的文件加载数量限制
     * @type    {Number}    数量
     */
    resourceMaxNumber: 64,

    /**
     * 是否缓存请求成功的资源
     * @type    {Boolean}
     */
    resourceCache: true,

    /**
     * 映射资源路径 - 与 `map` 参数互斥
     * @param   {String}    旧文件地址
     * @return  {String}    新文件地址
     */
    resourceMap: function(file) {},

    /**
     * 忽略资源 - 与 `ignore` 参数互斥
     * @param   {String}    文件地址
     * @return  {Boolean}   如果返回 `true` 则忽略当当前文件的加载
     */
    resourceIgnore: function(file) {},

    /**
     * 资源加载前的事件
     * @param   {String}    文件地址
     */
    resourceBeforeLoad: function(file) {},

    /**
     * 加载远程资源的自定义请求头
     * @param   {String}    文件地址
     * @return  {Object}
     */
    resourceRequestHeaders: function(file) {
        return {
            'accept-encoding': 'gzip,deflate'
        };
    }
}
</code></pre>
<h4>使用场景限制</h4>
<hr>
<ul>
<li>仅支持固定的文本与样式，不支持 javascript 动态插入的元素与样式</li>
<li>.otf 字体需要转换成 .ttf 才能被压缩</li>
<li>仅支持 <code>utf-8</code> 编码的 HTML 与 CSS 文件</li>
<li>CSS <code>content</code> 属性只支持普通文本，不支持属性、计数器等特性</li>
</ul>
<h4>字体兼容性参考</h4>
<hr>
<p><img decoding="async" src="https://www.zlhlab.top/wp-content/uploads/2017/11/A30D9C96-5608-443C-9B96-A1EC7CB80179.png" alt=""></p>
<p>文章仅作技术分享，原始地址： <a href="https://github.com/aui/gulp-font-spider" title="https://github.com/aui/gulp-font-spider" target="_blank">https://github.com/aui/gulp-font-spider</a></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
