This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Direct2D provides methods for rendering either text with formatting described by only anIDWriteTextFormat or anIDWriteTextLayout to a Direct2D surface.
To render a string using anIDWriteTextFormat object to describe the formatting for the entire string, use theID2D1RenderTarget::DrawText method provided byDirect2D.
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_ );
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. );
To draw the text with the text layout settings specified by theIDWriteTextLayout object, change the code in the MultiformattedText::DrawText method to useIDWriteTextLayout::DrawTextLayout.
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_) );
Draw the text to the screen by calling theID2D1RenderTarget::DrawTextLayout method of theDirect2D render target and passing theIDWriteTextLayout pointer.
pRT_->DrawTextLayout( origin, pTextLayout_, pBlackBrush_ );
Was this page helpful?
Was this page helpful?