Export (0) Print
Expand All

IFont interface

Provides a wrapper around a Windows font object. The COM font object supports a number of read/write properties as well as a set of methods through its IFont interface. It supports the same set of properties (but not the methods) through the dispatch interface IFontDisp, which is derived from IDispatch to provide access to the font's properties through Automation. The system provides a standard implementation of the font object with both interfaces.

The font object also supports the outgoing interface IPropertyNotifySink so a client can determine when font properties change. Because the font object supports at least one outgoing interface, it also implements IConnectionPointContainer and related interfaces for this purpose.

The font object provides an hFont property, which is a Windows font handle that conforms to the other attributes specified for the font. The font object delays realizing this hFont object when possible, so consecutively setting two properties on a font will not cause an intermediate font to be realized. In addition, as an optimization, the system-implemented font object maintains a cache of font handles. Two font objects in the same process that have identical properties will return the same font handle. The font object can remove font handles from this cache at will, which introduces special considerations for clients using the hFont property.

The font object also supports IPersistStream so that it can save and load itself from an instance of IStream. An object that uses a font object internally would normally save and load the font as part of the object's own persistence handling.

In addition, the font object supports IDataObject, which can render a property set containing the font's attributes, allowing a client to save these properties as text.

When to implement

Typically, you use the COM-provided font object, which implements the IFont interface as its primary interface. It allows the caller to manage font properties and to use that font in graphical rendering.

When to use

Use this interface to change or retrieve the properties of a font object.

Members

The IFont interface inherits from the IUnknown interface. IFont also has these types of members:

Methods

The IFont interface has these methods.

MethodDescription
AddRefHfont

Notifies the font object that the previously realized font identified with hFont (from get_hFont) should remain valid until ReleaseHfont is called or the font object itself is released.

Clone

Creates a duplicate font object with a state identical to the current font.

get_Bold

Gets the font's current Bold property.

get_Charset

Retrieves the character set used in the font.

get_hFont

Retrieves a handle to the font described by this font object.

get_Italic

Gets the font's current Italic property.

get_Name

Retrieves the name of the font family.

get_Size

Retrieves the point size of the font.

get_Strikethrough

Gets the font's current Strikethrough property.

get_Underline

Gets the font's current Underline property.

get_Weight

Gets the font's current Weight property.

IsEqual

Compares this font object to another for equality.

put_Bold

Sets the font's Bold property.

put_Charset

Sets the font's character set.

put_Italic

Sets the font's Italic property.

put_Name

Specifies a new name for the font family.

put_Size

Sets the point size of the font.

put_Strikethrough

Sets the font's Strikethrough property.

put_Underline

Sets the font's Underline property.

put_Weight

Sets the font's Weight property.

QueryTextMetrics

Retrieves information about the font.

ReleaseHfont

Notifies the font object that the caller that previously locked this font in the cache with AddRefHfont no longer requires the lock.

SetHdc

Provides a device context handle to the font that describes the logical mapping mode.

SetRatio

Converts the scaling factor for this font between logical units and HIMETRIC units (in which is expressed the point size in the Size property).

 

Remarks

Each property in the IFont interface includes a get_PropertyName method if the property supports read access and a put_PropertyName method if the property supports write access. Most of these properties support both read and write access.

PropertyTypeRead Access MethodWrite Access MethodDescription
NameBSTR get_Name put_Name The facename of the font, e.g. Arial.
SizeCY get_Size put_Size The point size of the font, expressed in a CY type to allow for fractional point sizes.
BoldBOOL get_Bold put_Bold Indicates whether the font is boldfaced.
ItalicBOOL get_Italic put_Italic Indicates whether the font is italicized.
UnderlineBOOL get_Underline put_Underline Indicates whether the font is underlined.
StrikethroughBOOL get_Strikethrough put_Strikethrough Indicates whether the font is strikethrough.
Weightshort get_Weight put_Weight The boldness of the font.
Charsetshort get_Charset put_Charset The character set used in the font, such as ANSI_CHARSET, DEFAULT_CHARSET, or SYMBOL_CHARSET.
hFontHFONT get_hFont The Windows font handle that can be selected into a device context for rendering.

 

OLE Implementation

The system provides a standard implementation of a font object with the IFont interface on top of the underlying system font support. A font object is created through the function OleCreateFontIndirect. A font object supports a number of read/write properties as well as a set of methods through its IFont interface and supports the same set of properties (but not the methods) through a dispatch interface IFontDisp which is derived from IDispatch to provide access to the font's properties through Automation. The system implementation of the font object supplies both interfaces.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps | Windows Store apps]

Minimum supported server

Windows 2000 Server [desktop apps | Windows Store apps]

Header

OCIdl.h

IDL

OCIdl.idl

IID

IID_IFont is defined as BEF6E002-A874-101A-8BBA-00AA00300CAB

See also

IFontDisp

 

 

Community Additions

ADD
Show:
© 2014 Microsoft