Move function from selection
This commit is contained in:
parent
4c1183102b
commit
9195b30d6f
Binary file not shown.
|
@ -96,32 +96,15 @@ def _latex_to_svg(code):
|
|||
|
||||
class ZAZLaTex2SVG(unohelper.Base, XJobExecutor):
|
||||
NAME = 'temp'
|
||||
_msg1 = _('Not found')
|
||||
_msg2 = _('Found')
|
||||
|
||||
def __init__(self, ctx):
|
||||
self.ctx = ctx
|
||||
|
||||
@app.catch_exception
|
||||
def trigger(self, args=''):
|
||||
main.ID_EXTENSION = ID_EXTENSION
|
||||
main.run(args, __file__)
|
||||
return
|
||||
|
||||
if args == 'app':
|
||||
self._app()
|
||||
return
|
||||
|
||||
if args == 'dlg':
|
||||
self._dlg()
|
||||
return
|
||||
|
||||
self._from_selection()
|
||||
return
|
||||
|
||||
def _app(self):
|
||||
return
|
||||
|
||||
def _from_selection(self):
|
||||
doc = app.active
|
||||
sel = doc.selection
|
||||
|
|
|
@ -4,17 +4,24 @@ import easymacro as app
|
|||
|
||||
|
||||
ID_EXTENSION = ''
|
||||
|
||||
_ = None
|
||||
|
||||
TEMPLATE = """\documentclass{{article}}
|
||||
\\usepackage[a5paper, landscape]{{geometry}}
|
||||
\\usepackage{{xcolor}}
|
||||
\\usepackage{{amssymb}}
|
||||
\\usepackage{{amsmath}}
|
||||
\pagestyle{{empty}}
|
||||
\\begin{{document}}
|
||||
\\begingroup
|
||||
\Huge
|
||||
|
||||
def from_selection():
|
||||
app.debug('From selection')
|
||||
return
|
||||
\[ {} \]
|
||||
|
||||
|
||||
def from_dialog():
|
||||
app.debug('From dialog')
|
||||
return
|
||||
\endgroup
|
||||
\end{{document}}
|
||||
"""
|
||||
|
||||
|
||||
def validate_app():
|
||||
|
@ -42,6 +49,52 @@ def validate_app():
|
|||
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
|
||||
|
||||
|
||||
def from_selection():
|
||||
doc = app.active
|
||||
sel = doc.selection
|
||||
|
||||
data = sel.value
|
||||
path_svg = _latex_to_svg(data)
|
||||
|
||||
sel = sel.offset()
|
||||
args = {}
|
||||
if doc.type == 'writer':
|
||||
args = {'Width': 5000, 'Height': 2000}
|
||||
image = sel.insert_image(path_svg, args)
|
||||
image.description = data
|
||||
return
|
||||
|
||||
|
||||
def from_dialog():
|
||||
app.debug('From dialog')
|
||||
return
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def run(args, path_locales):
|
||||
global _
|
||||
_ = app.install_locales(path_locales)
|
||||
|
|
Loading…
Reference in New Issue