티스토리 뷰

ID3DXFont 인터페이스 이용하기

 

ID3DXFont 인터페이스는 D3D 애플리케이션에서 텍스트를 그릴 때 사용한다.

이 인터페이스는 내부적으로 GDI를 이용하기 때문에 약간의 성능저하가 따르지만 ,

GDI의 도움으로 복잡한 글꼴이나 포맷팅을 이용할 수 있다.

 

//아래 함수를 이용해 폰트를 생성 한뒤( 구조체 정보는 아래에)

D3DXCreateFontIndirect(
  _In_        LPDIRECT3DDEVICE9 pDevice,
  _In_  const D3DXFONT_DESC     *pDesc,
  _Out_       LPD3DXFONT        *ppFont
);

Creates a font object indirectly for both a device and a font.

 

//아래함수로 그린다.

INT DrawText(
  [in] LPD3DXSPRITE pSprite,
  [in] LPCTSTR      pString,
  [in] INT          Count,
  [in] LPRECT       pRect,
  [in] DWORD        Format,
  [in] D3DCOLOR     Color
);

Draws formatted text. This method supports ANSI and Unicode strings.

ID3DXFont::DrawText method

Draws formatted text. This method supports ANSI and Unicode strings.

Syntax

C++
INT DrawText(
  [in] LPD3DXSPRITE pSprite,
  [in] LPCTSTR      pString,
  [in] INT          Count,
  [in] LPRECT       pRect,
  [in] DWORD        Format,
  [in] D3DCOLOR     Color
);

Parameters

pSprite [in]

Type: LPD3DXSPRITE

Pointer to an ID3DXSprite object that contains the string. Can be NULL, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.

pString [in]

Type: LPCTSTR

Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.

Count [in]

Type: INT

Specifies the number of characters in the string. If Count is -1, then the pString parameter is assumed to be a pointer to a null-terminated string and DrawText computes the character count automatically.

pRect [in]

Type: LPRECT

Pointer to a RECT structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.

Format [in]

Type: DWORD

 

Specifies the method of formatting the text. It can be any combination of the following values:

Value Meaning
DT_BOTTOM

Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.

DT_CALCRECT

Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.

DT_CENTER

Centers text horizontally in the rectangle.

DT_EXPANDTABS

Expands tab characters. The default number of characters per tab is eight.

DT_LEFT

Aligns text to the left.

DT_NOCLIP

Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.

DT_RIGHT

Aligns text to the right.

DT_RTLREADING

Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.

DT_SINGLELINE

Displays text on a single line only. Carriage returns and line feeds do not break the line.

DT_TOP

Top-justifies text.

DT_VCENTER

Centers text vertically (single line only).

DT_WORDBREAK

Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.

 

Color [in]

Type: D3DCOLOR

Color of the text. For more information, see D3DCOLOR.

Return value

Type: INT

If the function succeeds, the return value is the height of the text in logical units. If DT_VCENTER or DT_BOTTOM is specified, the return value is the offset from pRect (top to the bottom) of the drawn text. If the function fails, the return value is zero.

Remarks

The parameters of this method are very similar to those of the GDI DrawText function.

This method supports both ANSI and Unicode strings.

This method must be called inside a BeginScene ... EndScene block. The only exception is when an application calls DrawText with DT_CALCRECT to calculate the size of a given block of text.

Unless the DT_NOCLIP format is used, this method clips the text so that it does not appear outside the specified rectangle. All formatting is assumed to have multiple lines unless the DT_SINGLELINE format is specified.

If the selected font is too large for the rectangle, this method does not attempt to substitute a smaller font.

This method supports only fonts whose escapement and orientation are both zero.

Requirements

Header

D3dx9core.h

Library

D3dx9.lib

See also

ID3DXFont

 

 

 

 

 

D3DXFONT_DESC structure

Defines the attributes of a font.

Syntax

C++
typedef struct D3DXFONT_DESC {
  INT   Height;
  UINT  Width;
  UINT  Weight;
  UINT  MipLevels;
  BOOL  Italic;
  BYTE  CharSet;
  BYTE  OutputPrecision;
  BYTE  Quality;
  BYTE  PitchAndFamily;
  TCHAR FaceName;
} D3DXFONT_DESC, *LPD3DXFONT_DESC;

Members

Height

Type: INT

Height, in logical units, of the font's character cell or character.

Width

Type: UINT

Width, in logical units, of characters in the font.

Weight

Type: UINT

Weight of the font in the range from 0 through 1000.

MipLevels

Type: UINT

Number of mip levels requested. If this value is zero or D3DX_DEFAULT, a complete mipmap chain is created. If the value is 1, the texture space is mapped identically to the screen space.

Italic

Type: BOOL

Set to TRUE for an Italic font.

CharSet

Type: BYTE

Character set.

OutputPrecision

Type: BYTE

Output precision. The output precision defines how closely the output must match the requested font height, width, character orientation, escapement, pitch, and font type.

