本文整理汇总了C++中microsoft::wrl::ComPtr::GetMetrics方法的典型用法代码示例。如果您正苦于以下问题:C++ ComPtr::GetMetrics方法的具体用法?C++ ComPtr::GetMetrics怎么用?C++ ComPtr::GetMetrics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类microsoft::wrl::ComPtr
的用法示例。
在下文中一共展示了ComPtr::GetMetrics方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ZeroMemory
// Initializes D2D resources used for text rendering.
SampleDebugTextRenderer::SampleDebugTextRenderer(const std::shared_ptr<DX::DeviceResources>& deviceResources) :
Overlay(deviceResources)
{
ZeroMemory(&m_textMetrics, sizeof(DWRITE_TEXT_METRICS) * XINPUT_MAX_CONTROLLERS);
ZeroMemory(&m_textMetricsFPS, sizeof(DWRITE_TEXT_METRICS));
for (unsigned int i = 0; i < 4; i++)
{
m_text[i] = L"";
}
// Create device-independent resources.
DX::ThrowIfFailed(
m_deviceResources->GetDWriteFactory()->CreateTextFormat(
L"Segoe UI",
nullptr,
DWRITE_FONT_WEIGHT_LIGHT,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
32.0f,
L"en-US",
&m_textFormat
)
);
DX::ThrowIfFailed(
m_textFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR)
);
DX::ThrowIfFailed(
m_deviceResources->GetD2DFactory()->CreateDrawingStateBlock(&m_stateBlock)
);
// Generate static input text height.
unsigned int lines = 6; // Increase this if you need to display more than 5 separate action types
std::wstring inputText = L"";
for (unsigned int i = 0; i < lines; i++) inputText += L"\n";
Microsoft::WRL::ComPtr<IDWriteTextLayout> layout;
DX::ThrowIfFailed(
m_deviceResources->GetDWriteFactory()->CreateTextLayout(
inputText.c_str(),
(uint32) inputText.length(),
m_textFormat.Get(),
DEBUG_INPUT_TEXT_MAX_WIDTH,
DEBUG_INPUT_TEXT_MAX_HEIGHT,
&layout
)
);
DWRITE_TEXT_METRICS metrics;
DX::ThrowIfFailed(
layout->GetMetrics(&metrics)
);
m_inputTextHeight = metrics.height;
CreateDeviceDependentResources();
}
示例2:
bool CanvasD2D::MeasureTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect)
{
Microsoft::WRL::ComPtr<IDWriteTextLayout> textLayout;
HRESULT hr = c_DWFactory->CreateTextLayout(
str,
strLen,
((TextFormatD2D&)format).m_TextFormat.Get(),
10000,
10000,
textLayout.GetAddressOf());
if (SUCCEEDED(hr))
{
DWRITE_TEXT_METRICS metrics;
textLayout->GetMetrics(&metrics);
rect.Width = metrics.width + 5.0f;
rect.Height = metrics.height + 1.0f; // 1.0f to get same result as GDI+.
return true;
}
return false;
}
示例3:
DWRITE_TEXT_METRICS TextFormatD2D::GetMetrics(
const WCHAR* str, UINT strLen, bool gdiEmulation, float maxWidth)
{
// GDI+ compatibility: If the last character is a newline, GDI+ measurements seem to ignore it.
bool strippedLastNewLine = false;
if (strLen > 2 && str[strLen - 1] == L'\n')
{
strippedLastNewLine = true;
--strLen;
if (str[strLen - 1] == L'\r')
{
--strLen;
}
}
DWRITE_TEXT_METRICS metrics = {0};
Microsoft::WRL::ComPtr<IDWriteTextLayout> textLayout;
HRESULT hr = CanvasD2D::c_DWFactory->CreateTextLayout(
str,
strLen,
m_TextFormat.Get(),
maxWidth,
10000,
textLayout.GetAddressOf());
if (SUCCEEDED(hr))
{
const float xOffset = m_TextFormat->GetFontSize() / 6.0f;
if (gdiEmulation)
{
Microsoft::WRL::ComPtr<IDWriteTextLayout1> textLayout1;
textLayout.As(&textLayout1);
const float emOffset = xOffset / 24.0f;
const DWRITE_TEXT_RANGE range = {0, strLen};
textLayout1->SetCharacterSpacing(emOffset, emOffset, 0.0f, range);
}
textLayout->GetMetrics(&metrics);
if (metrics.width > 0.0f)
{
if (gdiEmulation)
{
metrics.width += xOffset * 2;
metrics.height += m_ExtraHeight;
// GDI+ compatibility: If the string contains a newline (even if it is the
// stripped last character), GDI+ adds the line gap to the overall height.
if (strippedLastNewLine || wmemchr(str, L'\n', strLen) != nullptr)
{
metrics.height += m_LineGap;
}
}
else
{
// GDI+ compatibility: With accurate metrics, the line gap needs to be subtracted
// from the overall height if the string does not contain newlines.
if (!strippedLastNewLine && wmemchr(str, L'\n', strLen) == nullptr)
{
metrics.height -= m_LineGap;
}
}
}
else
{
// GDI+ compatibility: Get rid of the height that DirectWrite assigns to zero-width
// strings.
metrics.height = 0.0f;
}
}
return metrics;
}