Improving the New York Times’ line wrap balancer
ctrl.blog
ctrl.blog
I think this isn't a failure of technical will, but scorn for non-JS users. At least on WP—I've never tried NYT without Javascript—disabling Javascript gets you past the paywall, and I assume otherwise cripples their tracking, so they don't want you there.
Well, this could also tell you just how few users disable Javascript. The numbers are so small, the Washington Post would rather let them read for free than update their paywall code and potentially convert them to subscribers.
Why not spend the effort exploring the problem at the browser implementation level? Is there opportunity to get NYT eng time dedicated to it?
> In 2013, Adobe proposed a new CSS text-wrap: balance property to make the browser do (and optimize) the heavy lifting. TextBalancer is a JavaScript implementation of this CSS property. The property has yet to be implemented into any web browsers. (Come on, guys! It’s in CSS Text Level 4.)
I'm not sure I agree, if it enhances readability. The users are there to read articles, so this is exactly the right place to spend spare CPU cycles.
Of course, it should be optimized as much as possible, and it sounds like the NYT's implementation was not very optimized. Then again, it also sounds like the NYT only briefly experimented with their version, and does not use it today.
> Why not spend the effort exploring the problem at the browser implementation level?
Well, but the NYT is not fundamentally a technology company, so pushing for browser changes seems beyond their scope IMO. Adobe did try, for their part.
Knuth-Plass is for setting all text to a specified width and balancing as best as possible within that, not having varying widths.
This was surprising to me. What are my options if I want to enforce consistent line breaks? I've thought about "freezing" line breaks by inserting <br/> tags, but to do that I would have to find out where the browser actually breaks the text, and I'm not sure how to go about that task.
If the screen resolution and scaling is the same, and the operating system is the same, then you should get very consistent results across operating systems. They use the same algorithm, but subpixel hinting may differ slightly.
If you stick to metrically compatible fonts for the different operating systems, you’ll get almost identical results across OSes too (assuming same screen resolution and scaling). https://www.ctrl.blog/entry/font-stack-text.html
One related thing I know for a fact is different between browsers is how they treat fractional line-height. While Firefox accurately scales the line-height along with a fractional font-height, Chrome notoriously snaps the line-height to an integer number.
Or so you'd think. On Linux Firefox, if you turn off system antialiasing using fontconfig, then glyph widths are quantized to integers. And due to a bug (https://bugzilla.mozilla.org/show_bug.cgi?id=1732577), turning off hinting but keeping antialiasing on does the same thing.
And I recall on Windows (Chrome?), if you zoom out a page until the text is really small, then the font stops shrinking when the zoom level decreases (causing text to take up more width than before).
You could generate a stylesheet with a stupid amount of generated breakpoints, or you could assume the user isn't going to resize the browser after loading the page. (Most won't, and if they do, the only consequence is non-ideal text wrapping).
The second problem is solvable though I think, by loading the JS text balancer asynchronously.
...oh, uh, no, that was dumb of me.
I do still wonder though if auto-generating a css file with lots of media queries would be feasible.
It can, yes. The response header `Accept-CH: Viewport-Width` suggest to the client that future request should transmit a `Viewport-Width: 320` header. Chrome only as the other browsers consider it harmful.
It doesn’t solve the problem, though. Font availability and subpixel rendering varies from OS to OS and browser to browser.