Project1

标题: 关于字体的描边 [打印本页]

作者: 喵呜喵5    时间: 2014-5-1 14:01
标题: 关于字体的描边
Font类自己的outline属性允许给字体增加描边,但是描边的厚度只有1个像素,请问如何实现2个像素乃至任意像素的字体描边?
作者: Sion    时间: 2014-5-1 14:11
photoshop
作者: taroxd    时间: 2014-5-1 14:56
试着只用脚本编辑器写了一下,结果就是个杯具
所以说这种东西应该不太能只用RGSS3来实现吧……

然后送一段杯具的代码=。=

[pre lang="ruby" line="1"]
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
[/pre]
作者: 无脑之人    时间: 2014-5-2 15:30
偏移几像素多画几遍呗233,虽然这样很没效率




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X5.0