2 # -*- coding: utf-8 -*-
7 from PIL
import Image
, ImageDraw
, ImageFont
9 chars_en
= u
""" !"#$%&'()*+,-./0123456789:;<=>?°ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz~|≥"""
10 chars_fr
= u
"""éèàîç"""
11 chars_de
= u
"""ÄäÖöÜüß"""
12 chars_cz
= u
"""ěščřžýáíéňóůúďťĚŠČŘŽÝÁÍÉŇÓÚŮĎŤ"""
14 chars_fi
= u
"""åäöÅÄÖ"""
16 chars_pl
= u
"""ąćęłńóśżźĄĆĘŁŃÓŚŻŹ"""
17 chars_pt
= u
"""ÁáÂâÃãÀàÇçÉéÊêÍíÓóÔôÕõÚú"""
18 chars_se
= u
"""åäöÅÄÖ"""
20 COUNT_EXTRA_CHARS
= 21
22 chars_extra
= u
"".join([chr(1+i
) for i
in range(COUNT_EXTRA_CHARS
)])
23 chars
= chars_en
+ chars_extra
+ chars_fr
+ chars_de
+ chars_cz
+ chars_es
+ chars_fi
+ chars_it
+ chars_pl
+ chars_se
26 def createFontBitmap(filename
, fontname
, fontsize
, fontoffset
, foreground
, background
, coordsfile
=True):
30 font_filename
= 'fonts/' + fontname
+ '.ttf'
32 print 'Font filename: %s' % font_filename
33 font
= ImageFont
.truetype(font_filename
, fontsize
)
36 extraFilename
= 'fonts/extra_%dpx.png' % fontsize
39 extraImage
= Image
.open(extraFilename
)
40 extraImage
= extraImage
.convert('RGB');
43 print 'Missing extra symbol filename %s' % extraFilename
48 # Extra characters 16px
59 w
, h
= font
.getsize(c
)
65 width
+= getCharWidth(c
)
68 width
= getFontWidth()
69 image
= Image
.new('RGB', (width
, fontsize
+ 4), background
)
70 draw
= ImageDraw
.Draw(image
)
77 if extraImage
and c
== chars_extra
[0]:
78 image
.paste(extraImage
.copy(),(width
,1))
82 w
, h
= font
.getsize(c
)
83 draw
.text( (width
+ 1, fontoffset
) , c
, fill
=foreground
, font
=font
)
85 width
+= getCharWidth(c
)
89 image
.save(filename
+ ".png")
91 with
open(filename
+ ".specs", "w") as f
:
92 f
.write(",".join(str(tmp
) for tmp
in coords
))
96 if __name__
== "__main__":
97 createFontBitmap(sys
.argv
[4], sys
.argv
[1], int(sys
.argv
[2]), int(sys
.argv
[3]), (0,0,0), (255,255,255))