Debian Codegraph @

tools/utility/slidereference.py

raw
1 #!/usr/bin/env python
2 from __future__ import print_function
3 import re
4 from sys import stdout, stderr
5 __license__ = """
6 This file is part of GNU FreeFont.
7
8 GNU FreeFont is free software: you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free Software
10 Foundation, either version 3 of the License, or (at your option) any later
11 version.
12
13 GNU FreeFont is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along with
18 GNU FreeFont. If not, see <http://www.gnu.org/licenses/>.
19 """
20 __author__ = "Stevan White"
21 __email__ = "[email protected]"
22 __copyright__ = "Copyright 2012, 2017, 2018 Stevan White"
23 __date__ = "$Date: 2011-09-12 14:25:06 +0200 (Mon, 12 Sep 2011) $"
24 __version__ = "$Revision: 1694 $"
25
26 sfdfile = open( "in-font.sfd" ) # the input font SFD file
27
28 __doc__ = """
29 To move all references to a couple of glyphs a bit horizontally.
30 Pretty primitive.
31 Operates directly on a FontForge SFD file (because I couldn't find a FontForge
32 interface that allowed moving references... why?)
33 So have to find "encoding" info for glyph.
34
35 StartChar: grave
36 Encoding: 96 96 64
37
38 StartChar: acute
39 Encoding: 180 180 113
40
41 The references to the glyph look like this:
42
43 Refer: 113 180 S 1 0 0 1 239 212 0
44
45 Refer: 113 180 N 1 0 0 1 99 2 0
46
47 Refer: 64 96 N 1 0 0 1 82 212 0
48
49 Don't know what the N and S stand for.
50 In all cases, the next numbers were 1 0 0 1. Probably identity matrix.
51 My guess is, the next are horizontal and vertical offsets.
52 The next is sometimes 0 sometimes 2.
53 """
54 refStart = 'Refer: 64 96 ' # recognize references to certain character
55 refTrans = ' 1 0 0 1 '
56 re_ref = re.compile( refStart + '(N|S)' + refTrans + '([-0-9]*) ([-0-9]*) (\d*)' )
57 re_charname = re.compile( 'StartChar: (.*)' )
58
59 charname = ''
60
61 for line in sfdfile:
62 charname_match = re_charname.match( line )
63 if charname_match:
64 charname = charname_match.group( 0 )
65 refer_match = re_ref.match( line )
66 if refer_match:
67 g = refer_match.groups()
68 print( charname, g, file=stderr )
69 dx = 79 # amount to slide horizontally
70 gnew = ( g[0], int( g[1] ) + dx, g[2], g[3] )
71 newline = ( refStart + '%s' + refTrans + '%s %s %s\n' ) % gnew
72 stdout.write( newline )
73 else:
74 stdout.write( line )
75