fix(ocr): Arabic+Latin font fix and added tests

This commit is contained in:
alam00000 committed 2026-05-19 15:05:17 +05:30
1 parent 58a0053778
commit 0ce043c18e
8 files changed
+356 -165

No files matched your search

+27
View File
@@ -8,6 +8,7 @@ import {
normalizeText,
calculateWordTransform,
calculateSpaceTransform,
calculateLineFontSize,
} from '../js/utils/hocr-transform';
import type { OcrWord } from '@/types';
@@ -298,6 +299,32 @@ describe('hocr-transform', () => {
});
});
describe('calculateLineFontSize', () => {
it('returns line height + baseline intercept', () => {
const line = {
bbox: { x0: 0, y0: 100, x1: 500, y1: 130 },
baseline: { slope: 0, intercept: 2 },
textangle: 0,
words: [] as OcrWord[],
direction: 'ltr' as const,
injectWordBreaks: true,
};
expect(calculateLineFontSize(line)).toBe(32);
});
it('clamps to a minimum of 1 for degenerate lines', () => {
const line = {
bbox: { x0: 0, y0: 0, x1: 0, y1: 0 },
baseline: { slope: 0, intercept: 0 },
textangle: 0,
words: [] as OcrWord[],
direction: 'ltr' as const,
injectWordBreaks: true,
};
expect(calculateLineFontSize(line)).toBe(1);
});
});
describe('calculateSpaceTransform', () => {
const baseLine = {
bbox: { x0: 0, y0: 100, x1: 500, y1: 130 },