/// <summary>
 /// Функция установки стиля текса
 /// </summary>
 /// <param name="style">Название шрифта</param>
 public static void ChangeTextStyle(string style)
 {
     try
     {
         // Get the current document and database
         Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
         Database acCurDb = acDoc.Database;
         // Start a transaction
         using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
         {
             // Open the current text style for write
             TextStyleTableRecord acTextStyleTblRec = acTrans.GetObject(acCurDb.Textstyle, OpenMode.ForWrite) as TextStyleTableRecord;
             // Get the current font settings
             acGI.FontDescriptor acFont = acTextStyleTblRec.Font;
             // Update the text style's typeface with "GOST Type A"
             acGI.FontDescriptor acNewFont = new acGI.FontDescriptor(style, acFont.Bold, acFont.Italic, acFont.CharacterSet, acFont.PitchAndFamily);
             acTextStyleTblRec.Font = acNewFont;
             acDoc.Editor.Regen();
             // Save the changes and dispose of the transaction
             acTrans.Commit();
         }
     }
     catch (System.Exception)
     {
         System.Windows.MessageBox.Show("При попытке установить стиль шрифта " + style + " возникла ошибка. Проверьте наличие необходимых шрифтов");
     }
 }
Beispiel #2
0
        public override void ViewportDraw(AcGi.ViewportDraw vd)
        {
            int glyphPixels = CustomObjectSnapMode.GlyphSize;
            var glyphSize   = vd.Viewport.GetNumPixelsInUnitSquare(_pt);

            // Calculate the size of the glyph in WCS
            //  (use for text height factor)

            // We'll add 10% to the size, as otherwise
            //  it looks a little too small

            double glyphHeight =
                (glyphPixels / glyphSize.Y) * 1.1;

            string text = "¼";

            // Translate the X-axis of the DCS to WCS
            //  (for the text direction) and the snap
            //  point itself (for the text location)

            var dist   = -glyphHeight / 2.0;
            var offset = new Vector3d(dist, dist, 0);
            var e2w    = vd.Viewport.EyeToWorldTransform;
            var dir    = Vector3d.XAxis.TransformBy(e2w);
            var pt     = (_pt + offset).TransformBy(e2w);

            //  Draw the centered text representing the glyph

            var style = new AcGi.TextStyle();
            var fd    =
                new AcGi.FontDescriptor("txt.shx", false, false, 0, 0);

            style.Font     = fd;
            style.TextSize = glyphHeight;

            vd.Geometry.Text(
                pt,
                vd.Viewport.ViewDirection,
                dir,
                text,
                false,
                style
                );
        }
Beispiel #3
0
        protected override void SubViewportDraw(AcGi.ViewportDraw vd)
        {
            int glyphSize   = CustomObjectSnapMode.GlyphSize;
            var glyphPixels = vd.Viewport.GetNumPixelsInUnitSquare(_pt);

            double glyphHeight = (glyphSize / glyphPixels.Y) * 1.1;
            string text        = "¼";

            var dist   = -glyphHeight / 2.0;
            var offset = new Vector3d(dist, dist, 0);
            var e2w    = vd.Viewport.EyeToWorldTransform;
            var dir    = Vector3d.XAxis.TransformBy(e2w);
            var pt     = (_pt + offset).TransformBy(e2w);

            var style = new AcGi.TextStyle();
            var fd    = new AcGi.FontDescriptor("txt.shx", false, false, 0, 0);

            style.Font     = fd;
            style.TextSize = glyphHeight;

            vd.Geometry.Text(pt, vd.Viewport.ViewDirection, dir, text, false, style);
        }