[226] Schriftfamilien im GPU-Text: Familie je Zeile im Szenenformat, Glyphen-Atlas je Familie/Schnitt lazy (WOFF2 in render2d), Messung mit denselben Metriken

This commit is contained in:
Claude committed 2026-11-12 22:43:58 +00:00
1 parent 35c26f9e85
commit cc14b1c837
84 files changed
+1063 -31

No files matched your search

+4 -2
View File
@@ -682,6 +682,8 @@ pub struct SText {
pub align: u32,
/// Schnitt der Zeile ([194], erster Lauf): Bit 0 fett, Bit 1 kursiv.
pub style: u32,
/// Schriftfamilie ([226]): 0 = Inter, sonst `text_layout::font_family_id`.
pub family: u32,
pub content: Vec<u8>,
}
@@ -791,7 +793,7 @@ pub fn encode_scene_bin(s: &Scene, texts: &[SText]) -> Vec<u8> {
for t in texts {
f(&mut rec, t.size_mm);
// Ausrichtung im unteren Byte, Schnitt darüber ([194], `render2d/src/scene_bin.rs`).
u(&mut rec, t.align | (t.style << 8));
u(&mut rec, t.align | (t.style << 8) | (t.family << 16));
u(&mut rec, strs.len() as u32);
u(&mut rec, t.content.len() as u32);
col(&mut rec, &t.color);
@@ -890,7 +892,7 @@ mod tests {
lines: vec![SLine { a: v2(0.0, 0.0), b: v2(2600000.5, 1200000.25), color: [0.0, 0.5, 0.0, 1.0], width_mm: 0.35, dash: SDash::List(vec![3.0, 1.0, 0.5, 1.0]), z: 4.0 }],
line_ends: 0,
};
let t = |x: f64, y: f64, content: &str, size_mm: f64, color: Rgba, align: u32| SText { pos: v2(x, y), size_mm, color, align, style: 0, content: content.as_bytes().to_vec() };
let t = |x: f64, y: f64, content: &str, size_mm: f64, color: Rgba, align: u32| SText { pos: v2(x, y), size_mm, color, align, style: 0, family: 0, content: content.as_bytes().to_vec() };
let texts = vec![
t(1.0, 2.0, "Küche 12,5 m²", 2.5, [0.0, 0.0, 0.0, 1.0], 1),
t(3.0, 4.0, "", 2.0, [0.0, 0.0, 0.0, 1.0], 2),
+18 -5
View File
@@ -13,7 +13,7 @@ use crate::plan::buf::{whole, T_DRAWING_TEXT, T_TEXT};
use crate::plan::dxf::{StampLine as DxfLine, TextIn, TextStyleIn};
use crate::plan::parts::{in_ranges, Part};
use crate::plan::scene::{to_rgba, Rgba, SText, STYLE_BOLD, STYLE_ITALIC};
use crate::text_layout::{doc_from_text, font_name_of, is_blank, plain_text, split_ws, stamp_block, stamp_line_offsets, wrap_doc_to_lines, LayoutOpts, LineAlign, Placed, PT_TO_MM, TEXT_LINE_HEIGHT_MULT};
use crate::text_layout::{doc_from_text, font_family_id, font_name_of, is_blank, plain_text, split_ws, stamp_block, stamp_line_offsets, wrap_doc_to_lines, LayoutOpts, LineAlign, Placed, PT_TO_MM, TEXT_LINE_HEIGHT_MULT};
use serde::{Deserialize, Deserializer};
fn num<'de, D: Deserializer<'de>>(d: D) -> Result<f64, D::Error> {
@@ -119,8 +119,13 @@ fn greyed_color(c: Rgba, greyed: bool) -> Rgba {
}
#[allow(clippy::too_many_arguments)]
fn push(out: &mut Vec<SText>, x: f64, y: f64, content: String, size_mm: f64, color: Rgba, align: LineAlign, style: u32) {
out.push(SText { pos: crate::hatch::V2 { x, y }, size_mm, color, align: align.code(), style, content: content.into_bytes() });
fn push(out: &mut Vec<SText>, x: f64, y: f64, content: String, size_mm: f64, color: Rgba, align: LineAlign, style: u32, family: u32) {
out.push(SText { pos: crate::hatch::V2 { x, y }, size_mm, color, align: align.code(), style, family, content: content.into_bytes() });
}
/// [226] Schriftfamilie einer gesetzten Zeile aus ihrem ersten Lauf (0 = Inter, auch für nicht gebündelte Namen).
fn line_family(line: &crate::text_layout::Line) -> u32 {
font_family_id(line.tspans.first().and_then(|s| font_name_of(s.font_family.as_deref())).as_deref())
}
/// Schnitt einer gesetzten Zeile aus ihrem ersten Lauf (wie der DXF-Export, `stamp_lines`).
@@ -193,7 +198,7 @@ fn stamp_scene(t: &StampText, forced: bool, mm_to_m: f64, out: &mut Vec<SText>)
let fill = line.tspans.first().map(|s| s.fill.as_str()).or(color);
let c = greyed_color(to_rgba(fill).unwrap_or(def), greyed);
let dx = offsets.get(k).copied().unwrap_or(0.0) * mm_to_m;
push(out, t.at.x + dx, t.at.y - y * mm_to_m, content, line.max_size().unwrap_or(base_mm), c, line.align, line_style(line));
push(out, t.at.x + dx, t.at.y - y * mm_to_m, content, line.max_size().unwrap_or(base_mm), c, line.align, line_style(line), line_family(line));
}
}
@@ -217,7 +222,7 @@ fn single_scene(t: &SingleText, forced: bool, mm_to_m: f64, out: &mut Vec<SText>
let fill = line.tspans.first().map(|s| s.fill.as_str()).or(color);
let c = greyed_color(to_rgba(fill).unwrap_or(def), greyed);
let style = line_style(&line);
push(out, t.at.x, t.at.y - dy, content, if unit_per_pt > 0.0 { size_m / mm_to_m } else { size_m }, c, line.align, style);
push(out, t.at.x, t.at.y - dy, content, if unit_per_pt > 0.0 { size_m / mm_to_m } else { size_m }, c, line.align, style, line_family(&line));
}
}
@@ -341,6 +346,14 @@ mod tests {
assert!((big[1].size_mm - 20.0 * PT_TO_MM).abs() < 1e-3, "{}", big[1].size_mm);
assert_eq!(big[1].style, STYLE_BOLD | STYLE_ITALIC);
assert_eq!(big[1].color, [1.0, 0.0, 0.0, 1.0]);
assert_eq!((plain[1].family, big[1].family), (0, 0));
// [226] Schriftfamilie der Zeile reist in die Szene: Serifenschrift = Kennung 15, Arial (nicht gebündelt) = Inter.
let serif = run(r##","marks":{"font":"'Source Serif 4', serif"}"##);
assert_eq!(serif[1].family, 15);
assert_eq!(run(r##","marks":{"font":"Arial"}"##)[1].family, 0);
// Block-Breite und Zeilenlage folgen der Metrik der gewählten Schrift (Serif ≠ Inter).
let (wide_inter, wide_serif) = (run(r##","marks":{"sizePt":30}"##), run(r##","marks":{"sizePt":30,"font":"Source Serif 4"}"##));
assert!((wide_serif[1].pos.x - wide_inter[1].pos.x).abs() > 1e-4, "{} {}", wide_serif[1].pos.x, wide_inter[1].pos.x);
// Grössere Zeile: der Block wird höher, die erste Grundlinie rückt nach oben (Modell-y nach oben).
assert!(big[0].pos.y > plain[0].pos.y);
}