# module TkFont::CoreMethods

### Private Instance Methods

actual_core(font, win=nil, option=nil)
Alias for: actual_core_tk4x
actual_core_tk4x(font, win=nil, option=nil) click to toggle source

    # File lib/tk/font.rb, line 1649
    def actual_core_tk4x(font, win=nil, option=nil)
      # dummy
      if option == 'pointadjust' || option == :pointadjust
          1.0
      elsif option
        case TkFont::OptionType[option.to_s]
        when ?n
          0
        when ?b
          false
        else
          ''
        end
      else
        [['family',''], ['size',0], ['weight',''], ['slant',''],
          ['underline',false], ['overstrike',false], ['charset',''],
          ['pointadjust',0]]
      end
    end

Also aliased as: actual_core
actual_core_tk8x(font, win=nil, option=nil) click to toggle source

    # File lib/tk/font.rb, line 1669
    def actual_core_tk8x(font, win=nil, option=nil)
      font = '{}' if font == ''

      if option == 'compound' || option == :compound
        ""
      elsif option
        if win
          val = tk_call('font', 'actual', font,
                        "-displayof", win, "-#{option}")
        else
          val = tk_call('font', 'actual', font, "-#{option}")
        end
        case TkFont::OptionType[option.to_s]
        when ?n
          num_or_str(val)
        when ?b
          bool(val)
        else
          val
        end
      else
        l = tk_split_simplelist(if win
                                   tk_call('font', 'actual', font,
                                                       "-displayof", win)
                                else
                                   tk_call('font', 'actual', font)
                                end)
        r = []
        while key=l.shift
          if key == '-compound'
            l.shift
          else
            key = key[1..-1]
            val = l.shift
            case TkFont::OptionType[key]
            when ?n
              r.push [key, num_or_str(val)]
            when ?b
              r.push [key, bool(val)]
            else
              r.push [key, val]
            end
          end
        end
        r
      end
    end

Also aliased as: actual_core, actual_core
configinfo_core(font, option=nil)
Alias for: configinfo_core_tk4x
configinfo_core_tk4x(font, option=nil) click to toggle source

    # File lib/tk/font.rb, line 1722
    def configinfo_core_tk4x(font, option=nil)
      # dummy
      if TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
        if option == 'pointadjust' || option == :pointadjust
          1.0
        elsif option
          case TkFont::OptionType[option.to_s]
          when ?n
            0
          when ?b
            false
          else
            ''
          end
        else
          [['family',''], ['size',0], ['weight',''], ['slant',''],
            ['underline',false], ['overstrike',false], ['charset',''],
            ['pointadjust',1.0]]
        end
      else # ! TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
        current_configinfo_core_tk4x(font, option)
      end
    end

Also aliased as: configinfo_core
configinfo_core_tk8x(font, option=nil) click to toggle source

    # File lib/tk/font.rb, line 1830
    def configinfo_core_tk8x(font, option=nil)
      if TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
        if option == 'compound' || option == :compound
          ""
        elsif option
          val = tk_call('font', 'configure', font, "-#{option}")
          case TkFont::OptionType[option.to_s]
          when ?n
            num_or_str(val)
          when ?b
            bool(val)
          else
            val
          end
        else
          l = tk_split_simplelist(tk_call('font', 'configure', font))
          r = []
          while key=l.shift
            if key == '-compound'
              l.shift
            else
              key = key[1..-1]
              val = l.shift
              case TkFont::OptionType[key]
              when ?n
                r.push [key, num_or_str(val)]
              when ?b
                r.push [key, bool(val)]
              else
                r.push [key, val]
              end
            end
          end
          r
        end
      else # ! TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
        current_configinfo_core_tk8x(font, option)
      end
    end

Also aliased as: configinfo_core, configinfo_core
configure_core(font, slot, value=None)
Alias for: configure_core_tk4x
configure_core_tk4x(font, slot, value=None) click to toggle source

    # File lib/tk/font.rb, line 1717
    def configure_core_tk4x(font, slot, value=None)
      #""
      self
    end

