summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tk/font.rb
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-03-26 13:58:11 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-03-26 13:58:11 +0000
commit7738391d237112db43bb47f793fc0939fb561d00 (patch)
tree6ee086fb50b03430ed910426c6cd676ea8de237d /ext/tk/lib/tk/font.rb
parentee46b19927ceb9993077579f0ede19afdc21e1be (diff)
* ext/tk/lib/tk.rb (_callback_entry_class?): add for checking whether
a class is available for a callback entry. * ext/tk/lib/tk.rb (after_cancel): add Tk.after_cancel(afterID) method. * ext/tk/lib/tk.rb (array2tk_list): change from private module method of TkComm to public module method. * ext/tk/lib/tk.rb (cget): add check that slot argument is not empty string. * ext/tk/lib/tk.rb (configinfo): ditto. * ext/tk/lib/tk/itemconfig.rb (itemcget): add check that slot argument is not empty string. * ext/tk/lib/tk/itemconfig.rb (itemconfiginfo): ditto. * ext/tk/lib/tk/entry.rb: add TkEntry#icursor and icursor= (alias of cursor and cursor= method). * ext/tk/lib/tk/font.rb: improve font treatment when the font name is empty string. * ext/tk/lib/tk/variable.rb: add :variable, :window and :procedure type. * ext/tk/lib/tk/variable.rb: improve treatment of array-type tkvariable. * ext/tk/lib/tkextlib/blt.rb: add commands for zooming. * ext/tk/lib/tkextlib/blt/*: bug fix. * ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: bug fix and add methods to call TreeCtrl commands for bindings. * ext/tk/sample/tkextlib/blt/*: new sample scritps. * ext/tk/sample/tkextlib/treectrl/*: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tk/font.rb')
-rw-r--r--ext/tk/lib/tk/font.rb113
1 files changed, 107 insertions, 6 deletions
diff --git a/ext/tk/lib/tk/font.rb b/ext/tk/lib/tk/font.rb
index 389f001..8e63558 100644
--- a/ext/tk/lib/tk/font.rb
+++ b/ext/tk/lib/tk/font.rb
@@ -164,6 +164,7 @@ class TkFont
# class methods
###################################
def TkFont.actual(fnt, option=nil)
+ fnt = '{}' if fnt == ''
if fnt.kind_of?(TkFont)
fnt.actual(option)
else
@@ -172,6 +173,7 @@ class TkFont
end
def TkFont.actual_displayof(fnt, win, option=nil)
+ fnt = '{}' if fnt == ''
if fnt.kind_of?(TkFont)
fnt.actual_displayof(win, option)
else
@@ -206,6 +208,7 @@ class TkFont
end
def TkFont.measure(fnt, text)
+ fnt = '{}' if fnt == ''
if fnt.kind_of?(TkFont)
fnt.measure(text)
else
@@ -214,6 +217,7 @@ class TkFont
end
def TkFont.measure_displayof(fnt, win, text)
+ fnt = '{}' if fnt == ''
if fnt.kind_of?(TkFont)
fnt.measure_displayof(win, text)
else
@@ -223,6 +227,7 @@ class TkFont
end
def TkFont.metrics(fnt, option=nil)
+ fnt = '{}' if fnt == ''
if fnt.kind_of?(TkFont)
fnt.metrics(option)
else
@@ -231,6 +236,7 @@ class TkFont
end
def TkFont.metrics_displayof(fnt, win, option=nil)
+ fnt = '{}' if fnt == ''
if fnt.kind_of?(TkFont)
font.metrics_displayof(win, option=nil)
else
@@ -338,13 +344,17 @@ class TkFont
fnt = nil if fnt == [] || fnt == ""
unless fnt
- TkFont.new(nil, nil).call_font_configure([path, key], *args)
+ # create dummy
+ # TkFont.new(nil, nil).call_font_configure([path, key], *args)
+ dummy_fnt = TkFont.allocate
+ dummy_fnt.instance_eval{ init_dummy_fontobj() }
+ dummy_fnt
else
begin
compound = tk_split_simplelist(
Hash[*tk_split_simplelist(tk_call('font', 'configure',
- fnt))].collect{|key,value|
- [key[1..-1], value]
+ fnt))].collect{|k,v|
+ [k[1..-1], v]
}.assoc('compound')[1])
rescue
compound = []
@@ -381,7 +391,51 @@ class TkFont
###################################
private
###################################
+ def init_dummy_fontobj
+ @id = Tk_FontID.join(TkCore::INTERP._ip_id_)
+ Tk_FontID[1].succ!
+ Tk_FontNameTBL[@id] = self
+
+ @latin_desscendant = nil
+ @kanji_desscendant = nil
+
+ case (Tk::TK_VERSION)
+ when /^4\.*/
+ @latinfont = ""
+ @kanjifont = ""
+ if JAPANIZED_TK
+ @compoundfont = [[@latinfont], [@kanjifont]]
+ @fontslot = {'font'=>@latinfont, 'kanjifont'=>@kanjifont}
+ else
+ @compoundfont = @latinfont
+ @fontslot = {'font'=>@latinfont}
+ end
+ else
+ @latinfont = @id + 'l'
+ @kanjifont = @id + 'k'
+ @compoundfont = @id + 'c'
+
+ if JAPANIZED_TK
+ tk_call('font', 'create', @latinfont, '-charset', 'iso8859')
+ tk_call('font', 'create', @kanjifont, '-charset', 'jisx0208.1983')
+ tk_call('font', 'create', @compoundfont,
+ '-compound', [@latinfont, @kanjifont])
+ else
+ tk_call('font', 'create', @latinfont)
+ tk_call('font', 'create', @kanjifont)
+ tk_call('font', 'create', @compoundfont)
+ end
+
+ @fontslot = {'font'=>@compoundfont}
+ end
+
+ self
+ end
+
def initialize(ltn=nil, knj=nil, keys=nil)
+ ltn = '{}' if ltn == ''
+ knj = '{}' if knj == ''
+
# @id = Tk_FontID.join('')
@id = Tk_FontID.join(TkCore::INTERP._ip_id_)
Tk_FontID[1].succ!
@@ -657,10 +711,17 @@ class TkFont
end
def create_compoundfont_tk8x(ltn, knj, keys)
- create_latinfont(ltn)
- create_kanjifont(knj)
+ if knj
+ create_latinfont(ltn)
+ create_kanjifont(knj)
+ else
+ cfnt = ltn
+ create_kanjifont(cfnt)
+ create_latinfont(cfnt)
+ end
@compoundfont = @id + 'c'
+
if JAPANIZED_TK
unless keys
keys = {}
@@ -735,6 +796,7 @@ class TkFont
end
if knj
+ compoundkeys = nil
kanjikeys = {}
begin
actual_core(@kanjifont).each{|key,val| kanjikeys[key] = val}
@@ -746,6 +808,17 @@ class TkFont
end
end
+ if cfnt
+ if cfnt.kind_of?(Hash)
+ compoundkeys = cfnt.dup
+ else
+ compoundkeys = {}
+ actual_core(cfnt).each{|key,val| compoundkeys[key] = val}
+ end
+ compoundkeys.update(_symbolkey2str(keys))
+ keys = compoundkeys
+ end
+
@fontslot = {'font'=>@compoundfont}
tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
end
@@ -754,11 +827,21 @@ class TkFont
###################################
public
###################################
+ def inspect
+ sprintf("#<%s:%0x:%s>", self.class.inspect, self.__id__, @compoundfont)
+ end
+
def method_missing(id, *args)
name = id.id2name
case args.length
when 1
- configure name, args[0]
+ if name[-1] == ?=
+ configure name[0..-2], args[0]
+ args[0]
+ else
+ configure name, args[0]
+ self
+ end
when 0
begin
configinfo name
@@ -1099,6 +1182,7 @@ class TkFont
alias ascii_metrics latin_metrics
###################################
+=begin
def dup
src = self
obj = super()
@@ -1111,6 +1195,13 @@ class TkFont
obj.instance_eval{ initialize(src) }
obj
end
+=end
+ def dup
+ TkFont.new(self)
+ end
+ def clone
+ TkFont.new(self)
+ end
end
module TkFont::CoreMethods
@@ -1140,6 +1231,8 @@ module TkFont::CoreMethods
end
def actual_core_tk8x(font, win=nil, option=nil)
+ font = '{}' if font == ''
+
if option == 'compound' || option == :compound
""
elsif option
@@ -1465,6 +1558,8 @@ module TkFont::CoreMethods
end
def latin_replace_core_tk8x(ltn)
+ ltn = '{}' if ltn == ''
+
if JAPANIZED_TK
begin
tk_call('font', 'delete', '@font_tmp')
@@ -1528,6 +1623,8 @@ module TkFont::CoreMethods
end
def kanji_replace_core_tk8x(knj)
+ knj = '{}' if knj == ''
+
if JAPANIZED_TK
begin
tk_call('font', 'delete', '@font_tmp')
@@ -1573,6 +1670,8 @@ module TkFont::CoreMethods
end
def measure_core_tk8x(font, win, text)
+ font = '{}' if font == ''
+
if win
number(tk_call('font', 'measure', font,
'-displayof', win, text))
@@ -1591,6 +1690,8 @@ module TkFont::CoreMethods
end
def metrics_core_tk8x(font, win, option=nil)
+ font = '{}' if font == ''
+
if option
if win
number(tk_call('font', 'metrics', font,