def create_oo_bezier( self, points, page, gr_style_name): ps = [j for i in map(geometry.quadratic_beziere_to_polyline, geometry.tkspline_to_quadratic_bezier(points)) for j in i] maxX, maxY, minX, minY = None,None,None,None for (x,y) in ps: if not maxX or x > maxX: maxX = x if not minX or x < minX: minX = x if not maxY or y > maxY: maxY = y if not minY or y < minY: minY = y points_txt = "" for (sx, sy, cxa, cya, cxb, cyb, ex, ey) in geometry.tkspline_to_cubic_bezier( points): if not points_txt: points_txt += "m %d %d c " % (1000*(sx-minX), 1000*(sy-minY)) points_txt += "%d %d %d %d %d %d " % (1000*(cxa-sx),1000*(cya-sy),1000*(cxb-sx),1000*(cyb-sy),1000*(ex-sx),1000*(ey-sy)) line = dom_extensions.elementUnder( page, 'draw:path', (( 'svg:x', '%fcm' % minX), ( 'svg:y', '%fcm' % minY), ( 'svg:width', '%fcm' % (maxX-minX)), ( 'svg:height', '%fcm' % (maxY-minY)), ( 'svg:viewBox', '0 0 %d %d' % ((maxX-minX)*1000,(maxY-minY)*1000)), ( 'svg:d', points_txt), ( 'draw:layer', 'layout'), ( 'draw:style-name', gr_style_name)))
def create_oo_bezier2(self, points, page, gr_style_name): points_txt = "" for (sx, sy, cxa, cya, cxb, cyb, ex, ey) in geometry.tkspline_to_cubic_bezier(points): if not points_txt: points_txt += "m %d %d c " % (1000 * (sx), 1000 * (sy)) points_txt += "%d %d %d %d %d %d " % (1000 * (cxa - sx), 1000 * (cya - sy), 1000 * (cxb - sx), 1000 * (cyb - sy), 1000 * (ex - sx), 1000 * (ey - sy)) print(points_txt) w = self.paper.get_paper_property('size_x') / 10.0 h = self.paper.get_paper_property('size_y') / 10.0 #wpx = Screen.cm_to_px( w) #hpx = Screen.cm_to_px( h) #print('svg:viewBox', '0 0 %d %d' % (wpx*1000,hpx*1000)) print('svg:viewBox', '0 0 %d %d' % (w * 1000, h * 1000)) line = dom_extensions.elementUnder( page, 'draw:path', (('svg:x', '0cm'), ('svg:y', '0cm'), ('svg:width', '%fcm' % w), ('svg:height', '%fcm' % h), ('svg:viewBox', '0 0 %d %d' % (w * 1000, h * 1000)), ('svg:d', points_txt), ('draw:layer', 'layout'), ('draw:style-name', gr_style_name)))
def create_oo_bezier( self, points, page, gr_style_name): ps = reduce( operator.add, map( geometry.quadratic_beziere_to_polyline, geometry.tkspline_to_quadratic_bezier( points))) maxX, maxY, minX, minY = None,None,None,None for (x,y) in ps: if not maxX or x > maxX: maxX = x if not minX or x < minX: minX = x if not maxY or y > maxY: maxY = y if not minY or y < minY: minY = y points_txt = "" for (sx, sy, cxa, cya, cxb, cyb, ex, ey) in geometry.tkspline_to_cubic_bezier( points): if not points_txt: points_txt += "m %d %d c " % (1000*(sx-minX), 1000*(sy-minY)) points_txt += "%d %d %d %d %d %d " % (1000*(cxa-sx),1000*(cya-sy),1000*(cxb-sx),1000*(cyb-sy),1000*(ex-sx),1000*(ey-sy)) line = dom_extensions.elementUnder( page, 'draw:path', (( 'svg:x', '%fcm' % minX), ( 'svg:y', '%fcm' % minY), ( 'svg:width', '%fcm' % (maxX-minX)), ( 'svg:height', '%fcm' % (maxY-minY)), ( 'svg:viewBox', '0 0 %d %d' % ((maxX-minX)*1000,(maxY-minY)*1000)), ( 'svg:d', points_txt), ( 'draw:layer', 'layout'), ( 'draw:style-name', gr_style_name)))
def _draw_line(self, item): if self.paper.itemcget(item, 'fill') != '': # arrows at first as they make the lines bellow them shorter start = None end = None arrows = self.paper.itemcget(item, 'arrow') if arrows != "none": color = self.paper.itemcget(item, 'fill') coords = self.paper.coords(item) if arrows in ("last", "both"): end = self._create_arrow( self.paper.itemcget(item, 'arrowshape'), coords[-4:-2], coords[-2:], color) if arrows in ("first", "both"): start = self._create_arrow( self.paper.itemcget(item, 'arrowshape'), coords[2:4], coords[0:2], color) coords = self.transformer.transform_xy_flat_list( self.paper.coords(item)) if start: coords[0] = start[0] coords[1] = start[1] if end: coords[-2] = end[0] coords[-1] = end[1] # cap style cap = self.paper.itemcget(item, 'capstyle') self.context.set_line_cap(self._caps[cap]) # join style join = self.paper.itemcget(item, 'joinstyle') self.context.set_line_join(self._joins[join]) # color is_visible = self.set_cairo_color(self.paper.itemcget( item, 'fill')) # line width width = self.p2c_width(float(self.paper.itemcget(item, 'width'))) self.context.set_line_width(width) # the path itself cs = self._flat_list_to_list_of_tuples(coords) if self.paper.itemcget(item, 'smooth') != "0": # smooth lines xycoords = self._flat_list_to_list_of_tuples(coords) beziers = geometry.tkspline_to_cubic_bezier(xycoords) for bez in beziers: self._create_cairo_curve(bez, closed=False) else: self._create_cairo_path(cs, closed=False) # stroke it if is_visible: self.context.stroke() else: pass #transparent things
def _draw_line( self, item): if self.paper.itemcget( item, 'fill') != '': # arrows at first as they make the lines bellow them shorter start = None end = None arrows = self.paper.itemcget( item, 'arrow') if arrows != "none": color = self.paper.itemcget( item, 'fill') coords = self.paper.coords( item) if arrows in ("last", "both"): end = self._create_arrow( self.paper.itemcget( item, 'arrowshape'), coords[-4:-2], coords[-2:], color) if arrows in ("first", "both"): start = self._create_arrow( self.paper.itemcget( item, 'arrowshape'), coords[2:4], coords[0:2], color) coords = self.transformer.transform_xy_flat_list( self.paper.coords( item)) if start: coords[0] = start[0] coords[1] = start[1] if end: coords[-2] = end[0] coords[-1] = end[1] # cap style cap = self.paper.itemcget( item, 'capstyle') self.context.set_line_cap( self._caps[ cap]) # join style join = self.paper.itemcget( item, 'joinstyle') self.context.set_line_join( self._joins[ join]) # color is_visible = self.set_cairo_color( self.paper.itemcget( item, 'fill')) # line width width = self.p2c_width( float( self.paper.itemcget( item, 'width'))) self.context.set_line_width( width) # the path itself cs = self._flat_list_to_list_of_tuples( coords) if self.paper.itemcget( item, 'smooth') != "0": # smooth lines xycoords = self._flat_list_to_list_of_tuples( coords) beziers = geometry.tkspline_to_cubic_bezier( xycoords) for bez in beziers: self._create_cairo_curve( bez, closed=False) else: self._create_cairo_path( cs, closed=False) # stroke it if is_visible: self.context.stroke() else: pass #transparent things
def _draw_line( self, item): if self.paper.itemcget( item, 'fill') != '': # arrows at first as they make the lines bellow them shorter start = None end = None arrows = self.paper.itemcget( item, 'arrow') if arrows != "none": color = self.paper_to_canvas_color( self.paper.itemcget( item, 'fill')) coords = self.paper.coords( item) if arrows in ("last", "both"): end = self._create_arrow( self.paper.itemcget( item, 'arrowshape'), coords[-4:-2], coords[-2:], color) if arrows in ("first", "both"): start = self._create_arrow( self.paper.itemcget( item, 'arrowshape'), coords[2:4], coords[0:2], color) coords = self.transformer.transform_xy_flat_list( self.paper.coords( item)) if start: coords[0] = start[0] coords[1] = start[1] if end: coords[-2] = end[0] coords[-1] = end[1] if len( coords) > 4: if self.paper.itemcget( item, 'smooth') != "0": #smooth is spline outline = self.paper_to_canvas_color( self.paper.itemcget( item, 'fill')) fill = piddle.transparent width = self.convert( float( self.paper.itemcget( item, 'width'))) xycoords = self._flat_list_to_list_of_tuples( coords) beziers = geometry.tkspline_to_cubic_bezier( xycoords) for bez in beziers: x1, y1, x2, y2, x3, y3, x4, y4 = bez self.canvas.drawCurve(x1, y1, x2, y2, x3, y3, x4, y4, edgeColor=outline, edgeWidth=width, fillColor=fill, closed=0) else: # polyline outline = self.paper_to_canvas_color( self.paper.itemcget( item, 'fill')) fill = piddle.transparent width = self.convert( float( self.paper.itemcget( item, 'width'))) cs = self._flat_list_to_list_of_tuples( coords) self.canvas.drawPolygon( cs, edgeColor=outline, edgeWidth=width, fillColor=fill, closed=0) else: # simple line fill = self.paper_to_canvas_color( self.paper.itemcget( item, 'fill')) width = self.convert( float( self.paper.itemcget( item, 'width'))) x1, y1, x2, y2 = coords self.canvas.drawLine( x1, y1, x2, y2, color=fill, width=width) else: pass #transparent things
def create_oo_bezier2( self, points, page, gr_style_name): points_txt = "" for (sx, sy, cxa, cya, cxb, cyb, ex, ey) in geometry.tkspline_to_cubic_bezier( points): if not points_txt: points_txt += "m %d %d c " % (1000*(sx), 1000*(sy)) points_txt += "%d %d %d %d %d %d " % (1000*(cxa-sx),1000*(cya-sy),1000*(cxb-sx),1000*(cyb-sy),1000*(ex-sx),1000*(ey-sy)) print(points_txt) w = self.paper.get_paper_property( 'size_x')/10.0 h = self.paper.get_paper_property( 'size_y')/10.0 #wpx = Screen.cm_to_px( w) #hpx = Screen.cm_to_px( h) #print('svg:viewBox', '0 0 %d %d' % (wpx*1000,hpx*1000)) print('svg:viewBox', '0 0 %d %d' % (w*1000,h*1000)) line = dom_extensions.elementUnder( page, 'draw:path', (( 'svg:x', '0cm'), ( 'svg:y', '0cm'), ( 'svg:width', '%fcm' % w), ( 'svg:height', '%fcm' % h), ( 'svg:viewBox', '0 0 %d %d' % (w*1000,h*1000)), ( 'svg:d', points_txt), ( 'draw:layer', 'layout'), ( 'draw:style-name', gr_style_name)))
def _draw_line(self, item): if self.paper.itemcget(item, 'fill') != '': # arrows at first as they make the lines bellow them shorter start = None end = None arrows = self.paper.itemcget(item, 'arrow') if arrows != "none": color = self.paper_to_canvas_color( self.paper.itemcget(item, 'fill')) coords = self.paper.coords(item) if arrows in ("last", "both"): end = self._create_arrow( self.paper.itemcget(item, 'arrowshape'), coords[-4:-2], coords[-2:], color) if arrows in ("first", "both"): start = self._create_arrow( self.paper.itemcget(item, 'arrowshape'), coords[2:4], coords[0:2], color) coords = self.transformer.transform_xy_flat_list( self.paper.coords(item)) if start: coords[0] = start[0] coords[1] = start[1] if end: coords[-2] = end[0] coords[-1] = end[1] if len(coords) > 4: if self.paper.itemcget(item, 'smooth') != "0": #smooth is spline outline = self.paper_to_canvas_color( self.paper.itemcget(item, 'fill')) fill = piddle.transparent width = self.convert( float(self.paper.itemcget(item, 'width'))) xycoords = self._flat_list_to_list_of_tuples(coords) beziers = geometry.tkspline_to_cubic_bezier(xycoords) for bez in beziers: x1, y1, x2, y2, x3, y3, x4, y4 = bez self.canvas.drawCurve(x1, y1, x2, y2, x3, y3, x4, y4, edgeColor=outline, edgeWidth=width, fillColor=fill, closed=0) else: # polyline outline = self.paper_to_canvas_color( self.paper.itemcget(item, 'fill')) fill = piddle.transparent width = self.convert( float(self.paper.itemcget(item, 'width'))) cs = self._flat_list_to_list_of_tuples(coords) self.canvas.drawPolygon(cs, edgeColor=outline, edgeWidth=width, fillColor=fill, closed=0) else: # simple line fill = self.paper_to_canvas_color( self.paper.itemcget(item, 'fill')) width = self.convert(float(self.paper.itemcget(item, 'width'))) x1, y1, x2, y2 = coords self.canvas.drawLine(x1, y1, x2, y2, color=fill, width=width) else: pass #transparent things