refactored parsing init

This commit is contained in:
Niklas von Hertzen 2012-12-30 16:06:59 +02:00
parent d93e36d768
commit 0dd2c24ab4

View File

@ -8,11 +8,6 @@ _html2canvas.Parse = function (images, options) {
support = _html2canvas.Util.Support(options, doc),
ignoreElementsRegExp = new RegExp("(" + options.ignoreElements + ")"),
body = doc.body,
stack,
ctx,
i,
children,
childrenLen,
getCSS = _html2canvas.Util.getCSS;
images = images || {};
@ -165,7 +160,7 @@ _html2canvas.Parse = function (images, options) {
}
}
function renderTextDecoration(text_decoration, bounds, metrics, color) {
function renderTextDecoration(ctx, text_decoration, bounds, metrics, color) {
switch(text_decoration) {
case "underline":
// Draws a line at the baseline of the font
@ -243,7 +238,7 @@ _html2canvas.Parse = function (images, options) {
var bounds = getTextBounds(state, text, textDecoration, (index < textList.length - 1));
if (bounds) {
drawText(text, bounds.left, bounds.bottom, ctx);
renderTextDecoration(textDecoration, bounds, metrics, color);
renderTextDecoration(ctx, textDecoration, bounds, metrics, color);
}
});
}
@ -317,6 +312,7 @@ _html2canvas.Parse = function (images, options) {
function renderListItem(element, stack, elBounds) {
var x,
text,
ctx = stack.ctx,
type = getCSS(element, "listStyleType"),
listBounds;
@ -850,8 +846,6 @@ _html2canvas.Parse = function (images, options) {
if (isElementVisible(el)) {
stack = renderElement(el, stack) || stack;
ctx = stack.ctx;
if (!ignoreElementsRegExp.test(el.nodeName)) {
_html2canvas.Util.Children(el).forEach(function(node) {
if (node.nodeType === 1) {
@ -864,14 +858,7 @@ _html2canvas.Parse = function (images, options) {
}
}
stack = renderElement(element, null);
/*
SVG powered HTML rendering, non-tainted canvas available from FF 11+ onwards
*/
if ( support.svgRendering ) {
(function( body ){
function svgDOMRender(body, stack) {
var img = new Image(),
docWidth = documentWidth(),
docHeight = documentHeight(),
@ -935,19 +922,25 @@ _html2canvas.Parse = function (images, options) {
stack.svgRender = img;
};
})(document.documentElement);
}
function init() {
var stack = renderElement(element, null);
// parse every child element
for (i = 0, children = element.children, childrenLen = children.length; i < childrenLen; i+=1){
parseElement(children[i], stack);
if (support.svgRendering) {
svgDOMRender(document.documentElement, stack);
}
Array.prototype.slice.call(element.children, 0).forEach(function(childElement) {
parseElement(childElement, stack);
});
stack.backgroundColor = getCSS(document.documentElement, "backgroundColor");
return stack;
}
return init();
};
function h2czContext(zindex) {