我在这里按照一个示例使用省略号来修剪文本:http: //cx5software.sakura.ne.jp/blog/2011/01/18/directwrite-ellipsis-trimming-sign/
它适用于英文文本,但不适用于日文文本。有谁知道为什么?
这是我尝试编写文本的代码片段:“日本语英语”
m_dwrite_factory->CreateTextFormat(L"Arial Unicode MS", NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 14.0f * 96.0f/72.0f, L"ja-JP", m_dwrite_text_format.GetAddressOf());
std::wstring text(L"日本語English");
IDWriteInlineObjectPtr trimming;
m_dwrite_factory->CreateEllipsisTrimmingSign(m_dwrite_text_format.Get(), trimming.GetAddressOf());
IDWriteTextLayoutPtr layout;
m_dwrite_factory->CreateTextLayout(text.c_str(), (UINT32)text.length(), m_dwrite_text_format.Get(), 50.0f, 100.0f, layout.GetAddressOf());
DWRITE_TRIMMING trimmingOpt = {DWRITE_TRIMMING_GRANULARITY_CHARACTER, 0, 0};
layout->SetTrimming(&trimmingOpt, trimming.Get());
d2d->DrawTextLayout(D2D1::Point2F(0, 0), layout.Get(), m_d2d_brush_2.Get());
这是生成的文本。请注意,省略号是在英文字符上添加的,而不是在日文文本上。