summaryrefslogtreecommitdiff
path: root/test/ft-svg-render-color.c
blob: c7572d5b0ef78da5ace1a85c1d1f9a95c395714c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright © 2023 Adrian Johnson
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * Author: Adrian Johnson <ajohnson@redneon.com>
 */

#include "cairo-test.h"
#include <cairo-ft.h>

#define FONT_SIZE 50
#define MARGIN 5
#define WIDTH  (FONT_SIZE*8 + MARGIN*9)
#define HEIGHT (FONT_SIZE*2 + MARGIN*3)

#define FONT_FILE "cairo-svg-test-color.ttf"

#define PALETTE_TEXT     "01"
#define FOREGROUND_TEXT  "234567"


static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_test_status_t result;
    cairo_font_options_t *font_options;

    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);
    cairo_set_source_rgb (cr, 0, 0, 0);

    result = cairo_test_ft_select_font_from_file (cr, FONT_FILE);
    if (result)
        return result;

    cairo_set_font_size (cr, FONT_SIZE);
    
    cairo_save (cr);
    cairo_move_to (cr, MARGIN, FONT_SIZE + MARGIN);
    font_options = cairo_font_options_create ();

    /* Default palette */
    cairo_show_text (cr, PALETTE_TEXT);

    /* Palette 1 */
    cairo_font_options_set_color_palette (font_options, 1);
    cairo_set_font_options (cr, font_options);
    cairo_show_text (cr, PALETTE_TEXT);

    /* Palette 0, override color 0 */
    cairo_font_options_set_color_palette (font_options, 0);
    cairo_font_options_set_custom_palette_color (font_options, 0, 1, 0, 1, 0.5);
    cairo_set_font_options (cr, font_options);
    cairo_show_text (cr, PALETTE_TEXT);

    /* Palette 1, override color 1 */
    cairo_font_options_set_color_palette (font_options, 1);
    cairo_font_options_set_custom_palette_color (font_options, 1, 0, 1, 1, 0.5);
    cairo_set_font_options (cr, font_options);
    cairo_show_text (cr, PALETTE_TEXT);

    cairo_font_options_destroy (font_options);
    cairo_restore (cr);

    cairo_move_to (cr, MARGIN, FONT_SIZE*2 + MARGIN*2);

    cairo_set_source_rgb (cr, 0, 1, 0);
    cairo_show_text (cr, FOREGROUND_TEXT);

    
    return CAIRO_TEST_SUCCESS;
}

CAIRO_TEST (ft_svg_render_color,
	    "Test cairo SVG font colors",
	    "svgrender", /* keywords */
	    NULL, /* requirements */
	    WIDTH, HEIGHT,
	    NULL, draw)