Commit e9ddf87a authored by techird's avatar techird

fix background export issue

parent 9f991aea
if (!kity.Browser.ie) { if (!kity.Browser.ie) {
KityMinder.registerProtocal('png', function() { KityMinder.registerProtocal('png', function() {
function loadImage(url, callback) { function loadImage(url, callback) {
...@@ -15,8 +14,9 @@ if (!kity.Browser.ie) { ...@@ -15,8 +14,9 @@ if (!kity.Browser.ie) {
svgXml, svgXml,
$svg, $svg,
bgDeclare = getComputedStyle(domContainer).backgroundImage, bgDeclare = km.getStyle('background').toString(),
bgUrl = /url\((.+)\)$/.exec(bgDeclare)[1], bgUrl = /url\((.+)\)/.exec(bgDeclare),
bgColor = kity.Color.parse(bgDeclare),
renderContainer = km.getRenderContainer(), renderContainer = km.getRenderContainer(),
renderBox = renderContainer.getRenderBox(), renderBox = renderContainer.getRenderBox(),
...@@ -29,7 +29,6 @@ if (!kity.Browser.ie) { ...@@ -29,7 +29,6 @@ if (!kity.Browser.ie) {
ctx = canvas.getContext('2d'), ctx = canvas.getContext('2d'),
blob, DomURL, url, img, finishCallback; blob, DomURL, url, img, finishCallback;
bgUrl = bgUrl.replace(/"/g, '');
renderContainer.translate(-renderBox.x, -renderBox.y); renderContainer.translate(-renderBox.x, -renderBox.y);
svgXml = km.getPaper().container.innerHTML; svgXml = km.getPaper().container.innerHTML;
...@@ -60,10 +59,10 @@ if (!kity.Browser.ie) { ...@@ -60,10 +59,10 @@ if (!kity.Browser.ie) {
canvas.width = width + padding * 2; canvas.width = width + padding * 2;
canvas.height = height + padding * 2; canvas.height = height + padding * 2;
function fillBackground(ctx, image, width, height) { function fillBackground(ctx, style) {
ctx.save(); ctx.save();
ctx.fillStyle = ctx.createPattern(image, "repeat"); ctx.fillStyle = style;
ctx.fillRect(0, 0, width, height); ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.restore(); ctx.restore();
} }
...@@ -75,11 +74,11 @@ if (!kity.Browser.ie) { ...@@ -75,11 +74,11 @@ if (!kity.Browser.ie) {
var url = canvas.toDataURL('png'); var url = canvas.toDataURL('png');
return url; return url;
} }
loadImage(url, function() {
var svgImage = this; function drawSVG() {
loadImage(bgUrl, function() { loadImage(url, function() {
var svgImage = this;
var downloadUrl; var downloadUrl;
fillBackground(ctx, this, canvas.width, canvas.height);
drawImage(ctx, svgImage, padding, padding); drawImage(ctx, svgImage, padding, padding);
DomURL.revokeObjectURL(url); DomURL.revokeObjectURL(url);
downloadUrl = generateDataUrl(canvas); downloadUrl = generateDataUrl(canvas);
...@@ -87,7 +86,17 @@ if (!kity.Browser.ie) { ...@@ -87,7 +86,17 @@ if (!kity.Browser.ie) {
finishCallback(downloadUrl); finishCallback(downloadUrl);
} }
}); });
}); }
if (bgUrl) {
loadImage(bgUrl[1], function() {
fillBackground(ctx, ctx.createPattern(this, 'repeat'));
drawSVG();
});
} else {
fillBackground(ctx, bgColor.toString());
drawSVG();
}
return { return {
then: function(callback) { then: function(callback) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment