Add Assertions for empty fontName
Simplify Dispose of fonts Check for existing fonts when none found
This commit is contained in:
1 parent
6c7b59ed44
commit
93a7e70ca3
1 file changed
+30
-29
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -49,6 +50,14 @@ namespace Vocaluxe.Base.Fonts
|
|||||||
public CFontStyle Italic;
|
public CFontStyle Italic;
|
||||||
public CFontStyle Bold;
|
public CFontStyle Bold;
|
||||||
public CFontStyle BoldItalic;
|
public CFontStyle BoldItalic;
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Normal.Dispose();
|
||||||
|
Italic.Dispose();
|
||||||
|
Bold.Dispose();
|
||||||
|
BoldItalic.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class CFonts
|
static class CFonts
|
||||||
@@ -70,12 +79,7 @@ namespace Vocaluxe.Base.Fonts
|
|||||||
public static void Close()
|
public static void Close()
|
||||||
{
|
{
|
||||||
foreach (SFontFamily font in _FontFamilies)
|
foreach (SFontFamily font in _FontFamilies)
|
||||||
{
|
font.Dispose();
|
||||||
font.Normal.Dispose();
|
|
||||||
font.Bold.Dispose();
|
|
||||||
font.Italic.Dispose();
|
|
||||||
font.BoldItalic.Dispose();
|
|
||||||
}
|
|
||||||
_FontFamilies.Clear();
|
_FontFamilies.Clear();
|
||||||
_IsInitialized = false;
|
_IsInitialized = false;
|
||||||
}
|
}
|
||||||
@@ -227,35 +231,36 @@ namespace Vocaluxe.Base.Fonts
|
|||||||
|
|
||||||
private static int _GetFontIndex(string fontName)
|
private static int _GetFontIndex(string fontName)
|
||||||
{
|
{
|
||||||
int index = _GetPartyFontIndex(fontName, PartyModeID);
|
if (fontName != "")
|
||||||
if (index < 0)
|
|
||||||
index = _GetThemeFontIndex(fontName, CConfig.Theme);
|
|
||||||
if (index >= 0)
|
|
||||||
return index;
|
|
||||||
for (int i = 0; i < _FontFamilies.Count; i++)
|
|
||||||
{
|
|
||||||
if (_FontFamilies[i].Name == fontName)
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
if (index < 0)
|
|
||||||
{
|
{
|
||||||
|
int index = _GetPartyFontIndex(fontName, PartyModeID);
|
||||||
|
if (index < 0)
|
||||||
|
index = _GetThemeFontIndex(fontName, CConfig.Theme);
|
||||||
|
if (index >= 0)
|
||||||
|
return index;
|
||||||
|
for (int i = 0; i < _FontFamilies.Count; i++)
|
||||||
|
{
|
||||||
|
if (_FontFamilies[i].Name == fontName)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
if (!_LoggedMissingFonts.Contains(fontName))
|
if (!_LoggedMissingFonts.Contains(fontName))
|
||||||
{
|
{
|
||||||
_LoggedMissingFonts.Add(fontName);
|
_LoggedMissingFonts.Add(fontName);
|
||||||
CLog.LogError("Font \"" + fontName + "\" not found!");
|
CLog.LogError("Font \"" + fontName + "\" not found!");
|
||||||
}
|
}
|
||||||
if (_FontFamilies.Count == 0)
|
|
||||||
CLog.LogError("No fonts found!", true, true);
|
|
||||||
index = 0;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
CLog.LogError("Empty fontName requested", false, false, new Exception());
|
||||||
|
|
||||||
return index;
|
if (_FontFamilies.Count == 0)
|
||||||
|
CLog.LogError("No fonts found!", true, true);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int _GetThemeFontIndex(string fontName, string themeName)
|
private static int _GetThemeFontIndex(string fontName, string themeName)
|
||||||
{
|
{
|
||||||
if (themeName == "" || fontName == "")
|
Debug.Assert(fontName != "" && themeName != "");
|
||||||
return -1;
|
|
||||||
|
|
||||||
for (int i = 0; i < _FontFamilies.Count; i++)
|
for (int i = 0; i < _FontFamilies.Count; i++)
|
||||||
{
|
{
|
||||||
@@ -268,8 +273,7 @@ namespace Vocaluxe.Base.Fonts
|
|||||||
|
|
||||||
private static int _GetPartyFontIndex(string fontName, int partyModeID)
|
private static int _GetPartyFontIndex(string fontName, int partyModeID)
|
||||||
{
|
{
|
||||||
if (partyModeID == -1 || fontName == "")
|
Debug.Assert(fontName != "");
|
||||||
return -1;
|
|
||||||
|
|
||||||
for (int i = 0; i < _FontFamilies.Count; i++)
|
for (int i = 0; i < _FontFamilies.Count; i++)
|
||||||
{
|
{
|
||||||
@@ -405,10 +409,7 @@ namespace Vocaluxe.Base.Fonts
|
|||||||
{
|
{
|
||||||
if (_FontFamilies[index].ThemeName == themeName)
|
if (_FontFamilies[index].ThemeName == themeName)
|
||||||
{
|
{
|
||||||
_FontFamilies[index].Normal.Dispose();
|
_FontFamilies[index].Dispose();
|
||||||
_FontFamilies[index].Italic.Dispose();
|
|
||||||
_FontFamilies[index].Bold.Dispose();
|
|
||||||
_FontFamilies[index].BoldItalic.Dispose();
|
|
||||||
_FontFamilies.RemoveAt(index);
|
_FontFamilies.RemoveAt(index);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in new issue
Block a user