Repository navigation
fix(svg): keep the page's line breaks under the layout zoom - #565
Conversation
|
Thanks a lot for this. The write-up is clear and the fix does what it says. However, I can't merge it as it is because of speed, which is the first rule of the project, but I think a much cheaper version is within reach and I'd love for you to take it there. Give me some time to provide you and idea to get the same but cheaper. |
|
Could you look into a way to detect only the risky cases, instead of applying it to every line? From what I saw, the only lines that break early are the ones that almost fill their box on the page; a line with room to spare never moves. If the pass can find those cheaply and leave the rest alone, most captures would pay close to nothing. If that turns out not to be possible, the last resort would be to run it only under the existing |
|
That's valid. I'm looking into it. Thanks! Regarding performance: on the side, I'm working on verifying some optimizations related to listing nodes and styles. If everything goes well, expect -20% in initial capture time. I'm watching out not to replicate changes on |
|
Great, thanks! I'll wait for the update. And the optimization sounds very welcome. Besides speed, keep two limits in mind:
Another option is to base it on |
|
Small update: What's left for your pass is Firefox at fractional scales (like your 1.25x example) and Chrome at 2x. Could you rebase onto |
|
As for your older comment: ofc, identical results are a must, I'm paying attention there. Otherwise wow, that's amazing! I'm gonna rebase to dev as soon as I'm free. |
|
Alright, the dev branch is "stable", so please work with it. First, we should solve the zoom issue you detected. And, then your speed improvements. So you can propose several PRs. Thank you! |
Under the layout zoom (zumerlab#508), Firefox lays a line of text out up to 0.33px wider or narrower than the page, and Chrome puts box edges on the zoomed 1/64px grid. A nearly full line broke a word early. The SVG engine now serializes a copy of the tree with each live line in a `nowrap` span, and each inline-block or image that shares a line in one of its own, so the shot wraps only where the page did. The clone stays intact for burst. Lines breaking differently from the page went from up to 76 per page to 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pinning every line cost Chrome 5-12% of a capture. The pass now compares each line's room, and in Firefox the next line's first word, with how far the engine can drift, and pins only the inline formatting contexts at risk or the ones it cannot read that way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
aefea55 to
849a2a5
Compare
|
I updated the base branch and the code. Now it takes up to 34ms less than the original version. WebKit measurements are missing due to my development setup being weird asl. I'd appreciate it much if you or anyone else could provide those... Optimization PR incoming soon(TM). |
At a devicePixelRatio other than 1, the clone is laid out under the layout zoom (#508), and its text doesn't wrap quite like the page's. In Firefox at fractional scales, a line comes out up to 0.33px wider or narrower. In Chrome, box edges land on the zoomed 1/64px grid. A nearly full line then breaks a word early, and fixed-height boxes overflow. In Firefox, a short word can also move up a line.
This reads where each text node's lines break on the page and pins the lines at risk: each one goes into a
nowrapspan, in a copy of theforeignObjectthat the SVG engine serializes. The clone stays intact for burst. An inline-block or image that shares a line gets a span of its own, so the line can't break beside it either.A line is at risk when its room is within the drift the engine can add. In Firefox, it's also at risk when the next line's first word would fit within that drift. The bound grows with the characters on the line in Firefox and with the box edges in Chrome. A context it can't judge that way, such as bidi, justified text, columns, floats or a CSS zoom, is pinned whole. The pass runs only when the layout zoom isn't 1, so Safari, 1× screens and Firefox at 2× and 3× skip it.
On my test pages, lines that break differently from the page went from 1–76 per page to 0 in Firefox at 1.25× and 1.5×, and from up to 26 per page to 0 in Chrome at 1.25× and 2×.
snapdom()plustoCanvas()takes longer:npm run checkpasses, and the newmodule.lineBreakstests pass. The Chromium suite shows no new failures. I haven't run the Firefox and WebKit suites.