From 44f55ac060f9839cd19c4f415a5a149aece5eb2f Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 30 Jul 2019 12:15:24 +0100 Subject: [PATCH] JAL-3364 revisions to split frame image export --- src/jalview/gui/AlignmentPanel.java | 31 ++++++++++++++++---------- src/jalview/gui/SeqCanvas.java | 17 ++++++-------- src/jalview/renderer/AnnotationRenderer.java | 18 +++++++++++---- src/jalview/util/ImageMaker.java | 15 +++++-------- 4 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 5c0d3a1..3c86653 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -970,7 +970,8 @@ public class AlignmentPanel extends GAlignmentPanel implements if (av.isShowAnnotation()) { - pagesHigh += getAnnotationPanel().adjustPanelHeight() + 3; + pagesHigh += getAnnotationPanel().adjustPanelHeight() + + SeqCanvas.SEQS_ANNOTATION_GAP; } pagesHigh /= pageHeight; @@ -979,7 +980,7 @@ public class AlignmentPanel extends GAlignmentPanel implements { return Printable.NO_SUCH_PAGE; } - final int alignmentDrawnHeight = (endSeq - startSeq) * charHeight + 3; + final int alignmentDrawnHeight = (endSeq - startSeq + 1) * charHeight; /* * draw the Scale at horizontal offset, then reset to top left (0, 0) @@ -1020,24 +1021,33 @@ public class AlignmentPanel extends GAlignmentPanel implements * then reset to (0, scale height) */ int offset = getAlabels().getScrollOffset(); + int yShift = alignmentDrawnHeight + SeqCanvas.SEQS_ANNOTATION_GAP; idGraphics.translate(0, -offset); - idGraphics.translate(0, alignmentDrawnHeight); + idGraphics.translate(0, yShift); getAlabels().drawComponent(idGraphics, idWidth); - idGraphics.translate(0, -alignmentDrawnHeight); + idGraphics.translate(0, -yShift); /* * draw the annotations starting at * (idOffset, alignmentHeight) from (0, scaleHeight) */ alignmentGraphics.translate(alignmentGraphicsOffset, - alignmentDrawnHeight); + yShift); getAnnotationPanel().renderer.drawComponent(getAnnotationPanel(), av, alignmentGraphics, -1, startRes, endRes + 1); /* - * reset to left margin + * reset to left margin below annotation */ - alignmentGraphics.translate(-alignmentGraphicsOffset, 0); + int justDrawn = getAnnotationPanel().renderer.getLastDrawnHeight(); + alignmentGraphics.translate(-alignmentGraphicsOffset, justDrawn); + } + else + { + /* + * shift graphics to position after drawn sequences + */ + alignmentGraphics.translate(0, alignmentDrawnHeight); } return Printable.PAGE_EXISTS; @@ -1244,10 +1254,7 @@ public class AlignmentPanel extends GAlignmentPanel implements /* * append coding complement image */ - /* - * to debug location of next write to Graphics - */ - // graphics.setColor(Color.red); + // to debug location of next write to Graphics: // graphics.drawString("Hello world", 0, 0); if (av.getCodingComplement().getWrapAlignment()) { @@ -1281,7 +1288,7 @@ public class AlignmentPanel extends GAlignmentPanel implements * * The alignment may be in wrapped or unwrapped mode. diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 8a587ea..5f67cb5 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -450,16 +450,17 @@ public class SeqCanvas extends JComponent implements ViewportListenerI } /** - * Draw a wrapped alignment panel for printing + * Draws a wrapped alignment panel for printing. After drawing, the graphics + * origin is shifted down by the height of the image drawn. * * @param g - * Graphics object to draw with + * Graphics object to draw with * @param canvasWidth - * width of drawing area + * width of drawing area * @param canvasHeight - * height of drawing area + * height of drawing area * @param startRes - * start residue of print area + * start residue of print area */ public void drawWrappedPanelForPrinting(Graphics g, int canvasWidth, int canvasHeight, int startRes) @@ -704,11 +705,7 @@ public class SeqCanvas extends JComponent implements ViewportListenerI // the Printable page which we need to account for here Shape clip = g.getClip(); - if (clip == null) - { - // g.setClip(0, 0, viewportWidth * charWidth, canvasHeight); - } - else + if (clip != null) { g.setClip(0, (int) clip.getBounds().getY(), viewportWidth * charWidth, (int) clip.getBounds().getHeight()); diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index 0a4c2d5..dcf2f20 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -419,6 +419,8 @@ public class AnnotationRenderer boolean rna = false; + private int lastDrawnHeight; + /** * Render the annotation rows associated with an alignment. * @@ -1093,14 +1095,22 @@ public class AnnotationRenderer System.err.println("Annotation Rendering time:" + (System.currentTimeMillis() - stime)); } - if (!av.getWrapAlignment()) - { - g.translate(0, y); - } + lastDrawnHeight = y; return !usedFaded; } + /** + * Answers the height in pixels of what was drawn on the graphics in the last + * call to {@code drawComponent} + * + * @return + */ + public int getLastDrawnHeight() + { + return lastDrawnHeight; + } + public static final Color GLYPHLINE_COLOR = Color.gray; public static final Color SHEET_COLOUR = Color.green; diff --git a/src/jalview/util/ImageMaker.java b/src/jalview/util/ImageMaker.java index 099bcee..4438de4 100755 --- a/src/jalview/util/ImageMaker.java +++ b/src/jalview/util/ImageMaker.java @@ -20,6 +20,7 @@ */ package jalview.util; +import jalview.bin.Cache; import jalview.bin.Jalview; import jalview.gui.EPSOptions; import jalview.gui.IProgressIndicator; @@ -60,8 +61,6 @@ public class ImageMaker EpsGraphics2D pg; - SVGGraphics2D g2; - Graphics graphics; FileOutputStream out; @@ -291,15 +290,13 @@ public class ImageMaker void setupSVG(int width, int height, String title) { + Graphics2D svgGraphics = new SVGGraphics2D(width, height); - g2 = new SVGGraphics2D(width, height); - Graphics2D ig2 = g2; - - String renderStyle = jalview.bin.Cache.getDefault("SVG_RENDERING", + String renderStyle = Cache.getDefault("SVG_RENDERING", "Prompt each time"); // If we need to prompt, and if the GUI is visible then - // Prompt for EPS rendering style + // Prompt for SVG rendering style if (renderStyle.equalsIgnoreCase("Prompt each time") && !(System.getProperty("java.awt.headless") != null && System .getProperty("java.awt.headless").equals("true"))) @@ -317,13 +314,13 @@ public class ImageMaker if (renderStyle.equalsIgnoreCase("Lineart")) { - ig2.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE, + svgGraphics.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE, SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); } setProgressMessage(MessageManager .formatMessage("status.export_complete", type.getName())); - graphics = g2; + graphics = svgGraphics; } static JalviewFileChooser getPNGChooser() -- 1.7.10.2