本文整理汇总了C++中IDWriteTextLayout::SetFontWeight方法的典型用法代码示例。如果您正苦于以下问题:C++ IDWriteTextLayout::SetFontWeight方法的具体用法?C++ IDWriteTextLayout::SetFontWeight怎么用?C++ IDWriteTextLayout::SetFontWeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDWriteTextLayout
的用法示例。
在下文中一共展示了IDWriteTextLayout::SetFontWeight方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createTextLayout
IDWriteTextLayout* createTextLayout(IDWriteFactory1* writeFactory, IDWriteTextFormat* textFormat, const Int2& layoutSize, float scale, const wchar_t* wtext)
{
IDWriteTextLayout* textLayout;
// Create a DirectWrite Text Layout object.
DX::ThrowIfFailed(
writeFactory->CreateTextLayout(
wtext, // Text to be displayed
(UINT32)wcslen(wtext), // Length of the text
textFormat, // DirectWrite Text Format object
layoutSize.width() / scale, // Width of the Text Layout
layoutSize.height() / scale, // Height of the Text Layout
&textLayout
)
);
// Create a text range corresponding to the entire string.
DWRITE_TEXT_RANGE textRange = { 0 };
textRange.length = static_cast<UINT32>(wcslen(wtext));
textRange.startPosition = 0;
// Set the font size and weight on the text range.
textLayout->SetFontSize(100.f, textRange);
textLayout->SetFontWeight(DWRITE_FONT_WEIGHT_BOLD, textRange);
//m_textLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
return textLayout;
}
示例2: PixelsToDipsX
void
DWriteContext::DrawText(HDC hdc, const WCHAR* text, int len,
int x, int y, int w, int h, int cellWidth, COLORREF color)
{
HRESULT hr = S_OK;
IDWriteBitmapRenderTarget *bmpRT = NULL;
// Skip when any fonts are not set.
if (mTextFormat == NULL)
return;
// Check possibility of zero divided error.
if (cellWidth == 0 || mDpiScaleX == 0.0f || mDpiScaleY == 0.0f)
return;
if (SUCCEEDED(hr))
hr = mGdiInterop->CreateBitmapRenderTarget(hdc, w, h, &bmpRT);
if (SUCCEEDED(hr))
{
IDWriteTextLayout *textLayout = NULL;
HDC memdc = bmpRT->GetMemoryDC();
BitBlt(memdc, 0, 0, w, h, hdc, x, y, SRCCOPY);
hr = mDWriteFactory->CreateGdiCompatibleTextLayout(
text, len, mTextFormat, PixelsToDipsX(w),
PixelsToDipsY(h), mDpiScaleX, NULL, TRUE, &textLayout);
if (SUCCEEDED(hr))
{
DWRITE_TEXT_RANGE textRange = { 0, (UINT32)len };
textLayout->SetFontWeight(mFontWeight, textRange);
textLayout->SetFontStyle(mFontStyle, textRange);
}
if (SUCCEEDED(hr))
{
GdiTextRenderer *renderer = new GdiTextRenderer(bmpRT,
mRenderingParams);
GdiTextRendererContext data = {
color,
PixelsToDipsX(cellWidth),
0.0f
};
textLayout->Draw(&data, renderer, 0, 0);
SafeRelease(&renderer);
}
BitBlt(hdc, x, y, w, h, memdc, 0, 0, SRCCOPY);
SafeRelease(&textLayout);
}
SafeRelease(&bmpRT);
}
示例3: addAttributedRange
void addAttributedRange (const AttributedString::Attribute& attr, IDWriteTextLayout& textLayout,
const int textLen, ID2D1RenderTarget& renderTarget, IDWriteFontCollection& fontCollection)
{
DWRITE_TEXT_RANGE range;
range.startPosition = attr.range.getStart();
range.length = jmin (attr.range.getLength(), textLen - attr.range.getStart());
if (const Font* const font = attr.getFont())
{
const String familyName (FontStyleHelpers::getConcreteFamilyName (*font));
BOOL fontFound = false;
uint32 fontIndex;
fontCollection.FindFamilyName (familyName.toWideCharPointer(), &fontIndex, &fontFound);
if (! fontFound)
fontIndex = 0;
ComSmartPtr<IDWriteFontFamily> fontFamily;
HRESULT hr = fontCollection.GetFontFamily (fontIndex, fontFamily.resetAndGetPointerAddress());
ComSmartPtr<IDWriteFont> dwFont;
uint32 fontFacesCount = 0;
fontFacesCount = fontFamily->GetFontCount();
for (int i = fontFacesCount; --i >= 0;)
{
hr = fontFamily->GetFont (i, dwFont.resetAndGetPointerAddress());
if (font->getTypefaceStyle() == getFontFaceName (dwFont))
break;
}
textLayout.SetFontFamilyName (familyName.toWideCharPointer(), range);
textLayout.SetFontWeight (dwFont->GetWeight(), range);
textLayout.SetFontStretch (dwFont->GetStretch(), range);
textLayout.SetFontStyle (dwFont->GetStyle(), range);
const float fontHeightToEmSizeFactor = getFontHeightToEmSizeFactor (*dwFont);
textLayout.SetFontSize (font->getHeight() * fontHeightToEmSizeFactor, range);
}
if (const Colour* const colour = attr.getColour())
{
ComSmartPtr<ID2D1SolidColorBrush> d2dBrush;
renderTarget.CreateSolidColorBrush (D2D1::ColorF (colour->getFloatRed(),
colour->getFloatGreen(),
colour->getFloatBlue(),
colour->getFloatAlpha()),
d2dBrush.resetAndGetPointerAddress());
// We need to call SetDrawingEffect with a legimate brush to get DirectWrite to break text based on colours
textLayout.SetDrawingEffect (d2dBrush, range);
}
}
示例4: 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;
//.........这里部分代码省略.........