8000 Let visualizers draw keystrokes in a user-chosen font by anandghegde · Pull Request #355 · keycastr/keycastr · GitHub
[go: up one dir, main page]

Skip to content
8000

Let visualizers draw keystrokes in a user-chosen font - #355

Open
anandghegde wants to merge 1 commit into
keycastr:mainfrom
anandghegde:feature/selectable-visualizer-font
Open

anandghegde wants to merge 1 commit into
keycastr:mainfrom
anandghegde:feature/selectable-visualizer-font

Conversation

@anandghegde
Copy link
Copy Markdown

Closes #169.

Every bundled visualizer already lets you pick a font size; the typeface has always been hardcoded to the system font. The request in #169 is for fixed-width — I vs l are indistinguishable in the system font, which matters a lot when you're recording a tutorial — but it's just as useful for matching a visualizer to a theme.

What this adds

A Font pop-up in each of the three bundled preference panes, directly above the existing Font Size control (Svelte has no size control, so it sits under "Display All Keystrokes"). Each pane stores its own choice:

Visualizer Key
Default default.fontName
Minimal minimal.fontName
Svelte svelte.fontName

The menu lists every installed family, each drawn in its own typeface, so it reads as a specimen sheet rather than a wall of identical text. The first item is "System Font", which is the default and restores today's behaviour exactly.

How it's put together

KCFontPopUpButton is a small NSPopUpButton subclass that populates itself from NSFontManager and reads/writes whichever defaults key the nib hands it via fontFamilyDefaultsKey (a user-defined runtime attribute). One class covers all three panes, and any future visualizer gets font selection by dropping the control into its nib and setting that one attribute.

Font resolution is -[NSUserDefaults fontForKey:size:bold:], sitting next to the existing colorForKey: / imageForKey: helpers. It always returns something drawable:

  • nothing stored, or the empty string → the system font
  • stored family no longer installed (uninstalled, or disabled in Font Book) → the system font, without clearing the stored value, so reinstalling the font brings the selection back
  • bold requested but the family has no bold face → the family's regular weight, rather than substituting a different family to honour boldness

Minimal is the only visualizer that asks for bold, matching its current boldSystemFontOfSize:.

Two judgement calls worth flagging

Svelte applies the font to the key label only, not the modifier strip above it. That strip is ⌘⌥⇧-style iconography and reads better kept in the system font; a decorative display face makes it much harder to parse at a glance.

Svelte's shrink-to-fit loop gained a minimum size. It previously ran while (size.width > frame.size.width - 10) fontSize -= 1.0; with no floor. That was unreachable with the system font, but a user-selectable wide face makes it reachable, so it now stops at 8pt.

Tests

New KCFontSelectionTests covers the resolution rules (unset, empty, installed, bold fallback, uninstalled family) and an integration test that instantiates the Default and Svelte preference views from their nibs and asserts each one has a font pop-up bound to its own key with a populated menu. That last one is what proves the nib wiring actually survives — the legacy wrapper.nib bundles can't be diffed usefully by eye.

To make the helper testable, NSUserDefaults+Utility.h is now a public header of the KCVisualizer framework.

Minimal isn't in that integration test because only KCDefaultVisualizer.kcplugin and Svelte.kcplugin are copied into the test bundle's plug-ins. Its pane is a plain xib and gets validated when the project builds; I verified all three panes' computed layouts by hand, including re-seating the separator boxes in Default and Minimal, which use autoresizing rather than autolayout and so don't move with the rest of the pane.

Both wrapper.nib bundles were recompiled with ibtool and produce no errors or warnings. The full test suite passes.

Closes keycastr#169.

Each of the three bundled visualizers already exposes a font size in its
preferences, but the typeface has always been hardcoded to the system font.
This adds a font family pop-up next to the existing size control in the
Default, Minimal and Svelte preference panes, stored per visualizer in
default.fontName / minimal.fontName / svelte.fontName.

KCFontPopUpButton builds its menu from NSFontManager's available families and
renders each family's name in that family, so the list doubles as a specimen
sheet. It reads and writes whichever defaults key the nib hands it through
fontFamilyDefaultsKey, which keeps one class serving all three panes.

Font resolution lives in -[NSUserDefaults fontForKey:size:bold:]. It answers
the system font when nothing is stored, and again when the stored family has
since been uninstalled or disabled in Font Book, so a visualizer always has
something to draw with. Minimal asks for bold and falls back to the family's
regular weight rather than substituting a different family when no bold face
exists. The stored value is deliberately left alone in that case, so
reinstalling a font restores the old selection.

In Svelte the chosen font applies to the key label only, not the modifier
strip above it, which reads better as system-font iconography. Its
shrink-to-fit loop also gained a minimum size, since a user-selectable wide
font makes a previously unreachable unbounded loop reachable.

NSUserDefaults+Utility.h becomes a public KCVisualizer header so the font
resolution is directly testable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Allow Changing Font

1 participant

0