summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tk/font.rb
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-08 18:14:15 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-08 18:14:15 +0000
commitac3b12233b23713a29c83eee3f92dd41f3ac3a77 (patch)
tree221dc68a440e6eb741b5f4c87ed9b6a32ebd298a /ext/tk/lib/tk/font.rb
parent2f6f96739b23c9d9a7573c4acf27430b4cb04cf0 (diff)
* ext/tcltklib/tcltklib.c (ip_init): set root-win title to "ruby" when
the running script is '-e one-liner' or '-' (stdin). * ext/tcltklib/extconf.rb: add find_library("#{lib}#{ver}",..) for stub libs * ext/tk/lib/tk/textmark.rb: TkTextMarkCurrent and TkTextMarkAnchor have a wrong parent class. * ext/tk/lib/tk/dialog.rb: rename TkDialog2 --> TkDialogObj and TkWarning2 --> TkWarningObj (old names are changed to alias names) * ext/tk/lib/tk/dialog.rb: bug fix of treatment of 'prev_command' option and hashes for configuration * ext/tk/lib/tk/dialog.rb: add TkDialogObj#name to return the button name * ext/tk/lib/tk/radiobutton.rb: rename enbugged method value() ==> get_value() and value=(val) ==> set_value(val). * ext/tk/lib/tk/menu.rb: add TkMenu.new_menuspec * ext/tk/lib/tk/menu.rb: add alias (TkMenuButton = TkMenubutton, TkOptionMenuButton = TkOptionMenubutton) * ext/tk/lib/tk/event.rb: new method aliases (same as option keys of event_generate) for Event object * ext/tk/lib/tk/font.rb: configinfo returns proper types of values * ext/tk/lib/tk.rb: bind methods accept subst_args + block * ext/tk/lib/tk/canvas.rb: ditto * ext/tk/lib/tk/canvastag.rb: ditto * ext/tk/lib/tk/frame.rb: ditto * ext/tk/lib/tk/text.rb: ditto * ext/tk/lib/tk/texttag.rb: ditto * ext/tk/lib/tk/toplevel.rb: ditto * ext/tk/lib/tkextlib/*: ditto and bug fix git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tk/font.rb')
-rw-r--r--ext/tk/lib/tk/font.rb143
1 files changed, 117 insertions, 26 deletions
diff --git a/ext/tk/lib/tk/font.rb b/ext/tk/lib/tk/font.rb
index 2ebe661..1e314e5 100644
--- a/ext/tk/lib/tk/font.rb
+++ b/ext/tk/lib/tk/font.rb
@@ -20,6 +20,17 @@ class TkFont
Tk_FontUseTBL.clear
}
+ # option_type : default => string
+ OptionType = Hash.new(?s)
+ OptionType['size'] = ?n
+ OptionType['pointadjust'] = ?n
+ OptionType['underline'] = ?b
+ OptionType['overstrike'] = ?b
+
+ # metric_type : default => num_or_str
+ MetricType = Hash.new(?n)
+ MetricType['fixed'] = ?b
+
# set default font
case Tk::TK_VERSION
when /^4\.*/
@@ -112,6 +123,8 @@ class TkFont
case type
when 'kanji', 'latin', 'ascii'
@type = type
+ when :kanji, :latin, :ascii
+ @type = type.to_s
else
fail ArgumentError, "unknown type '#{type}'"
end
@@ -637,7 +650,7 @@ class TkFont
begin
actual_core(@latinfont).each{|key,val| latinkeys[key] = val}
rescue
- latinkeys {}
+ latinkeys = {}
end
if latinkeys != {}
tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys))
@@ -648,7 +661,7 @@ class TkFont
begin
actual_core(@kanjifont).each{|key,val| kanjikeys[key] = val}
rescue
- kanjikeys {}
+ kanjikeys = {}
end
if kanjikeys != {}
tk_call('font', 'configure', @compoundfont, *hash_kv(kanjikeys))
@@ -662,23 +675,41 @@ class TkFont
def actual_core_tk4x(font, window=nil, option=nil)
# dummy
- if option
- ""
+ if option == 'pointadjust' || option == :pointadjust
+ 1.0
+ elsif option
+ case OptionType[option.to_s]
+ when ?n
+ 0
+ when ?b
+ false
+ else
+ ''
+ end
else
- [['family',[]], ['size',[]], ['weight',[]], ['slant',[]],
- ['underline',[]], ['overstrike',[]], ['charset',[]],
- ['pointadjust',[]]]
+ [['family',''], ['size',0], ['weight',''], ['slant',''],
+ ['underline',false], ['overstrike',false], ['charset',''],
+ ['pointadjust',0]]
end
end
def actual_core_tk8x(font, window=nil, option=nil)
- if option == 'compound'
+ if option == 'compound' || option == :compound
""
elsif option
if window
- tk_call('font', 'actual', font, "-displayof", window, "-#{option}")
+ val = tk_call('font', 'actual', font,
+ "-displayof", window, "-#{option}")
+ else
+ val = tk_call('font', 'actual', font, "-#{option}")
+ end
+ case OptionType[option.to_s]
+ when ?n
+ num_or_str(val)
+ when ?b
+ bool(val)
else
- tk_call('font', 'actual', font, "-#{option}")
+ val
end
else
l = tk_split_simplelist(if window
@@ -692,7 +723,16 @@ class TkFont
if key == '-compound'
l.shift
else
- r.push [key[1..-1], l.shift]
+ key = key[1..-1]
+ val = l.shift
+ case OptionType[key]
+ when ?n
+ r.push [key, num_or_str(val)]
+ when ?b
+ r.push [key, bool(val)]
+ else
+ r.push [key, val]
+ end
end
end
r
@@ -707,12 +747,21 @@ class TkFont
def configinfo_core_tk4x(font, option=nil)
# dummy
if TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
- if option
- ""
+ if option == 'pointadjust' || option == :pointadjust
+ 1.0
+ elsif option
+ case OptionType[option.to_s]
+ when ?n
+ 0
+ when ?b
+ false
+ else
+ ''
+ end
else
- [['family',[]], ['size',[]], ['weight',[]], ['slant',[]],
- ['underline',[]], ['overstrike',[]], ['charset',[]],
- ['pointadjust',[]]]
+ [['family',''], ['size',0], ['weight',''], ['slant',''],
+ ['underline',false], ['overstrike',false], ['charset',''],
+ ['pointadjust',1.0]]
end
else # ! TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
current_configinfo_core_tk4x(font, option)
@@ -721,10 +770,18 @@ class TkFont
def current_configinfo_core_tk4x(font, option=nil)
if option
- ""
+ case OptionType[option.to_s]
+ when ?n
+ 0
+ when ?b
+ false
+ else
+ ''
+ end
else
- {'family'=>'', 'size'=>'', 'weight'=>'', 'slant'=>'',
- 'underline'=>'', 'overstrike'=>'', 'charset'=>'', 'pointadjust'=>''}
+ {'family'=>'', 'size'=>0, 'weight'=>'', 'slant'=>'',
+ 'underline'=>false, 'overstrike'=>false,
+ 'charset'=>false, 'pointadjust'=>1.0}
end
end
@@ -797,10 +854,18 @@ class TkFont
def configinfo_core_tk8x(font, option=nil)
if TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
- if option == 'compound'
+ if option == 'compound' || option == :compound
""
elsif option
- tk_call('font', 'configure', font, "-#{option}")
+ val = tk_call('font', 'configure', font, "-#{option}")
+ case OptionType[option.to_s]
+ when ?n
+ num_or_str(val)
+ when ?b
+ bool(val)
+ else
+ val
+ end
else
l = tk_split_simplelist(tk_call('font', 'configure', font))
r = []
@@ -808,7 +873,16 @@ class TkFont
if key == '-compound'
l.shift
else
- r.push [key[1..-1], l.shift]
+ key = key[1..-1]
+ val = l.shift
+ case OptionType[key]
+ when ?n
+ r.push [key, num_or_str(val)]
+ when ?b
+ r.push [key, bool(val)]
+ else
+ r.push [key, val]
+ end
end
end
r
@@ -822,7 +896,15 @@ class TkFont
if option == 'compound'
""
elsif option
- tk_call('font', 'configure', font, "-#{option}")
+ val = tk_call('font', 'configure', font, "-#{option}")
+ case OptionType[option.to_s]
+ when ?n
+ num_or_str(val)
+ when ?b
+ bool(val)
+ else
+ val
+ end
else
l = tk_split_simplelist(tk_call('font', 'configure', font))
r = {}
@@ -830,7 +912,16 @@ class TkFont
if key == '-compound'
l.shift
else
- r[key[1..-1]] = l.shift
+ key = key[1..-1]
+ val = l.shift
+ case OptionType[key]
+ when ?n
+ r.push [key, num_or_str(val)]
+ when ?b
+ r.push [key, bool(val)]
+ else
+ r.push [key, val]
+ end
end
end
r
@@ -958,7 +1049,7 @@ class TkFont
begin
actual_core(@latinfont).each{|key,val| latinkeys[key] = val}
rescue
- latinkeys {}
+ latinkeys = {}
end
if latinkeys != {}
tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys))
@@ -981,7 +1072,7 @@ class TkFont
begin
actual_core(@latinfont).each{|key,val| latinkeys[key] = val}
rescue
- latinkeys {}
+ latinkeys = {}
end
if latinkeys != {}
tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys))