class FontLibraryClass
{
public class FontLibrary
{
private string FontsFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts);
private static FontLibrary inst = new FontLibrary();
public PrivateFontCollection privateFont = new PrivateFontCollection();
/// <summary>
///
/// </summary>
public static FontFamily[] Families
{
get
{
return inst.privateFont.Families;
}
}
/// <summary>
///
/// </summary>
public FontLibrary()
{
AddFontFromNanumgothic();
}
/// <summary>
/// 리소스에 포함된 폰트 파일을 로딩
/// </summary>
private void AddFontFromMemory()
{
/*
List<byte[]> fonts = new List<byte[]>();
fonts.Add(Properties.Resources.NanumGothic);
fonts.Add(Properties.Resources.NanumGothicBold);
foreach (byte[] FontData in fonts)
{
IntPtr fontBuffer = Marshal.AllocCoTaskMem(FontData.Length);
Marshal.Copy(FontData, 0, fontBuffer, FontData.Length);
privateFont.AddMemoryFont(fontBuffer, FontData.Length);
}
*/
}
/// <summary>
/// 폰트 파일을 추가함.
/// </summary>
private void AddFontFromNanumgothic()
{
privateFont.AddFontFile(FontsFolder + @"\\NANUMGOTHIC.TTF");
}
}
/// <summary>
/// 폰트 존재 여부 체크
/// </summary>
public void FontInstallCheck()
{
bool FontInstallBoolNanum = false;
//
FontFamily[] fonts = FontFamily.Families;
foreach (FontFamily font in fonts)
{
if (Convert.ToString(font.Name) == "나눔고딕")
{
FontInstallBoolNanum = true;
}
}
//
if (FontInstallBoolNanum == false)
{
MessageBox.Show("요청하신 나눔고딕이 설치 되지 않아서 적용할 수 없습니다.", "폰트 적용 에러", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}