Debian Codegraph @

texmf-dist/doc/fonts/gnu-freefont/tools/test/isMonoMono.py

raw
1 #!/usr/bin/env ../utility/fontforge-interp.sh
2 __license__ = """
3 This file is part of Gnu FreeFont.
4
5 Gnu FreeFont is free software: you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation, either version 3 of the License, or (at your option) any later
8 version.
9
10 Gnu FreeFont is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 Gnu FreeFont. If not, see <http://www.gnu.org/licenses/>.
16 """
17 __author__ = "Stevan White"
18 __email__ = "[email protected]"
19 __copyright__ = "Copyright 2009, 2010, Stevan White"
20 __date__ = "$Date: 2011-11-03 01:51:05 +0100 (Thu, 03 Nov 2011) $"
21 __version__ = "$Revision: 1864 $"
22
23 __doc__ = """
24 Diagnostic tool that checks that fonts are really monospace.
25
26 Allows characters to have 0 width though (note this is controversial)
27
28 Also: in order for box-drawing characters to connect properly, it is
29 important that the glyphs all lie between 800 and -200EM vertically.
30 """
31
32 import fontforge
33 import sys
34
35 problem = False
36
37 def ismonomono( fontfilename ):
38 print "Checking character bounding boxes: " + fontfilename
39 font = fontforge.open( fontfilename )
40
41 g = font.selection.all()
42 g = font.selection.byGlyphs
43
44 nonzero = 0
45
46 for e in g:
47 if nonzero == 0:
48 if e.width > 0:
49 nonzero = e.width
50 else:
51 if e.width > 0 and e.width != nonzero:
52 print ' ' + e.glyphname \
53 + '(' + str( e.encoding ) \
54 + ') width is ' + str( e.width ) \
55 + ' not ' + str( nonzero )
56 problem = True
57
58 ( xmin, ymin, xmax, ymax ) = e.boundingBox()
59 if ymin < -200 or ymax > 800:
60 print ' ' + e.glyphname + ' goes between heights ' \
61 + str( ymin ) + ' and ' + str( ymax )
62 """
63 For FontForge handling of TrueType/OpenType magic characters:
64 1) check that 0x0000 0x0001, 0x000D exist and have names
65 .notdef, .null, nonmarkingreturn
66 2) check that 0x0000 and 0x000D are width 600, and
67 0x0001 has no glyph and is width 0
68
69 Othewise complain that FontForge may not treat it right.
70 """
71 if not font[0x0000] \
72 or font[0x0000].glyphname != '.notdef' \
73 or font[0x0000].width != nonzero:
74 print 'Should be full-width ".notdef" glyph at 0x0000.'
75 if not font[0x0001] \
76 or font[0x0001].glyphname != '.null' \
77 or font[0x0001].width != 0:
78 print 'Should be zero-width ".null" glyph at 0x0001.'
79 if not font[0x000D] \
80 or font[0x000D].glyphname != 'nonmarkingreturn' \
81 or font[0x000D].width != nonzero:
82 print 'Should be full-width "nonmarkingreturn" glyph at 0x000D.'
83
84 scriptname = sys.argv[0];
85 argc = len( sys.argv )
86
87 if argc > 1:
88 for i in range( 1, argc ):
89 ismonomono( sys.argv[i] )
90
91 if problem:
92 sys.exit( 1 )
93 else:
94 sys.exit( 0 )