文档章节

Direct2D (38) : RenderTarget.DrawTextLayout() 与 IDWriteTextLayout

涂孟超
 涂孟超
发布于 2014/09/26 15:39
字数 1654
阅读 35
收藏 0

使用 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.

本文转载自:http://www.cnblogs.com/del/archive/2011/04/13/2014652.html

涂孟超
粉丝 12
博文 2011
码字总数 14107
作品 0
深圳
程序员
私信 提问
Direct2D 学习笔记(1)

Direct2D 应用程序接口概述 资源网站https://docs.microsoft.com/en-us/windows/win32/Direct2D/the-direct2d-api 主要用到的头文件是:d2d1.h 编译时需要连接文件:d2d1.lib Direct2D接口的...

Halation
09/27
0
0
关于Direct3D11里汉字显示的一些思考

本系列文章由zhmxy555(毛星云)编写,转载请注明出处。 http://blog.csdn.net/zhmxy555/article/details/8147234 作者:毛星云 邮箱: happylifemxy@163.com 这篇文章里,浅墨希望与大家一起...

长平狐
2012/11/12
858
0
Direct2D 学习笔记 前言

Direct2D模板程序网址:https://docs.microsoft.com/zh-cn/windows/win32/direct2d/direct2d-quickstart DirectX SDK下载地址:https://www.microsoft.com/en-us/download/details.aspx?id=......

Halation
09/24
0
0
Direct2D教程(十)绘制文本

概述 在Direct2D中,文本的绘制是通过DirectWrite来实现的,DirectWrite实际上已经是一个独立的DirectX组件了。关于DirectWrite,我摘录了MSDN的一段文字。 DirectWrite介绍 当今的应用程序应...

吞吞吐吐的
2017/10/17
0
0
使用 Direct2D 绘制分层窗口

这是我关于Direct2D的第三篇介绍了,今天主要讲下其无可比拟的互操作性。为了避免繁缛末节的讲述,我们从一个实例入手:层级窗口。相对于windows的其它众多功能。层级窗口并未做相应的更新,...

Dy_
2014/01/16
8.6K
10

没有更多内容

加载失败,请刷新页面

加载更多

经典系统设计面试题解析:如何设计TinyURL(二)

原文链接:https://www.educative.io/courses/grokking-the-system-design-interview/m2ygV4E81AR 编者注:本文以一道经典的系统设计面试题:《如何设计TinyURL》的参考答案和解析为例,帮助...

APEMESH
31分钟前
7
0
使用logstash同步MySQL数据到ES

概述   在生成业务常有将MySQL数据同步到ES的需求,如果需要很高的定制化,往往需要开发同步程序用于处理数据。但没有特殊业务需求,官方提供的logstash就很有优势了。   在使用logstas...

zxiaofan666
41分钟前
8
0
X-MSG-IM-分布式信令跟踪能力

经过一周多的鏖战, X-MSG-IM的分布式信令跟踪能力已基本具备, 特点是: 实时. 只有要RX/TX就会实时产生信令跟踪事件, 先入kafka, 再入influxdb待查. 同时提供实时sub/pub接口. 完备. 可以完整...

dev5
51分钟前
6
0
OpenJDK之CyclicBarrier

OpenJDK8,本人看的是openJDK。以前就看过,只是经常忘记,所以记录下 图1 CyclicBarrier是Doug Lea在JDK1.5中引入的,作用就不详细描述了,主要有如下俩个方法使用: await()方法,如果当前线...

克虏伯
54分钟前
6
0
实战项目-学成在线(八)

在前后端分离架构中,服务层被拆分成了很多的微服务,微服务的信息如何管理?Spring Cloud中提供服务注册中心来管理微服务信息。 注册中心作用: 1、微服务数量众多,要进行远程调用就需要知...

lianbang_W
55分钟前
6
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部