/// <summary> /// Updates the line <paramref name="guide" /> with a new format. /// </summary> /// <param name="guide">The <see cref="Line" /> to update.</param> /// <param name="formatIndex">The new format index.</param> private void UpdateGuide(LineSpan lineSpan, Line adornment) { if (lineSpan == null || adornment == null) { return; } LineFormat format; if (lineSpan.Type == LineSpanType.PageWidthMarker) { if (!Theme.PageWidthMarkers.TryGetValue(lineSpan.Indent, out format)) { format = Theme.DefaultLineFormat; } } else if (!Theme.LineFormats.TryGetValue(lineSpan.FormatIndex, out format)) { format = Theme.DefaultLineFormat; } if (!format.Visible) { adornment.Visibility = Visibility.Hidden; return; } bool highlight = lineSpan.Highlight || lineSpan.LinkedLines.Any(ls => ls.Highlight); LineStyle lineStyle = highlight ? format.HighlightStyle : format.LineStyle; Color lineColor = highlight && !lineStyle.HasFlag(LineStyle.Glow) ? format.HighlightColor : format.LineColor; Brush brush; if (!GuideBrushCache.TryGetValue(lineColor, out brush)) { brush = new SolidColorBrush(lineColor.ToSWMC()); if (brush.CanFreeze) { brush.Freeze(); } GuideBrushCache[lineColor] = brush; } adornment.Stroke = brush; adornment.StrokeThickness = lineStyle.GetStrokeThickness(); adornment.StrokeDashArray = lineStyle.GetStrokeDashArray(); if (lineStyle.HasFlag(LineStyle.Dotted) || lineStyle.HasFlag(LineStyle.Dashed)) { adornment.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Unspecified); } else { adornment.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased); } if (lineStyle.HasFlag(LineStyle.Glow)) { Effect effect; Color glowColor = highlight ? format.HighlightColor : format.LineColor; if (!GlowEffectCache.TryGetValue(glowColor, out effect)) { effect = new DropShadowEffect { Color = glowColor.ToSWMC(), BlurRadius = LineStyle.Thick.GetStrokeThickness(), Opacity = 1.0, ShadowDepth = 0.0, RenderingBias = RenderingBias.Performance }; if (effect.CanFreeze) { effect.Freeze(); } GlowEffectCache[glowColor] = effect; } try { adornment.Effect = effect; } catch (COMException) { // No sensible way to deal with this exception, so we'll // fall back on changing the color. adornment.Effect = null; if (!GuideBrushCache.TryGetValue(glowColor, out brush)) { brush = new SolidColorBrush(glowColor.ToSWMC()); if (brush.CanFreeze) { brush.Freeze(); } GuideBrushCache[glowColor] = brush; } adornment.Stroke = brush; } } else { adornment.Effect = null; } }