Class: Resedit::Font
- Inherits:
-
Object
- Object
- Resedit::Font
- Defined in:
- lib/resedit/font/font.rb
Instance Attribute Summary collapse
-
#bgColor ⇒ Object
Returns the value of attribute bgColor.
-
#bpp ⇒ Object
readonly
Returns the value of attribute bpp.
-
#charColor ⇒ Object
Returns the value of attribute charColor.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#gridColor ⇒ Object
Returns the value of attribute gridColor.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#userData ⇒ Object
Returns the value of attribute userData.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#widthColor ⇒ Object
Returns the value of attribute widthColor.
Instance Method Summary collapse
- #buildBppMap ⇒ Object
- #charFlags(id) ⇒ Object
- #charWidth(id) ⇒ Object
- #colorMap(val) ⇒ Object
- #getChar(id) ⇒ Object
-
#initialize(width, height, count: 256, bpp: 1) ⇒ Font
constructor
charWidth, charHeight, characters count.
- #load(filename) ⇒ Object
- #maxChar ⇒ Object
- #minChar ⇒ Object
- #save(filename) ⇒ Object
- #setChar(id, data, width = nil, flags = nil) ⇒ Object
- #valueMap(col) ⇒ Object
Constructor Details
#initialize(width, height, count: 256, bpp: 1) ⇒ Font
charWidth, charHeight, characters count
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/resedit/font/font.rb', line 12 def initialize(width, height, count: 256, bpp: 1) @width, @height, @count = width, height, count @gridColor = 0xFFEEEEEE @charColor = 0xFF000000 @bgColor = 0xFFFFFFFF @widthColor = 0xFFFF0000 @chars = {} @bpp = bpp @userData = nil @colmap = nil @valmap = nil end |
Instance Attribute Details
#bgColor ⇒ Object
Returns the value of attribute bgColor.
9 10 11 |
# File 'lib/resedit/font/font.rb', line 9 def bgColor @bgColor end |
#bpp ⇒ Object (readonly)
Returns the value of attribute bpp.
8 9 10 |
# File 'lib/resedit/font/font.rb', line 8 def bpp @bpp end |
#charColor ⇒ Object
Returns the value of attribute charColor.
9 10 11 |
# File 'lib/resedit/font/font.rb', line 9 def charColor @charColor end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
8 9 10 |
# File 'lib/resedit/font/font.rb', line 8 def count @count end |
#gridColor ⇒ Object
Returns the value of attribute gridColor.
9 10 11 |
# File 'lib/resedit/font/font.rb', line 9 def gridColor @gridColor end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
8 9 10 |
# File 'lib/resedit/font/font.rb', line 8 def height @height end |
#userData ⇒ Object
Returns the value of attribute userData.
9 10 11 |
# File 'lib/resedit/font/font.rb', line 9 def userData @userData end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
8 9 10 |
# File 'lib/resedit/font/font.rb', line 8 def width @width end |
#widthColor ⇒ Object
Returns the value of attribute widthColor.
9 10 11 |
# File 'lib/resedit/font/font.rb', line 9 def widthColor @widthColor end |
Instance Method Details
#buildBppMap ⇒ Object
25 26 27 28 |
# File 'lib/resedit/font/font.rb', line 25 def buildBppMap() return [@bgColor, @charColor] if @bpp==1 return ColorMap.new(@bgColor, @charColor).mapBpp(@bpp) end |
#charFlags(id) ⇒ Object
67 68 69 70 |
# File 'lib/resedit/font/font.rb', line 67 def charFlags(id) return nil if !@chars[id] return @chars[id].flags end |
#charWidth(id) ⇒ Object
62 63 64 65 |
# File 'lib/resedit/font/font.rb', line 62 def charWidth(id) return nil if !@chars[id] return @chars[id].realWidth ? @chars[id].realWidth : @width end |
#colorMap(val) ⇒ Object
30 31 32 33 34 |
# File 'lib/resedit/font/font.rb', line 30 def colorMap(val) @colmap = buildBppMap() if !@colmap #puts "#{val} = #{@colmap[val].to_s(16)}" return @colmap[val] end |
#getChar(id) ⇒ Object
50 51 52 |
# File 'lib/resedit/font/font.rb', line 50 def getChar(id) @chars[id].data if @chars[id] end |
#load(filename) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/resedit/font/font.rb', line 95 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(self, height, idx) c.scan(img, x, y) @chars[c.index] = c if c.data end @valmap = nil end |
#maxChar ⇒ Object
58 59 60 |
# File 'lib/resedit/font/font.rb', line 58 def maxChar return @chars.keys().max end |
#minChar ⇒ Object
54 55 56 |
# File 'lib/resedit/font/font.rb', line 54 def minChar return @chars.keys().min end |
#save(filename) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/resedit/font/font.rb', line 72 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, x, y) } img.save(filename) @colmap = nil end |
#setChar(id, data, width = nil, flags = nil) ⇒ Object
45 46 47 48 |
# File 'lib/resedit/font/font.rb', line 45 def setChar(id, data, width=nil, flags=nil) width=@width if !width @chars[id] = FontChar.new(self, @height, id, data, width, flags) end |
#valueMap(col) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/resedit/font/font.rb', line 36 def valueMap(col) if !@valmap @valmap = Hash[buildBppMap().each_with_index.map {|x,i| [x, i]}] if !@valmap end val=@valmap[col] raise "Wrong color in font #{col.to_s(16)}" if val==nil return val end |