0

How to Perform XOR from Graphics2D in SVGGraphics2D

Graphics2D g2D = (Graphics2D) svgGraphics2D;

// Using white as the XOR color.
g2D.setXORMode(Color.white);

// Draw two overlapping rectangles.
Rectangle2D r = new Rectangle2D.Double(50, 50, 150, 100);
g2D.setPaint(Color.BLACK);
g2D.fill(r);
g2D.transform(AffineTransform.getTranslateInstance(25, 25));
g2D.fill(r);

sout-> XOR Mode is not supported by Graphics2D SVG Generator

Is there a simple convert, or can I check while drawing a Pixel if its already Black. I Need to perform Black and White Overlapping for Fonts, BufferedImages, ... too. So I cant just .setPaint().

1 Answers1

0

I have tried to export SVG files with Batik's SVGGenerator from Graphics2D objects with XOR composite but it seems that it is not supported (not using setXORMode that is also not supported). I have managed to add it as a filter in Batik source but the result is not the same as the original java object. It seems that if you use operators like XOR as a filter in SVG the outcome is very different to almost useless. The only correct Batik conversion is SRC_OVER, this one is being composed as direct alpha values not as a filter.

If someone could approximate XOR operator in direct alpha values that could be great but I am not sure if this is possible, considering the differences between XOR and SRC_OVER operators.

An other option could be this library, it seems to support composite but I do not know to what extent: https://github.com/jfree/jfreesvg

jazznbass
  • 24
  • 6