I need a bit of advice from 2D graphicsexperts... I want to draw polygons with an outline, but I want the outline tobe inside the polygons as demonstrated on the attached image. The polygon onthe example image is self intersecting and the solution should be able tohandle them exactly this way. The solution should also work with polygons withholes, especially with polygons created from font glyphs.
So far I see two possible solutions but Idon't like any of them:
1) use conv_stroke with double the requestedoutline width and then use the gpc to intersect the stroke polygon with theoriginal polygon - only the internal parts of the stroke would be visible. I donot like this solution too much because the license of the gpc and because itseems too complicated and slow.
2) split the self-intersecting polygons toa set of not-self-intersecting ones and then use conv_contour to shrink them toget the "holes". I do not like this either, because splitting theself-intersecting polygon is probably not trivial and could take me days (isthere a source code for this somewhere? in agg possibly?) and after playingwith the conv_contour example, it seems I can run into problems if the originalpolygon is smaller than the outline should be. (I would need to handle caseswhere the outline covers the entire polygon and similar ones.)
I'm afraid there's no simple solution. Yousee, if you need to process arbirarily self-intersecting polygons, just imaginewhat you do with this one:
The general solution would be like this:
1) Apply GPC "union" with anempty polygon. It will break your self-intersecting polygon into simple ones.
2) Compute the directions of everyoutput-from-GPC-polygon.
3) Apply conv_contour, to erode the simplepolygons.
It will handle polygons without theexplicit holes and it is computationally expensive. I'm not sure about theholes in this case.
But you also mentioned font glyphs, right?Typically you don't need the general solution when dealing with a"faux-bold" or "faux-light" font. The direction of thecontours in both, TrueType and Type-I is known. So that, when dealing withfonts, you don't even need to compute the direction.
I would say it's crazy to haveself-intersections in glyphs, because it's much more efficient to pre-computeand eliminate all self-intersections.
The task is actually to allow users to drawarbitrary polygons (without holes), but I also wanted to use the same methodwith fonts. So it is either holes or self-intersecting polygons, not both atonce. I wanted to have similar look and options of all rendered shapes