Repository navigation
CTextFont2
Home › All Categories › sys/win › sys/win/richedit › CTextFont2
Reads and sets the character formatting of rich edit text: font, size, colour and effects.
Reads and sets the character formatting of rich edit text: font, size, colour and effects.
CTextFont2 wraps the Text Object Model's ITextFont2 interface, the TOM's view of character
formatting. You get one from a range or the selection, and from the document's default font:
| Source | Call | The font object is |
|---|---|---|
| A range of text |
CTextRange2.GetFont()
|
attached: every change applies to that text at once |
| The selection |
CTextSelection2.GetFont()
|
attached to the selected text |
| The document default |
CRichEditCtx.DocumentFont
|
the document's default character format |
| Another font object | GetDuplicate | a detached copy: changes go nowhere until applied |
Ownership. The constructor takes the ITextFont2 pointer as it is, without adding a
reference (pass true as the second argument to add one), and the destructor releases it. So
dim f as CTextFont2 = rng.GetFont() takes over the pointer GetFont returned and needs no
release of its own. The class has no copy constructor or assignment of its own: a copy shares the
same pointer and both copies release it, so pass a CTextFont2 byref and do not copy it. The
pointer is in the public field m_pTextFont2, for calls into the interface the class does not
wrap.
Three forms of each property. Most attributes come as GetX(), which returns the value;
SetX( Value ), which returns the HRESULT; and a property X to read and assign
(f.Bold = tomTrue). All three store the HRESULT of the call, which GetLastResult()
returns; GetErrorInfo() turns it into text. Both come from the base class CTextObjectBase
(see Text Object Model).
tomBool values. The on/off attributes (bold, italic, hidden …) use tomTrue (-1) and
tomFalse (0). When setting, tomToggle flips the current state and tomUndefined leaves it as
it is. When reading a range whose characters differ, the value is tomUndefined (-9999999); the
same goes for the numeric attributes, so Size on a range that mixes two sizes reads
-9999999.
Units. Size, Kerning, Spacing and Position are single values in points.
The examples assume hCtrl is a rich edit control made by CRichEditCtx and work
on its first five characters.
#import "sys/win"
#import "sys/win/richedit"
using win, richeditA rich edit control whose first words are made bold, red and large through CTextFont2. The
Bold button toggles bold on the selection and shows the selection's font in the caption.
#import "sys/win"
#import "sys/win/gui"
#import "sys/win/richedit"
using win, gui, richedit
const IDC_RICHEDIT = 101
const IDC_BOLD = 102
declare function WndProc( byval hwnd as HWND, byval uMsg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULT
function main() as long
SetProcessDpiAwareness( PROCESS_SYSTEM_DPI_AWARE )
dim pWindow as CWindow = "FontDemo"
dim hWin as HWND = pWindow.Create( NULL, "CTextFont2", @WndProc )
SetWindowClientSizeForDpi( hWin, 500, 260 )
CenterWindow( hWin )
dim pRichEdit as CRichEditCtx = CRichEditCtx( @pWindow, IDC_RICHEDIT, "", 10, 10, 480, 200 )
pRichEdit.SetText( "Bold, red and large: character formatting through the Text Object Model." )
scope
dim rng as CTextRange2 = pRichEdit.Range( 0, 4 ) ' "Bold"
dim f as CTextFont2 = rng.GetFont()
f.Bold = tomTrue
end scope
scope
dim rng as CTextRange2 = pRichEdit.Range( 6, 9 ) ' "red"
dim f as CTextFont2 = rng.GetFont()
f.ForeColor = BGR( 220, 0, 0 )
end scope
scope
dim rng as CTextRange2 = pRichEdit.Range( 14, 19 ) ' "large"
dim f as CTextFont2 = rng.GetFont()
f.Size = 16
f.Name = "Georgia"
end scope
pWindow.AddControl( "Button", hWin, IDC_BOLD, "&Bold", 10, 220, 100, 28 )
return pWindow.DoEvents( SW_NORMAL )
end function
function WndProc( byval hwnd as HWND, byval uMsg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULT
select case uMsg
case WM_COMMAND
if CBCTL( wParam, lParam ) = IDC_BOLD andalso CBCTLMSG( wParam, lParam ) = BN_CLICKED then
dim pRichEdit as CRichEditCtx ptr = CRichEditCtxPtr( hwnd, IDC_RICHEDIT )
if pRichEdit then
dim sel as CTextSelection2 = pRichEdit->Selection2()
dim f as CTextFont2 = sel.GetFont()
f.Bold = tomToggle
SetWindowText( hwnd, f.Name & ", " & f.Size & " pt" )
SetFocus( pRichEdit->hRichEdit )
end if
end if
return 0
case WM_DESTROY
PostQuitMessage( 0 )
return 0
end select
return DefWindowProcW( hwnd, uMsg, wParam, lParam )
end function
end main()constructor( byval pTextFont2 as ITextFont2 ptr, byval fAddRef as boolean = false )Wraps an ITextFont2 pointer. With fAddRef false (the default) the object takes over the
reference you hand it, which is right for the result of GetFont, GetDuplicate or
DocumentFont; with true it adds a reference of its own and you keep yours.
A NULL pointer leaves the object empty with GetLastResult() returning E_INVALIDARG
(&h80070057). Only PropertyInfo and GetPropertyInfo check for
an empty object (they return E_POINTER); every other member calls through the pointer, so do
not use an empty one.
| Parameter | Meaning |
|---|---|
pTextFont2 |
The font interface. |
fAddRef |
true to add a reference; false to take over the caller's. |
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
if f.GetLastResult() = S_OK then print "font: "; f.NamedestructorReleases the ITextFont2 pointer, if there is one. It runs when the variable goes out of scope.
Example
scope
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Italic = tomTrue
end scope ' f, then rng, released herefunction GetDuplicate() as ITextFont2 ptr
function SetDuplicate( byval pFont as ITextFont2 ptr ) as HRESULT
property Duplicate() as ITextFont2 ptr
property Duplicate( byval pFont as ITextFont2 ptr )GetDuplicate (and reading Duplicate) returns a new font object holding a copy of this one's
formatting. The copy is not attached to any text: change it freely, compare it with
IsEqual, and apply it to a range later. The caller owns the returned pointer: wrap it
in a CTextFont2 or release it.
SetDuplicate (and assigning Duplicate) copies the formatting of pFont into this object;
attributes that are tomUndefined in pFont are left as they are. These members call the
ITextFont2 methods GetDuplicate2 and SetDuplicate2. On the rich edit control of current
Windows versions SetDuplicate2 returns E_NOTIMPL (&h80004001) and nothing changes; the
ITextFont method SetDuplicate, reached through m_pTextFont2, applies the copy.
| Parameter | Meaning |
|---|---|
pFont |
The font object to copy from. |
Returns GetDuplicate: the new font object, or NULL on failure. SetDuplicate: S_OK
on success, otherwise an error code.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
dim d as CTextFont2 = f.GetDuplicate()
d.Italic = tomTrue : d.Size = 16
f.m_pTextFont2->lpvtbl->SetDuplicate( f.m_pTextFont2, d.m_pTextFont2 ) ' applies bothMicrosoft Learn: ITextFont2::GetDuplicate2, ITextFont2::SetDuplicate2, ITextFont::SetDuplicate
function GetDuplicate2() as ITextFont2 ptr
function SetDuplicate2( byval pFont as ITextFont2 ptr ) as HRESULT
property Duplicate2() as ITextFont2 ptr
property Duplicate2( byval pFont as ITextFont2 ptr )The same calls as Duplicate, GetDuplicate, SetDuplicate,
under the names of the ITextFont2 methods they call. The returned pointer is the caller's to
release.
| Parameter | Meaning |
|---|---|
pFont |
The font object to copy from. |
Returns GetDuplicate2: the new font object, or NULL. SetDuplicate2: the HRESULT.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
dim d as CTextFont2 = f.GetDuplicate2()
print "copy of "; d.Name; ","; d.Size; " pt"Microsoft Learn: ITextFont2::GetDuplicate2, ITextFont2::SetDuplicate2
function CanChange() as longTells whether the formatting can be changed: it cannot when part of the attached text is protected or the document is read-only. A duplicate is not bound by those rules.
Returns tomTrue if the formatting can change, otherwise tomFalse.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
if f.CanChange() = tomTrue then f.Bold = tomTrueMicrosoft Learn: ITextFont::CanChange
function IsEqual( byval pFont as ITextFont2 ptr ) as longCompares this formatting with that of pFont. Attributes that are tomUndefined in either
object are not compared. A fresh duplicate compares equal to the object it was made from.
| Parameter | Meaning |
|---|---|
pFont |
The font object to compare with. |
Returns tomTrue if the two match, otherwise tomFalse.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
dim d as CTextFont2 = f.GetDuplicate()
print f.IsEqual( d.m_pTextFont2 ) ' -1Microsoft Learn: ITextFont::IsEqual
function IsEqual2( byval pFont as ITextFont2 ptr ) as longCompares this formatting with that of pFont through the ITextFont2 method, which also
compares the ITextFont2 attributes. On the rich edit control of current Windows versions the
method returns E_NOTIMPL (GetLastResult() is &h80004001) and the result is tomFalse;
use IsEqual there.
| Parameter | Meaning |
|---|---|
pFont |
The font object to compare with. |
Returns tomTrue if the two match, otherwise tomFalse.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
dim d as CTextFont2 = f.GetDuplicate()
dim eq as long = f.IsEqual2( d.m_pTextFont2 )
if f.GetLastResult() = E_NOTIMPL then eq = f.IsEqual( d.m_pTextFont2 )Microsoft Learn: ITextFont2::IsEqual2
function Reset( byval Value as long ) as HRESULTResets the formatting, or changes how the object applies changes, according to Value:
Value |
Effect |
|---|---|
tomDefault |
The document's default character format (for an attached object) or the TOM defaults. |
tomUndefined |
Every attribute undefined, so applying the object changes nothing. Only for a duplicate: an attached object returns E_INVALIDARG. |
tomApplyLater, tomApplyNow
|
Hold changes back, then apply them to the attached text. |
tomCacheParms, tomTrackParms
|
Stop or resume updating the object from the attached text. |
tomApplyTmp |
Apply temporary formatting. |
tomDisableSmartFont, tomEnableSmartFont
|
Turn smart font selection off or on. |
tomUsePoints, tomUseTwips
|
Floating-point measurements in points or in twips. |
Returns S_OK on success; S_FALSE when the text is protected; otherwise an error code.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Reset( tomDefault ) ' back to the document's default fontMicrosoft Learn: ITextFont::Reset
function GetStyle() as long
function SetStyle( byval Value as long ) as HRESULT
property Style() as long
property Style( byval Value as long )The character style handle of the text. The TOM does not define what the handles mean; text with no character style reads 0.
| Parameter | Meaning |
|---|---|
Value |
The style handle. |
Returns the handle, or the HRESULT for SetStyle.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
print "style"; f.StyleMicrosoft Learn: ITextFont::GetStyle, ITextFont::SetStyle
function GetAllCaps() as long
function SetAllCaps( byval Value as long ) as HRESULT
property AllCaps() as long
property AllCaps( byval Value as long )Whether the text is shown in capitals, whatever its case. The characters themselves do not change.
| Parameter | Meaning |
|---|---|
Value |
A tomBool: tomTrue, tomFalse, tomToggle or tomUndefined. |
Returns the tomBool, or the HRESULT for SetAllCaps.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.AllCaps = tomTrueMicrosoft Learn: ITextFont::GetAllCaps, ITextFont::SetAllCaps
function GetAnimation() as long
function SetAnimation( byval Value as long ) as HRESULT
property Animation() as long
property Animation( byval Value as long )The animation type: tomNoAnimation (0), tomLasVegasLights, tomBlinkingBackground,
tomSparkleText, tomMarchingBlackAnts, tomMarchingRedAnts, tomShimmer, tomWipeDown
or tomWipeRight.
| Parameter | Meaning |
|---|---|
Value |
The animation type. |
Returns the animation type, or the HRESULT for SetAnimation.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
if f.Animation <> tomNoAnimation then f.Animation = tomNoAnimationMicrosoft Learn: ITextFont::GetAnimation, ITextFont::SetAnimation
function GetBackColor() as long
function SetBackColor( byval Value as long ) as HRESULT
property BackColor( byval Value as long )
property BackColor() as longThe background (highlight) colour of the text: a COLORREF (make one with BGR( r, g, b )), a
palette index, or tomAutoColor for the control's background colour. Text that has no highlight
reads tomAutoColor (-9999997).
| Parameter | Meaning |
|---|---|
Value |
The colour, tomAutoColor, or tomUndefined to leave it. |
Returns the colour, or the HRESULT for SetBackColor.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.BackColor = BGR( 255, 255, 0 ) ' yellow highlightMicrosoft Learn: ITextFont::GetBackColor, ITextFont::SetBackColor
function GetBold() as long
function SetBold( byval Value as long ) as HRESULT
property Bold() as long
property Bold( byval Value as long )Whether the text is bold. Setting a Weight of 700 or more also
makes Bold read tomTrue.
| Parameter | Meaning |
|---|---|
Value |
A tomBool: tomTrue, tomFalse, tomToggle or tomUndefined. |
Returns the tomBool, or the HRESULT for SetBold.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Bold = tomToggleMicrosoft Learn: ITextFont::GetBold, ITextFont::SetBold
function GetEmboss() as long
function SetEmboss( byval Value as long ) as HRESULT
property Emboss() as long
property Emboss( byval Value as long ) as HRESULTWhether the text is embossed (raised).
Use GetEmboss and SetEmboss. The setter of the Emboss property is declared with a result,
and a procedure that both assigns and reads the Emboss property does not build.
| Parameter | Meaning |
|---|---|
Value |
A tomBool: tomTrue, tomFalse, tomToggle or tomUndefined. |
Returns the tomBool, or the HRESULT for SetEmboss.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.SetEmboss( tomTrue )
print "embossed"; f.GetEmboss()Microsoft Learn: ITextFont::GetEmboss, ITextFont::SetEmboss
function GetForeColor() as long
function SetForeColor( byval Value as long ) as HRESULT
property ForeColor() as long
property ForeColor( byval Value as long )The colour of the text: a COLORREF (BGR( r, g, b )), a palette index, or tomAutoColor for
the control's text colour.
| Parameter | Meaning |
|---|---|
Value |
The colour, tomAutoColor, or tomUndefined to leave it. |
Returns the colour, or the HRESULT for SetForeColor.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.ForeColor = BGR( 0, 0, 255 )
print hex( f.ForeColor ) ' FF0000Microsoft Learn: ITextFont::GetForeColor, ITextFont::SetForeColor
function GetHidden() as long
function SetHidden( byval Value as long ) as HRESULT
property Hidden() as long
property Hidden( byval Value as long )Whether the text is hidden. Hidden text stays in the document but is not shown.
| Parameter | Meaning |
|---|---|
Value |
A tomBool: tomTrue, tomFalse, tomToggle or tomUndefined. |
Returns the tomBool, or the HRESULT for SetHidden.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Hidden = tomTrueMicrosoft Learn: ITextFont::GetHidden, ITextFont::SetHidden
function GetEngrave() as long
function SetEngrave( byval Value as long ) as HRESULT
property Engrave() as long
property Engrave( byval Value as long )Whether the text is engraved (imprinted, pressed into the page).
| Parameter | Meaning |
|---|---|
Value |
A tomBool: tomTrue, tomFalse, tomToggle or tomUndefined. |
Returns the tomBool, or the HRESULT for SetEngrave.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Engrave = tomTrueMicrosoft Learn: ITextFont::GetEngrave, ITextFont::SetEngrave
function GetItalic() as long
function SetItalic( byval Value as long ) as HRESULT
property Italic() as long
property Italic( byval Value as long )Whether the text is italic.
| Parameter | Meaning |
|---|---|
Value |
A tomBool: tomTrue, tomFalse, tomToggle or tomUndefined. |
Returns the tomBool, or the HRESULT for SetItalic.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.SetItalic( tomToggle )Microsoft Learn: ITextFont::GetItalic, ITextFont::SetItalic
function GetKerning() as single
function SetKerning( byval Value as single ) as HRESULT
property Kerning() as single
property Kerning( byval Value as single )The smallest font size, in points, at which pairs of characters are kerned. 0 turns kerning off.
| Parameter | Meaning |
|---|---|
Value |
The size in points, or 0. |
Returns the size, or the HRESULT for SetKerning.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Kerning = 10 ' kern text of 10 pt and largerMicrosoft Learn: ITextFont::GetKerning, ITextFont::SetKerning
function GetLanguageID() as long
function SetLanguageID( byval Value as long ) as HRESULT
property LanguageID() as long
property LanguageID( byval Value as long )The language of the text, as a locale identifier (LCID): 1033 is English (United States), 1036 French (France). The spelling checker and the choice of fonts follow it.
| Parameter | Meaning |
|---|---|
Value |
The LCID. |
Returns the LCID, or the HRESULT for SetLanguageID.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.LanguageID = 1036Microsoft Learn: ITextFont::GetLanguageID, ITextFont::SetLanguageID
function GetName() as ustring
function SetName( byref wszFontName as wstring ) as HRESULT
property Name() as ustring
property Name( byref dwsFontName as ustring )The name of the font, such as "Arial". The text is passed to and from the interface as a
BSTR, which the members allocate and free themselves.
| Parameter | Meaning |
|---|---|
wszFontName, dwsFontName
|
The font name. |
Returns the name, or the HRESULT for SetName.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Name = "Courier New"
print f.GetName() ' Courier NewMicrosoft Learn: ITextFont::GetName, ITextFont::SetName
function GetOutline() as long
function SetOutline( byval Value as long ) as HRESULT
property Outline() as long
property Outline( byval Value as long )Whether the text is drawn as outlines.
| Parameter | Meaning |
|---|---|
Value |
A tomBool: tomTrue, tomFalse, tomToggle or tomUndefined. |
Returns the tomBool, or the HRESULT for SetOutline.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Outline = tomTrueMicrosoft Learn: ITextFont::GetOutline, ITextFont::SetOutline
function GetPosition() as single
function SetPosition( byval Value as single ) as HRESULT
property Position() as single
property Position( byval Value as single )How far the text is raised above the baseline, in points; a negative value lowers it. Unlike Superscript, the size of the text does not change.
| Parameter | Meaning |
|---|---|
Value |
The offset in points. |
Returns the offset, or the HRESULT for SetPosition.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Position = 3 ' 3 pt upMicrosoft Learn: ITextFont::GetPosition, ITextFont::SetPosition
function GetProtected() as long
function SetProtected( byval Value as long ) as HRESULT
property Protected_() as long
property Protected_( byval Value as long )Whether the text is protected. When the user tries to change protected text, the control sends
its parent an EN_PROTECTED notification (if ENM_PROTECTED is in its event mask), and the
parent decides whether to allow the change. The property is Protected_ because protected is
a keyword.
| Parameter | Meaning |
|---|---|
Value |
A tomBool: tomTrue, tomFalse, tomToggle or tomUndefined. |
Returns the tomBool, or the HRESULT for SetProtected.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Protected_ = tomTrueMicrosoft Learn: ITextFont::GetProtected, ITextFont::SetProtected
function GetShadow() as long
function SetShadow( byval Value as long ) as HRESULT
property Shadow() as long
property Shadow( byval Value as long )Whether the text has a shadow.
| Parameter | Meaning |
|---|---|
Value |
A tomBool: tomTrue, tomFalse, tomToggle or tomUndefined. |
Returns the tomBool, or the HRESULT for SetShadow.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Shadow = tomTrueMicrosoft Learn: ITextFont::GetShadow, ITextFont::SetShadow
function GetSize() as single
function SetSize( byval Value as single ) as HRESULT
property Size() as single
property Size( byval Value as single )The font size in points. A range that mixes sizes reads tomUndefined (-9999999).
| Parameter | Meaning |
|---|---|
Value |
The size in points. |
Returns the size, or the HRESULT for SetSize.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Size = f.Size + 2Microsoft Learn: ITextFont::GetSize, ITextFont::SetSize
function GetSmallCaps() as long
function SetSmallCaps( byval Value as long ) as HRESULT
property SmallCaps() as long
property SmallCaps( byval Value as long )Whether lower-case letters are shown as small capitals.
| Parameter | Meaning |
|---|---|
Value |
A tomBool: tomTrue, tomFalse, tomToggle or tomUndefined. |
Returns the tomBool, or the HRESULT for SetSmallCaps.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.SmallCaps = tomTrueMicrosoft Learn: ITextFont::GetSmallCaps, ITextFont::SetSmallCaps
function GetSpacing() as single
function SetSpacing( byval Value as single ) as HRESULT
property Spacing() as single
property Spacing( byval Value as single )Extra horizontal space between characters, in points; a negative value condenses the text.
| Parameter | Meaning |
|---|---|
Value |
The extra space in points. |
Returns the spacing, or the HRESULT for SetSpacing.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Spacing = 2Microsoft Learn: ITextFont::GetSpacing, ITextFont::SetSpacing
function GetStrikeThrough() as long
function SetStrikeThrough( byval Value as long ) as HRESULT
property StrikeThrough() as long
property StrikeThrough( byval Value as long )Whether a horizontal line runs through the middle of the text.
| Parameter | Meaning |
|---|---|
Value |
A tomBool: tomTrue, tomFalse, tomToggle or tomUndefined. |
Returns the tomBool, or the HRESULT for SetStrikeThrough.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.StrikeThrough = tomTrueMicrosoft Learn: ITextFont::GetStrikeThrough, ITextFont::SetStrikeThrough
function GetSubscript() as long
function SetSubscript( byval Value as long ) as HRESULT
property Subscript() as long
property Subscript( byval Value as long )Whether the text is subscript: smaller and lowered. Setting it turns Superscript off.
| Parameter | Meaning |
|---|---|
Value |
A tomBool: tomTrue, tomFalse, tomToggle or tomUndefined. |
Returns the tomBool, or the HRESULT for SetSubscript.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 1, 2 )
dim f as CTextFont2 = rng.GetFont()
f.Subscript = tomTrue ' the second character, as in H2OMicrosoft Learn: ITextFont::GetSubscript, ITextFont::SetSubscript
function GetSuperscript() as long
function SetSuperscript( byval Value as long ) as HRESULT
property Superscript() as long
property Superscript( byval Value as long )Whether the text is superscript: smaller and raised. Setting it turns Subscript off.
| Parameter | Meaning |
|---|---|
Value |
A tomBool: tomTrue, tomFalse, tomToggle or tomUndefined. |
Returns the tomBool, or the HRESULT for SetSuperscript.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 4, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Superscript = tomTrueMicrosoft Learn: ITextFont::GetSuperscript, ITextFont::SetSuperscript
function GetUnderline() as long
function SetUnderline( byval Value as long ) as HRESULT
property Underline() as long
property Underline( byval Value as long )The type of underline: tomNone (0), tomSingle, tomWords, tomDouble, tomDotted,
tomDash, tomWave, tomThick, tomHair and the other tom* underline styles, or
tomToggle and tomUndefined as for a tomBool.
| Parameter | Meaning |
|---|---|
Value |
The underline type. |
Returns the underline type, or the HRESULT for SetUnderline.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Underline = tomWaveMicrosoft Learn: ITextFont::GetUnderline, ITextFont::SetUnderline
function GetWeight() as long
function SetWeight( byval Value as long ) as HRESULT
property Weight() as long
property Weight( byval Value as long )The font weight, from 1 to 1000 as for LOGFONTW: 400 is normal and 700 bold (FW_NORMAL,
FW_BOLD).
| Parameter | Meaning |
|---|---|
Value |
The weight. |
Returns the weight, or the HRESULT for SetWeight.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Weight = FW_SEMIBOLDMicrosoft Learn: ITextFont::GetWeight, ITextFont::SetWeight
function GetCount() as long
function Count() as longThe number of extra properties in the formatting, the ones PropertyInfo enumerates. Text with plain formatting has none.
Returns the count.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
print "extra properties:"; f.Count() ' 0Microsoft Learn: ITextFont2::GetCount
function GetAutoLigatures() as long
function SetAutoLigatures( byval Value as long ) as HRESULT
property AutoLigatures() as long
property AutoLigatures( byval Value as long )Whether the font's ligatures (such as "fi" drawn as one glyph) are used automatically.
| Parameter | Meaning |
|---|---|
Value |
A tomBool. |
Returns the tomBool, or the HRESULT for SetAutoLigatures.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.AutoLigatures = tomTrueMicrosoft Learn: ITextFont2::GetAutoLigatures, ITextFont2::SetAutoLigatures
function GetAutospaceAlpha() as long
function SetAutospaceAlpha( byval Value as long ) as HRESULT
property AutospaceAlpha() as long
property AutospaceAlpha( byval Value as long )The East Asian "autospace alphabetics" setting: extra space between East Asian and Latin text.
| Parameter | Meaning |
|---|---|
Value |
A tomBool. |
Returns the tomBool, or the HRESULT for SetAutospaceAlpha.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.AutospaceAlpha = tomTrueMicrosoft Learn: ITextFont2::GetAutospaceAlpha, ITextFont2::SetAutospaceAlpha
function GetAutospaceNumeric() as long
function SetAutospaceNumeric( byval Value as long ) as HRESULT
property AutospaceNumeric() as long
property AutospaceNumeric( byval Value as long )The East Asian "autospace numeric" setting: extra space between East Asian text and digits.
| Parameter | Meaning |
|---|---|
Value |
A tomBool. |
Returns the tomBool, or the HRESULT for SetAutospaceNumeric.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.AutospaceNumeric = tomTrueMicrosoft Learn: ITextFont2::GetAutospaceNumeric, ITextFont2::SetAutospaceNumeric
function GetAutospaceParens() as long
function SetAutospaceParens( byval Value as long ) as HRESULT
property AutospaceParens() as long
property AutospaceParens( byval Value as long )The East Asian "autospace parentheses" setting: adjusted space around parentheses.
| Parameter | Meaning |
|---|---|
Value |
A tomBool. |
Returns the tomBool, or the HRESULT for SetAutospaceParens.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.AutospaceParens = tomTrueMicrosoft Learn: ITextFont2::GetAutospaceParens, ITextFont2::SetAutospaceParens
function GetCharRep() as long
function SetCharRep( byval Value as long ) as HRESULT
property CharRep() as long
property CharRep( byval Value as long )The character repertoire, the writing system the font is chosen for: tomAnsi (0, Latin),
tomEastEurope, tomCyrillic, tomGreek, tomHebrew, tomArabic and the other tom*
repertoires up to tomCharRepMax.
| Parameter | Meaning |
|---|---|
Value |
The repertoire. |
Returns the repertoire, or the HRESULT for SetCharRep.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.CharRep = tomGreekMicrosoft Learn: ITextFont2::GetCharRep, ITextFont2::SetCharRep
function GetCompressionMode() as long
function SetCompressionMode( byval Value as long = tomCompressNone ) as HRESULT
property CompressionMode() as long
property CompressionMode( byval Value as long )The East Asian compression mode: tomCompressNone (0, the default of SetCompressionMode),
tomCompressPunctuation or tomCompressPunctuationAndKana. On the control CRichEditCtx
creates, reading it returns tomUndefined.
| Parameter | Meaning |
|---|---|
Value |
The compression mode. |
Returns the mode, or the HRESULT for SetCompressionMode.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.SetCompressionMode( tomCompressPunctuation )Microsoft Learn: ITextFont2::GetCompressionMode, ITextFont2::SetCompressionMode
function GetCookie() as long
function SetCookie( byval Value as long ) as HRESULT
property Cookie() as long
property Cookie( byval Value as long )A 32-bit value of your own kept with the character formatting. The control does not use it.
| Parameter | Meaning |
|---|---|
Value |
The value to store. |
Returns the value, or the HRESULT for SetCookie.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Cookie = 42
print f.Cookie ' 42Microsoft Learn: ITextFont2::GetCookie, ITextFont2::SetCookie
function GetDoubleStrike() as long
function SetDoubleStrike( byval Value as long ) as HRESULT
property DoubleStrike() as long
property DoubleStrike( byval Value as long )Whether two horizontal lines run through the middle of the text.
| Parameter | Meaning |
|---|---|
Value |
A tomBool. |
Returns the tomBool, or the HRESULT for SetDoubleStrike.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.DoubleStrike = tomTrueMicrosoft Learn: ITextFont2::GetDoubleStrike, ITextFont2::SetDoubleStrike
function GetLinkType() as long
function LinkType() as longThe kind of link the text belongs to: tomNoLink (0), tomClientLink, tomFriendlyLinkName,
tomFriendlyLinkAddress, tomAutoLinkURL, tomAutoLinkEmail, tomAutoLinkPhone or
tomAutoLinkPath. It is read-only.
Returns the link type.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
if f.LinkType() = tomAutoLinkURL then print "a URL"Microsoft Learn: ITextFont2::GetLinkType
function GetMathZone() as long
function SetMathZone( byval Value as long ) as HRESULT
property MathZone() as long
property MathZone( byval Value as long )Whether the text is a math zone, laid out as mathematics.
| Parameter | Meaning |
|---|---|
Value |
A tomBool. |
Returns the tomBool, or the HRESULT for SetMathZone.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
print "math zone"; f.MathZoneMicrosoft Learn: ITextFont2::GetMathZone, ITextFont2::SetMathZone
function GetModWidthPairs() as long
function SetModWidthPairs( byval Value as long ) as HRESULT
property ModWidthPairs() as long
property ModWidthPairs( byval Value as long )The "decrease widths on pairs" setting: narrower spacing for certain pairs of East Asian characters.
| Parameter | Meaning |
|---|---|
Value |
A tomBool. |
Returns the tomBool, or the HRESULT for SetModWidthPairs.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.ModWidthPairs = tomTrueMicrosoft Learn: ITextFont2::GetModWidthPairs, ITextFont2::SetModWidthPairs
function GetModWidthSpace() as long
function SetModWidthSpace( byval Value as long ) as HRESULT
property ModWidthSpace() as long
property ModWidthSpace( byval Value as long )The "increase width of white space" setting.
| Parameter | Meaning |
|---|---|
Value |
A tomBool. |
Returns the tomBool, or the HRESULT for SetModWidthSpace.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.ModWidthSpace = tomTrueMicrosoft Learn: ITextFont2::GetModWidthSpace, ITextFont2::SetModWidthSpace
function GetOldNumbers() as long
function SetOldNumbers( byval Value as long ) as HRESULT
property OldNumbers() as long
property OldNumbers( byval Value as long )Whether digits use the font's old-style (text) figures, which rise and descend like lower-case letters.
| Parameter | Meaning |
|---|---|
Value |
A tomBool. |
Returns the tomBool, or the HRESULT for SetOldNumbers.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.OldNumbers = tomTrueMicrosoft Learn: ITextFont2::GetOldNumbers, ITextFont2::SetOldNumbers
function GetOverlapping() as long
function SetOverlapping( byval Value as long ) as HRESULT
property Overlapping() as long
property Overlapping( byval Value as long )Whether overlapping text is active.
| Parameter | Meaning |
|---|---|
Value |
A tomBool. |
Returns the tomBool, or the HRESULT for SetOverlapping.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Overlapping = tomTrueMicrosoft Learn: ITextFont2::GetOverlapping, ITextFont2::SetOverlapping
function GetPositionSubSuper() as long
function SetPositionSubSuper( byval Value as long ) as HRESULT
property PositionSubSuper() as long
property PositionSubSuper( byval Value as long )How far subscript or superscript text sits from the baseline, as a percentage of the font height.
| Parameter | Meaning |
|---|---|
Value |
The offset in percent. |
Returns the offset, or the HRESULT for SetPositionSubSuper.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 4, 5 )
dim f as CTextFont2 = rng.GetFont()
f.Superscript = tomTrue
f.PositionSubSuper = 30Microsoft Learn: ITextFont2::GetPositionSubSuper, ITextFont2::SetPositionSubSuper
function GetScaling() as long
function SetScaling( byval Value as long ) as HRESULT
property Scaling() as long
property Scaling( byval Value as long )The horizontal scaling of the text, in percent: 100 is normal width. On the control
CRichEditCtx creates, reading it returns tomUndefined, and setting it returns S_OK without
changing what is read back.
| Parameter | Meaning |
|---|---|
Value |
The scaling in percent. |
Returns the scaling, or the HRESULT for SetScaling.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.SetScaling( 150 )Microsoft Learn: ITextFont2::GetScaling, ITextFont2::SetScaling
function GetSpaceExtension() as long
function SetSpaceExtension( byval Value as long ) as HRESULT
property SpaceExtension() as long
property SpaceExtension( byval Value as long )The East Asian space extension value.
| Parameter | Meaning |
|---|---|
Value |
The space extension. |
Returns the value, or the HRESULT for SetSpaceExtension.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
print "space extension"; f.SpaceExtensionMicrosoft Learn: ITextFont2::GetSpaceExtension, ITextFont2::SetSpaceExtension
function GetUnderlinePositionMode() as long
function SetUnderlinePositionMode( byval Value as long = tomUnderlinePositionAuto ) as HRESULT
property UnderlinePositionMode() as long
property UnderlinePositionMode( byval Value as long )Where the underline is drawn: tomUnderlinePositionAuto (0, the default of
SetUnderlinePositionMode), tomUnderlinePositionBelow or tomUnderlinePositionAbove. On the
control CRichEditCtx creates, reading it returns tomUndefined, and setting it returns S_OK
without changing what is read back.
| Parameter | Meaning |
|---|---|
Value |
The position mode. |
Returns the mode, or the HRESULT for SetUnderlinePositionMode.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.SetUnderlinePositionMode( tomUnderlinePositionBelow )Microsoft Learn: ITextFont2::GetUnderlinePositionMode, ITextFont2::SetUnderlinePositionMode
function GetEffects( byref Value as long, byref Mask as long ) as HRESULT
function SetEffects( byval Value as long, byval Mask as long ) as HRESULTReads or sets several on/off attributes in one call, as bits: tomBold, tomItalic,
tomUnderline, tomStrikeout, tomProtected, tomLink, tomSmallCaps, tomAllCaps,
tomHidden, tomOutline, tomShadow, tomEmboss, tomImprint, tomSubscriptCF,
tomSuperscriptCF and the other tom* effect flags. Mask says which bits count: for
GetEffects it receives the bits whose value is the same throughout the text, for SetEffects
it names the bits to change.
| Parameter | Meaning |
|---|---|
Value |
The effect bits (received by GetEffects). |
Mask |
Which bits are defined (GetEffects) or to change (SetEffects). |
Returns S_OK on success, otherwise an error code.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.SetEffects( tomBold or tomItalic, tomBold or tomItalic ) ' both on
dim as long v, m
f.GetEffects( v, m )Microsoft Learn: ITextFont2::GetEffects, ITextFont2::SetEffects
function GetEffects2( byref Value as long, byref Mask as long ) as HRESULT
function SetEffects2( byval Value as long, byval Mask as long ) as HRESULTThe same for the ITextFont2 attributes: tomModWidthPairs, tomModWidthSpace,
tomAutoSpaceAlpha, tomAutoSpaceNumeric, tomAutoSpaceParens, tomEmbeddedFont,
tomDoublestrike and tomOverlapping. GetEffects2 works on the rich edit control of current
Windows versions; SetEffects2 returns E_NOTIMPL (&h80004001) there, so set these one at a
time with their own properties.
| Parameter | Meaning |
|---|---|
Value |
The effect bits (received by GetEffects2). |
Mask |
Which bits are defined (GetEffects2) or to change (SetEffects2). |
Returns S_OK on success, otherwise an error code.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
dim as long v, m
if f.GetEffects2( v, m ) = S_OK andalso ( m and tomDoublestrike ) then print "double strike:"; ( v and tomDoublestrike ) <> 0Microsoft Learn: ITextFont2::GetEffects2, ITextFont2::SetEffects2
function GetProperty( byval nType as long ) as long
function SetProperty( byval nType as long, byval Value as long ) as HRESULT
property Property_( byval nType as long ) as long
property Property_( byval nType as long, byval Value as long )Reads or sets an extra property by its id: tomFontStretch, tomFontStyle, tomFontPropAlign,
tomFontPropTeXStyle and the other tomFont* ids. The property is Property_ because
property is a keyword.
| Parameter | Meaning |
|---|---|
nType |
The property id. |
Value |
The new value. |
Returns the value, or the HRESULT for SetProperty.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
f.SetProperty( tomFontStretch, 3 )
print f.GetProperty( tomFontStretch ) ' 3Microsoft Learn: ITextFont2::GetProperty, ITextFont2::SetProperty
function GetPropertyInfo( byval Index as long, byval pType as long ptr, byval pValue as long ptr ) as HRESULT
function PropertyInfo( byval Index as long, byval pType as long ptr, byval pValue as long ptr ) as HRESULTReads the id and value of the extra property at Index (0 to Count - 1).
These are the only members that check for an empty object: then they return E_POINTER. On the
rich edit control of current Windows versions the method returns E_NOTIMPL (&h80004001).
| Parameter | Meaning |
|---|---|
Index |
The index of the property. |
pType |
Receives the property id. |
pValue |
Receives the value. |
Returns S_OK on success, otherwise an error code.
Example
dim rng as CTextRange2 = CRichEditCtxPtr( hCtrl )->Range( 0, 5 )
dim f as CTextFont2 = rng.GetFont()
dim as long id, v
for i as long = 0 to f.Count() - 1
if f.GetPropertyInfo( i, @id, @v ) = S_OK then print hex( id ); " ="; v
nextMicrosoft Learn: ITextFont2::GetPropertyInfo
- sys/win/richedit
- CTextRange2 and CTextSelection2, where a font object comes from
- CTextPara2 for paragraph formatting
- CRichEditCtx: document for the document's default font
- Text Object Model
-
Colours for ready-made
COLORREFvalues
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing