- Linting (ESLint): Apply coding standards
- Breaking change (minor): Change export filename to check `exportWindowName` and change default from `download.pdf` to `svg.pdf` to distinguish from other downloads - Enhancement: Restore old dataURI functionality for non-Chrome browsersmaster
parent
1e9b72ef53
commit
b0bad24645
|
@ -181,17 +181,17 @@ const svgElementToPdf = function (element, pdf, options) {
|
|||
|
||||
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);
|
||||
try {
|
||||
box = node.getBBox(); // Firefox on MacOS will raise error here
|
||||
} catch (err) {
|
||||
// copy and append to body so that getBBox is available
|
||||
const nodeCopy = node.cloneNode(true);
|
||||
const svg = node.ownerSVGElement.cloneNode(false);
|
||||
svg.appendChild(nodeCopy);
|
||||
document.body.appendChild(svg);
|
||||
try{
|
||||
try {
|
||||
box = nodeCopy.getBBox();
|
||||
}catch(err){
|
||||
} catch (err) {
|
||||
box = {width: 0};
|
||||
}
|
||||
document.body.removeChild(svg);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import './touch.js';
|
||||
import {NS} from './namespaces.js';
|
||||
import {isWebkit, isGecko, isIE, isMac, isTouch} from './browser.js';
|
||||
import {isWebkit, isChrome, isGecko, isIE, isMac, isTouch} from './browser.js';
|
||||
import * as Utils from './utilities.js';
|
||||
import {getTypeMap, convertUnit, isValidUnit} from './units.js';
|
||||
import {
|
||||
|
@ -3382,6 +3382,18 @@ editor.init = function () {
|
|||
svgCanvas.bind('saved', saveHandler);
|
||||
svgCanvas.bind('exported', exportHandler);
|
||||
svgCanvas.bind('exportedPDF', function (win, data) {
|
||||
if (!data.output) { // Ignore Chrome
|
||||
return;
|
||||
}
|
||||
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);
|
||||
|
@ -4199,7 +4211,10 @@ editor.init = function () {
|
|||
exportWindow = window.open(popURL, exportWindowName);
|
||||
}
|
||||
if (imgType === 'PDF') {
|
||||
svgCanvas.exportPDF(exportWindowName, 'save');
|
||||
if (!customExportPDF && !isChrome()) {
|
||||
openExportWindow();
|
||||
}
|
||||
svgCanvas.exportPDF(exportWindowName, isChrome() ? 'save' : undefined);
|
||||
} else {
|
||||
if (!customExportImage) {
|
||||
openExportWindow();
|
||||
|
|
|
@ -3956,7 +3956,7 @@ this.rasterExport = function (imgType, quality, exportWindowName, cb) {
|
|||
* Generates a PDF based on the current image, then calls "exportedPDF" with
|
||||
* an object including the string, the data URL, and any issues found
|
||||
* @function module:svgcanvas.SvgCanvas#exportPDF
|
||||
* @param {string} exportWindowName
|
||||
* @param {string} exportWindowName Will also be used for the download file name here
|
||||
* @param {external:jsPDF.OutputType} [outputType="dataurlstring"]
|
||||
* @param {module:svgcanvas.PDFExportedCallback} cb
|
||||
* @fires module:svgcanvas.SvgCanvas#event:exportedPDF
|
||||
|
@ -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, outputType === 'save' ? 'Download.pdf' : void 0);
|
||||
obj.output = doc.output(outputType, outputType === 'save' ? (exportWindowName || 'svg.pdf') : undefined);
|
||||
if (cb) {
|
||||
cb(obj);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue