Enable color font option for Direct2D text drawing on Windows 8.1 and newer (PR #26657)

35 views
Skip to first unread message

Tobias Predel

unread,
Jul 4, 2026, 12:48:28 PMĀ (4 days ago)Ā Jul 4
to wx-...@googlegroups.com, Subscribed

You can view, comment on, or merge this pull request online at:

Ā Ā https://github.com/wxWidgets/wxWidgets/pull/26657

Commit Summary

  • 241cd60 Enable color font option for Direct2D text drawing on Windows 8.1 and newer

File Changes

(1Ā file)

Patch Links:

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657@github.com>

Tobias Predel

unread,
Jul 4, 2026, 12:49:28 PMĀ (4 days ago)Ā Jul 4
to wx-...@googlegroups.com, Subscribed
tobiolo left a comment (wxWidgets/wxWidgets#26657)

This hopefully addresses #19275

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/c4883115811@github.com>

VZ

unread,
Jul 4, 2026, 12:52:39 PMĀ (4 days ago)Ā Jul 4
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#26657)

Looks good, thanks, I think we can merge this even just before 3.3.3.

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/c4883124513@github.com>

Tobias Predel

unread,
Jul 4, 2026, 1:02:52 PMĀ (4 days ago)Ā Jul 4
to wx-...@googlegroups.com, Subscribed
tobiolo left a comment (wxWidgets/wxWidgets#26657)

This would be awesome! šŸŽ‰
Thanks for your fast response!

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/c4883153382@github.com>

PB

unread,
Jul 4, 2026, 3:48:57 PMĀ (4 days ago)Ā Jul 4
to wx-...@googlegroups.com, Subscribed

@PBfordev commented on this pull request.


In src/msw/graphicsd2d.cpp:

> @@ -4852,11 +4852,22 @@ void wxD2DContext::DoDrawText(const wxString& str, wxDouble x, wxDouble y)
         textLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING);
     }
 
+    D2D1_DRAW_TEXT_OPTIONS drawTextOptions = D2D1_DRAW_TEXT_OPTIONS_NONE;
+
+#ifdef D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT

Does using #ifdef really works here, as D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT is not a define but an enumerator of D2D1_DRAW_TEXT_OPTIONS enum, both in the Windows SDK and mingw-w64.

Perhaps just ORing with hardcoded 4 with an explaining comment would be better, as suggested elsewhere...

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/review/4630181267@github.com>

VZ

unread,
Jul 4, 2026, 3:52:09 PMĀ (4 days ago)Ā Jul 4
to wx-...@googlegroups.com, Subscribed

@vadz commented on this pull request.


In src/msw/graphicsd2d.cpp:

> @@ -4852,11 +4852,22 @@ void wxD2DContext::DoDrawText(const wxString& str, wxDouble x, wxDouble y)
         textLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING);
     }
 
+    D2D1_DRAW_TEXT_OPTIONS drawTextOptions = D2D1_DRAW_TEXT_OPTIONS_NONE;
+
+#ifdef D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT

Oh, good point, it definitely does not work. Now I wonder whether this has actually been tested?

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/review/4630184397@github.com>

VZ

unread,
Jul 4, 2026, 3:53:49 PMĀ (4 days ago)Ā Jul 4
to wx-...@googlegroups.com, Subscribed

@vadz commented on this pull request.


In src/msw/graphicsd2d.cpp:

> @@ -4852,11 +4852,22 @@ void wxD2DContext::DoDrawText(const wxString& str, wxDouble x, wxDouble y)
         textLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING);
     }
 
+    D2D1_DRAW_TEXT_OPTIONS drawTextOptions = D2D1_DRAW_TEXT_OPTIONS_NONE;
+
+#ifdef D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT

Actually I'm not sure if this symbol is still missing from any SDKs by now, maybe we could remove the compile-time test.

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/review/4630186051@github.com>

Tobias Predel

unread,
Jul 4, 2026, 3:59:45 PMĀ (4 days ago)Ā Jul 4
to wx-...@googlegroups.com, Push

@tobiolo pushed 1 commit.

  • bed25cb Remove compile-time check

—
View it on GitHub or unsubscribe.


Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/before/241cd604faa6600b1b1c593d82422e76a2b65f57/after/bed25cbaf327702f0be57193903da0846b17cc6e@github.com>

Tobias Predel

unread,
Jul 4, 2026, 4:01:01 PMĀ (4 days ago)Ā Jul 4
to wx-...@googlegroups.com, Subscribed

@tobiolo commented on this pull request.


In src/msw/graphicsd2d.cpp:

> @@ -4852,11 +4852,22 @@ void wxD2DContext::DoDrawText(const wxString& str, wxDouble x, wxDouble y)
         textLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING);
     }
 
+    D2D1_DRAW_TEXT_OPTIONS drawTextOptions = D2D1_DRAW_TEXT_OPTIONS_NONE;
+
+#ifdef D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT

Thanks for the feedback. I removed the compile time check and just placed 4. Is it ok now?

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/review/4630196521@github.com>

Tobias Predel

unread,
Jul 4, 2026, 4:06:10 PMĀ (4 days ago)Ā Jul 4
to wx-...@googlegroups.com, Push

@tobiolo pushed 1 commit.

—
View it on GitHub or unsubscribe.


Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/before/bed25cbaf327702f0be57193903da0846b17cc6e/after/6298fa1a530147d84750de3d3569691e13e46c6c@github.com>

VZ

unread,
Jul 4, 2026, 4:07:58 PMĀ (4 days ago)Ā Jul 4
to wx-...@googlegroups.com, Subscribed

@vadz commented on this pull request.


In src/msw/graphicsd2d.cpp:

