RED-8212: fix specific case

*refactor slightly
This commit is contained in:
Kilian Schuettler 2024-01-23 12:34:41 +01:00
parent 2a9583318b
commit 323c5a47b5

View File

@ -85,6 +85,7 @@ public class InvisibleElementRemovalService {
} }
/** /**
* This method is similar to {@link #removeInvisibleElements(InputStream, OutputStream, boolean, boolean)}, just with a PDFDoc. * This method is similar to {@link #removeInvisibleElements(InputStream, OutputStream, boolean, boolean)}, just with a PDFDoc.
*/ */
@ -94,6 +95,7 @@ public class InvisibleElementRemovalService {
execute(pdfDoc, delta, removePaths); execute(pdfDoc, delta, removePaths);
} }
/** /**
* This method is equal to {@link #removeInvisibleElements(PDFDoc, boolean, boolean)}, with removePaths == true. * This method is equal to {@link #removeInvisibleElements(PDFDoc, boolean, boolean)}, with removePaths == true.
*/ */
@ -306,18 +308,12 @@ public class InvisibleElementRemovalService {
if (inClippingPath) { if (inClippingPath) {
if (isFilledAndNonTransparent(pathElement)) { if (isFilledAndNonTransparent(pathElement)) {
List<ElementFeatures> currentOverlappedElements = context.visibleElements() calculateOverlapsForLinePath(context, linePath);
.stream()
.filter(features -> almostContains(linePath, features.getBoundingBox()))
.toList();
context.overlappedElements().addAll(currentOverlappedElements);
context.visibleElements().removeAll(currentOverlappedElements);
} }
context.visibleElements().add(ElementFeatureFactory.extractFeatures(pathElement)); context.visibleElements().add(ElementFeatureFactory.extractFeatures(pathElement));
if (!context.delta()) {
writer.writeElement(pathElement);
} }
} else if (!context.delta() && !context.removePaths()) {
if (!context.delta() && (inClippingPath || !context.removePaths())) {
writer.writeElement(pathElement); writer.writeElement(pathElement);
} }
@ -332,6 +328,17 @@ public class InvisibleElementRemovalService {
} }
private void calculateOverlapsForLinePath(InvisibleElementRemovalContext context, GeneralPath linePath) {
List<ElementFeatures> currentOverlappedElements = context.visibleElements()
.stream()
.filter(features -> almostContains(linePath, features.getBoundingBox()))
.toList();
context.overlappedElements().addAll(currentOverlappedElements);
context.visibleElements().removeAll(currentOverlappedElements);
}
private void removeOverlappedElements(Page page, ElementWriter writer, InvisibleElementRemovalContext context) throws PDFNetException { private void removeOverlappedElements(Page page, ElementWriter writer, InvisibleElementRemovalContext context) throws PDFNetException {
context.reader().begin(page); context.reader().begin(page);