-
Notifications
You must be signed in to change notification settings - Fork 0
/
fonts.lua
40 lines (33 loc) · 1.29 KB
/
fonts.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
local fonts = {}
local fontsPath = {
--fontName = "path"
segoe_sb = "files/seguisb.ttf",
segoe_r = "files/segoeui.ttf",
}
local function requestFont(fontName, size, bold, quality)
assert(fontName, "[Error] Need a font name!")
--assert(size and type(size) == "number", "[Error] Need a size!")
local fontPath = fontsPath[fontName]
assert(fontPath, "[Error] The "..fontName.." font was not found.")
if not fonts[fontName] then
fonts[fontName] = {}
end
if not fonts[fontName][size] then
local font = dxCreateFont(fontPath, size or 9, bold or false, quality or "default")
fonts[fontName][size] = {font = font, count = 1}
return font
else
fonts[fontName][size].count = fonts[fontName][size].count + 1
return fonts[fontName][size].font
end
end
local function destroyFont(fontName, size)
assert(size and type(size) == "number", "[Fonts]: Need a size to destroy the correct font!")
if fonts[fontName] and fonts[fontName][size] then
fonts[fontName][size].count = fonts[fontName][size].count - 1
if fonts[fontName][size].count <= 0 then
destroyElement(fonts[fontName][size].font)
fonts[fontName][size] = nil
end
end
end