Menu

#1277 Color font for Windows 8.1 and above in Direct2D mode

Committed
closed
5
2019-04-16
2019-04-07
Zufu Liu
No

https://docs.microsoft.com/en-us/windows/desktop/api/d2d1/ne-d2d1-d2d1_draw_text_options
D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT is available for Windows 8.1 and above ( not available in Win7 SDK and MinGW-w64 before 2019-02-12).

Using this option crashed on early systems.
The patch is just an outline, need portable version checking (versionhelpers.h only usable for _WIN32_WINNT >= 0x0501 and not available in MinGW-w64 before 2015-03-09. call GetVersion() may got deprecated warnings).

2 Attachments

Discussion

  • Neil Hodgson

    Neil Hodgson - 2019-04-10

    Versionhelpers have an unchecked version dependency themselves since VerifyVersionInfo is only from Windows 2000 or later. Not that Windows NT 4 has been checked recently.
    https://docs.microsoft.com/en-us/windows/desktop/api/Winbase/nf-winbase-verifyversioninfoa

    Attempting to dynamically load and use VerifyVersionInfo is complex.
    https://walbourn.github.io/whats-in-a-version-number/

    Its unclear just which call 'crashed on early systems' and its possible the crash can be avoided by checking the results from some test calls with coloured characters.

    kD2D1DrawTextOptions isn't a constant and Scintilla doesn't use 'k' prefixes for constants. Its also inside the Scintilla namespace so doesn't need to be static.

    Perhaps its better to have a more direct check. The coloured text support arrived with the dwrite_2.h file and IDWriteFactory2.
    https://docs.microsoft.com/en-us/windows/desktop/api/dwrite_2/nn-dwrite_2-idwritefactory2
    So, the code could ask for IDWriteFactory2, and set D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT if that worked. If it fails, ask for IDWriteFactory. Something like:

    DWriteCFSig fnDWCF = reinterpret_cast<DWriteCFSig>(::GetProcAddress(hDLLDWrite, "DWriteCreateFactory"));
    if (fnDWCF) {
        const HRESULT hr = fnDWCF(DWRITE_FACTORY_TYPE_SHARED,
            __uuidof(IDWriteFactory2),
            reinterpret_cast<IUnknown**>(&pIDWriteFactory));
        if (SUCCEEDED(hr)) {
            // D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT
            drawTextOptions = static_cast<D2D1_DRAW_TEXT_OPTIONS>(0x00000004);
        } else {
            fnDWCF(DWRITE_FACTORY_TYPE_SHARED,
                __uuidof(IDWriteFactory),
                reinterpret_cast<IUnknown**>(&pIDWriteFactory));
        }
    }
    

    Including dwrite_2.h could have its own problems with older SDKs or MinGW distributions.

     
  • Zufu Liu

    Zufu Liu - 2019-04-10

    Your code works.
    the patch replaced __uuidof(IDWriteFactory2) with hard-coded UUID (which not changes), no dependency on dwrite_2.h.

     
    • Zufu Liu

      Zufu Liu - 2019-04-10

      'crashed on early systems': application (i.e. SciTE) not crashed, but draws nothing when open files, only got a black editor window, no caret, no text.

       
  • Neil Hodgson

    Neil Hodgson - 2019-04-10
    • labels: --> scintilla, win32, directwrite
    • Group: Completed --> Committed
     
  • Neil Hodgson

    Neil Hodgson - 2019-04-10

    Change committed as [76fcbb].

     

    Related

    Commit: [76fcbb]

  • Neil Hodgson

    Neil Hodgson - 2019-04-16
    • status: open --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.