From 9388ed284d600f2225a745dfb3edb6ac1758fdb8 Mon Sep 17 00:00:00 2001 From: nagai Date: Tue, 2 Sep 2003 05:04:30 +0000 Subject: [PATCH] * 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 --- ChangeLog | 7 + ext/tcltklib/tcltklib.c | 6 +- ext/tk/lib/tk.rb | 332 +++++++++++++++++++++----------- ext/tk/lib/tkcanvas.rb | 20 +- ext/tk/lib/tkfont.rb | 144 ++++++++++++-- ext/tk/lib/tktext.rb | 36 +++- ext/tk/sample/demos-en/widget | 6 +- ext/tk/sample/demos-jp/ctext.rb | 2 +- ext/tk/sample/demos-jp/widget | 4 +- 9 files changed, 414 insertions(+), 143 deletions(-) diff --git a/ChangeLog b/ChangeLog index a29f931c38..7e617126cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Sep 2 14:02:19 2003 + + * 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 * 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)) - else - fobj.latin_configure(conf) - end + 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 - fobj.latin_replace(ltn) + tk_call(self.path, 'configure', '-font', ltn) + return self end - self + + 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_replace(ltn) + end + end + + 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)) - else - fobj.kanji_configure(cond) - end + 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 - fobj.kanji_replace(knj) + tk_call(self.path, 'configure', '-font', knj) + return self end - self + + 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_replace(knj) + end + end + + 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)) - else - fobj.latin_configure(conf) - end + 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 - fobj.latin_replace(ltn) + tk_call(self.path, __conf_cmd(0), __conf_cmd(1), tagOrId, '-font', ltn) + return self end - self + + 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_replace(ltn) + end + end + + 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)) - else - fobj.kanji_configure(conf) - end + 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 - fobj.kanji_replace(knj) + tk_call(self.path, __conf_cmd(0), __conf_cmd(1), tagOrId, '-font', knj) + return self end - self + + 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_replace(knj) + end + end + + 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 TkObjectval}) + 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 TkMenuval}) + 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 TkCanvasvalue}) + 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@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 TkTextval}) + 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"これはキャンバス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.*/