]> git.tdb.fi Git - libs/gl.git/commitdiff
Make the font script compatible with new ttf2png output
authorMikko Rasa <tdb@tdb.fi>
Thu, 5 Sep 2013 19:22:00 +0000 (22:22 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 9 Sep 2013 15:52:39 +0000 (18:52 +0300)
scripts/makefont.py

index ad12fee828405860b91159401466ffc47b48eafd..84e9c6099dedcf5c0d18e2a02c068f110d4cc813 100755 (executable)
@@ -3,21 +3,26 @@
 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"
 
        return result