mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-18 16:34:56 +00:00
Shape Format: Shape Effects — shadow, glow and soft edges (#275)
Shapes and text boxes get an effects model (outer shadow with colour, transparency, blur, distance and angle; glow with colour, size and transparency; soft-edge radius), the shape.effects command (presets, custom values or null per effect, applied to every selected shape, undoable, hostile numbers clamped), screen and PDF rendering with the same banded approximation of a blur, DOCX a:effectLst read/write (outerShdw, glow, softEdge) with a matching wp:effectExtent, and a contextual Shape Format tab with Shape Fill, Shape Outline and Shape Effects (Shadow, Glow, Soft Edges submenus) plus Arrange. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
40c5d51bf9
commit
2f8f304fc9
25 files changed
+959
-23
No files matched your search
@@ -64,6 +64,8 @@ pub enum Draw {
|
||||
fill: Option<Rgb>,
|
||||
stroke: Option<Rgb>,
|
||||
stroke_width: f32,
|
||||
/// Shadow, glow and soft edges (drawn with [`wordcraft_doc::effects::bands`]).
|
||||
effects: wordcraft_doc::effects::ShapeEffects,
|
||||
},
|
||||
/// A formatting mark (¶ · → ↵) in the UI's mark colour, or in `color` (a tracked
|
||||
/// paragraph mark in its reviser's colour).
|
||||
@@ -188,8 +190,8 @@ fn item(doc: &Document, it: &Placed, opts: &DisplayOptions, alpha: f32, out: &mu
|
||||
Placed::Fill { rect, color } => out.push(Draw::Fill { rect: *rect, color: *color, alpha }),
|
||||
Placed::Rule { x0, y0, x1, y1, border } => out.push(rule(*x0, *y0, *x1, *y1, border, alpha)),
|
||||
Placed::Image { rect, media, crop, .. } => out.push(Draw::Image { rect: *rect, media: media.clone(), crop: *crop, alpha }),
|
||||
Placed::Shape { rect, kind, fill, stroke, stroke_width } => {
|
||||
out.push(Draw::Shape { rect: *rect, kind: *kind, fill: *fill, stroke: *stroke, stroke_width: *stroke_width })
|
||||
Placed::Shape { rect, kind, fill, stroke, stroke_width, effects } => {
|
||||
out.push(Draw::Shape { rect: *rect, kind: *kind, fill: *fill, stroke: *stroke, stroke_width: *stroke_width, effects: *effects })
|
||||
}
|
||||
Placed::Cell { .. } | Placed::Object { .. } => {}
|
||||
Placed::Lines { story, path, para, l0, l1, x, y, turn } if turn.is_turned() => {
|
||||
@@ -512,8 +514,8 @@ fn lines(
|
||||
let rect = inline_rect(obj, cx, base, c.adv, c.obj_h);
|
||||
match obj {
|
||||
Some(InlineObject::Image { media, crop, .. }) => out.push(Draw::Image { rect, media: media.clone(), crop: *crop, alpha }),
|
||||
Some(InlineObject::Shape { kind, fill, stroke, stroke_width, .. }) => {
|
||||
out.push(Draw::Shape { rect, kind: *kind, fill: *fill, stroke: *stroke, stroke_width: *stroke_width })
|
||||
Some(InlineObject::Shape { kind, fill, stroke, stroke_width, effects, .. }) => {
|
||||
out.push(Draw::Shape { rect, kind: *kind, fill: *fill, stroke: *stroke, stroke_width: *stroke_width, effects: *effects })
|
||||
}
|
||||
Some(InlineObject::Equation { .. }) => {
|
||||
if let Some((_, ml)) = pl.maths.iter().find(|(k, _)| *k == oi) {
|
||||
|
||||
@@ -95,6 +95,7 @@ pub enum Placed {
|
||||
fill: Option<Rgb>,
|
||||
stroke: Option<Rgb>,
|
||||
stroke_width: f32,
|
||||
effects: wordcraft_doc::effects::ShapeEffects,
|
||||
},
|
||||
/// A table cell's area (for hit testing and cell selection).
|
||||
Cell {
|
||||
@@ -1108,8 +1109,8 @@ fn float_item(o: &InlineObject, rect: Rect, story: StoryRef, path: &[u32], off:
|
||||
InlineObject::Image { media, crop, .. } => {
|
||||
Some(Placed::Image { rect, media: media.clone(), crop: *crop, story, path: Path(path.to_vec()), off })
|
||||
}
|
||||
InlineObject::Shape { kind, fill, stroke, stroke_width, .. } => {
|
||||
Some(Placed::Shape { rect, kind: *kind, fill: *fill, stroke: *stroke, stroke_width: *stroke_width })
|
||||
InlineObject::Shape { kind, fill, stroke, stroke_width, effects, .. } => {
|
||||
Some(Placed::Shape { rect, kind: *kind, fill: *fill, stroke: *stroke, stroke_width: *stroke_width, effects: *effects })
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
|
||||
@@ -231,6 +231,7 @@ fn many_hidden_float_anchors_lay_out_in_linear_time() {
|
||||
stroke_width: 1.0,
|
||||
float,
|
||||
story: None,
|
||||
effects: Default::default(),
|
||||
};
|
||||
let obj = wordcraft_doc::para::OBJ.to_string();
|
||||
let mut p = wordcraft_doc::Paragraph::with_text("Text ", Default::default());
|
||||
@@ -970,6 +971,7 @@ fn text_wraps_around_square_float() {
|
||||
stroke_width: 1.0,
|
||||
float,
|
||||
story: None,
|
||||
effects: Default::default(),
|
||||
};
|
||||
d.insert_object(&Pos::body(0, 0), shape, &Default::default()).unwrap();
|
||||
let l = lay(&d);
|
||||
@@ -1007,6 +1009,7 @@ fn deleted_float_leaves_no_wrap_area_without_markup() {
|
||||
stroke_width: 1.0,
|
||||
float,
|
||||
story: None,
|
||||
effects: Default::default(),
|
||||
};
|
||||
d.insert_object(&Pos::body(0, 0), shape, &Default::default()).unwrap();
|
||||
let obj = wordcraft_doc::para::OBJ.len_utf8();
|
||||
@@ -1058,6 +1061,7 @@ fn hidden_float_leaves_no_wrap_area_when_hidden_text_is_not_shown() {
|
||||
stroke_width: 1.0,
|
||||
float,
|
||||
story: None,
|
||||
effects: Default::default(),
|
||||
};
|
||||
d.insert_object(&Pos::body(0, 0), shape, &Default::default()).unwrap();
|
||||
let obj = wordcraft_doc::para::OBJ.len_utf8();
|
||||
@@ -1094,6 +1098,7 @@ fn line_numbers_borders_text_boxes() {
|
||||
stroke_width: 1.0,
|
||||
float: Default::default(),
|
||||
story: Some(id),
|
||||
effects: Default::default(),
|
||||
};
|
||||
d.insert_object(&Pos::body(2, 5), tb, &Default::default()).unwrap();
|
||||
let l = lay(&d);
|
||||
@@ -1387,6 +1392,7 @@ fn text_box_at(d: &mut Document, pos: &Pos, text: &str, w: f32, h: f32, float: w
|
||||
stroke_width: 0.75,
|
||||
float,
|
||||
story: Some(id),
|
||||
effects: Default::default(),
|
||||
};
|
||||
d.insert_object(pos, shape, &Default::default()).unwrap();
|
||||
id
|
||||
@@ -1457,6 +1463,7 @@ fn presses_grab_pictures_anywhere_and_text_boxes_by_their_border() {
|
||||
stroke_width: 1.0,
|
||||
float: Default::default(),
|
||||
story: None,
|
||||
effects: Default::default(),
|
||||
};
|
||||
d.insert_object(&Pos::body(0, 0), shape, &Default::default()).unwrap();
|
||||
let l = lay(&d);
|
||||
@@ -1676,6 +1683,7 @@ fn box_fan_out(levels: usize, fan: usize) -> Document {
|
||||
stroke_width: 0.0,
|
||||
float: Default::default(),
|
||||
story: Some(story),
|
||||
effects: Default::default(),
|
||||
};
|
||||
for (k, id) in ids.iter().enumerate() {
|
||||
let next = *ids.get(k + 1).unwrap_or(id);
|
||||
@@ -1739,7 +1747,17 @@ fn a_text_box_inside_a_text_box_still_shows_its_text() {
|
||||
}
|
||||
|
||||
fn picture(w: f32, h: f32, float: wordcraft_doc::para::Float) -> InlineObject {
|
||||
InlineObject::Shape { kind: wordcraft_doc::para::ShapeKind::Rectangle, w, h, fill: None, stroke: None, stroke_width: 1.0, float, story: None }
|
||||
InlineObject::Shape {
|
||||
kind: wordcraft_doc::para::ShapeKind::Rectangle,
|
||||
w,
|
||||
h,
|
||||
fill: None,
|
||||
stroke: None,
|
||||
stroke_width: 1.0,
|
||||
float,
|
||||
story: None,
|
||||
effects: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1877,7 +1895,17 @@ fn lines_with_tabs_never_shrink() {
|
||||
}
|
||||
|
||||
fn rect_shape(w: f32, h: f32, float: wordcraft_doc::para::Float) -> InlineObject {
|
||||
InlineObject::Shape { kind: wordcraft_doc::para::ShapeKind::Rectangle, w, h, fill: None, stroke: None, stroke_width: 1.0, float, story: None }
|
||||
InlineObject::Shape {
|
||||
kind: wordcraft_doc::para::ShapeKind::Rectangle,
|
||||
w,
|
||||
h,
|
||||
fill: None,
|
||||
stroke: None,
|
||||
stroke_width: 1.0,
|
||||
float,
|
||||
story: None,
|
||||
effects: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn shapes(items: &[Placed]) -> Vec<Rect> {
|
||||
@@ -2042,6 +2070,7 @@ fn floating_header_text_box_leaves_the_body_at_the_top_margin() {
|
||||
stroke_width: 0.75,
|
||||
float,
|
||||
story: Some(story),
|
||||
effects: Default::default(),
|
||||
};
|
||||
anchor.insert_object(0, tb, &Default::default()).unwrap();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user