Support for Calc and Writer
This commit is contained in:
parent
3fc8f94ea4
commit
e0f484cdaa
|
@ -51,5 +51,8 @@ sudo apt install pdf2svg
|
||||||
* For OSx
|
* For OSx
|
||||||
|
|
||||||
```
|
```
|
||||||
|
brew install mactex
|
||||||
|
brew install tex-live-utility
|
||||||
|
sudo tlmgr install --reinstall pdfcrop
|
||||||
brew install pdf2svg
|
brew install pdf2svg
|
||||||
```
|
```
|
||||||
|
|
Binary file not shown.
|
@ -71,19 +71,22 @@ class Controllers(object):
|
||||||
self.d.image.url = self._path
|
self.d.image.url = self._path
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@app.catch_exception
|
||||||
def cmd_insert_action(self, event):
|
def cmd_insert_action(self, event):
|
||||||
if not self._path:
|
if not self._path:
|
||||||
msg = _('First, generate preview')
|
msg = _('First, generate preview')
|
||||||
app.errorbox(msg)
|
app.errorbox(msg)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
attr = {}
|
||||||
sel = app.selection
|
sel = app.selection
|
||||||
if hasattr(sel, 'anchor'):
|
if hasattr(sel, 'anchor'):
|
||||||
|
attr = sel.size
|
||||||
anchor = sel.anchor
|
anchor = sel.anchor
|
||||||
anchor.dp.remove(sel)
|
anchor.dp.remove(sel)
|
||||||
sel = anchor
|
sel = anchor
|
||||||
|
|
||||||
image = sel.insert_image(self._path, {})
|
image = sel.insert_image(self._path, attr)
|
||||||
image.description = self.d.text.value
|
image.description = self.d.text.value
|
||||||
self.d.close()
|
self.d.close()
|
||||||
return
|
return
|
||||||
|
@ -152,6 +155,22 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor):
|
||||||
app.msgbox(msg)
|
app.msgbox(msg)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@app.catch_exception
|
||||||
|
def _from_selection(self):
|
||||||
|
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 _dlg(self):
|
def _dlg(self):
|
||||||
dlg = self._create_dialog()
|
dlg = self._create_dialog()
|
||||||
sel = app.selection
|
sel = app.selection
|
||||||
|
@ -243,23 +262,6 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor):
|
||||||
|
|
||||||
return dlg
|
return dlg
|
||||||
|
|
||||||
def _from_selection(self):
|
|
||||||
doc = app.active
|
|
||||||
sel = doc.selection
|
|
||||||
if doc.type == 'writer':
|
|
||||||
sel = sel[0]
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
g_ImplementationHelper = unohelper.ImplementationHelper()
|
g_ImplementationHelper = unohelper.ImplementationHelper()
|
||||||
g_ImplementationHelper.addImplementation(ZAZLaTex2SVG, ID_EXTENSION, SERVICE)
|
g_ImplementationHelper.addImplementation(ZAZLaTex2SVG, ID_EXTENSION, SERVICE)
|
||||||
|
|
|
@ -119,7 +119,10 @@ TYPE_RANGES = (OBJ_CELL, OBJ_RANGE, OBJ_RANGES)
|
||||||
|
|
||||||
OBJ_SHAPES = 'com.sun.star.drawing.SvxShapeCollection'
|
OBJ_SHAPES = 'com.sun.star.drawing.SvxShapeCollection'
|
||||||
OBJ_SHAPE = 'com.sun.star.comp.sc.ScShapeObj'
|
OBJ_SHAPE = 'com.sun.star.comp.sc.ScShapeObj'
|
||||||
|
OBJ_GRAPHIC = 'SwXTextGraphicObject'
|
||||||
|
|
||||||
|
OBJ_TEXTS = 'SwXTextRanges'
|
||||||
|
OBJ_TEXT = 'SwXTextRange'
|
||||||
|
|
||||||
# ~ 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):
|
||||||
|
@ -767,7 +770,8 @@ class LODocument(object):
|
||||||
@property
|
@property
|
||||||
def selection(self):
|
def selection(self):
|
||||||
sel = self.obj.CurrentSelection
|
sel = self.obj.CurrentSelection
|
||||||
return _get_class_uno(sel)
|
# ~ return _get_class_uno(sel)
|
||||||
|
return sel
|
||||||
|
|
||||||
def create_instance(self, name):
|
def create_instance(self, name):
|
||||||
obj = self.obj.createInstance(name)
|
obj = self.obj.createInstance(name)
|
||||||
|
@ -1535,6 +1539,10 @@ class LOWriterTextRange(object):
|
||||||
def cursor(self):
|
def cursor(self):
|
||||||
return self.text.createTextCursorByRange(self.obj)
|
return self.text.createTextCursorByRange(self.obj)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dp(self):
|
||||||
|
return self._doc.dp
|
||||||
|
|
||||||
def offset(self):
|
def offset(self):
|
||||||
cursor = self.cursor.getEnd()
|
cursor = self.cursor.getEnd()
|
||||||
return LOWriterTextRange(cursor, self._doc)
|
return LOWriterTextRange(cursor, self._doc)
|
||||||
|
@ -1554,7 +1562,7 @@ class LOWriterTextRange(object):
|
||||||
image.Width = w
|
image.Width = w
|
||||||
image.Height = h
|
image.Height = h
|
||||||
self.insert_content(image)
|
self.insert_content(image)
|
||||||
return
|
return self._doc.dp.last
|
||||||
|
|
||||||
|
|
||||||
class LOWriterTextRanges(object):
|
class LOWriterTextRanges(object):
|
||||||
|
@ -1580,11 +1588,33 @@ class LOWriter(LODocument):
|
||||||
@property
|
@property
|
||||||
def selection(self):
|
def selection(self):
|
||||||
sel = self.obj.CurrentSelection
|
sel = self.obj.CurrentSelection
|
||||||
# ~ print(sel.ImplementationName)
|
if sel.ImplementationName == OBJ_TEXTS:
|
||||||
if sel.ImplementationName == 'SwXTextRanges':
|
if len(sel) == 1:
|
||||||
sel = LOWriterTextRanges(sel, self)
|
sel = LOWriterTextRanges(sel, self)[0]
|
||||||
|
else:
|
||||||
|
sel = LOWriterTextRanges(sel, self)
|
||||||
|
return sel
|
||||||
|
|
||||||
|
if sel.ImplementationName == OBJ_SHAPES:
|
||||||
|
if len(sel) == 1:
|
||||||
|
sel = sel[0]
|
||||||
|
sel = LODrawPage(sel.Parent)[sel.Name]
|
||||||
|
return sel
|
||||||
|
|
||||||
|
if sel.ImplementationName == OBJ_GRAPHIC:
|
||||||
|
sel = self.dp[sel.Name]
|
||||||
|
else:
|
||||||
|
debug(sel.ImplementationName)
|
||||||
|
|
||||||
return sel
|
return sel
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dp(self):
|
||||||
|
return self.draw_page
|
||||||
|
@property
|
||||||
|
def draw_page(self):
|
||||||
|
return LODrawPage(self.obj.DrawPage)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def view_cursor(self):
|
def view_cursor(self):
|
||||||
return self._cc.ViewCursor
|
return self._cc.ViewCursor
|
||||||
|
@ -1620,6 +1650,12 @@ class LOShape(LOBaseObject):
|
||||||
def index(self):
|
def index(self):
|
||||||
return self._index
|
return self._index
|
||||||
|
|
||||||
|
@property
|
||||||
|
def size(self):
|
||||||
|
s = self.obj.Size
|
||||||
|
a = dict(Width=s.Width, Height=s.Height)
|
||||||
|
return a
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def string(self):
|
def string(self):
|
||||||
return self.obj.String
|
return self.obj.String
|
||||||
|
@ -1637,11 +1673,14 @@ class LOShape(LOBaseObject):
|
||||||
@property
|
@property
|
||||||
def cell(self):
|
def cell(self):
|
||||||
return self.anchor
|
return self.anchor
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def anchor(self):
|
def anchor(self):
|
||||||
obj = self.obj.Anchor
|
obj = self.obj.Anchor
|
||||||
if obj.ImplementationName == OBJ_CELL:
|
if obj.ImplementationName == OBJ_CELL:
|
||||||
obj = LOCalcRange(obj)
|
obj = LOCalcRange(obj)
|
||||||
|
elif obj.ImplementationName == OBJ_TEXT:
|
||||||
|
obj = LOWriterTextRange(obj, LODocs().active)
|
||||||
else:
|
else:
|
||||||
debug('Anchor', obj.ImplementationName)
|
debug('Anchor', obj.ImplementationName)
|
||||||
return obj
|
return obj
|
||||||
|
@ -1693,6 +1732,10 @@ class LODrawPage(LOBaseObject):
|
||||||
def count(self):
|
def count(self):
|
||||||
return self.obj.Count
|
return self.obj.Count
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last(self):
|
||||||
|
return self[self.count - 1]
|
||||||
|
|
||||||
def create_instance(self, name):
|
def create_instance(self, name):
|
||||||
return self.doc.createInstance(name)
|
return self.doc.createInstance(name)
|
||||||
|
|
||||||
|
@ -3342,7 +3385,7 @@ class Paths(object):
|
||||||
pattern = re.compile(r'\.(?:{})$'.format(filters), re.IGNORECASE)
|
pattern = re.compile(r'\.(?:{})$'.format(filters), re.IGNORECASE)
|
||||||
paths += [cls.join(folder, f) for f in files if pattern.search(f)]
|
paths += [cls.join(folder, f) for f in files if pattern.search(f)]
|
||||||
else:
|
else:
|
||||||
paths += files
|
paths += [cls.join(folder, f) for f in files]
|
||||||
return paths
|
return paths
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in New Issue