21 ms·
Wait, like this? https://codepen.io/cperardi/pen/VwPmMrM https://codepen.io/cperardi/pen/VwPmMrM I would have no expectation at all that would work without sp
by perardi 6y ago
Wait, like this?
https://codepen.io/cperardi/pen/VwPmMrM https://codepen.io/cperardi/pen/VwPmMrM
I would have no expectation at all that would work without specifying a specific font. Fonts just have different horizontal metrics. That doesn't seem to be a bug, so much as “fonts are different, if you want very specific space-constrained rendering, you should explicitly specify a font, and ideally serve it so all platforms get the exact same font metrics”.
- perardi 6y ago(Or convert to outlines, and then embed some sort of metadata for accessibility and machine readability. But that’s probably overkill.)
- runarberg 6y agoAs a user I sometimes need to select a part of the text and copy to my clipboard
- jancsika 6y ago> you should explicitly specify a font, and ideally serve it so all platforms get the exact same font metrics Oh wow, do I have news for you. The hidden premise of my quest is that: 1. I'm shipping a fixed-width font and using it on every browser/platform combo. 2. I'm setting the same exact pixel font size that is being used on every browser/platform combo. (Well, I was until I found this discrepancy-- read below.) 3. The font metrics are different across all platforms! Now, normally this shouldn't matter. The rendered width differences across, say, OSX and Windows are so small that we're talking a fraction of a pixel for a small test string. But at some point in the past five years, somebody made a change in the Gnu font-rendering stack that made it an outlier in terms of rendered width. The same small test string would be greater than a pixel wider than the other systems. So for a medium to long string the width is different enough that in general you'd need to set a smaller pixel width for the recent Gnu systems if you want to get close to the same width as the other systems. There's no spec about these metrics, so there's absolutely nothing I can do about the discrepancy. Welcome to the Font Rendering Matrix! I maintain a diagram-based language that has text in boxes connected by lines. On OSX and Windows the box is tight-fitting around the text. But on recent Ubuntu the box has empty space at the right-- this is because I had to choose a smaller font-size for Linux to keep the wider text from overlapping the box. Once the renderer does all its font business with the smaller font (and I am not limited myself to integer numbers, btw), the width of the Gnu-rendered string is noticeably less wide than what would be rendered on OSX/Windows. However, I must keep the box at the same dimensions as it would display on OSX/Windows-- otherwise a user on Ubuntu could place two boxes side by side and cause an overlap when opened on OSX/Windows. So I'm forced to make things a bit ugly on Ubuntu to retain compatibility across platforms, and introduce Ubuntu users to The Font Matrix problem if they happen to complain. Edit: clarification