class Font
attr_accessor :outline_size
singleton_class.send :attr_accessor, :default_outline_size
self.default_outline_size = 1
alias initialize_without_outline initialize
def initialize(*args)
initialize_without_outline(*args)
@outline_size = Font.default_outline_size
end
end
class Bitmap
alias draw_text_without_outline draw_text
def draw_text(*args)
draw_text_without_outline(*args)
return unless font.outline_size
white = Color.new(255,255,255)
temp = Bitmap.new(width, height)
temp.fill_rect(0, 0, width, height, white)
temp.draw_text_without_outline(*args)
width.times do |x|
height.times do |y|
unless temp.get_pixel(x, y) == white
(x - font.outline_size + 1).upto(x + font.outline_size - 1) do |i|
(y - font.outline_size + 1).upto(y + font.outline_size - 1) do |j|
set_pixel(i, j, font.out_color)
end
end
end
end
end
temp.dispose
end
end