1
/*
2
 * Copyright © 2005 Red Hat, Inc.
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
 * Author: Carl D. Worth <cworth@cworth.org>
24
 */
25

            
26
#include "cairo-test.h"
27

            
28
#include <stdio.h>
29

            
30
#include <cairo-svg.h>
31

            
32
/* Pretty boring test just to make sure things aren't crashing ---
33
 * no verification that we're getting good results yet.
34
 * But you can manually view the image to make sure it looks happy.
35
 */
36

            
37
#define WIDTH_IN_INCHES  3
38
#define HEIGHT_IN_INCHES 3
39
#define WIDTH_IN_POINTS  (WIDTH_IN_INCHES  * 72)
40
#define HEIGHT_IN_POINTS (HEIGHT_IN_INCHES * 72)
41
#define BASENAME "svg-surface.out"
42

            
43
static cairo_test_status_t
44
draw (cairo_t *cr, int width, int height)
45
{
46
#define STROKE_WIDTH .04
47

            
48
    double size;
49

            
50
    if (width > height)
51
	size = height;
52
    else
53
	size = width;
54

            
55
    cairo_translate (cr, (width - size) / 2.0, (height - size) / 2.0);
56
    cairo_scale (cr, size, size);
57

            
58
    /* Fill face */
59
    cairo_arc (cr, 0.5, 0.5, 0.5 - STROKE_WIDTH, 0, 2 * M_PI);
60
    cairo_set_source_rgb (cr, 1, 1, 0);
61
    cairo_save (cr);
62
    {
63
	cairo_fill (cr);
64
    }
65
    cairo_restore (cr);
66

            
67
    cairo_set_source_rgb (cr, 0, 0, 0);
68

            
69
    /* Stroke face */
70
    cairo_set_line_width (cr, STROKE_WIDTH / 2.0);
71
    cairo_stroke (cr);
72

            
73
    /* Eyes */
74
    cairo_set_line_width (cr, STROKE_WIDTH);
75
    cairo_arc (cr, 0.3, 0.4, STROKE_WIDTH, 0, 2 * M_PI);
76
    cairo_fill (cr);
77
    cairo_arc (cr, 0.7, 0.4, STROKE_WIDTH, 0, 2 * M_PI);
78
    cairo_fill (cr);
79

            
80
    /* Mouth */
81
    cairo_move_to (cr, 0.3, 0.7);
82
    cairo_curve_to (cr,
83
		    0.4, 0.8,
84
		    0.6, 0.8,
85
		    0.7, 0.7);
86
    cairo_stroke (cr);
87

            
88
    return CAIRO_TEST_SUCCESS;
89
}
90

            
91
static cairo_test_status_t
92
1
preamble (cairo_test_context_t *ctx)
93
{
94
    cairo_t *cr;
95
    cairo_surface_t *surface;
96
    char *filename;
97
1
    const char *path = cairo_test_mkdir (CAIRO_TEST_OUTPUT_DIR) ? CAIRO_TEST_OUTPUT_DIR : ".";
98

            
99
2
    if (! cairo_test_is_target_enabled (ctx, "svg11") &&
100
1
	! cairo_test_is_target_enabled (ctx, "svg12"))
101
    {
102
1
	return CAIRO_TEST_UNTESTED;
103
    }
104

            
105
    xasprintf (&filename, "%s/%s.svg", path, BASENAME);
106
    surface = cairo_svg_surface_create (filename,
107
					WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
108
    if (cairo_surface_status (surface)) {
109
	cairo_test_log (ctx,
110
			"Failed to create svg surface for file %s: %s\n",
111
			filename,
112
			cairo_status_to_string (cairo_surface_status (surface)));
113
	free (filename);
114
	return CAIRO_TEST_FAILURE;
115
    }
116

            
117
    cr = cairo_create (surface);
118

            
119
    draw (cr, WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
120

            
121
    cairo_show_page (cr);
122

            
123
    cairo_destroy (cr);
124
    cairo_surface_destroy (surface);
125

            
126
    printf ("svg-surface: Please check %s to make sure it looks happy.\n", filename);
127
    free (filename);
128
    return CAIRO_TEST_SUCCESS;
129
}
130

            
131
1
CAIRO_TEST (svg_surface,
132
	    "Check creation of a SVG surface",
133
	    "svg", /* keywords */
134
	    NULL, /* requirements */
135
	    0, 0,
136
	    preamble, NULL)