Rich text and the anti-aliased canvas
- From: Jean Bréfort <jean brefort ac-dijon fr>
- To: gnome-devel-list gnome org
- Subject: Rich text and the anti-aliased canvas
- Date: Fri, 25 Apr 2003 16:14:45 +0200
Hi,
I have written some code to support the Rich Text Item in the
anti-aliased canvas. My code is probably far from perfect since it uses
mostly the same things than for the normal canvas but it seems to work.
I intend to use it for GChemPaint.
Best regards
Jean Bréfort
--- gnome-canvas-rich-text.c.orig Fri Apr 25 16:05:12 2003
+++ gnome-canvas-rich-text.c.new Fri Apr 25 16:09:28 2003
@@ -2087,11 +2087,90 @@
} /* gnome_canvas_rich_text_draw */
static void
gnome_canvas_rich_text_render(GnomeCanvasItem *item, GnomeCanvasBuf *buf)
{
- g_warning ("rich text item not implemented for anti-aliased canvas");
+ GnomeCanvasRichText *text = GNOME_CANVAS_RICH_TEXT (item);
+ int x, y, i, r;
+ double x0, y0, h, w;
+ guchar* data;
+ double i2w[6], w2c[6], i2c[6];
+ double ax, ay;
+ double x1, y1, x2, y2;
+ ArtPoint ip, cp;
+
+ gnome_canvas_buf_ensure_buf (buf);
+
+ gnome_canvas_item_i2w_affine(item, i2w);
+ gnome_canvas_w2c_affine(item->canvas, w2c);
+ art_affine_multiply(i2c, i2w, w2c);
+
+ adjust_for_anchors(text, &ax, &ay);
+
+ ip.x = ax;
+ ip.y = ay;
+ art_affine_point(&cp, &ip, i2c);
+ x1 = cp.x;
+ y1 = cp.y;
+
+ ip.x = ax + text->_priv->width;
+ ip.y = ay + text->_priv->height;
+ art_affine_point(&cp, &ip, i2c);
+ x2 = cp.x;
+ y2 = cp.y;
+
+ ip.x = text->_priv->x;
+ ip.y = text->_priv->y;
+ art_affine_point(&cp, &ip, i2c);
+ x0 = cp.x;
+ y0 = cp.y;
+
+ w = x2 - x1;
+ h = y2 - y1;
+ if (x0 < buf->rect.x0)
+ {
+ w -= buf->rect.x0 - x0;
+ x0 = buf->rect.x0;
+ x = 0;
+ }
+ else x = x0 - buf->rect.x0;
+ if (x0 + w >= buf->rect.x1)
+ w = buf->rect.x1 - x0;
+ if (y0 < buf->rect.y0)
+ {
+ h -= buf->rect.y0 - y0;
+ y0 = buf->rect.y0;
+ y = 0;
+ }
+ else y = y0 - buf->rect.y0;
+ if (y0 + h >= buf->rect.y1)
+ h = buf->rect.y1 - y0;
+ if (((int) w == 0) || ((int) h == 0)) return;
+ GdkPixbuf *pxb = gdk_pixbuf_new_from_data (buf->buf + y * buf->buf_rowstride + x * 3,
+ GDK_COLORSPACE_RGB, FALSE, 8, (int) w, (int) h,
+ buf->buf_rowstride, NULL, NULL);
+ GdkPixmap* pb = gdk_pixmap_new (item->canvas->layout.bin_window, (int) w, (int) h, gtk_widget_get_visual ((GtkWidget*) item->canvas)->depth);
+ GdkGC* gc = gdk_gc_new (pb);
+ gdk_pixbuf_render_to_drawable (pxb, pb, gc, 0, 0, 0, 0, w, h, GDK_RGB_DITHER_NONE, 0, 0);
+ gtk_text_layout_set_screen_width(text->_priv->layout, x2 - x1);
+ /* FIXME: should last arg be NULL? */
+ gtk_text_layout_draw(
+ text->_priv->layout,
+ GTK_WIDGET(item->canvas),
+ pb,
+ GTK_WIDGET (item->canvas)->style->text_gc[GTK_STATE_NORMAL],
+ x0 - x1, y0 - y1,
+ 0, 0, x2 - x0, y2 - y0,
+ NULL);
+
+ GdkPixbuf* pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, (int) w, (int) h);
+ GdkColormap* map = gdk_colormap_new (gtk_widget_get_visual ((GtkWidget*) item->canvas), FALSE);
+ gdk_pixbuf_get_from_drawable (pixbuf, pb, map, 0, 0, 0, 0, (int) w, (int) h);
+ data = gdk_pixbuf_get_pixels (pixbuf);
+ r = gdk_pixbuf_get_rowstride (pixbuf);
+ for (i = 0; i < h; i++)
+ memcpy (buf->buf + (y + i) * buf->buf_rowstride + x * 3, data + i * r, (int) w * 3);
} /* gnome_canvas_rich_text_render */
#if 0
static GtkTextTag *
gnome_canvas_rich_text_add_tag(GnomeCanvasRichText *text, char *tag_name,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]