[cairo-commit] pycairo/examples context-subclass.py, 1.1, 1.2 gradient.py, 1.1, 1.2 hering.py, 1.2, 1.3 warpedtext.py, 1.2, 1.3

Steve Chaplin commit at pdx.freedesktop.org
Tue Mar 29 16:22:21 PST 2005


Committed by: stevech1097

Update of /cvs/cairo/pycairo/examples
In directory gabe:/tmp/cvs-serv14462/examples

Modified Files:
	context-subclass.py gradient.py hering.py warpedtext.py 
Log Message:
SC 2005/03/30

Index: context-subclass.py
===================================================================
RCS file: /cvs/cairo/pycairo/examples/context-subclass.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- context-subclass.py	15 Nov 2004 10:05:27 -0000	1.1
+++ context-subclass.py	30 Mar 2005 00:22:18 -0000	1.2
@@ -37,12 +37,15 @@
         self.set_rgb_color (0, 1, 0)
         self.stroke()
         
+surface = cairo.Surface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
+ctx = MyContext()
+ctx.set_target_surface(surface)
+
+ctx.draw()
+
 try:
     fileObject = file('context-subclass.png', 'wb')
 except IOError, exc:
     raise SystemExit("%s: %s" % (exc.filename, exc.strerror))
 
-ctx = MyContext()
-ctx.set_target_png (fileObject, cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
-ctx.draw()
-ctx.show_page()
+surface.write_png(fileObject)

Index: gradient.py
===================================================================
RCS file: /cvs/cairo/pycairo/examples/gradient.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- gradient.py	4 Nov 2004 14:45:35 -0000	1.1
+++ gradient.py	30 Mar 2005 00:22:18 -0000	1.2
@@ -7,13 +7,9 @@
 
 WIDTH, HEIGHT  = 256, 256
 
-try:
-    fileObject = file('gradient.png', 'wb')
-except IOError, exc:
-    raise SystemExit("%s: %s" % (exc.filename, exc.strerror))
-
+surface = cairo.Surface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
 ctx = cairo.Context()
-ctx.set_target_png (fileObject, cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
+ctx.set_target_surface(surface)
 
 ctx.scale (WIDTH/1.0, HEIGHT/1.0)
 
@@ -34,4 +30,9 @@
 ctx.arc (0.5, 0.5, 0.3, 0, 2 * math.pi)
 ctx.fill ()
 
-ctx.show_page()
+try:
+    fileObject = file('gradient.png', 'wb')
+except IOError, exc:
+    raise SystemExit("%s: %s" % (exc.filename, exc.strerror))
+
+surface.write_png(fileObject)

Index: hering.py
===================================================================
RCS file: /cvs/cairo/pycairo/examples/hering.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- hering.py	11 Nov 2004 15:32:12 -0000	1.2
+++ hering.py	30 Mar 2005 00:22:18 -0000	1.3
@@ -42,13 +42,9 @@
     ctx.stroke()
 
 
-try:
-    fileObject = file('hering.png', 'wb')
-except IOError, exc:
-    raise SystemExit("%s: %s" % (exc.filename, exc.strerror))
-
+surface = cairo.Surface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
 ctx = cairo.Context()
-ctx.set_target_png (fileObject, cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
+ctx.set_target_surface(surface)
 
 ctx.rectangle (0, 0, WIDTH, HEIGHT)
 ctx.set_rgb_color (1, 1, 1)
@@ -56,4 +52,9 @@
 
 draw_hering (ctx, WIDTH, HEIGHT)
 
-ctx.show_page()
+try:
+    fileObject = file('hering.png', 'wb')
+except IOError, exc:
+    raise SystemExit("%s: %s" % (exc.filename, exc.strerror))
+
+surface.write_png(fileObject)

Index: warpedtext.py
===================================================================
RCS file: /cvs/cairo/pycairo/examples/warpedtext.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- warpedtext.py	14 Mar 2005 16:43:41 -0000	1.2
+++ warpedtext.py	30 Mar 2005 00:22:18 -0000	1.3
@@ -34,10 +34,11 @@
 
 
 WIDTH, HEIGHT = 512, 512
-file = open("warpedtext.png", "wb")
 
+surface = cairo.Surface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
 ctx = cairo.Context()
-ctx.set_target_png(file, cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
+ctx.set_target_surface(surface)
+
 ctx.identity_matrix()
 
 solidpattern = ctx.pattern
@@ -79,7 +80,7 @@
 textwidth, textheight = ctx.text_extents(text)[2:4]
 def curl(x, y):
 	xn = x - textwidth/2
-	yn = y - textheight/2
+	#yn = y - textheight/2
 	xnew = xn
 	ynew = y + xn ** 3 / ((textwidth/2)**3) * 70
 	return xnew + WIDTH/2, ynew + HEIGHT*2/5
@@ -88,5 +89,9 @@
 ctx.fill()
 
 
-ctx.show_page()
+try:
+    fileObject = file("warpedtext.png", 'wb')
+except IOError, exc:
+    raise SystemExit("%s: %s" % (exc.filename, exc.strerror))
 
+surface.write_png(fileObject)




More information about the cairo-commit mailing list