From a24275f33859c2c8386d144c9120c465c229a4d2 Mon Sep 17 00:00:00 2001 From: Qier LU Date: Sun, 21 Jan 2018 15:32:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81font=E5=92=8Ctext=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E9=80=9A=E8=BF=87=E5=B1=9E=E6=80=A7=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E5=AD=97=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/spider/index.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/spider/index.js b/src/spider/index.js index 4c92d50..3faa335 100644 --- a/src/spider/index.js +++ b/src/spider/index.js @@ -53,6 +53,7 @@ FontSpider.prototype = { var pseudoCssStyleRules = []; var pseudoSelector = /\:\:?(?:before|after)$/i; var inlineStyleSelectors = 'body[style*="font"], body [style*="font"]'; + var specialTags = { font: 'face', text: 'font-family' }; cssStyleRules.forEach(function(cssStyleRule) { @@ -173,6 +174,32 @@ FontSpider.prototype = { }); + // 通过 attribute 指定字体的特殊标签 + Object.keys(specialTags).forEach(function(tagName) { + var attribute = specialTags[tagName]; + var selector = tagName + '[' + attribute + ']'; + that.getElements(selector).forEach(function(element) { + var fontFamily = element.getAttribute(attribute); + webFonts.forEach(function(webFont) { + if (webFont.family === fontFamily) { + var chars = element.textContent; + + webFont.addChar(chars); + + if (that.debug) { + that.debugInfo({ + family: webFont.family, + selector: selector, + chars: chars, + type: 4 + }); + } + } + }); + }); + }); + + pseudoCssStyleRules = null; webFonts = webFonts.map(function(webFont) { @@ -432,4 +459,4 @@ module.exports = function(htmlFiles, adapter, callback) { return webFonts; } -}; \ No newline at end of file +};