缺失字体时使用引擎自带字体

This commit is contained in:
MrZ626
2020-09-06 21:35:32 +08:00
parent e47e0e1c78
commit 68c4a9fceb

View File

@@ -2,23 +2,42 @@ local gc=love.graphics
local int=math.floor local int=math.floor
local format=string.format local format=string.format
local fontData=love.filesystem.newFile("font.ttf") do
local newFont=gc.setNewFont local newFont=gc.setNewFont
local setNewFont=gc.setFont local setNewFont=gc.setFont
local fontCache,currentFontSize={} local fontCache,currentFontSize={}
function setFont(s) if love.filesystem.getInfo("font.ttf")then
local f=fontCache[s] local fontData=love.filesystem.newFile("font.ttf")
if s~=currentFontSize then function setFont(s)
if f then local f=fontCache[s]
setNewFont(f) if s~=currentFontSize then
else if f then
f=newFont(fontData,s) setNewFont(f)
fontCache[s]=f else
setNewFont(f) f=newFont(fontData,s)
fontCache[s]=f
setNewFont(f)
end
currentFontSize=s
end
return f
end
else
function setFont(s)
local f=fontCache[s]
if s~=currentFontSize then
if f then
setNewFont(f)
else
f=newFont(s)
fontCache[s]=f
setNewFont(f)
end
currentFontSize=s
end
return f
end end
currentFontSize=s
end end
return f
end end
function toTime(s) function toTime(s)