+static void do_draw_rect(frontend *fe, int x, int y, int w, int h)
+{
+ gdk_draw_rectangle(fe->pixmap, fe->gc, 1, x, y, w, h);
+}
+
+static void do_draw_line(frontend *fe, int x1, int y1, int x2, int y2)
+{
+ gdk_draw_line(fe->pixmap, fe->gc, x1, y1, x2, y2);
+}
+
+static void do_draw_thick_line(frontend *fe, float thickness,
+ float x1, float y1, float x2, float y2)
+{
+ GdkGCValues save;
+
+ gdk_gc_get_values(fe->gc, &save);
+ gdk_gc_set_line_attributes(fe->gc,
+ thickness,
+ GDK_LINE_SOLID,
+ GDK_CAP_BUTT,
+ GDK_JOIN_BEVEL);
+ gdk_draw_line(fe->pixmap, fe->gc, x1, y1, x2, y2);
+ gdk_gc_set_line_attributes(fe->gc,
+ save.line_width,
+ save.line_style,
+ save.cap_style,
+ save.join_style);
+}
+
+static void do_draw_poly(frontend *fe, int *coords, int npoints,
+ int fillcolour, int outlinecolour)
+{
+ GdkPoint *points = snewn(npoints, GdkPoint);
+ int i;
+
+ for (i = 0; i < npoints; i++) {
+ points[i].x = coords[i*2];
+ points[i].y = coords[i*2+1];
+ }
+
+ if (fillcolour >= 0) {
+ set_colour(fe, fillcolour);
+ gdk_draw_polygon(fe->pixmap, fe->gc, TRUE, points, npoints);
+ }
+ assert(outlinecolour >= 0);
+ set_colour(fe, outlinecolour);
+
+ /*
+ * In principle we ought to be able to use gdk_draw_polygon for
+ * the outline as well. In fact, it turns out to interact badly
+ * with a clipping region, for no terribly obvious reason, so I
+ * draw the outline as a sequence of lines instead.
+ */
+ for (i = 0; i < npoints; i++)
+ gdk_draw_line(fe->pixmap, fe->gc,
+ points[i].x, points[i].y,
+ points[(i+1)%npoints].x, points[(i+1)%npoints].y);
+
+ sfree(points);
+}
+
+static void do_draw_circle(frontend *fe, int cx, int cy, int radius,
+ int fillcolour, int outlinecolour)
+{
+ if (fillcolour >= 0) {
+ set_colour(fe, fillcolour);
+ gdk_draw_arc(fe->pixmap, fe->gc, TRUE,
+ cx - radius, cy - radius,
+ 2 * radius, 2 * radius, 0, 360 * 64);
+ }
+
+ assert(outlinecolour >= 0);
+ set_colour(fe, outlinecolour);
+ gdk_draw_arc(fe->pixmap, fe->gc, FALSE,
+ cx - radius, cy - radius,
+ 2 * radius, 2 * radius, 0, 360 * 64);
+}
+
+static void setup_blitter(blitter *bl, int w, int h)
+{
+ /*
+ * We can't create the pixmap right now, because fe->window
+ * might not yet exist. So we just cache w and h and create it
+ * during the firs call to blitter_save.
+ */
+ bl->pixmap = NULL;
+}
+
+static void teardown_blitter(blitter *bl)
+{
+ if (bl->pixmap)
+ gdk_pixmap_unref(bl->pixmap);
+}
+
+static void do_blitter_save(frontend *fe, blitter *bl, int x, int y)
+{
+ if (!bl->pixmap)
+ bl->pixmap = gdk_pixmap_new(fe->area->window, bl->w, bl->h, -1);
+ gdk_draw_pixmap(bl->pixmap,
+ fe->area->style->fg_gc[GTK_WIDGET_STATE(fe->area)],
+ fe->pixmap,
+ x, y, 0, 0, bl->w, bl->h);
+}
+
+static void do_blitter_load(frontend *fe, blitter *bl, int x, int y)
+{
+ assert(bl->pixmap);
+ gdk_draw_pixmap(fe->pixmap,
+ fe->area->style->fg_gc[GTK_WIDGET_STATE(fe->area)],
+ bl->pixmap,
+ 0, 0, x, y, bl->w, bl->h);
+}
+
+static void clear_backing_store(frontend *fe)
+{
+ fe->pixmap = NULL;
+}
+
+static void setup_backing_store(frontend *fe)
+{
+ GdkGC *gc;
+
+ fe->pixmap = gdk_pixmap_new(fe->area->window, fe->pw, fe->ph, -1);
+
+ gc = gdk_gc_new(fe->area->window);
+ gdk_gc_set_foreground(gc, &fe->colours[0]);
+ gdk_draw_rectangle(fe->pixmap, gc, 1, 0, 0, fe->pw, fe->ph);
+ gdk_draw_rectangle(fe->area->window, gc, 1, 0, 0, fe->w, fe->h);
+ gdk_gc_unref(gc);
+}
+
+static int backing_store_ok(frontend *fe)
+{
+ return (!!fe->pixmap);
+}
+
+static void teardown_backing_store(frontend *fe)
+{
+ gdk_pixmap_unref(fe->pixmap);
+ fe->pixmap = NULL;
+}
+
+#endif
+
+static void repaint_rectangle(frontend *fe, GtkWidget *widget,
+ int x, int y, int w, int h)
+{
+ GdkGC *gc = gdk_gc_new(widget->window);
+#ifdef USE_CAIRO
+ gdk_gc_set_foreground(gc, &fe->background);
+#else
+ gdk_gc_set_foreground(gc, &fe->colours[fe->backgroundindex]);
+#endif
+ if (x < fe->ox) {
+ gdk_draw_rectangle(widget->window, gc,
+ TRUE, x, y, fe->ox - x, h);
+ w -= (fe->ox - x);
+ x = fe->ox;
+ }
+ if (y < fe->oy) {
+ gdk_draw_rectangle(widget->window, gc,
+ TRUE, x, y, w, fe->oy - y);
+ h -= (fe->oy - y);
+ y = fe->oy;
+ }
+ if (w > fe->pw) {
+ gdk_draw_rectangle(widget->window, gc,
+ TRUE, x + fe->pw, y, w - fe->pw, h);
+ w = fe->pw;
+ }
+ if (h > fe->ph) {
+ gdk_draw_rectangle(widget->window, gc,
+ TRUE, x, y + fe->ph, w, h - fe->ph);
+ h = fe->ph;
+ }
+ gdk_draw_pixmap(widget->window, gc, fe->pixmap,
+ x - fe->ox, y - fe->oy, x, y, w, h);
+ gdk_gc_unref(gc);
+}
+
+/* ----------------------------------------------------------------------
+ * Pango font functions.
+ */
+
+#ifdef USE_PANGO
+
+static void add_font(frontend *fe, int index, int fonttype, int fontsize)