Debian Codegraph @

texmf-dist/doc/fonts/gnu-freefont/tools/utility/special-purpose/makeBraille.py

raw
1 __license__ = """
2 This file is part of Gnu FreeFont.
3
4 Gnu FreeFont is free software: you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free Software
6 Foundation, either version 3 of the License, or (at your option) any later
7 version.
8
9 Gnu FreeFont is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along with
14 Gnu FreeFont. If not, see <http://www.gnu.org/licenses/>.
15 """
16 __author__ = "Stevan White"
17 __email__ = "[email protected]"
18 __copyright__ = "Copyright 2010, Stevan White"
19 __date__ = "$Date: 2010/09/18 08:50:42 $"
20 __version__ = "$Revision: 1.6 $"
21
22 import fontforge
23 import psMat
24 from sys import stdout
25
26 __doc__ = """
27 Replaces the Braille Pattern range in a font. There must already be
28 characters defined there.
29
30 Two auxiliar glyphs, in variables glyphOff and glyphOn below, represent the
31 off and on state of the Braille dots, respectively.
32
33 One also needs to set the font file path, the width between columns of dots,
34 and the width between rows of dots, as well as the width of the glyphs.
35
36 The first 64 Braille Patterns consist of two columns of four dots,
37 the bottom two of which are all zero. The other 6 dots are represented
38 by the bit patterns of the octal digits of the offset from the range start.
39
40 The remaining three sets of 64 patterns repeat the first set, with
41 the bottom two dots being the bit pattern for the numbers 1 to 4 in binary.
42 """
43
44 font = fontforge.open( '../../sfd/FreeMono.sfd' )
45
46 glyphOff = 'braille_off'
47 glyphOn = 'braille_on'
48 colwidth = 220
49 rowheight = -220
50 glyphwidth = 600
51
52 def drawdot( g, col, row, on ):
53 move = psMat.translate( col * colwidth, row * rowheight )
54 if on:
55 g.addReference( glyphOn, move )
56 else:
57 g.addReference( glyphOff, move )
58
59 def createAndName( font, off ):
60 return font.createChar( 0x2800 + off, 'braille%0.2X' % off )
61
62 def drawtopsix( g, off ):
63 print 'created', 'braille%0.2X' % off
64 g.clear()
65 g.right_side_bearing = glyphwidth
66 for col in range ( 0, 2 ):
67 for row in range ( 0, 3 ):
68 print 'shift', ( 3 * col + row )
69 state = ( 1 << ( 3 * col + row ) ) & off
70 drawdot( g, col, row, state )
71
72 # Contrary to the FontForge docs, font.createChar does *not* create a
73 # glyph if one doesn't exist, but *does* re-name it if it already exists.
74 for off in range ( 0, 0x0100 ):
75 g = createAndName( font, off )
76 drawtopsix( g, off )
77 drawdot( g, 0, 3, ( off / 0x40 ) % 2 != 0 )
78 drawdot( g, 1, 3, off / 0x80 != 0 )
79
80 font.save()