Beispiel #1
0
 public static double GetStrokeThickness(this LineStyle style)
 {
     if (style.HasFlag(LineStyle.Thick))
     {
         return(3.0);
     }
     return(1.0);
 }
Beispiel #2
0
 public static DoubleCollection GetStrokeDashArray(this LineStyle style)
 {
     if (style.HasFlag(LineStyle.Dotted))
     {
         return new DoubleCollection {
                    1.0, 2.0, 1.0, 2.0
         }
     }
     ;
     if (style.HasFlag(LineStyle.Dashed))
     {
         return new DoubleCollection {
                    3.0, 3.0, 3.0, 3.0
         }
     }
     ;
     return(null);
 }
 public static System.Windows.Media.DoubleCollection GetStrokeDashArray(this LineStyle style)
 {
     if (style.HasFlag(LineStyle.Dotted))
     {
         return new System.Windows.Media.DoubleCollection {
                    1.0, 2.0, 1.0, 2.0
         }
     }
     ;
     else if (style.HasFlag(LineStyle.Dashed))
     {
         return new System.Windows.Media.DoubleCollection {
                    3.0, 3.0, 3.0, 3.0
         }
     }
     ;
     else
     {
         return(null);
     }
 }
Beispiel #4
0
        /// <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;
            }
        }