Originally created by: Hema2-official
At a devicePixelRatio other than 1, the clone is laid out under zoom: <dpr> (#508), where text comes out slightly wider than on the page: up to 0.33px per line in Firefox, 0.01px in Chrome. A nearly full line then breaks a word early, and fixed-height boxes overflow.
This reads where each text node's lines break on the page and puts each line in a nowrap span, in a copy of the foreignObject that the SVG engine serializes. The clone itself is left untouched for burst.


On my test pages, lines that break differently from the page went from 1–83 per page to 0 in Firefox at 1.25–2×, and from 15–26 to 0 in Chrome. Captures take 2–6ms longer. npm run check and the new module.lineBreaks tests pass. Safari doesn't zoom the clone, so nothing changes there.
Originally posted by: tinchox5
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.
Originally posted by: tinchox5
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.
freezeOneLineinsrc/modules/styles.jsdoes something similar for one-line boxes and is a good place to start.If that turns out not to be possible, the last resort would be to run it only under the existing
reconcile: trueoption, which already means "exact layout, slower". I'd rather have it work for everyone by default, though.Originally posted by: Hema2-official
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
dev.Originally posted by: tinchox5
Great, thanks! I'll wait for the update.
And the optimization sounds very welcome. Besides speed, keep two limits in mind:
npm run test:fullcovers both.Another option is to base it on
dev. That branch is changing a lot right now, so if you can wait a few days until it settles, your work would land on the new structure and you wouldn't have to redo it.Originally posted by: tinchox5
Small update:
devnow has a change that touches the same area as this PR. Firefox no longer applies the layout zoom on 2x and 3x screens, so the early line breaks are gone there without any extra work per capture.What's left for your pass is Firefox at fractional scales (like your 1.25x example) and Chrome at 2x. Could you rebase onto
devand work from there? It will save you a conflict insvg.js, and with fewer cases to cover the cheaper version should be easier to reach.Originally posted by: Hema2-official
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.