Jump to content
pyscripter

Choice of Windows text rendering engines

Recommended Posts

There are a few choices when it comes to native processing and rendering of Unicode text in Windows applications.  Namely, GDI, GDI+, UniScribe and DirectWrite.  I have been doing some research in the process of updating/fixing the Unicode handling in SynEdit.  It appears that the future lies with DirectWrite.  Here are some reasons:

  • WPF is based on DirectWrite
  • Recent Microsoft applications, such as the Windows Terminal, use DirectWrite
  • The Windows App SDK (new name of Project Reunion) is using a new cross-platform version of DirectWrite called DWriteCore, which is mostly compatible with DirectWrite.  So presumably, switching to DWriteCore, if needed, would be easy.

 

DirectWrite has many advantages including:

  • Can play with GDI well, so you can mix the two.
  • Supports color fonts
  • Handles Unicode such as emojis reasonably well.
  • Supports bi-directional text (e.g. mixing Arabic with English)
  • Provides GPU acceleration.

The downside is that it is fairly complex and there is not much Delphi Code that is using DirectWrite.  Also the Delphi header translations have bugs and have not been updated for years (see [RSP-36642] CreateGdiCompatibleTextLayout is declared wrongly in Winapi.D2D1 - Embarcadero Technologies for instance).

 

Further to the discussion in Unicode string - how element iterating? - RTL and Delphi Object Pascal - Delphi-PRAXiS [en] (delphipraxis.net), I have created a little demo which showcases rendering complex Unicode text with DirectWrite and also provides a Grapheme enumerator for Delphi strings also based on DirectWrite.  Here is a screenshot.

 

image.png.7554b5741de81631cccf94948d2fcb98.png

 

The ListBox shows the graphemes of the text.  It is custom painted with DirectWrite.  The Emoji consists of 7 unicode codepoints.

See also fdwr/TextLayoutSampler: Utility to display text via multiple Windows API's simultaneously (D2D, DWrite, GDI, GDI+). (github.com)

The source code of the project is attached.

 

 

 

DirectWriteTest.zip

Edited by pyscripter
  • Like 3

Share this post


Link to post

I couldn't figure out how to load DWriteFactory fonts.

Can you show an example where the emoji font is loaded dynamically (from resources/memory, non directly font file)?
The AddFontMemResourceEx function only makes private fonts(invisible to DirectWrite), and AddFontResourceExW doesn't work for me.

 

Share this post


Link to post

Guys, I have zero skill in DirectDraw... I just need to draw 1 color glyph with standard tools.

I already create a program that aligns monochrome glyphs. Git: FontFit

But in "the whole big Internet" there was only one free program for adding colored glyphs, and it has no scaling... OpenType SVG Font Editor  (already slightly modified by a friend elricbk
And I really want to make a more functional analogue. FreeWare-OpenSource.

fontfit.jpg

Edited by Dimon_II

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×