Set font options in the test context and make tests not do that

This should help with not requiring many backend-specific reference
images, and some should be removed now.
This commit is contained in:
Behdad Esfahbod 2006-07-31 15:17:15 -04:00
parent 9fcb3c32c1
commit 2fa709d6af
18 changed files with 19 additions and 116 deletions

View file

@ -1481,6 +1481,7 @@ cairo_test_for_target (cairo_test_t *test,
char *format;
cairo_test_status_t ret;
cairo_content_t expected_content;
cairo_font_options_t *font_options;
/* Get the strings ready that we'll need. */
format = _cairo_test_content_name (target->content);
@ -1567,6 +1568,15 @@ cairo_test_for_target (cairo_test_t *test,
cairo_paint (cr);
cairo_restore (cr);
/* Set all components of font_options to avoid backend differences
* and reduce number of needed reference images. */
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_ON);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
status = (test->draw) (cr, test->width, test->height);
/* Then, check all the different ways it could fail. */

View file

@ -144,7 +144,6 @@ draw (cairo_t *cr, int width, int height)
{
int j, x, y;
cairo_operator_t op;
cairo_font_options_t *font_options;
cairo_pattern_t *pattern;
cairo_select_font_face (cr, "Bitstream Vera Sans",
@ -152,14 +151,6 @@ draw (cairo_t *cr, int width, int height)
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 0.9 * HEIGHT);
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) {
for (op = CAIRO_OPERATOR_CLEAR; op < N_OPERATORS; op++) {
x = op * (WIDTH + PAD) + PAD;

View file

@ -64,7 +64,6 @@ box_text (cairo_t *cr, const char *utf8, double x, double y)
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
cairo_font_options_t *font_options;
cairo_text_extents_t extents;
cairo_matrix_t matrix;
@ -76,14 +75,6 @@ draw (cairo_t *cr, int width, int height)
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, TEXT_SIZE);
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
cairo_translate (cr, PAD, PAD);
cairo_set_line_width (cr, 1.0);

View file

@ -80,6 +80,8 @@ draw (cairo_t *cr, int width, int height)
font_options = cairo_font_options_create ();
cairo_get_font_options (cr, font_options);
scaled_font = cairo_scaled_font_create (font_face,
&font_matrix,
&ctm,

View file

@ -55,8 +55,7 @@ create_scaled_font (cairo_t * cr)
font_options = cairo_font_options_create ();
/* disable hinting */
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_get_font_options (cr, font_options);
pattern = FcPatternCreate ();

View file

@ -55,10 +55,7 @@ create_scaled_font (cairo_t * cr)
font_options = cairo_font_options_create ();
/* disable hinting */
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
/* enable antialias and override screen settings */
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
cairo_get_font_options (cr, font_options);
pattern = FcPatternCreate ();

View file

@ -61,8 +61,6 @@ cairo_test_t test = {
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
cairo_font_options_t *font_options;
/* We draw in the default black, so paint white first. */
cairo_save (cr);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
@ -76,14 +74,6 @@ draw (cairo_t *cr, int width, int height)
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, TEXT_SIZE);
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
cairo_set_source_rgb (cr, 0, 0, 0); /* black */
cairo_move_to (cr, 1, TEXT_SIZE);

View file

@ -159,21 +159,12 @@ static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
int i, j, x, y;
cairo_font_options_t *font_options;
cairo_pattern_t *pattern;
cairo_select_font_face (cr, "Bitstream Vera Sans",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) {
for (i = 0; i < ARRAY_SIZE (pattern_funcs); i++) {
x = i * (WIDTH + PAD) + PAD;

View file

@ -198,21 +198,12 @@ static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
int i, j, x, y;
cairo_font_options_t *font_options;
cairo_pattern_t *pattern;
cairo_select_font_face (cr, "Bitstream Vera Sans",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) {
for (i = 0; i < ARRAY_SIZE (pattern_funcs); i++) {
x = i * (WIDTH + PAD) + PAD;

View file

@ -39,23 +39,12 @@ cairo_test_t test = {
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
cairo_font_options_t *font_options;
/* We draw in the default black, so paint white first. */
cairo_save (cr);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
cairo_paint (cr);
cairo_restore (cr);
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
cairo_set_source_rgb (cr, 0, 0, 0); /* black */
cairo_select_font_face (cr, "Bitstream Vera Serif",

View file

@ -91,7 +91,6 @@ static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
cairo_glyph_t glyphs[NUM_GLYPHS];
cairo_font_options_t *font_options;
int i;
/* Initialize our giant array of glyphs. */
@ -110,14 +109,6 @@ draw (cairo_t *cr, int width, int height)
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, TEXT_SIZE);
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
cairo_show_glyphs (cr, glyphs, NUM_GLYPHS);
return CAIRO_TEST_SUCCESS;

View file

@ -39,8 +39,6 @@ cairo_test_t test = {
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
cairo_font_options_t *font_options;
/* We draw in the default black, so paint white first. */
cairo_save (cr);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
@ -52,14 +50,6 @@ draw (cairo_t *cr, int width, int height)
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, TEXT_SIZE);
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
cairo_set_source_rgb (cr, 0, 0, 0); /* black */
cairo_move_to (cr, 0, TEXT_SIZE);

View file

@ -57,12 +57,9 @@ draw (cairo_t *cr, int width, int height)
cairo_set_font_size (cr, TEXT_SIZE);
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_get_font_options (cr, font_options);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
cairo_set_source_rgb (cr, 0, 0, 0); /* black */
cairo_text_extents (cr, black, &extents);

View file

@ -57,12 +57,9 @@ draw (cairo_t *cr, int width, int height)
cairo_set_font_size (cr, TEXT_SIZE);
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_get_font_options (cr, font_options);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_NONE);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
cairo_set_source_rgb (cr, 0, 0, 0); /* black */
cairo_text_extents (cr, black, &extents);

View file

@ -53,16 +53,12 @@ draw (cairo_t *cr, int width, int height)
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, TEXT_SIZE);
/* Sub-pixel antialiasing with unhinted glyphs can be pretty ugly
* (bad color fringing). The reason we turn off hints here is to
* try to get repeatable glyph shapes on multiple systems, not for
* any aesthetic reason. */
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_get_font_options (cr, font_options);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_SUBPIXEL);
cairo_font_options_set_subpixel_order (font_options, CAIRO_SUBPIXEL_ORDER_RGB);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
cairo_set_source_rgb (cr, 0, 0, 0); /* black */

View file

@ -40,17 +40,8 @@ cairo_test_t test = {
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
cairo_font_options_t *font_options;
cairo_pattern_t *pat;
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
cairo_select_font_face (cr, "Bitstream Vera Sans",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);

View file

@ -110,9 +110,8 @@ draw (cairo_t *cr, int width, int height)
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_get_font_options (cr, font_options);
cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);

View file

@ -145,21 +145,12 @@ static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
int i, j, x, y;
cairo_font_options_t *font_options;
cairo_pattern_t *pattern;
cairo_select_font_face (cr, "Bitstream Vera Sans",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
cairo_set_font_options (cr, font_options);
cairo_font_options_destroy (font_options);
for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) {
for (i = 0; i < ARRAY_SIZE (operators); i++) {
x = i * (WIDTH + PAD) + PAD;