フォントにより、それぞれの文字セットを構成する文字の形状が定義されます。1 つのフォントは、複数のスタイルで使用できます。文字スタイルにフォント ファイルを設定するには、FileName プロパティを使用します。TrueType フォントまたは AutoCAD でコンパイル済みの SHX フォントを文字スタイルに割り当てることができます。
次の例は、アクティブな文字スタイルの Font プロパティを使用して現在のフォントの値を取得し、フォントの書体を「PlayBill」に変更します。書体の変更の効果を確認するには、現在の図面にマルチ テキストか 1 行文字をいくつか記入してから、この例を実行してください。フォント 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
'' 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;
// 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();
}
}
Sub UpdateTextFont()
MsgBox ("Look at the text now...")
Dim typeFace As String
Dim SavetypeFace As String
Dim Bold As Boolean
Dim Italic As Boolean
Dim charSet As Long
Dim PitchandFamily As Long
' Get the current settings to fill in the
' default values for the SetFont method
ThisDrawing.ActiveTextStyle.GetFont typeFace, _
Bold, Italic, charSet, PitchandFamily
' Change the typeface for the font
SavetypeFace = typeFace
typeFace = "PlayBill"
ThisDrawing.ActiveTextStyle.SetFont typeFace, _
Bold, Italic, charSet, PitchandFamily
ThisDrawing.Regen acActiveViewport
End Sub