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

            
30
#include "cairo-test.h"
31

            
32
#define WIDTH  31
33
#define HEIGHT 22
34
#define TEXT_SIZE 12
35

            
36
static cairo_test_status_t
37
12
draw (cairo_t *cr, cairo_subpixel_order_t order)
38
{
39
    cairo_text_extents_t extents;
40
    cairo_font_options_t *font_options;
41
12
    const char black[] = "black", blue[] = "blue";
42

            
43
12
    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
44
12
    cairo_paint (cr);
45

            
46
12
    cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans",
47
			    CAIRO_FONT_SLANT_NORMAL,
48
			    CAIRO_FONT_WEIGHT_NORMAL);
49
12
    cairo_set_font_size (cr, TEXT_SIZE);
50

            
51
12
    font_options = cairo_font_options_create ();
52
12
    cairo_get_font_options (cr, font_options);
53
12
    cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_SUBPIXEL);
54
12
    cairo_font_options_set_subpixel_order (font_options, order);
55
12
    cairo_set_font_options (cr, font_options);
56

            
57
12
    cairo_font_options_destroy (font_options);
58

            
59
12
    cairo_set_source_rgb (cr, 0, 0, 0); /* black */
60
12
    cairo_text_extents (cr, black, &extents);
61
12
    cairo_move_to (cr, -extents.x_bearing, -extents.y_bearing);
62
12
    cairo_show_text (cr, black);
63
12
    cairo_translate (cr, 0, -extents.y_bearing + 1);
64

            
65
12
    cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
66
12
    cairo_text_extents (cr, blue, &extents);
67
12
    cairo_move_to (cr, -extents.x_bearing, -extents.y_bearing);
68
12
    cairo_show_text (cr, blue);
69

            
70
12
    return CAIRO_TEST_SUCCESS;
71
}
72

            
73
static cairo_test_status_t
74
3
draw_rgb (cairo_t *cr, int width, int height)
75
{
76
3
    return draw (cr, CAIRO_SUBPIXEL_ORDER_RGB);
77
}
78

            
79
static cairo_test_status_t
80
3
draw_bgr (cairo_t *cr, int width, int height)
81
{
82
3
    return draw (cr, CAIRO_SUBPIXEL_ORDER_BGR);
83
}
84

            
85
static cairo_test_status_t
86
3
draw_vrgb (cairo_t *cr, int width, int height)
87
{
88
3
    return draw (cr, CAIRO_SUBPIXEL_ORDER_VRGB);
89
}
90

            
91
static cairo_test_status_t
92
3
draw_vbgr (cairo_t *cr, int width, int height)
93
{
94
3
    return draw (cr, CAIRO_SUBPIXEL_ORDER_VBGR);
95
}
96

            
97
1
CAIRO_TEST (text_antialias_subpixel_rgb,
98
	    "Tests text rendering with rgb subpixel antialiasing",
99
	    "text", /* keywords */
100
	    "target=raster", /* requirements */
101
	    WIDTH, HEIGHT,
102
	    NULL, draw_rgb)
103

            
104
1
CAIRO_TEST (text_antialias_subpixel_bgr,
105
	    "Tests text rendering with bgr subpixel antialiasing",
106
	    "text", /* keywords */
107
	    "target=raster", /* requirements */
108
	    WIDTH, HEIGHT,
109
	    NULL, draw_bgr)
110

            
111
1
CAIRO_TEST (text_antialias_subpixel_vrgb,
112
	    "Tests text rendering with vertical rgb subpixel antialiasing",
113
	    "text", /* keywords */
114
	    "target=raster", /* requirements */
115
	    WIDTH, HEIGHT,
116
	    NULL, draw_vrgb)
117

            
118
1
CAIRO_TEST (text_antialias_subpixel_vbgr,
119
	    "Tests text rendering with vertical bgr subpixel antialiasing",
120
	    "text", /* keywords */
121
	    "target=raster", /* requirements */
122
	    WIDTH, HEIGHT,
123
	    NULL, draw_vbgr)