diff --git a/src/Core.js b/src/Core.js index 1dc22c9..9caaa5c 100644 --- a/src/Core.js +++ b/src/Core.js @@ -20,6 +20,33 @@ _html2canvas.Util.trimText = (function(isNative){ }; })( String.prototype.trim ); +(function() { + + // TODO: support all possible length values + var TEXT_SHADOW_PROPERTY = /((rgba|rgb)\([^\)]+\)(\s-?\d+px){0,})/g; + var TEXT_SHADOW_VALUES = /(-?\d+px)|(#.+)|(rgb\(.+\))|(rgba\(.+\))/g; + _html2canvas.Util.parseTextShadows = function (value) { + if (value === 'none') { + return []; + } + + // find multiple shadow declarations + var shadows = value.match(TEXT_SHADOW_PROPERTY), + results = []; + for (var i = 0; i < shadows.length; i++) { + var s = shadows[i].match(TEXT_SHADOW_VALUES); + results.push({ + color: s[0], + offsetX: s[1] ? s[1].replace('px', '') : 0, + offsetY: s[2] ? s[2].replace('px', '') : 0, + blur: s[3] ? s[3].replace('px', '') : 0 + }); + } + return results; + }; +})(); + + _html2canvas.Util.parseBackgroundImage = function (value) { var whitespace = ' \r\n\t', method, definition, prefix, prefix_i, block, results = [], diff --git a/src/Parse.js b/src/Parse.js index 643d534..bad6ab2 100644 --- a/src/Parse.js +++ b/src/Parse.js @@ -79,7 +79,8 @@ _html2canvas.Parse = function (images, options) { var align = false, bold = getCSS(el, "fontWeight"), family = getCSS(el, "fontFamily"), - size = getCSS(el, "fontSize"); + size = getCSS(el, "fontSize"), + shadow = getCSS(el, "textShadow"); switch(parseInt(bold, 10)){ case 401: @@ -94,6 +95,17 @@ _html2canvas.Parse = function (images, options) { ctx.setVariable("font", [getCSS(el, "fontStyle"), getCSS(el, "fontVariant"), bold, size, family].join(" ")); ctx.setVariable("textAlign", (align) ? "right" : "left"); + if (shadow !== "none") { + var shadows = _html2canvas.Util.parseTextShadows(shadow); + + // TODO: support multiple text shadows + // apply the first text shadow + ctx.setVariable("shadowColor", shadows[0].color); + ctx.setVariable("shadowOffsetX", shadows[0].offsetX); + ctx.setVariable("shadowOffsetY", shadows[0].offsetY); + ctx.setVariable("shadowBlur", shadows[0].blur); + } + if (text_decoration !== "none"){ return _html2canvas.Util.Font(family, size, doc); } diff --git a/tests/qunit/index.html b/tests/qunit/index.html index 4545f06..acef453 100644 --- a/tests/qunit/index.html +++ b/tests/qunit/index.html @@ -70,6 +70,17 @@
+