3

Does anyone know of an existing solution for font glyph fallthrough in Java? For example, our designers have decided that Calibri is the font that mostly fits our needs, but if I specify Calibri, it can naturally not render characters that do not have a matching glyph in that font. In that case, I would need it to fall through to a second specified font, and if all else fails - use one of Java's logical fonts.

Has anyone come up with a solution for this, which can be plugged into existing Swing components without having to write custom Swing components for the entire project?

This is a very old project already, and building custom graphical components is not a feasible solution.

melladh
  • 133
  • 2
  • 9

1 Answers1

1

This isn't a code-based solution and probably won't be of much help, since it requires each user to install a file locally, but just in case...

You can add fallback fonts in a special directory within the JRE installation. From the Java documentation:

Users can add a physical font as a fallback font to logical fonts used in Java 2D rendering by installing it in the lib/fonts/fallback directory within the JRE.

VGR
  • 40,506
  • 4
  • 48
  • 63
  • That's more fallback FROM logical, but is there any way to make a fallback TO logical, if my chosen font is missing a character? – melladh Dec 19 '14 at 12:35
  • I see what you mean. The fallback directory only works for logical fonts, which limits its usefulness. What about using HTML to force the font for unusual characters? For instance, instead of `new JLabel("Testing: \u2588 \u2592 \u259a \u259e")`, you can do `new JLabel("Testing: \u2588 \u2592 \u259a \u259e")`. – VGR Dec 19 '14 at 15:35
  • Unfortunately I need a solution to plug in more or less invisibly - the characters are not really known beforehand, and changing each individual swing component would take ages and result in a frail solution as it's not intuitive for future programmers to imitate instead of just making a label normally. – melladh Dec 20 '14 at 16:13
  • The only other thing I can think of is creating a custom Swing look-and-feel. Wish I could think of something that won't be so much of a headache. I don't suppose you can point out to your designers that, aesthetics aside, Calibri is not practical since it doesn't support the all of the characters required by the application. – VGR Dec 21 '14 at 05:37