displayArea, labelItem.isPartialsEnabled());
if (point == null)
return false;
// prepare for the search loop
TextStyle2D ts = labelItem.getTextStyle();
// ... use at least a 2 pixel step, no matter what the label length is
final double step = painter.getAscent() > 2 ? painter.getAscent() : 2;
double radius = Math.sqrt(ts.getDisplacementX() * ts.getDisplacementX()
+ ts.getDisplacementY() * ts.getDisplacementY());
AffineTransform tx = new AffineTransform(tempTransform);
// if straight paint works we're good
if(paintPointLabelInternal(painter, tx, displayArea, glyphs, labelItem, point, ts)) {
return true;
}
// see if we have a search radius
if(labelItem.maxDisplacement <= 0) {
return false;
}
// get a cloned text style that we can modify without issues
TextStyle2D cloned = new TextStyle2D(ts);
// ... and the closest quadrant angle that we'll use to start the search from
int startAngle = getClosestStandardAngle(ts.getDisplacementX(), ts.getDisplacementY());
int angle = startAngle;
while(radius <= labelItem.maxDisplacement) {
// the offset is used to generate a x, -x, 2x, -2x, 3x, -3x sequence
for (int offset = 45; offset <= 360; offset = offset + 45) {
double dx = radius * Math.cos(Math.toRadians(angle));
double dy = radius * Math.sin(Math.toRadians(angle));
// using dx and dy would be easy but due to numeric approximations,
// it's actually very hard to get it right so we use the angle
double[] anchorPointCandidates;
// normalize the angle so that it's between 0 and 360
int normAngle = angle % 360;
if(normAngle < 0)
normAngle = 360 + normAngle;
if(normAngle < 90 || normAngle > 270) {
anchorPointCandidates = RIGHT_ANCHOR_CANDIDATES;
} else if(normAngle > 90 && normAngle < 270) {
anchorPointCandidates = LEFT_ANCHOR_CANDIDATES;
} else {
anchorPointCandidates = MID_ANCHOR_CANDIDATES;
}
// try out various anchor point positions
for (int i = 0; i < anchorPointCandidates.length; i +=2) {
double ax = anchorPointCandidates[i];
double ay = anchorPointCandidates[i + 1];
cloned.setAnchorX(ax);
cloned.setAnchorY(ay);
cloned.setDisplacementX(dx);
cloned.setDisplacementY(dy);
tx = new AffineTransform(tempTransform);
if(paintPointLabelInternal(painter, tx, displayArea, glyphs, labelItem, point, cloned))
return true;
}