本文整理汇总了C++中IDWriteTextLayout::Release方法的典型用法代码示例。如果您正苦于以下问题:C++ IDWriteTextLayout::Release方法的具体用法?C++ IDWriteTextLayout::Release怎么用?C++ IDWriteTextLayout::Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDWriteTextLayout
的用法示例。
在下文中一共展示了IDWriteTextLayout::Release方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool CanvasD2D::MeasureTextLinesW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect, UINT& lines)
{
((TextFormatD2D&)format).m_TextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_WRAP);
IDWriteTextLayout* textLayout;
HRESULT hr = c_DWFactory->CreateTextLayout(
str,
strLen,
((TextFormatD2D&)format).m_TextFormat,
rect.Width,
10000,
&textLayout);
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+.
lines = metrics.lineCount;
textLayout->Release();
return true;
}
return false;
}
示例2: createTextLayout
// Create geometry from a string
void STDMETHODCALLTYPE CFW1FontWrapper::AnalyzeString(
ID3D11DeviceContext *pContext,
const WCHAR *pszString,
const WCHAR *pszFontFamily,
FLOAT FontSize,
const FW1_RECTF *pLayoutRect,
UINT32 Color,
UINT Flags,
IFW1TextGeometry *pTextGeometry
) {
IDWriteTextLayout *pTextLayout = createTextLayout(pszString, pszFontFamily, FontSize, pLayoutRect, Flags);
if(pTextLayout != NULL) {
AnalyzeTextLayout(
pContext,
pTextLayout,
pLayoutRect->Left,
pLayoutRect->Top,
Color,
Flags,
pTextGeometry
);
pTextLayout->Release();
}
}
示例3: DText
void ClixRenderer::DText(std::wstring text, float x, float y, float w, float h, float size, CColor color)
{
IDWriteTextLayout* textLayout;
D2Brush->SetColor(CColor::ColorF(color));
pDWriteFactory->CreateTextLayout(text.c_str(), text.length(), pTextFormat, w, h, &textLayout);
DWRITE_TEXT_RANGE range = { 0, text.length() };
textLayout->SetFontSize(size, range);
D2Render->DrawTextLayout(D2D1::Point2F(x, y), textLayout, D2Brush);
textLayout->Release();
}
示例4: 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;
}
示例5: GetTextMetrics
bool CDirectWriteRenderer::GetTextMetrics(
LPCWSTR pText, int Length, CDirectWriteFont &Font, TextMetrics *pMetrics)
{
if (pText == nullptr || pMetrics == nullptr)
return false;
if (m_pRenderTarget == nullptr)
return false;
HRESULT hr = E_UNEXPECTED;
IDWriteFactory *pFactory = m_System.GetDWriteFactory();
if (pFactory != nullptr) {
IDWriteTextFormat *pTextFormat = Font.GetTextFormat();
if (pTextFormat != nullptr) {
D2D1_SIZE_F Size;
IDWriteTextLayout *pTextLayout;
pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
pTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
if (Length < 0)
Length = ::lstrlenW(pText);
Size = m_pRenderTarget->GetSize();
hr = pFactory->CreateTextLayout(
pText,
Length,
pTextFormat,
Size.width,
Size.height,
&pTextLayout);
if (SUCCEEDED(hr)) {
DWRITE_TEXT_METRICS Metrics;
hr = pTextLayout->GetMetrics(&Metrics);
if (SUCCEEDED(hr)) {
pMetrics->Width = Metrics.width;
pMetrics->WidthIncludingTrailingWhitespace = Metrics.widthIncludingTrailingWhitespace;
pMetrics->Height = Metrics.height;
}
pTextLayout->Release();
}
pTextFormat->Release();
}
pFactory->Release();
}
return SUCCEEDED(hr);
}
示例6: DrawNormal
void DrawNormal(const Chat &chat, int vpos) {
int x = static_cast<int>(rcWnd_.right - (float)(chat.width + rcWnd_.right) * (vpos - chat.vpos) / VPOS_LEN);
int y = static_cast<int>(((float)yPitch_ * CNJIni::GetSettings()->commentLineMargin) * (float)chat.line);
IDWriteTextLayout *pLayout;
pDWriteFactory_->CreateTextLayout(chat.text.c_str(), chat.text.length(), pTextFormat_, 1920, 1200, &pLayout);
D2D1_POINT_2F pt = {static_cast<FLOAT>(x) / dpiScaleX_, static_cast<FLOAT>(y) / dpiScaleY_};
ID2D1SolidColorBrush *pColor;
pRT_->CreateSolidColorBrush(
D2D1::ColorF(bgr2rgb(chat.color)),
&pColor
);
renderer_->SetColorBrush(pColor);
pLayout->Draw(NULL, pTextRenderer_, pt.x, pt.y);
pColor->Release();
pLayout->Release();
}
示例7: SetText
void MWinDeviceImpl::SetText(
const string& inText)
{
if (mTextLayout != nil)
mTextLayout->Release();
wstring s(c2w(inText));
THROW_IF_HRESULT_ERROR(
sDWFactory->CreateTextLayout(
s.c_str(),
s.length(),
GetTextFormat(),
99999.0f,
99999.0f,
&mTextLayout
));
}
示例8: DrawShita
void DrawShita(const Chat &chat) {
RECT rc;
rc.top = rcWnd_.bottom - yPitch_ - static_cast<LONG>(chat.line * (int)((float)yPitch_ * CNJIni::GetSettings()->commentLineMargin));
rc.bottom = rc.top + yPitch_;
rc.left = 0;
rc.right = rcWnd_.right;
D2D1_RECT_F layoutRect = D2D1::RectF(
static_cast<FLOAT>(rc.left) / dpiScaleX_,
static_cast<FLOAT>(rc.top) / dpiScaleY_,
static_cast<FLOAT>(rc.right) / dpiScaleX_,
static_cast<FLOAT>(rc.bottom) / dpiScaleY_
);
pTextFormat_->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
IDWriteTextLayout *pLayout;
pDWriteFactory_->CreateTextLayout(
chat.text.c_str(),
chat.text.length(),
pTextFormat_,
static_cast<FLOAT>(rc.right) / dpiScaleX_,
static_cast<FLOAT>(yPitch_) / dpiScaleY_,
&pLayout
);
D2D1_POINT_2F pt = {static_cast<FLOAT>(rc.left) / dpiScaleX_, static_cast<FLOAT>(rc.top) / dpiScaleY_};
ID2D1SolidColorBrush *pColor;
pRT_->CreateSolidColorBrush(
D2D1::ColorF(bgr2rgb(chat.color)),
&pColor
);
renderer_->SetColorBrush(pColor);
pLayout->Draw(NULL, pTextRenderer_, pt.x, pt.y);
pColor->Release();
pLayout->Release();
pTextFormat_->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
}
示例9: nf_print
//.........这里部分代码省略.........
text_alignment = DWRITE_TEXT_ALIGNMENT_JUSTIFIED;
break;
case NF_FEATURE_ALIGN_PARAGRAPH_LEFT:
parg_alignment = DWRITE_PARAGRAPH_ALIGNMENT_NEAR;
break;
case NF_FEATURE_ALIGN_PARAGRAPH_CENTER:
parg_alignment = DWRITE_PARAGRAPH_ALIGNMENT_CENTER;
break;
case NF_FEATURE_ALIGN_PARAGRAPH_RIGHT:
parg_alignment = DWRITE_PARAGRAPH_ALIGNMENT_FAR;
break;
case NF_FEATURE_AA_DISABLED:
text_aa_mode = D2D1_TEXT_ANTIALIAS_MODE_ALIASED;
break;
case NF_FEATURE_AA_WIN_CLEARTYPE:
text_aa_mode = D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
break;
case NF_FEATURE_AA_WIN_GREYSCALE:
text_aa_mode = D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE;
break;
case NF_FEATURE_PPI:
ppi_x = features[i].ppi.x;
ppi_y = features[i].ppi.y;
break;
case NF_FEATURE_COLOR_BG:
bg_color = D2D1::ColorF(
features[i].color.r,
features[i].color.g,
features[i].color.b,
features[i].color.a);
break;
case NF_FEATURE_COLOR_TEXT:
fg_color = D2D1::ColorF(
features[i].color.r,
features[i].color.g,
features[i].color.b,
features[i].color.a);
break;
default:
break;
}
}
layout->SetWordWrapping(text_wrap);
layout->SetTextAlignment(text_alignment);
layout->SetParagraphAlignment(parg_alignment);
ctx.d2d_rt->SetDpi(ppi_x, ppi_y);
ctx.d2d_rt->SetTextAntialiasMode(text_aa_mode);
ctx.d2d_brush->SetColor(fg_color);
// figure our result metrics
// TODO does this call actually rasterizes text?
DWRITE_TEXT_METRICS text_metrics;
layout->GetMetrics(&text_metrics);
float clip_x1 = text_metrics.left;
float clip_y1 = text_metrics.top;
float clip_x2 = text_metrics.left + text_metrics.width;
float clip_y2 = text_metrics.top + text_metrics.height;
clip_x1 = clip_x1 < 0 ? 0 : (clip_x1 >= w ? w - 1 : clip_x1);
clip_y1 = clip_y1 < 0 ? 0 : (clip_y1 >= h ? h - 1 : clip_y1);
clip_x2 = clip_x2 < 0 ? 0 : (clip_x2 >= w ? w - 1 : clip_x2);
clip_y2 = clip_y2 < 0 ? 0 : (clip_y2 >= h ? h - 1 : clip_y2);
float clip_w = clip_x2 - clip_x1 + 1.0f;
float clip_h = clip_y2 - clip_y1 + 1.0f;
nf_aabb_t aabb;
aabb.x = clip_x1;
aabb.y = clip_y1;
aabb.w = clip_w;
aabb.h = clip_h;
if(result_rect)
*result_rect = aabb;
// render text
ctx.d2d_rt->BeginDraw();
ctx.d2d_rt->Clear(bg_color);
ctx.d2d_rt->DrawTextLayout(D2D1::Point2F(), layout, ctx.d2d_brush);
ctx.d2d_rt->EndDraw();
layout->Release();
layout = NULL;
// read texture from d3d
ctx.d3d_device->CopyResource(ctx.d3d_texture2, ctx.d3d_texture1);
D3D10_MAPPED_TEXTURE2D mapped = {0};
if(FAILED(hr = ctx.d3d_texture2->Map(0, D3D10_MAP_READ, 0, &mapped)))
{
nf_explain_hr(hr, "can't map d3d texture");
return -1;
}
for(size_t j = aabb.y; j < aabb.y + aabb.h; ++j)
// hardcoded BGRA8 format
memcpy(
(uint8_t*)bitmap + (j * w + aabb.x) * 4,
(uint8_t*)mapped.pData + j * mapped.RowPitch + aabb.x,
aabb.w * 4);
ctx.d3d_texture2->Unmap(0);
return 0;
}