Class: BDFFont

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

Overview

Note:

iso8859, jisx0208, iso10646 のみに対応

BDFフォント描画用クラス

Examples:

require 'dxruby'
require_relative 'bdffont'
bdf = BDFFont.new("mplus_j12r_jisx0208.bdf")
bdf.add("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)
  y += bdf.height
  Window.draw_bdffont(x, y, "JAPANESE MESSAGE OK", 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 を並べた配列で指定



218
219
220
221
222
223
224
225
# File 'bdffont.rb', line 218

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

Instance Attribute Details

- (Integer) height (readonly)

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

Returns:

  • (Integer)

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



208
209
210
# File 'bdffont.rb', line 208

def height
  @height
end

- (Integer) ofsy (readonly)

Returns バウンディングボックスのyオフセット

Returns:

  • (Integer)

    バウンディングボックスのyオフセット



211
212
213
# File 'bdffont.rb', line 211

def ofsy
  @ofsy
end

Instance Method Details

- (Object?) [](index)

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

Parameters:

  • index (Integer)

    配列添字

Returns:

  • (Object)

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

  • (nil)

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



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'bdffont.rb', line 249

def [](index)
  @bdffiles.each do |d|
    code = nil
    case d.charset
    when :jisx0208
      code = self.sjis2jisx0208(index.ord)
    when :jisx0213
      # ΉBϊ@Ȃ
      code = self.sjis2jisx0208(index.ord)
      # code = index.encode("UTF-8", "Windows-31J").ord
      # code = index.encode("EUC-JISX0213", "Windows-31J").ord
      # code = index.encode("EUC-JP-2004", "Windows-31J").ord
    when :iso10646
      code = index.encode("UTF-8", "Windows-31J").ord
    else
      code = index.ord
    end
    return d.bdf_dic[code] if d.bdf_dic.has_key?(code)
  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 を並べた配列で指定



235
236
237
238
239
240
241
# File 'bdffont.rb', line 235

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