#!/usr/bin/python
# bdflib-fill, a tool to fill out combining characters in a BDF font file
# Copyright (C) 2009, Timothy Alle
#
# This program 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.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

import sys
import unicodedata
from bdflib import reader, writer, glyph_combining


print "Using Unicode %s data." % unicodedata.unidata_version
print

input = open(sys.argv[1], 'r')
output = open(sys.argv[2], 'w+')

print "Reading font..."
font = reader.read_bdf(input)
print "Building list of decompositions..."
decompositions = glyph_combining.build_unicode_decompositions()
print "Generating combined characters..."
filler = glyph_combining.FontFiller(font, decompositions)
filler.add_decomposable_glyphs_to_font()
print "Writing out result..."
writer.write_bdf(font, output)

# Show the inventory of things this font is missing.
print
filler.unknown_classes.show()
print
filler.missing_chars.show(
		lambda char: "%r (%s)" % (char, unicodedata.name(char)))

input.close()
output.close()
