lfItalic
Specifies an italic font if set to TRUE.
lfUnderline
Specifies an underlined font if set to TRUE.
lfStrikeOut
Specifies a strikeout font if set to TRUE.
lfCharSet
Specifies the character set. The following values are predefined:
ANSI_CHARSET
BALTIC_CHARSET
CHINESEBIG5_CHARSET
DEFAULT_CHARSET
EASTEUROPE_CHARSET
GB2312_CHARSET
GREEK_CHARSET
HANGUL_CHARSET
MAC_CHARSET
OEM_CHARSET
RUSSIAN_CHARSET
SHIFTJIS_CHARSET
SYMBOL_CHARSET
TURKISH_CHARSET
Korean Windows:
JOHAB_CHARSET
Middle-Eastern Windows:
HEBREW_CHARSET
ARABIC_CHARSET
Thai Windows:
THAI_CHARSET
The OEM_CHARSET value specifies a character set that is operating-system dependent.
You can use the DEFAULT_CHARSET value to allow the name and size of a font to fully describe the logical font. If the specified font name does not exist, a font from any character set can be substituted for the specified font, so you should use DEFAULT_CHARSET sparingly to avoid unexpected results.
Fonts with other character sets may exist in the operating system. If an application uses a font with an unknown character set, it should not attempt to translate or interpret strings that are rendered with that font.
This parameter is important in the font mapping process. To ensure consistent results, specify a specific character set. If you specify a typeface name in the lfFaceName member, make sure that the lfCharSet value matches the character set of the typeface specified in lfFaceName.
lfOutPrecision
Specifies the output precision. The output precision defines how closely the output must match the requested font's height, width, character orientation, escapement, pitch, and font type. It can be one of the following values: Value Meaning
OUT_CHARACTER_PRECIS Not used.
OUT_DEFAULT_PRECIS Specifies the default font mapper behavior.
OUT_DEVICE_PRECIS Instructs the font mapper to choose a Device font when the system contains multiple fonts with the same name.
OUT_OUTLINE_PRECIS Windows NT: This value instructs the font mapper to choose from TrueType and other outline-based fonts.
OUT_RASTER_PRECIS Instructs the font mapper to choose a raster font when the system contains multiple fonts with the same name.
OUT_STRING_PRECIS This value is not used by the font mapper, but it is returned when raster fonts are enumerated.
OUT_STROKE_PRECIS Windows NT: This value is not used by the font mapper, but it is returned when TrueType, other outline-based fonts, and vector fonts are enumerated.
Windows 95: This value is used to map vector fonts, and is returned when TrueType or vector fonts are enumerated.
OUT_TT_ONLY_PRECIS Instructs the font mapper to choose from only TrueType fonts. If there are no TrueType fonts installed in the system, the font mapper returns to default behavior.
OUT_TT_PRECIS Instructs the font mapper to choose a TrueType font when the system contains multiple fonts with the same name.
Applications can use the OUT_DEVICE_PRECIS, OUT_RASTER_PRECIS, and OUT_TT_PRECIS values to control how the font mapper chooses a font when the operating system contains more than one font with a given name. For example, if an operating system contains a font named Symbol in raster and TrueType form, specifying OUT_TT_PRECIS forces the font mapper to choose the TrueType version. Specifying OUT_TT_ONLY_PRECIS forces the font mapper to choose a TrueType font, even if it must substitute a TrueType font of another name.
lfClipPrecision
Specifies the clipping precision. The clipping precision defines how to clip characters that are partially outside the clipping region. It can be one or more of the following values: Value Meaning
CLIP_DEFAULT_PRECIS Specifies default clipping behavior.
CLIP_CHARACTER_PRECIS Not used.
CLIP_STROKE_PRECIS Not used by the font mapper, but is returned when raster, vector, or TrueType fonts are enumerated.
Windows NT: For compatibility, this value is always returned when enumerating fonts.
CLIP_MASK Not used.
CLIP_EMBEDDED You must specify this flag to use an embedded read-only font.
CLIP_LH_ANGLES When this value is used, the rotation for all fonts depends on whether the orientation of the coordinate system is left-handed or right-handed.
If not used, device fonts always rotate counterclockwise, but the rotation of other fonts is dependent on the orientation of the coordinate system.
For more information about the orientation of coordinate systems, see the description of the nOrientation parameter
CLIP_TT_ALWAYS Not used.
lfQuality
Specifies the output quality. The output quality defines how carefully the graphics device interface (GDI) must attempt to match the logical-font attributes to those of an actual physical font. It can be one of the following values: Value Meaning
DEFAULT_QUALITY Appearance of the font does not matter.
DRAFT_QUALITY Appearance of the font is less important than when PROOF_QUALITY is used. For GDI raster fonts, scaling is enabled, which means that more font sizes are available, but the quality may be lower. Bold, italic, underline, and strikeout fonts are synthesized if necessary.
PROOF_QUALITY Character quality of the font is more important than exact matching of the logical-font attributes. For GDI raster fonts, scaling is disabled and the font closest in size is chosen. Although the chosen font size may not be mapped exactly when PROOF_QUALITY is used, the quality of the font is high and there is no distortion of appearance. Bold, italic, underline, and strikeout fonts are synthesized if necessary.
lfPitchAndFamily
Specifies the pitch and family of the font. The two low-order bits specify the pitch of the font and can be one of the following values:
DEFAULT_PITCH
FIXED_PITCH
VARIABLE_PITCH
Bits 4 through 7 of the member specify the font family and can be one of the following values:
The proper value can be obtained by using the Boolean OR operator to join one pitch constant with one family constant.
Font families describe the look of a font in a general way. They are intended for specifying fonts when the exact typeface desired is not available. The values for font families are as follows: Value Meaning
FF_DECORATIVE Novelty fonts. Old English is an example.
FF_DONTCARE Don't care or don't know.
FF_MODERN Fonts with constant stroke width (monospace), with or without serifs. Monospace fonts are usually modern. Pica, Elite, and CourierNew® are examples.
FF_ROMAN Fonts with variable stroke width (proportional) and with serifs. MS® Serif is an example.
FF_SCRIPT Fonts designed to look like handwriting. Script and Cursive are examples.
FF_SWISS Fonts with variable stroke width (proportional) and without serifs. MS® Sans Serif is an example.
lfFaceName
A null-terminated string that specifies the typeface name of the font. The length of this string must not exceed 32 characters, including the null terminator. The EnumFontFamilies function can be used to enumerate the typeface names of all currently available fonts. If lfFaceName is an empty string, GDI uses the first font that matches the other specified attributes
LOGFONT
The LOGFONT structure defines the attributes of a font.
typedef struct tagLOGFONT { // lf
LONG lfHeight;
LONG lfWidth;
LONG lfEscapement;
LONG lfOrientation;
LONG lfWeight;
BYTE lfItalic;
BYTE lfUnderline;
BYTE lfStrikeOut;
BYTE lfCharSet;
BYTE lfOutPrecision;
BYTE lfClipPrecision;
BYTE lfQuality;
BYTE lfPitchAndFamily;
TCHAR lfFaceName[LF_FACESIZE];
} LOGFONT;
Members
lfHeight
Specifies the height, in logical units, of the font's character cell or character. The character height value (also known as the em height) is the character cell height value minus the internal-leading value. The font mapper interprets the value specified in lfHeight in the following manner: Value Meaning
> 0 The font mapper transforms this value into device units and matches it against the cell height of the available fonts.
0 The font mapper uses a default height value when it searches for a match.
< 0 The font mapper transforms this value into device units and matches its absolute value against the character height of the available fonts.
For all height comparisons, the font mapper looks for the largest font that does not exceed the requested size.
This mapping occurs when the font is used for the first time.
For the MM_TEXT mapping mode, you can use the following formula to specify a height for a font with a given point size:
lfWidth
Specifies the average width, in logical units, of characters in the font. If lfWidth is zero, the aspect ratio of the device is matched against the digitization aspect ratio of the available fonts to find the closest match, determined by the absolute value of the difference.
lfEscapement
Specifies the angle, in tenths of degrees, between the escapement vector and the x-axis of the device. The escapement vector is parallel to the base line of a row of text.
Windows NT: When the graphics mode is set to GM_ADVANCED, you can specify the escapement angle of the string independently of the orientation angle of the string's characters.
When the graphics mode is set to GM_COMPATIBLE, lfEscapement specifies both the escapement and orientation. You should set lfEscapement and lfOrientation to the same value.
Windows 95: The lfEscapement member specifies both the escapement and orientation. You should set lfEscapement and lfOrientation to the same value.
lfOrientation
Specifies the angle, in tenths of degrees, between each character's base line and the x-axis of the device.
lfWeight
Specifies the weight of the font in the range 0 through 1000. For example, 400 is normal and 700 is bold. If this value is zero, a default weight is used.
The following values are defined for convenience: Value Weight
FW_DONTCARE 0
FW_THIN 100
FW_EXTRALIGHT 200
FW_ULTRALIGHT 200
FW_LIGHT 300
FW_NORMAL 400
FW_REGULAR 400
FW_MEDIUM 500
FW_SEMIBOLD 600
FW_DEMIBOLD 600
FW_BOLD 700
FW_EXTRABOLD 800
FW_ULTRABOLD 800
FW_HEAVY 900
FW_BLACK 900
Type LOGFONT
lfHeight As Integer ' 字体的高度
lfWidth As Integer ' 字体的宽度
lfEscapement As Integer ' 字体旋转的角度
lfOrientation As Integer
lfWeight As Integer ' 字体的轻重
lfItalic As String * 1 ' 是否为斜体
lfUnderline As String * 1 ' 是否有下划线
lfStrikeOut As String * 1 ' 是否有强调线
lfCharSet As String * 1 ' 字符集
lfOutPrecision As String * 1 ' 输出精度
lfClipPrecision As String * 1 ' 剪裁精度
lfQuality As String * 1 ' 输出质量
lfPitchAndFamily As String * 1 ' 间距和字体族
lfFaceName As String * LF_FACESIZE ' 字体名,如“宋体”
End Type
利用这个数据结构,你可以方便地设置各种字体参数,比如高度、宽度等。该结构中同我们所要讨论的问题关系最大的是lfEscapement,它表示字符的基线同坐标的X轴之间的旋转角度,从X轴正方向开始沿逆时针方向旋转,以十分之一度为单位(图2)。蔡明志先生著的《Windows程序设计·绘图篇--使用Borland C++ for Windows》一书(科学出版社1993年9月出版)的482页上指出旋转角度以十度为单位,为此笔者查阅了SDK手册,其英文原文为:“measured in tenths of a degree”,似应为以十分之一度为单位。
' 逻辑字体
Global Const LF_FACESIZE = 32 ' 最长的字体名称
Global Const SYSTEM_FONT = 13
Type LOGFONT
lfHeight As Integer
lfWidth As Integer
lfEscapement As Integer
lfOrientation As Integer
lfWeight As Integer
lfItalic As String * 1
lfUnderline As String * 1
lfStrikeOut As String * 1
lfCharSet As String * 1
lfOutPrecision As String * 1
lfClipPrecision As String * 1
lfQuality As String * 1
lfPitchAndFamily As String * 1
lfFaceName As String * LF_FACESIZE
End Type
' 字体的族
Global Const FF_DONTCARE = 0 ' 无所谓
Global Const FF_ROMAN = 16 ' 字体宽度可变,Times Roman, Century ' Schoolbook等
Global Const FF_SWISS = 32 ' 宽度可变,带衬线,如Helvetica, Swiss等
Global Const FF_MODERN = 48 ' 具有规定的宽度,衬线可有可无,
' 如Pica, Elite, Courier等等.
Global Const FF_SCRIPT = 64 ' 手写体,如Cursive
Global Const FF_DECORATIVE = 80 ' 特殊字体,如Old English
' GDI字体函数
Declare Function CreateFontIndirect Lib "GDI" (lpLogFont As LOGFONT) As Integer
Declare Function SelectObject Lib "GDI" (ByVal hDC%, ByVal Object%) As Integer
Declare Sub DeleteObject Lib "GDI" (ByVal Object%)
Declare Function GetStockObject Lib "GDI" (ByVal nIndex As Integer) As Integer
Declare Sub GDIGetObject Lib "GDI" Alias "GetObject" (ByVal hObject As Integer, ByVal nCount As Integer, lpObject As Any)
Declare Sub TextOut Lib "GDI" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal lpString As String, ByVal nCount As Integer)
ROTFONT.FRM文件:
VERSION 2.00
Begin Form frmRotDemo
Caption = "旋转字体演示"
ClientHeight = 4980
ClientLeft = 1095
ClientTop = 1785
ClientWidth = 4380
FontBold = -1 'True
FontItalic = 0 'False
FontName = "Courier New"
FontSize = 18
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 5670
Left = 1035
LinkTopic = "Form1"
ScaleHeight = 332
ScaleMode = 3 'Pixel
ScaleWidth = 292
Top = 1155
Width = 4500
Begin CommonDialog CMDialog1
Flags = 257
Left = 0
Top = 0
End
Begin Menu mnuOption
Caption = "选择(&O)"
Begin Menu mnuFont
Caption = "字体(&F)..."
Shortcut = ^F
End
Begin Menu mnuS1
Caption = "-"
End
Begin Menu mnuExit
Caption = "退出(&X)"
Shortcut = ^X
End
End
End
Option Explicit
Sub Form_Paint ()
Dim nAngle%
Cls
For nAngle% = 20 To 80 Step 10
ForeColor = QBColor(nAngle% / 10 - 2)
RotPrint hDC, "热情技术技巧 旋转字体", 10, 290, nAngle%
Next
End Sub