1import sys, dia 2 3# sys.path.insert(0, 'd:/graph/dia/dia') 4 5class DumpRenderer : 6 def __init__ (self) : 7 pass 8 def begin_render (self, data, filename) : 9 # DiagramData 10 self.f = open(filename, "w") 11 self.f.write("Data: " + str(data) + "\n") 12 self.f.write("Extents: "+ str(data.extents) + "\n") 13 self.f.write("active_layer: " + str(data.active_layer) + " " \ 14 + data.active_layer.name + "\n") 15 #self.f.write("grid .width: " + str(data.grid.width) \ 16 # + " .height" + str(data.grid.height) \ 17 # + "visible: " + str(data.visible) + "\n") 18 def end_render (self) : 19 self.f.close() 20 def set_linewidth (self, width) : 21 self.line_width = width 22 def set_linecaps (self, mode) : 23 self.line_caps = mode 24 def set_linejoin (self, mode) : 25 self.line_join = mode 26 def set_linestyle (self, style) : 27 self.line_style = style 28 def set_dashlength (self, length) : 29 self.dash_length = length 30 def set_fillstyle (self, style) : 31 self.fill_style = style 32 def set_font (self, font, size) : 33 self.font = font 34 def draw_line (self, start, end, color) : 35 self.f.write("draw_line:" + str(start) + str(end) + str(color) + "\n") 36 def draw_polyline (self, points, color) : 37 self.f.write("draw_polyline: " + str(color) + "\n") 38 for pt in points : 39 self.f.write ("\t" + str(pt) + "\n") 40 def draw_polygon (self, points, color) : 41 self.f.write("draw_polygon: " + str(color) + "\n") 42 for pt in points : 43 self.f.write ("\t" + str(pt) + "\n") 44 def fill_polygon (self, points, color) : 45 self.f.write("fill_polygon: " + str(color) + "\n") 46 for pt in points : 47 self.f.write ("\t" + str(pt) + "\n") 48 def draw_rect (self, rect, color) : 49 self.f.write("draw_rect: " + str(rect) + str(color) + "\n") 50 def fill_rect (self, rect, color) : 51 self.f.write("fill_rect: " + str(rect) + str(color) + "\n") 52 def draw_arc (self, center, width, height, angle1, angle2, color) : 53 self.f.write("draw_arc: " + str(center) + ";" \ 54 + str(width) + "x" + str(height) + ";" \ 55 + str(angle1) + "," + str(angle2) + ";" + str(color) + "\n") 56 def fill_arc (self, center, width, height, angle1, angle2, color) : 57 self.f.write("fill_arc: " + str(center) + ";" \ 58 + str(width) + "x" + str(height) + ";" \ 59 + str(angle1) + "," + str(angle2) + ";" + str(color) + "\n") 60 def draw_ellipse (self, center, width, height, color) : 61 self.f.write("draw_ellipse: " + str(center) \ 62 + str(width) + "x" +str(height) + ";" + str(color) + "\n") 63 def fill_ellipse (self, center, width, height, color) : 64 self.f.write("fill_ellipse: " + str(center) \ 65 + str(width) + "x" +str(height) + ";" + str(color) + "\n") 66 def draw_bezier (self, bezpoints, color) : 67 self.f.write("draw_bezier: " + str(color) + "\n") 68 for pt in bezpoints : 69 self.f.write ("\t" + str(pt) + "\n") 70 def fill_bezier (self, bezpoints, color) : 71 self.f.write("fill_bezier: " + str(color) + "\n") 72 for pt in bezpoints : 73 self.f.write ("\t" + str(pt) + "\n") 74 def draw_string (self, text, pos, alignment, color) : 75 self.f.write("draw_string: [" + text + "]; " + str(pos) \ 76 + str(alignment) + "; " +str(color)) 77 def draw_image (self, point, width, height, image) : 78 self.f.write("draw_image: " + str(point) + str(width) + "x" +str(height) \ 79 + " " + image.filename + "\n") 80 self.f.write("<rgb_data>" + image.rgb_data + "</rgb_data>") 81 self.f.write("<mask_data>" + image.mask_data + "</mask_data>") 82 83# dia-python keeps a reference to the renderer class and uses it on demand 84dia.register_export ("PyDia Render Export", "diapyr", DumpRenderer()) 85