cdk icon indicating copy to clipboard operation
cdk copied to clipboard

Molecule titles as Bounds

Open parit opened this issue 2 years ago • 3 comments

Hello, I was going through the code for org.openscience.cdk.depict.DepictionGenerator for drawing a reaction as svg. I noticed that a molecule's title is generated as a <path> element in the resulting svg instead of a usual <text>. Reading through the code, I noticed that titles are interpreted as org.openscience.cdk.renderer.elements.Bounds instead of org.openscience.cdk.renderer.elements.TextElement.

https://github.com/cdk/cdk/blob/82b1a3c6ffd06de262fc9fcdc9ddd4da836acf99/app/depict/src/main/java/org/openscience/cdk/depict/DepictionGenerator.java#L487

I am not sure why is this the case. Maybe someone from the cdk developers could throw light on this. My problem is that my titles are HTML strings with <sub> <sup> tags in there. These are not rendered correctly in the resulting svg.

parit avatar Jun 01 '23 15:06 parit

We renderer them as paths otherwise we don’t have correct sizing information and we want things to be consistent. We could make an option to not do this for the title though.

A work around is to use Unicode sub/super scripts instead of HTML. What I prefer to do is just not embedded the title, check out the advanced options on cdkdepict (www.simolecule.com/cdkdepict) you can embedded the title or render it in HTML

johnmay avatar Jun 02 '23 08:06 johnmay

Hello @johnmay I checked the cdkdepict, my problem is that I am rendering an entire reaction, so can't use the similar logic of showing the name at the bottom is each molecule (as is in the example) without embedding it. Do you know a way to associate metadata like custom class name to the <g> tag surrounding the title? Right now there is no way to associate title to the molecule in the svg. 10001

parit avatar Jun 06 '23 11:06 parit

There is no way to currently do it then, a new option "NonRenderedTitle" option which by passes the rendering would do the trick. Please feel free to submit a patch

johnmay avatar Jun 06 '23 11:06 johnmay