Skip to content

Support choosing real fonts for text (not just Carlito styles); fix mislabeled 'Narrow' #47

Description

@szrudi

Summary

Text widgets currently expose only four "styles" — regular, bold, italic, narrow — which map to the four bundled Carlito faces in labelle. There's no way to pick an actual font family. We'd like to let users choose real fonts.

Motivation / bug that surfaced this

While reviewing the style options we noticed the "Narrow" option is mislabeled — in labelle's font_config.py the narrow style is wired to Carlito-BoldItalic.ttf:

_DEFAULT_STYLES_TO_FONT_PATH = {
    "regular": ".../Carlito-Regular.ttf",
    "bold":    ".../Carlito-Bold.ttf",
    "italic":  ".../Carlito-Italic.ttf",
    "narrow":  ".../Carlito-BoldItalic.ttf",   # <-- not narrow at all
}

Carlito ships only those four faces (no condensed/narrow variant), so "Narrow" renders bold-italic. Quick mitigation in labelle-web: relabel the dropdown option to "Bold Italic" (keep value="narrow", which is the key labelle expects). The real fix — actual font choice — is this feature.

What labelle already gives us

labelle.lib.font_config.get_font_path() accepts either:

  • font= — a font name (resolved from get_available_fonts() = bundled Carlito + matplotlib.findSystemFonts()) or a path to a .ttf, or
  • style= — one of the four named styles above.

So the print engine already supports arbitrary fonts; labelle-web simply doesn't surface it.

Proposed work

Backend (server/)

  • Add GET /api/fonts wrapping get_available_fonts() (return display names / stems).
  • In label_builder.py, when a widget has a font name/path, call get_font_path(font=...) instead of get_font_path(style=...). Define precedence (explicit font overrides style).

Frontend (client/)

  • Add optional fontName?: string to TextWidget in types/label.ts.
  • Font picker in TextWidgetEditor.tsx populated from /api/fonts.
  • Store wiring + save/load .json round-trip.

Constraints to decide up front

  • font OR style, not both: get_font_path can't express "Arial + bold" — bold/italic only work if that face is its own file. Combining a chosen family with bold/italic would need an upstream labelle change or per-face selection.
  • Fonts in the container: the Docker image ships almost no system fonts, so on the Pi findSystemFonts() will return little. To be genuinely useful this likely needs bundling more fonts and/or a .ttf upload flow (mirroring the existing image-upload path).

Related

  • Upstream naming: the narrow style name is a labelle-library misnomer — worth a separate upstream note to labelle-org/labelle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions