fix: bei Cluster-Ueberschuss die breitesten N Cluster waehlen
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 30s
CI / test-go-edu-search (push) Successful in 30s
CI / test-python-klausur (push) Failing after 2m5s
CI / test-python-agent-core (push) Successful in 22s
CI / test-nodejs-website (push) Successful in 20s

Wenn mehr Pixel-Cluster als Text-Gruppen existieren (z.B. wegen
Box-Rahmenlinien), werden jetzt die N breitesten Cluster ausgewaehlt
statt naiv clusters[i]→groups[i] zuzuordnen. Text-Cluster sind
breiter als Rahmenlinien-Cluster.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-03-11 14:34:58 +01:00
parent dd7087cd6d
commit 87efc1b4ba

View File

@@ -126,10 +126,20 @@ export function usePixelWordPositions(
const wordPos: WordPosition[] = []
if (groups.length > 1 && clusters.length >= groups.length) {
// Multiple text groups with enough clusters: map each group to a cluster
// When more clusters than groups, pick the N widest clusters
// (text clusters are wider than box-border clusters)
let matchClusters = clusters
if (groups.length > 1 && clusters.length > groups.length) {
matchClusters = [...clusters]
.sort((a, b) => (b.end - b.start) - (a.end - a.start))
.slice(0, groups.length)
.sort((a, b) => a.start - b.start)
}
if (groups.length > 1 && matchClusters.length >= groups.length) {
// Multiple text groups with matching clusters
for (let i = 0; i < groups.length; i++) {
const cl = clusters[i]
const cl = matchClusters[i]
const clusterW = cl.end - cl.start + 1
const measured = ctx.measureText(groups[i])
const autoFontPx = refFontSize * (clusterW / measured.width)