# class Font

autoload

### Constants

DEFAULT_KANJI_FONT_NAME
DEFAULT_LATIN_FONT_NAME
MetricType

  metric_type : default => num_or_str

OptionType

  option_type : default => string

SYSTEM_FONT_NAMES

  system font names

TkCommandNames
Tk_FontID
Tk_FontNameTBL
Tk_FontUseTBL

### Public Class Methods

actual(fnt, option=nil) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

class methods

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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

names() click to toggle source

    # 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

new(ltn=nil, knj=nil, keys=nil) click to toggle source

    # File lib/tk/font.rb, line 588
    def initialize(ltn=nil, knj=nil, keys=nil)
      ltn = '{}' if ltn == ''
      knj = '{}' if knj == ''

      Tk_FontID.mutex.synchronize{
        # @id = Tk_FontID.join('')
        @id = Tk_FontID.join(TkCore::INTERP._ip_id_)
        Tk_FontID[1].succ!
      }
      Tk_FontNameTBL.mutex.synchronize{
        Tk_FontNameTBL[@id] = self
      }

      # @latin_desscendant = nil
      # @kanji_desscendant = nil
      @descendant = [nil, nil] # [latin, kanji]

      # @latinfont = @id + 'l'
      # @kanjifont = @id + 'k'
      # @compoundfont = @id + 'c'
      # @fontslot = {}

      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

used_on(path=nil) click to toggle source

    # 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

### Public Instance Methods

[](slot) click to toggle source

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

[]=(slot, val) click to toggle source

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

actual(option=nil) click to toggle source

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

actual_displayof(win, option=nil) click to toggle source

    # 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) click to toggle source

    # File lib/tk/font.rb, line 1193
    def actual_hash(option=nil)
      Hash[actual(option)]
    end

actual_hash_displayof(win, option=nil) click to toggle source

    # File lib/tk/font.rb, line 1201
    def actual_hash_displayof(win, option=nil)
      Hash[actual_displayof(win, option)]
    end

ascii_actual(option=nil)
Alias for: latin_actual
ascii_actual_displayof(win, option=nil)
Alias for: latin_actual_displayof
ascii_configinfo(slot=nil)
Alias for: latin_configinfo
ascii_configure(slot, value=None)
Alias for: latin_configure
ascii_font()

public alias

Alias for: latin_font
ascii_metrics(option=nil)
Alias for: latin_metrics
ascii_replace(ltn)
Alias for: latin_replace
asciifont()
Alias for: latinfont
call_font_configure(path, *args) click to toggle source

    # 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) click to toggle source

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

configure(slot, value=None) click to toggle source

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

create_asciifont(font)
Alias for: create_latinfont
create_compoundfont(ltn, knj, keys)
Alias for: create_compoundfont_tk4x
create_kanjifont(font)
Alias for: create_kanjifont_tk4x
create_latinfont(font)
Also aliased as: create_asciifont
Alias for: create_latinfont_tk4x
current_configinfo(slot=nil) click to toggle source

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

delete() click to toggle source

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

font() click to toggle source

    # File lib/tk/font.rb, line 1141
    def font
      @compoundfont
    end

Also aliased as: font_id, name, to_s
font_id()
Alias for: font
id() click to toggle source

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

inspect() click to toggle source

    # File lib/tk/font.rb, line 1013
    def inspect
      sprintf("#<%s:%0x:%s>", self.class.inspect, self.__id__, @compoundfont)
    end

kanji_actual(option=nil) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # File lib/tk/font.rb, line 1328
    def kanji_current_configinfo(slot=nil)
      Hash[kanji_configinfo(slot)]
    end

kanji_font() click to toggle source

    # 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

Also aliased as: kanjifont
kanji_font_id() click to toggle source

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

kanji_metrics(option=nil) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # File lib/tk/font.rb, line 1362
    def kanji_replace(knj)
      return self unless @kanjifont  # ignore
      kanji_replace_core(knj)
      reset_pointadjust
      self
    end

kanjifont()
Alias for: kanji_font
latin_actual(option=nil) click to toggle source

    # 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

Also aliased as: ascii_actual
latin_actual_displayof(win, option=nil) click to toggle source

    # 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

Also aliased as: ascii_actual_displayof
latin_actual_hash(option=nil) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

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

Also aliased as: ascii_configinfo
latin_configure(slot, value=None) click to toggle source

    # 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

Also aliased as: ascii_configure
latin_current_configinfo(slot=nil) click to toggle source

    # File lib/tk/font.rb, line 1299
    def latin_current_configinfo(slot=nil)
      Hash[latin_configinfo(slot)]
    end

