Debian Codegraph @

tools/test/findDuplicateNames.py

raw
1 #!/usr/bin/env ../utility/fontforge-interp.sh
2 from __future__ import print_function
3 __license__ = """
4 This file is part of GNU FreeFont.
5
6 GNU FreeFont is free software: you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free Software
8 Foundation, either version 3 of the License, or (at your option) any later
9 version.
10
11 GNU FreeFont is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along with
16 GNU FreeFont. If not, see <http://www.gnu.org/licenses/>.
17 """
18 __author__ = "Stevan White"
19 __email__ = "[email protected]"
20 __copyright__ = "Copyright 2013, 2017, 2018 Stevan White"
21 __date__ = "$Date: $"
22 __version__ = "$Revision: 2589 $"
23
24 __doc__ = """
25 Purpose is to list out any glyphs in the fonts whose names are duplicated.
26 I don't know how that issue arises, but somehow it does.
27 Works by direct parsing of the SFD files.
28 This is a hack.
29 """
30
31 import fontforge
32 from sys import argv
33 from os import path
34
35 def findDuplicateNames( fontDir, fontFile ):
36 if isinstance( fontFile, ( list, tuple ) ):
37 print( "In directory", fontDir )
38 for f in fontFile:
39 findDuplicateNames( fontDir, f )
40 return
41
42 print( "Checking for duplicate glyph names in", fontFile )
43
44 font = fontforge.open( path.join( fontDir, fontFile ) )
45
46 g = font.selection.all()
47 g = font.selection.byGlyphs
48
49 names = {}
50 for glyph in g:
51 if glyph.glyphname in names:
52 names[glyph.glyphname].append( glyph.encoding )
53 else:
54 names[glyph.glyphname] = [ glyph.encoding ]
55 print( len( names ) )
56 for n in names:
57 if len( names[n] ) > 1:
58 print( "duplicate", n )
59 print( "\t" + names[n] )
60
61
62 # --------------------------------------------------------------------------
63 args = argv[1:]
64
65 if len( args ) < 1 or len( args[0].strip() ) == 0:
66 findDuplicateNames( '../../sfd/',
67 ( 'FreeSerif.sfd', 'FreeSerifItalic.sfd',
68 'FreeSerifBold.sfd', 'FreeSerifBoldItalic.sfd',
69 'FreeSans.sfd', 'FreeSansOblique.sfd',
70 'FreeSansBold.sfd', 'FreeSansBoldOblique.sfd',
71 'FreeMono.sfd', 'FreeMonoOblique.sfd',
72 'FreeMonoBold.sfd', 'FreeMonoBoldOblique.sfd' ) )
73 else:
74 findDuplicateNames( args[0], args[1:] )
75