> @@ -4852,11 +4852,22 @@ void wxD2DContext::DoDrawText(const wxString& str, wxDouble x, wxDouble y)
         textLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING);
     }
 
+    D2D1_DRAW_TEXT_OPTIONS drawTextOptions = D2D1_DRAW_TEXT_OPTIONS_NONE;
+
+#ifdef D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT

I was thinking of just using the symbolic constant and checking if any of the CI jobs had trouble with it.

But most of all I thought that you did test it and checked that emojis were rendered correctly and it's worrisome that you didn't because now I have no idea if it works or not.

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/review/4630203102@github.com>

Tobias Predel

unread,
Jul 4, 2026, 5:07:16 PMĀ (4 days ago)Ā Jul 4
to wx-...@googlegroups.com, Subscribed

@tobiolo commented on this pull request.


In src/msw/graphicsd2d.cpp:

> @@ -4852,11 +4852,22 @@ void wxD2DContext::DoDrawText(const wxString& str, wxDouble x, wxDouble y)
         textLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING);
     }
 
+    D2D1_DRAW_TEXT_OPTIONS drawTextOptions = D2D1_DRAW_TEXT_OPTIONS_NONE;
+
+#ifdef D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT

I will double-check.

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/review/4630261209@github.com>

Tobias Predel

unread,
Jul 4, 2026, 5:36:06 PMĀ (4 days ago)Ā Jul 4
to wx-...@googlegroups.com, Subscribed

@tobiolo commented on this pull request.


In src/msw/graphicsd2d.cpp:

> @@ -4852,11 +4852,22 @@ void wxD2DContext::DoDrawText(const wxString& str, wxDouble x, wxDouble y)
         textLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING);
     }
 
+    D2D1_DRAW_TEXT_OPTIONS drawTextOptions = D2D1_DRAW_TEXT_OPTIONS_NONE;
+
+#ifdef D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT
diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp
index 5801bbdfea..727cf1d668 100644
--- a/samples/drawing/drawing.cpp
+++ b/samples/drawing/drawing.cpp
@@ -1100,9 +1100,12 @@ void MyCanvas::DrawText(wxDC& dc)
         dc.DrawRotatedText(text , dc.FromDIP(400), dc.FromDIP(400), n);
     }
 
-    dc.SetFont( wxFontInfo(18).Family(wxFONTFAMILY_SWISS) );
+    wxFont emojiFont(wxFontInfo(18).FaceName("Twemoji"));
+    dc.SetFont(emojiFont);
+
+    dc.DrawText( wxString( "😊", wxConvUTF8 ), dc.FromDIP(110), dc.FromDIP(40) );
 
-    dc.DrawText( "This is Swiss 18pt text.", dc.FromDIP(110), dc.FromDIP(40) );
+    dc.SetFont( wxFontInfo(18).Family(wxFONTFAMILY_SWISS) );
 
     wxCoord length;
     wxCoord height;

I have this in the samples but I cannot verify :-( I'm using Wine here so it can be either unsupported by Wine or something not correct towards the Direct2D API.

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/review/4630288289@github.com>

PB

unread,
Jul 5, 2026, 7:43:41 AMĀ (3 days ago)Ā Jul 5
to wx-...@googlegroups.com, Subscribed
PBfordev left a comment (wxWidgets/wxWidgets#26657)

I have tested that it works on Windows 11
wx-d2d-clr-emoji.png (view on web)
with

diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp
index 5801bbdfea..95c8bcf761 100644
--- a/samples/drawing/drawing.cpp
+++ b/samples/drawing/drawing.cpp
@@ -1082,6 +1082,11 @@ void MyCanvas::DrawDefault(wxDC& dc)
 
 void MyCanvas::DrawText(wxDC& dc)
 {
+    dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
+    dc.SetFont(wxFontInfo(12).FaceName("Segoe UI Emoji"));
+    dc.DrawText(wxString::FromUTF8("\U0001F44D"), dc.FromDIP(10), dc.FromDIP(10));
+    return;
+
     // set underlined font for testing
     dc.SetFont( wxFontInfo(12).Family(wxFONTFAMILY_MODERN).Underlined() );
     dc.DrawText( "This is text", dc.FromDIP(110), dc.FromDIP(10) );

TBH, I don't like testing for the OS version during every draw text call, even when I do understand that the call cost is small, considering everything. I would still set-up the drawing options once, e.g. as wxD2DContext class member.

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/c4885910550@github.com>

VZ

unread,
Jul 5, 2026, 11:03:47 AMĀ (3 days ago)Ā Jul 5
to wx-...@googlegroups.com, Push

@vadz pushed 2 commits.

  • 8b733f4 Test OS version only once and use D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT
  • 9c09f5a Check drawing colour emojis in the drawing sample

—
View it on GitHub or unsubscribe.


Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/before/6298fa1a530147d84750de3d3569691e13e46c6c/after/9c09f5a43ee6e01d78aea0dc53ff1eb9c4578c3a@github.com>

VZ

unread,
Jul 5, 2026, 11:04:16 AMĀ (3 days ago)Ā Jul 5
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#26657)

Let's try if this compiles. It does work, even under Windows 10.

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/c4886489318@github.com>

VZ

unread,
Jul 5, 2026, 12:03:01 PMĀ (3 days ago)Ā Jul 5
to wx-...@googlegroups.com, Subscribed

Closed #26657 via a239436.

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/issue_event/27576313079@github.com>

Tobias Predel

unread,
Jul 5, 2026, 12:11:11 PMĀ (3 days ago)Ā Jul 5
to wx-...@googlegroups.com, Subscribed
tobiolo left a comment (wxWidgets/wxWidgets#26657)

Thanks @vadz and @PBfordev for your review and the further development in this PR!

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26657/c4886685995@github.com>

Reply all
Reply to author
Forward
0 new messages