Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

T: Preferences › Advanced Type (super/subscript size and position)

Brandon Thomas53ec1e046cad
diff --git a/ROADMAP.md b/ROADMAP.md
index c42088809..761a164ee 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -40,6 +40,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope
- Object ▸ Select (first/next above, next/last below, container, content, previous/next in group), full Object ▸ Convert Shape (`object.convertShape`), Table ▸ Split Cell Horizontally/Vertically.
- Attributes panel (`object.attributes`: Overprint Fill/Stroke/Gap, Nonprinting), with Overprint Gap in Overprint Preview and IDML.
- Page Numbering View (Preferences: section or absolute): page labels everywhere follow it; Go to Page takes section names, numbers or `+n`.
+- Preferences › Advanced Type (document `advancedType`: superscript/subscript size and position; IDML TextPreference); subscripts now drop 33.3% like InDesign.
- 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.
@@ -88,7 +89,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: ~84% weighted** (P0 core 99%, P1 84%, P2 24%) over the 275 features of the InDesign catalogue, scored
+**Breadth: ~85% weighted** (P0 core 99%, P1 87%, P2 24%) over the 275 features of the InDesign catalogue, scored
row by row in [docs/parity.md](docs/parity.md) (`cargo xtask parity` recomputes it). Many features scored done still
lack some of InDesign's options or dialog details, so **overall parity including depth is about 70%**.
diff --git a/crates/compose/src/cache.rs b/crates/compose/src/cache.rs
index cf4b16336..039e14b54 100644
--- a/crates/compose/src/cache.rs
+++ b/crates/compose/src/cache.rs
@@ -88,6 +88,9 @@ impl Cache {
format!("{:?}", doc.footnote_options).hash(&mut h);
sig.extend([doc.footnote_start(sid) as usize, h.finish() as usize]);
}
+ // Advanced Type sizes super/subscripts.
+ let a = doc.settings.advanced_type;
+ sig.extend([a.superscript_size, a.superscript_position, a.subscript_size, a.subscript_position].map(|v| v.to_bits() as usize));
// Named lists continue from earlier stories.
for l in &doc.settings.lists {
sig.push(doc.list_start(sid, &l.name) as usize);
diff --git a/crates/compose/src/lib.rs b/crates/compose/src/lib.rs
index fe099264b..ae0f3e755 100644
--- a/crates/compose/src/lib.rs
+++ b/crates/compose/src/lib.rs
@@ -475,7 +475,7 @@ pub fn compose(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &Compo
pi,
prange.clone(),
&base_chars,
- pp.auto_leading,
+ shape::TypeEnv { auto_leading: pp.auto_leading, adv: doc.settings.advanced_type },
&sub,
&mut table,
&pp.nested_styles,
@@ -1456,7 +1456,19 @@ fn prepend_label(
let mut tmp = Story::new(StoryId(0));
tmp.insert(0, label);
let styles = designcraft_doc::Styles::default();
- let shaped = shape::shape_para(db, &styles, &tmp, 0, 0..label.len(), base, pp.auto_leading, &SubstCtx::default(), table, &[], &[]);
+ let shaped = shape::shape_para(
+ db,
+ &styles,
+ &tmp,
+ 0,
+ 0..label.len(),
+ base,
+ shape::TypeEnv { auto_leading: pp.auto_leading, adv: Default::default() },
+ &SubstCtx::default(),
+ table,
+ &[],
+ &[],
+ );
let mut pre: Vec<Glyph> = shaped
.glyphs
.into_iter()
diff --git a/crates/compose/src/shape.rs b/crates/compose/src/shape.rs
index 0ae7259d6..c23f55ad0 100644
--- a/crates/compose/src/shape.rs
+++ b/crates/compose/src/shape.rs
@@ -142,7 +142,7 @@ pub(crate) fn shape_para(
pi: usize,
range: std::ops::Range<usize>,
para_chars: &CharProps,
- auto_leading: f64,
+ auto_leading: TypeEnv,
sub: &SubstCtx,
table: &mut StyleTable<'_>,
nested: &[designcraft_doc::NestedStyle],
@@ -255,7 +255,7 @@ fn shape_run(
text: &str,
range: std::ops::Range<usize>,
p: &CharProps,
- auto_leading: f64,
+ auto_leading: TypeEnv,
style: u32,
sub: &SubstCtx,
out: &mut Vec<Glyph>,
@@ -439,27 +439,34 @@ fn shape_cached(face: &FontFace, src: &str, feats: &[Feature], caps: bool) -> Ve
out
}
-fn metrics(face: &FontFace, p: &CharProps, auto_leading: f64) -> (f64, f64, f64, f64, f64, f64, f64, f64) {
- let (size, shift) = effective_size(p);
+fn metrics(face: &FontFace, p: &CharProps, auto_leading: TypeEnv) -> (f64, f64, f64, f64, f64, f64, f64, f64) {
+ let (size, shift) = effective_size(p, &auto_leading.adv);
let k = size / face.upem;
let vs = p.v_scale;
let leading = match p.leading {
- Leading::Auto => p.size * auto_leading,
+ Leading::Auto => p.size * auto_leading.auto_leading,
Leading::Points(v) => v,
};
(size, k, face.ascent * k * vs, face.descent * k * vs, leading, face.cap_height * k * vs, face.x_height * k * vs, shift)
}
-/// Super/subscript use 58.3% size and ±33.3% / −10% shift (InDesign's defaults).
-fn effective_size(p: &CharProps) -> (f64, f64) {
+/// Auto leading and the document's Advanced Type settings, for shaping.
+#[derive(Clone, Copy, Debug)]
+pub struct TypeEnv {
+ pub auto_leading: f64,
+ pub adv: designcraft_doc::AdvancedType,
+}
+
+/// Synthesised super/subscript: size and shift from Advanced Type (percent of the font size).
+fn effective_size(p: &CharProps, adv: &designcraft_doc::AdvancedType) -> (f64, f64) {
match p.position {
- Position::Superscript => (p.size * 0.583, p.baseline_shift + p.size * 0.333),
- Position::Subscript => (p.size * 0.583, p.baseline_shift - p.size * 0.333 * 0.3),
+ Position::Superscript => (p.size * adv.superscript_size / 100.0, p.baseline_shift + p.size * adv.superscript_position / 100.0),
+ Position::Subscript => (p.size * adv.subscript_size / 100.0, p.baseline_shift - p.size * adv.subscript_position / 100.0),
_ => (p.size, p.baseline_shift),
}
}
-fn control_glyph(face: &Arc<FontFace>, p: &CharProps, auto_leading: f64, style: u32, byte: usize, ch: char) -> Glyph {
+fn control_glyph(face: &Arc<FontFace>, p: &CharProps, auto_leading: TypeEnv, style: u32, byte: usize, ch: char) -> Glyph {
let (size, k, ascent, descent, leading, cap, xh, shift) = metrics(face, p, auto_leading);
Glyph {
face: FaceRef::of(face),
@@ -493,7 +500,7 @@ fn shape_segment(
replacement: Option<&str>,
p: &CharProps,
face: &Arc<FontFace>,
- auto_leading: f64,
+ auto_leading: TypeEnv,
style: u32,
out: &mut Vec<Glyph>,
) {
diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs
index 075364214..90e3bde99 100644
--- a/crates/doc/src/lib.rs
+++ b/crates/doc/src/lib.rs
@@ -131,6 +131,22 @@ impl Default for NumberedList {
}
}
+/// Preferences › Advanced Type (stored with the document, like InDesign).
+#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase", default)]
+pub struct AdvancedType {
+ pub superscript_size: f64,
+ pub superscript_position: f64,
+ pub subscript_size: f64,
+ pub subscript_position: f64,
+}
+
+impl Default for AdvancedType {
+ fn default() -> Self {
+ AdvancedType { superscript_size: 58.3, superscript_position: 33.3, subscript_size: 58.3, subscript_position: 33.3 }
+ }
+}
+
/// File → Document Setup + the guide/grid/unit preferences stored with the document.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", default)]
@@ -164,6 +180,9 @@ pub struct DocSettings {
pub chapter_number: u32,
/// Object › Effects › Global Light: the angle (degrees) shadows that use it share.
pub global_light: f64,
+ /// Preferences › Advanced Type: superscript and subscript size and position (percent of the
+ /// font size).
+ pub advanced_type: AdvancedType,
}
impl Default for DocSettings {
@@ -190,6 +209,7 @@ impl Default for DocSettings {
lists: Vec::new(),
chapter_number: 1,
global_light: 120.0,
+ advanced_type: AdvancedType::default(),
}
}
}
diff --git a/crates/engine/src/cmd/prefs.rs b/crates/engine/src/cmd/prefs.rs
index a0984d757..0297b82ee 100644
--- a/crates/engine/src/cmd/prefs.rs
+++ b/crates/engine/src/cmd/prefs.rs
@@ -18,6 +18,7 @@ const DOC_KEYS: &[&str] = &[
"columnColor",
"bleedColor",
"slugColor",
+ "advancedType",
];
pub fn specs() -> Vec<CommandSpec> {
@@ -41,7 +42,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Document Preferences",
[],
None,
- "{horizontalUnits?, verticalUnits?: points|picas|inches|millimeters|…, keyboardIncrement? (pt), baselineGrid?: {start, increment, relativeTo, color, viewThreshold}, grid?: {horizontal, vertical, subdivisions, color, inBack}, pasteboard?: [h, v], marginColor?, columnColor?, bleedColor?, slugColor?: [r, g, b]} → those settings",
+ "{horizontalUnits?, verticalUnits?: points|picas|inches|millimeters|…, keyboardIncrement? (pt), baselineGrid?: {start, increment, relativeTo, color, viewThreshold}, grid?: {horizontal, vertical, subdivisions, color, inBack}, pasteboard?: [h, v], marginColor?, columnColor?, bleedColor?, slugColor?: [r, g, b], advancedType?: {superscriptSize, superscriptPosition, subscriptSize, subscriptPosition} (%)} → those settings",
has_doc,
|s, p| {
let cur = serde_json::to_value(&s.doc()?.doc.settings).map_err(|e| bad("document.preferences", e.to_string()))?;
@@ -115,3 +116,51 @@ mod tests {
assert_eq!(s.doc().unwrap().doc.settings.horizontal_units, designcraft_geom::Unit::Picas);
}
}
+
+#[cfg(test)]
+mod advanced_type_tests {
+ use serde_json::json;
+
+ use crate::Session;
+
+ #[test]
+ fn advanced_type_sizes_superscripts() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 400, 300], "content": "text", "text": "x2"})).unwrap();
+ let sid = designcraft_doc::StoryId(r["story"].as_u64().unwrap());
+ s.execute("text.select", &json!({"story": r["story"], "anchor": 1, "focus": 2})).unwrap();
+ s.execute("type.char", &json!({"position": "superscript"})).unwrap();
+ let glyph = |s: &Session| {
+ let cs = s.cache.get(&s.doc().unwrap().doc, sid, None);
+ let g = cs.frames[0].lines[0].glyphs.iter().find(|g| g.byte == 1).unwrap().clone();
+ let base = cs.frames[0].lines[0].glyphs.iter().find(|g| g.byte == 0).unwrap().clone();
+ (g.sy / base.sy, base.y - g.y)
+ };
+ let (k, rise) = glyph(&s);
+ assert!((k - 0.583).abs() < 1e-3, "{k}");
+ s.execute("document.preferences", &json!({"advancedType": {"superscriptSize": 80, "superscriptPosition": 50}})).unwrap();
+ let (k2, rise2) = glyph(&s);
+ assert!((k2 - 0.8).abs() < 1e-3, "{k2}");
+ assert!(rise2 > rise, "{rise} → {rise2}");
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert!((glyph(&s).0 - 0.583).abs() < 1e-3);
+ }
+}
+
+#[cfg(test)]
+mod advanced_type_idml_tests {
+ use serde_json::json;
+
+ use crate::Session;
+
+ #[test]
+ fn advanced_type_round_trips_through_idml() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ s.execute("document.preferences", &json!({"advancedType": {"subscriptPosition": 12.5}})).unwrap();
+ let back = designcraft_idml::import_idml(&designcraft_idml::export_idml(&s.doc().unwrap().doc)).unwrap();
+ assert_eq!(back.settings.advanced_type.subscript_position, 12.5);
+ assert_eq!(back.settings.advanced_type.superscript_size, 58.3);
+ }
+}
diff --git a/crates/idml/src/export.rs b/crates/idml/src/export.rs
index 4a38dafd9..57db4c191 100644
--- a/crates/idml/src/export.rs
+++ b/crates/idml/src/export.rs
@@ -681,6 +681,14 @@ impl<'a> Ex<'a> {
);
root.push(El::new("PasteboardPreference").attr("PasteboardMargins", pt(s.pasteboard.0, s.pasteboard.1)));
root.push(self.footnote_option_el());
+ let a = &s.advanced_type;
+ root.push(
+ El::new("TextPreference")
+ .attr("SuperscriptSize", num(a.superscript_size))
+ .attr("SuperscriptPosition", num(a.superscript_position))
+ .attr("SubscriptSize", num(a.subscript_size))
+ .attr("SubscriptPosition", num(a.subscript_position)),
+ );
document(&root)
}
diff --git a/crates/idml/src/import.rs b/crates/idml/src/import.rs
index 16d6a0f1e..2f78e7f3d 100644
--- a/crates/idml/src/import.rs
+++ b/crates/idml/src/import.rs
@@ -213,6 +213,19 @@ impl<'r> Importer<'r> {
for e in top {
match e.local() {
"DocumentPreference" => self.doc_prefs(e),
+ "TextPreference" => {
+ let a = &mut self.settings.advanced_type;
+ for (k, v) in [
+ ("SuperscriptSize", &mut a.superscript_size),
+ ("SuperscriptPosition", &mut a.superscript_position),
+ ("SubscriptSize", &mut a.subscript_size),
+ ("SubscriptPosition", &mut a.subscript_position),
+ ] {
+ if let Some(x) = e.num(k) {
+ *v = x;
+ }
+ }
+ }
"MarginPreference" => {
let (m, c) = margins_of(e);
self.default_margins = Some((m, c));
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 995c29b31..47a30a213 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -339,6 +339,7 @@ fn preferences(ui: &mut egui::Ui, d: &mut Dialog) {
("general", "General"),
("interface", "Interface"),
("type", "Type"),
+ ("advancedType", "Advanced Type"),
("units", "Units & Increments"),
("grids", "Grids"),
("guides", "Guides & Pasteboard"),
@@ -372,6 +373,25 @@ fn preferences(ui: &mut egui::Ui, d: &mut Dialog) {
ui.label(egui::RichText::new("Smart Text Reflow").font(semibold(12.0)));
check(ui, d, "smartTextReflow", "Add and remove pages as the primary text frame's story grows and shrinks");
}
+ "advancedType" => {
+ ui.label(egui::RichText::new("Character Settings").font(semibold(12.0)));
+ egui::Grid::new("pref_adv").num_columns(3).spacing([8.0, 6.0]).show(ui, |ui| {
+ ui.label("");
+ ui.label("Size");
+ ui.label("Position");
+ ui.end_row();
+ for (k, l) in [("superscript", "Superscript:"), ("subscript", "Subscript:")] {
+ ui.label(l);
+ for f in ["Size", "Position"] {
+ ui.horizontal(|ui| {
+ text_field(ui, d, &format!("adv.{k}{f}"), 50.0);
+ ui.label("%");
+ });
+ }
+ ui.end_row();
+ }
+ });
+ }
"black" => {
ui.label(egui::RichText::new("Options for Black on RGB and Grayscale Devices").font(semibold(12.0)));
ui.horizontal(|ui| {
@@ -944,6 +964,13 @@ pub fn confirm(app: &mut DesignApp) -> Result<Value, String> {
if let Some(v) = d.fields.get("keyboardIncrement").and_then(Value::as_str).and_then(|s| parse_measure(s, Unit::Points).ok()) {
doc["keyboardIncrement"] = json!(v.max(0.001));
}
+ let mut adv = json!({});
+ for k in ["superscriptSize", "superscriptPosition", "subscriptSize", "subscriptPosition"] {
+ if let Some(v) = d.n(&format!("adv.{k}")) {
+ adv[k] = json!(if k.ends_with("Size") { v.clamp(1.0, 200.0) } else { v.clamp(-500.0, 500.0) });
+ }
+ }
+ doc["advancedType"] = adv;
app.run("document.preferences", doc)
}
"polygonSettings" => app.run("tool.polygonSettings", json!({"sides": d.n("sides").unwrap_or(6.0) as u64, "starInset": d.n("starInset").unwrap_or(0.0)})),
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index 68608b886..015c401ab 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -649,6 +649,9 @@ pub fn run_ui(app: &mut DesignApp, id: &str, p: &Value) -> Option<Result<Value,
if app.session.active().is_some() {
let doc = app.session.execute("document.preferences", &json!({})).unwrap_or_default();
f["horizontalUnits"] = doc["horizontalUnits"].clone();
+ for k in ["superscriptSize", "superscriptPosition", "subscriptSize", "subscriptPosition"] {
+ f[format!("adv.{k}")] = json!(format!("{}", doc["advancedType"][k].as_f64().unwrap_or(0.0)));
+ }
f["verticalUnits"] = doc["verticalUnits"].clone();
let inc = doc["keyboardIncrement"].as_f64().unwrap_or(1.0);
f["keyboardIncrement"] = json!(designcraft_geom::format_measure(inc, designcraft_geom::Unit::Points));