DM-305: fix isTextRenderedVisibly

This commit is contained in:
Kilian Schuettler 2023-07-11 16:35:43 +02:00
parent c88d0cf186
commit 96b27bdb21

View File

@ -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);
}