Skip to content

Commit

Permalink
Merge branch 'v0.3.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
糖饼 committed Aug 4, 2015
2 parents 29ba312 + 0864680 commit 74ce6a5
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# 更新日志

## 0.3.7

* 完善伪类选择器支持
* 给部分不支持的 CSS 规则显示警告信息

## 0.3.6

* 修复 BUG [#43](https://github.com/aui/font-spider/issues/43)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ font-spider --ignore *-icon.css,*.eot dest/*.html
``` shell
-h, --help 输出帮助信息
-V, --version 输出当前版本号
--info 仅提取 WebFont 信息显示,不压缩与转码
--info 输出 WebFont 的 JSON 描述信息,不压缩与转码
--ignore <pattern> 忽略的文件配置(可以是字体、CSS、HTML)
--map <remotePath,localPath> 映射 CSS 内部 HTTP 路径到本地(支持正则表达式)
--no-backup 关闭字体备份功能
Expand All @@ -101,10 +101,10 @@ font-spider --ignore *-icon.css,*.eot dest/*.html

- 仅支持 `link``style` 标签引入的样式,不支持元素行内样式
- 仅支持固定的文本与样式,不支持 javascript 动态插入的元素与样式
- 不支持字体继承(例如 CSS `content` 属性插入的字符需要声明 `font-family`
- .otf 字体需要转换成 .ttf 才能被压缩
- 仅支持 `utf-8` 编码
- 不支持 CSS `unicode-range` 属性
- 不支持字体继承(例如 CSS `content` 属性插入的字符需要定义 `font-family`

## 字体兼容性参考

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "font-spider",
"description": "Webfont optimizer",
"version": "0.3.6",
"version": "0.3.7",
"homepage": "https://github.com/aui/font-spider",
"author": {
"name": "aui",
Expand Down Expand Up @@ -48,6 +48,10 @@
"devDependencies": {
"mocha": "=2.2.5"
},
"license": {
"type": "MIT",
"url": "http://creativecommons.org/licenses/MIT/"
},
"keywords": [
"font",
"fontforge",
Expand Down
3 changes: 2 additions & 1 deletion src/compress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ Compress.prototype = {
var fontmin = new Fontmin().src(source);
var temp = path.join(dirname, TEMP + number);


// 有些 webfont 使用 content 属性加字体继承,查询不到 chars
// 不压缩,避免意外将 fonticon 干掉了
if (webFont.chars) {
fontmin.use(Fontmin.glyph({
text: webFont.chars
Expand Down
28 changes: 24 additions & 4 deletions src/spider/css-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ CssParser.Parser.prototype = {

var url = utils.unquotation(rule.href.trim());
url = utils.resolve(base, url);
url = this._uri(url);
url = this._getUrl(url);


if (!url) {
Expand Down Expand Up @@ -298,7 +298,7 @@ CssParser.Parser.prototype = {
var urls = [];
src.forEach(function (file) {
file = utils.resolve(base, file);
file = that._uri(file);
file = that._getUrl(file);
if (file) {
urls.push(file);
}
Expand All @@ -321,7 +321,20 @@ CssParser.Parser.prototype = {


var selectorText = rule.selectorText;
var content = utils.unquotation(style.content || '');
var content = style.content || '';

// CSS content 属性
// @see https://developer.mozilla.org/en-US/docs/Web/CSS/content
if (/^['"]|['"]$/.test(content)) {
content = utils.unquotation(content);
} else if (/^(?:open|close)-quote$/.test(content)) {

console.warn('[WARN]', 'does not support `content: ' + content + '`',
'from:', this.file,
'selector:', selectorText);

}


var model = new CssParser
.Model('CSSStyleRule')
Expand Down Expand Up @@ -369,6 +382,13 @@ CssParser.Parser.prototype = {
});


// 不支持继承的字体
if (model.family.indexOf('inherit') !== -1) {
console.warn('[WARN]', 'does not support `font-family: inherit`',
'from:', this.file,
'selector:', selectorText);
}


return model;
},
Expand All @@ -387,7 +407,7 @@ CssParser.Parser.prototype = {

// 转换文件地址
// 执行顺序:ignore > map > normalize
_uri: function (file) {
_getUrl: function (file) {
if (!this.ignore(file)) {
file = this.map(file);
file = utils.normalize(file);
Expand Down
8 changes: 4 additions & 4 deletions src/spider/html-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ HtmlParser.Parser.prototype = {
var href = $this.attr('href');

cssFile = utils.resolve(base, href);
cssFile = uri(cssFile);
cssFile = getUrl(cssFile);

// 注意:为空也得放进去,保持与 link 标签一一对应
files.push(cssFile);
Expand All @@ -121,7 +121,7 @@ HtmlParser.Parser.prototype = {

// 转换 file 地址
// 执行顺序:ignore > map > normalize
function uri (file) {
function getUrl (file) {

if (!that.ignore(file)) {
file = that.map(file);
Expand Down Expand Up @@ -192,11 +192,11 @@ HtmlParser.Parser.prototype = {

var $elem;
var $ = this.$;
var RE_SPURIOUS = /\:(link|visited|hover|active|focus)\b/ig;
var RE_DPSEUDOS = /\:(link|visited|target|active|focus|hover|checked|disabled|enabled|selected|lang\(([-\w]{2,})\)|not\(([^()]*|.*)\))?(.*)/i;


// 剔除状态伪类
selector = selector.replace(RE_SPURIOUS, '');
selector = selector.replace(RE_DPSEUDOS, '');


// 使用选择器查找节点
Expand Down
1 change: 1 addition & 0 deletions test/css/test.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

h1 {
font-weight: ft;
font-family: inherit;
}

#content > h3 {
Expand Down

0 comments on commit 74ce6a5

Please sign in to comment.