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