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:
@@ -97,6 +97,30 @@ Conversions:
|
||||
- screen → app-local: **Y − 128** (surface starts below the status bar; X unchanged)
|
||||
- app-local px → pt: **÷ 2.625** (density 420)
|
||||
|
||||
There are TWO independent scale factors, not one:
|
||||
|
||||
- **Density** (`PxPerDp`, 2.625 here): the px↔dp conversion above. All
|
||||
geometry bookkeeping is in density-dp, so the pipeline is scale-free and
|
||||
holds at any display density (verified algebraically; the tap/scroll proof
|
||||
in Phase 10 uses no device numbers).
|
||||
- **User font scale** (`PxPerSp/PxPerDp`, e.g. `settings put system
|
||||
font_scale 1.3`): scales the *text* only (the shaper draws in sp), so the
|
||||
rendered line pitch is `16.8 × fontScale` dp. The logic side tracks this
|
||||
via `EffectiveLineHeight()` and every line-height consumer uses it
|
||||
(window start, sub-line remainder, tap mapping, scroll clamp, caret,
|
||||
handles, highlight). Change it and the line pitch on screen changes
|
||||
(57 px/line at 1.3× vs 44 px/line at 1.0× on this AVD).
|
||||
|
||||
On-device verification notes:
|
||||
|
||||
- The profiler CSV (`/storage/emulated/0/PadPerf/logic_frames.csv`) flushes
|
||||
to disk at most every 2 s, so `tail` can be up to 2 s stale — a scroll
|
||||
fling still settling reads as "settled" if two reads fall in the same
|
||||
flush window. Compare rows ≥ 2.5 s apart, taken after the last input.
|
||||
- The tap test is the ground truth and does not depend on the profiler:
|
||||
screenshot → visually identify a line → tap it → type a marker → read the
|
||||
file off the device → the marker must be on exactly the tapped line.
|
||||
|
||||
Full pipeline, screen → file byte (each hop has exactly one place it
|
||||
happens; the app is internally consistent, so errors only appear at the
|
||||
hops, not inside a space):
|
||||
|
||||
@@ -246,6 +246,19 @@ Only the visible byte range is shaped and drawn each frame:
|
||||
a float64 mod still reflects the line below, so the window start and the
|
||||
remainder disagree by one line in a sub-pixel-wide band of offsets and the
|
||||
whole rendered window (hence every tapped line) shifts by one.
|
||||
- **Font-scale axis.** The shaper draws baselines in sp, so on Android the
|
||||
rendered line pitch in density-dp is `EditorLineHeight()*fontScale`
|
||||
(`fontScale = Metric.PxPerSp/PxPerDp`, the user font-size setting).
|
||||
Every consumer of `lh` above therefore uses `EffectiveLineHeight()` (the
|
||||
font-scale-applied value, tracked in `State` via `ScaleEvent.FontScale`),
|
||||
and the renderer's `GlyphLayout.LineHeight`, caret, handles, and selection
|
||||
highlight use the same scaled pitch. With the raw line height, a
|
||||
non-default font setting would misplace taps by up to (fontScale-1)
|
||||
viewportfuls of lines and make scroll clamping stop short of (or run past)
|
||||
the file ends. Density itself (pure hi-DPI) is a separate axis: all
|
||||
geometry bookkeeping is in density-dp and scale enters only at the px↔dp
|
||||
conversion (single `r.scale`/`State.scale`), so the invariant above is
|
||||
scale-free and holds at any display density.
|
||||
- **Never shape the whole file.** Lesson learned (Phase 3): the shaper's
|
||||
internal `document` retains the backing array of its largest layout forever
|
||||
(`reset()` keeps the cap), so one whole-file layout permanently inflated
|
||||
|
||||
+45
-2
@@ -1,9 +1,10 @@
|
||||
# Development Plan: reach a lean, usable Android text editor
|
||||
|
||||
Status: v9, 2026-08-17 (Phases 0–3 + doc reorg + Phase 6 scroll-perf/clamping
|
||||
Status: v10, 2026-08-17 (Phases 0–3 + doc reorg + Phase 6 scroll-perf/clamping
|
||||
verification + tap-to-position-cursor fix + selection + real-file e2e +
|
||||
Android arrow/shift workaround + touch selection + scroll-offset tap proof &
|
||||
float32 decomposition fix). Written
|
||||
float32 decomposition fix + font-scale (user font-size setting) support).
|
||||
Written
|
||||
against the **live** repo `/home/gmp/pad`. v1 (the widget-rebuild plan) is
|
||||
superseded — see §12 for why. Doc reorganization (2026-08-16): the over-detailed
|
||||
docs (`*_implementation_plan.md`, `touch.md`, `element_model.md`,
|
||||
@@ -454,6 +455,48 @@ now fixed and property-tested.
|
||||
of a 300-line file). Screenshot, profiler ScrollDP, formula, and disk all
|
||||
agreed.
|
||||
|
||||
### Phase 11 — hi-DPI / font-scale audit and font-scale fix — DONE (2026-08-17)
|
||||
|
||||
Question: does the tap/scroll mapping hold under all allowed device display
|
||||
configurations, or only on this AVD's density?
|
||||
|
||||
- **Density (pure hi-DPI): holds, provably.** All geometry bookkeeping is in
|
||||
density-dp; the device scale enters only at the px↔dp boundary via a single
|
||||
`r.scale`/`State.scale` (= `PxPerDp`), with sub-pixel float32 rounding that
|
||||
cannot cross a line boundary. The Phase 10 invariant uses no device numbers,
|
||||
so it is scale-free: any density.
|
||||
- **Font scale (user font-size setting): was broken, now fixed.** On Android,
|
||||
`PxPerSp = fontScale × PxPerDp` (the Settings → font-size knob), and the
|
||||
shaper draws baselines in sp — so at, say, fontScale 1.3 the rendered line
|
||||
pitch is 21.84 dp while every logic-side consumer used the raw 16.8 dp.
|
||||
Taps would have been off by up to (fontScale−1) viewportfuls of lines and
|
||||
scroll clamping would have stopped short of the file bottom. Fixed by
|
||||
tracking `fontScale` in `State` (`ScaleEvent.FontScale`, closed loop via
|
||||
`Frame.FontScale`) and routing every line-height consumer through
|
||||
`EffectiveLineHeight()` (window start, sub-line remainder, tap mapping,
|
||||
scroll clamp, page size, cursor vertical move, menu position), with the
|
||||
renderer using the same scaled pitch for `GlyphLayout.LineHeight`, the
|
||||
caret, selection handles, and highlight (ascent/line-height in
|
||||
`drawWrappedText` now `× fontScale` from `gtx.Metric`).
|
||||
- **Proof:** `font_scale_test.go` — `TestTapPosition_FontScale_Property`
|
||||
(2000 random scroll/tap pairs at fontScale 1.3 with the glyph layout
|
||||
fabricated at the scaled line pitch, same independent ground truth as
|
||||
Phase 10) plus an `EffectiveLineHeight` unit test. Existing tests are
|
||||
unaffected (unknown fontScale ⇒ 1.0).
|
||||
- **On-device cross-check:** with `settings put system font_scale 1.3` and
|
||||
`0.8`, at multiple scroll positions (including a settled one where the
|
||||
topmost visible line was verified to be exactly k = floor(s/lh_eff)), a tap
|
||||
on a visually identified line typed a marker that landed on exactly that
|
||||
line in the file on disk (fsline060, fsline080, fsline081 at 1.3×; fsline039
|
||||
at 0.8×). Rendered line pitch measured 57 px at 1.3× and 35 px at 0.8× vs
|
||||
44 px at 1.0× — matching 16.8×fontScale×2.625.
|
||||
- **Verification-method note:** the profiler CSV flushes to disk at most every
|
||||
2 s, so `tail` reads can be up to 2 s stale (a settling fling reads as
|
||||
"settled" if two reads land in the same flush window). Settle checks compare
|
||||
rows ≥ 2.5 s apart after the last input; the tap test (screenshot → tap →
|
||||
marker → read the file off the device) is the ground truth and needs no
|
||||
profiler.
|
||||
|
||||
## 6. File-size decision (re-framed)
|
||||
|
||||
v1 framed this as "accept a limit vs build a windowed editor." The live repo
|
||||
|
||||
Reference in New Issue
Block a user