- 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)
+ if parts[0]=="font":
+ tw, th, fh, fa, fd = map(int, parts[1:])
+ result += "native_size {};\n".format(fh)
+ result += "ascent {:.3f};\n".format(float(fa)/fh)
+ result += "descent {:.3f};\n".format(float(fd)/fh)
+ elif parts[0]=="code":
+ c, n = tuple(map(int, parts[1:]))
+ codes[c] = n
+ elif parts[0]=="metrics":
+ metrics[values[0]] = values[1:]
+ elif parts[0]=="glyph":
+ glyphs[values[0]] = values[1:]
+ elif parts[0]=="kern":
+ kerning.append(values)
+
+ for c, n in codes.items():
+ h = metrics[n][1]
+ if c in caps:
+ cap_height.append(h)
+ elif c in xchars:
+ x_height.append(h)
+
+ if cap_height:
+ cap_height.sort()
+ result += "cap_height {:.3f};\n".format(float(cap_height[len(cap_height)*2//3])/fh)
+ if x_height:
+ x_height.sort()
+ result += "x_height {:.3f};\n".format(float(x_height[len(x_height)*2//3])/fh)
+
+ for c, n in codes.items():
+ _, _, ox, oy, a = metrics[n]
+ x, y, w, h, b = glyphs[n]
+ result += "glyph {}\n{{\n".format(c)
+ result += "\ttexcoords {} {} {} {};\n".format(float(x)/tw, float(th-y-h)/th, float(x+w)/tw, float(th-y)/th)
+ result += "\tsize {:.3f} {:.3f};\n".format(float(w)/fh, float(h)/fh)
+ result += "\toffset {:.3f} {:.3f};\n".format(float(ox-b)/fh, float(oy-b)/fh)
+ result += "\tadvance {:.3f};\n".format(float(a)/fh)