첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170
using System;
using System.Runtime.InteropServices;

#region 폰트 패밀리 열거하기 (확장) - EnumFontFamiliesEx(deviceContextHandle, logFontHandle, enumerateFontDelegate, longParameter, flag)

/// <summary>
/// 폰트 패밀리 열거하기 (확장)
/// </summary>
/// <param name="deviceContextHandle">디바이스 컨텍스트 핸들</param>
/// <param name="logFontHandle">LOG 폰트 핸들</param>
/// <param name="enumerateFontDelegate">폰트 열거하기 대리자</param>
/// <param name="longParameter">LONG 매개 변수</param>
/// <param name="flag">플래그</param>
/// <returns>처리 결과</returns>
[DllImport("gdi32", CharSet = CharSet.Auto)]
private static extern int EnumFontFamiliesEx
(
    int                   deviceContextHandle,
    [In] IntPtr           logFontHandle,
    EnumerateFontDelegate enumerateFontDelegate,
    IntPtr                longParameter,
    uint                  flag
);

#endregion

/// <summary>
/// 폰트 문자 세트
/// </summary>
public enum FontCharSet : byte
{
    /// <summary>
    /// ANSI_CHARSET
    /// </summary>
    ANSI_CHARSET = 0,

    /// <summary>
    /// DEFAULT_CHARSET
    /// </summary>
    DEFAULT_CHARSET = 1,

    /// <summary>
    /// SYMBOL_CHARSET
    /// </summary>
    SYMBOL_CHARSET = 2,

    /// <summary>
    /// MAC_CHARSET
    /// </summary>
    MAC_CHARSET = 77,

    /// <summary>
    /// SHIFTJIS_CHARSET
    /// </summary>
    SHIFTJIS_CHARSET = 128,

    /// <summary>
    /// HANGEUL_CHARSET
    /// </summary>
    HANGEUL_CHARSET = 129,

    /// <summary>
    /// HANGUL_CHARSET
    /// </summary>
    HANGUL_CHARSET = 129,

    /// <summary>
    /// JOHAB_CHARSET
    /// </summary>
    JOHAB_CHARSET = 130,

    /// <summary>
    /// GB2312_CHARSET
    /// </summary>
    GB2312_CHARSET = 134,

    /// <summary>
    /// CHINESEBIG5_CHARSET
    /// </summary>
    CHINESEBIG5_CHARSET = 136,

    /// <summary>
    /// GREEK_CHARSET
    /// </summary>
    GREEK_CHARSET = 161,

    /// <summary>
    /// TURKISH_CHARSET
    /// </summary>
    TURKISH_CHARSET = 162,

    /// <summary>
    /// VIETNAMESE_CHARSET
    /// </summary>
    VIETNAMESE_CHARSET = 163,

    /// <summary>
    /// HEBREW_CHARSET
    /// </summary>
    HEBREW_CHARSET = 177,

    /// <summary>
    /// ARABIC_CHARSET
    /// </summary>
    ARABIC_CHARSET = 178,

    /// <summary>
    /// BALTIC_CHARSET
    /// </summary>
    BALTIC_CHARSET = 186,

    /// <summary>
    /// RUSSIAN_CHARSET
    /// </summary>
    RUSSIAN_CHARSET = 204,

    /// <summary>
    /// THAI_CHARSET
    /// </summary>
    THAI_CHARSET = 222,

    /// <summary>
    /// EASTEUROPE_CHARSET
    /// </summary>
    EASTEUROPE_CHARSET = 238,

    /// <summary>
    /// OEM_CHARSET
    /// </summary>
    OEM_CHARSET = 255
}

/// <summary>
/// 폰트 클리핑 정밀도
/// </summary>
public enum FontClipPrecision : byte
{
    /// <summary>
    /// CLIP_DEFAULT_PRECIS
    /// </summary>
    CLIP_DEFAULT_PRECIS = 0,

    /// <summary>
    /// CLIP_CHARACTER_PRECIS
    /// </summary>
    CLIP_CHARACTER_PRECIS = 1,

