The strangely difficult problem of drawing a box around text
blog.battlefy.com
blog.battlefy.com
Pagemaker - invalidated the font cache at the drop of a hat, spent all its time rebuilding it.
But Quark express was the hard one - it spent all its time multiplying (which was slowish on 680x0s) - turns out it used Adobe Type Manager (ATM) to render text and they had solved some pixel cruft problems by adding 2 spaces to the end of every string they rendered and clipping it to the desired space .... in other word they drew a box around it ... ATM solved this problem (clipping) by laying out a line (all those multiplications) and if it didn't fit it would split the line in two and try again - because of those 2 clipped spaces this resulted in N squared/2 behaviour (24 char text would do 24->12 12-> 6 6-> 3 3-> 2 1) and as a result the code spent all its time laying out the text over and over again and comparatively none actually drawing
So don't do that
I made an app that lets you highlight quotes on Apple devices and it was such a pain building it in Swift. Just highlighting so it would look absolutely beautiful took about a month (it was also my first time learning the language). I had to dig deep down into the way fonts worked. CGRect became my best friend.
Fun project, but there's a reason why you don't see a lot of apps replicating Medium.com's highlighting feature. I also believe it's why highlighting text on iOS devices breaks every couple of months.
It's literally built a top a mountain of chewing gum and sticks holding it together. It's a mess.
https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/...
Complicated...
Ludicrously difficult. I thought there would be a library for it or something.
I should make it open-source. I spent so much time on it and it doesn’t see much use. And I’m sure a lot of programmers could use it in a project somewhere.
It's not easy to read, but web specs are always written in over complicated and overly detailed prose that might as well have been written by a lawyer.
I enjoyed the project, but it was definitely rife with a lot of strange behavior layered on top of each other.
And Apple Documentation is a bit of a nightmare and basically useless in most cases.
.
L̷̛͎͈̗̜̼͚̔̋͌̈́̂i̶̗͓̹̭͉̘͒͗͗͗̿̉̑͜k̷̨̡͇̩̝̖͙̱͇͙͔̣̿̂͑̊͒̎̓̓̑ę̴̡̛͔̝͚̻͔͙̫̩͈̙̇̽́̔̆́̕͜ ̸̡̘̬͖́͒̄̂͗̑̕͘͝t̸̞͍̜͉̼͙̳̣̠̠́̉̈̊͜ḩ̵̞̪̟͙̲̤̐̓̒i̵̧̞̝̻̜̪̬̖̜̮̳̙͚̥͐͐͒͌̆̇͑́͌̒͠s̶̨͔̘̖̕
.
Draw a box around this. Oh, and they're called diacritic marks.
I didn't want to push the limit, but I think my comment with the diacritics could have covered other people's comments or the entire page.
Because even in his demo, you can see where he's not encapsulating all of the text space. The comma is cut. As would be any letter with a descender. Also any letter with an ascender or capital letter with a diacritic mark.
Also, he has some space before the first "B", but not after the last "x". Why doe the first letter get leading space but the last not get an equal amount of trailing space? Or is the kerning of the letters just concerned with leading space?
Here's an example https://jsfiddle.net/y4uk07jL/1/
If you want the box exactly like the author in the blog post (don't really know why anyone would want that?) you can do that by adjusting the line-height.
I can recommend Ellen Luptons book Thinking with type. Turns out some typographic problems was actually solved long before CSS and even computers. :)
[1]: https://docs.microsoft.com/en-us/typography/opentype/spec/he...
[2]: https://docs.microsoft.com/en-us/typography/opentype/spec/os...
But if you’re going to try to do anything fancy like this, it’s practically certainly better to do it as a build step, because otherwise you’ll be shipping extra parser code, doing extra work, and either loading the font twice or slowing down the CSS pipeline by putting JavaScript into the critical path. Also, remember that the font may not load (e.g. user preference overriding all fonts), so don’t depend on this sort of thing for fine detail unless you’ve confirmed the font is actually being used.
https://stackoverflow.com/questions/47538712/what-determines...
But for instance, towards the end the writer says: 'The next time somebody complains about paragraphs having inconsistent spacing when the font changes, I’ll know why and how to fix it.'. So, it looks like they care about h
[ I can't check out his example on my current device, so I don't know if it's scale/custom-css compatible or not. ]