Also aliased as: configure_core
configure_core_tk8x(font, slot, value=None) click to toggle source

    # File lib/tk/font.rb, line 1763
    def configure_core_tk8x(font, slot, value=None)
      if JAPANIZED_TK
        begin
          padjust = tk_call('font', 'configure', font, '-pointadjust')
        rescue
          padjust = nil
        end
      else
        padjust = nil
      end
      if slot.kind_of? Hash
        if JAPANIZED_TK && (slot.key?('family') || slot.key?(:family))
          slot = _symbolkey2str(slot)
          configure_core_tk8x(font, 'family', slot.delete('family'))
        end

        if ((slot.key?('size') || slot.key?(:size)) &&
            padjust && !slot.key?('pointadjust') && !slot.key?(:pointadjust))
          tk_call('font', 'configure', font,
                  '-pointadjust', padjust, *hash_kv(slot))
        else
          tk_call('font', 'configure', font, *hash_kv(slot))
        end
      elsif (slot == 'size' || slot == :size) && padjust != nil
        tk_call('font', 'configure', font,
                "-#{slot}", value, '-pointadjust', padjust)
      elsif JAPANIZED_TK && (slot == 'family' || slot == :family)
        # compound font?
        begin
          compound = tk_split_simplelist(tk_call('font', 'configure',
                                                 font, '-compound'))
        rescue
          tk_call('font', 'configure', font, '-family', value)
          return self
        end
        if compound == []
          tk_call('font', 'configure', font, '-family', value)
          return self
        end
        ltn, knj = compound

        lfnt = tk_call('font', 'create', '-copy', ltn)
        begin
          tk_call('font', 'configure', lfnt, '-family', value)
          latin_replace_core_tk8x(lfnt)
        rescue RuntimeError => e
          fail e if $DEBUG
        ensure
          tk_call('font', 'delete', lfnt) if lfnt != ''
        end

        kfnt = tk_call('font', 'create', '-copy', knj)
        begin
          tk_call('font', 'configure', kfnt, '-family', value)
          kanji_replace_core_tk8x(lfnt)
        rescue RuntimeError => e
          fail e if $DEBUG
        ensure
          tk_call('font', 'delete', kfnt) if kfnt != ''
        end

      else
        tk_call('font', 'configure', font, "-#{slot}", value)
      end
      self
    end

Also aliased as: configure_core, configure_core
current_configinfo_core(font, option=nil)
Alias for: current_configinfo_core_tk4x
current_configinfo_core_tk4x(font, option=nil) click to toggle source

    # File lib/tk/font.rb, line 1746
    def current_configinfo_core_tk4x(font, option=nil)
      if option
        case TkFont::OptionType[option.to_s]
        when ?n
          0
        when ?b
          false
        else
          ''
        end
      else
        {'family'=>'', 'size'=>0, 'weight'=>'', 'slant'=>'',
          'underline'=>false, 'overstrike'=>false,
          'charset'=>false, 'pointadjust'=>1.0}
      end
    end

Also aliased as: current_configinfo_core
current_configinfo_core_tk8x(font, option=nil) click to toggle source

    # File lib/tk/font.rb, line 1870
    def current_configinfo_core_tk8x(font, option=nil)
      if option == 'compound'
        ""
      elsif option
        val = tk_call('font', 'configure', font, "-#{option}")
        case TkFont::OptionType[option.to_s]
        when ?n
          num_or_str(val)
        when ?b
          bool(val)
        else
          val
        end
      else
        l = tk_split_simplelist(tk_call('font', 'configure', font))
        h = {}
        while key=l.shift
          if key == '-compound'
            l.shift
          else
            key = key[1..-1]
            val = l.shift
            case TkFont::OptionType[key]
            when ?n
              h[key] = num_or_str(val)
            when ?b
              h[key] = bool(val)
            else
              h[key] = val
            end
          end
        end
        h
      end
    end

Also aliased as: current_configinfo_core, current_configinfo_core
delete_core()
Alias for: delete_core_tk4x
delete_core_tk4x() click to toggle source

    # File lib/tk/font.rb, line 1906
    def delete_core_tk4x
      TkFont::Tk_FontNameTBL.mutex.synchronize{
        TkFont::Tk_FontNameTBL.delete(@id)
      }
      TkFont::Tk_FontUseTBL.mutex.synchronize{
        TkFont::Tk_FontUseTBL.delete_if{|key,value| value == self}
      }
    end

Also aliased as: delete_core
delete_core_tk8x() click to toggle source

    # File lib/tk/font.rb, line 1915
    def delete_core_tk8x
      begin
        tk_call('font', 'delete', @latinfont) if @latinfont
      rescue
      end
      begin
        tk_call('font', 'delete', @kanjifont) if @kanjifont
      rescue
      end
      begin
        tk_call('font', 'delete', @compoundfont) if @compoundfont
      rescue
      end
      TkFont::Tk_FontNameTBL.mutex.synchronize{
        TkFont::Tk_FontNameTBL.delete(@id)
      }
      TkFont::Tk_FontUseTBL.mutex.synchronize{
        TkFont::Tk_FontUseTBL.delete_if{|key,value| value == self}
      }
    end

