Module: TkTreatFont

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

Instance Method Summary collapse

Instance Method Details

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



3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
# File 'ext/lib/tk.rb', line 3264

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



3294
3295
3296
3297
3298
3299
3300
3301
3302
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
3331
3332
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
# File 'ext/lib/tk.rb', line 3294

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



3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
# File 'ext/lib/tk.rb', line 3486

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



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
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
# File 'ext/lib/tk.rb', line 3427

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 => e
          # ignore
        end
      end
      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



3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
# File 'ext/lib/tk.rb', line 3534

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



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
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
# File 'ext/lib/tk.rb', line 3367

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 => e
          # ignore
        end
      end
      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



3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
# File 'ext/lib/tk.rb', line 3509

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