Browse Source

Support for TextFormattingMode.Display in line number margin and other AvalonEdit components using the FormattedText class.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5263 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 16 years ago
parent
commit
a7454197bd
  1. 10
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/LineNumberMargin.cs
  2. 6
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingElementGenerator.cs
  3. 6
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/NewLineElementGenerator.cs
  4. 15
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/SingleCharacterElementGenerator.cs
  5. 40
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/TextFormatterFactory.cs

10
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/LineNumberMargin.cs

@ -41,10 +41,9 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -41,10 +41,9 @@ namespace ICSharpCode.AvalonEdit.Editing
typeface = this.CreateTypeface();
emSize = (double)GetValue(TextBlock.FontSizeProperty);
FormattedText text = new FormattedText(
FormattedText text = TextFormatterFactory.CreateFormattedText(
this,
new string('9', maxLineNumberLength),
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
typeface,
emSize,
(Brush)GetValue(Control.ForegroundProperty)
@ -61,10 +60,9 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -61,10 +60,9 @@ namespace ICSharpCode.AvalonEdit.Editing
var foreground = (Brush)GetValue(Control.ForegroundProperty);
foreach (VisualLine line in textView.VisualLines) {
int lineNumber = line.FirstDocumentLine.LineNumber;
FormattedText text = new FormattedText(
FormattedText text = TextFormatterFactory.CreateFormattedText(
this,
lineNumber.ToString(CultureInfo.CurrentCulture),
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
typeface, emSize, foreground
);
drawingContext.DrawText(text, new Point(renderSize.Width - text.Width,

6
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingElementGenerator.cs

@ -11,6 +11,7 @@ using System.Windows.Media; @@ -11,6 +11,7 @@ using System.Windows.Media;
using System.Windows.Media.TextFormatting;
using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.AvalonEdit.Utils;
namespace ICSharpCode.AvalonEdit.Folding
{
@ -63,10 +64,9 @@ namespace ICSharpCode.AvalonEdit.Folding @@ -63,10 +64,9 @@ namespace ICSharpCode.AvalonEdit.Folding
if (foldedUntil > offset) {
if (string.IsNullOrEmpty(title))
title = "...";
FormattedText text = new FormattedText(
FormattedText text = TextFormatterFactory.CreateFormattedText(
CurrentContext.TextView,
title,
CurrentContext.GlobalTextRunProperties.CultureInfo,
FlowDirection.LeftToRight,
CurrentContext.GlobalTextRunProperties.Typeface,
CurrentContext.GlobalTextRunProperties.FontRenderingEmSize,
Brushes.Gray

6
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/NewLineElementGenerator.cs

@ -11,6 +11,7 @@ using System.Windows.Documents; @@ -11,6 +11,7 @@ using System.Windows.Documents;
using System.Windows.Media;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Utils;
namespace ICSharpCode.AvalonEdit.Rendering
{
@ -57,10 +58,9 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -57,10 +58,9 @@ namespace ICSharpCode.AvalonEdit.Rendering
} else {
return null;
}
FormattedText text = new FormattedText(
FormattedText text = TextFormatterFactory.CreateFormattedText(
CurrentContext.TextView,
newlineText,
CurrentContext.GlobalTextRunProperties.CultureInfo,
FlowDirection.LeftToRight,
CurrentContext.GlobalTextRunProperties.Typeface,
CurrentContext.GlobalTextRunProperties.FontRenderingEmSize,
Brushes.LightGray

15
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/SingleCharacterElementGenerator.cs

@ -92,30 +92,27 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -92,30 +92,27 @@ namespace ICSharpCode.AvalonEdit.Rendering
{
char c = CurrentContext.Document.GetCharAt(offset);
if (ShowSpaces && c == ' ') {
FormattedText text = new FormattedText(
FormattedText text = TextFormatterFactory.CreateFormattedText(
CurrentContext.TextView,
"\u00B7",
CurrentContext.GlobalTextRunProperties.CultureInfo,
FlowDirection.LeftToRight,
CurrentContext.GlobalTextRunProperties.Typeface,
CurrentContext.GlobalTextRunProperties.FontRenderingEmSize,
Brushes.LightGray
);
return new SpaceTextElement(text);
} else if (ShowTabs && c == '\t') {
FormattedText text = new FormattedText(
FormattedText text = TextFormatterFactory.CreateFormattedText(
CurrentContext.TextView,
"\u00BB",
CurrentContext.GlobalTextRunProperties.CultureInfo,
FlowDirection.LeftToRight,
CurrentContext.GlobalTextRunProperties.Typeface,
CurrentContext.GlobalTextRunProperties.FontRenderingEmSize,
Brushes.LightGray
);
return new TabTextElement(text);
} else if (ShowBoxForControlCharacters && char.IsControl(c)) {
FormattedText text = new FormattedText(
FormattedText text = TextFormatterFactory.CreateFormattedText(
CurrentContext.TextView,
TextUtilities.GetControlCharacterName(c),
CurrentContext.GlobalTextRunProperties.CultureInfo,
FlowDirection.LeftToRight,
CurrentContext.GlobalTextRunProperties.Typeface,
CurrentContext.GlobalTextRunProperties.FontRenderingEmSize * 0.9,
Brushes.White

40
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/TextFormatterFactory.cs

@ -6,8 +6,11 @@ @@ -6,8 +6,11 @@
// </file>
using System;
using System.Globalization;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
namespace ICSharpCode.AvalonEdit.Utils
@ -46,5 +49,42 @@ namespace ICSharpCode.AvalonEdit.Utils @@ -46,5 +49,42 @@ namespace ICSharpCode.AvalonEdit.Utils
// return dp == TextOptions.TextFormattingModeProperty;
return dp == TextFormattingModeProperty && TextFormattingModeProperty != null;
}
public static FormattedText CreateFormattedText(FrameworkElement element, string text, Typeface typeface, double? emSize, Brush foreground)
{
if (element == null)
throw new ArgumentNullException("element");
if (text == null)
throw new ArgumentNullException("text");
if (typeface == null)
typeface = element.CreateTypeface();
if (emSize == null)
emSize = TextBlock.GetFontSize(element);
if (foreground == null)
foreground = TextBlock.GetForeground(element);
if (TextFormattingModeProperty != null) {
object formattingMode = element.GetValue(TextFormattingModeProperty);
return (FormattedText)Activator.CreateInstance(
typeof(FormattedText),
text,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
typeface,
emSize,
foreground,
null,
formattingMode
);
} else {
return new FormattedText(
text,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
typeface,
emSize.Value,
foreground
);
}
}
}
}

Loading…
Cancel
Save