Font size discrepancy in .NET GDI+?

后端 未结 2 1991
半阙折子戏
半阙折子戏 2021-02-20 14:16

I am wracking my brains in trying to understand the discrepancy between the font sizes users select or specify (for example, using a FontDialog) and the em-size

相关标签:
2条回答
  • 2021-02-20 14:32

    there is no pattern in the discrepancy

    As you can see, font sizes happen in increments of 0.75.

    Edit: You can fine tune sizes if you do not use the font dialog, but the results I suspect will be less pleasing than the 'preferred' sizes.

    0 讨论(0)
  • 2021-02-20 14:34

    Consider these tidbits:

    • An inch, as a result of however these things are decided in history, contains 72 points.
    • Usually people are running Windows at a logical resolution of 96 dots per inch.
    • Hmm, OK, we've got points, inches, and dots--three units to deal with here.
    • GDI wants to know how many dots to draw, and the user is selecting points.
    • Finally, the ratio of 72 points per inch / 96 dots per inch = 0.75 points per dot.

    That 0.75 is unfortunate! It means that if we allow the user to choose points straight up, then the ideal rendering would draw on just part of a logical dot. It'd be nice if we could snap the entire rendering up or down to the nearest whole logical dot.

    Ready? Here we go!


    • 11:
      • 11 points / 72 points per inch = 0.153 inches * 96 dots per inch = 14.667 dots, BARF!
      • Let's round up to 15 dots,
      • SO then 15 dots / 96 dots per inch * 72 points per inch = 11.25 points.

    • 12:
      • 12 / 72 * 96 = 16 dots.
      • I can live with that, no fudging necessary.

    • 16:
      • 16 / 72 * 96 = 21.3333, BARF!
      • Let's round down to 21 dots / 96 * 72 = 15.75, much nicer.

    You get the idea.

    Remember that these numbers will change if the user changes their logical resolution (96 dpi, 120 dpi, etc.)

    0 讨论(0)
提交回复
热议问题