Sha256: 396dc1efa60e4e6e32ce39176a3a2fbd0cf037690b7694f639e1b5c6e938aa7c

Contents?: true

Size: 1.08 KB

Versions: 166

Compression:

Stored size: 1.08 KB

Contents

# Copyright (c) 2005 Ruby-GNOME2 Project Team
# This program is licenced under the same licence as Ruby-GNOME2.
#
# $Id: cairo-text-extents.rb,v 1.1 2005/10/12 05:38:30 ktou Exp $
=begin
= cairo/Text Extents

This demo shows how to use GDK and cairo to show text extents.
From http://cairographics.org/samples/text.html.
=end
require 'common'

module Demo
  class CairoTextExtents < CairoWindow
    TEXT = "Ruby"

    def initialize
      super('cairo text')
    end

    def draw(cr)
      cr.select_font_face("Sans",
                              Cairo::FONT_SLANT_NORMAL,
                              Cairo::FONT_WEIGHT_NORMAL)

      cr.set_font_size(0.3)
      extents = cr.text_extents(TEXT)

      x = 0.1
      y = 0.6

      cr.move_to(x, y)
      cr.show_text(TEXT)

      # draw helping lines
      cr.set_source_rgba(1, 0.2, 0.2, 0.6)
      cr.arc(x, y, 0.05, 0, 2 * Math::PI)
      cr.fill
      cr.move_to(x, y)
      cr.rel_line_to(0, -extents.height)
      cr.rel_line_to(extents.width, 0)
      cr.rel_line_to(extents.x_bearing, -extents.y_bearing)
      cr.stroke
    end
  end
end

Version data entries

166 entries across 158 versions & 2 rubygems

Version Path
gtk3-4.2.7 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.2.6 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.2.5 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.2.4 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.2.3 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.2.2 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.2.1 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.2.0 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.1.9 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.1.8 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.1.7 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.1.6 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.1.5 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.1.4 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.1.3 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.1.2 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.1.1 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.1.0 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.0.9 sample/gtk-demo/old_demos/cairo-text-extents.rb
gtk3-4.0.8 sample/gtk-demo/old_demos/cairo-text-extents.rb