Merge main into feat/proof-setup-customize

This commit is contained in:
dotCooCoo
2026-11-14 15:17:57 -08:00
291 changed files with 21346 additions and 3663 deletions
+5 -5
View File
@@ -155,19 +155,19 @@ pub(crate) fn path_cull_bounds(symbols: &SymbolBoxes, n: &Node, visual: impl FnO
/// How far brush art can paint past `n`'s brushed strokes, or past the brushed strokes in the art
/// of symbol instance `n`: `16 × w + 8`, where `w` is the widest stroke (at least 1) of `n` when it
/// has a visible brushed stroke and of the objects in that art that have one
/// has a visible brushed stroke with a paint and of the objects in that art that have one
/// ([`SymbolBoxes::brush_width`]) or the pieces live-effect plug-ins paint for them
/// ([`crate::fx::painted_brush_width`]), and 0 when neither has one.
/// ([`crate::fx::painted_brush_width`]), and 0 when neither has one. The room for `n`'s own strokes
/// is [`vectorcraft_brush::reach`], which the exports leave too.
pub(crate) fn pad(symbols: &SymbolBoxes, n: &Node) -> f64 {
let own = vectorcraft_brush::has_brush(n)
.then(|| n.appearance.items.iter().filter_map(|i| if let AppearanceItem::Stroke(s) = i { Some(s.width) } else { None }).fold(1.0, f64::max));
let own = vectorcraft_brush::reach(n);
let art = match &n.kind {
NodeKind::SymbolInstance { symbol, .. } => {
symbols.brush_width(symbol).into_iter().chain(crate::fx::painted_brush_width(symbols, symbol)).reduce(f64::max).map(|w| w.max(1.0))
}
_ => None,
};
own.into_iter().chain(art).reduce(f64::max).map_or(0.0, |w| 16.0 * w + 8.0)
art.map_or(own, |w| own.max(16.0 * w + 8.0))
}
pub use vectorcraft_brush::instance_art;
+2 -6
View File
@@ -28,16 +28,12 @@ const ADAM7: [(u32, u32, u32, u32); 7] = [(0, 0, 8, 8), (4, 0, 8, 8), (0, 4, 4,
/// Pixels per metre for a resolution in pixels per inch (the unit `pHYs` stores).
pub fn pixels_per_metre(ppi: f64) -> u32 {
(ppi / 0.0254).round().clamp(1.0, u32::MAX as f64) as u32
vectorcraft_doc::ppi::pixels_per_metre(ppi)
}
/// A whole `pHYs` chunk (length, type, data, CRC) declaring `x` × `y` pixels per inch.
pub fn phys_chunk(x: f64, y: f64) -> Vec<u8> {
let [x, y] = [x, y].map(|v| pixels_per_metre(v).to_be_bytes());
let mut out = Vec::with_capacity(21);
// x, y, unit 1 = metre.
chunk(&mut out, b"pHYs", &[x.as_slice(), y.as_slice(), &[1]].concat());
out
vectorcraft_doc::ppi::phys_chunk(x, y)
}
/// Encode straight-alpha RGBA8 pixels (`width`×`height`, row-major) as a PNG file.
+7
View File
@@ -67,6 +67,13 @@ pub(crate) fn visual_bounds(symbols: &SymbolBoxes, n: &Node) -> Option<Rect> {
if let Some(art) = painted_art(symbols, n) {
return art.visual_bounds_with(symbols).map(|r| with_raster_reach(symbols, n, r));
}
// Copies that each carry the raster effects listed before their Transform effect reach as far
// as each copy's raster effects paint, and the raster effects after it spread them all.
if effects::outer_effects(n).len() < n.appearance.effects.len()
&& let Some(art) = effects::reshape(Some(symbols.document()), n, None)
{
return cull_bounds(symbols, &art);
}
let bp = node_bezpath(n)?;
let ctx = GeomContext { doc: Some(symbols.document()), ..GeomContext::of(n) };
let (g, carry) = effected_path_carrying(symbols.document(), n, &bp);
+3 -2
View File
@@ -423,11 +423,12 @@ impl Renderer {
let outer = self.made_again;
self.made_again = outer || !kept;
// With Crop Marks, the object inside the art paints its own raster effects; Vector
// Halftone samples them with the object.
// Halftone samples them with the object. The copies of a Transform effect that carry the
// raster effects listed before it paint those themselves.
let rfx = if effects::has_crop_marks(a) || effects::addons::halftone::has_halftone(a) {
vec![]
} else {
effects::raster_effects(&a.appearance.effects)
effects::raster_effects(effects::outer_effects(a))
};
match cull_bounds(f.symbols, &art) {
Some(reach) if !f.opts.outline && !rfx.is_empty() => {
+3 -2
View File
@@ -425,8 +425,9 @@ impl Renderer {
if !k.is_finite() || k <= 1e-12 {
return;
}
// The art in its own coordinates, with its own resources (its composite fonts included).
let _lent = vectorcraft_text::FontDb::global().lend_composite_fonts(&e.doc.composite_fonts);
// The art in its own coordinates, with its own resources (its composite fonts included, and
// none of the host document's).
let _lent = vectorcraft_text::FontDb::global().lend_document_composite_fonts(&e.doc.composite_fonts);
let symbols = e.doc.symbol_boxes().quick();
let visible = m.inverse().transform_rect_bbox(f.visible);
let inner = Frame { doc: &e.doc, symbols: &symbols, view: f.view * m, visible, px: f.px / k, output: f.output * m, ..*f };
+50 -1
View File
@@ -209,7 +209,7 @@ fn a_documents_own_composite_font_draws_without_being_registered() {
}
/// A placed document draws its type in its own definition of a composite font that the document
/// placing it defines differently.
/// placing it defines differently, and as missing in one only the document placing it defines.
#[test]
fn a_placed_document_draws_its_own_definition_of_a_name_the_page_defines() {
use vectorcraft_doc::{CompositeFont, CompositePart, CompositeParts, ImageBlob, LinkInfo, PlacedDocument};
@@ -260,6 +260,55 @@ fn a_placed_document_draws_its_own_definition_of_a_name_the_page_defines() {
assert!(own == page(&plain, plain_id, "fontchange-placed-twice-plain", vec![]), "drawn in the placed document's definition");
assert!(own != page(&inter, inter_id, "fontchange-placed-twice-inter", vec![]), "not in the page's");
assert!(vectorcraft_text::FontDb::global().composite_font(NAME).is_none());
// A placed document that defines no composite font draws type naming the page's as missing.
let (undefined, undefined_id) = typed(NAME);
let (missing, missing_id) = typed("CF Placed Nowhere");
let borrowed = page(&undefined, undefined_id, "fontchange-placed-undefined", vec![definition("Inter")]);
assert!(borrowed == page(&missing, missing_id, "fontchange-placed-missing", vec![]), "drawn as in a missing font");
assert!(borrowed != page(&inter, inter_id, "fontchange-placed-undefined-inter", vec![]), "not in the page's definition");
}
/// A document that defines no composite font, drawn while another document's composite font of
/// the name its type is set in is registered (that document in front), draws that type as in a
/// missing font: in a render, an ink render, a thumbnail and a node render.
#[test]
fn a_document_draws_type_in_another_documents_composite_font_as_missing() {
use vectorcraft_doc::{CompositeFont, CompositePart, CompositeParts};
let _adding = adding_fonts();
const NAME: &str = "CF Front Only";
let db = vectorcraft_text::FontDb::global();
let typed = |family: &str| {
let mut d = Document::new(300.0, 150.0);
let style = CharStyle { size: 60.0, font_family: family.into(), ..Default::default() };
let n = Node::new(d.alloc_id(), NodeKind::Text(Box::new(TextObject::point(Point::new(10.0, 100.0), "Hamburg", style))));
let l = d.layers[0].id;
let id = d.insert(Some(l), 0, n).unwrap();
(d, id)
};
let (back, id) = typed(NAME);
let (missing, missing_id) = typed("CF Front Nowhere");
let (plain, plain_id) = typed("JetBrains Mono");
let opts = RenderOptions { background: Some([255, 255, 255, 255]), ..Default::default() };
let region = Rect::new(0.0, 0.0, 300.0, 150.0);
let draw = |d: &Document, id: NodeId| {
let n = d.node(id).unwrap().clone();
(
Renderer::new().render(d, 300, 150, Affine::IDENTITY, &opts).pixels,
Renderer::new().render_region_inks(d, region, 1.0, &opts),
Renderer::new().render_thumbnail(d, id, 64).map(|r| r.pixels),
Renderer::new().render_node(d, &std::sync::Arc::new(n), 300, 150, Affine::IDENTITY).map(|r| r.pixels),
)
};
let mut parts = CompositeParts::all(CompositePart::new("Source Sans 3", "Regular"));
parts.roman = CompositePart::new("JetBrains Mono", "Regular");
db.set_composite_font(&CompositeFont { name: NAME.into(), parts });
let (drawn, as_missing, in_front) = (draw(&back, id), draw(&missing, missing_id), draw(&plain, plain_id));
db.remove_composite_font(NAME);
assert!(drawn.0 != in_front.0, "not in the front document's definition");
assert!(drawn.0 == as_missing.0, "rendered");
assert!(drawn.1 == as_missing.1, "rendered as ink amounts");
assert!(drawn.2 == as_missing.2, "thumbnail");
assert!(drawn.3 == as_missing.3, "node");
}
/// Type at 80% opacity, in Multiply and with a drop shadow redraws in a font that becomes
+23
View File
@@ -1219,3 +1219,26 @@ fn a_shadow_before_a_skipped_transform_reaches_as_far_as_it_is_drawn() {
assert!(within(b), "{what}: painted {b:?} for art {art:?}");
}
}
/// Each copy of a Transform effect draws the drop shadow listed before the effect under itself,
/// scaled with it: the red square (10..30) and its copy scaled 200 % and moved 60 pt down (0..40
/// across, 60..100 down) each have a green shadow to their right, 20 pt for the square and 40 pt
/// for the copy. The bounds reach as far as the copy's shadow.
#[test]
fn each_copy_of_a_transform_effect_draws_its_own_shadow() {
let shadow = fx("stylize.dropShadow", json!({"x": 20, "y": 0, "blur": 0, "opacity": 100, "mode": "normal", "color": "#00ff00"}));
let copies = fx("distort.transform", json!({"scaleH": 200, "scaleV": 200, "moveV": 60, "copies": 1}));
let red = Appearance::basic(Paint::solid(Color::rgb(1.0, 0.0, 0.0)), Paint::None, 0.0);
let mut n = Node::path(NodeId(0), shapes::rectangle(Rect::new(10.0, 10.0, 30.0, 30.0)), red);
n.appearance.effects = vec![shadow, copies];
let d = doc_with(Document::new(100.0, 100.0), n);
let img = render(&d);
assert_eq!(img.pixel(20, 20), [255, 0, 0, 255], "the square");
assert_eq!(img.pixel(45, 20), [0, 255, 0, 255], "the square's shadow");
assert_eq!(img.pixel(20, 80), [255, 0, 0, 255], "the copy");
assert_eq!(img.pixel(70, 80), [0, 255, 0, 255], "the copy's shadow, 40 pt to its right");
assert_eq!(img.pixel(85, 80), [255, 255, 255, 255], "past the copy's shadow");
let n = &d.layers[0].children().unwrap()[0];
let b = crate::fx::visual_bounds(&d.symbol_boxes(), n).unwrap();
assert!(b.x1 >= 80.0 - 1e-9, "{b:?}");
}