From ea259dc0c05f372e79dcb2571dfde702e71d7cb5 Mon Sep 17 00:00:00 2001 From: rodinia814 Date: Mon, 19 Mar 2012 05:23:54 +0000 Subject: [PATCH] DGP - change to design figure offset to prevent the image from creeping off the top of the page git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@475 180e2498-e6e9-4542-8430-84ac67f01cd8 --- .../sf/openrocket/gui/print/DesignReport.java | 20 ++++++++++++------- .../sf/openrocket/gui/print/PrintFigure.java | 4 ++++ .../gui/scalefigure/RocketFigure.java | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/core/src/net/sf/openrocket/gui/print/DesignReport.java b/core/src/net/sf/openrocket/gui/print/DesignReport.java index e6290c3e..1af2b13a 100644 --- a/core/src/net/sf/openrocket/gui/print/DesignReport.java +++ b/core/src/net/sf/openrocket/gui/print/DesignReport.java @@ -80,8 +80,9 @@ public class DesignReport { * The logger. */ private static final LogHelper log = Application.getLogger(); - - /** + public static final double SCALE_FUDGE_FACTOR = 0.4d; + + /** * The OR Document. */ private OpenRocketDocument rocketDocument; @@ -264,20 +265,25 @@ public class DesignReport { double scale = (thePageImageableWidth * 2.2) / theFigure.getFigureWidth(); - theFigure.setScale(scale); /* * page dimensions are in points-per-inch, which, in Java2D, are the same as pixels-per-inch; thus we don't need any conversion */ theFigure.setSize(thePageImageableWidth, thePageImageableHeight); theFigure.updateFigure(); - final DefaultFontMapper mapper = new DefaultFontMapper(); Graphics2D g2d = theCanvas.createGraphics(thePageImageableWidth, thePageImageableHeight * 2, mapper); - g2d.translate(20, 120); - - g2d.scale(0.4d, 0.4d); + final double halfFigureHeight = SCALE_FUDGE_FACTOR * theFigure.getFigureHeightPx()/2; + int y = PrintUnit.POINTS_PER_INCH; + //If the y dimension is negative, then it will potentially be drawn off the top of the page. Move the origin + //to allow for this. + if (theFigure.getDimensions().getY() < 0.0d) { + y += (int)halfFigureHeight; + } + g2d.translate(20, y); + + g2d.scale(SCALE_FUDGE_FACTOR, SCALE_FUDGE_FACTOR); theFigure.paint(g2d); g2d.dispose(); return scale; diff --git a/core/src/net/sf/openrocket/gui/print/PrintFigure.java b/core/src/net/sf/openrocket/gui/print/PrintFigure.java index 3f4655c6..648e7231 100644 --- a/core/src/net/sf/openrocket/gui/print/PrintFigure.java +++ b/core/src/net/sf/openrocket/gui/print/PrintFigure.java @@ -31,4 +31,8 @@ public class PrintFigure extends RocketFigure { this.scale = theScale; //dpi/0.0254*scaling; updateFigure(); } + + public double getFigureHeightPx() { + return this.figureHeightPx; + } } diff --git a/core/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java b/core/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java index 854eb17a..bd63d8ba 100644 --- a/core/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java +++ b/core/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java @@ -77,7 +77,7 @@ public class RocketFigure extends AbstractScaleFigure { private double minX = 0, maxX = 0, maxR = 0; // Figure width and height in SI-units and pixels private double figureWidth = 0, figureHeight = 0; - private int figureWidthPx = 0, figureHeightPx = 0; + protected int figureWidthPx = 0, figureHeightPx = 0; private AffineTransform g2transformation = null; -- 2.30.2