[ruby-gnome2-doc-cvs] [Ruby-GNOME2 Project Website] update - tut-gtk2-dancr-rbcatut

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2013年 3月 29日 (金) 04:45:26 JST


-------------------------
REMOTE_ADDR = 70.49.48.128
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dancr-rbcatut
-------------------------
@@ -204,8 +204,29 @@
 Now, all you need to run these programs above is to copy the((*'hiki2-gtk-w-cairo.rb'*))module file into your working directory. You will find it near the end of this chapter (look for the section (12.3.XXXX) ((<Hiki Gtk With Cairo Module File|tut-gtk2-dancr-rbcatut#Hiki Gtk With Cairo Module File>)).
 
 {{br}}
+{{br}}
 
 
+
+
+
+
+=== Running Pure Cairo Without Gtk In Ruby
+
+One reason I separated this paragraph from the rest of the tutorial is to stress the difference between using into Ruby Gtk integrated Cairo Library from the original pure (you can say stand-alone) Cairo Library. The first, integrated one, is available to Gtk programmers automatically, i.e. requiring Gtk module is all that is needed. But If you want the full featured Cairo library, you need to((*require 'cairo'*)) yourself. Indeed, you can do that even if you are not running Gtk at all, that is you do not need to((*require 'gtk2',*)) and obviously, without this module you also can not run the gtk-main loop.
+
+The examples in ((<the official Cairo Tutorial|URL:http://www.cairographics.org/tutorial/>)) run outside any particular GUI system, hence, we should not, and we do not, have any trouble running them in Ruby directly without the Gtk. But, since this is the Gtk Tutorial, which, as anybody who read most of it before any Cairo features even came up, knows that Cairo should be part of the Gtk. Unfortunately, for those of us who have been struggling to learn or master Gtk for a while, encountering Cairo outside our GUI, it may seem odd, why would anyone consider running 2D graphic programs from a text based terminal. Why would I even try to look for solutions outside my GUI environment which as I could see includes Cairo Library. It never crossed my mind, that by requiring 'cairo' module, I'd gain power of pure Cairo beyond that available in my GUI!
+
+The fact is, that's exactly what you should do, to translate and run the official Cairo Tutorial examples in Ruby. Hence, you should forget, about Ruby's Gdk::Drawable#create_cairo_context, and resort to plain old Cairo ways of creating it via:
+
+ surface = Cairo::XyzSurface.new(width, height)
+ cr = Cairo::Context.new(surface)
+ # -- Your cairo code starts here -------------- -s-
+ #      o o o
+ # -- Your cairo code ends here ---------------- -e-
+ cr.target.write_to_png("output-file.png")
+
+by replacing the word "Xyz" above with one of the following { Image, PDF, PS, SVG, ... }, including your cairo code and at the end write the contents of the cairo surface you created to the file.
 
 
 




ruby-gnome2-cvs メーリングリストの案内
Back to archive index