I investigated what metrics I can get from DirectWrite text layout (IDWriteTextLayout).
IDWriteTextLayout::GetMaxWidth(), GetMaxHeight()
It seems that GetMaxWidth() and GetMaxHeight() simply return the layout width and height which are specified at IDWriteFactory::CreateTextLayout method().
IDWriteTextLayout::DetermineMinWidth(FLOAT)
DetermineMinWidth() returns the maximum width of the word in the text. If the layout width is smaller than this width, the word in the text is broken.
example 1:
std::wstring text(L"Aa Bbbbb");
m_pDWriteFactory->CreateTextLayout(
text.c_str(),
text.length(),
textFormat,
120.0f, 30.0f,
&textLayout);
FLOAT width;
textLayout->DetermineMinWidth(&width);

example 2:
std::wstring text(L"Aaaaaa Bbb Cccc");
...

DWRITE_TEXT_METRICS layoutWidth/layoutHeight
layoutWidth and layoutHeight of a DWRITE_TEXT_METRICS structure are same as the layout width and height which are specified at IDWriteFactory::CreateTextLayout method().
DWRITE_TEXT_METRICS width/height
DWRITE_TEXT_METRICS.width indicates the width of the formatted text, while ignoring trailing whitespace at the end of each line.
DWRITE_TEXT_METRICS.height indicates the height of the formatted text.
example 1:
std::wstring text(L"Abc");
m_pDWriteFactory->CreateTextLayout(
text.c_str(),
text.length(),
textFormat,
120.0f, 30.0f,
&textLayout);
DWRITE_TEXT_METRICS textMetrics;
textLayout->GetMetrics(&textMetrics);

example 2:
std::wstring text(L" Abc ");
...

example 3:
std::wstring text(L"Abc Def");
...

DWRITE_TEXT_METRICS widthIncludingTrailingWhitespace
DWRITE_TEXT_METRICS.widthIncludingTrailingWhitespace indicates the width of the formatted text, taking into account the trailing whitespace at the end of each line.
example 1:
std::wstring text(L" Abc ");

Filed under: Article, C++, C++ 0x, Metro, WinRT, Windows Development by yohei
Comments Off on Metroスタイルアプリ開発をチェック