Skip to content

Commit 1f602d9

Browse files
authored
Merge pull request #40 from jepler/pcfmetrics
PCF: Fix font metrics of "5x8.pcf"
2 parents cb5d9db + a8eb9d3 commit 1f602d9

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

adafruit_bitmap_font/pcf.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,29 @@
2525
from collections import namedtuple
2626
import gc
2727
import struct
28+
from micropython import const
2829

2930
from fontio import Glyph
3031
from .glyph_cache import GlyphCache
3132

32-
_PCF_PROPERTIES = 1 << 0
33-
_PCF_ACCELERATORS = 1 << 1
34-
_PCF_METRICS = 1 << 2
35-
_PCF_BITMAPS = 1 << 3
36-
_PCF_INK_METRICS = 1 << 4
37-
_PCF_BDF_ENCODINGS = 1 << 5
38-
_PCF_SWIDTHS = 1 << 6
39-
_PCF_GLYPH_NAMES = 1 << 7
40-
_PCF_BDF_ACCELERATORS = 1 << 8
41-
42-
_PCF_DEFAULT_FORMAT = 0x00000000
43-
_PCF_INKBOUNDS = 0x00000200
44-
_PCF_ACCEL_W_INKBOUNDS = 0x00000100
45-
_PCF_COMPRESSED_METRICS = 0x00000100
46-
47-
_PCF_GLYPH_PAD_MASK = 3 << 0 # See the bitmap table for explanation */
48-
_PCF_BYTE_MASK = 1 << 2 # If set then Most Sig Byte First */
49-
_PCF_BIT_MASK = 1 << 3 # If set then Most Sig Bit First */
50-
_PCF_SCAN_UNIT_MASK = 3 << 4
33+
_PCF_PROPERTIES = const(1 << 0)
34+
_PCF_ACCELERATORS = const(1 << 1)
35+
_PCF_METRICS = const(1 << 2)
36+
_PCF_BITMAPS = const(1 << 3)
37+
_PCF_INK_METRICS = const(1 << 4)
38+
_PCF_BDF_ENCODINGS = const(1 << 5)
39+
_PCF_SWIDTHS = const(1 << 6)
40+
_PCF_GLYPH_NAMES = const(1 << 7)
41+
_PCF_BDF_ACCELERATORS = const(1 << 8)
42+
43+
_PCF_DEFAULT_FORMAT = const(0x00000000)
44+
_PCF_ACCEL_W_INKBOUNDS = const(0x00000100)
45+
_PCF_COMPRESSED_METRICS = const(0x00000100)
46+
47+
_PCF_GLYPH_PAD_MASK = const(3 << 0) # See the bitmap table for explanation */
48+
_PCF_BYTE_MASK = const(1 << 2) # If set then Most Sig Byte First */
49+
_PCF_BIT_MASK = const(1 << 3) # If set then Most Sig Bit First */
50+
_PCF_SCAN_UNIT_MASK = const(3 << 4)
5151

5252
# https://fontforge.org/docs/techref/pcf-format.html
5353

@@ -214,9 +214,7 @@ def _read_accelerator_tables(self):
214214
raise RuntimeError("Accelerator table missing")
215215

216216
format_ = self._seek_table(accelerators)
217-
218217
has_inkbounds = format_ & _PCF_ACCEL_W_INKBOUNDS
219-
compressed_metrics = format_ & _PCF_COMPRESSED_METRICS
220218

221219
(
222220
no_overlap,
@@ -231,11 +229,11 @@ def _read_accelerator_tables(self):
231229
font_descent,
232230
max_overlap,
233231
) = self._read(">BBBBBBBBIII")
234-
minbounds = self._read_metrics(compressed_metrics)
235-
maxbounds = self._read_metrics(compressed_metrics)
232+
minbounds = self._read_metrics(False)
233+
maxbounds = self._read_metrics(False)
236234
if has_inkbounds:
237-
ink_minbounds = self._read_metrics(compressed_metrics)
238-
ink_maxbounds = self._read_metrics(compressed_metrics)
235+
ink_minbounds = self._read_metrics(False)
236+
ink_maxbounds = self._read_metrics(False)
239237
else:
240238
ink_minbounds = minbounds
241239
ink_maxbounds = maxbounds

test/displayio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
"""Implementation of minimal displayio subset for testing"""
56

7+
# pylint: disable=all
68
class Bitmap:
79
def __init__(self, width, height, color_count):
810
self.width = width

test/fontio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
"""Implementation of minimal fontio subset for testing"""
6+
57
import collections
68

79
Glyph = collections.namedtuple(

0 commit comments

Comments
 (0)