#316 image export changes

This commit is contained in:
agriyadev5
2021-07-22 13:00:54 +05:30
parent 49f0207b94
commit 785c19a7ff

View File

@@ -778,31 +778,23 @@ export const rasterExport = async function (imgType, quality, exportWindowName,
const { issues, issueCodes } = getIssues(); const { issues, issueCodes } = getIssues();
const svg = svgCanvas.svgCanvasToString(); const svg = svgCanvas.svgCanvasToString();
if (!$id('export_canvas')) { const iframe = document.createElement('iframe');
const canvasEx = document.createElement('CANVAS'); iframe.onload = function() {
canvasEx.id = 'export_canvas'; const iframedoc=iframe.contentDocument||iframe.contentWindow.document;
canvasEx.style.display = 'none'; const ele = svgContext_.getSVGContent();
document.body.appendChild(canvasEx); const cln = ele.cloneNode(true);
} iframedoc.body.appendChild(cln);
const c = $id('export_canvas'); setTimeout(function(){
c.style.width = svgCanvas.contentW + "px"; // eslint-disable-next-line promise/catch-or-return
c.style.height = svgCanvas.contentH + "px"; html2canvas(iframedoc.body, { useCORS: true, allowTaint: true }).then((canvas) => {
const canvg = svgContext_.getcanvg();
const ctx = c.getContext('2d');
const v = canvg.fromString(ctx, svg);
// Render only first frame, ignoring animations.
await v.render();
// Todo: Make async/await utility in place of `toBlob`, so we can remove this constructor
return new Promise((resolve) => { return new Promise((resolve) => {
const dataURLType = type.toLowerCase(); const dataURLType = type.toLowerCase();
const datauri = quality const datauri = quality
? c.toDataURL('image/' + dataURLType, quality) ? canvas.toDataURL('image/' + dataURLType, quality)
: c.toDataURL('image/' + dataURLType); : canvas.toDataURL('image/' + dataURLType);
iframe.parentNode.removeChild(iframe);
let bloburl; let bloburl;
/**
* Called when `bloburl` is available for export.
* @returns {void}
*/
function done() { function done() {
const obj = { const obj = {
datauri, bloburl, svg, issues, issueCodes, type: imgType, datauri, bloburl, svg, issues, issueCodes, type: imgType,
@@ -813,8 +805,8 @@ export const rasterExport = async function (imgType, quality, exportWindowName,
} }
resolve(obj); resolve(obj);
} }
if (c.toBlob) { if (canvas.toBlob) {
c.toBlob((blob) => { canvas.toBlob((blob) => {
bloburl = createObjectURL(blob); bloburl = createObjectURL(blob);
done(); done();
}, mimeType, quality); }, mimeType, quality);
@@ -823,6 +815,10 @@ export const rasterExport = async function (imgType, quality, exportWindowName,
bloburl = dataURLToObjectURL(datauri); bloburl = dataURLToObjectURL(datauri);
done(); done();
}); });
});
}, 1000);
};
document.body.appendChild(iframe);
}; };
/** /**