GetFont Method (ActiveX)

Gets the definition data of the font for the TextStyle.

Supported platforms: Windows only

Signature

VBA:

object.GetFont Typeface, Bold, Italic, CharSet, PitchAndFamily
object

Type: TextStyle

The object this method applies to.

Typeface

Access: Output-only

Type: String

The typeface (font name) of the TextStyle you queried.

Bold

Access: Output-only

Type: Boolean

Specifies if the TextStyle is bold.

  • True: The TextStyle is bold.
  • False: The TextStyle is not bold.
Italic

Access: Output-only

Type: Boolean

Specifies if the TextStyle is italic.

  • True: The TextStyle is italic.
  • False: The TextStyle is not italic.
CharSet

Access: Output-only

Type: Long

The character set for the font. (See the available values in the Remarks section.)

PitchAndFamily

Access: Output-only

Type: Long

The pitch and family definitions for the font. (See the available values in the Remarks section.)

Return Value (RetVal)

No return value.

Remarks

This section provides definitions for constants to use with this method. To use these constants, copy the definitions you need and paste them into the Declarations section of your application. A complete list of the constants that are available from Microsoft can be found in the file win32api.txt, which is provided with the Visual Basic Development Environment.

The CharSet parameter specifies the character set for the font. To use the following constants in your VB or VBA application, copy the definitions into the Declaration section of your code.

Public Const ANSI_CHARSET = 0
Public Const DEFAULT_CHARSET = 1
Public Const SYMBOL_CHARSET = 2
Public Const SHIFTJIS_CHARSET = 128
Public Const OEM_CHARSET = 255

The PitchAndFamily parameter specifies the pitch and family values for the font. The value is determined by a combination of three different settings. By choosing a setting from each of the three categories and using the Boolean operator OR to combine them, you achieve the PitchAndFamily value. A setting is required from the first two categories: the pitch and the family. The third category, the TrueType Flag, is used only when you are specifying a TrueType font.

' Pitch Values
Public Const DEFAULT_PITCH = 0
Public Const FIXED_PITCH = 1
Public Const VARIABLE_PITCH = 2


' Family Values
Public Const FF_DONTCARE = 0    '  Don't care or don't know.
Public Const FF_ROMAN = 16      '  Variable stroke width, serifed.
Public Const FF_SWISS = 32      '  Variable stroke width, sans-serifed.
Public Const FF_MODERN = 48     '  Constant stroke width, serifed or sans-serifed.
Public Const FF_SCRIPT = 64     '  Cursive, etc.
Public Const FF_DECORATIVE = 80 '  Old English, etc.


' TrueType Flag
Public Const TMPF_TRUETYPE = &H4

Examples

VBA:

Sub Example_GetFont()
    ' This example find the font information for the active text style.
    
    Dim typeFace As String
    Dim Bold As Boolean
    Dim Italic As Boolean
    Dim charSet As Long
    Dim PitchandFamily As Long
    
    ThisDrawing.ActiveTextStyle.GetFont typeFace, Bold, Italic, charSet, PitchandFamily
    
    MsgBox "The current text style has the following font properties:" & vbCrLf _
            & "Typeface: " & typeFace & vbCrLf _
            & "Bold: " & Bold & vbCrLf _
            & "Italic: " & Italic & vbCrLf _
            & "Character set: " & charSet & vbCrLf _
            & "Pitch and Family: " & PitchandFamily
    
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_GetFont()
    ;; This example finds the font information for the active text style.
    ;; It then changes the font to bold.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))

    (vla-GetFont (vla-get-ActiveTextStyle doc) 'typeFace 'Bold 'Italic 'charSet 'PitchandFamily)
    
    (alert (strcat "The current text style has the following font properties:"
                   "\nTypeface: " typeFace
                   "\nBold: " (if (= Bold :vlax-true) "True" "False")
                   "\nItalic: " (if (= Italic :vlax-true) "True" "False")
                   "\nCharacter set: " (itoa charSet)
                   "\nPitch and Family: " (itoa PitchandFamily)))
            
    ;; Change the bold property
    (setq Bold (if (= Bold :vlax-true) :vlax-false :vlax-true))

    (vla-SetFont (vla-get-ActiveTextStyle doc) typeFace Bold Italic charSet PitchandFamily)
  
    (alert (strcat "The current text style has the following font properties:"
                   "\nTypeface: " typeFace
                   "\nBold: " (if (= Bold :vlax-true) "True" "False")
                   "\nItalic: " (if (= Italic :vlax-true) "True" "False")
                   "\nCharacter set: " (itoa charSet)
                   "\nPitch and Family: " (itoa PitchandFamily)))
            
    ;; Reset the font
    (setq Bold (if (= Bold :vlax-true) :vlax-false :vlax-true))
    (vla-SetFont (vla-get-ActiveTextStyle doc) typeFace Bold Italic charSet PitchandFamily)
)