Merge branch 'RED-8212' into 'master'

RED-8212: fix specific case

Closes RED-8212

See merge request redactmanager/commons/pdftron-logic-commons!20
This commit is contained in:
Kilian Schüttler 2024-01-23 12:40:03 +01:00
commit 073312702c

View File

@ -85,15 +85,17 @@ 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.
*/ */
@SneakyThrows @SneakyThrows
public void removeInvisibleElements(PDFDoc pdfDoc, boolean removePaths, boolean delta) { public void removeInvisibleElements(PDFDoc pdfDoc, boolean delta, boolean removePaths) {
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,15 @@ 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() || !context.removePaths()) { }
if (!context.delta() && (inClippingPath || !context.removePaths())) {
writer.writeElement(pathElement); writer.writeElement(pathElement);
} }
}
if (context.delta() && !inClippingPath && context.removePaths()) { if (context.delta() && !inClippingPath && context.removePaths()) {
pathElement.getGState().setFillColorSpace(ColorSpace.createDeviceRGB()); pathElement.getGState().setFillColorSpace(ColorSpace.createDeviceRGB());
pathElement.getGState().setFillColor(new ColorPt(1, 0, 0)); pathElement.getGState().setFillColor(new ColorPt(1, 0, 0));
@ -329,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);