字蛛-中文字體壓縮器安裝及使用方法,讓網(wǎng)頁(yè)自由引入中文字體成為可能。

字蛛通過(guò)分析本地 CSS 與 HTML 文件獲取 WebFont 中沒(méi)有使用的字符,并將這些字符數(shù)據(jù)從字體中刪除以實(shí)現(xiàn)壓縮,同時(shí)生成跨瀏覽器使用的格式。
先安裝好 NodeJS,然后執(zhí)行:
npm install font-spider -g
在 CSS 中使用 WebFont:
/*聲明 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 > .test {
font-family: 'pinghei';
}1. @font-face 中的 src 定義的 .ttf 文件必須存在,其余的格式將由工具自動(dòng)生成
2. 開(kāi)發(fā)階段請(qǐng)使用相對(duì)路徑的 CSS 與 WebFont
運(yùn)行 font-spider 命令:
font-spider G:/test/font/font.html
頁(yè)面依賴的字體將會(huì)自動(dòng)壓縮好,原 .ttf 字體會(huì)備份。

注:紅色框是命令,玫紅色框是 所使用文字html的路徑(上圖是單一HTML文件字體壓縮)

上面就是生成的字體文件(圈起來(lái)的是備份出來(lái)的源文件)
掃描二維碼手機(jī)查看該文章
文章引用:http://www.qingbaosc.com/news/webzhishi/1441.html




