mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-20 08:57:44 +00:00
test(format): area type round-trips through .pcraft
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
19261c5f12
commit
d2856e6ecb
1 file changed
+26
@@ -562,6 +562,32 @@ fn path_text_shape_roundtrips() {
|
||||
assert_eq!(shape, Some(TextShape::Path { path, start: 12.5, flip: true }));
|
||||
}
|
||||
|
||||
/// Area type (#218): the whole path, ops and fill rule included, survives .pcraft.
|
||||
#[test]
|
||||
fn area_text_shape_roundtrips() {
|
||||
use photocraft_doc::text::TextShape;
|
||||
use photocraft_doc::vector::{FillRule, Path, PathOp, Subpath};
|
||||
let mut doc = rich_doc(ColorMode::Rgb, SampleType::U8);
|
||||
let mut path = Path::new(vec![
|
||||
Subpath::polygon(&[(0.0, 0.0), (200.0, 0.0), (200.0, 120.0), (0.0, 120.0)]),
|
||||
Subpath::polygon(&[(80.0, 40.0), (120.0, 40.0), (120.0, 80.0)]).with_op(PathOp::Subtract),
|
||||
]);
|
||||
path.fill_rule = FillRule::EvenOdd;
|
||||
let ids: Vec<LayerId> = doc.walk().into_iter().filter(|(_, _, l)| matches!(l.content, LayerContent::Text(_))).map(|(_, _, l)| l.id).collect();
|
||||
assert!(!ids.is_empty());
|
||||
for id in ids {
|
||||
if let Some(LayerContent::Text(t)) = doc.layer_mut(id).map(|l| &mut l.content) {
|
||||
t.shape = TextShape::Area { path: path.clone() };
|
||||
}
|
||||
}
|
||||
let back = load_from_bytes(&save_to_bytes(&doc, &SaveOptions::default()).unwrap()).unwrap();
|
||||
let shape = back.walk().into_iter().find_map(|(_, _, l)| match &l.content {
|
||||
LayerContent::Text(t) => Some(t.shape.clone()),
|
||||
_ => None,
|
||||
});
|
||||
assert_eq!(shape, Some(TextShape::Area { path }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn channel_restrictions_and_bevel_elements_roundtrip() {
|
||||
use photocraft_doc::{Bevel, BevelContour, BevelTexture, Contour, Effect};
|
||||
|
||||
Reference in new issue
Block a user