Merge pull request #15 from stafyniaksacha/master

Parsing all text font properties
This commit is contained in:
clintjd 2015-04-22 13:17:16 -07:00
commit 4290be85d0

View File

@ -681,12 +681,14 @@
* @private * @private
*/ */
ctx.prototype.__parseFont = function() { ctx.prototype.__parseFont = function() {
var font = this.font, parts, token, index = 0, data = { var regex = /^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-,\"\sa-z]+?)\s*$/i;
style : "normal", var fontPart = regex.exec( this.font );
size : "10px", var data = {
family : "sans-serif", style : fontPart[1] || 'normal',
weight: "normal", size : fontPart[4] || '10px',
decoration : "none", //underline | none family : fontPart[6] || 'sans-serif',
weight: fontPart[3] || 'normal',
decoration : fontPart[2] || 'normal',
href : null href : null
}; };
@ -700,31 +702,6 @@
data.href = this.__fontHref; data.href = this.__fontHref;
} }
parts = font.split(" ");
token = parts[index];
//text decoration
while(/italic|bold|normal/.test(token)) {
if(token === "bold") {
data.weight = token; //[normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit]
} else {
data.style = token; //[normal / italic /oblique /inherit]
}
//advance to next token
index++;
token = parts[index];
}
//next token should be font size
if(/em|px|pt|%/.test(token)) {
data.size = token;
index++;
}
//font family?
parts.splice(0, index);
data.family = parts.join(" ");
return data; return data;
}; };