diff --git a/crates/doc/src/node.rs b/crates/doc/src/node.rs index 144ca4101..6a0ba7517 100644 --- a/crates/doc/src/node.rs +++ b/crates/doc/src/node.rs @@ -784,12 +784,14 @@ impl Node { self.board.as_ref().is_some_and(crate::BoardItem::is_atom) } - /// Whether this layer puts nothing on the canvas: no visible fill (its own or a vector - /// region's), stroke or effect and no children (a placeholder box whose image was taken out, + /// Whether this layer puts nothing on the canvas: no visible fill (its own, a vector + /// region's or a text run's), stroke or effect and no children (a placeholder box whose image was taken out, /// an empty frame). pub fn draws_nothing(&self) -> bool { + let shows = |f: &Option>| f.as_deref().is_some_and(|f| f.iter().any(|p| p.visible)); let region_fill = match &self.kind { - NodeKind::Vector { network } => network.regions.iter().any(|r| r.fills.as_deref().is_some_and(|f| f.iter().any(|p| p.visible))), + NodeKind::Vector { network } => network.regions.iter().any(|r| shows(&r.fills)), + NodeKind::Text(t) => shows(&t.style.fills) || t.runs.iter().any(|r| shows(&r.style.fills)), _ => false, }; self.children.is_empty() diff --git a/crates/render/src/draw.rs b/crates/render/src/draw.rs index 1bdf7f2fd..07c162b4c 100644 --- a/crates/render/src/draw.rs +++ b/crates/render/src/draw.rs @@ -242,8 +242,13 @@ fn paint_each( .bounds() .transform(ts_transform(xf)) .and_then(|b| int_rect(Rect::new(b.left().into(), b.top().into(), b.right().into(), b.bottom().into()), (pix.width(), pix.height()))); - let Some(mut alone) = area.and_then(|r| Pixmap::new(r.width(), r.height())) else { continue }; let Some(r) = area else { continue }; + // Past the layer budget, the paint draws in the nearest mode tiny-skia has instead. + let held = crate::layer_budget::Held::take(r.width(), r.height(), 1); + let Some(mut alone) = held.as_ref().and_then(|_| Pixmap::new(r.width(), r.height())) else { + pix.fill_path(path, &paint, rule, ts_transform(xf), mask); + continue; + }; let t = ts_transform(Affine::translate((-f64::from(r.x()), -f64::from(r.y()))) * xf); alone.fill_path(path, &tiny_skia::Paint { blend_mode: tiny_skia::BlendMode::SourceOver, ..paint }, rule, t, None); crate::paint::composite(pix, (r.x(), r.y()), &alone, 1.0, p.blend); @@ -942,6 +947,8 @@ fn blends_through(doc: &Document, n: &Node, backdrop: bool) -> bool { } paints_blend(n) || doc.subtree(n.id).iter().skip(1).filter_map(|c| doc.node(*c)).any(|c| match c.blend { + // A hidden layer draws nothing (nor do the layers inside it). + _ if !c.visible => false, BlendMode::Normal => false, // Its paints blend with what lies under it too. BlendMode::PassThrough => paints_blend(c), diff --git a/crates/render/src/export_framing_tests.rs b/crates/render/src/export_framing_tests.rs index bf0c3e63d..c1b19a416 100644 --- a/crates/render/src/export_framing_tests.rs +++ b/crates/render/src/export_framing_tests.rs @@ -98,3 +98,22 @@ fn a_fitted_image_shown_smaller_fades_the_shapes_edge_once() { assert!((ink(0) - 255.0 * 0.75).abs() < 4.0, "the first pixel, three quarters covered, holds {}", ink(0)); assert!(ink(1) > 250.0, "the next, inside, holds {}", ink(1)); } + +/// Text painted only through its runs' fills draws something, so it counts for the export. +#[test] +fn text_painted_by_its_runs_counts_for_the_export() { + let (mut d, p) = page(); + let mut td = figcraft_doc::TextData::new("Hi"); + td.runs = vec![figcraft_doc::StyleRun { + start: 0, + end: 2, + style: figcraft_doc::TextStyle { fills: Some(vec![Paint::solid(Color::BLACK)]), ..td.style.clone() }, + }]; + let t = d.create(p, NodeKind::Text(td), "T", 0.0, 0.0, 40.0, 20.0).unwrap(); + let n = d.get_mut(t).unwrap(); + n.fills.clear(); + assert!(!n.draws_nothing()); + let NodeKind::Text(td) = &mut n.kind else { panic!("not text") }; + td.runs.clear(); + assert!(n.draws_nothing(), "without the runs' fills, nothing"); +} diff --git a/crates/render/src/resample.rs b/crates/render/src/resample.rs index ab34a29f9..481b8e7e8 100644 --- a/crates/render/src/resample.rs +++ b/crates/render/src/resample.rs @@ -25,13 +25,19 @@ pub(crate) fn area_averaged(src: &Pixmap, m: Transform, area: IntRect, clip: Rec } let (sw, sh) = (src.width() as usize, src.height() as usize); let (dw, dh) = (area.width() as usize, area.height() as usize); + // Bounded before any weight is worked out: each device pixel covers at most 1 / s + 2 image + // pixels along an axis, however wide the area a caller asks for. + let setup = |n: usize, s: f64| (n as f64) * (1.0 / s.abs() + 2.0); + if setup(dw, sx) + setup(dh, sy) > MAX_WORK as f64 { + return None; + } + let _held = crate::layer_budget::Held::take(area.width(), area.height(), 1)?; let cols = spans(area.x(), dw, (clip.left().into(), clip.right().into()), tx, sx, sw)?; let rows = spans(area.y(), dh, (clip.top().into(), clip.bottom().into()), ty, sy, sh)?; let work = |s: &[Span]| s.iter().map(|s| s.weights.len() as u64).sum::(); if work(&cols).saturating_mul(work(&rows)) > MAX_WORK { return None; } - let _held = crate::layer_budget::Held::take(area.width(), area.height(), 1)?; let mut out = Pixmap::new(area.width(), area.height())?; let data = src.data(); // Each device row: the image rows it covers, each averaged across into the device columns