Skip to content

Commit

Permalink
XASY: Add support for custom svg converter path.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamievlin committed Jul 2, 2024
1 parent 03b5e65 commit 6b2f0cb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
17 changes: 11 additions & 6 deletions GUI/configs/xasyconfig.cson
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
38 changes: 28 additions & 10 deletions GUI/xasygui/xasySvg.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 6b2f0cb

Please sign in to comment.