[gjs/cairo: 4/12] [cairo] Add examples
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/cairo: 4/12] [cairo] Add examples
- Date: Sun, 21 Feb 2010 19:07:00 +0000 (UTC)
commit e615aa99c5f4c20ae178a3b7ad6159bcb9b0ce2e
Author: Johan Dahlin <johan gnome org>
Date: Sun Feb 21 16:00:11 2010 -0300
[cairo] Add examples
Makefile-examples.am | 4 ++++
examples/cairo/fill.js | 11 +++++++++++
examples/cairo/paint.js | 10 ++++++++++
examples/cairo/poppler-gdk.js | 32 ++++++++++++++++++++++++++++++++
examples/cairo/setsourcergba.js | 28 ++++++++++++++++++++++++++++
examples/cairo/showtext.js | 17 +++++++++++++++++
examples/cairo/stroke.js | 13 +++++++++++++
7 files changed, 115 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-examples.am b/Makefile-examples.am
index 70d59a0..e8d045d 100644
--- a/Makefile-examples.am
+++ b/Makefile-examples.am
@@ -1,4 +1,8 @@
EXTRA_DIST += \
+ examples/cairo/fill.js \
+ examples/cairo/poppler-gdk.js \
+ examples/cairo/setsourcergba.js \
+ examples/cairo/stroke.js \
examples/clutter.js \
examples/gio-cat.js \
examples/gtk.js \
diff --git a/examples/cairo/fill.js b/examples/cairo/fill.js
new file mode 100644
index 0000000..cc2a036
--- /dev/null
+++ b/examples/cairo/fill.js
@@ -0,0 +1,11 @@
+const Cairo = imports.cairo;
+
+let surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 120, 120);
+let cr = new Cairo.Context(surface);
+cr.scale(120, 120);
+
+cr.setSourceRGB(0, 0, 0);
+cr.rectangle(0.25, 0.25, 0.5, 0.5);
+cr.fill();
+
+surface.writeToPNG("fill.png");
diff --git a/examples/cairo/paint.js b/examples/cairo/paint.js
new file mode 100644
index 0000000..4c53280
--- /dev/null
+++ b/examples/cairo/paint.js
@@ -0,0 +1,10 @@
+const Cairo = imports.cairo;
+
+let surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 120, 120);
+let cr = new Cairo.Context(surface);
+cr.scale(120, 120);
+
+cr.setSourceRGB(0.0, 0.0, 0.0);
+cr.paintWithAlpha(0.5);
+
+surface.writeToPNG("paint.png");
diff --git a/examples/cairo/poppler-gdk.js b/examples/cairo/poppler-gdk.js
new file mode 100644
index 0000000..1463e68
--- /dev/null
+++ b/examples/cairo/poppler-gdk.js
@@ -0,0 +1,32 @@
+const Gdk = imports.gi.Gdk;
+const Gtk = imports.gi.Gtk;
+const Poppler = imports.gi.Poppler;
+const Cairo = imports.cairo;
+
+function onExpose(window, event) {
+ var cr = Gdk.cairo_create(window.window);
+ page.render(cr);
+}
+
+function onDestroy() {
+ Gtk.main_quit();
+}
+
+Gtk.init(0, null);
+
+var doc = Poppler.Document.new_from_file("file://" + ARGV[0], "");
+var page = doc.get_page(0);
+
+var win = new Gtk.Window({
+ 'type': Gtk.WindowType.TOPLEVEL
+});
+
+var draw = new Gtk.DrawingArea();
+win.add(draw);
+
+win.connect("destroy", onDestroy);
+draw.connect("expose-event", onExpose);
+
+win.show_all();
+
+Gtk.main();
diff --git a/examples/cairo/setsourcergba.js b/examples/cairo/setsourcergba.js
new file mode 100644
index 0000000..99a064d
--- /dev/null
+++ b/examples/cairo/setsourcergba.js
@@ -0,0 +1,28 @@
+const Cairo = imports.cairo;
+
+let surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 120, 120);
+let cr = new Cairo.Context(surface);
+cr.scale(120, 120);
+
+cr.setSourceRGB(0, 0, 0);
+cr.moveTo(0, 0);
+cr.lineTo(1, 1);
+cr.moveTo(1, 0);
+cr.lineTo(0, 1);
+cr.setLineWidth(0.2);
+cr.stroke();
+
+cr.rectangle(0, 0, 0.5, 0.5);
+cr.setSourceRGBA(1, 0, 0, 0.80);
+cr.fill();
+
+cr.rectangle(0, 0.5, 0.5, 0.5);
+cr.setSourceRGBA(0, 1, 0, 0.60);
+cr.fill();
+
+cr.rectangle(0.5, 0, 0.5, 0.5);
+cr.setSourceRGBA(0, 0, 1, 0.40);
+cr.fill();
+
+surface.writeToPNG("setsourcergba.png");
+
diff --git a/examples/cairo/showtext.js b/examples/cairo/showtext.js
new file mode 100644
index 0000000..6fb364c
--- /dev/null
+++ b/examples/cairo/showtext.js
@@ -0,0 +1,17 @@
+const Cairo = imports.cairo;
+
+let surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 120, 120);
+let cr = new Cairo.Context(surface);
+cr.scale(120, 120);
+
+cr.setSourceRGB(0, 0, 0);
+cr.selectFontFace("Georgia", Cairo.FontSlant.NORMAL, Cairo.FontWeight.BOLD);
+cr.setFontSize(1.2);
+
+//let te = cr.text_extents("a");
+//cr.moveTo(0.5 - te.width / 2 - te.xBearing,
+// 0.5 - te.height / 2 - te.yBearing);
+cr.showText("a");
+
+surface.writeToPNG("showtext.png");
+
diff --git a/examples/cairo/stroke.js b/examples/cairo/stroke.js
new file mode 100644
index 0000000..821d55a
--- /dev/null
+++ b/examples/cairo/stroke.js
@@ -0,0 +1,13 @@
+const Cairo = imports.cairo;
+
+let surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 120, 120);
+let cr = new Cairo.Context(surface);
+cr.scale(120, 120);
+
+cr.setLineWidth(0.1);
+cr.setSourceRGB(0, 0, 0);
+cr.rectangle(0.25, 0.25, 0.5, 0.5);
+cr.stroke();
+
+surface.writeToPNG("stroke.png");
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]