parent
b370f4a207
commit
4857561b71
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)
|
||||
: 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!!
|
||||
let x, y, xOffset = 0;
|
||||
if (node.hasAttribute('text-anchor')) {
|
||||
switch (node.getAttribute('text-anchor')) {
|
||||
case 'end': xOffset = box.width; break;
|
||||
case 'middle': xOffset = box.width / 2; break;
|
||||
case 'end': xOffset = getWidth(node); break;
|
||||
case 'middle': xOffset = getWidth(node) / 2; break;
|
||||
case 'start': break;
|
||||
case 'default': node.setAttribute('text-anchor', 'start'); break;
|
||||
}
|
||||
|
|
|
@ -3382,15 +3382,6 @@ editor.init = function () {
|
|||
svgCanvas.bind('saved', saveHandler);
|
||||
svgCanvas.bind('exported', exportHandler);
|
||||
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('zoomDone', zoomDone);
|
||||
|
@ -4208,10 +4199,7 @@ editor.init = function () {
|
|||
exportWindow = window.open(popURL, exportWindowName);
|
||||
}
|
||||
if (imgType === 'PDF') {
|
||||
if (!customExportPDF) {
|
||||
openExportWindow();
|
||||
}
|
||||
svgCanvas.exportPDF(exportWindowName);
|
||||
svgCanvas.exportPDF(exportWindowName, 'save');
|
||||
} else {
|
||||
if (!customExportImage) {
|
||||
openExportWindow();
|
||||
|
|
|
@ -4015,7 +4015,7 @@ this.exportPDF = function (exportWindowName, outputType, cb) {
|
|||
// opposed to opening a new tab
|
||||
outputType = outputType || 'dataurlstring';
|
||||
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) {
|
||||
cb(obj);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue