diff --git a/crates/cdr/PROVENANCE.md b/crates/cdr/PROVENANCE.md index 7c79cd3c8c..73642424cd 100644 --- a/crates/cdr/PROVENANCE.md +++ b/crates/cdr/PROVENANCE.md @@ -97,3 +97,4 @@ file is committed. | R47 | Argument 8000 marks an object seen through: a lens or a transparency. The reader does not apply it, and names lenses in the warnings | K L859 (the argument); S: of the sample files of versions 7 to 25, the argument is on the see-through objects that the pictures of LT `square_blackfill_nooutline_transparency50percent` of `testset/12` to `testset/25`, TDF 80103 and eight UC lens test files of versions 7 to 13 show, and otherwise only on text in UC `fancytext_cdr7.cdr` to `fancytext_x3.cdr` and on two objects of TDF 114901. The value K reads at byte 10 (14 from version 13) is not the transparency in these samples | public-spec (the argument: K; what it marks: sample; its layout: unconfirmed, and it is not read) | | R48 | Bit 2 (0x04) of the outline's line type marks the outline dashed; the dashes of an outline without it are not drawn | S: every outline of versions 6 to 25 in the sample files with that bit set (316 of them, in 29 files) stores dashes; TDF 76771 (version 15) stores dashes 2 and 1 in an outline of line type 0x22, and the file's picture draws that outline solid | sample | | R49 | Bit 4 (0x10) of the outline's line type puts the outline behind the fill | S: UC `outl_behind_fill_cdr7.cdr` to `outl_behind_fill_x3.cdr`, whose outline of line type 0x12 the file's picture shows behind the fill, and whose other outlines (0x02) it shows over the fill | sample | +| R50 | Bit 5 (0x20) of the outline's line type scales the outline's width and dashes with the shape's matrix. The engine multiplies them by the square root of the matrix's area factor (VectorCraft's own value for a matrix that scales x and y differently) | S: UC `outl_scale_with_cdr7.cdr` to `outl_scale_with_cdr12.cdr`, of whose outlines only one, 3.969 mm wide, has line type 0x22 and the others 0x02 or 0x01; TDF 76771 (version 15), whose outline of line type 0x22 is 10 mm wide on a shape that the matrix stretches and skews, and whose picture draws that outline several times wider and skewed | sample (the bit; the single width for a matrix that scales x and y differently: VectorCraft's own) | diff --git a/crates/cdr/src/inline.rs b/crates/cdr/src/inline.rs index dc44ae0b23..3d5214f136 100644 --- a/crates/cdr/src/inline.rs +++ b/crates/cdr/src/inline.rs @@ -79,7 +79,7 @@ pub(crate) fn outline(b: &[u8], p: &Profile, warn: &mut Vec) -> Option< let _stretch = r.u16()?; let _nib = angle(&mut r, p)?; let color = records::color(&mut r, p, warn)?; - let mut out = Outline { width, color, cap: Cap::Butt, join: Join::Miter, dashes: Vec::new(), behind_fill: false }; + let mut out = Outline { width, color, cap: Cap::Butt, join: Join::Miter, dashes: Vec::new(), behind_fill: false, scale_with: false }; let Some(stored) = r.skip(7).and_then(|()| r.u8()).map(usize::from) else { return Some(Some(out)) }; let Some(area) = r.bytes(DASH_AREA) else { return Some(Some(out)) }; if stored > DASH_AREA { diff --git a/crates/cdr/src/model.rs b/crates/cdr/src/model.rs index cd3946ab7d..6e48fef497 100644 --- a/crates/cdr/src/model.rs +++ b/crates/cdr/src/model.rs @@ -107,6 +107,9 @@ pub struct Outline { pub dashes: Vec, /// Drawn behind the fill, so that a filled shape shows only the outer half of it. pub behind_fill: bool, + /// Scaled with the shape: the shape's matrix scales the width and dashes as it scales the + /// geometry. + pub scale_with: bool, } #[derive(Clone, Debug, PartialEq)] diff --git a/crates/cdr/src/records.rs b/crates/cdr/src/records.rs index dac441940f..0680583453 100644 --- a/crates/cdr/src/records.rs +++ b/crates/cdr/src/records.rs @@ -360,7 +360,9 @@ pub(crate) fn outline(b: &[u8], p: &Profile, warn: &mut Vec) -> Option< let dashes = if line_type & 4 != 0 && dashes.iter().any(|d| *d > 0.0) { dashes } else { Vec::new() }; // Bit 4 of the line type: behind the fill (R49). let behind_fill = line_type & 0x10 != 0; - Some((id, Some(Outline { width, color, cap, join, dashes, behind_fill }))) + // Bit 5 of the line type: scaled with the shape (R50). + let scale_with = line_type & 0x20 != 0; + Some((id, Some(Outline { width, color, cap, join, dashes, behind_fill, scale_with }))) } /// A name argument (R9): Windows-1252 up to a NUL before version 12, UTF-16LE from it. A name diff --git a/crates/cdr/src/wl.rs b/crates/cdr/src/wl.rs index 3ca20a1111..3ec6f26c79 100644 --- a/crates/cdr/src/wl.rs +++ b/crates/cdr/src/wl.rs @@ -184,7 +184,15 @@ fn shape(rec: &[u8], fields: Fields, p: &Profile, budget: &mut Budget, warn: &mu }; let outline = if *rec.get(OUTLINED)? != 0 { let width = f64::from(Rd::at(rec, OUTLINE_WIDTH).u16()?) * k; - Some(Outline { width, color: color_at(OUTLINE_COLOR, warn)?, cap: Cap::Butt, join: Join::Miter, dashes: Vec::new(), behind_fill: false }) + Some(Outline { + width, + color: color_at(OUTLINE_COLOR, warn)?, + cap: Cap::Butt, + join: Join::Miter, + dashes: Vec::new(), + behind_fill: false, + scale_with: false, + }) } else { None }; diff --git a/crates/cdr/tests/it/read.rs b/crates/cdr/tests/it/read.rs index 1a5416d864..370db2f2fe 100644 --- a/crates/cdr/tests/it/read.rs +++ b/crates/cdr/tests/it/read.rs @@ -1600,6 +1600,23 @@ fn outlines_flagged_behind_the_fill_say_so() { } } +/// Bit 5 of the line type scales the outline with the shape. +#[test] +fn outlines_flagged_to_scale_with_the_shape_say_so() { + let black = synth::color(2, [0, 0, 0, 100]); + for version in [700, 1300, 1600] { + for (line_type, scale_with) in [(2, false), (0x22, true), (0x12, false), (0x26, true)] { + let v = V(version); + let outline = v.outline(9, synth::Pen { line_type, width: 4.0, cap: 0, join: 0 }, &black, &[]); + let style = vec![(10, 9u32.to_le_bytes().to_vec()), (30, v.rect(10.0, 10.0, 0.0))]; + let page = synth::page(false, vec![synth::layer(v, [0, 0, 0, 0x98], "L", vec![synth::object(v, 1, &style, None)])]); + let d = read(&synth::file_of(version, vec![list(b"otlt", vec![chunk(b"outl", outline)]), page]), Limits::default()).unwrap(); + let s = shapes(&d.pages[0].layers[0].objects); + assert_eq!(s[0].outline.as_ref().map(|o| o.scale_with), Some(scale_with), "{version} {line_type:#x}"); + } + } +} + #[test] fn library_colors_from_version_13_keep_their_names_and_tints() { // A model 21 color (blue, green, red, tint) shown at 50 %, and its library name. diff --git a/crates/engine/src/cmd/fileio/cdr/shapes.rs b/crates/engine/src/cmd/fileio/cdr/shapes.rs index 69e9cb1ea4..070bcff762 100644 --- a/crates/engine/src/cmd/fileio/cdr/shapes.rs +++ b/crates/engine/src/cmd/fileio/cdr/shapes.rs @@ -173,13 +173,13 @@ impl Builder { // In paint order: an outline behind the fill comes first. let mut items = Vec::new(); if let Some(o) = s.outline.as_ref().filter(|o| o.behind_fill) { - items.push(AppearanceItem::Stroke(self.stroke(o))); + items.push(AppearanceItem::Stroke(self.stroke(o, &s.matrix))); } if let Some(c) = &s.fill { items.push(AppearanceItem::Fill(FillLayer::new(self.paint(c)))); } if let Some(o) = s.outline.as_ref().filter(|o| !o.behind_fill) { - items.push(AppearanceItem::Stroke(self.stroke(o))); + items.push(AppearanceItem::Stroke(self.stroke(o, &s.matrix))); } // A curve of several subpaths is filled with holes where they overlap: VectorCraft's own // choice of rule for it. @@ -189,9 +189,19 @@ impl Builder { Some(Arc::new(n)) } - fn stroke(&mut self, o: &cd::Outline) -> StrokeLayer { + /// The stroke of outline `o` on a shape placed by `matrix`. + fn stroke(&mut self, o: &cd::Outline, matrix: &cd::Matrix) -> StrokeLayer { + // The width of an outline scaled with the shape is multiplied by the square root of the + // matrix's area factor (R50). For a matrix that scales x and y differently, that width is + // VectorCraft's own value. + let width = if o.scale_with { + let [a, b, c, d, _, _] = matrix.0; + o.width * (a * d - b * c).abs().sqrt() + } else { + o.width + }; // 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 width = if width.is_finite() && width > 0.0 { 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, @@ -485,6 +495,7 @@ mod tests { join: cd::Join::Miter, dashes: vec![1.0; 299], behind_fill: false, + scale_with: false, }; let rect = cd::Object::Shape(Box::new(cd::Shape { geometry: Geometry::Rect { w: 10.0, h: 10.0, radii: [0.0; 4] }, @@ -509,6 +520,32 @@ mod tests { assert!(b.notes.contains(&Warning::TooDeep)); } + /// An outline scaled with the shape takes the square root of the matrix's area factor on its + /// width and dashes; another outline keeps its stored width under the same matrix. + #[test] + fn outlines_scaled_with_the_shape_scale_their_width_and_dashes() { + // A matrix that scales by 2 and 8 and skews: area factor 2 * 8 - 3 * 0 = 16, mean scale 4. + let matrix = cd::Matrix([2.0, 0.0, 3.0, 8.0, 5.0, 5.0]); + for (scale_with, width, dashes) in [(true, 6.0, [12.0, 6.0]), (false, 1.5, [3.0, 1.5])] { + let outline = cd::Outline { + width: 1.5, + color: cd::Color::Gray(1.0), + cap: cd::Cap::Butt, + join: cd::Join::Miter, + dashes: vec![2.0, 1.0], + behind_fill: false, + scale_with, + }; + let rect = cd::Shape { geometry: Geometry::Rect { w: 10.0, h: 10.0, radii: [0.0; 4] }, matrix, fill: None, outline: Some(outline) }; + let mut b = Builder::new(); + let Some(node) = b.shape(&rect, Affine::IDENTITY, false) else { panic!("{scale_with}: no shape") }; + let [AppearanceItem::Stroke(s)] = node.appearance.items.as_slice() else { panic!("{scale_with}: {:?}", node.appearance.items) }; + assert!((s.width - width).abs() < 1e-9, "{scale_with}: {}", s.width); + let pattern = s.dash.as_ref().map(|d| d.pattern.clone()); + assert_eq!(pattern, Some(dashes.to_vec()), "{scale_with}"); + } + } + /// A corner rounded in the file stays on the same corner of the page, however the rectangle's /// size points. #[test] diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 460c891980..486344b298 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1697,7 +1697,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, clipping containers (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/it/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, clipping containers (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, or scaled with the object's matrix, 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/it/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`).