From 16c5b2406cac683eb7009ae84f0c6a4db36cf7c7 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Thu, 28 Jun 2012 14:39:08 +0000 Subject: First stage of port of Paint to cairo Brushes and shapes are working. NOTES: * The pixmaps used as canvas has been replaced by ImageSurface and cairo context. * All the gc with tool properties were removed. * The variables needed by the freeform and rainbow were moved from Area to Desenha * The freeform code was simplified. * The heart is draw using cairo curves and is a little different than before. * I am using cairo_stroke_color and cairo_fill_color values in the tool dict to enable compatibility while the port is done, later will be unified. I am setting this color with a fixed alpha of 0.3 to display artifacts if we want enable alpha in the future. It's only for test at this stage. * The code used to display the polygons (triangle, trapezoid, arrow, paralellogram, star, polygon_regular) was simplified calling a method _draw_polygon witha array of points. PENDING: * All the clipboard operations. * All the efects. * Text * Bucket * Stamps --- (limited to 'OficinaActivity.py') diff --git a/OficinaActivity.py b/OficinaActivity.py index 64dace4..16484b6 100644 --- a/OficinaActivity.py +++ b/OficinaActivity.py @@ -140,21 +140,23 @@ class OficinaActivity(activity.Activity): logging.debug('reading file %s, mimetype: %s, title: %s', file_path, self.metadata['mime_type'], self.metadata['title']) - pixbuf = gtk.gdk.pixbuf_new_from_file(file_path) + self.area.load_from_file(file_path) def size_allocate_cb(widget, allocation): + logging.error('read file size allocate') self.fixed.disconnect(self._setup_handle) - self.area.setup(pixbuf.get_width(), pixbuf.get_height()) + width = self.area.drawing_canvas.get_width() + height = self.area.drawing_canvas.get_height() + self.area.setup(width, height) # The scrolled window is confused with a image of the same size # of the canvas when the toolbars popup and the scrolls # keep visible. - if pixbuf.get_height() > allocation.height or \ - pixbuf.get_width() > allocation.width: - self.canvas.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + if height > allocation.height or width > allocation.width: + self.canvas.set_policy(gtk.POLICY_AUTOMATIC, + gtk.POLICY_AUTOMATIC) else: self.canvas.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) - self.area.loadImageFromJournal(pixbuf) self.center_area() self.canvas.add_with_viewport(self.fixed) @@ -186,12 +188,8 @@ class OficinaActivity(activity.Activity): self.area.d.text(self.area, event=None) self.area.getout() - pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, - width, height) - pixbuf.get_from_drawable(self.area.pixmap, - gtk.gdk.colormap_get_system(), 0, 0, 0, 0, -1, -1) + self.area.drawing_canvas.write_to_png(file_path) self.metadata['mime_type'] = 'image/png' - pixbuf.save(file_path, 'png', {}) def _get_area_displacement(self): """Return the point to use as top left corner in order to move -- cgit v0.9.1