    /// <summary>
    /// CLIP_STROKE_PRECIS
    /// </summary>
    CLIP_STROKE_PRECIS = 2,

    /// <summary>
    /// CLIP_MASK
    /// </summary>
    CLIP_MASK = 0xf,

    /// <summary>
    /// CLIP_LH_ANGLES
    /// </summary>
    CLIP_LH_ANGLES = (1 << 4),

    /// <summary>
    /// CLIP_TT_ALWAYS
    /// </summary>
    CLIP_TT_ALWAYS = (2 << 4),

    /// <summary>
    /// CLIP_DFA_DISABLE
    /// </summary>
    CLIP_DFA_DISABLE = (4 << 4),

    /// <summary>
    /// CLIP_EMBEDDED
    /// </summary>
    CLIP_EMBEDDED = (8 << 4)
}

/// <summary>
/// 폰트 피치 & 패밀리
/// </summary>
[Flags]
public enum FontPitchAndFamily : byte
{
    /// <summary>
    /// DEFAULT_PITCH
    /// </summary>
    DEFAULT_PITCH = 0,

    /// <summary>
    /// FIXED_PITCH
    /// </summary>
    FIXED_PITCH = 1,

    /// <summary>
    /// VARIABLE_PITCH
    /// </summary>
    VARIABLE_PITCH = 2,

    /// <summary>
    /// FF_DONTCARE
    /// </summary>
    FF_DONTCARE = (0 << 4),

    /// <summary>
    /// FF_ROMAN
    /// </summary>
    FF_ROMAN = (1 << 4),

    /// <summary>
    /// FF_SWISS
    /// </summary>
    FF_SWISS = (2 << 4),

    /// <summary>
    /// FF_MODERN
    /// </summary>
    FF_MODERN = (3 << 4),

    /// <summary>
    /// FF_SCRIPT
    /// </summary>
    FF_SCRIPT = (4 << 4),

    /// <summary>
    /// FF_DECORATIVE
    /// </summary>
    FF_DECORATIVE = (5 << 4)
}

/// <summary>
/// 폰트 정밀도
/// </summary>
public enum FontPrecision : byte
{
    /// <summary>
    /// OUT_DEFAULT_PRECIS
    /// </summary>
    OUT_DEFAULT_PRECIS = 0,

    /// <summary>
    /// OUT_STRING_PRECIS
    /// </summary>
    OUT_STRING_PRECIS = 1,

    /// <summary>
    /// OUT_CHARACTER_PRECIS
    /// </summary>
    OUT_CHARACTER_PRECIS = 2,

    /// <summary>
    /// OUT_STROKE_PRECIS
    /// </summary>
    OUT_STROKE_PRECIS = 3,

    /// <summary>
    /// OUT_TT_PRECIS
    /// </summary>
    OUT_TT_PRECIS = 4,

    /// <summary>
    /// OUT_DEVICE_PRECIS
    /// </summary>
    OUT_DEVICE_PRECIS = 5,

    /// <summary>
    /// OUT_RASTER_PRECIS
    /// </summary>
    OUT_RASTER_PRECIS = 6,

    /// <summary>
    /// OUT_TT_ONLY_PRECIS
    /// </summary>
    OUT_TT_ONLY_PRECIS = 7,

    /// <summary>
    /// OUT_OUTLINE_PRECIS
    /// </summary>
    OUT_OUTLINE_PRECIS = 8,

    /// <summary>
    /// OUT_SCREEN_OUTLINE_PRECIS
    /// </summary>
    OUT_SCREEN_OUTLINE_PRECIS = 9,

    /// <summary>
    /// OUT_PS_ONLY_PRECIS
    /// </summary>
    OUT_PS_ONLY_PRECIS = 10
}

/// <summary>
/// 폰트 품질
/// </summary>
public enum FontQuality : byte
{
    /// <summary>
    /// DEFAULT_QUALITY
    /// </summary>
    DEFAULT_QUALITY = 0,

    /// <summary>
    /// DRAFT_QUALITY
    /// </summary>
    DRAFT_QUALITY = 1,

