【问题标题】:How to calculate /Widths table?如何计算 /Widths 表?
【发布时间】:2018-05-29 20:30:35
【问题描述】:

我的 MFC 应用程序生成 PDF,现在我正在尝试嵌入 TrueType 字体,要嵌入我需要“告诉”PDF 上的字体对象Glyph Widths 的字体,

我无法获取这些值,我已经尝试使用 GetCharABCWidthsFloatGetCharWidthFloat 并结合 this answer 表示我需要使用公式 (advance * 1000) / unitsPerEm(将 GetCharWidthFloat 的结果缩放为获得预付款)。

但我不明白如何扩展它?是否有返回这些值的 winApi 函数?

任何帮助将不胜感激!谢谢!

【问题讨论】:

    标签: pdf winapi mfc pdf-generation


    【解决方案1】:

    1 em 等于 12 points
    see reference


    对于MM_TEXT映射模式,字体高度定义为:

    lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
    //or 
    lfHeight = round(PointSize * GetDeviceCaps(hDC, LOGPIXELSY) / 72.0f);
    

    see LOGFONG documentation


    例如,对于桌面屏幕,在 100% DPI 时,GetDeviceCaps(hDC, LOGPIXELSY) 返回 96。在这种情况下,我们有:

    1em = 16,100% DPI

    1em = 20,DPI 为 125%

    1em = 24,DPI 为 150%

    double inch_per_pixel_y = (double)dc.GetDeviceCaps(LOGPIXELSY);
    
    int size_em = 1;
    int size_from_em = (int)round(size_em * inch_per_pixel_y / 6.0f);
    printf("size_from_em %d\n", size_from_em);
    
    size_em = (int)round(size_from_em * 6.0f / inch_per_pixel_y);
    printf("size_from_em %d\n", size_em);
    

    请注意,我们在这里失去了很多精度。也许这就是 PDF 乘以因子 1000 的原因。

    使用dc.GetDeviceCaps(LOGPIXELSX) 进行宽度计算。

    【讨论】:

      猜你喜欢
      • 2018-05-08
      • 1970-01-01
      • 2017-06-19
      • 1970-01-01
      • 2020-03-21
      • 1970-01-01
      • 2016-04-19
      • 1970-01-01
      • 2011-12-16
      相关资源
      最近更新 更多