parent
4b22c248e4
commit
fc1f36714e
File diff suppressed because one or more lines are too long
|
@ -179,13 +179,31 @@ const svgElementToPdf = function (element, pdf, options) {
|
||||||
? parseInt(node.getAttribute('font-size'), 10)
|
? parseInt(node.getAttribute('font-size'), 10)
|
||||||
: 16;
|
: 16;
|
||||||
|
|
||||||
const box = node.getBBox();
|
const getWidth = (node) => {
|
||||||
|
let box;
|
||||||
|
try{
|
||||||
|
box = node.getBBox(); //Firefox on MacOS will raise error here
|
||||||
|
}catch(err){
|
||||||
|
//copy and append to body so that getBBox is available
|
||||||
|
let nodeCopy = node.cloneNode(true);
|
||||||
|
let svg = node.ownerSVGElement.cloneNode(false);
|
||||||
|
svg.appendChild(nodeCopy);
|
||||||
|
document.body.appendChild(svg);
|
||||||
|
try{
|
||||||
|
box = nodeCopy.getBBox();
|
||||||
|
}catch(err){
|
||||||
|
box = {width: 0};
|
||||||
|
}
|
||||||
|
document.body.removeChild(svg);
|
||||||
|
}
|
||||||
|
return box.width;
|
||||||
|
};
|
||||||
// FIXME: use more accurate positioning!!
|
// FIXME: use more accurate positioning!!
|
||||||
let x, y, xOffset = 0;
|
let x, y, xOffset = 0;
|
||||||
if (node.hasAttribute('text-anchor')) {
|
if (node.hasAttribute('text-anchor')) {
|
||||||
switch (node.getAttribute('text-anchor')) {
|
switch (node.getAttribute('text-anchor')) {
|
||||||
case 'end': xOffset = box.width; break;
|
case 'end': xOffset = getWidth(node); break;
|
||||||
case 'middle': xOffset = box.width / 2; break;
|
case 'middle': xOffset = getWidth(node) / 2; break;
|
||||||
case 'start': break;
|
case 'start': break;
|
||||||
case 'default': node.setAttribute('text-anchor', 'start'); break;
|
case 'default': node.setAttribute('text-anchor', 'start'); break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3382,15 +3382,6 @@ editor.init = function () {
|
||||||
svgCanvas.bind('saved', saveHandler);
|
svgCanvas.bind('saved', saveHandler);
|
||||||
svgCanvas.bind('exported', exportHandler);
|
svgCanvas.bind('exported', exportHandler);
|
||||||
svgCanvas.bind('exportedPDF', function (win, data) {
|
svgCanvas.bind('exportedPDF', function (win, data) {
|
||||||
const {exportWindowName} = data;
|
|
||||||
if (exportWindowName) {
|
|
||||||
exportWindow = window.open('', exportWindowName); // A hack to get the window via JSON-able name without opening a new one
|
|
||||||
}
|
|
||||||
if (!exportWindow || exportWindow.closed) {
|
|
||||||
$.alert(uiStrings.notification.popupWindowBlocked);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
exportWindow.location.href = data.output;
|
|
||||||
});
|
});
|
||||||
svgCanvas.bind('zoomed', zoomChanged);
|
svgCanvas.bind('zoomed', zoomChanged);
|
||||||
svgCanvas.bind('zoomDone', zoomDone);
|
svgCanvas.bind('zoomDone', zoomDone);
|
||||||
|
@ -4208,10 +4199,7 @@ editor.init = function () {
|
||||||
exportWindow = window.open(popURL, exportWindowName);
|
exportWindow = window.open(popURL, exportWindowName);
|
||||||
}
|
}
|
||||||
if (imgType === 'PDF') {
|
if (imgType === 'PDF') {
|
||||||
if (!customExportPDF) {
|
svgCanvas.exportPDF(exportWindowName, 'save');
|
||||||
openExportWindow();
|
|
||||||
}
|
|
||||||
svgCanvas.exportPDF(exportWindowName);
|
|
||||||
} else {
|
} else {
|
||||||
if (!customExportImage) {
|
if (!customExportImage) {
|
||||||
openExportWindow();
|
openExportWindow();
|
||||||
|
|
|
@ -4015,7 +4015,7 @@ this.exportPDF = function (exportWindowName, outputType, cb) {
|
||||||
// opposed to opening a new tab
|
// opposed to opening a new tab
|
||||||
outputType = outputType || 'dataurlstring';
|
outputType = outputType || 'dataurlstring';
|
||||||
const obj = {svg, issues, issueCodes, exportWindowName, outputType};
|
const obj = {svg, issues, issueCodes, exportWindowName, outputType};
|
||||||
obj.output = doc.output(outputType);
|
obj.output = doc.output(outputType, outputType === 'save' ? 'Download.pdf' : void 0);
|
||||||
if (cb) {
|
if (cb) {
|
||||||
cb(obj);
|
cb(obj);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue