diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridTextNode.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridTextNode.java index 594bca1676cf8ebb8534c19b5837c25cb4abeb77..a088244c1b47c0cabf55e0556b0d7c90646b61f4 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridTextNode.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridTextNode.java @@ -145,7 +145,7 @@ public final class GridTextNode extends RBaseNode { // actual drawing if (draw && doDraw) { - text(loc.x, loc.y, text, hjust, vjust, rotation, gpar.getDrawingContext(i), dev); + text(loc.x, loc.y, text, hjust, vjust, rotation + vpTransform.rotationAngle, gpar.getDrawingContext(i), dev); } // or bounds checking @@ -210,13 +210,13 @@ public final class GridTextNode extends RBaseNode { // transcribed from engine.c - private void text(double x, double y, String text, double xadjIn, double yadj, double rotation, DrawingContext drawingCtx, GridDevice device) { + private void text(double x, double y, String text, double xadjIn, double yadj, double rotationDegrees, DrawingContext drawingCtx, GridDevice device) { if (!Double.isFinite(yadj)) { throw RInternalError.unimplemented("'exact' vertical centering, see engine.c:1700"); } double xadj = Double.isFinite(xadjIn) ? xadjIn : 0.5; - double radRotation = Math.toRadians(rotation); + double radRotation = Math.toRadians(rotationDegrees); double cosRot = Math.cos(radRotation); double sinRot = Math.sin(radRotation); String[] lines = text.split("\n"); diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPoints.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPoints.java index 477e1e4993e981d0ec48ffd8b75a979052541119..493157255576979c9c0a924cdfaf00fac2c4dd09 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPoints.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPoints.java @@ -130,7 +130,7 @@ public abstract class LPoints extends RExternalBuiltinNode.Arg4 { if (cex > 0 && yc < 0.5) { yc = 0.5; } - dev.drawRect(drawingCtx, x - xc, y - yc, x + xc, y + yc); + dev.drawRect(drawingCtx, x - xc, y - yc, x + xc, y + yc, 0); return drawingCtx; } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LRect.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LRect.java index 7c69b09329958ebcea04cf4367605b532d63a9d4..8fc3969d15b59e1d191e525a57fed2ce0948946f 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LRect.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LRect.java @@ -65,7 +65,7 @@ public abstract class LRect extends RExternalBuiltinNode.Arg6 { Point origLoc = Point.fromUnits(unitToInches, xVec, yVec, i, conversionCtx); Point transLoc = TransformMatrix.transLocation(origLoc, vpTransform.transform); Point loc = transLoc.justify(size, getDataAtMod(hjust, i), getDataAtMod(vjust, i)); - dev.drawRect(gpar.getDrawingContext(i), loc.x, loc.y, size.getWidth(), size.getHeight()); + dev.drawRect(gpar.getDrawingContext(i), loc.x, loc.y, size.getWidth(), size.getHeight(), Math.toRadians(vpTransform.rotationAngle)); } return RNull.instance; } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPortTransform.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPortTransform.java index 0e8ea8aa082fd627a3857caa998e923d758989fc..bed955d7f2988fb4a85d773cb1c452d7b4016484 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPortTransform.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPortTransform.java @@ -25,7 +25,10 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; * Holds the data of a viewport needed to perform transformations. */ public final class ViewPortTransform { - private final double rotationAngle; + /** + * Angle in radians. + */ + public final double rotationAngle; public final double[][] transform; public final Size size; diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/BufferedJFrameDevice.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/BufferedJFrameDevice.java index fa8e3a5b6ff51d21525762d62feea7052f3c87ac..131165f954c651e39fd2558735541c9a627b1a3f 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/BufferedJFrameDevice.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/BufferedJFrameDevice.java @@ -86,10 +86,10 @@ public final class BufferedJFrameDevice implements GridDevice { } @Override - public void drawRect(DrawingContext ctx, double leftX, double topY, double width, double height) { - inner.drawRect(ctx, leftX, topY, width, height); + public void drawRect(DrawingContext ctx, double leftX, double topY, double width, double height, double rotationAnticlockWise) { + inner.drawRect(ctx, leftX, topY, width, height, rotationAnticlockWise); if (buffer != null) { - drawActions.add(() -> inner.drawRect(ctx, leftX, topY, width, height)); + drawActions.add(() -> inner.drawRect(ctx, leftX, topY, width, height, rotationAnticlockWise)); } } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java index 03df48b53f972eb12b50bf06d8bab924494718ce..afe759f3f09cdd99b23f3fda22107266ab63def3 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java @@ -46,7 +46,11 @@ public interface GridDevice { default void flush() { } - void drawRect(DrawingContext ctx, double leftX, double topY, double width, double height); + /** + * Draws a rectangle at given position, the center of the rotation should be the center of the + * rectangle. The rotation is given in radians. + */ + void drawRect(DrawingContext ctx, double leftX, double topY, double width, double height, double rotationAnticlockWise); /** * Connects given points with a line, there has to be at least two points in order to actually diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/JFrameDevice.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/JFrameDevice.java index c92cb0558d127a61a14343fa53ebabea29a1c171..6ee2268766a6fb73822b1734bfff37def493a466 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/JFrameDevice.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/JFrameDevice.java @@ -83,9 +83,19 @@ public final class JFrameDevice implements GridDevice { } @Override - public void drawRect(DrawingContext ctx, double leftX, double topY, double width, double height) { + public void drawRect(DrawingContext ctx, double leftX, double topY, double width, double height, double rotationAnticlockWise) { setContext(ctx); - drawShape(ctx, new Rectangle2D.Double(leftX, topY, width, height)); + if (rotationAnticlockWise == 0.) { + drawShape(ctx, new Rectangle2D.Double(leftX, topY, width, height)); + return; + } + AffineTransform oldTr = graphics.getTransform(); + AffineTransform newTr = new AffineTransform(oldTr); + newTr.translate(leftX + width / 2, topY + height / 2); + newTr.rotate(rotationAnticlockWise); + graphics.setTransform(newTr); + drawShape(ctx, new Rectangle2D.Double(-(width / 2), -(height / 2), width, height)); + graphics.setTransform(oldTr); } @Override