#! /usr/bin/env python
# -*- python -*-

####################################################################################################
# 
# PyDvi - A Python Library to Process DVI Stream
# Copyright (C) 2014 Fabrice Salvaire
#
# 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/>.
# 
####################################################################################################

####################################################################################################
#
# Audit
# 
#  - 23/01/2010 fabrice
#    move to test?
#    warn if no arg
#
####################################################################################################

####################################################################################################

import argparse
import sys

from PyQt4 import QtGui, QtCore

####################################################################################################

parser = argparse.ArgumentParser(description='Qt Font.')
parser.add_argument('font', metavar='Font',
                    help='Font Name')
args = parser.parse_args()

####################################################################################################

application = QtGui.QApplication(sys.argv)

font_database = QtGui.QFontDatabase()

font_id = font_database.addApplicationFont(args.font)
print 'Font File Name:', args.font
print 'Font ID:', font_id

print 'Font Families/Styles/Point Sizes:'
for family in font_database.applicationFontFamilies(font_id):
    print ' -', family
    for style in font_database.styles(family):
        print '  -', style, ' / '.join(map(str, font_database.pointSizes(family, style)))
        
font = QtGui.QFont('Computer Modern', 10, QtGui.QFont.StyleNormal)
print 'Font', font.toString()

font = font_database.font('Computer Modern', 'Normal', 10)
print 'Font', font.toString()

font_metrics = QtGui.QFontMetrics(font)
char = QtCore.QChar('p')
print 'Font Metrics', \
    font_metrics.width(char), font_metrics.leftBearing(char), font_metrics.rightBearing(char) 

####################################################################################################
#
# End
#
####################################################################################################
