Search code examples
c++fontsdirect2ddirectwrite

DirectWrite: Use Different Font for Latin and Complex Script


I use CreateTextLayout and CreateTextFormat to draw text with DirectWrite (C++), the text is mixed Hebrew/English, is there a way to use a different font/font size for the Latin and Hebrew characters?

Thanks.


Solution

  • I ended up calling IDWriteFont::HasCharacter to build text ranges inside which all characters use the same font (the hebrew or the latin one).

    If that text range uses the hebrew font, I call textLayout->SetFontSize on it to increase the font size.

    This amounts to anticipating the font callback DirectWrite will do, which is automatic and cannot be customized.