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

Drawing offset curves #75

Open
bluebear94 opened this issue Feb 25, 2023 · 5 comments
Open

Drawing offset curves #75

bluebear94 opened this issue Feb 25, 2023 · 5 comments

Comments

@bluebear94
Copy link

Are there plans to support drawing offset curves for font outlines? I’m currently using ab_glyph_rasterizer for rasterizing glyphs from a font and would like to support outlined text as well.

@alexheretic
Copy link
Owner

I don't personally have any plans for such support no.

ab_glyph_rasterizer seems lower level that this concept since i just draws the curves it is given. I guess the missing piece is the logic to generate the offset outline curves from the original glyph outline curves. This could be done outside of ab_glyph & ab_glyph_rasterizer.

I'm not 100% sure how you see outlined-text working. Do you want to rasterize both the glyph and then the modified bigger glyph, then render them one on top of the other? If so that does seems possible already.

@bluebear94
Copy link
Author

I was asking about this since the crate seems to rasterize glyphs by decomposing the outline into line segments, which happen to be easy to offset compared to quadratic and cubic Bézier curves.

@alexheretic
Copy link
Owner

Yes that is an interesting point and reason to bake it into ab-glyph-rasterizer. Might be worth a PR.

I guess the only downside would be complicating the rasterizer, but allowing configurable offset without too much extra complexity seems nice to have.

@bluebear94
Copy link
Author

Offsetting the outlines would require storing the list of line segments so that segments that were originally connected stay connected to each other. I think a separate struct that retains such a list instead of drawing them to a buffer might be the best approach, so that Rasterizer and (say) LineBuffer implement the shared trait

pub trait CurveDrawer {
  fn draw_line(&mut self, p0: Point, p1: Point);
  fn draw_quad(&mut self, p0: Point, p1: Point, p2: Point) { ... }
  fn draw_cubic(&mut self, p0: Point, p1: Point, p2: Point, p3: Point) { ... }
}

Then those who just want to rasterize the original outline could use Rasterizer directly, while those who want to rasterize an offset curve could construct a LineBuffer, call an offset method, and pass it to a Rasterizer. Even then, we’d have to worry about the offset curve intersecting itself. I wonder if I should use a completely different approach to this problem.

@alexheretic
Copy link
Owner

It's definitely worth some experimentation. My main worry is if the complexity will be worth it, compared to external logic calculating the offset curves and just keeping ab_glyph_rasterizer as something that can draw the curves.

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

No branches or pull requests

2 participants