latin_font() click to toggle source

    # 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

Also aliased as: latinfont, ascii_font
latin_font_id() click to toggle source

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

latin_metrics(option=nil) click to toggle source

    # 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

Also aliased as: ascii_metrics
latin_metrics_displayof(win, option=nil) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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

Also aliased as: ascii_replace
latinfont()
Also aliased as: asciifont
Alias for: latin_font
measure(text) click to toggle source

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

measure_displayof(win, text) click to toggle source

    # File lib/tk/font.rb, line 1373
    def measure_displayof(win, text)
      win = '.' unless win
      measure_core(@compoundfont, win, text)
    end

method_missing(id, *args) click to toggle source
Calls superclass method Object#method_missing

    # 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

metrics(option=nil) click to toggle source

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

metrics_displayof(win, option=nil) click to toggle source

    # 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) click to toggle source

    # 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) click to toggle source

    # 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

mutex() click to toggle source

    # File lib/tk/font.rb, line 17
    def mutex; @mutex; end

name()
Alias for: font
replace(ltn, knj=None) click to toggle source

    # 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_pointadjust() click to toggle source

    # 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_eval() click to toggle source

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

to_s()
Alias for: font
used() click to toggle source

    # 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

### Private Instance Methods

_get_font_info_from_hash(font) click to toggle source

    # File lib/tk/font.rb, line 667
    def _get_font_info_from_hash(font)
      font = _symbolkey2str(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

create_compoundfont_tk4x(ltn, knj, keys) click to toggle source

    # File lib/tk/font.rb, line 784
    def create_compoundfont_tk4x(ltn, knj, keys)
      create_latinfont(ltn)
      create_kanjifont(knj)

      if JAPANIZED_TK
        @compoundfont = [[@latinfont], [@kanjifont]]
        @fontslot = {'font'=>@latinfont, 'kanjifont'=>@kanjifont}
        # @fontslot.clear
        # @fontslot['font'] = @latinfont
        # @fontslot['kanjifont'] = @kanjifont
      else
        @compoundfont = @latinfont
        @fontslot = {'font'=>@latinfont}
        # @fontslot.clear
        # @fontslot['font'] = @latinfont
      end
    end

Also aliased as: create_compoundfont
create_compoundfont_tk8x(ltn, knj, keys) click to toggle source

    # File lib/tk/font.rb, line 894
    def create_compoundfont_tk8x(ltn, knj, keys)
      if knj
        create_latinfont(ltn)
        create_kanjifont(knj)
      else
        cfnt = ltn
        create_kanjifont(cfnt)
        create_latinfont(cfnt)
      end

      @compoundfont = @id + 'c'

      if JAPANIZED_TK
        unless keys
          keys = {}
        else
          keys = keys.dup
        end
        if (tk_call('font', 'configure', @latinfont, '-underline') == '1' &&
            tk_call('font', 'configure', @kanjifont, '-underline') == '1' &&
            !keys.key?('underline'))
          keys['underline'] = true
        end
        if (tk_call('font', 'configure', @latinfont, '-overstrike') == '1' &&
            tk_call('font', 'configure', @kanjifont, '-overstrike') == '1' &&
            !keys.key?('overstrike'))
          keys['overstrike'] = true
        end

        @fontslot = {'font'=>@compoundfont}
        # @fontslot['font'] = @compoundfont
        begin
          tk_call('font', 'create', @compoundfont,
                  '-compound', [@latinfont, @kanjifont], *hash_kv(keys))
        rescue RuntimeError => e
          if ltn == knj
            if e.message =~ /kanji font .* specified/
              tk_call('font', 'delete', @latinfont)
              create_latinfont(DEFAULT_LATIN_FONT_NAME)
              opts = []
              Hash[*(tk_split_simplelist(tk_call('font', 'configure',
                                                 @kanjifont)))].each{|k,v|
                case k
                when '-size', '-weight', '-slant', '-underline', '-overstrike'
                  opts << k << v
                end
              }
              tk_call('font', 'configure', @latinfont, *opts)
              tk_call('font', 'create', @compoundfont,
                      '-compound', [@latinfont, @kanjifont], *hash_kv(keys))

            elsif e.message =~ /ascii font .* specified/
              tk_call('font', 'delete', @kanjifont)
              create_kanjifont(DEFAULT_KANJI_FONT_NAME)
              opts = []
              Hash[*(tk_split_simplelist(tk_call('font', 'configure',
                                                 @latinfont)))].each{|k,v|
                case k
                when '-size', '-weight', '-slant', '-underline', '-overstrike'
                  opts << k << v
                end
              }
              tk_call('font', 'configure', @kanjifont, *opts)
              tk_call('font', 'create', @compoundfont,
                      '-compound', [@latinfont, @kanjifont], *hash_kv(keys))

            else
              raise e
            end
          else
            raise e
          end
        end
      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

        if knj
          compoundkeys = nil
          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
        end

        if cfnt
          if cfnt.kind_of?(Hash)
            compoundkeys = cfnt.dup
          else
            compoundkeys = {}
            actual_core(cfnt).each{|key,val| compoundkeys[key] = val}
          end
          compoundkeys.update(_symbolkey2str(keys))
          keys = compoundkeys
        end

        @fontslot = {'font'=>@compoundfont}
        # @fontslot['font'] = @compoundfont
        tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
      end
    end

Also aliased as: create_compoundfont, create_compoundfont
create_kanjifont_tk4x(font) click to toggle source

    # File lib/tk/font.rb, line 735
    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_id
      else
        if font
          @kanjifont = font
        else
          @kanjifont = DEFAULT_KANJI_FONT_NAME
        end
      end
    end

Also aliased as: create_kanjifont
create_kanjifont_tk8x(font) click to toggle source

    # File lib/tk/font.rb, line 847
    def create_kanjifont_tk8x(font)
      @kanjifont = @id + 'k'

      if JAPANIZED_TK
        if font.kind_of? Hash
          if font[:charset] || 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_id)
        elsif font
          tk_call('font', 'create', @kanjifont, '-copy', font,
                  '-charset', 'jisx0208.1983')
        else
          tk_call('font', 'create', @kanjifont, '-charset', 'jisx0208.1983')
        end
        # end of JAPANIZED_TK

      else
        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_id).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

        if font && @compoundfont
          keys = {}
          actual_core(@kanjifont).each{|key,val| keys[key] = val}
          tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
        end
      end
    end

