Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Redor2016-07-01 11:18:37 +0000
committerLaurent Redor2016-07-07 15:16:51 +0000
commitebc68755874dabd8873a839806689b5021cdd59b (patch)
tree0ae71b548ff7c373ed53cdbf0a4d0a0958f8c2e8
parent34be5e0167ca821ef9c60b278f7c54454e1d76f0 (diff)
downloadorg.eclipse.sirius-ebc68755874dabd8873a839806689b5021cdd59b.tar.gz
org.eclipse.sirius-ebc68755874dabd8873a839806689b5021cdd59b.tar.xz
org.eclipse.sirius-ebc68755874dabd8873a839806689b5021cdd59b.zip
[491913] Fix pb of png gradient according to figure location
The export of png with gradient was KO. According to the location of the shape, the gradient was (or was not) correctly drawn. The previous commit [1] does not consider the translation offset of the SiriusGraphicsToGraphics2DAdaptor. This commit also fixes some gradient computations (confusion between x,y of second point and width,height). [1] http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=225f5107a327a9817035ba761203fdb5f93bedd2 Bug: 491913 Change-Id: I991c92086978d1144814ab1a63c7f0a3afaea3ac Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/GradientHelper.java11
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsToGraphics2DAdaptor.java19
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release_Notes.html5
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile2
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/color/VisualBindingManager.java2
5 files changed, 29 insertions, 10 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/GradientHelper.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/GradientHelper.java
index e315af7f7d..ae319b71ec 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/GradientHelper.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/figure/GradientHelper.java
@@ -53,8 +53,7 @@ public final class GradientHelper {
} else {
SiriusGraphicsToGraphics2DAdaptor siriusGraphics2DAdaptor = GraphicsUtilities.getSiriusGraphicsToGraphics2DAdaptor(graphics);
if (siriusGraphics2DAdaptor != null) {
- GradientPaint gradientPaint = GradientHelper.getGradientPaint(figure.getBackgroundStyle().getValue(), zoomedBounds, figure.getBackgroundColor(), figure.getGradientColor());
- siriusGraphics2DAdaptor.setBackgroundPattern(gradientPaint);
+ siriusGraphics2DAdaptor.setBackgroundPattern(figure.getBackgroundStyle().getValue(), zoomedBounds, figure.getBackgroundColor(), figure.getGradientColor());
}
}
}
@@ -103,7 +102,7 @@ public final class GradientHelper {
* the gradient color
* @return the wanted pattern
*/
- private static GradientPaint getGradientPaint(int backgroundStyle, Rectangle bounds, Color backgroundColor, Color gradientColor) {
+ public static GradientPaint getGradientPaint(int backgroundStyle, Rectangle bounds, Color backgroundColor, Color gradientColor) {
GradientPaint gradientPaint;
switch (backgroundStyle) {
case BackgroundStyle.GRADIENT_TOP_TO_BOTTOM:
@@ -176,7 +175,7 @@ public final class GradientHelper {
* @return the corresponding pattern.
*/
public static Pattern getGradientTopToBottom(final Rectangle bounds, final Color backgroundColor, final Color gradientColor) {
- return VisualBindingManager.getDefault().getPatternFromValue(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height, backgroundColor, gradientColor);
+ return VisualBindingManager.getDefault().getPatternFromValue(bounds.x, bounds.y, 0, bounds.height, backgroundColor, gradientColor);
}
/**
@@ -191,7 +190,7 @@ public final class GradientHelper {
* @return the correesponding pattern.
*/
public static GradientPaint getGradientPaintLeftToRight(final Rectangle bounds, final Color backgroundColor, final Color gradientColor) {
- return VisualBindingManager.getDefault().getGradientPaintFromValue(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y, backgroundColor, gradientColor);
+ return VisualBindingManager.getDefault().getGradientPaintFromValue(bounds.x, bounds.y, bounds.width, 0, backgroundColor, gradientColor);
}
/**
@@ -220,7 +219,7 @@ public final class GradientHelper {
if (gradientZoneHeight != bounds.height) {
y = bounds.y - (i - bounds.height) / 2;
}
- return VisualBindingManager.getDefault().getGradientPaintFromValue(x, y, x + gradientZoneWidth, y + gradientZoneHeight, backgroundColor, gradientColor);
+ return VisualBindingManager.getDefault().getGradientPaintFromValue(x, y, gradientZoneWidth, gradientZoneHeight, backgroundColor, gradientColor);
}
/**
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsToGraphics2DAdaptor.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsToGraphics2DAdaptor.java
index 3943ebdc76..5d94be7619 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsToGraphics2DAdaptor.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/render/SiriusGraphicsToGraphics2DAdaptor.java
@@ -44,6 +44,7 @@ import org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.metafile.GdiFon
import org.eclipse.gmf.runtime.draw2d.ui.render.internal.DrawableRenderedImage;
import org.eclipse.gmf.runtime.draw2d.ui.render.internal.RenderingListener;
import org.eclipse.gmf.runtime.draw2d.ui.text.TextUtilitiesEx;
+import org.eclipse.sirius.diagram.ui.tools.api.figure.GradientHelper;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
@@ -1557,5 +1558,23 @@ public class SiriusGraphicsToGraphics2DAdaptor extends Graphics implements Drawa
relativeClipRegion = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
}
+ /**
+ * Compute the right pattern according to current translate offset and set
+ * it.
+ *
+ * @param backgroundStyle
+ * the background style
+ * @param bounds
+ * the bounds of the figure (without current translate offset)
+ * @param backgroundColor
+ * the background color
+ * @param gradientColor
+ * the gradient color
+ */
+ public void setBackgroundPattern(int backgroundStyle, Rectangle zoomedBounds, Color backgroundColor, Color gradientColor) {
+ GradientPaint gradientPaint = GradientHelper.getGradientPaint(backgroundStyle, zoomedBounds.getTranslated(getTranslationOffset()), backgroundColor, gradientColor);
+ setBackgroundPattern(gradientPaint);
+ }
+
}
// CHECKSTYLE:ON
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
index 70611da4ed..68923f33ad 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
+++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
@@ -484,8 +484,9 @@
<code>java.awt.GradientPaint</code> as
<code>org.eclipse.swt.graphics.Pattern</code>:
<code>getGradientPaintDiag(Rectangle, Color, Color)</code>,
- <code>getGradientPaintLeftToRight(Rectangle, Color, Color)</code> and
- <code>getGradientPaintTopToBottom(Rectangle, Color, Color)</code>.
+ <code>getGradientPaintLeftToRight(Rectangle, Color, Color)</code>,
+ <code>getGradientPaintTopToBottom(Rectangle, Color, Color)</code> and
+ <code>getGradientPaint(int, Rectangle, Color, Color)</code>.
</li>
<li><span class="label label-success">Added</span>
<code>org.eclipse.sirius.diagram.ui.tools.api.ui.actions.ActionIds.ACTION_SIRIUS_COPY_APPEARANCE_PROPERTIES</code> has been added to identify the new
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
index 660a4b682d..2a388bda12 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
+++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
@@ -136,7 +136,7 @@ h4. Changes in @org.eclipse.sirius.diagram.ui@
* <span class="label label-success">Added</span> The following protected methods have been added to @org.eclipse.sirius.diagram.ui.tools.api.figure.SVGFigure@ : @String getKey(Graphics)@, @Image getImage(Rectangle, Graphics)@, @static boolean doRemoveFromCache(String)@.
* <span class="label label-success">Added</span> 2 methods are added in @org.eclipse.sirius.diagram.ui.tools.api.part.DiagramEditPartService@ to manage gradient color in export to PNG or SVG formats: @DiagramEditPartService.saveSVGToFile(IPath, SiriusDiagramSVGGenerator, IProgressMonitor)@ and @org.eclipse.sirius.diagram.ui.tools.api.part.DiagramEditPartService.saveToFile(IPath, SiriusDiagramSVGGenerator, ImageFileFormat, IProgressMonitor)@. These 2 methods are copy of parent methods with @SiriusDiagramSVGGenerator@ as parameter instead of a @DiagramSVGGenerator@.
* <span class="label label-success">Added</span> The method @org.eclipse.sirius.ui.tools.api.color.VisualBindingManager.getGradientPaintFromValue(int, int, int, int, Color, Color)@ has been added to handle a cache for @java.awt.GradientPaint@ as it is the case for @org.eclipse.swt.graphics.Pattern@ with @getPatternFromValue()@.
-* <span class="label label-success">Added</span> Methods have been added in @org.eclipse.sirius.diagram.ui.tools.api.figure.GradientHelper@ to handle @java.awt.GradientPaint@ as @org.eclipse.swt.graphics.Pattern@: @getGradientPaintDiag(Rectangle, Color, Color)@, @getGradientPaintLeftToRight(Rectangle, Color, Color)@ and @getGradientPaintTopToBottom(Rectangle, Color, Color)@.
+* <span class="label label-success">Added</span> Methods have been added in @org.eclipse.sirius.diagram.ui.tools.api.figure.GradientHelper@ to handle @java.awt.GradientPaint@ as @org.eclipse.swt.graphics.Pattern@: @getGradientPaintDiag(Rectangle, Color, Color)@, @getGradientPaintLeftToRight(Rectangle, Color, Color)@, @getGradientPaintTopToBottom(Rectangle, Color, Color)@ and @getGradientPaint(int, Rectangle, Color, Color)@.
* <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.tools.api.ui.actions.ActionIds.ACTION_SIRIUS_COPY_APPEARANCE_PROPERTIES@ has been added to identify the new _Sirius Copy Appearence Properties_ action.
* <span class="label label-info">Modified</span> @org.eclipse.sirius.diagram.ui.tools.api.figure.BundleImageFigure@ now overrides the method @setBorder(Border border)@. It also provides the accessors for the new field @mainBorderSize@.
* <span class="label label-info">Modified</span> @org.eclipse.sirius.diagram.ui.tools.api.figure.BundledImageFigure@ now inherits directly from @SVGFigure@ instead of @AbstractCachedSVGFigure@.
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/color/VisualBindingManager.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/color/VisualBindingManager.java
index 6ce9135f42..f5c768ea41 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/color/VisualBindingManager.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/color/VisualBindingManager.java
@@ -556,7 +556,7 @@ public class VisualBindingManager {
}
public GradientPaint createGradientPaint() {
- return new GradientPaint(this.x, this.y, new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue()), this.w, this.h,
+ return new GradientPaint(this.x, this.y, new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue()), this.x + this.w, this.y + this.h,
new java.awt.Color(foregroundColor.getRed(), foregroundColor.getGreen(), foregroundColor.getBlue()));
}
}

Back to the top