Replace equations
This commit is contained in:
parent
412ad7056f
commit
2df7ed5d0a
Binary file not shown.
|
@ -20,7 +20,7 @@ TEMPLATE = """\documentclass{{article}}
|
|||
\pagestyle{{empty}}
|
||||
\\begin{{document}}
|
||||
\\begingroup
|
||||
\huge
|
||||
\Huge
|
||||
|
||||
\[ {} \]
|
||||
|
||||
|
@ -60,7 +60,6 @@ class Controllers(object):
|
|||
self.d.close()
|
||||
return
|
||||
|
||||
@app.catch_exception
|
||||
def cmd_preview_action(self, event):
|
||||
code = self.d.text.value
|
||||
if not code:
|
||||
|
@ -69,21 +68,23 @@ class Controllers(object):
|
|||
return
|
||||
|
||||
self._path = _latex_to_svg(code)
|
||||
self.d.image.value = self._path
|
||||
self.d.image.url = self._path
|
||||
return
|
||||
|
||||
def cmd_insert_action(self, event):
|
||||
data = self.d.text.value
|
||||
if not data:
|
||||
msg = _('Write some code')
|
||||
if not self._path:
|
||||
msg = _('First, generate preview')
|
||||
app.errorbox(msg)
|
||||
return
|
||||
|
||||
msg = _('You shure insert this equation')
|
||||
if not app.question(msg):
|
||||
return
|
||||
sel = app.selection
|
||||
if hasattr(sel, 'anchor'):
|
||||
anchor = sel.anchor
|
||||
anchor.dp.remove(sel)
|
||||
sel = anchor
|
||||
|
||||
app.selection.insert_image(self._path, {})
|
||||
image = sel.insert_image(self._path, {})
|
||||
image.description = self.d.text.value
|
||||
self.d.close()
|
||||
return
|
||||
|
||||
|
@ -153,6 +154,9 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor):
|
|||
|
||||
def _dlg(self):
|
||||
dlg = self._create_dialog()
|
||||
sel = app.selection
|
||||
if hasattr(sel, 'description'):
|
||||
dlg.text.value = sel.description
|
||||
dlg.open()
|
||||
return
|
||||
|
||||
|
@ -244,30 +248,16 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor):
|
|||
sel = doc.selection
|
||||
if doc.type == 'writer':
|
||||
sel = sel[0]
|
||||
|
||||
data = sel.value
|
||||
|
||||
data = TEMPLATE.format(data)
|
||||
dt = app.paths.dir_tmp()
|
||||
path_tex = app._P.join(dt.name, f'{self.NAME}.tex')
|
||||
path_pdf = app._P.join(dt.name, f'{self.NAME}.pdf')
|
||||
path_svg = app._P.join(dt.name, f'{self.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)
|
||||
# ~ app.paths.copy(path_pdf, '/home/mau')
|
||||
cmd = f'pdf2svg "{path_pdf}" "{path_svg}"'
|
||||
app.run(cmd)
|
||||
path_svg = _latex_to_svg(data)
|
||||
|
||||
sel = sel.offset()
|
||||
args = {}
|
||||
if doc.type == 'writer':
|
||||
args = {'Width': 5000, 'Height': 2000}
|
||||
sel.insert_image(path_svg, args)
|
||||
|
||||
dt.cleanup()
|
||||
image = sel.insert_image(path_svg, args)
|
||||
image.description = data
|
||||
return
|
||||
|
||||
|
||||
|
|
|
@ -117,6 +117,10 @@ OBJ_RANGE = 'ScCellRangeObj'
|
|||
OBJ_RANGES = 'ScCellRangesObj'
|
||||
TYPE_RANGES = (OBJ_CELL, OBJ_RANGE, OBJ_RANGES)
|
||||
|
||||
OBJ_SHAPES = 'com.sun.star.drawing.SvxShapeCollection'
|
||||
OBJ_SHAPE = 'com.sun.star.comp.sc.ScShapeObj'
|
||||
|
||||
|
||||
# ~ from com.sun.star.sheet.FilterOperator import EMPTY, NO_EMPTY, EQUAL, NOT_EQUAL
|
||||
class FilterOperator(IntEnum):
|
||||
EMPTY = 0
|
||||
|
@ -841,6 +845,12 @@ class LOCalc(LODocument):
|
|||
sel = self.obj.CurrentSelection
|
||||
if sel.ImplementationName in TYPE_RANGES:
|
||||
sel = LOCalcRange(sel)
|
||||
elif sel.ImplementationName == OBJ_SHAPES:
|
||||
if len(sel) == 1:
|
||||
sel = sel[0]
|
||||
sel = LODrawPage(sel.Parent)[sel.Name]
|
||||
else:
|
||||
debug(sel.ImplementationName)
|
||||
return sel
|
||||
|
||||
@property
|
||||
|
@ -1171,6 +1181,10 @@ class LOCalcRange(object):
|
|||
def is_none(self):
|
||||
return self.obj is None
|
||||
|
||||
@property
|
||||
def dp(self):
|
||||
return self.sheet.dp
|
||||
|
||||
@property
|
||||
def sheet(self):
|
||||
return LOCalcSheet(self.obj.Spreadsheet)
|
||||
|
@ -1591,6 +1605,10 @@ class LOShape(LOBaseObject):
|
|||
self._index = index
|
||||
super().__init__(obj)
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
return 'shape'
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.obj.Name or f'shape{self.index}'
|
||||
|
@ -1610,8 +1628,23 @@ class LOShape(LOBaseObject):
|
|||
self.obj.String = value
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
return self.obj.Description
|
||||
@description.setter
|
||||
def description(self, value):
|
||||
self.obj.Description = value
|
||||
|
||||
@property
|
||||
def cell(self):
|
||||
return self.anchor
|
||||
@property
|
||||
def anchor(self):
|
||||
return self.obj.Anchor
|
||||
obj = self.obj.Anchor
|
||||
if obj.ImplementationName == OBJ_CELL:
|
||||
obj = LOCalcRange(obj)
|
||||
else:
|
||||
debug('Anchor', obj.ImplementationName)
|
||||
return obj
|
||||
@anchor.setter
|
||||
def anchor(self, value):
|
||||
if hasattr(value, 'obj'):
|
||||
|
@ -1684,6 +1717,11 @@ class LODrawPage(LOBaseObject):
|
|||
self.obj.add(shape)
|
||||
return LOShape(self.obj[index], index)
|
||||
|
||||
def remove(self, shape):
|
||||
if hasattr(shape, 'obj'):
|
||||
shape = shape.obj
|
||||
return self.obj.remove(shape)
|
||||
|
||||
def insert_image(self, path, args={}):
|
||||
w = args.get('Width', 3000)
|
||||
h = args.get('Height', 3000)
|
||||
|
@ -2644,9 +2682,16 @@ class UnoImage(UnoBaseObject):
|
|||
|
||||
@property
|
||||
def value(self):
|
||||
return self.m.ImageURL
|
||||
return self.url
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
self.url = value
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return self.m.ImageURL
|
||||
@url.setter
|
||||
def url(self, value):
|
||||
self.m.ImageURL = None
|
||||
self.m.ImageURL = _P.to_url(value)
|
||||
|
||||
|
|
Loading…
Reference in New Issue