mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
BUG-1770: Fix problems when a font doesn't want to draw itself. [skip ci]
This commit is contained in:
parent
71ff4c6286
commit
29c7f466ec
1 changed files with 28 additions and 11 deletions
|
@ -57,30 +57,47 @@ namespace Greenshot.Controls {
|
||||||
|
|
||||||
if (e.Index > -1) {
|
if (e.Index > -1) {
|
||||||
FontFamily fontFamily = Items[e.Index] as FontFamily;
|
FontFamily fontFamily = Items[e.Index] as FontFamily;
|
||||||
FontStyle fs = FontStyle.Regular;
|
FontStyle fontStyle = FontStyle.Regular;
|
||||||
if (!fontFamily.IsStyleAvailable(FontStyle.Regular)) {
|
if (!fontFamily.IsStyleAvailable(FontStyle.Regular)) {
|
||||||
if (fontFamily.IsStyleAvailable(FontStyle.Bold)) {
|
if (fontFamily.IsStyleAvailable(FontStyle.Bold)) {
|
||||||
fs = FontStyle.Bold;
|
fontStyle = FontStyle.Bold;
|
||||||
} else if (fontFamily.IsStyleAvailable(FontStyle.Italic)) {
|
} else if (fontFamily.IsStyleAvailable(FontStyle.Italic)) {
|
||||||
fs = FontStyle.Italic;
|
fontStyle = FontStyle.Italic;
|
||||||
} else if (fontFamily.IsStyleAvailable(FontStyle.Strikeout)) {
|
} else if (fontFamily.IsStyleAvailable(FontStyle.Strikeout)) {
|
||||||
fs = FontStyle.Strikeout;
|
fontStyle = FontStyle.Strikeout;
|
||||||
} else if (fontFamily.IsStyleAvailable(FontStyle.Underline)) {
|
} else if (fontFamily.IsStyleAvailable(FontStyle.Underline)) {
|
||||||
fs = FontStyle.Underline;
|
fontStyle = FontStyle.Underline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
using (Font font = new Font(fontFamily, this.Font.Size + 5, fs, GraphicsUnit.Pixel)) {
|
try {
|
||||||
// Make sure the text is visible by centering it in the line
|
DrawText(e.Graphics, fontFamily, fontStyle, e.Bounds, fontFamily.Name);
|
||||||
using(StringFormat stringFormat = new StringFormat()) {
|
} catch {
|
||||||
stringFormat.LineAlignment = StringAlignment.Center;
|
// If the drawing failed, BUG-1770 seems to have a weird case that causes: Font 'Lucida Sans Typewriter' does not support style 'Regular'
|
||||||
e.Graphics.DrawString(fontFamily.Name, font, Brushes.Black, e.Bounds, stringFormat);
|
DrawText(e.Graphics, FontFamily.GenericSansSerif, FontStyle.Regular, e.Bounds, fontFamily.Name);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Uncomment this if you actually like the way the focus rectangle looks
|
// Uncomment this if you actually like the way the focus rectangle looks
|
||||||
//e.DrawFocusRectangle ();
|
//e.DrawFocusRectangle ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper method to draw the string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="graphics"></param>
|
||||||
|
/// <param name="fontFamily"></param>
|
||||||
|
/// <param name="fontStyle"></param>
|
||||||
|
/// <param name="bounds"></param>
|
||||||
|
/// <param name="text"></param>
|
||||||
|
private void DrawText(Graphics graphics, FontFamily fontFamily, FontStyle fontStyle, Rectangle bounds, string text) {
|
||||||
|
using (Font font = new Font(fontFamily, this.Font.Size + 5, fontStyle, GraphicsUnit.Pixel)) {
|
||||||
|
// Make sure the text is visible by centering it in the line
|
||||||
|
using (StringFormat stringFormat = new StringFormat()) {
|
||||||
|
stringFormat.LineAlignment = StringAlignment.Center;
|
||||||
|
graphics.DrawString(text, font, Brushes.Black, bounds, stringFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BindableToolStripComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
void BindableToolStripComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
||||||
if (PropertyChanged != null) {
|
if (PropertyChanged != null) {
|
||||||
PropertyChanged(this, new PropertyChangedEventArgs("Text"));
|
PropertyChanged(this, new PropertyChangedEventArgs("Text"));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue