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
"""ÁáÂâÃãÀàÇçÉéÊêÍíÓóÔôÕõÚú"""
19 COUNT_EXTRA_CHARS
= 21
21 chars_extra
= u
"".join([chr(1+i
) for i
in range(COUNT_EXTRA_CHARS
)])
22 chars
= chars_en
+ chars_extra
+ chars_fr
+ chars_de
+ chars_cz
+ chars_es
+ chars_fi
+ chars_it
+ chars_pl
25 def createFontBitmap(filename
, fontname
, fontsize
, fontoffset
, foreground
, background
, coordsfile
=True):
29 font_filename
= 'fonts/' + fontname
+ '.ttf'
31 print("Font filename: %s" % font_filename
)
32 font
= ImageFont
.truetype(font_filename
, fontsize
)
35 extraFilename
= 'fonts/extra_%dpx.png' % fontsize
38 extraImage
= Image
.open(extraFilename
)
39 extraImage
= extraImage
.convert('RGB');
42 print("Missing extra symbol filename %s" % extraFilename
)
47 # Extra characters 16px
58 w
, h
= font
.getsize(c
)
64 width
+= getCharWidth(c
)
67 width
= getFontWidth()
68 image
= Image
.new('RGB', (width
, fontsize
+ 4), background
)
69 draw
= ImageDraw
.Draw(image
)
76 if extraImage
and c
== chars_extra
[0]:
77 image
.paste(extraImage
.copy(),(width
,1))
81 w
, h
= font
.getsize(c
)
82 draw
.text((width
+ 1, fontoffset
), c
, fill
=foreground
, font
=font
)
84 width
+= getCharWidth(c
)
88 image
.save(filename
+ ".png")
90 with
open(filename
+ ".specs", "w") as f
:
91 f
.write(",".join(str(tmp
) for tmp
in coords
))
95 if __name__
== "__main__":
96 createFontBitmap(sys
.argv
[4], sys
.argv
[1], int(sys
.argv
[2]), int(sys
.argv
[3]), (0,0,0), (255,255,255))