1
/*
2
 * Copyright © 2024 worldiety GmbH
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
 * worldiety not be used in advertising or publicity pertaining to
10
 * distribution of the software without specific, written prior
11
 * permission. worldiety 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
 * WORLDIETY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17
 * FITNESS, IN NO EVENT SHALL WORLDIETY 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
 * Author: Heiko Lewin <hlewin@worldiety.de>
24
 */
25
#include "cairo-test.h"
26

            
27
#define WIDTH  128
28
#define HEIGHT 64
29

            
30

            
31
static cairo_test_status_t
32
3
draw(cairo_t *cr, int width, int height) {
33
3
    cairo_glyph_t *glyphs = NULL;
34
3
    int num_glyphs = 0;
35
3
    cairo_path_t *path = NULL, *path2 = NULL;
36
    (void)width;
37
    (void)height;
38

            
39
    /* black on white color */
40
3
    cairo_set_source_rgb(cr, 1., 1., 1.);
41
3
    cairo_paint(cr);
42
3
    cairo_set_source_rgb(cr, 0, 0, 0);
43

            
44

            
45
    /* translate to some point well outside the surface */
46
3
    cairo_translate(cr, -width * 100, 0);
47

            
48
    /* create a simple path to illustrate the correct behaviour */
49
3
    cairo_rectangle(cr, 0, 0, width/2.0, 2);
50
3
    path = cairo_copy_path(cr);
51
3
    cairo_new_path(cr);
52

            
53
    /* create another path from glyphs - this is broken when clipping to early */
54
    {
55
3
        cairo_set_font_size(cr, 32);
56
3
        cairo_scaled_font_t *sf = cairo_get_scaled_font(cr);
57
3
        cairo_scaled_font_text_to_glyphs(sf, 0, 0, "Test", 4, &glyphs, &num_glyphs, 0, 0, 0);
58
3
        cairo_glyph_path(cr, glyphs, num_glyphs);
59
3
        path2 = cairo_copy_path(cr);
60
    }
61

            
62
    /* translate to a visible point and draw both paths */
63
3
    cairo_identity_matrix(cr);
64
3
    cairo_translate(cr, width/4.0, 48);
65

            
66
3
    cairo_append_path(cr, path);
67
3
    cairo_append_path(cr, path2);
68
3
    cairo_fill(cr);
69

            
70
3
    cairo_path_destroy(path);
71
3
    cairo_path_destroy(path2);
72
3
    free(glyphs);
73

            
74
3
    return CAIRO_TEST_SUCCESS;
75
}
76

            
77
1
CAIRO_TEST (glyph_path,
78
            "Tests cairo_glyph_path",
79
            "text, glyph, path", /* keywords */
80
            "target=raster", /* should be enough */
81
            WIDTH, HEIGHT,
82
            NULL, draw)