Class: BMFont
- Inherits:
-
Object
- Object
- BMFont
- Defined in:
- bmfont.rb
Overview
DXRuby BMFont 描画用クラス
ShoeBox で作成したビットマップフォントを描画する
Defined Under Namespace
Classes: BMFontData
Instance Attribute Summary (collapse)
-
- (Integer) baseofs
readonly
フォントベースライン位置.
-
- (Integer) height
readonly
フォント縦幅(単位はドット).
-
- (Integer) line_height
readonly
フォント縦幅調整値(単位はドット).
-
- (Integer) spacing
文字間スペース(単位はドット).
Instance Method Summary (collapse)
-
- (Object) [](index)
配列として指定した際に、BMFont情報の構造体を返す.
-
- (BMFont) initialize(imgfilename, fntfilename, spacing = 0)
constructor
コンストラクタ.
Constructor Details
- (BMFont) initialize(imgfilename, fntfilename, spacing = 0)
コンストラクタ
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'bmfont.rb', line 41 def initialize(imgfilename, fntfilename, spacing = 0) img = Image.load(imgfilename) @bmfont_array = {} @spacing = spacing @height = 0 @line_height = 0 @baseofs = 0 @chars_count = 0 cnt = 0 # .fntt@C1sǂݍŏ open(fntfilename) {|file| while l = file.gets l.chomp! if l =~ /^chars count=(\d+)$/ # 擾 @chars_count = $1.to_i elsif l =~ /^common (.+)$/ p = $1 p.split(' ').each do |s| if s=~ /^(\S+)=(\d+)$/ case $1 when "lineHeight" @line_height = $2.to_i puts "height = #{@height}" when "base" @baseofs = $2.to_i end end end elsif l =~ /^char (.+) letter=\"(.)\"$/ # 1 str, c = $1, $2 p = {} str.split(' ').each do |s| p[$1] = $2.to_i if s =~ /^(\S+)=(\d+)$/ end id, x, y, w, h = p["id"], p["x"], p["y"], p["width"], p["height"] xs, ys, xa = p["xoffset"], p["yoffset"], p["xadvance"] cimg = img.slice(x, y, w, h) # 摜o @bmfont_array[id] = BMFontData.new(cimg, w, h, xs, ys, xa) @height = h if @height < h cnt += 1 end end } img.dispose end |
Instance Attribute Details
- (Integer) baseofs (readonly)
Returns フォントベースライン位置
35 36 37 |
# File 'bmfont.rb', line 35 def baseofs @baseofs end |
- (Integer) height (readonly)
Returns フォント縦幅(単位はドット)
29 30 31 |
# File 'bmfont.rb', line 29 def height @height end |
- (Integer) line_height (readonly)
Returns フォント縦幅調整値(単位はドット)
32 33 34 |
# File 'bmfont.rb', line 32 def line_height @line_height end |
- (Integer) spacing
Returns 文字間スペース(単位はドット)
26 27 28 |
# File 'bmfont.rb', line 26 def spacing @spacing end |
Instance Method Details
- (Object) [](index)
配列として指定した際に、BMFont情報の構造体を返す
94 95 96 |
# File 'bmfont.rb', line 94 def [](index) return @bmfont_array[index] end |