using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
///
/// Font families describe the look of a font in a general way. They are intended for specifying fonts when the exact typeface desired is
/// not available.
///
[PInvokeData("Wingdi.h", MSDNShortId = "dd145037")]
public enum FontFamily : byte
{
/// Use default font.
FF_DONTCARE = 0 << 4,
/// Fonts with variable stroke width (proportional) and with serifs. MS Serif is an example.
FF_ROMAN = 1 << 4,
/// Fonts with variable stroke width (proportional) and without serifs. MS Sans Serif is an example.
FF_SWISS = 2 << 4,
///
/// Fonts with constant stroke width (monospace), with or without serifs. Monospace fonts are usually modern. Pica, Elite, and
/// CourierNew are examples.
///
FF_MODERN = 3 << 4,
/// Fonts designed to look like handwriting. Script and Cursive are examples.
FF_SCRIPT = 4 << 4,
/// Novelty fonts. Old English is an example.
FF_DECORATIVE = 5 << 4,
}
/// Specifies information about the pitch, the technology, and the family of a physical font.
[PInvokeData("Wingdi.h", MSDNShortId = "dd145037")]
[Flags]
public enum FontPitch : byte
{
/// The default pitch, which is implementation-dependent.
DEFAULT_PITCH = 0,
/// A fixed pitch, which means that all the characters in the font occupy the same width when output in a string.
FIXED_PITCH = 1,
///
/// A variable pitch, which means that the characters in the font occupy widths that are proportional to the actual widths of the
/// glyphs when output in a string. For example, the "i" and space characters usually have much smaller widths than a "W" or "O" character.
///
VARIABLE_PITCH = 2,
/// The mono font/
MONO_FONT = 8,
///
/// If this bit is set the font is a variable pitch font. If this bit is clear the font is a fixed pitch font. Note very carefully
/// that those meanings are the opposite of what the constant name implies.
///
TMPF_FIXED_PITCH = 0x01,
/// If this bit is set the font is a vector font.
TMPF_VECTOR = 0x02,
/// If this bit is set the font is a TrueType font.
TMPF_TRUETYPE = 0x04,
/// If this bit is set the font is a device font.
TMPF_DEVICE = 0x08,
}
/// The character set.
[PInvokeData("Wingdi.h", MSDNShortId = "dd145037")]
public enum CharacterSet : byte
{
/// Specifies the English character set.
ANSI_CHARSET = 0,
///
/// Specifies a character set based on the current system locale; for example, when the system locale is United States English, the
/// default character set is ANSI_CHARSET.
///
DEFAULT_CHARSET = 1,
/// Specifies a character set of symbols.
SYMBOL_CHARSET = 2,
/// Specifies the Japanese character set.
SHIFTJIS_CHARSET = 128,
/// Specifies the Hangul Korean character set.
HANGEUL_CHARSET = 129,
/// Also spelled "Hangeul". Specifies the Hangul Korean character set.
HANGUL_CHARSET = 129,
/// Specifies the "simplified" Chinese character set for People's Republic of China.
GB2312_CHARSET = 134,
///
/// Specifies the "traditional" Chinese character set, used mostly in Taiwan and in the Hong Kong and Macao Special Administrative Regions.
///
CHINESEBIG5_CHARSET = 136,
/// Specifies a mapping to one of the OEM code pages, according to the current system locale setting.
OEM_CHARSET = 255,
/// Also spelled "Johap". Specifies the Johab Korean character set.
JOHAB_CHARSET = 130,
/// Specifies the Hebrew character set.
HEBREW_CHARSET = 177,
/// Specifies the Arabic character set.
ARABIC_CHARSET = 178,
/// Specifies the Greek character set.
GREEK_CHARSET = 161,
/// Specifies the Turkish character set.
TURKISH_CHARSET = 162,
/// Specifies the Vietnamese character set.
VIETNAMESE_CHARSET = 163,
/// Specifies the Thai character set.
THAI_CHARSET = 222,
/// Specifies a Eastern European character set.
EASTEUROPE_CHARSET = 238,
/// Specifies the Russian Cyrillic character set.
RUSSIAN_CHARSET = 204,
/// Specifies the Apple Macintosh character set.
MAC_CHARSET = 77,
/// Specifies the Baltic (Northeastern European) character set.
BALTIC_CHARSET = 186
}
/// The clipping precision defines how to clip characters that are partially outside the clipping region.
[PInvokeData("Wingdi.h", MSDNShortId = "dd145037")]
public enum LogFontClippingPrecision : byte
{
/// Not used.
CLIP_CHARACTER_PRECIS = 1,
/// Specifies default clipping behavior.
CLIP_DEFAULT_PRECIS = 0,
///
/// Windows XP SP1: Turns off font association for the font. Note that this flag is not guaranteed to have any effect on any platform
/// after Windows Server 2003.
///
CLIP_DFA_DISABLE = 4 << 4,
///
/// Turns off font association for the font. This is identical to CLIP_DFA_DISABLE, but it can have problems in some situations; the
/// recommended flag to use is CLIP_DFA_DISABLE.
///
CLIP_DFA_OVERRIDE = 64,
/// You must specify this flag to use an embedded read-only font.
CLIP_EMBEDDED = 8 << 4,
///
/// When this value is used, the rotation for all fonts depends on whether the orientation of the coordinate system is left-handed or
/// right-handed. If not used, device fonts always rotate counterclockwise, but the rotation of other fonts is dependent on the
/// orientation of the coordinate system.
///
CLIP_LH_ANGLES = 1 << 4,
/// Not used.
CLIP_MASK = 0xf,
///
/// Not used by the font mapper, but is returned when raster, vector, or TrueType fonts are enumerated. For compatibility, this value
/// is always returned when enumerating fonts.
///
CLIP_STROKE_PRECIS = 2,
/// Not used.
CLIP_TT_ALWAYS = 2 << 4,
}
///
/// The output precision. The output precision defines how closely the output must match the requested font's height, width, character
/// orientation, escapement, pitch, and font type.
///
[PInvokeData("Wingdi.h", MSDNShortId = "dd145037")]
public enum LogFontOutputPrecision : byte
{
/// Not used.
OUT_CHARACTER_PRECIS = 2,
/// Specifies the default font mapper behavior.
OUT_DEFAULT_PRECIS = 0,
/// Instructs the font mapper to choose a Device font when the system contains multiple fonts with the same name.
OUT_DEVICE_PRECIS = 5,
/// This value instructs the font mapper to choose from TrueType and other outline-based fonts.
OUT_OUTLINE_PRECIS = 8,
///
/// Instructs the font mapper to choose from only PostScript fonts. If there are no PostScript fonts installed in the system, the
/// font mapper returns to default behavior.
///
OUT_PS_ONLY_PRECIS = 10,
/// Instructs the font mapper to choose a raster font when the system contains multiple fonts with the same name.
OUT_RASTER_PRECIS = 6,
/// A value that specifies a preference for TrueType and other outline fonts.
OUT_SCREEN_OUTLINE_PRECIS = 9,
/// This value is not used by the font mapper, but it is returned when raster fonts are enumerated.
OUT_STRING_PRECIS = 1,
///
/// This value is not used by the font mapper, but it is returned when TrueType, other outline-based fonts, and vector fonts are enumerated.
///
OUT_STROKE_PRECIS = 3,
///
/// Instructs the font mapper to choose from only TrueType fonts. If there are no TrueType fonts installed in the system, the font
/// mapper returns to default behavior.
///
OUT_TT_ONLY_PRECIS = 7,
/// Instructs the font mapper to choose a TrueType font when the system contains multiple fonts with the same name.
OUT_TT_PRECIS = 4,
}
///
/// The output quality defines how carefully the graphics device interface (GDI) must attempt to match the logical-font attributes to
/// those of an actual physical font.
///
[PInvokeData("Wingdi.h", MSDNShortId = "dd145037")]
public enum LogFontOutputQuality : byte
{
/// Appearance of the font does not matter.
DEFAULT_QUALITY = 0,
///
/// Appearance of the font is less important than when PROOF_QUALITY is used. For GDI raster fonts, scaling is enabled, which means
/// that more font sizes are available, but the quality may be lower. Bold, italic, underline, and strikeout fonts are synthesized if necessary.
///
DRAFT_QUALITY = 1,
///
/// Character quality of the font is more important than exact matching of the logical-font attributes. For GDI raster fonts, scaling
/// is disabled and the font closest in size is chosen. Although the chosen font size may not be mapped exactly when PROOF_QUALITY is
/// used, the quality of the font is high and there is no distortion of appearance. Bold, italic, underline, and strikeout fonts are
/// synthesized if necessary.
///
PROOF_QUALITY = 2,
/// Font is never antialiased.
NONANTIALIASED_QUALITY = 3,
/// Font is always antialiased if the font supports it and the size of the font is not too small or too large.
ANTIALIASED_QUALITY = 4,
///
/// If set, text is rendered (when possible) using ClearType antialiasing method. The font quality is given less importance than
/// maintaining the text size.
///
CLEARTYPE_QUALITY = 5,
///
/// If set, text is rendered (when possible) using ClearType antialiasing method. The font quality is given more importance than
/// maintaining the text size.
///
CLEARTYPE_NATURAL_QUALITY = 6
}
/// The LOGFONT structure defines the attributes of a font.
[PInvokeData("Wingdi.h", MSDNShortId = "dd145037")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct LOGFONT
{
///
/// The height, in logical units, of the font's character cell or character. The character height value (also known as the em height)
/// is the character cell height value minus the internal-leading value. The font mapper interprets the value specified in lfHeight
/// in the following manner.
///
///
/// Value
/// Meaning
///
/// -
/// > 0
/// The font mapper transforms this value into device units and matches it against the cell height of the available fonts.
///
/// -
/// 0
/// The font mapper uses a default height value when it searches for a match.
///
/// -
/// < 0
/// The font mapper transforms this value into device units and matches its absolute value against the character height
/// of the available fonts.
///
///
/// For all height comparisons, the font mapper looks for the largest font that does not exceed the requested size.
/// This mapping occurs when the font is used for the first time.
///
/// For the MM_TEXT mapping mode, you can use the following formula to specify a height for a font with a specified point size:
///
///
public int lfHeight;
///
/// The average width, in logical units, of characters in the font. If lfWidth is zero, the aspect ratio of the device is matched
/// against the digitization aspect ratio of the available fonts to find the closest match, determined by the absolute value of the difference.
///
public int lfWidth;
///
/// The angle, in tenths of degrees, between the escapement vector and the x-axis of the device. The escapement vector is parallel to
/// the base line of a row of text.
///
/// When the graphics mode is set to GM_ADVANCED, you can specify the escapement angle of the string independently of the orientation
/// angle of the string's characters.
///
///
/// When the graphics mode is set to GM_COMPATIBLE, lfEscapement specifies both the escapement and orientation. You should set
/// lfEscapement and lfOrientation to the same value.
///
///
public int lfEscapement;
/// The angle, in tenths of degrees, between each character's base line and the x-axis of the device.
public int lfOrientation;
///
/// The weight of the font in the range 0 through 1000. For example, 400 is normal and 700 is bold. If this value is zero, a default
/// weight is used.
///
private int _lfWeight;
/// An italic font if set to TRUE.
[MarshalAs(UnmanagedType.U1)]
public bool lfItalic;
/// An underlined font if set to TRUE.
[MarshalAs(UnmanagedType.U1)]
public bool lfUnderline;
/// A strikeout font if set to TRUE.
[MarshalAs(UnmanagedType.U1)]
public bool lfStrikeOut;
/// The character set.
public CharacterSet lfCharSet;
///
/// The output precision. The output precision defines how closely the output must match the requested font's height, width,
/// character orientation, escapement, pitch, and font type.
///
public LogFontOutputPrecision lfOutPrecision;
///
/// The clipping precision. The clipping precision defines how to clip characters that are partially outside the clipping region.
///
public LogFontClippingPrecision lfClipPrecision;
///
/// The output quality. The output quality defines how carefully the graphics device interface (GDI) must attempt to match the
/// logical-font attributes to those of an actual physical font.
///
public LogFontOutputQuality lfQuality;
/// The pitch and family of the font.
private byte lfPitchAndFamily;
///
/// A null-terminated string that specifies the typeface name of the font. The length of this string must not exceed 32 TCHAR values,
/// including the terminating NULL. The EnumFontFamiliesEx function can be used to enumerate the typeface names of all currently
/// available fonts. If lfFaceName is an empty string, GDI uses the first font that matches the other specified attributes.
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
private string _lfFaceName;
/// Gets or sets the font family.
/// The font family.
public FontFamily FontFamily
{
get => (FontFamily)(lfPitchAndFamily & 0xF0);
set => lfPitchAndFamily = (byte)((lfPitchAndFamily & 0x0F) | (byte)value);
}
///
/// A string that specifies the typeface name of the font. The length of this string must not exceed 31 characters. The
/// EnumFontFamiliesEx function can be used to enumerate the typeface names of all currently available fonts. If lfFaceName is an
/// empty string, GDI uses the first font that matches the other specified attributes.
///
/// The face name of the font.
public string lfFaceName
{
get => _lfFaceName;
set => _lfFaceName = value?.Length <= 31 ? value : throw new ArgumentException(@"The face name may not have more than 31 characters.", nameof(lfFaceName));
}
///
/// The weight of the font in the range 0 through 1000. For example, 400 is normal and 700 is bold. If this value is zero, a default
/// weight is used.
///
public short lfWeight
{
get => (short)_lfWeight;
set => _lfWeight = value >= 0 && value <= 1000 ? value : throw new ArgumentOutOfRangeException(nameof(lfWeight), @"Font weight must be a value in the range 0 through 1000.");
}
/// Gets or sets the font pitch.
/// The pitch.
public FontPitch Pitch
{
get => (FontPitch)(lfPitchAndFamily & 0x0F);
set => lfPitchAndFamily = (byte)((lfPitchAndFamily & 0xF0) | (byte)value);
}
/// Returns a that represents this instance.
/// A that represents this instance.
public override string ToString() => $"lfHeight={lfHeight}, lfWidth={lfWidth}, lfEscapement={lfEscapement}, lfOrientation={lfOrientation}, lfWeight={lfWeight}, lfItalic={lfItalic}, lfUnderline={lfUnderline}, lfStrikeOut={lfStrikeOut}, lfCharSet={lfCharSet}, lfOutPrecision={lfOutPrecision}, lfClipPrecision={lfClipPrecision}, lfQuality={lfQuality}, lfPitchAndFamily={lfPitchAndFamily}, lfFaceName={lfFaceName}";
}
}