Expose fontKerning option in prepare() — align measurement with rendering
Problem
pretext's core value is "accurate measurement without DOM reflow". However, measurement is always locked to the browser default kerning ("auto", which typically applies kerning) because prepare() never sets ctx.fontKerning when measuring with measureText().
When a consumer renders with kerning disabled (font-kerning: none / ctx.fontKerning = "none"), pretext's measured widths no longer match the rendered text, causing bounding-box / layout mismatches.
So this isn't really "I want kerning off" — it's that there's no way to align the measurement's kerning mode with the actual rendering. Today PrepareOptions only exposes whiteSpace, wordBreak, and letterSpacing.
Proposal
Add an optional fontKerning to PrepareOptions:
export type PrepareOptions = {
whiteSpace?: WhiteSpaceMode
wordBreak?: WordBreakMode
letterSpacing?: number
fontKerning?: 'auto' | 'normal' | 'none' // default 'auto' (current behavior)
}
Then set ctx.fontKerning alongside ctx.font in the measurement path.
Defaulting to 'auto' keeps the current behavior intact. Users who render with kerning are unaffected; users who render with a different kerning mode can align measurement with their rendering. → non-breaking.
Note on caching
Segment widths are cached by (segment, font). Since kerning mode affects width, the cache key needs to include fontKerning (e.g. (segment, font, fontKerning)) so a width measured under a different kerning mode isn't reused incorrectly.
Happy to open a PR if this direction sounds good.
Source: chenglou/pretext