Class: Font

Inherits:
Object
  • Object
show all
Defined in:
lib/openrgss/font.rb

Overview

The font class. Font is a property of the Bitmap class.

If there is a “Fonts” folder directly under the game folder, the font files in it can be used even if they are not installed on the system.

You can change the default values set for each component when a new Font object is created.

Font.default_name = ["Myriad", "Verdana"]
Font.default_size = 22
Font.default_bold = true

Constant Summary collapse

@@cache =
{}
@@default_name =

  • Standard Einstellungen aus der RGSS102E.dll.


"Arial"
@@default_size =
22
@@default_bold =
false
@@default_italic =
false
@@default_color =
Color.new(255, 255, 255, 255)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg_name = @@default_name, arg_size = @@default_size) ⇒ Font

Creates a Font object.



15
16
17
18
19
20
21
# File 'lib/openrgss/font.rb', line 15

def initialize(arg_name=@@default_name, arg_size=@@default_size)
  @name  = arg_name
  @size  = arg_size
  @bold  = @@default_bold
  @italic= @@default_italic
  @color = @@default_color
end

Instance Attribute Details

#boldObject

The bold flag. The default is FALSE.



72
73
74
# File 'lib/openrgss/font.rb', line 72

def bold
  @bold
end

#colorObject

The font color (Color). Alpha values may also be used. The default is (255,255,255,255).

Alpha values are also used when drawing outline (RGSS3) and shadow text.



86
87
88
# File 'lib/openrgss/font.rb', line 86

def color
  @color
end

#italicObject

The italic flag. The default is FALSE.



75
76
77
# File 'lib/openrgss/font.rb', line 75

def italic
  @italic
end

#nameObject

The font name. Include an array of strings to specify multiple fonts to be used in a desired order.

font.name = ["Myriad", "Verdana"]

In this example, if the higher priority font Myriad does not exist on the system, the second choice Verdana will be used instead.

The default is [“Verdana”, “Arial”, “Courier New”].



66
67
68
# File 'lib/openrgss/font.rb', line 66

def name
  @name
end

#out_colorObject

The outline color (Color). The default is (0,0,0,128).



89
90
91
# File 'lib/openrgss/font.rb', line 89

def out_color
  @out_color
end

#outlineObject

The flag for outline text. The default is TRUE.



78
79
80
# File 'lib/openrgss/font.rb', line 78

def outline
  @outline
end

#shadowObject

The flag for shadow text. The default is false (RGSS3). When enabled, a black shadow will be drawn to the bottom right of the character.



81
82
83
# File 'lib/openrgss/font.rb', line 81

def shadow
  @shadow
end

#sizeObject

The font size. The default is 24.



69
70
71
# File 'lib/openrgss/font.rb', line 69

def size
  @size
end

Class Method Details

.exist?(arg_font_name) ⇒ Boolean

Returns true if the specified font exists on the system.

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/openrgss/font.rb', line 25

def Font.exist?(arg_font_name)
  font_key       = 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts'
  reg_open_keyex = Win32API.new('Advapi32', 'RegOpenKeyEx', 'lpllp', 'l')
  reg_enum_value = Win32API.new('Advapi32', 'RegEnumValue', 'llppiiii', 'l')
  reg_close_key  = Win32API.new('Advapi32', 'RegCloseKey', 'l', 'l')
  open_key       = [0].pack('V')
  # get key
  reg_open_keyex.call(0x80000002, font_key, 0, 0x20019, open_key)
  open_key  = (open_key + [0].pack('V')).unpack('V').first
  # enumerate
  buffer    = "\0"*256
  buff_size = [255].pack('l')
  key_i     = 0
  font_names= []
  while (reg_enum_value.call(open_key, key_i, buffer, buff_size, 0, 0, 0, 0).zero?)
    # get name
    font_names << buffer[0, buff_size.unpack('l').first].sub(/\s\(.*\)/, '')
    # reset
    buff_size = [255].pack('l')
    # increment
    key_i     += 1
  end
  reg_close_key.call(open_key)
  # test
  return font_names.include?(arg_font_name)
end

Instance Method Details

#entityObject

SDL::TTF对象



54
55
56
57
58
# File 'lib/openrgss/font.rb', line 54

def entity
  result       = @@cache[[@name, @size]] ||= SDL::TTF.open('wqy-microhei.ttc', @size)
  result.style = (@bold ? SDL::TTF::STYLE_BOLD : 0) | (@italic ? SDL::TTF::STYLE_ITALIC : 0)
  result
end