Class: RubyLabs::Canvas::Font

Inherits:
TkObject
  • Object
show all
Defined in:
lib/rubylabs.rb

Overview

Font

A Font object defines the appearance of strings displayed by a Text object.  A Font
object is a proxy for a Tk font object.  The proxy is never used by an application;
instead, when text is created, it is passed the name of the Tk font (see the example in 
the description of Font.new).

Constant Summary collapse

@@fonts =
[]

Instance Attribute Summary

Attributes inherited from TkObject

#coords, #name, #penpoint

Instance Method Summary collapse

Methods inherited from TkObject

#erase, #fill=, #lower, nextId, options, #raise, reset

Constructor Details

#initialize(name, args) ⇒ Font

Create a font named name with attributes defined in args. When creating a new Text object, name can be passed as an argument to Text.new so the string will be displayed in the specified font.

Example – create a new font for displaying fixed width text, and then display a message using this font:

>> f = Canvas::Font.new('code', :family => 'Courier', :size => 20)
=> #<RubyLabs::Canvas::Font:0x1012587b0 @name="code">
>> t = Canvas::Text.new("Go Ducks!", 100, 100, :font => 'code')
=> #<RubyLabs::Canvas::Text:0x101249300 @coords=[100, 100], @name="obj3", @penpoint=nil>

:call-seq:

x = Font.new(name,args)


1111
1112
1113
1114
1115
1116
1117
1118
# File 'lib/rubylabs.rb', line 1111

def initialize(name, args)
  @name = name
  if @@fonts.index(name).nil?
    cmnd = "font create #{name} #{TkObject.options(args)}"
    @@pipe.puts cmnd
    @@fonts << name
  end
end