diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-09-02 05:04:30 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-09-02 05:04:30 +0000 |
commit | 9388ed284d600f2225a745dfb3edb6ac1758fdb8 (patch) | |
tree | 1b7b09cfaa93e97d9e38389ddec7657418aa17ac | |
parent | 645d4abf426fb2ef4ae72d0d46c24607b71be3a8 (diff) | |
download | ruby-9388ed284d600f2225a745dfb3edb6ac1758fdb8.tar.gz |
* ext/tcltklib/tcltklib.c (ip_invoke): fixed bug on passing a exception
* ext/tk/lib/{tk.rb, tkcanvas.rb, tkfont.rb, tktext.rb} :
bug fix and improvement of font control
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | ext/tcltklib/tcltklib.c | 6 | ||||
-rw-r--r-- | ext/tk/lib/tk.rb | 324 | ||||
-rw-r--r-- | ext/tk/lib/tkcanvas.rb | 20 | ||||
-rw-r--r-- | ext/tk/lib/tkfont.rb | 144 | ||||
-rw-r--r-- | ext/tk/lib/tktext.rb | 36 | ||||
-rw-r--r-- | ext/tk/sample/demos-en/widget | 6 | ||||
-rw-r--r-- | ext/tk/sample/demos-jp/ctext.rb | 2 | ||||
-rw-r--r-- | ext/tk/sample/demos-jp/widget | 4 |
9 files changed, 410 insertions, 139 deletions
@@ -1,3 +1,10 @@ +Tue Sep 2 14:02:19 2003 <nagai@ai.kyutech.ac.jp> + + * ext/tcltklib/tcltklib.c (ip_invoke): fixed bug on passing a exception + + * ext/tk/lib/{tk.rb, tkcanvas.rb, tkfont.rb, tktext.rb} : + bug fix and improvement of font control + Tue Sep 2 09:51:36 2003 Nobuyoshi Nakada <nobu@ruby-lang.org> * eval.c (rb_eval): should not handle exceptions within rescue diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c index cb2036296a..ef91fcae3d 100644 --- a/ext/tcltklib/tcltklib.c +++ b/ext/tcltklib/tcltklib.c @@ -1313,7 +1313,11 @@ ip_invoke(argc, argv, obj) } if (eventloop_thread == 0 || current == eventloop_thread) { DUMP2("invoke from current eventloop %lx", current); - return ip_invoke_real(argc, argv, obj); + result = ip_invoke_real(argc, argv, obj); + if (rb_obj_is_kind_of(result, rb_eException)) { + rb_exc_raise(result); + } + return result; } DUMP2("invoke from thread %lx (NOT current eventloop)", current); diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 2f42160313..6bd2736fe4 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -3233,94 +3233,131 @@ module TkTreatFont def font_configure(slot) slot = _symbolkey2str(slot) - if (fnt = slot.delete('font')) + + if slot.key?('font') + fnt = slot.delete('font') if fnt.kind_of? TkFont return fnt.call_font_configure(self.path, self.path,'configure',slot) else - if fnt - latinfont_configure(fnt) - kanjifont_configure(fnt) + if fnt + if (slot.key?('kanjifont') || + slot.key?('latinfont') || + slot.key?('asciifont')) + fnt = TkFont.new(fnt) + + lfnt = slot.delete('latinfont') + lfnt = slot.delete('asciifont') if slot.key?('asciifont') + kfnt = slot.delete('kanjifont') + + fnt.latin_replace(lfnt) if lfnt + fnt.kanji_replace(kfnt) if kfnt + else + slot['font'] = fnt + tk_call(self.path, 'configure', *hash_kv(slot)) + end end + return self end end - if (ltn = slot.delete('latinfont')) - latinfont_configure(ltn) if ltn - end - if (ltn = slot.delete('asciifont')) - latinfont_configure(ltn) if ltn - end - if (knj = slot.delete('kanjifont')) - kanjifont_configure(knj) if knj + + lfnt = slot.delete('latinfont') + lfnt = slot.delete('asciifont') if slot.key?('asciifont') + kfnt = slot.delete('kanjifont') + + if lfnt && kfnt + return TkFont.new(lfnt, kfnt).call_font_configure(self.path, self.path, + 'configure', slot) end + latinfont_configure(lfnt) if lfnt + kanjifont_configure(kfnt) if kfnt + tk_call(self.path, 'configure', *hash_kv(slot)) if slot != {} self end def latinfont_configure(ltn, keys=nil) - fobj = fontobj - if ltn.kind_of? TkFont - conf = {} - ltn.latin_configinfo.each{|key,val| conf[key] = val} - if keys - fobj.latin_configure(conf.update(keys)) + if (fobj = TkFont.used_on(self.path)) + fobj = TkFont.new(fobj) # create a new TkFont object + elsif Tk::JAPANIZED_TK + fobj = fontobj # create a new TkFont object + else + tk_call(self.path, 'configure', '-font', ltn) + return self + end + + if fobj.kind_of?(TkFont) + if ltn.kind_of? TkFont + conf = {} + ltn.latin_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.latin_configure(conf.update(keys)) + else + fobj.latin_configure(conf) + end else - fobj.latin_configure(conf) + fobj.latin_replace(ltn) end - else - fobj.latin_replace(ltn) end - self + + return fobj.call_font_configure(self.path, self.path, 'configure', {}) end alias asciifont_configure latinfont_configure def kanjifont_configure(knj, keys=nil) - fobj = fontobj - if knj.kind_of? TkFont - conf = {} - knj.kanji_configinfo.each{|key,val| conf[key] = val} - if keys - fobj.kanji_configure(conf.update(keys)) + if (fobj = TkFont.used_on(self.path)) + fobj = TkFont.new(fobj) # create a new TkFont object + elsif Tk::JAPANIZED_TK + fobj = fontobj # create a new TkFont object + else + tk_call(self.path, 'configure', '-font', knj) + return self + end + + if fobj.kind_of?(TkFont) + if knj.kind_of? TkFont + conf = {} + knj.kanji_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.kanji_configure(conf.update(keys)) + else + fobj.kanji_configure(conf) + end else - fobj.kanji_configure(cond) + fobj.kanji_replace(knj) end - else - fobj.kanji_replace(knj) end - self + + return fobj.call_font_configure(self.path, self.path, 'configure', {}) end def font_copy(window, tag=nil) if tag - window.tagfontobj(tag).configinfo.each{|key,value| - fontobj.configure(key,value) - } - fontobj.replace(window.tagfontobj(tag).latin_font, - window.tagfontobj(tag).kanji_font) + fnt = window.tagfontobj(tag).dup else - window.fontobj.configinfo.each{|key,value| - fontobj.configure(key,value) - } - fontobj.replace(window.fontobj.latin_font, window.fontobj.kanji_font) + fnt = window.fontobj.dup end + fnt.call_font_configure(self.path, self.path, 'configure', {}) self end def latinfont_copy(window, tag=nil) + fontobj.dup.call_font_configure(self.path, self.path, 'configure', {}) if tag - fontobj.latin_replace(window.tagfontobj(tag).latin_font) + fontobj.latin_replace(window.tagfontobj(tag).latin_font_id) else - fontobj.latin_replace(window.fontobj.latin_font) + fontobj.latin_replace(window.fontobj.latin_font_id) end self end alias asciifont_copy latinfont_copy def kanjifont_copy(window, tag=nil) + fontobj.dup.call_font_configure(self.path, self.path, 'configure', {}) if tag - fontobj.kanji_replace(window.tagfontobj(tag).kanji_font) + fontobj.kanji_replace(window.tagfontobj(tag).kanji_font_id) else - fontobj.kanji_replace(window.fontobj.kanji_font) + fontobj.kanji_replace(window.fontobj.kanji_font_id) end self end @@ -3357,104 +3394,151 @@ module TkTreatItemFont def tagfont_configure(tagOrId, slot) pathname = __item_pathname(tagOrId) slot = _symbolkey2str(slot) - if (fnt = slot.delete('font')) + + if slot.key?('font') + fnt = slot.delete('font') if fnt.kind_of? TkFont - return fnt.call_font_configure(pathname, self.path, + return fnt.call_font_configure(pathname, self.path, __conf_cmd(0), __conf_cmd(1), tagOrId, slot) else - if fnt - latintagfont_configure(tagOrId, fnt) - kanjitagfont_configure(tagOrId, fnt) + if fnt + if (slot.key?('kanjifont') || + slot.key?('latinfont') || + slot.key?('asciifont')) + fnt = TkFont.new(fnt) + + lfnt = slot.delete('latinfont') + lfnt = slot.delete('asciifont') if slot.key?('asciifont') + kfnt = slot.delete('kanjifont') + + fnt.latin_replace(lfnt) if lfnt + fnt.kanji_replace(kfnt) if kfnt + end + + slot['font'] = fnt + tk_call(self.path, __conf_cmd(0), __conf_cmd(1), + tagOrId, *hash_kv(slot)) end + return self end end - if (ltn = slot.delete('latinfont')) - latintagfont_configure(tagOrId, ltn) if ltn - end - if (ltn = slot.delete('asciifont')) - latintagfont_configure(tagOrId, ltn) if ltn - end - if (knj = slot.delete('kanjifont')) - kanjitagfont_configure(tagOrId, knj) if knj + + lfnt = slot.delete('latinfont') + lfnt = slot.delete('asciifont') if slot.key?('asciifont') + kfnt = slot.delete('kanjifont') + + if lfnt && kfnt + return TkFont.new(lfnt, kfnt).call_font_configure(pathname, self.path, + __conf_cmd(0), + __conf_cmd(1), + tagOrId, slot) end + latintagfont_configure(tagOrId, lfnt) if lfnt + kanjitagfont_configure(tagOrId, kfnt) if kfnt + tk_call(self.path, __conf_cmd(0), __conf_cmd(1), tagOrId, *hash_kv(slot)) if slot != {} self end def latintagfont_configure(tagOrId, ltn, keys=nil) - fobj = tagfontobj(tagOrId) - if ltn.kind_of? TkFont - conf = {} - ltn.latin_configinfo.each{|key,val| conf[key] = val if val != []} - if conf == {} - fobj.latin_replace(ltn) - fobj.latin_configure(keys) if keys - elsif keys - fobj.latin_configure(conf.update(keys)) + pathname = __item_pathname(tagOrId) + if (fobj = TkFont.used_on(pathname)) + fobj = TkFont.new(fobj) # create a new TkFont object + elsif Tk::JAPANIZED_TK + fobj = tagfontobj(tagOrId) # create a new TkFont object + else + tk_call(self.path, __conf_cmd(0), __conf_cmd(1), tagOrId, '-font', ltn) + return self + end + + if fobj.kind_of?(TkFont) + if ltn.kind_of? TkFont + conf = {} + ltn.latin_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.latin_configure(conf.update(keys)) + else + fobj.latin_configure(conf) + end else - fobj.latin_configure(conf) + fobj.latin_replace(ltn) end - else - fobj.latin_replace(ltn) end - self + + return fobj.call_font_configure(pathname, self.path, + __conf_cmd(0), __conf_cmd(1), tagOrId, {}) end alias asciitagfont_configure latintagfont_configure def kanjitagfont_configure(tagOrId, knj, keys=nil) - fobj = tagfontobj(tagOrId) - if knj.kind_of? TkFont - conf = {} - knj.kanji_configinfo.each{|key,val| conf[key] = val if val != []} - if conf == {} - fobj.kanji_replace(knj) - fobj.kanji_configure(keys) if keys - elsif keys - fobj.kanji_configure(conf.update(keys)) + pathname = __item_pathname(tagOrId) + if (fobj = TkFont.used_on(pathname)) + fobj = TkFont.new(fobj) # create a new TkFont object + elsif Tk::JAPANIZED_TK + fobj = tagfontobj(tagOrId) # create a new TkFont object + else + tk_call(self.path, __conf_cmd(0), __conf_cmd(1), tagOrId, '-font', knj) + return self + end + + if fobj.kind_of?(TkFont) + if knj.kind_of? TkFont + conf = {} + knj.kanji_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.kanji_configure(conf.update(keys)) + else + fobj.kanji_configure(conf) + end else - fobj.kanji_configure(conf) + fobj.kanji_replace(knj) end - else - fobj.kanji_replace(knj) end - self + + return fobj.call_font_configure(pathname, self.path, + __conf_cmd(0), __conf_cmd(1), tagOrId, {}) end def tagfont_copy(tagOrId, window, wintag=nil) + pathname = __item_pathname(tagOrId) if wintag - window.tagfontobj(wintag).configinfo.each{|key,value| - tagfontobj(tagOrId).configure(key,value) - } - tagfontobj(tagOrId).replace(window.tagfontobj(wintag).latin_font, - window.tagfontobj(wintag).kanji_font) + fnt = window.tagfontobj(wintag).dup else - window.tagfont(wintag).configinfo.each{|key,value| - tagfontobj(tagOrId).configure(key,value) - } - tagfontobj(tagOrId).replace(window.fontobj.latin_font, - window.fontobj.kanji_font) + fnt = window.fontobj.dup end - self + fnt.call_font_configure(pathname, self.path, + __conf_cmd(0), __conf_cmd(1), tagOrId, {}) + return self end def latintagfont_copy(tagOrId, window, wintag=nil) + pathname = __item_pathname(tagOrId) + tagfontobj(tagOrId).dup.call_font_configure(pathname, self.path, + __conf_cmd(0), __conf_cmd(1), + tagOrId, {}) if wintag - tagfontobj(tagOrId).latin_replace(window.tagfontobj(wintag).latin_font) + tagfontobj(tagOrId). + latin_replace(window.tagfontobj(wintag).latin_font_id) else - tagfontobj(tagOrId).latin_replace(window.fontobj.latin_font) + tagfontobj(tagOrId).latin_replace(window.fontobj.latin_font_id) end self end alias asciitagfont_copy latintagfont_copy def kanjitagfont_copy(tagOrId, window, wintag=nil) + pathname = __item_pathname(tagOrId) + tagfontobj(tagOrId).dup.call_font_configure(pathname, self.path, + __conf_cmd(0), __conf_cmd(1), + tagOrId, {}) if wintag - tagfontobj(tagOrId).kanji_replace(window.tagfontobj(wintag).kanji_font) + tagfontobj(tagOrId). + kanji_replace(window.tagfontobj(wintag).kanji_font_id) else - tagfontobj(tagOrId).kanji_replace(window.fontobj.kanji_font) + tagfontobj(tagOrId).kanji_replace(window.fontobj.kanji_font_id) end self end @@ -3513,11 +3597,17 @@ class TkObject<TkKernel when 'text', 'label', 'show', 'data', 'file' tk_call path, 'cget', "-#{slot}" when 'font', 'kanjifont' - fnt = tk_tcl2ruby(tk_call(path, 'cget', "-#{slot}")) + #fnt = tk_tcl2ruby(tk_call(path, 'cget', "-#{slot}")) + fnt = tk_tcl2ruby(tk_call(path, 'cget', "-font")) unless fnt.kind_of?(TkFont) fnt = fontobj(fnt) end - fnt + if slot == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/ + # obsolete; just for compatibility + fnt.kanji_font + else + fnt + end else tk_tcl2ruby tk_call(path, 'cget', "-#{slot}") end @@ -4883,11 +4973,17 @@ class TkListbox<TkTextWin when 'text', 'label', 'show' tk_send('itemcget', index, "-#{key}") when 'font', 'kanjifont' - fnt = tk_tcl2ruby(tk_send('itemcget', index, "-#{key}")) + #fnt = tk_tcl2ruby(tk_send('itemcget', index, "-#{key}")) + fnt = tk_tcl2ruby(tk_send('itemcget', index, '-font')) unless fnt.kind_of?(TkFont) fnt = tagfontobj(index, fnt) end - fnt + if key.to_s == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/ + # obsolete; just for compatibility + fnt.kanji_font + else + fnt + end else tk_tcl2ruby(tk_send('itemcget', index, "-#{key}")) end @@ -4908,7 +5004,11 @@ class TkListbox<TkTextWin key == 'kanjifont' || key == :kanjifont || key == 'latinfont' || key == :latinfont || key == 'asciifont' || key == :asciifont ) - tagfont_configure(index, {key=>val}) + if val == None + tagfontobj(index) + else + tagfont_configure(index, {key=>val}) + end else tk_call 'itemconfigure', index, "-#{key}", val end @@ -5065,11 +5165,17 @@ class TkMenu<TkWindow when 'text', 'label', 'show' tk_send 'entrycget', index, "-#{key}" when 'font', 'kanjifont' - fnt = tk_tcl2ruby(tk_send('entrycget', index, "-#{key}")) + #fnt = tk_tcl2ruby(tk_send('entrycget', index, "-#{key}")) + fnt = tk_tcl2ruby(tk_send('entrycget', index, '-font')) unless fnt.kind_of?(TkFont) fnt = tagfontobj(index, fnt) end - fnt + if key.to_s == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/ + # obsolete; just for compatibility + fnt.kanji_font + else + fnt + end else tk_tcl2ruby(tk_send('entrycget', index, "-#{key}")) end @@ -5090,7 +5196,11 @@ class TkMenu<TkWindow key == 'kanjifont' || key == :kanjifont || key == 'latinfont' || key == :latinfont || key == 'asciifont' || key == :asciifont ) - tagfont_configure({key=>val}) + if val == None + tagfontobj(index) + else + tagfont_configure(index, {key=>val}) + end else tk_call 'entryconfigure', index, "-#{key}", val end diff --git a/ext/tk/lib/tkcanvas.rb b/ext/tk/lib/tkcanvas.rb index 9e386ee50d..024211aa1d 100644 --- a/ext/tk/lib/tkcanvas.rb +++ b/ext/tk/lib/tkcanvas.rb @@ -212,11 +212,17 @@ class TkCanvas<TkWindow when 'text', 'label', 'show', 'data', 'file', 'maskdata', 'maskfile' tk_send 'itemcget', tagid(tagOrId), "-#{option}" when 'font', 'kanjifont' - fnt = tk_tcl2ruby(tk_send('itemcget', tagid(tagOrId), "-#{option}")) + #fnt = tk_tcl2ruby(tk_send('itemcget', tagid(tagOrId), "-#{option}")) + fnt = tk_tcl2ruby(tk_send('itemcget', tagid(tagOrId), '-font')) unless fnt.kind_of?(TkFont) fnt = tagfontobj(tagid(tagOrId), fnt) end - fnt + if option.to_s == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/ + # obsolete; just for compatibility + fnt.kanji_font + else + fnt + end else tk_tcl2ruby tk_send('itemcget', tagid(tagOrId), "-#{option}") end @@ -227,7 +233,7 @@ class TkCanvas<TkWindow key = _symbolkey2str(key) if ( key['font'] || key['kanjifont'] \ || key['latinfont'] || key['asciifont'] ) - tagfont_configure(tagOrId, key.dup) + tagfont_configure(tagid(tagOrId), key.dup) else tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(key) end @@ -237,7 +243,11 @@ class TkCanvas<TkWindow key == 'kanjifont' || key == :kanjifont || key == 'latinfont' || key == :latinfont || key == 'asciifont' || key == :asciifont ) - tagfont_configure(tagid(tagOrId), {key=>value}) + if value == None + tagfontobj(tagid(tagOrId)) + else + tagfont_configure(tagid(tagOrId), {key=>value}) + end else tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value end @@ -750,7 +760,7 @@ class TkcItem<TkObject @id = create_self(*args).to_i ;# 'canvas item id' is integer number CItemID_TBL[@path] = {} unless CItemID_TBL[@path] CItemID_TBL[@path][@id] = self - font_configure(fontkeys) unless fontkeys.empty? + configure(fontkeys) unless fontkeys.empty? ######## old version # if args[-1].kind_of? Hash diff --git a/ext/tk/lib/tkfont.rb b/ext/tk/lib/tkfont.rb index f0c88e432d..be925dce7a 100644 --- a/ext/tk/lib/tkfont.rb +++ b/ext/tk/lib/tkfont.rb @@ -25,6 +25,7 @@ class TkFont when /^4\.*/ DEFAULT_LATIN_FONT_NAME = 'a14'.freeze DEFAULT_KANJI_FONT_NAME = 'k14'.freeze + when /^8\.*/ if JAPANIZED_TK begin @@ -89,6 +90,8 @@ class TkFont ltn = 'Helvetica' knj = 'mincho' end + + knj = ltn end DEFAULT_LATIN_FONT_NAME = ltn.freeze @@ -105,6 +108,49 @@ class TkFont print "default kanji font = "; p DEFAULT_KANJI_FONT_NAME end + + ################################### + class DescendantFont + def initialize(compound, type) + unless compound.kind_of?(TkFont) + fail ArgumentError, "a TkFont object is expected for the 1st argument" + end + @compound = compound + case type + when 'kanji', 'latin', 'ascii' + @type = type + else + fail ArgumentError, "unknown type '#{type}'" + end + end + + def dup + fail RuntimeError, "cannot dupulicate a descendant font" + end + def clone + fail RuntimeError, "cannot clone a descendant font" + end + + def to_eval + @compound.__send__(@type + '_font_id') + end + def font + @compound.__send__(@type + '_font_id') + end + + def [](slot) + @compound.__send__(@type + '_configinfo', slot) + end + def []=(slot, value=None) + @compound.__send__(@type + '_configure', slot, value) + end + + def method_missing(id, *args) + @compound.__send__(@type + '_' + id.id2name, *args) + end + end + + ################################### # class methods ################################### @@ -140,7 +186,7 @@ class TkFont fail 'source-font must be a TkFont object' unless font.kind_of? TkFont keys = {} font.configinfo.each{|key,value| keys[key] = value } - TkFont.new(font.latin_font, font.kanji_font, keys) + TkFont.new(font.latin_font_id, font.kanji_font_id, keys) end def TkFont.get_obj(name) @@ -222,6 +268,8 @@ class TkFont end ################################### + # instance methods + ################################### private ################################### def initialize(ltn=nil, knj=nil, keys=nil) @@ -229,13 +277,16 @@ class TkFont Tk_FontID[1].succ! Tk_FontNameTBL[@id] = self + @latin_desscendant = nil + @kanji_desscendant = nil + if knj.kind_of?(Hash) && !keys keys = knj knj = nil end # compound font check - if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK + if Tk::TK_VERSION == '8.0' && JAPANIZED_TK begin compound = tk_split_simplelist(tk_call('font', 'configure', ltn, '-compound')) @@ -374,7 +425,7 @@ class TkFont @kanjifont = '-' + _get_font_info_from_hash(finfo).join('-') + '-' elsif font.kind_of? TkFont - @kanjifont = font.kanji_font + @kanjifont = font.kanji_font_id else if font @kanjifont = font @@ -457,7 +508,7 @@ class TkFont tk_call('font', 'create', @kanjifont, '-copy', array2tk_list(font)) tk_call('font', 'configure', @kanjifont, '-charset', 'jisx0208.1983') elsif font.kind_of? TkFont - tk_call('font', 'create', @kanjifont, '-copy', font.kanji_font) + tk_call('font', 'create', @kanjifont, '-copy', font.kanji_font_id) elsif font tk_call('font', 'create', @kanjifont, '-copy', font, '-charset', 'jisx0208.1983') @@ -474,7 +525,7 @@ class TkFont if font.kind_of? Array actual_core(array2tk_list(font)).each{|key,val| keys[key] = val} elsif font.kind_of? TkFont - actual_core(font.kanji_font).each{|key,val| keys[key] = val} + actual_core(font.kanji_font_id).each{|key,val| keys[key] = val} elsif font actual_core(font).each{|key,val| keys[key] = val} end @@ -495,6 +546,22 @@ class TkFont @compoundfont = @id + 'c' if JAPANIZED_TK + unless keys + keys = {} + else + keys = keys.dup + end + if (tk_call('font', 'configure', @latinfont, '-underline') == '1' && + tk_call('font', 'configure', @kanjifont, '-underline') == '1' && + !keys.key?('underline')) + keys['underline'] = true + end + if (tk_call('font', 'configure', @latinfont, '-overstrike') == '1' && + tk_call('font', 'configure', @kanjifont, '-overstrike') == '1' && + !keys.key?('overstrike')) + keys['overstrike'] = true + end + @fontslot = {'font'=>@compoundfont} begin tk_call('font', 'create', @compoundfont, @@ -806,7 +873,8 @@ class TkFont begin fnt_bup = tk_call('font', 'create', '@font_tmp', '-copy', @latinfont) rescue - fnt_bup = '' + #fnt_bup = '' + fnt_bup = DEFAULT_LATIN_FONT_NAME end end @@ -822,16 +890,29 @@ class TkFont begin tk_call('font', 'create', @compoundfont, '-compound', [@latinfont, @kanjifont], *hash_kv(keys)) +=begin + latinkeys = {} + begin + actual_core(@latinfont).each{|key,val| latinkeys[key] = val} + rescue + latinkeys {} + end + if latinkeys != {} + tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys)) + end +=end rescue RuntimeError => e tk_call('font', 'delete', @latinfont) - if fnt_bup != '' + if fnt_bup && fnt_bup != '' tk_call('font', 'create', @latinfont, '-copy', fnt_bup) tk_call('font', 'create', @compoundfont, '-compound', [@latinfont, @kanjifont], *hash_kv(keys)) tk_call('font', 'delete', fnt_bup) + else + fail e end - fail e end + else latinkeys = {} begin @@ -855,7 +936,8 @@ class TkFont begin fnt_bup = tk_call('font', 'create', '@font_tmp', '-copy', @kanjifont) rescue - fnt_bup = '' + #fnt_bup = '' + fnt_bup = DEFAULT_KANJI_FONT_NAME end end @@ -873,13 +955,14 @@ class TkFont '-compound', [@latinfont, @kanjifont], *hash_kv(keys)) rescue RuntimeError => e tk_call('font', 'delete', @kanjifont) - if fnt_bup != '' + if fnt_bup && fnt_bup != '' tk_call('font', 'create', @kanjifont, '-copy', fnt_bup) tk_call('font', 'create', @compoundfont, '-compound', [@latinfont, @kanjifont], *hash_kv(keys)) tk_call('font', 'delete', fnt_bup) + else + fail e end - fail e end end self @@ -1039,15 +1122,36 @@ class TkFont def font @compoundfont end + alias font_id font - def latin_font + def latin_font_id @latinfont end - def kanji_font + def latin_font + # @latinfont + if @latin_descendant + @latin_descendant + else + @latin_descendant = DescendantFont.new(self, 'latin') + end + end + alias latinfont latin_font + + def kanji_font_id @kanjifont end + def kanji_font + # @kanjifont + if @kanji_descendant + @kanji_descendant + else + @kanji_descendant = DescendantFont.new(self, 'kanji') + end + end + alias kanjifont kanji_font + def actual(option=nil) actual_core(@compoundfont, nil, option) end @@ -1222,6 +1326,7 @@ class TkFont # public alias ################################### alias ascii_font latin_font + alias asciifont latinfont alias create_asciifont create_latinfont alias ascii_actual latin_actual alias ascii_actual_displayof latin_actual_displayof @@ -1230,6 +1335,19 @@ class TkFont alias ascii_replace latin_replace alias ascii_metrics latin_metrics + ################################### + def dup + src = self + obj = super() + obj.instance_eval{ initialize(src) } + obj + end + def clone + src = self + obj = super() + obj.instance_eval{ initialize(src) } + obj + end end module TkTreatTagFont diff --git a/ext/tk/lib/tktext.rb b/ext/tk/lib/tktext.rb index 9f1ad24665..cf4fc68ddc 100644 --- a/ext/tk/lib/tktext.rb +++ b/ext/tk/lib/tktext.rb @@ -331,11 +331,17 @@ class TkText<TkTextWin when 'text', 'label', 'show', 'data', 'file' tk_call(@path, 'tag', 'cget', tag, "-#{key}") when 'font', 'kanjifont' - fnt = tk_tcl2ruby(tk_send('tag', 'cget', tag, "-#{key}")) + #fnt = tk_tcl2ruby(tk_send('tag', 'cget', tag, "-#{key}")) + fnt = tk_tcl2ruby(tk_send('tag', 'cget', tag, '-font')) unless fnt.kind_of?(TkFont) fnt = tagfontobj(tag, fnt) end - fnt + if key.to_s == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/ + # obsolete; just for compatibility + fnt.kanji_font + else + fnt + end else tk_tcl2ruby(tk_call(@path, 'tag', 'cget', tag, "-#{key}")) end @@ -356,7 +362,11 @@ class TkText<TkTextWin key == 'kanjifont' || key == :kanjifont || key == 'latinfont' || key == :latinfont || key == 'asciifont' || key == :asciifont - tagfont_configure(tag, {key=>val}) + if val == None + tagfontobj(tag) + else + tagfont_configure(tag, {key=>val}) + end else tk_send 'tag', 'configure', tag, "-#{key}", val end @@ -450,11 +460,17 @@ class TkText<TkTextWin when 'text', 'label', 'show', 'data', 'file' tk_send('window', 'cget', index, "-#{slot}") when 'font', 'kanjifont' - fnt = tk_tcl2ruby(tk_send('window', 'cget', index, "-#{slot}")) + #fnt = tk_tcl2ruby(tk_send('window', 'cget', index, "-#{slot}")) + fnt = tk_tcl2ruby(tk_send('window', 'cget', index, '-font')) unless fnt.kind_of?(TkFont) fnt = tagfontobj(index, fnt) end - fnt + if slot.to_s == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/ + # obsolete; just for compatibility + fnt.kanji_font + else + fnt + end else tk_tcl2ruby(tk_send('window', 'cget', index, "-#{slot}")) end @@ -878,11 +894,17 @@ class TkTextTag<TkObject when 'text', 'label', 'show', 'data', 'file' tk_call @t.path, 'tag', 'cget', @id, "-#{key}" when 'font', 'kanjifont' - fnt = tk_tcl2ruby(tk_call(@t.path, 'tag', 'cget', @id, "-#{key}")) + #fnt = tk_tcl2ruby(tk_call(@t.path, 'tag', 'cget', @id, "-#{key}")) + fnt = tk_tcl2ruby(tk_call(@t.path, 'tag', 'cget', @id, '-font')) unless fnt.kind_of?(TkFont) fnt = tagfontobj(@id, fnt) end - fnt + if key.to_s == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/ + # obsolete; just for compatibility + fnt.kanji_font + else + fnt + end else tk_tcl2ruby(tk_call(@t.path, 'tag', 'cget', @id, "-#{key}")) end diff --git a/ext/tk/sample/demos-en/widget b/ext/tk/sample/demos-en/widget index 7379d11cbd..b6b63d644b 100644 --- a/ext/tk/sample/demos-en/widget +++ b/ext/tk/sample/demos-en/widget @@ -11,9 +11,9 @@ require 'tk' -unless /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK - require 'tkencoding' -end +#unless /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK +# require 'tkencoding' +#end require 'tkafter' diff --git a/ext/tk/sample/demos-jp/ctext.rb b/ext/tk/sample/demos-jp/ctext.rb index 62b02b3972..6d9355e2f8 100644 --- a/ext/tk/sample/demos-jp/ctext.rb +++ b/ext/tk/sample/demos-jp/ctext.rb @@ -62,7 +62,7 @@ $ctag_text.withtag(TkcText.new($ctext_canvas, 250, 200, 'text'=>"これはキャンバスwidgetのテキスト機能をデモするための文字列です。マウスを持っていき、クリックして入力できます。選択してコントロール-Dで消去することもできます。", 'width'=>440, 'anchor'=>'n', 'font'=>'-*-Helvetica-Medium-R-Normal--*-240-*-*-*-*-*-*', - 'kanjifont'=>'-*--24-*-jisx0208.1983-0', + 'kanjifont'=>'-*-r-*--24-*-jisx0208.1983-0', 'justify'=>'left') ) $ctag_text.bind('1', proc{|x,y| textB1Press $ctext_canvas,x,y}, "%x %y") diff --git a/ext/tk/sample/demos-jp/widget b/ext/tk/sample/demos-jp/widget index d7c1876eeb..bda80d5541 100644 --- a/ext/tk/sample/demos-jp/widget +++ b/ext/tk/sample/demos-jp/widget @@ -18,12 +18,12 @@ $tk_platform = TkVarAccess.new('tcl_platform') # フォント設定 $font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*', nil) -knjfont = '-*--16-*-jisx0208.1983-0' +knjfont = '-*-r-*--16-*-jisx0208.1983-0' $kanji_font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*', knjfont) TkOption.add('*kanjiFont', knjfont, 'startupFile') $msg_kanji_font = TkFont.new('-*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*', - '-*--24-*-jisx0208.1983-0') + '-*-r-*--24-*-jisx0208.1983-0') ####### #case($tk_version) #when /^4.*/ |