/// <summary>
 /// Sets the <see cref="TextDecorations"/>.
 /// </summary>
 public void SetTextDecorations(TextDecorationCollection value)
 {
     ExtensionMethods.CheckIsFrozen(value);
     if (textDecorations == null)
     {
         textDecorations = value;
     }
     else
     {
         textDecorations = new TextDecorationCollection(textDecorations.Union(value));
     }
 }
Beispiel #2
0
        /// <inheritdoc/>
        public override void Draw(object dc, TextShape text, double dx, double dy, object db, object r)
        {
            var _dc = dc as DrawingContext;

            var style = text.Style;

            if (style == null)
            {
                return;
            }

            var properties = (ImmutableArray <Property>)db;
            var record     = (Record)r;
            var tbind      = text.BindText(properties, record);

            if (string.IsNullOrEmpty(tbind))
            {
                return;
            }

            double thickness = style.Thickness / _state.ZoomX;
            double half      = thickness / 2.0;

            Tuple <Brush, Pen> styleCached = _styleCache.Get(style);
            Brush fill;
            Pen   stroke;

            if (styleCached != null)
            {
                fill   = styleCached.Item1;
                stroke = styleCached.Item2;
            }
            else
            {
                fill   = CreateBrush(style.Fill);
                stroke = CreatePen(style, thickness);
                _styleCache.Set(style, Tuple.Create(fill, stroke));
            }

            var rect = CreateRect(text.TopLeft, text.BottomRight, dx, dy);

            Tuple <string, FormattedText, ShapeStyle> tcache = _textCache.Get(text);
            FormattedText ft;
            string        ct;

            if (tcache != null && string.Compare(tcache.Item1, tbind) == 0 && tcache.Item3 == style)
            {
                ct = tcache.Item1;
                ft = tcache.Item2;
                _dc.DrawText(ft, GetTextOrigin(style, ref rect, ft));
            }
            else
            {
                var ci = CultureInfo.InvariantCulture;

                var fontStyle  = System.Windows.FontStyles.Normal;
                var fontWeight = FontWeights.Regular;

                if (style.TextStyle.FontStyle != null)
                {
                    if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Italic))
                    {
                        fontStyle = System.Windows.FontStyles.Italic;
                    }

                    if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Bold))
                    {
                        fontWeight = FontWeights.Bold;
                    }
                }

                var tf = new Typeface(new FontFamily(style.TextStyle.FontName), fontStyle, fontWeight, FontStretches.Normal);

                ft = new FormattedText(
                    tbind,
                    ci,
                    ci.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight,
                    tf,
                    style.TextStyle.FontSize > 0.0 ? style.TextStyle.FontSize : double.Epsilon,
                    stroke.Brush, null, TextFormattingMode.Ideal);

                if (style.TextStyle.FontStyle != null)
                {
                    if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Underline) ||
                        style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Strikeout))
                    {
                        var decorations = new TextDecorationCollection();

                        if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Underline))
                        {
                            decorations = new TextDecorationCollection(
                                decorations.Union(TextDecorations.Underline));
                        }

                        if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.Style.FontStyleFlags.Strikeout))
                        {
                            decorations = new TextDecorationCollection(
                                decorations.Union(TextDecorations.Strikethrough));
                        }

                        ft.SetTextDecorations(decorations);
                    }
                }

                _textCache.Set(text, Tuple.Create(tbind, ft, style));

                _dc.DrawText(ft, GetTextOrigin(style, ref rect, ft));
            }
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="text"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object dc, XText text, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r)
        {
            var _dc = dc as DrawingContext;

            var style = text.Style;

            if (style == null)
            {
                return;
            }

            var tbind = text.BindToTextProperty(db, r);

            if (string.IsNullOrEmpty(tbind))
            {
                return;
            }

            double thickness = style.Thickness / _state.Zoom;
            double half      = thickness / 2.0;

            Tuple <Brush, Pen> cache = null;
            Brush fill;
            Pen   stroke;

            if (_enableStyleCache &&
                _styleCache.TryGetValue(style, out cache))
            {
                fill   = cache.Item1;
                stroke = cache.Item2;
            }
            else
            {
                fill   = CreateBrush(style.Fill);
                stroke = CreatePen(style, thickness);
                if (_enableStyleCache)
                {
                    _styleCache.Add(style, Tuple.Create(fill, stroke));
                }
            }

            var rect = CreateRect(
                text.TopLeft,
                text.BottomRight,
                dx, dy);

            Tuple <string, FormattedText, ShapeStyle> tcache = null;
            FormattedText ft;
            string        ct;

            if (_enableTextCache &&
                _textCache.TryGetValue(text, out tcache) &&
                string.Compare(tcache.Item1, tbind) == 0 &&
                tcache.Item3 == style)
            {
                ct = tcache.Item1;
                ft = tcache.Item2;

                _dc.DrawText(
                    ft,
                    GetTextOrigin(style, ref rect, ft));
            }
            else
            {
                var ci = CultureInfo.InvariantCulture;

                var fontStyle = System.Windows.FontStyles.Normal;
                if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Italic))
                {
                    fontStyle = System.Windows.FontStyles.Italic;
                }

                var fontWeight = FontWeights.Regular;
                if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Bold))
                {
                    fontWeight = FontWeights.Bold;
                }

                var tf = new Typeface(
                    new FontFamily(style.TextStyle.FontName),
                    fontStyle,
                    fontWeight,
                    FontStretches.Normal);

                ft = new FormattedText(
                    tbind,
                    ci,
                    ci.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight,
                    tf,
                    style.TextStyle.FontSize > 0.0 ? style.TextStyle.FontSize : double.Epsilon,
                    stroke.Brush, null, TextFormattingMode.Ideal);

                if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Underline) ||
                    style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Strikeout))
                {
                    var decorations = new TextDecorationCollection();

                    if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Underline))
                    {
                        decorations = new TextDecorationCollection(
                            decorations.Union(TextDecorations.Underline));
                    }

                    if (style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Strikeout))
                    {
                        decorations = new TextDecorationCollection(
                            decorations.Union(TextDecorations.Strikethrough));
                    }

                    ft.SetTextDecorations(decorations);
                }

                if (_enableTextCache)
                {
                    var tuple = Tuple.Create(tbind, ft, style);
                    if (_textCache.ContainsKey(text))
                    {
                        _textCache[text] = tuple;
                    }
                    else
                    {
                        _textCache.Add(text, tuple);
                    }
                }

                _dc.DrawText(
                    ft,
                    GetTextOrigin(style, ref rect, ft));
            }
        }