[194] Plan-Texte auf macOS in der nativen Fläche: Glyphen-Pass im selben Frame wie die Linien

Raumstempel und waagrechte Textfelder/Masszahlen/Beschriftungen (mehrzeilig, Umbruch, fett/kursiv,
Ausrichtung) zeichnet der Chunk-Renderer der Metal-Fläche selbst, mit demselben glyphon-Pass wie der
Browser (neu render2d/src/glyph.rs, eingebettetes Inter, Zeilen einmal geshapt und je Frame nur
skaliert). Zeilen setzt der Kern (neue Bindung plan_screen_texts, Layout text_layout.rs), die Webview
schickt sie roh als f64-Bytes (Tauri-Befehl native2d_scene_texts, Satz-Massstab im Header); Anker in
f64 (Landeskoordinaten). Gedrehte Einzeiler bleiben Vektor-Glyphen (vtext), volle Umdrehungen (2π bei
Masszahlen) gelten als waagrecht. Das SVG-Overlay zeichnet nur noch gedrehte Mehrzeiler, Text auf Pfad
und den Text im Editor; lehnt die Fläche ab, bleibt alles im Overlay.

Szene: Schnitt (Bit 0 fett, Bit 1 kursiv) im Byte über der Ausrichtung (scene_bin), damit auch der
Browser fette Stempelnamen zeigt; die Bildschirm-Szene (plan_scene_bin) lässt gedrehte Einzeltexte weg
(vorher ungedreht doppelt zum SVG gezeichnet). Exporte unverändert (plan_scene_texts).

Tests: Kern text.rs (Schnitt, gedrehte/Editor-Texte ausgelassen), render2d text_lines (Puffer lesen,
kaputte Puffer), scene_bin (Schnitt-Bits), headless chunk_renderer_zeichnet_textzeilen (lavapipe:
fett, Ausrichtung, Zoom), vitest nativeText, e2e nativeOverlaySync (Texte an die Fläche, nicht im
Overlay; Rückfall). render_png --chunks … --texts angesehen (Musterhaus komplex, Software-Vulkan).
Nicht auf dem Mac/in der Tauri-App geprüft (native_embed.rs/lib.rs dort nicht kompiliert).
This commit is contained in:
Claude committed 2026-11-12 02:34:00 +00:00
1 parent 05f4293fe2
commit f837b85bbb
27 files changed
+894 -295

No files matched your search

