Created
September 27, 2019 17:51
-
-
Save ffAudio/2940b369dbe1cc42e91b70cdb933840a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys, json | |
if len (sys.argv) < 4: | |
print "Usage: " + sys.argv[0] + " <font.otf> <font_metadata.json> fontname" | |
exit (-1) | |
fontname = sys.argv[3] | |
with open(sys.argv[1], 'rb') as fontfile: | |
with open('../include/' + fontname + '.h', 'w') as header: | |
with open('../include/' + fontname + '.cpp', 'w') as implementation: | |
implementation.write ('// This file was autogenerated by:\n// "' + " ".join (sys.argv) + '"\n//\n\n') | |
implementation.write ('namespace ' + fontname + '\n{\n') | |
implementation.write (' static const unsigned char font_otf[] = {\n ') | |
byte = fontfile.read (1) | |
column = 0 | |
while (byte): | |
num = ord (byte) | |
implementation.write (str (num)) | |
if num > 99: | |
column += 4 | |
elif num > 9: | |
column += 3 | |
else: | |
column += 2 | |
byte = fontfile.read (1) | |
if byte: | |
implementation.write (',') | |
if column > 100: | |
implementation.write ('\n ') | |
column = 0 | |
implementation.write ('};\n\n') | |
implementation.write (' static const int font_size = ' + str (fontfile.tell()) + ';\n\n') | |
implementation.write (""" | |
juce::Typeface::Ptr createTypeface() | |
{ | |
return juce::Typeface::createSystemTypefaceFor (font_otf, font_size); | |
}\n""") | |
implementation.write ('\n} // namespace ' + fontname + '\n') | |
header.write ('// This file was autogenerated by:\n// "' + " ".join (sys.argv) + '"\n//\n\n') | |
header.write ('namespace ' + fontname + '\n{\n') | |
header.write (' juce::Typeface::Ptr createTypeface();\n') | |
header.write ('\n} // namespace ' + fontname + '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment