Browse Source

change monospace-detection in FontSelector

newNRvisualizers
Siegfried Pammer 13 years ago
parent
commit
dccd899196
  1. 15
      src/Main/Base/Project/Src/Gui/Components/FontSelector.xaml.cs

15
src/Main/Base/Project/Src/Gui/Components/FontSelector.xaml.cs

@ -15,6 +15,7 @@ using System.Windows.Data;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Threading;
namespace ICSharpCode.SharpDevelop.Gui namespace ICSharpCode.SharpDevelop.Gui
{ {
@ -34,7 +35,6 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
DataContext = Fonts.SystemFontFamilies DataContext = Fonts.SystemFontFamilies
.OrderBy(ff => ff.Source) .OrderBy(ff => ff.Source)
.AsParallel().AsOrdered()
.Select(ff => new FontFamilyInfo(ff)) .Select(ff => new FontFamilyInfo(ff))
.ToArray(); .ToArray();
InitializeComponent(); InitializeComponent();
@ -98,21 +98,26 @@ namespace ICSharpCode.SharpDevelop.Gui
if (fontFamily == null) if (fontFamily == null)
throw new ArgumentNullException("fontFamily"); throw new ArgumentNullException("fontFamily");
this.FontFamily = fontFamily; this.FontFamily = fontFamily;
Task.Run(() => DetectMonospaced(fontFamily)).FireAndForget(); DetectMonospaced();
} }
void DetectMonospaced(FontFamily fontFamily) async void DetectMonospaced()
{
this.IsMonospaced = await Task.Run(() => DetectMonospaced(this.FontFamily));
}
bool DetectMonospaced(FontFamily fontFamily)
{ {
var tf = fontFamily.GetTypefaces().FirstOrDefault(t => t.Style == FontStyles.Normal); var tf = fontFamily.GetTypefaces().FirstOrDefault(t => t.Style == FontStyles.Normal);
if (tf == null) if (tf == null)
return; return false;
// determine if the length of i == m because I see no other way of // determine if the length of i == m because I see no other way of
// getting if a font is monospaced or not. // getting if a font is monospaced or not.
FormattedText formatted = new FormattedText("i.", CultureInfo.InvariantCulture, FlowDirection.LeftToRight, FormattedText formatted = new FormattedText("i.", CultureInfo.InvariantCulture, FlowDirection.LeftToRight,
tf, 12f, Brushes.Black); tf, 12f, Brushes.Black);
FormattedText formatted2 = new FormattedText("mw", CultureInfo.InvariantCulture, FlowDirection.LeftToRight, FormattedText formatted2 = new FormattedText("mw", CultureInfo.InvariantCulture, FlowDirection.LeftToRight,
tf, 12f, Brushes.Black); tf, 12f, Brushes.Black);
this.IsMonospaced = formatted.Width == formatted2.Width; return formatted.Width == formatted2.Width;
} }
public FontFamily FontFamily { get; private set; } public FontFamily FontFamily { get; private set; }

Loading…
Cancel
Save