+5 -3
View File
@@ -4,7 +4,7 @@
// `PlanView`; die Reihenfolge der Hooks und Effekte ist wie vor der Aufteilung.
import { useRef, useEffect, useMemo, useState, useLayoutEffect } from "react";
import { PlanPickIndex, planTextEntries, materializeGreyed, materializeUnderlay, roomStampAt, buildDrawingIndex, isGpuText, meetScale, PLAN_DASH_VAR, toScreen, scaleFromView, PX_PER_M } from "../../../core";
import { PlanPickIndex, planTextEntries, materializeGreyed, materializeUnderlay, roomStampAt, buildDrawingIndex, isGpuText, isSceneText, meetScale, PLAN_DASH_VAR, toScreen, scaleFromView, PX_PER_M } from "../../../core";
import { useNativeAvailable, useNativePlanRenderer } from "../useNativePlanRenderer";
import { useWasmPlanRenderer } from "../useWasmPlanRenderer";
import type { UnderlayGroup, DrawingIndex, Primitive, ViewBox__plan_planView_geometry as ViewBox } from "../../../core";
@@ -197,12 +197,14 @@ export function usePlanEngine(inp: UsePlanEngineArgs) {
? p.kind !== "drawingText"
: p.kind !== "text" && p.kind !== "drawingText"
: p.kind === "line" && !!p.drawingId;
// Einfache Texte zeichnet die native Fläche selbst (Vektor-Glyphen, auch gedreht).
// Texte zeichnet die native Fläche selbst, im selben Frame wie die Linien ([194]): Raumstempel und
// waagrechte Textfelder über den Glyphen-Pass, gedrehte Einzeiler als Vektor-Glyphen.
if (useGpuRenderer && wantNative && nativeHook.sceneTexts && isSceneText(p)) continue;
if (useGpuRenderer && wantNative && nativeHook.gpuTexts && isGpuText(p)) continue;
if (!drawnElsewhere) out.push({ p, i });
}
return out;
}, [plan, useGpuRenderer, wantWasm, wantNative, nativeHook.gpuTexts]);
}, [plan, useGpuRenderer, wantWasm, wantNative, nativeHook.gpuTexts, nativeHook.sceneTexts]);
const needsCull = svgCandidates.length > CULL_THRESHOLD;
const [cullState, setCullState] = useState<CullState | null>(() => {
if (!needsCull) return null;
+1 -1
View File
@@ -25,7 +25,7 @@ export interface UsePlanHighlightsArgs {
editTextId: string | null | undefined;
useGpuRenderer: boolean;
wantNative: boolean;
nativeHook: { render: (viewBox: ViewBox, paperScaleN?: number, _textScale?: number, onSent?: () => void) => void; updateGeometry: (plan: Plan, pxPerMeter?: number) => void; ready: boolean; gpuTexts: boolean; setExcludedText: (id: string | null) => void; setHighlight: (prims: readonly Primitive[], color: string) => void; setDashScale: (n: number) => void; };
nativeHook: { render: (viewBox: ViewBox, paperScaleN?: number, _textScale?: number, onSent?: () => void) => void; updateGeometry: (plan: Plan, pxPerMeter?: number) => void; ready: boolean; gpuTexts: boolean; sceneTexts: boolean; setExcludedText: (id: string | null) => void; setHighlight: (prims: readonly Primitive[], color: string) => void; setDashScale: (n: number) => void; };
toLocal: (p: Vec2) => Vec2;
overlayHeavyRef: React.MutableRefObject<boolean>;
selectedCeilingIds: string[];
+61 -7
View File
@@ -5,7 +5,9 @@
*
* Kompilierung + Chunk-Cache bleiben TypeScript (`GpuChunkCache` mit `NativeGl`);
* Rust hält die Puffer. Pan/Zoom kostet nur noch einen kleinen Frame-Aufruf.
* Eingaben, Auswahl, Griffe, Text bleiben im SVG-Overlay darüber.
* Texte zeichnet die Fläche im selben Frame wie die Linien ([194], s. nativeText.ts): Raumstempel
* und waagrechte Textfelder über den Glyphen-Pass, gedrehte Einzeiler als Vektor-Glyphen.
* Eingaben, Auswahl, Griffe und der Text-Editor bleiben im SVG-Overlay darüber.
*/
import { useCallback, useEffect, useRef, useState } from 'react';
@@ -18,7 +20,7 @@ import { NativeGl, type NativeInvoke } from './nativeGl';
import { readCssColor } from './cssColor';
import { NativeFrameQueue } from './nativeFrameQueue';
import { NativeTextSync } from "../../core";
import { planTextEntries } from "../../core";
import { planTextEntries, planScreenTexts } from "../../core";
/** Läuft die App in einer Tauri-Webview? */
const isTauri = (): boolean => typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;
@@ -87,6 +89,44 @@ export function useNativePlanRenderer(
const highlightGeom = useRef<GpuGeometry | null>(null);
const lastPxPerMeter = useRef(0);
const excludedText = useRef<string | null>(null);
// Glyphen-Pass ([194]): Raumstempel + waagrechte Textfelder, gesetzt im Kern zum Text-Massstab.
// `sceneTexts` = die Fläche hat sie angenommen (bis dahin zeichnet sie das SVG-Overlay).
const [sceneTexts, setSceneTexts] = useState(false);
const sceneTextsDisabled = useRef(false);
const sceneTextsSent = useRef<{ plan: Plan; n: number; skip: string | null } | null>(null);
const textScaleRef = useRef(100);
const sceneTextsRetries = useRef(0);
const pushSceneTexts = useCallback(function push(plan: Plan | null) {
const invoke = invokeRef.current;
if (!invoke || !plan || sceneTextsDisabled.current) return;
const n = textScaleRef.current;
const skip = excludedText.current;
const last = sceneTextsSent.current;
if (last && last.plan === plan && last.n === n && last.skip === skip) return;
sceneTextsSent.current = { plan, n, skip };
const skipIndex = skip == null ? -1 : (planTextEntries(plan).find((e) => e.p.kind === 'drawingText' && e.p.drawingId === skip)?.i ?? -1);
const f = planScreenTexts(plan, n, skipIndex);
if (f.length === 0) return; // Kern konnte nicht lesen: Stand behalten
const bytes = new Uint8Array(f.buffer, f.byteOffset, f.byteLength);
void invoke('native2d_scene_texts', bytes, { headers: { 'x-text-scale': String(n) } })
.then((ok) => {
if (ok === true) {
sceneTextsRetries.current = 0;
setSceneTexts(true);
} else {
// Fläche (noch) nicht bereit: etwas später erneut versuchen (höchstens ein paar Mal).
sceneTextsSent.current = null;
setSceneTexts(false);
if (sceneTextsRetries.current++ < 10) setTimeout(() => push(lastPlan.current), 300);
}
})
.catch(() => {
// Ältere App ohne den Befehl: Texte bleiben im SVG-Overlay.
sceneTextsDisabled.current = true;
setSceneTexts(false);
});
}, []);
const pushTexts = useCallback((plan: Plan | null) => {
const invoke = invokeRef.current;
@@ -115,8 +155,9 @@ export function useNativePlanRenderer(
if (excludedText.current === id) return;
excludedText.current = id;
pushTexts(lastPlan.current);
pushSceneTexts(lastPlan.current);
},
[pushTexts],
[pushTexts, pushSceneTexts],
);
// Frame-Aufrufe zusammenfassen: höchstens einer in der Luft, der letzte gewinnt ([145]: das
@@ -183,6 +224,12 @@ export function useNativePlanRenderer(
highlightGeom.current = null;
lastSentGeoms.current = null;
setGpuTexts(false);
if (sceneTextsSent.current) {
const empty = new Uint8Array(new Float64Array([0]).buffer);
void invoke('native2d_scene_texts', empty, { headers: { 'x-text-scale': '100' } }).catch(() => {});
}
sceneTextsSent.current = null;
setSceneTexts(false);
const { delete: del } = glRef.current.takeLayout([]);
void invoke('native2d_layout', { layout: [], delete: del }).catch(() => {});
void invoke('native2d_embed_hide').catch(() => {});
@@ -280,7 +327,8 @@ export function useNativePlanRenderer(
);
}
pushTexts(plan);
}, [pushTexts, takeFullLayout]);
pushSceneTexts(plan);
}, [pushTexts, pushSceneTexts, takeFullLayout]);
// Plot-Massstab der Strichmuster (`setDashScale`), mit jedem Frame gesendet.
const dashScaleRef = useRef(0);
@@ -292,13 +340,19 @@ export function useNativePlanRenderer(
* `onSent`: läuft synchron, sobald der Frame an die Fläche geht (gleicher Takt wie deren
* Zeichnen) — dort setzt die Ansicht das SVG-Overlay (Texte, Griffe) auf denselben Ausschnitt.
*/
(viewBox: ViewBox, paperScaleN = 100, _textScale?: number, onSent?: () => void) => {
(viewBox: ViewBox, paperScaleN = 100, textScaleN = 100, onSent?: () => void) => {
const invoke = invokeRef.current;
if (!invoke) {
onSent?.();
return;
}
syncRect();
// Text-Massstab gewechselt (Druckansicht ↔ Anzeige): Zeilen VOR dem Frame neu setzen lassen.
const tn = textScaleN > 0 && Number.isFinite(textScaleN) ? textScaleN : 100;
if (tn !== textScaleRef.current) {
textScaleRef.current = tn;
pushSceneTexts(lastPlan.current);
}
const sheet = readCssColor('--sheet');
frames.current!.send(
() =>
@@ -311,8 +365,8 @@ export function useNativePlanRenderer(
onSent,
);
},
[syncRect],
[syncRect, pushSceneTexts],
);
return { render, updateGeometry, ready, gpuTexts, setExcludedText, setHighlight, setDashScale };
return { render, updateGeometry, ready, gpuTexts, sceneTexts, setExcludedText, setHighlight, setDashScale };
}