我的测试背景是Win7+VS2010+AutoCAD2008,根据文中提供的方法,到控制面板的字体中找到“宋体”的文件名是simsun.ttc,但是按照下面的代码却没有成功地生成字体样式:
Dim str As New TextStyleTableRecord()
str.Name = "TextStyle-宋体-横向"
str.FileName = "simsun.ttc"
我猜是不是应该为“simsun.ttf”,结果运行后字体名显示为“SimSun-ExtB”,也失败了。那到底是什么啊?
'创建文字样式
Public Shared Function CreateStyle(ByVal textstyleName As String, ByVal font1 As String, ByVal bigfont As String, ByVal anger As Double, ByVal textwidth As Double) As ObjectId
Dim db As Database = HostApplicationServices.WorkingDatabase
Using trans As Transaction = db.TransactionManager.StartTransaction
' 得到文字样式表
Dim st As TextStyleTable = trans.GetObject(db.TextStyleTableId, OpenMode.ForWrite)
Dim StyleName As String = textstyleName
' 如果名为"工程图"的文字样式不存在,则新建一个文字样式.
If st.Has(StyleName) = True Then
'Dim TextstyleId As ObjectId = st(StyleName)
db.Textstyle = st(StyleName)
trans.Commit()
End If
If st.Has(StyleName) = False Then
' 新建一个文字样式表记录.
Dim str As New TextStyleTableRecord()
' 设置文字样式名.
str.Name = StyleName
' 设置TrueType字体(仿宋体)
If Right(font1, 3) = "ttf" Or Right(font1, 3) = "TTC" Or font1 = "宋体" Then
str.FileName = font1
Else
' 设置SHX字体
str.FileName = font1
' 设置大字体.
str.BigFontFileName = bigfont
End If
' 设置倾斜角(弧度).
str.ObliquingAngle = anger * Math.PI / 180
' 设置宽度比例.
str.XScale = textwidth
' 把文字样式表记录添加到文字样式表中.
Dim TextstyleId As ObjectId = st.Add(str)
' 把文字样式表记录添加到事务处理中.
trans.AddNewlyCreatedDBObject(str, True)
' 将文字样式"工程图"设置为当前文字样式
db.Textstyle = TextstyleId
trans.Commit()
End If
End Using
End Function
Dim st As TextStyleTable = trans.GetObject(db.TextStyleTableId, OpenMode.ForWrite)
我的怎么只能用读的方式打开呢,用写报错啊!
"Autodesk.AutoCAD.Runtime.Exception"的异常
cad2005 & vs2008
new Autodesk.AutoCAD.GraphicsInterface.FontDescriptor("宋体",false,false,0,34)里面的参数“34”为“the pitch and family attributes”,设置字体间距与Family(字符集?),34指的是DefaultPitch吧?