sschwieb commented on a change in pull request #127:
URL: https://github.com/apache/pdfbox/pull/127#discussion_r686419849
##########
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:
In that case, the check in
[PageDrawer.setClip](https://github.com/apache/pdfbox/pull/127/files#diff-66f2c150ea226006468292d4bfc54515e251b5b8e50d15450675a774bc70144eR386)
would always return `false`, and break the optimisation.
It would also only prevent modifications on the list itself, but the
returned paths would still be mutable. What do you think about a warning in the
JavaDoc, similar to how it is currently done with `getCurrentClippingPath`?
Something like
```
This will get the current clipping paths. Do not modify the list or
individual elements in it!
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]