You need to convert the GraphicsComplex
style polygon to a normal, coordinate-point one:
gcpolyToNormal = # /.
GraphicsComplex[p_, g_, o___] :>
GraphicsComplex[p,
g /. Polygon[v_] :> Polygon[v /. i_Integer :> p[[i]]]] &;
polygon2FilledCurve = # /. {Polygon[pts_ /; Depth[pts] == 4] :>
FilledCurve /@ Thread[Line[pts]],
Polygon[pts_ /; Depth[pts] == 3] :> FilledCurve[Line[pts]]} &;
polygon = {{0, 1}, {1, 3}, {5, 5}, {5, 0}, {-5, 0}, {-5, 5}, {-4,
3}, {0, 1}};
image = ListLinePlot[polygon, Filling -> {1 -> Axis}] /. _Line ->
Sequence[]
Export["image.pdf", polygon2FilledCurve[gcpolyToNormal@image]]
(I always add "/tmp/" to my test filenames, but it doesn't work on Windows, I think.)
Alternatively, one can fix polygon2FilledCurve
for GraphicsComplex
:
polygon2FilledCurve = # /. {Polygon[pts_ /; Depth[pts] == 2] :>
FilledCurve[Thread[Line[pts]]],
Polygon[pts_ /; Depth[pts] == 1] :> FilledCurve[Line[pts]]} &;
But then you have to decide which way you want it. Or one could write a more complicated function that parsed the polygons to see if they were "normal" or GraphicsComplex
type.
Here's a way to convert polygons in GraphicsComplex
to filled curves without converting them to normal form:
gcpolyToFilledCurved = # /.
GraphicsComplex[p_, g_, o___] :> GraphicsComplex[p, g /. {
Polygon[v : {__Integer}] :> FilledCurve[Line[v]],
Polygon[v : {{__Integer} ..}] :>
FilledCurve[Thread@Line[v]]}] &;
I see @AlexeyPopkov had already posted something like this, plus a fix to the polygon2FilledCurve
from the OP. I was called to dinner before I finished my edit.