summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Couzens <lynxis@fe80.eu>2019-07-11 16:09:35 +0200
committerlynxis lazus <lynxis@fe80.eu>2019-08-09 13:33:17 +0000
commitf5afdf4c204d861f5645f8b9c72a590e1c9c845e (patch)
treec47b6aad761f71eb359d8af9e4e068a3bc36230a /src
parent2cc3392706bdf15455755549468a741a56217d60 (diff)
fb_tools/bdf_to_c.py: make it compatible with python3
This would break python2 compatibility. Change-Id: Iaa20dd0aafa20e36186cf8dfe4d0ac9ab638f235
Diffstat (limited to 'src')
-rwxr-xr-xsrc/host/fb_tools/bdf_to_c.py66
1 files changed, 33 insertions, 33 deletions
diff --git a/src/host/fb_tools/bdf_to_c.py b/src/host/fb_tools/bdf_to_c.py
index 86be6a6..ebeb7f9 100755
--- a/src/host/fb_tools/bdf_to_c.py
+++ b/src/host/fb_tools/bdf_to_c.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
@@ -133,7 +133,7 @@ class BDF_Font(object) :
arr = l.split(None,1)
if len(arr) < 2 and \
arr[0].lower() != 'STARTCHAR' :
- print >>sys.stderr,'Not start of glyph: %s'%(l)
+ print('Not start of glyph: %s'%(l), file=sys.stderr)
continue
inchar = unique_name(arr[1],self.glyphs)
continue
@@ -159,7 +159,7 @@ class BDF_Font(object) :
continue
if len(arr) < 2 :
- print >>sys.stderr,'Bad line in font: %s'%(l)
+ print('Bad line in font: %s'%(l), file=sys.stderr)
continue
data[arr[0].lower()] = arr[1]
@@ -183,40 +183,40 @@ if __name__ == '__main__' :
if opts.firstchar == None :
opts.firstchar = min(font.enc)
- print 'First character in font: %d, %s'%(opts.firstchar,
- font.enc[opts.firstchar])
+ print('First character in font: %d, %s'%(opts.firstchar,
+ font.enc[opts.firstchar]))
if opts.lastchar == None :
opts.lastchar = max(font.enc)
- print 'Last character in font: %d, %s'%(opts.lastchar,
- font.enc[opts.lastchar])
+ print('Last character in font: %d, %s'%(opts.lastchar,
+ font.enc[opts.lastchar]))
if opts.base == None :
opts.base = 'font_'+os.path.basename(args[0])
if opts.base[-4:] == '.bdf' :
opts.base = opts.base[:-4]
- print >>sys.stderr,'Guessing symbol prefix to be %s.'%(opts.base)
+ print('Guessing symbol prefix to be %s.'%(opts.base), file=sys.stderr)
if opts.out == None :
opts.out = os.path.basename(args[0])
if opts.out[-4:] == '.bdf' :
opts.out = opts.out[:-4]
opts.out = opts.out + '.c'
- print >>sys.stderr,'Guessing output filename to be %s.'%(opts.out)
+ print('Guessing output filename to be %s.'%(opts.out), file=sys.stderr)
if os.path.exists(opts.out) :
- print >>sys.stderr,'Will *NOT* overwrite existing file when guessing output!'
+ print('Will *NOT* overwrite existing file when guessing output!', file=sys.stderr)
sys.exit(1)
of = file(opts.out,'w')
- print >>of,'#include <fb/font.h>'
- print >>of,'/* file autogenerated by %s */'%(sys.argv[0])
+ print('#include <fb/font.h>', file=of)
+ print('/* file autogenerated by %s */' %(sys.argv[0]), file=of)
offsets = list()
glyphnames = list()
- print >>of,'static const uint8_t %s_data[] = {'%(opts.base)
+ print('static const uint8_t %s_data[] = {'%(opts.base), file=of)
pos = 0
@@ -236,8 +236,8 @@ if __name__ == '__main__' :
bitmap = glyph['bitmap']
if bbx[1] != len(bitmap) :
- print >>sys.stderr,'ERROR: glyph',charname,'has wrong number of lines of data!'
- print >>sys.stderr,' want: ',bbx[1],'but have',len(bitmap)
+ print('ERROR: glyph',charname,'has wrong number of lines of data!', file=sys.stderr)
+ print(' want: ',bbx[1],'but have',len(bitmap), file=sys.stderr)
sys.exit(1)
removedrows = 0
@@ -254,40 +254,40 @@ if __name__ == '__main__' :
bitmap = bitmap[:-1]
if removedrows > 0 :
- print "Glyph %s: removed %d rows."%(charname,removedrows)
+ print("Glyph %s: removed %d rows."%(charname,removedrows))
w = int(glyph['dwidth'].split(None,1)[0])
- print >>of,'/* --- new character %s %s starting at offset 0x%04x --- */'%(
- charname,ascii_charnum(i),pos)
- print >>of,'\t/*%04x:*/\t%d, %d, %d, %d, %d, /* width and bbox (w,h,x,y) */'%(
- pos,w,bbx[0],bbx[1],bbx[2],bbx[3])
+ print('/* --- new character %s %s starting at offset 0x%04x --- */'%(
+ charname,ascii_charnum(i),pos), file=of)
+ print('\t/*%04x:*/\t%d, %d, %d, %d, %d, /* width and bbox (w,h,x,y) */'%(
+ pos,w,bbx[0],bbx[1],bbx[2],bbx[3]), file=of)
pos += 5
for k,l in enumerate(bitmap) :
bytes = [ int(l[i:i+2],16) for i in range(0,len(l),2) ]
if len(bytes) != (bbx[0]+7)/8 :
- print >>sys.stderr,'ERROR: glyph',charname,'has wrong # of bytes'
- print >>sys.stderr,' per line. Want',(bbx[0]+7)/8,'have',len(bytes)
+ print('ERROR: glyph',charname,'has wrong # of bytes', file=sys.stderr)
+ print(' per line. Want',(bbx[0]+7)/8,'have',len(bytes), file=sys.stderr)
sys.exit(1)
cdata = ','.join([ '0x%02x'%v for v in bytes ])
comment = ''.join([ byte_to_bits(b) for b in bytes ])
- print >>of,'\t/*%04x:*/\t'%(pos)+cdata+', /* '+comment+' */'
+ print('\t/*%04x:*/\t'%(pos)+cdata+', /* '+comment+' */', file=of)
pos += len(bytes)
- print >>of,"};"
+ print("};", file=of)
x = ',\n\t'.join(['0x%04x /* %s */'%(w,n) for w,n in zip(offsets,glyphnames)])
- print >>of,'static const uint16_t %s_offsets[] = {\n\t%s\n};'%(opts.base,x)
+ print('static const uint16_t %s_offsets[] = {\n\t%s\n};'%(opts.base,x), file=of)
height = font.ascent + font.descent
- print >>of,'const struct fb_font %s = {'%(opts.base)
- print >>of,'\t.height = %d,'%(height)
- print >>of,'\t.ascent = %d,'%(font.ascent)
- print >>of,'\t.firstchar = %d, /* %s */'%(opts.firstchar,font.enc.get(opts.firstchar,"?"))
- print >>of,'\t.lastchar = %d, /* %s */'%(opts.lastchar,font.enc.get(opts.lastchar,"?"))
- print >>of,'\t.chardata = %s_data,'%(opts.base)
- print >>of,'\t.charoffs = %s_offsets,'%(opts.base)
- print >>of,'};'
+ print('const struct fb_font %s = {'%(opts.base), file=of)
+ print('\t.height = %d,'%(height), file=of)
+ print('\t.ascent = %d,'%(font.ascent), file=of)
+ print('\t.firstchar = %d, /* %s */'%(opts.firstchar,font.enc.get(opts.firstchar,"?")), file=of)
+ print('\t.lastchar = %d, /* %s */'%(opts.lastchar,font.enc.get(opts.lastchar,"?")), file=of)
+ print('\t.chardata = %s_data,'%(opts.base), file=of)
+ print('\t.charoffs = %s_offsets,'%(opts.base), file=of)
+ print('};', file=of)