mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-02 22:20:50 -06:00
File > Document Setup is a tabbed dialog over one engine command, document.setup (no params: a query; any keys: one undo step; document.setUnits stays as the units alias). - General: units, bleed (four sides with a link toggle), Edit Artboards, Show Images in Outline Mode (greyscale pixels under the frame), Highlight Substituted Fonts/Glyphs (pink boxes on screen only). - Transparency: grid size and colour presets or custom colours, Simulate Colored Paper, the flattener preset (built-in or saved) and Discard White Overprint (Overprint Preview keeps white overprints visible). - Type: language with its quotes, Use Typographer's Quotes for the Type tool and Smart Punctuation, superscript/subscript size and position and small caps size (Character panel position/smallCaps; changing the setup restyles the text in the same undo step), text export (SVG text as text or outlines by default). - The canvas draws a red bleed outline and the grid in the document's colours and cell size as one textured quad, also in rotated views; a white Background Contents exports raster formats opaque. Model: Document.setup (DocSetup, defaulted, skipped when default) and CharStyle position/small_caps; old files load unchanged. tests_transparencygrid's helper now finds the grid by its texture (the grid is one textured mesh instead of per-cell rectangles). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.5 KiB
Rust
34 lines
1.5 KiB
Rust
//! Document Setup options the renderer honours.
|
||
|
||
use std::sync::Arc;
|
||
|
||
use vectorcraft_doc::{Document, ImageBlob, ImageObject, Node, NodeKind};
|
||
|
||
use super::*;
|
||
|
||
fn doc_with_red_image() -> Document {
|
||
let mut d = Document::new(40.0, 40.0);
|
||
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();
|
||
d.images.insert("red".into(), ImageBlob { mime: "image/png".into(), bytes: Arc::new(png) });
|
||
let (id, layer) = (d.alloc_id(), d.layers[0].id);
|
||
let im = ImageObject { key: "red".into(), width: 40, height: 40, xf: Affine::IDENTITY, link: None };
|
||
d.insert(Some(layer), 0, Node::new(id, NodeKind::Image(im))).unwrap();
|
||
d
|
||
}
|
||
|
||
#[test]
|
||
fn outline_mode_draws_images_in_grey_only_when_the_setup_asks() {
|
||
let mut d = doc_with_red_image();
|
||
let outline = RenderOptions { outline: true, ..Default::default() };
|
||
let centre = |d: &Document| Renderer::new().render(d, 40, 40, Affine::IDENTITY, &outline).pixel(20, 20);
|
||
assert_eq!(centre(&d)[3], 0, "outline mode draws only the image frame");
|
||
d.setup.outline_images = true;
|
||
let [r, g, b, a] = centre(&d);
|
||
// Red's luma (0.2126 × 255 ≈ 54) in every channel.
|
||
assert_eq!(a, 255);
|
||
assert!(r == g && g == b && (50..=58).contains(&r), "{:?}", [r, g, b]);
|
||
// Preview mode keeps the colours.
|
||
assert_eq!(Renderer::new().render(&d, 40, 40, Affine::IDENTITY, &RenderOptions::default()).pixel(20, 20), [255, 0, 0, 255]);
|
||
}
|