Archived
God-Files aufgeteilt (ResourceManager/generatePlan/toWalls3d/App.tsx-Handler), Totcode entfernt (geometry-Crate, OCCT/HLR-Spike), PDF/Bild-Import ergänzt.
ResourceManager.tsx, generatePlan.ts und toWalls3d.ts sind nach Bauteil- Domäne in src/ui/resourceManager/, src/plan/generatePlan/ und src/plan/toWalls3d/ aufgeteilt (reine Verschiebung, keine Verhaltens- änderung). App.tsx verliert weitere Handler-Gruppen an eigene Hooks (useExportHandlers, useImportHandling, useKeyboardShortcuts) sowie Hit-Testing an src/viewport/planHitTest.ts. Unbenutzte Rust-geometry-Crate (durch WASM-Joins abgelöst) sowie der alte OCCT/HLR-Schnitt-Spike (hlr.ts/occt.ts, vite occt-Aliases) entfernt. Neu: PDF-Import als Rasterbild (src/io/pdfImport.ts) + gemeinsamer Bild-Asset-Helfer (src/io/imageAsset.ts) für Plan- und Layout-Bilder. tsc -b sauber, vitest 891/891 grün.
This commit is contained in:
1 parent
06c0143d32
commit
1507c2bf00
85 files changed
+12461
-11280
No files matched your search
@@ -0,0 +1,58 @@
|
||||
// Tests für wrapDocToLines: Wortumbruch auf feste Breite unter Erhalt der
|
||||
// Run-Grenzen (gemischte Formatierung pro Zeile bleibt möglich).
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { docFromText, makeRun, type RichTextDoc } from "./richText";
|
||||
import { docToLines, wrapDocToLines } from "./renderHtml";
|
||||
|
||||
const OPTS = { x: 0, y: 0, lineHeight: 10, unitPerPt: 1, basePt: 10, color: "#000000" };
|
||||
|
||||
describe("wrapDocToLines", () => {
|
||||
it("ohne wrapWidthUnits identisch zu docToLines (eine Zeile je Absatz)", () => {
|
||||
const doc = docFromText("hallo welt");
|
||||
expect(wrapDocToLines(doc, OPTS)).toEqual(docToLines(doc, OPTS));
|
||||
});
|
||||
|
||||
it("bricht lange Absätze wortweise auf mehrere Zeilen um", () => {
|
||||
const doc = docFromText("eins zwei drei vier fünf");
|
||||
const lines = wrapDocToLines(doc, { ...OPTS, wrapWidthUnits: 30 });
|
||||
expect(lines.length).toBeGreaterThan(1);
|
||||
const joined = lines.map((l) => l.tspans.map((t) => t.text).join("")).join(" ");
|
||||
expect(joined.replace(/\s+/g, " ").trim()).toBe("eins zwei drei vier fünf");
|
||||
});
|
||||
|
||||
it("respektiert Run-Grenzen: ein fett formatiertes Wort bleibt in einem eigenen Tspan", () => {
|
||||
const doc: RichTextDoc = {
|
||||
version: 1,
|
||||
paragraphs: [
|
||||
{
|
||||
runs: [
|
||||
makeRun("normal ", {}),
|
||||
makeRun("fett", { bold: true }),
|
||||
makeRun(" weiter", {}),
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
const lines = wrapDocToLines(doc, { ...OPTS, wrapWidthUnits: 1000 });
|
||||
expect(lines).toHaveLength(1);
|
||||
const boldTspan = lines[0].tspans.find((t) => t.text === "fett");
|
||||
expect(boldTspan?.fontWeight).toBe("700");
|
||||
const otherTspans = lines[0].tspans.filter((t) => t.text !== "fett");
|
||||
expect(otherTspans.every((t) => t.fontWeight === undefined)).toBe(true);
|
||||
});
|
||||
|
||||
it("leerer Absatz erzeugt eine leere Zeile (Vorschub bleibt erhalten)", () => {
|
||||
const doc: RichTextDoc = { version: 1, paragraphs: [{ runs: [] }, { runs: [makeRun("x")] }] };
|
||||
const lines = wrapDocToLines(doc, { ...OPTS, wrapWidthUnits: 100 });
|
||||
expect(lines).toHaveLength(2);
|
||||
expect(lines[0].tspans).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("sehr schmale Breite bricht auf ein Wort je Zeile um, ohne Wörter zu verlieren", () => {
|
||||
const doc = docFromText("aa bb cc");
|
||||
const lines = wrapDocToLines(doc, { ...OPTS, wrapWidthUnits: 1 });
|
||||
const words = lines.map((l) => l.tspans.map((t) => t.text).join("").trim());
|
||||
expect(words).toEqual(["aa", "bb", "cc"]);
|
||||
});
|
||||
});
|
||||
@@ -167,6 +167,81 @@ export function docToLines(doc: RichTextDoc, opts: SvgTextOptions): SvgLine[] {
|
||||
}));
|
||||
}
|
||||
|
||||
/** Geschätzte Zeichenbreite als Vielfaches der Schriftgrösse (gleiche Heuristik
|
||||
* wie der bisherige Wortumbruch für einheitlich formatierten Text, s.
|
||||
* PlanView.tsx `case "drawingText"`) — kein echtes Font-Metrics-Messen, aber
|
||||
* für die Platzierung von Zeilenumbrüchen ausreichend. */
|
||||
const CHAR_WIDTH_FACTOR = 0.55;
|
||||
|
||||
/**
|
||||
* Wie {@link docToLines}, bricht aber zusätzlich wortweise auf `wrapWidthUnits`
|
||||
* um (in denselben Benutzereinheiten wie `SvgTextOptions.x`) — für Textfelder/
|
||||
* -rahmen mit fester Breite (InDesign-artig). Ohne `wrapWidthUnits` identisch
|
||||
* zu `docToLines` (eine Zeile je Absatz). Respektiert Run-Grenzen: ein Wort
|
||||
* behält die Formatierung seines Runs, auch wenn die Zeile mehrere Runs mischt.
|
||||
*/
|
||||
export function wrapDocToLines(
|
||||
doc: RichTextDoc,
|
||||
opts: SvgTextOptions & { wrapWidthUnits?: number },
|
||||
): SvgLine[] {
|
||||
if (!opts.wrapWidthUnits || opts.wrapWidthUnits <= 0) return docToLines(doc, opts);
|
||||
const basePt = opts.basePt ?? 12;
|
||||
const color = opts.color ?? "#000000";
|
||||
const baseUnit = basePt * opts.unitPerPt;
|
||||
const maxWidth = opts.wrapWidthUnits;
|
||||
|
||||
interface Token {
|
||||
tspan: SvgTspan;
|
||||
widthUnits: number;
|
||||
isSpace: boolean;
|
||||
}
|
||||
|
||||
const lines: SvgLine[] = [];
|
||||
for (const p of doc.paragraphs) {
|
||||
const lineHeight = p.lineHeight != null ? baseUnit * p.lineHeight : opts.lineHeight;
|
||||
const align = p.align ?? "left";
|
||||
|
||||
const tokens: Token[] = [];
|
||||
for (const run of p.runs) {
|
||||
if (run.text.length === 0) continue;
|
||||
const base = runToTspan(run, basePt, opts.unitPerPt, color);
|
||||
for (const part of run.text.split(/(\s+)/).filter((s) => s.length > 0)) {
|
||||
const isSpace = /^\s/.test(part);
|
||||
tokens.push({
|
||||
tspan: { ...base, text: part },
|
||||
widthUnits: part.length * base.fontSize * CHAR_WIDTH_FACTOR,
|
||||
isSpace,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (tokens.length === 0) {
|
||||
lines.push({ tspans: [], align, lineHeight });
|
||||
continue;
|
||||
}
|
||||
|
||||
let current: Token[] = [];
|
||||
let currentWidth = 0;
|
||||
const flush = () => {
|
||||
while (current.length && current[current.length - 1].isSpace) current.pop();
|
||||
lines.push({ tspans: current.map((t) => t.tspan), align, lineHeight });
|
||||
current = [];
|
||||
currentWidth = 0;
|
||||
};
|
||||
for (const tok of tokens) {
|
||||
if (current.length === 0 && tok.isSpace) continue;
|
||||
if (current.length > 0 && currentWidth + tok.widthUnits > maxWidth) {
|
||||
flush();
|
||||
if (tok.isSpace) continue;
|
||||
}
|
||||
current.push(tok);
|
||||
currentWidth += tok.widthUnits;
|
||||
}
|
||||
flush();
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
function runToTspan(run: TextRun, basePt: number, unitPerPt: number, color: string): SvgTspan {
|
||||
const m = run.marks;
|
||||
const script = m.super || m.sub;
|
||||
|
||||
Reference in new issue
Block a user