Class: TkFont

Inherits:
Object show all
Extended by:
TkCore, CoreMethods
Includes:
Tk, CoreMethods
Defined in:
lib/tk/font.rb,
lib/tk/font.rb,
lib/tk/font.rb

Overview

autoload

Direct Known Subclasses

TkNamedFont

Defined Under Namespace

Modules: Chooser, CoreMethods Classes: DescendantFont

Constant Summary collapse

TkCommandNames =
['font'.freeze].freeze
Tk_FontNameTBL =
TkCore::INTERP.create_table
Tk_FontUseTBL =
TkCore::INTERP.create_table
OptionType =

option_type : default => string

Hash.new(?s)
MetricType =

metric_type : default => num_or_str

Hash.new(?n)
SYSTEM_FONT_NAMES =

system font names

[]

Constants included from TkCore

TkCore::EventFlag, TkCore::INTERP, TkCore::INTERP_MUTEX, TkCore::INTERP_ROOT_CHECK, TkCore::INTERP_THREAD, TkCore::INTERP_THREAD_STATUS, TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD, TkCore::WIDGET_DESTROY_HOOK, TkCore::WITH_ENCODING, TkCore::WITH_RUBY_VM

Constants included from TkComm

TkComm::GET_CONFIGINFO_AS_ARRAY, TkComm::GET_CONFIGINFOwoRES_AS_ARRAY, TkComm::TkExtlibAutoloadModule, TkComm::Tk_CMDTBL, TkComm::Tk_IDs, TkComm::Tk_WINDOWS, TkComm::USE_TCLs_LIST_FUNCTIONS, TkComm::WidgetClassNames

Constants included from TkUtil

TkUtil::None, TkUtil::RELEASE_DATE

Constants included from Tk

Tk::AUTO_PATH, Tk::Fontchooser, Tk::INTERP, Tk::JAPANIZED_TK, Tk::LIBRARY_PATH, Tk::MAINLOOP, Tk::PACKAGE_PATH, Tk::RELEASE_DATE, Tk::TCL_LIBRARY_PATH, Tk::TCL_MAJOR_VERSION, Tk::TCL_MINOR_VERSION, Tk::TCL_PACKAGE_PATH, Tk::TCL_PATCHLEVEL, Tk::TCL_PRECISION, Tk::TCL_VERSION, Tk::TK_MAJOR_VERSION, Tk::TK_MINOR_VERSION, Tk::TK_PATCHLEVEL, Tk::TK_VERSION, Tk::Tkextlib_RELEASE_DATE, Tk::TreeCtrl_Widget, Tk::X_Scrollable, Tk::Y_Scrollable

Constants included from Tk::Encoding

Tk::Encoding::BINARY, Tk::Encoding::BINARY_NAME, Tk::Encoding::DEFAULT_EXTERNAL_NAME, Tk::Encoding::DEFAULT_INTERNAL_NAME, Tk::Encoding::ENCODING_TABLE, Tk::Encoding::RubyEncoding, Tk::Encoding::UNKNOWN, Tk::Encoding::UTF8_NAME

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TkCore

_tk_call_to_list_core, after, after_cancel, after_idle, appname, appsend, appsend_deny, appsend_displayof, callback, callback_break, callback_continue, callback_return, chooseColor, chooseDirectory, do_one_event, event_generate, getMultipleOpenFile, getMultipleSaveFile, getOpenFile, getSaveFile, get_eventloop_tick, get_eventloop_weight, get_no_event_wait, inactive, inactive_displayof, info, ip_eval, ip_eval_with_enc, ip_eval_without_enc, ip_invoke, ip_invoke_with_enc, ip_invoke_without_enc, is_mainloop?, load_cmd_on_ip, mainloop, mainloop_exist?, mainloop_thread?, mainloop_watchdog, messageBox, rb_appsend, rb_appsend_displayof, reset_inactive, reset_inactive_displayof, restart, scaling, scaling_displayof, set_eventloop_tick, set_eventloop_weight, set_no_event_wait, tk_call, tk_call_to_list, tk_call_to_list_with_enc, tk_call_to_list_without_enc, tk_call_to_simplelist, tk_call_to_simplelist_with_enc, tk_call_to_simplelist_without_enc, tk_call_with_enc, tk_call_without_enc, windowingsystem

Methods included from TkComm

_at, _callback_entry?, _callback_entry_class?, _curr_cmd_id, _fromUTF8, _genobj_for_tkwidget, _next_cmd_id, _toUTF8, array2tk_list, #bind, #bind_all, #bind_append, #bind_append_all, #bind_remove, #bind_remove_all, #bindinfo, #bindinfo_all, bool, image_obj, #install_cmd, install_cmd, list, num_or_nil, num_or_str, number, procedure, simplelist, slice_ary, string, #subst, tk_tcl2ruby, uninstall_cmd, #uninstall_cmd, window

Methods included from TkEvent

#install_bind, #install_bind_for_event_class

Methods included from TkUtil

