def convert_stroke_to_curve(self): doc = self.app.current_doc selection = self.app.current_doc.selection doc.canvas.set_mode(modes.WAIT_MODE) try: objs = [] for obj in selection.objs: if obj.is_primitive and not obj.is_pixmap and obj.style[1] \ and obj.style[1][1]: pths = libgeom.apply_trafo_to_paths(obj.get_initial_paths(), obj.trafo) style = [ [sk2const.FILL_EVENODD, sk2const.FILL_SOLID, deepcopy(obj.style[1][2])], [], [], []] pths = libgeom.stroke_to_curve(pths, obj.style[1]) objs.append(doc.api.create_curve(pths, style)) if obj.cache_arrows: for pair in obj.cache_arrows: [objs.append(doc.api.create_curve( libcairo.get_path_from_cpath(item), style)) for item in pair if item] selection.set(objs) if len(objs) > 1: doc.api.group_selected() except Exception as e: LOG.error('Error in convert_stroke_to_curve(), %s', e) doc.canvas.set_mode() msg = _('Error occurred during this operation.') msg += '\n' + _( 'Perhaps this was due to the imperfection of the algorithm.') error_dialog(self.app.mw, self.app.appdata.app_name, msg) doc.canvas.set_mode()
def draw_curve(self, curve_obj): paths = libgeom.apply_trafo_to_paths(curve_obj.paths, curve_obj.trafo) arrow_paths = [] if curve_obj.cache_arrows: for pair in curve_obj.cache_arrows: for item in pair: if item: arrow_paths += libcairo.get_path_from_cpath(item) arrow_paths = self.make_pdfpath(arrow_paths)[0] arrow_fill_style = None if arrow_paths and curve_obj.style[1]: color = curve_obj.style[1][2] arrow_fill_style = [ sk2const.FILL_NONZERO, sk2const.FILL_SOLID, color ] pdfpath, closed = self.make_pdfpath(paths) fill_style = curve_obj.style[0] stroke_style = curve_obj.style[1] if stroke_style and stroke_style[7]: self.stroke_pdfpath(pdfpath, stroke_style, curve_obj.stroke_trafo) if arrow_paths and arrow_fill_style: self.fill_pdfpath(None, arrow_paths, arrow_fill_style, None) if fill_style and fill_style[0] & sk2const.FILL_CLOSED_ONLY and closed: self.fill_pdfpath(curve_obj, pdfpath, fill_style, curve_obj.fill_trafo) elif fill_style and not fill_style[0] & sk2const.FILL_CLOSED_ONLY: self.fill_pdfpath(curve_obj, pdfpath, fill_style, curve_obj.fill_trafo) if stroke_style and not stroke_style[7]: self.stroke_pdfpath(pdfpath, stroke_style, curve_obj.stroke_trafo) if arrow_paths and arrow_fill_style: self.fill_pdfpath(None, arrow_paths, arrow_fill_style, None)
def get_transformed_path(obj): if obj.cache_cpath is None: obj.update() if obj.cache_cpath is None: return None return libcairo.get_path_from_cpath(obj.cache_cpath)
def get_paths_from_glyph(glyph): glyph = libcairo.get_path_from_cpath(glyph) ret = [] for item in glyph: if item and item[1]: ret.append(item) if not ret: return None return ret
def get_paths_from_glyph(glyph): glyph = libcairo.get_path_from_cpath(glyph) ret = [] for item in glyph: if item and item[1]: ret.append(item) if not ret:return None return ret
def get_path_from_cpath(cpath): return libcairo.get_path_from_cpath(cpath)
def get_paths_from_glyph(glyph): ret = [item for item in libcairo.get_path_from_cpath(glyph) if item and item[1]] return ret if ret else None