Skip to content

core: let a font ask for tracking - #1

Open
Colin-Hayes wants to merge 3 commits into
masterfrom
codex/font-letter-spacing
Open

core: let a font ask for tracking#1
Colin-Hayes wants to merge 3 commits into
masterfrom
codex/font-letter-spacing

Conversation

@Colin-Hayes

Copy link
Copy Markdown

Cosmic Text has carried letter spacing all along; nothing above it could ask for it. A design that specifies tracking on its labels had no way to say so, and uppercasing a label is not the same thing.

Font gains a Tracking, expressed as a fraction of the type size so a heading and a caption asking for the same tracking stay proportionate to one another. Cosmic Text takes em as well, so the value passes through unscaled, and it is left unset when it would change nothing — a font asking for no tracking keeps whatever the face itself specifies.

Font is a hash key throughout the text pipeline, so Tracking compares and hashes by bits, canonicalizing the two values that would otherwise break the Eq/Hash agreement: NaN, which is never equal to itself, and negative zero, which is equal to zero while their bits differ. That is the same treatment Cosmic Text gives its own wrapper.

Additive: Font::DEFAULT and every existing constructor leave tracking unset, so nothing that does not ask for it changes. iced_core, iced_graphics, iced_widget, iced_runtime and iced_winit all build unchanged.

Four tests cover the default, that tracking takes part in equality and hashing, that the awkward float values keep Eq and Hash in agreement, and that only a real tracking counts as set.

Consumed by MicroPerceptron/vkore#18 and MicroPerceptron/axiom#84.

Cosmic Text has carried letter spacing all along; nothing above it could ask
for it. A design that specifies tracking on its labels had no way to say so,
and uppercasing a label is not the same thing.

Font gains a Tracking, expressed as a fraction of the type size so a heading
and a caption asking for the same tracking stay proportionate. Cosmic Text
takes em as well, so the value passes through unscaled, and it is left unset
when it would change nothing -- a font asking for no tracking keeps whatever
the face itself specifies.

Font is a hash key throughout the text pipeline, so Tracking compares and
hashes by bits, canonicalizing the two values that would otherwise break the
Eq/Hash agreement: NaN, which is never equal to itself, and negative zero,
which is equal to zero while their bits differ. That is the same treatment
Cosmic Text gives its own wrapper.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 3, 2026 02:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Adding a new public field to Font is a breaking public API change and needs an explicit API/semver decision (or an alternative approach) before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR extends the text/font pipeline so a Font can request glyph tracking (letter spacing) and have it propagated into the cosmic_text::Attrs used by the graphics text backend.

Changes:

  • Introduces a new Tracking(f32) type and adds it to core::Font, including Eq/Hash behavior that remains consistent for NaN and -0.0.
  • Adds a Font::tracking(...) setter and defaults tracking to “unset/no-op” so existing constructors keep prior behavior.
  • Updates the graphics text attribute conversion to set cosmic_text letter spacing only when tracking is non-zero, and re-exports Tracking from iced_core.
File summaries
File Description
core/src/font.rs Adds Tracking, integrates it into Font, and adds unit tests for equality/hashing/default semantics.
core/src/lib.rs Re-exports Tracking alongside Font for public API access.
graphics/src/text.rs Applies Font::tracking to cosmic_text::Attrs via letter_spacing when non-zero.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread core/src/font.rs
Comment on lines 62 to 66
/// The [`Style`] of the [`Font`].
pub style: Style,
/// The [`Tracking`] of the [`Font`].
pub tracking: Tracking,
}
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.

2 participants