#_conv_args, _conv_args, #_fromUTF8, #_get_eval_enc_str, _get_eval_enc_str, #_get_eval_string, _get_eval_string, _symbolkey2str, #_symbolkey2str, #_toUTF8, #bool, bool, callback, eval_cmd, #hash_kv, hash_kv, install_cmd, #num_or_nil, num_or_nil, num_or_str, #num_or_str, number, #number, string, #string, uninstall_cmd, untrust

Methods included from Tk

BinaryString, EncodedString, #Grid, #Pack, #Place, UTF8_String, __create_widget_set__, __disable_toplevel_control__, __import_toplevel_aliases__, __regist_toplevel_aliases__, __remove_toplevel_aliases__, __reset_toplevel_owner__, __set_loaded_toplevel_aliases__, __set_toplevel_aliases__, __toplevel_alias_setup_proc__, _replace_toplevel_aliases, add_kinsoku, backup_current_topdef, bell, bell_on_display, const_missing, current_grabs, cursor_display, default_widget_set, default_widget_set=, define_topalias, define_topobj, delete_kinsoku, destroy, #encoding, #encoding=, errorCode, errorInfo, exit, focus, focus_lastfor, focus_next, focus_prev, focus_to, fromUTF8, grid, grid_forget, has_mainwindow?, load_tcllibrary, load_tclscript, load_tclscript_rsrc, load_tclscript_rsrcid, lower_window, pack, pack_forget, pkgconfig_get, pkgconfig_list, place, place_forget, raise_window, regist_sym_for_loaded_file, replace_topalias, replace_topobj, #root, set_topalias, show_kinsoku, sleep, strictMotif, subst_tk_backslash, subst_utf_backslash, tcl_pkgconfig_get, tcl_pkgconfig_list, thread_update, thread_update_idletasks, tk_pkgconfig_get, tk_pkgconfig_list, toUTF8, to_backslash_sequence, topalias_defined?, toplevel_aliases_on_widget_set, topobj_defined?, ungrid, unload_tcllibrary, unpack, unplace, update, #update, update_idletasks, utf_to_backslash, utf_to_backslash_sequence, wakeup, widget_set_symbols

Methods included from Tk::Encoding

#default_encoding=, #encoding=, #encoding_convertfrom, #encoding_convertto, #encoding_dirs, #encoding_dirs=, #encoding_name, #encoding_names, #encoding_obj, #encoding_objs, #encoding_system=, #encoding_system_name, #encoding_system_obj, #force_default_encoding, #force_default_encoding=, #force_default_encoding?, #tk_encoding_names

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *args) ⇒ Object



1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
# File 'lib/tk/font.rb', line 1017

def method_missing(id, *args)
  name = id.id2name
  case args.length
  when 1
    if name[-1] == ?=
      configure name[0..-2], args[0]
      args[0]
    else
      configure name, args[0]
      self
    end
  when 0
    begin
      configinfo name
    rescue
      super(id, *args)
#        fail NameError, "undefined local variable or method `#{name}' for #{self.to_s}", error_at
    end
  else
    super(id, *args)
#      fail NameError, "undefined method `#{name}' for #{self.to_s}", error_at
  end
end

Class Method Details

.actual(fnt, option = nil) ⇒ Object



206
207
208
209
210
211
212
213
# File 'lib/tk/font.rb', line 206

def TkFont.actual(fnt, option=nil)
  fnt = '{}' if fnt == ''
  if fnt.kind_of?(TkFont)
   fnt.actual(option)
  else
    actual_core(fnt, nil, option)
  end
end

.actual_displayof(fnt, win, option = nil) ⇒ Object



218
219
220
221
222
223
224
225
226
# File 'lib/tk/font.rb', line 218

def TkFont.actual_displayof(fnt, win, option=nil)
  fnt = '{}' if fnt == ''
  if fnt.kind_of?(TkFont)
   fnt.actual_displayof(win, option)
  else
    win = '.' unless win
    actual_core(fnt, win, option)
  end
end

.actual_hash(fnt, option = nil) ⇒ Object



214
215
216
# File 'lib/tk/font.rb', line 214

def TkFont.actual_hash(fnt, option=nil)
  Hash[TkFont.actual(fnt, option)]
end

.actual_hash_displayof(fnt, option = nil) ⇒ Object



227
228
229
# File 'lib/tk/font.rb', line 227

def TkFont.actual_hash_displayof(fnt, option=nil)
  Hash[TkFont.actual_displayof(fnt, option)]
end

.configinfo(fnt, slot = nil) ⇒ Object



240
241
242
243
244
245
246
# File 'lib/tk/font.rb', line 240

def TkFont.configinfo(fnt, slot=nil)
  if fnt.kind_of?(TkFont)
    fnt.configinfo(fnt, slot)
  else
    configinfo_core(fnt, slot)
  end
end

.configure(fnt, slot, value = None) ⇒ Object



231
232
233
234
235
236
237
238
# File 'lib/tk/font.rb', line 231

