head 1.6; access; symbols; locks; strict; comment @ * @; 1.6 date 2005.08.05.06.05.40; author krh; state Exp; branches; next 1.5; commitid 473b42f301b04567; 1.5 date 2005.05.17.14.41.07; author cworth; state Exp; branches; next 1.4; commitid 789428a02834567; 1.4 date 2005.01.20.16.32.57; author cworth; state Exp; branches; next 1.3; 1.3 date 2003.11.04.14.14.07; author cworth; state Exp; branches; next 1.2; 1.2 date 2003.11.03.21.36.28; author cworth; state Exp; branches; next 1.1; 1.1 date 2003.11.01.05.59.13; author cworth; state Exp; branches; next ; desc @@ 1.6 log @2005-08-05 Kristian Høgsberg * basket.c (main): Add cairo_surface_destroy() to make sure we write finish the PS file properly (from Adrian Johnson). @ text @/* * Copyright © 2003 USC, Information Sciences Institute * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without * fee, provided that the above copyright notice appear in all copies * and that both that copyright notice and this permission notice * appear in supporting documentation, and that the name of the * University of Southern California not be used in advertising or * publicity pertaining to distribution of the software without * specific, written prior permission. The University of Southern * California makes no representations about the suitability of this * software for any purpose. It is provided "as is" without express * or implied warranty. * * THE UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF * SOUTHERN CALIFORNIA BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Author: Carl D. Worth */ #include #include #include void draw (cairo_t *cr); #define X_INCHES 8 #define Y_INCHES 3 #define FILENAME "basket.ps" int main (void) { cairo_surface_t *surface; cairo_t *cr; FILE *file; file = fopen (FILENAME, "w"); if (file == NULL) { fprintf (stderr, "Failed to open file %s for writing.\n", FILENAME); return 1; } surface = cairo_ps_surface_create (FILENAME, X_INCHES * 72.0, Y_INCHES * 72.0); cr = cairo_create (surface); cairo_surface_destroy(surface); draw (cr); cairo_show_page (cr); cairo_destroy (cr); fclose (file); return 0; } void draw (cairo_t *cr) { cairo_move_to (cr, 50, 50); cairo_line_to (cr, 550, 50); cairo_curve_to (cr, 450, 240, 150, 240, 50, 50); cairo_close_path (cr); cairo_save (cr); cairo_set_source_rgb (cr, .8, .1, .1); cairo_fill_preserve (cr); cairo_restore (cr); cairo_set_line_width (cr, 6); cairo_set_source_rgb (cr, 0., 0., 0.); cairo_stroke (cr); } @ 1.5 log @ * Makefile: * basket.c: (main), (draw): * write_png.c: Update to latest cairo API changes. @ text @d58 1 @ 1.4 log @ * basket.c: Track split-up of cairo.h. @ text @a31 2 #include "write_png.h" d35 2 a36 10 #define WIDTH 600 #define HEIGHT 250 #define STRIDE (WIDTH*4) #define X_INCHES (WIDTH / 96.0) #define Y_INCHES (HEIGHT / 96.0) #define X_PPI 300.0 #define Y_PPI 300.0 char image[STRIDE*HEIGHT]; d43 1 a45 1 int i; d53 3 a55 1 cr = cairo_create (); d57 1 a57 1 cairo_set_target_image (cr, image, CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT, STRIDE); d60 1 a60 14 write_png_argb32 (image, "basket.png", WIDTH, HEIGHT, STRIDE); cairo_set_target_ps (cr, file, X_INCHES, Y_INCHES, X_PPI, Y_PPI); for (i = 0; i <= 5 ; i++) { draw (cr); if (i == 0) cairo_copy_page (cr); cairo_show_page (cr); cairo_rotate (cr, - M_PI / 10.0); cairo_translate (cr, 50, 100); cairo_scale (cr, .5, .5); } d78 2 a79 2 cairo_set_rgb_color (cr, .8, .1, .1); cairo_fill (cr); d83 1 a83 1 cairo_set_rgb_color (cr, 0., 0., 0.); a85 1 @ 1.3 log @Add a loop so that the PostScript output has more than one page. @ text @d29 1 @ 1.2 log @Increased page size and borders so the figure doesn't land in the unprintable regions near the paper edge. @ text @d29 1 d54 1 d64 1 a64 1 cairo_set_target_ps (cr, file, X_INCHES, Y_INCHES, X_PPI, Y_PPI); d68 1 a68 1 cairo_show_page (cr); d70 1 a70 1 cairo_set_target_image (cr, image, CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT, STRIDE); d72 9 a80 3 draw (cr); write_png_argb32 (image, "basket.png", WIDTH, HEIGHT, STRIDE); a85 2 FcFini (); @ 1.1 log @Initial import of basket example. @ text @d35 2 a36 2 #define WIDTH 520 #define HEIGHT 170 d86 3 a88 3 cairo_move_to (cr, 10, 10); cairo_line_to (cr, 510, 10); cairo_curve_to (cr, 410, 200, 110, 200, 10, 10); @