mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-11 01:14:35 +01:00
fix(ocr): Arabic+Latin font fix and added tests
This commit is contained in:
1 parent
58a0053778
commit
0ce043c18e
8 files changed
+356
-165
No files matched your search
@@ -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 },
|
||||
|
||||
Reference in new issue
Block a user