ImageFont = {}
function ImageFont.load(path, baseHeight)
local imageFont = {}
imageFont.chars = {}
for k, v in pairs(System.listDirectory(path)) do
imageFont.chars[string.char(v['name']:sub(1, -5))] = Graphics.loadImage(path .. v['name'])
end
imageFont.baseHeight = baseHeight
imageFont.height = baseHeight
return imageFont
end
function ImageFont.setPixelSizes(imageFont, height)
imageFont.height = height
end
function ImageFont.print(imageFont, x, y, text, color)
local offset = x
color = color or Color.new(0, 0, 0)
for i = 1, #text do
if(text:sub(i, i) == ' ') then
offset = math.floor(offset + imageFont.height / 4 + 0.5)
else
Graphics.drawScaleImage(offset, y, imageFont.chars[text:sub(i, i)], imageFont.height / imageFont.baseHeight, imageFont.height / imageFont.baseHeight, color)
offset = math.floor(offset + Graphics.getImageWidth(imageFont.chars[text:sub(i, i)]) * 0.9 * imageFont.height / imageFont.baseHeight + math.ceil(imageFont.height / 36) + 0.5)
end
end
end
function ImageFont.unload(imageFont)
for k, v in pairs(imageFont.chars) do
Graphics.freeImage(v)
end
end