Direct2D를 사용하여 렌더링

Direct2D는 IDWriteTextFormat 또는 IDWriteTextLayout 에서 설명하는 서식이 있는 텍스트를 Direct2D 화면으로 렌더링하는 메서드를 제공합니다.

IDWriteTextFormat에서 설명하는 렌더링 텍스트

IDWriteTextFormat 개체를 사용하여 문자열을 렌더링하여 전체 문자열의 서식을 설명하려면 Direct2D에서 제공하는 ID2D1RenderTarget::D rawText 메서드를 사용합니다.

  1. 렌더링 영역의 차원을 검색하여 텍스트 레이아웃의 영역을 정의하고 동일한 차원의 Direct2D 사각형을 만듭니다.

    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. ID2D1RenderTarget::D rawText 메서드 및 IDWriteTextFormat 개체를 사용하여 텍스트를 화면에 렌더링합니다. ID2D1RenderTarget::D rawText 메서드는 다음 매개 변수를 사용합니다.

    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.
        );
    
    

IDWriteText 레이아웃 개체 렌더링

IDWriteTextLayout 개체에서 지정한 텍스트 레이아웃 설정을 사용하여 텍스트를 그리려면 MultiformattedText::D rawText 메서드의 코드를 변경하여 IDWriteTextLayout::D rawTextLayout을 사용합니다.

  1. D2D1_POINT_2F 변수를 Delcare로 설정하고 창의 왼쪽 위 지점으로 설정합니다.

    D2D1_POINT_2F origin = D2D1::Point2F(
        static_cast<FLOAT>(rc.left / dpiScaleX_),
        static_cast<FLOAT>(rc.top / dpiScaleY_)
        );
    
    
  2. Direct2D 렌더링 대상의 ID2D1RenderTarget::D rawTextLayout 메서드를 호출하고 IDWriteTextLayout 포인터를 전달하여 화면에 텍스트를 그립니다.

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