def TkFont.configure(fnt, slot, value=None)
  if fnt.kind_of?(TkFont)
    fnt.configure(fnt, slot, value)
  else
    configure_core(fnt, slot, value)
  end
  fnt
end

.create_copy(font) ⇒ Object



379
380
381
382
383
384
385
386
387
388
# File 'lib/tk/font.rb', line 379

def TkFont.create_copy(font)
  fail 'source-font must be a TkFont object' unless font.kind_of? TkFont
  if TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
    keys = {}
    font.configinfo.each{|key,value| keys[key] = value }
    TkFont.new(font.latin_font_id, font.kanji_font_id, keys)
  else # ! TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
    TkFont.new(font.latin_font_id, font.kanji_font_id, font.configinfo)
  end
end

.current_configinfo(fnt, slot = nil) ⇒ Object



248
249
250
251
252
253
254
# File 'lib/tk/font.rb', line 248

def TkFont.current_configinfo(fnt, slot=nil)
  if fnt.kind_of?(TkFont)
    fnt.current_configinfo(fnt, slot)
  else
    current_configinfo_core(fnt, slot)
  end
end

.failsafe(font) ⇒ Object



528
529
530
531
532
533
534
535
# File 'lib/tk/font.rb', line 528

def TkFont.failsafe(font)
  begin
    if /^8\..*/ === Tk::TK_VERSION  && JAPANIZED_TK
      tk_call('font', 'failsafe', font)
    end
  rescue
  end
end

.families(win = nil) ⇒ Object



348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/tk/font.rb', line 348

def TkFont.families(win=nil)
  case (Tk::TK_VERSION)
  when /^4\..*/
    ['fixed']

  when /^8\..*/
    if win
      tk_split_simplelist(tk_call('font', 'families', '-displayof', win))
    else
      tk_split_simplelist(tk_call('font', 'families'))
    end
  end
end

.get_obj(name) ⇒ Object



390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/tk/font.rb', line 390

def TkFont.get_obj(name)
  name = name.to_s
  if name =~ /^(@font[0-9]+)(|c|l|k)$/
    Tk_FontNameTBL.mutex.synchronize{
      Tk_FontNameTBL[$1]
    }
  else
    Tk_FontNameTBL.mutex.synchronize{
      Tk_FontNameTBL[name]
    }
  end
end

.init_widget_font(pathname, *args) ⇒ Object



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
# File 'lib/tk/font.rb', line 403

def TkFont.init_widget_font(pathname, *args)
  win, tag, key = pathname.split(';')
  key = 'font' if key == nil || key == ''
  path = [win, tag, key].join(';')

  case (Tk::TK_VERSION)
  when /^4\..*/
    regexp = /^-(|kanji)#{key} /

    conf_list = tk_split_simplelist(tk_call(*args)).
      find_all{|prop| prop =~ regexp}.
      collect{|prop| tk_split_simplelist(prop)}

    if conf_list.size == 0
      raise RuntimeError, "the widget may not support 'font' option"
    end

    args << {}

    ltn_key = "-#{key}"
    knj_key = "-kanji#{key}"

    ltn_info = conf_list.find{|conf| conf[0] == ltn_key}
    ltn = ltn_info[-1]
    ltn = nil if ltn == [] || ltn == ""

    knj_info = conf_list.find{|conf| conf[0] == knj_key}
    knj = knj_info[-1]
    knj = nil if knj == [] || knj == ""

    TkFont.new(ltn, knj).call_font_configure([path, key], *args)

  when /^8\.[0-4]/
    regexp = /^-#{key} /

    conf_list = tk_split_simplelist(tk_call(*args)).
      find_all{|prop| prop =~ regexp}.
      collect{|prop| tk_split_simplelist(prop)}

    if conf_list.size == 0
      raise RuntimeError, "the widget may not support 'font' option"
    end

    args << {}

    optkey = "-#{key}"

    info = conf_list.find{|conf| conf[0] == optkey}
    fnt = info[-1]
    fnt = nil if fnt == [] || fnt == ""

    unless fnt
      # 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{|k,v|
              [k[1..-1], v]
            }.assoc('compound')[1])
      rescue
        compound = []
      end
      if compound == []
        if TkFont.is_system_font?(fnt)
          TkNamedFont.new(fnt).call_font_configure([path, key], *args)
        else
          TkFont.new(fnt).call_font_configure([path, key], *args)
        end
      else
        TkFont.new(compound[0],
                   compound[1]).call_font_configure([path, key], *args)
      end
    end

  when /^8\.[5-9]/, /^9\..*/
    regexp = /^-#{key} /

    conf_list = tk_split_simplelist(tk_call(*args)).
      find_all{|prop| prop =~ regexp}.
      collect{|prop| tk_split_simplelist(prop)}

    if conf_list.size == 0
      raise RuntimeError, "the widget may not support 'font' option"
    end

    args << {}

    optkey = "-#{key}"

    info = conf_list.find{|conf| conf[0] == optkey}
    fnt = info[-1]
    fnt = nil if fnt == [] || fnt == ""

    unless fnt
      # 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
      if TkFont.is_system_font?(fnt)
        TkNamedFont.new(fnt).call_font_configure([path, key], *args)
      else
        TkFont.new(fnt).call_font_configure([path, key], *args)
      end
    end
  end
