From 7f8615b8c1dd08ce0a2e4405951420ec0b8b0293 Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Tue, 10 Mar 2026 14:28:23 +0100 Subject: [PATCH] fix: Schriftgroesse auf haeufigsten Wert (Mode) normalisieren Alle Wortgruppen bekommen die gleiche fontRatio (gerundet auf 0.02), basierend auf der haeufigsten berechneten Groesse. Ueberschriften und Fliesstext haben damit einheitliche Schriftgroesse. Co-Authored-By: Claude Opus 4.6 --- .../components/ocr-pipeline/StepLlmReview.tsx | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/admin-lehrer/components/ocr-pipeline/StepLlmReview.tsx b/admin-lehrer/components/ocr-pipeline/StepLlmReview.tsx index 9f9161c..45ee16e 100644 --- a/admin-lehrer/components/ocr-pipeline/StepLlmReview.tsx +++ b/admin-lehrer/components/ocr-pipeline/StepLlmReview.tsx @@ -221,6 +221,29 @@ export function StepLlmReview({ sessionId, onNext }: StepLlmReviewProps) { positions.set(cell.cell_id, wordPos) } + // Normalise: find the most common fontRatio (mode) and apply it to all + const allRatios: number[] = [] + for (const wps of positions.values()) { + for (const wp of wps) allRatios.push(wp.fontRatio) + } + if (allRatios.length > 0) { + // Bucket ratios to 2 decimal places, find mode + const buckets = new Map() + for (const r of allRatios) { + const key = Math.round(r * 50) / 50 // round to nearest 0.02 + buckets.set(key, (buckets.get(key) || 0) + 1) + } + let modeRatio = allRatios[0] + let modeCount = 0 + for (const [ratio, count] of buckets) { + if (count > modeCount) { modeRatio = ratio; modeCount = count } + } + // Apply mode to all word positions + for (const wps of positions.values()) { + for (const wp of wps) wp.fontRatio = modeRatio + } + } + setCellWordPositions(positions) } img.src = imgUrl