字体问题
1 GetTextMetrics(hdc,&tm);
2 cxChar=tm.tmAveCharWidth;
3 cxCaps=(tm.tmPitchAndFamily & 1 ? 3:2)*cxChar/2;
4 cyChar=tm.tmHeight+tm.tmExternalLeading;
5 iMaxWidth=40*cxChar+22*cxCaps;
第3和5句是什么意思?
问题点数:100、回复次数:4Top
1 楼AloneWolf(孤狼)回复于 2002-03-28 09:43:53 得分 50
3.
if(tm.tmPitchAndFamily & 1 !=0)
{
cxCaps=3*cxChar/2;
}
else cxCaps=2*cxChar/2;
tmPitchAndFamily
Specifies information about the pitch, the technology, and the family of a physical font.
The four low-order bits of this member specify information about the pitch and the technology of the font. A constant is defined for each of the four bits: Constant Meaning
TMPF_FIXED_PITCH If this bit is set the font is a variable pitch font. If this bit is clear the font is a fixed pitch font. Note very carefully that those meanings are the opposite of what the constant name implies.
TMPF_VECTOR If this bit is set the font is a vector font.
TMPF_TRUETYPE If this bit is set the font is a TrueType font.
TMPF_DEVICE If this bit is set the font is a device font.
An application should carefully test for qualities encoded in these low-order bits, making no arbitrary assumptions. For example, besides having their own bits set, TrueType and PostScript fonts set the TMPF_VECTOR bit. A monospace bitmap font has all of these low-order bits clear; a proportional bitmap font sets the TMPF_FIXED_PITCH bit. A Postscript printer device font sets the TMPF_DEVICE, TMPF_VECTOR, and TMPF_FIXED_PITCH bits.
The four high-order bits of tmPitchAndFamily designate the font's font family. An application can use the value 0xF0 and the bitwise AND operator to mask out the four low-order bits of tmPitchAndFamily, thus obtaining a value that can be directly compared with font family names to find an identical match. For information about font families, see the description of the LOGFONT structure.
Top
2 楼rocmeteor(拄杖携残醉,扶风上九霄)回复于 2002-03-28 09:54:53 得分 50
是Programming Windows上的代码吧?
#define TMPF_FIXED_PITCH 0x01
#define TMPF_VECTOR 0x02
#define TMPF_DEVICE 0x08
#define TMPF_TRUETYPE 0x04
tmPitchAndFamily & 1是说如果字体宽度可变,则采用1.5倍于平均字符宽度,也就是的该字体的最大宽度了,如果字体宽度固定,则用平均字符宽度就可以了(实际上也是该字体的最大宽度了,)最大宽度与平均宽度的关系,参见原书。
iMaxWidth=40*cxChar+22*cxCaps;
是为了定义横行滚动条出现的条件,因为下面的WM_PAINT中就是这么TextOut的。
OK?
Top
3 楼ffuu()回复于 2002-03-28 10:32:05 得分 0
牛!
这都看得出来,能把QQ号告诉我吗?以后我可以请教。---不是很过分吧?Top
4 楼rocmeteor(拄杖携残醉,扶风上九霄)回复于 2002-03-28 11:22:42 得分 0
是在说我吗?不是吧?是在说别人吧?:)
我没有QQ:(Top




