Commit 25457b72 authored by Federico Mena Quintero's avatar Federico Mena Quintero

Add a testing mode so reftests can use predictable text rendering

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.
parent c742926a
......@@ -2142,6 +2142,22 @@ rsvg_handle_new_from_stream_sync (GInputStream *input_stream,
return handle;
}
/**
* _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:
*
......
......@@ -358,6 +358,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)
{
......@@ -373,6 +386,13 @@ rsvg_cairo_create_pango_context (RsvgDrawingCtx * ctx)
rsvg_drawing_ctx_get_dpi (ctx, NULL, &dpi_y);
pango_cairo_context_set_resolution (context, 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;
}
......
......@@ -160,6 +160,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);
......
......@@ -95,6 +95,8 @@ rsvg_handle_init (RsvgHandle * self)
self->priv->is_disposed = FALSE;
self->priv->in_loop = FALSE;
self->priv->is_testing = FALSE;
}
static void
......
......@@ -176,6 +176,8 @@ struct RsvgHandlePrivate {
gboolean first_write;
GInputStream *data_input_stream; /* for rsvg_handle_write of svgz data */
gboolean is_testing; /* Are we being run from the test suite? */
};
typedef struct {
......@@ -196,6 +198,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)*/
......
......@@ -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__
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment