Advertisement

Direct2D and DirectWrite wrap text in layer

Started by April 18, 2020 04:14 PM
0 comments, last by gomidas 4 years, 8 months ago

Hello, I am trying to wrap text inside a layer within client area. Is that possible to do that ?

...

m_d2dRenderTarget->CreateSolidColorBrush(ColorF(colorf), &m_Brush);
m_d2dRenderTarget->BeginDraw();
wstring textWstr = wstring(text.begin(), text.end());
const wchar_t* wcharText = textWstr.c_str();
// Create a layer.
ID2D1Layer* mainLayer = NULL;  
m_d2dRenderTarget->CreateLayer(NULL, &mainLayer);
m_d2dRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(0, 0));
 m_d2dRenderTarget->PushLayer(D2D1::LayerParameters(D2D1::RectF(0, 0, 200, m_screenSize.y)), mainLayer);
m_d2dRenderTarget->DrawTextW(wcharText, wcslen(wcharText), textFormat, RectF(posX, posY, m_screenSize.x, m_screenSize.y), m_Brush);
m_d2dRenderTarget->PopLayer();
m_d2dRenderTarget->EndDraw();

textFormat->Release();
mainLayer->Release();

...

I am trying to achieve something like in PAINT's Text drawing tool. Just like in this image.

This topic is closed to new replies.

Advertisement