Update canvas2svg.js

update the __parseFont for parsing all css font values
This commit is contained in:
STAFYNIAK 2015-03-12 20:52:14 +01:00
parent 16384e302c
commit bba650de98

View File

@ -681,50 +681,17 @@
* @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 : parts[2] || 'normal',
href : null href : null
}; };
//canvas doesn't support underline natively, but we can pass this attribute
if(this.__fontUnderline === "underline") {
data.decoration = "underline";
}
//canvas also doesn't support linking, but we can pass this as well
if(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;
}; };