Padding mixed CJK/ASCII input for monospaced output

82 Views Asked by At

I have been trying to solve this for some time. I have a need to output console stuff like:

          ABC-花海 | 123 | 456789
     JustSomeAnsi | 123 | 456789
       花花花花花花 | 123 | 456789
     追不到我别生气 | 123 | 456789

Now I know perfect alignment is not possible, but the example above would be tolerable to me. The question is how would you figure out how much to pad and with what space char.

If context is relevant, this is being output into Unreal Engine console. I've already have replacement for original Roboto font - either Sarasa Gothic or GNU Unifont or just any normal monospaced font like Fira Code + fallback for CJK (DroindSans right now, but it is not monospace)

1

There are 1 best solutions below

2
On

In Unicode, there are fullwidth versions of ASCII characters compatible with CJK in the U+FF00 code point block (See Unicode code chart).

Here is your text using only fullwidth characters, including IDEOGRAPHIC SPACE U+3000:

           ABC-花海 | 123 | 456789
     JustSomeAnsi | 123 | 456789
           花花花花花花 | 123 | 456789
          追不到我别生气 | 123 | 456789

Also see this answer for a related Python-coded example that translates ASCII to the fullwidth forms.