使用 RenderTarget.DrawTextLayout() 方法主要是设置 IDWriteTextLayout 接口;
构建 IDWriteTextLayout 接口需要 IDWriteTextFormat 接口。
IDWriteTextLayout 接口是经过完全分析和格式化后的文本块。
{RenderTarget.DrawTextLayout() 方法}
procedure DrawTextLayout(
origin: D2D1_POINT_2F; //起点
const textLayout: IDWriteTextLayout; //分析和格式化后的文本块
const defaultForegroundBrush: ID2D1Brush; //前景画刷
options: TD2D1DrawTextOptions //见下(参数4);默认值 D2D1_DRAW_TEXT_OPTIONS_NONE
); stdcall;
{参数4}
options: TD2D1DrawTextOptions {指定是禁用文本对齐还是启用剪切到布局矩形, 可使用按位组合值}
D2D1_DRAW_TEXT_OPTIONS_NO_SNAP = 1; //文本不垂直对齐到像素边界。建议对要进行动画处理的文本采用此设置。
D2D1_DRAW_TEXT_OPTIONS_CLIP = 2; //文本剪切到布局矩形。
D2D1_DRAW_TEXT_OPTIONS_NONE = 0; //文本垂直对齐到像素边界,但是不剪切到布局矩形。
{IDWriteTextLayout 接口提供的方法}
IDWriteTextLayout.Draw //使用指定的客户端绘制上下文绘制文本
IDWriteTextLayout.GetClusterMetrics //检索每个字形群集的逻辑属性和度量
IDWriteTextLayout.DetermineMinWidth //确定在整个词的各字符之间不断开的前提下可以为布局设置的最小宽度
IDWriteTextLayout.GetDrawingEffect //获取在指定文本位置处应用程序定义的绘制效果
IDWriteTextLayout.GetFontCollection //获取与指定位置处的文本关联的字体集合
IDWriteTextLayout.GetFontFamilyName //复制指定位置处文本的字体系列名称
IDWriteTextLayout.GetFontFamilyNameLength //获取当前位置处的字体系列名称的长度
IDWriteTextLayout.GetFontSize //获取指定位置处文本的字体高度(以 em 为单位)
IDWriteTextLayout.GetFontStretch //获取指定位置处文本的字体拉伸方式
IDWriteTextLayout.GetFontStyle //获取指定位置处文本的字体样式(也称作斜度)
IDWriteTextLayout.GetFontWeight //获取指定位置处文本的字体粗细
IDWriteTextLayout.GetInlineObject //获取给定位置处的嵌入式对象
IDWriteTextLayout.GetLineMetrics //检索文本字符串的每一文本行的相关信息
IDWriteTextLayout.GetLocaleName //获取指定位置处文本的区域设置名称
IDWriteTextLayout.GetLocaleNameLength //获取指定位置处文本的区域设置名称的长度
IDWriteTextLayout.GetMaxHeight //获取布局最大高度
IDWriteTextLayout.GetMaxWidth //获取布局最大宽度
IDWriteTextLayout.GetMetrics //检索格式化后的字符串的总体度量
IDWriteTextLayout.GetOverhangMetrics //返回布局及其包含的所有对象(包括文本字形和嵌入式对象)的延伸量(以与设备无关的像素(DIP)为单位)
IDWriteTextLayout.GetStrikethrough //获取指定位置处文本中存在的删除线
IDWriteTextLayout.GetTypography //获取指定位置处文本的版式设置
IDWriteTextLayout.GetUnderline //获取指定位置处文本中存在的下划线
IDWriteTextLayout.HitTestPoint //获取布局框中指定点的 DWRITE_HIT_TEST_METRICS 结构; 它还报告该点是否在由文本布局表示的文本字符串内
IDWriteTextLayout.HitTestTextPosition //获取相对于布局框左上角的指定文本的位置以及包含围绕该文本位置的输出几何图形的 DWRITE_HIT_TEST_METRICS 结构
IDWriteTextLayout.HitTestTextRange //在给定起始文本位置和文本长度的情况下, 获取指定文本位置的 DWRITE_HIT_TEST_METRICS 结构
IDWriteTextLayout.SetDrawingEffect //设置应用程序定义的绘制效果
IDWriteTextLayout.SetFontCollection //设置字体集合
IDWriteTextLayout.SetFontFamilyName //为指定文本范围内的文本设置以 Null 结尾的字体系列名称
IDWriteTextLayout.SetFontSize //设置指定文本范围内文本的字体高度(以 em 为单位)
IDWriteTextLayout.SetFontStretch //设置指定文本范围内文本的字体拉伸方式
IDWriteTextLayout.SetFontStyle //设置指定文本范围内文本的字体样式
IDWriteTextLayout.SetFontWeight //设置指定文本范围内文本的字体粗细
IDWriteTextLayout.SetInlineObject //设置嵌入式对象
IDWriteTextLayout.SetLocaleName //设置指定文本范围内文本的区域设置名称
IDWriteTextLayout.SetMaxHeight //设置布局最大高度
IDWriteTextLayout.SetMaxWidth //设置布局最大宽度
IDWriteTextLayout.SetStrikethrough //为指定文本范围内的文本设置删除线
IDWriteTextLayout.SetTypography //为指定文本范围内的文本设置字体版式功能
IDWriteTextLayout.SetUnderline //为指定文本范围内的文本设置下划线
测试代码:
uses Direct2D, D2D1;
{构建 DWRITE_TEXT_RANGE 结构的函数}
function DWriteTextRange(pos,len: Cardinal): TDwriteTextRange;
begin
Result.startPosition := pos;
Result.length := len;
end;
{构建 DWRITE_FONT_FEATURE 结构的函数}
function DWriteFontFeature(nameTag: Integer; parameter: Cardinal): TDwriteFontFeature;
begin
Result.nameTag := nameTag;
Result.parameter := parameter; //选择器索引, 0 表示禁用
end;
procedure TForm1.FormPaint(Sender: TObject);
var
cvs: TDirect2DCanvas;
str: string;
iTextFormat: IDWriteTextFormat;
iSolidColorBrush: ID2D1SolidColorBrush;
iTextLayout: IDWriteTextLayout;
iTypography: IDWriteTypography;
begin
str := 'Hello World using DirectWrite!';
{建立 IDWriteTextFormat}
DWriteFactory.CreateTextFormat(
'Gabriola', //Gabriola 是 Win7 的新字体
nil,
DWRITE_FONT_WEIGHT_REGULAR,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
72.0,
'en-us',
iTextFormat
);
iTextFormat.SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
iTextFormat.SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
{建立 IDWriteTextLayout}
DWriteFactory.CreateTextLayout(
PWideChar(str), //文本
Length(str), //文本长度
iTextFormat, //IDWriteTextFormat 接口
ClientWidth, //宽度
ClientHeight, //高度
iTextLayout //输出 IDWriteTextLayout
);
{设置部分文本的字号、下划线、粗体}
iTextLayout.SetFontSize(100.0, DWriteTextRange(18, 6)); //指定从 18 个字符起的 6 个字符的大小为 100
iTextLayout.SetUnderline(True, DWriteTextRange(18, 11));
iTextLayout.SetFontWeight(DWRITE_FONT_WEIGHT_BOLD, DWriteTextRange(18, 11));
{设置不同的花式变体, 只对支持该功能的字体(如 Gabriola)有效}
DWriteFactory.CreateTypography(iTypography);
iTypography.AddFontFeature(DWriteFontFeature(DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_7, 1));
iTextLayout.SetTypography(iTypography, DWriteTextRange(0, Length(str)));
cvs := TDirect2DCanvas.Create(Canvas, ClientRect);
cvs.RenderTarget.CreateSolidColorBrush(D2D1ColorF(clGreen), nil, iSolidColorBrush);
cvs.RenderTarget.BeginDraw;
cvs.RenderTarget.Clear(D2D1ColorF(clWhite));
cvs.RenderTarget.DrawTextLayout(D2D1PointF(0,0), iTextLayout, iSolidColorBrush);
cvs.RenderTarget.EndDraw();
cvs.Free;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
Repaint;
end;
效果图:
测试其它字体和其它花式的程序: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) ComboBox1: TComboBox; ComboBox2: TComboBox; procedure FormPaint(Sender: TObject); procedure FormResize(Sender: TObject); procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} uses Direct2D, D2D1; const list = 'DWRITE_FONT_FEATURE_TAG_ALTERNATIVE_FRACTIONS ,' + 'DWRITE_FONT_FEATURE_TAG_PETITE_CAPITALS_FROM_CAPITALS ,' + 'DWRITE_FONT_FEATURE_TAG_SMALL_CAPITALS_FROM_CAPITALS ,' + 'DWRITE_FONT_FEATURE_TAG_CONTEXTUAL_ALTERNATES ,' + 'DWRITE_FONT_FEATURE_TAG_CASE_SENSITIVE_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_GLYPH_COMPOSITION_DECOMPOSITION ,' + 'DWRITE_FONT_FEATURE_TAG_CONTEXTUAL_LIGATURES ,' + 'DWRITE_FONT_FEATURE_TAG_CAPITAL_SPACING ,' + 'DWRITE_FONT_FEATURE_TAG_CONTEXTUAL_SWASH ,' + 'DWRITE_FONT_FEATURE_TAG_CURSIVE_POSITIONING ,' + 'DWRITE_FONT_FEATURE_TAG_DEFAULT ,' + 'DWRITE_FONT_FEATURE_TAG_DISCRETIONARY_LIGATURES ,' + 'DWRITE_FONT_FEATURE_TAG_EXPERT_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_FRACTIONS ,' + 'DWRITE_FONT_FEATURE_TAG_FULL_WIDTH ,' + 'DWRITE_FONT_FEATURE_TAG_HALF_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_HALANT_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_ALTERNATE_HALF_WIDTH ,' + 'DWRITE_FONT_FEATURE_TAG_HISTORICAL_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_HORIZONTAL_KANA_ALTERNATES ,' + 'DWRITE_FONT_FEATURE_TAG_HISTORICAL_LIGATURES ,' + 'DWRITE_FONT_FEATURE_TAG_HALF_WIDTH ,' + 'DWRITE_FONT_FEATURE_TAG_HOJO_KANJI_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_JIS04_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_JIS78_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_JIS83_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_JIS90_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_KERNING ,' + 'DWRITE_FONT_FEATURE_TAG_STANDARD_LIGATURES ,' + 'DWRITE_FONT_FEATURE_TAG_LINING_FIGURES ,' + 'DWRITE_FONT_FEATURE_TAG_LOCALIZED_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_MARK_POSITIONING ,' + 'DWRITE_FONT_FEATURE_TAG_MATHEMATICAL_GREEK ,' + 'DWRITE_FONT_FEATURE_TAG_MARK_TO_MARK_POSITIONING ,' + 'DWRITE_FONT_FEATURE_TAG_ALTERNATE_ANNOTATION_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_NLC_KANJI_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_OLD_STYLE_FIGURES ,' + 'DWRITE_FONT_FEATURE_TAG_ORDINALS ,' + 'DWRITE_FONT_FEATURE_TAG_PROPORTIONAL_ALTERNATE_WIDTH ,' + 'DWRITE_FONT_FEATURE_TAG_PETITE_CAPITALS ,' + 'DWRITE_FONT_FEATURE_TAG_PROPORTIONAL_FIGURES ,' + 'DWRITE_FONT_FEATURE_TAG_PROPORTIONAL_WIDTHS ,' + 'DWRITE_FONT_FEATURE_TAG_QUARTER_WIDTHS ,' + 'DWRITE_FONT_FEATURE_TAG_REQUIRED_LIGATURES ,' + 'DWRITE_FONT_FEATURE_TAG_RUBY_NOTATION_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_ALTERNATES ,' + 'DWRITE_FONT_FEATURE_TAG_SCIENTIFIC_INFERIORS ,' + 'DWRITE_FONT_FEATURE_TAG_SMALL_CAPITALS ,' + 'DWRITE_FONT_FEATURE_TAG_SIMPLIFIED_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_1 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_2 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_3 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_4 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_5 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_6 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_7 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_8 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_9 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_10 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_11 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_12 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_13 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_14 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_15 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_16 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_17 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_18 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_19 ,' + 'DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_20 ,' + 'DWRITE_FONT_FEATURE_TAG_SUBSCRIPT ,' + 'DWRITE_FONT_FEATURE_TAG_SUPERSCRIPT ,' + 'DWRITE_FONT_FEATURE_TAG_SWASH ,' + 'DWRITE_FONT_FEATURE_TAG_TITLING ,' + 'DWRITE_FONT_FEATURE_TAG_TRADITIONAL_NAME_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_TABULAR_FIGURES ,' + 'DWRITE_FONT_FEATURE_TAG_TRADITIONAL_FORMS ,' + 'DWRITE_FONT_FEATURE_TAG_THIRD_WIDTHS ,' + 'DWRITE_FONT_FEATURE_TAG_UNICASE ,' + 'DWRITE_FONT_FEATURE_TAG_SLASHED_ZERO '; var arrFeatureTag: array[0..78] of Integer = ( DWRITE_FONT_FEATURE_TAG_ALTERNATIVE_FRACTIONS , DWRITE_FONT_FEATURE_TAG_PETITE_CAPITALS_FROM_CAPITALS , DWRITE_FONT_FEATURE_TAG_SMALL_CAPITALS_FROM_CAPITALS , DWRITE_FONT_FEATURE_TAG_CONTEXTUAL_ALTERNATES , DWRITE_FONT_FEATURE_TAG_CASE_SENSITIVE_FORMS , DWRITE_FONT_FEATURE_TAG_GLYPH_COMPOSITION_DECOMPOSITION , DWRITE_FONT_FEATURE_TAG_CONTEXTUAL_LIGATURES , DWRITE_FONT_FEATURE_TAG_CAPITAL_SPACING , DWRITE_FONT_FEATURE_TAG_CONTEXTUAL_SWASH , DWRITE_FONT_FEATURE_TAG_CURSIVE_POSITIONING , DWRITE_FONT_FEATURE_TAG_DEFAULT , DWRITE_FONT_FEATURE_TAG_DISCRETIONARY_LIGATURES , DWRITE_FONT_FEATURE_TAG_EXPERT_FORMS , DWRITE_FONT_FEATURE_TAG_FRACTIONS , DWRITE_FONT_FEATURE_TAG_FULL_WIDTH , DWRITE_FONT_FEATURE_TAG_HALF_FORMS , DWRITE_FONT_FEATURE_TAG_HALANT_FORMS , DWRITE_FONT_FEATURE_TAG_ALTERNATE_HALF_WIDTH , DWRITE_FONT_FEATURE_TAG_HISTORICAL_FORMS , DWRITE_FONT_FEATURE_TAG_HORIZONTAL_KANA_ALTERNATES , DWRITE_FONT_FEATURE_TAG_HISTORICAL_LIGATURES , DWRITE_FONT_FEATURE_TAG_HALF_WIDTH , DWRITE_FONT_FEATURE_TAG_HOJO_KANJI_FORMS , DWRITE_FONT_FEATURE_TAG_JIS04_FORMS , DWRITE_FONT_FEATURE_TAG_JIS78_FORMS , DWRITE_FONT_FEATURE_TAG_JIS83_FORMS , DWRITE_FONT_FEATURE_TAG_JIS90_FORMS , DWRITE_FONT_FEATURE_TAG_KERNING , DWRITE_FONT_FEATURE_TAG_STANDARD_LIGATURES , DWRITE_FONT_FEATURE_TAG_LINING_FIGURES , DWRITE_FONT_FEATURE_TAG_LOCALIZED_FORMS , DWRITE_FONT_FEATURE_TAG_MARK_POSITIONING , DWRITE_FONT_FEATURE_TAG_MATHEMATICAL_GREEK , DWRITE_FONT_FEATURE_TAG_MARK_TO_MARK_POSITIONING , DWRITE_FONT_FEATURE_TAG_ALTERNATE_ANNOTATION_FORMS , DWRITE_FONT_FEATURE_TAG_NLC_KANJI_FORMS , DWRITE_FONT_FEATURE_TAG_OLD_STYLE_FIGURES , DWRITE_FONT_FEATURE_TAG_ORDINALS , DWRITE_FONT_FEATURE_TAG_PROPORTIONAL_ALTERNATE_WIDTH , DWRITE_FONT_FEATURE_TAG_PETITE_CAPITALS , DWRITE_FONT_FEATURE_TAG_PROPORTIONAL_FIGURES , DWRITE_FONT_FEATURE_TAG_PROPORTIONAL_WIDTHS , DWRITE_FONT_FEATURE_TAG_QUARTER_WIDTHS , DWRITE_FONT_FEATURE_TAG_REQUIRED_LIGATURES , DWRITE_FONT_FEATURE_TAG_RUBY_NOTATION_FORMS , DWRITE_FONT_FEATURE_TAG_STYLISTIC_ALTERNATES , DWRITE_FONT_FEATURE_TAG_SCIENTIFIC_INFERIORS , DWRITE_FONT_FEATURE_TAG_SMALL_CAPITALS , DWRITE_FONT_FEATURE_TAG_SIMPLIFIED_FORMS , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_1 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_2 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_3 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_4 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_5 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_6 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_7 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_8 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_9 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_10 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_11 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_12 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_13 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_14 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_15 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_16 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_17 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_18 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_19 , DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_20 , DWRITE_FONT_FEATURE_TAG_SUBSCRIPT , DWRITE_FONT_FEATURE_TAG_SUPERSCRIPT , DWRITE_FONT_FEATURE_TAG_SWASH , DWRITE_FONT_FEATURE_TAG_TITLING , DWRITE_FONT_FEATURE_TAG_TRADITIONAL_NAME_FORMS , DWRITE_FONT_FEATURE_TAG_TABULAR_FIGURES , DWRITE_FONT_FEATURE_TAG_TRADITIONAL_FORMS , DWRITE_FONT_FEATURE_TAG_THIRD_WIDTHS , DWRITE_FONT_FEATURE_TAG_UNICASE , DWRITE_FONT_FEATURE_TAG_SLASHED_ZERO ); {构建 DWRITE_TEXT_RANGE 结构的函数} function DWriteTextRange(pos,len: Cardinal): TDwriteTextRange; begin Result.startPosition := pos; Result.length := len; end; {构建 DWRITE_FONT_FEATURE 结构的函数} function DWriteFontFeature(nameTag: Integer; parameter: Cardinal): TDwriteFontFeature; begin Result.nameTag := nameTag; Result.parameter := parameter; //选择器索引, 0 表示禁用 end; procedure TForm1.FormCreate(Sender: TObject); begin ComboBox1.Align := alTop; ComboBox1.Items := Screen.Fonts; ComboBox1.Text := 'Gabriola'; ComboBox1.OnChange := OnPaint; ComboBox2.Align := alTop; ComboBox2.Items.CommaText := list; ComboBox2.ItemIndex := 55; ComboBox2.OnChange := OnPaint; end; procedure TForm1.FormPaint(Sender: TObject); var cvs: TDirect2DCanvas; str: string; iTextFormat: IDWriteTextFormat; iSolidColorBrush: ID2D1SolidColorBrush; iTextLayout: IDWriteTextLayout; iTypography: IDWriteTypography; begin str := 'Hello World using DirectWrite!'; DWriteFactory.CreateTextFormat( PWideChar(ComboBox1.Text), //Gabriola nil, DWRITE_FONT_WEIGHT_REGULAR, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 72.0, 'en-us', iTextFormat ); iTextFormat.SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER); iTextFormat.SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER); DWriteFactory.CreateTextLayout( PWideChar(str), Length(str), iTextFormat, ClientWidth, ClientHeight, iTextLayout ); iTextLayout.SetFontSize(100.0, DWriteTextRange(18, 6)); iTextLayout.SetUnderline(True, DWriteTextRange(18, 11)); iTextLayout.SetFontWeight(DWRITE_FONT_WEIGHT_BOLD, DWriteTextRange(18, 11)); DWriteFactory.CreateTypography(iTypography); iTypography.AddFontFeature(DWriteFontFeature(arrFeatureTag[ComboBox2.ItemIndex], 1)); iTextLayout.SetTypography(iTypography, DWriteTextRange(0, Length(str))); cvs := TDirect2DCanvas.Create(Canvas, ClientRect); cvs.RenderTarget.CreateSolidColorBrush(D2D1ColorF(clBlack), nil, iSolidColorBrush); cvs.RenderTarget.BeginDraw; cvs.RenderTarget.Clear(D2D1ColorF(clWhite)); cvs.RenderTarget.DrawTextLayout(D2D1PointF(0,0), iTextLayout, iSolidColorBrush); cvs.RenderTarget.EndDraw(); cvs.Free; end; procedure TForm1.FormResize(Sender: TObject); begin Repaint; end; end.