head 1.9; access; symbols; locks; strict; comment @ * @; 1.9 date 2005.07.29.07.48.07; author behdad; state Exp; branches; next 1.8; commitid 284a42e9df0e4567; 1.8 date 2005.05.17.15.24.39; author cworth; state Exp; branches; next 1.7; commitid 22b4428a0cb74567; 1.7 date 2005.05.17.14.31.43; author cworth; state Exp; branches; next 1.6; commitid 2e0428a004e4567; 1.6 date 2005.04.02.04.20.39; author cworth; state Exp; branches; next 1.5; 1.5 date 2004.05.11.14.52.19; author pippin; state Exp; branches; next 1.4; 1.4 date 2004.04.06.20.08.20; author davidr; state Exp; branches; next 1.3; 1.3 date 2003.12.11.15.09.12; author cworth; state Exp; branches; next 1.2; 1.2 date 2003.09.04.13.54.29; author cworth; state Exp; branches; next 1.1; 1.1 date 2003.08.18.18.11.38; author cworth; state Exp; branches; next ; desc @@ 1.9 log @2005-07-29 Behdad Esfahbod */ #include void draw_outlines (cairo_t *cr, int surface_width, int surface_height); void draw_flat (cairo_t *cr, double width, double height); void draw_tent (cairo_t *cr, double width, double height); void draw_cylinder (cairo_t *cr, double width, double height); cairo_pattern_t * create_gradient (double width, double height); #define WIDTH 750 #define HEIGHT 500 #define STRIDE (WIDTH * 4) unsigned char image[STRIDE*HEIGHT]; int main (void) { cairo_surface_t *surface; cairo_t *cr; surface = cairo_image_surface_create_for_data (image, CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT, STRIDE); cr = cairo_create (surface); cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT); cairo_set_source_rgb (cr, 1, 1, 1); cairo_fill (cr); draw_outlines (cr, WIDTH, HEIGHT); cairo_surface_write_to_png (surface, "outline.png"); cairo_destroy (cr); cairo_surface_destroy (surface); return 0; } cairo_pattern_t * create_gradient (double width, double height) { cairo_pattern_t *gradient; gradient = cairo_pattern_create_linear (0, 0, width, 0); cairo_pattern_add_color_stop_rgb (gradient, 0.0, 0., 0., 0.); cairo_pattern_add_color_stop_rgb (gradient, 0.5, 1., 1., 1.); cairo_pattern_add_color_stop_rgb (gradient, 1.0, 0., 0., 0.); return gradient; } void draw_outlines (cairo_t *cr, int surface_width, int surface_height) { cairo_pattern_t *gradient; double width, height, pad; width = surface_width / 4.0; pad = (surface_width - (3 * width)) / 2.0; height = surface_height; gradient = create_gradient (width, height); cairo_set_source (cr, gradient); draw_flat (cr, width, height); cairo_translate (cr, width + pad, 0); cairo_set_source (cr, gradient); draw_tent (cr, width, height); cairo_translate (cr, width + pad, 0); cairo_set_source (cr, gradient); draw_cylinder (cr, width, height); cairo_restore (cr); cairo_pattern_destroy (gradient); } void draw_flat (cairo_t *cr, double width, double height) { double hwidth = width / 2.0; cairo_rectangle (cr, 0, hwidth, width, height - hwidth); cairo_fill (cr); } void draw_tent (cairo_t *cr, double width, double height) { double hwidth = width / 2.0; cairo_move_to (cr, 0, hwidth); cairo_rel_line_to (cr, hwidth, -hwidth); cairo_rel_line_to (cr, hwidth, hwidth); cairo_rel_line_to (cr, 0, height - hwidth); cairo_rel_line_to (cr, -hwidth, -hwidth); cairo_rel_line_to (cr, -hwidth, hwidth); cairo_close_path (cr); cairo_fill (cr); } void draw_cylinder (cairo_t *cr, double width, double height) { double hwidth = width / 2.0; cairo_move_to (cr, 0, hwidth); cairo_rel_curve_to (cr, 0, -hwidth, width, -hwidth, width, 0); cairo_rel_line_to (cr, 0, height - hwidth); cairo_rel_curve_to (cr, 0, -hwidth, -width, -hwidth, -width, 0); cairo_close_path (cr); cairo_fill (cr); } @ 1.8 log @ * bevels.c: * caps_joins.c: * hering.c: * outline.c: * snapping.c: * spiral.c: * splines_tolerance.c: * star_and_ring.c: * stars.c: * text-rotate.c: * text.c: Remove stale includes of write_png.h. @ text @d43 1 a43 1 create_gradient (cairo_t *cr, double width, double height); d77 1 a77 1 create_gradient (cairo_t *cr, double width, double height) d105 1 a105 1 gradient = create_gradient (cr, width, height); @ 1.7 log @ * Makefile: * bevels.c: (set_hex_color), (main): * caps_joins.c: (main), (stroke_v_twice), (draw_caps_joins): * hering.c: (main), (draw_hering): * outline.c: (main), (create_gradient), (draw_outlines): * snapping.c: (snap_point_for_fill), (snap_point_for_stroke), (snap_line_width), (snap_path_for_fill), (snap_path_for_stroke), (draw_nested), (main): * spiral.c: (main), (draw_spiral): * splines_tolerance.c: (main), (draw_splines): * star_and_ring.c: (star_path), (fill_ring), (fill_star), (main): * stars.c: (main), (draw_stars): * text-rotate.c: (main): * text.c: (box_text), (box_glyphs), (main): Update all programs to match recent cairo API changes. @ text @a29 2 #include "write_png.h" @ 1.6 log @ * caps_joins.c: * hering.c: * outline.c: * spiral.c: * splines_tolerance.c: * stars.c: * text-rotate.c: * text.c: * write_png.c: * write_png.h: Convert file encodings to utf-8. @ text @d51 1 a51 1 char image[STRIDE*HEIGHT]; d56 1 d59 3 a61 4 cr = cairo_create (); cairo_set_target_image (cr, image, CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT, STRIDE); d64 1 a64 1 cairo_set_rgb_color (cr, 1, 1, 1); d69 1 a69 1 write_png_argb32 (image, "outline.png", WIDTH, HEIGHT, STRIDE); d73 2 d81 1 a81 14 cairo_surface_t *gradient; cairo_matrix_t *matrix; cairo_pattern_t *gradient_pattern; cairo_save (cr); gradient = cairo_surface_create_similar (cairo_current_target_surface (cr), CAIRO_FORMAT_ARGB32, 3, 2); cairo_set_target_surface (cr, gradient); cairo_set_rgb_color (cr, 0, 0, 0); cairo_rectangle (cr, 0, 0, 1, 2); cairo_fill (cr); d83 1 a83 3 cairo_set_rgb_color (cr, 1, 1, 1); cairo_rectangle (cr, 1, 0, 1, 2); cairo_fill (cr); d85 2 a86 3 cairo_set_rgb_color (cr, 0, 0, 0); cairo_rectangle (cr, 2, 0, 1, 2); cairo_fill (cr); d88 2 a89 1 cairo_restore (cr); d91 2 a92 10 matrix = cairo_matrix_create (); cairo_matrix_scale (matrix, 2.0 / width, 1.0 / height); gradient_pattern = cairo_pattern_create_for_surface (gradient); cairo_surface_destroy (gradient); cairo_pattern_set_matrix (gradient_pattern, matrix); cairo_pattern_set_filter (gradient_pattern, CAIRO_FILTER_BILINEAR); cairo_matrix_destroy (matrix); d94 1 a94 1 return gradient_pattern; d109 1 a109 1 cairo_set_pattern (cr, gradient); d113 1 a113 1 cairo_set_pattern (cr, gradient); d117 1 a117 1 cairo_set_pattern (cr, gradient); @ 1.5 log @global replacing of ct with cr @ text @d2 1 a2 1 * Copyright © 2003 USC, Information Sciences Institute @ 1.4 log @Fix cairo_set_pattern @ text @d33 1 a33 1 draw_outlines (cairo_t *ct, int surface_width, int surface_height); d36 1 a36 1 draw_flat (cairo_t *ct, double width, double height); d39 1 a39 1 draw_tent (cairo_t *ct, double width, double height); d42 1 a42 1 draw_cylinder (cairo_t *ct, double width, double height); d45 1 a45 1 create_gradient (cairo_t *ct, double width, double height); d56 1 a56 1 cairo_t *ct; d58 1 a58 1 ct = cairo_create (); d60 1 a60 1 cairo_set_target_image (ct, image, CAIRO_FORMAT_ARGB32, d63 3 a65 3 cairo_rectangle (ct, 0, 0, WIDTH, HEIGHT); cairo_set_rgb_color (ct, 1, 1, 1); cairo_fill (ct); d67 1 a67 1 draw_outlines (ct, WIDTH, HEIGHT); d71 1 a71 1 cairo_destroy (ct); d77 1 a77 1 create_gradient (cairo_t *ct, double width, double height) d83 1 a83 1 cairo_save (ct); d85 1 a85 1 gradient = cairo_surface_create_similar (cairo_current_target_surface (ct), d88 1 a88 1 cairo_set_target_surface (ct, gradient); d90 3 a92 3 cairo_set_rgb_color (ct, 0, 0, 0); cairo_rectangle (ct, 0, 0, 1, 2); cairo_fill (ct); d94 3 a96 3 cairo_set_rgb_color (ct, 1, 1, 1); cairo_rectangle (ct, 1, 0, 1, 2); cairo_fill (ct); d98 3 a100 3 cairo_set_rgb_color (ct, 0, 0, 0); cairo_rectangle (ct, 2, 0, 1, 2); cairo_fill (ct); d102 1 a102 1 cairo_restore (ct); d119 1 a119 1 draw_outlines (cairo_t *ct, int surface_width, int surface_height) d128 1 a128 1 gradient = create_gradient (ct, width, height); d130 2 a131 2 cairo_set_pattern (ct, gradient); draw_flat (ct, width, height); d133 3 a135 3 cairo_translate (ct, width + pad, 0); cairo_set_pattern (ct, gradient); draw_tent (ct, width, height); d137 3 a139 3 cairo_translate (ct, width + pad, 0); cairo_set_pattern (ct, gradient); draw_cylinder (ct, width, height); d141 1 a141 1 cairo_restore (ct); d147 1 a147 1 draw_flat (cairo_t *ct, double width, double height) d151 1 a151 1 cairo_rectangle (ct, 0, hwidth, width, height - hwidth); d153 1 a153 1 cairo_fill (ct); d157 1 a157 1 draw_tent (cairo_t *ct, double width, double height) d161 7 a167 7 cairo_move_to (ct, 0, hwidth); cairo_rel_line_to (ct, hwidth, -hwidth); cairo_rel_line_to (ct, hwidth, hwidth); cairo_rel_line_to (ct, 0, height - hwidth); cairo_rel_line_to (ct, -hwidth, -hwidth); cairo_rel_line_to (ct, -hwidth, hwidth); cairo_close_path (ct); d169 1 a169 1 cairo_fill (ct); d173 1 a173 1 draw_cylinder (cairo_t *ct, double width, double height) d177 2 a178 2 cairo_move_to (ct, 0, hwidth); cairo_rel_curve_to (ct, d182 2 a183 2 cairo_rel_line_to (ct, 0, height - hwidth); cairo_rel_curve_to (ct, d187 1 a187 1 cairo_close_path (ct); d189 1 a189 1 cairo_fill (ct); @ 1.3 log @ * Makefile (CFLAGS): Use pkg-config to find libpng. @ text @d44 1 a44 1 cairo_surface_t * d76 1 a76 1 cairo_surface_t * d81 1 d108 5 a112 2 cairo_surface_set_matrix (gradient, matrix); cairo_surface_set_filter (gradient, CAIRO_FILTER_BILINEAR); d115 1 a115 1 return gradient; d121 1 a121 1 cairo_surface_t *gradient; d143 1 a143 1 cairo_surface_destroy (gradient); @ 1.2 log @Updated to track changes in Cairo API @ text @d85 2 a86 2 CAIRO_FORMAT_ARGB32, 3, 2); @ 1.1 log @Added demos from OLS paper. @ text @d84 1 a84 1 gradient = cairo_surface_create_similar (cairo_get_target_surface (ct), @