The CFont font class initialization function CreateFontIndirect Initializes a CFont object that is given its characteristics by the LOGFONT structure CreateFont initializes the CFont object defined with the specified attribute CreatePointFont Initializes a CFont object with a specified height (with 0.1 dots) and a font createpointfontindirect similar to CreateFontIndirect, but the font height is defined with 0.1 points instead of the logical unit definition operation FromHandle Returns a pointer property to the CFont object when given a Windows HfontoperatorHfont returns the Windows GDI font handle attached to the CFont object Getlogfont fills a logfontcfont::cfontcfont () with the logical font information attached to the CFont object; Description: Constructs a CFont object , the result object must be initialized with Createfont,createfontindirect,createpointfont or createpointfontindirect before it is used. Cfont::createfontbool CreateFont (intnheight,intnwidth,intnescapenment, Intnorientation,intnweight, Byte bitalic, byte Bunderline, byte Cstrikeout, byte Ncharset, byte noutprecision, Byte nclipprecision, byte nquality, byte npitchandfamily, LPCTSTR lpszfacename); return value: If successful, returns a value other than 0, no is 0. Parameters: nheight Specifies the height of the font in logical units, and the font height can be one of the following values: • Greater than 0, when the height is converted to device units, compared to the grid height of the available fonts. equals 0, the appropriate default size is used at this time. • Less than 0, when the height is converted to device units, and the absolute value is compared to the character height of the available font. Nheight absolute value cannot exceed 16,384 device units after conversion. In all height comparisons, if the font exceeds the required value, the large font in the font image will not exceed the desired size and the small font will not exceed. Nwidth the average width of characters in the specified font (in logical units). If 0, the device orientation ratio is compared to the digital direction ratio of the available fonts, and a recent match is found, which is determined by the absolute value of the difference. nescapement Specifies the angle (in 0.1-degree units) between the deviation perpendicular and the x-axis on the display surface. A line starting from one line to the last character in a row when deviating from the vertical, measured counterclockwise from the x-axis. norientation specifies the angle between the's baseline line and the x-axis (in 0.1-degree units). In this degree, the Y axis of the coordinate system is measured counterclockwise from the x-axis, and the y-axis is upward when the clockwise direction is rotated from the x-axis. Nweight Specifies the number of font points (in dots pixels per 1000 dots). Although nweight can be any integer value from 0 to 1000, the common values and constants are as follows: Constant value Fw_dontcare0Fw_thin -Fw_extralight $Fw_ultralight $Fw_light -Fw_normal -Fw_regular -Fw_medium -Fw_semibold -Fw_demibold -Fw_bold theFw_extrabold -Fw_ultrabold -Fw_black theFw_heavy theeach of these values is approximate, the actual appearance depends on the font size, and some fonts have only fw_normal,fw_regular,fw_bold points. If Fw_dontcare is specified, the default number of points is used. BITALIC Specifies whether the font is italic. BUNDERLINE Specifies whether the font is underlined. BSTRIKEOUT Specifies whether the font character is highlighted. If set to nonzero, it is highlighted. Ncharset the character set of the specified font, the following are predefined constants and values: Constant value Ansi_charset0Default_charset1Symbol_charset2Shiftjis_charset -Oem_charset255 The OEM character set relies on the system. Fonts with other character sets may exist in the system. An app that uses an unknown character set font cannot translate or interpret a string that is colored in this character set, instead, enter the string directly into the device driver. The font mapper does not use the Default_charset value, and an app can use this value to let the font name and size fully describe the logical font. If the specified name does not exist, the app should use default_charset sparingly in order to avoid unpredictable results. The noutprecision specifies the desired output precision. The output precision defines how close the output is to the desired font height, width, character orientation, and spacing, and can be one of the following values: Out_character_precis out_string_precisout_default_precis out_ Stroke_precisout_device_precis Out_tt_precisout_raster_precis applies when the system contains multiple fonts of a given name, the out_device_precis,out_raster_p is available The Recis and Out_tt_precis values control how a font mapper chooses a font. For example, if a system contains a font named symbol that exists as a raster and TrueType, specify OUT_TT_PRECIS to have the font mapper select the TrueType type (Specify Out_tt_ Precis forces the font mapper to select a TrueType font (when the specified font name matches a device or raster font), even if there is no TrueType font with the same name. NCLIPPRECISION Specifies the desired clipping precision. The clip precision defines how the clipped portion of the clip exceeds the clipping range and can be one of the following values: Clip_character_precis clip_maskclip_default_precis clip_stroke_precisclip_ Encapsulate Clip_tt_alwaysclip_lh_angles to use the inserted read-only font, the app must specify Clip_encapsulate. To set up device rotation, TrueType, and vector fonts, applications can combine clip_lh_angles values with other nclipprecision values using the OR operator. If the clip_lh_angles bit is set, all font rotations depend on whether the coordinate system is positioned in the left or right hand direction (for more information on axis positioning,See the description of the norientation parameter). If the clip_lh_angles is not set, the font is rotated counterclockwise, but the rotation of the other fonts depends on the rotation of the coordinate system. Nquality indicates the output quality of the font, defining the extent to which GDI must match the logical font attributes to the physical font attributes. Can be one of the following values: The appearance of the Default_quality font does not matter. Draft_quality when proof_quality is used, the appearance of the font is less important. For GDI raster fonts, scaling is allowed. Bold, italic, underline, highlighted fonts, and synthetic processing are available when needed. The character quality of proof_quality fonts is more important than matching the exact logical font characteristics. For GDI raster fonts, scaling is not valid and the size closest to the font is selected. Bold, italic, underline, highlight, and synthetic processing are available when needed. npitchandfamily Specifies the spacing and family of fonts. Two lows specifies the spacing for the font, which can be one of the following values: Default_pitch, Variable_pitch, fixed_pitch applications can t\mpf_ TrueType is added to the npitchandfamily parameter to select a TrueType font. High four-bit specifies the font family, which can be one of the following values: • ff_decorative novelty fonts, such as the previous English font. Ff_dontcare do not care or know. Ff_modern Pen-type width-invariant font, with or without serif. Fixed-pitch fonts are often modern in style, such as Pica,elite and Courier New. Ff_roman Stroke width variable (proportional adjustment space) and lined font. such as Times New Roman and Century Schoolbook. Ff_script fonts similar to handwriting, such as SCRIPT and cursive. Ff_swiss Stroke width variable (proportional space) and without serif fonts, such as Ms Sans Serif. An application can use Boolean operations or specify a npithandfamily value to combine an italic and a family constant. The font family describes the appearance of fonts in a normal way, which is used to define the specified font when the required lead font is invalid. Lpszfacenamecstring or points to a pointer to a null-terminated string that specifies the name of the font typeface. The length of this string cannot be longer than 30 characters, WindowsenThe Umfontfamilies function can be used to enumerate all currently available fonts. If NULL, GDI uses a font that is not dependent on the device. Description: Initializes a CFont object with the specified characteristics. This font can be selected as the font for any device context. The CreateFont function does not create a new Windows GDI font, just selects the closest matching font from the GDI physical font library. When you construct a logical font, the app can use the default settings for most of these parameters. The parameters should often be given a specific value of nheight and Lpszfacename. If the app does not have a given nheight and Lpszface Name, the logical font is device-related. When a CFont object is created with the CreateFont function, first select the font from the device context and then delete the CFont object. Cfont::createfontindirectbool CreateFontIndirect (Constlogfont*lplogfont); return value: If successful, a value other than 0 is returned, otherwise 0. Parameters: lpLogFont points to a LOGFONT structure that defines the characteristics of a logical font. Description: Initializes a CFont object with the features defined by the LOGFONT structure pointed to by lpLogFont, which can then be selected as the current font by any device. This font has characteristics defined by the LOGFONT structure. When you use the CDC::SelectObject member function selection, the GDI font Mapper strives to match the logical font to the existing physical font. If a matching logical font is not found, try to find the font substitution that matches the most attributes. After you have created the CFont object with the CreateFontIndirect function, first select the font in the device context and then delete the CFont object. Cfont::createpointfontbool CreatePointFont (intNpointsize, LPCTSTR lpszfacename, cdc* PDC =NULL); return value: If successful, a value other than 0 is returned, otherwise 0. Parameters: npointsize the desired font height (denoted by 0.1 dots, for example, pass 120 for 12-point font). Lpszfacename a CString or a string that ends with a null terminator to define the font name. The length of this string should not exceed 30 characters. The Windows enumfontfamilies function can be used to calculate the total number of currently available fonts. If NULL, GDI uses device-independent fonts. The PDC points to the CDC object and converts the height in npointsize to a logical unit. If NULL, the screen device context is used for the conversion. Description: This function provides a way to create a font object of the specified font and point size, which automatically converts the height in npointsize to a logical unit, which is implemented using the CDC object pointed to by the PDC. When you are finished creating the CFont object with the CreatePointFont function, select the font from the device context and then delete the CFont object. Cfont::createpointfontindirectbool Createpointfontindirect (Constlogfont* lpLogFont, cdc* PDC =NULL); return value: If successful, a value other than 0 is returned, otherwise 0. Parameters: lpLogFont points to the LOGFONT structure, defining the logical font characteristics. The lfheight members of the LOGFONT are calculated with 0.1 points instead of logical units (12-point font is required if the set Lfheight is 120). The PDC points to the CDC object, which converts the height in lfheight to a logical unit. If NULL, the screen device context is used for the conversion. Description: This function is similar to CreateFontIndirect, but the lfheight member of LOGFONT is represented by 0.1 points instead of in device units. Before passing the LOGFONT structure to Windows, the CDC object that the PDC points to automatically translates the height in the function's lfheight to logical units. After completing the CFont object created by the Createpointfontindirect function, first select the device context font and then delete the CFont object. Cfont::fromhandleStaticcfont*PASCAL FromHandle (Hfont hfont); return value: If successful, a pointer to the CFont object, otherwise null. Parameter: Hfontwindows the Hfont handle in the font. When given a hfont handle to a Windows GDI font object, returns a pointer to the CFont object. If the CFont object is not yet attached to the handle, a temporary CFont object is created and attached, and the temporary CFont object is only available when the app is idle in the event loop, and the temporary drawing object is deleted. Another argument is that temporary objects are only available in a window message process. Cfont::getlogfontintGetlogfont (logfont*plogfont); return value: If successful, a value other than 0 is returned, otherwise 0. Parameters: Plogfont points to the LOGFONT structure to receive font information. Description: Call this member function to get a copy of the CFont LOGFONT structure. CFont::operatorHfontoperatorHfont ()Constreturn value: If successful, returns a handle to the Windows GDI Font object attached to CFont, otherwise null. Description: Use this operation to obtain a handle to the Windows GDI Font object attached to CFont. Because the operation automatically converts cfont to fonts and text, you can pass the CFont object to a function other than Hfont.
CFont Font Class