将LogFont高度转换为字体大小 [英] Converting LogFont height to Font size in points

查看:1447
本文介绍了将LogFont高度转换为字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个LOGFONT结构。现在我想做的是从LOGFONT高度得到相关的字体大小。

解决方案

当映射模式是 mm_Text (通常是这样),当 lfHeight 字段为正时,它已经给出了高度。当它是负数时,单位是像素。 用于LogFont的MSDN 为您提供了在它们之间转换的公式:


  lfHeight = -MulDiv(PointSize,GetDeviceCaps(hDC,LOGPIXELSY),72); 


每英寸有72点。 GetDeviceCaps 告诉您给定设备每英寸的像素数。反转公式从点获取像素:

  PointSize:= MulDiv(-lfHeight,72,GetDeviceCaps(hDC,LogPixelsY); 

这里要重要的一点是需要一个设备上下文,字体大小不会独立存在他们出现的媒体的像素高度在屏幕上的像素高度将不同于打印机上字体的像素高度,使用任何画布的句柄属性你正在计划绘图。


I have a LOGFONT structure. Now all i'd like to do is get the associated font size in points from the LOGFONT height.

解决方案

When the mapping mode is mm_Text (which it usually is), and when the lfHeight field is positive, it already gives the height in points. When it's negative, the units are pixels. MSDN for LogFont gives you the formula to convert between them:

lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);

There are 72 points per inch. GetDeviceCaps tells you the number of pixels per inch on a given device. Invert the formula to get pixels from points:

PointSize := MulDiv(-lfHeight, 72, GetDeviceCaps(hDC, LogPixelsY);

The important thing to realize here is that you need a device context. Font sizes don't exist independently of the media they appear on. The pixel height of a font on the screen will be different from the pixel height of a font on a printer. Use the Handle property of whatever canvas you're planning on drawing to.

这篇关于将LogFont高度转换为字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