Class: Tk::Font
Overview
Create and inspect fonts. The font command provides several facilities for dealing with fonts, such as defining named fonts and inspecting the actual attributes of a font.
Constant Summary collapse
- FONT_CONFIGURE_HINTS =
{ underline: :boolean, overstrike: :boolean, weight: :symbol, slant: :symbol }.freeze
Class Method Summary collapse
-
.actual(font, options = {}) ⇒ Object
NOTE: the signature has been simplified to a required
fontargument and a simpleoptionshash. - .configure(fontname, argument = None) ⇒ Object
- .create(fontname, options = None) ⇒ Object
- .delete(*fontnames) ⇒ Object
- .execute(command, *args) ⇒ Object
- .execute_only(command, *args) ⇒ Object
-
.families(options = {}) ⇒ Object
The return value is a list of the case-insensitive names of all font families that exist on window’s display.
- .measure(font, text, options = {}) ⇒ Object
- .metrics(font, option, options = {}) ⇒ Object
-
.names ⇒ Object
The return value is a list of all the named fonts that are currently defined.
Instance Method Summary collapse
- #actual(options = {}) ⇒ Object
- #actual_hash(options = {}) ⇒ Object
- #configure(argument = None) ⇒ Object
-
#initialize(string_or_hash) ⇒ Font
constructor
A new instance of Font.
- #measure(text, options = {}) ⇒ Object
- #metrics(option, options = {}) ⇒ Object
- #to_tcl ⇒ Object
Constructor Details
#initialize(string_or_hash) ⇒ Font
Returns a new instance of Font.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ffi-tk/command/font.rb', line 7 def initialize(string_or_hash) if string_or_hash.respond_to?(:to_str) string_or_hash =~ /^(.*)\s+(\d+)?$/ params = {} params[:family] = Regexp.last_match(1).to_s params[:size] = Regexp.last_match(2).to_i if Regexp.last_match(2) @font = Font.create(params) elsif string_or_hash.respond_to?(:to_hash) @font = Font.create(string_or_hash) else raise ArgumentError end end |
Class Method Details
.actual(font, options = {}) ⇒ Object
NOTE:
the signature has been simplified to a required +font+ argument and a
simple +options+ hash.
The original signature is:
`font actual font ?-displayof window? ?option? ?--? ?char?`
But it just makes things very painful.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ffi-tk/command/font.rb', line 72 def self.actual(font, = {}) window = .fetch(:displayof, None) option = .fetch(:option, None) char = .fetch(:char, None) args = [] args << '-displayof' << window unless window == None args << option.to_tcl_option unless option == None args << '--' << char.to_tcl unless char == None array = execute(:actual, font, *args) array.(FONT_CONFIGURE_HINTS) end |
.configure(fontname, argument = None) ⇒ Object
86 87 88 89 90 |
# File 'lib/ffi-tk/command/font.rb', line 86 def self.configure(fontname, argument = None) Configure.common( self, [:configure, fontname], argument, FONT_CONFIGURE_HINTS ) end |
.create(fontname, options = None) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/ffi-tk/command/font.rb', line 92 def self.create(fontname, = None) if fontname.respond_to?(:to_tcl_options) = fontname fontname = None = . end execute(:create, fontname, )&.to_str end |
.delete(*fontnames) ⇒ Object
102 103 104 |
# File 'lib/ffi-tk/command/font.rb', line 102 def self.delete(*fontnames) execute(:delete, *fontnames) end |
.execute(command, *args) ⇒ Object
54 55 56 |
# File 'lib/ffi-tk/command/font.rb', line 54 def self.execute(command, *args) Tk.execute(:font, command, *args) end |
.execute_only(command, *args) ⇒ Object
58 59 60 |
# File 'lib/ffi-tk/command/font.rb', line 58 def self.execute_only(command, *args) Tk.execute_only(:font, command, *args) end |
.families(options = {}) ⇒ Object
The return value is a list of the case-insensitive names of all font families that exist on window’s display. If the window argument is omitted, it defaults to the main window.
109 110 111 |
# File 'lib/ffi-tk/command/font.rb', line 109 def self.families( = {}) execute(:families, .) end |
.measure(font, text, options = {}) ⇒ Object
113 114 115 |
# File 'lib/ffi-tk/command/font.rb', line 113 def self.measure(font, text, = {}) execute(:measure, font, ., text) end |
.metrics(font, option, options = {}) ⇒ Object
117 118 119 |
# File 'lib/ffi-tk/command/font.rb', line 117 def self.metrics(font, option, = {}) execute(:metrics, font, ., option.to_tcl_option) end |
.names ⇒ Object
The return value is a list of all the named fonts that are currently defined.
123 124 125 |
# File 'lib/ffi-tk/command/font.rb', line 123 def self.names execute(:names).to_a end |
Instance Method Details
#actual(options = {}) ⇒ Object
23 24 25 |
# File 'lib/ffi-tk/command/font.rb', line 23 def actual( = {}) Font.actual(@font, ) end |
#actual_hash(options = {}) ⇒ Object
27 28 29 |
# File 'lib/ffi-tk/command/font.rb', line 27 def actual_hash( = {}) Font.actual(@font, ) end |
#configure(argument = None) ⇒ Object
39 40 41 |
# File 'lib/ffi-tk/command/font.rb', line 39 def configure(argument = None) Font.configure(@font, argument) end |
#measure(text, options = {}) ⇒ Object
31 32 33 |
# File 'lib/ffi-tk/command/font.rb', line 31 def measure(text, = {}) Font.measure(@font, text, ) end |