Browse Source

Font selection panel is now much faster in initalization.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@48 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Mike Krüger 21 years ago
parent
commit
aebdd74371
  1. 17
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs
  2. 57
      src/Main/Base/Project/Src/Gui/Components/FontSelectionPanel.cs
  3. 1
      src/Main/Base/Project/Src/Services/ParserService/IProjectContent.cs

17
src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs

@ -24,15 +24,6 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
ICSharpCode.NRefactory.Parser.LookupTableVisitor lookupTableVisitor; ICSharpCode.NRefactory.Parser.LookupTableVisitor lookupTableVisitor;
IProjectContent projectContent = null; IProjectContent projectContent = null;
public IProjectContent ProjectContent {
get {
return projectContent;
}
set {
projectContent = value;
}
}
bool showStatic = false; bool showStatic = false;
bool inNew = false; bool inNew = false;
@ -42,6 +33,14 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
int caretLine; int caretLine;
int caretColumn; int caretColumn;
public IProjectContent ProjectContent {
get {
return projectContent;
}
set {
projectContent = value;
}
}
public ICompilationUnit CompilationUnit { public ICompilationUnit CompilationUnit {
get { get {

57
src/Main/Base/Project/Src/Gui/Components/FontSelectionPanel.cs

@ -65,12 +65,12 @@ namespace ICSharpCode.SharpDevelop.Gui
((ComboBox)ControlDictionary["fontSizeComboBox"]).Items.Add(i); ((ComboBox)ControlDictionary["fontSizeComboBox"]).Items.Add(i);
} }
((ComboBox)ControlDictionary["fontSizeComboBox"]).TextChanged += new EventHandler(UpdateFontPreviewLabel); ((ComboBox)ControlDictionary["fontSizeComboBox"]).TextChanged += new EventHandler(UpdateFontPreviewLabel);
foreach (FontFamily fontFamily in installedFontCollection.Families) { foreach (FontFamily fontFamily in installedFontCollection.Families) {
if (fontFamily.IsStyleAvailable(FontStyle.Regular) && fontFamily.IsStyleAvailable(FontStyle.Bold) && fontFamily.IsStyleAvailable(FontStyle.Italic)) { if (fontFamily.IsStyleAvailable(FontStyle.Regular) && fontFamily.IsStyleAvailable(FontStyle.Bold) && fontFamily.IsStyleAvailable(FontStyle.Italic)) {
((ComboBox)ControlDictionary["fontListComboBox"]).Items.Add(new FontDescriptor(fontFamily.Name, IsMonospaced(fontFamily))); ((ComboBox)ControlDictionary["fontListComboBox"]).Items.Add(new FontDescriptor(fontFamily));
} }
} }
Console.WriteLine("GET FONTS DONE!!!");
((ComboBox)ControlDictionary["fontListComboBox"]).TextChanged += new EventHandler(UpdateFontPreviewLabel); ((ComboBox)ControlDictionary["fontListComboBox"]).TextChanged += new EventHandler(UpdateFontPreviewLabel);
((ComboBox)ControlDictionary["fontListComboBox"]).SelectedIndexChanged += new EventHandler(UpdateFontPreviewLabel); ((ComboBox)ControlDictionary["fontListComboBox"]).SelectedIndexChanged += new EventHandler(UpdateFontPreviewLabel);
((ComboBox)ControlDictionary["fontListComboBox"]).MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.MeasureComboBoxItem); ((ComboBox)ControlDictionary["fontListComboBox"]).MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.MeasureComboBoxItem);
@ -91,21 +91,7 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
bool IsMonospaced(FontFamily fontFamily)
{
using (Bitmap newBitmap = new Bitmap(1, 1)) {
using (Graphics g = Graphics.FromImage(newBitmap)) {
using (Font f = new Font(fontFamily, 10)) {
// determine if the length of i == m because I see no other way of
// getting if a font is monospaced or not.
int w1 = (int)g.MeasureString("i.", f).Width;
int w2 = (int)g.MeasureString("mw", f).Width;
return w1 == w2;
}
}
}
}
public static Font ParseFont(string font) public static Font ParseFont(string font)
{ {
try { try {
@ -146,31 +132,42 @@ namespace ICSharpCode.SharpDevelop.Gui
class FontDescriptor class FontDescriptor
{ {
string name; FontFamily fontFamily;
bool isMonospaced; bool isMonospaced = false;
bool initializedMonospace = false;
public string Name { public string Name {
get { get {
return name; return fontFamily.Name;
}
set {
name = value;
} }
} }
public bool IsMonospaced { public bool IsMonospaced {
get { get {
if (!initializedMonospace) {
isMonospaced = GetIsMonospaced(fontFamily);
}
return isMonospaced; return isMonospaced;
} }
set { }
isMonospaced = value;
bool GetIsMonospaced(FontFamily fontFamily)
{
using (Bitmap newBitmap = new Bitmap(1, 1)) {
using (Graphics g = Graphics.FromImage(newBitmap)) {
using (Font f = new Font(fontFamily, 10)) {
// determine if the length of i == m because I see no other way of
// getting if a font is monospaced or not.
int w1 = (int)g.MeasureString("i.", f).Width;
int w2 = (int)g.MeasureString("mw", f).Width;
return w1 == w2;
}
}
} }
} }
public FontDescriptor(string name, bool isMonospaced) public FontDescriptor(FontFamily fontFamily)
{ {
this.name = name; this.fontFamily = fontFamily;
this.isMonospaced = isMonospaced;
} }
} }

1
src/Main/Base/Project/Src/Services/ParserService/IProjectContent.cs

@ -27,6 +27,7 @@ namespace ICSharpCode.Core
XmlDoc XmlDoc { XmlDoc XmlDoc {
get; get;
} }
ICollection<IClass> Classes { ICollection<IClass> Classes {
get; get;
} }

Loading…
Cancel
Save