Debian Codegraph @

tools/test/isMonoMono.py

raw
1 from __future__ import print_function
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, 2018 Stevan White"
20 __date__ = "$Date:: 2018-06-03 21:57:09 +0200#$"
21 __version__ = "$Revision: 3914 $"
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 from sys import argv, exit
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, '(', e.encoding, ')',
53 'width is', e.width, 'not', nonzero
54 )
55 problem = True
56
57 ( xmin, ymin, xmax, ymax ) = e.boundingBox()
58 if ymin < -200 or ymax > 800:
59 print( ' ', e.glyphname, 'goes between heights',
60 ymin, 'and', ymax )
61 """
62 For FontForge handling of TrueType/OpenType magic characters:
63 1) check that 0x0000 0x0001, 0x000D exist and have names
64 .notdef, .null, nonmarkingreturn
65 2) check that 0x0000 and 0x000D are width 600, and
66 0x0001 has no glyph and is width 0
67
68 Othewise complain that FontForge may not treat it right.
69 """
70 if not 0x0000 in font \
71 or font[0x0000].glyphname != '.notdef' \
72 or font[0x0000].width != nonzero:
73 print( 'Should be full-width ".notdef" glyph at 0x0000.' )
74 if not 0x0001 in font \
75 or font[0x0001].glyphname != '.null' \
76 or font[0x0001].width != 0:
77 print( 'Should be zero-width ".null" glyph at 0x0001.' )
78 if not 0x000D in font \
79 or font[0x000D].glyphname != 'nonmarkingreturn' \
80 or font[0x000D].width != nonzero:
81 print( 'Should be full-width "nonmarkingreturn" glyph at 0x000D.' )
82
83 scriptname = argv[0];
84 argc = len( argv )
85
86 if argc > 1:
87 for i in range( 1, argc ):
88 ismonomono( argv[i] )
89
90 if problem:
91 exit( 1 )
92 else:
93 exit( 0 )