本文整理汇总了C++中IDWriteTextLayout::GetClusterMetrics方法的典型用法代码示例。如果您正苦于以下问题:C++ IDWriteTextLayout::GetClusterMetrics方法的具体用法?C++ IDWriteTextLayout::GetClusterMetrics怎么用?C++ IDWriteTextLayout::GetClusterMetrics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDWriteTextLayout
的用法示例。
在下文中一共展示了IDWriteTextLayout::GetClusterMetrics方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetFitCharCount
int CDirectWriteRenderer::GetFitCharCount(LPCWSTR pText, int Length, int Width, CDirectWriteFont &Font)
{
if (pText == nullptr || Length == 0)
return 0;
if (m_pRenderTarget == nullptr)
return 0;
int FitCharCount = 0;
IDWriteFactory *pFactory = m_System.GetDWriteFactory();
if (pFactory != nullptr) {
IDWriteTextFormat *pTextFormat = Font.GetTextFormat();
if (pTextFormat != nullptr) {
IDWriteTextLayout *pTextLayout;
pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
pTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
if (Length < 0)
Length = ::lstrlenW(pText);
HRESULT hr = pFactory->CreateTextLayout(
pText,
Length,
pTextFormat,
static_cast<float>(Width),
m_pRenderTarget->GetSize().height,
&pTextLayout);
if (SUCCEEDED(hr)) {
Util::CTempBuffer<DWRITE_CLUSTER_METRICS, 256> ClusterMetrics(Length);
UINT32 ClusterCount;
hr = pTextLayout->GetClusterMetrics(ClusterMetrics.GetBuffer(), Length, &ClusterCount);
if (SUCCEEDED(hr)) {
float Pos = 0.0f;
for (UINT32 i = 0; i < ClusterCount; i++) {
Pos += ClusterMetrics[i].width;
if (static_cast<int>(std::ceil(Pos)) > Width)
break;
FitCharCount += ClusterMetrics[i].length;
}
}
pTextLayout->Release();
}
pTextFormat->Release();
}
pFactory->Release();
}
return FitCharCount;
}