zoukankan      html  css  js  c++  java
  • 文字打断

    /// <summary>
            /// 文字打断
            /// </summary>
            [CommandMethod("sText_break")]
            public void sText_break()
            {
                Document doc = MgdAcApplication.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                Editor ed = doc.Editor;

                PromptEntityOptions optEnt = new PromptEntityOptions(" 选择单个文字");
                PromptEntityResult resEnt = ed.GetEntity(optEnt);
                if (resEnt.Status != PromptStatus.OK) return;

                using (Transaction acTrans = db.TransactionManager.StartTransaction())
                {
                    if (acTrans.GetObject(resEnt.ObjectId, OpenMode.ForWrite).GetType().Name != "DBText")
                    {
                        ed.WriteMessage(" 请选择单行文字");
                        return;
                    }

                    BlockTable acBlkTbl;
                    acBlkTbl = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;                

                    DBText sText = acTrans.GetObject(resEnt.ObjectId, OpenMode.ForWrite) as DBText;
                    //返回的数据中,sdPoint的X值是长度,Y值是高度
    #if CadVersion2014
                    Point2d sdPoint = Autodesk.AutoCAD.Internal.Utils.GetTextExtents(sText.TextStyleId, sText.TextString, sText.Height);
    #elif CadVersion2010
                    Point2d sdPoint = Autodesk.AutoCAD.Internal.Utils.GetTextExtents(sText.TextStyleId, sText.TextString, sText.Height);
    #else
                    Point2d sdPoint = Autodesk.AutoCAD.Internal.Utils.GetTextExtents(sText.TextStyle, sText.TextString, sText.Height);
    #endif
                    //取得单个字符的宽度,必须注意宽度系数,对于旋转的也可以
                    double sCharLen = sdPoint.X * sText.WidthFactor / sText.TextString.Length;
                    //取得鼠标离文字端点的直线长度
                    Point3d MousePoint = resEnt.PickedPoint;
                    Point3d TextPoint = sText.Position;
                    //double sLen = Math.Sqrt(Math.Pow(MousePoint.X - TextPoint.X, 2) + Math.Pow(MousePoint.Y - TextPoint.Y, 2));
                    double sLen = MousePoint.DistanceTo(TextPoint);
                    //计算当前点离起点的字符数并向下取整
                    double sCount = Math.Floor(sLen / sCharLen);

                    //开始截断
                    //第1个字符不变
                    double sLenCount = sText.TextString.Length;
                    string sTemp = sText.TextString;
                    sText.TextString = sText.TextString.Substring(0, (int)sCount);

                    //第2个字符位置
                    DBText sCreateText = new DBText();
                    double sHudu = sText.Rotation;
    #if CadVersion2014
                    Point2d sdP = Autodesk.AutoCAD.Internal.Utils.GetTextExtents(sText.TextStyleId, sText.TextString, sText.Height);
    #elif CadVersion2010
                    Point2d sdP = Autodesk.AutoCAD.Internal.Utils.GetTextExtents(sText.TextStyleId, sText.TextString, sText.Height);
    #else
                    Point2d sdP = Autodesk.AutoCAD.Internal.Utils.GetTextExtents(sText.TextStyle, sText.TextString, sText.Height);
    #endif
                    double sX = sText.Position.X + sdP.X * Math.Cos(sHudu) * sText.WidthFactor;
                    double sY = sText.Position.Y + sdP.X * Math.Sin(sHudu) * sText.WidthFactor;
                    sCreateText.Position = new Point3d(sX, sY, 0);
                    sCreateText.TextString = sTemp.Substring((int)sCount);
                    sCreateText.WidthFactor = sText.WidthFactor;
                    sCreateText.Rotation = sHudu;                
                    sCreateText.Height = sText.Height;

                    acBlkTblRec.AppendEntity(sCreateText);
                    acTrans.AddNewlyCreatedDBObject(sCreateText, true);

                    acTrans.Commit();
                }
                ed.WriteMessage(" 文字打断完成");
            }

  • 相关阅读:
    2.2 范式和反范式
    1.7 关系数据库设计理论
    2.1 选择优化的数据类型
    1.6 间隙锁(next-key locking)
    1.5 MySQL的存储引擎
    1.4 多版本并发控制
    1.3 事物和并发一致性问题
    1.2 并发控制
    1.1 MySQL逻辑架构
    php自定义函数及内部函数----数组处理函数
  • 原文地址:https://www.cnblogs.com/swtool/p/3828985.html
Copyright © 2011-2022 走看看