private Dictionary<string, Font> _fontCache;
_fontCache = new Dictionary<string, Font>();
protected virtual Font GetFont(string fontFamilyName)
{
lock (_fontCache)
{
if (!_fontCache.ContainsKey(fontFamilyName))
{
Font font;
font = this.GetFont(fontFamilyName, FontStyle.Regular);
if (font == null)
font = this.GetFont(fontFamilyName, FontStyle.Bold);
if (font == null)
font = this.GetFont(fontFamilyName, FontStyle.Italic);
if (font == null)
font = this.GetFont(fontFamilyName, FontStyle.Bold | FontStyle.Italic);
if (font == null)
font = (Font)this.Font.Clone();
_fontCache.Add(fontFamilyName, font);
}
}
return _fontCache[fontFamilyName];
}
protected virtual Font GetFont(string fontFamilyName, FontStyle fontStyle)
{
Font font;
try
{
font = new Font(fontFamilyName, this.PreviewFontSize, fontStyle);
}
catch
{
font = null;
}
return font;
}
protected virtual void ClearFontCache()
{
if (_fontCache != null)
{
foreach (string key in _fontCache.Keys)
_fontCache[key].Dispose();
_fontCache.Clear();
}
}