[K3d][K4] Text-Layout im Kern: Raumstempel, Rich-Text, Umbruch, Text-Rahmen
Neu `core/src/text_layout.rs` (Rich-Text → Zeilen/Tspans, Wortumbruch, Raumstempel-Block, einfacher Umbruch, Text-Rahmen, fontNameOf) und `core/src/plan_text.rs` (Texte aus dem Text-JSON des Plan-Puffers). Render-Szene, DXF und Druck-SVG setzen die Texte selbst beim Massstab der Ausgabe; TS übergibt kein Layout mehr. renderHtml.ts/textFrame.ts sind dünne Fassaden. Gelöscht: planSceneTexts, stampLines/textInput, drawingTextNode, runToTspan und Umbruch in TS, dxfCadParts.ts, texts_from (Szene, DXF). Gleichheit alt/neu (temporäre Tests, entfernt): 288 Pläne Szene/DXF/Druck-SVG, 600 Layouts, 3000 Stempel-Blöcke/Umbrüche, 230 CLI-Dateien byte-gleich.
This commit is contained in:
20 files changed
+1456
-720
No files matched your search
+10
-43
@@ -11,8 +11,8 @@
|
||||
import type { Vec2 } from "../model/types";
|
||||
import type { Marks, RichTextDoc } from "./richText";
|
||||
import { docFromText } from "./richText";
|
||||
import { wrapDocToLines } from "./renderHtml";
|
||||
import { contentFontBaselineFromTop, TEXT_LINE_HEIGHT_MULT } from "./fontMetrics";
|
||||
import { core } from "../engine/coreWasm";
|
||||
|
||||
/** Minimale Felder, die `textFrameCorners` braucht — sowohl `Primitive`
|
||||
* ("drawingText", PlanView.tsx) als auch `Drawing2DGeom["text"]`
|
||||
@@ -30,52 +30,19 @@ export interface TextFrameInput {
|
||||
wrapWidth?: number;
|
||||
}
|
||||
|
||||
/** Geschätzter Zeichenbreite-Faktor je Schriftgrösse — deckt sich mit
|
||||
* `CHAR_WIDTH_FACTOR` in `renderHtml.ts` (dort nicht exportiert; kein echtes
|
||||
* Font-Measuring im SVG, reicht aber für Rahmen/Griffe). */
|
||||
const TEXT_CHAR_WIDTH_FACTOR = 0.55;
|
||||
|
||||
/**
|
||||
* Vier Eckpunkte (Modell-Meter, Reihenfolge oben-links · oben-rechts ·
|
||||
* unten-rechts · unten-links VOR Rotation) eines groben Rahmens um einen
|
||||
* gezeichneten Text. Höhe aus der ECHTEN Zeilenzahl (`wrapDocToLines`,
|
||||
* dieselbe Umbruch-Logik wie beim Rendern in `primitives.tsx`
|
||||
* "drawingText"), Breite aus der längsten Zeile geschätzt (oder `wrapWidth`,
|
||||
* falls gesetzt — dann ist die Spaltenbreite exakt bekannt). `at` ist die
|
||||
* Baseline-links der ERSTEN Zeile; Rotation um `angle` (CCW, Modell-Radiant)
|
||||
* um genau diesen Punkt, analog zum SVG-`rotate` beim eigentlichen Rendern.
|
||||
* gezeichneten Text. Rechnet der Kern (`text_layout::text_frame_corners`): Höhe aus der
|
||||
* ECHTEN Zeilenzahl (derselbe Umbruch wie beim Rendern), Breite aus der längsten Zeile
|
||||
* geschätzt (UTF-16-Länge × Höhe × 0.55, oder `wrapWidth`, falls gesetzt). `at` ist die
|
||||
* Baseline-links der ERSTEN Zeile; Rotation um `angle` (CCW, Modell-Radiant) um genau
|
||||
* diesen Punkt. Hier bleibt nur die Canvas-Messung Baseline → Oberkante.
|
||||
*/
|
||||
export function textFrameCorners(p: TextFrameInput): Vec2[] {
|
||||
const doc = p.doc ?? docFromText(p.text, p.marks ?? {});
|
||||
const lineHeight = p.heightM * TEXT_LINE_HEIGHT_MULT;
|
||||
const wrapWidthUnits = p.wrapWidth && p.wrapWidth > 0 ? p.wrapWidth : undefined;
|
||||
const lines = wrapDocToLines(doc, {
|
||||
x: 0,
|
||||
y: 0,
|
||||
lineHeight,
|
||||
unitPerPt: 1,
|
||||
basePt: p.heightM,
|
||||
...(wrapWidthUnits ? { wrapWidthUnits } : {}),
|
||||
});
|
||||
const maxLineChars = lines.length
|
||||
? Math.max(1, ...lines.map((l) => l.tspans.reduce((n, t) => n + t.text.length, 0)))
|
||||
: 1;
|
||||
const width =
|
||||
wrapWidthUnits ?? Math.max(p.heightM, maxLineChars * p.heightM * TEXT_CHAR_WIDTH_FACTOR);
|
||||
const height = Math.max(1, lines.length) * lineHeight;
|
||||
// Baseline → Oberkante erste Zeile: echtes Font-Measuring statt der groben
|
||||
// "ganzes heightM"-Näherung.
|
||||
const top = p.heightM * contentFontBaselineFromTop(TEXT_LINE_HEIGHT_MULT);
|
||||
const local: Vec2[] = [
|
||||
{ x: 0, y: top },
|
||||
{ x: width, y: top },
|
||||
{ x: width, y: top - height },
|
||||
{ x: 0, y: top - height },
|
||||
];
|
||||
const cos = Math.cos(p.angle);
|
||||
const sin = Math.sin(p.angle);
|
||||
return local.map((l) => ({
|
||||
x: p.at.x + l.x * cos - l.y * sin,
|
||||
y: p.at.y + l.x * sin + l.y * cos,
|
||||
}));
|
||||
const top = contentFontBaselineFromTop(TEXT_LINE_HEIGHT_MULT);
|
||||
const f = core().text_frame(JSON.stringify(doc), Float64Array.of(p.at.x, p.at.y, p.heightM, p.angle, p.wrapWidth ?? NaN, top));
|
||||
if (f.length !== 8) return [p.at, p.at, p.at, p.at].map((q) => ({ x: q.x, y: q.y }));
|
||||
return [0, 2, 4, 6].map((i) => ({ x: f[i], y: f[i + 1] }));
|
||||
}
|
||||
Reference in new issue
Block a user