Browse Source

Remove dependency to System.Drawing.Font.

DefaultFont is stored as two Property's (FontSize and FontFamily)
newNRvisualizers
Peter Forstmeier 13 years ago
parent
commit
f0ef718865
  1. 4
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/GeneralEditorOptions.xaml.cs
  2. 8
      src/Main/Base/Project/Src/Gui/Components/FontSelector.xaml.cs
  3. 40
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/OutputWindowOptionsPanelXaml.xaml.cs
  4. 14
      src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/CompilerMessageView.cs

4
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/GeneralEditorOptions.xaml.cs

@ -31,14 +31,14 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -31,14 +31,14 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
base.LoadOptions();
CodeEditorOptions options = CodeEditorOptions.Instance;
fontSelectionPanel.SelectedFontName = options.FontFamily;
fontSelectionPanel.SelectedFontSize = SDFontSizeConverter.FromDouble(options.FontSize);
fontSelectionPanel.SelectedFontSize = SDFontSizeConverter.ToWinFormsFontSize(options.FontSize);
}
public override bool SaveOptions()
{
CodeEditorOptions options = CodeEditorOptions.Instance;
options.FontFamily = fontSelectionPanel.SelectedFontName;
options.FontSize = SDFontSizeConverter.ToDouble(fontSelectionPanel.SelectedFontSize);
options.FontSize = SDFontSizeConverter.ToWpfFontSize(fontSelectionPanel.SelectedFontSize);
return base.SaveOptions();
}
}

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

@ -152,7 +152,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -152,7 +152,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (value == null)
throw new ArgumentNullException("value");
if (value is int)
return ToDouble((int)value);
return ToWpfFontSize((int)value);
throw new NotSupportedException("Cannot convert value of type " + value.GetType());
}
@ -161,16 +161,16 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -161,16 +161,16 @@ namespace ICSharpCode.SharpDevelop.Gui
if (value == null)
throw new ArgumentNullException("value");
if (value is double)
return FromDouble((double)value);
return ToWinFormsFontSize((double)value);
throw new NotSupportedException("Cannot convert value of type " + value.GetType());
}
public static int FromDouble(double value)
public static int ToWinFormsFontSize(double value)
{
return (int)Math.Round(value * 72.0 / 96.0);
}
public static double ToDouble(int value)
public static double ToWpfFontSize(int value)
{
return Math.Round(value * 96.0 / 72.0);
}

40
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/OutputWindowOptionsPanelXaml.xaml.cs

@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Windows.Media;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
@ -18,6 +18,9 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -18,6 +18,9 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
public partial class OutputWindowOptionsPanelXaml : OptionPanel
{
public static readonly string OutputWindowsProperty = "SharpDevelop.UI.OutputWindowOptions";
private static readonly string FontFamilyName = "FontFamily";
private static readonly string FontSizeName = "FontSize";
public OutputWindowOptionsPanelXaml()
{
@ -31,38 +34,27 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -31,38 +34,27 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
base.LoadOptions();
var properties = PropertyService.NestedProperties(OutputWindowsProperty);
WordWrap = properties.Get("WordWrap", true);
var fontStr = properties.Get("DefaultFont", SD.WinForms.DefaultMonospacedFont.ToString()).ToString();
var font = ParseFont(fontStr);
fontSelectionPanel.SelectedFontFamily = new System.Windows.Media.FontFamily(font.Name);
fontSelectionPanel.SelectedFontSize = (int)font.Size;
font.Dispose();
var fontDescription = OutputWindowOptionsPanelXaml.DefaultFontDescription();
fontSelectionPanel.SelectedFontFamily = new FontFamily(fontDescription.Item1);
fontSelectionPanel.SelectedFontSize = fontDescription.Item2;
}
public static Font ParseFont(string font)
public override bool SaveOptions()
{
try {
string[] descr = font.Split(new char[]{',', '='});
return new Font(descr[1], Single.Parse(descr[3]));
} catch (Exception ex) {
LoggingService.Warn(ex);
return SD.WinForms.DefaultMonospacedFont;
}
var properties = PropertyService.NestedProperties(OutputWindowsProperty);
properties.Set("WordWrap", WordWrap);
properties.Set(FontFamilyName,fontSelectionPanel.SelectedFontFamily);
properties.Set(FontSizeName,fontSelectionPanel.SelectedFontSize);
return base.SaveOptions();
}
public override bool SaveOptions()
public static Tuple<string,int> DefaultFontDescription()
{
var properties = PropertyService.NestedProperties(OutputWindowsProperty);
properties.Set("WordWrap", WordWrap);
var font = new Font(new System.Drawing.FontFamily(fontSelectionPanel.SelectedFontName),
(float)fontSelectionPanel.SelectedFontSize);
if (font != null) {
properties.Set("DefaultFont", font.ToString());
}
font.Dispose();
return base.SaveOptions();
return new Tuple<string,int>(properties.Get(FontFamilyName,"Consolas"),properties.Get(FontSizeName,13));
}

14
src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/CompilerMessageView.cs

@ -9,7 +9,6 @@ using System.Linq; @@ -9,7 +9,6 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
@ -210,8 +209,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -210,8 +209,7 @@ namespace ICSharpCode.SharpDevelop.Gui
properties = PropertyService.NestedProperties(OutputWindowOptionsPanelXaml.OutputWindowsProperty);
SetTextEditorFont();
// textEditor.FontFamily = new FontFamily(font.FontFamily.Name);
// textEditor.FontSize = Math.Round(font.Size * 96.0 / 72.0);
properties.PropertyChanged += new PropertyChangedEventHandler(PropertyChanged);
MessageViewLinkElementGenerator.RegisterGenerators(textEditor.TextArea.TextView);
@ -247,10 +245,9 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -247,10 +245,9 @@ namespace ICSharpCode.SharpDevelop.Gui
private void SetTextEditorFont()
{
var font = OutputWindowOptionsPanelXaml.ParseFont(properties.Get("DefaultFont",
SD.WinForms.DefaultMonospacedFont.ToString()).ToString());
textEditor.FontFamily = new FontFamily(font.FontFamily.Name);
textEditor.FontSize = Math.Round(font.Size * 96.0 / 72.0);
var fontDescription = OutputWindowOptionsPanelXaml.DefaultFontDescription();
textEditor.FontFamily = new FontFamily(fontDescription.Item1);
textEditor.FontSize = fontDescription.Item2;
}
#region Category handling
@ -414,8 +411,6 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -414,8 +411,6 @@ namespace ICSharpCode.SharpDevelop.Gui
}
if (e.PropertyName == "DefaultFont") {
SetTextEditorFont();
// textEditor.FontFamily = new FontFamily(font.FontFamily.Name);
// textEditor.FontSize = Math.Round(font.Size * 96.0 / 72.0);
}
}
@ -437,6 +432,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -437,6 +432,7 @@ namespace ICSharpCode.SharpDevelop.Gui
public event EventHandler SelectedCategoryIndexChanged;
#region ICSharpCode.SharpDevelop.Gui.IClipboardHandler interface implementation
public bool EnableCut {
get {
return false;

Loading…
Cancel
Save