Class: BDFFont

Inherits:
Object
  • Object
show all
Defined in:
bdffont.rb

Overview

Note:

iso8859 と jisx0208 のみに対応

BDFフォント描画用クラス

Examples:

require 'dxruby'
require_relative 'bdffont'
bdf = BDFFont.new("mplus_f12r_iso8859.bdf")
Window.loop do
  x, y = 10, 10
  Window.draw_bdffont(x, y, "This is a BDF font", bdf)
  y += bdf.height
  Window.draw_bdffont(x, y, "The quick brown fox jumps over the lazy dog.", bdf)
  y += bdf.height
  Window.draw_bdffont(x, y, "1234567890 ! = - +", bdf)
end

Version:

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (BDFFont) initialize(bdffilename, col = [255, 255, 255, 255])

コンストラクタ

Parameters:

  • bdffilename (String)

    BDFフォントファイル名

  • col (Array) (defaults to: [255, 255, 255, 255])

    文字色。a,r,g,b を並べた配列で指定



255
256
257
258
259
260
261
# File 'bdffont.rb', line 255

def initialize(bdffilename, col = [255, 255, 255, 255])
  @bdffiles = []
  bdfdt = BDFdata.new(bdffilename, col)
  @bdffiles.push(bdfdt)
  @width = bdfdt.width
  @height = bdfdt.height
end

Instance Attribute Details

- (Integer) height (readonly)

Returns バウンディングボックスの縦幅(最大値)

Returns:

  • (Integer)

    バウンディングボックスの縦幅(最大値)



248
249
250
# File 'bdffont.rb', line 248

def height
  @height
end

Instance Method Details

- (Object?) [](index)

配列として指定した際に、BDFフォント1文字分用のクラスを返す

Parameters:

  • index (Integer)

    配列添字

Returns:

  • (Object)

    BDFフォント1文字分のクラス

  • (nil)

    nilなら登録文字は見つからなかった



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'bdffont.rb', line 284

def [](index)
  @bdffiles.each do |d|
    code = index
    case d.charset
    when :jisx0208
      code = self.sjis2jisx0208(code.ord)
    when :iso10646
      # BSJISiso10646ւ̕ϊ@Ȃc
      code = NKF.nkf('-w -S --cp932', code).ord
    else
      code = code.ord
    end
    if d.bdf_dic.has_key?(code)
      return d.bdf_dic[code]
    end
  end
  return nil
end

- (Object) add(bdffilename, col = [255, 255, 255, 255])

BDFファイルを追加。

漢字BDFフォント(jisx0208)でクラスを生成した後、 英数字BDFフォント(iso8859)を一緒に含める時に使う。

Parameters:

  • bdffilename (String)

    BDFフォントファイル名

  • col (Array) (defaults to: [255, 255, 255, 255])

    文字色。a,r,g,b を並べた配列で指定



271
272
273
274
275
276
# File 'bdffont.rb', line 271

def add(bdffilename, col = [255, 255, 255, 255])
  bdfdt = BDFdata.new(bdffilename, col)
  @bdffiles.push(bdfdt)
  @width = bdfdt.width if @width <= bdfdt.width
  @height = bdfdt.height if @height <= bdfdt.height
end