From f8f2d4c21c420920ebd88ba0e3fabc9012fd51b4 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Sat, 13 May 2023 21:18:59 +0200 Subject: [PATCH] Draft: Skip SVG import DPI dialog if a unit is specified in the file - fixes #6653 (#9533) --- src/Mod/Draft/importSVG.py | 59 ++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/src/Mod/Draft/importSVG.py b/src/Mod/Draft/importSVG.py index aeb6ef6ed6..f2f64d2662 100644 --- a/src/Mod/Draft/importSVG.py +++ b/src/Mod/Draft/importSVG.py @@ -741,32 +741,41 @@ class svgHandler(xml.sax.ContentHandler): else: self.svgdpi = 96.0 if 'inkscape:version' not in data: - _inf = ("This SVG file does not appear to have been produced " - "by Inkscape. If it does not contain absolute units " - "then a DPI setting will be used.") - _qst = ("Do you wish to use 96 dpi? Choosing 'No' " - "will use the older standard 90 dpi.") - if FreeCAD.GuiUp: - msgBox = QtGui.QMessageBox() - msgBox.setText(translate("ImportSVG", _inf)) - msgBox.setInformativeText(translate("ImportSVG", _qst)) - msgBox.setStandardButtons(QtGui.QMessageBox.Yes - | QtGui.QMessageBox.No) - msgBox.setDefaultButton(QtGui.QMessageBox.No) - ret = msgBox.exec_() - if ret == QtGui.QMessageBox.Yes: - self.svgdpi = 96.0 - else: - self.svgdpi = 90.0 - if ret: - _msg(translate("ImportSVG", _inf)) - _msg(translate("ImportSVG", _qst)) - _msg("*** User specified {} " - "dpi ***".format(self.svgdpi)) - else: + # exact scaling is calculated later below. Here we just want + # to skip the DPI dialog if a unit is specified in the viewbox + if "width" in data and "mm" in attrs.getValue('width'): self.svgdpi = 96.0 - _msg(_inf) - _msg("*** Assuming {} dpi ***".format(self.svgdpi)) + elif "width" in data and "in" in attrs.getValue('width'): + self.svgdpi = 96.0 + elif "width" in data and "cm" in attrs.getValue('width'): + self.svgdpi = 96.0 + else: + _inf = ("This SVG file does not appear to have been produced " + "by Inkscape. If it does not contain absolute units " + "then a DPI setting will be used.") + _qst = ("Do you wish to use 96 dpi? Choosing 'No' " + "will use the older standard 90 dpi.") + if FreeCAD.GuiUp: + msgBox = QtGui.QMessageBox() + msgBox.setText(translate("ImportSVG", _inf)) + msgBox.setInformativeText(translate("ImportSVG", _qst)) + msgBox.setStandardButtons(QtGui.QMessageBox.Yes + | QtGui.QMessageBox.No) + msgBox.setDefaultButton(QtGui.QMessageBox.No) + ret = msgBox.exec_() + if ret == QtGui.QMessageBox.Yes: + self.svgdpi = 96.0 + else: + self.svgdpi = 90.0 + if ret: + _msg(translate("ImportSVG", _inf)) + _msg(translate("ImportSVG", _qst)) + _msg("*** User specified {} " + "dpi ***".format(self.svgdpi)) + else: + self.svgdpi = 96.0 + _msg(_inf) + _msg("*** Assuming {} dpi ***".format(self.svgdpi)) if self.svgdpi == 1.0: _wrn("This SVG file (" + inks_doc_name + ") " "has an unrecognised format which means "