X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Futil%2FImageMaker.java;h=016feee7f72dbdde8ca2544928bd18cad38564be;hb=ec24991b1786e17158a43f713c8ae9c4f8647393;hp=e89596b1c459eddc4422fdd56c7043955c20e849;hpb=17e4ea278bc9a5fb280db1252ce78b7a295215f5;p=jalview.git diff --git a/src/jalview/util/ImageMaker.java b/src/jalview/util/ImageMaker.java index e89596b..016feee 100755 --- a/src/jalview/util/ImageMaker.java +++ b/src/jalview/util/ImageMaker.java @@ -20,8 +20,6 @@ */ package jalview.util; -import jalview.io.JalviewFileChooser; - import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; @@ -36,6 +34,8 @@ import org.jfree.graphics2d.svg.SVGGraphics2D; import org.jfree.graphics2d.svg.SVGHints; import org.jibble.epsgraphics.EpsGraphics2D; +import jalview.io.JalviewFileChooser; + public class ImageMaker { public static final String SVG_DESCRIPTION = "Scalable Vector Graphics"; @@ -110,11 +110,12 @@ public class ImageMaker * @param file * @param fileTitle * @param useLineart + * @param bitmapscale * @throws IOException */ - public ImageMaker(TYPE imageType, int width, int height, - File file, String fileTitle, boolean useLineart) - throws IOException + public ImageMaker(TYPE imageType, int width, int height, File file, + String fileTitle, boolean useLineart, float bitmapscale, + int bitmapwidth, int bitmapheight) throws IOException { this.type = imageType; @@ -128,7 +129,7 @@ public class ImageMaker setupEPS(width, height, fileTitle, useLineart); break; case PNG: - setupPNG(width, height); + setupPNG(width, height, bitmapscale, bitmapwidth, bitmapheight); break; default: } @@ -177,14 +178,52 @@ public class ImageMaker * * @param width * @param height + * @param scale */ - protected void setupPNG(int width, int height) + protected void setupPNG(int width, int height, float scale, + int bitmapwidth, int bitmapheight) { - bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + if (width == 0 || height == 0) + return; + + float usescale = 0.0f; + int usewidth = width; + int useheight = height; + + // use the smallest positive scale (i.e. fit in the box) + if (scale > 0.0f) + { + usescale = scale; + usewidth = Math.round(scale * width); + useheight = Math.round(scale * height); + } + if (bitmapwidth > 0) + { + float wscale = (float) bitmapwidth / width; + if (wscale > 0.0f && (usescale == 0.0f || wscale < usescale)) + { + usescale = wscale; + usewidth = bitmapwidth; + useheight = Math.round(usescale * height); + } + } + if (bitmapheight > 0) + { + float hscale = (float) bitmapheight / height; + if (hscale > 0.0f && (usescale == 0.0f || hscale < usescale)) + { + usescale = hscale; + usewidth = Math.round(usescale * width); + useheight = bitmapheight; + } + } + bi = new BufferedImage(usewidth, useheight, BufferedImage.TYPE_INT_RGB); graphics = bi.getGraphics(); Graphics2D ig2 = (Graphics2D) graphics; ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + if (usescale > 0.0f) + ig2.scale(usescale, usescale); } /**