diff options
| author | Pierre-Charles David | 2016-02-19 10:27:29 +0000 |
|---|---|---|
| committer | Pierre-Charles David | 2016-02-19 16:12:03 +0000 |
| commit | a4ce04159734e26350ff87408932216500e0ddb0 (patch) | |
| tree | 41cff444766a9b249fc32dfcae75cd5f9435cbed | |
| parent | c008499e5956922de4d7091e890222b62eb4f979 (diff) | |
| download | org.eclipse.sirius-a4ce04159734e26350ff87408932216500e0ddb0.tar.gz org.eclipse.sirius-a4ce04159734e26350ff87408932216500e0ddb0.tar.xz org.eclipse.sirius-a4ce04159734e26350ff87408932216500e0ddb0.zip | |
[442268] Move some code into SimpleImageTranscoder
The getImage*() and updateRenderingHints() logic and the aspectRatio was
almost entirely about the transcoder state.
Bug: 442268
Change-Id: I7ab9e393ff634547f0136595d8284e3f1d704d22
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
3 files changed, 67 insertions, 75 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGFigure.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGFigure.java index d431fad787..be5e1b8e9f 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGFigure.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGFigure.java @@ -12,7 +12,6 @@ */ package org.eclipse.sirius.diagram.ui.tools.api.figure; -import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.io.IOException; import java.text.MessageFormat; @@ -85,42 +84,27 @@ public class SVGFigure extends Figure implements StyledFigure, ITransparentFigur @Override public int getImageHeight() { SimpleImageTranscoder transcoder = getTranscoder(); - int height = 0; if (transcoder != null) { - int canvasHeight = transcoder.getCanvasHeight(); - if (canvasHeight == -1) { - height = transcoder.getBufferedImage().getHeight(); - } else { - height = canvasHeight; - } + return transcoder.getImageHeight(); + } else { + return 0; } - return height; } @Override public int getImageWidth() { SimpleImageTranscoder transcoder = getTranscoder(); - int width = 0; if (transcoder != null) { - int canvasWidth = transcoder.getCanvasWidth(); - if (canvasWidth == -1) { - width = transcoder.getBufferedImage().getWidth(); - } else { - width = canvasWidth; - } + return transcoder.getImageWidth(); } - return width; + return 0; } @Override public int getImageAlphaValue(int x, int y) { SimpleImageTranscoder transcoder = getTranscoder(); if (transcoder != null) { - BufferedImage bufferedImage = transcoder.getBufferedImage(); - if (bufferedImage != null && bufferedImage.getWidth() >= x && bufferedImage.getHeight() >= y) { - int[] result = bufferedImage.getAlphaRaster().getPixel(x, y, new int[1]); - return result[0]; - } + return transcoder.getImageAlphaValue(x, y); } return 255; } @@ -226,16 +210,7 @@ public class SVGFigure extends Figure implements StyledFigure, ITransparentFigur protected void updateRenderingHints(Graphics graphics) { if (transcoder != null) { - Object antiAliasHint = SVGUtils.getAntialiasHint(graphics); - if (transcoder.getRenderingHints().get(RenderingHints.KEY_ANTIALIASING) != antiAliasHint) { - transcoder.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, antiAliasHint); - transcoder.contentChanged(); - } - Object textAntiAliasHint = SVGUtils.getTextAntialiasHint(graphics); - if (transcoder.getRenderingHints().get(RenderingHints.KEY_TEXT_ANTIALIASING) != textAntiAliasHint) { - transcoder.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, textAntiAliasHint); - transcoder.contentChanged(); - } + transcoder.updateRenderingHints(graphics); } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGWorkspaceImageFigure.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGWorkspaceImageFigure.java index 9036623654..8256a640ea 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGWorkspaceImageFigure.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGWorkspaceImageFigure.java @@ -14,7 +14,6 @@ import java.io.File; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Path; -import org.eclipse.draw2d.XYLayout; import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.sirius.common.tools.api.resource.FileProvider; @@ -43,8 +42,7 @@ public class SVGWorkspaceImageFigure extends AbstractCachedSVGFigure implements /** * Create a new {@link SVGWorkspaceImageFigure}. */ - public SVGWorkspaceImageFigure() { // final Image flyWeightImage) { - this.setLayoutManager(new XYLayout()); + public SVGWorkspaceImageFigure() { minSize = new Dimension(0, 0); } @@ -151,16 +149,7 @@ public class SVGWorkspaceImageFigure extends AbstractCachedSVGFigure implements this.contentChanged(); SimpleImageTranscoder transcoder = getTranscoder(); if (transcoder != null) { - int canvasHeight = transcoder.getCanvasHeight(); - int canvasWidth = transcoder.getCanvasWidth(); - - if (canvasHeight == -1 || canvasWidth == -1) { - int width = transcoder.getBufferedImage().getWidth(); - int height = transcoder.getBufferedImage().getHeight(); - imageAspectRatio = (double) width / (double) height; - } else { - imageAspectRatio = (double) canvasWidth / (double) canvasHeight; - } + imageAspectRatio = transcoder.getAspectRatio(); } } } else { diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/svg/SimpleImageTranscoder.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/svg/SimpleImageTranscoder.java index 9e20ddd66e..d4eccfafd0 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/svg/SimpleImageTranscoder.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/svg/SimpleImageTranscoder.java @@ -24,6 +24,7 @@ import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; import org.apache.batik.transcoder.image.ImageTranscoder; +import org.eclipse.draw2d.Graphics; import org.eclipse.sirius.diagram.DiagramPlugin; import org.eclipse.sirius.diagram.ui.provider.Messages; import org.w3c.dom.Document; @@ -50,10 +51,6 @@ public class SimpleImageTranscoder extends SVGAbstractTranscoder { return document; } - public final RenderingHints getRenderingHints() { - return renderingHints; - } - public final int getCanvasWidth() { return canvasWidth; } @@ -71,32 +68,6 @@ public class SimpleImageTranscoder extends SVGAbstractTranscoder { contentChanged(); } - public final Rectangle2D getCanvasAreaOfInterest() { - if (canvasAOI == null) { - return null; - } - Rectangle2D result = new Rectangle2D.Float(); - result.setRect(canvasAOI); - return result; - } - - public void setCanvasAreaOfInterest(Rectangle2D value) { - if (value == null) { - if (canvasAOI == null) { - return; - } - canvasAOI = null; - contentChanged(); - return; - } - if (value.equals(canvasAOI)) { - return; - } - canvasAOI = new Rectangle2D.Float(); - canvasAOI.setRect(value); - contentChanged(); - } - public void contentChanged() { bufferedImage = null; } @@ -160,5 +131,62 @@ public class SimpleImageTranscoder extends SVGAbstractTranscoder { } return bufferedImage; } + + public int getImageHeight() { + int height = 0; + int canvasHeight = getCanvasHeight(); + if (canvasHeight == -1) { + height = getBufferedImage().getHeight(); + } else { + height = canvasHeight; + } + return height; + } + + public int getImageWidth() { + int width = 0; + int canvasWidth = getCanvasWidth(); + if (canvasWidth == -1) { + width = getBufferedImage().getWidth(); + } else { + width = canvasWidth; + } + return width; + } + + public int getImageAlphaValue(int x, int y) { + BufferedImage bufferedImage = getBufferedImage(); + if (bufferedImage != null && bufferedImage.getWidth() >= x && bufferedImage.getHeight() >= y) { + int[] result = bufferedImage.getAlphaRaster().getPixel(x, y, new int[1]); + return result[0]; + } + return 255; + } + + public double getAspectRatio() { + int canvasHeight = getCanvasHeight(); + int canvasWidth = getCanvasWidth(); + + if (canvasHeight == -1 || canvasWidth == -1) { + int width = getBufferedImage().getWidth(); + int height = getBufferedImage().getHeight(); + return (double) width / (double) height; + } else { + return (double) canvasWidth / (double) canvasHeight; + } + } + + public void updateRenderingHints(Graphics graphics) { + Object antiAliasHint = SVGUtils.getAntialiasHint(graphics); + if (renderingHints.get(RenderingHints.KEY_ANTIALIASING) != antiAliasHint) { + renderingHints.put(RenderingHints.KEY_ANTIALIASING, antiAliasHint); + contentChanged(); + } + Object textAntiAliasHint = SVGUtils.getTextAntialiasHint(graphics); + if (renderingHints.get(RenderingHints.KEY_TEXT_ANTIALIASING) != textAntiAliasHint) { + renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, textAntiAliasHint); + contentChanged(); + } + } } // CHECKSTYLE:ON |
