... | ... |
@@ -192,6 +192,30 @@ class TextShape(Shape): |
192 | 192 |
cr.stroke() |
193 | 193 |
|
194 | 194 |
|
195 |
+class ImageShape(Shape): |
|
196 |
+ |
|
197 |
+ def __init__(self, pen, x0, y0, w, h, path): |
|
198 |
+ Shape.__init__(self) |
|
199 |
+ self.pen = pen.copy() |
|
200 |
+ self.x0 = x0 |
|
201 |
+ self.y0 = y0 |
|
202 |
+ self.w = w |
|
203 |
+ self.h = h |
|
204 |
+ self.path = path |
|
205 |
+ |
|
206 |
+ def draw(self, cr, highlight=False): |
|
207 |
+ cr2 = gtk.gdk.CairoContext(cr) |
|
208 |
+ pixbuf = gtk.gdk.pixbuf_new_from_file(self.path) |
|
209 |
+ sx = float(self.w)/float(pixbuf.get_width()) |
|
210 |
+ sy = float(self.h)/float(pixbuf.get_height()) |
|
211 |
+ cr.save() |
|
212 |
+ cr.translate(self.x0, self.y0 - self.h) |
|
213 |
+ cr.scale(sx, sy) |
|
214 |
+ cr2.set_source_pixbuf(pixbuf, 0, 0) |
|
215 |
+ cr2.paint() |
|
216 |
+ cr.restore() |
|
217 |
+ |
|
218 |
+ |
|
195 | 219 |
class EllipseShape(Shape): |
196 | 220 |
|
197 | 221 |
def __init__(self, pen, x0, y0, w, h, filled=False): |
... | ... |
@@ -610,6 +634,12 @@ class XDotAttrParser: |
610 | 634 |
elif op == "p": |
611 | 635 |
points = self.read_polygon() |
612 | 636 |
self.handle_polygon(points, filled=False) |
637 |
+ elif op == "I": |
|
638 |
+ x0, y0 = s.read_point() |
|
639 |
+ w = s.read_number() |
|
640 |
+ h = s.read_number() |
|
641 |
+ path = s.read_text() |
|
642 |
+ self.handle_image(x0, y0, w, h, path) |
|
613 | 643 |
else: |
614 | 644 |
sys.stderr.write("unknown xdot opcode '%s'\n" % op) |
615 | 645 |
break |
... | ... |
@@ -647,6 +677,9 @@ class XDotAttrParser: |
647 | 677 |
self.shapes.append(EllipseShape(self.pen, x0, y0, w, h, filled=True)) |
648 | 678 |
self.shapes.append(EllipseShape(self.pen, x0, y0, w, h)) |
649 | 679 |
|
680 |
+ def handle_image(self, x0, y0, w, h, path): |
|
681 |
+ self.shapes.append(ImageShape(self.pen, x0, y0, w, h, path)) |
|
682 |
+ |
|
650 | 683 |
def handle_line(self, points): |
651 | 684 |
self.shapes.append(LineShape(self.pen, points)) |
652 | 685 |
|