I ran the demo and got an exception - see above.
This function should fix the 'fonstyle availability' issue:
private static Font CreateFont(string family, float size, FontStyle style)
{
FontFamily fontFamily;
if (_existingFontFamilies.TryGetValue(family, out fontFamily))
{ return new Font(fontFamily.Name , size, EnsureStyleAvailable(fontFamily , style)); }
{
var f=new Font(family,size,GraphicsUnit.Point );
return new Font( f.Name,size, EnsureStyleAvailable(f.FontFamily , style));
{
}
}
}
private static FontStyle EnsureStyleAvailable(FontFamily family, FontStyle style)
{
if (family.IsStyleAvailable(style))
return style;
var stl = (FontStyle[])Enum.GetValues(typeof(FontStyle));
foreach ( FontStyle st in stl) {
if ((style & st) == 0) {
if (family.IsStyleAvailable(style | st))
return st | style;
}
}
return Array.Find(stl, s => (family.IsStyleAvailable(s)));
}
This function should fix the 'fonstyle availability' issue:
private static Font CreateFont(string family, float size, FontStyle style)
{
FontFamily fontFamily;
if (_existingFontFamilies.TryGetValue(family, out fontFamily))
{ return new Font(fontFamily.Name , size, EnsureStyleAvailable(fontFamily , style)); }
{
var f=new Font(family,size,GraphicsUnit.Point );
return new Font( f.Name,size, EnsureStyleAvailable(f.FontFamily , style));
{
}
}
}
private static FontStyle EnsureStyleAvailable(FontFamily family, FontStyle style)
{
if (family.IsStyleAvailable(style))
return style;
var stl = (FontStyle[])Enum.GetValues(typeof(FontStyle));
foreach ( FontStyle st in stl) {
if ((style & st) == 0) {
if (family.IsStyleAvailable(style | st))
return st | style;
}
}
return Array.Find(stl, s => (family.IsStyleAvailable(s)));
}