From 16495674277dfed5241d0bf6711d475765e731a8 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Wed, 06 Mar 2013 17:30:50 +0000 Subject: Use GdkPixbuf to open files - SL #4418 Instead of use a cairo.ImageSurface, use a GdkPixbuf to load files and paint it over the ImageSurface. In this way we can open more file types than png, like in previous Paint versions. This solves opening a clipboard object, like in the ticket SL #4418 Also the cairo developers said the ImageSurface.create_from_png method is not designed to use in production but only to help in testing. This patch is a simpler version based in the work of Manuel Kauffman. Signed-off-by: Gonzalo Odiard --- (limited to 'Area.py') diff --git a/Area.py b/Area.py index e42be83..ee29f91 100644 --- a/Area.py +++ b/Area.py @@ -241,8 +241,13 @@ class Area(Gtk.DrawingArea): return style.zoom(44) def load_from_file(self, file_path): - self.drawing_canvas_data = \ - cairo.ImageSurface.create_from_png(file_path) + # load using a pixbuf to be able to read different formats + loaded_pxb = GdkPixbuf.Pixbuf.new_from_file(file_path) + self.drawing_canvas_data = cairo.ImageSurface(cairo.FORMAT_ARGB32, + loaded_pxb.get_width(), loaded_pxb.get_height()) + ctx = cairo.Context(self.drawing_canvas_data) + Gdk.cairo_set_source_pixbuf(ctx, loaded_pxb, 0, 0) + ctx.paint() def setup(self, width, height): """Configure the Area object.""" -- cgit v0.9.1