end

.is_system_font?(fnt) ⇒ Boolean

class methods

Returns:

  • (Boolean)


198
199
200
201
202
203
204
# File 'lib/tk/font.rb', line 198

def TkFont.is_system_font?(fnt)
  # true  --> system font which is available on the current system
  # false --> not system font (or unknown system font)
  # nil   --> system font name, but not available on the current system
  fnt = fnt.to_s
  SYSTEM_FONT_NAMES.include?(fnt) && self.names.index(fnt) && true
end

.measure(fnt, text) ⇒ Object



256
257
258
259
260
261
262
263
# File 'lib/tk/font.rb', line 256

def TkFont.measure(fnt, text)
  fnt = '{}' if fnt == ''
  if fnt.kind_of?(TkFont)
    fnt.measure(text)
  else
    measure_core(fnt, nil, text)
  end
end

.measure_displayof(fnt, win, text) ⇒ Object



265
266
267
268
269
270
271
272
273
# File 'lib/tk/font.rb', line 265

def TkFont.measure_displayof(fnt, win, text)
  fnt = '{}' if fnt == ''
  if fnt.kind_of?(TkFont)
    fnt.measure_displayof(win, text)
  else
    win = '.' unless win
    measure_core(fnt, win, text)
  end
end

.metrics(fnt, option = nil) ⇒ Object



275
276
277
278
279
280
281
282
# File 'lib/tk/font.rb', line 275

def TkFont.metrics(fnt, option=nil)
  fnt = '{}' if fnt == ''
  if fnt.kind_of?(TkFont)
    fnt.metrics(option)
  else
    metrics_core(fnt, nil, option)
  end
end

.metrics_displayof(fnt, win, option = nil) ⇒ Object



311
312
313
314
315
316
317
318
319
# File 'lib/tk/font.rb', line 311

def TkFont.metrics_displayof(fnt, win, option=nil)
  fnt = '{}' if fnt == ''
  if fnt.kind_of?(TkFont)
    font.metrics_displayof(win, option=nil)
  else
    win = '.' unless win
    metrics_core(fnt, win, option)
  end
end

.metrics_hash(fnt, option = nil) ⇒ Object



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
# File 'lib/tk/font.rb', line 283

def TkFont.metrics_hash(fnt, option=nil)
  if option
    val = TkFont.metrics(fnt, option)
    case TkFont::MetricsType[option.to_s]
    when ?n
      val = TkComm::num_or_str(val)
    when ?b
      val = TkComm::bool(val)
    else
      # do nothing
    end
    return val
  end

  h = Hash[TkFont.metrics(fnt)]
  h.keys.each{|k|
    case TkFont::MetricsType[k.to_s]
    when ?n
      h[k] = TkComm::num_or_str(h[k])
    when ?b
      h[k] = TkComm::bool(h[k])
    else
      # do nothing
    end
  }
  h
end

.metrics_hash_displayof(fnt, win, option = nil) ⇒ Object



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
# File 'lib/tk/font.rb', line 320

def TkFont.metrics_hash_displayof(fnt, win, option=nil)
  if option
    val = TkFont.metrics_displayof(fnt, win, option)
    case TkFont::MetricsType[option.to_s]
    when ?n
      val = TkComm::num_or_str(val)
    when ?b
      val = TkComm::bool(val)
    else
      # do nothing
    end
    return val
  end

  h = Hash[TkFont.metrics_displayof(fnt, win, option)]
  h.keys.each{|k|
    case TkFont::MetricsType[k.to_s]
    when ?n
      h[k] = TkComm::num_or_str(h[k])
    when ?b
      h[k] = TkComm::bool(h[k])
    else
      # do nothing
    end
  }
  h
end

.namesObject



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/tk/font.rb', line 362

def TkFont.names
  case (Tk::TK_VERSION)
  when /^4\..*/
    r = ['fixed']
    r += ['a14', 'k14'] if JAPANIZED_TK
    Tk_FontNameTBL.mutex.synchronize{
      Tk_FontNameTBL.each_value{|obj| r.push(obj)}
    }
    #r | []
    r.uniq

  when /^8\..*/
    tk_split_simplelist(tk_call('font', 'names'))

  end
end

.used_on(path = nil) ⇒ Object



517
518
519
520
521
522
523
524
525
526
# File 'lib/tk/font.rb', line 517

def TkFont.used_on(path=nil)
  Tk_FontUseTBL.mutex.synchronize{
    if path
      Tk_FontUseTBL[path]
    else
      # Tk_FontUseTBL.values | []
      Tk_FontUseTBL.values.uniq
    end
  }
end

Instance Method Details

