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

Zurück zum Archiv-Index

ruby-****@sourc***** ruby-****@sourc*****
2013年 3月 29日 (金) 05:28:31 JST


-------------------------
REMOTE_ADDR = 70.49.48.128
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dancr-rbcatut
-------------------------
@@ -433,33 +433,34 @@
 
     The ((<cairo_show_text()|URL:http://www.cairographics.org/manual/cairo-text.html#cairo-show-text>)) operation forms the mask from text. It may be easier to think of cairo_show_text() as a shortcut for creating a path with ((<cairo_text_path()|URL:http://www.cairographics.org/manual/cairo-Paths.html#cairo-text-path>)) and then using ((<cairo_fill()|URL:http://www.cairographics.org/manual/cairo-cairo-t.html#cairo-fill>)) to transfer it. Be aware cairo_show_text() caches glyphs so is much more efficient if you work with a lot of text.
 
-
-
     {{br}}{{image_right("1203-p06-showtext-a.png")}}
 
-     # -- your code - start ------------------------------- -s-
+     #!/usr/bin/env ruby
+     require 'cairo'
+     surface = Cairo::ImageSurface.new(120, 120)
+     cr = Cairo::Context.new(surface)
      cr.scale(120, 120)
      cr.select_font_face(
-        font_family = "Georgia", 
-        font_slant  = Cairo::FONT_SLANT_NORMAL,
-        font_weight = Cairo::FONT_WEIGHT_BOLD
+       font_family = "Georgia", 
+       font_slant  = Cairo::FONT_SLANT_NORMAL,
+       font_weight = Cairo::FONT_WEIGHT_BOLD
      )
-     cr.set_font_size(0.8)
+     cr.set_font_size(1.2)
      cr.set_source_rgb(0, 0, 1)
-
      cr_te = cr.text_extents("a")
      cr.move_to(0.5 - cr_te.width / 2  - cr_te.x_bearing, 
                 0.5 - cr_te.height / 2 - cr_te.y_bearing)
      cr.show_text("a")
-     # -- your code - end --------------------------------- -e-
+     puts "DEBUG: cr.target.class=#{cr.target.class}"	#=> Cairo::ImageSurface
+     cr.target.write_to_png("textextents-pure-cr.png")
 
 
+    This code snippet written in non-GUI environment, produces the output png image file, shown above on the right. Note, that the letter is printed on transparent surface. Indeed, to view the output of this program we have to write the contents of the surface to a file utilizing surface's write-to file method. Note, that the surface written to a file here is saved in "cairo context's target attribute". 
 
-    {{br}}{{image_right("dialog-warning.png")}}
-    This code snippet would produce the output png image file, shown above on the right, only, had Ruby supported the drawing surfaces and their behaviour, namely the ((*image_surface_create*)) method, as well as, allow them to be bound to a backend of your choice (we talked about backends above in section ((<12.3.0.1.1|tut-gtk2-dancr-rbcatut#Cairo Backends>)) and, indeed, utilize surface's write-to file method. (Instead, in Ruby Cairo implementation, you can achieve similar results by employing Ruby Gtk's file manipulation behaviours, explained in section 12.2 "((<Writing the Image Of a Drawing Area Into a Pixbuf File|tut-gtk2-dancr-wr-dapxb2file>))".
 
-    Lets look at the complete working Ruby version "Show Text / Glyphs" example program. I took liberty to add and change a few things, as well as comment the most important issues.
+    Now, lets look at the same cairo drawing as we would write it in a Ruby Gtk/Cairo version of the "Show Text / Glyphs" example program. I took liberty to add and change a few things. If you'd like to write the contents of the cairo drawing area to a file, of course, you should employ Ruby Gtk's file manipulation behaviour, explained in section 12.2 "((<Writing the Image Of a Drawing Area Into a Pixbuf File|tut-gtk2-dancr-wr-dapxb2file>))".
 
+
     {{br}}{{image_right("1203-p06-showtext-rb-s1.png")}}
 
      #!/usr/bin/env ruby
@@ -480,10 +481,12 @@
          cr.set_source_rgb(1, 0, 0)
          cr.rectangle(0.25, 0.25, 0.5, 0.5)
          cr.stroke
-         # ------------------- clone: drawing surface creation ---- -e-
+         # ------------------- clone: drawing surface creation ---- -s-
      
          # Drawing code goes here
          # ----------------------
+
          cr.select_font_face(
             font_family = "Georgia", 
             font_slant  = Cairo::FONT_SLANT_NORMAL,
@@ -502,6 +504,10 @@
      window = TextExtendsDemo.new("TextExtends Tut. Example")
      window.show_all
      Gtk.main
+
+
 
 
 




ruby-gnome2-cvs メーリングリストの案内
Zurück zum Archiv-Index