# vim: set filetype=python : 
from __future__ import print_function
__license__ = """
This file is part of GNU FreeFont.

GNU FreeFont is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.

GNU FreeFont is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
GNU FreeFont.  If not, see <http://www.gnu.org/licenses/>. 
"""
__author__ = "Stevan White"
__email__ = "stevan.white@googlemail.com"
__copyright__ = "Copyright 2009, 2010, 2012, 2018 Stevan White"
__date__ = "$Date:: 2018-06-13 23:04:40 +0200#$"
__version__ = "$Revision: 3953 $"
__doc__ = """
Convert fonts from FontForge's native SFD format to TrueType format
First auto-hints whole font

Old-style kern tables seem to be what is actually used by Windows and
some Linux programs such as OpenOffice.

According to the FAQ, need to pass Flags=(apple) to build Mac fonts.
But this option seems to rule out old-style kern tables
"""

import fontforge
from sys import argv
from buildutils import *

def build_ttf_file( sfd_filename ):
	f = fontforge.open( argv[i] )
	ttfile = f.fontname + '.ttf'
	vstr = trim_version_str( f )
	print( 'Generating TrueType file', ttfile, vstr )
	# Wanted to set to 'UniocdeBmp' if there were no high unicodes
	# but all attemtps to determine that from Python failed.
	f.encoding = 'UnicodeFull'

	f.layers['Fore'].is_quadratic = True
	f.selection.all()
	f.autoHint()
	f.autoInstr()
	# 'old-kern' and 'dummy-dsig' are work-arounds for Windows
	# 'no-hints' means no PS (old-style) hints -- there are also TTF hints.
	fl = ('opentype','no-hints','old-kern','dummy-dsig','round')
	f.generate( ttfile, flags = fl )
	f.close()

scriptname = argv[0];
argc = len( argv )

if argc > 1:
	for i in range( 1, argc ):
		build_ttf_file( argv[i] )
else:
	print( "Usage:", scriptname, "font.sfd [font.sfd ...]" )
