reduce statement complexity in drawContent, also has fewer FLOPS

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753114 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-07-17 20:29:34 +00:00
parent ec4a47df73
commit 056a8dac84

View File

@ -70,16 +70,20 @@ public class DrawTextShape extends DrawSimpleShape {
// Horizontal flipping applies only to shape outline and not to the text in the shape. // Horizontal flipping applies only to shape outline and not to the text in the shape.
// Applying flip second time restores the original not-flipped transform // Applying flip second time restores the original not-flipped transform
if (horzFlip ^ vertFlip) { if (horzFlip ^ vertFlip) {
graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY()); final double ax = anchor.getX();
final double ay = anchor.getY();
graphics.translate(ax + anchor.getWidth(), ay);
graphics.scale(-1, 1); graphics.scale(-1, 1);
graphics.translate(-anchor.getX(), -anchor.getY()); graphics.translate(-ax, -ay);
} }
Double textRot = s.getTextRotation(); Double textRot = s.getTextRotation();
if (textRot != null && textRot != 0) { if (textRot != null && textRot != 0) {
graphics.translate(anchor.getCenterX(), anchor.getCenterY()); final double cx = anchor.getCenterX();
final double cy = anchor.getCenterY();
graphics.translate(cx, cy);
graphics.rotate(Math.toRadians(textRot)); graphics.rotate(Math.toRadians(textRot));
graphics.translate(-anchor.getCenterX(), -anchor.getCenterY()); graphics.translate(-cx, -cy);
} }
// first dry-run to calculate the total height of the text // first dry-run to calculate the total height of the text
@ -101,16 +105,19 @@ public class DrawTextShape extends DrawSimpleShape {
TextDirection textDir = s.getTextDirection(); TextDirection textDir = s.getTextDirection();
if (textDir == TextDirection.VERTICAL || textDir == TextDirection.VERTICAL_270) { if (textDir == TextDirection.VERTICAL || textDir == TextDirection.VERTICAL_270) {
double deg = (textDir == TextDirection.VERTICAL) ? 90 : 270; final double deg = (textDir == TextDirection.VERTICAL) ? 90 : 270;
graphics.translate(anchor.getCenterX(), anchor.getCenterY()); final double cx = anchor.getCenterX();
final double cy = anchor.getCenterY();
graphics.translate(cx, cy);
graphics.rotate(Math.toRadians(deg)); graphics.rotate(Math.toRadians(deg));
graphics.translate(-anchor.getCenterX(), -anchor.getCenterY()); graphics.translate(-cx, -cy);
// old top/left edge is now bottom/left or top/right - as we operate on the already // old top/left edge is now bottom/left or top/right - as we operate on the already
// rotated drawing context, both verticals can be moved in the same direction // rotated drawing context, both verticals can be moved in the same direction
double w = anchor.getWidth(); final double w = anchor.getWidth();
double h = anchor.getHeight(); final double h = anchor.getHeight();
graphics.translate((w-h)/2d,(h-w)/2d); final double dx = (w-h)/2d;
graphics.translate(dx,-dx);
} }
drawParagraphs(graphics, x, y); drawParagraphs(graphics, x, y);