[librsvg/librsvg-2.40] Backport: Add a testing mode so reftests can use predictable text rendering
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/librsvg-2.40] Backport: Add a testing mode so reftests can use predictable text rendering
- Date: Wed, 4 Oct 2017 13:01:24 +0000 (UTC)
commit e659c14a5e1c5360cb7a81129b704935cf79cd1a
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Dec 19 11:49:17 2016 -0600
Backport: Add a testing mode so reftests can use predictable text rendering
From commit 25457b72770018045aa88d47688fbf1a45bff9af
This adds an rsvg_handle_internal_set_testing() API, which should only
be called by the test suite. Internally, it sets cairo_font_options_t
that should yield reproducible text rendering.
For example, I get different rendering results from text objects when I
run "make check" as a user, than when I run it as root.
rsvg-base.c | 16 ++++++++++++++++
rsvg-cairo-draw.c | 22 ++++++++++++++++++++++
rsvg-cairo-render.c | 1 +
rsvg-gobject.c | 2 ++
rsvg-private.h | 3 +++
rsvg.h | 2 ++
tests/rsvg-test.c | 2 ++
7 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index b421a91..247b06f 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -2094,6 +2094,22 @@ rsvg_handle_new_from_stream_sync (GInputStream *input_stream,
}
/**
+ * _rsvg_handle_internal_set_testing:
+ * @handle: a #RsvgHandle
+ * @testing: Whether to enable testing mode
+ *
+ * Do not call this function. This is intended for librsvg's internal
+ * test suite only.
+ **/
+void
+rsvg_handle_internal_set_testing (RsvgHandle *handle, gboolean testing)
+{
+ g_return_if_fail (RSVG_IS_HANDLE (handle));
+
+ handle->priv->is_testing = testing ? TRUE : FALSE;
+}
+
+/**
* rsvg_init:
*
* Initializes librsvg
diff --git a/rsvg-cairo-draw.c b/rsvg-cairo-draw.c
index 9e098fa..002e90f 100644
--- a/rsvg-cairo-draw.c
+++ b/rsvg-cairo-draw.c
@@ -366,6 +366,19 @@ _set_rsvg_affine (RsvgCairoRender * render, cairo_matrix_t *affine)
cairo_set_matrix (cr, &matrix);
}
+static cairo_font_options_t *
+get_font_options_for_testing (void)
+{
+ cairo_font_options_t *options;
+
+ options = cairo_font_options_create ();
+ cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_GRAY);
+ cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_FULL);
+ cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
+
+ return options;
+}
+
PangoContext *
rsvg_cairo_create_pango_context (RsvgDrawingCtx * ctx)
{
@@ -376,7 +389,16 @@ rsvg_cairo_create_pango_context (RsvgDrawingCtx * ctx)
fontmap = pango_cairo_font_map_get_default ();
context = pango_font_map_create_context (fontmap);
pango_cairo_update_context (render->cr, context);
+
pango_cairo_context_set_resolution (context, ctx->dpi_y);
+
+ if (ctx->is_testing) {
+ cairo_font_options_t *font_options;
+ font_options = get_font_options_for_testing ();
+ pango_cairo_context_set_font_options (context, font_options);
+ cairo_font_options_destroy (font_options);
+ }
+
return context;
}
diff --git a/rsvg-cairo-render.c b/rsvg-cairo-render.c
index e06a65a..46dfd74 100644
--- a/rsvg-cairo-render.c
+++ b/rsvg-cairo-render.c
@@ -154,6 +154,7 @@ rsvg_cairo_new_drawing_ctx (cairo_t * cr, RsvgHandle * handle)
draw->pango_context = NULL;
draw->drawsub_stack = NULL;
draw->acquired_nodes = NULL;
+ draw->is_testing = handle->priv->is_testing;
rsvg_state_push (draw);
state = rsvg_current_state (draw);
diff --git a/rsvg-gobject.c b/rsvg-gobject.c
index 2d9d273..2a4726c 100644
--- a/rsvg-gobject.c
+++ b/rsvg-gobject.c
@@ -93,6 +93,8 @@ rsvg_handle_init (RsvgHandle * self)
self->priv->is_disposed = FALSE;
self->priv->in_loop = FALSE;
+
+ self->priv->is_testing = FALSE;
}
static void
diff --git a/rsvg-private.h b/rsvg-private.h
index 68ab06e..85936d1 100644
--- a/rsvg-private.h
+++ b/rsvg-private.h
@@ -187,6 +187,8 @@ struct RsvgHandlePrivate {
gboolean in_loop; /* see get_dimension() */
GInputStream *compressed_input_stream; /* for rsvg_handle_write of svgz data */
+
+ gboolean is_testing; /* Are we being run from the test suite? */
};
typedef struct {
@@ -207,6 +209,7 @@ struct RsvgDrawingCtx {
GSList *vb_stack;
GSList *drawsub_stack;
GSList *acquired_nodes;
+ gboolean is_testing;
};
/*Abstract base class for context for our backends (one as yet)*/
diff --git a/rsvg.h b/rsvg.h
index 25b775a..e4350da 100644
--- a/rsvg.h
+++ b/rsvg.h
@@ -194,6 +194,8 @@ RsvgHandle *rsvg_handle_new_from_stream_sync (GInputStream *input_stream,
RsvgHandle *rsvg_handle_new_from_data (const guint8 * data, gsize data_len, GError ** error);
RsvgHandle *rsvg_handle_new_from_file (const gchar * file_name, GError ** error);
+void rsvg_handle_internal_set_testing (RsvgHandle *handle, gboolean testing);
+
/* BEGIN deprecated APIs. Do not use! */
#ifndef __GI_SCANNER__
diff --git a/tests/rsvg-test.c b/tests/rsvg-test.c
index 0969333..c4188b7 100644
--- a/tests/rsvg-test.c
+++ b/tests/rsvg-test.c
@@ -259,6 +259,8 @@ rsvg_cairo_check (gconstpointer data)
g_assert_no_error (error);
g_assert (rsvg != NULL);
+ rsvg_handle_internal_set_testing (rsvg, TRUE);
+
rsvg_handle_get_dimensions (rsvg, &dimensions);
g_assert (dimensions.width > 0);
g_assert (dimensions.height > 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]