Skip to content

get_font_height() returns 0 for the 5x7 BDF face, so BDF-based row stacking collapses #397

Description

@ChuckBuilds

What happens

In ledmatrix-music, a track with an album name draws the artist and album lines on top of each other. Instrumenting the layout shows why:

128x32  font_heights: title=8, artist=0, album=0   positions - title: 1, artist: 11, album: 13
128x64  font_heights: title=8, artist=0, album=0   positions - title: 2, artist: 14, album: 18

artist_height and album_height are 0. The plugin stacks rows as
next_y = prev_y + prev_height + line_gap, so with a height of 0 the album row lands one line_gap below the artist row rather than a full row below. The artist string is 7px tall, so the two overlap almost completely.

It is not a short-panel clamp — it happens at 128x64 too — and not a frame-stepping artifact: it reproduces with a single display() call.

Why the height is 0

The artist and album rows default to 5x7.bdf, which resolves to display_manager.bdf_5x7_font. In the core's DisplayManager that face is built like this:

face = freetype.Face(self.calendar_font_path)
logger.info(f"Calendar font size: {face.size.height >> 6} pixels")
self.calendar_font = face
...
self.bdf_5x7_font = self.calendar_font

There is no set_char_size() call, so face.size.height stays 0 and get_font_height() — which returns font.size.height >> 6 for a FreeType face — returns 0.

Two things worth noting:

  1. The core's own log line already prints the symptom. That logger.info emits Calendar font size: 0 pixels on every start-up.
  2. The core contradicts itself. font_manager._load_bdf() does call face.set_char_size(size_px * 64, size_px * 64, 72, 72) right after constructing the face. DisplayManager does not. So whether get_font_height() works depends on which path loaded the face.

The real DisplayManager and the testing VisualTestDisplayManager construct the face the same way, so this is not a harness artifact — it is what a real install does.

Fix here vs fix in the core

The proper fix is in the core: either call set_char_size() in DisplayManager alongside the font_manager path, or have get_font_height() fall back when size.height is 0. That is the other repo, so I have not touched it.

Plugin-side, ledmatrix-music now refuses to believe a zero: it falls back to the configured font_size (which is what the row was asked to be) and then to a sane default. Rows come out at 1 / 11 / 20 on a 32px panel instead of 1 / 11 / 13.

Other plugins to check

Four plugins call get_font_height() and also reference BDF fonts:

  • ledmatrix-music — confirmed broken, fixed in the PR that accompanies this issue
  • calendar
  • clock-simple
  • ledmatrix-flights

I have not verified whether the other three actually pass a BDF face to get_font_height() (several use it only on TTF fonts, where getmetrics() works). Worth checking each before assuming.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions