3

Please can some one explain the reason for an IllegalArgumentException: negative width exception being thrown when using Kabeja package?

This is the error stack that I got:

    java.lang.IllegalArgumentException: negative width
    at java.awt.BasicStroke.<init>(BasicStroke.java:181)
    at org.apache.batik.bridge.PaintServer.convertStroke(Unknown Source)
    at org.apache.batik.bridge.PaintServer.convertStrokePainter(Unknown Source)
    at org.apache.batik.bridge.SVGLineElementBridge.createFillStrokePainter(Unknown Source)
    at org.apache.batik.bridge.SVGDecoratedShapeElementBridge.createShapePainter(Unknown Source)
    at org.apache.batik.bridge.SVGShapeElementBridge.buildGraphicsNode(Unknown Source)
    at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(Unknown Source)
    at org.apache.batik.bridge.GVTBuilder.buildComposite(Unknown Source)
    at org.apache.batik.bridge.GVTBuilder.build(Unknown Source)
    at org.apache.batik.bridge.SVGUseElementBridge.buildCompositeGraphicsNode(Unknown Source)
    at org.apache.batik.bridge.SVGUseElementBridge.createGraphicsNode(Unknown Source)
    at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(Unknown Source)
    at org.apache.batik.bridge.GVTBuilder.buildComposite(Unknown Source)
    at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(Unknown Source)
    at org.apache.batik.bridge.GVTBuilder.buildComposite(Unknown Source)
    at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(Unknown Source)
    at org.apache.batik.bridge.GVTBuilder.buildComposite(Unknown Source)
    at org.apache.batik.bridge.GVTBuilder.build(Unknown Source)
    at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
    at org.apache.batik.transcoder.image.ImageTranscoder.transcode(Unknown Source)
    at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)
    at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
    at org.kabeja.batik.tools.AbstractSAXSerializer.transcode(AbstractSAXSerializer.java:214)
    at org.kabeja.batik.tools.AbstractSAXSerializer.endDocument(AbstractSAXSerializer.java:156)
    at org.kabeja.svg.SVGGenerator.generateSAX(SVGGenerator.java:361)
    at org.kabeja.svg.SVGGenerator.generate(SVGGenerator.java:88)
    at org.kabeja.xml.AbstractSAXGenerator.generate(AbstractSAXGenerator.java:37)
    at BasicFunc.DXFFileLoad.parseFile(DXFFileLoad.java:54)
    at desktopapplication3.Foundation_details.jButton1ActionPerformed(Foundation_details.java:450)
    at desktopapplication3.Foundation_details.access$200(Foundation_details.java:12)
    at desktopapplication3.Foundation_details$3.actionPerformed(Foundation_details.java:147)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6263)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6028)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4630)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.java:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2475)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Please can someone explain the reason for this exception?

Bobulous
  • 12,967
  • 4
  • 37
  • 68
LkDev
  • 221
  • 3
  • 9
  • 2
    What is the intended behavior for negative width, according to you? – Vikdor Aug 23 '12 at 07:25
  • I'm trying to generate SVG from DXF file and I have generate SVG files to set of DXF files but unfortunately I got this exception for one DXF file. But it doesn't have much different from others. – LkDev Aug 23 '12 at 07:30

3 Answers3

1

Looking at the stacktrace, it seems that the error is triggered when trying to draw the stroke of a shape using a negative width. That, of course, is not correct, since there can't be a stroke of negative width. The SVG specification even mentions that a negative width is an error.

I would say that the DXF input file is wrong. Does it render fine in Autodesk? Can you find the element with the wrong stroke, and see how it's displayed?

The solution would be to file a bug report to the Kabeja project asking for a fix. Depending on how that element is displayed in Autodesk, the negative stroke width could either be:

  1. set to 0 if the stroke shouldn't be displayed
  2. set to the absolute value if the sign should just be ignored, and a width of -1mm should be the same as 1mm.
Sergiu Dumitriu
  • 11,455
  • 3
  • 39
  • 62
0

U just need to set the data account to two (or three ) decimal places when saving the .dxf file in AUTOCAD
Screenshot of setting

Das_Geek
  • 2,775
  • 7
  • 20
  • 26
G A
  • 1
  • Hi. This isn't super helpful, since the answer is not descriptive. Try to answer a little more clearly. Also, attempt to add an explanation to your answer, why this happens. – OrdoFlammae Sep 28 '19 at 17:06
0

If you use kapeja-0.4, you can look up this class by org.kabeja.svg.generators.SVGInsertGenerator. detail

                AttributesImpl attr = new AttributesImpl();
            SVGUtils.addAttribute(attr, "transform", buf.toString());
            super.setCommonAttributes(attr, svgContext, insert);
            if (scale_x + scale_y != 0.0D && svgContext.containsKey(SVGContext.LAYER_STROKE_WIDTH)) {
                Double lw = (Double)svgContext.get(SVGContext.LAYER_STROKE_WIDTH);
                double width = lw * 2.0D / (scale_x + scale_y);
                SVGUtils.addAttribute(attr, "stroke-width", SVGUtils.formatNumberAttribute(width));
            }

Now you can modify by this: detail

                AttributesImpl attr = new AttributesImpl();
            SVGUtils.addAttribute(attr, "transform", buf.toString());
            super.setCommonAttributes(attr, svgContext, insert);
            double s = Math.abs(scale_x) + Math.abs(scale_y);
            if (s != 0.0D && svgContext.containsKey(SVGContext.LAYER_STROKE_WIDTH)) {
                Double lw = (Double)svgContext.get(SVGContext.LAYER_STROKE_WIDTH);
                double width = lw * 2.0D / s;
                SVGUtils.addAttribute(attr, "stroke-width", SVGUtils.formatNumberAttribute(width));
            }

If you use kapeja-0.5, you need do nothing.

forestxin
  • 1
  • 1