Skip to content

PCF: Fix font metrics of "5x8.pcf" #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 23 additions & 25 deletions adafruit_bitmap_font/pcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,29 @@
from collections import namedtuple
import gc
import struct
from micropython import const

from fontio import Glyph
from .glyph_cache import GlyphCache

_PCF_PROPERTIES = 1 << 0
_PCF_ACCELERATORS = 1 << 1
_PCF_METRICS = 1 << 2
_PCF_BITMAPS = 1 << 3
_PCF_INK_METRICS = 1 << 4
_PCF_BDF_ENCODINGS = 1 << 5
_PCF_SWIDTHS = 1 << 6
_PCF_GLYPH_NAMES = 1 << 7
_PCF_BDF_ACCELERATORS = 1 << 8

_PCF_DEFAULT_FORMAT = 0x00000000
_PCF_INKBOUNDS = 0x00000200
_PCF_ACCEL_W_INKBOUNDS = 0x00000100
_PCF_COMPRESSED_METRICS = 0x00000100

_PCF_GLYPH_PAD_MASK = 3 << 0 # See the bitmap table for explanation */
_PCF_BYTE_MASK = 1 << 2 # If set then Most Sig Byte First */
_PCF_BIT_MASK = 1 << 3 # If set then Most Sig Bit First */
_PCF_SCAN_UNIT_MASK = 3 << 4
_PCF_PROPERTIES = const(1 << 0)
_PCF_ACCELERATORS = const(1 << 1)
_PCF_METRICS = const(1 << 2)
_PCF_BITMAPS = const(1 << 3)
_PCF_INK_METRICS = const(1 << 4)
_PCF_BDF_ENCODINGS = const(1 << 5)
_PCF_SWIDTHS = const(1 << 6)
_PCF_GLYPH_NAMES = const(1 << 7)
_PCF_BDF_ACCELERATORS = const(1 << 8)

_PCF_DEFAULT_FORMAT = const(0x00000000)
_PCF_ACCEL_W_INKBOUNDS = const(0x00000100)
_PCF_COMPRESSED_METRICS = const(0x00000100)

_PCF_GLYPH_PAD_MASK = const(3 << 0) # See the bitmap table for explanation */
_PCF_BYTE_MASK = const(1 << 2) # If set then Most Sig Byte First */
_PCF_BIT_MASK = const(1 << 3) # If set then Most Sig Bit First */
_PCF_SCAN_UNIT_MASK = const(3 << 4)

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

Expand Down Expand Up @@ -214,9 +214,7 @@ def _read_accelerator_tables(self):
raise RuntimeError("Accelerator table missing")

format_ = self._seek_table(accelerators)

has_inkbounds = format_ & _PCF_ACCEL_W_INKBOUNDS
compressed_metrics = format_ & _PCF_COMPRESSED_METRICS

(
no_overlap,
Expand All @@ -231,11 +229,11 @@ def _read_accelerator_tables(self):
font_descent,
max_overlap,
) = self._read(">BBBBBBBBIII")
minbounds = self._read_metrics(compressed_metrics)
maxbounds = self._read_metrics(compressed_metrics)
minbounds = self._read_metrics(False)
maxbounds = self._read_metrics(False)
if has_inkbounds:
ink_minbounds = self._read_metrics(compressed_metrics)
ink_maxbounds = self._read_metrics(compressed_metrics)
ink_minbounds = self._read_metrics(False)
ink_maxbounds = self._read_metrics(False)
else:
ink_minbounds = minbounds
ink_maxbounds = maxbounds
Expand Down
2 changes: 2 additions & 0 deletions test/displayio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#
# SPDX-License-Identifier: MIT

"""Implementation of minimal displayio subset for testing"""

# pylint: disable=all
class Bitmap:
def __init__(self, width, height, color_count):
self.width = width
Expand Down
2 changes: 2 additions & 0 deletions test/fontio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
# SPDX-License-Identifier: MIT

"""Implementation of minimal fontio subset for testing"""

import collections

Glyph = collections.namedtuple(
Expand Down