#[](slot) ⇒ Object



1257
1258
1259
# File 'lib/tk/font.rb', line 1257

def [](slot)
  configinfo slot
end

#[]=(slot, val) ⇒ Object



1261
1262
1263
1264
# File 'lib/tk/font.rb', line 1261

def []=(slot, val)
  configure slot, val
  val
end

#actual(option = nil) ⇒ Object



1190
1191
1192
# File 'lib/tk/font.rb', line 1190

def actual(option=nil)
  actual_core(@compoundfont, nil, option)
end

#actual_displayof(win, option = nil) ⇒ Object



1197
1198
1199
1200
# File 'lib/tk/font.rb', line 1197

def actual_displayof(win, option=nil)
  win = '.' unless win
  actual_core(@compoundfont, win, option)
end

#actual_hash(option = nil) ⇒ Object



1193
1194
1195
# File 'lib/tk/font.rb', line 1193

def actual_hash(option=nil)
  Hash[actual(option)]
end

#actual_hash_displayof(win, option = nil) ⇒ Object



1201
1202
1203
# File 'lib/tk/font.rb', line 1201

def actual_hash_displayof(win, option=nil)
  Hash[actual_displayof(win, option)]
end

#call_font_configure(path, *args) ⇒ Object



1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
# File 'lib/tk/font.rb', line 1041

def call_font_configure(path, *args)
  if path.kind_of?(Array)
    # [path, optkey]
    win, tag = path[0].split(';')
    optkey = path[1].to_s
  else
    win, tag, optkey = path.split(';')
  end

  fontslot = _symbolkey2str(@fontslot)
  if optkey && optkey != ""
    ltn = fontslot.delete('font')
    knj = fontslot.delete('kanjifont')
    fontslot[optkey] = ltn if ltn
    fontslot["kanji#{optkey}"] = knj if knj
  end

  keys = _symbolkey2str(args.pop).update(fontslot)
  args.concat(hash_kv(keys))
  begin
    tk_call(*args)
  rescue => e
    unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
      fail e
    end
  end
  Tk_FontUseTBL.mutex.synchronize{
    Tk_FontUseTBL[[win, tag, optkey].join(';')] = self
  }
  self
end

#configinfo(slot = nil) ⇒ Object



1271
1272
1273
# File 'lib/tk/font.rb', line 1271

def configinfo(slot=nil)
  configinfo_core(@compoundfont, slot)
end

#configure(slot, value = None) ⇒ Object



1266
1267
1268
1269
# File 'lib/tk/font.rb', line 1266

def configure(slot, value=None)
  configure_core(@compoundfont, slot, value)
  self
end

#current_configinfo(slot = nil) ⇒ Object



1275
1276
1277
# File 'lib/tk/font.rb', line 1275

def current_configinfo(slot=nil)
  current_configinfo_core(@compoundfont, slot)
end

#deleteObject



1279
1280
1281
# File 'lib/tk/font.rb', line 1279

def delete
  delete_core
end

#fontObject Also known as: font_id, name, to_s



1141
1142
1143
# File 'lib/tk/font.rb', line 1141

def font
  @compoundfont
end

#idObject



1133
1134
1135
# File 'lib/tk/font.rb', line 1133

def id
  @id
end

#inspectObject



1013
1014
1015
# File 'lib/tk/font.rb', line 1013

def inspect
  sprintf("#<%s:%0x:%s>", self.class.inspect, self.__id__, @compoundfont)
end

#kanji_actual(option = nil) ⇒ Object



1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
# File 'lib/tk/font.rb', line 1228

def kanji_actual(option=nil)
  #if JAPANIZED_TK
  if @kanjifont == nil
    actual_core(@compoundfont, nil, option) # use @compoundfont
  elsif @kanjifont != ""
    actual_core(@kanjifont, nil, option)
  else
    actual_core_tk4x(nil, nil, option)
  end
end

#kanji_actual_displayof(win, option = nil) ⇒ Object



1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
# File 'lib/tk/font.rb', line 1242

def kanji_actual_displayof(win, option=nil)
  #if JAPANIZED_TK
  if @kanjifont == nil
    actual_core(@compoundfont, nil, option) # use @compoundfont
  elsif @kanjifont != ""
    win = '.' unless win
    actual_core(@kanjifont, win, option)
  else
    actual_core_tk4x(nil, win, option)
  end
end

#kanji_actual_hash(option = nil) ⇒ Object



1238
1239
1240
# File 'lib/tk/font.rb', line 1238

def kanji_actual_hash(option=nil)
  Hash[kanji_actual(option)]
end

#kanji_actual_hash_displayof(win, option = nil) ⇒ Object



1253
1254
1255
# File 'lib/tk/font.rb', line 1253

def kanji_actual_hash_displayof(win, option=nil)
  Hash[kanji_actual_displayof(win, option)]
end

#kanji_configinfo(slot = nil) ⇒ Object



1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
# File 'lib/tk/font.rb', line 1317

