您可能不需要对 IDWriteTextAnalysisSink / AnalyzeScript 做太多工作。
HRESULT hr = S_OK;
ComPtr<IDWriteTextFormat> textFormat;
ComPtr<IDWriteTextLayout> textLayout;
// Error checking omitted for brevity
hr = textFactory->CreateTextFormat(L"Arial", nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 30.0f, L"", textFormat.GetAddressOf());
hr = textFormat->SetReadingDirection(DWRITE_READING_DIRECTION_RIGHT_TO_LEFT);
hr = textFactory->CreateTextLayout(L"[HEBREW TEXT HERE]", textsize, textFormat.Get(), 0.0f, 0.0f, textLayout.GetAddressOf());
渲染代码:
renderTarget->Clear(BG_COLOR);
auto size = renderTarget->GetSize();
auto margin = 50.0f;
size.width -= margin * 2.0f;
size.height -= margin * 2.0f;
if (S_OK == textLayout->SetMaxWidth(size.width) &&
S_OK == textLayout->SetMaxHeight(size.height))
{
renderTarget->DrawTextLayout(Point2F(margin, margin), textLayout.Get(), brush.Get(), D2D1_DRAW_TEXT_OPTIONS_NONE);
}
阅读希伯来文文件的截图:
(注意:我的解决方案基于来自 Kenny Kerr 的示例)我意识到您正在混合 LTR 和 RTL,但是我不确定这是否会增加 IDWriteTextAnalysisSink / AnalyzeScript 的复杂性。