Class ContrastResult

java.lang.Object
com.itextpdf.kernel.contrast.ContrastResult

public class ContrastResult extends Object
Represents the complete contrast analysis result for a single text element.

This class encapsulates all the contrast information for a text element, including the text itself and a list of all background elements that it overlaps with, along with their respective contrast ratios.

Each text element may have multiple background elements behind it, especially in complex PDF layouts. This class collects all such relationships to provide a comprehensive view of the text's contrast characteristics for accessibility analysis.

  • Constructor Details

    • ContrastResult

      public ContrastResult (TextColorInfo textRenderInfo, int pageNumber)
      Constructs a new ContrastResult for the specified text element.

      The result is initialized with an empty list of background entries, which should be populated using addContrastResult(OverlappingArea).

      Parameters:
      textRenderInfo - the text element for which contrast is being analyzed
      pageNumber - the page number where the text element is located
  • Method Details

    • getPageNumber

      public int getPageNumber()
      Gets the page number where the text element is located.
      Returns:
      the page number
    • getTextRenderInfo

      public TextColorInfo getTextRenderInfo()
      Gets the text render information for this contrast result.

      The text information includes the character, parent text, color, geometric path, and font size of the text element being analyzed.

      Returns:
      the text render information
    • addContrastResult

      public void addContrastResult (ContrastResult.OverlappingArea overlappingArea)
      Adds a background contrast entry to this result.

      Each entry represents a background element that the text overlaps with, along with the calculated contrast ratio between the text color and background color. Multiple entries indicate that the text appears over multiple backgrounds.

      Parameters:
      overlappingArea - the contrast result entry containing background information and contrast ratio
    • getOverlappingAreas

      public List<ContrastResult.OverlappingArea> getOverlappingAreas()
      Gets all the background contrast entries for this text element.

      Each entry in the list represents a background element that the text overlaps with, containing the background's color, path, and the calculated contrast ratio. The list may be empty if no backgrounds were detected, or may contain multiple entries if the text overlaps multiple background elements.

      Returns:
      an unmodifiable view of the list of contrast result entries