Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
var face: Text
# Size of the source true type font
var face: Text
# Size of the source true type font
# Is the font bold?
var bold: Bool
# Is the font bold?
var bold: Bool
# Information common to all characters
# Distance in pixels between each line of text
# Information common to all characters
# Distance in pixels between each line of text
# Pixels from the top of the line to the base of the characters
# Pixels from the top of the line to the base of the characters
# Textures
var pages = new Map[String, TextureAsset]
# Textures
var pages = new Map[String, TextureAsset]
var chars = new Map[Char, BMFontChar]
# Distance between certain characters
var chars = new Map[Char, BMFontChar]
# Distance between certain characters
- var kernings = new HashMap2[Char, Char, Int]
+ var kernings = new HashMap2[Char, Char, Float]
redef fun to_s do return "<{class_name} {face} at {size} pt, "+
"{pages.length} pages, {chars.length} chars>"
redef fun to_s do return "<{class_name} {face} at {size} pt, "+
"{pages.length} pages, {chars.length} chars>"
class BMFontChar
# Subtexture left coordinate
class BMFontChar
# Subtexture left coordinate
# Subtexture top coordinate
# Subtexture top coordinate
# Cursor advance after drawing this character
# Cursor advance after drawing this character
# Full texture contaning this character and others
var page: TextureAsset
# Full texture contaning this character and others
var page: TextureAsset
# """
#
# var fnt = desc.parse_bmfont("dir_in_assets").value
# """
#
# var fnt = desc.parse_bmfont("dir_in_assets").value
- # assert fnt.to_s == "<BMFont arial at 72 pt, 1 pages, 3 chars>"
- # assert fnt.line_height == 80
- # assert fnt.kernings['A', 'C'] == -1
+ # assert fnt.to_s == "<BMFont arial at 72.0 pt, 1 pages, 3 chars>"
+ # assert fnt.line_height == 80.0
+ # assert fnt.kernings['A', 'C'] == -1.0
# assert fnt.chars['A'].page.path == "dir_in_assets/arial.png"
# ~~~
fun parse_bmfont(dir: String): MaybeError[BMFont, Error]
# assert fnt.chars['A'].page.path == "dir_in_assets/arial.png"
# ~~~
fun parse_bmfont(dir: String): MaybeError[BMFont, Error]
var fnt = new BMFont(
info_map["face"],
var fnt = new BMFont(
info_map["face"],
info_map["bold"] == "1",
info_map["italic"] == "1",
info_map["unicode"] == "1",
info_map["padding"],
info_map["spacing"],
info_map["bold"] == "1",
info_map["italic"] == "1",
info_map["unicode"] == "1",
info_map["padding"],
info_map["spacing"],
- common_map["lineHeight"].to_i,
- common_map["base"].to_i,
- common_map["scaleW"].to_i,
- common_map["scaleH"].to_i
+ common_map["lineHeight"].to_f,
+ common_map["base"].to_f,
+ common_map["scaleW"].to_f,
+ common_map["scaleH"].to_f
)
# Pages / pixel data files
)
# Pages / pixel data files
var id = attributes["id"].to_i.code_point
var c = new BMFontChar(
var id = attributes["id"].to_i.code_point
var c = new BMFontChar(
- attributes["x"].to_i, attributes["y"].to_i,
- attributes["width"].to_i, attributes["height"].to_i,
- attributes["xoffset"].to_i, attributes["yoffset"].to_i,
- attributes["xadvance"].to_i,
+ attributes["x"].to_f, attributes["y"].to_f,
+ attributes["width"].to_f, attributes["height"].to_f,
+ attributes["xoffset"].to_f, attributes["yoffset"].to_f,
+ attributes["xadvance"].to_f,
fnt.pages[attributes["page"]])
fnt.chars[id] = c
fnt.pages[attributes["page"]])
fnt.chars[id] = c
var attributes = item.attributes_to_map
var first = attributes["first"].to_i.code_point
var second = attributes["second"].to_i.code_point
var attributes = item.attributes_to_map
var first = attributes["first"].to_i.code_point
var second = attributes["second"].to_i.code_point
- var amount = attributes["amount"].to_i
+ var amount = attributes["amount"].to_f
fnt.kernings[first, second] = amount
end
end
fnt.kernings[first, second] = amount
end
end
var dx = 0.0
var dy = 0.0
var dx = 0.0
var dy = 0.0
- var line_height = desc.line_height.to_f
+ var line_height = desc.line_height
var prev_char = null
for c in text do
var prev_char = null
for c in text do
continue
else if c.is_whitespace then
var advance = if desc.chars.keys.has(' ') then
continue
else if c.is_whitespace then
var advance = if desc.chars.keys.has(' ') then
- desc.chars[' '].xadvance.to_f
+ desc.chars[' '].xadvance
else if desc.chars.keys.has('f') then
else if desc.chars.keys.has('f') then
- desc.chars['f'].xadvance.to_f
+ desc.chars['f'].xadvance
else 16.0
dx += advance
prev_char = null
else 16.0
dx += advance
prev_char = null
end
var char_info = desc.chars[c]
end
var char_info = desc.chars[c]
- var advance = char_info.xadvance.to_f
+ var advance = char_info.xadvance
var kerning = 0.0
if prev_char != null then
var kerning = 0.0
if prev_char != null then
- kerning = (desc.kernings[prev_char, c] or else 0).to_f
+ kerning = desc.kernings[prev_char, c] or else 0.0
- var x = dx + char_info.width.to_f/2.0 + char_info.xoffset.to_f + kerning
- var y = dy - char_info.height.to_f/2.0 - char_info.yoffset.to_f
+ var x = dx + char_info.width/2.0 + char_info.xoffset + kerning
+ var y = dy - char_info.height/2.0 - char_info.yoffset
var pos = text_sprites.anchor.offset(x, y, 0.0)
text_sprites.sprites.add new Sprite(char_info.subtexture, pos)
var pos = text_sprites.anchor.offset(x, y, 0.0)
text_sprites.sprites.add new Sprite(char_info.subtexture, pos)