Also aliased as: create_kanjifont, create_kanjifont
create_latinfont_tk4x(font) click to toggle source

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

Also aliased as: create_latinfont
create_latinfont_tk8x(font) click to toggle source

    # File lib/tk/font.rb, line 802
    def create_latinfont_tk8x(font)
      @latinfont = @id + 'l'

      if JAPANIZED_TK
        if font.kind_of? Hash
          if font[:charset] || 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

        if font && @compoundfont
          keys = {}
          actual_core(@latinfont).each{|key,val| keys[key] = val}
          tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
        end
      end
    end

Also aliased as: create_latinfont, create_latinfont
init_dummy_fontobj() click to toggle source

    # File lib/tk/font.rb, line 542
    def init_dummy_fontobj
      Tk_FontID.mutex.synchronize{
        @id = Tk_FontID.join(TkCore::INTERP._ip_id_)
        Tk_FontID[1].succ!
      }
      Tk_FontNameTBL.mutex.synchronize{
        Tk_FontNameTBL[@id] = self
      }

      # @latin_desscendant = nil
      # @kanji_desscendant = nil
      @descendant = [nil, nil] # [latin, kanji]

      case (Tk::TK_VERSION)
      when /^4\..*/
        @latinfont = ""
        @kanjifont = ""
        if JAPANIZED_TK
          @compoundfont = [[@latinfont], [@kanjifont]]
          @fontslot = {'font'=>@latinfont, 'kanjifont'=>@kanjifont}
        else
          @compoundfont = @latinfont
          @fontslot = {'font'=>@latinfont}
        end
      else
        @latinfont = @id + 'l'
        @kanjifont = @id + 'k'
        @compoundfont = @id + 'c'

        if JAPANIZED_TK
          tk_call('font', 'create', @latinfont, '-charset', 'iso8859')
          tk_call('font', 'create', @kanjifont, '-charset', 'jisx0208.1983')
          tk_call('font', 'create', @compoundfont,
                  '-compound', [@latinfont, @kanjifont])
        else
          tk_call('font', 'create', @latinfont)
          tk_call('font', 'create', @kanjifont)
          tk_call('font', 'create', @compoundfont)
        end

        @fontslot = {'font'=>@compoundfont}
      end

      self
    end

initialize_copy(font) click to toggle source

    # File lib/tk/font.rb, line 654
    def initialize_copy(font)
      unless font.kind_of?(TkFont)
        fail TypeError, '"initialize_copy should take same class object'
      end
      if TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
        keys = {}
        font.configinfo.each{|key,value| keys[key] = value }
        initialize(font.latin_font_id, font.kanji_font_id, keys)
      else # ! TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
        initialize(font.latin_font_id, font.kanji_font_id, font.configinfo)
      end
    end