private CaptionShape GetGroup(StreamReader r, int count, List <Ornament> ornaments) { ShapeList tempShapes = new ShapeList(); List <Ornament> newOrnaments = new List <Ornament>(); for (int i = 0; i < count; i++) //loop group count { string groupLine = r.ReadLine(); if (groupLine.StartsWith("ornament")) { newOrnaments.Add(GetOrnament(groupLine)); i--; //ornament doesn't count as shape } else if (groupLine.StartsWith("group")) { CaptionShape group = GetGroup(r, int.Parse(groupLine.Split(' ')[1]), newOrnaments); if (group != null) { tempShapes.Attach(group); newOrnaments.Clear(); } } else { CaptionShape s = GetShape(groupLine, newOrnaments); if (s != null) { tempShapes.Attach(s); newOrnaments.Clear(); } } } CaptionShape result = new CaptionShape(new GroupShape(tempShapes)); foreach (Ornament o in ornaments) { result.AddOrnament(o); } return(result); }