Prevent anti-aliasing (or sub-pixel rendering) of a TrueType font

拟墨画扇 提交于 2019-12-05 02:14:29
Nowayz

Working Solution

Credit goes to Brian Nixon for posting the solution URL, and to Erik Olofsson for researching and posting the solution on his blog.

Erik Olofsson provides a solution that forces Windows font API to prioritize .ttf embedded bitmaps to be used with priority over glyphs when rendering.

The solution can be found in detail at http://www.electronicdissonance.com/2010/01/raster-fonts-in-visual-studio-2010.html


Solution Summary

  1. Add 'Traditional Chinese' code page to the OS/2 Panpose table.
  2. Use the 'ISO 106046-1' (Unicode, UCS-2) encoding.
  3. Include glyphs for the following seemingly random Hiragana characters:
    • い - U+3044
    • う - U+3046
    • か - U+304B
    • ひ - U+3057
    • の - U+306E
    • ん - U+3093

This list is not a joke

On certain color-schemes this sub-pixel rendering that Windows does makes the font completely unreadable.

It sounds as if ClearType is not correctly calibrated.

"Pixel-perfect" display is possible only when the text color matches a color plane of the display. For black or grayscale text, that means a grayscale display (high-resolution and expensive digital monochrome displays are popular in the medical imaging field, for example).

Otherwise, you run into the fundamental fact that color components are physically separated on the display. The concept of ClearType is to adjust the image to compensate for the actual physical offset between color planes.

Printed media with high-precision registration is the closest you get to multiple color planes without any offset.

Now, it does still make sense to disable ClearType in some cases -- when the image is intended to be saved in a file rather than presented on the local display, disabling ClearType can produce results that are legible across a wider range of displays and also compress better. (But for best results, send vectors and let the end-user display compensate for its particular sub-pixel structure)

In GDI, control of ClearType is set via the LOGFONT structure that command text-drawing functions which font family, size, and attributes to use. In GDI+, use SetTextRenderingHint on a Graphics instance.

Because the use of ClearType is set by the application at the same time as size, weight, and other attributes, your font is subject to being requested both with and without. However, ClearType is not compatible with all fonts, by forcing incompatibility you will avoid ClearType for your font alone.

The LOGFONT documentation has the following remarks about ClearType:

The following situations do not support ClearType antialiasing:

  • Text is rendered on a printer.
  • Display set for 256 colors or less.
  • Text is rendered to a terminal server client.
  • The font is not a TrueType font or an OpenType font with TrueType outlines. For example, the following do not support ClearType antialiasing: Type 1 fonts, Postscript OpenType fonts without TrueType outlines, bitmap fonts, vector fonts, and device fonts.
  • The font has tuned embedded bitmaps, for any font sizes that contain the embedded bitmaps. For example, this occurs commonly in East Asian fonts.

In addition, the gasp table within the TTF format has several fields specified to influence ClearType usage.

Documentation at https://www.microsoft.com/typography/otspec/gasp.htm and https://fontforge.github.io/fontinfo.html#gasp

And of course, make sure that the "optimized for ClearType" bit in the head table is not set.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!