Skip to content

Commit

Permalink
Fix contrast ratio detection in case of exception
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Jan 30, 2025
1 parent 9294e40 commit 9e04072
Showing 2 changed files with 1 addition and 4 deletions.
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ public class TextChunk extends TextInfoChunk {
private double fontWeight;
private double italicAngle;
private double[] fontColor;
private double contrastRatio;
private double contrastRatio = Integer.MAX_VALUE;
private boolean hasSpecialStyle = false;
private boolean hasSpecialBackground = false;
private double[] backgroundColor;
Original file line number Diff line number Diff line change
@@ -111,7 +111,6 @@ private void calculateContrastRatio(SemanticTextNode node) {

public void calculateContrastRation(TextChunk textChunk, BufferedImage renderedPage) {
if ((textChunk.getValue() != null && (TextChunkUtils.isWhiteSpaceChunk(textChunk)))) {
textChunk.setContrastRatio(Integer.MAX_VALUE);
return;
}

@@ -129,15 +128,13 @@ public void calculateContrastRation(TextChunk textChunk, BufferedImage renderedP
if (isOverlappingBox) {
scaledBBox = scaledBBox.cross(pageBBox);
} else if (!pageBBox.contains(scaledBBox)) {
textChunk.setContrastRatio(Integer.MAX_VALUE);
return;
}
int x = (int) (Math.round(scaledBBox.getLeftX()));
int y = (int) (Math.round(scaledBBox.getTopY()));
int width = getIntegerBBoxValueForProcessing(scaledBBox.getWidth(), 1);
int height = getIntegerBBoxValueForProcessing(scaledBBox.getHeight(), 1);
if (width <= 1 || height <= 1) {
textChunk.setContrastRatio(Integer.MAX_VALUE);
return;
}
try {

0 comments on commit 9e04072

Please sign in to comment.