From 35cb5a6300db7c24c531b8eb133e7235100534c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= <1987.tangbin@gmail.com> Date: Sun, 2 Aug 2015 23:57:30 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E5=AF=B9=E4=B8=8D=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=9A=84=E7=89=B9=E6=80=A7=E6=98=BE=E7=A4=BA=E8=AD=A6=E5=91=8A?= =?UTF-8?q?=E4=BF=A1=E6=81=AF#44?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- package.json | 2 +- src/spider/css-parser.js | 7 +++++++ test/css/test.css | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 64c9fb9..2fa8c27 100644 --- a/README.md +++ b/README.md @@ -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`) ## 字体兼容性参考 diff --git a/package.json b/package.json index 3bd11ce..56f369a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/spider/css-parser.js b/src/spider/css-parser.js index 787c0cb..8907c45 100644 --- a/src/spider/css-parser.js +++ b/src/spider/css-parser.js @@ -369,6 +369,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; }, diff --git a/test/css/test.css b/test/css/test.css index cacfb65..d63af55 100644 --- a/test/css/test.css +++ b/test/css/test.css @@ -45,6 +45,7 @@ h1 { font-weight: ft; + font-family: inherit; } #content > h3 { From c221ea62df63152e05d11e1a2ecf564ebf029c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= <1987.tangbin@gmail.com> Date: Mon, 3 Aug 2015 13:55:21 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0license?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index 56f369a..993a329 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,10 @@ "devDependencies": { "mocha": "=2.2.5" }, + "license": { + "type": "MIT", + "url": "http://creativecommons.org/licenses/MIT/" + }, "keywords": [ "font", "fontforge", From 8f532ce33df0126c4f30a327f7caf6a3345e3df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= <1987.tangbin@gmail.com> Date: Mon, 3 Aug 2015 18:39:45 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compress/index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/compress/index.js b/src/compress/index.js index 5640032..475f8b2 100644 --- a/src/compress/index.js +++ b/src/compress/index.js @@ -133,11 +133,9 @@ Compress.prototype = { var temp = path.join(dirname, TEMP + number); - if (webFont.chars) { - fontmin.use(Fontmin.glyph({ - text: webFont.chars - })); - } + fontmin.use(Fontmin.glyph({ + text: webFont.chars || '-' + })); Object.keys(files).forEach(function (key) { From 458f871e98afe07acced93a786a7e47988ad520b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= <1987.tangbin@gmail.com> Date: Mon, 3 Aug 2015 18:40:39 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E5=AF=B9=E4=B8=8D=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=9A=84content=E5=85=B3=E9=94=AE=E5=AD=97=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E8=AD=A6=E5=91=8A=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/spider/css-parser.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/spider/css-parser.js b/src/spider/css-parser.js index 8907c45..024ab7c 100644 --- a/src/spider/css-parser.js +++ b/src/spider/css-parser.js @@ -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) { @@ -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); } @@ -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') @@ -394,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); From 360bce9fdaff0a653283f31e1c9a70aba0c7c09c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= <1987.tangbin@gmail.com> Date: Tue, 4 Aug 2015 14:46:38 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BC=AA=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/spider/html-parser.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/spider/html-parser.js b/src/spider/html-parser.js index a262e6e..f74d6c2 100644 --- a/src/spider/html-parser.js +++ b/src/spider/html-parser.js @@ -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); @@ -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); @@ -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, ''); // 使用选择器查找节点 From a3d2c2fc3ea3dd6edc3c0a7f7b3d13b2344cf72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= <1987.tangbin@gmail.com> Date: Tue, 4 Aug 2015 14:48:16 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E5=85=BC=E5=AE=B9fonticon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compress/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compress/index.js b/src/compress/index.js index 475f8b2..72dfe8c 100644 --- a/src/compress/index.js +++ b/src/compress/index.js @@ -132,10 +132,13 @@ Compress.prototype = { var fontmin = new Fontmin().src(source); var temp = path.join(dirname, TEMP + number); - - fontmin.use(Fontmin.glyph({ - text: webFont.chars || '-' - })); + // 有些 webfont 使用 content 属性加字体继承,查询不到 chars + // 不压缩,避免意外将 + if (webFont.chars) { + fontmin.use(Fontmin.glyph({ + text: webFont.chars + })); + } Object.keys(files).forEach(function (key) { From cf804d048fa323aeaf7339939a8d2190240c69d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= <1987.tangbin@gmail.com> Date: Tue, 4 Aug 2015 14:48:36 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E5=85=BC=E5=AE=B9fonticon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compress/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compress/index.js b/src/compress/index.js index 72dfe8c..6031b6e 100644 --- a/src/compress/index.js +++ b/src/compress/index.js @@ -133,7 +133,7 @@ Compress.prototype = { var temp = path.join(dirname, TEMP + number); // 有些 webfont 使用 content 属性加字体继承,查询不到 chars - // 不压缩,避免意外将 + // 不压缩,避免意外将 fonticon 干掉了 if (webFont.chars) { fontmin.use(Fontmin.glyph({ text: webFont.chars From aa4f6b0dc5087045e30c3f093bb213d9e6c77f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= <1987.tangbin@gmail.com> Date: Tue, 4 Aug 2015 14:48:47 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2fa8c27..5fd10b2 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ font-spider --ignore *-icon.css,*.eot dest/*.html ``` shell -h, --help 输出帮助信息 -V, --version 输出当前版本号 ---info 仅提取 WebFont 信息显示,不压缩与转码 +--info 输出 WebFont 的 JSON 描述信息,不压缩与转码 --ignore 忽略的文件配置(可以是字体、CSS、HTML) --map 映射 CSS 内部 HTTP 路径到本地(支持正则表达式) --no-backup 关闭字体备份功能 From 0864680f5399cf0607757090d4a41b764b6c0b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B3=96=E9=A5=BC?= <1987.tangbin@gmail.com> Date: Tue, 4 Aug 2015 14:52:28 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61913b4..326aa8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +## 0.3.7 + +* 完善伪类选择器支持 +* 给部分不支持的 CSS 规则显示警告信息 + ## 0.3.6 * 修复 BUG [#43](https://github.com/aui/font-spider/issues/43)