zoukankan      html  css  js  c++  java
  • [Programming Visual C++]Chapter Five Fonts

    With the TrueType fonts, it doesn't much matter what mapping mode you use; simply choose a font height and go for it. No need to worry about points.

    If you're using the CDC::GetTextExtent function to calculate line breaks, the screen breakpoint will occasionally be different from the printer breakpoint.


    Index Description Value
    HORZSIZE Physical width in millimeters 320
    VERTSIZE Physical height in millimeters 240
    HORZRES Width in pixels 640
    VERTRES Height in raster lines 480
    LOGPIXELSX Horizontal dots per logical inch 96
    LOGPIXELSY Vertical dots per logical inch 96
    1 inch = 25.4 mm
    Using the values above and the fact that there are 25.4 millimeters per inch

    physical display size:
    320mm/ (25.4mm/inch) = 12.60 inch
    240mm/(25.4mm/inch) = 9.45 inch
    The physical display size is 12.60-by-9.45 inches,

    logical size:
    640pix/(96pix/inch) = 6.67inch
    480pix/(96pix/inch) = 5.00inch
    The logical size is 6.67-by-5.00 inches.

    So the physical size and the logical size need not be the same.


    For Windows NT 4.0, it turns out that HORZSIZE and VERTSIZE are independent of the display resolution, and LOGPIXELSX and LOGPIXELSY are always 96. So the logical size changes for different display resolutions, but the physical size does not. For Windows 95, the logical size and the physical size are equal, so both change with the display resolution. (At a resolution of 640-by-480 pixels with Windows 95, HORZSIZE is 169 and VERTSIZE is 127.)

    So, for Windows NT, text is smaller on a small monitor; but that's not what you want. Instead, you want your font sizes to correspond to the logical display size, not the physical size.

    You can invent a special mapping mode, called logical twips, for which one logical unit is equal to 1/1440 logical inch. This mapping mode is independent of the operating system and display resolution and is used by programs such as Microsoft Word. Here is the code that sets the mapping mode to logical twips:


    pDC->SetMapMode(MM_ANISOTROPIC);
    pDC->SetWindowExt(1440, 1440);
    pDC->SetViewportExt(pDC->GetDeviceCaps(LOGPIXELSX),
                        -pDC->GetDeviceCaps(LOGPIXELSY));


    From the Windows Control Panel, you can adjust both the display font size and the display resolution. If you change the display font size from the default 100 percent to 200 percent, HORZSIZE becomes 160, VERTSIZE becomes 120, and the dots-per-inch value becomes 192. In that case, the logical size is divided by 2, and all text drawn with the logical twips mapping mode is doubled in size.

    上面这段看不懂,为什么Horzsize是160?

    You would think that tmHeight would represent the font size in points. Wrong! Another GetTextMetrics parameter, tmInternalLeading, comes into play. The point size corresponds to the difference between tmHeight and tmInternalLeading. With the MM_TWIPS mapping mode in effect, a selected 12-point font might have a tmHeight value of 295 logical units and a tmInter-nalLeading value of 55. The font's net height of 240 corresponds to the point size of 12.

    Font size =  tmHeight - tmInter-nalLeading = net height
    example: 12-point font <=> 240 = 295 - 55


    If you want your font to be a specific point size, the CreateFont font height parameter (the first parameter) must be negative. If you're using the MM_TWIPS mapping mode for a printer, for example, a height parameter of -240 ensures a true 12-point font, with tmHeight - tmInternalLeading = 240. A +240 height parameter gives you a smaller font, with tmHeight = 240.


  • 相关阅读:
    linux那点事儿(六)进程管理详解(推荐)
    linux那点事儿(下)
    视图的架构刷新和绑定
    HttpHandler开发的两个重点问题
    RichTextBox控件的几点有意思的东西
    重复输入某个字符(C++,C#)
    几个博客系统点评
    怎么理解符号整数的取值范围(C++)
    为SSIS编写自定义任务项(Task)之进阶篇
    LINQ TO XML之判断不存在行则插入
  • 原文地址:https://www.cnblogs.com/huqingyu/p/200881.html
Copyright © 2011-2022 走看看