Track Android user font scale in all line-height geometry (Phase 11)
Density (pure hi-DPI) was already scale-free: all bookkeeping is in density-dp and the scale enters only at the px<->dp boundary. But Android also has a second axis, the user font-size setting (PxPerSp = fontScale * PxPerDp), and the shaper draws baselines in sp. At a non-default font scale the rendered line pitch is 16.8*fontScale dp while every logic-side consumer used the raw 16.8 dp: taps would misplace by up to (fontScale-1) viewportfuls of lines and scroll clamping would stop short of the bottom. - ScaleEvent.FontScale + Frame.FontScale closed loop (main reads gtx.Metric, logic tracks it in State.fontScale). - EffectiveLineHeight()/EffectiveLineHeightAt(): the font-scale-applied line height, now used by every consumer (window start, sub-line remainder, tap mapping, scroll clamp, page size, cursor vertical move, menu position, chunk-prefetch fallbacks). - Renderer: GlyphLayout.LineHeight, caret, selection handles, and highlight all use the scaled ascent/line-height from gtx.Metric. - font_scale_test.go: 2000-pair tap property test at fontScale 1.3 with the glyph layout fabricated at the scaled pitch (independent ground truth), plus EffectiveLineHeight unit test. - On-device: tap markers landed on exactly the tapped line at font_scale 1.3 (fsline060/080/081) and 0.8 (fsline039); rendered pitch measured 57/35/44 px at 1.3/0.8/1.0 (matches 16.8*fs*2.625); settled-position window start k = floor(s/lh_eff) verified against the visible top line. - Docs: architecture.md 6.2 font-scale axis, README two-scale note + profiler 2s flush staleness note, development plan v10 Phase 11.
This commit is contained in:
+11
-2
@@ -146,6 +146,14 @@ func run(w *app.Window) error {
|
||||
}
|
||||
gtx := app.NewContext(&ops, e)
|
||||
newScale := gtx.Metric.PxPerDp
|
||||
// User font-size setting: the shaper draws baselines in sp, so the
|
||||
// rendered line pitch in density-dp is scaled by this factor. Logic
|
||||
// bookkeeping (tap mapping, window start, scroll clamp) must follow
|
||||
// it (EffectiveLineHeight).
|
||||
newFontScale := float32(1)
|
||||
if gtx.Metric.PxPerDp > 0 && gtx.Metric.PxPerSp > 0 {
|
||||
newFontScale = gtx.Metric.PxPerSp / gtx.Metric.PxPerDp
|
||||
}
|
||||
// Clipboard: forward a read result from an earlier frame to the
|
||||
// logic goroutine (one DataEvent per ReadCmd).
|
||||
for {
|
||||
@@ -187,6 +195,7 @@ func run(w *app.Window) error {
|
||||
if curScale <= 0 {
|
||||
curScale = 1 // no frame yet
|
||||
}
|
||||
curFontScale := frame.FontScale // 0 until the logic has the value
|
||||
renderer.Draw(gtx, frame.Elems, curScale)
|
||||
glyphLayout := renderer.GlyphLayout()
|
||||
// Send search query update to the logic goroutine when it changes.
|
||||
@@ -269,8 +278,8 @@ func run(w *app.Window) error {
|
||||
}
|
||||
e.Frame(&ops)
|
||||
mu.Unlock()
|
||||
if newScale != curScale {
|
||||
logic.ConfigChan() <- editor.ScaleEvent{Scale: newScale}
|
||||
if newScale != curScale || newFontScale != curFontScale {
|
||||
logic.ConfigChan() <- editor.ScaleEvent{Scale: newScale, FontScale: newFontScale}
|
||||
}
|
||||
if len(events) > 0 {
|
||||
logic.InputChan() <- events
|
||||
|
||||
Reference in New Issue
Block a user