mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
refactored parsing init
This commit is contained in:
parent
d93e36d768
commit
0dd2c24ab4
37
src/Parse.js
37
src/Parse.js
@ -8,11 +8,6 @@ _html2canvas.Parse = function (images, options) {
|
|||||||
support = _html2canvas.Util.Support(options, doc),
|
support = _html2canvas.Util.Support(options, doc),
|
||||||
ignoreElementsRegExp = new RegExp("(" + options.ignoreElements + ")"),
|
ignoreElementsRegExp = new RegExp("(" + options.ignoreElements + ")"),
|
||||||
body = doc.body,
|
body = doc.body,
|
||||||
stack,
|
|
||||||
ctx,
|
|
||||||
i,
|
|
||||||
children,
|
|
||||||
childrenLen,
|
|
||||||
getCSS = _html2canvas.Util.getCSS;
|
getCSS = _html2canvas.Util.getCSS;
|
||||||
|
|
||||||
images = images || {};
|
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) {
|
switch(text_decoration) {
|
||||||
case "underline":
|
case "underline":
|
||||||
// Draws a line at the baseline of the font
|
// 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));
|
var bounds = getTextBounds(state, text, textDecoration, (index < textList.length - 1));
|
||||||
if (bounds) {
|
if (bounds) {
|
||||||
drawText(text, bounds.left, bounds.bottom, ctx);
|
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) {
|
function renderListItem(element, stack, elBounds) {
|
||||||
var x,
|
var x,
|
||||||
text,
|
text,
|
||||||
|
ctx = stack.ctx,
|
||||||
type = getCSS(element, "listStyleType"),
|
type = getCSS(element, "listStyleType"),
|
||||||
listBounds;
|
listBounds;
|
||||||
|
|
||||||
@ -850,8 +846,6 @@ _html2canvas.Parse = function (images, options) {
|
|||||||
|
|
||||||
if (isElementVisible(el)) {
|
if (isElementVisible(el)) {
|
||||||
stack = renderElement(el, stack) || stack;
|
stack = renderElement(el, stack) || stack;
|
||||||
ctx = stack.ctx;
|
|
||||||
|
|
||||||
if (!ignoreElementsRegExp.test(el.nodeName)) {
|
if (!ignoreElementsRegExp.test(el.nodeName)) {
|
||||||
_html2canvas.Util.Children(el).forEach(function(node) {
|
_html2canvas.Util.Children(el).forEach(function(node) {
|
||||||
if (node.nodeType === 1) {
|
if (node.nodeType === 1) {
|
||||||
@ -864,14 +858,7 @@ _html2canvas.Parse = function (images, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stack = renderElement(element, null);
|
function svgDOMRender(body, stack) {
|
||||||
|
|
||||||
/*
|
|
||||||
SVG powered HTML rendering, non-tainted canvas available from FF 11+ onwards
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ( support.svgRendering ) {
|
|
||||||
(function( body ){
|
|
||||||
var img = new Image(),
|
var img = new Image(),
|
||||||
docWidth = documentWidth(),
|
docWidth = documentWidth(),
|
||||||
docHeight = documentHeight(),
|
docHeight = documentHeight(),
|
||||||
@ -935,19 +922,25 @@ _html2canvas.Parse = function (images, options) {
|
|||||||
stack.svgRender = img;
|
stack.svgRender = img;
|
||||||
};
|
};
|
||||||
|
|
||||||
})(document.documentElement);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
var stack = renderElement(element, null);
|
||||||
|
|
||||||
// parse every child element
|
if (support.svgRendering) {
|
||||||
for (i = 0, children = element.children, childrenLen = children.length; i < childrenLen; i+=1){
|
svgDOMRender(document.documentElement, stack);
|
||||||
parseElement(children[i], stack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Array.prototype.slice.call(element.children, 0).forEach(function(childElement) {
|
||||||
|
parseElement(childElement, stack);
|
||||||
|
});
|
||||||
|
|
||||||
stack.backgroundColor = getCSS(document.documentElement, "backgroundColor");
|
stack.backgroundColor = getCSS(document.documentElement, "backgroundColor");
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
return init();
|
||||||
};
|
};
|
||||||
|
|
||||||
function h2czContext(zindex) {
|
function h2czContext(zindex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user