1
/*
2
 * Copyright © 2022 Behdad Esfahbod
3
 *
4
 * Permission to use, copy, modify, distribute, and sell this software
5
 * and its documentation for any purpose is hereby granted without
6
 * fee, provided that the above copyright notice appear in all copies
7
 * and that both that copyright notice and this permission notice
8
 * appear in supporting documentation, and that the name of
9
 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10
 * distribution of the software without specific, written prior
11
 * permission. Red Hat, Inc. makes no representations about the
12
 * suitability of this software for any purpose.  It is provided "as
13
 * is" without express or implied warranty.
14
 *
15
 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17
 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
18
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
 *
23
 * Contributor(s):
24
 *	Behdad Esfahbod <behdad@behdad.org>
25
 */
26

            
27
/* Test that user-fonts can subpixel positioning.
28
 */
29

            
30
#include "cairo-test.h"
31

            
32

            
33
#define BORDER 10
34
#define REPEAT 16
35
#define TEXT_SIZE 24
36
#define WIDTH  (TEXT_SIZE * REPEAT + 2*BORDER)
37
#define HEIGHT (TEXT_SIZE + 2*BORDER)
38

            
39

            
40
static cairo_status_t
41
12
test_scaled_font_render_glyph (cairo_scaled_font_t  *scaled_font,
42
			       unsigned long         glyph,
43
			       cairo_t              *cr,
44
			       cairo_text_extents_t *metrics)
45
{
46
12
    cairo_rectangle (cr, 0, .45, 1., .1);
47
12
    cairo_fill (cr);
48
12
    return CAIRO_STATUS_SUCCESS;
49
}
50

            
51
static cairo_font_face_t *
52
3
_user_font_face_create (void)
53
{
54
    cairo_font_face_t *user_font_face;
55

            
56
3
    user_font_face = cairo_user_font_face_create ();
57
3
    cairo_user_font_face_set_render_glyph_func (user_font_face, test_scaled_font_render_glyph);
58

            
59
3
    return user_font_face;
60
}
61

            
62
static cairo_test_status_t
63
3
draw (cairo_t *cr, int width, int height)
64
{
65
    cairo_font_face_t *font_face;
66

            
67
3
    cairo_set_source_rgb (cr, 1, 1, 1);
68
3
    cairo_paint (cr);
69

            
70
3
    font_face = _user_font_face_create ();
71

            
72
3
    cairo_set_font_face (cr, font_face);
73
3
    cairo_font_face_destroy (font_face);
74

            
75
3
    cairo_set_source_rgb (cr, 0, 0, 0);
76
3
    cairo_set_font_size (cr, TEXT_SIZE);
77

            
78
51
    for (unsigned i = 0; i < REPEAT; i++)
79
    {
80
48
      cairo_move_to (cr, BORDER + TEXT_SIZE * i, BORDER + i * .1);
81
48
      cairo_show_text (cr, "-");
82
    }
83

            
84
3
    return CAIRO_TEST_SUCCESS;
85
}
86

            
87
1
CAIRO_TEST (user_font_subpixel,
88
	    "Tests user font subpixel rendering",
89
	    "font, user-font", /* keywords */
90
	    "cairo >= 1.17.4", /* requirements */
91
	    WIDTH, HEIGHT,
92
	    NULL, draw)