Ejemplo n.º 1
0
		public ChatFormatter(Typeface typeface, double fontSize, Brush foreground, IDictionary<string,Brush> palette)
		{
			_runProperties = new CustomTextRunProperties(typeface, fontSize, foreground, Brushes.Transparent, false);
			_paraProperties = new CustomParagraphProperties(_runProperties);
			_formatter = TextFormatter.Create(TextFormattingMode.Display);
			_palette = palette;
		}
Ejemplo n.º 2
0
        public override TextRun GetTextRun(int idx)
        {
            if (idx >= _text.Length)
            {
                return(new TextEndOfLine(1));
            }
            var props = _runProperties;
            int end   = _text.Length;

            if (_spans != null)
            {
                var span = _spans.GetSpan(idx);
                if (span.Flags > 0)
                {
                    props = new CustomTextRunProperties(
                        new Typeface(_runProperties.Typeface.FontFamily,
                                     _runProperties.Typeface.Style,
                                     (span.Flags & ChatSpanFlags.Bold) > 0 ? FontWeights.Bold : FontWeights.Normal,
                                     _runProperties.Typeface.Stretch),
                        _runProperties.FontRenderingEmSize,
                        (span.Flags & ChatSpanFlags.Reverse) > 0 ? _background :
                        ((span.Flags & ChatSpanFlags.Foreground) > 0 ? _palette["Color" + span.Foreground] : _runProperties.ForegroundBrush),
                        (span.Flags & ChatSpanFlags.Reverse) > 0 ? _runProperties.ForegroundBrush :
                        ((span.Flags & ChatSpanFlags.Background) > 0 ? _palette["Color" + span.Background] : _runProperties.BackgroundBrush),
                        (span.Flags & ChatSpanFlags.Underline) > 0);
                }
                end = span.End;
            }
            return(new TextCharacters(_text, idx, end - idx, props));
        }
Ejemplo n.º 3
0
 public ChatFormatter(Typeface typeface, double fontSize, Brush foreground, IDictionary <string, Brush> palette)
 {
     _runProperties  = new CustomTextRunProperties(typeface, fontSize, foreground, Brushes.Transparent, false);
     _paraProperties = new CustomParagraphProperties(_runProperties);
     _formatter      = TextFormatter.Create(TextFormattingMode.Display);
     _palette        = palette;
 }
Ejemplo n.º 4
0
        public IEnumerable <TextLine> Format(string text, IChatSpanProvider spans, double width, Brush foreground, Brush background,
                                             TextWrapping textWrapping)
        {
            _text          = text;
            _spans         = spans;
            _background    = background;
            _runProperties = new CustomTextRunProperties(_runProperties.Typeface, _runProperties.FontRenderingEmSize, foreground,
                                                         Brushes.Transparent, false);
            _paraProperties = new CustomParagraphProperties(_runProperties);
            if (width < 0)
            {
                width = 0;
                text  = "";
            }

            int idx = 0;

            while (idx < _text.Length)
            {
                var line = _formatter.FormatLine(this, idx, width, _paraProperties, null);
                idx += line.Length;
                yield return(line);
            }
        }
Ejemplo n.º 5
0
		public IEnumerable<TextLine> Format(string text, IChatSpanProvider spans, double width, Brush foreground, Brush background,
			TextWrapping textWrapping)
		{
			_text = text;
			_spans = spans;
			_background = background;
			_runProperties = new CustomTextRunProperties(_runProperties.Typeface, _runProperties.FontRenderingEmSize, foreground,
				Brushes.Transparent, false);
			_paraProperties = new CustomParagraphProperties(_runProperties);
			if (width < 0)
			{
				width = 0;
				text = "";
			}

			int idx = 0;
			while(idx < _text.Length)
			{
				var line = _formatter.FormatLine(this, idx, width, _paraProperties, null);
				idx += line.Length;
				yield return line;
			}
		}
Ejemplo n.º 6
0
		public override TextRun GetTextRun(int idx)
		{
			if (idx >= _text.Length)
			{
				return new TextEndOfLine(1);
			}
			var props = _runProperties;
			int end = _text.Length;
			if (_spans != null)
			{
				var span = _spans.GetSpan(idx);
				if (span.Flags > 0)
				{
					props = new CustomTextRunProperties(
						new Typeface(_runProperties.Typeface.FontFamily,
							_runProperties.Typeface.Style,
							(span.Flags & ChatSpanFlags.Bold) > 0 ? FontWeights.Bold : FontWeights.Normal,
							_runProperties.Typeface.Stretch),
							_runProperties.FontRenderingEmSize,
							(span.Flags & ChatSpanFlags.Reverse) > 0 ? _background : 
							((span.Flags & ChatSpanFlags.Foreground) > 0 ? _palette["Color"+span.Foreground] : _runProperties.ForegroundBrush),
							(span.Flags & ChatSpanFlags.Reverse) > 0 ? _runProperties.ForegroundBrush :
							((span.Flags & ChatSpanFlags.Background) > 0 ? _palette["Color"+span.Background] : _runProperties.BackgroundBrush),
							(span.Flags & ChatSpanFlags.Underline) > 0);
				}
				end = span.End;
			}
			return new TextCharacters(_text, idx, end - idx, props);
		}