mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-30 10:16:46 +01:00
M3: second review round for export framing, blend-through and budgets
- Text painted only through its runs' fills counts for export framing. - A hidden layer inside a pass-through frame no longer makes it draw straight onto the canvas. - The scratch surface for plus lighter and plus darker comes from the layer budget; refused, the paint draws in tiny-skia's nearest mode. - Averaging an image shown smaller bounds the weight setup before working it out, and reserves its output first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012eBDgsvRwsSRpWeWrzabVY
This commit is contained in:
1 parent
ff3cd3f9fe
commit
e26b0aa223
4 files changed
+39
-5
No files matched your search
@@ -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<Vec<Paint>>| 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()
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
@@ -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::<u64>();
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user