From 24c0a2c2ee772c068635770e7584e5410c2420f4 Mon Sep 17 00:00:00 2001 From: Carlos Fernandez Date: Sat, 20 Dec 2025 20:03:42 +0100 Subject: [PATCH] fix(ocr): Future-proof Tesseract version check for 6+ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The version check for Tesseract was explicitly checking for versions "4." and "5." which would fail for future Tesseract versions (6, 7, etc.). Changed the check to use TessVersion()[0] >= '4' which will correctly handle all versions >= 4.0. Tesseract 4+ uses: - Different tessdata path convention (appends /tessdata to path) - Different default OEM mode (1 = LSTM vs 0 = Legacy) The previous explicit check would cause future Tesseract versions to incorrectly use the legacy Tesseract 3.x code path. Addresses remaining concern from #1412 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/lib_ccx/hardsubx.c | 4 +++- src/lib_ccx/ocr.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib_ccx/hardsubx.c b/src/lib_ccx/hardsubx.c index 7ddff8d4..3d15de25 100644 --- a/src/lib_ccx/hardsubx.c +++ b/src/lib_ccx/hardsubx.c @@ -266,7 +266,9 @@ struct lib_hardsubx_ctx *_init_hardsubx(struct ccx_s_options *options) int ret = -1; - if (!strncmp("4.", TessVersion(), 2) || !strncmp("5.", TessVersion(), 2)) + // Tesseract 4+ uses different tessdata path convention and default OEM mode + // Use >= '4' check to handle future versions (5, 6, 7, etc.) + if (TessVersion()[0] >= '4') { char tess_path[1024]; if (ccx_options.ocr_oem < 0) diff --git a/src/lib_ccx/ocr.c b/src/lib_ccx/ocr.c index 45c7ffb0..0684ba6b 100644 --- a/src/lib_ccx/ocr.c +++ b/src/lib_ccx/ocr.c @@ -191,7 +191,9 @@ void *init_ocr(int lang_index) } ctx->api = TessBaseAPICreate(); - if (!strncmp("4.", TessVersion(), 2) || !strncmp("5.", TessVersion(), 2)) + // Tesseract 4+ uses different tessdata path convention and default OEM mode + // Use >= '4' check to handle future versions (5, 6, 7, etc.) + if (TessVersion()[0] >= '4') { char tess_path[1024]; snprintf(tess_path, 1024, "%s%s%s", tessdata_path, "/", "tessdata");