Debian Codegraph @

tools/script-menu/unnameBySlot.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: $"
21 __version__ = "$Revision: 1.3 $"
22
23 __doc__ = """
24 For use from the FontForge Script Menu.
25 Add it to the Scripts Menu using the Preferences dialog.
26
27 Sets the name and unicode values of the selected range of slots to
28 the encoding, that is
29 Name: uniXXXX
30 Unocode: u+XXXX
31 where XXXX is the 4-digit hex value for the slot encoding.
32
33 Careful! it changes the falue whether it was previously set or not.
34
35 Detailed info is printed to standard output (see by launching FontForge
36 from a console).
37 """
38
39 import fontforge
40
41 def explain_error_and_quit( e ):
42 if e:
43 print( 'Error:', e )
44 exit( 1 )
45
46 try:
47 glyphs = fontforge.activeFont().selection.byGlyphs
48 for g in glyphs:
49 newname = 'NameMe.%s' %( str( g.encoding ) )
50 print( "naming", g.glyphname, 'as', newname )
51 g.glyphname = newname
52 g.unicode = -1
53 except ValueError as e:
54 explain_error_and_quit( e )
55