diff --git a/src/main/java/com/iqser/red/pdftronlogic/commons/InvisibleElementRemovalService.java b/src/main/java/com/iqser/red/pdftronlogic/commons/InvisibleElementRemovalService.java index cacb66f..7153441 100644 --- a/src/main/java/com/iqser/red/pdftronlogic/commons/InvisibleElementRemovalService.java +++ b/src/main/java/com/iqser/red/pdftronlogic/commons/InvisibleElementRemovalService.java @@ -252,7 +252,7 @@ public class InvisibleElementRemovalService { PathData pathData = pathElement.getPathData(); if (pathData.getOperators().length == 0 && pathData.getPoints().length == 0 || pathElement.getBBox() == null) { - writer.writeElement(pathElement); + writer.writeGStateChanges(pathElement); return; } @@ -387,16 +387,18 @@ public class InvisibleElementRemovalService { private boolean isTextRenderedVisibly(GState gState, Rect textBBox, InvisibleElementRemovalContext context) throws PDFNetException { - return gState.getTextRenderMode() != GState.e_invisible_text && // - !(gState.getTextRenderMode() == GState.e_fill_text && fillIsVisible(gState, textBBox, context)) && // - !(gState.getTextRenderMode() == GState.e_stroke_text && strokeIsVisible(gState, textBBox, context)) && // - !(gState.getTextRenderMode() == GState.e_fill_stroke_text && (fillIsVisible(gState, textBBox, context) || strokeIsVisible(gState, textBBox, context))); + return switch (gState.getTextRenderMode()) { + case GState.e_invisible_text -> false; + case GState.e_fill_text -> fillIsVisible(gState, textBBox, context); + case GState.e_stroke_text -> strokeIsVisible(gState, textBBox, context); + default -> fillIsVisible(gState, textBBox, context) || strokeIsVisible(gState, textBBox, context); + }; } private boolean strokeIsVisible(GState gState, Rect textBBox, InvisibleElementRemovalContext context) throws PDFNetException { - return gState.getStrokeOpacity() == 0 && differentColorThanBackgroundColor(Converter.convertColor(gState.getStrokeColorSpace(), gState.getStrokeColor()), + return gState.getStrokeOpacity() != 0 && differentColorThanBackgroundColor(Converter.convertColor(gState.getStrokeColorSpace(), gState.getStrokeColor()), textBBox, context); } @@ -404,7 +406,7 @@ public class InvisibleElementRemovalService { private boolean fillIsVisible(GState gState, Rect textBBox, InvisibleElementRemovalContext context) throws PDFNetException { - return gState.getFillOpacity() == 0 && differentColorThanBackgroundColor(Converter.convertColor(gState.getFillColorSpace(), gState.getFillColor()), textBBox, context); + return gState.getFillOpacity() != 0 && differentColorThanBackgroundColor(Converter.convertColor(gState.getFillColorSpace(), gState.getFillColor()), textBBox, context); }