Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

Render Using Direct2D

  • 2020-08-19
Feedback

In this article

Direct2D provides methods for rendering either text with formatting described by only anIDWriteTextFormat or anIDWriteTextLayout to a Direct2D surface.

Rendering Text Described by IDWriteTextFormat

To render a string using anIDWriteTextFormat object to describe the formatting for the entire string, use theID2D1RenderTarget::DrawText method provided byDirect2D.

  1. Define the area for the text layout by retrieving the dimensions of the rendering area, and create aDirect2D rectangle that has the same dimensions.

    D2D1_RECT_F layoutRect = D2D1::RectF(    static_cast<FLOAT>(rc.left) / dpiScaleX_,    static_cast<FLOAT>(rc.top) / dpiScaleY_,    static_cast<FLOAT>(rc.right - rc.left) / dpiScaleX_,    static_cast<FLOAT>(rc.bottom - rc.top) / dpiScaleY_    );
  2. Use theID2D1RenderTarget::DrawText method and theIDWriteTextFormat object to render text to the screen. TheID2D1RenderTarget::DrawText method takes the following parameters:

    pRT_->DrawText(    wszText_,        // The string to render.    cTextLength_,    // The string's length.    pTextFormat_,    // The text format.    layoutRect,       // The region of the window where the text will be rendered.    pBlackBrush_     // The brush used to draw the text.    );

Rendering a IDWriteText Layout Object

To draw the text with the text layout settings specified by theIDWriteTextLayout object, change the code in the MultiformattedText::DrawText method to useIDWriteTextLayout::DrawTextLayout.

  1. Delcare aD2D1_POINT_2F variable and set it to the upper-left point of the window.

    D2D1_POINT_2F origin = D2D1::Point2F(    static_cast<FLOAT>(rc.left / dpiScaleX_),    static_cast<FLOAT>(rc.top / dpiScaleY_)    );
  2. Draw the text to the screen by calling theID2D1RenderTarget::DrawTextLayout method of theDirect2D render target and passing theIDWriteTextLayout pointer.

    pRT_->DrawTextLayout(    origin,    pTextLayout_,    pBlackBrush_    );

 

 


Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo