-1

I have hexdump view in my application: enter image description here

I use Courier New font in java:

private final Text contentText;

contentText.setFont(Font.font("Courier New"));

But as you can see some unicode signs have more width. There is some way or another font which make all signs with equal width?

xav9211
  • 191
  • 1
  • 3
  • 14
  • You may look into this: http://denisbider.blogspot.fr/2015/09/when-monospace-fonts-arent-unicode.html – dotvav Sep 21 '15 at 15:00
  • 3
    while interesting to know, this is not really the kind of question Stackoverflow is for. This isn't a question about solving a programming problem: you discovered that a font that is marked as monospace is not true monospace across all its characters. If you want to know why, that's an excellent question to ask in a typography forum, not here. – Mike 'Pomax' Kamermans Sep 21 '15 at 16:06
  • Short answer is: *you can't rely on anything being monospaced*. I don't know all details either. AFAIK courier New is true monospace, but modern systems use glyphs from other fonts if a character is not found in the specified font. Also a combining character like *U+0300 — COMBINING GRAVE ACCENT* doesn't occupy any space. – roeland Sep 21 '15 at 23:22

1 Answers1

1

You're seeing the results of font fallback, which substitutes something other than the original font you specified when you try to render characters that aren't in that font. In this case, the kana and several other characters (Won sign, others) are not present in Courier New, so you get some other font whose metrics do not match those of Courier New.

There's no simple solution to this, particularly if you expect to be displaying a wide range of characters. What you could possibly do is set up a filter, as many hex editors do, and just show a '.' or similar for anything non-ASCII (or in this case you might be able to do a little detective work and set it up to show '.' for anything that is not present in Courier New font).

djangodude
  • 5,362
  • 3
  • 27
  • 39