Class: Resedit::Font

Inherits:
Object
  • Object
show all
Defined in:
lib/resedit/font/font.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width, height, count = 256) ⇒ Font

charWidth, charHeight, characters count



11
12
13
14
15
16
17
18
19
# File 'lib/resedit/font/font.rb', line 11

def initialize(width, height, count=256)
    @width, @height, @count = width, height, count
    @gridColor = 0xFFEEEEEE
    @charColor = 0xFF000000
    @bgColor = 0xFFFFFFFF
    @widthColor = 0xFFFF0000
    @chars = {}
    @userData = nil
end

Instance Attribute Details

#bgColorObject

Returns the value of attribute bgColor.



8
9
10
# File 'lib/resedit/font/font.rb', line 8

def bgColor
  @bgColor
end

#charColorObject

Returns the value of attribute charColor.



8
9
10
# File 'lib/resedit/font/font.rb', line 8

def charColor
  @charColor
end

#countObject (readonly)

Returns the value of attribute count.



7
8
9
# File 'lib/resedit/font/font.rb', line 7

def count
  @count
end

#gridColorObject

Returns the value of attribute gridColor.



8
9
10
# File 'lib/resedit/font/font.rb', line 8

def gridColor
  @gridColor
end

#heightObject (readonly)

Returns the value of attribute height.



7
8
9
# File 'lib/resedit/font/font.rb', line 7

def height
  @height
end

#userDataObject

Returns the value of attribute userData.



8
9
10
# File 'lib/resedit/font/font.rb', line 8

def userData
  @userData
end

#widthObject (readonly)

Returns the value of attribute width.



7
8
9
# File 'lib/resedit/font/font.rb', line 7

def width
  @width
end

#widthColorObject

Returns the value of attribute widthColor.



8
9
10
# File 'lib/resedit/font/font.rb', line 8

def widthColor
  @widthColor
end

Instance Method Details

#charFlags(id) ⇒ Object



43
44
45
46
# File 'lib/resedit/font/font.rb', line 43

def charFlags(id)
    return nil if !@chars[id]
    return @chars[id].flags
end

#charWidth(id) ⇒ Object



38
39
40
41
# File 'lib/resedit/font/font.rb', line 38

def charWidth(id)
    return nil if !@chars[id]
    return @chars[id].realWidth ? @chars[id].realWidth : @width
end

#getChar(id) ⇒ Object



26
27
28
# File 'lib/resedit/font/font.rb', line 26

def getChar(id)
    @chars[id].data if @chars[id]
end

#load(filename) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/resedit/font/font.rb', line 70

def load(filename)
    img = Resedit.loadImage(filename)
    rows = @count/16 + (@count%16 == 0 ? 0 : 1)
    raise "Wrong image size" if (img.width!=@width*16+17 || img.height!=@height*rows+rows+1)
    for idx in 0..@count-1
        x = idx%16
        y = idx/16
        x += 1+x*@width
        y += 1+y*@height
        c = FontChar.new(width,height,idx)
        c.scan(img, @charColor, x, y, @widthColor, [@bgColor, @gridColor])
        @chars[c.index] = c if c.data
    end
end

#maxCharObject



34
35
36
# File 'lib/resedit/font/font.rb', line 34

def maxChar
    return @chars.keys().max
end

#minCharObject



30
31
32
# File 'lib/resedit/font/font.rb', line 30

def minChar
    return @chars.keys().min
end

#save(filename) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/resedit/font/font.rb', line 48

def save(filename)
    rows = @count/16 + (@count%16 == 0 ? 0 : 1)
    img = Resedit.createImage(@width*16+17 , @height*rows+rows+1, filename)
    img.fill(@bgColor)
    #draw grid
    for i in 0..16
        img.vline(i*(@width+1), gridColor)
    end
    for j in 0..rows
        img.hline(j*(@height+1), gridColor)
    end
    #draw letters
    @chars.each { |idx,c|
        x = idx%16
        y = idx/16
        x += 1+x*@width
        y += 1+y*@height
        c.draw(img, @charColor, x, y, @widthColor)
    }
    img.save(filename)
end

#setChar(id, data, width = nil, flags = nil) ⇒ Object



21
22
23
24
# File 'lib/resedit/font/font.rb', line 21

def setChar(id, data, width=nil, flags=nil)
    width=@width if !width
    @chars[id] = FontChar.new(@width, @height, id, data, width, flags)
end