    /// <summary>
    /// PROOF_QUALITY
    /// </summary>
    PROOF_QUALITY = 2,

    /// <summary>
    /// NONANTIALIASED_QUALITY
    /// </summary>
    NONANTIALIASED_QUALITY = 3,

    /// <summary>
    /// ANTIALIASED_QUALITY
    /// </summary>
    ANTIALIASED_QUALITY = 4,

    /// <summary>
    /// CLEARTYPE_QUALITY
    /// </summary>
    CLEARTYPE_QUALITY = 5,

    /// <summary>
    /// CLEARTYPE_NATURAL_QUALITY
    /// </summary>
    CLEARTYPE_NATURAL_QUALITY = 6
}

/// <summary>
/// 폰트 가중치
/// </summary>
public enum FontWeight : int
{
    /// <summary>
    /// DONT_CARE
    /// </summary>
    DONT_CARE = 0,

    /// <summary>
    /// THIN
    /// </summary>
    THIN = 100,

    /// <summary>
    /// EXTRA_LIGHT
    /// </summary>
    EXTRA_LIGHT = 200,

    /// <summary>
    /// LIGHT
    /// </summary>
    LIGHT = 300,

    /// <summary>
    /// NORMAL
    /// </summary>
    NORMAL = 400,

    /// <summary>
    /// MEDIUM
    /// </summary>
    MEDIUM = 500,

    /// <summary>
    /// SEMI_BOLD
    /// </summary>
    SEMI_BOLD = 600,

    /// <summary>
    /// BOLD
    /// </summary>
    BOLD = 700,

    /// <summary>
    /// EXTRA_BOLD
    /// </summary>
    EXTRA_BOLD = 800,

    /// <summary>
    /// HEAVY
    /// </summary>
    HEAVY = 900
}

/// <summary>
/// LOGFONT
/// </summary>
[StructLayout(LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public struct LOGFONT
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Field
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region Field

    /// <summary>
    /// 높이
    /// </summary>
    public int Height;

    /// <summary>
    /// 너비
    /// </summary>
    public int Width;

    /// <summary>
    /// 이스케이프먼트
    /// </summary>
    public int Escapement;

    /// <summary>
    /// 방향
    /// </summary>
    public int Orientation;

    /// <summary>
    /// 가중치
    /// </summary>
    public FontWeight Weight;

    /// <summary>
    /// 이탤릭체 여부
    /// </summary>
    [MarshalAs(UnmanagedType.U1)]
    public bool Italic;

    /// <summary>
    /// 밑줄 여부
    /// </summary>
    [MarshalAs(UnmanagedType.U1)]
    public bool Underline;

    /// <summary>
    /// 스트라이크 아웃 여부
    /// </summary>
    [MarshalAs(UnmanagedType.U1)]
    public bool StrikeOut;

    /// <summary>
    /// 문자 세트
    /// </summary>
    public FontCharSet CharSet;

    /// <summary>
    /// 출력 정밀도
    /// </summary>
    public FontPrecision OutPrecision;

    /// <summary>
    /// 클리핑 정밀도
    /// </summary>
    public FontClipPrecision ClipPrecision;

    /// <summary>
    /// 품질
    /// </summary>
    public FontQuality Quality;

    /// <summary>
    /// 피치 & 패밀리
    /// </summary>
    public FontPitchAndFamily PitchAndFamily;

    /// <summary>
    /// 폰트명
    /// </summary>
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
    public string FaceName;

    #endregion
}

/// <summary>
/// ENUMLOGFONTEX
/// </summary>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct ENUMLOGFONTEX
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Field
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region Field

    /// <summary>
    /// LOG 폰트
    /// </summary>
    public LOGFONT LogFont;

    /// <summary>
    /// 전체 명칭
    /// </summary>
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
    public string FullName;

    /// <summary>
    /// 스타일
    /// </summary>
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
    public string Style;

    /// <summary>
    /// 스크립트
    /// </summary>
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
    public string Script;

    #endregion
}