Quality

Type: BYTE

Output quality.

PitchAndFamily

Type: BYTE

Pitch and family of the font.

FaceName

Type: TCHAR

A null-terminated string or characters that specifies the typeface name of the font. The length of the string must not exceed 32 characters, including the terminating null character. If FaceName is an empty string, the first font that matches the other specified attributes will be used. If the compiler settings require Unicode, the data type TCHAR resolves to WCHAR; otherwise, the data type resolves to CHAR. See Remarks.

Remarks

The compiler setting also determines the structure type. If Unicode is defined, the D3DXFONT_DESC structure type resolves to a D3DXFONT_DESCW; otherwise the structure type resolves to a D3DXFONT_DESCA.

Possible values of the above members are given in the GDI LOGFONT structure.

Requirements

Header

D3dx9core.h

See also

D3DX Structures
GetDesc

 

 

 

D3DXCreateFont function 로도 LOGFONT 객체를 만들 수 있다.

HRESULT D3DXCreateFont(
  _In_  LPDIRECT3DDEVICE9 pDevice,
  _In_  INT               Height,
  _In_  UINT              Width,
  _In_  UINT              Weight,
  _In_  UINT              MipLevels,
  _In_  BOOL              Italic,
  _In_  DWORD             CharSet,
  _In_  DWORD             OutputPrecision,
  _In_  DWORD             Quality,
  _In_  DWORD             PitchAndFamily,
  _In_  LPCTSTR           pFacename,
  _Out_ LPD3DXFONT        *ppFont
);

 

 

 

 

 

The LOGFONT structure defines the attributes of a font.

typedef struct tagLOGFONT {
  LONG  lfHeight;
  LONG  lfWidth;
  LONG  lfEscapement;
  LONG  lfOrientation;
  LONG  lfWeight;
  BYTE  lfItalic;
  BYTE  lfUnderline;
  BYTE  lfStrikeOut;
  BYTE  lfCharSet;
  BYTE  lfOutPrecision;
  BYTE  lfClipPrecision;
  BYTE  lfQuality;
  BYTE  lfPitchAndFamily;
  TCHAR lfFaceName[LF_FACESIZE];
} LOGFONT, *PLOGFONT;

 

Members

lfHeight

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:

C++
lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);


lfWidth

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.

lfEscapement

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.

lfOrientation

The angle, in tenths of degrees, between each character's base line and the x-axis of the device.

lfWeight

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.

The following values are defined for convenience.

Value Weight
FW_DONTCARE 0
FW_THIN 100
FW_EXTRALIGHT 200
FW_ULTRALIGHT 200
FW_LIGHT 300
FW_NORMAL 400
FW_REGULAR 400
FW_MEDIUM 500
FW_SEMIBOLD 600
FW_DEMIBOLD 600
FW_BOLD 700
FW_EXTRABOLD 800
FW_ULTRABOLD 800
FW_HEAVY 900
FW_BLACK 900

 

lfItalic

An italic font if set to TRUE.

lfUnderline

An underlined font if set to TRUE.

lfStrikeOut

A strikeout font if set to TRUE.

lfCharSet

The character set. The following values are predefined.

 

ANSI_CHARSET
BALTIC_CHARSET
CHINESEBIG5_CHARSET
DEFAULT_CHARSET
EASTEUROPE_CHARSET
GB2312_CHARSET
GREEK_CHARSET
HANGUL_CHARSET
MAC_CHARSET
OEM_CHARSET
RUSSIAN_CHARSET
SHIFTJIS_CHARSET
SYMBOL_CHARSET
TURKISH_CHARSET
VIETNAMESE_CHARSET

Korean language edition of Windows:

JOHAB_CHARSET

Middle East language edition of Windows:

ARABIC_CHARSET
HEBREW_CHARSET

Thai language edition of Windows:

THAI_CHARSET

The OEM_CHARSET value specifies a character set that is operating-system dependent.

DEFAULT_CHARSET is set to a value based on the current system locale. For example, when the system locale is English (United States), it is set as ANSI_CHARSET.

Fonts with other character sets may exist in the operating system. If an application uses a font with an unknown character set, it should not attempt to translate or interpret strings that are rendered with that font.

This parameter is important in the font mapping process. To ensure consistent results, specify a specific character set. If you specify a typeface name in the lfFaceName member, make sure that the lfCharSet value matches the character set of the typeface specified in lfFaceName.

lfOutPrecision

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. It can be one of the following values.

