Turn off subpixel rendering in wxMemoryDC?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Earned a small fee
Earned a small fee
Posts: 13
Joined: Tue May 31, 2016 11:30 am

Turn off subpixel rendering in wxMemoryDC?

Post by gunterkoenigsmann » Sat Aug 20, 2016 3:16 am

Dear all,

I like how wxWidgets does antialiassing and subpixel rendering (https://en.wikipedia.org/wiki/Subpixel_rendering) on the screen. But there are 2 drawbacks:
  1. If an application claims not to be high-dpi-aware subpixel rendering doesn't lead to an object ending in the middle of a RGB pixel, but that it ends with one (or a few) red, green or blue pixels of the target system. This might be no problem as applications should be high-dpi-aware anyway and always look a little bit blocky if they aren't.
  2. And if I use wxMemoryDC in order to render an image subpixel rendering is still used - which is fine if I render things for my own screan. But if I render bitmaps for other systems this might lead to suboptimal results:
    1. On my screen Pixels begin with blue and end with red. Therefore a black line beginning in the middle of a pixel will begin with a red pixel and a black line ending in the middle of a pixel will end with a blue pixel.If this bitmap is then saved as .png and viewed on a screen with a different ordering this will lead to visible color seams.
    2. And if you use such a .png file at web resolutions the same will be true:Image
Is there any way of turning of subpixel rendering without turning off antialiassing?

Thanks a lot,
and kind regards,


User avatar
Posts: 15174
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Turn off subpixel rendering in wxMemoryDC?

Post by doublemax » Sat Aug 20, 2016 9:11 am

What you're seeing is Windows Cleartype in action and this can be changed through a font property.

This works only under Windows.

Code: Select all

Possible values for "quality" parameter
#define CLEARTYPE 5
bool MSWSetFontQuality(wxFont &font, int quality)
  if( !font.Ok() )
    return false;

  wxString fontinfo = font.GetNativeFontInfoDesc();

  wxArrayString tokens = wxSplit( fontinfo, ';' );
  if( tokens.Count() != 15 )
    wxLogDebug(wxT("warning: updateNativeFontInfo(): unexpected token count, %d instead of 15"), tokens.Count() );
    return false;

  tokens[12] = wxString::Format( "%d", quality );

  fontinfo = wxJoin( tokens, ';' );

  return true;
font_quality_windows.png (3.82 KiB) Viewed 748 times
Use the source, Luke!

Post Reply