Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styled/Dashed Lines for Shapes #1210

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

anesthetice
Copy link
Contributor

@anesthetice anesthetice commented Sep 8, 2024

The goal of this PR is to allow users to modify the style of shapes, e.g. dashed lines, dotted lines, dotted shapes, etc. Furthermore to unify UI elements of the Shaper menu.

The current implementation could be made more efficient in the future if a pull request to add a sync flag in Piet gets merged.

style_demo.mp4

fixes #852
fixes #375

Cons of the current implementation

  • piet::StrokeStyle built on every call to draw_composed()
  • the use of a SmoothOptionPrecursor and ShapeStylePrecursor

Pros of the current implementation

  • minor impact on file size
  • don't have to wait for a piet PR to be merged

@flxzt
Copy link
Owner

flxzt commented Sep 9, 2024

Yes by using piet's abstraction the core logic is relatively trivially implemented - regarding integration into the UI what about adding another dropdown right above "shaper style"'s where a few predetermined stroke dash styles are available:

I am thinking about:

  • solid
  • dotted (1:1 ratio)
  • short dashed ( 2:1, maybe? let's see what fits best)
  • long dashed

this should give users some option without having complicated settings - for high precision shaping Inkscape is the better choice anyways.

What I think is worth discussing : what about offering more complicated choices like mixed dottted and shaped style's? Is that supported by piet currently?

@anesthetice
Copy link
Contributor Author

Good suggestions, things should be kept relatively simple, concerning more complicated choices, they are somewhat possible, for example we could use a StrokeDash ~ [0, 3, 1, 3] and a round LineCap to create a dot-dash line

Implementation

Trickier than I initially thought, but still nonetheless possible, here's what I'm currently working on

  • adding a shape_style entry to SmoothOptions shape_style: Option<ShapeStyle>
  • ShapeStyle being a complex wrapper around piet::StrokeStyle
  • ui: making a "Shaper Configuration"

Also considering adding a simple dashed line to the possible shapes

Tricky parts

1. piet::StrokeStyle contains piet::StrokeDash

/// A type that represents an alternating pattern of drawn and undrawn segments.
///
/// We use our own type as a way of making this work in `const` contexts.
///
/// This type `Deref`s to `&[f64]`.
#[derive(Debug, Default, Clone, PartialEq)]
pub struct StrokeDash {
    slice: &'static [f64],
    alloc: Option<Rc<[f64]>>,
}

Rc is neither Send nor Sync, which is required for items inside SmoothOptions

Currently trying to address this by using the Fragile crate, https://crates.io/crates/fragile, I thinks it's lightweight enough to add to rnote-compose (0 additional dependencies, read through the Fragile implementation, seems sound)

2. consistency

Hard to clearly explain this part, so I'll just be using an example:

Imagine you want a simple, pretty dashed line with rounded edges
unlike piet::LineCap::Butt, piet::LineCap::Round extends the length of a line in proportion to it's width, this will not be taken into consideration by piet::StrokeDash, it will have to be updated, neither will the width of the line itself, etc.

@flxzt flxzt self-requested a review September 29, 2024 21:18
@MarcA711
Copy link

It would be useful if one can also select the brush style for the shape as well. This way one can select the brush marker and draw the shape line to highlight text. This would look much cleaner than highlighting the text freehand.

Moreover, why only implement styled lines for shapes? It would be useful to draw dashed/dotted lines freehand as well. Maybe this could be implemented similar to how it's done in Xournal++: You can select a pen independently (brush style, size, color, line style) and in the next step you choose if you want to use this selected pen freehand or with a shape. Why should freehand and shapes have different pens? This would also integrate nicely with #1175, because you can select the pen you want, draw something and use the hold feature to convert it to a shape.

@anesthetice
Copy link
Contributor Author

It would be useful if one can also select the brush style for the shape as well. This way one can select the brush marker and draw the shape line to highlight text. This would look much cleaner than highlighting the text freehand.

Moreover, why only implement styled lines for shapes? It would be useful to draw dashed/dotted lines freehand as well. Maybe this could be implemented similar to how it's done in Xournal++: You can select a pen independently (brush style, size, color, line style) and in the next step you choose if you want to use this selected pen freehand or with a shape. Why should freehand and shapes have different pens? This would also integrate nicely with #1175, because you can select the pen you want, draw something and use the hold feature to convert it to a shape.

Good point, I'll see what I can do, under the hood pen strokes and shapes uses the same styles, so this might not be too complicated. I've also been thinking about having presets for pens and shapes, as having to switch back and forth within the settings is slightly inconvenient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Different line styles [Feature Request] Shapes with dotted lines
3 participants