本文整理汇总了C++中IDWriteTextLayout::SetUnderline方法的典型用法代码示例。如果您正苦于以下问题:C++ IDWriteTextLayout::SetUnderline方法的具体用法?C++ IDWriteTextLayout::SetUnderline怎么用?C++ IDWriteTextLayout::SetUnderline使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDWriteTextLayout
的用法示例。
在下文中一共展示了IDWriteTextLayout::SetUnderline方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nf_print
int nf_print(void * bitmap, uint16_t w, uint16_t h,
nf_font_t font, nf_feature_t * features, size_t features_count,
nf_aabb_t * result_rect, const char * text, ...)
{
if(!bitmap)
{
NF_ERROR("can't print with invalid bitmap\n");
return -1;
}
if(!font)
{
NF_ERROR("can't print with invalid font\n");
return -1;
}
if(!text)
{
NF_ERROR("can't print with invalid text\n");
return -1;
}
// figure out text rendering settings
HRESULT hr = 0;
D2D1_COLOR_F bg_color = D2D1::ColorF(0.0f, 0.0f, 0.0f, 0.0f);
D2D1_COLOR_F fg_color = D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f);
DWRITE_WORD_WRAPPING text_wrap = DWRITE_WORD_WRAPPING_WRAP;
DWRITE_TEXT_ALIGNMENT text_alignment = DWRITE_TEXT_ALIGNMENT_LEADING;
DWRITE_PARAGRAPH_ALIGNMENT parg_alignment = DWRITE_PARAGRAPH_ALIGNMENT_NEAR;
D2D1_TEXT_ANTIALIAS_MODE text_aa_mode = D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE;
float ppi_x = 0.0f, ppi_y = 0.0f;
ctx.d2d_factory->GetDesktopDpi(&ppi_x, &ppi_y);
size_t len = strlen(text) + 1;
WCHAR * wtext = (WCHAR*)alloca(len * sizeof(WCHAR));
size_t wlen = mbstowcs(wtext, text, len);
if(wlen == (size_t)-1)
{
NF_ERROR("failed to convert text to wchar, text : '%s'\n", text);
return -1;
}
IDWriteTextLayout * layout = NULL;
if(FAILED(hr = ctx.dw_factory->CreateTextLayout(
wtext, wlen,
(IDWriteTextFormat*)font,
w, h,
&layout)))
{
nf_explain_hr(hr, "can't create dwrite text layout");
return -1;
}
for(size_t i = 0; i < features_count; ++i)
{
DWRITE_TEXT_RANGE range;
range.startPosition = features[i].range.start;
range.length = features[i].range.end - features[i].range.start + 1;
switch(features[i].type)
{
case NF_FEATURE_BOLD:
layout->SetFontWeight(DWRITE_FONT_WEIGHT_BOLD, range);
break;
case NF_FEATURE_UNDERLINE:
layout->SetUnderline(true, range);
break;
case NF_FEATURE_ITALIC:
layout->SetFontStyle(DWRITE_FONT_STYLE_ITALIC, range);
break;
case NF_FEATURE_WRAP:
text_wrap = DWRITE_WORD_WRAPPING_WRAP;
break;
case NF_FEATURE_NO_WRAP:
text_wrap = DWRITE_WORD_WRAPPING_NO_WRAP;
break;
case NF_FEATURE_ALIGN_LEFT:
text_alignment = DWRITE_TEXT_ALIGNMENT_LEADING;
break;
case NF_FEATURE_ALIGN_CENTER:
text_alignment = DWRITE_TEXT_ALIGNMENT_CENTER;
break;
case NF_FEATURE_ALIGN_RIGHT:
text_alignment = DWRITE_TEXT_ALIGNMENT_TRAILING;
break;
case NF_FEATURE_ALIGN_JUSTIFIED:
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;
//.........这里部分代码省略.........