1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
|
#
# tkfont.rb - the class to treat fonts on Ruby/Tk
#
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
class TkFont
include Tk
extend TkCore
Tk_FontID = [0]
Tk_FontNameTBL = {}
Tk_FontUseTBL = {}
case Tk::TK_VERSION
when /^4\.*/
DEFAULT_LATIN_FONT_NAME = 'a14'.freeze
DEFAULT_KANJI_FONT_NAME = 'k14'.freeze
when /^8\.*/
if JAPANIZED_TK
begin
fontnames = tk_call('font', 'names')
case fontnames
when /defaultgui/
# Tcl/Tk-JP for Windows
ltn = 'defaultgui'
knj = 'defaultgui'
when /Mincho:Helvetica-12/
# Tcl/Tk-JP for UNIX/X
ltn, knj = tk_split_simplelist(tk_call('font', 'configure',
'Mincho:Helvetica-12',
'-compound'))
else
# unknown Tcl/Tk-JP
ltn = 'Helvetica'
knj = 'mincho'
end
rescue
ltn = 'Helvetica'
knj = 'mincho'
end
DEFAULT_LATIN_FONT_NAME = ltn.freeze
DEFAULT_KANJI_FONT_NAME = knj.freeze
else
DEFAULT_LATIN_FONT_NAME = 'Helvetica'.freeze
DEFAULT_KANJI_FONT_NAME = 'mincho'.freeze
end
end
p "default latin font = #{DEFAULT_LATIN_FONT_NAME}" if $DEBUG
p "default kanji font = #{DEFAULT_KANJI_FONT_NAME}" if $DEBUG
###################################
# class methods
###################################
def TkFont.families(window=nil)
case (Tk::TK_VERSION)
when /^4\.*/
['fixed']
when /^8\.*/
if window
tk_split_simplelist(tk_call('font', 'families', '-displayof', window))
else
tk_split_simplelist(tk_call('font', 'families'))
end
end
end
def TkFont.names
case (Tk::TK_VERSION)
when /^4\.*/
r = ['fixed']
r += ['a14', 'k14'] if JAPANIZED_TK
Tk_FontNameTBL.each_value{|obj| r.push(obj)}
r | []
when /^8\.*/
tk_split_simplelist(tk_call('font', 'names'))
end
end
def TkFont.create_copy(font)
fail 'source-font need to be TkFont' unless font.kind_of? TkFont
keys = {}
font.configinfo.each{|key,value| keys[key] = value }
TkFont.new(font.latin_font, font.kanji_font, keys)
end
def TkFont.get_obj(name)
if name =~ /^(@font[0-9]+)(|c|l|k)$/
Tk_FontNameTBL[$1]
else
nil
end
end
def TkFont.init_widget_font(path, *args)
case (Tk::TK_VERSION)
when /^4\.*/
conf = tk_split_simplelist(tk_call(*args)).
find_all{|prop| prop[0..5]=='-font ' || prop[0..10]=='-kanjifont '}.
collect{|prop| tk_split_simplelist(prop)}
if font_inf = conf.assoc('-font')
ltn = font_inf[4]
ltn = nil if ltn == []
else
#ltn = nil
raise RuntimeError, "unknown option '-font'"
end
if font_inf = conf.assoc('-kanjifont')
knj = font_inf[4]
knj = nil if knj == []
else
knj = nil
end
TkFont.new(ltn, knj).call_font_configure(path, *(args + [{}]))
when /^8\.*/
font_prop = tk_split_simplelist(tk_call(*args)).find{|prop|
prop[0..5] == '-font '
}
unless font_prop
raise RuntimeError, "unknown option '-font'"
end
fnt = tk_split_simplelist(font_prop)[4]
if fnt == ""
TkFont.new(nil, nil).call_font_configure(path, *(args + [{}]))
else
begin
compound = Hash[*list(tk_call('font', 'configure',
fnt))].collect{|key,value|
[key[1..-1], value]
}.assoc('compound')[1]
rescue
compound = []
end
if compound == []
TkFont.new(fnt, DEFAULT_KANJI_FONT_NAME) \
.call_font_configure(path, *(args + [{}]))
else
TkFont.new(compound[0], compound[1]) \
.call_font_configure(path, *(args + [{}]))
end
end
end
end
def TkFont.used_on(path=nil)
if path
Tk_FontUseTBL[path]
else
Tk_FontUseTBL.values | []
end
end
def TkFont.failsafe(font)
begin
if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK
tk_call('font', 'failsafe', font)
end
rescue
end
end
###################################
private
###################################
def initialize(ltn=DEFAULT_LATIN_FONT_NAME, knj=DEFAULT_KANJI_FONT_NAME,
keys=nil)
@id = format("@font%.4d", Tk_FontID[0])
Tk_FontID[0] += 1
Tk_FontNameTBL[@id] = self
create_latinfont(ltn)
create_kanjifont(knj)
create_compoundfont(keys)
end
def _get_font_info_from_hash(font)
foundry = (info = font['foundry'] .to_s)? info: '*'
family = (info = font['family'] .to_s)? info: '*'
weight = (info = font['weight'] .to_s)? info: '*'
slant = (info = font['slant'] .to_s)? info: '*'
swidth = (info = font['swidth'] .to_s)? info: '*'
adstyle = (info = font['adstyle'] .to_s)? info: '*'
pixels = (info = font['pixels'] .to_s)? info: '*'
points = (info = font['points'] .to_s)? info: '*'
resx = (info = font['resx'] .to_s)? info: '*'
resy = (info = font['resy'] .to_s)? info: '*'
space = (info = font['space'] .to_s)? info: '*'
avgWidth = (info = font['avgWidth'].to_s)? info: '*'
charset = (info = font['charset'] .to_s)? info: '*'
encoding = (info = font['encoding'].to_s)? info: '*'
[foundry, family, weight, slant, swidth, adstyle,
pixels, points, resx, resy, space, avgWidth, charset, encoding]
end
def create_latinfont_tk4x(font)
if font.kind_of? Hash
@latinfont = '-' + _get_font_info_from_hash(font).join('-') + '-'
elsif font.kind_of? Array
finfo = {}
finfo['family'] = font[0].to_s
if font[1]
fsize = font[1].to_s
if fsize != '0' && fsize =~ /^(|\+|-)([0-9]+)$/
if $1 == '-'
finfo['pixels'] = $2
else
finfo['points'] = $2
end
else
finfo['points'] = '13'
end
end
font[2..-1].each{|style|
case (style)
when 'normal'
finfo['weight'] = style
when 'bold'
finfo['weight'] = style
when 'roman'
finfo['slant'] = 'r'
when 'italic'
finfo['slant'] = 'i'
end
}
@latinfont = '-' + _get_font_info_from_hash(finfo).join('-') + '-'
elsif font.kind_of? TkFont
@latinfont = font.latin_font
else
if font
@latinfont = font
else
@latinfont = DEFAULT_LATIN_FONT_NAME
end
end
end
def create_kanjifont_tk4x(font)
unless JAPANIZED_TK
@kanjifont = ""
return
end
if font.kind_of? Hash
@kanjifont = '-' + _get_font_info_from_hash(font).join('-') + '-'
elsif font.kind_of? Array
finfo = {}
finfo['family'] = font[0].to_s
if font[1]
fsize = font[1].to_s
if fsize != '0' && fsize =~ /^(|\+|-)([0-9]+)$/
if $1 == '-'
finfo['pixels'] = $2
else
finfo['points'] = $2
end
else
finfo['points'] = '13'
end
end
font[2..-1].each{|style|
case (style)
when 'normal'
finfo['weight'] = style
when 'bold'
finfo['weight'] = style
when 'roman'
finfo['slant'] = 'r'
when 'italic'
finfo['slant'] = 'i'
end
}
@kanjifont = '-' + _get_font_info_from_hash(finfo).join('-') + '-'
elsif font.kind_of? TkFont
@kanjifont = font.kanji_font
else
if font
@kanjifont = font
else
@kanjifont = DEFAULT_KANJI_FONT_NAME
end
end
end
def create_compoundfont_tk4x(keys)
if JAPANIZED_TK
@compoundfont = [[@latinfont], [@kanjifont]]
@fontslot = {'font'=>@latinfont, 'kanjifont'=>@kanjifont}
else
@compoundfont = @latinfont
@fontslot = {'font'=>@latinfont}
end
end
def create_latinfont_tk8x(font)
@latinfont = @id + 'l'
if JAPANIZED_TK
if font.kind_of? Hash
if font['charset']
tk_call('font', 'create', @latinfont, *hash_kv(font))
else
tk_call('font', 'create', @latinfont,
'-charset', 'iso8859', *hash_kv(font))
end
elsif font.kind_of? Array
tk_call('font', 'create', @latinfont, '-copy', array2tk_list(font))
tk_call('font', 'configure', @latinfont, '-charset', 'iso8859')
elsif font.kind_of? TkFont
tk_call('font', 'create', @latinfont, '-copy', font.latin_font)
elsif font
tk_call('font', 'create', @latinfont, '-copy', font,
'-charset', 'iso8859')
else
tk_call('font', 'create', @latinfont, '-charset', 'iso8859')
end
else
if font.kind_of? Hash
tk_call('font', 'create', @latinfont, *hash_kv(font))
else
keys = {}
if font.kind_of? Array
actual_core(array2tk_list(font)).each{|key,val| keys[key] = val}
elsif font.kind_of? TkFont
actual_core(font.latin_font).each{|key,val| keys[key] = val}
elsif font
actual_core(font).each{|key,val| keys[key] = val}
end
tk_call('font', 'create', @latinfont, *hash_kv(keys))
end
end
end
def create_kanjifont_tk80(font)
unless JAPANIZED_TK
@kanjifont = ""
return
end
@kanjifont = @id + 'k'
if font.kind_of? Hash
if font['charset']
tk_call('font', 'create', @kanjifont, *hash_kv(font))
else
tk_call('font', 'create', @kanjifont,
'-charset', 'jisx0208.1983', *hash_kv(font))
end
elsif font.kind_of? Array
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)
elsif font
tk_call('font', 'create', @kanjifont, '-copy', font,
'-charset', 'jisx0208.1983')
else
tk_call('font', 'create', @kanjifont, '-charset', 'jisx0208.1983')
end
end
def create_kanjifont_tk81(font)
@kanjifont = @id + 'k'
if font.kind_of? Hash
tk_call('font', 'create', @kanjifont, *hash_kv(font))
else
keys = {}
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}
elsif font
actual_core(font).each{|key,val| keys[key] = val}
end
tk_call('font', 'create', @kanjifont, *hash_kv(keys))
end
keys = {}
actual_core(@kanjifont).each{|key,val| keys[key] = val}
begin
tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
rescue
end
end
def create_compoundfont_tk80(keys)
@compoundfont = @id + 'c'
if JAPANIZED_TK
@fontslot = {'font'=>@compoundfont}
tk_call('font', 'create', @compoundfont,
'-compound', [@latinfont, @kanjifont], *hash_kv(keys))
else
tk_call('font', 'create', @compoundfont)
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
@fontslot = {'font'=>@compoundfont}
tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
end
end
def create_compoundfont_tk81(keys)
@compoundfont = @id + 'c'
tk_call('font', 'create', @compoundfont)
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
kanjikeys = {}
begin
actual_core(@kanjifont).each{|key,val| kanjikeys[key] = val}
rescue
kanjikeys {}
end
if kanjikeys != {}
tk_call('font', 'configure', @compoundfont, *hash_kv(kanjikeys))
end
@fontslot = {'font'=>@compoundfont}
tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
end
def actual_core_tk4x(font, window=nil, option=nil)
# dummy
if option
""
else
[['family',[]], ['size',[]], ['weight',[]], ['slant',[]],
['underline',[]], ['overstrike',[]], ['charset',[]],
['pointadjust',[]]]
end
end
def actual_core_tk8x(font, window=nil, option=nil)
if option == 'compound'
""
elsif option
if window
tk_call('font', 'actual', font, "-displayof", window, "-#{option}")
else
tk_call('font', 'actual', font, "-#{option}")
end
else
l = tk_split_simplelist(if window
tk_call('font', 'actual', font,
"-displayof", window)
else
tk_call('font', 'actual', font)
end)
r = []
while key=l.shift
if key == '-compound'
l.shift
else
r.push [key[1..-1], l.shift]
end
end
r
end
end
def configure_core_tk4x(font, slot, value=None)
""
end
def configinfo_core_tk4x(font, option=nil)
# dummy
if option
""
else
[['family',[]], ['size',[]], ['weight',[]], ['slant',[]],
['underline',[]], ['overstrike',[]], ['charset',[]],
['pointadjust',[]]]
end
end
def configure_core_tk8x(font, slot, value=None)
if slot.kind_of? Hash
tk_call 'font', 'configure', font, *hash_kv(slot)
else
tk_call 'font', 'configure', font, "-#{slot}", value
end
end
def configinfo_core_tk8x(font, option=nil)
if option == 'compound'
""
elsif option
tk_call('font', 'configure', font, "-#{option}")
else
l = tk_split_simplelist(tk_call('font', 'configure', font))
r = []
while key=l.shift
if key == '-compound'
l.shift
else
r.push [key[1..-1], l.shift]
end
end
r
end
end
def delete_core_tk4x
Tk_FontNameTBL[@id] = nil
Tk_FontUseTBL.delete_if{|key,value| value == self}
end
def delete_core_tk8x
begin
tk_call('font', 'delete', @latinfont)
rescue
end
begin
tk_call('font', 'delete', @kanjifont)
rescue
end
begin
tk_call('font', 'delete', @compoundfont)
rescue
end
Tk_FontNameTBL[@id] = nil
Tk_FontUseTBL.delete_if{|key,value| value == self}
end
def latin_replace_core_tk4x(ltn)
create_latinfont_tk4x(ltn)
@compoundfont[0] = [@latinfont] if JAPANIZED_TK
@fontslot['font'] = @latinfont
Tk_FontUseTBL.dup.each{|w, fobj|
if self == fobj
begin
if w.include?(';')
win, tag = w.split(';')
winobj = tk_tcl2ruby(win)
# winobj.tagfont_configure(tag, {'font'=>@latinfont})
if winobj.kind_of? TkText
tk_call(win, 'tag', 'configure', tag, '-font', @latinfont)
elsif winobj.kind_of? TkCanvas
tk_call(win, 'itemconfigure', tag, '-font', @latinfont)
elsif winobj.kind_of? TkMenu
tk_call(win, 'entryconfigure', tag, '-font', @latinfont)
else
raise RuntimeError, "unknown widget type"
end
else
# tk_tcl2ruby(w).font_configure('font'=>@latinfont)
tk_call(w, 'configure', '-font', @latinfont)
end
rescue
Tk_FontUseTBL[w] = nil
end
end
}
self
end
def kanji_replace_core_tk4x(knj)
return self unless JAPANIZED_TK
create_kanjifont_tk4x(knj)
@compoundfont[1] = [@kanjifont]
@fontslot['kanjifont'] = @kanjifont
Tk_FontUseTBL.dup.each{|w, fobj|
if self == fobj
begin
if w.include?(';')
win, tag = w.split(';')
winobj = tk_tcl2ruby(win)
# winobj.tagfont_configure(tag, {'kanjifont'=>@kanjifont})
if winobj.kind_of? TkText
tk_call(win, 'tag', 'configure', tag, '-kanjifont', @kanjifont)
elsif winobj.kind_of? TkCanvas
tk_call(win, 'itemconfigure', tag, '-kanjifont', @kanjifont)
elsif winobj.kind_of? TkMenu
tk_call(win, 'entryconfigure', tag, '-kanjifont', @latinfont)
else
raise RuntimeError, "unknown widget type"
end
else
# tk_tcl2ruby(w).font_configure('kanjifont'=>@kanjifont)
tk_call(w, 'configure', '-kanjifont', @kanjifont)
end
rescue
Tk_FontUseTBL[w] = nil
end
end
}
self
end
def latin_replace_core_tk8x(ltn)
begin
tk_call('font', 'delete', @latinfont)
rescue
end
create_latinfont(ltn)
self
end
def kanji_replace_core_tk80(knj)
return self unless JAPANIZED_TK
begin
tk_call('font', 'delete', @kanjifont)
rescue
end
create_kanjifont(knj)
self
end
def kanji_replace_core_tk81(knj)
if font.kind_of? Hash
tk_call('font', 'configure', @compoundfont, *hash_kv(knj))
else
keys = {}
if knj.kind_of? Array
actual_core(array2tk_list(knj)).each{|key,val| keys[key] = val}
elsif knj.kind_of? TkFont
actual_core(knj.latin_font).each{|key,val| keys[key] = val}
else
actual_core(knj).each{|key,val| keys[key] = val}
end
tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
end
self
end
def measure_core_tk4x(window, text)
0
end
def measure_core_tk8x(window, text)
if window
number(tk_call('font', 'measure', @compoundfont,
'-displayof', window, text))
else
number(tk_call('font', 'measure', @compoundfont, text))
end
end
def metrics_core_tk4x(font, window, option=nil)
# dummy
if option
""
else
[['ascent',[]], ['descent',[]], ['linespace',[]], ['fixed',[]]]
end
end
def metrics_core_tk8x(font, window, option=nil)
if option
if window
number(tk_call('font', 'metrics', font, "-#{option}"))
else
number(tk_call('font', 'metrics', font,
"-displayof", window, "-#{option}"))
end
else
l = tk_split_list(if window
tk_call('font','metrics',font,"-displayof",window)
else
tk_call('font','metrics',font)
end)
r = []
while key=l.shift
r.push [key[1..-1], l.shift.to_i]
end
r
end
end
###################################
# private alias
###################################
case (Tk::TK_VERSION)
when /^4\.*/
alias create_latinfont create_latinfont_tk4x
alias create_kanjifont create_kanjifont_tk4x
alias create_compoundfont create_compoundfont_tk4x
alias actual_core actual_core_tk4x
alias configure_core configure_core_tk4x
alias configinfo_core configinfo_core_tk4x
alias delete_core delete_core_tk4x
alias latin_replace_core latin_replace_core_tk4x
alias kanji_replace_core kanji_replace_core_tk4x
alias measure_core measure_core_tk4x
alias metrics_core metrics_core_tk4x
when /^8\.0/
alias create_latinfont create_latinfont_tk8x
alias create_kanjifont create_kanjifont_tk80
alias create_compoundfont create_compoundfont_tk80
alias actual_core actual_core_tk8x
alias configure_core configure_core_tk8x
alias configinfo_core configinfo_core_tk8x
alias delete_core delete_core_tk8x
alias latin_replace_core latin_replace_core_tk8x
alias kanji_replace_core kanji_replace_core_tk80
alias measure_core measure_core_tk8x
alias metrics_core metrics_core_tk8x
when /^8\.[123]/
alias create_latinfont create_latinfont_tk8x
alias create_kanjifont create_kanjifont_tk81
alias create_compoundfont create_compoundfont_tk81
alias actual_core actual_core_tk8x
alias configure_core configure_core_tk8x
alias configinfo_core configinfo_core_tk8x
alias delete_core delete_core_tk8x
alias latin_replace_core latin_replace_core_tk8x
alias kanji_replace_core kanji_replace_core_tk81
alias measure_core measure_core_tk8x
alias metrics_core metrics_core_tk8x
when /^8\.*/
alias create_latinfont create_latinfont_tk8x
alias create_kanjifont create_kanjifont_tk81
alias create_compoundfont create_compoundfont_tk81
alias actual_core actual_core_tk8x
alias configure_core configure_core_tk8x
alias configinfo_core configinfo_core_tk8x
alias delete_core delete_core_tk8x
alias latin_replace_core latin_replace_core_tk8x
alias kanji_replace_core kanji_replace_core_tk81
alias measure_core measure_core_tk8x
alias metrics_core metrics_core_tk8x
end
###################################
public
###################################
def call_font_configure(path, *args)
args += hash_kv(args.pop.update(@fontslot))
tk_call *args
Tk_FontUseTBL[path] = self
self
end
def used
ret = []
Tk_FontUseTBL.each{|key,value|
if key.include?(';')
win, tag = key.split(';')
winobj = tk_tcl2ruby(win)
if winobj.kind_of? TkText
ret.push([winobj, winobj.tagid2obj(tag)])
elsif winobj.kind_of? TkCanvas
if (tagobj = TkcTag.id2obj(winobj, tag)).kind_of? TkcTag
ret.push([winobj, tagobj])
elsif (tagobj = TkcItem.id2obj(tag)).kind_of? TkcItem
ret.push([winobj, tagobj])
else
ret.push([winobj, tag])
end
elsif winobj.kind_of? TkMenu
ret.push([winobj, tag])
else
ret.push([win, tag])
end
else
ret.push(tk_tcl2ruby(key)) if value == self
end
}
ret
end
def id
@id
end
def to_eval
font
end
def font
@compoundfont
end
def latin_font
@latinfont
end
def kanji_font
@kanjifont
end
def actual(option=nil)
actual_core(@compoundfont, nil, option)
end
def actual_displayof(window, option=nil)
window = '.' unless window
actual_core(@compoundfont, window, option)
end
def latin_actual(option=nil)
actual_core(@latinfont, nil, option)
end
def latin_actual_displayof(window, option=nil)
window = '.' unless window
actual_core(@latinfont, window, option)
end
def kanji_actual(option=nil)
#if JAPANIZED_TK
if @kanjifont != ""
actual_core(@kanjifont, nil, option)
else
actual_core_tk4x(nil, nil, option)
end
end
def kanji_actual_displayof(window, option=nil)
#if JAPANIZED_TK
if @kanjifont != ""
window = '.' unless window
actual_core(@kanjifont, window, option)
else
actual_core_tk4x(nil, window, option)
end
end
def [](slot)
configinfo slot
end
def []=(slot, val)
configure slot, val
end
def configure(slot, value=None)
configure_core(@compoundfont, slot, value)
end
def configinfo(slot=nil)
configinfo_core(@compoundfont, slot)
end
def delete
delete_core
end
def latin_configure(slot, value=None)
if JAPANIZED_TK
configure_core(@latinfont, slot, value)
else
configure(slot, value)
end
end
def latin_configinfo(slot=nil)
if JAPANIZED_TK
configinfo_core(@latinfont, slot)
else
configinfo(slot)
end
end
def kanji_configure(slot, value=None)
#if JAPANIZED_TK
if @kanjifont != ""
configure_core(@kanjifont, slot, value)
configure('size'=>configinfo('size')) # to reflect new configuration
else
#""
configure(slot, value)
end
end
def kanji_configinfo(slot=nil)
#if JAPANIZED_TK
if @kanjifont != ""
configinfo_core(@kanjifont, slot)
else
#[]
configinfo(slot)
end
end
def replace(ltn, knj)
latin_replace(ltn)
kanji_replace(knj)
self
end
def latin_replace(ltn)
latin_replace_core(ltn)
reset_pointadjust
end
def kanji_replace(knj)
kanji_replace_core(knj)
reset_pointadjust
end
def measure(text)
measure_core(nil, text)
end
def measure_displayof(window, text)
window = '.' unless window
measure_core(window, text)
end
def metrics(option=nil)
metrics_core(@compoundfont, nil, option)
end
def metrics_displayof(window, option=nil)
window = '.' unless window
metrics_core(@compoundfont, window, option)
end
def latin_metrics(option=nil)
metrics_core(@latinfont, nil, option)
end
def latin_metrics_displayof(window, option=nil)
window = '.' unless window
metrics_core(@latinfont, window, option)
end
def kanji_metrics(option=nil)
if JAPANIZED_TK
metrics_core(@kanjifont, nil, option)
else
metrics_core_tk4x(nil, nil, option)
end
end
def kanji_metrics_displayof(window, option=nil)
if JAPANIZED_TK
window = '.' unless window
metrics_core(@kanjifont, window, option)
else
metrics_core_tk4x(nil, window, option)
end
end
def reset_pointadjust
begin
if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK
configure('pointadjust' => latin_actual.assoc('size')[1].to_f /
kanji_actual.assoc('size')[1].to_f )
end
rescue
end
self
end
###################################
# public alias
###################################
alias ascii_font latin_font
alias create_asciifont create_latinfont
alias ascii_actual latin_actual
alias ascii_actual_displayof latin_actual_displayof
alias ascii_configure latin_configure
alias ascii_configinfo latin_configinfo
alias ascii_replace latin_replace
alias ascii_metrics latin_metrics
end
module TkTreatTagFont
def font_configinfo
@parent.tagfont_configinfo(@id)
end
alias font font_configinfo
def font_configure(slot)
@parent.tagfont_configure(@id, slot)
end
def latinfont_configure(ltn, keys=nil)
@parent.latintagfont_configure(@id, ltn, keys)
end
alias asciifont_configure latinfont_configure
def kanjifont_configure(knj, keys=nil)
@parent.kanjitagfont_configure(@id, ltn, keys)
end
def font_copy(window, wintag=nil)
@parent.tagfont_copy(@id, window, wintag)
end
def latinfont_copy(window, wintag=nil)
@parent.latintagfont_copy(@id, window, wintag)
end
alias asciifont_copy latinfont_copy
def kanjifont_copy(window, wintag=nil)
@parent.kanjitagfont_copy(@id, window, wintag)
end
end
|