Skip to content

Commit

Permalink
Abbreviation labels can now go above/below the labels.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Sep 16, 2016
1 parent 3c0f5c5 commit 68d76b3
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.List;

import static org.openscience.cdk.renderer.generators.standard.HydrogenPosition.Above;
import static org.openscience.cdk.renderer.generators.standard.HydrogenPosition.Below;
import static org.openscience.cdk.renderer.generators.standard.HydrogenPosition.Left;
import static org.openscience.cdk.renderer.generators.standard.HydrogenPosition.Right;

Expand Down Expand Up @@ -279,6 +280,11 @@ AtomSymbol generateAbbreviationSymbol(List<String> tokens, HydrogenPosition posi

final Font italicFont = font.deriveFont(Font.ITALIC);

if (position == Below || position == Above)
AbbreviationLabel.reduce(fTexts, 1, fTexts.size());
else
AbbreviationLabel.reduce(fTexts, 0, fTexts.size());

// convert to outlines
final List<TextOutline> outlines = new ArrayList<>(fTexts.size());
for (FormattedText fText : fTexts) {
Expand Down Expand Up @@ -321,8 +327,19 @@ AtomSymbol generateAbbreviationSymbol(List<String> tokens, HydrogenPosition posi
for (index = 0; index < outlines.size(); index++)
if ((fTexts.get(index).style & 0x1) == 0) break;
}

TextOutline primary = outlines.remove(index);

if (position == Below || position == Above) {
double offsetX = primary.getBounds().getX() - outlines.get(0).getBounds().getX();
double offsetY = position == Below
? padding + primary.getBounds().getHeight()
: -primary.getBounds().getHeight() - padding;
for (int i = 0; i < outlines.size(); i++) {
outlines.set(i, outlines.get(i).translate(offsetX, offsetY));
}
}

return new AtomSymbol(primary, outlines);
}

Expand Down

0 comments on commit 68d76b3

Please sign in to comment.