Class TkFont
In: tk/lib/tk/font.rb
Parent: Object

Methods

Included Modules

Tk

Classes and Modules

Class TkFont::DescendantFont

Constants

TkCommandNames = ['font'.freeze].freeze
Tk_FontID = ["@font".freeze, "00000".taint].freeze
Tk_FontNameTBL = TkCore::INTERP.create_table
Tk_FontUseTBL = TkCore::INTERP.create_table
DEFAULT_LATIN_FONT_NAME = 'a14'.freeze
DEFAULT_KANJI_FONT_NAME = 'k14'.freeze
DEFAULT_LATIN_FONT_NAME = ltn.freeze
DEFAULT_KANJI_FONT_NAME = knj.freeze
DEFAULT_LATIN_FONT_NAME = 'Helvetica'.freeze
DEFAULT_KANJI_FONT_NAME = 'mincho'.freeze

Public Class methods

[Source]

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

[Source]

# File tk/lib/tk/font.rb, line 279
  def TkFont.failsafe(font)
    begin
      if /^8\.*/ === Tk::TK_VERSION  && JAPANIZED_TK
        tk_call('font', 'failsafe', font)
      end
    rescue
    end
  end

class methods

[Source]

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

[Source]

# File tk/lib/tk/font.rb, line 190
  def TkFont.get_obj(name)
    if name =~ /^(@font[0-9]+)(|c|l|k)$/
      Tk_FontNameTBL[$1]
    else
      nil
    end
  end

[Source]

# File tk/lib/tk/font.rb, line 198
  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\.*/
      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
        TkFont.new(nil, nil).call_font_configure([path, key], *args)
      else
        begin
          compound = tk_split_simplelist(
              Hash[*tk_split_simplelist(tk_call('font', 'configure', 
                                                fnt))].collect{|key,value|
                [key[1..-1], value]
              }.assoc('compound')[1])
        rescue
          compound = []
        end
        if compound == []
          TkFont.new(fnt).call_font_configure([path, key], *args)
        else
          TkFont.new(compound[0], 
                     compound[1]).call_font_configure([path, key], *args)
        end
      end
    end
  end

[Source]

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

[Source]

# File tk/lib/tk/font.rb, line 293
  def initialize(ltn=nil, knj=nil, keys=nil)
    # @id = Tk_FontID.join('')

    @id = Tk_FontID.join(TkCore::INTERP._ip_id_)
    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 Tk::TK_VERSION == '8.0' && JAPANIZED_TK
      begin
        compound = tk_split_simplelist(tk_call('font', 'configure', 
                                               ltn, '-compound'))
        if knj == nil
          if compound != []
            ltn, knj = compound
          end
        else
          if compound != []
            ltn = compound[0]
          end
          compound = tk_split_simplelist(tk_call('font', 'configure', 
                                                 knj, '-compound'))
          if compound != []
            knj = compound[1]
          end
        end
      rescue
      end
    end

    if ltn
      if JAPANIZED_TK && !knj
        if Tk::TK_VERSION =~ /^4.*/
          knj = DEFAULT_KANJI_FONT_NAME
        else
          knj = ltn 
        end
      end
    else
      ltn = DEFAULT_LATIN_FONT_NAME
      knj = DEFAULT_KANJI_FONT_NAME if JAPANIZED_TK && !knj
    end

    create_compoundfont(ltn, knj, keys)
  end

[Source]

# File tk/lib/tk/font.rb, line 271
  def TkFont.used_on(path=nil)
    if path
      Tk_FontUseTBL[path]
    else
      Tk_FontUseTBL.values | []
    end
  end

Public Instance methods

[Source]

# File tk/lib/tk/font.rb, line 1300
  def [](slot)
    configinfo slot
  end

[Source]

# File tk/lib/tk/font.rb, line 1304
  def []=(slot, val)
    configure slot, val
    val
  end

[Source]

# File tk/lib/tk/font.rb, line 1263
  def actual(option=nil)
    actual_core(@compoundfont, nil, option)
  end

[Source]

# File tk/lib/tk/font.rb, line 1267
  def actual_displayof(window, option=nil)
    window = '.' unless window
    actual_core(@compoundfont, window, option)
  end
ascii_actual(option=nil)

Alias for latin_actual

ascii_actual_displayof(window, option=nil)
ascii_configinfo(slot=nil)

Alias for latin_configinfo

ascii_configure(slot, value=None)

Alias for latin_configure

ascii_font()

Alias for latin_font

ascii_metrics(option=nil)

Alias for latin_metrics

ascii_replace(ltn)

Alias for latin_replace

asciifont()

Alias for latinfont

[Source]

# File tk/lib/tk/font.rb, line 1145
  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))
    tk_call(*args)
    Tk_FontUseTBL[[win, tag, optkey].join(';')] = self
    self
  end

[Source]

# File tk/lib/tk/font.rb, line 1458
  def clone
    src = self
    obj = super()
    obj.instance_eval{ initialize(src) }
    obj
  end

[Source]

# File tk/lib/tk/font.rb, line 1314
  def configinfo(slot=nil)
    configinfo_core(@compoundfont, slot)
  end

[Source]

# File tk/lib/tk/font.rb, line 1309
  def configure(slot, value=None)
    configure_core(@compoundfont, slot, value)
    self
  end
create_asciifont(font)

Alias for create_latinfont

[Source]

# File tk/lib/tk/font.rb, line 1318
  def current_configinfo(slot=nil)
    current_configinfo_core(@compoundfont, slot)
  end

