[cairo-commit] cairo-5c ChangeLog, 1.11, 1.12 cairo-5c.h, 1.7, 1.8 cairo.5c, 1.5, 1.6 init.c, 1.8, 1.9 surface.c, 1.6, 1.7 text.c, 1.3, 1.4

Keith Packard commit at pdx.freedesktop.org
Sat Dec 18 16:06:28 PST 2004


Committed by: keithp

Update of /cvs/cairo/cairo-5c
In directory gabe:/tmp/cvs-serv31041

Modified Files:
	ChangeLog cairo-5c.h cairo.5c init.c surface.c text.c 
Log Message:
2004-12-18  Keith Packard  <keithp at keithp.com>

	* 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


Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-5c/ChangeLog,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- ChangeLog	18 Dec 2004 08:16:28 -0000	1.11
+++ ChangeLog	19 Dec 2004 00:06:26 -0000	1.12
@@ -1,5 +1,23 @@
 2004-12-18  Keith Packard  <keithp at keithp.com>
 
+	* 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
+	
+
+2004-12-18  Keith Packard  <keithp at keithp.com>
+
 	* Makefile.am:
 	* cairo.5c:
 	* examples/animate.5c:

Index: cairo-5c.h
===================================================================
RCS file: /cvs/cairo/cairo-5c/cairo-5c.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- cairo-5c.h	18 Dec 2004 08:16:28 -0000	1.7
+++ cairo-5c.h	19 Dec 2004 00:06:26 -0000	1.8
@@ -390,9 +390,15 @@
 do_Cairo_select_font (Value cv, Value fv, Value sv, Value wv);
 
 Value
+do_Cairo_set_font (Value cv, Value fv);
+
+Value
 do_Cairo_scale_font (Value cv, Value sv);
 
 Value
+do_Cairo_transform_font (Value cv, Value mv);
+
+Value
 do_Cairo_show_text (Value cv, Value uv);
 
 Value

Index: cairo.5c
===================================================================
RCS file: /cvs/cairo/cairo-5c/cairo.5c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cairo.5c	18 Dec 2004 08:16:28 -0000	1.5
+++ cairo.5c	19 Dec 2004 00:06:26 -0000	1.6
@@ -183,4 +183,65 @@
 	    value = t[2]
 	};
     }
+
+    public namespace Matrix {
+	matrix_t multiply_scalar (matrix_t a, real scalar) = 
+	    (matrix_t) { [row,col] = a[row,col] * scalar };
+
+	public matrix_t identity () =
+	    (matrix_t) { [row,col] = row == col ? 1 : 0 };
+
+	public real determinant (matrix_t m) = 
+	    m[0,0] * m[1,1] - m[0,1] * m[1,0];
+	
+	/* This function isn't a correct adjoint in that the implicit 1 in the
+	 homogeneous result should actually be ad-bc instead. But, since this
+	 adjoint is only used in the computation of the inverse, which
+	 divides by det (A)=ad-bc anyway, everything works out in the end. */
+	matrix_t adjoint (matrix_t m) = 
+	    (matrix_t) {
+		{    m[1,1], -m[0,1] },
+		{   -m[1,0],  m[0,0] },
+		{    m[1,0] * m[2,1] - m[1,1] * m[2,0], 
+		     m[0,1] * m[2,0] - m[0,0] * m[2,1] }};
+	
+	/* inv (A) = 1/det (A) * adj (A) */
+	public matrix_t invert (matrix_t a) =
+	    multiply_scalar (adjoint (a), 1 / determinant (a));
+
+	public matrix_t multiply (matrix_t a, matrix_t b) =
+	    (matrix_t) { [row,col] { 
+		real t = 0;
+		if (row == 2)
+		    t = b[2,col];
+		for (int n = 0; n < 2; n++)
+		    t += a[row,n] * b[n,col];
+		return t;
+	    }};
+
+	public matrix_t translate (matrix_t m, real tx, real ty) =
+	    multiply ((matrix_t) { { 1, 0 }, { 0, 1 }, { tx, ty } }, m);
+	
+	public matrix_t scale (matrix_t m, real sx, real sy) =
+	    multiply ((matrix_t) { { sx, 0 }, { 0, sy }, { 0, 0 } }, m);
+	
+	public matrix_t rotate (matrix_t m, real a) =
+	    multiply ((matrix_t) { 
+		{  (real c = cos(a)), (real s = sin(a)) },
+		{      -s,                c },
+		{       0,                0 } }, m);
+
+	public point_t point (matrix_t m, point_t p) =
+	    (point_t) { 
+		x = m[0,0] * p.x + m[1,0] * p.y + m[2,0],
+		y = m[0,1] * p.x + m[1,1] * p.y + m[2,1]
+	    };
+	
+	public point_t distance (matrix_t m, point_t p) =
+	    (point_t) { 
+		x = m[0,0] * p.x + m[1,0] * p.y,
+		y = m[0,1] * p.x + m[1,1] * p.y
+	    };
+	
+     }	
 }

