zoukankan      html  css  js  c++  java
  • cad.net cad宋体问号 删除 KT_ST.ttf

    我的两台电脑是win10的,(可能这个问题也存在在xp.win7.win8.......毕竟十年前我就遇到过了.......)

    一台电脑的cad字体设置为"宋体",另一台电脑打开之后就变成了问号,这很奇怪....

    以至于我很烦恼....

    搜了一波之后,这个链接说的是对的 https://blog.csdn.net/tisn05/article/details/53063702

    但是他只是找到了解决方案,没有找到问题原因

    原因

    我用了e大告诉我的方法,在cmd上用  dir c:windowsfonts*.*  检查字体是否相同,

    因为win字体文件夹有权限,所以我用pe (u盘装机进入的小系统)来替换字体,

    第一次直接替换了没有受影响的电脑的所有字体,然后发现OK的.....

    虽然这样可以结束了,但是我要具体分析到是什么字体导致的,免得再次出现同类情况,

    然后就是排除法,每次把所有字体都分成几份,然后如果是错的...就再分它....重复开关电脑十来次.....

    经过一晚上的排查,发现了一个字体:  KT_ST.ttf  导致的宋体问号....请大家删掉它....

    (话外题,宋体比新宋体好!!原因是宋体没有字体偏移问题,详见我 的字体问题集合)

    代码的解决方案:

    我的c#代码写得比链接多了点东西,主要是两台电脑相互保存的话,要能看见才行....

     主函数: 部分代码是替换新宋体到宋体...没删,懒.....

    AutoGo.ConfigTxtStyle ="宋体"

        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);       
                         //直接发送命令到cad命令栏 高版本发送命令刷新不了,只能发送延后的lisp...
                         SendToCad.SendLisp("(command "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();
                }
                //防止ctrl+u回滚事务出错,改名字之后再改内容
                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();
                }
            }
        }
    View Code

    新建字体函数

            /// <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;
            }
    View Code

    (完)

  • 相关阅读:
    【hdu 6214】Smallest Minimum Cut
    Spring Boot核心配置
    Spring Cloud是什么?
    Spring Boot开启的2种方式
    JVM运行时区域详解。
    史上最全Java多线程面试题及答案
    Git文件操作命令
    Git的安装配置
    Git SSH连接方式配置
    Intellij Idea乱码解决方案都在这里了
  • 原文地址:https://www.cnblogs.com/JJBox/p/10919629.html
Copyright © 2011-2022 走看看