Soft hyphens with DirectWrite API

279 views Asked by At

In a sample application DWriteSimpleHelloWorld I render a text

wszText_ = L"Hello World using Direct\u00ADWrite!";

to a DWrite HwndRenderTarget -- effectively, to a window of my application. I render text with a DrawText method of ID2D1HwndRenderTarget. I expect a behavior conformant to a rendering of text strings containing entity ­ (soft or syllable hyphen) in web browsers.

If a window is wide enough to fit the width of the rendered phrase, I see a text like

Hello World using DirectWrite!

But when I resize my window so that the tail of a phrase fails to fit into the window, I see :

Hello World using Direct
Write!

while web browsers would render this text with a hyphen at the end of a first line:

Hello World using Direct-
Write!

My purpose is to let users insert hyphenation hints for long words in my DWrite application, but what I see is as if \u00AD works as a "hidden" whitespace.

I have read of subtleties concerning a soft hyphen definition and usage (for example, https://www.cs.tut.fi/~jkorpela/shy.html), so I humbly ask : is the observed behavior of DWrite "by design"? If so, how one can implement hyphenation hints that would produce hyphens at the end of lines when needed?

Notice that when I use glyph indices of my wszText_ string to draw text as a geometry created with a method GetGlyphRunOutline of IDWriteFontFace, I see a string containing a hyphen in its due position:

Hello World using Direct-Write!
0

There are 0 answers