Also aliased as: delete_core, delete_core
kanji_replace_core(knj)
Alias for: kanji_replace_core_tk4x
kanji_replace_core_tk4x(knj) click to toggle source

    # File lib/tk/font.rb, line 1978
      def kanji_replace_core_tk4x(knj)
        return self unless JAPANIZED_TK

        create_kanjifont_tk4x(knj)
        @compoundfont[1] = [@kanjifont]
        @fontslot['kanjifont'] = @kanjifont
        table = nil
        TkFont::Tk_FontUseTBL.mutex.synchronize{
          table = TkFont::Tk_FontUseTBL.clone
        }
        table.dup.each{|w, fobj|
          if self == fobj
            begin
              if w.include?(';')
                win, tag, optkey = w.split(';')
                optkey = 'kanjifont' unless optkey
                winobj = tk_tcl2ruby(win)
    #           winobj.tagfont_configure(tag, {'kanjifont'=>@kanjifont})
                #if winobj.kind_of? TkText
                if winobj.kind_of?(TkText) || winobj.kind_of?(Tk::Text)
                  tk_call(win, 'tag', 'configure', tag, "-#{optkey}", @kanjifont)
                #elsif winobj.kind_of? TkCanvas
                elsif winobj.kind_of?(TkCanvas) || winobj.kind_of?(Tk::Canvas)
                  tk_call(win, 'itemconfigure', tag, "-#{optkey}", @kanjifont)
                #elsif winobj.kind_of? TkMenu
                elsif winobj.kind_of?(TkMenu) || winobj.kind_of?(Tk::Menu)
                  tk_call(win, 'entryconfigure', tag, "-#{optkey}", @latinfont)
                else
                  raise RuntimeError, "unknown widget type"
                end
              else
    #           tk_tcl2ruby(w).font_configure('kanjifont'=>@kanjifont)
                tk_call(w, 'configure', '-kanjifont', @kanjifont)
              end
            rescue
              Tk_FontUseTBL.mutex.synchronize{
                TkFont::Tk_FontUseTBL.delete(w)
              }
            end
          end
        }
        self
      end

Also aliased as: kanji_replace_core
kanji_replace_core_tk8x(knj) click to toggle source

    # File lib/tk/font.rb, line 2090
    def kanji_replace_core_tk8x(knj)
      knj = '{}' if knj == ''

      if JAPANIZED_TK
        begin
          tk_call('font', 'delete', '@font_tmp')
        rescue
        end
        begin
          fnt_bup = tk_call('font', 'create', '@font_tmp', '-copy', @kanjifont)
        rescue
          #fnt_bup = ''
          fnt_bup = TkFont::DEFAULT_KANJI_FONT_NAME
        end
      end

      begin
        tk_call('font', 'delete', @kanjifont)
      rescue
      end
      create_kanjifont(knj)

      if JAPANIZED_TK
        keys = self.configinfo
        tk_call('font', 'delete', @compoundfont)
        begin
          tk_call('font', 'create', @compoundfont,
                  '-compound', [@latinfont, @kanjifont], *hash_kv(keys))
        rescue RuntimeError => e
          tk_call('font', 'delete', @kanjifont)
          if fnt_bup && fnt_bup != ''
            tk_call('font', 'create', @kanjifont, '-copy', fnt_bup)
            tk_call('font', 'create', @compoundfont,
                    '-compound', [@latinfont, @kanjifont], *hash_kv(keys))
            tk_call('font', 'delete', fnt_bup)
          else
            fail e
          end
        end
      end
      self
    end

