Font Management and GlyphVectors

Fonts and text are always a pain when drawing vector graphics!

After hitting myself over the head over a stupid bug in my zoom tests (like this:)
JButton inButton = new JButton("IN");
inButton.setActionCommand("IN");
JButton outButton = new JButton("OUT");
inButton.setActionCommand("OUT");
I got center scaling implemented in my branch. Which lets me test a different approach to managing fonts. I had tried to be clever and do something like:
GlyphVector glyphs = font.createGlyphVector("N");
ArrayList shapes = new ArrayList();
for (int i = 0; i < glyphs.getNumberOfGlyphs(); i++) {
shapes.add(affineTransform.getTransformedShape(glyphs.get(i)));
}
but letter shapes fill horribly with lots of missing pixels. Anyway, I eventually settled on just storing the Glyphs themselves. Less pure, but it works, and it allows the size of TextSymbols to be computed and used by the class in between drawing.

So, for fonts there had to be a way in my architecture to change the font size when the whole molecule is scaled. The nicer approach is the obvious one - just to transform the Graphics object. However, it turns out there are advantages to the more cumbersome approach. Here's an image:
which shows rings at various sizes, with the numbers at their centers showing the font size at that scale. An important one is the 'size' (9-5) - which is 4, but there is no readable size of font at that size. However, the FontManager class keeps track of how far below (or above) the minimum and maximum font sizes, and then returns to that size at the appropriate point.

Comments