Index: init.c
===================================================================
RCS file: /cvs/cairo/cairo-5c/init.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- init.c	18 Dec 2004 08:16:28 -0000	1.8
+++ init.c	19 Dec 2004 00:06:26 -0000	1.9
@@ -629,10 +629,18 @@
 	    " void rotate (cairo_t cr, real radians)\n"
 	    "\n"
 	    " Rotate current transformation matrix by specified amount\n" },
+	{ do_Cairo_set_font, "set_font", "v", CAIRO_S "s", "\n"
+	    " void set_font (cairo_t cr, string name)\n"
+	    "\n"
+	    " Select and set current font from name.\n" },
 	{ do_Cairo_scale_font, "scale_font", "v", CAIRO_S "n", "\n"
 	    " void scale_font (cairo_t cr, real scale)\n"
 	    "\n"
 	    " Scales current font by specified amount\n" },
+	{ do_Cairo_transform_font, "transform_font", "v", CAIRO_S MATRIX_S, "\n"
+	    " void transform_font (cairo_t cr, matrix_t matrix)\n"
+	    "\n"
+	    " Transforms current font by specified matrix\n" },
 	{ do_Cairo_show_text, "show_text", "v", CAIRO_S "s", "\n"
 	    " void show_text (cairo_t cr, string text)\n"
 	    "\n"

Index: surface.c
===================================================================
RCS file: /cvs/cairo/cairo-5c/surface.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- surface.c	18 Dec 2004 08:16:28 -0000	1.6
+++ surface.c	19 Dec 2004 00:06:26 -0000	1.7
@@ -296,6 +296,7 @@
     *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);
 
     RETURN (ret);

Index: text.c
===================================================================
RCS file: /cvs/cairo/cairo-5c/text.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- text.c	17 Dec 2004 02:09:45 -0000	1.3
+++ text.c	19 Dec 2004 00:06:26 -0000	1.4
@@ -49,6 +49,45 @@
 }
 
 Value
+do_Cairo_set_font (Value cv, Value fv)
+{
+    ENTER ();
+    cairo_5c_t		*c5c = get_cairo_5c (cv);
+    char		*name = StrzPart (fv, "invalid name");
+    FcPattern		*pat;
+    static FT_Library	ft_library;
+    cairo_font_t	*font;
+    double		scale = 0;
+
+    if (aborting)
+	RETURN (Void);
+    if (!ft_library)
+	if (FT_Init_FreeType (&ft_library))
+	{
+	    RaiseStandardException (exception_open_error,
+				    "can't open FreeType",
+				    1, fv);
+	    RETURN (Void);
+	}
+    pat = FcNameParse (name);
+    FcPatternGetDouble (pat, FC_SIZE, 0, &scale);
+    font = cairo_ft_font_create (ft_library, pat);
+    FcPatternDestroy (pat);
+    if (!font)
+    {
+	RaiseStandardException (exception_open_error,
+				"can't open font",
+				1, fv);
+	RETURN (Void);
+    }
+    cairo_set_font (c5c->cr, font);
+    if (scale != 0)
+	cairo_scale_font(c5c->cr, scale);
+    cairo_font_destroy (font);
+    RETURN(Void);
+}
+
+Value
 do_Cairo_scale_font (Value cv, Value sv)
 {
     cairo_5c_t		*c5c = get_cairo_5c (cv);
@@ -60,6 +99,23 @@
 }
 
 Value
+do_Cairo_transform_font (Value cv, Value mv)
+{
+    ENTER ();
+    cairo_5c_t		*c5c = get_cairo_5c (cv);
+    cairo_matrix_t	*matrix;
+    
+    if (aborting)
+	RETURN(Void);
+    matrix = cairo_matrix_part (mv, "invalid matrix");
+    if (aborting)
+	RETURN(Void);
+    cairo_transform_font (c5c->cr, matrix);
+    cairo_matrix_destroy (matrix);
+    RETURN(Void);
+}
+
+Value
 do_Cairo_show_text (Value cv, Value uv)
 {
     cairo_5c_t		*c5c = get_cairo_5c (cv);




More information about the cairo-commit mailing list