|
|
|
@ -9,8 +9,9 @@ using System;
@@ -9,8 +9,9 @@ using System;
|
|
|
|
|
using System.IO; |
|
|
|
|
using System.Drawing; |
|
|
|
|
using System.Drawing.Text; |
|
|
|
|
using System.Collections; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Windows.Forms; |
|
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
|
|
using ICSharpCode.SharpDevelop.Internal.ExternalTool; |
|
|
|
|
using ICSharpCode.Core; |
|
|
|
@ -34,31 +35,27 @@ namespace ICSharpCode.SharpDevelop.Gui
@@ -34,31 +35,27 @@ namespace ICSharpCode.SharpDevelop.Gui
|
|
|
|
|
|
|
|
|
|
public Font CurrentFont { |
|
|
|
|
get { |
|
|
|
|
int fontSize = 10; |
|
|
|
|
try { |
|
|
|
|
fontSize = Math.Max(6, Int32.Parse(ControlDictionary["fontSizeComboBox"].Text)); |
|
|
|
|
} catch (Exception) {} |
|
|
|
|
|
|
|
|
|
int index = ((ComboBox)ControlDictionary["fontListComboBox"]).SelectedIndex; |
|
|
|
|
if (index < 0) { |
|
|
|
|
return Font; |
|
|
|
|
} |
|
|
|
|
FontDescriptor fontDescriptor = (FontDescriptor)((ComboBox)ControlDictionary["fontListComboBox"]).Items[index]; |
|
|
|
|
|
|
|
|
|
return new Font(fontDescriptor.Name, |
|
|
|
|
fontSize); |
|
|
|
|
if (helper == null) |
|
|
|
|
return null; |
|
|
|
|
return helper.GetSelectedFont(); |
|
|
|
|
} |
|
|
|
|
set { |
|
|
|
|
int index = 0; |
|
|
|
|
for (int i = 0; i < ((ComboBox)ControlDictionary["fontListComboBox"]).Items.Count; ++i) { |
|
|
|
|
FontDescriptor descriptor = (FontDescriptor)((ComboBox)ControlDictionary["fontListComboBox"]).Items[i]; |
|
|
|
|
if (descriptor.Name == value.Name) { |
|
|
|
|
index = i; |
|
|
|
|
if (helper == null) { |
|
|
|
|
helper = new FontSelectionPanelHelper((ComboBox)ControlDictionary["fontSizeComboBox"], (ComboBox)ControlDictionary["fontListComboBox"], value); |
|
|
|
|
helper.StartThread(); |
|
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).MeasureItem += helper.MeasureComboBoxItem; |
|
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).DrawItem += helper.ComboBoxDrawItem; |
|
|
|
|
} else { |
|
|
|
|
int index = 0; |
|
|
|
|
for (int i = 0; i < ((ComboBox)ControlDictionary["fontListComboBox"]).Items.Count; ++i) { |
|
|
|
|
FontSelectionPanelHelper.FontDescriptor descriptor = (FontSelectionPanelHelper.FontDescriptor)((ComboBox)ControlDictionary["fontListComboBox"]).Items[i]; |
|
|
|
|
if (descriptor.Name == value.Name) { |
|
|
|
|
index = i; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).SelectedIndex = index; |
|
|
|
|
} |
|
|
|
|
((ComboBox)ControlDictionary["fontSizeComboBox"]).Text = value.Size.ToString(); |
|
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).SelectedIndex = index; |
|
|
|
|
UpdateFontPreviewLabel(this, EventArgs.Empty); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -66,38 +63,18 @@ namespace ICSharpCode.SharpDevelop.Gui
@@ -66,38 +63,18 @@ namespace ICSharpCode.SharpDevelop.Gui
|
|
|
|
|
{ |
|
|
|
|
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.FontSelectionPanel.xfrm")); |
|
|
|
|
|
|
|
|
|
InstalledFontCollection installedFontCollection = new InstalledFontCollection(); |
|
|
|
|
|
|
|
|
|
for (int i = 6; i <= 24; ++i) { |
|
|
|
|
((ComboBox)ControlDictionary["fontSizeComboBox"]).Items.Add(i); |
|
|
|
|
} |
|
|
|
|
((ComboBox)ControlDictionary["fontSizeComboBox"]).TextChanged += new EventHandler(UpdateFontPreviewLabel); |
|
|
|
|
foreach (FontFamily fontFamily in installedFontCollection.Families) { |
|
|
|
|
if (fontFamily.IsStyleAvailable(FontStyle.Regular) && fontFamily.IsStyleAvailable(FontStyle.Bold) && fontFamily.IsStyleAvailable(FontStyle.Italic)) { |
|
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).Items.Add(new FontDescriptor(fontFamily)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
((ComboBox)ControlDictionary["fontSizeComboBox"]).Enabled = false; |
|
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).Enabled = false; |
|
|
|
|
|
|
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).TextChanged += new EventHandler(UpdateFontPreviewLabel); |
|
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).SelectedIndexChanged += new EventHandler(UpdateFontPreviewLabel); |
|
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.MeasureComboBoxItem); |
|
|
|
|
((ComboBox)ControlDictionary["fontListComboBox"]).DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ComboBoxDrawItem); |
|
|
|
|
|
|
|
|
|
boldComboBoxFont = new Font(ControlDictionary["fontListComboBox"].Font, FontStyle.Bold); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MeasureComboBoxItem(object sender, System.Windows.Forms.MeasureItemEventArgs e) |
|
|
|
|
{ |
|
|
|
|
ComboBox comboBox = (ComboBox)sender; |
|
|
|
|
if (e.Index >= 0) { |
|
|
|
|
FontDescriptor fontDescriptor = (FontDescriptor)comboBox.Items[e.Index]; |
|
|
|
|
SizeF size = e.Graphics.MeasureString(fontDescriptor.Name, comboBox.Font); |
|
|
|
|
e.ItemWidth = (int)size.Width; |
|
|
|
|
e.ItemHeight = (int)comboBox.Font.Height; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
FontSelectionPanelHelper helper; |
|
|
|
|
|
|
|
|
|
public static Font ParseFont(string font) |
|
|
|
|
{ |
|
|
|
@ -110,25 +87,107 @@ namespace ICSharpCode.SharpDevelop.Gui
@@ -110,25 +87,107 @@ namespace ICSharpCode.SharpDevelop.Gui
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static StringFormat drawStringFormat = new StringFormat(StringFormatFlags.NoWrap); |
|
|
|
|
static Font boldComboBoxFont; |
|
|
|
|
void UpdateFontPreviewLabel(object sender, EventArgs e) |
|
|
|
|
{ |
|
|
|
|
helper.UpdateFontPreviewLabel(ControlDictionary["fontPreviewLabel"]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class FontSelectionPanelHelper |
|
|
|
|
{ |
|
|
|
|
ComboBox fontSizeComboBox, fontListComboBox; |
|
|
|
|
Font defaultFont; |
|
|
|
|
|
|
|
|
|
public FontSelectionPanelHelper(ComboBox fontSizeComboBox, ComboBox fontListComboBox, Font defaultFont) |
|
|
|
|
{ |
|
|
|
|
this.fontSizeComboBox = fontSizeComboBox; |
|
|
|
|
this.fontListComboBox = fontListComboBox; |
|
|
|
|
this.defaultFont = defaultFont; |
|
|
|
|
boldComboBoxFont = new Font(fontListComboBox.Font, FontStyle.Bold); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void StartThread() |
|
|
|
|
{ |
|
|
|
|
Thread thread = new Thread(DetectMonospacedThread); |
|
|
|
|
thread.IsBackground = true; |
|
|
|
|
thread.Start(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ComboBoxDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) |
|
|
|
|
void DetectMonospacedThread() |
|
|
|
|
{ |
|
|
|
|
Thread.Sleep(0); // first allow UI thread to do some work
|
|
|
|
|
DebugTimer.Start(); |
|
|
|
|
InstalledFontCollection installedFontCollection = new InstalledFontCollection(); |
|
|
|
|
Font currentFont = defaultFont; |
|
|
|
|
List<FontDescriptor> fonts = new List<FontDescriptor>(); |
|
|
|
|
|
|
|
|
|
int index = 0; |
|
|
|
|
foreach (FontFamily fontFamily in installedFontCollection.Families) { |
|
|
|
|
if (fontFamily.IsStyleAvailable(FontStyle.Regular) && fontFamily.IsStyleAvailable(FontStyle.Bold) && fontFamily.IsStyleAvailable(FontStyle.Italic)) { |
|
|
|
|
if (fontFamily.Name == currentFont.Name) { |
|
|
|
|
index = fonts.Count; |
|
|
|
|
} |
|
|
|
|
fonts.Add(new FontDescriptor(fontFamily)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
DebugTimer.Stop("Getting installed fonts"); |
|
|
|
|
WorkbenchSingleton.SafeThreadAsyncCall( |
|
|
|
|
delegate { |
|
|
|
|
fontListComboBox.Items.AddRange(fonts.ToArray()); |
|
|
|
|
fontSizeComboBox.Enabled = true; |
|
|
|
|
fontListComboBox.Enabled = true; |
|
|
|
|
fontListComboBox.SelectedIndex = index; |
|
|
|
|
fontSizeComboBox.Text = currentFont.Size.ToString(); |
|
|
|
|
}); |
|
|
|
|
DebugTimer.Start(); |
|
|
|
|
using (Bitmap newBitmap = new Bitmap(1, 1)) { |
|
|
|
|
using (Graphics g = Graphics.FromImage(newBitmap)) { |
|
|
|
|
foreach (FontDescriptor fd in fonts) { |
|
|
|
|
fd.DetectMonospaced(g); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
DebugTimer.Stop("Detect Monospaced"); |
|
|
|
|
fontListComboBox.Invalidate(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal void MeasureComboBoxItem(object sender, System.Windows.Forms.MeasureItemEventArgs e) |
|
|
|
|
{ |
|
|
|
|
ComboBox comboBox = (ComboBox)sender; |
|
|
|
|
e.DrawBackground(); |
|
|
|
|
if (e.Index >= 0) { |
|
|
|
|
FontDescriptor fontDescriptor = (FontDescriptor)comboBox.Items[e.Index]; |
|
|
|
|
Rectangle drawingRect = new Rectangle(e.Bounds.X, |
|
|
|
|
e.Bounds.Y, |
|
|
|
|
e.Bounds.Width, |
|
|
|
|
e.Bounds.Height); |
|
|
|
|
|
|
|
|
|
Brush drawItemBrush = SystemBrushes.WindowText; |
|
|
|
|
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { |
|
|
|
|
drawItemBrush = SystemBrushes.HighlightText; |
|
|
|
|
} |
|
|
|
|
SizeF size = e.Graphics.MeasureString(fontDescriptor.Name, comboBox.Font); |
|
|
|
|
e.ItemWidth = (int)size.Width; |
|
|
|
|
e.ItemHeight = (int)comboBox.Font.Height; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static StringFormat drawStringFormat = new StringFormat(StringFormatFlags.NoWrap); |
|
|
|
|
Font boldComboBoxFont; |
|
|
|
|
|
|
|
|
|
internal void ComboBoxDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) |
|
|
|
|
{ |
|
|
|
|
ComboBox comboBox = (ComboBox)sender; |
|
|
|
|
e.DrawBackground(); |
|
|
|
|
|
|
|
|
|
Rectangle drawingRect = new Rectangle(e.Bounds.X, |
|
|
|
|
e.Bounds.Y, |
|
|
|
|
e.Bounds.Width, |
|
|
|
|
e.Bounds.Height); |
|
|
|
|
|
|
|
|
|
Brush drawItemBrush = SystemBrushes.WindowText; |
|
|
|
|
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { |
|
|
|
|
drawItemBrush = SystemBrushes.HighlightText; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (comboBox.Enabled == false) { |
|
|
|
|
e.Graphics.DrawString(ResourceService.GetString("ICSharpCode.SharpDevelop.Gui.Pads.ClassScout.LoadingNode"), |
|
|
|
|
comboBox.Font, |
|
|
|
|
drawItemBrush, |
|
|
|
|
drawingRect, |
|
|
|
|
drawStringFormat); |
|
|
|
|
} else if (e.Index >= 0) { |
|
|
|
|
FontDescriptor fontDescriptor = (FontDescriptor)comboBox.Items[e.Index]; |
|
|
|
|
e.Graphics.DrawString(fontDescriptor.Name, |
|
|
|
|
fontDescriptor.IsMonospaced ? boldComboBoxFont : comboBox.Font, |
|
|
|
|
drawItemBrush, |
|
|
|
@ -138,50 +197,57 @@ namespace ICSharpCode.SharpDevelop.Gui
@@ -138,50 +197,57 @@ namespace ICSharpCode.SharpDevelop.Gui
|
|
|
|
|
e.DrawFocusRectangle(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class FontDescriptor |
|
|
|
|
public Font GetSelectedFont() |
|
|
|
|
{ |
|
|
|
|
FontFamily fontFamily; |
|
|
|
|
bool isMonospaced = false; |
|
|
|
|
bool initializedMonospace = false; |
|
|
|
|
public string Name { |
|
|
|
|
get { |
|
|
|
|
return fontFamily.Name; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!fontListComboBox.Enabled) |
|
|
|
|
return null; |
|
|
|
|
int fontSize = 10; |
|
|
|
|
try { |
|
|
|
|
fontSize = Math.Max(6, Int32.Parse(fontSizeComboBox.Text)); |
|
|
|
|
} catch (Exception) {} |
|
|
|
|
|
|
|
|
|
public bool IsMonospaced { |
|
|
|
|
get { |
|
|
|
|
if (!initializedMonospace) { |
|
|
|
|
isMonospaced = GetIsMonospaced(fontFamily); |
|
|
|
|
} |
|
|
|
|
return isMonospaced; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
FontDescriptor fontDescriptor = (FontDescriptor)fontListComboBox.Items[fontListComboBox.SelectedIndex]; |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return new Font(fontDescriptor.Name, |
|
|
|
|
fontSize); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void UpdateFontPreviewLabel(Control fontPreviewLabel) |
|
|
|
|
{ |
|
|
|
|
Font currentFont = GetSelectedFont(); |
|
|
|
|
fontPreviewLabel.Visible = currentFont != null; |
|
|
|
|
if (currentFont != null) { |
|
|
|
|
fontPreviewLabel.Font = currentFont; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public class FontDescriptor |
|
|
|
|
{ |
|
|
|
|
FontFamily fontFamily; |
|
|
|
|
internal string Name; |
|
|
|
|
internal bool IsMonospaced; |
|
|
|
|
|
|
|
|
|
public FontDescriptor(FontFamily fontFamily) |
|
|
|
|
{ |
|
|
|
|
this.fontFamily = fontFamily; |
|
|
|
|
this.Name = fontFamily.Name; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void UpdateFontPreviewLabel(object sender, EventArgs e) |
|
|
|
|
{ |
|
|
|
|
ControlDictionary["fontPreviewLabel"].Font = CurrentFont; |
|
|
|
|
internal void DetectMonospaced(Graphics g) |
|
|
|
|
{ |
|
|
|
|
this.IsMonospaced = DetectMonospaced(g, fontFamily); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static bool DetectMonospaced(Graphics g, FontFamily fontFamily) |
|
|
|
|
{ |
|
|
|
|
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 = TextRenderer.MeasureText("i.", f).Width; |
|
|
|
|
int w2 = TextRenderer.MeasureText("mw", f).Width; |
|
|
|
|
return w1 == w2; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|