/// <summary>
/// NEWTEXTMETRIC
/// </summary>
[StructLayout(LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public struct NEWTEXTMETRIC
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Field

    #region Field

    /// <summary>
    /// 높이
    /// </summary>
    public int Height;

    /// <summary>
    /// 상단 높이
    /// </summary>
    public int Ascent;

    /// <summary>
    /// 하단 높이
    /// </summary>
    public int Descent;

    /// <summary>
    /// 내부 간격
    /// </summary>
    public int InternalLeading;

    /// <summary>
    /// 외부 간격
    /// </summary>
    public int ExternalLeading;

    /// <summary>
    /// 평균 문자 너비
    /// </summary>
    public int AverageCharacterWidth;

    /// <summary>
    /// 최대 문자 너비
    /// </summary>
    public int MaximumCharacterWidth;

    /// <summary>
    /// 가중치
    /// </summary>
    public int Weight;

    /// <summary>
    /// 오버행
    /// </summary>
    public int Overhang;

    /// <summary>
    /// 종횡비 X
    /// </summary>
    public int AspectX;

    /// <summary>
    /// 종횡비 Y
    /// </summary>
    public int AspectY;

    /// <summary>
    /// 첫번째 문자
    /// </summary>
    public char FirstCharacter;

    /// <summary>
    /// 마지막 문자
    /// </summary>
    public char LastCharacter;

    /// <summary>
    /// 디폴트 문자
    /// </summary>
    public char DefaultCharacter;

    /// <summary>
    /// BREAK 문자
    /// </summary>
    public char BreakCharacter;

    /// <summary>
    /// 이탤릭체 여부
    /// </summary>
    public byte Italic;

    /// <summary>
    /// 밑줄 여부
    /// </summary>
    public byte Underlined;

    /// <summary>
    /// 스트라이크 아웃 여부
    /// </summary>
    public byte StrikeOut;

    /// <summary>
    /// 피치 & 패밀리
    /// </summary>
    public byte PitchAndFamily;

    /// <summary>
    /// 문자 세트 여부
    /// </summary>
    public byte CharSet;

    /// <summary>
    /// 플래그
    /// </summary>
    public int Flag;

    /// <summary>
    /// EM 크기
    /// </summary>
    public int SizeEM;

    /// <summary>
    /// 셀 높이
    /// </summary>
    public int CellHeight;

    /// <summary>
    /// 평균 너비
    /// </summary>
    public int AverageWidth;

    #endregion
}

/// <summary>
/// FONTSIGNATURE
/// </summary>
public struct FONTSIGNATURE
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Field
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region Field

    /// <summary>
    /// USB
    /// </summary>
    [MarshalAs(UnmanagedType.ByValArray)]
    public int[] USB;

    /// <summary>
    /// CSB
    /// </summary>
    [MarshalAs(UnmanagedType.ByValArray)]
    public int[] CSB;

    #endregion
}

/// <summary>
/// NEWTEXTMETRICEX
/// </summary>
public struct NEWTEXTMETRICEX
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Field
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region Field

    /// <summary>
    /// 텍스트 메트릭
    /// </summary>
    public NEWTEXTMETRIC TextMetric;

    /// <summary>
    /// 폰트 서명
    /// </summary>
    public FONTSIGNATURE FontSignature;

    #endregion
}

#region 폰트 열거하기 대리자 - EnumerateFontDelegate(enumLogFontEx, newTextMetricEx, fontType, longParameter);

/// <summary>
/// 폰트 열거하기 대리자
/// </summary>
/// <param name="enumLogFontEx">ENUMLOGFONTEX</param>
/// <param name="newTextMetricEx">NEWTEXTMETRICEX</param>
/// <param name="fontType">폰트 타입</param>
/// <param name="longParameter">LONG 매개 변수</param>
/// <returns>처리 결과</returns>
public delegate int EnumerateFontDelegate
(
    ref ENUMLOGFONTEX   enumLogFontEx,
    ref NEWTEXTMETRICEX newTextMetricEx,
    int                 fontType,
    int                 longParameter
);

#endregion
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요