Skip to content

fix(html): ink lands where the finger went under a fit the rects leave out - #918

Merged
andiwand merged 1 commit into
mainfrom
fix-ink-under-a-fit-the-rects-leave-out
Sep 20, 2026
Merged

andiwand merged 1 commit into
mainfrom
fix-ink-under-a-fit-the-rects-leave-out

Conversation

@andiwand

@andiwand andiwand commented Sep 20, 2026

Copy link
Copy Markdown
Member

Drawing on a pdf put the stroke about twice as far from the page's corner as
the finger went. OpenDocument.ios hits it on every phone; OpenDocument.droid
never did.

toBox mapped a pointer through page.getBoundingClientRect(). Every other
input to it is a rect — the glyph and run boxes the text marks are built from —
so the raw layout box is the space it is written against, and those cancel. A
pointer is the one input that does not arrive in it.

Measured in the app, on an iPhone 17 simulator:

page.getBoundingClientRect()  left 16.0   width 793.3
odr.getViewportRect(page)     left  7.8   width 386.6
page.offsetWidth              794
applied fit                   0.487

So the scale came out 0.999 where it should be 0.487, from an origin of 16.0
where the page is drawn at 7.8.

layoutScale now brings a pointer back into the rects' space before pageAt
and toBox see it. pageAt needs it too: it takes rects from pushBox and
pointers from onPointerDown, so with the spaces mixed a page far down the
list is picked wrong. It is read once per event, not per coalesced sample —
each read costs two layouts. Without viewport.js the scale is 1 and nothing
changes.

Chromium fits the page in the view itself, so odr's zoom stays 1, rectFactor()
is 1 and both rects agree. A webkit view does no such fit.

Checks

The browser suite cannot reach the case on its own, so the new check stands in
a getViewportRect that halves the box.

  • with the fix: 71 checks, 0 failed
  • with it reverted: 71 checks, 1 failed — the stroke lands at [45.1, 746.9]
    instead of [100, 692]

🤖 Generated with Claude Code

https://claude.ai/code/session_01XASU9ZfSJ6QwsAJGE3DrN1

…e out

The ink tool mapped a pointer through a page's own rect. Every other input
to that mapping is a rect, and a webkit view leaves the fit's zoom out of a
rect while a pointer carries it, so the stroke landed as far out as the page
is scaled - about twice, on a phone.

A pointer now comes back through `odr.getViewportRect` before the page is
picked and the point is mapped. Chromium reports both alike and was never
affected, so the new browser check stands in a rect of its own to reach the
case.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XASU9ZfSJ6QwsAJGE3DrN1
@andiwand
andiwand force-pushed the fix-ink-under-a-fit-the-rects-leave-out branch from 6a52189 to 5385c89 Compare September 20, 2026 17:28
@andiwand
andiwand merged commit 732968a into main Sep 20, 2026
25 checks passed
@andiwand
andiwand deleted the fix-ink-under-a-fit-the-rects-leave-out branch September 20, 2026 17:29
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.

1 participant