Also aliased as: kanji_replace_core, kanji_replace_core
latin_replace_core(ltn)
Alias for: latin_replace_core_tk4x
latin_replace_core_tk4x(ltn) click to toggle source

    # File lib/tk/font.rb, line 1936
      def latin_replace_core_tk4x(ltn)
        create_latinfont_tk4x(ltn)
        @compoundfont[0] = [@latinfont] if JAPANIZED_TK
        @fontslot['font'] = @latinfont
        table = nil
        TkFont::Tk_FontUseTBL.mutex.synchronize{
          table = TkFont::Tk_FontUseTBL.clone
        }
        table.each{|w, fobj|
          if self == fobj
            begin
              if w.include?(';')
                win, tag, optkey = w.split(';')
                optkey = 'font' if optkey == nil || optkey == ''
                winobj = tk_tcl2ruby(win)
    #           winobj.tagfont_configure(tag, {'font'=>@latinfont})
                #if winobj.kind_of? TkText
                if winobj.kind_of?(TkText) || winobj.kind_of?(Tk::Text)
                  tk_call(win, 'tag', 'configure', tag, "-#{optkey}", @latinfont)
                #elsif winobj.kind_of? TkCanvas
                elsif winobj.kind_of?(TkCanvas) || winobj.kind_of?(Tk::Canvas)
                  tk_call(win, 'itemconfigure', tag, "-#{optkey}", @latinfont)
                #elsif winobj.kind_of? TkMenu
                elsif winobj.kind_of?(TkMenu) || winobj.kind_of?(Tk::Menu)
                  tk_call(win, 'entryconfigure', tag, "-#{optkey}", @latinfont)
                else
                  raise RuntimeError, "unknown widget type"
                end
              else
    #           tk_tcl2ruby(w).font_configure('font'=>@latinfont)
                tk_call(w, 'configure', '-font', @latinfont)
              end
            rescue
              TkFont::Tk_FontUseTBL.mutex.synchronize{
                TkFont::Tk_FontUseTBL.delete(w)
              }
            end
          end
        }
        self
      end

Also aliased as: latin_replace_core
latin_replace_core_tk8x(ltn) click to toggle source

    # File lib/tk/font.rb, line 2022
      def latin_replace_core_tk8x(ltn)
        ltn = '{}' if ltn == ''

        if JAPANIZED_TK
          begin
            tk_call('font', 'delete', '@font_tmp')
          rescue
          end
          begin
            fnt_bup = tk_call('font', 'create', '@font_tmp', '-copy', @latinfont)
          rescue
            #fnt_bup = ''
            fnt_bup = TkFont::DEFAULT_LATIN_FONT_NAME
          end
        end

        begin
          tk_call('font', 'delete', @latinfont)
        rescue
        end
        create_latinfont(ltn)

        if JAPANIZED_TK
          keys = self.configinfo
          tk_call('font', 'delete', @compoundfont)
          begin
            tk_call('font', 'create', @compoundfont,
                    '-compound', [@latinfont, @kanjifont], *hash_kv(keys))
            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
          rescue RuntimeError => e
            tk_call('font', 'delete', @latinfont)
            if fnt_bup && fnt_bup != ''
              tk_call('font', 'create', @latinfont, '-copy', fnt_bup)
              tk_call('font', 'create', @compoundfont,
                      '-compound', [@latinfont, @kanjifont], *hash_kv(keys))
              tk_call('font', 'delete', fnt_bup)
            else
              fail e
            end
          end

        else
          latinkeys = {}
          begin
            actual_core(@latinfont).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: latin_replace_core, latin_replace_core
measure_core(font, win, text)
Alias for: measure_core_tk4x
measure_core_tk4x(font, win, text) click to toggle source

    # File lib/tk/font.rb, line 2133
    def measure_core_tk4x(font, win, text)
      0
    end

Also aliased as: measure_core
measure_core_tk8x(font, win, text) click to toggle source

    # File lib/tk/font.rb, line 2137
    def measure_core_tk8x(font, win, text)
      font = '{}' if font == ''

      if win
        number(tk_call('font', 'measure', font,
                       '-displayof', win, text))
      else
        number(tk_call('font', 'measure', font, text))
      end
    end

Also aliased as: measure_core, measure_core
metrics_core(font, win, option=nil)
Alias for: metrics_core_tk4x
metrics_core_tk4x(font, win, option=nil) click to toggle source

    # File lib/tk/font.rb, line 2148
    def metrics_core_tk4x(font, win, option=nil)
      # dummy
      if option
        ""
      else
        [['ascent',[]], ['descent',[]], ['linespace',[]], ['fixed',[]]]
      end
    end

Also aliased as: metrics_core
metrics_core_tk8x(font, win, option=nil) click to toggle source

    # File lib/tk/font.rb, line 2157
      def metrics_core_tk8x(font, win, option=nil)
        font = '{}' if font == ''

        if option
          if win
            number(tk_call('font', 'metrics', font,
                           "-displayof", win, "-#{option}"))
          else
            number(tk_call('font', 'metrics', font, "-#{option}"))
          end
        else
          l = tk_split_list(if win
                              tk_call('font','metrics',font,"-displayof",win)
                            else
                              tk_call('font','metrics',font)
                            end)
          r = []
          while key=l.shift
            r.push [key[1..-1], l.shift.to_i]
            if key == '-fixed'  # boolean value
              r.push [key[1..-1], bool(l.shift)]
            else
              r.push [key[1..-1], l.shift.to_i]
            end
          end
          r
        end
      end

Also aliased as: metrics_core, metrics_core