Skip to content

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

Merge PR #825 (gradient text paint goes through #657's stroke-behind-fill painting)

Brandon Thomasd35887f49480
diff --cc ROADMAP.md
index e4c0bb889,b9647d43b..029856255
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -131,45 -126,9 +131,46 @@@ list) · [roadmap.md](docs/roadmap.md)
## Progress log
+- **2026-10-13** · Switching between document and parent pages refreshes the canvas immediately, preventing black parent pages and stale document objects when the zoom stays the same. Ordinary edits retain partial repainting. No readiness percentage change.
+
Newest first.
+- **2026-10-14** · The Type tool draws a new text frame over a locked empty frame, as InDesign does, instead of turning the locked frame into a text frame. No readiness percentage change.
+- **2026-10-14** · 100% black shows as pure black on screen by default, as InDesign's Appearance of Black does out of the box (Display All Blacks as Rich Black); Preferences › Appearance of Black › Display All Blacks Accurately still shows it as the dark grey it prints, and a saved choice is kept. No readiness percentage change.
+- **2026-10-14** · Pathfinder keeps the frontmost object, as InDesign does: a photo placed over shapes and intersected with them shows through the shapes (it was dropped, and the shapes kept their black fill); Add, Exclude Overlap and Minus Back take the front object's fill too, Subtract still keeps the back one. No readiness percentage change.
+- **2026-10-14** · The Color panel's Tint field keeps what is typed while it has focus and applies it on Enter or when it loses focus, clamped to 0–100 %. Typing 60 over 100 % no longer snaps back to 100 after the first digit (10060), and a typed tint is no longer ignored. No readiness percentage change.
+- **2026-10-15** · IDML: ruler guides import and export (they were dropped). Each page's guides come in measured from the document's ruler origin (spread, page or spine), with Fit to Page, Locked and their layer, parent pages' included, and go out again under their pages. No readiness percentage change.
+- **2026-10-15** · Find Font no longer reports a style missing when it differs from the installed one only in spacing or case (InDesign files can name `Regular ` with a trailing space); the text was already drawn in the right face. No readiness percentage change.
+- **2026-10-15** · A line of text is set when its baseline fits in the frame, as in InDesign: descenders may hang below the frame's bottom. A frame sized to the cap height of a big heading (103 pt in a 2.77 cm frame, as Zero2Graphic's magazine tutorial draws them) no longer oversets. No readiness percentage change.
+- **2026-10-15** · A story that ends with a return is no longer overset when only its empty last paragraph doesn't fit, as in InDesign (Preflight said "Overset text: 0 characters" for a caption InDesign shows with no errors). No readiness percentage change.
+- **2026-10-15** · IDML: the CJK leading model InDesign writes on [No paragraph style] of every document (Aki Below) only applies when the document uses a Japanese composer, as in InDesign; a Western document's paragraphs after a size change no longer sit lower than in InDesign (Montilla Design's Flex Layout file: its captions came out overset). No readiness percentage change.
+- **2026-10-13** · Object › Fitting has InDesign's shortcuts: Fill Frame Proportionally ⌘⌥⇧C, Fit Content Proportionally ⌘⌥⇧E, Fit Frame to Content ⌘⌥C, Fit Content to Frame ⌘⌥E, Center Content ⌘⇧E. No readiness percentage change.
+- **2026-10-13** · Gradients between process colours blend as inks, as InDesign shows them: magenta to cyan passes through C 50 M 50 (a light lilac) on screen instead of the darker RGB mix, and a midpoint between CMYK or grey stops no longer turns the PDF shading RGB. No readiness percentage change.
+- **2026-10-14** · The Swatches panel has InDesign's header: a Fill/Stroke proxy, Formatting Affects Container/Text and the Tint of the colour in front (a tint alone keeps each object's own swatch). Clicking a swatch applies it to the fill or stroke in front (of the text, when formatting affects text), and the bottom row has New Color Group, New Swatch and Delete Swatch. No readiness percentage change.
+- **2026-10-14** · With the Page tool, the Control panel shows the page as InDesign's does: W/H from a reference point, page-size preset (US Business Card added), orientation, Liquid Page Rule (now with Controlled by Parent) and Show Parent Page Overlay, which draws the parent page's size over a resized page. No readiness percentage change.
+- **2026-10-14** · On an object-based page the Page tool shows a selected object's liquid pins and resize locks as InDesign does: a click pins a side to the page edge or locks the width or height, with InDesign's tooltips. No readiness percentage change.
+- **2026-10-14** · The Liquid Layout panel follows InDesign's: Liquid Page Rule with the page number, Content › Auto-Fit, and Object Constraints › Resize with Page and Pin for the selected object on an object-based page; Create Alternate Layout moved to the Layout menu. No readiness percentage change.
+- **2026-10-14** · With the Page tool, the Control panel shows the page as InDesign's does: W/H from a reference point, page-size preset (US Business Card added), orientation, Liquid Page Rule (now with Controlled by Parent) and Show Parent Page Overlay, which draws the parent page's size over a resized page. No readiness percentage change.
+- **2026-10-14** · With the Page tool, the Control panel shows the page as InDesign's does: W/H from a reference point, page-size preset (US Business Card added), orientation, Liquid Page Rule and Show Parent Page Overlay, which draws the parent page's size over a resized page. No readiness percentage change.
+- **2026-10-14** · The Page tool works as InDesign's: a click selects a page and shows its handles and liquid page rule; dragging a handle previews the rule and springs back, Alt-drag resizes the page from the opposite edge, Shift keeps proportions, with a W/H readout. No readiness percentage change.
+- **2026-10-14** · With the Page tool, a guide dragged from a ruler is a liquid guide (dashed), as in InDesign; guide-based pages stretch the objects it crosses. No readiness percentage change.
+- **2026-10-14** · The Pages panel menu follows InDesign's order: Insert Pages…, Move Pages…, Duplicate Spread (and at End of Document), Delete Page/Spread, New Parent…, Apply Parent to Pages, Override All Parent Page Items, Parent Pages, Create Alternate Layout…, Numbering & Section Options…, Allow Selected Spread to Shuffle. No readiness percentage change.
+- **2026-10-14** · Pages panel: Alt-drag copies a page, a page dropped on Create new page is duplicated at the end, Edit page size offers the presets and Custom Page Size…; duplicated pages keep their own size, rule and guides; thumbnails of pages of their own size stay in their rows. No readiness percentage change.
+- **2026-10-12 (PDFW)** · PDF, booklet and book composition share guarded writing, metadata and font preparation through craft-pdf. Layout, shaping, placed graphics, colour policy, tagging and PDF/X postprocessing remain in DesignCraft. Failed native drawing returns an export error; failed writer cleanup cannot serialize an incomplete document. No readiness percentage change.
+
+- **2026-10-13** · Copy with a placed graphic selected (Direct Selection) copies just the graphic, uncropped, where it sits on the page and without the frame's stroke, so Paste Into puts the whole image in place; Cut and Delete then remove only the graphic and leave its frame empty. Nested selections copy in their spread coordinates. No readiness percentage change.
+- **2026-10-13** · Object effects (Basic Feather, Inner Glow, shadows, glows, bevel, satin, directional and gradient feathers) apply to frames with pasted-in content, on screen and in image exports: the frame, its clipped content and its stroke are one object to the effect. PDF export still has no soft effects for any object. No readiness percentage change.
+- **2026-10-13** · Links rows show their source paths; selecting a link shows its full path wrapped inside the panel, so same-named files from different folders can be distinguished. No readiness percentage change.
+- **2026-10-13** · The Text Wrap panel is laid out as InDesign's: the wrap buttons with Invert, and the four offsets (Top, Left, Bottom, Right) showing the object's values, with the link button that sets them all the same. It used to show a single offset, always 0. No readiness percentage change.
+- **2026-10-13** · Radial gradients stretch with the object's box, as InDesign draws them: by default an ellipse reaching the frame's sides (it was a circle reaching only the longer side), and a Gradient Swatch tool drag keeps the box's proportions; on screen and in PDF. No readiness percentage change.
+- **2026-10-13** · The Window menu follows InDesign's order (Arrange, Workspace, then the panels alphabetically with Color, Editorial, Object & Layout, Styles… submenus), and Window › Workspace lists the workspaces as InDesign does, now with Essentials Classic: the Control panel and an icon column of named panel groups. No readiness percentage change.
+- **2026-10-14** · In a facing document, pages take their side from their section's page numbers, as InDesign shuffles them: a section that starts at 1 on a left page moves it to the right and the pages after it follow, with their objects. No readiness percentage change.
+- **2026-10-14** · The Type menu follows InDesign's order (Size, Character ⌘T, Paragraph ⌥⌘T, Glyphs, the style panels, Notes, footnotes and endnotes, then the insert submenus and Show Hidden Characters); Current Page Number has ⌥⇧⌘N. No readiness percentage change.
+- **2026-10-14** · Colour parameters: a bare `{c,m,y,k}` is always read as 0..100, so C 1 is a 1 % tint and no longer
+ solid cyan; fractions take the colour's own `{model: "cmyk", …}` form (#910). No readiness percentage change.
+- **2026-10-14** · The Tools panel follows InDesign's: Gradient Swatch and Gradient Feather are tools of their own; in two columns Content Collector and Placer, Apply Color / Gradient / None and Normal / Preview each get a button; View Options holds Frame Edges, Rulers, Guides, Smart Guides, Baseline Grid and Hidden Characters; Apply Color (,) and Apply Gradient (.) reuse the last colour and gradient. No readiness percentage change.
+- **2026-10-13** · Gradient swatches work on strokes: drawn across the path's box on screen and in PDF (they drew nothing), set with `object.gradient {target: stroke}` and in the Gradient panel when the Stroke box is in front; the stroke's gradient vector moves with the shape and round-trips through IDML. No readiness percentage change.
+ - **2026-10-13** · Text takes gradient swatches: a gradient fill or stroke on characters spans the text frame's box (on a path: the path's), on screen and in PDF. No readiness percentage change.
- **2026-10-12** · Text threads by hand: click a selected text frame's in or out port to load
the text cursor, then click a frame to thread it, click empty space for a column-wide frame or
drag one (it snaps like frame drawing); Shift-click autoflows, Alt-click stays loaded on the
diff --cc crates/engine/src/cmd/text.rs
index e3bb8b7ab,0c32a50aa..1c6b6ba3c
--- a/crates/engine/src/cmd/text.rs
+++ b/crates/engine/src/cmd/text.rs
@@@ -2741,45 -2559,127 +2741,170 @@@ mod sentence_selection_tests
}
}
+#[cfg(test)]
+mod open_type_features_tests {
+ use serde_json::{Value, json};
+
+ use crate::Session;
+
+ fn feature<'a>(v: &'a Value, tag: &str) -> &'a Value {
+ v["features"].as_array().unwrap().iter().find(|f| f["tag"] == tag).unwrap_or(&Value::Null)
+ }
+
+ #[test]
+ fn the_selected_fonts_features_are_listed_with_their_state() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 400, 200], "content": "text", "text": "Hello fi"})).unwrap();
+ s.execute("text.select", &json!({"story": r["story"], "anchor": 0, "focus": 8})).unwrap();
+ let v = s.execute("type.openTypeFeatures", &json!({})).unwrap();
+ assert_eq!(v["fonts"][0]["family"], "Source Serif 4", "{v}");
+ assert_eq!(feature(&v, "liga")["applied"], "all", "liga is on by default: {v}");
+ assert_eq!(feature(&v, "kern")["available"], "all", "{v}");
+ }
+
+ #[test]
+ fn a_feature_on_part_of_the_selection_is_some_and_on_all_of_it_is_all() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 400, 200], "content": "text", "text": "Hello world"})).unwrap();
+ let story = r["story"].clone();
+ s.execute("text.select", &json!({"story": story, "anchor": 0, "focus": 5})).unwrap();
+ s.execute("type.feature", &json!({"features": {"lnum": true}})).unwrap();
+ s.execute("text.select", &json!({"story": story, "anchor": 0, "focus": 11})).unwrap();
+ let v = s.execute("type.openTypeFeatures", &json!({})).unwrap();
+ assert_eq!(feature(&v, "lnum")["applied"], "some", "{v}");
+ s.execute("text.select", &json!({"story": story, "anchor": 0, "focus": 5})).unwrap();
+ let v = s.execute("type.openTypeFeatures", &json!({})).unwrap();
+ assert_eq!(feature(&v, "lnum")["applied"], "all", "{v}");
+ s.execute("type.feature", &json!({"features": {"lnum": false}})).unwrap();
+ s.execute("text.select", &json!({"story": story, "anchor": 0, "focus": 11})).unwrap();
+ let v = s.execute("type.openTypeFeatures", &json!({})).unwrap();
+ assert_eq!(feature(&v, "lnum")["applied"], "none", "{v}");
+ }
+}
++
+ #[cfg(test)]
+ mod gradient_text_tests {
+ use serde_json::json;
+
+ /// Mean red and blue of the ink (pixels whose green is low: red → blue has none) in columns
+ /// `x0..x1`.
+ fn ink(img: &designcraft_render::Rendered, x0: u32, x1: u32) -> (f64, f64) {
+ let (mut r, mut b, mut n) = (0.0, 0.0, 0.0);
+ for x in x0..x1 {
+ for y in 0..img.height {
+ let p = img.pixel(x, y);
+ if p[1] < 100 {
+ (r, b, n) = (r + p[0] as f64, b + p[2] as f64, n + 1.0);
+ }
+ }
+ }
+ assert!(n > 50.0, "no ink in {x0}..{x1}");
+ (r / n, b / n)
+ }
+
+ /// Red ink at the frame's left, blue at its right.
+ fn check(img: &designcraft_render::Rendered, what: &str) {
+ let (lr, lb) = ink(img, 0, 60);
+ let (rr, rb) = ink(img, 200, 300);
+ assert!(lr > lb + 80.0, "{what}: the left ink is red ({lr:.0}, {lb:.0})");
+ assert!(rb > rr + 80.0, "{what}: the right ink is blue ({rr:.0}, {rb:.0})");
+ }
+
+ #[test]
+ fn a_gradient_on_text_spans_its_frame_on_screen_and_in_pdf() {
+ let mut s = crate::Session::new();
+ s.execute("file.new", &json!({"width": 300, "height": 120, "facingPages": false, "margins": 0})).unwrap();
+ // A gradient swatch (an off-page object's unnamed one), red → blue.
+ let shape = s.execute("frame.create", &json!({"rect": [-60, 0, -50, 10], "content": "unassigned"})).unwrap()["id"].clone();
+ s.execute("object.gradient", &json!({"ids": [shape], "stops": [{"location": 0, "color": "#ff0000"}, {"location": 100, "color": "#0000ff"}]}))
+ .unwrap();
+ let id = designcraft_doc::ItemId(shape.as_u64().unwrap());
+ let swatch = s.doc().unwrap().doc.item(id).unwrap().fill.swatch.clone();
+ let r = s.execute("frame.create", &json!({"rect": [0, 0, 300, 120], "content": "text", "text": "IIIIIIIIIIIIIIIIIIIIIIIIIIIIII"})).unwrap();
+ s.execute("text.select", &json!({"story": r["story"], "anchor": 0, "focus": 30})).unwrap();
+ s.execute("type.char", &json!({"size": 60, "tracking": 0, "fill": swatch})).unwrap();
+ let d = s.doc().unwrap().doc.clone();
+ let mut rr = designcraft_render::Renderer::new();
+ check(&rr.render_page(&d, &s.cache, 0, 1.0, false, &Default::default()).unwrap(), "screen");
+ // The PDF, placed back and drawn: the same gradient.
+ let pdf = designcraft_pdf::export_pdf(&d, &s.cache, &Default::default()).unwrap();
+ let mut p = crate::Session::new();
+ p.execute("file.new", &json!({"width": 300, "height": 120, "facingPages": false})).unwrap();
+ p.execute("file.place", &json!({"base64": super::super::file::base64_encode(&pdf), "name": "text.pdf", "x": 0, "y": 0, "width": 300}))
+ .unwrap();
+ let d = p.doc().unwrap().doc.clone();
+ check(&rr.render_page(&d, &p.cache, 0, 1.0, false, &Default::default()).unwrap(), "pdf");
+ }
+
+ /// The columns the red → blue ink spans (black table edges left out).
+ fn ink_span(img: &designcraft_render::Rendered) -> (u32, u32) {
+ let cols: Vec<u32> = (0..img.width)
+ .filter(|&x| {
+ (0..img.height).any(|y| {
+ let p = img.pixel(x, y);
+ p[1] < 100 && p[0].max(p[2]) > 100
+ })
+ })
+ .collect();
+ (*cols.first().unwrap(), *cols.last().unwrap())
+ }
+
+ /// Mean red and blue of the red → blue ink in columns `x0..x1`.
+ fn coloured_ink(img: &designcraft_render::Rendered, x0: u32, x1: u32) -> (f64, f64) {
+ let (mut r, mut b, mut n) = (0.0, 0.0, 0.0);
+ for x in x0..x1 {
+ for y in 0..img.height {
+ let p = img.pixel(x, y);
+ if p[1] < 100 && p[0].max(p[2]) > 100 {
+ (r, b, n) = (r + p[0] as f64, b + p[2] as f64, n + 1.0);
+ }
+ }
+ }
+ assert!(n > 20.0, "no ink in {x0}..{x1}");
+ (r / n, b / n)
+ }
+
+ #[test]
+ fn a_gradient_on_table_cell_text_spans_the_cells_text_in_pdf_as_on_screen() {
+ let mut s = crate::Session::new();
+ s.execute("file.new", &json!({"width": 300, "height": 120, "facingPages": false, "margins": 0})).unwrap();
+ // A gradient swatch (an off-page object's unnamed one), red → blue.
+ let shape = s.execute("frame.create", &json!({"rect": [-60, 0, -50, 10], "content": "unassigned"})).unwrap()["id"].clone();
+ s.execute("object.gradient", &json!({"ids": [shape], "stops": [{"location": 0, "color": "#ff0000"}, {"location": 100, "color": "#0000ff"}]}))
+ .unwrap();
+ let g = s.doc().unwrap().doc.item(designcraft_doc::ItemId(shape.as_u64().unwrap())).unwrap().fill.swatch.clone();
+ let r = s.execute("frame.create", &json!({"rect": [0, 0, 300, 120], "content": "text", "text": ""})).unwrap();
+ s.execute("text.select", &json!({"story": r["story"], "anchor": 0, "focus": 0})).unwrap();
+ s.execute("table.insert", &json!({"rows": 1, "cols": 3})).unwrap();
+ // A third of the frame's width: the cell's text, red → blue.
+ let mut d: designcraft_doc::Document = (*s.doc().unwrap().doc).clone();
+ let sid = d.stories.values().find(|st| !st.tables.is_empty()).unwrap().id;
+ let t = std::sync::Arc::make_mut(d.story_mut(sid).unwrap().tables.values_mut().next().unwrap());
+ let text = &mut t.cell_mut(0, 0).unwrap().text;
+ text.insert(0, "HHHH");
+ text.format_chars(0..4, |f| {
+ f.over.fill = Some(g.clone());
+ f.over.size = Some(24.0);
+ });
+ let mut rr = designcraft_render::Renderer::new();
+ let cache = designcraft_compose::Cache::new();
+ let screen = rr.render_page(&d, &cache, 0, 1.0, false, &Default::default()).unwrap();
+ let pdf = designcraft_pdf::export_pdf(&d, &cache, &Default::default()).unwrap();
+ let mut p = crate::Session::new();
+ p.execute("file.new", &json!({"width": 300, "height": 120, "facingPages": false})).unwrap();
+ p.execute("file.place", &json!({"base64": super::super::file::base64_encode(&pdf), "name": "cell.pdf", "x": 0, "y": 0, "width": 300}))
+ .unwrap();
+ let placed = rr.render_page(&p.doc().unwrap().doc.clone(), &p.cache, 0, 1.0, false, &Default::default()).unwrap();
+ let (x0, x1) = ink_span(&screen);
+ assert!(x1 < 120, "the text stays in the first column: {x0}..{x1}");
+ let q = (x1 - x0) / 4;
+ for (what, img) in [("screen", &screen), ("pdf", &placed)] {
+ let (lr, lb) = coloured_ink(img, x0, x0 + q);
+ let (rr, rb) = coloured_ink(img, x1 + 1 - q, x1 + 1);
+ assert!(lr > lb + 50.0, "{what}: the left ink is red ({lr:.0}, {lb:.0})");
+ assert!(rb > rr + 50.0, "{what}: the right ink is blue ({rr:.0}, {rb:.0})");
+ }
+ }
+ }
diff --cc crates/pdf/src/export.rs
index a6f05dce4,45eb331ff..b76af6ec5
--- a/crates/pdf/src/export.rs
+++ b/crates/pdf/src/export.rs
@@@ -988,19 -986,17 +997,25 @@@ impl Exporter<'_>
}
/// A swatch fill (solid or gradient) in the item's inner space. `None` for [None]/unknown.
- fn fill_paint(&mut self, fill: &designcraft_doc::Fill, bounds: Rect) -> Option<krilla::paint::Paint> {
+ pub(crate) fn fill_paint(&mut self, fill: &designcraft_doc::Fill, bounds: Rect) -> Option<krilla::paint::Paint> {
+ self.fill_paint_in(fill, bounds, Affine::IDENTITY)
+ }
+
+ /// [`Self::fill_paint`] for a gradient laid out in a space that `xf` maps to the current one
+ /// (text runs: the frame's text space under the run's origin).
+ pub(crate) fn fill_paint_in(&mut self, fill: &designcraft_doc::Fill, bounds: Rect, xf: Affine) -> Option<krilla::paint::Paint> {
- let (swatch, tint, angle) = (fill.swatch.as_str(), fill.tint, fill.gradient_angle);
+ let (swatch, tint) = (fill.swatch.as_str(), fill.tint);
if let Some(g) = designcraft_color::swatch::resolve_gradient(&self.doc.swatches, swatch) {
let kind = g.kind;
- let expanded = g.expanded_stops();
+ let mut expanded = g.expanded_stops();
+ // Grey and CMYK stops blend as inks, so a grey stop beside a CMYK one is the K ink.
+ if !self.rgb_only && expanded.iter().any(|(_, c, _)| matches!(c, Color::Cmyk { .. })) {
+ for (_, c, _) in &mut expanded {
+ if let Color::Gray { k } = *c {
+ *c = Color::cmyk(0.0, 0.0, 0.0, k);
+ }
+ }
+ }
// A PDF shading needs one colour space. Midpoint expansion can introduce RGB even
// when every authored stop is CMYK/Gray; PDF/A can also change the output space.
let components = |c: &Color| match c {
@@@ -1043,8 -1042,8 +1058,8 @@@
fr: 0.0,
cx,
cy,
- cr: r,
- transform: tf(xf),
+ cr: rx as f32,
- transform: tf(stretch),
++ transform: tf(xf * stretch),
spread_method: SpreadMethod::Pad,
stops,
anti_alias: false,
diff --cc crates/pdf/src/text.rs
index 51eda5ece,a6695d0b7..9cadccd55
--- a/crates/pdf/src/text.rs
+++ b/crates/pdf/src/text.rs
@@@ -299,53 -332,28 +331,65 @@@ impl Exporter<'_>
let hs = g0.sx / g0.sy;
let skew = if st.skew != 0.0 { Affine::new([1.0, 0.0, -st.skew.to_radians().tan(), 1.0, 0.0, 0.0]) } else { Affine::IDENTITY };
let origin = Affine::translate((g0.x, baseline + g0.y)) * skew * Affine::scale_non_uniform(hs, 1.0);
+ // Outside a frame (no text area), a gradient spans the run.
+ let end = glyphs.last().map_or(g0.x, |g| g.x + g.adv);
+ let run_area = Rect::new(g0.x, baseline - size, end.max(g0.x + 1.0), baseline + size * 0.25);
+ let fill = self.text_paint(&st.fill, st.fill_tint, origin, run_area);
+ let stroke = if st.stroke != designcraft_color::swatch::NONE && st.stroke_weight > 0.0 {
+ self.text_paint(&st.stroke, st.stroke_tint, origin, run_area)
+ } else {
+ None
+ };
+ if fill.is_none() && stroke.is_none() {
+ return;
+ }
+ // Stroke behind fill: a double-width stroke first, as outlines so the text is not
+ // duplicated, then the fill over its inner half. With no fill, the stroke is clipped
+ // to the outside of the glyphs instead.
+ let behind = st.stroke_behind_fill && stroke.is_some();
+ let weight = if behind { st.stroke_weight * 2.0 } else { st.stroke_weight };
+ let mut clipped = false;
+ let stroke = if behind {
+ let outlines = glyph_outlines(glyphs, size);
+ if fill.is_some() {
+ self.paint_outlines(s, &outlines, origin, None, stroke, weight);
+ None
+ } else {
+ clipped = self.push_outside_clip(s, &outlines, origin, weight);
+ stroke
+ }
+ } else {
+ stroke
+ };
// A missing glyph is drawn as its box: PDF/A and PDF/UA forbid showing .notdef as text.
if g0.gid == 0 {
- self.outline_run(s, glyphs, origin, size, fill, stroke, st.stroke_weight);
- return;
- }
- let Some(font) = self.font(&face) else {
+ self.paint_outlines(s, &glyph_outlines(glyphs, size), origin, fill, stroke, weight);
+ } else if let Some(font) = self.font(&face) {
+ self.text_run(s, glyphs, story, font, origin, size, hs, fill, stroke, weight);
+ } else {
self.warn(format!("font `{} {}` could not be embedded; its text was drawn as outlines", face.family, face.style));
- self.outline_run(s, glyphs, origin, size, fill, stroke, st.stroke_weight);
- return;
- };
+ self.paint_outlines(s, &glyph_outlines(glyphs, size), origin, fill, stroke, weight);
+ }
+ if clipped {
+ s.pop();
+ }
+ }
+
+ /// A run as real text.
+ #[allow(clippy::too_many_arguments)]
+ fn text_run(
+ &mut self,
+ s: &mut Surface,
+ glyphs: &[PlacedGlyph],
+ story: &str,
+ font: Font,
+ origin: Affine,
+ size: f64,
+ hs: f64,
- fill: Option<krilla::color::Color>,
- stroke: Option<krilla::color::Color>,
++ fill: Option<Paint>,
++ stroke: Option<Paint>,
+ stroke_weight: f64,
+ ) {
let (text, ranges) = self.run_text(glyphs, story);
let k = 1.0 / (hs * size);
let kg: Vec<KrillaGlyph> = glyphs
@@@ -358,28 -366,40 +402,28 @@@
})
.collect();
s.push_transform(&tf(origin));
- s.set_fill(fill.map(|c| solid_fill(c, 1.0)));
- s.set_stroke(stroke.map(|c| Stroke { paint: c.into(), width: stroke_weight as f32, ..Default::default() }));
+ s.set_fill(fill.map(paint_fill));
- s.set_stroke(stroke.map(|paint| Stroke { paint, width: st.stroke_weight as f32, ..Default::default() }));
++ s.set_stroke(stroke.map(|paint| Stroke { paint, width: stroke_weight as f32, ..Default::default() }));
s.draw_glyphs(Point::from_xy(0.0, 0.0), &kg, font, &text, size as f32, false);
s.set_fill(None);
s.set_stroke(None);
s.pop();
}
- /// Fallback for faces krilla can't embed: glyph outlines as paths.
- #[allow(clippy::too_many_arguments)]
- fn outline_run(
+ /// Glyph outlines as paths (faces krilla can't embed, missing glyphs, strokes behind fill).
+ fn paint_outlines(
&mut self,
s: &mut Surface,
- glyphs: &[PlacedGlyph],
+ outlines: &BezPath,
origin: Affine,
- fill: Option<krilla::color::Color>,
- stroke: Option<krilla::color::Color>,
- size: f64,
+ fill: Option<Paint>,
+ stroke: Option<Paint>,
stroke_weight: f64,
) {
- let db = FontDb::global();
- let g0 = &glyphs[0];
- let k = size / g0.face.upem;
- let mut bp = BezPath::new();
- for g in glyphs {
- let a = Affine::translate(((g.x - g0.x) / (g0.sx / g0.sy), 0.0)) * Affine::scale(k);
- let mut o = (*db.outline(&g.face, g.gid)).clone();
- o.apply_affine(a);
- bp.extend(o.iter());
- }
- let Some(p) = to_path(&bp) else { return };
+ let Some(p) = to_path(outlines) else { return };
s.push_transform(&tf(origin));
- s.set_fill(fill.map(|c| solid_fill(c, 1.0)));
- s.set_stroke(stroke.map(|c| Stroke { paint: c.into(), width: stroke_weight as f32, ..Default::default() }));
+ s.set_fill(fill.map(paint_fill));
+ s.set_stroke(stroke.map(|paint| Stroke { paint, width: stroke_weight as f32, ..Default::default() }));
s.draw_path(&p);
s.set_fill(None);
s.set_stroke(None);
diff --cc crates/render/src/text.rs
index 31733759d,26a2a8e6c..398c787f3
--- a/crates/render/src/text.rs
+++ b/crates/render/src/text.rs
@@@ -374,9 -416,34 +416,9 @@@ impl Renderer
let lg = &fg.lines[i];
self.stats.glyphs += lg.glyphs;
for (si, bp) in &lg.runs {
- if let Some(c) = fill_of(*si) {
- let st = &cs.styles[*si as usize];
- let op = crate::overprints(f, &st.fill, st.fill_tint, false);
- if op {
- ctx.push_layer(
- None,
- Some(vello_cpu::peniko::BlendMode::new(vello_cpu::peniko::Mix::Multiply, vello_cpu::peniko::Compose::SrcOver)),
- None,
- None,
- None,
- );
- }
- c.set(ctx, doc, area);
- ctx.fill_path(bp);
- ctx.reset_paint_transform();
- if op {
- ctx.pop_layer();
- }
- }
let st = &cs.styles[*si as usize];
- if st.stroke != designcraft_color::swatch::NONE
- && let Some(c) = TextPaint::of(doc, &st.stroke, st.stroke_tint)
- {
- c.set(ctx, doc, area);
- ctx.set_stroke(kurbo::Stroke::new(st.stroke_weight));
- ctx.stroke_path(bp);
- ctx.reset_paint_transform();
- }
+ let fill = fill_of(*si).map(|c| (c, crate::overprints(f, &st.fill, st.fill_tint, false)));
- paint_glyphs(ctx, bp, fill, stroke_of(doc, st), st.stroke_weight, st.stroke_behind_fill);
++ paint_glyphs(ctx, doc, area, bp, fill, stroke_of(doc, st), st.stroke_weight, st.stroke_behind_fill);
}
}
for &i in &shown {
@@@ -449,62 -516,6 +491,69 @@@ impl Renderer
}
/// Kurbo stroke for a table edge.
+/// A run's stroke colour, if it has one.
- fn stroke_of(doc: &designcraft_doc::Document, st: &designcraft_compose::RunStyle) -> Option<peniko::Color> {
++fn stroke_of(doc: &designcraft_doc::Document, st: &designcraft_compose::RunStyle) -> Option<TextPaint> {
+ if st.stroke == designcraft_color::swatch::NONE {
+ return None;
+ }
- doc.resolve_color(&st.stroke, st.stroke_tint).map(|c| color_of(&c, 1.0))
++ TextPaint::of(doc, &st.stroke, st.stroke_tint)
+}
+
+/// Paint glyph outlines: the fill (multiplied when it overprints), then the stroke over it. With
+/// stroke behind fill a double-width stroke goes first and the fill covers its inner half; with
+/// no fill to cover it, the glyph shapes are cut out of the stroke instead.
++#[allow(clippy::too_many_arguments)]
+fn paint_glyphs(
+ ctx: &mut RenderContext,
++ doc: &designcraft_doc::Document,
++ area: Rect,
+ bp: &BezPath,
- fill: Option<(peniko::Color, bool)>,
- stroke: Option<peniko::Color>,
++ fill: Option<(TextPaint, bool)>,
++ stroke: Option<TextPaint>,
+ weight: f64,
+ behind: bool,
+) {
++ // A gradient paint runs across `area`; reset its transform after each use.
+ let paint_fill = |ctx: &mut RenderContext| {
- let Some((c, overprint)) = fill else { return };
- if overprint {
++ let Some((c, overprint)) = &fill else { return };
++ if *overprint {
+ ctx.push_layer(None, Some(peniko::BlendMode::new(peniko::Mix::Multiply, peniko::Compose::SrcOver)), None, None, None);
+ }
- ctx.set_paint(c);
++ c.set(ctx, doc, area);
+ ctx.fill_path(bp);
- if overprint {
++ ctx.reset_paint_transform();
++ if *overprint {
+ ctx.pop_layer();
+ }
+ };
+ let Some(sc) = stroke else {
+ paint_fill(ctx);
+ return;
+ };
++ let paint_stroke = |ctx: &mut RenderContext, width: f64| {
++ sc.set(ctx, doc, area);
++ ctx.set_stroke(kurbo::Stroke::new(width));
++ ctx.stroke_path(bp);
++ ctx.reset_paint_transform();
++ };
+ if !behind {
+ paint_fill(ctx);
- ctx.set_paint(sc);
- ctx.set_stroke(kurbo::Stroke::new(weight));
- ctx.stroke_path(bp);
++ paint_stroke(ctx, weight);
+ return;
+ }
- ctx.set_paint(sc);
- ctx.set_stroke(kurbo::Stroke::new(weight * 2.0));
+ if fill.is_some() {
- ctx.stroke_path(bp);
++ paint_stroke(ctx, weight * 2.0);
+ paint_fill(ctx);
+ } else {
+ ctx.push_layer(None, None, None, None, None);
- ctx.stroke_path(bp);
++ paint_stroke(ctx, weight * 2.0);
+ ctx.push_layer(None, Some(peniko::BlendMode::new(peniko::Mix::Normal, peniko::Compose::DestOut)), None, None, None);
+ ctx.fill_path(bp);
+ ctx.pop_layer();
+ ctx.pop_layer();
+ }
+}
+
fn cell_stroke(s: &designcraft_doc::CellStroke) -> kurbo::Stroke {
let st = kurbo::Stroke::new(s.weight).with_caps(kurbo::Cap::Square);
match &s.kind {
@@@ -531,10 -542,23 +580,12 @@@ impl Renderer
) {
let doc = f.doc;
ctx.set_transform(f.view * xf);
+ // A gradient on type on a path spans the path's box.
+ let area = path.bounding_box();
for (si, bp) in designcraft_compose::path_glyphs(cs, ft, path, pt) {
let st = &cs.styles[si as usize];
- let fill = doc.resolve_color(&st.fill, st.fill_tint).map(|c| (color_of(&c, 1.0), false));
- paint_glyphs(ctx, &bp, fill, stroke_of(doc, st), st.stroke_weight, st.stroke_behind_fill);
- if let Some(c) = TextPaint::of(doc, &st.fill, st.fill_tint) {
- c.set(ctx, doc, area);
- ctx.fill_path(&bp);
- ctx.reset_paint_transform();
- }
- if st.stroke != designcraft_color::swatch::NONE
- && let Some(c) = TextPaint::of(doc, &st.stroke, st.stroke_tint)
- {
- c.set(ctx, doc, area);
- ctx.set_stroke(kurbo::Stroke::new(st.stroke_weight));
- ctx.stroke_path(&bp);
- ctx.reset_paint_transform();
- }
++ let fill = TextPaint::of(doc, &st.fill, st.fill_tint).map(|c| (c, false));
++ paint_glyphs(ctx, doc, area, &bp, fill, stroke_of(doc, st), st.stroke_weight, st.stroke_behind_fill);
self.stats.glyphs += 1;
}
}
diff --cc docs/target-app-parity.md
index 0a0cee649,9c2c101d2..c88afca38
--- a/docs/target-app-parity.md
+++ b/docs/target-app-parity.md
@@@ -424,7 -423,7 +424,7 @@@ It is evidence of breadth: each item ex
- View › Display Performance: Fast (grey boxes, no effects, ⌥⇧⌘Z), Typical (72 ppi proxies, ⌥⌘Z), High Quality (⌥⌘H, our default — the renderer is fast enough).
- OpenType menu (Character panel): discretionary ligatures, fractions, ordinal, swash, titling, contextual alternates, slashed zero, the four figure styles and stylistic sets 1–20; `type.openType`; mapped to IDML's OTF attributes.
- Add Anchor Point (=), Delete Anchor Point (-) and Convert Direction Point (⇧C) tools (click toggles smooth/corner, drag pulls out handles), with `path.addAnchor`, `path.deleteAnchor`, `path.convertAnchor`.
- - Gradients: the Gradient Swatch tool (G) drags a gradient's start and end across objects (Shift: 45°); the Gradient panel sets type, angle, reverse and edits stops on a ramp (drag, add, drag off to remove, location, colour). Edited gradients are unnamed swatches; `object.gradient` (`target: stroke` for a stroke's gradient, drawn across the path's box on screen and in PDF); the vector round-trips through IDML (`GradientFill…`/`GradientStroke…`). The Gradient panel follows the Fill/Stroke proxy. A radial gradient stretches with the object's box as InDesign's does (an ellipse reaching the sides of a non-square frame, on screen and in PDF).
-- Gradients: the Gradient Swatch tool (G) drags a gradient's start and end across objects (Shift: 45°); the Gradient panel sets type, angle, reverse and edits stops on a ramp (drag, add, drag off to remove, location, colour). Edited gradients are unnamed swatches; `object.gradient`; the vector round-trips through IDML. Text takes a gradient swatch as its fill or stroke, laid across its frame's box as in InDesign (screen and PDF).
++- Gradients: the Gradient Swatch tool (G) drags a gradient's start and end across objects (Shift: 45°); the Gradient panel sets type, angle, reverse and edits stops on a ramp (drag, add, drag off to remove, location, colour). Edited gradients are unnamed swatches; `object.gradient` (`target: stroke` for a stroke's gradient, drawn across the path's box on screen and in PDF); the vector round-trips through IDML (`GradientFill…`/`GradientStroke…`). The Gradient panel follows the Fill/Stroke proxy. A radial gradient stretches with the object's box as InDesign's does (an ellipse reaching the sides of a non-square frame, on screen and in PDF). Text takes a gradient swatch as its fill or stroke, laid across its frame's box as in InDesign (screen and PDF).
- Document Setup (⌥⌘P): intent, number of pages, start page # (an even start begins with a left page), facing pages, size presets and orientation, bleed and slug per edge; `layout.documentSetup {}` reports the setup.
- Stroke panel: cap, join, miter limit, alignment, type, Start/End arrowheads (12 kinds, drawn on screen and in PDF; the path is shortened under pointed heads) and gap colour under dashes and dots.
- Preferences (⌘K: General, Type, Units & Increments, Grids, Guides & Pasteboard, Display Performance) backed by `prefs.set` (application) and `document.preferences` (units, increments, grids — undoable, saved with the document; right-click a ruler to pick its units, the horizontal and vertical rulers each have their own); scaling applies to content and scales stroke weights (Include Stroke Weight), and X/Y/W/H measure the stroke's outer edge (Dimensions Include Stroke Weight). Quick Apply (⌘Return) finds paragraph, character and object styles as well as commands.