diff --git a/README.md b/README.md index c836594..16e7d3a 100644 --- a/README.md +++ b/README.md @@ -51,5 +51,8 @@ sudo apt install pdf2svg * For OSx ``` +brew install mactex +brew install tex-live-utility +sudo tlmgr install --reinstall pdfcrop brew install pdf2svg ``` diff --git a/files/ZAZLaTex2SVG_v0.1.0.oxt b/files/ZAZLaTex2SVG_v0.1.0.oxt index 733fbd2..007cdfd 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 ce704ff..187569f 100644 --- a/source/ZAZLaTex2SVG.py +++ b/source/ZAZLaTex2SVG.py @@ -71,19 +71,22 @@ class Controllers(object): self.d.image.url = self._path return + @app.catch_exception def cmd_insert_action(self, event): if not self._path: msg = _('First, generate preview') app.errorbox(msg) return + attr = {} sel = app.selection if hasattr(sel, 'anchor'): + attr = sel.size anchor = sel.anchor anchor.dp.remove(sel) sel = anchor - image = sel.insert_image(self._path, {}) + image = sel.insert_image(self._path, attr) image.description = self.d.text.value self.d.close() return @@ -152,6 +155,22 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor): app.msgbox(msg) 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): dlg = self._create_dialog() sel = app.selection @@ -243,23 +262,6 @@ class ZAZLaTex2SVG(unohelper.Base, XJobExecutor): 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.addImplementation(ZAZLaTex2SVG, ID_EXTENSION, SERVICE) diff --git a/source/pythonpath/easymacro2.py b/source/pythonpath/easymacro2.py index 14ef6a2..d11c7e2 100644 --- a/source/pythonpath/easymacro2.py +++ b/source/pythonpath/easymacro2.py @@ -119,7 +119,10 @@ TYPE_RANGES = (OBJ_CELL, OBJ_RANGE, OBJ_RANGES) OBJ_SHAPES = 'com.sun.star.drawing.SvxShapeCollection' 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 class FilterOperator(IntEnum): @@ -767,7 +770,8 @@ class LODocument(object): @property def selection(self): sel = self.obj.CurrentSelection - return _get_class_uno(sel) + # ~ return _get_class_uno(sel) + return sel def create_instance(self, name): obj = self.obj.createInstance(name) @@ -1535,6 +1539,10 @@ class LOWriterTextRange(object): def cursor(self): return self.text.createTextCursorByRange(self.obj) + @property + def dp(self): + return self._doc.dp + def offset(self): cursor = self.cursor.getEnd() return LOWriterTextRange(cursor, self._doc) @@ -1554,7 +1562,7 @@ class LOWriterTextRange(object): image.Width = w image.Height = h self.insert_content(image) - return + return self._doc.dp.last class LOWriterTextRanges(object): @@ -1580,11 +1588,33 @@ class LOWriter(LODocument): @property def selection(self): sel = self.obj.CurrentSelection - # ~ print(sel.ImplementationName) - if sel.ImplementationName == 'SwXTextRanges': - sel = LOWriterTextRanges(sel, self) + if sel.ImplementationName == OBJ_TEXTS: + if len(sel) == 1: + 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 + @property + def dp(self): + return self.draw_page + @property + def draw_page(self): + return LODrawPage(self.obj.DrawPage) + @property def view_cursor(self): return self._cc.ViewCursor @@ -1620,6 +1650,12 @@ class LOShape(LOBaseObject): def index(self): return self._index + @property + def size(self): + s = self.obj.Size + a = dict(Width=s.Width, Height=s.Height) + return a + @property def string(self): return self.obj.String @@ -1637,11 +1673,14 @@ class LOShape(LOBaseObject): @property def cell(self): return self.anchor + @property def anchor(self): obj = self.obj.Anchor if obj.ImplementationName == OBJ_CELL: obj = LOCalcRange(obj) + elif obj.ImplementationName == OBJ_TEXT: + obj = LOWriterTextRange(obj, LODocs().active) else: debug('Anchor', obj.ImplementationName) return obj @@ -1693,6 +1732,10 @@ class LODrawPage(LOBaseObject): def count(self): return self.obj.Count + @property + def last(self): + return self[self.count - 1] + def create_instance(self, name): return self.doc.createInstance(name) @@ -3342,7 +3385,7 @@ class Paths(object): pattern = re.compile(r'\.(?:{})$'.format(filters), re.IGNORECASE) paths += [cls.join(folder, f) for f in files if pattern.search(f)] else: - paths += files + paths += [cls.join(folder, f) for f in files] return paths @classmethod