def kanji_configinfo(slot=nil)
  #if JAPANIZED_TK
  if @kanjifont == nil
    configure_core(@compoundfont, slot) # use @compoundfont
  elsif @kanjifont != ""
    configinfo_core(@kanjifont, slot)
  else
    #[]
    configinfo(slot)
  end
end

#kanji_configure(slot, value = None) ⇒ Object



1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
# File 'lib/tk/font.rb', line 1303

def kanji_configure(slot, value=None)
  #if JAPANIZED_TK
  if @kanjifont == nil
    configure_core(@compoundfont, slot, value) # use @compoundfont
  elsif @kanjifont != ""
    configure_core(@kanjifont, slot, value)
    configure('size'=>configinfo('size')) # to reflect new configuration
  else
    #""
    configure(slot, value)
  end
  self
end

#kanji_current_configinfo(slot = nil) ⇒ Object



1328
1329
1330
# File 'lib/tk/font.rb', line 1328

def kanji_current_configinfo(slot=nil)
  Hash[kanji_configinfo(slot)]
end

#kanji_fontObject Also known as: kanjifont



1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
# File 'lib/tk/font.rb', line 1173

def kanji_font
  # @kanjifont
  if @descendant[1] # [1] -> kanji
    @descendant[1]
  else
    @descendant[1] = DescendantFont.new(self, 'kanji')
  end
=begin
  if @kanji_descendant
    @kanji_descendant
  else
    @kanji_descendant = DescendantFont.new(self, 'kanji')
  end
=end
end

#kanji_font_idObject



1169
1170
1171
# File 'lib/tk/font.rb', line 1169

def kanji_font_id
  @kanjifont
end

#kanji_metrics(option = nil) ⇒ Object



1512
1513
1514
1515
1516
1517
1518
1519
1520
# File 'lib/tk/font.rb', line 1512

def kanji_metrics(option=nil)
  if @latinfont == nil
    metrics_core(@compoundfont, nil, option) # use @compoundfont
  elsif JAPANIZED_TK
    metrics_core(@kanjifont, nil, option)
  else
    metrics_core_tk4x(nil, nil, option)
  end
end

#kanji_metrics_displayof(win, option = nil) ⇒ Object



1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
# File 'lib/tk/font.rb', line 1549

def kanji_metrics_displayof(win, option=nil)
  win = '.' unless win
  if @latinfont == nil
    metrics_core(@compoundfont, win, option) # use @compoundfont
  elsif JAPANIZED_TK
    metrics_core(@kanjifont, win, option)
  else
    metrics_core_tk4x(nil, win, option)
  end
end

#kanji_metrics_hash(option = nil) ⇒ Object



1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
# File 'lib/tk/font.rb', line 1521

def kanji_metrics_hash(option=nil)
  if option
    val = kanji_metrics(option)
    case TkFont::MetricsType[option.to_s]
    when ?n
      val = TkComm::num_or_str(val)
    when ?b
      val = TkComm::bool(val)
    else
      # do nothing
    end
    return val
  end

  h = Hash[kanji_metrics(option)]
  h.keys.each{|k|
    case TkFont::MetricsType[k.to_s]
    when ?n
      h[k] = TkComm::num_or_str(h[k])
    when ?b
      h[k] = TkComm::bool(h[k])
    else
      # do nothing
    end
  }
  h
end

#kanji_metrics_hash_displayof(win, option = nil) ⇒ Object



1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
# File 'lib/tk/font.rb', line 1559

def kanji_metrics_hash_displayof(win, option=nil)
  if option
    val = kanji_metrics_displayof(win, option)
    case TkFont::MetricsType[option.to_s]
    when ?n
      val = TkComm::num_or_str(val)
    when ?b
      val = TkComm::bool(val)
    else
      # do nothing
    end
    return val
  end

  h = Hash[kanji_metrics_displayof(win, option)]
  h.keys.each{|k|
    case TkFont::MetricsType[k.to_s]
    when ?n
      h[k] = TkComm::num_or_str(h[k])
    when ?b
      h[k] = TkComm::bool(h[k])
    else
      # do nothing
    end
  }
  h
end

#kanji_replace(knj) ⇒ Object



1362
1363
1364
1365
1366
1367
# File 'lib/tk/font.rb', line 1362

def kanji_replace(knj)
  return self unless @kanjifont  # ignore
  kanji_replace_core(knj)
  reset_pointadjust
  self
end

#latin_actual(option = nil) ⇒ Object Also known as: ascii_actual



1205
1206
1207
1208
1209
1210
1211
# File 'lib/tk/font.rb', line 1205

def latin_actual(option=nil)
  if @latinfont == nil
    actual_core(@compoundfont, nil, option) # use @compoundfont
  else
    actual_core(@latinfont, nil, option)
  end
end

#latin_actual_displayof(win, option = nil) ⇒ Object Also known as: ascii_actual_displayof



1216
1217
1218
1219
1220
1221
1222
1223
# File 'lib/tk/font.rb', line 1216