[Source]

# File tk/lib/tk/font.rb, line 1322
  def delete
    delete_core
  end

[Source]

# File tk/lib/tk/font.rb, line 1452
  def dup
    src = self
    obj = super()
    obj.instance_eval{ initialize(src) }
    obj
  end

[Source]

# File tk/lib/tk/font.rb, line 1230
  def font
    @compoundfont
  end
font_id()

Alias for font

[Source]

# File tk/lib/tk/font.rb, line 1222
  def id
    @id
  end

[Source]

# File tk/lib/tk/font.rb, line 1281
  def kanji_actual(option=nil)
    #if JAPANIZED_TK

    if @kanjifont != ""
      actual_core(@kanjifont, nil, option)
    else
      actual_core_tk4x(nil, nil, option)
    end
  end

[Source]

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

[Source]

# File tk/lib/tk/font.rb, line 1355
  def kanji_configinfo(slot=nil)
    #if JAPANIZED_TK

    if @kanjifont != ""
      configinfo_core(@kanjifont, slot)
    else
      #[]

      configinfo(slot)
    end
  end

[Source]

# File tk/lib/tk/font.rb, line 1343
  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
    self
  end

[Source]

# File tk/lib/tk/font.rb, line 1253
  def kanji_font
    # @kanjifont

    if @kanji_descendant
      @kanji_descendant
    else
      @kanji_descendant = DescendantFont.new(self, 'kanji')
    end
  end

[Source]

# File tk/lib/tk/font.rb, line 1249
  def kanji_font_id
    @kanjifont
  end

[Source]

# File tk/lib/tk/font.rb, line 1410
  def kanji_metrics(option=nil)
    if JAPANIZED_TK
      metrics_core(@kanjifont, nil, option)
    else
      metrics_core_tk4x(nil, nil, option)
    end
  end

[Source]

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

[Source]

# File tk/lib/tk/font.rb, line 1377
  def kanji_replace(knj)
    kanji_replace_core(knj)
    reset_pointadjust
    self
  end
kanjifont()

Alias for kanji_font

[Source]

# File tk/lib/tk/font.rb, line 1272
  def latin_actual(option=nil)
    actual_core(@latinfont, nil, option)
  end

[Source]

# File tk/lib/tk/font.rb, line 1276
  def latin_actual_displayof(window, option=nil)
    window = '.' unless window
    actual_core(@latinfont, window, option)
  end

[Source]

# File tk/lib/tk/font.rb, line 1335
  def latin_configinfo(slot=nil)
    if JAPANIZED_TK
      configinfo_core(@latinfont, slot)
    else
      configinfo(slot)
    end
  end

[Source]

# File tk/lib/tk/font.rb, line 1326
  def latin_configure(slot, value=None)
    if JAPANIZED_TK
      configure_core(@latinfont, slot, value)
    else
      configure(slot, value)
    end
    self
  end

[Source]

# File tk/lib/tk/font.rb, line 1239
  def latin_font
    # @latinfont

    if @latin_descendant
      @latin_descendant
    else
      @latin_descendant = DescendantFont.new(self, 'latin')
    end
  end

[Source]

# File tk/lib/tk/font.rb, line 1235
  def latin_font_id
    @latinfont
  end

[Source]

# File tk/lib/tk/font.rb, line 1401
  def latin_metrics(option=nil)
    metrics_core(@latinfont, nil, option)
  end

[Source]

# File tk/lib/tk/font.rb, line 1405
  def latin_metrics_displayof(window, option=nil)
    window = '.' unless window
    metrics_core(@latinfont, window, option)
  end

[Source]

# File tk/lib/tk/font.rb, line 1371
  def latin_replace(ltn)
    latin_replace_core(ltn)
    reset_pointadjust
    self
  end
latinfont()

Alias for latin_font

[Source]

# File tk/lib/tk/font.rb, line 1383
  def measure(text)
    measure_core(nil, text)
  end

[Source]

# File tk/lib/tk/font.rb, line 1387
  def measure_displayof(window, text)
    window = '.' unless window
    measure_core(window, text)
  end

[Source]

# File tk/lib/tk/font.rb, line 1129
  def method_missing(id, *args)
    name = id.id2name
    case args.length
    when 1
      configure name, args[0]
    when 0
      begin
        configinfo name
      rescue
        fail NameError, "undefined local variable or method `#{name}' for #{self.to_s}", error_at
      end
    else
      fail NameError, "undefined method `#{name}' for #{self.to_s}", error_at
    end
  end

[Source]

# File tk/lib/tk/font.rb, line 1392
  def metrics(option=nil)
    metrics_core(@compoundfont, nil, option)
  end

[Source]

# File tk/lib/tk/font.rb, line 1396
  def metrics_displayof(window, option=nil)
    window = '.' unless window
    metrics_core(@compoundfont, window, option)
  end

[Source]

# File tk/lib/tk/font.rb, line 1365
  def replace(ltn, knj)
    latin_replace(ltn)
    kanji_replace(knj)
    self
  end

[Source]

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

[Source]

# File tk/lib/tk/font.rb, line 1226
  def to_eval
    font
  end

[Source]

# File tk/lib/tk/font.rb, line 1169
  def used
    ret = []
    Tk_FontUseTBL.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 optkey
            ret.push([winobj, winobj.tagid2obj(tag), optkey])
          else
            ret.push([winobj, winobj.tagid2obj(tag)])
          end
        elsif winobj.kind_of? TkCanvas
          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
          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

[Validate]