code: public static Polygon calculateBounds(final MapfishMapContext context) {
          double rotation = context.getRootContext().getRotation();
          ReferencedEnvelope env = context.getRootContext().toReferencedEnvelope();
  
          Coordinate centre = env.centre();
          AffineTransform rotateInstance = AffineTransform.getRotateInstance(rotation, centre.x, centre.y);
  
          double[] dstPts = new double[8];
          double[] srcPts = {
                  env.getMinX(), env.getMinY(), env.getMinX(), env.getMaxY(),
                  env.getMaxX(), env.getMaxY(), env.getMaxX(), env.getMinY()
          };
  
          rotateInstance.transform(srcPts, 0, dstPts, 0, 4);
  
          return new GeometryFactory().createPolygon(new Coordinate[]{
                  new Coordinate(dstPts[0], dstPts[1]), new Coordinate(dstPts[2], dstPts[3]),
                  new Coordinate(dstPts[4], dstPts[5]), new Coordinate(dstPts[6], dstPts[7]),
                  new Coordinate(dstPts[0], dstPts[1])
          });
      }
docs: Create a polygon that represents in world space the exact area that will be visible on the printed
  map.
  
  @param context map context