From 234a272540e55443326dd87e5071e3c19bd3bbe9 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Thu, 26 Jul 2012 13:37:30 +0000 Subject: Text tool ported to cairo This patch reorganize a little the text management code, to do the font_properties private to Area. Signed-off-by: Gonzalo Odiard --- (limited to 'Desenho.py') diff --git a/Desenho.py b/Desenho.py index cdcc674..19f561d 100644 --- a/Desenho.py +++ b/Desenho.py @@ -70,6 +70,7 @@ import math import gc import gobject import cairo +import pangocairo RESIZE_DELAY = 500 # The time to wait for the resize operation to be # executed, after the resize controls are pressed. @@ -558,22 +559,32 @@ class Desenho: else: widget.text_in_progress = False - try: - # This works for a gtk.Entry - text = widget.activity.textview.get_text() - except AttributeError: - # This works for a gtk.TextView - buf = widget.activity.textview.get_buffer() - start, end = buf.get_bounds() - text = buf.get_text(start, end) + buf = widget.activity.textview.get_buffer() + start, end = buf.get_bounds() + text = buf.get_text(start, end) + + textview = widget.activity.textview + tv_layout = textview.create_pango_layout(text) + + ctx = widget.drawing_ctx + + ctx.save() + ctx.new_path() + pango_context = pangocairo.CairoContext(ctx) + pango_context.set_source_rgba(*widget.tool['cairo_stroke_color']) + + pango_layout = pango_context.create_layout() + pango_layout.set_font_description(widget.get_font_description()) + pango_layout.set_text(unicode(text)) - layout = widget.activity.textview.create_pango_layout(text) + tv_alloc = textview.get_allocation() + pango_context.move_to(tv_alloc.x, tv_alloc.y) + pango_context.show_layout(pango_layout) + ctx.stroke() + ctx.restore() - widget.pixmap.draw_layout(widget.gc_brush, - widget.oldx, widget.oldy, layout) - widget.pixmap_temp.draw_layout(widget.gc, - widget.oldx, widget.oldy, layout) widget.activity.textview.hide() + widget.drawing_canvas.flush() try: widget.activity.textview.set_text('') -- cgit v0.9.1