Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDFGraphics2D loses color in writeSetClip #34

Open
benediktmu opened this issue Jul 30, 2015 · 0 comments
Open

PDFGraphics2D loses color in writeSetClip #34

benediktmu opened this issue Jul 30, 2015 · 0 comments

Comments

@benediktmu
Copy link

PDFGraphics2D has two bugs which share a root cause: 1. When two draw calls are in different clips but share the same color (identical rgba values), the second one is drawn black. 2. Related but slightly different: Colors set before the clip don't affect the clipped objects.

These effects happen because in writeSetClip, a new state is opened which is unaffected by the previously set color. This issue gets more pronounced by the fact that AbstractVectorGraphicsIO optimizes writePaint calls away if the previous current color is the same as the one for the new call - then even setting a color after setting a clip can fail.

The fix is simple: writeSetClip needs to take over the current color to the new state, like it already does for transform and stroke:

    protected void writeSetClip(Shape s) throws IOException {
        // clear old clip
        try {
            AffineTransform at = getTransform();
            Stroke stroke = getStroke();
            Color color = getColor(); // fix

            writeGraphicsRestore();
            writeGraphicsSave();

            writeStroke(stroke);
            writeTransform(at);
            writePaint(color); // fix
        } catch (IOException e) {
            handleException(e);
        }

        // write clip
        writeClip(s);
    }
benediktmu added a commit to benediktmu/freehep-vectorgraphics that referenced this issue Mar 21, 2016
setClip now takes over color to new state.
@benediktmu benediktmu mentioned this issue Mar 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant