diff --git a/README.md b/README.md index c755fb2..831e26e 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ sudo apt install texlive-extra-utils sudo apt install pdf2svg ``` + * For OSx ``` diff --git a/files/ZAZLaTex2SVG_v0.1.0.oxt b/files/ZAZLaTex2SVG_v0.1.0.oxt index bfda184..1fb7e3d 100644 Binary files a/files/ZAZLaTex2SVG_v0.1.0.oxt and b/files/ZAZLaTex2SVG_v0.1.0.oxt differ diff --git a/source/ZAZLaTex2SVG.py b/source/ZAZLaTex2SVG.py index 5a49d49..5a26e6b 100644 --- a/source/ZAZLaTex2SVG.py +++ b/source/ZAZLaTex2SVG.py @@ -19,9 +19,12 @@ TEMPLATE = """\documentclass{{article}} \\usepackage{{amsmath}} \pagestyle{{empty}} \\begin{{document}} +\\begingroup +\huge \[ {} \] +\endgroup \end{{document}} """ # ~ TEMPLATE = """\documentclass{{standalone}} @@ -51,19 +54,22 @@ class Controllers(object): def __init__(self, dlg): self.d = dlg + self._path = '' def cmd_close_action(self, event): self.d.close() return + @app.catch_exception def cmd_preview_action(self, event): - data = self.d.text.value - if not data: + code = self.d.text.value + if not code: msg = _('Write some code') app.errorbox(msg) return - app.msgbox(data) + self._path = _latex_to_svg(code) + self.d.image.value = self._path return def cmd_insert_action(self, event): @@ -77,10 +83,33 @@ class Controllers(object): if not app.question(msg): return + app.selection.insert_image(self._path, {}) self.d.close() return +def _latex_to_svg(code): + NAME = 'temp' + data = TEMPLATE.format(code) + dt = app.paths.dir_tmp() + path_tex = app._P.join(dt.name, f'{NAME}.tex') + path_pdf = app._P.join(dt.name, f'{NAME}.pdf') + path_svg = app._P.join(app._P.temp_dir, f'{NAME}.svg') + + app.paths.save(path_tex, data) + cmd = f'pdflatex --interaction=batchmode -output-directory="{dt.name}" "{path_tex}"' + app.run(cmd) + cmd = f'pdfcrop "{path_pdf}" "{path_pdf}"' + app.run(cmd) + cmd = f'pdf2svg "{path_pdf}" "{path_svg}"' + app.run(cmd) + + if not app.paths.exists(path_svg): + path_svg = '' + dt.cleanup() + return path_svg + + class ZAZLaTex2SVG(unohelper.Base, XJobExecutor): NAME = 'temp' _msg1 = _('Not found') @@ -122,7 +151,6 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor): app.msgbox(msg) return - @app.catch_exception def _dlg(self): dlg = self._create_dialog() dlg.open() @@ -144,7 +172,7 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor): 'Name': 'lbl_code', 'Label': _('Latex code'), 'Width': 70, - 'Height': 15, + 'Height': 10, 'X': 10, 'Y': 5, 'VerticalAlign': 1, @@ -172,6 +200,14 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor): } dlg.add_control(args) + args = { + 'Type': 'Image', + 'Name': 'image', + 'Width': 250, + 'Height': 100, + } + dlg.add_control(args) + args = { 'Type': 'Button', 'Name': 'cmd_insert', @@ -195,8 +231,9 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor): dlg.text.move(dlg.lbl_code) dlg.cmd_preview.move(dlg.text, center=True) - dlg.cmd_insert.move(dlg.cmd_preview) - dlg.cmd_close.move(dlg.cmd_preview) + dlg.image.move(dlg.cmd_preview, center=True) + dlg.cmd_insert.move(dlg.image) + dlg.cmd_close.move(dlg.image) controls = (dlg.cmd_insert, dlg.cmd_close) dlg.center(controls) diff --git a/source/pythonpath/easymacro2.py b/source/pythonpath/easymacro2.py index 580bca5..52d5dad 100644 --- a/source/pythonpath/easymacro2.py +++ b/source/pythonpath/easymacro2.py @@ -2633,6 +2633,24 @@ class UnoText(UnoBaseObject): self.model.Text = value +class UnoImage(UnoBaseObject): + + def __init__(self, obj): + super().__init__(obj) + + @property + def type(self): + return 'image' + + @property + def value(self): + return self.m.ImageURL + @value.setter + def value(self, value): + self.m.ImageURL = None + self.m.ImageURL = _P.to_url(value) + + UNO_CLASSES = { 'label': UnoLabel, 'link': UnoLabelLink, @@ -2640,6 +2658,7 @@ UNO_CLASSES = { 'radio': UnoRadio, 'check': UnoCheck, 'text': UnoText, + 'image': UnoImage, } @@ -2652,13 +2671,13 @@ class LODialog(object): 'radio': 'com.sun.star.awt.UnoControlRadioButtonModel', 'check': 'com.sun.star.awt.UnoControlCheckBoxModel', 'text': 'com.sun.star.awt.UnoControlEditModel', + 'image': 'com.sun.star.awt.UnoControlImageControlModel', # ~ 'grid': 'com.sun.star.awt.grid.UnoControlGridModel', # ~ 'groupbox': 'com.sun.star.awt.UnoControlGroupBoxModel', # ~ 'listbox': 'com.sun.star.awt.UnoControlListBoxModel', # ~ 'roadmap': 'com.sun.star.awt.UnoControlRoadmapModel', # ~ 'tree': 'com.sun.star.awt.tree.TreeControlModel', # ~ 'groupbox': 'com.sun.star.awt.UnoControlGroupBoxModel', - # ~ 'image': 'com.sun.star.awt.UnoControlImageControlModel', # ~ 'pages': 'com.sun.star.awt.UnoMultiPageModel', }