You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by GitBox <gi...@apache.org> on 2021/08/10 17:09:30 UTC

[GitHub] [pdfbox] lehmi commented on a change in pull request #127: Lazier clipping

lehmi commented on a change in pull request #127:
URL: https://github.com/apache/pdfbox/pull/127#discussion_r685687060



##########
File path: pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java
##########
@@ -601,7 +612,30 @@ public void intersectClippingPath(Area area)
      */
     public Area getCurrentClippingPath()
     {
-        return clippingPath;
+        if (clippingPaths.size() == 1)
+        {
+            // If there is just a single clipping path, no intersections are needed.
+            GeneralPath path = clippingPaths.get(0);
+            return clippingCache.computeIfAbsent(path, Area::new);
+        }
+        // If there are multiple clipping paths, combine them to a single area.
+        Area clippingArea = new Area();
+        clippingArea.add(new Area(clippingPaths.get(0)));
+        for (int i = 1; i < clippingPaths.size(); i++)
+        {
+            clippingArea.intersect(new Area(clippingPaths.get(i)));
+        }
+        // Replace the list of individual clipping paths with the intersection, and add it to the cache.
+        GeneralPath newPath = new GeneralPath(clippingArea);
+        clippingPaths = new ArrayList<>();
+        clippingPaths.add(newPath);
+        clippingCache.put(newPath, clippingArea);
+        return clippingArea;
+    }
+
+    public List<GeneralPath> getCurrentClippingPaths()
+    {
+        return clippingPaths;

Review comment:
       Maybe it is a good idea to return an unmodifiable version of that list so that it can't be modified from outside?
   
   `return Collections.unmodifiableList(clippingPaths)`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org