From 88f239570e5871a221b8122570026f66f7213c3d Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Wed, 09 Oct 2013 05:31:37 +0000 Subject: Use a different technique to draw text in the canvas Previously, we used the cairo toy api, but had problem with complex scripts. Signed-off-by: Gonzalo Odiard --- diff --git a/Desenho.py b/Desenho.py index 2e4868b..cac2749 100644 --- a/Desenho.py +++ b/Desenho.py @@ -62,7 +62,8 @@ Walter Bender (walter@laptop.org) """ from gi.repository import Gdk -from gi.repository import PangoCairo +from gi.repository import Gtk +from gi.repository import GObject import logging import math import cairo @@ -629,45 +630,34 @@ class Desenho: widget.activity.move_textview(coord_x, coord_y) widget.activity.textview.show() + widget.activity.textview.set_cursor_visible(True) widget.activity.textview.grab_focus() else: widget.text_in_progress = False - - buf = widget.activity.textview.get_buffer() - start, end = buf.get_bounds() - text = buf.get_text(start, end, True) - textview = widget.activity.textview - #tv_layout = textview.create_pango_layout(text) - - ctx = widget.drawing_ctx - - ctx.save() - ctx.new_path() - ctx.set_source_rgba(*widget.tool['cairo_stroke_color']) - - pango_layout = PangoCairo.create_layout(ctx) - pango_layout.set_font_description(widget.get_font_description()) - pango_layout.set_text(unicode(text), len(unicode(text))) - - tv_alloc = textview.get_allocation() - ctx.move_to(tv_alloc.x, tv_alloc.y) - PangoCairo.show_layout(ctx, pango_layout) - ctx.stroke() - ctx.restore() - - widget.activity.textview.hide() - widget.drawing_canvas.flush() - - try: - widget.activity.textview.set_text('') - except AttributeError: - buf.set_text('') - - widget.enable_undo() - # TODO: clip - widget.queue_draw() + textview.set_cursor_visible(False) + # need wait until the cursor is hidden + GObject.idle_add(self._finalize_text, widget, textview) + + def _finalize_text(self, widget, textview): + buf = textview.get_buffer() + window = textview.get_window(Gtk.TextWindowType.TEXT) + ctx = widget.drawing_ctx + tv_alloc = textview.get_allocation() + Gdk.cairo_set_source_window(ctx, window, tv_alloc.x, tv_alloc.y) + ctx.paint() + + widget.activity.textview.hide() + widget.drawing_canvas.flush() + + try: + widget.activity.textview.set_text('') + except AttributeError: + buf.set_text('') + + widget.enable_undo() + widget.queue_draw() def selection(self, widget, coords): """Make a selection. -- cgit v0.9.1