本文整理汇总了C++中IDWriteTextLayout::SetTextAlignment方法的典型用法代码示例。如果您正苦于以下问题:C++ IDWriteTextLayout::SetTextAlignment方法的具体用法?C++ IDWriteTextLayout::SetTextAlignment怎么用?C++ IDWriteTextLayout::SetTextAlignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDWriteTextLayout
的用法示例。
在下文中一共展示了IDWriteTextLayout::SetTextAlignment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
// Create text layout from string
IDWriteTextLayout* CFW1FontWrapper::createTextLayout(
const WCHAR *pszString,
const WCHAR *pszFontFamily,
FLOAT fontSize,
const FW1_RECTF *pLayoutRect,
UINT flags
) {
if(m_defaultTextInited) {
UINT32 stringLength = 0;
while(pszString[stringLength] != 0)
++stringLength;
// Create DWrite text layout for the string
IDWriteTextLayout *pTextLayout;
HRESULT hResult = m_pDWriteFactory->CreateTextLayout(
pszString,
stringLength,
m_pDefaultTextFormat,
pLayoutRect->Right - pLayoutRect->Left,
pLayoutRect->Bottom - pLayoutRect->Top,
&pTextLayout
);
if(SUCCEEDED(hResult)) {
// Layout settings
DWRITE_TEXT_RANGE allText = {0, stringLength};
pTextLayout->SetFontSize(fontSize, allText);
if(pszFontFamily != NULL)
pTextLayout->SetFontFamilyName(pszFontFamily, allText);
if((flags & FW1_NOWORDWRAP) != 0)
pTextLayout->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
if(flags & FW1_RIGHT)
pTextLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING);
else if(flags & FW1_CENTER)
pTextLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
if(flags & FW1_BOTTOM)
pTextLayout->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_FAR);
else if(flags & FW1_VCENTER)
pTextLayout->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
return pTextLayout;
}
}
return NULL;
}
示例2: 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;
}