2 * Copyright © 2005 Red Hat, Inc.
3 * Copyright © 2011 Uli Schlachter
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.
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.
24 * Author: Uli Schlachter <psychon@znc.in>
26 * Based on test/text-antialias.c
27 * Author: Carl D. Worth <cworth@cworth.org>
30 #include "cairo-test.h"
36 static cairo_test_status_t
37 draw (cairo_t *cr, cairo_subpixel_order_t order)
39 cairo_text_extents_t extents;
40 cairo_font_options_t *font_options;
41 const char black[] = "black", blue[] = "blue";
43 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
46 cairo_select_font_face (cr, CAIRO_TEST_FONT_FAMILY " Sans",
47 CAIRO_FONT_SLANT_NORMAL,
48 CAIRO_FONT_WEIGHT_NORMAL);
49 cairo_set_font_size (cr, TEXT_SIZE);
51 font_options = cairo_font_options_create ();
52 cairo_get_font_options (cr, font_options);
53 cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_SUBPIXEL);
54 cairo_font_options_set_subpixel_order (font_options, order);
55 cairo_set_font_options (cr, font_options);
57 cairo_font_options_destroy (font_options);
59 cairo_set_source_rgb (cr, 0, 0, 0); /* black */
60 cairo_text_extents (cr, black, &extents);
61 cairo_move_to (cr, -extents.x_bearing, -extents.y_bearing);
62 cairo_show_text (cr, black);
63 cairo_translate (cr, 0, -extents.y_bearing + 1);
65 cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
66 cairo_text_extents (cr, blue, &extents);
67 cairo_move_to (cr, -extents.x_bearing, -extents.y_bearing);
68 cairo_show_text (cr, blue);
70 return CAIRO_TEST_SUCCESS;
73 static cairo_test_status_t
74 draw_rgb (cairo_t *cr, int width, int height)
76 return draw (cr, CAIRO_SUBPIXEL_ORDER_RGB);
79 static cairo_test_status_t
80 draw_bgr (cairo_t *cr, int width, int height)
82 return draw (cr, CAIRO_SUBPIXEL_ORDER_BGR);
85 static cairo_test_status_t
86 draw_vrgb (cairo_t *cr, int width, int height)
88 return draw (cr, CAIRO_SUBPIXEL_ORDER_VRGB);
91 static cairo_test_status_t
92 draw_vbgr (cairo_t *cr, int width, int height)
94 return draw (cr, CAIRO_SUBPIXEL_ORDER_VBGR);
97 CAIRO_TEST (text_antialias_subpixel_rgb,
98 "Tests text rendering with rgb subpixel antialiasing",
99 "text", /* keywords */
100 "target=raster", /* requirements */
104 CAIRO_TEST (text_antialias_subpixel_bgr,
105 "Tests text rendering with bgr subpixel antialiasing",
106 "text", /* keywords */
107 "target=raster", /* requirements */
111 CAIRO_TEST (text_antialias_subpixel_vrgb,
112 "Tests text rendering with vertical rgb subpixel antialiasing",
113 "text", /* keywords */
114 "target=raster", /* requirements */
118 CAIRO_TEST (text_antialias_subpixel_vbgr,
119 "Tests text rendering with vertical bgr subpixel antialiasing",
120 "text", /* keywords */
121 "target=raster", /* requirements */