コード例 #1
0
ファイル: FontUtils.cs プロジェクト: huaj1101/AcPlugin
        private static void Redraw(Document doc, BlockTableRecord btr)
        {
            Regex regex = new Regex(@"\\[Ff][^;]+;");

            // 替换模型里所有文本的TextStyle
            foreach (ObjectId oid in btr)
            {
                if (oid.ObjectClass.DxfName == "TEXT")
                {
                    DBText text = (DBText)oid.GetObject(OpenMode.ForWrite);
                    if (doc.UserData.ContainsKey(text.TextStyleName) && (bool)doc.UserData[text.TextStyleName])
                    {
                        text.WidthFactor = text.WidthFactor * WIDTH_SCALE;
                        text.Height      = text.Height * HEIGHT_SCALE;
                    }
                }
                else if (oid.ObjectClass.DxfName == "MTEXT")
                {
                    MText text = (MText)oid.GetObject(OpenMode.ForWrite);
                    if (doc.UserData.ContainsKey(text.TextStyleName) && (bool)doc.UserData[text.TextStyleName])
                    {
                        text.TextHeight        = text.TextHeight * HEIGHT_SCALE;
                        text.LineSpacingFactor = text.LineSpacingFactor * HEIGHT_SCALE;
                        // 多行文本中可以嵌入字体,去掉这个信息
                        text.Contents = regex.Replace(text.Contents, "");
                    }
                }
                else if (oid.ObjectClass.DxfName == "DIMENSION")
                {
                    Dimension dim = (Dimension)oid.GetObject(OpenMode.ForRead);
                    dim.Draw();
                }
                else if (oid.ObjectClass.DxfName == "INSERT")
                {
                    Entity entity = (Entity)oid.GetObject(OpenMode.ForRead);
                    if (entity is BlockReference)
                    {
                        BlockReference br = entity as BlockReference;
                        // 处理未命名块(命名块在其他地方处理)
                        if (br.Name.StartsWith("*"))
                        {
                            Redraw(doc, br.BlockTableRecord.GetObject(OpenMode.ForRead) as BlockTableRecord);
                        }
                        br.RecordGraphicsModified(true);
                    }
                }
            }
        }