mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-05 18:20:01 +00:00
* M8: one depth cap for a whole render; render threads get 8 MiB stacks (#1082) A pattern fill drew its source as a fresh render from depth 0, so patterns in patterns could stack three renders of 256 levels. The source now goes on from the depth of the layer it fills. A render level takes about 6.5 KB of stack (measured), about 1.7 MB at the cap: the canvas render, preview and save threads and a band pool of their own now get 8 MiB stacks instead of the default 2 MiB. * M8: SVG and PDF exports carry the depth into pattern sources and embedded renders (#1082)
42 lines
1.8 KiB
Rust
42 lines
1.8 KiB
Rust
//! A pattern fill's source exports one level below the layer it fills, so one depth cap bounds
|
|
//! the whole export (#1082).
|
|
|
|
use figcraft_color::{Color, Paint, PaintKind, PatternPaint};
|
|
use figcraft_doc::{Document, NodeId, NodeKind};
|
|
|
|
use crate::tests::inflated;
|
|
use crate::{PdfOptions, export_pdf};
|
|
|
|
/// `levels` frames under `parent`, each inside the last; the outermost and the innermost.
|
|
fn chain(d: &mut Document, parent: NodeId, levels: usize) -> (NodeId, NodeId) {
|
|
let mut at = parent;
|
|
let mut first = None;
|
|
for _ in 0..levels {
|
|
at = d.create(at, NodeKind::Frame, "F", 0.0, 0.0, 100.0, 100.0).unwrap();
|
|
d.get_mut(at).unwrap().fills.clear();
|
|
first.get_or_insert(at);
|
|
}
|
|
(first.unwrap(), at)
|
|
}
|
|
|
|
/// The export of an `outer`-deep chain ending in a frame filled with a pattern of another chain,
|
|
/// `inner` deep and ending in red.
|
|
fn export(outer: usize, inner: usize) -> String {
|
|
let mut d = Document::new("depth");
|
|
let page = d.first_page().unwrap();
|
|
let sources = d.add_page("Sources");
|
|
let (source, red) = chain(&mut d, sources, inner);
|
|
d.get_mut(red).unwrap().fills = vec![Paint::solid(Color::from_hex("FF0000").unwrap())];
|
|
let (root, filled) = chain(&mut d, page, outer);
|
|
d.get_mut(filled).unwrap().fills = vec![Paint { kind: PaintKind::Pattern(PatternPaint::new(source.0)), ..Paint::solid(Color::WHITE) }];
|
|
inflated(&export_pdf(&d, &[root], &PdfOptions::default()).unwrap())
|
|
}
|
|
|
|
#[test]
|
|
fn a_pattern_source_exports_from_the_depth_of_the_layer_it_fills() {
|
|
assert!(export(200, 40).contains("1 0 0 rg"), "within the cap");
|
|
// It used to start again at depth 0 and export all of it.
|
|
assert!(!export(200, 100).contains("1 0 0 rg"), "the levels past the cap are left out");
|
|
assert!(export(1, 100).contains("1 0 0 rg"));
|
|
}
|