Skip to content

Commit

Permalink
支持font和text标签通过属性指定字体
Browse files Browse the repository at this point in the history
  • Loading branch information
lvqier committed Jan 21, 2018
1 parent f56dc05 commit 0eb1748
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/spider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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: 2
});
}
}
});
});
});


pseudoCssStyleRules = null;

webFonts = webFonts.map(function(webFont) {
Expand Down Expand Up @@ -432,4 +459,4 @@ module.exports = function(htmlFiles, adapter, callback) {
return webFonts;
}

};
};

0 comments on commit 0eb1748

Please sign in to comment.