DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
U: Font menu with search, favourites and previews; persist engine preferences
Brandon Thomasc9785ae1eddd
diff --git a/ROADMAP.md b/ROADMAP.mdindex 8fbcd8c49..84b0c8967 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -60,6 +60,8 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope- User dictionary hyphenation exceptions (`hyphenation.addException/removeException/list`, Edit ▸ Spelling ▸ User Dictionary): `ex~am~ple` breaks only at `~`, a plain word never hyphenates.- Frame Fitting Options (`object.fittingOptions`, Object ▸ Fitting ▸ Frame Fitting Options…): Auto-Fit refits on resize, fitting, Align From reference point, crop amounts; IDML FrameFittingOption.- Paragraph borders (per-side weights, colour, tint, offsets) and shading offsets, drawn per column part of split paragraphs (also when overset); Paragraph panel controls; IDML ParagraphBorder*/ParagraphShading*Offset.+- Font menu: search, favourites (stars, Show Favorites Only; `favoriteFonts` preference) and each family previewed in its own face.+- Application preferences (engine `Prefs`) now persist across launches (desktop: prefs.json beside ui.json).- Drag and drop text editing: drag selected text to move it (Alt copies) with its formatting (`text.release`).- Image Import Options: place any page of a multi-page PDF (`file.place {pdfPage}`; the app asks which page), shown on screen and embedded as that page in PDF export.- Define Lists: named numbered lists that continue across stories in page order (`list.define`, paragraph `listName` / `startAt`), round-tripped through IDML; `null` in `type.para` / `type.char` now removes an override.@@ -108,7 +110,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope## How far from full parity (estimate, 2026-10-02, updated)-**Breadth: ~87% weighted** (P0 core 99%, P1 88%, P2 38%) over the 275 features of the InDesign catalogue, scored+**Breadth: ~89% weighted** (P0 core 99%, P1 92%, P2 39%) over the 275 features of the InDesign catalogue, scoredrow by row in [docs/parity.md](docs/parity.md) (`cargo xtask parity` recomputes it). Many features scored done stilllack some of InDesign's options or dialog details, so **overall parity including depth is about 72%**.diff --git a/apps/designcraft/src/main.rs b/apps/designcraft/src/main.rsindex 046ffd1a6..222511ec5 100644--- a/apps/designcraft/src/main.rs+++ b/apps/designcraft/src/main.rs@@ -63,6 +63,13 @@ fn load_prefs(app: &mut DesignApp) {{app.ui = ui;}+ // Engine preferences (Preferences dialog, favourites…) live beside the UI state.+ if let Some(p) = prefs_path().map(|p| p.with_file_name("prefs.json"))+ && let Ok(bytes) = std::fs::read(&p)+ && let Ok(prefs) = serde_json::from_slice::<designcraft_engine::Prefs>(&bytes)+ {+ app.session.prefs = prefs;+ }}fn save_prefs(app: &DesignApp) {@@ -72,7 +79,10 @@ fn save_prefs(app: &DesignApp) {if let Some(p) = prefs_path() {let _ = std::fs::create_dir_all(p.parent().unwrap_or(std::path::Path::new(".")));if let Ok(bytes) = serde_json::to_vec_pretty(&app.ui) {- let _ = std::fs::write(p, bytes);+ let _ = std::fs::write(&p, bytes);+ }+ if let Ok(bytes) = serde_json::to_vec_pretty(&app.session.prefs) {+ let _ = std::fs::write(p.with_file_name("prefs.json"), bytes);}}}diff --git a/crates/engine/src/cmd/prefs.rs b/crates/engine/src/cmd/prefs.rsindex 54ecc2abe..27d31b173 100644--- a/crates/engine/src/cmd/prefs.rs+++ b/crates/engine/src/cmd/prefs.rs@@ -47,7 +47,7 @@ pub fn specs() -> Vec<CommandSpec> {"Preferences",[],None,- "{showHiddenCharacters?, typographersQuotes?, polygonSides?, starInset?, scaleStrokes?, dimensionsIncludeStroke?, transformationsAreTotals?, absolutePageNumbers?, highlightHj?, highlightKeeps?, highlightCustomTracking?, highlightSubstitutedFonts?, richBlackOutput?} → all application preferences",+ "{showHiddenCharacters?, typographersQuotes?, polygonSides?, starInset?, scaleStrokes?, dimensionsIncludeStroke?, transformationsAreTotals?, absolutePageNumbers?, highlightHj?, highlightKeeps?, highlightCustomTracking?, highlightSubstitutedFonts?, richBlackOutput?, favoriteFonts?: [family]} → all application preferences",super::always,|s, p| {let cur = serde_json::to_value(&s.prefs).map_err(|e| bad("prefs.set", e.to_string()))?;diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rsindex 5c5e5b4d4..629266907 100644--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@ -147,6 +147,8 @@ pub struct Prefs {/// Preferences › Appearance of Black › Printing / Exporting: 100% K as rich (pure) black in/// RGB output (PNG) instead of the accurate dark grey.pub rich_black_output: bool,+ /// Font menu favourites (family names).+ pub favorite_fonts: Vec<String>,/// Preferences › Type › Smart Text Reflow: pages follow the primary text frame's story/// (added while it oversets, empty ones at the end removed).pub smart_text_reflow: bool,@@ -168,6 +170,7 @@ impl Default for Prefs {highlight_custom_tracking: false,highlight_substituted_fonts: true,rich_black_output: false,+ favorite_fonts: Vec::new(),smart_text_reflow: true,}}diff --git a/crates/render/src/glyphs.rs b/crates/render/src/glyphs.rsindex 1bf23be02..3cf584df8 100644--- a/crates/render/src/glyphs.rs+++ b/crates/render/src/glyphs.rs@@ -43,6 +43,38 @@ pub fn glyph_grid(family: &str, style: &str, chars: &[char], cols: u32, cell: u3Rendered { width: w as u32, height: h as u32, pixels }}+/// `text` set in `family`/`style` on one line, `height` pixels tall (the em fits the height), in+/// `color` on transparency — for font menus that preview each family.+pub fn text_line(family: &str, style: &str, text: &str, height: u32, color: [u8; 4]) -> Rendered {+ let db = FontDb::global();+ let face = db.face(family, style);+ let upem = face.units_per_em().max(1.0);+ let k = height as f64 * 0.72 / upem;+ let glyphs = designcraft_fonts::shape(&face, text, &[], |c| c);+ let width: f64 = glyphs.iter().map(|g| g.x_advance as f64 * k).sum::<f64>().ceil() + 2.0;+ let (w, h) = ((width as u32).clamp(1, 2048) as u16, height.clamp(1, 512) as u16);+ let mut ctx = RenderContext::new(w, h);+ ctx.set_paint(peniko::Color::from_rgba8(color[0], color[1], color[2], color[3]));+ let (asc, desc) = face.vertical_metrics();+ let baseline = h as f64 / 2.0 + (asc - desc.abs()) / 2.0 * k;+ let mut x = 1.0;+ for g in &glyphs {+ let outline = db.outline(&face, g.gid);+ if !outline.elements().is_empty() {+ ctx.set_transform(+ kurbo::Affine::translate((x + g.x_offset as f64 * k, baseline - g.y_offset as f64 * k)) * kurbo::Affine::scale_non_uniform(k, -k),+ );+ ctx.fill_path(&outline);+ }+ x += g.x_advance as f64 * k;+ }+ ctx.flush();+ let mut pixels = vec![0u8; w as usize * h as usize * 4];+ let mut res = Resources::new();+ ctx.render(vello_cpu::PixmapMut::new(w, h, &mut pixels).expect("buffer size"), &mut res);+ Rendered { width: w as u32, height: h as u32, pixels }+}+#[cfg(test)]mod tests {use super::*;@@ -57,4 +89,13 @@ mod tests {assert!(ink(0, 0) > 30 && ink(1, 0) > 30 && ink(0, 1) > 30, "letters drawn");assert_eq!(ink(1, 1), 0, "a space is blank");}++ #[test]+ fn text_line_draws_the_name() {+ let img = text_line(designcraft_fonts::DEFAULT_FAMILY, "Regular", "Serif", 24, [0, 0, 0, 255]);+ assert_eq!(img.height, 24);+ assert!(img.width > 30);+ let ink = (0..img.width).flat_map(|x| (0..img.height).map(move |y| (x, y))).filter(|&(x, y)| img.pixel(x, y)[3] > 128).count();+ assert!(ink > 40, "{ink}");+ }}diff --git a/crates/ui-egui/src/panels/mod.rs b/crates/ui-egui/src/panels/mod.rsindex 9e11c9c93..7beb995c5 100644--- a/crates/ui-egui/src/panels/mod.rs+++ b/crates/ui-egui/src/panels/mod.rs@@ -167,16 +167,99 @@ pub fn swatch_picker(app: &mut DesignApp, ui: &mut egui::Ui, id: &str, current:}}+/// A five-pointed star (filled, or outlined).+fn paint_star(p: &egui::Painter, c: egui::Pos2, r: f32, filled: bool, color: egui::Color32) {+ let pt = |i: usize, rad: f32| {+ let a = -std::f32::consts::FRAC_PI_2 + i as f32 * std::f32::consts::PI / 5.0;+ c + egui::vec2(a.cos(), a.sin()) * rad+ };+ let outline: Vec<egui::Pos2> = (0..10).map(|i| pt(i, if i % 2 == 0 { r } else { r * 0.42 })).collect();+ if filled {+ // The inner pentagon and the five points (each convex).+ let inner: Vec<egui::Pos2> = (0..5).map(|i| outline[2 * i + 1]).collect();+ p.add(egui::Shape::convex_polygon(inner, color, egui::Stroke::NONE));+ for i in 0..5 {+ p.add(egui::Shape::convex_polygon(vec![outline[(2 * i + 9) % 10], outline[2 * i], outline[2 * i + 1]], color, egui::Stroke::NONE));+ }+ } else {+ p.add(egui::Shape::closed_line(outline, egui::Stroke::new(1.0, color)));+ }+}++/// The Font menu: search, favourites (★, Show Favorites Only), and each family's name shown in+/// that family.pub fn font_family_picker(app: &mut DesignApp, ui: &mut egui::Ui, current: &str, width: f32) {let fams = designcraft_fonts::FontDb::global().families();+ let mut favs = app.session.prefs.favorite_fonts.clone();let mut pick = None;- egui::ComboBox::from_id_salt("font_family").selected_text(if current.is_empty() { "—" } else { current }).width(width).show_ui(ui, |ui| {- for f in &fams {- if ui.selectable_label(f == current, f).clicked() {- pick = Some(f.clone());+ let mut favs_changed = false;+ let state_id = egui::Id::new("font_menu_state");+ let (mut query, mut only_favs): (String, bool) = ui.data(|d| d.get_temp(state_id)).unwrap_or_default();+ let t = crate::theme::Tokens::get(ui.ctx());+ egui::ComboBox::from_id_salt("font_family").selected_text(if current.is_empty() { "—" } else { current }).width(width).height(420.0).show_ui(+ ui,+ |ui| {+ ui.set_min_width(300.0);+ ui.horizontal(|ui| {+ ui.add(egui::TextEdit::singleline(&mut query).hint_text("Search fonts").desired_width(200.0));+ ui.toggle_value(&mut only_favs, "Favorites").on_hover_text("Show Favorites Only");+ });+ let q = query.to_lowercase();+ let ppp = ui.ctx().pixels_per_point();+ let shown: Vec<&String> =+ fams.iter().filter(|f| (q.is_empty() || f.to_lowercase().contains(&q)) && (!only_favs || favs.contains(f))).collect();+ for f in shown {+ let (row, resp) = ui.allocate_exact_size(egui::vec2(ui.available_width(), 24.0), egui::Sense::click());+ if !ui.is_rect_visible(row) {+ continue;+ }+ if f == current {+ ui.painter().rect_filled(row, 0.0, t.row_selected);+ } else if resp.hovered() {+ ui.painter().rect_filled(row, 0.0, t.hover);+ }+ // Favourite star.+ let star = egui::Rect::from_min_size(row.min + egui::vec2(2.0, 4.0), egui::vec2(16.0, 16.0));+ let fav = favs.contains(f);+ let sr = ui.interact(star, ui.id().with(("fav", f)), egui::Sense::click());+ paint_star(ui.painter(), star.center(), 6.5, fav, if fav { t.accent } else { t.text_dim });+ if sr.clicked() {+ if fav {+ favs.retain(|x| x != f);+ } else {+ favs.push(f.clone());+ }+ favs_changed = true;+ }+ ui.painter().text(row.min + egui::vec2(22.0, 12.0), egui::Align2::LEFT_CENTER, f, egui::FontId::proportional(12.0), t.text);+ // The name in its own face (rendered once per family and scale).+ let key = egui::Id::new(("font_preview", f, (ppp * 100.0) as u32, t.text.to_array()));+ let tex: Option<egui::TextureHandle> = ui.data(|d| d.get_temp(key));+ let tex = tex.unwrap_or_else(|| {+ let img = designcraft_render::glyphs::text_line(f, "Regular", "Sample", (18.0 * ppp) as u32, t.text.to_array());+ let ci = egui::ColorImage::from_rgba_premultiplied([img.width as usize, img.height as usize], &img.pixels);+ let h = ui.ctx().load_texture(format!("font_preview_{f}"), ci, egui::TextureOptions::LINEAR);+ ui.data_mut(|d| d.insert_temp(key, h.clone()));+ h+ });+ let size = tex.size_vec2() / ppp;+ let at = egui::pos2(row.max.x - size.x - 4.0, row.center().y - size.y / 2.0);+ ui.painter().image(+ tex.id(),+ egui::Rect::from_min_size(at, size),+ egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(1.0, 1.0)),+ egui::Color32::WHITE,+ );+ if resp.clicked() {+ pick = Some(f.clone());+ }}- }- });+ },+ );+ ui.data_mut(|d| d.insert_temp(state_id, (query, only_favs)));+ if favs_changed {+ let _ = app.run("prefs.set", json!({ "favoriteFonts": favs }));+ }if let Some(f) = pick {let styles = designcraft_fonts::FontDb::global().styles(&f);let style = if styles.iter().any(|s| s == "Regular") { "Regular".to_string() } else { styles.first().cloned().unwrap_or_default() };diff --git a/docs/parity.md b/docs/parity.mdindex 66a9b2978..40241f94b 100644--- a/docs/parity.md+++ b/docs/parity.md@@ -10,7 +10,7 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia| Priority | Features | Done | Partial | Missing | Parity ||---|---|---|---|---|---|| P0 | 102 | 99 | 3 | 0 | 99% |-| P1 | 97 | 83 | 13 | 1 | 92% |+| P1 | 97 | 84 | 12 | 1 | 93% || P2 | 76 | 23 | 13 | 40 | 39% || Area | Parity |@@ -23,7 +23,7 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia| Fill, stroke, colour | 93% || Effects & transparency | 71% || Placing & links | 82% |-| Type & text frames | 92% |+| Type & text frames | 94% || Typography | 94% || Styles | 92% || Tables | 92% |@@ -202,7 +202,7 @@ Open P0 items: Preferences, Vector/page formats (PDF/AI/SVG/EPS place), Export t| Type & text frames | Create Outlines | P1 | D || Type & text frames | Change Case | P0 | D || Type & text frames | Show Hidden Characters | P0 | D |-| Type & text frames | Font menu with preview, favourites | P1 | P |+| Type & text frames | Font menu with preview, favourites | P1 | D || Type & text frames | Missing fonts handling | P0 | D || Type & text frames | Footnotes | P1 | D || Type & text frames | Endnotes | P2 | D |