cad.net 两台电脑的宋体居然不一样 cad宋体问号
Posted jjbox
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cad.net 两台电脑的宋体居然不一样 cad宋体问号相关的知识,希望对你有一定的参考价值。
我的两台电脑是win10的,然后设置了cad字体是"宋体",但是别的电脑打开之后就变成了问号,这很奇怪....以至于我很烦恼....
搜了一波之后,这个链接说的是对的 https://blog.csdn.net/tisn05/article/details/53063702
但是他只是找到了解决方案,没有找到问题原因,谁知道的告诉我一下...
我的c#代码写得比他多了点东西,主要是两台电脑相互保存的话,要能看见才行...
主函数:
public class Command_ChangNewSong : IAutoGo { public void Initialize() { ChangNewSong();//自执行一次 Application.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(ChangNewSong); } public void Terminate() { } public static void ChangNewSong(object sender = null, DocumentCollectionEventArgs e = null) { try { using (Application.DocumentManager.MdiActiveDocument.LockDocument())//锁文档 { Database db = HostApplicationServices.WorkingDatabase;//当前的数据库 ChangNewSongEnt(db); db.Save(); //直接发送命令到cad命令栏 SendToCad.SendCommand("REGENALL"); } } catch { } } public static void ChangNewSongEnt(Database db) { //更改新宋体为宋体 bool songticunzai = false;//SD_宋体 存在 bool songticunzaiNew = false;//SD_新宋体 存在 string ttc = ".TTF"; using (Transaction tr = db.TransactionManager.StartTransaction())//来源数据库的事务 { var st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable; foreach (ObjectId id in st) { if (id.IsOk()) { var tstr = tr.GetObject(id, OpenMode.ForRead) as TextStyleTableRecord; if (tstr.Name == "SD_" + AutoGo.ConfigTxtStyle) { songticunzai = true; } if (tstr.Name == "SD_新宋体") { songticunzaiNew = true; } if (tstr.Font.TypeFace != "")//缺失字体 { string trypFace = tstr.Font.TypeFace.ToUpper(); //if (tstr.Name == "SD_宋体") //{ // System.Windows.Forms.MessageBox.Show($"SD_宋体用了这个:{trypFace}"); //} if (trypFace == "RS_Song".ToUpper() || trypFace == "SimSun".ToUpper()) { tr.AddTextStyle(db, tstr.Name, AutoGo.ConfigTxtStyle + ttc); } } } } if (!songticunzai) //没有就是可以改名称 { foreach (ObjectId id in st) { if (id.IsOk()) { var tstr = tr.GetObject(id, OpenMode.ForRead) as TextStyleTableRecord; if (tstr.Font.TypeFace == "新宋体" && tstr.Name == "SD_新宋体") { tstr.UpgradeOpen(); tstr.Name = "SD_" + AutoGo.ConfigTxtStyle; tstr.DowngradeOpen(); } if (tstr.Font.TypeFace == "新宋体") { tr.AddTextStyle(db, tstr.Name, AutoGo.ConfigTxtStyle + ttc); } } } } tr.Commit(); } using (Transaction tr = db.TransactionManager.StartTransaction())//来源数据库的事务 { if (songticunzai) { if (songticunzaiNew) //判断有没有 "SD_新宋体" { #if !HC2019 //文字样式 var stid = tr.AddTextStyle(db, "SD_新宋体", AutoGo.ConfigTxtStyle + ttc); #else //文字样式 var stid = tr.AddTextStyleToDatabase(db,"SD_新宋体", AutoGo.ConfigTxtStyle); #endif } } else { #if !HC2019 //文字样式 var stid = tr.AddTextStyle(db, "SD_" + AutoGo.ConfigTxtStyle, AutoGo.ConfigTxtStyle + ttc); #else //文字样式 var stid = tr.AddTextStyleToDatabase(db,"SD_" + AutoGo.ConfigTxtStyle, AutoGo.ConfigTxtStyle); #endif } tr.Commit(); } } }
新建字体函数
/// <summary> /// 新建文字样式 /// </summary> /// <param name="db"></param> /// <param name="name">样式名</param> /// <param name="smallfont">字体名</param> /// <param name="bigfont">大字体</param> /// <param name="height">高度</param> /// <param name="xscale">宽度因子</param> /// <returns></returns> public static ObjectId AddTextStyle(this Transaction tr, Database db, string name, string smallfont, string bigfont = null, double xscale = 1, double height = 0) { ObjectId ida = ObjectId.Null; //获取已有这个名字的文字样式表记录 var st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable; foreach (ObjectId id in st) { if (id.IsOk()) { var tstr = tr.GetObject(id, OpenMode.ForRead) as TextStyleTableRecord; if (tstr.Name == name)//有就打开,并修改内容 { if (!string.IsNullOrEmpty(smallfont))//如果字体不设置,就只返回 { tstr.UpgradeOpen(); tstr.FileName = smallfont; if (bigfont == null) { tstr.BigFontFileName = ""; } else { tstr.BigFontFileName = bigfont; } tstr.TextSize = height; tstr.XScale = xscale; tstr.DowngradeOpen(); } ida = id; break; } } } //没有就新建一个 if (ida == ObjectId.Null) { TextStyleTableRecord tstr = new TextStyleTableRecord { Name = name, FileName = smallfont, TextSize = height, XScale = xscale }; if (bigfont == null) { tstr.BigFontFileName = ""; } else { tstr.BigFontFileName = bigfont; } st.UpgradeOpen(); ida = st.Add(tstr); tr.AddNewlyCreatedDBObject(tstr, true); st.DowngradeOpen(); } return ida; }
以上是关于cad.net 两台电脑的宋体居然不一样 cad宋体问号的主要内容,如果未能解决你的问题,请参考以下文章
cad.net 利用win32api实现一个命令开关参照面板