Fonts define the shapes of the text characters that make up each character set. A single font can be used by more than one style. Use the FileName property to set the font file for the text style. You can assign TrueType or AutoCAD-compiled SHX fonts to a text style.
字体定义了构成每个字符集的文字字符的形状。一种字体可以被多个样式使用。使用 FileName 属性设置文字样式的字体文件。通过输入 TrueType 或 AutoCAD 编译的 SHX 字体给文字样式。
The following example gets the current font values using the Font property for the active text style and then changes the typeface for the font to “PlayBill.” To see the effects of changing the typeface, add some multiline or single-line text to your current drawing before running the example. Note that, if you don't have the PlayBill font on your system, you need to substitute a font you do have in order for this example to work.
本例利用 Font 属性获取活动文字样式的当前字体值,并随后将该字体更改为“PlayBill”。要查看字体更改的效果,请在运行样例之前,向当前图形中添加一些多行文字或单行文字。注意,如果系统上没有 PlayBill 字体,则需要将其替换为一种已有的字体以使本例有效。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
<CommandMethod("UpdateTextFont")> _
Public Sub UpdateTextFont()
'' 获得当前文档和数据库 Get the current document and database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
''启动一个事务 Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' 以写的方式打开当前文字样式 Open the current text style for write
Dim acTextStyleTblRec As TextStyleTableRecord
acTextStyleTblRec = acTrans.GetObject(acCurDb.Textstyle, _
OpenMode.ForWrite)
'' 获得当前的字体设置 Get the current font settings
Dim acFont As Autodesk.AutoCAD.GraphicsInterface.FontDescriptor
acFont = acTextStyleTblRec.Font
'' 用“PlayBill”更新文字样式的字体 Update the text style's typeface with "PlayBill"
Dim acNewFont As Autodesk.AutoCAD.GraphicsInterface.FontDescriptor
acNewFont = New _
Autodesk.AutoCAD.GraphicsInterface.FontDescriptor("PlayBill", _
acFont.Bold, _
acFont.Italic, _
acFont.CharacterSet, _
acFont.PitchAndFamily)
acTextStyleTblRec.Font = acNewFont
acDoc.Editor.Regen()
''保存更改并销毁事务 Save the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
[CommandMethod("UpdateTextFont")]
public static void UpdateTextFont()
{
// 获得当前文档和数据库 Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// 启动一个事务 Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// 以写的方式打开当前文字样式 Open the current text style for write
TextStyleTableRecord acTextStyleTblRec;
acTextStyleTblRec = acTrans.GetObject(acCurDb.Textstyle,
OpenMode.ForWrite) as TextStyleTableRecord;
// 获得当前的字体设置 Get the current font settings
Autodesk.AutoCAD.GraphicsInterface.FontDescriptor acFont;
acFont = acTextStyleTblRec.Font;
// 用“PlayBill”更新文字样式的字体 Update the text style's typeface with "PlayBill"
Autodesk.AutoCAD.GraphicsInterface.FontDescriptor acNewFont;
acNewFont = new
Autodesk.AutoCAD.GraphicsInterface.FontDescriptor("PlayBill",
acFont.Bold,
acFont.Italic,
acFont.CharacterSet,
acFont.PitchAndFamily);
acTextStyleTblRec.Font = acNewFont;
acDoc.Editor.Regen();
// Save the changes and dispose of the transaction
acTrans.Commit();
}
}