static void WidenPath(GraphicsPath path, Pen pen, out List<PointF> widePoints, out List<byte> wideTypes)
{
widePoints = new List<PointF> ();
wideTypes = new List<byte> ();
var pathData = path.PathData;
var iterator = new GraphicsPathIterator(path);
var subPaths = iterator.SubpathCount;
int startIndex = 0;
int endIndex = 0;
bool isClosed = false;
var flattenedSubpath = new Paths();
var offsetPaths = new Paths();
var width = (pen.Width / 2) * scale;
var miterLimit = pen.MiterLimit * scale;
var joinType = JoinType.jtMiter;
switch (pen.LineJoin)
{
case LineJoin.Round:
joinType = JoinType.jtRound;
break;
case LineJoin.Bevel:
joinType = JoinType.jtSquare;
break;
}
for (int sp = 0; sp < subPaths; sp++)
{
var numOfPoints = iterator.NextSubpath(out startIndex, out endIndex, out isClosed);
//Console.WriteLine("subPath {0} - from {1} to {2} closed {3}", sp+1, startIndex, endIndex, isClosed);
var subPoints = pathData.Points.Skip(startIndex).Take(numOfPoints).ToArray();
//for (int pp = startIndex; pp <= endIndex; pp++)
//{
// Console.WriteLine(" {0} - {1}", pathData.Points[pp], (PathPointType)pathData.Types[pp]);
//}
// Load our Figure Subpath
flattenedSubpath.Clear();
flattenedSubpath.Add(Region.PointFArrayToIntArray(subPoints, scale));
// Calculate the outter offset region
var outerOffsets = Clipper.OffsetPaths(flattenedSubpath, width, joinType, EndType.etClosed, miterLimit);
// Calculate the inner offset region
var innerOffsets = Clipper.OffsetPaths(flattenedSubpath, -width, joinType, EndType.etClosed, miterLimit);
// Add the offsets to our paths
offsetPaths.AddRange(outerOffsets);
// revers our innerOffsets so that they create a hole when filling
Clipper.ReversePaths (innerOffsets);
offsetPaths.AddRange(innerOffsets);
}
foreach (var offPath in offsetPaths)
{
if (offPath.Count < 1)
continue;
var pointArray = Region.PathToPointFArray(offPath, scale);
var type = (byte)PathPointType.Start;
widePoints.Add (pointArray [0]);
wideTypes.Add (type);
type = (byte)PathPointType.Line;
for (int i = 1; i < offPath.Count; i++)
{
widePoints.Add (pointArray [i]);
wideTypes.Add (type);
}
if (widePoints.Count > 0)
wideTypes [wideTypes.Count-1] = (byte) (wideTypes [wideTypes.Count-1] | (byte) PathPointType.CloseSubpath);
}
}