Browse our Products

Aspose.OCR for Java 26.8 - Release Notes

What was changed

KeySummaryCategory
OCRJAVA‑469Added support for recognizing currency symbols, including , £, and ¥, when using the Language.ExtLatin recognition language.Enhancement
OCRJAVA‑474Added font detection support for recognized text lines, including font family, style, size, and confidence values.New feature

Public API changes and backwards compatibility

This section lists all public API changes introduced in Aspose.OCR for Java 26.8 that may affect the code of existing applications.

Added public APIs:

The following public APIs have been introduced in this release:

com.aspose.ocr.RecognitionSettings.setDetectFonts - a new method

Enables font detection for each recognized text line. When enabled, font information is returned in RecognitionResult.LinesResult.font.

New Methods

MethodDescription
void setDetectFonts(boolean detectFonts)Enables or disables font detection.

com.aspose.ocr.FontLineResult - a new class

Contains detected font information for a recognized text line.

New Fields

FieldDescription
int lineIndexZero-based line index in the processed font batch.
int sizePxDetected line height in pixels.
Double sizePtEstimateEstimated font size in points. Can be null when the estimate is unavailable.
String styleDetected font style, for example regular, italic, or bold_italic.
double styleConfidenceConfidence score for the detected style.
String fontDetected font family name.
double fontConfidenceConfidence score for the detected font family.

com.aspose.ocr.RecognitionResult.LinesResult.font - a new field

Returns FontLineResult for the recognized text line when font detection is enabled.

Updated public APIs:

No signature changes.

Recognition with Language.ExtLatin has been improved to handle currency symbols such as , £, and ¥.

Removed public APIs:

No changes.

Examples

The code samples below illustrate the changes introduced in this release:

Detect fonts in recognized text lines

import com.aspose.ocr.AsposeOCR;
import com.aspose.ocr.FontLineResult;
import com.aspose.ocr.InputType;
import com.aspose.ocr.OcrInput;
import com.aspose.ocr.PreprocessingFilter;
import com.aspose.ocr.RecognitionResult;
import com.aspose.ocr.RecognitionSettings;
import com.aspose.ocr.models.DetectAreasMode;
import com.aspose.ocr.models.Language;

import java.util.ArrayList;

public class FontDetectionExample {
    public static void main(String[] args) throws Exception {
        String file = "source.png";

        RecognitionSettings settings = new RecognitionSettings();
        settings.setDetectFonts(true);

        PreprocessingFilter filters = new PreprocessingFilter();
        OcrInput input = new OcrInput(InputType.SingleImage, filters);
        input.add(file);

        try (AsposeOCR api = new AsposeOCR()) {
            ArrayList<RecognitionResult> results = api.Recognize(input, settings);
            RecognitionResult result = results.get(0);

            System.out.println("--- full text ---");
            System.out.println(result.recognitionText);

            if (result.recognitionRegionsResult != null) {
                for (RecognitionResult.RegionResult region : result.recognitionRegionsResult) {
                    System.out.println("--- region ---");
                    System.out.println("Rectangle: " + region.region);
                    System.out.println("Type: " + region.regionType);
                    System.out.println("Text: " + region.textInRegion);
                }
            }

            for (RecognitionResult.LinesResult line : result.recognitionLinesResult) {
                if (line.textInLine == null || line.textInLine.trim().isEmpty()) {
                    continue;
                }

                System.out.println("--- line ---");
                System.out.println("Rectangle: " + line.line);
                System.out.println("Confidence: " + line.confidence);
                System.out.println("Text: " + line.textInLine);

                FontLineResult font = line.font;
                if (font == null) {
                    System.out.println("Font was not detected. Enable it with RecognitionSettings.setDetectFonts(true).");
                    continue;
                }

                System.out.println("Font line index: " + font.lineIndex);
                System.out.println("Font family: " + font.font);
                System.out.println("Font confidence: " + font.fontConfidence);
                System.out.println("Style: " + font.style);
                System.out.println("Style confidence: " + font.styleConfidence);
                System.out.println("Size in pixels: " + font.sizePx);
                System.out.println("Estimated size in points: " + font.sizePtEstimate);
            }
        }
    }
}