Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How could end users reasonably solve this?

You can’t know exactly how text will be laid out, so I can only imagine using… canvas and doing your own font rendering? Which sounds horrible for all number of reasons.



More importantly, why should they?

I mean, yeah, I guess giving end users that level of control is a good thing, just like how they can decide the default font style of their browser.

But it's not the user's job to fix your web page.

How text is rendered on a page is a result of intention. The web developer should be able to implement the design intent of a body of text and either allow it to widow where it makes sense or force the text to balance. The problem is that the tool for that simply doesn't exist without some JavaScript foolery, not that the user can't toggle something to make it happen.

> so I can only imagine using… canvas and doing your own font rendering? Which sounds horrible for all number of reasons.

It's both horrible and not.

Canvas can be used merely to make appropriate calculations for text given that it is aware of the size of any font it is using. Rather than rendering with a canvas directly, it could be used to efficiently determine what the width of an element containing text should be to make it "balanced", and maybe where to stick `<br>`.

This has basically nothing specifically to do with widowing, but I once implemented the approach of using canvas to do calculations for actual page text. The goal was to make it so that a given text would always fit the size of its containing element no matter how long the text. In other words, if the container has a fixed height and width, like if you wanted for whatever reason to render the Declaration Of Independence in a 300x300 div, it will find the correct font size to squeeze that whole thing into that div.

https://codepen.io/Ravenstine/pen/QdRYeq

Of course it will get slower the more text it has to calculate. Kinda tempted to see if WASM speeds it up any.

I think it's a poor idea to try to polyfill text balancing in that way, but I think it can be done and in a way that doesn't sacrifice rendering actual text.

EDIT: I realized I contradicted myself.


Its not my problem to solve, that's the whole point. Its a niche enough need that it shouldn't even be part of CSS. people who have a need for it, should figure out some solution on their own, not force their complication onto the entire spec itself.


This isn’t niche at all, this has been a problem on many of the sites I’ve worked on. And the comment above is right, this is a rendering engine issue, there’s not really much you can do as an end-user.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: