TkFont (Class)

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

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

Classes and Modules

Class TkFont::DescendantFont

Included Modules

Tk

Public Class methods

[Source]

# File tk/lib/tk/font.rb, line 186
  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 266
  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 158
  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 197
  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 205
  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 = 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, DEFAULT_KANJI_FONT_NAME) \

          #.call_font_configure(path, *(args + [{}]))

          TkFont.new(fnt).call_font_configure(path, *(args + [{}]))
        else
          TkFont.new(compound[0], compound[1]) \
          .call_font_configure(path, *(args + [{}]))
        end
      end
    end
  end

[Source]

# File tk/lib/tk/font.rb, line 172
  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 280
  def initialize(ltn=nil, knj=nil, keys=nil)
    @id = Tk_FontID.join('')
    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 258
  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 1243
  def [](slot)
    configinfo slot
  end

[Source]

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

[Source]

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

[Source]

# File tk/lib/tk/font.rb, line 1210
  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 1129
  def call_font_configure(path, *args)
    keys = args.pop.update(@fontslot)
    args.concat(hash_kv(keys))
    tk_call(*args)
    Tk_FontUseTBL[path] = self
    self
  end

[Source]

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

[Source]

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

[Source]

# File tk/lib/tk/font.rb, line 1252
  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 1261
  def current_configinfo(slot=nil)
    current_configinfo_core(@compoundfont, slot)
  end

[Source]

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

[Source]

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

[Source]

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

Alias for font

[Source]

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

[Source]

# File tk/lib/tk/font.rb, line 1224
  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 1233
  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 1298
  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 1286
  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 1196
  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 1192
  def kanji_font_id
    @kanjifont
  end

[Source]

# File tk/lib/tk/font.rb, line 1353
  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 1361
  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 1320
  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 1215
  def latin_actual(option=nil)
    actual_core(@latinfont, nil, option)
  end

[Source]

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

[Source]

# File tk/lib/tk/font.rb, line 1278
  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 1269
  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 1182
  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 1178
  def latin_font_id
    @latinfont
  end

[Source]

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

[Source]

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

[Source]

# File tk/lib/tk/font.rb, line 1314
  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 1326
  def measure(text)
    measure_core(nil, text)
  end

[Source]

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

[Source]

# File tk/lib/tk/font.rb, line 1113
  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 1335
  def metrics(option=nil)
    metrics_core(@compoundfont, nil, option)
  end

[Source]

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

[Source]

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

[Source]

# File tk/lib/tk/font.rb, line 1370
  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 1169
  def to_eval
    font
  end

[Source]

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

[Validate]