font_table_ttf.py :  » Chart-Report » Matplotlib » matplotlib-0.99.1.1 » examples » pylab_examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Chart Report » Matplotlib 
Matplotlib » matplotlib 0.99.1.1 » examples » pylab_examples » font_table_ttf.py
#!/usr/bin/env python
# -*- noplot -*-
"""
matplotlib has support for freetype fonts.  Here's a little example
using the 'table' command to build a font table that shows the glyphs
by character code.

Usage python font_table_ttf.py somefile.ttf
"""
import sys, os
from matplotlib.ft2font import FT2Font
from pylab import figure,table,show,axis,title
from matplotlib.font_manager import FontProperties

# the font table grid

labelc = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
          'A', 'B', 'C', 'D', 'E', 'F']
labelr = ['00', '10', '20', '30', '40', '50', '60', '70', '80', '90',
          'A0', 'B0', 'C0', 'D0', 'E0', 'F0']

fontname = sys.argv[1]
font = FT2Font(fontname)
codes = font.get_charmap().items()
codes.sort()

# a 16,16 array of character strings
chars = [ ['' for c in range(16)] for r in range(16)]
colors = [ [(0.95,0.95,0.95) for c in range(16)] for r in range(16)]

figure(figsize=(8,4),dpi=120)
for ccode, glyphind in codes:
    if ccode>=256: continue
    r,c = divmod(ccode,16)
    s = chr(ccode)
    chars[r][c] = s



lightgrn = (0.5,0.8,0.5)
title(fontname)
tab = table(cellText=chars,
            rowLabels=labelr,
            colLabels=labelc,
            rowColours=[lightgrn]*16,
            colColours=[lightgrn]*16,
            cellColours=colors,
            cellLoc='center',
            loc='upper left')

for key, cell in tab.get_celld().items():
    row, col = key
    if row>0 and col>0:
        cell.set_text_props(fontproperties=FontProperties(fname=sys.argv[1]))
axis('off')
show()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.