? tests/s.c
Index: libgnomeprintui/gnome-print-job-preview.c
===================================================================
RCS file: /cvs/gnome/libgnomeprintui/libgnomeprintui/gnome-print-job-preview.c,v
retrieving revision 1.44
diff -u -5 -r1.44 gnome-print-job-preview.c
--- libgnomeprintui/gnome-print-job-preview.c	1 Nov 2002 23:31:52 -0000	1.44
+++ libgnomeprintui/gnome-print-job-preview.c	17 Dec 2002 01:54:46 -0000
@@ -33,10 +33,11 @@
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
 
 #include <libgnomeprint/private/gnome-print-private.h>
 
+#include "gnome-print-preview-private.h"
 #include "gnome-print-i18n.h"
 #include "gnome-print-job-preview.h"
 
 #define GPMP_ZOOM_IN_FACTOR M_SQRT2
 #define GPMP_ZOOM_OUT_FACTOR M_SQRT1_2
@@ -92,10 +93,12 @@
 	GnomeCanvas *canvas;
 
 	gint current_page;
 	gint pagecount;
 
+	/* Strict theme compliance [#96802] */
+	gboolean theme_compliance;
 };
 
 static void gpmp_parse_layout (GnomePrintJobPreview *mp);
 
 /*
@@ -133,10 +136,12 @@
 	region.x1 = mp->paw + PAGE_PAD;
 	region.y1 = mp->pah + PAGE_PAD;
 
 	config = gnome_print_job_get_config (priv->job);
 	priv->preview = gnome_print_preview_new_full (config, priv->canvas, transform, &region);
+	gnome_print_preview_theme_compliance (GNOME_PRINT_PREVIEW (priv->preview),
+					      priv->theme_compliance);
 	gnome_print_config_unref (config);
 
 	gnome_print_job_render_page (priv->job, priv->preview, page, TRUE);
 
 	return GNOME_PRINT_OK;
@@ -523,10 +528,12 @@
 	GPMPPrivate *priv;
 	AtkObject *relation_targets[1];
 	AtkObject *atko;
 	GtkWidget *status;
 	GtkWidget *l;
+	gint32 border_color;
+	gint32 page_color;
 
 	priv = (GPMPPrivate *) mp->priv;
 
 	priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
 
@@ -550,26 +557,43 @@
 
 	config = gnome_print_job_get_config (priv->job);
 	priv->preview = gnome_print_preview_new (config, priv->canvas);
 	gnome_print_config_unref (config);
 
+	if (priv->theme_compliance) {
+		GtkStyle *style;
+		style = gtk_widget_get_style (GTK_WIDGET (priv->canvas));
+		border_color = GPP_COLOR_RGBA (style->text [GTK_STATE_NORMAL], 0xff);
+		page_color   = GPP_COLOR_RGBA (style->bg [GTK_STATE_NORMAL], 0xff);
+	} else {
+		border_color = 0 | 0xff;
+		page_color   = ~0;
+	}
+	
 	/*
 	 * Now add some padding above and below and put a simulated
 	 * page on the background
 	 */
-
 	item = gnome_canvas_item_new (gnome_canvas_root (priv->canvas),
 				      GNOME_TYPE_CANVAS_RECT,
-				      "x1", 0.0, "y1", 0.0, "x2", (gdouble) mp->paw, "y2", (gdouble) mp->pah,
-				      "fill_color", "white",
-				      "outline_color", "black",
-				      "width_pixels", 1, NULL);
+				      "x1", 0.0,
+				      "y1", 0.0,
+				      "x2", (gdouble) mp->paw,
+				      "y2", (gdouble) mp->pah,
+				      "fill_color_rgba", page_color,
+				      "outline_color_rgba", border_color,
+				      "width_pixels", 1,
+				      NULL);
 	gnome_canvas_item_lower_to_bottom (item);
 	item = gnome_canvas_item_new (gnome_canvas_root (priv->canvas),
 				      GNOME_TYPE_CANVAS_RECT,
-				      "x1", 3.0, "y1", 3.0, "x2", (gdouble) mp->paw + 3, "y2", (gdouble) mp->pah + 3,
-				      "fill_color", "black", NULL);
+				      "x1", 3.0,
+				      "y1", 3.0,
+				      "x2", (gdouble) mp->paw + 3,
+				      "y2", (gdouble) mp->pah + 3,
+				      "fill_color_rgba", border_color,
+				      NULL);
 	gnome_canvas_item_lower_to_bottom (item);
 	gnome_canvas_set_scroll_region (priv->canvas, 0 - PAGE_PAD, 0 - PAGE_PAD, mp->paw + PAGE_PAD, mp->pah + PAGE_PAD);
 
 	status = gtk_hbox_new (FALSE, 0);
 	l = gtk_label_new_with_mnemonic (_("P_age: "));