def latin_actual_displayof(win, option=nil)
  win = '.' unless win
  if @latinfont == nil
    actual_core(@compoundfont, win, option) # use @compoundfont
  else
    actual_core(@latinfont, win, option)
  end
end

#latin_actual_hash(option = nil) ⇒ Object



1212
1213
1214
# File 'lib/tk/font.rb', line 1212

def latin_actual_hash(option=nil)
  Hash[latin_actual(option)]
end

#latin_actual_hash_displayof(win, option = nil) ⇒ Object



1224
1225
1226
# File 'lib/tk/font.rb', line 1224

def latin_actual_hash_displayof(win, option=nil)
  Hash[latin_actual_displayof(win, option)]
end

#latin_configinfo(slot = nil) ⇒ Object Also known as: ascii_configinfo



1292
1293
1294
1295
1296
1297
1298
# File 'lib/tk/font.rb', line 1292

def latin_configinfo(slot=nil)
  if JAPANIZED_TK
    configinfo_core(@latinfont, slot)
  else
    configinfo(slot)
  end
end

#latin_configure(slot, value = None) ⇒ Object Also known as: ascii_configure



1283
1284
1285
1286
1287
1288
1289
1290
# File 'lib/tk/font.rb', line 1283

def latin_configure(slot, value=None)
  if JAPANIZED_TK
    configure_core(@latinfont, slot, value)
  else
    configure(slot, value)
  end
  self
end

#latin_current_configinfo(slot = nil) ⇒ Object



1299
1300
1301
# File 'lib/tk/font.rb', line 1299

def latin_current_configinfo(slot=nil)
  Hash[latin_configinfo(slot)]
end

#latin_fontObject Also known as: latinfont, ascii_font



1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
# File 'lib/tk/font.rb', line 1152

def latin_font
  # @latinfont
  if @descendant[0] # [0] -> latin
    @descendant[0]
  else
    @descendant[0] = DescendantFont.new(self, 'latin')
  end
=begin
  if @latin_descendant
    @latin_descendant
  else
    @latin_descendant = DescendantFont.new(self, 'latin')
  end
=end
end

#latin_font_idObject



1148
1149
1150
# File 'lib/tk/font.rb', line 1148

def latin_font_id
  @latinfont
end

#latin_metrics(option = nil) ⇒ Object Also known as: ascii_metrics



1441
1442
1443
1444
1445
1446
1447
# File 'lib/tk/font.rb', line 1441

def latin_metrics(option=nil)
  if @latinfont == nil
    metrics_core(@compoundfont, nil, option) # use @compoundfont
  else
    metrics_core(@latinfont, nil, option)
  end
end

#latin_metrics_displayof(win, option = nil) ⇒ Object



1476
1477
1478
1479
1480
1481
1482
1483
# File 'lib/tk/font.rb', line 1476

def latin_metrics_displayof(win, option=nil)
  win = '.' unless win
  if @latinfont == nil
    metrics_core(@compoundfont, win, option) # use @compoundfont
  else
    metrics_core(@latinfont, win, option)
  end
end

#latin_metrics_hash(option = nil) ⇒ Object



1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
# File 'lib/tk/font.rb', line 1448

def latin_metrics_hash(option=nil)
  if option
    val = latin_metrics(option)
    case TkFont::MetricsType[option.to_s]
    when ?n
      val = TkComm::num_or_str(val)
    when ?b
      val = TkComm::bool(val)
    else
      # do nothing
    end
    return val
  end

  h = Hash[latin_metrics(option)]
  h.keys.each{|k|
    case TkFont::MetricsType[k.to_s]
    when ?n
      h[k] = TkComm::num_or_str(h[k])
    when ?b
      h[k] = TkComm::bool(h[k])
    else
      # do nothing
    end
  }
  h
end

#latin_metrics_hash_displayof(win, option = nil) ⇒ Object



1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
# File 'lib/tk/font.rb', line 1484

def latin_metrics_hash_displayof(win, option=nil)
  if option
    val = latin_metrics_displayof(win, option)
    case TkFont::MetricsType[option.to_s]
    when ?n
      val = TkComm::num_or_str(val)
    when ?b
      val = TkComm::bool(val)
    else
      # do nothing
    end
    return val
  end

  h = Hash[latin_metrics_displayof(win, option)]
  h.keys.each{|k|
    case TkFont::MetricsType[k.to_s]
    when ?n
      h[k] = TkComm::num_or_str(h[k])
    when ?b
      h[k] = TkComm::bool(h[k])
    else
      # do nothing
    end
  }
  h
end

#latin_replace(ltn) ⇒ Object Also known as: ascii_replace



1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
# File 'lib/tk/font.rb', line 1339

def latin_replace(ltn)
  if @latinfont
    latin_replace_core(ltn)
    reset_pointadjust
  else
    # not compound font -> copy properties of ltn
    latinkeys = {}
    begin
      actual_core(ltn).each{|key,val| latinkeys[key] = val}
    rescue
      latinkeys = {}
    end
    begin
      tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys))
    rescue
      # not exist? (deleted?) -> create font
      tk_call('font', 'create', @compoundfont, *hash_kv(latinkeys))
    end
  end

  self
