Module: TkTreatFont

Included in:
TkConfigMethod
Defined in:
lib/tk.rb

Instance Method Summary collapse

Instance Method Details

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



3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
# File 'lib/tk.rb', line 3303

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{|k|
      k = k.to_s
      pathname = [win, tag, k].join(';')
      fonts[k] =
        TkFont.used_on(pathname) ||
        TkFont.init_widget_font(pathname, *__confinfo_cmd)
    }
    fonts
  end
end

#font_configure(slot) ⇒ Object



3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
# File 'lib/tk.rb', line 3333

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)
            unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
              tk_call(*(__config_cmd << "-#{optkey}" << fnt))
            else
              begin
                tk_call(*(__config_cmd << "-#{optkey}" << fnt))
              rescue
                # ignore
              end
            end
          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



3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
# File 'lib/tk.rb', line 3525

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



3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
# File 'lib/tk.rb', line 3466

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)
      unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
        tk_call(*(__config_cmd << "-#{optkey}" << knj))
      else
        begin
          tk_call(*(__config_cmd << "-#{optkey}" << knj))
        rescue
          # ignore
        end
      end
      next
    end

    if fobj.kind_of?(TkFont)
      if knj.kind_of?(TkFont)
        conf = {}
        knj.kanji_configinfo.each{|k,val| conf[k] = 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



3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
# File 'lib/tk.rb', line 3573

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



3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
# File 'lib/tk.rb', line 3406

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)
      unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
        tk_call(*(__config_cmd << "-#{optkey}" << ltn))
      else
        begin
          tk_call(*(__config_cmd << "-#{optkey}" << ltn))
        rescue
          # ignore
        end
      end
      next
    end

    if fobj.kind_of?(TkFont)
      if ltn.kind_of?(TkFont)
        conf = {}
        ltn.latin_configinfo.each{|k,val| conf[k] = 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



3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
# File 'lib/tk.rb', line 3548

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