.cdr import: an outline of width 0 opens as a hairline

A drawn outline of width 0 became a stroke of width 0, which the
renderer does not draw. It now becomes a 0.25 pt stroke, the width PDF
import gives a line width of 0.
This commit is contained in:
dotCooCoo committed 2026-11-12 13:54:24 -08:00
1 parent e71ab08233
commit 8fbb5aae5c
4 files changed
+38 -4

No files matched your search

+5 -1
View File
@@ -15,6 +15,9 @@ use vectorcraft_doc::{Document, Guide, LiveShape, Node, NodeKind};
/// The most nested groups mapped; the reader holds nesting well below it.
const MAX_DEPTH: usize = 256;
/// The width, in points, of a stroke made from an outline of width 0: the width PDF import gives a
/// line width of 0 (`crates/pdf/src/import/state.rs`).
const HAIRLINE: f64 = 0.25;
pub(super) struct Builder {
pub(super) doc: Document,
@@ -187,7 +190,8 @@ impl Builder {
}
fn stroke(&mut self, o: &cd::Outline) -> StrokeLayer {
let width = if o.width.is_finite() { o.width.clamp(0.0, 1000.0) } else { 0.0 };
// A drawn outline of width 0 shows as a hairline, as a PDF line width of 0 does.
let width = if o.width.is_finite() && o.width > 0.0 { o.width.min(1000.0) } else { HAIRLINE };
let mut l = StrokeLayer::new(self.paint(&o.color), width);
l.cap = match o.cap {
cd::Cap::Butt => LineCap::Butt,
+30
View File
@@ -411,6 +411,36 @@ fn fills_and_outlines_keep_their_colors_widths_caps_joins_and_dashes() {
assert!(dash.pattern.len() == 2 && (dash.pattern[0] - 6.0).abs() < 0.01 && (dash.pattern[1] - 2.0).abs() < 0.01, "{:?}", dash.pattern);
}
/// An outline of width 0 opens as a hairline stroke, which draws; a thin outline keeps its width.
#[test]
fn outlines_of_width_0_open_as_hairlines() {
use vectorcraft_doc::appearance::AppearanceItem;
let v = V(1100);
let black = synth::color(2, [0, 0, 0, 100]);
let doc = list(
b"doc ",
vec![list(
b"otlt",
vec![
chunk(b"outl", v.outline(2, synth::Pen { line_type: 2, width: 0.0, cap: 0, join: 0 }, &black, &[])),
chunk(b"outl", v.outline(3, synth::Pen { line_type: 2, width: 0.1, cap: 0, join: 0 }, &black, &[])),
],
)],
);
let rect = |outline: u32| synth::object(v, 1, &[(10, outline.to_le_bytes().to_vec()), (30, v.rect(10.0, 10.0, 0.0))], None);
let page = synth::page(false, vec![synth::layer(v, [0, 0, 0, 0x98], "L", vec![rect(2), rect(3)])]);
let (doc, _) = super::cdr::import(&synth::riff(1100, &[chunk(b"vrsn", 1100u16.to_le_bytes().to_vec()), doc, page])).unwrap();
let widths: Vec<f64> = paths(&doc)
.iter()
.map(|n| match n.appearance.items.as_slice() {
[AppearanceItem::Stroke(s)] => s.width,
other => panic!("{other:?}"),
})
.collect();
// Bottom to top: the file lists the 0.1 pt outline last.
assert!(widths.len() == 2 && (widths[0] - 0.1).abs() < 0.01 && (widths[1] - 0.25).abs() < 1e-9, "{widths:?}");
}
/// An outline behind the fill becomes a stroke painted before the fill.
#[test]
fn outlines_behind_the_fill_paint_first() {
+2 -2
View File
@@ -6845,8 +6845,8 @@ by side. Layers of the same name on different pages become one layer when the pa
the master page's guidelines become guides on every page. Groups stay groups, and a PowerClip becomes a clipping
group whose clipping path keeps the container's fill and outline. Curves, paths, arcs and polygons (stars
included) become paths, and rectangles and ellipses become live shapes; a rectangle keeps each corner's radius. Uniform
fills and outlines keep their colors, widths, caps, joins and dashes, an outline behind the fill becomes a stroke below
the fill, and an object without a fill or outline of its own
fills and outlines keep their colors, widths, caps, joins and dashes (an outline of width 0 becomes a 0.25 pt stroke),
an outline behind the fill becomes a stroke below the fill, and an object without a fill or outline of its own
takes its style's. A library color that the drawing stores with its
name and values (version 13 and later) becomes a spot swatch with its tint, and one stored only by its number opens as
a black spot color. Text, bitmaps, blends, contours, brush strokes, other objects the reader doesn't read yet,
+1 -1
View File
@@ -1542,7 +1542,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- DXF export's Include Placed Images and Include Fill Hatches (`includeImages`, `includeHatches`; VectorCraft's own options, on by default and off in CNC / CAM) leave out placed images with their linked files, without decoding them, and the solid hatch after each filled area's outlines, each on its own, with one note in `warnings` when something was left out; R12 keeps its own notes. An open path's fill outline is closed, as the fill is, in every version (`an_open_path_s_fill_outline_keeps_its_closing_edge`, `fills_without_hatches_keep_their_outlines`, `images_can_be_left_out_with_their_files`, `images_and_hatches_are_left_out_independently_and_the_cnc_preset_leaves_out_both`, `placed_images_and_fill_hatches_can_be_left_out`, `include_placed_images_and_fill_hatches_follow_the_preset_and_a_change_shows_custom`).
- DXF export writes a path of straight segments and circular arcs (a slot, a D shape, a rounded rectangle, a pie) as one polyline whose vertices carry a bulge (group 42) for each arc: an LWPOLYLINE in R14 and later, a POLYLINE with VERTEX entities in R12 and R13, closed when the path is closed, and it reads back as the same outline (#1299, `crates/cad/src/tests.rs`). Such a path was written as one SPLINE (a flattened polyline in R12); a path with any other curve still is. A shallow curve becomes an ARC or a bulge only when it lies on the circle within 5e-4 of its own extent as well as of the radius, and the drawing extents (`$EXTMIN`, `$EXTMAX`) reach the furthest points of every ARC and bulge.
- Affinity documents in (AF.1–AF.4): `.af` (Affinity 3) and `.afdesign`/`.afphoto`/`.afpub` (Affinity 1 and 2, container versions 8–12) open and place as editable art: layers and sublayers, groups (pass-through or isolated), artboards (with their names and backgrounds) and Publisher pages side by side, curves with live corners, parametric shapes (rectangles with corner radii, ellipses, polygons, stars, pies, triangles, trapezoids), compound shapes, solid/linear/elliptical gradient fills and strokes (weight, dashes, alignment, scale-with-object), clipping by nesting, vector and pixel masks, artistic and frame text with fonts, sizes, tracking, leading and alignment, placed images (their original JPEG/PNG) and pixel layers (8/16-bit RGB, CMYK), opacity, visibility, locking and blend modes, at the document's resolution in points. Effects, adjustments, brushes and pressure profiles, transparency gradients, master pages, symbol instances (imported as their cached picture), special shapes (cloud, heart, cog…, imported as ellipses) and Affinity-only blend modes are named in the import warning. A file whose native data can't be read opens as its embedded preview with the reason, and that preview can't be placed. Save never writes back over the Affinity file and there is no Affinity export. AF.5 (from DesignCraft's import, storytold/designcraft#291) adds master pages (on a locked layer behind the pages that show them), tables (area type per cell and a line per edge), each paragraph's alignment, indents, spacing and leading, horizontal text scale, outlined text, frame text sized by its text scale, drop shadows and outer glows as live effects (inner shadows as inner glows), outline effects as strokes, colour and gradient overlays baked into the paint, embedded Affinity documents as editable content (their artboards don't become artboards), pixel layers over 64 MP at a reduced resolution and HEIC photos from their stored pixels; automatic leading (size plus the font's line gap) fitted on thumbnails; underlines and strikethrough; strokes whose style is None (every shape stores one) left out, which also brings 6 public files closer to their thumbnails; line breaks inside a paragraph; table cell text centred as Affinity centres it, also where it is taller than its cell; CMYK pixel layers converted through the document's embedded CMYK profile (relative colorimetric with black-point compensation, as each layer's colour settings name), or kept as CMYK images when there is none; outline effects on stroked shapes around their stroke; artistic text whose paragraphs align differently aligned within its longest line, a frame's first baseline at cap height, and frames whose last lines' descenders hang out made tall enough to show them (all measured on a local document's own PDF export: baselines match to 0.1 pt); a local 56-artboard document's mean thumbnail difference went from 16.2 to 11.4, and its pages' mean difference from the owner's PDF export from 12.9 to 9.3. AF.4 adds Affinity 3 artboard recognition and actual-outline clipping, source-backed JPEG/PNG raster tiles, Unicode text-run recovery, stored fallback/exact installed fonts, OpenType feature flags and compound-geometry limits. 51 public CC0/MIT/Apache-2.0 files (33 current `.af`), pinned and sha256-verified (`cargo xtask corpus --affinity`), test native retention and every-board native/SVG/PDF/PSD output for current files; selected files compare their saved thumbnails. No Affinity reopen or independent paired PSD oracle was available; [source audit and complex-font gaps](affinity-validation.md); [scope, provenance and limits](../crates/affinity/README.md).
- `.cdr` drawings of versions 1 to 27 open and place, and `.cdt` templates open as new untitled documents. `vectorcraft-cdr` reads the `WL` files of versions 1 and 2 (one page and one layer of rectangles, whole ellipses and curves with uniform fills and outlines), the RIFF chunk tree of versions 3 on and its compressed lists, and the ZIP packages of versions 14 on with the data streams of versions 16 on, and the importer maps pages to artboards side by side, layers by name, the master page's guidelines to guides on every page, groups, PowerClips (as clipping groups), curves and paths, rectangles (live, with each corner's radius), ellipses (live), arcs and polygons, uniform fills in CMYK, CMY, RGB, gray and registration, and outlines with their width, caps, joins and dashes (behind the fill where the file says so), an object without a fill or outline of its own taking its style's. A library color stored with its name and values (version 13 and later) becomes a spot swatch with its tint; one stored only by its number opens as a black spot color named by its palette and number, with a warning. Text, bitmaps, blends, contours, brush strokes, fountain, pattern, texture and PostScript fills, arrowheads, lenses, object transparency and the envelopes of version 3 are left out with a warning, and encrypted, ZIP64 and split packages are refused with a message. Every record layout has a source in `crates/cdr/PROVENANCE.md`. Reading is bounded by limits on input size, inflated size, package members, nesting, chunks, objects, coordinates and dashes, where an outline's dashes count for every shape that uses it (`crates/cdr/tests/read.rs`, `crates/engine/src/cmd/fileio/tests_cdr.rs`, `crates/engine/tests/import_fuzz.rs`).
- `.cdr` drawings of versions 1 to 27 open and place, and `.cdt` templates open as new untitled documents. `vectorcraft-cdr` reads the `WL` files of versions 1 and 2 (one page and one layer of rectangles, whole ellipses and curves with uniform fills and outlines), the RIFF chunk tree of versions 3 on and its compressed lists, and the ZIP packages of versions 14 on with the data streams of versions 16 on, and the importer maps pages to artboards side by side, layers by name, the master page's guidelines to guides on every page, groups, PowerClips (as clipping groups), curves and paths, rectangles (live, with each corner's radius), ellipses (live), arcs and polygons, uniform fills in CMYK, CMY, RGB, gray and registration, and outlines with their width (0.25 pt for a width of 0), caps, joins and dashes (behind the fill where the file says so), an object without a fill or outline of its own taking its style's. A library color stored with its name and values (version 13 and later) becomes a spot swatch with its tint; one stored only by its number opens as a black spot color named by its palette and number, with a warning. Text, bitmaps, blends, contours, brush strokes, fountain, pattern, texture and PostScript fills, arrowheads, lenses, object transparency and the envelopes of version 3 are left out with a warning, and encrypted, ZIP64 and split packages are refused with a message. Every record layout has a source in `crates/cdr/PROVENANCE.md`. Reading is bounded by limits on input size, inflated size, package members, nesting, chunks, objects, coordinates and dashes, where an outline's dashes count for every shape that uses it (`crates/cdr/tests/read.rs`, `crates/engine/src/cmd/fileio/tests_cdr.rs`, `crates/engine/tests/import_fuzz.rs`).
- Placed documents: File › Place of a `.vectorcraft` file links to it by default (`file.place`'s `link`): one locked object showing an artboard of the document (or its art's bounds), read the way placing it without Link reads it, its symbols, patterns and images kept apart from the document's; without Link (or from bytes, not a file) it is an editable copy as before. It stays vectors in every output (SVG, PDF, EPS, EMF, DXF), and so do placed documents inside it, read from their own files up to 8 levels deep (documents that place each other stop there). On screen they draw from bitmaps cached per file and zoom step, shared by every copy and made in the background (a placeholder until ready), so a sheet of them redraws in about a millisecond; exports and prints draw them exactly. Like linked images, a save keeps only a preview of each (JPEG when opaque) unless Include Linked Files; output, and zooming past the preview, read the file again, falling back to the preview with a warning when it is gone or changed. Saves for older versions write them as plain art. Links check, update, relink, Update Links on open, Link Info (the artboard's size), Placement Options, Break Link (also Embed, Object › Expand: the editable copy placing without Link gives, its resources joining the document), Edit Original (the document in a new tab) and the Links panel cover them; saving a document updates the open documents that place it. The native format (v4) keeps data of 8 KB or more after the JSON instead of base64 in it.
- Placed documents' bitmaps on screen: when a bitmap made in the background is ready, the desktop app renders the canvas again only where the objects that show its file are, when the frame shown was rendered on the UI thread and that part is at most half the canvas. Bitmaps drawn or made since a frame began are kept for that frame past the 512 MiB budget, up to 2 GiB, so a view showing more than the budget does not make them again in every frame. A bitmap that would take them past 2 GiB is not kept, and its file draws exactly at that zoom. A bitmap that can't be made (the file can't be read and there is no preview) shows the light placeholder and is not asked for again. Each ready bitmap used to render the whole canvas again, and bitmaps past the budget and bitmaps that could not be made were asked for again in every frame (`crates/render/src/tests/placed_document.rs`).
- Linked PDF and `.ai` pages: File › Place with Link (the default) places a page of a PDF, `.ai` or `.ait` file read as PDF pages as a placed document, as it links an image, the page and its box (`crop`) kept with the link: Links check, update and relink it, Break Link and Object › Expand give the group placing it without Link gives, every output draws the page's vectors, and Package copies the file. Without Link, or with a password or `textAs: "outlines"`, the page is embedded. EPS and PostScript `.ai` files are still embedded (`crates/engine/src/tests/placed_document.rs`).