Debian Codegraph @

tools/generate/TrueType

raw
1 # vim: set filetype=python :
2 from __future__ import print_function
3 __license__ = """
4 This file is part of GNU FreeFont.
5
6 GNU FreeFont is free software: you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free Software
8 Foundation, either version 3 of the License, or (at your option) any later
9 version.
10
11 GNU FreeFont is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along with
16 GNU FreeFont. If not, see <http://www.gnu.org/licenses/>.
17 """
18 __author__ = "Stevan White"
19 __email__ = "[email protected]"
20 __copyright__ = "Copyright 2009, 2010, 2012, 2018 Stevan White"
21 __date__ = "$Date:: 2018-06-13 23:04:40 +0200#$"
22 __version__ = "$Revision: 3953 $"
23 __doc__ = """
24 Convert fonts from FontForge's native SFD format to TrueType format
25 First auto-hints whole font
26
27 Old-style kern tables seem to be what is actually used by Windows and
28 some Linux programs such as OpenOffice.
29
30 According to the FAQ, need to pass Flags=(apple) to build Mac fonts.
31 But this option seems to rule out old-style kern tables
32 """
33
34 import fontforge
35 from sys import argv
36 from buildutils import *
37
38 def build_ttf_file( sfd_filename ):
39 f = fontforge.open( argv[i] )
40 ttfile = f.fontname + '.ttf'
41 vstr = trim_version_str( f )
42 print( 'Generating TrueType file', ttfile, vstr )
43 # Wanted to set to 'UniocdeBmp' if there were no high unicodes
44 # but all attemtps to determine that from Python failed.
45 f.encoding = 'UnicodeFull'
46
47 f.layers['Fore'].is_quadratic = True
48 f.selection.all()
49 f.autoHint()
50 f.autoInstr()
51 # 'old-kern' and 'dummy-dsig' are work-arounds for Windows
52 # 'no-hints' means no PS (old-style) hints -- there are also TTF hints.
53 fl = ('opentype','no-hints','old-kern','dummy-dsig','round')
54 f.generate( ttfile, flags = fl )
55 f.close()
56
57 scriptname = argv[0];
58 argc = len( argv )
59
60 if argc > 1:
61 for i in range( 1, argc ):
62 build_ttf_file( argv[i] )
63 else:
64 print( "Usage:", scriptname, "font.sfd [font.sfd ...]" )