When I use the Courier New font, at some font sizes some glyphs are showing up with missing pixels. The problem is reproducible. It usually happens when the glyph is one pixel in width or height. Is this a bug with the font hinting? Here is a bitmap illustrating what is happening.
And here is the code that produced this effect:
case WM_PAINT: { PAINTSTRUCT ps; HDC hDC = BeginPaint(hWnd, &ps); RECT rect; HFONT hf, hfOld; GetClientRect(hWnd, &rect); SetMapMode(hDC, MM_ISOTROPIC); SetWindowExtEx(hDC, 1250, 1250, NULL); SetViewportExtEx(hDC, rect.right, rect.bottom, NULL); SetViewportOrgEx(hDC, 0,0,NULL); hf = CreateFont(3000/7, 3000/30, 0, 0, FW_DEMIBOLD, 0, 0, 0, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Courier New"); hfOld = SelectObject(hDC, hf); TextOut(hDC,500,500,"This is a test of font scaling", strlen("This is a test of font scaling")); SelectObject(hDC, hfOld); DeleteObject(hf); EndPaint(hWnd, &ps); } break;
I have always been fascinated with hieroglyphics, although I have to admit that I generally associate them with the Mummy (the monster, not Billy). This of course makes me think of my childhood days watching horror movies. I would, without fail, find myself cowering behind the gray-and-salmon overstuffed chair just waiting for the door to crash in as the Mummy, Frankenstein, or Wolfman sought to rip the arms and legs off my puny nine-year-old frame. Whoa, did you hear something? Was that your door or mine?!
This problem can be the result of a number of factors, including:
· The Courier New font has rather thin strokes to begin with.
· The application program compresses the font in the x direction.
· For performance reasons, the hinting turns off dropout control at large pixel-per-em (ppem) sizes.
· The rasterizer uses the y direction to determine the ppem size.
The bottom line here is that while the font/rasterizer thinks that the glyphs are big enough to disable dropout control safely, the compression makes the strokes even thinner than usual, causing dropouts. A couple of technically possible, but not bloody likely (some casual doctor talk here), solutions are:
· Change the rasterizer to use the lesser of (x,y) to determine ppem size. But hey, you can't change the rasterizer in the first place!
· Change the font to leave dropout control set to the maximum size of 255 ppem. (This would be a large performance hit, and there would still be problems with extreme compressionnot to mention the fact that you can't change the font!)
Some more plausible solutions would include:
· Don't x-compress the font. (Set the second parameter of CreateFont (nWidth) to 0, which will use the default width, which is what the font designer had in mind to begin with.)
· Choose a different font. (One without such thin, waifish, Kate-Moss-like strokes.)