예제 #1
0
        public override void AddTo(System.Windows.Documents.InlineCollection inlines)
        {
            var errorText = new Run(Error);

            errorText.Foreground = Brushes.Red;
            inlines.Add(errorText);

            if (!String.IsNullOrEmpty(Detail))
            {
                var detailText = new Run(Detail);
                detailText.Foreground = Brushes.Gray;

                inlines.Add(new LineBreak());
                inlines.Add(detailText);
            }
        }
예제 #2
0
 void FlushText(SWD.InlineCollection col, string text, ref int i, int pos)
 {
     if (pos > i)
     {
         col.Add(text.Substring(i, pos - i));
         i = pos;
     }
 }
예제 #3
0
        public override void AddTo(System.Windows.Documents.InlineCollection inlines)
        {
            string text = String.Format("[{0}] {1}", Stamp.ToShortTimeString(), Info);

            var run = new Run(text);

            run.Foreground = Brushes.DarkGray;
            inlines.Add(run);
        }
예제 #4
0
        void GenerateBlocks(SWD.InlineCollection col, string text, ref int i, int spanEnd, List <Drawing.TextAttribute> attributes, ref int attrIndex)
        {
            while (attrIndex < attributes.Count)
            {
                var at = attributes[attrIndex];
                if (at.StartIndex > spanEnd)
                {
                    FlushText(col, text, ref i, spanEnd);
                    return;
                }

                FlushText(col, text, ref i, at.StartIndex);

                var s = new SWD.Span();

                if (at is Drawing.BackgroundTextAttribute)
                {
                    s.Background = new SWM.SolidColorBrush(((Drawing.BackgroundTextAttribute)at).Color.ToWpfColor());
                }
                else if (at is Drawing.FontWeightTextAttribute)
                {
                    s.FontWeight = ((Drawing.FontWeightTextAttribute)at).Weight.ToWpfFontWeight();
                }
                else if (at is Drawing.FontStyleTextAttribute)
                {
                    s.FontStyle = ((Drawing.FontStyleTextAttribute)at).Style.ToWpfFontStyle();
                }
                else if (at is Drawing.UnderlineTextAttribute)
                {
                    var xa  = (Drawing.UnderlineTextAttribute)at;
                    var dec = new TextDecoration(TextDecorationLocation.Underline, null, 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended);
                    s.TextDecorations.Add(dec);
                }
                else if (at is Drawing.StrikethroughTextAttribute)
                {
                    var xa  = (Drawing.StrikethroughTextAttribute)at;
                    var dec = new TextDecoration(TextDecorationLocation.Strikethrough, null, 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended);
                    s.TextDecorations.Add(dec);
                }
                else if (at is Drawing.FontTextAttribute)
                {
                    var xa = (Drawing.FontTextAttribute)at;
                    s.FontFamily  = new SWM.FontFamily(xa.Font.Family);
                    s.FontSize    = WpfFontBackendHandler.GetPointsFromDeviceUnits(xa.Font.Size);
                    s.FontStretch = xa.Font.Stretch.ToWpfFontStretch();
                    s.FontStyle   = xa.Font.Style.ToWpfFontStyle();
                    s.FontWeight  = xa.Font.Weight.ToWpfFontWeight();
                }
                else if (at is Drawing.ColorTextAttribute)
                {
                    s.Foreground = new SWM.SolidColorBrush(((Drawing.ColorTextAttribute)at).Color.ToWpfColor());
                }
                else if (at is Drawing.LinkTextAttribute)
                {
                    var link = new SWD.Hyperlink()
                    {
                        NavigateUri = ((Drawing.LinkTextAttribute)at).Target
                    };
                    link.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(link_RequestNavigate);
                    s = link;
                }

                col.Add(s);

                var max = i + at.Count;
                if (max > spanEnd)
                {
                    max = spanEnd;
                }

                attrIndex++;
                GenerateBlocks(s.Inlines, text, ref i, i + at.Count, attributes, ref attrIndex);
            }
            FlushText(col, text, ref i, spanEnd);
        }