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");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:
inButton.setActionCommand("IN");
JButton outButton = new JButton("OUT");
inButton.setActionCommand("OUT");
GlyphVector glyphs = font.createGlyphVector("N");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.
ArrayListshapes = new ArrayList ();
for (int i = 0; i < glyphs.getNumberOfGlyphs(); i++) {
shapes.add(affineTransform.getTransformedShape(glyphs.get(i)));
}
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