Pen InitializePen(Pen pen, BlockStructureLineKind lineKind) { switch (lineKind) { case BlockStructureLineKind.Solid: break; case BlockStructureLineKind.Dashed_1_1: pen.DashStyle = new DashStyle(dashed_1_1_DashStyle, 1); pen.DashCap = PenLineCap.Flat; break; case BlockStructureLineKind.Dashed_2_2: pen.DashStyle = new DashStyle(dashed_2_2_DashStyle, 1); pen.DashCap = PenLineCap.Flat; break; case BlockStructureLineKind.Dashed_3_3: pen.DashStyle = new DashStyle(dashed_3_3_DashStyle, 1); pen.DashCap = PenLineCap.Flat; break; case BlockStructureLineKind.Dashed_4_4: pen.DashStyle = new DashStyle(dashed_4_4_DashStyle, 1); pen.DashCap = PenLineCap.Flat; break; default: Debug.Fail($"Unknown line kind: {lineKind}"); break; } return(pen); }
Pen GetPen(ResourceDictionary props, BlockStructureLineKind lineKind) { Color? color; SolidColorBrush scBrush; Pen newPen; if ((color = props[EditorFormatDefinition.ForegroundColorId] as Color?) != null) { var brush = new SolidColorBrush(color.Value); brush.Freeze(); newPen = InitializePen(new Pen(brush, PEN_THICKNESS), lineKind); newPen.Freeze(); } else if ((scBrush = props[EditorFormatDefinition.ForegroundBrushId] as SolidColorBrush) != null) { if (scBrush.CanFreeze) { scBrush.Freeze(); } newPen = InitializePen(new Pen(scBrush, PEN_THICKNESS), lineKind); newPen.Freeze(); } else if ((newPen = props[MarkerFormatDefinition.BorderId] as Pen) != null) { if (newPen.CanFreeze) { newPen.Freeze(); } } return(newPen); }