Debian Codegraph @

tools/generate/tweeks/OpenType/typeutils.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 2012, 2015, 2018 Stevan White"
19 __date__ = "$Date: 2018-06-03 22:20:36 +0200 (So, 03. Jun 2018) $"
20 __version__ = "$Revision: 3921 $"
21
22 __doc__ = """ Utilities for handling OpenType/TrueType data types.
23 """
24
25 from datetime import date, timedelta
26
27 """Returns a string representation of a TrueType 4-character tag """
28 def int_to_tag( val ):
29 c = ( chr( ( val >> 24 ) & 0x000000FF ),
30 chr( ( val >> 16 ) & 0x000000FF ),
31 chr( ( val >> 8 ) & 0x000000FF ),
32 chr( ( val ) & 0x000000FF ) )
33 return ''.join( c )
34
35 """Returns a string representation of a TrueType Fixed-point (16.16)
36 number """
37 def fixed_str( val ):
38 ct = ( val >> 16 )
39 cb = ( val ) & 0xFFFF
40 return "%i.%u" % ( ct, cb )
41
42 _truetype_start_date = date( 1904, 1, 1 )
43 """Returns a Python date object from a 64-bit signed TrueType longdatetime """
44 def longdatetime2date( ldt ):
45 delta = timedelta( seconds = ldt )
46 return delta + _truetype_start_date
47
48 def bitfield2str( val, fieldlen = 16 ):
49 s = [ str( ( val >> i ) & 1 ) for i in range( 0, fieldlen ) ]
50 return ''.join( s )
51
52 def panose_str( val ):
53 v = str( val )
54 s = [ "{:X}".format( ord( v[i] ) ) for i in range( 0, 10 ) ]
55 return '|'.join( s )