@@ -757,10 +781,23 @@
 {
 	GPMPPrivate *priv;
 
 	mp->priv = priv = g_new0 (GPMPPrivate, 1);
 	priv->current_page = -1;
+	priv->theme_compliance = FALSE;
+	
+#ifdef __GNUC__
+#warning FIXME: Figure out how to set this
+#endif
+#if 1
+{
+	gchar *env_var;
+	const env_var = g_getenv("GNOME_PRINT_PREVIEW_STRICT_THEME_COMPLIANCE");
+	if (env_var && env_var[0])
+		priv->theme_compliance = TRUE;
+}
+#endif
 
 	/* Main VBox */
 	mp->vbox = gtk_vbox_new (FALSE, 0);
 	gtk_widget_show (mp->vbox);
 	gtk_container_add (GTK_CONTAINER (mp), mp->vbox);
Index: libgnomeprintui/gnome-print-preview-private.h
===================================================================
RCS file: /cvs/gnome/libgnomeprintui/libgnomeprintui/gnome-print-preview-private.h,v
retrieving revision 1.6
diff -u -5 -r1.6 gnome-print-preview-private.h
--- libgnomeprintui/gnome-print-preview-private.h	2 Sep 2002 06:12:37 -0000	1.6
+++ libgnomeprintui/gnome-print-preview-private.h	17 Dec 2002 01:54:46 -0000
@@ -51,8 +51,17 @@
 
 struct _GnomePrintPreviewClass {
 	GnomePrintContextClass parent_class;
 };
 
+#define GPP_COLOR_RGBA(color, ALPHA)              \
+             	((guint32) (ALPHA               | \
+                (((color).red   / 256) << 24)   | \
+                (((color).green / 256) << 16)   | \
+                (((color).blue  / 256) << 8)))
+
+void gnome_print_preview_theme_compliance (GnomePrintPreview *pp,
+					   gboolean strict);
+
 G_END_DECLS
 
 #endif /* __GNOME_PRINT_PREVIEW_PRIVATE_H__ */
Index: libgnomeprintui/gnome-print-preview.c
===================================================================
RCS file: /cvs/gnome/libgnomeprintui/libgnomeprintui/gnome-print-preview.c,v
retrieving revision 1.70
diff -u -5 -r1.70 gnome-print-preview.c
--- libgnomeprintui/gnome-print-preview.c	6 Sep 2002 06:01:29 -0000	1.70
+++ libgnomeprintui/gnome-print-preview.c	17 Dec 2002 01:54:46 -0000
@@ -27,14 +27,14 @@
 #include <config.h>
 
 #include <string.h>
 #include <math.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
-#include <gtk/gtksignal.h>
 
 #include <libgnomecanvas/gnome-canvas-clipgroup.h>
 #include <libgnomeprint/private/gp-gc-private.h>
+#include <libgnomeprint/private/gnome-glyphlist-private.h>
 
 #include "gnome-canvas-hacktext.h"
 #include "gnome-print-preview-private.h"
 
 struct _GnomePrintPreviewPrivate {
@@ -47,10 +47,13 @@
 	/* The root group, with a translation setup */
 	GnomeCanvasItem *root;
 
 	/* The current page */
 	GnomeCanvasItem *page;
+
+	/* Strict theme compliance [#96802] */
+	gboolean theme_compliance; 
 };
 
 static GnomePrintContextClass *parent_class;
 
 static int
@@ -59,29 +62,38 @@
 	GnomePrintPreview *pp = GNOME_PRINT_PREVIEW (pc);
 	GnomePrintPreviewPrivate *priv = pp->priv;
 	GnomeCanvasGroup *group;
 	GnomeCanvasItem *item;
 	GnomeCanvasPathDef *path;
+	guint color;
 
 	/* fixme: currentpath invariants */
 
 	group = (GnomeCanvasGroup *) gp_gc_get_data (priv->gc);
 	g_assert (group != NULL);
 	g_assert (GNOME_IS_CANVAS_GROUP (group));
 
 	path = gnome_canvas_path_def_new_from_foreign_bpath ((ArtBpath *) bpath);
 
+	if (pp->priv->theme_compliance) {
+		GtkStyle *style;
+		style = gtk_widget_get_style (GTK_WIDGET (pp->canvas));
+		color = GPP_COLOR_RGBA (style->text [GTK_STATE_NORMAL], 0xff);
+	} else {
+		color = gp_gc_get_rgba (pc->gc);
+	}
+	
 	/* Fixme: Can we assume that linewidth == width_units? */
 	/* Probably yes, as object->page ctm == identity */
 
 	item = gnome_canvas_item_new (group,
 		gnome_canvas_bpath_get_type (),
 		"bpath",	path,
 		"width_units",	gp_gc_get_linewidth (pc->gc),
 		"cap_style",	gp_gc_get_linecap (pc->gc),
 		"join_style",	gp_gc_get_linejoin (pc->gc),
-		"outline_color_rgba", gp_gc_get_rgba (pc->gc),
+		"outline_color_rgba", color,
 		"miterlimit",	gp_gc_get_miterlimit (pc->gc),
 		"dash",		gp_gc_get_dash (pc->gc),
 		NULL);
 
 	gnome_canvas_path_def_unref (path);
@@ -95,25 +107,34 @@
 	GnomePrintPreview *pp;
 	GnomePrintPreviewPrivate * priv;
 	GnomeCanvasGroup *group;
 	GnomeCanvasItem *item;
 	GnomeCanvasPathDef *path;
+	guint32 color;
 	
 	pp = GNOME_PRINT_PREVIEW (pc);
 	priv = pp->priv;
 
 	group = (GnomeCanvasGroup *) gp_gc_get_data (priv->gc);
 	g_assert (group != NULL);
 	g_assert (GNOME_IS_CANVAS_GROUP (group));
 
 	path = gnome_canvas_path_def_new_from_foreign_bpath ((ArtBpath *) bpath);
 
+	if (pp->priv->theme_compliance) {
+		GtkStyle *style;
+		style = gtk_widget_get_style (GTK_WIDGET (pp->canvas));
+		color = GPP_COLOR_RGBA (style->text [GTK_STATE_NORMAL], 0xff);
+	} else {
+		color = gp_gc_get_rgba (pc->gc);
+	}
+
 	item = gnome_canvas_item_new (group,
 		gnome_canvas_bpath_get_type (),
 		"bpath", path,
 		"outline_color", NULL,
-		"fill_color_rgba", gp_gc_get_rgba (pc->gc),
+		"fill_color_rgba", color,
 		"wind", rule,
 		NULL);
 
 	gnome_canvas_path_def_unref (path);
 
@@ -272,10 +293,21 @@
 	art_affine_scale (a, 1.0, -1.0);
 	art_affine_multiply (transform, a, affine);
 
 	group = (GnomeCanvasGroup *) gp_gc_get_data (pp->priv->gc);
 
+	if (pp->priv->theme_compliance) {
+		GtkStyle *style;
+		gint32 color;
+		gint i;
+		style = gtk_widget_get_style (GTK_WIDGET (pp->canvas));
+		color = GPP_COLOR_RGBA (style->text [GTK_STATE_NORMAL], 0xff);
+		for (i = glyphlist->r_length - 1; i >= 0; i--)
+			if (glyphlist->rules[i].code == GGL_COLOR)
+				glyphlist->rules[i].value.color = color;
+	}
+	
 	item = gnome_canvas_item_new (group,
 				      gnome_canvas_hacktext_get_type (),
 				      "x", 0.0,
 				      "y", 0.0,
 				      "glyphlist", glyphlist,
@@ -372,10 +404,17 @@
 clear_val (GtkObject *object, void **val)
 {
 	*val = NULL;
 }
 
+void
+gnome_print_preview_theme_compliance (GnomePrintPreview *pp,
+				      gboolean compliance)
+{
+	pp->priv->theme_compliance = compliance;
+}
+
 GnomePrintContext *
 gnome_print_preview_new_full (GnomePrintConfig *config, GnomeCanvas *canvas,
 			      const gdouble *transform, const ArtDRect *region)
 {
 	GnomePrintPreview *preview;
@@ -391,10 +430,11 @@
 
 	ctx = g_object_new (GNOME_TYPE_PRINT_PREVIEW, NULL);
 	ret = gnome_print_context_construct (ctx, config);
 	if (ret != GNOME_PRINT_OK) {
 		g_object_unref (ctx);
+		g_warning ("Could not construct the GnomePrintPreview context\n");
 		return NULL;
 	}
 	preview = GNOME_PRINT_PREVIEW (ctx);
 
 	g_object_ref (G_OBJECT (canvas));
