Class: Resedit::FontChar
- Inherits:
-
Object
- Object
- Resedit::FontChar
- Defined in:
- lib/resedit/font/font_char.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#flags ⇒ Object
Returns the value of attribute flags.
-
#index ⇒ Object
Returns the value of attribute index.
-
#realWidth ⇒ Object
Returns the value of attribute realWidth.
Instance Method Summary collapse
- #draw(image, x, y) ⇒ Object
- #hasPixel(x, y) ⇒ Object
-
#initialize(font, height, index, data = nil, realWidth = nil, flags = nil) ⇒ FontChar
constructor
A new instance of FontChar.
- #readFlags(image, x, y) ⇒ Object
- #scan(image, x, y) ⇒ Object
- #valueAt(x, y) ⇒ Object
Constructor Details
#initialize(font, height, index, data = nil, realWidth = nil, flags = nil) ⇒ FontChar
Returns a new instance of FontChar.
6 7 8 9 10 11 12 13 |
# File 'lib/resedit/font/font_char.rb', line 6 def initialize(font, height, index, data=nil, realWidth=nil, flags=nil) @font = font @width = font.width @height, @index = height, index @realWidth=realWidth @flags = flags @data=data if (data && data.length==@width*height) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/resedit/font/font_char.rb', line 4 def data @data end |
#flags ⇒ Object
Returns the value of attribute flags.
4 5 6 |
# File 'lib/resedit/font/font_char.rb', line 4 def flags @flags end |
#index ⇒ Object
Returns the value of attribute index.
4 5 6 |
# File 'lib/resedit/font/font_char.rb', line 4 def index @index end |
#realWidth ⇒ Object
Returns the value of attribute realWidth.
4 5 6 |
# File 'lib/resedit/font/font_char.rb', line 4 def realWidth @realWidth end |
Instance Method Details
#draw(image, x, y) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/resedit/font/font_char.rb', line 19 def draw(image, x, y) for j in 0..@height-1 for i in 0..@width-1 #p "#{@index} #{@width} #{@height} #{i} #{j} #{valueAt(i,j)}" image.setPixel(x+i, y+j, @font.colorMap(valueAt(i,j))) if hasPixel(i,j) end end if @realWidth image.setPixel(x+@realWidth, y, @font.widthColor) end if @flags && @flags.length>0 for i in 0..@flags.length-1 image.setPixel(x+@realWidth, y+i+1, @flags[i]) end end end |
#hasPixel(x, y) ⇒ Object
15 |
# File 'lib/resedit/font/font_char.rb', line 15 def hasPixel(x, y); @data[y*@width+x] != 0 end |
#readFlags(image, x, y) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/resedit/font/font_char.rb', line 36 def readFlags(image, x, y) empty = true flags = [] for i in 0..@height-2 col = image.getPixel(x, y+i) if col==@font.bgColor || col==@font.gridColor next end empty=false flags[i] = col end return nil if empty return flags end |
#scan(image, x, y) ⇒ Object
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 |
# File 'lib/resedit/font/font_char.rb', line 52 def scan(image, x, y) wColor = @font.widthColor bgColor = @font.bgColor @data=[0]*@width*@height @realWidth = nil width = @width _hasData = false for j in 0..@height-1 for i in 0..width-1 col=image.getPixel(x+i, y+j) if col == wColor @realWidth = i width = @realWidth break elsif col != bgColor @data[j*@width+i] = @font.valueMap(col) _hasData = true end end end fx = x + (@realWidth ? @realWidth : @width) @flags = readFlags(image, fx, y+1) @data=nil if !_hasData return @data!=nil end |
#valueAt(x, y) ⇒ Object
17 |
# File 'lib/resedit/font/font_char.rb', line 17 def valueAt(x,y); @data[y*@width+x] end |