make_bmfhdr.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import sys
  2. if (len(sys.argv) != 2):
  3. print("Pass me a .fnt argument!")
  4. f = open(sys.argv[1], "rb")
  5. name = sys.argv[1].lower().replace(".fnt", "")
  6. l = f.readline()
  7. font_height = 0
  8. font_ascent = 0
  9. font_charcount = 0
  10. font_chars = []
  11. font_cc = 0
  12. while(l != ""):
  13. fs = l.strip().find(" ")
  14. if (fs == -1):
  15. l = f.readline()
  16. continue
  17. t = l[0:fs]
  18. dv = l[fs + 1:].split(" ")
  19. d = {}
  20. for x in dv:
  21. if (x.find("=") == -1):
  22. continue
  23. s = x.split("=")
  24. d[s[0]] = s[1]
  25. if (t == "common"):
  26. font_height = d["lineHeight"]
  27. font_ascent = d["base"]
  28. if (t == "char"):
  29. font_chars.append(d["id"])
  30. font_chars.append(d["x"])
  31. font_chars.append(d["y"])
  32. font_chars.append(d["width"])
  33. font_chars.append(d["height"])
  34. font_chars.append(d["xoffset"])
  35. font_chars.append(d["yoffset"])
  36. font_chars.append(d["xadvance"])
  37. font_cc += 1
  38. l = f.readline()
  39. print("static const int _bi_font_" + name + "_height=" + str(font_height) + ";")
  40. print("static const int _bi_font_" + name + "_ascent=" + str(font_ascent) + ";")
  41. print("static const int _bi_font_" + name + "_charcount=" + str(font_cc) + ";")
  42. cstr = "static const int _bi_font_" + name + "_characters={"
  43. for i in range(len(font_chars)):
  44. c = font_chars[i]
  45. if (i > 0):
  46. cstr += ", "
  47. cstr += c
  48. cstr += ("};")
  49. print(cstr)