logoalt Hacker News

thrdbndndntoday at 1:53 AM4 repliesview on HN

I love this kind of stuff (ASCII art, if you will), but it just breaks down too easily as soon as Unicode characters (mainly CJK, as I'm Chinese) and fonts are involved.

For example, on your website, any chart or plot involving horizontal arrows breaks down because the assigned font-family (`ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`, which ends up as Consolas on my machine) has no such glyph. Thus, it falls back to Segoe UI Symbol, which does not have the same fixed width (or is not fixed-width at all) as other characters: https://i.imgur.com/d2DPGHE.png


Replies

numpad0today at 5:57 AM

Aren't those non-ASCII "rich" symbols from Japanese fonts around PC-98/Win95 domains anyway? For me with my background, it was always obvious that mixing full-width character in ASCII text never go well for various reasons. For ASCII arts, it is obvious that vertical lines never line up, and there are going to be tons of wasted spaces and different kinds of whitespaces needed to compensate for those. I wonder if specifying MS Gothic and retuning widths for it could help, at least for Windows/Linux.

show 1 reply
uhoh-itsmaciektoday at 2:11 AM

I ran into this problem recently on one of our blog posts: we used some Claude output which included tables drawn with Unicode line drawing characters. However, our monospace font did not include these characters, and so rendering fell back to another font in our font stack with different width metrics. I fixed it by using a font that had similar metrics and did include those characters with `unicode-range` (to only select characters we needed) and `size-adjust` (to match font width more exactly), and adding it to the stack. It's a little hacky but works pretty well in practice.

biztostoday at 4:15 AM

Interesting. Thai characters can also blow it out, I imagine because of the difficulty mapping glyphs to width:

https://biztos.com/hey/thai-mermaid-chart.png

To my surprise, Sublime Text gets it almost right:

https://biztos.com/hey/sublime-thai-mermaid.png

I tried finding a Thai monospace font and using that in the HTML but it was worse, probably didn't have the box drawing chars.

Still a fun tool and useful for lots of ASCII cases!

show 1 reply
pmarrecktoday at 2:11 AM

I was going to say, perhaps generate a failing test case, but testing for proper unicode rendering might be tricky??