2
0

Font.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. require "Polycode/Resource"
  2. class "Font" (Resource)
  3. function Font:__getvar(name)
  4. if name == "loaded" then
  5. return Polycode.Font_get_loaded(self.__ptr)
  6. end
  7. if Resource["__getvar"] ~= nil then
  8. return Resource.__getvar(self, name)
  9. end
  10. end
  11. function Font:__setvar(name,value)
  12. if name == "loaded" then
  13. Polycode.Font_set_loaded(self.__ptr, value)
  14. return true
  15. end
  16. if Resource["__setvar"] ~= nil then
  17. return Resource.__setvar(self, name, value)
  18. else
  19. return false
  20. end
  21. end
  22. function Font:Font(...)
  23. local arg = {...}
  24. if type(arg[1]) == "table" and count(arg) == 1 then
  25. if ""..arg[1].__classname == "Resource" then
  26. self.__ptr = arg[1].__ptr
  27. return
  28. end
  29. end
  30. for k,v in pairs(arg) do
  31. if type(v) == "table" then
  32. if v.__ptr ~= nil then
  33. arg[k] = v.__ptr
  34. end
  35. end
  36. end
  37. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  38. self.__ptr = Polycode.Font(unpack(arg))
  39. end
  40. end
  41. function Font:getFace()
  42. local retVal = Polycode.Font_getFace(self.__ptr)
  43. if retVal == nil then return nil end
  44. local __c = _G["FT_Face"]("__skip_ptr__")
  45. __c.__ptr = retVal
  46. return __c
  47. end
  48. function Font:isValid()
  49. local retVal = Polycode.Font_isValid(self.__ptr)
  50. return retVal
  51. end
  52. function Font:setFontName(fontName)
  53. local retVal = Polycode.Font_setFontName(self.__ptr, fontName)
  54. end
  55. function Font:getFontName()
  56. local retVal = Polycode.Font_getFontName(self.__ptr)
  57. return retVal
  58. end
  59. function Font:getFontPath()
  60. local retVal = Polycode.Font_getFontPath(self.__ptr)
  61. return retVal
  62. end
  63. function Font:__delete()
  64. if self then Polycode.delete_Font(self.__ptr) end
  65. end