55import displayio
66import struct
77
8- _PCF_PROPERTIES = ( 1 << 0 )
9- _PCF_ACCELERATORS = ( 1 << 1 )
10- _PCF_METRICS = ( 1 << 2 )
11- _PCF_BITMAPS = ( 1 << 3 )
12- _PCF_INK_METRICS = ( 1 << 4 )
13- _PCF_BDF_ENCODINGS = ( 1 << 5 )
14- _PCF_SWIDTHS = ( 1 << 6 )
15- _PCF_GLYPH_NAMES = ( 1 << 7 )
16- _PCF_BDF_ACCELERATORS = ( 1 << 8 )
8+ _PCF_PROPERTIES = 1 << 0
9+ _PCF_ACCELERATORS = 1 << 1
10+ _PCF_METRICS = 1 << 2
11+ _PCF_BITMAPS = 1 << 3
12+ _PCF_INK_METRICS = 1 << 4
13+ _PCF_BDF_ENCODINGS = 1 << 5
14+ _PCF_SWIDTHS = 1 << 6
15+ _PCF_GLYPH_NAMES = 1 << 7
16+ _PCF_BDF_ACCELERATORS = 1 << 8
1717
1818_PCF_DEFAULT_FORMAT = 0x00000000
1919_PCF_INKBOUNDS = 0x00000200
2020_PCF_ACCEL_W_INKBOUNDS = 0x00000100
2121_PCF_COMPRESSED_METRICS = 0x00000100
2222
23- _PCF_GLYPH_PAD_MASK = ( 3 << 0 ) # See the bitmap table for explanation */
24- _PCF_BYTE_MASK = ( 1 << 2 ) # If set then Most Sig Byte First */
25- _PCF_BIT_MASK = ( 1 << 3 ) # If set then Most Sig Bit First */
26- _PCF_SCAN_UNIT_MASK = ( 3 << 4 )
23+ _PCF_GLYPH_PAD_MASK = 3 << 0 # See the bitmap table for explanation */
24+ _PCF_BYTE_MASK = 1 << 2 # If set then Most Sig Byte First */
25+ _PCF_BIT_MASK = 1 << 3 # If set then Most Sig Bit First */
26+ _PCF_SCAN_UNIT_MASK = 3 << 4
2727
2828# https://fontforge.github.io/en-US/documentation/reference/pcf-format/
2929
30+
3031class PCF (GlyphCache ):
3132 def __init__ (self , f ):
3233 super ().__init__ ()
@@ -47,17 +48,17 @@ def read(self, format):
4748 def get_bounding_box (self ):
4849 property_table_offset = self .tables [_PCF_PROPERTIES ]["offset" ]
4950 self .file .seek (property_table_offset )
50- format , = self .read ("<I" )
51+ ( format ,) = self .read ("<I" )
5152
5253 if format & _PCF_BYTE_MASK == 0 :
5354 raise RuntimeError ("Only big endian supported" )
54- nprops , = self .read (">I" )
55+ ( nprops ,) = self .read (">I" )
5556 self .file .seek (property_table_offset + 8 + 9 * nprops )
5657
5758 pos = self .file .tell ()
5859 if pos % 4 > 0 :
5960 self .file .read (4 - pos % 4 )
60- string_size , = self .read (">I" )
61+ ( string_size ,) = self .read (">I" )
6162
6263 strings = self .file .read (string_size )
6364 string_map = {}
@@ -89,7 +90,7 @@ def load_glyphs(self, code_points):
8990
9091 x , _ , _ , _ = self .get_bounding_box ()
9192 # create a scratch bytearray to load pixels into
92- scratch_row = memoryview (bytearray ((((x - 1 ) // 32 )+ 1 ) * 4 ))
93+ scratch_row = memoryview (bytearray ((((x - 1 ) // 32 ) + 1 ) * 4 ))
9394
9495 self .file .seek (0 )
9596 while True :
@@ -104,7 +105,7 @@ def load_glyphs(self, code_points):
104105 pass
105106 elif line .startswith (b"STARTCHAR" ):
106107 # print(lineno, line.strip())
107- #_, character_name = line.split()
108+ # _, character_name = line.split()
108109 character = True
109110 elif line .startswith (b"ENDCHAR" ):
110111 character = False
@@ -151,10 +152,12 @@ def load_glyphs(self, code_points):
151152 if desired_character :
152153 bits = int (line .strip (), 16 )
153154 for i in range (rounded_x ):
154- val = (bits >> ((rounded_x - i - 1 ) * 8 )) & 0xFF
155+ val = (bits >> ((rounded_x - i - 1 ) * 8 )) & 0xFF
155156 scratch_row [i ] = val
156- current_info ["bitmap" ]._load_row (current_y , scratch_row [:bytes_per_row ])
157+ current_info ["bitmap" ]._load_row (
158+ current_y , scratch_row [:bytes_per_row ]
159+ )
157160 current_y += 1
158161 elif metadata :
159- #print(lineno, line.strip())
162+ # print(lineno, line.strip())
160163 pass
0 commit comments