class EZDraw::Font
Attributes
font[R]
Public Class Methods
_destroy(font, destroyed_flag)
click to toggle source
# File lib/ezdraw.rb, line 482 def self._destroy(font, destroyed_flag) if destroyed_flag[0] #EZDraw.logger.debug "(already destroyed font #{font})" return end EZDraw.logger.debug "destroy font #{font}" SDL2::Ttf.TTF_CloseFont(font) destroyed_flag[0] = true end
cleanup()
click to toggle source
# File lib/ezdraw.rb, line 472 def self.cleanup EZDraw.requires_init # destroy instances explicitly # to prevent finalizers from double-destroying after TTF_Quit @@instances.each {|font| font.close} @@instances = [] SDL2::Ttf.TTF_Quit end
init()
click to toggle source
# File lib/ezdraw.rb, line 465 def self.init if SDL2::Ttf.TTF_WasInit == 0 err = SDL2::Ttf.TTF_Init raise "TTF_Init: #{SDL2::Ttf.TTF_GetError}" if err != 0 end end
new(ttf_filename, ptheight)
click to toggle source
TODO: better API to distinguish between unsized “typeface” and sized “font”?
# File lib/ezdraw.rb, line 450 def initialize(ttf_filename, ptheight) EZDraw.requires_init @font = SDL2::Ttf.TTF_OpenFont(ttf_filename, ptheight) raise "TTF_OpenFont: #{SDL2::Ttf.TTF_GetError}" if @font.null? # wrapping in array to make changes shared by all references @destroyed_flag = [false] ObjectSpace.define_finalizer(self, proc {|id| self.class.class._destroy(@font, @destroyed_flag) }) @@instances << self end
Public Instance Methods
close()
click to toggle source
# File lib/ezdraw.rb, line 493 def close self.class._destroy(@font, @destroyed_flag) end
height()
click to toggle source
# File lib/ezdraw.rb, line 497 def height # BUG: methods should check whether font was destroyed SDL2::Ttf.TTF_FontHeight(@font) end
line_pitch()
click to toggle source
# File lib/ezdraw.rb, line 502 def line_pitch SDL2::Ttf.TTF_FontLineSkip(@font) end
render_utf8(text, color)
click to toggle source
# File lib/ezdraw.rb, line 509 def render_utf8(text, color) c = SDL2::SDL_Color.new c[:r] = color[0] c[:g] = color[1] c[:b] = color[2] c[:a] = color[3] sfc = SDL2::Ttf.TTF_RenderUTF8_Solid(@font, text, c) end
Also aliased as: render