Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 363281 - CopyToImageAction fails if the diagram contains any figure that has a negative line width
Summary: CopyToImageAction fails if the diagram contains any figure that has a negativ...
Status: NEW
Alias: None
Product: GMF-Runtime
Classification: Modeling
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows Vista
: P3 normal
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-09 05:51 EST by Andreas Mayer CLA
Modified: 2011-11-09 05:51 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Mayer CLA 2011-11-09 05:51:06 EST
Build Identifier: M20110909-1335

CopyToImageAction (File > Save As Image File ...) fails with an IllegalArgumentException("negative width") from java.awt.BasicStroke, if any figure in the diagram has a negative line width (see also bug #243187). 

java.lang.IllegalArgumentException: negative width
    at java.awt.BasicStroke.<init>(BasicStroke.java:192)
    at org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.graphics.GraphicsToGraphics2DAdaptor.createStroke(GraphicsToGraphics2DAdaptor.java:1543)
    at org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.graphics.GraphicsToGraphics2DAdaptor.drawPolygon(GraphicsToGraphics2DAdaptor.java:633)
    at org.eclipse.draw2d.Graphics.drawPolygon(Graphics.java:293)
    at org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.ScaledGraphics.drawPolygon(ScaledGraphics.java:356)
    at org.eclipse.draw2d.Polygon.outlineShape(Polygon.java:64)
    at org.eclipse.draw2d.Shape.paintOutline(Shape.java:175)
    at org.eclipse.draw2d.Shape.paintFigure(Shape.java:147)
    at org.eclipse.draw2d.Figure.paint(Figure.java:1115)
    at org.eclipse.draw2d.Figure.paintChildren(Figure.java:1167)
    at org.eclipse.draw2d.Figure.paintClientArea(Figure.java:1202)
    at org.eclipse.draw2d.Figure.paint(Figure.java:1117)
    at org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramGenerator.paintFigure(DiagramGenerator.java:373)
    at org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramGenerator.renderToGraphics(DiagramGenerator.java:237)
    at org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramGenerator.createSWTImageDescriptorForParts(DiagramGenerator.java:721)
    at org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUtil.copyToImage(CopyToImageUtil.java:376)
    at org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUtil.copyToImage(CopyToImageUtil.java:305)
    at org.eclipse.gmf.runtime.diagram.ui.render.actions.CopyToImageAction$1.run(CopyToImageAction.java:260)
    at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464)
    at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372)
    at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)
    at org.eclipse.gmf.runtime.diagram.ui.render.actions.CopyToImageAction.runCopyToImageUI(CopyToImageAction.java:170)
    [...]

Troubleshooting is difficult here, because the operation fails completely and the exception provides no hint at the offending figure. The Javadocs of Graphics don't specify a behaviour for negative line widths, but under Windows, lines with a negative width are drawn with a line width of 1. If GraphicsToGraphics2DAdaptor would do the same, then CopyToImageAction could succeed and you would be able to spot the error in the resulting image. Therefore, GraphicsToGraphics2DAdator.createStroke() should be changed as follows:

  /*
-  * SWT paints line width == 0 as if it is == 1, so AWT is synced up with that below.
+  * SWT paints line width <= 0 as if it is == 1, so AWT is synced up with that below.
   */
  stroke =
      new BasicStroke(
-         currentState.lineAttributes.width != 0 ? currentState.lineAttributes.width : 1,
+         currentState.lineAttributes.width > 0 ? currentState.lineAttributes.width : 1,
          awt_cap,
          awt_join,
          currentState.lineAttributes.miterLimit,
          awt_dash,
          currentState.lineAttributes.dashOffset);


Reproducible: Always