CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2024 开发者帮助

GetFont 方法 (ActiveX)

2024-5-18 19:07| 发布者: admin| 查看: 131| 评论: 0|原作者: admin|来自: AutoCAD

GetFont 方法 (ActiveX)

获取 TextStyle 字体的定义数据。

支持的平台:仅限 Windows

签名

VBA:

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

类型:TextStyle

此方法应用到的对象。

字体

访问:仅输出

类型:字符串

您查询的字体(字体名称)。TextStyle

大胆

访问:仅输出

类型:布尔

指定 是否为粗体。TextStyle

  • True:粗体。TextStyle
  • False:不粗体。TextStyle
斜体的

访问:仅输出

类型:布尔

指定是否为斜体。TextStyle

  • True:为斜体。TextStyle
  • False:不是斜体。TextStyle
字符集

访问:仅输出

类型:

字体的字符集。(请参阅“备注”部分中的可用值。

PitchAndFamily(音高与家庭公寓)

访问:仅输出

类型:

字体的音高和系列定义。(请参阅“备注”部分中的可用值。

返回值 (RetVal)

无返回值。

言论

本部分提供用于此方法的常量的定义。若要使用这些常量,请复制所需的定义,并将其粘贴到应用程序的“声明”部分。可以在 Visual Basic 开发环境随附的文件win32api.txt中找到 Microsoft 中可用的常量的完整列表。

CharSet 参数指定字体的字符集。若要在 VB 或 VBA 应用程序中使用以下常量,请将定义复制到代码的“声明”部分。

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

PitchAndFamily 参数指定字体的音高和族值。该值由三种不同设置的组合确定。通过从三个类别中的每一个类别中选择一个设置并使用布尔运算符 OR 组合它们,您可以获得 PitchAndFamily 值。前两个类别需要设置:音高和家庭。第三类是 TrueType 标志,仅在指定 TrueType 字体时使用。

' 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

例子

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

可视化 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)
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1   苏公网安备32011402011833)

GMT+8, 2024-12-15 11:26

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部