end

#measure(text) ⇒ Object



1369
1370
1371
# File 'lib/tk/font.rb', line 1369

def measure(text)
  measure_core(@compoundfont, nil, text)
end

#measure_displayof(win, text) ⇒ Object



1373
1374
1375
1376
# File 'lib/tk/font.rb', line 1373

def measure_displayof(win, text)
  win = '.' unless win
  measure_core(@compoundfont, win, text)
end

#metrics(option = nil) ⇒ Object



1378
1379
1380
# File 'lib/tk/font.rb', line 1378

def metrics(option=nil)
  metrics_core(@compoundfont, nil, option)
end

#metrics_displayof(win, option = nil) ⇒ Object



1409
1410
1411
1412
# File 'lib/tk/font.rb', line 1409

def metrics_displayof(win, option=nil)
  win = '.' unless win
  metrics_core(@compoundfont, win, option)
end

#metrics_hash(option = nil) ⇒ Object



1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
# File 'lib/tk/font.rb', line 1381

def metrics_hash(option=nil)
  if option
    val = metrics(option)
    case TkFont::MetricsType[option.to_s]
    when ?n
      val = TkComm::num_or_str(val)
    when ?b
      val = TkComm::bool(val)
    else
      # do nothing
    end
    return val
  end

  h = Hash[metrics(option)]
  h.keys.each{|k|
    case TkFont::MetricsType[k.to_s]
    when ?n
      h[k] = TkComm::num_or_str(h[k])
    when ?b
      h[k] = TkComm::bool(h[k])
    else
      # do nothing
    end
  }
  h
end

#metrics_hash_displayof(win, option = nil) ⇒ Object



1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
# File 'lib/tk/font.rb', line 1413

def metrics_hash_displayof(win, option=nil)
  if option
    val = metrics_displayof(win, option)
    case TkFont::MetricsType[option.to_s]
    when ?n
      val = TkComm::num_or_str(val)
    when ?b
      val = TkComm::bool(val)
    else
      # do nothing
    end
    return val
  end

  h = Hash[metrics_displayof(win, option)]
  h.keys.each{|k|
    case TkFont::MetricsType[k.to_s]
    when ?n
      h[k] = TkComm::num_or_str(h[k])
    when ?b
      h[k] = TkComm::bool(h[k])
    else
      # do nothing
    end
  }
  h
end

#replace(ltn, knj = None) ⇒ Object



1332
1333
1334
1335
1336
1337
# File 'lib/tk/font.rb', line 1332

def replace(ltn, knj=None)
  knj = ltn if knj == None
  latin_replace(ltn)
  kanji_replace(knj)
  self
end

#reset_pointadjustObject



1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
# File 'lib/tk/font.rb', line 1587

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

#to_evalObject



1137
1138
1139
# File 'lib/tk/font.rb', line 1137

def to_eval
  font
end

#usedObject



1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
# File 'lib/tk/font.rb', line 1073

def used
  ret = []
  table = nil
  Tk_FontUseTBL.mutex.synchronize{
    table = Tk_FontUseTBL.clone # to avoid deadlock
  }
  table.each{|key,value|
    next unless self == value
    if key.include?(';')
      win, tag, optkey = key.split(';')
      winobj = tk_tcl2ruby(win)
      #if winobj.kind_of? TkText
      if winobj.kind_of?(TkText) || winobj.kind_of?(Tk::Text)
        if optkey
          ret.push([winobj, winobj.tagid2obj(tag), optkey])
        else
          ret.push([winobj, winobj.tagid2obj(tag)])
        end
      #elsif winobj.kind_of? TkCanvas
      elsif winobj.kind_of?(TkCanvas) || winobj.kind_of?(Tk::Canvas)
        if (tagobj = TkcTag.id2obj(winobj, tag)).kind_of? TkcTag
          if optkey
            ret.push([winobj, tagobj, optkey])
          else
            ret.push([winobj, tagobj])
          end
        elsif (tagobj = TkcItem.id2obj(winobj, tag)).kind_of? TkcItem
          if optkey
            ret.push([winobj, tagobj, optkey])
          else
            ret.push([winobj, tagobj])
          end
        else
          if optkey
            ret.push([winobj, tag, optkey])
          else
            ret.push([winobj, tag])
          end
        end
      #elsif winobj.kind_of? TkMenu
      elsif winobj.kind_of?(TkMenu) || winobj.kind_of?(Tk::Menu)
        if optkey
          ret.push([winobj, tag, optkey])
        else
          ret.push([winobj, tag])
        end
      else
        if optkey
          ret.push([win, tag, optkey])
        else
          ret.push([win, tag])
        end
      end
    else
      ret.push(tk_tcl2ruby(key))
    end
  }
  ret
end