head 1.13; access; symbols initial:1.1.1.1 start:1.1.1; locks; strict; comment @ * @; 1.13 date 2005.07.09.23.40.55; author keithp; state Exp; branches; next 1.12; commitid 13c342d060824567; 1.12 date 2005.05.18.06.21.15; author keithp; state Exp; branches; next 1.11; commitid 431d428aded64567; 1.11 date 2005.05.02.20.24.38; author keithp; state Exp; branches; next 1.10; commitid 416842768c824567; 1.10 date 2005.02.11.21.15.46; author keithp; state Exp; branches; next 1.9; 1.9 date 2004.12.24.09.00.10; author keithp; state Exp; branches; next 1.8; 1.8 date 2004.12.23.22.39.40; author keithp; state Exp; branches; next 1.7; 1.7 date 2004.12.19.00.06.26; author keithp; state Exp; branches; next 1.6; 1.6 date 2004.12.18.08.16.28; author keithp; state Exp; branches; next 1.5; 1.5 date 2004.12.17.09.40.43; author keithp; state Exp; branches; next 1.4; 1.4 date 2004.12.17.02.09.45; author keithp; state Exp; branches; next 1.3; 1.3 date 2004.12.15.07.04.50; author keithp; state Exp; branches; next 1.2; 1.2 date 2004.12.14.08.34.27; author keithp; state Exp; branches; next 1.1; 1.1 date 2004.12.11.06.26.52; author keithp; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2004.12.11.06.26.52; author keithp; state Exp; branches; next ; desc @@ 1.13 log @2005-07-09 Keith Packard * cairo-5c.h: * cairo.c: (cairo_5c_get): * examples/animate.5c: * gtk.c: (configure_event), (expose_event), (delete_drawing_area), (gtk_repaint), (gtk_tool_free), (cairo_5c_tool_create), (cairo_5c_tool_destroy): * surface.c: (create_cairo_window): Pass GtkPixmap objects around as they are reference counted. Use proposed new cairo_xlib_surface_set_drawable API to deal with window back-buffer resize issue. @ text @/* $Id: surface.c,v 1.12 2005/05/18 06:21:15 keithp Exp $ * * Copyright © 2004 Keith Packard * * This library is free software; you can redistribute it and/or * modify it either under the terms of the GNU Lesser General Public * License version 2.1 as published by the Free Software Foundation * (the "LGPL") or, at your option, under the terms of the Mozilla * Public License Version 1.1 (the "MPL"). If you do not alter this * notice, a recipient may use your version of this file under either * the MPL or the LGPL. * * You should have received a copy of the LGPL along with this library * in the file COPYING-LGPL-2.1; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * You should have received a copy of the MPL along with this library * in the file COPYING-MPL-1.1 * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY * OF ANY KIND, either express or implied. See the LGPL or the MPL for * the specific language governing rights and limitations. * * The Original Code is the cairo graphics library. * * The Initial Developer of the Original Code is Keith Packard * * Contributor(s): * Keith Packard */ #include "cairo-5c.h" static char CairoSurfaceId[] = "CairoSurface"; static Bool create_cairo_window (cairo_5c_surface_t *c5s) { Display *dpy = cairo_5c_tool_display (c5s); Pixmap pixmap; if (!c5s->u.window.pixmap) { RaiseStandardException (exception_invalid_argument, "window destroyed", 2, NewInt (0), NewInt (0)); return False; } gdk_threads_enter (); gdk_drawable_ref (c5s->u.window.pixmap); if (c5s->u.window.curpix) gdk_drawable_unref (c5s->u.window.curpix); c5s->u.window.curpix = c5s->u.window.pixmap; pixmap = GDK_PIXMAP_XID (GDK_DRAWABLE(c5s->u.window.curpix)); gdk_threads_leave (); if (c5s->surface) cairo_xlib_surface_set_drawable (c5s->surface, pixmap, c5s->width, c5s->height); else c5s->surface = cairo_xlib_surface_create (dpy, pixmap, DefaultVisual (dpy, DefaultScreen (dpy)), c5s->width, c5s->height); return True; } cairo_5c_surface_t * cairo_5c_surface_get (Value av) { cairo_5c_surface_t *c5s; if (av == Void) { RaiseStandardException (exception_invalid_argument, "context not bound to surface", 2, NewInt(0), av); } if (av->foreign.id != CairoSurfaceId) { RaiseStandardException (exception_invalid_argument, "not a surface_t", 2, NewInt(0), av); return 0; } c5s = av->foreign.data; if (!c5s) { RaiseStandardException (exception_invalid_argument, "surface destroyed", 2, NewInt(0), av); return 0; } switch (c5s->kind) { case CAIRO_5C_WINDOW: if (c5s->u.window.curpix != c5s->u.window.pixmap) if (!create_cairo_window (c5s)) return 0; break; case CAIRO_5C_IMAGE: case CAIRO_5C_SCRATCH: case CAIRO_5C_PDF: break; } return c5s; } /* * These are the functions for the nickle memory allocator interface * for the CairoSurfaceType datatype */ static void cairo_5c_surface_mark (void *object) { cairo_5c_surface_t *c5s = object; MemReference (c5s->recv_events); switch (c5s->kind) { case CAIRO_5C_WINDOW: cairo_5c_tool_mark (c5s); break; case CAIRO_5C_IMAGE: case CAIRO_5C_SCRATCH: break; case CAIRO_5C_PDF: MemReference (c5s->u.pdf.file); break; } } static void cairo_5c_surface_destroy (cairo_5c_surface_t *c5s) { if (!c5s->surface) return; switch (c5s->kind) { case CAIRO_5C_PDF: if (!c5s->copied) { cairo_t *cr = cairo_create (c5s->surface); if (cr) { cairo_copy_page (cr); cairo_destroy (cr); } } break; default: break; } cairo_surface_destroy (c5s->surface); c5s->surface = 0; switch (c5s->kind) { case CAIRO_5C_WINDOW: cairo_5c_tool_destroy (c5s); break; case CAIRO_5C_IMAGE: break; case CAIRO_5C_PDF: c5s->u.pdf.file = Void; break; case CAIRO_5C_SCRATCH: break; } } static int cairo_5c_surface_free (void *object) { cairo_5c_surface_t *c5s = object; cairo_5c_surface_destroy (c5s); return 1; } static DataType Cairo5cSurfaceType = { cairo_5c_surface_mark, cairo_5c_surface_free, "Cairo5cSurface" }; /* * These are the functions for the nickle foreign function interface * for the "CairoSurface" foreign datatype */ static void cairo_surface_foreign_mark (void *object) { MemReference (object); } static void cairo_surface_foreign_free (void *object) { /* let nickle finalizer deal with this */ ; } Value do_Cairo_Surface_create_window (Value namev, Value wv, Value hv) { ENTER (); cairo_5c_surface_t *c5s; Value ret; char *name = StrzPart (namev, "invalid name"); int width = IntPart (wv, "invalid width"); int height = IntPart (hv, "invalid height"); if (aborting ) RETURN (Void); c5s = ALLOCATE (&Cairo5cSurfaceType, sizeof (cairo_5c_surface_t)); c5s->kind = CAIRO_5C_WINDOW; c5s->surface = 0; c5s->width = width; c5s->height = height; c5s->dirty = False; c5s->copied = False; c5s->recv_events = Void; if (!cairo_5c_tool_create (c5s, name, width, height)) { RaiseStandardException (exception_open_error, "Can't create window", 0, wv); RETURN (Void); } create_cairo_window (c5s); ret = NewForeign (CairoSurfaceId, c5s, cairo_surface_foreign_mark, cairo_surface_foreign_free); RETURN (ret); } Value do_Cairo_Surface_write_to_png (Value sv, Value fv) { ENTER (); cairo_5c_surface_t *c5s = cairo_5c_surface_get (sv); char *filename = StrzPart (fv, "invalid filename"); cairo_status_t status; if (aborting) RETURN (Void); status = cairo_surface_write_to_png (c5s->surface, filename); RETURN (IntToEnum (typeCairoStatus, status)); } Value do_Cairo_Surface_write_to_png_file (Value sv, Value fv) { ENTER (); RETURN (Void); } Value do_Cairo_Surface_set_device_offset (Value sv, Value xv, Value yv) { ENTER (); cairo_5c_surface_t *c5s = cairo_5c_surface_get (sv); double x = DoublePart (xv, "invalid X value"); double y = DoublePart (yv, "invalid Y value"); if (!aborting) cairo_surface_set_device_offset (c5s->surface, x, y); RETURN (Void); } Value do_Cairo_Surface_create_similar (Value sv, Value wv, Value hv) { ENTER (); cairo_5c_surface_t *c5s; cairo_5c_surface_t *c5os = cairo_5c_surface_get (sv); int width = IntPart (wv, "invalid width"); int height = IntPart (hv, "invalid height"); Value ret; if (aborting) RETURN (Void); c5s = ALLOCATE (&Cairo5cSurfaceType, sizeof (cairo_5c_surface_t)); c5s->kind = CAIRO_5C_SCRATCH; c5s->surface = 0; c5s->width = width; c5s->height = height; c5s->dirty = False; c5s->copied = False; c5s->recv_events = Void; c5s->surface = cairo_surface_create_similar (c5os->surface, CAIRO_FORMAT_ARGB32, width, height); ret = NewForeign (CairoSurfaceId, c5s, cairo_surface_foreign_mark, cairo_surface_foreign_free); RETURN (ret); } Value do_Cairo_Surface_finish (Value sv) { ENTER (); cairo_5c_surface_t *c5s = cairo_5c_surface_get (sv); if (!aborting) cairo_surface_finish (c5s->surface); RETURN (Void); } Value do_Cairo_Surface_destroy (Value sv) { ENTER (); cairo_5c_surface_t *c5s = cairo_5c_surface_get (sv); if (aborting) RETURN (Void); cairo_5c_surface_destroy (c5s); RETURN(Void); } Value do_Cairo_Surface_width (Value sv) { ENTER (); cairo_5c_surface_t *c5s = cairo_5c_surface_get (sv); if (aborting) RETURN (Void); RETURN(Reduce (NewDoubleFloat (c5s->width))); } Value do_Cairo_Surface_height (Value sv) { ENTER (); cairo_5c_surface_t *c5s = cairo_5c_surface_get (sv); if (aborting) RETURN (Void); RETURN(Reduce (NewDoubleFloat (c5s->height))); } Value do_Cairo_Image_surface_create (Value fv, Value wv, Value hv) { ENTER (); cairo_5c_surface_t *c5s; int width = IntPart (wv, "invalid width"); int height = IntPart (hv, "invalid height"); Value ret; if (aborting) RETURN (Void); c5s = ALLOCATE (&Cairo5cSurfaceType, sizeof (cairo_5c_surface_t)); c5s->kind = CAIRO_5C_IMAGE; c5s->surface = 0; c5s->width = width; c5s->height = height; c5s->dirty = False; c5s->recv_events = Void; c5s->copied = False; c5s->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); ret = NewForeign (CairoSurfaceId, c5s, cairo_surface_foreign_mark, cairo_surface_foreign_free); RETURN (ret); } Value do_Cairo_Image_surface_create_from_png (Value filenamev) { ENTER (); char *filename = StrzPart (filenamev, "invalid filename"); cairo_surface_t *image; cairo_5c_surface_t *c5s; Value ret; if (aborting) RETURN(Void); image = cairo_image_surface_create_from_png (filename); if (!image) { RaiseStandardException (exception_open_error, "cannot read png file", 1, filenamev); RETURN (Void); } if (aborting) RETURN (Void); c5s = ALLOCATE (&Cairo5cSurfaceType, sizeof (cairo_5c_surface_t)); c5s->kind = CAIRO_5C_IMAGE; c5s->surface = 0; c5s->width = cairo_image_surface_get_width (image); c5s->height = cairo_image_surface_get_height (image); c5s->dirty = False; c5s->recv_events = Void; c5s->copied = False; ret = NewForeign (CairoSurfaceId, c5s, cairo_surface_foreign_mark, cairo_surface_foreign_free); RETURN (ret); } Value do_Cairo_Image_surface_create_from_png_file (Value filev) { ENTER (); /* XXX */ RETURN (Void); } Value do_Cairo_Pdf_surface_create (Value fnv, Value wv, Value hv) { ENTER (); cairo_5c_surface_t *c5s; char *filename = StrzPart (fnv, "invalid filename"); double width = DoublePart (wv, "invalid width_in_points"); double height = DoublePart (hv, "invalid height_in_points"); Value ret; if (aborting) RETURN (Void); c5s = ALLOCATE (&Cairo5cSurfaceType, sizeof (cairo_5c_surface_t)); c5s->kind = CAIRO_5C_PDF; c5s->surface = 0; c5s->width = width; c5s->height = height; c5s->dirty = False; c5s->copied = False; c5s->recv_events = Void; c5s->u.pdf.file = Void; c5s->surface = cairo_pdf_surface_create (filename, width, height); ret = NewForeign (CairoSurfaceId, c5s, cairo_surface_foreign_mark, cairo_surface_foreign_free); RETURN (ret); } @ 1.12 log @2005-05-17 Keith Packard * cairo-5c.h: * cairo.5c: * cairo.c: (cairo_5c_get), (do_Cairo_create), (cairo_5c_dirty), (cairo_5c_enable), (cairo_5c_disable), (do_Cairo_get_target): * draw.c: (do_Cairo_paint), (do_Cairo_paint_with_alpha), (do_Cairo_mask), (do_Cairo_mask_surface), (do_Cairo_fill_preserve), (do_Cairo_stroke_preserve), (path_elt_new), (path_array), (do_Cairo_copy_path), (do_Cairo_copy_path_flat), (do_Cairo_append_path): * event.c: (do_Cairo_Surface_open_event): * examples/animate.5c: * examples/draw.5c: * examples/fob.5c: * examples/metrics.5c: * examples/sin.5c: * examples/spin.5c: * examples/spinman.5c: * examples/test.5c: * gstate.c: (do_Cairo_set_source_surface), (do_Cairo_identity_matrix), (do_Cairo_transform), (do_Cairo_user_to_device), (do_Cairo_user_to_device_distance), (do_Cairo_device_to_user), (do_Cairo_device_to_user_distance), (do_Cairo_reset_clip), (do_Cairo_clip_preserve): * gtk.c: (create_gtk_global): * init.c: (init_types), (nickle_init): * pattern.c: (do_Cairo_Pattern_create_for_surface), (do_Cairo_Pattern_add_color_stop_rgba), (do_Cairo_Pattern_add_color_stop_rgb): * surface.c: (cairo_5c_surface_get), (cairo_5c_surface_mark), (cairo_5c_surface_destroy), (do_Cairo_Surface_write_to_png), (do_Cairo_Surface_write_to_png_file), (do_Cairo_Surface_set_device_offset), (do_Cairo_Surface_create_similar), (do_Cairo_Surface_finish), (do_Cairo_Surface_destroy), (do_Cairo_Surface_width), (do_Cairo_Surface_height), (do_Cairo_Image_surface_create), (do_Cairo_Image_surface_create_from_png), (do_Cairo_Image_surface_create_from_png_file), (do_Cairo_Pdf_surface_create): * text.c: (do_Cairo_select_font_face), (do_Cairo_get_font_matrix): Another round of API changes for cairo 0.5, the putative final API structure. @ text @d1 1 a1 1 /* $Id: surface.c,v 1.11 2005/05/02 20:24:38 keithp Exp $ d44 1 a45 2 if (c5s->surface) cairo_surface_destroy (c5s->surface); d53 5 a57 5 c5s->surface = cairo_xlib_surface_create (dpy, c5s->u.window.pixmap, DefaultVisual (dpy, DefaultScreen (dpy)), 0, DefaultColormap (dpy, DefaultScreen (dpy))); d59 13 @ 1.11 log @2005-05-02 Keith Packard * cairo-5c.h: * cairo.5c: * cairo.c: (cairo_5c_dirty), (cairo_5c_enable), (cairo_5c_disable), (do_Cairo_get_target_surface): * event.c: (do_Cairo_Surface_open_event): * gstate.c: (do_Cairo_set_source_rgb), (do_Cairo_set_source_rgba), (do_Cairo_get_matrix), (do_Cairo_concat_matrix), (do_Cairo_set_matrix), (do_Cairo_get_operator), (do_Cairo_get_tolerance), (do_Cairo_get_current_point), (do_Cairo_get_fill_rule), (do_Cairo_get_line_width), (do_Cairo_get_line_cap), (do_Cairo_get_line_join), (do_Cairo_get_miter_limit): * gtk.c: (delete_drawing_area), (motion_notify_event), (button_press_event), (button_release_event), (gtk_repaint_timeout), (gtk_thread_main), (gtk_global_free), (create_gtk_global), (cairo_5c_tool_dirty), (cairo_5c_tool_enable): * init.c: (init_types), (nickle_init): * matrix.c: (cairo_matrix_part), (new_cairo_matrix): * pattern.c: (do_Cairo_set_source), (do_Cairo_get_source), (do_Cairo_Pattern_set_matrix), (do_Cairo_Pattern_get_matrix): * surface.c: (cairo_5c_surface_get), (cairo_5c_surface_mark), (cairo_5c_surface_destroy), (do_Cairo_Surface_create_image), (do_Cairo_Surface_write_to_png): * text.c: (do_Cairo_set_font), (do_Cairo_set_font_size), (do_Cairo_set_font_matrix), (do_Cairo_font_extents): Match cairo API as of today. * examples/draw.5c: * examples/fob.5c: * examples/graph.5c: * examples/grid.5c: * examples/led.5c: * examples/pie-new.5c: * examples/pie.5c: * examples/rottext.5c: * examples/sin.5c: * examples/spin-cairo.5c: * examples/spin.5c: * examples/spinman.5c: * examples/test.5c: * examples/text45.5c: Update examples to match API changes @ text @d1 1 a1 1 /* $Id: surface.c,v 1.10 2005/02/11 21:15:46 keithp Exp $ a95 1 case CAIRO_5C_PS: d97 1 a118 1 case CAIRO_5C_PS: d121 3 d135 1 a135 2 case CAIRO_5C_PS: FilePrintf (FileStdout, "Copied %d\n", c5s->copied); d138 1 a138 1 cairo_t *cr = cairo_create (); a140 1 cairo_set_target_surface (cr, c5s->surface); d159 2 a160 3 case CAIRO_5C_PS: fclose (c5s->u.ps.file); c5s->u.ps.file = NULL; d238 34 d273 1 a273 1 do_Cairo_Surface_create_image (Value wv, Value hv) d277 1 d286 1 a286 1 c5s->kind = CAIRO_5C_IMAGE; d291 1 a292 5 c5s->copied = False; c5s->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); d294 4 d305 12 a316 1 do_Cairo_Surface_write_to_png (Value sv, Value fv) d320 1 a320 3 char *filename = StrzPart (fv, "invalid filename"); cairo_status_t status; d323 2 a324 2 status = cairo_surface_write_to_png (c5s->surface, filename); RETURN (IntToEnum (typeCairoStatus, status)); d328 1 a328 1 do_Cairo_Surface_create_ps (Value fv, Value wv, Value hv, Value xppiv, Value yppiv) d331 1 a331 7 cairo_5c_surface_t *c5s; char *filename = StrzPart (fv, "invalid filename"); double width = DoublePart (wv, "invalid width"); double height = DoublePart (hv, "invalid height"); double xppi = DoublePart (xppiv, "invalid x pixels per inch"); double yppi = DoublePart (yppiv, "invalid y pixels per inch"); Value ret; d335 2 a336 19 c5s = ALLOCATE (&Cairo5cSurfaceType, sizeof (cairo_5c_surface_t)); c5s->kind = CAIRO_5C_PS; c5s->surface = 0; c5s->width = width * xppi; c5s->height = height * yppi; c5s->dirty = False; c5s->copied = False; c5s->recv_events = Void; c5s->u.ps.file = fopen (filename, "w"); if (!c5s->u.ps.file) { RaiseStandardException (exception_open_error, "can't open file", 0, fv); RETURN (Void); } d338 5 a342 4 c5s->surface = cairo_ps_surface_create (c5s->u.ps.file, width, height, xppi, yppi); ret = NewForeign (CairoSurfaceId, c5s, cairo_surface_foreign_mark, cairo_surface_foreign_free); d344 3 a346 1 RETURN (ret); d349 1 d351 1 a351 1 do_Cairo_Surface_create_similar (Value sv, Value wv, Value hv) a354 1 cairo_5c_surface_t *c5os = cairo_5c_surface_get (sv); d363 1 a363 1 c5s->kind = CAIRO_5C_SCRATCH; d368 1 a369 1 c5s->recv_events = Void; d371 4 a374 4 c5s->surface = cairo_surface_create_similar (c5os->surface, CAIRO_FORMAT_ARGB32, width, height); d382 1 a382 1 do_Cairo_Surface_destroy (Value sv) d385 15 a399 1 cairo_5c_surface_t *c5s = cairo_5c_surface_get (sv); d403 13 a415 2 cairo_5c_surface_destroy (c5s); RETURN(Void); d419 1 a419 1 do_Cairo_Surface_width (Value sv) d422 2 a423 5 cairo_5c_surface_t *c5s = cairo_5c_surface_get (sv); if (aborting) RETURN (Void); RETURN(NewInt (c5s->width)); d427 1 a427 1 do_Cairo_Surface_height (Value sv) d430 5 a434 1 cairo_5c_surface_t *c5s = cairo_5c_surface_get (sv); d438 18 a455 1 RETURN(NewInt (c5s->height)); d457 1 @ 1.10 log @2005-01-02 Keith Packard * cairo-5c.h: Add do_Cairo_copy_page and do_Cairo_show_page. Track whether copy_page/show_page have ever been called so that they can be when the surface is destroyed. * cairo.c: (cairo_5c_free), (cairo_5c_dirty): * draw.c: (do_Cairo_arc), (do_Cairo_arc_negative), (do_Cairo_copy_page), (do_Cairo_show_page): Fix arc arguments * event.c: (do_Cairo_Surface_open_event): * gtk.c: (cairo_5c_tool_destroy): * init.c: (nickle_init): * surface.c: (cairo_5c_surface_mark), (cairo_5c_surface_destroy), (cairo_5c_surface_free), (do_Cairo_Surface_create_window), (do_Cairo_Surface_create_png), (do_Cairo_Surface_create_ps), (do_Cairo_Surface_create_similar), (do_Cairo_Surface_destroy): dunno @ text @d1 1 a1 1 /* $Id: surface.c,v 1.9 2004/12/24 09:00:10 keithp Exp $ d95 1 a95 1 case CAIRO_5C_PNG: d118 1 a118 1 case CAIRO_5C_PNG: a132 1 case CAIRO_5C_PNG: d157 1 a157 3 case CAIRO_5C_PNG: fclose (c5s->u.png.file); c5s->u.png.file = NULL; d240 1 a240 1 do_Cairo_Surface_create_png (Value fv, Value wv, Value hv) a243 1 char *filename = StrzPart (fv, "invalid filename"); d252 1 a252 1 c5s->kind = CAIRO_5C_PNG; d260 3 a262 14 c5s->u.png.file = fopen (filename, "w"); if (!c5s->u.png.file) { RaiseStandardException (exception_open_error, "can't open file", 0, fv); RETURN (Void); } c5s->surface = cairo_png_surface_create (c5s->u.png.file, CAIRO_FORMAT_ARGB32, width, height); d271 14 @ 1.9 log @2004-12-24 Keith Packard * cairo-5c.h: * cairo.5c: * cairo.c: (do_Cairo_set_target_surface): * gtk.c: (delete_drawing_area), (gtk_tool_free), (cairo_5c_tool_create), (cairo_5c_tool_destroy): * init.c: (nickle_init): * surface.c: (create_cairo_window), (cairo_5c_surface_get), (do_Cairo_Surface_create_window): Handle window delete more gracefully; report exception on drawing, report 'delete' event to event reader. Have default surface creation code re-create a surface when the old default surface has been destroyed. @ text @d1 1 a1 1 /* $Id: surface.c,v 1.8 2004/12/23 22:39:40 keithp Exp $ d112 1 d125 2 a126 2 static int cairo_5c_surface_free (void *object) d128 22 a149 1 cairo_5c_surface_t *c5s = object; d152 2 d159 3 d163 3 d169 8 d223 1 d262 1 d306 1 d346 1 d367 1 a367 2 cairo_surface_destroy (c5s->surface); c5s->surface = 0; @ 1.8 log @2004-12-23 Keith Packard * Makefile.am: * cairo-5c.h: * cairo.5c: * cairo.c: (cairo_5c_get), (cairo_5c_mark), (cairo_5c_free), (cairo_foreign_mark), (cairo_foreign_free), (do_Cairo_create), (cairo_5c_dirty), (cairo_5c_enable), (cairo_5c_disable), (do_Cairo_set_target_surface), (do_Cairo_current_target_surface), (do_Cairo_destroy), (do_Cairo_copy), (do_Cairo_status), (do_Cairo_status_string), (do_Cairo_enable), (do_Cairo_disable): * draw.c: (do_Cairo_new_path), (do_Cairo_move_to), (do_Cairo_line_to), (do_Cairo_curve_to), (do_Cairo_arc), (do_Cairo_arc_negative), (do_Cairo_rel_move_to), (do_Cairo_rel_line_to), (do_Cairo_rel_curve_to), (do_Cairo_rectangle), (do_Cairo_close_path), (do_Cairo_fill), (do_Cairo_stroke), (do_Cairo_in_stroke), (do_Cairo_in_fill), (do_Cairo_stroke_extents), (do_Cairo_fill_extents), (do_Cairo_current_path_list), (do_Cairo_current_path_flat_list): * event.c: (do_Cairo_Surface_open_event): * examples/draw.5c: * examples/graph.5c: * examples/grid.5c: * examples/rottext.5c: * gstate.c: (do_Cairo_save), (do_Cairo_restore), (do_Cairo_set_operator), (do_Cairo_set_rgb_color), (do_Cairo_set_alpha), (do_Cairo_set_tolerance), (do_Cairo_set_fill_rule), (do_Cairo_set_line_width), (do_Cairo_set_line_cap), (do_Cairo_set_line_join), (do_Cairo_set_dash), (do_Cairo_set_miter_limit), (do_Cairo_identity_matrix), (do_Cairo_default_matrix), (do_Cairo_translate), (do_Cairo_scale), (do_Cairo_rotate), (do_Cairo_current_matrix), (do_Cairo_concat_matrix), (do_Cairo_set_matrix), (do_Cairo_transform_point), (do_Cairo_transform_distance), (do_Cairo_inverse_transform_point), (do_Cairo_inverse_transform_distance), (do_Cairo_init_clip), (do_Cairo_clip), (do_Cairo_current_operator), (do_Cairo_current_rgb_color), (do_Cairo_current_alpha), (do_Cairo_current_tolerance), (do_Cairo_current_point), (do_Cairo_current_fill_rule), (do_Cairo_current_line_width), (do_Cairo_current_line_cap), (do_Cairo_current_line_join), (do_Cairo_current_miter_limit): * gtk.c: (configure_event), (expose_event), (delete_drawing_area), (delete_event), (motion_notify_event), (button_press_event), (button_release_event), (gtk_repaint), (gtk_repaint_timeout), (gtk_global_mark), (gtk_global_free), (create_gtk_global), (gtk_tool_mark), (gtk_tool_free), (cairo_5c_tool_create), (cairo_5c_tool_destroy), (cairo_5c_tool_mark), (cairo_5c_tool_dirty), (cairo_5c_tool_disable), (cairo_5c_tool_enable), (cairo_5c_tool_display): * init.c: (init_types), (nickle_init): * pattern.c: (mark_cairo_pattern), (make_pattern_value), (do_Cairo_set_pattern), (do_Cairo_current_pattern), (do_Cairo_Pattern_create_for_surface): * surface.c: (create_cairo_window), (cairo_5c_surface_get), (cairo_5c_surface_mark), (cairo_5c_surface_free), (cairo_surface_foreign_mark), (cairo_surface_foreign_free), (do_Cairo_Surface_create_window), (do_Cairo_Surface_create_png), (do_Cairo_Surface_create_ps), (do_Cairo_Surface_create_similar), (do_Cairo_Surface_destroy), (do_Cairo_Surface_width), (do_Cairo_Surface_height): * text.c: (do_Cairo_select_font), (do_Cairo_set_font), (do_Cairo_scale_font), (do_Cairo_transform_font), (do_Cairo_current_font_extents), (do_Cairo_show_text), (do_Cairo_text_path), (do_Cairo_text_extents): Split cairo_t and cairo_surface_t functions apart, permitting more complex programs to be written that use more than a single window. Switch allocations around to mostly use the nickle memory allocator now. Requires updated nickle bits that expose this change in the foreign object API. @ text @d1 1 a1 1 /* $Id: surface.c,v 1.7 2004/12/19 00:06:26 keithp Exp $ d47 7 d92 2 a93 1 create_cairo_window (c5s); d167 1 a167 1 do_Cairo_Surface_create_window (Value wv, Value hv) d172 1 d187 1 a187 1 if (!cairo_5c_tool_create (c5s, width, height)) @ 1.7 log @2004-12-18 Keith Packard * cairo.5c: Add matrix operations * cairo-5c.h: * text.c: (do_Cairo_set_font), (do_Cairo_transform_font): * init.c: (nickle_init): Add set_font and transform_font interfaces * examples/animate.5c: * examples/pie.5c: use set_font interface * surface.c: (do_Cairo_dup): Duplicate gstate in dup operator @ text @d1 1 a1 1 /* $Id: surface.c,v 1.6 2004/12/18 08:16:28 keithp Exp $ d38 1 a38 1 static char CairoId[] = "Cairo"; d40 2 a41 2 cairo_5c_t * get_cairo_5c (Value av) d43 1 a43 1 cairo_5c_t *c5c; d45 17 a61 1 if (av->foreign.id != CairoId) d64 7 a70 1 "not a cairo_t", d74 2 a75 2 c5c = av->foreign.data; if (!c5c) d78 1 a78 1 "cairo destroyed", d82 1 a82 1 switch (c5c->kind) { d84 2 a85 7 if (c5c->u.window.pix != c5c->u.window.x->pixmap) { c5c->u.window.pix = c5c->u.window.x->pixmap; c5c->width = c5c->u.window.x->width; c5c->height = c5c->u.window.x->height; cairo_set_target_drawable (c5c->cr, c5c->u.window.x->dpy, c5c->u.window.pix); } d88 1 d92 1 a92 1 return c5c; d95 4 a98 4 void free_cairo_5c (void *v) { cairo_5c_t *c5c = v; d100 2 a101 19 if (c5c) { cairo_destroy (c5c->cr); switch (c5c->kind) { case CAIRO_5C_WINDOW: break; case CAIRO_5C_PNG: fflush (c5c->u.png.file); break; case CAIRO_5C_SCRATCH: cairo_surface_destroy (c5c->u.scratch.surface); break; } free (c5c); } } void dirty_cairo_5c (cairo_5c_t *c5c) d103 3 a105 1 switch (c5c->kind) { d107 1 a107 1 dirty_x (c5c->u.window.x, 0, 0, 0, 0); d110 1 d116 2 a117 2 static Bool enable_cairo_5c (cairo_5c_t *c5c) d119 4 a122 1 switch (c5c->kind) { d124 2 a125 1 return enable_x (c5c->u.window.x); d127 1 d131 18 a148 1 return True; d151 2 a152 2 static Bool disable_cairo_5c (cairo_5c_t *c5c) d154 2 a155 8 switch (c5c->kind) { case CAIRO_5C_WINDOW: return disable_x (c5c->u.window.x); case CAIRO_5C_PNG: case CAIRO_5C_SCRATCH: break; } return True; d159 1 a159 1 do_Cairo_new (int n, Value *v) d162 4 a165 3 cairo_5c_t *c5c; Value ret; int width, height; d167 1 a167 4 c5c = malloc (sizeof (cairo_5c_t)); c5c->kind = CAIRO_5C_WINDOW; if (!c5c) a168 8 if (n > 0) width = IntPart (v[0], "invalid width"); else width = 0; if (n > 1) height = IntPart (v[1], "invalid height"); else height = 0; d170 9 a178 1 if (aborting) d180 3 a182 1 free (c5c); d186 1 a186 17 c5c->recv_events = 0; c5c->u.window.x = start_x (width, height); c5c->width = c5c->u.window.x->width; c5c->height = c5c->u.window.x->height; c5c->u.window.pix = c5c->u.window.x->pixmap; c5c->cr = cairo_create (); cairo_set_target_drawable (c5c->cr, c5c->u.window.x->dpy, c5c->u.window.pix); cairo_save (c5c->cr); { cairo_identity_matrix (c5c->cr); cairo_set_rgb_color (c5c->cr, 1, 1, 1); cairo_rectangle (c5c->cr, 0, 0, c5c->width, c5c->height); cairo_fill (c5c->cr); } cairo_restore (c5c->cr); cairo_set_rgb_color (c5c->cr, 0, 0, 0); d188 2 a189 1 ret = NewForeign (CairoId, c5c, free_cairo_5c); d195 1 a195 1 do_Cairo_new_png (Value fv, Value wv, Value hv) d198 5 a202 5 cairo_5c_t *c5c; char *filename = StrzPart (fv, "invalid filename"); int width = IntPart (wv, "invalid width"); int height = IntPart (hv, "invalid height"); Value ret; d207 11 a217 8 c5c = malloc (sizeof (cairo_5c_t)); if (!c5c) RETURN (Void); c5c->kind = CAIRO_5C_PNG; c5c->u.png.file = fopen (filename, "w"); if (!c5c->u.png.file) a221 1 free (c5c); a223 14 c5c->width = width; c5c->height = height; c5c->cr = cairo_create (); cairo_set_target_png (c5c->cr, c5c->u.png.file, CAIRO_FORMAT_ARGB32, c5c->width, c5c->height); cairo_save (c5c->cr); { cairo_set_rgb_color (c5c->cr, 0, 0, 0); cairo_set_alpha (c5c->cr, 0); cairo_set_operator (c5c->cr, CAIRO_OPERATOR_SRC); cairo_rectangle (c5c->cr, 0, 0, c5c->width, c5c->height); cairo_fill (c5c->cr); } cairo_restore (c5c->cr); d225 7 a231 3 cairo_set_rgb_color (c5c->cr, 0, 0, 0); ret = NewForeign (CairoId, c5c, free_cairo_5c); d237 1 a237 1 do_Cairo_new_scratch (Value cov, Value wv, Value hv) d240 8 a247 6 cairo_5c_t *c5co = get_cairo_5c (cov); cairo_5c_t *c5c; int width = IntPart (wv, "invalid width"); int height = IntPart (hv, "invalid height"); Value ret; d251 15 a265 2 c5c = malloc (sizeof (cairo_5c_t)); if (!c5c) d267 1 d269 4 a272 21 c5c->kind = CAIRO_5C_SCRATCH; c5c->u.scratch.surface = cairo_surface_create_similar (cairo_current_target_surface (c5co->cr), CAIRO_FORMAT_ARGB32, width, height); c5c->width = width; c5c->height = height; c5c->cr = cairo_create (); cairo_set_target_surface (c5c->cr, c5c->u.scratch.surface); cairo_save (c5c->cr); { cairo_set_rgb_color (c5c->cr, 0, 0, 0); cairo_set_alpha (c5c->cr, 0); cairo_set_operator (c5c->cr, CAIRO_OPERATOR_SRC); cairo_rectangle (c5c->cr, 0, 0, c5c->width, c5c->height); cairo_fill (c5c->cr); } cairo_restore (c5c->cr); cairo_set_rgb_color (c5c->cr, 0, 0, 0); ret = NewForeign (CairoId, c5c, free_cairo_5c); d278 1 a278 1 do_Cairo_dup (Value cov) d281 6 a286 4 cairo_5c_t *c5co = get_cairo_5c (cov); cairo_5c_t *c5c; Value ret; d290 14 a303 9 c5c = malloc (sizeof (cairo_5c_t)); if (!c5c) RETURN (Void); *c5c = *c5co; c5c->cr = cairo_create (); cairo_set_target_surface (c5c->cr, cairo_current_target_surface (c5co->cr)); cairo_copy (c5c->cr, c5co->cr); ret = NewForeign (CairoId, c5c, free_cairo_5c); d309 1 a309 11 do_Cairo_width (Value av) { ENTER (); cairo_5c_t *c5c = get_cairo_5c (av); if (aborting) return Void; RETURN(NewInt (c5c->width)); } Value do_Cairo_height (Value av) d312 1 a312 1 cairo_5c_t *c5c = get_cairo_5c (av); d315 4 a318 2 return Void; RETURN(NewInt (c5c->height)); d322 1 a322 1 do_Cairo_status (Value cv) d325 1 a325 1 cairo_5c_t *c5c = get_cairo_5c (cv); d328 2 a329 2 return Void; RETURN(IntToEnum (typeCairoStatus, cairo_status (c5c->cr))); d333 1 a333 1 do_Cairo_status_string (Value cv) d336 1 a336 1 cairo_5c_t *c5c = get_cairo_5c (cv); d339 2 a340 48 return Void; RETURN(NewStrString (cairo_status_string (c5c->cr))); } Value do_Cairo_dispose (Value av) { ENTER (); cairo_5c_t *c5c = get_cairo_5c (av); if (c5c) { free_cairo_5c (c5c); av->foreign.data = 0; } RETURN (Void); } Value do_Cairo_enable (Value cv) { cairo_5c_t *c5c = get_cairo_5c (cv); if (aborting) return Void; if (!enable_cairo_5c (c5c)) { RaiseStandardException (exception_invalid_argument, "already enabled", 2, NewInt(0), cv); } return Void; } Value do_Cairo_disable (Value cv) { cairo_5c_t *c5c = get_cairo_5c (cv); if (aborting) return Void; if (!disable_cairo_5c (c5c)) { RaiseStandardException (exception_invalid_argument, "can't disable", 2, NewInt(0), cv); } return Void; @ 1.6 log @2004-12-18 Keith Packard * Makefile.am: * cairo.5c: * examples/animate.5c: * examples/draw.5c: * examples/pie.5c: * examples/rottext.5c: Fix examples to match API changes * gstate.c: (do_Cairo_transform_point), (do_Cairo_transform_distance), (do_Cairo_inverse_transform_point), (do_Cairo_inverse_transform_distance): transforms take point_t, return point_t * cairo-5c.h: * init.c: (nickle_init): * pattern.c: (do_Cairo_Pattern_create_for_surface), (premultiply_data), (create_surface_from_png), (do_Cairo_Pattern_create_png): * surface.c: (get_cairo_5c), (free_cairo_5c), (dirty_cairo_5c), (enable_cairo_5c), (disable_cairo_5c), (do_Cairo_new_png), (do_Cairo_new_scratch), (do_Cairo_dup), (do_Cairo_status): Add png loading, scratch surfaces and surface patterns @ text @d1 1 a1 1 /* $Id: surface.c,v 1.5 2004/12/17 09:40:43 keithp Exp $ d299 1 @ 1.5 log @2004-12-17 Keith Packard * cairo-5c.h: * cairo.5c: * draw.c: (path_new), (path_box), (cairo_5c_move_to), (cairo_5c_line_to), (cairo_5c_curve_to), (cairo_5c_close_path), (do_Cairo_current_path_list), (do_Cairo_current_path_flat_list): * init.c: (make_typedef), (init_types), (nickle_init): * surface.c: (get_cairo_5c): Add current_path/current_path_flat by creating nickle structure in C code holding the entire path and walking it in nickle code. * examples/.cvsignore: ignore build files @ text @d1 1 a1 1 /* $Id: surface.c,v 1.4 2004/12/17 02:09:45 keithp Exp $ d71 1 d91 3 d107 1 d119 1 d132 1 d223 51 a274 3 cairo_set_alpha (c5c->cr, 0); cairo_rectangle (c5c->cr, 0, 0, c5c->width, c5c->height); cairo_fill (c5c->cr); d282 23 d333 1 a333 1 RETURN(NewInt (cairo_status (c5c->cr))); @ 1.4 log @2004-12-16 Keith Packard * Makefile.am: * autogen.sh: * cairo.5c: * configure.in: Add cairo.5c and install it to nickle libary * cairo-5c.h: * draw.c: (do_Cairo_rectangle), (do_Cairo_in_stroke), (do_Cairo_in_fill), (do_Cairo_stroke_extents), (do_Cairo_fill_extents), (cairo_5c_move_to), (do_Cairo_current_path), (do_Cairo_current_path_flat): * gstate.c: (do_Cairo_set_operator), (do_Cairo_set_fill_rule), (do_Cairo_set_line_cap), (do_Cairo_set_line_join), (do_Cairo_set_dash), (do_Cairo_set_miter_limit), (do_Cairo_default_matrix), (do_Cairo_transform_point), (do_Cairo_transform_distance), (do_Cairo_inverse_transform_point), (do_Cairo_inverse_transform_distance), (do_Cairo_init_clip), (do_Cairo_clip), (do_Cairo_current_operator), (do_Cairo_current_rgb_color), (do_Cairo_current_alpha), (do_Cairo_current_tolerance), (do_Cairo_current_point), (do_Cairo_current_fill_rule), (do_Cairo_current_line_width), (do_Cairo_current_line_cap), (do_Cairo_current_line_join), (do_Cairo_current_miter_limit): * init.c: (make_typedef), (init_types), (EnumIntPart), (IntToEnum), (nickle_init): * text.c: (do_Cairo_select_font), (do_Cairo_text_extents), (do_Cairo_select_ft_font): Add a bunch more bindings. Still more to do, especially the path walkers. Switch from int constants to enums for enumerated types. * gtk.c: (motion_notify_event), (button_press_event), (button_release_event), (cairo_5c_window_new): * surface.c: (do_Cairo_new): Add mouse input support. * examples/animate.5c: * examples/cairo.5c: * examples/draw.5c: * examples/graph.5c: * examples/pie.5c: * examples/rottext.5c: * examples/sin.5c: * examples/test.5c: Change examples to use cairo.5c file with autoimport @ text @d1 1 a1 1 /* $Id: surface.c,v 1.3 2004/12/15 07:04:50 keithp Exp $ d48 1 a48 1 "not a cairo", @ 1.3 log @2004-12-14 Keith Packard * cairo-5c.h: * gtk.c: (gtk_repaint_timeout), (dirty_x), (disable_x), (enable_x): * init.c: (nickle_init): * surface.c: (enable_cairo_5c), (disable_cairo_5c), (do_Cairo_enable), (do_Cairo_disable): Add enable/disable to take advantage of double buffering for smooth animation. * examples/animate.5c: Use enable/disable to smooth this animation out @ text @d1 1 a1 1 /* $Id: surface.c,v 1.2 2004/12/14 08:34:27 keithp Exp $ d159 1 @ 1.2 log @2004-12-14 Keith Packard * .cvsignore: * Makefile.am: * cairo-5c.h: * configure.in: * draw.c: (do_Cairo_fill), (do_Cairo_stroke): * gtk.c: (configure_event), (expose_event), (cairo_5c_window_new), (repaint_x), (gtk_repaint_timeout), (gtk_thread_main), (start_x), (dirty_x): * init.c: (nickle_init): * surface.c: (get_cairo_5c), (free_cairo_5c), (dirty_cairo_5c), (do_Cairo_new): * text.c: (do_Cairo_show_text): Replace lame Xlib-based output with more capable gtk+ based output, including backing storage and resize handling. Input still isn't hooked up. * gstate.c: (do_Cairo_current_matrix), (do_Cairo_set_matrix): Add current_matrix and set_matrix functions; these only do affine matrices. * examples/animate.5c: * examples/pie.5c: * examples/rottext.5c: * examples/sin.5c: * examples/test.5c: Update examples to use installed library @ text @d1 1 a1 1 /* $Id: surface.c,v 1.1.1.1 2004/12/11 06:26:52 keithp Exp $ d107 24 d281 32 @ 1.1 log @Initial revision @ text @d1 1 a1 1 /* $Id: $ d60 13 a75 12 static void Cairo_block_handler (void *closure) { cairo_5c_t *c5c = closure; if (c5c->dirty) { XFlush (c5c->u.window.dpy); c5c->dirty = False; } } a85 2 XCloseDisplay (c5c->u.window.dpy); ThreadsUnregisterBlockHandler (Cairo_block_handler, c5c); d95 12 a111 1 int screen; d113 1 a113 1 Display *dpy; a115 3 if (!c5c) RETURN (Void); d118 1 a118 8 dpy = XOpenDisplay (0); c5c->u.window.dpy = dpy; if (!dpy) { RaiseStandardException (exception_open_error, "can't open X display", 0, Void); free (c5c); a119 3 } screen = DefaultScreen(dpy); d121 1 a121 1 c5c->width = IntPart (v[0], "invalid width"); d123 1 a123 1 c5c->width = DisplayWidth (dpy, screen) / 3; d125 1 a125 1 c5c->height = IntPart (v[1], "invalid height"); d127 2 a128 1 c5c->height = DisplayWidth (dpy, screen) / 3; a130 1 XCloseDisplay (dpy); d135 5 a139 4 c5c->u.window.w = XCreateSimpleWindow (dpy, RootWindow (dpy, screen), 0, 0, c5c->width, c5c->height, 0, BlackPixel (dpy, screen), WhitePixel (dpy, screen)); d141 1 a141 1 cairo_set_target_drawable (c5c->cr, dpy, c5c->u.window.w); a151 3 XMapWindow (dpy, c5c->u.window.w); XFlush (dpy); a153 2 ThreadsRegisterBlockHandler (Cairo_block_handler, c5c); @ 1.1.1.1 log @Add cairo-5c to repository @ text @@