]> git.tdb.fi Git - libs/gl.git/blobdiff - scripts/makefont.py
Enhance the extension generator to support different APIs
[libs/gl.git] / scripts / makefont.py
index ad12fee828405860b91159401466ffc47b48eafd..8cc9b17c6e49de535f9b769c6e141d395e9ac8a0 100755 (executable)
@@ -3,21 +3,29 @@
 def convert_def(fn):
        src = file(fn)
 
-       line = src.readline()
-       tw, th, fh, fa, fd = map(int, line.split())
-
-       result = "native_size %d;\n"%fh
-       result += "ascent %.3f;\n"%(float(fa)/fh)
-       result += "descent %.3f;\n"%(float(fd)/fh)
-
        for line in src.readlines():
-               g, x, y, w, h, ox, oy, a = map(int, line.split())
-               result += "glyph %d\n{\n"%g
-               result += "\ttexcoords %f %f %f %f;\n"%(float(x)/tw, float(th-y-h)/th, float(x+w)/tw, float(th-y)/th)
-               result += "\tsize %.3f %.3f;\n"%(float(w)/fh, float(h)/fh)
-               result += "\toffset %.3f %.3f;\n"%(float(ox)/fh, float(oy)/fh)
-               result += "\tadvance %.3f;\n"%(float(a)/fh)
-               result += "};\n"
+               line = line.strip()
+               if not line or line[0]=='#':
+                       continue
+
+               parts = line.split()
+
+               if parts[0]=="font":
+                       tw, th, fh, fa, fd = map(int, parts[1:])
+                       result = "native_size %d;\n"%fh
+                       result += "ascent %.3f;\n"%(float(fa)/fh)
+                       result += "descent %.3f;\n"%(float(fd)/fh)
+               elif parts[0]=="glyph":
+                       g, x, y, w, h, ox, oy, a = map(int, parts[1:])
+                       result += "glyph %d\n{\n"%g
+                       result += "\ttexcoords %f %f %f %f;\n"%(float(x)/tw, float(th-y-h)/th, float(x+w)/tw, float(th-y)/th)
+                       result += "\tsize %.3f %.3f;\n"%(float(w)/fh, float(h)/fh)
+                       result += "\toffset %.3f %.3f;\n"%(float(ox)/fh, float(oy)/fh)
+                       result += "\tadvance %.3f;\n"%(float(a)/fh)
+                       result += "};\n"
+               elif parts[0]=="kern":
+                       l, r, d = map(int, parts[1:])
+                       result += "kerning %d %d %.3f;\n"%(l, r, float(d)/fh)
 
        return result
 
@@ -29,8 +37,7 @@ def make_font(fn, size):
                raise Exception("Could not execute ttf2png")
 
        result = "texture\n{\n"
-       result += "wrap CLAMP_TO_EDGE;\n"
-       result += maketex.make_tex("makefont-tmp.png")
+       result += maketex.make_tex("makefont-tmp.png", wrap="CLAMP_TO_EDGE")
        result += "};\n"
        result += convert_def("makefont-tmp.def")