File tree 1 file changed +6
-5
lines changed
1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 3
3
import io
4
4
import struct
5
5
from functools import lru_cache
6
+ from hashlib import md5
6
7
7
8
import pydyf
8
9
from fontTools import subset
@@ -34,14 +35,14 @@ def __init__(self, pango_font):
34
35
self .style = pango .pango_font_description_get_style (description )
35
36
self .family = ffi .string (
36
37
pango .pango_font_description_get_family (description ))
37
- digest = pango .pango_font_description_hash (description )
38
+ description_string = ffi .string (
39
+ pango .pango_font_description_to_string (description ))
40
+ # Never use the built-in hash function here: it’s not stable
38
41
self .hash = '' .join (
39
- chr (65 + letter % 26 ) + chr ( 65 + ( letter << 6 ) % 26 ) for letter
40
- in ( hash ( str ( digest )) % ( 2 ** ( 3 * 8 ))). to_bytes ( 3 , 'big' ) )
42
+ chr (65 + letter % 26 ) for letter
43
+ in md5 ( description_string ). digest ()[: 6 ] )
41
44
42
45
# Name
43
- description_string = ffi .string (
44
- pango .pango_font_description_to_string (description ))
45
46
fields = description_string .split (b' ' )
46
47
if fields and b'=' in fields [- 1 ]:
47
48
fields .pop () # Remove variations
You can’t perform that action at this time.
0 commit comments