[ 
https://issues.apache.org/jira/browse/PDFBOX-5258?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17399168#comment-17399168
 ] 

Tilman Hausherr edited comment on PDFBOX-5258 at 8/14/21, 12:35 PM:
--------------------------------------------------------------------

Not part of the upcoming commit but worth to mention; this moves the 
intersectioning to the graphics device (which sadly makes it slower (tested on 
my 1000 files), but makes the files from PDFBOX-4718 and PDFBOX-4743 faster)
{code}
    protected void transferClip(PDGraphicsState graphicsState, Graphics2D 
graphics)
    {
        List<Path2D.Double> paths = graphicsState.getCurrentClippingPaths();
        boolean allDone = true;
        for (Path2D.Double path : paths)
        {
            if (!path.getPathIterator(null).isDone())
            {
                allDone = false;
                break;
            }
        }
        if (allDone)
        {
            // PDFBOX-4821: avoid bug with java printing that empty clipping 
path is ignored by
            // replacing with empty rectangle, works because this is not an 
empty path
            graphics.setClip(new Rectangle());
            return;
        }
        Path2D.Double first = paths.get(0);
        graphics.setClip(first);
        for (int i = 1; i < paths.size(); i++)
        {
            graphics.clip(paths.get(i));
        }
    }
{code}



was (Author: tilman):
Not part of the commit but worth to mention; this moves the intersectioning to 
the graphics device (which sadly makes it slower (tested on my 1000 files), but 
makes the files from PDFBOX-4718 and PDFBOX-4743 faster)
{code}
    protected void transferClip(PDGraphicsState graphicsState, Graphics2D 
graphics)
    {
        List<Path2D.Double> paths = graphicsState.getCurrentClippingPaths();
        boolean allDone = true;
        for (Path2D.Double path : paths)
        {
            if (!path.getPathIterator(null).isDone())
            {
                allDone = false;
                break;
            }
        }
        if (allDone)
        {
            // PDFBOX-4821: avoid bug with java printing that empty clipping 
path is ignored by
            // replacing with empty rectangle, works because this is not an 
empty path
            graphics.setClip(new Rectangle());
            return;
        }
        Path2D.Double first = paths.get(0);
        graphics.setClip(first);
        for (int i = 1; i < paths.size(); i++)
        {
            graphics.clip(paths.get(i));
        }
    }
{code}


> Lazier clipping
> ---------------
>
>                 Key: PDFBOX-5258
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5258
>             Project: PDFBox
>          Issue Type: Improvement
>          Components: Rendering
>    Affects Versions: 2.0.24, 3.0.0 PDFBox
>            Reporter: Tilman Hausherr
>            Priority: Major
>             Fix For: 2.0.25, 3.0.0 PDFBox
>
>
> From Stephan Schwiebert in linked PR:
> {quote}
> Calculating the intersection of two Area can take a lot of time. However, 
> depending on the Graphics2D that is used for rendering, it may not be 
> necessary to actually perform this operation.
> For instance, when generating an SVG, the individual clipping paths can be 
> serialized individually, and the intersection is then calculated at runtime, 
> when the SVG file is rendered.
> The idea of this PR is to replace PDGraphicsState.clippingPath with a list of 
> GeneralPaths, which is lazily evaluated, truncated & cached when 
> getCurrentClippingPath() is called (effectively leaving the current behaviour 
> of PdfBox unchanged, and it should also not have any significant impact on 
> the performance).
> Additionally, a new method protected void transferClip(PDGraphicsState 
> graphicsState, Graphics2D graphics) is added to PageDrawer. By default, this 
> method makes use of getCurrentClippingPath() to call graphics.setClip(...), 
> which again is what PdfBox currently does.
> However, classes that extend PageDrawer can override this method, and 
> directly access the individual clipping paths, without any need to calculate 
> their intersection.
> In some cases (shading fills & transparency groups), it is still necessary to 
> calculate the intersection.
> {quote}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to