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

Add a stroke-dashcap option to LineSymbolizer. #3982

Open
StyXman opened this issue Sep 4, 2018 · 3 comments
Open

Add a stroke-dashcap option to LineSymbolizer. #3982

StyXman opened this issue Sep 4, 2018 · 3 comments

Comments

@StyXman
Copy link

StyXman commented Sep 4, 2018

Mapnik has the stroke-linecap option that handles how ends of lines are rendered. One of the consequences is that when you use stroke-dasharray, the same cap is used for the dashes. I would like to define the dash caps independently.

I also plan to try to implement this myself, so if you could just give me some pointer where to start, I would really appreciate it.

@StyXman StyXman changed the title Add a stroke-dahcap option to LineSymbolizer. Add a stroke-dashcap option to LineSymbolizer. Sep 4, 2018
@talaj
Copy link
Member

talaj commented Sep 4, 2018

That would be great, @StyXman . I see that you already opened this issue in #3849. Can you please close it?

Concerning implementation, I can offer some basic help.

There is a pipeline of operations which geometry goes through. These operations convert a stream of vertices of a geometry to another stream of vertices. Here is a list of operations for LineSymbolizer:

using vertex_converter_type = vertex_converter<clip_line_tag, clip_poly_tag, transform_tag,
affine_transform_tag,
simplify_tag, smooth_tag,
offset_transform_tag,
dash_tag, stroke_tag>;

vertex_converter is a template which chains those operations.

The last two from the list are dash and stroke converters. Dash converter splits line to dashes - many short lines. Stroke converter converts lines to polygons with given parameters (such as stroke-width and stroke-linecap). Resulting polygons are rasterized.

Your target is therefore the stroke converter. I would try to extend it or rather introduce specialized stroke converter for dashed lines to keep original code efficient.

The dash converter and the stroke converter are part of AGG library as templates agg::conv_stroke and agg::conv_dash. It may be useful to read Introduction to AGG library. There are some Demo Examples, especially conv_stroke.cpp is useful for our case.

@StyXman
Copy link
Author

StyXman commented Sep 4, 2018

Yeah, when I was filling the info for the issue I had a déjà-vu sensation :)

Thanks for the pointers. I'll try to do it, but I really don't have much time.

@StyXman
Copy link
Author

StyXman commented Feb 9, 2019

It took me a long time to have the time to look at this with time.

Could you explain how does the rendering machinery work? From what I read, the converters are instantiated, then vertexes are added with add_vertex() and then vertex() is called, which runs a quasi-state-machine (they keep track of past and future states) to do... what?

What I'm thinking of is to extend the dasher to mark the first and last segments of the original line, and the stroker to use that to use one cap or another, but I can't see how the data is fed to the converters, and how the converters modify the data so it's fed to the following one. I think I see the hooks, but I need to understand the machinery that makes them tick, and AGG's site is not really explicit about it. i didn't manage to extract that info form the example you gave me.

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