Skip to content

Commit e7de75d

Browse files
committed
Allow charges to be places on the left side of an atom if orientation allows.
1 parent c76443e commit e7de75d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

display/renderbasic/src/main/java/org/openscience/cdk/renderer/generators/standard/StandardAtomGenerator.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,10 @@ TextOutline positionAfter(TextOutline before, TextOutline after) {
476476
* @param hydrogen the hydrogen label outline
477477
* @return positioned charge label
478478
*/
479-
TextOutline positionChargeLabel(int hydrogens, HydrogenPosition position, TextOutline charge, TextOutline element,
479+
TextOutline positionChargeLabel(int hydrogens,
480+
HydrogenPosition position,
481+
TextOutline charge,
482+
TextOutline element,
480483
TextOutline hydrogen) {
481484

482485
final Rectangle2D chargeBounds = charge.getBounds();
@@ -486,12 +489,14 @@ TextOutline positionChargeLabel(int hydrogens, HydrogenPosition position, TextOu
486489
// are in the way - in which case we place it relative to the
487490
// hydrogen
488491
Rectangle2D referenceBounds = element.getBounds();
489-
if (hydrogens > 0 && position == Right)
492+
if (hydrogens > 0 && position != Below)
490493
referenceBounds = hydrogen.getBounds();
491-
else if (hydrogens > 1 && position == Above) referenceBounds = hydrogen.getBounds();
492-
493-
return charge.translate((referenceBounds.getMaxX() + padding) - chargeBounds.getMinX(),
494-
(referenceBounds.getMinY() - (chargeBounds.getHeight() / 2)) - chargeBounds.getMinY());
494+
if (position == Left)
495+
return charge.translate((referenceBounds.getMinX() - padding) - chargeBounds.getMaxX(),
496+
(referenceBounds.getMinY() - (chargeBounds.getHeight() / 2)) - chargeBounds.getMinY());
497+
else
498+
return charge.translate((referenceBounds.getMaxX() + padding) - chargeBounds.getMinX(),
499+
(referenceBounds.getMinY() - (chargeBounds.getHeight() / 2)) - chargeBounds.getMinY());
495500
}
496501

497502
/**

0 commit comments

Comments
 (0)