title: GDI - Can I use the new Windows 10 Segoe UI Emoji colored font with DrawText?
body: <p>I'm creating a c++ project using Embarcadero RAD Studio (10.2 Tokyo starter) and the Windows GDI to draw text, via the DrawText() function.</p>
  <p>I recently saw that Windows 10 provides a new &quot;Segoe UI Emoji&quot; font, that potentially allows text functions to draw colored emojis. I found several examples using Direct2D, but none with pure GDI functions.</p>
  <p>I also tried a simple code, like this:</p>
  <pre class="lang-cpp prettyprint-override"><code>HDC hDC = ::GetDC(Handle);
  
  std::auto_ptr&lt;TCanvas&gt; pCanvas(new TCanvas());
  pCanvas-&gt;Handle = hDC;
  
  pCanvas-&gt;Brush-&gt;Color = clWhite;
  pCanvas-&gt;Brush-&gt;Style = bsSolid;
  pCanvas-&gt;FillRect(TRect(0, 0, ClientWidth, ClientHeight));
  
  const std::wstring text = L&quot;Test        &quot;;
  
  TRect textRect(10, 10, ClientWidth - 10, ClientHeight - 10);
  
  hFont = ::CreateFont(-40,
                        0, 
                        0,
                        0,
                        FW_DONTCARE,
                        FALSE,
                        FALSE,
                        FALSE,
                        DEFAULT_CHARSET,
                        OUT_OUTLINE_PRECIS,
                        CLIP_DEFAULT_PRECIS,
                        CLEARTYPE_QUALITY,
                        VARIABLE_PITCH,
                        L&quot;Segoe UI Emoji&quot;);
  
  ::SelectObject(hDC, hFont);
  
  ::DrawTextW(hDC,
              text.c_str(),
              text.length(),
              &amp;textRect,
              DT_LEFT | DT_TOP | DT_SINGLELINE);
  
  ::DeleteObject(hFont);
  </code></pre>
  <p>The output result sounds good in terms of symbols, but they are drawn in black&amp;white, without colors, as you can see on the screenshot below:
  <a href="https://i.stack.imgur.com/STqT9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/STqT9.png" alt="enter image description here" /></a></p>
  <p>I could not find any additional options that may allow the text to be drawn using colored symbols instead of black&amp;white. Is there a way to activate the support of the color in GDI DrawText() function, and if yes, how to do that? Or only Direct2D may draw colored emojis?</p>
  <p><strong>EDITED on 30.10.2017</strong></p>
  <p>As the GDI cannot do the job (unfortunately, and as I thought) I publish here the Direct2D version of the above code, that worked for me.</p>
  <pre class="lang-cpp prettyprint-override"><code>const std::wstring text = L&quot;Test        &quot;;
  
  HDC hDC = ::GetDC(Handle);
  
  std::auto_ptr&lt;TCanvas&gt; pGDICanvas(new TCanvas());
  pGDICanvas-&gt;Handle = hDC;
  
  pGDICanvas-&gt;Brush-&gt;Color = clWhite;
  pGDICanvas-&gt;Brush-&gt;Style = bsSolid;
  pGDICanvas-&gt;FillRect(TRect(0, 0, ClientWidth, ClientHeight));
  
  ::D2D1_RECT_F textRect;
  textRect.left   = 10;
  textRect.top    = 10;
  textRect.right  = ClientWidth  - 10;
  textRect.bottom = ClientHeight - 10;
  
  std::auto_ptr&lt;TDirect2DCanvas&gt; pCanvas(new TDirect2DCanvas(hDC, TRect(0, 0, ClientWidth, ClientHeight)));
  
  // configure Direct2D font
  pCanvas-&gt;Font-&gt;Size        = 40;
  pCanvas-&gt;Font-&gt;Name        = L&quot;Segoe UI Emoji&quot;;
  pCanvas-&gt;Font-&gt;Orientation = 0;
  pCanvas-&gt;Font-&gt;Pitch       = System::Uitypes::TFontPitch::fpVariable;
  pCanvas-&gt;Font-&gt;Style       = TFontStyles();
  
  // get DirectWrite text format object
  _di_IDWriteTextFormat pFormat = pCanvas-&gt;Font-&gt;Handle;
  
  if (!pFormat)
      return;
  
  pCanvas-&gt;RenderTarget-&gt;SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE);
  
  ::D2D1_COLOR_F color;
  color.r = 0.0f;
  color.g = 0.0f;
  color.b = 0.0f;
  color.a = 1.0f;
  
  ::ID2D1SolidColorBrush* pBrush = NULL;
  
  // create solid color brush, use pen color if rect is completely filled with outline
  pCanvas-&gt;RenderTarget-&gt;CreateSolidColorBrush(color, &amp;pBrush);
  
  if (!pBrush)
      return;
  
  // set horiz alignment
  pFormat-&gt;SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
  
  // set vert alignment
  pFormat-&gt;SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR);
  
  // set reading direction
  pFormat-&gt;SetReadingDirection(DWRITE_READING_DIRECTION_LEFT_TO_RIGHT);
  
  // set word wrapping mode
  pFormat-&gt;SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
  
  IDWriteInlineObject* pInlineObject = NULL;
  
  ::DWRITE_TRIMMING trimming;
  trimming.delimiter      = 0;
  trimming.delimiterCount = 0;
  trimming.granularity    = DWRITE_TRIMMING_GRANULARITY_NONE;
  
  // set text trimming
  pFormat-&gt;SetTrimming(&amp;trimming, pInlineObject);
  
  pCanvas-&gt;BeginDraw();
  
  pCanvas-&gt;RenderTarget-&gt;DrawText(text.c_str(), text.length(), pFormat, textRect, pBrush,
              D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT);
  
  pCanvas-&gt;EndDraw();
  </code></pre>
  <p>Of course this code will draw colored emojis only on the currently most recent versions of Windows 10, and above. On previous versions the text will be drawn as above (and the code may not compile).</p>
  <h2>Bonus Reading</h2>
  <ul>
  <li>MSDN: <a href="https://docs.microsoft.com/en-us/windows/win32/directwrite/color-fonts" rel="nofollow noreferrer">Color Fonts with DirectWrite, Direct2D, and Win2D</a></li>
  </ul>