Value Meaning
OUT_CHARACTER_PRECIS Not used.
OUT_DEFAULT_PRECIS Specifies the default font mapper behavior.
OUT_DEVICE_PRECIS Instructs the font mapper to choose a Device font when the system contains multiple fonts with the same name.
OUT_OUTLINE_PRECIS This value instructs the font mapper to choose from TrueType and other outline-based fonts.
OUT_PS_ONLY_PRECIS 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_RASTER_PRECIS Instructs the font mapper to choose a raster font when the system contains multiple fonts with the same name.
OUT_STRING_PRECIS This value is not used by the font mapper, but it is returned when raster fonts are enumerated.
OUT_STROKE_PRECIS 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_TT_ONLY_PRECIS 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_PRECIS Instructs the font mapper to choose a TrueType font when the system contains multiple fonts with the same name.

 

Applications can use the OUT_DEVICE_PRECIS, OUT_RASTER_PRECIS, OUT_TT_PRECIS, and OUT_PS_ONLY_PRECIS values to control how the font mapper chooses a font when the operating system contains more than one font with a specified name. For example, if an operating system contains a font named Symbol in raster and TrueType form, specifying OUT_TT_PRECIS forces the font mapper to choose the TrueType version. Specifying OUT_TT_ONLY_PRECIS forces the font mapper to choose a TrueType font, even if it must substitute a TrueType font of another name.

lfClipPrecision

The clipping precision. The clipping precision defines how to clip characters that are partially outside the clipping region. It can be one or more of the following values.

For more information about the orientation of coordinate systems, see the description of the nOrientation parameter.

Value Meaning
CLIP_CHARACTER_PRECIS Not used.
CLIP_DEFAULT_PRECIS Specifies default clipping behavior.
CLIP_DFA_DISABLE 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_EMBEDDED You must specify this flag to use an embedded read-only font.
CLIP_LH_ANGLES 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_MASK Not used.
CLIP_DFA_OVERRIDE 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_STROKE_PRECIS 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_TT_ALWAYS Not used.

 

lfQuality

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. It can be one of the following values.

Value Meaning
ANTIALIASED_QUALITY Font is always antialiased if the font supports it and the size of the font is not too small or too large.
CLEARTYPE_QUALITY If set, text is rendered (when possible) using ClearType antialiasing method. See Remarks for more information.
DEFAULT_QUALITY Appearance of the font does not matter.
DRAFT_QUALITY 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.
NONANTIALIASED_QUALITY Font is never antialiased.
PROOF_QUALITY 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.

 

If neither ANTIALIASED_QUALITY nor NONANTIALIASED_QUALITY is selected, the font is antialiased only if the user chooses smooth screen fonts in Control Panel.

lfPitchAndFamily

The pitch and family of the font. The two low-order bits specify the pitch of the font and can be one of the following values.

  • DEFAULT_PITCH
  • FIXED_PITCH
  • VARIABLE_PITCH

Bits 4 through 7 of the member specify the font family and can be one of the following values.

  • FF_DECORATIVE
  • FF_DONTCARE
  • FF_MODERN
  • FF_ROMAN
  • FF_SCRIPT
  • FF_SWISS

The proper value can be obtained by using the Boolean OR operator to join one pitch constant with one family constant.

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. The values for font families are as follows.

Value Meaning
FF_DECORATIVE Novelty fonts. Old English is an example.
FF_DONTCARE Use default font.
FF_MODERN Fonts with constant stroke width (monospace), with or without serifs. Monospace fonts are usually modern. Pica, Elite, and CourierNew are examples.
FF_ROMAN Fonts with variable stroke width (proportional) and with serifs. MS Serif is an example.
FF_SCRIPT Fonts designed to look like handwriting. Script and Cursive are examples.
FF_SWISS Fonts with variable stroke width (proportional) and without serifs. MS Sans Serif is an example.

 

lfFaceName

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.

Remarks

The following situations do not support ClearType antialiasing:

  • Text is rendered on a printer.
  • Display set for 256 colors or less.
  • Text is rendered to a terminal server client.
  • The font is not a TrueType font or an OpenType font with TrueType outlines. For example, the following do not support ClearType antialiasing: Type 1 fonts, Postscript OpenType fonts without TrueType outlines, bitmap fonts, vector fonts, and device fonts.
  • The font has tuned embedded bitmaps, for any font sizes that contain the embedded bitmaps. For example, this occurs commonly in East Asian fonts.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps | Windows Store apps]

Minimum supported server

Windows 2000 Server [desktop apps | Windows Store apps]

Header

Wingdi.h (include Windows.h)

Unicode and ANSI names

LOGFONTW (Unicode) and LOGFONTA (ANSI)

See also

Fonts and Text Overview
Font and Text Structures
CreateFont
CreateFontIndirect
EnumFontFamiliesEx

 

 

https://msdn.microsoft.com/ko-kr/library/windows/desktop/bb172773(v=vs.85).aspx

https://msdn.microsoft.com/ko-kr/library/windows/desktop/dd145037(v=vs.85).aspx

https://msdn.microsoft.com/ko-kr/library/windows/desktop/bb173962(v=vs.85).aspx

https://msdn.microsoft.com/ko-kr/library/windows/desktop/bb172843(v=vs.85).aspx

 

 

 

댓글