DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge storytold/main (v0.14.0) into inline-objects-under-text
Claude5c6909db46eb
diff --cc ROADMAP.mdindex b364bc400,c02176bab..67f1a13a9--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -348,7 -380,74 +380,75 @@@ list) · [roadmap.md](docs/roadmap.md)Newest first.+ - **2026-10-27** · An iconic panel's flyout stays open while you work in the canvas or a text field: Auto-Collapse Iconic Panels is off by default, and preferences saved with it on start with it off. Preferences › Interface › Panels holds the setting next to the column bar's menu item. No readiness percentage change.+ - **2026-10-24** · Column rules run from the top line's ascent to the bottom line's descent, as InDesign draws them, instead of from the top to the bottom of the columns, on screen, in PDF and in PowerPoint export. The top and bottom insets shorten the rule from those lines. Existing documents draw their column rules at the new length. No readiness percentage change.+ - **2026-10-20** · Edit › Keyboard Shortcuts is craft-keymap's shared dialog: commands grouped by menu with Show and Filter, recording that asks before taking a key from another command, undo and redo, named shortcut sets (edits of Default become Custom; an imported set becomes a set of its own), an on-screen US keyboard, InDesign Show Set files reviewed before they apply, JSON export and an HTML summary. ui.json keeps the `shortcuts` map earlier versions read, for the active set. No readiness percentage change.+ - **2026-10-19** · Import InDesign Set… runs on craft-keymap's importer: a set's Window menu panel items (Layers F7, Pages F12, Swatches F5) and Tools items set the panel and tool shortcuts, all of an item's Default keys apply, and the report adds numeric keypad keys read as main keys and likely commands for unmatched items (`window.importShortcuts`). On InDesign's Windows defaults it matches 366 of 1,629 items (was 233) and changes 23 commands. No readiness percentage change.+ - **2026-10-19** · Keyboard shortcuts run on the shared craft-keymap crate. Panels take shortcuts, with InDesign's defaults where the key is free (Swatches F5, Color F6, Layers F7, Info F8, Stroke F10, Paragraph Styles F11, Character Styles Shift+F11, Pages F12, Align Shift+F7); tool keys are editable in Edit › Keyboard Shortcuts and `window.setShortcut`, and tools sharing a key take turns (B). Saved shortcuts load unchanged. No readiness percentage change.+ - **2026-10-16** · Edit › Keyboard Shortcuts imports a set saved by InDesign's Show Set (.txt, Windows or Mac key names, UTF-8 or UTF-16): matched commands take its Default shortcuts or lose theirs, other commands give up keys it takes, and a report lists what it changed and the items it could not match (`window.importShortcuts`, #1180). Tool keys stay fixed. No readiness percentage change.+ - **2026-10-20** · PDF/X-1a:2003 export (craft-libs#194): `file.exportPdf {standard: "x1a"}`, the Export PDF dialog's PDF/X-1a:2003 preset and standard. The PDF/X-4 print file is flattened in its inks by craft-prepress (no transparency; spot, process, overprint and live text kept; complex regions as DeviceN images at the Transparency Flattener preset's resolution), then written as PDF 1.4 with the X-1a identification and checked; `validate-pdf --standard x1a`. Soft drop shadows reach the flattener in their swatch's inks; other soft effects are still RGB images. No readiness percentage change.+ - **2026-10-20** · Print color (craft-libs#190): CMYK print PDFs blend in DeviceCMYK through craft-pdf's print settings instead of byte rewrites, with the CMYK working space as the output intent in PDF/X-4 only; overprint (Overprint Fill, Stroke and Gap, overprinting text, 100% [Black]) is written as `/op` `/OP` `/OPM 1`; Knockout Group writes `/K true` instead of becoming an image; File › Print prints the PDF Export PDF writes. No readiness percentage change.+ - **2026-10-20** · Separations Preview shows the plates the exported PDF prints, spot plates included: each visible spread is exported in memory with the Export PDF settings and separated by craft-prepress off the UI thread, then shown as all inks, one plate or an ink limit. The Ink Manager builds craft-prepress's `InkSet` from the document for export and preview. On the sample magazine the first preview of a spread takes about 0.6–1.1 s, most of it the PDF export. No readiness percentage change.+ - **2026-10-20** · Spot gradients print on their plates. A gradient stop keeps the swatch it was given (Gradient panel drop, `swatch.create {gradient}`, `object.gradient`, IDML `StopColor`), following its renames and edits. PDF export shades one spot with its tints or [Paper] as a Separation, and a spot with process inks or a second spot as DeviceN; a process gradient to [Paper] prints in DeviceCMYK. Documents with plain-color stops export as before. No readiness percentage change.+ - **2026-10-24** · Panels dock through the suite's shared docking (craft-libs), and on desktop a floating panel opens in its own window that can leave the main window: keys pressed there run the main window's shortcuts, clipboard and tool keys, and the canvas paints no tool cursor while another of the app's windows has the pointer. The web build keeps floating panels in the page. No readiness percentage change.+ - **2026-10-24** · Story Options rejects malformed or nonexistent explicit story/frame IDs without changing the selected story, including an invalid frame alongside a valid story. Null targets remain absent; omitted targets still use the selection. No readiness percentage change.+ - **2026-10-24** · Text Frame Options explains that a custom baseline-grid increment must be a measure greater than zero when zero, a negative value or a non-measure is entered. Validation is unchanged. No readiness percentage change.+ - **2026-10-24** · Renaming a paragraph or character style, or moving it into a style group, keeps its Export Tagging under the new name, and undo puts it back under the old one. Deleting a tagged style drops its tagging and leaves the replacement style's own tagging as it was. No readiness percentage change.+ - **2026-10-24** · Quick Apply and the application bar's search leave out the interface commands that failed or reset a setting when chosen there: those that need a workspace, a command and shortcut, a menu item, a panel, a window edge, an app page, a recent file or a swatch they can't give them, a Contextual Task Bar place, and Interface Color Theme, UI Scaling, Reset Shortcuts, the flattener preset, Screen Mode and Zoom To, which without a value switched to the dark theme, set 100%, cleared every custom shortcut or the preset, or went to Normal mode or 100% zoom. Each stays in the menu, panel or dialog that gives it the value. No readiness percentage change.+ - **2026-10-24** · EPUB Export Options › Split Document, a dialog before File › Export EPUB… saves (`document.epubSplit`, stored with the document): off, a single paragraph style, or based on paragraph style export tags, with Paragraph Style Options › Export Tagging's Split Document flag marking those styles. A reflowable EPUB is one content file unless Split Document is on; the split before each top-level h1 from #791 is gone. A split before a list item or preformatted line no longer leaves an unclosed list or block in a content file. IDML import and export keep the setting and the flag, and Load Styles the flag. No readiness percentage change.+ - **2026-10-18** · Repeated placed-PDF layer variants are prepared once per asset and hidden-name set, with recovery warnings retained. All-visible named layers keep their original source bytes, including PDFs whose cross-reference tables the reader repairs, in plain, PDF/X-4, booklet and book-merge output. Layer changes that require writing still reject an unusable cross-reference table with a file-named damage error; the first placement error is retained (#906). No readiness percentage change.+ - **2026-10-18** · Placed PDF optional-content defaults and per-frame overrides survive plain and PDF/X-4 vector export, including repeated placements, booklet output and book merging (#906). Source usage-application arrays are accepted; groups without a catalog configuration stay visible. Missing or unreadable default configurations and unsupported base states use all-ON defaults with a file-named export warning, retaining explicit frame overrides. Readable groups omitted from the catalog list are added with a distinct file-named warning, preserving their default ON/OFF states. Concurrent recovery warnings are combined. Malformed ON data is recoverable when a known ON base and empty OFF list prove it cannot hide artwork; missing display names are generated without changing known visibility when no override needs name matching. Contradictory states, unresolved references and ambiguous name overrides still fail export. Print-usage adjustments and IDML layer overrides remain follow-ups. No readiness percentage change.++ - **2026-10-24** · Optical Margin Alignment and hanging punctuation apply to lines with a tab or a right indent tab, as both composers already measured them: the edge glyphs hang, and tab stops stay where they are. Such a line was set without the hang: a justified line that fit only because its period or closing quote hangs had its word spaces squeezed to make up for it, and text after a right indent tab stopped at the measure instead of hanging. No readiness percentage change.+ - **2026-10-23** · `designcraft-cli mcp` takes `--automation-read-root` and `--automation-write-root` more than once, as the suite's other apps do (#1552): a path inside any root of its kind passes, and the roots' common parent, `..` or a link out of them and the other kind's roots stay refused. No readiness percentage change.+ - **2026-10-23** · Layout › Go Back and Go Forward (Cmd+Page Up / Cmd+Page Down, Ctrl on Windows and Linux) retrace the jumps between pages (Go to Page, the page and spread commands, the Pages panel) as InDesign's do, returning to where the view was on each page at the current zoom; a new jump after going back drops the pages ahead, scrolling adds no entry, and pages deleted since are skipped. No readiness percentage change.+ - **2026-10-24** · The Story Editor has InDesign's vertical depth ruler between the style column and the text, and View › Story Editor › Show/Hide Depth Ruler (`view.storyEditorDepthRuler`) shows or hides it in the Story Editor, remembered with the preferences. The ruler is marked in the document's vertical ruler units with how deep the story's text fills its frames, counted through its columns and threaded frames (lines set side by side, in the sub-columns of a split paragraph or on both sides of a wrap object, count once), and is shaded down to the overset point, where a red line now crosses the editor. No readiness percentage change.+ - **2026-10-24** · Split Note (`note.split {story, id, at}`, the Notes panel's Split Note button): as in InDesign, a note splits in two at the insertion point in its text. DesignCraft moves the text after it into a new note by the same author, anchored right after the first. No readiness percentage change.+ - **2026-10-24** · Type › Notes › Previous Note and Next Note (`note.previous`, `note.next`): as in InDesign, they move the insertion point from note to note in the story, putting the caret after the note's anchor. Each item is unavailable when no note lies in its direction in the story, or when the insertion point is in a table cell or a footnote. No readiness percentage change.+ - **2026-10-24** · Type › Notes › Convert to Note (`note.convertFromText {author?}`): as in InDesign, the selected text leaves the story and becomes the text of a new note, whose anchor takes its place; Convert Note to Text puts it back. DesignCraft refuses a selection in a table cell, or one that holds a note, footnote, endnote, anchored object, index marker, text anchor, cross-reference or table. No readiness percentage change.+ - **2026-10-23** · Effects dialog: with Use Global Light on, the Angle field (and the Bevel and Emboss one) stays editable and shows the document's global light angle; a change there sets the global light for every effect that uses it, applied with the effects in one undo step (`object.effects` takes `globalLight`). Before, the field was greyed out and the angle couldn't be changed in the dialog. No readiness percentage change.+ - **2026-10-24** · Story panel (Window › Type & Tables › Story): Optical Margin Alignment and its size for the stories of the text selection or the selected text frames, disabled without either; `type.selectionAttrs` reports them as `storyOptions`, null where the stories differ. The Paragraph panel menu has Ignore Optical Margin in place of the per-paragraph Optical Margin Alignment switch, which stays in `type.para`, and Paragraph Style Options › Indents and Spacing has Ignore Optical Margin (#947). No readiness percentage change.+ - **2026-10-24** · Optical Margin Alignment per story with a size (`story.options {opticalMargin, opticalMarginSize}`, off by default): when it is on, the story's paragraphs hang punctuation and letter edges by amounts set for that type size, except paragraphs with Ignore Optical Margin (`ignoreOpticalMargin` in `type.para` and paragraph styles). Table cells and footnotes don't take the story setting yet. When it is off, the per-paragraph switch still hangs at the text's own size. IDML imports and exports both (`StoryPreference/@OpticalMarginAlignment`, `@OpticalMarginSize`, `IgnoreEdgeAlignment`) (#947). No readiness percentage change.+ - **2026-10-24** · Text frames: a custom baseline grid's Relative To (Text Frame Options › Baseline Options, `object.textFrameOptions {baselineGrid: {relativeTo}}`, IDML `BaselineFrameGridRelativeOption`) measures the grid's start from the top of the page, the top margin, the top of the frame or its top inset. Text Frame Options had no custom baseline grid controls, imports dropped the setting and every frame grid started from the page top, so grid-aligned text in a frame measured from its own top sat on the wrong lines. No readiness percentage change.+ - **2026-10-24** · Paragraph Style Options › Indents and Spacing has an Align to Grid menu: None, All Lines or First Line Only. It shows the style's current setting. A First Line Only style could be set only in the CJK Grid Settings section, which shows only with CJK features on, or through commands. No readiness percentage change.+ - **2026-10-24** · Anchored text frames, such as marginal notes, compose where their host story places them: they align to the baseline grid at that position, and page-number markers and spine-relative alignment inside them read the host's page. They composed against a grid measured from their stored position and on no page, so a note set to Only Align First Line to Grid could sit a fraction of a line off the body text's grid line. No readiness percentage change.+ - **2026-10-24** · Tables: a gradient swatch in a cell fill draws as a gradient on the canvas and in PDF, in one gradient space for the whole table, so it runs across cells without restarting. Cells showed the gradient's first stop as a solid colour. No readiness percentage change.+ - **2026-10-24** · New documents start with Hyphenate Capitalized Words, Hyphenate Last Word and Hyphenate Across Column off in [Basic Paragraph], as in InDesign. Opened and imported files keep the values they carry. No readiness percentage change.+ - **2026-10-24** · The baseline grid's Relative To setting applies: with Top Margin, the grid starts at each page's own top margin in text composition, on the canvas and for snapping. It started at the page top, so grid-aligned text sat on the wrong lines and a page could fit one line fewer. No readiness percentage change.+ - **2026-10-24** · Custom-positioned anchored objects honour Relative to Spine (`anchored.options {spineRelative}`, IDML `SpineRelative`): the settings describe a left-hand page and mirror on a right-hand page, so marginal notes stay in the outside margin on both pages of a spread. On right-hand pages they took the left-hand placement and landed in the inside margin, across the spine or over the body text. No readiness percentage change.+ - **2026-10-24** · Text frames: a custom baseline grid (Text Frame Options › Baseline Options) from an IDML file sets lines from its start by its increment. The composer read the two values in the other order, so lines landed on the wrong grid. No readiness percentage change.+ - **2026-10-23** · File › File Info… edits the document's Document Title, Author, Description, Keywords, Copyright Notice and Copyright Info URL (`file.info`), and the document saves them. PDF export (PDF/X-4 and Print Booklet included) writes the title, author, description and keywords into the PDF's document information and XMP. EPUB export takes the title and author from File Info, and HTML export takes the title. A title or author given to the export replaces File Info's, and an empty Document Title leaves the document's name as the title. No readiness percentage change.+ - **2026-10-23** · Save and export dialogs (Save As, Save a Copy, Export PDF and the other exports, Package, libraries and books) start in the active document's folder once it has been saved, and for a document never saved in the folder of the last file saved or exported, remembered across sessions (#1653). A folder deleted since falls back to the system's choice. No readiness percentage change.+ - **2026-10-22** · Autoflow (Shift-click with the loaded text cursor, autoflow on Place, `text.thread {autoflow}`) fills the pages that follow before it adds any, as InDesign does: one frame per column on each following page, whatever else the page holds, then new pages at the end of the document. It inserted pages right after the story's last frame, in front of the document's own pages. Frames it set past the end of the text go again; a page the document had stays, and a page autoflow added only for such a frame goes with it. Smart Text Reflow of the primary text frame is unchanged. No readiness percentage change.+ - **2026-10-16** · Edit › Keyboard Shortcuts imports a set saved by InDesign's Show Set (.txt, Windows or Mac key names, UTF-8 or UTF-16): matched commands take its Default shortcuts or lose theirs, other commands give up keys it takes, and a report lists what it changed and the items it could not match (`window.importShortcuts`, #1180). Tool keys stay fixed. No readiness percentage change.+ - **2026-10-23** · Translations: a missing string shows in English and fails no test; `cargo xtask i18n-report`, run by `cargo xtask ci`, prints the missing strings per language. Tests keep duplicate-key and placeholder checks and the language mechanics (lookup, context captions, plural captions, right-to-left). No readiness percentage change.+ - **2026-10-22** · Hyphenation Settings, as in InDesign: the Paragraph panel menu's Hyphenation… (`app.hyphenationDialog`) sets the selected paragraphs' Hyphenate, Words with at Least, After First, Before Last, Hyphen Limit, Hyphenation Zone, the Better Spacing ↔ Fewer Hyphens slider (InDesign's 0–10 steps), Hyphenate Capitalized Words, Last Word and Across Column, with Preview, as one undo step; Paragraph Style Options › Hyphenation has the same form. The panel menu lists its items in InDesign's order. Replicated from a hyphenation tutorial: the same text in Minion Pro breaks into the same lines as InDesign's with hyphenation on, off, and at Fewer Hyphens. No readiness percentage change.+ - **2026-10-22** · Hyphenate Across Column (Hyphenation Settings; IDML HyphenateAcrossColumns) is applied: with it off, a paragraph whose line ending in an automatic hyphen would end a column or frame is re-composed without that hyphenation point, so the word moves on whole, as in InDesign. Opened and imported files keep their own setting, so their layouts don't change. No readiness percentage change.+ - **2026-10-22** · The Paragraph panel is laid out as InDesign's: the nine alignment buttons in groups; indent, spacing and drop cap fields by their icons in two columns, with Space Between Paragraphs Using Same Style (Ignore or a space); Shading and Border with the Paragraph Borders and Shading button and colour; Hyphenate with Do Not Align / Align to Baseline Grid. Its panel menu follows InDesign's order: Paragraph and Single-line Composer, Only Align First Line to Grid, Balance Ragged Lines, Optical Margin Alignment, Justification…, Keep Options…, Span Columns…, Hyphenation…, Drop Caps and Nested Styles…, GREP Styles… (these three now open for the selected paragraphs), Paragraph Rules…, Paragraph Borders and Shading…, Bullets and Numbering…, Restart/Continue Numbering, Define Lists… and the paragraph direction. Convert Bullets and Numbering to Text is listed but not available yet. No readiness percentage change.+ - **2026-10-22** · A ruler guide dragged with the Selection tools, out of a ruler, on its own or with other selected guides, snaps along its axis as objects do (#1221): to other ruler guides, margins, columns, bleed, page and object edges and centers (with the smart-guide mark) and the document grid, within the snap zone and following Snap to Guides and Smart Guides. Shift snaps to the ruler's ticks and Cmd suspends snapping. The preview line, the position readout and the drop use the same snapped position. No readiness percentage change.+ - **2026-10-22** · macOS: the app menu has a Language submenu after Settings… with each interface language in its own name and the current one checked, as in the suite's other apps; Preferences › General › Interface Language stays. No readiness percentage change.+ - **2026-10-23** · Type › Text Variables › Convert Variable to Text (`variables.convertToText`): the variable instances in the selected text, in a story, a table cell or a footnote, become plain text of the value each shows on its own page (a running header on page 3 becomes page 3's heading). `variables.convertAllToText {name}` does the same for every instance of one variable in the document, as the Text Variables dialog's Convert to Text button. The variable stays defined; one undo step. No readiness percentage change.+ - **2026-10-22** · macOS menu bar: the menus keep working after the interface language or Show CJK Features changes (a rebuilt menu bar lost every click, Quit included), and its key equivalents are the shortcuts in effect, so a shortcut moved in the Keyboard Shortcuts editor leaves its old menu item. No readiness percentage change.+ - **2026-10-22** · Paragraph rules: Rule Above's offset is measured from the first line's baseline to the rule's bottom edge, as in InDesign. Rules sat one ascent too high and crossed the previous paragraph's text (reported from an imported INDD document). No readiness percentage change.+ - **2026-10-21** · Ruler guides are selected like objects (#1282): a click with the Selection tools selects a guide (also where it crosses an object), Shift-click adds or removes one, a new guide from the rulers is selected, a marquee that touches no object selects the guides it crosses, and Edit › Select All Guides (⌥⌘G, `guide.selectAll`) selects every unlocked guide on the spread. Selected guides draw thicker in their layer's color, drag together (all of them shown moving), nudge with the arrow keys and go with Delete, each as one undo step (`guide.select`, `guide.deselect`, `guide.moveBy`, `guide.delete {}`). With one guide selected the Control bar's X (vertical guide) or Y (horizontal guide) field and Properties › Transform show where it is, as the rulers measure, and typing a value moves it there. No readiness percentage change.+ - **2026-10-17** · PDF/X-4 export warns about fonts drawing visible text without an embedded+ font program, including placed PDF forms; `validate-pdf` reports the font and page (#909).+ Invisible OCR text is exempt. Detection only: fonts are not embedded or outlined automatically.+ Repeated forms reuse context-aware font findings; a document-wide operation limit and a form-nesting depth limit+ report incomplete checks instead of allowing excessive nested-form traversal.+ No readiness percentage change.+ - **2026-10-16** · Selection: drag a column guide to move its gutter, as in InDesign (#1096). Both guides of the gutter move together and keep its width, stop at the neighbouring guides and the margins, and snap to the document grid, guides and objects, or with Shift to the ruler's tick marks; Escape cancels and the drag is one undo step. Locked column guides (the default) are not picked. A document page takes the result as its own columns; on a parent page it passes to the pages that follow it. `layout.moveColumnGuide` does the same over the control channel and MCP. No readiness percentage change.+ - **2026-10-16** · Layout: autoflow, inserted pages and new parents follow dragged column guides (#1096). Autoflow sets one frame per dragged column and counts the pages it adds from them; Insert Pages and New Parent keep the custom positions with the column count and gutter; a page that moves to the other side of the spine (inserted, deleted or moved pages, Duplicate Spread, a new parent's other page) has them mirrored across its margin box, as InDesign does; `document.inspect` reports each page's gutter, column rects and whether its columns are custom. No readiness percentage change.+ - **2026-10-16** · Layout: Margins and Columns keeps dragged column guides unless the column count or gutter changes (#1096). The dialog sends every field on OK, so a margin-only change re-divided the columns evenly. Margin changes keep the positions; the columns follow them only while they fit the margin box. No readiness percentage change.+ - **2026-10-16** · Lock Guides and Lock Column Guides are commands in View ▸ Grids & Guides (`view.lockGuides`, ⌥⌘;, and `view.lockColumnGuides`), so the control channel and MCP reach them. Lock Column Guides is an undo step, is saved with the document, on in new ones, and read from and written to IDML's `ColumnGuideLocked`, which export always wrote as locked (#1096). No readiness percentage change.+ - **2026-10-16** · IDML: a page keeps column guides that were dragged off centre (InDesign's Custom columns). They were divided evenly on import, so the gutter sprang back to the middle; the imported positions now place the columns, with the canvas guides, snapping and text placement following them, and they are written back on export. Layout › Margins and Columns re-divides them evenly when the count or gutter changes, as InDesign's does. No readiness percentage change.+ - **2026-10-16** · IDML: custom column positions are checked before they are used (#1096). A set must give two edges per column, ascending from the left margin to the right one; any other (a wrong count, unsorted or non-numeric values, a list longer than 216 columns allow, or positions left behind by a margin or page-size change) is the even split, in the canvas, on import and on export, instead of columns drawn outside the margins. No readiness percentage change.+ - **2026-10-21** · Properties › Character and Paragraph: ••• (More Options) expands the section in place, as InDesign's: Character adds vertical and horizontal scale, baseline shift, skew, language and OpenType, and All Caps, Small Caps, Superscript, Subscript, Underline and Strikethrough; Paragraph adds the left, right, first line and last line indents, space before and after, the drop cap's lines and characters, Align to Baseline Grid and Hyphenate. It used to open the Character or Paragraph panel; the language field moved under ••• as in InDesign. Found in the Learn Skills Daily course, chapter 16. No readiness percentage change.+ - **2026-10-21** · The text Control panel has InDesign's two modes: A (Character Formatting Controls: font and style, size and leading, All Caps/Superscript/Underline and Small Caps/Subscript/Strikethrough, kerning and tracking, vertical and horizontal scale, baseline shift and skew, character style and language) and ¶ (Paragraph Formatting Controls: the nine alignments, left/first line and right/last line indents, space before and after, the drop cap's lines and characters, paragraph style, Hyphenate and Align to Baseline Grid). It used to show a fixed mix of both. Found in the Learn Skills Daily course, chapter 16. No readiness percentage change.+ - **2026-10-20** · With the Type tool, the Control panel's font size, leading and tracking fields have a spinner and a list of common values, as in InDesign (auto leading in parentheses). No readiness percentage change.+ - **2026-10-21** · The ¶ (Paragraph Formatting Controls) mode of the text Control panel has InDesign's Bulleted List and Numbered List buttons (with the default hanging indent) and Shading and Border: a checkbox, a button opening Paragraph Borders and Shading on that tab, and the colour. Found in the Learn Skills Daily course, chapter 21. No readiness percentage change.+ - **2026-10-21** · The Bulleted and Numbered List buttons (Properties, and Type › Bulleted & Numbered Lists › Apply Bullets / Apply Numbers) work as InDesign's: a paragraph with no indents gets the default hanging indent (0.25 in, −0.25 in), so the text lines up after the bullet instead of at the next default tab stop, and pressing the button again removes the list and that indent (`list.bullets`, `list.numbers`). Found in the Learn Skills Daily course, chapter 21. No readiness percentage change.+- **2026-10-17** · Inline and anchored objects paint under their frame's text, on screen and in PDF, as InDesign draws them: a picture whose frame reaches into the next line (a negative Y offset) no longer hides the top of that line. No readiness percentage change.- **2026-10-16** · Type › Reload Fonts (`font.reload`): fonts installed, edited or removed while DesignCraft runs are read again without a restart, and the open documents recompose with them (#328, #547). An edited font file is noticed by its length and modification time; bundled, added and document fonts stay as they are. InDesign does this by itself, so noticing changes automatically is still open (gap 6). No readiness percentage change.- **2026-10-16** · Parents can be deleted from their Pages-panel context menu or `layout.parents.delete {id}`. Applied-page and based-on references are cleared, local override copies survive, and Undo restores the parent. Addresses the deletion portion of #956; no readiness percentage change.- **2026-10-17** · File › Package writes the document's and the IDML's links relative to the package (`Links/logo.png`, `file:Links/logo.png`), so a package holds no path from the machine that made it; opening a document resolves them to the files beside it. Links › Copy Link(s) To still links by full path. (#340). No readiness percentage change.diff --cc crates/pdf/src/export/walk.rsindex 000000000,af6429b23..d8a4d2739mode 000000,100644..100644--- a/crates/pdf/src/export/walk.rs+++ b/crates/pdf/src/export/walk.rs@@@ -1,0 -1,440 +1,446 @@@+ use super::common::{TagEntry, blend, norm, rects_overlap, solid_fill, tf, to_path};+ use super::graphics::draw_coverage;+ use super::pipeline::{item_exported, layer_exported};+ use super::*;++ impl Exporter<'_> {+ /// Story `sid` composed for `page` ([`Cache::get`]), asked of the cache once per export.+ fn composed(&mut self, sid: designcraft_doc::StoryId, page: Option<usize>) -> Arc<designcraft_compose::ComposedStory> {+ let (doc, cache) = (self.doc, self.cache);+ self.composed.entry((sid, page)).or_insert_with(|| cache.get(doc, sid, page)).clone()+ }++ /// The parent pages' items on `layer` shown on page `pi` of spread `si`: the parent's bases+ /// first, then the parent.+ fn parent_items(&mut self, s: &mut Surface, si: usize, pi: usize, page: &designcraft_doc::Page, layer: &designcraft_doc::Layer, first: usize) {+ let doc = self.doc;+ for (ppi, ppage) in doc.shown_parent_pages(SpreadRef::Doc(si), pi) {+ let Some(parent) = doc.parents.get(ppi) else { continue };+ let Some(ppg) = parent.pages.get(ppage) else { continue };+ let dx = page.x - ppg.x;+ for it in &parent.items {+ if it.layer != layer.id || page.overridden.contains(&it.id) {+ continue;+ }+ // Parent items belong to the parent page they sit on.+ if parent.page_at_x(it.bounds().center().x) != Some(ppage) && parent.pages.len() > 1 {+ continue;+ }+ self.top_item(s, it, Affine::translate((dx, 0.0)), Some(first + pi), true);+ }+ }+ }++ pub(super) fn spread(&mut self, s: &mut Surface, si: usize) {+ let doc = self.doc;+ let Some(sp) = doc.spreads.get(si) else { return };+ let first = doc.first_page_of_spread(si);+ for layer in doc.layers.iter().rev() {+ if !layer_exported(layer) {+ continue;+ }+ for (pi, page) in sp.pages.iter().enumerate() {+ if page.show_parent_items {+ self.parent_items(s, si, pi, page, layer, first);+ }+ }+ for it in &sp.items {+ if it.layer == layer.id {+ self.top_item(s, it, Affine::IDENTITY, None, false);+ }+ }+ }+ }++ /// Push blend/opacity for an item drawn as a group. Returns the number of pushes.+ fn push_group(s: &mut Surface, opacity: f32, mode: DcBlend) -> usize {+ let mut n = 0;+ if mode != DcBlend::Normal {+ s.push_blend_mode(blend(mode));+ n += 1;+ }+ if opacity < 0.999 {+ s.push_opacity(norm(opacity));+ n += 1;+ } else if mode != DcBlend::Normal {+ s.push_isolated();+ n += 1;+ }+ n+ }++ /// Isolate Blending / Knockout Group: a transparency group with `/I` and `/K` as set.+ fn push_isolation(s: &mut Surface, it: &Item) -> usize {+ if it.isolate || it.knockout {+ s.push_group(krilla::blend::GroupOptions { isolated: it.isolate, knockout: it.knockout });+ 1+ } else {+ 0+ }+ }++ /// A spread or parent item, inside its structure tag when tagging.+ fn top_item(&mut self, s: &mut Surface, it: &Item, parent: Affine, page: Option<usize>, on_parent: bool) {+ if !self.opts.tagged || !item_exported(it) {+ return self.item(s, it, parent, page);+ }+ let story = it.text_frame().map(|t| t.story);+ let figure = !it.alt_text.is_empty() || matches!(it.content, Content::Graphic(_)) || it.has_nested_items();+ if on_parent || it.export_options.artifact || (story.is_none() && !figure) {+ // Page furniture and decoration.+ let kind = if on_parent { ArtifactType::Page } else { ArtifactType::Other };+ s.start_tagged(ContentTag::Artifact(Artifact::new(kind, None)));+ self.item(s, it, parent, page);+ s.end_tagged();+ return;+ }+ if let Some(sid) = story {+ // Text runs tag themselves by paragraph; the rest of the frame is an artifact.+ if let std::collections::hash_map::Entry::Vacant(e) = self.story_tags.entry(sid) {+ e.insert(Vec::new());+ self.tags.push(TagEntry::Story(sid));+ }+ self.tag_story = Some(sid);+ self.item(s, it, parent, page);+ self.tag_story = None;+ return;+ }+ let id = s.start_tagged(ContentTag::Other);+ self.item(s, it, parent, page);+ s.end_tagged();+ let alt = (!it.alt_text.is_empty()).then(|| it.alt_text.clone());+ let mut g = TagGroup::new(Tag::Figure(alt));+ g.push(id);+ self.tags.push(TagEntry::Figure(g));+ }++ /// The structure tree: stories (one paragraph each, its frames in thread order of appearance)+ /// and figures, in the order they first appear.+ pub(super) fn tag_tree(&mut self) -> TagTree {+ let mut tree = TagTree::new();+ for e in std::mem::take(&mut self.tags) {+ match e {+ TagEntry::Story(sid) => {+ // One structure element per paragraph: headings and quotes from the+ // paragraph style's Export Tagging, else P.+ let mut paras: Vec<usize> = self.para_tags.keys().filter(|(s, _)| *s == sid).map(|(_, p)| *p).collect();+ paras.sort_unstable();+ let story = self.doc.story(sid);+ for pi in paras {+ let ids = self.para_tags.remove(&(sid, pi)).unwrap_or_default();+ let style = story.and_then(|st| st.paras.get(pi)).map(|p| p.style.clone()).unwrap_or_default();+ let tag = self.doc.styles.export_tag(&style, false).map(|e| e.tag.clone()).unwrap_or_default();+ let text = || story.and_then(|st| st.para_ranges().get(pi).map(|r| st.text[r.clone()].trim().to_string()));+ let kind: krilla::tagging::TagKind = match tag.as_str() {+ h if h.len() == 2 && h.starts_with('h') => {+ let n = h[1..].parse::<u16>().unwrap_or(1).clamp(1, 6);+ Tag::Hn(std::num::NonZeroU16::new(n).unwrap_or(std::num::NonZeroU16::MIN), text()).into()+ }+ "blockquote" => Tag::BlockQuote.into(),+ _ => Tag::P.into(),+ };+ let mut g = TagGroup::new(kind);+ for id in ids {+ g.push(id);+ }+ tree.push(g);+ }+ }+ TagEntry::Figure(g) => tree.push(g),+ }+ }+ tree+ }++ fn item(&mut self, s: &mut Surface, it: &Item, parent: Affine, page: Option<usize>) {+ if self.drawing_items.len() >= 64 || self.drawing_items.contains(&it.id) {+ self.warnings.push(format!("Cyclic or excessively nested item {} was not rendered", it.id));+ return;+ }+ self.drawing_items.push(it.id);+ self.item_guarded(s, it, parent, page);+ self.drawing_items.pop();+ }++ fn item_guarded(&mut self, s: &mut Surface, it: &Item, parent: Affine, page: Option<usize>) {+ let gf = &it.effects.gradient_feather;+ if !gf.on || !item_exported(it) {+ return self.item_inner(s, it, parent, page);+ }+ // Gradient feather: a luminosity mask (white = opaque) over the object.+ let xf = parent * it.xf;+ let (p0, p1) = gf.points(it.feather_bounds());+ let gray = |a: f32| -> krilla::color::Color { luma::Color::new((a.clamp(0.0, 1.0) * 255.0).round() as u8).into() };+ let stops = vec![+ Stop { offset: NormalizedF32::ZERO, color: gray(gf.start), opacity: NormalizedF32::ONE },+ Stop { offset: NormalizedF32::ONE, color: gray(gf.end), opacity: NormalizedF32::ONE },+ ];+ let paint: krilla::paint::Paint = if gf.radial {+ let r = (p1 - p0).hypot().max(1e-3) as f32;+ RadialGradient {+ fx: p0.x as f32,+ fy: p0.y as f32,+ fr: 0.0,+ cx: p0.x as f32,+ cy: p0.y as f32,+ cr: r,+ transform: tf(xf),+ spread_method: SpreadMethod::Pad,+ stops,+ anti_alias: false,+ }+ .into()+ } else {+ LinearGradient {+ x1: p0.x as f32,+ y1: p0.y as f32,+ x2: p1.x as f32,+ y2: p1.y as f32,+ transform: tf(xf),+ spread_method: SpreadMethod::Pad,+ stops,+ anti_alias: false,+ }+ .into()+ };+ // The gradient keeps its item-space geometry, but its mask covers the complete exported+ // area (including bleed), so distant child shadows and thick strokes are never cut off.+ let mut sb = s.stream_builder();+ let mut ms = sb.surface();+ if let Some(p) = to_path(&self.clip.to_path(0.1)) {+ ms.set_fill(Some(Fill { paint, opacity: NormalizedF32::ONE, rule: FillRule::NonZero }));+ ms.draw_path(&p);+ }+ ms.finish();+ let stream = sb.finish();+ s.push_mask(krilla::mask::Mask::new(stream, krilla::mask::MaskType::Luminosity));+ self.item_inner(s, it, parent, page);+ s.pop();+ }++ fn item_inner(&mut self, s: &mut Surface, it: &Item, parent: Affine, page: Option<usize>) {+ if !item_exported(it) {+ return;+ }+ let ds = &it.effects.drop_shadow;+ let grow = it.stroke.extent() + 2.0 + if ds.on { ds.distance.abs() + ds.size.abs() } else { 0.0 };+ let vb = parent.transform_rect_bbox(it.bounds()).inflate(grow, grow);+ if !rects_overlap(vb, self.clip) {+ return;+ }+ let xf = parent * it.xf;+ if it.has_nested_items() {+ self.draw_nested_item(s, it, xf, page);+ return;+ }+ if !it.children().is_empty() {+ self.draw_group_children(s, it, xf, page);+ return;+ }+ let bp = if it.corners.is_none() { it.path.to_bezpath() } else { corners::apply(&it.path, &it.corners) };+ let path = to_path(&bp);+ self.draw_leaf_item(s, it, parent, page, &bp, path.as_ref());+ }++ fn draw_nested_item(&mut self, s: &mut Surface, it: &Item, xf: Affine, page: Option<usize>) {+ // A frame with items pasted into it: fill, the items clipped to the frame, stroke.+ let bp = if it.corners.is_none() { it.path.to_bezpath() } else { corners::apply(&it.path, &it.corners) };+ let path = to_path(&bp);+ let pushes = Self::push_group(s, it.opacity, it.blend);+ s.push_transform(&tf(xf));+ if !it.fill.is_none()+ && let Some(p) = &path+ && let Some(paint) = self.fill_paint(&it.fill, bp.bounding_box())+ {+ self.fill_item_path(s, &it.fill, paint, p);+ }+ s.pop();+ // The clip in page space, so the children keep their absolute transforms.+ let mut page_bp = bp.clone();+ page_bp.apply_affine(xf);+ let clip = to_path(&page_bp);+ if let Some(c) = &clip {+ s.push_clip_path(c, &FillRule::NonZero);+ }+ for child in it.children() {+ self.item(s, child, xf, page);+ }+ if clip.is_some() {+ s.pop();+ }+ if !it.stroke.is_none()+ && let Some(p) = &path+ {+ s.push_transform(&tf(xf));+ self.stroke(s, it, &bp, p);+ s.pop();+ }+ for _ in 0..pushes {+ s.pop();+ }+ }++ fn draw_group_children(&mut self, s: &mut Surface, it: &Item, xf: Affine, page: Option<usize>) {+ let pushes = Self::push_group(s, it.opacity, it.blend) + Self::push_isolation(s, it);+ for child in it.shown_children() {+ self.item(s, child, xf, page);+ }+ for _ in 0..pushes {+ s.pop();+ }+ }++ fn draw_leaf_item(&mut self, s: &mut Surface, it: &Item, parent: Affine, page: Option<usize>, bp: &BezPath, path: Option<&Path>) {+ let xf = parent * it.xf;+ let pushes = Self::push_group(s, it.opacity, it.blend);+ let frame_art = self.tag_story.is_some();+ if frame_art {+ s.start_tagged(ContentTag::Artifact(Artifact::new(ArtifactType::Other, None)));+ }+ self.draw_drop_shadow(s, it, parent, xf, path);+ s.push_transform(&tf(xf));+ if !it.fill.is_none()+ && let Some(p) = path+ && let Some(paint) = self.fill_paint(&it.fill, bp.bounding_box())+ {+ self.fill_item_path(s, &it.fill, paint, p);+ }+ if frame_art {+ s.end_tagged();+ }- self.draw_leaf_content(s, it, bp, path, page);++ // A text frame's anchored objects are drawn under its text when they can be.++ let drawn = self.draw_leaf_content(s, it, xf, bp, path, page);+ self.draw_leaf_stroke(s, it, bp, path, frame_art);+ s.pop();+ for _ in 0..pushes {+ s.pop();+ }- if let Content::Text(tfr) = &it.content {++ if let Content::Text(tfr) = &it.content++ && !drawn++ {+ let cs = self.composed(tfr.story, page);+ if let Some(ft) = cs.frame(it.id) {+ self.frame_objects(s, ft, xf * self.doc.text_local(it), page);+ }+ }+ }++ /// Draw a cached coverage mask or the offset item silhouette as the drop shadow.+ fn draw_drop_shadow(&mut self, s: &mut Surface, it: &Item, parent: Affine, xf: Affine, path: Option<&Path>) {+ let ds = &it.effects.drop_shadow;+ if ds.on+ && let Some(mask) = self.opts.shadows.get(&it.id)+ && let Some(c) = self.swatch_color(&ds.color, 1.0)+ {+ s.push_transform(&tf(parent));+ draw_coverage(s, mask, c);+ s.pop();+ } else if ds.on+ && let Some(p) = path+ && let Some(c) = self.swatch_color(&ds.color, 1.0)+ {+ let a = self.doc.light_angle(ds.angle, ds.global_light).to_radians();+ let off = Vec2::new(-a.cos() * ds.distance, a.sin() * ds.distance);+ s.push_transform(&tf(Affine::translate(off) * xf));+ s.set_stroke(None);+ s.set_fill(Some(solid_fill(c, ds.opacity)));+ s.draw_path(p);+ s.set_fill(None);+ s.pop();+ }+ }+- fn draw_leaf_content(&mut self, s: &mut Surface, it: &Item, bp: &BezPath, path: Option<&Path>, page: Option<usize>) {++ /// The item's content; returns whether a text frame's anchored objects were drawn with it.++ fn draw_leaf_content(&mut self, s: &mut Surface, it: &Item, xf: Affine, bp: &BezPath, path: Option<&Path>, page: Option<usize>) -> bool {+ let doc = self.doc;++ let mut drawn = false;+ match &it.content {+ Content::Graphic(g) => {+ let g = &if it.media.is_some() { it.drawn_graphic(&self.doc.assets).unwrap_or_else(|| g.clone()) } else { g.clone() };+ if let Some(p) = path {+ s.push_clip_path(p, &FillRule::NonZero);+ // An explicit all-on choice is `Some(&[])`, not the file's defaults: passing+ // `None` would embed the source's default-hidden layers and skip the rewrite+ // error that a stale choice must raise.+ self.graphic(s, g, it.has_pdf_layer_override().then_some(it.pdf_hidden_layers.as_slice()));+ s.pop();+ }+ }+ Content::Text(tfr) => {+ let cs = self.composed(tfr.story, page);+ if let (Some(ft), Some(pt)) = (cs.frame(it.id), &tfr.options.path) {+ // Type on a path: the glyphs as outlines along the path.+ for (si, gp) in designcraft_compose::path_glyphs(&cs, ft, bp, pt) {+ let st = &cs.styles[si as usize];+ // A gradient spans the path's box.+ let fill = designcraft_doc::Fill {+ swatch: st.fill.clone(),+ tint: st.fill_tint,+ overprint: st.overprint_fill,+ ..designcraft_doc::Fill::none()+ };+ if let (Some(paint), Some(p)) = (self.fill_paint(&fill, bp.bounding_box()), to_path(&gp)) {+ let op = self.overprints(&st.fill, st.fill_tint, st.overprint_fill);+ let op = self.push_overprint(s, op, false);+ s.set_fill(Some(Fill { paint, opacity: NormalizedF32::ONE, rule: FillRule::NonZero }));+ s.draw_path(&p);+ s.set_fill(None);+ if op {+ s.pop();+ }+ }+ }+ } else if let Some(ft) = cs.frame(it.id) {+ let text = doc.story(tfr.story).map(|st| st.text.as_str()).unwrap_or("");+ let local = doc.text_local(it);+ if local != Affine::IDENTITY {+ s.push_transform(&tf(local));+ }+ self.text_area = (local.determinant().abs() > 1e-12).then(|| local.inverse().transform_rect_bbox(it.inner_bounds()));- self.frame_text(s, &cs, ft, text);++ drawn = self.frame_text(s, &cs, ft, text, Some((xf * local, page)));+ self.text_area = None;+ if local != Affine::IDENTITY {+ s.pop();+ }+ }+ }+ _ => {}+ }++ drawn+ }++ fn draw_leaf_stroke(&mut self, s: &mut Surface, it: &Item, bp: &BezPath, path: Option<&Path>, frame_art: bool) {+ if !it.stroke.is_none()+ && let Some(p) = path+ {+ if frame_art {+ s.start_tagged(ContentTag::Artifact(Artifact::new(ArtifactType::Other, None)));+ }+ self.stroke(s, it, bp, p);+ if frame_art {+ s.end_tagged();+ }+ }+ }++ /// Draw embedded page items after restoring the surface, retaining spread-space+ /// transforms for page culling (also for anonymous note and cell stories).- fn frame_objects(&mut self, s: &mut Surface, ft: &designcraft_compose::FrameText, xf: Affine, page: Option<usize>) {++ pub(crate) fn frame_objects(&mut self, s: &mut Surface, ft: &designcraft_compose::FrameText, xf: Affine, page: Option<usize>) {+ let mut pending = vec![(ft, xf)];+ while let Some((frame, transform)) = pending.pop() {+ for object in &frame.objects {+ self.item(s, &object.object.item, transform * Affine::translate(object.origin.to_vec2()), page);+ }+ for note in &frame.notes {+ if let Some(frame) = note.text.frames.first() {+ pending.push((frame, transform * Affine::translate(note.origin.to_vec2())));+ }+ }+ for cell in frame.tables.iter().flat_map(|t| &t.cells) {+ if let Some(frame) = cell.text.frames.first() {+ pending.push((frame, transform * Affine::translate(cell.origin.to_vec2())));+ }+ }+ }+ }+ }diff --cc crates/pdf/src/tests.rsindex 8eee19a88,2accc79fa..58b1b72c8--- a/crates/pdf/src/tests.rs+++ b/crates/pdf/src/tests.rs@@@ -848,59 -898,29 +912,86 @@@ fn a_swatch_colours_a_greyscale_image(assert!(!s.contains("PANTONE#20Test"), "a colour image keeps its colours");}+/// An inline object is painted under its frame's text, as InDesign draws it: a picture whose+/// frame reaches down into the next line (a negative Y offset) doesn't hide that line.+#[test]+fn inline_objects_are_painted_under_the_text() {+ use designcraft_doc::{AnchorPosition, AnchoredObject};+ let mut d = doc_with_text("A\nWWWW");+ let sid = *d.stories.keys().next().unwrap();+ let mut item = Item::new(+ ItemId(d.alloc()),+ d.default_layer(),+ designcraft_doc::Shape::Rectangle,+ designcraft_geom::shapes::rectangle(Rect::new(0.0, 0.0, 200.0, 30.0)),+ );+ item.fill = Fill::swatch(designcraft_color::swatch::BLACK);+ d.story_mut(sid).unwrap().insert_object(1, AnchoredObject::new(item, AnchorPosition::Inline { y_offset: -20.0 }));+ let order = paint_order(&export_pdf(&d, &Cache::new(), &PdfOptions::default()).unwrap());+ let first_text = order.iter().position(|(op, _)| op.ends_with("text")).unwrap();+ let the_box = order.iter().position(|(op, _)| op == "fill path").unwrap();+ assert!(the_box < first_text, "{order:?}");+}++/// An anchored object is painted as part of its host frame, as the screen renderer paints it:+/// inside the frame's transparency group (so a half-transparent frame shows its inline picture+/// half-transparent too), after the frame's fill and before its text and stroke.+#[test]+fn inline_objects_share_their_frames_transparency() {+ use designcraft_doc::{AnchorPosition, AnchoredObject};+ let mut d = doc_with_text("A\nWWWW");+ let sid = *d.stories.keys().next().unwrap();+ let fid = d.stories[&sid].frames[0];+ {+ let host = d.item_mut(fid).unwrap();+ host.opacity = 0.5;+ host.fill = Fill::swatch(designcraft_color::swatch::PAPER);+ host.stroke.weight = 3.0;+ host.stroke.swatch = designcraft_color::swatch::BLACK.into();+ }+ let mut item = Item::new(+ ItemId(d.alloc()),+ d.default_layer(),+ designcraft_doc::Shape::Rectangle,+ designcraft_geom::shapes::rectangle(Rect::new(0.0, 0.0, 200.0, 30.0)),+ );+ item.fill = Fill::swatch(designcraft_color::swatch::BLACK);+ d.story_mut(sid).unwrap().insert_object(1, AnchoredObject::new(item, AnchorPosition::Inline { y_offset: -20.0 }));+ let ev = paint_events(&export_pdf(&d, &Cache::new(), &PdfOptions::default()).unwrap(), true);+ let at = |op: &str| ev.iter().position(|(o, _)| o == op).unwrap_or_else(|| panic!("no {op}: {ev:?}"));+ let group = ev.iter().position(|(o, a)| o == "group" && (*a - 0.5).abs() < 1e-3).unwrap_or_else(|| panic!("no half-opacity group: {ev:?}"));+ let end = group + ev[group..].iter().position(|(o, _)| o == "end group").unwrap();+ // Fills in order: the frame's, then the anchored box's.+ let fills: Vec<usize> = ev.iter().enumerate().filter(|(_, (o, _))| o == "fill path").map(|(i, _)| i).collect();+ assert!(fills.len() >= 2, "{ev:?}");+ let the_box = fills[1];+ assert!(group < the_box && the_box < end, "the box is inside the frame's group: {ev:?}");+ assert!(the_box < at("fill text") && at("fill text") < at("stroke path") && at("stroke path") < end, "{ev:?}");+}+++ /// The export asks for each story's composition once per page it is shown on: a parent page's+ /// page number still reads its own page everywhere, and a story threaded across pages shows each+ /// frame's own lines.+ #[test]+ fn each_page_shows_its_own_composition() {+ use designcraft_doc::story::PAGE_NUMBER;+ let mut d = Document::new(&NewDocument { pages: 3, facing_pages: false, ..NewDocument::default() });+ let lid = d.default_layer();+ d.add_text_frame(SpreadRef::Parent(0), Rect::new(36.0, 700.0, 300.0, 740.0), lid, &format!("Folio{PAGE_NUMBER}"), ParaFormat::default()).unwrap();+ let (first, _) =+ d.add_text_frame(SpreadRef::Doc(0), Rect::new(36.0, 36.0, 300.0, 56.0), lid, "Alpha\nBravo\nCharlie", ParaFormat::default()).unwrap();+ let mut prev = first;+ for si in 1..3 {+ let id = ItemId(d.alloc());+ let it = Item::new(id, lid, designcraft_doc::Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(36.0, 36.0, 300.0, 56.0)));+ d.insert_item(SpreadRef::Doc(si), it, None).unwrap();+ d.thread(prev, id).unwrap();+ prev = id;+ }+ let cache = Cache::new();+ let opts = PdfOptions { created: Some(0), ..PdfOptions::default() };+ let bytes = export_pdf(&d, &cache, &opts).unwrap();+ // Parent items first, then the page's own.+ assert_eq!(extract_text(&bytes), ["Folio1Alpha", "Folio2Bravo", "Folio3Charlie"]);+ assert_eq!(export_pdf(&d, &cache, &opts).unwrap(), bytes, "a warm cache exports the same bytes");+ }diff --cc crates/pdf/src/text.rsindex f059bb605,ba44cf713..fdef09fae--- a/crates/pdf/src/text.rs+++ b/crates/pdf/src/text.rs@@@ -233,17 -234,35 +234,45 @@@ impl Exporter<'_>}}+ /// One line's glyphs as tagged runs; a glyph that is turned or slanted gets a transform of its own.+ fn line_glyphs(&mut self, s: &mut Surface, cs: &ComposedStory, ft: &FrameText, l: &designcraft_compose::Line, story: &str) {+ let gs = &l.glyphs;+ let mut i = 0;+ while i < gs.len() {+ let g = &gs[i];+ if !g.visible || g.sx <= 0.0 || g.sy <= 0.0 {+ i += 1;+ continue;+ }+ // Vertical type: an upright glyph turns back a quarter about its em box centre.+ // Shatai slants each glyph about its own em box centre first.+ let turn = if ft.vertical { g.vertical_xf(l.baseline) } else { None };+ let shatai = cs.styles.get(g.style as usize).and_then(|st| st.shatai_xf(g, l.baseline));+ if turn.is_some() || shatai.is_some() {+ let m = turn.unwrap_or(Affine::IDENTITY) * shatai.unwrap_or(Affine::IDENTITY);+ s.push_transform(&crate::export::tf(m));+ self.tagged_run(s, cs, &gs[i..i + 1], l.baseline, story);+ s.pop();+ i += 1;+ continue;+ }+ let j = run_end(ft, gs, i);+ self.tagged_run(s, cs, &gs[i..j], l.baseline, story);+ i = j;+ }+ }+- pub(crate) fn frame_text(&mut self, s: &mut Surface, cs: &ComposedStory, ft: &FrameText, story: &str) {+ /// The frame's text. With `objects` (the frame text space → page transform and the page),+ /// the frame's anchored objects are drawn too, over its paragraph shading and under its text;+ /// returns whether they were.+ pub(crate) fn frame_text(+ &mut self,+ s: &mut Surface,+ cs: &ComposedStory,+ ft: &FrameText,+ story: &str,+ objects: Option<(Affine, Option<usize>)>,+ ) -> bool {// Paragraph shading and rules under the text.self.as_artifact(s, |me, s| {for d in ft.decos.iter().filter(|d| !d.nonprinting) {@@@ -322,9 -307,27 +328,28 @@@}}});+ drawn}+ /// One table cell's graphic, or its text composed in the cell's own area.+ fn table_cell(&mut self, s: &mut Surface, c: &designcraft_compose::PlacedCell) {+ if let Some(g) = &c.graphic {+ if let Some(clip) = to_path(&c.clip.to_path(0.1)) {+ s.push_clip_path(&clip, &krilla::paint::FillRule::NonZero);+ s.push_transform(&tf(Affine::translate((c.clip.x0, c.clip.y0))));+ self.graphic(s, g, None);+ s.pop();+ s.pop();+ }+ } else if let Some(cft) = c.text.frames.first() {+ s.push_transform(&tf(Affine::translate(c.origin.to_vec2())));+ let area = std::mem::replace(&mut self.text_area, lines_area(cft));- self.frame_text(s, &c.text, cft, &c.source);++ self.frame_text(s, &c.text, cft, &c.source, None);+ self.text_area = area;+ s.pop();+ }+ }+/// Table fragments: cell fills, cell text (real text), edges and the border.fn tables(&mut self, s: &mut Surface, ft: &FrameText) {for t in &ft.tables {diff --cc crates/render/src/tests.rsindex 000000000,295a0da5f..0ea80e7femode 000000,100644..100644--- a/crates/render/src/tests.rs+++ b/crates/render/src/tests.rs@@@ -1,0 -1,671 +1,697 @@@+ use super::*;+ use designcraft_doc::build::NewDocument;+ use designcraft_doc::{Fill, ParaFormat};++ #[test]+ fn eps_source_decodes_like_its_preview() {+ let source = b"%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 20 10\n%%EOF\n";+ let mut tiff = Vec::new();+ image::DynamicImage::ImageRgba8(image::RgbaImage::from_pixel(3, 2, image::Rgba([255, 0, 0, 128])))+ .write_to(&mut std::io::Cursor::new(&mut tiff), image::ImageFormat::Tiff)+ .unwrap();+ let mut dos = vec![0xC5, 0xD0, 0xD3, 0xC6];+ for value in [30usize, source.len(), 0, 0, 30 + source.len(), tiff.len()] {+ dos.extend((value as u32).to_le_bytes());+ }+ dos.extend([0xFF, 0xFF]);+ dos.extend_from_slice(source);+ dos.extend_from_slice(&tiff);+ for source in [source.as_slice(), dos.as_slice()] {+ let proxy = designcraft_images::eps_proxy(source).unwrap().0;+ let actual = decode_pixmap(source).unwrap();+ let expected = decode_pixmap(&proxy).unwrap();+ assert_eq!((actual.width(), actual.height()), (expected.width(), expected.height()));+ assert_eq!(actual.data(), expected.data());+ assert_eq!(image_size(source), image_size(&proxy));+ assert_eq!(image_mime(source), "application/postscript");+ }+ let corrupt = b"%!PS-Adobe-3.0 EPSF-3.0\nno bounding box\n";+ assert!(decode_pixmap(corrupt).is_none());+ assert!(image_size(corrupt).is_none());+ }++ #[test]+ fn footnote_vector_objects_are_painted() {+ use designcraft_doc::{AnchorPosition, AnchoredObject, ItemId, Shape, SpreadRef};+ let mut d = Document::new(&NewDocument::default());+ let (_, sid) =+ d.add_text_frame(SpreadRef::Doc(0), Rect::new(20.0, 20.0, 300.0, 300.0), d.default_layer(), "Body", ParaFormat::default()).unwrap();+ let mut item =+ Item::new(ItemId(d.alloc()), d.default_layer(), Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(0.0, 0.0, 12.0, 12.0)));+ item.fill = Fill::swatch(designcraft_color::swatch::BLACK);+ // Open contours with a fill are implicitly closed for painting. A single+ // open contour must not hide the whole compound glyph.+ item.path.subpaths[0].closed = false;+ let story = d.story_mut(sid).unwrap();+ story.insert_note(4, "", ParaFormat::default());+ Arc::make_mut(&mut story.notes[0]).text.insert_object(0, AnchoredObject::new(item, AnchorPosition::Inline { y_offset: 0.0 }));+ let cache = Cache::new();+ let cs = cache.get(&d, sid, None);+ let note = &cs.frames[0].notes[0];+ let object = ¬e.text.frames[0].objects[0];+ let centre = note.origin + object.origin.to_vec2() + designcraft_geom::Vec2::new(6.0, 6.0);+ let image = Renderer::new().render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap();+ let pixel = image.pixel(centre.x as u32, centre.y as u32);+ assert!(pixel[0] < 80 && pixel[1] < 80 && pixel[2] < 80, "{pixel:?}");+ }++ /// `Rendered` has public fields: a buffer that doesn't match the stated size used to panic+ /// in `to_png`.+ /// A canvas 65535 pixels wide (any render wider than that was clamped to it) panicked inside+ /// vello_cpu when it snapped the width up to its tiles; a huge page export now declines.+ #[test]+ fn very_wide_renders_do_not_panic() {+ let doc = Document::new(&NewDocument::default());+ let cache = Cache::new();+ let mut r = Renderer::new();+ let img = r.render(&doc, &cache, &[], (70_000, 4), Affine::IDENTITY, &RenderOptions::default());+ assert_eq!(img.width, MAX_SIDE);+ let page = [Placed { spread: SpreadRef::Doc(0), xf: Affine::IDENTITY }];+ let opts = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() };+ let img = r.render(&doc, &cache, &page, (70_000, 64), Affine::scale(120.0), &opts);+ assert_eq!(img.width, MAX_SIDE);+ assert!(r.render_page(&doc, &cache, 0, 500.0, true, &RenderOptions::default()).is_none());+ }++ #[test]+ fn to_png_survives_a_mismatched_buffer() {+ let short = Rendered { width: 4, height: 4, pixels: vec![255; 10] };+ let png = short.to_png();+ assert_eq!(image::load_from_memory(&png).map(|i| (i.width(), i.height())).ok(), Some((4, 4)));+ assert!(Rendered { width: 0, height: 0, pixels: vec![] }.to_png().len() < 1024);+ }++ #[test]+ fn proof_view_simulates_the_target() {+ use designcraft_color::cms::{ProofSetup, ProofTarget};+ let red = |a: u8| Rendered { width: 1, height: 1, pixels: vec![a, 0, 0, a] };+ let mut img = red(255);+ proof_view(&mut img, &ProofSetup { target: ProofTarget::Protanopia, ..Default::default() });+ assert!(img.pixels[1] > 40, "protanopia turns pure red olive: {:?}", img.pixels);+ let mut img = red(255);+ proof_view(&mut img, &ProofSetup { target: ProofTarget::MonitorRgb, ..Default::default() });+ assert!(img.pixels[0] > 245 && img.pixels[1] < 10, "monitor RGB is no simulation: {:?}", img.pixels);+ // Transparent pixels stay transparent; premultiplication is kept.+ let mut img = Rendered { width: 2, height: 1, pixels: vec![0, 0, 0, 0, 100, 0, 0, 128] };+ proof_view(&mut img, &ProofSetup { target: ProofTarget::WorkingCmyk, ..Default::default() });+ assert_eq!(&img.pixels[..4], &[0, 0, 0, 0]);+ assert!(img.pixels[4] <= 128 && img.pixels[7] == 128);+ }++ #[test]+ fn renders_page_with_text_and_fill() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let (fid, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(36.0, 36.0, 576.0, 300.0), lid, "Hello DesignCraft", ParaFormat::default()).unwrap();+ let id = designcraft_doc::ItemId(d.alloc());+ let mut box_ = Item::new(id, lid, designcraft_doc::Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(36.0, 400.0, 136.0, 500.0)));+ box_.fill = Fill::swatch("C=100 M=0 Y=0 K=0");+ d.insert_item(SpreadRef::Doc(0), box_, None).unwrap();+ let cache = Cache::new();+ let mut r = Renderer::new();+ r.threads = 0;+ let img = r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap();+ assert_eq!((img.width, img.height), (612, 792));+ // Paper is white, the box is cyan-ish, text drew some dark pixels.+ assert_eq!(img.pixel(300, 700), [255, 255, 255, 255]);+ let c = img.pixel(80, 450);+ assert!(c[0] < 80 && c[2] > 150, "{c:?}");+ let dark = (36..300).flat_map(|x| (36..60).map(move |y| (x, y))).filter(|&(x, y)| img.pixel(x, y)[0] < 100).count();+ assert!(dark > 50, "text pixels: {dark}");+ let _ = fid;+ assert!(r.stats.glyphs >= 15);+ }++ /// An inside-aligned stroke is the stroke of the path inset by half its weight: a band from the+ /// edge inwards, its rounded corners concentric with the frame's.+ #[test]+ fn inside_strokes_are_inset_by_half_the_weight() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let id = designcraft_doc::ItemId(d.alloc());+ let mut it = Item::new(id, lid, designcraft_doc::Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(100.0, 100.0, 300.0, 300.0)));+ it.stroke = designcraft_doc::Stroke {+ swatch: designcraft_color::swatch::BLACK.into(),+ weight: 10.0,+ align: designcraft_doc::StrokeAlign::Inside,+ ..Default::default()+ };+ it.corners = designcraft_geom::corners::CornerOptions::uniform(designcraft_geom::corners::CornerShape::Rounded, 20.0);+ d.insert_item(SpreadRef::Doc(0), it, None).unwrap();+ let cache = Cache::new();+ let mut r = Renderer::new();+ r.threads = 0;+ let img = r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap();+ let ink = |x: u32, y: u32| img.pixel(x, y)[0] < 64;+ let paper = |x: u32, y: u32| img.pixel(x, y)[0] > 192;+ // Straight edges: ink from the edge to 10 pt inside, nothing outside.+ assert!(paper(97, 200) && ink(101, 200) && ink(108, 200) && paper(112, 200));+ assert!(ink(298, 200) && paper(302, 200) && paper(288, 200));+ // Rounded corner centred at (120, 120): ink between radii 10 and 20, paper outside the arc+ // and inside the band.+ assert!(paper(103, 103) && ink(108, 108) && paper(114, 114));+ }++ #[test]+ fn arrowheads_draw_at_line_ends() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let id = designcraft_doc::ItemId(d.alloc());+ let path = designcraft_geom::shapes::line(designcraft_geom::Point::new(100.0, 400.0), designcraft_geom::Point::new(400.0, 400.0));+ let mut line = Item::new(id, lid, designcraft_doc::Shape::GraphicLine, path);+ line.stroke = designcraft_doc::Stroke {+ swatch: designcraft_color::swatch::BLACK.into(),+ weight: 2.0,+ end: designcraft_doc::Arrowhead::TriangleWide,+ ..Default::default()+ };+ d.insert_item(SpreadRef::Doc(0), line, None).unwrap();+ // A dashed line with a gap colour: the gaps are painted.+ let id = designcraft_doc::ItemId(d.alloc());+ let path = designcraft_geom::shapes::line(designcraft_geom::Point::new(100.0, 500.0), designcraft_geom::Point::new(400.0, 500.0));+ let mut dashed = Item::new(id, lid, designcraft_doc::Shape::GraphicLine, path);+ dashed.stroke = designcraft_doc::Stroke {+ swatch: designcraft_color::swatch::BLACK.into(),+ weight: 4.0,+ kind: designcraft_doc::StrokeType::Dashed { pattern: vec![12.0, 4.0] },+ gap_swatch: "C=100 M=0 Y=0 K=0".into(),+ ..Default::default()+ };+ d.insert_item(SpreadRef::Doc(0), dashed, None).unwrap();+ let cache = Cache::new();+ let mut r = Renderer::new();+ r.threads = 0;+ let img = r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap();+ // The head is 6.4 × weight wide: ink 4 pt above the line near the tip, none at the start.+ assert!(img.pixel(393, 396)[0] < 128, "{:?}", img.pixel(393, 396));+ assert_eq!(img.pixel(105, 396), [255, 255, 255, 255]);+ // Nothing past the tip.+ assert_eq!(img.pixel(403, 400), [255, 255, 255, 255]);+ let (dash, gap) = (img.pixel(106, 500), img.pixel(114, 500));+ assert!(dash[0] < 80 && dash[2] < 80, "dash {dash:?}");+ assert!(gap[0] < 80 && gap[2] > 150, "gap {gap:?}");+ }++ #[test]+ fn overprint_preview_mixes_inks() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ for (sw, op) in [("C=0 M=0 Y=100 K=0", false), ("C=0 M=100 Y=0 K=0", true)] {+ let id = designcraft_doc::ItemId(d.alloc());+ let mut it =+ Item::new(id, lid, designcraft_doc::Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(100.0, 100.0, 200.0, 200.0)));+ it.fill = Fill { overprint: op, ..Fill::swatch(sw) };+ d.insert_item(SpreadRef::Doc(0), it, None).unwrap();+ }+ let cache = Cache::new();+ let mut r = Renderer::new();+ r.threads = 0;+ let px = |on: bool, r: &mut Renderer| {+ r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions { overprint_preview: on, ..Default::default() }).unwrap().pixel(150, 150)+ };+ let off = px(false, &mut r);+ let on = px(true, &mut r);+ assert!(off[2] > 100, "magenta knocks out: {off:?}");+ assert!(on[2] < 60 && on[0] > 180, "magenta over yellow → red: {on:?}");+ }++ #[test]+ fn cmyk_blend_space_shows_transparent_spreads_in_cmyk() {+ let mut d = Document::new(&NewDocument::default());+ d.swatches.push(designcraft_color::swatch::Swatch::color("Green", designcraft_color::Color::rgb8(0, 255, 0)));+ let lid = d.default_layer();+ let id = designcraft_doc::ItemId(d.alloc());+ let mut it = Item::new(id, lid, designcraft_doc::Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(100.0, 100.0, 200.0, 200.0)));+ it.fill = Fill::swatch("Green");+ d.insert_item(SpreadRef::Doc(0), it, None).unwrap();+ let cache = Cache::new();+ let mut r = Renderer::new();+ r.threads = 0;+ let px = |d: &Document, r: &mut Renderer| {+ r.render_page(d, &cache, 0, 1.0, false, &RenderOptions { blend_space_view: true, ..Default::default() }).unwrap().pixel(150, 150)+ };+ // No transparency on the spread: shown as is.+ assert_eq!(px(&d, &mut r)[1], 255);+ // With transparency in a CMYK blend space the bright green leaves the RGB gamut's edge.+ d.item_mut(id).unwrap().opacity = 0.99;+ let cmyk = px(&d, &mut r);+ assert!(cmyk[0] > 20 || cmyk[1] < 240, "{cmyk:?}");+ d.settings.blend_space = designcraft_doc::BlendSpace::Rgb;+ let rgb = px(&d, &mut r);+ assert!(rgb[1] > 245 && rgb[0] < 10, "{rgb:?}");+ }++ #[test]+ fn blend_modes_blend_in_cmyk_on_screen_in_a_cmyk_blend_space() {+ // A lilac (RGB) rectangle, and a 100% K one over its lower half and the paper below it,+ // in Color Dodge: in CMYK the black clears the lilac's inks (white), over the paper it+ // shows as it is; in RGB, dodging with black changes nothing.+ let mut d = Document::new(&NewDocument::default());+ d.swatches.push(designcraft_color::swatch::Swatch::color("Lilac", designcraft_color::Color::rgb8(171, 154, 227)));+ let lid = d.default_layer();+ let rect = |d: &mut Document, r: Rect, fill: &str| {+ let id = designcraft_doc::ItemId(d.alloc());+ let mut it = Item::new(id, lid, designcraft_doc::Shape::Rectangle, designcraft_geom::shapes::rectangle(r));+ it.fill = Fill::swatch(fill);+ d.insert_item(SpreadRef::Doc(0), it, None).unwrap();+ id+ };+ rect(&mut d, Rect::new(100.0, 100.0, 300.0, 200.0), "Lilac");+ let black = rect(&mut d, Rect::new(150.0, 150.0, 250.0, 250.0), designcraft_color::swatch::BLACK);+ d.item_mut(black).unwrap().blend = DcBlend::ColorDodge;+ let cache = Cache::new();+ let mut r = Renderer::new();+ r.threads = 0;+ let px = |d: &Document, r: &mut Renderer, x: u32, y: u32| {+ r.render_page(d, &cache, 0, 1.0, false, &RenderOptions { blend_space_view: true, ..Default::default() }).unwrap().pixel(x, y)+ };+ let over_lilac = px(&d, &mut r, 200, 175);+ assert!(over_lilac[..3].iter().all(|v| *v > 235), "dodged to white: {over_lilac:?}");+ let over_paper = px(&d, &mut r, 200, 225);+ assert!(over_paper[..3].iter().all(|v| *v < 90), "black as it is: {over_paper:?}");+ let lilac = px(&d, &mut r, 120, 150);+ assert!(lilac[2] > lilac[1] + 25, "the lilac beside it: {lilac:?}");+ // Inside a group, the group's blend mode.+ let g = designcraft_doc::ItemId(d.alloc());+ let it = d.remove_item(black).unwrap();+ let mut grp = Item::new(g, lid, designcraft_doc::Shape::Group, Default::default());+ let mut inner = (*it).clone();+ inner.blend = DcBlend::Normal;+ grp.content = Content::Group { items: vec![Arc::new(inner)] };+ grp.blend = DcBlend::ColorDodge;+ d.insert_item(SpreadRef::Doc(0), grp, None).unwrap();+ let grouped = px(&d, &mut r, 200, 175);+ assert!(grouped[..3].iter().all(|v| *v > 235), "{grouped:?}");+ // An RGB blend space: still lilac under the black (lightened a little: [Black] shows as a+ // dark grey in RGB).+ d.settings.blend_space = designcraft_doc::BlendSpace::Rgb;+ let rgb = px(&d, &mut r, 200, 175);+ assert!(rgb[2] > rgb[1] + 25 && rgb[1] < 220, "{rgb:?}");+ }++ #[test]+ fn knockout_group_hides_its_own_objects() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let mut kids = Vec::new();+ for (sw, x) in [("C=0 M=0 Y=100 K=0", 100.0), ("C=0 M=100 Y=0 K=0", 150.0)] {+ let id = designcraft_doc::ItemId(d.alloc());+ let mut it =+ Item::new(id, lid, designcraft_doc::Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(x, 100.0, x + 100.0, 200.0)));+ it.fill = Fill::swatch(sw);+ it.opacity = 0.5;+ kids.push(std::sync::Arc::new(it));+ }+ let gid = designcraft_doc::ItemId(d.alloc());+ let mut g = Item::new(gid, lid, designcraft_doc::Shape::Group, designcraft_geom::shapes::rectangle(Rect::new(100.0, 100.0, 250.0, 200.0)));+ g.content = designcraft_doc::Content::Group { items: kids };+ d.insert_item(SpreadRef::Doc(0), g, None).unwrap();+ let cache = Cache::new();+ let mut r = Renderer::new();+ r.threads = 0;+ let overlap = |d: &Document, r: &mut Renderer| r.render_page(d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap().pixel(175, 150);+ let plain = overlap(&d, &mut r);+ d.item_mut(gid).unwrap().knockout = true;+ let ko = overlap(&d, &mut r);+ let magenta_only = r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap().pixel(225, 150);+ assert_ne!(plain, ko, "{plain:?} {ko:?}");+ for c in 0..3 {+ assert!((ko[c] as i32 - magenta_only[c] as i32).abs() <= 3, "the overlap shows magenta alone: {ko:?} vs {magenta_only:?}");+ }+ }++ #[test]+ fn black_overprints_only_with_the_preference() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ for (sw, r) in+ [("C=100 M=0 Y=0 K=0", Rect::new(100.0, 100.0, 200.0, 200.0)), (designcraft_color::swatch::BLACK, Rect::new(150.0, 100.0, 250.0, 200.0))]+ {+ let id = designcraft_doc::ItemId(d.alloc());+ let mut it = Item::new(id, lid, designcraft_doc::Shape::Rectangle, designcraft_geom::shapes::rectangle(r));+ it.fill = Fill::swatch(sw);+ d.insert_item(SpreadRef::Doc(0), it, None).unwrap();+ }+ let cache = Cache::new();+ let mut r = Renderer::new();+ r.threads = 0;+ let o = RenderOptions { overprint_preview: true, ..Default::default() };+ let on = r.render_page(&d, &cache, 0, 1.0, false, &o).unwrap().pixel(175, 150);+ let alone = r.render_page(&d, &cache, 0, 1.0, false, &o).unwrap().pixel(225, 150);+ d.settings.overprint_black = false;+ let off = r.render_page(&d, &cache, 0, 1.0, false, &o).unwrap().pixel(175, 150);+ assert_eq!(off, alone, "knocks out: black alone");+ assert_ne!(on, alone, "overprints: the cyan shows through");+ }++ #[test]+ fn appearance_of_black_on_screen() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let id = designcraft_doc::ItemId(d.alloc());+ let mut it = Item::new(id, lid, designcraft_doc::Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(100.0, 100.0, 200.0, 200.0)));+ it.fill = Fill::swatch(designcraft_color::swatch::BLACK);+ d.insert_item(SpreadRef::Doc(0), it, None).unwrap();+ let cache = Cache::new();+ let mut r = Renderer::new();+ r.threads = 0;+ let px = |rich: bool, r: &mut Renderer| {+ r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions { rich_black: rich, ..Default::default() }).unwrap().pixel(150, 150)+ };+ assert!(px(false, &mut r)[0] > 20, "accurate: a dark grey");+ assert_eq!(px(true, &mut r)[..3], [0, 0, 0]);+ }++ #[test]+ fn display_performance_fast_draws_grey_boxes() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ // A 4×4 red PNG placed at 100,100 (100×100 pt).+ let mut png = Vec::new();+ image::RgbaImage::from_pixel(4, 4, image::Rgba([255, 0, 0, 255])).write_to(&mut std::io::Cursor::new(&mut png), image::ImageFormat::Png).unwrap();+ let aid = designcraft_doc::AssetId(d.alloc());+ d.assets.insert(+ aid,+ Arc::new(designcraft_doc::Asset {+ id: aid,+ name: "red.png".into(),+ mime: "image/png".into(),+ data: Arc::new(png),+ pixels: Some((4, 4)),+ ..Default::default()+ }),+ );+ let id = designcraft_doc::ItemId(d.alloc());+ let mut it = Item::new(id, lid, designcraft_doc::Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(100.0, 100.0, 200.0, 200.0)));+ it.content = designcraft_doc::Content::Graphic(designcraft_doc::Graphic {+ layer_options: None,+ asset: aid,+ size: (100.0, 100.0),+ xf: Affine::translate((100.0, 100.0)),+ clip: None,+ auto_fit: Default::default(),+ fit_align: 4,+ crop: [0.0; 4],+ wrap: Default::default(),+ fill: Default::default(),+ });+ d.insert_item(SpreadRef::Doc(0), it, None).unwrap();+ let cache = Cache::new();+ let mut r = Renderer::new();+ r.threads = 0;+ let px = |q: DisplayQuality, r: &mut Renderer| {+ r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions { quality: q, ..Default::default() }).unwrap().pixel(150, 150)+ };+ assert_eq!(px(DisplayQuality::High, &mut r)[..3], [255, 0, 0]);+ assert_eq!(px(DisplayQuality::Typical, &mut r)[..3], [255, 0, 0]);+ assert_eq!(px(DisplayQuality::Fast, &mut r)[..3], [178, 178, 178]);+ }++ #[test]+ fn clipping_path_hides_the_image_outside_it() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let mut png = Vec::new();+ image::RgbaImage::from_pixel(4, 4, image::Rgba([255, 0, 0, 255])).write_to(&mut std::io::Cursor::new(&mut png), image::ImageFormat::Png).unwrap();+ let aid = designcraft_doc::AssetId(d.alloc());+ d.assets.insert(+ aid,+ Arc::new(designcraft_doc::Asset {+ page: 0,+ id: aid,+ name: "red.png".into(),+ mime: "image/png".into(),+ link: None,+ data: Arc::new(png),+ pixels: Some((4, 4)),+ ..Default::default()+ }),+ );+ // A 100 pt image at 100,100 clipped by a triangle with its apex at the top middle.+ let triangle = designcraft_geom::PathData::single(designcraft_geom::path::SubPath::polyline(+ &[designcraft_geom::Point::new(0.0, 100.0), designcraft_geom::Point::new(50.0, 0.0), designcraft_geom::Point::new(100.0, 100.0)],+ true,+ ));+ let mut clip = designcraft_doc::ClippingPath::new(designcraft_doc::ClippingKind::PhotoshopPath, triangle);+ let id = designcraft_doc::ItemId(d.alloc());+ let mut it = Item::new(id, lid, designcraft_doc::Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(100.0, 100.0, 200.0, 200.0)));+ it.content = designcraft_doc::Content::Graphic(designcraft_doc::Graphic {+ layer_options: None,+ asset: aid,+ size: (100.0, 100.0),+ xf: Affine::translate((100.0, 100.0)),+ auto_fit: Default::default(),+ fit_align: 4,+ crop: [0.0; 4],+ wrap: Default::default(),+ clip: Some(Arc::new(clip.clone())),+ fill: Default::default(),+ });+ d.insert_item(SpreadRef::Doc(0), it, None).unwrap();+ let cache = Cache::new();+ let mut r = Renderer::new();+ r.threads = 0;+ let page = r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap();+ assert_eq!(page.pixel(150, 170)[..3], [255, 0, 0], "inside the triangle");+ assert_eq!(page.pixel(110, 110)[..3], [255, 255, 255], "inside the frame, outside the triangle: paper");+ // Inverted: the corners show and the triangle is paper.+ clip.invert = true;+ if let Some(designcraft_doc::Content::Graphic(g)) = d.item_mut(id).map(|it| &mut it.content) {+ g.clip = Some(Arc::new(clip));+ }+ let cache = Cache::new();+ let page = r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap();+ assert_eq!(page.pixel(150, 170)[..3], [255, 255, 255]);+ assert_eq!(page.pixel(110, 110)[..3], [255, 0, 0]);+ }++ #[test]+ fn missing_fonts_are_highlighted_on_screen_only() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let (_, sid) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(36.0, 36.0, 336.0, 100.0), lid, "Missing font", ParaFormat::default()).unwrap();+ d.story_mut(sid).unwrap().format_chars(0..12, |f| f.over.font_family = Some("No Such Family".into()));+ let cache = Cache::new();+ let cs = cache.get(&d, sid, None);+ assert!(cs.styles.iter().any(|s| s.missing_font));+ let l = &cs.frames[0].lines[0];+ // A point inside the line box but between glyph strokes: the space after "Missing".+ let g = l.glyphs.iter().find(|g| g.byte == 7).unwrap();+ let (x, y) = ((g.x + g.adv / 2.0) as u32, (l.baseline - l.ascent * 0.5) as u32);+ let mut r = Renderer::new();+ r.threads = 0;+ let plain = r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap();+ let shown = r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions { highlight_missing_fonts: true, ..Default::default() }).unwrap();+ assert_eq!(plain.pixel(x, y)[1], 255, "no highlight in output");+ let p = shown.pixel(x, y);+ assert!(p[0] > 240 && p[1] < 200, "pink on screen: {p:?}");+ }++ #[test]+ fn table_edges_paint_gap_colour_between_dashes_and_stripes() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let (_, sid) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(36.0, 36.0, 336.0, 400.0), lid, "", ParaFormat::default()).unwrap();+ let mut t = designcraft_doc::Table::new(1, 1, 1, 0, 0, 200.0);+ t.rows[0].height = 60.0;+ t.rows[0].mode = designcraft_doc::RowHeightMode::Exactly;+ let gap = |kind| designcraft_doc::CellStroke { weight: 8.0, kind, gap_color: "C=100 M=0 Y=0 K=0".into(), ..Default::default() };+ let cell = t.cell_mut(0, 0).unwrap();+ cell.strokes[0] = gap(designcraft_doc::StrokeType::Dashed { pattern: vec![12.0, 6.0] });+ cell.strokes[2] = gap(designcraft_doc::StrokeType::ThickThin);+ cell.border_overrides = [true; 4];+ cell.stroke_defined = [true; 4];+ d.story_mut(sid).unwrap().insert_table(0, t);+ let cache = Cache::new();+ let rect = cache.get(&d, sid, None).frames[0].tables[0].cell(0, 0).unwrap().rect;+ let mut r = Renderer::new();+ r.threads = 0;+ let img = r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap();+ let ink = |p: [u8; 4]| p[0] < 80 && p[2] < 80;+ let cyan = |p: [u8; 4]| p[0] < 80 && p[2] > 150;+ let y = rect.y0.round() as u32;+ let (dash, space) = (img.pixel((rect.x0 + 6.0) as u32, y), img.pixel((rect.x0 + 15.0) as u32, y));+ assert!(ink(dash), "dash {dash:?}");+ assert!(cyan(space), "gap {space:?}");+ let column: Vec<_> = (rect.y1 as u32 - 5..=rect.y1 as u32 + 5).map(|y| img.pixel(rect.center().x as u32, y)).collect();+ assert!(column.iter().any(|p| ink(*p)) && column.iter().any(|p| cyan(*p)), "stripes and gap: {column:?}");+ }++ #[test]+ fn degenerate_dash_patterns_draw_solid_and_fill_types_close_table_corners() {+ let fine = designcraft_doc::StrokeType::Dashed { pattern: vec![1e-6, 1e-6] };+ // Expanding these would take ~10^8 dashes per edge.+ assert!(text::cell_stroke(&fine, 4.0, 200.0).dash_pattern.is_empty());+ assert!(text::cell_stroke(&designcraft_doc::StrokeType::Dotted, 1e-6, 200.0).dash_pattern.is_empty());+ assert!(!text::cell_stroke(&designcraft_doc::StrokeType::Dashed { pattern: vec![3.0, 2.0] }, 1.0, 200.0).dash_pattern.is_empty());+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let (fid, sid) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(36.0, 36.0, 336.0, 400.0), lid, "", ParaFormat::default()).unwrap();+ d.item_mut(fid).unwrap().stroke = designcraft_doc::Stroke { weight: 2.0, kind: fine.clone(), ..Default::default() };+ let mut t = designcraft_doc::Table::new(1, 2, 2, 0, 0, 200.0);+ for r in 0..2 {+ t.rows[r].height = 60.0;+ t.rows[r].mode = designcraft_doc::RowHeightMode::Exactly;+ }+ let stroke = |kind| designcraft_doc::CellStroke { weight: 8.0, kind, gap_color: "C=100 M=0 Y=0 K=0".into(), ..Default::default() };+ for cell in &mut t.cells {+ cell.strokes = std::array::from_fn(|_| stroke(designcraft_doc::StrokeType::ThickThin));+ cell.border_overrides = [true; 4];+ cell.stroke_defined = [true; 4];+ }+ if let Some(cell) = t.cell_mut(1, 0) {+ cell.strokes[2] = stroke(fine);+ }+ d.story_mut(sid).unwrap().insert_table(0, t);+ let cache = Cache::new();+ let frag = cache.get(&d, sid, None).frames[0].tables[0].clone();+ let (top, bottom) = (frag.cell(0, 0).unwrap().rect, frag.cell(1, 0).unwrap().rect);+ let mut r = Renderer::new();+ r.threads = 0;+ let img = r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap();+ let ink = |p: [u8; 4]| p[0] < 80;+ let solid: Vec<_> = (2..10).map(|i| img.pixel((bottom.x0 + 20.0 + i as f64 * 0.5) as u32, bottom.y1.round() as u32)).collect();+ assert!(solid.iter().all(|p| ink(*p)), "the degenerate dashed edge draws solid: {solid:?}");+ // Outside the table's top-left corner, inside both edges' reach.+ let corner = img.pixel((top.x0 - 3.0) as u32, (top.y0 - 3.0) as u32);+ assert!(ink(corner), "corner closed: {corner:?}");+ let edge = frag.strokes.iter().find(|s| s.a == designcraft_geom::Point::new(top.x0, top.y0) && s.a.y == s.b.y).unwrap();+ let (a, b) = frag.corner_capped(edge);+ assert_eq!((a, b), (designcraft_geom::Point::new(top.x0 - 4.0, top.y0), edge.b), "only table corners extend");+ }++ #[test]+ fn table_gradient_fill_is_continuous_across_cells() {+ let mut d = Document::new(&NewDocument::default());+ let mut gradient = designcraft_color::Gradient::default();+ gradient.stops[0].color = designcraft_color::Color::rgb(1.0, 0.0, 0.0);+ gradient.stops[1].color = designcraft_color::Color::rgb(0.0, 0.0, 1.0);+ d.swatches.push(designcraft_color::Swatch {+ name: "Table gradient".into(),+ value: designcraft_color::SwatchValue::Gradient { gradient },+ locked: false,+ named: true,+ hidden: false,+ });+ let (_, sid) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(36.0, 36.0, 336.0, 300.0), d.default_layer(), "", ParaFormat::default()).unwrap();+ let mut t = designcraft_doc::Table::new(1, 1, 2, 0, 0, 200.0);+ t.rows[0].height = 40.0;+ t.rows[0].mode = designcraft_doc::RowHeightMode::Exactly;+ for cell in &mut t.cells {+ cell.fill = "Table gradient".into();+ }+ d.story_mut(sid).unwrap().insert_table(0, t);+ let cache = Cache::new();+ let rect = cache.get(&d, sid, None).frames[0].tables[0].rect;+ let mut renderer = Renderer::new();+ renderer.threads = 0;+ let img = renderer.render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap();+ let y = rect.center().y as u32;+ let a = img.pixel((rect.x0 + 20.0) as u32, y);+ let b = img.pixel((rect.x1 - 20.0) as u32, y);+ assert!(i16::from(a[0]) - i16::from(a[2]) > 80, "red end: {a:?}");+ assert!(i16::from(b[2]) - i16::from(b[0]) > 80, "blue end: {b:?}");+ let left = img.pixel((rect.center().x - 2.0) as u32, y);+ let right = img.pixel((rect.center().x + 2.0) as u32, y);+ assert!((i16::from(left[0]) - i16::from(right[0])).abs() < 20, "no gradient restart between cells");+ }++ #[test]+ fn renders_tables() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let (_, sid) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(36.0, 36.0, 336.0, 400.0), lid, "", ParaFormat::default()).unwrap();+ let mut t = designcraft_doc::Table::new(5, 3, 3, 1, 0, 300.0);+ for c in 0..3 {+ let cell = t.cell_mut(0, c).unwrap();+ cell.fill = "C=100 M=0 Y=0 K=0".into();+ cell.text.insert(0, "Head");+ t.cell_mut(2, c).unwrap().text.insert(0, "WWWWWWWW");+ }+ d.story_mut(sid).unwrap().insert_table(0, t);+ let cache = Cache::new();+ let cs = cache.get(&d, sid, None);+ let tf = &cs.frames[0].tables[0];+ let head = tf.cell(0, 1).unwrap().rect;+ let body = tf.cell(2, 0).unwrap().rect;+ let mut r = Renderer::new();+ r.threads = 0;+ let img = r.render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap();+ // Header fill (cyan) near the right edge of the middle header cell.+ let c = img.pixel((head.x1 - 3.0) as u32, (head.y0 + 3.0) as u32);+ assert!(c[0] < 80 && c[2] > 150, "{c:?}");+ // The table border (black) on the left edge.+ let e = img.pixel(body.x0.round() as u32, body.center().y as u32);+ assert!(e[0] < 200, "{e:?}");+ // Cell text drew dark pixels inside the body cell.+ let dark = ((body.x0 + 5.0) as u32..(body.x1 - 2.0) as u32)+ .flat_map(|x| ((body.y0 + 2.0) as u32..(body.y1 - 2.0) as u32).map(move |y| (x, y)))+ .filter(|&(x, y)| img.pixel(x, y)[0] < 100)+ .count();+ assert!(dark > 30, "cell text pixels: {dark}");+ }++ /// A one-page PDF (612 x 792 pt) that draws `content`.+ fn one_page_pdf(content: &str) -> Vec<u8> {+ let objects = [+ "<< /Type /Catalog /Pages 2 0 R >>".to_string(),+ "<< /Type /Pages /Kids [3 0 R] /Count 1 >>".to_string(),+ "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R >>".to_string(),+ format!("<< /Length {} >>\nstream\n{content}\nendstream", content.len()),+ ];+ let mut out = b"%PDF-1.4\n".to_vec();+ let mut offsets = Vec::new();+ for (i, o) in objects.iter().enumerate() {+ offsets.push(out.len());+ out.extend(format!("{} 0 obj\n{o}\nendobj\n", i + 1).bytes());+ }+ let xref = out.len();+ out.extend(format!("xref\n0 {}\n0000000000 65535 f \n", objects.len() + 1).bytes());+ for o in offsets {+ out.extend(format!("{o:010} 00000 n \n").bytes());+ }+ out.extend(format!("trailer\n<< /Size {} /Root 1 0 R >>\nstartxref\n{xref}\n%%EOF\n", objects.len() + 1).bytes());+ out+ }++ /// A Bounding Box crop is the exact extent of what the page draws, strokes included, found+ /// without rasterizing the page: PDF export of a document that places a complex illustration+ /// cropped that way spent seconds rendering it just to measure it.+ #[test]+ fn content_crop_box_is_measured_without_rendering_the_page() {+ // A filled rectangle 100..300 x 532..592 (PDF y up) and a 10 pt horizontal line at+ // y 100 from x 400 to 500, butt capped. Clipped away: a rectangle off to the left.+ let pdf = one_page_pdf("0 0 0 rg 100 532 200 60 re f 10 w 400 100 m 500 100 l S q 0 0 50 50 re W n 100 0 10 10 re f Q");+ let before = PDF_RENDERS.with(std::cell::Cell::get);+ let (frac, size) = pdf_crop_box(&pdf, 0, designcraft_doc::PdfCrop::ContentVisible).unwrap();+ assert_eq!(PDF_RENDERS.with(std::cell::Cell::get), before, "the page was rasterized");+ let want = [100.0 / 612.0, 200.0 / 792.0, 500.0 / 612.0, 697.0 / 792.0];+ assert!(frac.iter().zip(want).all(|(a, b)| (a - b).abs() < 1e-6), "{frac:?} vs {want:?}");+ assert!((size.0 - 400.0).abs() < 1e-3 && (size.1 - 497.0).abs() < 1e-3, "{size:?}");+ }++++/// An inline object is painted under its frame's text, as InDesign draws it: a picture++/// whose frame reaches down into the next line (a negative Y offset) doesn't hide that line.++#[test]++fn inline_objects_are_painted_under_the_text() {++ use designcraft_doc::{AnchorPosition, AnchoredObject, ItemId, Shape, SpreadRef};++ let mut d = Document::new(&NewDocument::default());++ let (fid, sid) =++ d.add_text_frame(SpreadRef::Doc(0), Rect::new(20.0, 20.0, 300.0, 300.0), d.default_layer(), "A\nWWWW", ParaFormat::default()).unwrap();++ let mut item =++ Item::new(ItemId(d.alloc()), d.default_layer(), Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(0.0, 0.0, 250.0, 60.0)));++ item.fill = Fill::swatch(designcraft_color::swatch::PAPER);++ d.story_mut(sid).unwrap().insert_object(1, AnchoredObject::new(item, AnchorPosition::Inline { y_offset: -40.0 }));++ let cache = Cache::new();++ let cs = cache.get(&d, sid, None);++ let (ft, obj) = (&cs.frames[0], &cs.frames[0].objects[0]);++ let l = ft.lines.iter().find(|l| l.range.start > 1).unwrap();++ // The second line lies inside the white box.++ assert!(obj.origin.y + obj.size.1 > l.baseline && obj.origin.y < l.baseline - l.ascent, "{:?} {}", obj.origin, l.baseline);++ let m = d.text_xf(d.item(fid).unwrap());++ let image = Renderer::new().render_page(&d, &cache, 0, 1.0, false, &RenderOptions::default()).unwrap();++ let (a, b) = (m * designcraft_geom::Point::new(l.x0, l.baseline - l.ascent), m * designcraft_geom::Point::new(l.end_x, l.baseline));++ let dark =++ (a.y as u32..b.y as u32).flat_map(|y| (a.x as u32..b.x as u32).map(move |x| (x, y))).filter(|&(x, y)| image.pixel(x, y)[0] < 100).count();++ assert!(dark > 20, "the line's glyphs show over the box: {dark} dark pixels");++}diff --cc crates/render/src/text.rsindex a40e666ab,3797f508e..d10fd30f9--- a/crates/render/src/text.rs+++ b/crates/render/src/text.rs@@@ -267,119 -387,7 +387,12 @@@ impl Rendererif !ft.tables.is_empty() {self.draw_tables(ctx, f, ft, xf);}+ // Anchored objects ride on their lines, under the frame's text (as InDesign draws them):+ // a picture whose frame reaches into the next line doesn't hide that line.+ for o in &ft.objects {+ self.draw_item(ctx, f, &o.object.item, xf * Affine::translate(o.origin.to_vec2()), ShownOn::Own);+ }- // Text in fonts that aren't installed: pink behind the glyphs (screen only).- if f.opts.highlight_missing_fonts && cs.styles.iter().any(|s| s.missing_font) {- ctx.set_transform(m);- ctx.set_paint(screen_color([255, 166, 214], 255));- for l in &ft.lines {- for g in l.glyphs.iter().filter(|g| g.adv > 0.0 && cs.styles.get(g.style as usize).is_some_and(|s| s.missing_font)) {- ctx.fill_rect(&kurbo::Rect::new(g.x, l.baseline - l.ascent, g.x + g.adv, l.baseline + l.descent));- }- }- }- if f.opts.highlight_keeps && ft.lines.iter().any(|l| l.keep_violation) {- ctx.set_transform(m);- ctx.set_paint(screen_color([255, 236, 120], 255));- for l in ft.lines.iter().filter(|l| l.keep_violation) {- ctx.fill_rect(&kurbo::Rect::new(l.x0, l.baseline - l.ascent, l.x1, l.baseline + l.descent));- }- }- if f.opts.highlight_hj && ft.lines.iter().any(|l| l.hj > 0) {- ctx.set_transform(m);- for l in ft.lines.iter().filter(|l| l.hj > 0) {- let shade = [0u8, 0xF6, 0xEA, 0xD8][l.hj.min(3) as usize];- ctx.set_paint(screen_color([255, shade, [0u8, 0xB0, 0x70, 0x30][l.hj.min(3) as usize]], 255));- ctx.fill_rect(&kurbo::Rect::new(l.x0, l.baseline - l.ascent, l.end_x.max(l.x0 + 1.0), l.baseline + l.descent));- }- }- if f.opts.highlight_custom_tracking && cs.styles.iter().any(|s| s.custom_tracking) {- ctx.set_transform(m);- ctx.set_paint(screen_color([176, 236, 176], 255));- for l in &ft.lines {- for g in l.glyphs.iter().filter(|g| g.adv > 0.0 && cs.styles.get(g.style as usize).is_some_and(|s| s.custom_tracking)) {- ctx.fill_rect(&kurbo::Rect::new(g.x, l.baseline - l.ascent, g.x + g.adv, l.baseline + l.descent));- }- }- }- if f.opts.tag_markers && cs.styles.iter().any(|s| s.xml_tag.is_some()) {- ctx.set_transform(m);- let px = 1.0 / m.determinant().abs().sqrt().max(1e-9);- for l in &ft.lines {- let tag_of = |g: &designcraft_compose::PlacedGlyph| cs.styles.get(g.style as usize).and_then(|s| s.xml_tag.clone());- let gs: Vec<_> = l.glyphs.iter().filter(|g| g.len > 0).collect();- let mut i = 0;- while i < gs.len() {- let Some(tag) = tag_of(gs[i]) else {- i += 1;- continue;- };- let mut j = i + 1;- while j < gs.len() && tag_of(gs[j]).as_deref() == Some(tag.as_str()) {- j += 1;- }- let c = f.doc.xml.tags.iter().find(|t| t.name == tag).map_or([100, 100, 220], |t| t.color);- ctx.set_paint(screen_color([c[0], c[1], c[2]], 255));- let (x0, x1) = (gs[i].x, gs[j - 1].x + gs[j - 1].adv);- let (top, bot) = (l.baseline - l.ascent, l.baseline + l.descent);- let (w, t) = (2.5 * px, px.max(0.3));- // [ before the element, ] after it.- for (x, dir) in [(x0, 1.0), (x1, -1.0)] {- ctx.fill_rect(&kurbo::Rect::new(x - t / 2.0, top, x + t / 2.0, bot));- for y in [top, bot - t] {- let (a, b) = if dir > 0.0 { (x, x + w) } else { (x - w, x) };- ctx.fill_rect(&kurbo::Rect::new(a, y, b, y + t));- }- }- i = j;- }- }- }- if f.opts.change_markup && cs.styles.iter().any(|s| s.inserted) {- ctx.set_transform(m);- for l in &ft.lines {- for g in l.glyphs.iter().filter(|g| g.adv > 0.0 && cs.styles.get(g.style as usize).is_some_and(|s| s.inserted)) {- ctx.set_paint(screen_color([120, 190, 255], 110));- ctx.fill_rect(&kurbo::Rect::new(g.x, l.baseline - l.ascent, g.x + g.adv, l.baseline + l.descent));- }- }- }- if f.opts.note_indicators- && let Some(st) = f.doc.story(cs.story).filter(|st| !st.editorial.is_empty())- {- // A small flag at each note anchor, in the notes' amber.- ctx.set_transform(m);- ctx.set_paint(screen_color([232, 160, 32], 255));- for l in &ft.lines {- for g in l.glyphs.iter().filter(|g| st.text.get(g.byte..).is_some_and(|t| t.starts_with(designcraft_doc::NOTE_MARK))) {- let h = l.ascent.max(4.0);- let mut p = BezPath::new();- p.move_to((g.x - h * 0.25, l.baseline - h));- p.line_to((g.x + h * 0.25, l.baseline - h));- p.line_to((g.x, l.baseline - h * 0.55));- p.close_path();- ctx.fill_path(&p);- ctx.fill_rect(&kurbo::Rect::new(g.x - h * 0.03, l.baseline - h * 0.6, g.x + h * 0.03, l.baseline + l.descent * 0.5));- }- }- }- if f.opts.condition_indicators && !f.doc.conditions.is_empty() && cs.styles.iter().any(|s| s.condition.is_some()) {- ctx.set_transform(m);- let px = 1.0 / m.determinant().abs().sqrt().max(1e-9);- for l in &ft.lines {- for g in l.glyphs.iter().filter(|g| g.visible && g.adv > 0.0) {- let Some(name) = cs.styles.get(g.style as usize).and_then(|s| s.condition.as_deref()) else { continue };- let Some(c) = f.doc.conditions.iter().find(|c| c.name == name) else { continue };- ctx.set_paint(screen_color([c.color[0], c.color[1], c.color[2]], 255));- let y = l.baseline + l.descent * 0.6;- ctx.fill_rect(&kurbo::Rect::new(g.x, y, g.x + g.adv, y + 2.0 * px));- }- }- }+ draw_text_indicators(ctx, f, cs, ft, m);let scale = m.determinant().abs().sqrt();let greek_px = f.opts.greek_below_px;let mut greek = BezPath::new();