public static ObjectId SetFontStyle(string strTextStyleName)
{
ObjectId objID; //文字样式表的样式
Database m_db = HostApplicationServices.WorkingDatabase;
DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
using (Transaction m_tr = m_db.TransactionManager.StartTransaction())
{
TextStyleTable tst = (TextStyleTable)m_tr.GetObject(m_db.TextStyleTableId, OpenMode.ForWrite);
if(tst.Has(strTextStyleName))
{
objID = tst[strTextStyleName];
TextStyleTableRecord tstr = (TextStyleTableRecord)m_tr.GetObject(objID, OpenMode.ForWrite);
string str1 = tstr.BigFontFileName;
string str2 = tstr.FileName;
}
else
{
TextStyleTableRecord tstr = new TextStyleTableRecord();
tstr.Name = strTextStyleName;
tstr.BigFontFileName = "gbcbig.shx";
//tstr.FileName = "SimSun.ttf";//字体名
tstr.FileName = "gbenor.shx";//字体名
//Returns with file name pointing to a copy of the name of the font file for this text style
//返回一个指向文字文件名称的拷贝的名称,用于文字样式
tstr.TextSize = 200;
tst.Add(tstr);
m_tr.AddNewlyCreatedDBObject(tstr, true);
m_tr.Commit();
objID = tst[strTextStyleName];
m_db.Textstyle = objID;
}
}
docLock.Dispose();
return objID;
}