In fact, besides these points, it basically just comes down to replacing the BasicAtomGenerator with the ExtendedAtomGenerator. Except a bug I found. I'll fix that in the next release, but right now, the extended atom generator requires the AtomNumberGenerator to be loaded as well, and thus we also must turn atom numbering off. Therefore, we basically get this code snippet (here's the full code):
// generators make the image elements
List<IGenerator> generators = new ArrayList<IGenerator>();
generators.add(new BasicSceneGenerator());
generators.add(new BasicBondGenerator());
generators.add(new AtomNumberGenerator());
generators.add(new ExtendedAtomGenerator());
// the renderer needs to have a toolkit-specific font manager
AtomContainerRenderer renderer =
new AtomContainerRenderer(generators, new AWTFontManager());
// disable atom number rendering
model = renderer.getRenderer2DModel()
model.set(WillDrawAtomNumbers.class, Boolean.FALSE)
As said, this code will be simpler in the next CDK-JChemPaint release. The results looks like:
As you can see by the amount of whitespace around the carbon, the scaling issue has not been resolved yet :(
Drawing isotope information works pretty much in the same way. In fact, we do not even have to change the rendering code, and the ExtendedAtomContainer automatically adds the isotope information (and no, indeed, not in the expected superscript fashion; so, another thing to fix):
But alas, there are always things to fix. I'm personally not aesthetically pleased with the kerning of just CH4 either.


Just keep at it, it's a great piece of sowftware and we appreciate your work :). Spacing bug or not I'm quite happy with it.
ReplyDeleteThanx, Ryan!
ReplyDeleteI cannot seem to find WillDrawAtomNumbers.class. Is it part of the CDK or JChempaint?
ReplyDeleteHi Gengnom,
ReplyDeletethe WillDrawAtomNumers is an inner class of the AtomNumberGenerator which can be found in the cdk-jchempaint-XX.jar downloadable from this repository:
https://github.com/egonw/groovy-jcp
Egon
Thanks
ReplyDelete