typo.lua 983 B

123456789101112131415161718192021222324252627282930313233343536
  1. Typo = {}
  2. Typo.fonts = {}
  3. local setFont = love.graphics and love.graphics.setFont
  4. Typo.font = function(name, size)
  5. if not love.graphics then return nil end
  6. size = math.round(size)
  7. if name == 'mesmerize' then name = 'rawengulk' end
  8. if not name then
  9. Typo.fonts.default[size] = Typo.fonts.default[size] or love.graphics.newFont(size)
  10. return Typo.fonts.default[size]
  11. end
  12. if Typo.fonts[name] and Typo.fonts[name][size] then return Typo.fonts[name][size] end
  13. Typo.fonts[name] = Typo.fonts[name] or setmetatable({}, {__mode = 'v'})
  14. Typo.fonts[name][size] = Typo.fonts[name][size] or love.graphics.newFont('media/fonts/' .. name .. '.ttf', size)
  15. return Typo.fonts[name][size]
  16. end
  17. if love.graphics then
  18. love.graphics.setFont = function(name, size)
  19. if type(name) ~= 'string' then
  20. setFont(name)
  21. else
  22. setFont(Typo.font(name, size))
  23. end
  24. return love.graphics.getFont()
  25. end
  26. end
  27. Typo.resize = function()
  28. table.clear(Typo.fonts)
  29. end