private void ParseShapeWithStyle(ShapeWithStyle tag) { ParseFillStyleArray(tag.FillStyles); foreach (IShapeRecord o in tag.ShapeRecords) { if (o is StyleChangedRecord) { StyleChangedRecord scr = (StyleChangedRecord)o; if (scr.HasNewStyles) { ParseFillStyleArray(scr.FillStyles); } } } }
Edge[] ParseEdges(ShapeWithStyle s, Rect bounds) { List <Edge> edges = new List <Edge>(); uint f0 = 0; uint f1 = 0; uint ln = 0; int curX = -bounds.XMin; // always 0,0 int curY = -bounds.YMin; FillStyleArray curFills = s.FillStyles; LineStyleArray curLines = s.LineStyles; int fillOffset = 0; int lineOffset = 0; foreach (IShapeRecord rec in s.ShapeRecords) { if (rec is StyleChangedRecord) { StyleChangedRecord r = (StyleChangedRecord)rec; if (r.HasNewStyles) // todo: this also sets 'grouped' elements (and therefore layers) { fillOffset = curFills.FillStyles.Count; lineOffset = curLines.LineStyles.Count; curFills.FillStyles.AddRange(r.FillStyles.FillStyles); curLines.LineStyles.AddRange(r.LineStyles.LineStyles); } if (r.HasFillStyle0) { f0 = r.FillStyle0 == 0 ? 0 : (uint)(r.FillStyle0 + fillOffset); } if (r.HasFillStyle1) { f1 = r.FillStyle1 == 0 ? 0 : (uint)(r.FillStyle1 + fillOffset); } if (r.HasLineStyle) { ln = r.LineStyle == 0 ? 0 : (uint)(r.LineStyle + lineOffset); } if (r.HasMove) { curX = r.MoveDeltaX; // this is based on the initial location, which is now 0,0 curY = r.MoveDeltaY; } } else if (rec is StraightEdgeRecord) { StraightEdgeRecord r = (StraightEdgeRecord)rec; Edge e = new Edge(curX, curY, curX + r.DeltaX, curY + r.DeltaY, (byte)f0, (byte)f1, (byte)ln); curX += r.DeltaX; curY += r.DeltaY; edges.Add(e); } else if (rec is CurvedEdgeRecord) { CurvedEdgeRecord r = (CurvedEdgeRecord)rec; int curveX = curX + r.ControlX; int curveY = curY + r.ControlY; int destX = curveX + r.AnchorX; int destY = curveY + r.AnchorY; // split nodes if curve is outside start/end Y if (curveY >= curY && curveY <= destY) { Edge e = new CurvedEdge(curX, curY, curveX, curveY, destX, destY, (byte)f0, (byte)f1, (byte)ln); edges.Add(e); } else { Edge[] split = CurvedEdge.SplitAtPeak(curX, curY, curveX, curveY, destX, destY, (byte)f0, (byte)f1, (byte)ln); edges.Add(split[0]); edges.Add(split[1]); } curX = destX; curY = destY; } } edges.Sort(Edge.MaxYComparer); return(edges.ToArray()); }