Module: TkTreatFont

Defined in:
lib/tk.rb

Instance Method Summary collapse

Instance Method Details

#font_configinfo(key = nil) ⇒ Object Also known as: fontobj



2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
# File 'lib/tk.rb', line 2543

def font_configinfo(key = nil)
  optkeys = __font_optkeys
  if key && !optkeys.find{|opt| opt.to_s == key.to_s}
    fail ArgumentError, "unknown font option name `#{key}'"
  end

  win, tag = __pathname.split(':')

  if key
    pathname = [win, tag, key].join(';')
    TkFont.used_on(pathname) || 
      TkFont.init_widget_font(pathname, *__confinfo_cmd)
  elsif optkeys.size == 1
    pathname = [win, tag, optkeys[0]].join(';')
    TkFont.used_on(pathname) || 
      TkFont.init_widget_font(pathname, *__confinfo_cmd)
  else
    fonts = {}
    optkeys.each{|key|
      key = key.to_s
      pathname = [win, tag, key].join(';')
      fonts[key] = 
        TkFont.used_on(pathname) || 
        TkFont.init_widget_font(pathname, *__confinfo_cmd)
    }
    fonts
  end
end

#font_configure(slot) ⇒ Object



2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
# File 'lib/tk.rb', line 2573

def font_configure(slot)
  pathname = __pathname

  slot = _symbolkey2str(slot)

  __font_optkeys.each{|optkey|
    optkey = optkey.to_s
    l_optkey = 'latin' << optkey
    a_optkey = 'ascii' << optkey
    k_optkey = 'kanji' << optkey

    if slot.key?(optkey)
      fnt = slot.delete(optkey)
      if fnt.kind_of?(TkFont)
        slot.delete(l_optkey)
        slot.delete(a_optkey)
        slot.delete(k_optkey)

        fnt.call_font_configure([pathname, optkey], *(__config_cmd << {}))
        next
      else
        if fnt
          if (slot.key?(l_optkey) || 
              slot.key?(a_optkey) || 
              slot.key?(k_optkey))
            fnt = TkFont.new(fnt)

            lfnt = slot.delete(l_optkey)
            lfnt = slot.delete(a_optkey) if slot.key?(a_optkey)
            kfnt = slot.delete(k_optkey)

            fnt.latin_replace(lfnt) if lfnt
            fnt.kanji_replace(kfnt) if kfnt

            fnt.call_font_configure([pathname, optkey], 
                                    *(__config_cmd << {}))
            next
          else
            fnt = hash_kv(fnt) if fnt.kind_of?(Hash)
            tk_call(*(__config_cmd << "-#{optkey}" << fnt))
          end
        end
        next
      end
    end

    lfnt = slot.delete(l_optkey)
    lfnt = slot.delete(a_optkey) if slot.key?(a_optkey)
    kfnt = slot.delete(k_optkey)

    if lfnt && kfnt
      TkFont.new(lfnt, kfnt).call_font_configure([pathname, optkey], 
                                                 *(__config_cmd << {}))
    elsif lfnt
      latinfont_configure([lfnt, optkey])
    elsif kfnt
      kanjifont_configure([kfnt, optkey])
    end
  }

  # configure other (without font) options
  tk_call(*(__config_cmd.concat(hash_kv(slot)))) if slot != {}
  self
end

#font_copy(win, wintag = nil, winkey = nil, targetkey = nil) ⇒ Object



2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
# File 'lib/tk.rb', line 2741

def font_copy(win, wintag=nil, winkey=nil, targetkey=nil)
  if wintag
    if winkey
      fnt = win.tagfontobj(wintag, winkey).dup
    else
      fnt = win.tagfontobj(wintag).dup
    end
  else
    if winkey
      fnt = win.fontobj(winkey).dup
    else
      fnt = win.fontobj.dup
    end
  end

  if targetkey
    fnt.call_font_configure([__pathname, targetkey], *(__config_cmd << {}))
  else
    fnt.call_font_configure(__pathname, *(__config_cmd << {}))
  end
  self
end

#kanjifont_configure(knj, keys = nil) ⇒ Object



2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
# File 'lib/tk.rb', line 2690

