Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="text"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, Core2D.XText text, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _gfx = gfx as XGraphics;

            var tbind = text.BindToTextProperty(db, r);

            if (string.IsNullOrEmpty(tbind))
            {
                return;
            }

            var options = new XPdfFontOptions(PdfFontEncoding.Unicode);

            var fontStyle = XFontStyle.Regular;

            if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Bold))
            {
                fontStyle |= XFontStyle.Bold;
            }

            if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Italic))
            {
                fontStyle |= XFontStyle.Italic;
            }

            if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Underline))
            {
                fontStyle |= XFontStyle.Underline;
            }

            if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Core2D.FontStyleFlags.Strikeout))
            {
                fontStyle |= XFontStyle.Strikeout;
            }

            var font = new XFont(
                text.Style.TextStyle.FontName,
                _scaleToPage(text.Style.TextStyle.FontSize),
                fontStyle,
                options);

            var rect = Core2D.Rect2.Create(
                text.TopLeft,
                text.BottomRight,
                dx, dy);

            var srect = new XRect(
                _scaleToPage(rect.X),
                _scaleToPage(rect.Y),
                _scaleToPage(rect.Width),
                _scaleToPage(rect.Height));

            var format = new XStringFormat();

            switch (text.Style.TextStyle.TextHAlignment)
            {
            case Core2D.TextHAlignment.Left:
                format.Alignment = XStringAlignment.Near;
                break;

            case Core2D.TextHAlignment.Center:
                format.Alignment = XStringAlignment.Center;
                break;

            case Core2D.TextHAlignment.Right:
                format.Alignment = XStringAlignment.Far;
                break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
            case Core2D.TextVAlignment.Top:
                format.LineAlignment = XLineAlignment.Near;
                break;

            case Core2D.TextVAlignment.Center:
                format.LineAlignment = XLineAlignment.Center;
                break;

            case Core2D.TextVAlignment.Bottom:
                format.LineAlignment = XLineAlignment.Far;
                break;
            }

            _gfx.DrawString(
                tbind,
                font,
                ToXSolidBrush(text.Style.Stroke),
                srect,
                format);
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="text"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object doc, Core2D.XText text, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            var _doc = doc as DxfDocument;

            var tbind = text.BindToTextProperty(db, r);

            if (string.IsNullOrEmpty(tbind))
            {
                return;
            }

            var style             = text.Style;
            var stroke            = GetColor(style.Stroke);
            var strokeTansparency = GetTransparency(style.Stroke);

            var    attachmentPoint = default(MTextAttachmentPoint);
            double x, y;
            var    rect = Core2D.Rect2.Create(text.TopLeft, text.BottomRight, dx, dy);

            switch (text.Style.TextStyle.TextHAlignment)
            {
            default:
            case Core2D.TextHAlignment.Left:
                x = rect.X;
                break;

            case Core2D.TextHAlignment.Center:
                x = rect.X + rect.Width / 2.0;
                break;

            case Core2D.TextHAlignment.Right:
                x = rect.X + rect.Width;
                break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
            default:
            case Core2D.TextVAlignment.Top:
                y = rect.Y;
                break;

            case Core2D.TextVAlignment.Center:
                y = rect.Y + rect.Height / 2.0;
                break;

            case Core2D.TextVAlignment.Bottom:
                y = rect.Y + rect.Height;
                break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
            default:
            case Core2D.TextVAlignment.Top:
                switch (text.Style.TextStyle.TextHAlignment)
                {
                default:
                case Core2D.TextHAlignment.Left:
                    attachmentPoint = MTextAttachmentPoint.TopLeft;
                    break;

                case Core2D.TextHAlignment.Center:
                    attachmentPoint = MTextAttachmentPoint.TopCenter;
                    break;

                case Core2D.TextHAlignment.Right:
                    attachmentPoint = MTextAttachmentPoint.TopRight;
                    break;
                }
                break;

            case Core2D.TextVAlignment.Center:
                switch (text.Style.TextStyle.TextHAlignment)
                {
                default:
                case Core2D.TextHAlignment.Left:
                    attachmentPoint = MTextAttachmentPoint.MiddleLeft;
                    break;

                case Core2D.TextHAlignment.Center:
                    attachmentPoint = MTextAttachmentPoint.MiddleCenter;
                    break;

                case Core2D.TextHAlignment.Right:
                    attachmentPoint = MTextAttachmentPoint.MiddleRight;
                    break;
                }
                break;

            case Core2D.TextVAlignment.Bottom:
                switch (text.Style.TextStyle.TextHAlignment)
                {
                default:
                case Core2D.TextHAlignment.Left:
                    attachmentPoint = MTextAttachmentPoint.BottomLeft;
                    break;

                case Core2D.TextHAlignment.Center:
                    attachmentPoint = MTextAttachmentPoint.BottomCenter;
                    break;

                case Core2D.TextHAlignment.Right:
                    attachmentPoint = MTextAttachmentPoint.BottomRight;
                    break;
                }
                break;
            }

            var ts       = new TextStyle(style.TextStyle.FontName, style.TextStyle.FontFile);
            var dxfMText = new MText(
                new Vector3(ToDxfX(x), ToDxfY(y), 0),
                text.Style.TextStyle.FontSize * 72.0 / 96.0,
                rect.Width,
                ts);

            dxfMText.AttachmentPoint = attachmentPoint;

            var fs      = text.Style.TextStyle.FontStyle;
            var options = new MTextFormattingOptions(dxfMText.Style);

            options.Bold          = fs.Flags.HasFlag(Core2D.FontStyleFlags.Bold);
            options.Italic        = fs.Flags.HasFlag(Core2D.FontStyleFlags.Italic);
            options.Underline     = fs.Flags.HasFlag(Core2D.FontStyleFlags.Underline);
            options.StrikeThrough = fs.Flags.HasFlag(Core2D.FontStyleFlags.Strikeout);

            options.Aligment = MTextFormattingOptions.TextAligment.Default;
            options.Color    = null;
            dxfMText.Write(tbind, options);

            dxfMText.Layer = _currentLayer;
            dxfMText.Transparency.Value = strokeTansparency;
            dxfMText.Color = stroke;

            _doc.AddEntity(dxfMText);
        }