Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Charles David2015-09-18 15:06:23 +0000
committerPierre-Charles David2016-02-23 10:29:39 +0000
commit89aaf8ac55fb02d2e0007a4a26a42f10d2706c45 (patch)
treea4a8e177fd3d3008560a44b32da9ec4d13d5fadc
parenta7ecf8f13b7ecd7d4b17ef288a89965dc4c35657 (diff)
downloadorg.eclipse.sirius-89aaf8ac55fb02d2e0007a4a26a42f10d2706c45.tar.gz
org.eclipse.sirius-89aaf8ac55fb02d2e0007a4a26a42f10d2706c45.tar.xz
org.eclipse.sirius-89aaf8ac55fb02d2e0007a4a26a42f10d2706c45.zip
[442268] Add compile-time flag to enable scaled images caching
Bug: 442268 Change-Id: If3a3f1745ced25f726454e2b20c412217aaa4222 Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/SVGFigure.java38
1 files changed, 29 insertions, 9 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 01f7239489..315e4dfcf5 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
@@ -104,9 +104,11 @@ public class SVGFigure extends Figure implements StyledFigure, ITransparentFigur
}
private static final ImageCache CACHE = new ImageCache();
-
+
private static final boolean CACHE_ENABLED = true;
-
+
+ private static final boolean CACHE_SCALED_IMAGES = true;
+
/**
* The uri of the image to display when the file has not been found.
*/
@@ -292,7 +294,10 @@ public class SVGFigure extends Figure implements StyledFigure, ITransparentFigur
result.append(SVGFigure.SEPARATOR);
result.append(aaText);
result.append(SVGFigure.SEPARATOR);
- Rectangle r = getClientArea();
+ Rectangle r = getClientArea().getCopy();
+ if (CACHE_SCALED_IMAGES && graphics != null) {
+ r.performScale(graphics.getAbsoluteScale());
+ }
result.append(r.width);
result.append(SVGFigure.SEPARATOR);
result.append(r.height);
@@ -304,10 +309,19 @@ public class SVGFigure extends Figure implements StyledFigure, ITransparentFigur
protected void paintFigure(Graphics graphics) {
TransparentFigureGraphicsModifier modifier = new TransparentFigureGraphicsModifier(this, graphics);
modifier.pushState();
- Rectangle r = getClientArea();
- Image image = getImage(r, graphics);
- if (image != null) {
- graphics.drawImage(image, r.x, r.y);
+ Rectangle svgArea = getClientArea();
+ if (CACHE_SCALED_IMAGES) {
+ Rectangle scaledArea = new Rectangle(svgArea);
+ scaledArea.performScale(graphics.getAbsoluteScale());
+ Image image = getImage(svgArea, graphics);
+ if (image != null) {
+ graphics.drawImage(image, 0, 0, scaledArea.width, scaledArea.height, svgArea.x, svgArea.y, svgArea.width, svgArea.height);
+ }
+ } else {
+ Image image = getImage(svgArea, graphics);
+ if (image != null) {
+ graphics.drawImage(image, svgArea.x, svgArea.y);
+ }
}
modifier.popState();
}
@@ -332,7 +346,13 @@ public class SVGFigure extends Figure implements StyledFigure, ITransparentFigur
protected static Image render(SVGFigure fig, Rectangle clientArea, Graphics graphics) {
Image result = null;
if (fig.getDocument() != null) {
- fig.getTranscoder().setCanvasSize(clientArea.width, clientArea.height);
+ if (CACHE_SCALED_IMAGES && graphics != null) {
+ Rectangle scaledArea = new Rectangle(clientArea);
+ scaledArea.performScale(graphics.getAbsoluteScale());
+ fig.getTranscoder().setCanvasSize(scaledArea.width, scaledArea.height);
+ } else {
+ fig.getTranscoder().setCanvasSize(clientArea.width, clientArea.height);
+ }
fig.getTranscoder().updateRenderingHints(graphics);
BufferedImage awtImage = fig.getTranscoder().getBufferedImage();
if (awtImage != null) {
@@ -341,7 +361,7 @@ public class SVGFigure extends Figure implements StyledFigure, ITransparentFigur
}
return result;
}
-
+
/**
* Remove all entries whose key begins with the given key. Remove from the
* document map, the entries with the given keys to force to re-read the

Back to the top