def kanjifont_configure(knj, keys=nil)
  if knj.kind_of?(Array)
    key = knj[1]
    knj = knj[0]
  else
    key = nil
  end

  optkeys = __font_optkeys
  if key && !optkeys.find{|opt| opt.to_s == key.to_s}
    fail ArgumentError, "unknown font option name `#{key}'"
  end

  win, tag = __pathname.split(':')

  optkeys = [key] if key

  optkeys.each{|optkey|
    optkey = optkey.to_s

    pathname = [win, tag, optkey].join(';')

    if (fobj = TkFont.used_on(pathname))
      fobj = TkFont.new(fobj) # create a new TkFont object
    elsif Tk::JAPANIZED_TK
      fobj = fontobj          # create a new TkFont object
    else
      knj = hash_kv(knj) if knj.kind_of?(Hash)
      tk_call(*(__config_cmd << "-#{optkey}" << knj))
      next
    end

    if fobj.kind_of?(TkFont)
      if knj.kind_of?(TkFont)
        conf = {}
        knj.kanji_configinfo.each{|key,val| conf[key] = val}
        if keys
          fobj.kanji_configure(conf.update(keys))
        else
          fobj.kanji_configure(conf)
        end
      else
        fobj.kanji_replace(knj)
      end
    end

    fobj.call_font_configure([pathname, optkey], *(__config_cmd << {}))
  }
  self
end

#kanjifont_copy(win, wintag = nil, winkey = nil, targetkey = nil) ⇒ Object



2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
# File 'lib/tk.rb', line 2789

def kanjifont_copy(win, wintag=nil, winkey=nil, targetkey=nil)
  if targetkey
    fontobj(targetkey).dup.call_font_configure([__pathname, targetkey], 
                                               *(__config_cmd << {}))
  else
      fontobj.dup.call_font_configure(__pathname, *(__config_cmd << {}))
  end

  if wintag
    if winkey
      fontobj.kanji_replace(win.tagfontobj(wintag, winkey).kanji_font_id)
    else
      fontobj.kanji_replace(win.tagfontobj(wintag).kanji_font_id)
    end
  else
    if winkey
      fontobj.kanji_replace(win.fontobj(winkey).kanji_font_id)
    else
      fontobj.kanji_replace(win.fontobj.kanji_font_id)
    end
  end
  self
end

#latinfont_configure(ltn, keys = nil) ⇒ Object Also known as: asciifont_configure



2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
# File 'lib/tk.rb', line 2638

def latinfont_configure(ltn, keys=nil)
  if ltn.kind_of?(Array)
    key = ltn[1]
    ltn = ltn[0]
  else
    key = nil
  end

  optkeys = __font_optkeys
  if key && !optkeys.find{|opt| opt.to_s == key.to_s}
    fail ArgumentError, "unknown font option name `#{key}'"
  end

  win, tag = __pathname.split(':')

  optkeys = [key] if key

  optkeys.each{|optkey|
    optkey = optkey.to_s

    pathname = [win, tag, optkey].join(';')

    if (fobj = TkFont.used_on(pathname))
      fobj = TkFont.new(fobj) # create a new TkFont object
    elsif Tk::JAPANIZED_TK
      fobj = fontobj          # create a new TkFont object
    else
      ltn = hash_kv(ltn) if ltn.kind_of?(Hash)
      tk_call(*(__config_cmd << "-#{optkey}" << ltn))
      next
    end

    if fobj.kind_of?(TkFont)
      if ltn.kind_of?(TkFont)
        conf = {}
        ltn.latin_configinfo.each{|key,val| conf[key] = val}
        if keys
          fobj.latin_configure(conf.update(keys))
        else
          fobj.latin_configure(conf)
        end
      else
        fobj.latin_replace(ltn)
      end
    end

    fobj.call_font_configure([pathname, optkey], *(__config_cmd << {}))
  }
  self
end

#latinfont_copy(win, wintag = nil, winkey = nil, targetkey = nil) ⇒ Object Also known as: asciifont_copy



2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
# File 'lib/tk.rb', line 2764

def latinfont_copy(win, wintag=nil, winkey=nil, targetkey=nil)
  if targetkey
    fontobj(targetkey).dup.call_font_configure([__pathname, targetkey], 
                                               *(__config_cmd << {}))
  else
    fontobj.dup.call_font_configure(__pathname, *(__config_cmd << {}))
  end

  if wintag
    if winkey
      fontobj.latin_replace(win.tagfontobj(wintag, winkey).latin_font_id)
    else
      fontobj.latin_replace(win.tagfontobj(wintag).latin_font_id)
    end
  else
    if winkey
      fontobj.latin_replace(win.fontobj(winkey).latin_font_id)
    else
      fontobj.latin_replace(win.fontobj.latin_font_id)
    end
  end
  self
end