본문 바로가기

일하면서 사용한 짧은 지식/C++, DirectX11

GDI의 LOGFONT에서 DirectWrite 폰트를 생성할 때 가져오지 못하는 정보도 있다. (Underline, StrikeOut)

Glyph를 이용해 텍스트를 그리는데 Bold, Italic, Underline, StrikeOut 효과를 적용할 필요가 있었다.

 

IDWriteFontFace*에서 GlyphIndices 받아와 ID2D1PathGeometry*를 생성하고 그려야하는 상황이었다.

 

IDWriteFont를 GDI의 LOGFONT를 통해 생성하여 위 과정을 수행.

 

https://docs.microsoft.com/en-us/windows/win32/directwrite/interoperating-with-gdi

 

Interoperating with GDI - Win32 apps

DirectWrite provides a migration path from, and some interoperability with, GDI's font model, as well as interfaces for rendering text to a bitmap that can then be drawn on a window.

docs.microsoft.com

 

ID2D1Factory1*의 GetGdiInterop 메서드를 통해 IDWriteGdiInterop*를 생성.

 

IDWriteGdiInterop*의 CreateFontFromLOGFONT 메서드를 통해 LOGFONT를 IDWriteFont로 전환

 

https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-logfonta

 

LOGFONTA (wingdi.h) - Win32 apps

The LOGFONT structure defines the attributes of a font.

docs.microsoft.com

 

LOGFONT 구조체에서 lfWeight, lfItalic, lfUnderline, lfStrikeOut 멤버에 적용값을 대입하여 IDWriteFont를 생성하여 그려보았다.

 

Bold와 Italic 적용은 되었지만 밑줄, 취소선은 적용되지 않았다.

 

아래의 내용과 같이 LOGFONT의 모든 정보를 IDWriteFont로 캡슐화하지 않고 IDWriteTextFormat, IDWriteTextLayout에서 IDWriteFont로 캡슐화되지 않은 정보를 사용한다.

 

Interoperating with GDI

...
However, IDWriteFont does not encapsulate all of the same information that a LOGFONT does.
...
IDWriteFont objects contain information about a font and its weight and style, but not the font size, underline, and so on. With DirectWrite, formatting information elements such as these are encapsulated by an IDWriteTextFormat object or, for specific ranges of text, an IDWriteTextLayout object.