fix: Slide-Modus Scale-Berechnung auf Ink-Span statt Ink-Count
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 36s
CI / test-go-edu-search (push) Successful in 31s
CI / test-python-klausur (push) Failing after 2m11s
CI / test-python-agent-core (push) Successful in 24s
CI / test-nodejs-website (push) Successful in 31s
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 36s
CI / test-go-edu-search (push) Successful in 31s
CI / test-python-klausur (push) Failing after 2m11s
CI / test-python-agent-core (push) Successful in 24s
CI / test-nodejs-website (push) Successful in 31s
totalInk zaehlte nur dunkle Pixel-Spalten (Striche), ignorierte Luecken zwischen Buchstaben. Scale war dadurch viel zu klein, Schrift unlesbar. Jetzt wird der Ink-Span (erstes bis letztes dunkles Pixel) als Referenz fuer die Textbreite verwendet. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -129,16 +129,23 @@ export function useSlideWordPositions(
|
|||||||
const spaceWidth = ctx.measureText(' ').width
|
const spaceWidth = ctx.measureText(' ').width
|
||||||
const totalTextW = tokenWidths.reduce((a, b) => a + b, 0) + (tokens.length - 1) * spaceWidth
|
const totalTextW = tokenWidths.reduce((a, b) => a + b, 0) + (tokens.length - 1) * spaceWidth
|
||||||
|
|
||||||
// Scale factor: how much to scale reference measurements to cell pixels
|
// Scale factor: map measured text width → pixel width on image.
|
||||||
// We use the total ink coverage as reference for total text width.
|
// Use the total INK SPAN (first dark pixel to last dark pixel),
|
||||||
let totalInk = 0
|
// not the count of dark columns. Text characters have gaps between
|
||||||
for (let x = 0; x < cw; x++) totalInk += ink[x]
|
// strokes, so counting only dark pixels gives a much-too-small scale.
|
||||||
|
let firstInk = -1, lastInk = -1
|
||||||
|
for (let x = 0; x < cw; x++) {
|
||||||
|
if (ink[x]) {
|
||||||
|
if (firstInk < 0) firstInk = x
|
||||||
|
lastInk = x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If almost no ink, fall back to centering
|
// If almost no ink, skip
|
||||||
if (totalInk < 3) continue
|
if (firstInk < 0 || lastInk <= firstInk) continue
|
||||||
|
|
||||||
// The scale maps measured text width → pixel width on the image
|
const inkSpan = lastInk - firstInk + 1
|
||||||
const scale = Math.min(totalInk / totalTextW, cw / totalTextW)
|
const scale = inkSpan / totalTextW
|
||||||
|
|
||||||
// --- Slide each token from left to right ---
|
// --- Slide each token from left to right ---
|
||||||
const wordPos: WordPosition[] = []
|
const wordPos: WordPosition[] = []
|
||||||
|
|||||||
Reference in New Issue
Block a user