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:
commit
073312702c
@ -50,11 +50,11 @@ public class InvisibleElementRemovalService {
|
|||||||
* -Elements covered by widely stroked path
|
* -Elements covered by widely stroked path
|
||||||
* -Any Text set to clipping with its many interactions with other elements
|
* -Any Text set to clipping with its many interactions with other elements
|
||||||
*
|
*
|
||||||
* @param pdfFile The PDF file to process
|
* @param pdfFile The PDF file to process
|
||||||
* @param removePaths If this flag is set, invisible path elements will be removed
|
* @param removePaths If this flag is set, invisible path elements will be removed
|
||||||
* @param delta If this flag is set only the removed Elements will be written to the output file.
|
* @param delta If this flag is set only the removed Elements will be written to the output file.
|
||||||
* The Elements are red if they are removed by clipping path, blue for transparency, and a green bounding box for overlap.
|
* The Elements are red if they are removed by clipping path, blue for transparency, and a green bounding box for overlap.
|
||||||
* @param out OutputStream to write the resulting file to
|
* @param out OutputStream to write the resulting file to
|
||||||
**/
|
**/
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void removeInvisibleElements(InputStream pdfFile, OutputStream out, boolean delta, boolean removePaths) {
|
public void removeInvisibleElements(InputStream pdfFile, OutputStream out, boolean delta, boolean removePaths) {
|
||||||
@ -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()) {
|
|
||||||
writer.writeElement(pathElement);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!context.delta() && (inClippingPath || !context.removePaths())) {
|
||||||
|
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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user