diff --git a/GUI/configs/xasyconfig.cson b/GUI/configs/xasyconfig.cson index 5f0c1abc1..0f31740a6 100644 --- a/GUI/configs/xasyconfig.cson +++ b/GUI/configs/xasyconfig.cson @@ -1,13 +1,13 @@ # Default Options for xasy -# External editor. $asypath will be replaced by the current file. +# External editor. $asypath will be replaced by the current file. externalEditor: "vi" externalEditorArgs: ["$asypath"] # Path to Asymptote executable asyPath: "asy" -# Overwrites the ASYMPTOTE_DIR Environment variable if set. Otherwise, leaves asymptote to decide. +# Overwrites the ASYMPTOTE_DIR Environment variable if set. Otherwise, leaves asymptote to decide. asyBaseLocation: null # Show Debugging Information @@ -16,21 +16,21 @@ showDebug: false # Default Pen Options defaultPenOptions: "" -# Default Pen Color +# Default Pen Color defaultPenColor: "#000000" -# +# defaultPenWidth: 0.5 useLegacyDrawMode: false enableImmediatePreview: true useDegrees: false groupObjDefault: false -# +# terminalFont: "Courier" terminalFontSize: 9 -# +# defaultShowAxes: true defaultShowGrid: false defaultGridSnap: false @@ -52,6 +52,11 @@ renderDensity: 2 minimumMagnification: 0.01 maximumMagnification: 100 +# SVG options +# If null, use "rsvg-convert". +# otherwise use the converter in the path +svgConverterPath: null + # Debug Mode debugMode: true diff --git a/GUI/xasygui/xasySvg.py b/GUI/xasygui/xasySvg.py index 7261dc5b6..dfefa0909 100644 --- a/GUI/xasygui/xasySvg.py +++ b/GUI/xasygui/xasySvg.py @@ -1,22 +1,40 @@ #!/usr/bin/env python3 +import platform import PyQt5.QtGui as QtGui import PyQt5.QtWidgets as QtWidgets -import io import subprocess import sys +from xasygui import xasyOptions as xo -class SvgObject(): + +class SvgObject: def __init__(self, file: str): - self.file=file + self.file = file + + def _create_call_arguments(self, dpi: int): + settings = xo.BasicConfigs.defaultOpt + return [ + settings.get("svgConverterPath") or "rsvg-convert", + f"--dpi-x={dpi}", + f"--dpi-y={dpi}", + "--format=png", + self.file, + ] - def render(self, dpi:int) -> QtGui.QImage: + def render(self, dpi: int) -> QtGui.QImage: + callArgs = self._create_call_arguments(dpi) try: - rawDataProc = subprocess.Popen(['rsvg-convert', '--dpi-x', str(dpi), - '--dpi-y', str(dpi), self.file], - stdout=subprocess.PIPE) - except: - QtWidgets.QMessageBox.about(None,'rsvg-convert missing','Please install rsvg-convert version >= 2.40 in your path.') + rawDataProc = subprocess.run( + callArgs, + stdout=subprocess.PIPE, + ) + except OSError: + QtWidgets.QMessageBox.about( + None, + "SVG Converter missing", + "Please ensure svg converter is available.", + ) sys.exit(-1) - return QtGui.QImage.fromData(rawDataProc.stdout.read(), 'PNG') + return QtGui.QImage.fromData(rawDataProc.stdout, "PNG")