---恢复内容开始---
文字的呈现要求。
内容,格式。
ID2D1Factory -> DrawText -> DreaTextLayout -> SetFontSize -> SetUnderlineIDWriteFactory -> IDWriteTextFormat -> IDWriteTextLayout
WriteFactory 提供格式。
D2D1Factory 提供画图方法。
IDWriteFactory
hr = DWriteCreateFactory( DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast<IUnknown**>(&pDWriteFactory_) );
IDWriteTextFormat
virtual HRESULT CreateTextFormat( [in] const WCHAR * fontFamilyName, //字体名 IDWriteFontCollection * fontCollection, //字体集合的指针,一般为NULL DWRITE_FONT_WEIGHT fontWeight, //指示字体粗细 DWRITE_FONT_STYLE fontStyle, //指示字体样式 DWRITE_FONT_STRETCH fontStretch, //指示字体拉伸 FLOAT fontSize, //指示字体的逻辑大小,(DPI) [in] const WCHAR * localeName, //区域设置名称 [out] IDWriteTextFormat ** textFormat ) = 0;
DrawText
void DrawText( [in] WCHAR *string, //字符串 UINT stringLength, //字符串长度 [in] IDWriteTextFormat *textFormat, //IDWriteTextFormat [ref] const D2D1_RECT_F &layoutRect, //呈现矩形 [in] ID2D1Brush *defaultForegroundBrush, //画刷 D2D1_DRAW_TEXT_OPTIONS options = D2D1_DRAW_TEXT_OPTIONS_NONE, //可省略 DWRITE_MEASURING_MODE measuringMode = DWRITE_MEASURING_MODE_NATURAL //可省略 );
IDWriteTextLayout
virtual HRESULT CreateTextLayout( [in] const WCHAR * string, //字符 UINT32 stringLength, //字符长度 IDWriteTextFormat * textFormat, //IDWriteTextFormat FLOAT maxWidth, //呈现矩形大小 FLOAT maxHeight, [out] IDWriteTextLayout ** textLayout ) = 0;
DrawTextLayout
virtual void DrawTextLayout( D2D1_POINT_2F origin, //开始位置 [in] IDWriteTextLayout *textLayout, //IDWriteTextLayout [in] ID2D1Brush *defaultForegroundBrush, //画刷 D2D1_DRAW_TEXT_OPTIONS options = D2D1_DRAW_TEXT_OPTIONS_NONE ) = 0;
使用IDWriteTextLayout可以使文本其中指定的子文本,呈现不同的格式。
SetFontSize
virtual HRESULT SetFontSize( FLOAT fontSize, //大小 DWRITE_TEXT_RANGE textRange //指示子文本在原来文本中的位置。 ) = 0;
DWRITE_TEXT_RANGE
struct DWRITE_TEXT_RANGE { UINT32 startPosition; //指示子文本在原文本的开始位置 UINT32 length; //指示自文本的长度 };
---恢复内容结束---
时间: 2024-10-26 12:36:50