Class: TkFont

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

### Methods

[] []= actual actual actual_displayof actual_displayof ascii_actual ascii_actual_displayof ascii_configinfo ascii_configure ascii_font ascii_metrics ascii_replace asciifont call_font_configure clone configinfo configinfo configure configure create_asciifont create_compoundfont create_compoundfont create_compoundfont create_copy create_kanjifont create_kanjifont create_kanjifont create_latinfont create_latinfont create_latinfont current_configinfo current_configinfo delete dup failsafe families font font_id get_obj id init_widget_font inspect kanji_actual kanji_actual_displayof kanji_configinfo kanji_configure kanji_font kanji_font_id kanji_metrics kanji_metrics_displayof kanji_replace kanjifont latin_actual latin_actual_displayof latin_configinfo latin_configure latin_font latin_font_id latin_metrics latin_metrics_displayof latin_replace latinfont measure measure measure_displayof measure_displayof method_missing metrics metrics metrics_displayof metrics_displayof names new replace reset_pointadjust to_eval used used_on

### Included Modules

Tk TkFont::CoreMethods

### Classes and Modules

Module TkFont::CoreMethods
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
OptionType | = | Hash.new(?s) |  | option_type : default => string
MetricType | = | Hash.new(?n) |  | metric_type : default => num_or_str
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

actual(fnt, option=nil)

class methods

[Source]

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

[Source]

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

configinfo(fnt, slot=nil)

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

families(win=nil)

[Source]

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

[Source]

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

init_widget_font(pathname, *args)

[Source]

    # File tk/lib/tk/font.rb, line 295
      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
            # 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 == []
              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

measure(fnt, text)

[Source]

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

[Source]

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

[Source]

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

[Source]

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

names()

[Source]

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

new(ltn=nil, knj=nil, keys=nil)

[Source]

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

        # @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

used_on(path=nil)

[Source]

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

### Public Instance methods

[](slot)

[Source]

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

[]=(slot, val)

[Source]

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

actual(option=nil)

[Source]

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

actual_displayof(win, option=nil)

[Source]

    # File tk/lib/tk/font.rb, line 978
      def actual_displayof(win, option=nil)
        win = '.' unless win
        actual_core(@compoundfont, 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()

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)

[Source]

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

clone()

[Source]

    # File tk/lib/tk/font.rb, line 1202
      def clone
        TkFont.new(self)
      end

configinfo(slot=nil)

[Source]

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

configure(slot, value=None)

[Source]

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

create_compoundfont(ltn, knj, keys)

Alias for create_compoundfont_tk4x

create_compoundfont(ltn, knj, keys)

Alias for create_compoundfont_tk8x

create_kanjifont(font)

Alias for create_kanjifont_tk8x

create_kanjifont(font)

Alias for create_kanjifont_tk4x

create_kanjifont(font)

Alias for create_kanjifont_tk8x

create_latinfont(font)

Alias for create_latinfont_tk8x

create_latinfont(font)

Alias for create_latinfont_tk8x

create_latinfont(font)

Alias for create_latinfont_tk4x

current_configinfo(slot=nil)

[Source]

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

delete()

[Source]

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

dup()

[Source]

    # File tk/lib/tk/font.rb, line 1199
      def dup
        TkFont.new(self)
      end

font()

[Source]

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

font_id()

Alias for font

id()

[Source]

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

inspect()

[Source]

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

kanji_actual(option=nil)

[Source]

    # File tk/lib/tk/font.rb, line 992
      def kanji_actual(option=nil)
        #if JAPANIZED_TK
        if @kanjifont != ""
          actual_core(@kanjifont, nil, option)
        else
          actual_core_tk4x(nil, nil, option)
        end
      end

kanji_actual_displayof(win, option=nil)

[Source]

    # File tk/lib/tk/font.rb, line 1001
      def kanji_actual_displayof(win, option=nil)
        #if JAPANIZED_TK
        if @kanjifont != ""
          win = '.' unless win
          actual_core(@kanjifont, win, option)
        else
          actual_core_tk4x(nil, win, option)
        end
      end

kanji_configinfo(slot=nil)

[Source]

    # File tk/lib/tk/font.rb, line 1066
      def kanji_configinfo(slot=nil)
        #if JAPANIZED_TK
        if @kanjifont != ""
          configinfo_core(@kanjifont, slot)
        else
          #[]
          configinfo(slot)
        end
      end

kanji_configure(slot, value=None)

[Source]

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

kanji_font()

[Source]

    # File tk/lib/tk/font.rb, line 964
      def kanji_font
        # @kanjifont
        if @kanji_descendant
          @kanji_descendant
        else
          @kanji_descendant = DescendantFont.new(self, 'kanji')
        end
      end

kanji_font_id()

[Source]

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

kanji_metrics(option=nil)

[Source]

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

kanji_metrics_displayof(win, option=nil)

[Source]

    # File tk/lib/tk/font.rb, line 1130
      def kanji_metrics_displayof(win, option=nil)
        if JAPANIZED_TK
          win = '.' unless win
          metrics_core(@kanjifont, win, option)
        else
          metrics_core_tk4x(nil, win, option)
        end
      end

kanji_replace(knj)

[Source]

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

kanjifont()

Alias for kanji_font

latin_actual(option=nil)

[Source]

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

latin_actual_displayof(win, option=nil)

[Source]

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

latin_configinfo(slot=nil)

[Source]

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

latin_configure(slot, value=None)

[Source]

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

latin_font()

[Source]

    # File tk/lib/tk/font.rb, line 950
      def latin_font
        # @latinfont
        if @latin_descendant
          @latin_descendant
        else
          @latin_descendant = DescendantFont.new(self, 'latin')
        end
      end

latin_font_id()

[Source]

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

latin_metrics(option=nil)

[Source]

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

latin_metrics_displayof(win, option=nil)

[Source]

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

latin_replace(ltn)

[Source]

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

latinfont()

Alias for latin_font

measure(text)

[Source]

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

measure_displayof(win, text)

[Source]

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

method_missing(id, *args)

[Source]

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

metrics(option=nil)

[Source]

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

metrics_displayof(win, option=nil)

[Source]

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

replace(ltn, knj=None)

[Source]

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

reset_pointadjust()

[Source]

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

[Source]

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

used()

[Source]

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