fontsize和字体的宽度和高度之间是什么关系? [英] What is the relationship between fontsize and font width and height?

查看:646
本文介绍了fontsize和字体的宽度和高度之间是什么关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,伙计们
在记事本等应用程序中选择字体时,我们选择fontsize.但是,当我们使用chossefont选择字体时,我们仅选择字体的宽度和高度.我的问题是这样的:如何像记事本一样将字体大小转换为字体宽度和字体大小.
谢谢
abzadeh

Hello, guys
When selecting a font in applications such as notepad, we select fontsize. However When we use chossefont to select a font, we select only a font width and height. My question is this: How to transform font size to font width and font size as notepad does.
Thanks
abzadeh

推荐答案

我从来没有真正在意"我正在开发的应用程序中的字体宽度,在大多数情况下,用户只会看到字体点大小(例如CFontDialog).

使用LOGFONT结构时,需要将磅值转换为字体高度(计算字体的逻辑高度和磅值 [^ ])

带有类似的内容(从磅值到字体高度):

I never really "care" about the font width in the application I''ve been working on, most of the time the user will only see the font point size (e.g. CFontDialog).

When working with the LOGFONT structure, you need to convert the point size to the font height (Calculating The Logical Height and Point Size of a Font[^] )

With something like (from point size to font height):

CDC* cdc = GetDC();
HDC hdc = cdc->GetSafeHdc();
int pointPerInch = 72;
int deviceCaps = GetDeviceCaps( hdc, LOGPIXELSY );
// Generate a LOGFONT containing all the font properties.
LOGFONT logFont;
strcpy( logFont.lfFaceName, fontProperties.m_FontName );
logFont.lfHeight = -MulDiv(fontProperties.m_FontSize, deviceCaps, pointPerInch);
logFont.lfWidth = 0; // keep zero.
...


它们都是相同指标的一部分.字体大小以字体中每个字符的边界矩形的高度(以磅为单位)给出,或者当字符的某些部分可以在该矩形的上方或下方延伸时,每个字符的最大高度;或宽度,或某些功能组合.字体中每个字符的宽度将与字体设计者设置的高度成比例.在固定宽度字体中,每个字符都具有相同的宽度,在比例字体中,宽度应尽可能大以显示字符(参见"i"和"w").在设备上下文中选择字体后,您可以获取包括高度,宽度等在内的文本指标.

以下代码提供了一个示例:
They are all part of the same metrics. Font size is given as either the height (in points) of the bounding rectangle of each character in the font, or the maximum height of each character when parts of the character can extend above or below this rectangle; or the width, or some combination of features. The width of each character in the font will be proportional to the height as set by the font designer. In fixed width fonts each character has the same width, in proportional fonts the width is as much as necessary to display the character (cf. ''i'' and ''w''). Once you have selected a font into a device context you can get the text metrics which includes height, width etc.

The following code gives a sample:
HFONT		hFont, hOldFont;

// get a 10-point font and select it into the DC
currentY = MulDiv(10, GetDeviceCaps(hDC, LOGPIXELSY), 72);
hFont = CreateFont(-currentY, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0, 0, 0, 0, L"Courier New");
hOldFont = SelectFont(hDC, hFont);

GetTextMetrics(hDC, &textMetric);



看看 MSDN页面 [



Take a look at the MSDN pages[^] for each of the above functions for more detail.


"大小"通常指高度(或单元格高度",请参见此处 [
在不知道是否同样适用于垂直脚本(如一些亚洲字母)(带有"transforantions").
"Size" is commonly referred to the height (or to the "cell height", see here[^]), letting the width chosen proportionally.

It essentially derives from the fact that words are written horizontally, so in a line "same height" (or different height) is a more important concept than "same width".

In don''t know if the same applies (with the due "transforantions") to vertical scripting (like some asian alphabets) as well.


这篇关于fontsize和字体的宽度和高度之间是什么关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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