refactored background color rendering

This commit is contained in:
Niklas von Hertzen 2012-12-30 01:11:05 +02:00
parent 5faa45847e
commit bb1cd21367

View File

@ -718,6 +718,17 @@ _html2canvas.Parse = function (images, options) {
} }
} }
function renderBackgroundColor(ctx, backgroundBounds, bgcolor) {
renderRect(
ctx,
backgroundBounds.left,
backgroundBounds.top,
backgroundBounds.width,
backgroundBounds.height,
bgcolor
);
}
function renderBackground(el,bounds,ctx){ function renderBackground(el,bounds,ctx){
// TODO add support for multi background-images // TODO add support for multi background-images
var background_image = getCSS(el, "backgroundImage"), var background_image = getCSS(el, "backgroundImage"),
@ -859,10 +870,6 @@ _html2canvas.Parse = function (images, options) {
function renderElement(el, parentStack){ function renderElement(el, parentStack){
var bounds = _html2canvas.Util.Bounds(el), var bounds = _html2canvas.Util.Bounds(el),
x = bounds.left,
y = bounds.top,
w = bounds.width,
h = bounds.height,
image, image,
bgcolor = getCSS(el, "backgroundColor"), bgcolor = getCSS(el, "backgroundColor"),
zindex, zindex,
@ -870,12 +877,7 @@ _html2canvas.Parse = function (images, options) {
stackLength, stackLength,
borders, borders,
ctx, ctx,
backgroundBounds, backgroundBounds;
imgSrc,
paddingLeft,
paddingTop,
paddingRight,
paddingBottom;
stack = createStack(el, parentStack, bounds); stack = createStack(el, parentStack, bounds);
zindex = stack.zIndex; zindex = stack.zIndex;
@ -903,26 +905,16 @@ _html2canvas.Parse = function (images, options) {
backgroundBounds = getBackgroundBounds(borders, bounds, stack.clip); backgroundBounds = getBackgroundBounds(borders, bounds, stack.clip);
if (backgroundBounds.height > 0 && backgroundBounds.width > 0){ if (backgroundBounds.height > 0 && backgroundBounds.width > 0){
renderRect( renderBackgroundColor(ctx, backgroundBounds, bgcolor);
ctx,
backgroundBounds.left,
backgroundBounds.top,
backgroundBounds.width,
backgroundBounds.height,
bgcolor
);
renderBackground(el, backgroundBounds, ctx); renderBackground(el, backgroundBounds, ctx);
} }
switch(el.nodeName){ switch(el.nodeName){
case "IMG": case "IMG":
imgSrc = el.getAttribute('src'); if ((image = loadImage(el.getAttribute('src')))) {
image = loadImage(el.getAttribute('src'));
if (image) {
renderImage(ctx, el, image, bounds, borders); renderImage(ctx, el, image, bounds, borders);
} else { } else {
h2clog("html2canvas: Error loading <img>:" + imgSrc); h2clog("html2canvas: Error loading <img>:" + el.getAttribute('src'));
} }
break; break;
case "INPUT": case "INPUT":