public static System.Windows.TextAlignment AttachmentPointToAlign(MTextAttachmentPoint Attach) { System.Windows.TextAlignment hAlign = new System.Windows.TextAlignment(); List <int> list = new List <int> { 2, 5, 8 }; if (list.Contains((int)Attach)) { hAlign = System.Windows.TextAlignment.Center; } list = new List <int> { 1, 4, 7 }; if (list.Contains((int)Attach)) { hAlign = System.Windows.TextAlignment.Left; } list = new List <int> { 3, 6, 9 }; if (list.Contains((int)Attach)) { hAlign = System.Windows.TextAlignment.Right; } return(hAlign); }
/// <summary> /// Initializes a new instance of the <c>Dimension</c> class. /// </summary> protected Dimension(DimensionType type) : base(EntityType.Dimension, DxfObjectCode.Dimension) { this.definitionPoint = Vector3.Zero; this.midTextPoint = Vector3.Zero; this.dimensionType = type; this.attachmentPoint = MTextAttachmentPoint.MiddleCenter; this.lineSpacingStyle = MTextLineSpacingStyle.AtLeast; this.lineSpacing = 1.0; this.block = null; this.style = DimensionStyle.Default; }
/// <summary> /// Initializes a new instance of the <c>MText</c> class. /// </summary> /// <param name="text">Text string.</param> /// <param name="position">Text <see cref="Vector2">position</see> in world coordinates.</param> /// <param name="height">Text height.</param> /// <param name="rectangleWidth">Reference rectangle width.</param> /// <param name="style">Text <see cref="TextStyle">style</see>.</param> public MText(string text, Vector3 position, double height, double rectangleWidth, TextStyle style) : base(EntityType.MText, DxfObjectCode.MText) { this.value = text; this.position = position; this.attachmentPoint = MTextAttachmentPoint.TopLeft; if (style == null) { throw new ArgumentNullException("style", "The Text style cannot be null."); } this.style = style; this.rectangleWidth = rectangleWidth; this.height = height; this.lineSpacing = 1.0; this.paragraphHeightFactor = 1.0; this.lineSpacingStyle = MTextLineSpacingStyle.AtLeast; this.rotation = 0.0; }
/// <summary> /// Initializes a new instance of the <c>MText</c> class. /// </summary> /// <param name="text">Text string.</param> /// <param name="position">Text <see cref="Vector2">position</see> in world coordinates.</param> /// <param name="height">Text height.</param> /// <param name="rectangleWidth">Reference rectangle width.</param> /// <param name="style">Text <see cref="TextStyle">style</see>.</param> public MText(string text, Vector3 position, double height, double rectangleWidth, TextStyle style) : base(EntityType.MText, DxfObjectCode.MText) { this.text = text; this.position = position; this.attachmentPoint = MTextAttachmentPoint.TopLeft; this.style = style ?? throw new ArgumentNullException(nameof(style)); this.rectangleWidth = rectangleWidth; if (height <= 0.0) { throw new ArgumentOutOfRangeException(nameof(height), this.text, "The MText height must be greater than zero."); } this.height = height; this.lineSpacing = 1.0; this.lineSpacingStyle = MTextLineSpacingStyle.AtLeast; this.drawingDirection = MTextDrawingDirection.ByStyle; this.rotation = 0.0; }
/// <summary> /// Initializes a new instance of the <c>Dimension</c> class. /// </summary> protected Dimension(DimensionType type) : base(EntityType.Dimension, DxfObjectCode.Dimension) { this.definitionPoint = Vector3.Zero; this.midTextPoint = Vector3.Zero; this.dimensionType = type; this.attachmentPoint = MTextAttachmentPoint.MiddleCenter; this.lineSpacingStyle = MTextLineSpacingStyle.AtLeast; this.lineSpacing = 1.0; this.block = null; this.style = DimensionStyle.Default; this.userText = null; this.elevation = 0.0; this.styleOverrides = new DimensionStyleOverrideDictionary(); this.styleOverrides.BeforeAddItem += this.StyleOverrides_BeforeAddItem; this.styleOverrides.AddItem += this.StyleOverrides_AddItem; this.styleOverrides.BeforeRemoveItem += this.StyleOverrides_BeforeRemoveItem; this.styleOverrides.RemoveItem += this.StyleOverrides_RemoveItem; }
/// <summary> /// Initializes a new instance of the <c>Dimension</c> class. /// </summary> protected Dimension(DimensionType type) : base(EntityType.Dimension, DxfObjectCode.Dimension) { defPoint = Vector2.Zero; textRefPoint = Vector2.Zero; dimensionType = type; attachmentPoint = MTextAttachmentPoint.MiddleCenter; lineSpacingStyle = MTextLineSpacingStyle.AtLeast; lineSpacing = 1.0; block = null; style = DimensionStyle.Default; textRotation = 0.0; userText = null; elevation = 0.0; styleOverrides = new DimensionStyleOverrideDictionary(); styleOverrides.BeforeAddItem += StyleOverrides_BeforeAddItem; styleOverrides.AddItem += StyleOverrides_AddItem; styleOverrides.BeforeRemoveItem += StyleOverrides_BeforeRemoveItem; styleOverrides.RemoveItem += StyleOverrides_RemoveItem; }
/// <summary> /// Initializes a new instance of the <c>Dimension</c> class. /// </summary> protected Dimension(DimensionType type) : base(EntityType.Dimension, DxfObjectCode.Dimension) { this.definitionPoint = Vector3.Zero; this.midTextPoint = Vector3.Zero; this.dimensionType = type; this.attachmentPoint = MTextAttachmentPoint.MiddleCenter; this.lineSpacingStyle = MTextLineSpacingStyle.AtLeast; this.lineSpacing = 1.0; this.block = null; this.style = DimensionStyle.Default; this.userText = null; }
public static Vector3 TextAttachmentToPosition(MTextAttachmentPoint Attach, Vector3 position, double width, double height, double angle) { Vector3 newPos = new Vector3(); newPos = position; List <int> list = new List <int> { 2, 5, 8 }; /*Center*/ if (list.Contains((int)Attach)) { newPos.X = newPos.X - width / 2 - Math.Sin(Deg2Rad(angle)) * (height / 2 - 6); //newPos.X = newPos.X -Math.Cos(Deg2Rad(angle))*width/2 -Math.Sin(Deg2Rad(angle))*(height+height/2 +1); //newPos.X = newPos.X - height -Math.Cos(Deg2Rad(angle))*width/2 -Math.Sin(Deg2Rad(angle))*(height/2 +1); //newPos.X = newPos.X -Math.Sin(Deg2Rad(angle))*width/2 -Math.Cos(Deg2Rad(angle))*height/2; } list = new List <int> { 1, 4, 7 }; /*Left*/ if (list.Contains((int)Attach)) { newPos.X = newPos.X; } list = new List <int> { 3, 6, 9 }; /*Right*/ if (list.Contains((int)Attach)) { newPos.X = newPos.X - width; } list = new List <int> { 1, 2, 3 }; /*Top*/ if (list.Contains((int)Attach)) { newPos.Y = newPos.Y - Math.Sin(Deg2Rad(90)) * (height / 2 + 1); } list = new List <int> { 4, 5, 6 }; /*Middle*/ if (list.Contains((int)Attach)) { newPos.Y = newPos.Y + height / 2; } list = new List <int> { 7, 8, 9 }; /*Bottom*/ if (list.Contains((int)Attach)) { //newPos.Y = newPos.Y + Math.Sin(Deg2Rad(angle))*height/2 + 6; newPos.Y = newPos.Y + Math.Sin(Deg2Rad(angle)) * height / 2 + Math.Cos(Deg2Rad(angle)) * (height - 6); //- Math.Sin(Deg2Rad(90))*(width +1) } return(newPos); }
/// <summary> /// Moves, scales, and/or rotates the current entity given a 3x3 transformation matrix and a translation vector. /// </summary> /// <param name="transformation">Transformation matrix.</param> /// <param name="translation">Translation vector.</param> /// <remarks> /// Non-uniform scaling is not supported, it would require to decompose each line into independent Text entities. /// When the current MText entity does not belong to a DXF document, the text will be mirrored by default when a symmetry is performed; /// otherwise, the drawing variable MirrText will be used. /// </remarks> public override void TransformBy(Matrix3 transformation, Vector3 translation) { bool mirrText = this.Owner == null ? DefaultMirrText : this.Owner.Record.Owner.Owner.DrawingVariables.MirrText; Vector3 newPosition; Vector3 newNormal; Vector2 newUvector; Vector2 newVvector; double scale; double newHeight; double newRotation; newPosition = transformation * this.Position + translation; newNormal = transformation * this.Normal; Matrix3 transOW = MathHelper.ArbitraryAxis(this.Normal); Matrix3 transWO = MathHelper.ArbitraryAxis(newNormal); transWO = transWO.Transpose(); IList <Vector2> uv = MathHelper.Transform(new List <Vector2> { Vector2.UnitX, Vector2.UnitY }, this.Rotation * MathHelper.DegToRad, CoordinateSystem.Object, CoordinateSystem.World); Vector3 v; v = transOW * new Vector3(uv[0].X, uv[0].Y, 0.0); v = transformation * v; v = transWO * v; newUvector = new Vector2(v.X, v.Y); v = transOW * new Vector3(uv[1].X, uv[1].Y, 0.0); v = transformation * v; v = transWO * v; newVvector = new Vector2(v.X, v.Y); newRotation = Vector2.Angle(newUvector) * MathHelper.RadToDeg; if (mirrText) { if (Vector2.CrossProduct(newUvector, newVvector) < 0.0) { newRotation += 180; newNormal = -newNormal; } } else { if (Vector2.CrossProduct(newUvector, newVvector) < 0.0) { if (Vector2.DotProduct(newUvector, uv[0]) < 0.0) { newRotation += 180; switch (this.AttachmentPoint) { case MTextAttachmentPoint.TopLeft: this.AttachmentPoint = MTextAttachmentPoint.TopRight; break; case MTextAttachmentPoint.TopRight: this.AttachmentPoint = MTextAttachmentPoint.TopLeft; break; case MTextAttachmentPoint.MiddleLeft: this.AttachmentPoint = MTextAttachmentPoint.MiddleRight; break; case MTextAttachmentPoint.MiddleRight: this.AttachmentPoint = MTextAttachmentPoint.MiddleLeft; break; case MTextAttachmentPoint.BottomLeft: this.AttachmentPoint = MTextAttachmentPoint.BottomRight; break; case MTextAttachmentPoint.BottomRight: this.AttachmentPoint = MTextAttachmentPoint.BottomLeft; break; } } else { switch (this.AttachmentPoint) { case MTextAttachmentPoint.TopLeft: this.AttachmentPoint = MTextAttachmentPoint.BottomLeft; break; case MTextAttachmentPoint.TopCenter: this.attachmentPoint = MTextAttachmentPoint.BottomCenter; break; case MTextAttachmentPoint.TopRight: this.AttachmentPoint = MTextAttachmentPoint.BottomRight; break; case MTextAttachmentPoint.BottomLeft: this.AttachmentPoint = MTextAttachmentPoint.TopLeft; break; case MTextAttachmentPoint.BottomCenter: this.attachmentPoint = MTextAttachmentPoint.TopCenter; break; case MTextAttachmentPoint.BottomRight: this.AttachmentPoint = MTextAttachmentPoint.TopRight; break; } } } } // the MText entity does not support non-uniform scaling scale = newNormal.Modulus(); newHeight = this.Height * scale; newHeight = MathHelper.IsZero(newHeight) ? MathHelper.Epsilon : newHeight; this.Position = newPosition; this.Normal = newNormal; this.Rotation = newRotation; this.Height = newHeight; this.RectangleWidth *= scale; }
public static Vector2 CalculateCenter(float xLeft, float yBottom, float width, float height, bool isMText, MTextAttachmentPoint attachmentPoint) { if (isMText) { if (attachmentPoint == MTextAttachmentPoint.TopRight || attachmentPoint == MTextAttachmentPoint.MiddleRight || attachmentPoint == MTextAttachmentPoint.BottomRight) { xLeft -= width; } if (attachmentPoint == MTextAttachmentPoint.TopCenter || attachmentPoint == MTextAttachmentPoint.MiddleCenter || attachmentPoint == MTextAttachmentPoint.BottomCenter) { xLeft -= width * 0.5f; } if (attachmentPoint == MTextAttachmentPoint.MiddleRight || attachmentPoint == MTextAttachmentPoint.MiddleCenter || attachmentPoint == MTextAttachmentPoint.MiddleLeft) { yBottom -= height * 0.5f; } if (attachmentPoint == MTextAttachmentPoint.TopRight || attachmentPoint == MTextAttachmentPoint.TopCenter || attachmentPoint == MTextAttachmentPoint.TopLeft) { yBottom -= height; } } else { // Single line uses top left attachment point yBottom -= height; } //var h = HorizontalTextJustification; //var v = VerticalTextJustification; //var x1 = GetDoubleValueOrNull(DxfPartKind.PosX); //var y1 = GetDoubleValueOrNull(DxfPartKind.PosY); //var x2 = GetDoubleValueOrNull(DxfPartKind.AltPosX); //var y2 = GetDoubleValueOrNull(DxfPartKind.AltPosY); //if (!IsMText) //{ // // Even if center, the 1st point is still bottom left (so use it even though the alignment is not perfect) // //if (h == DxfValue_Text72_HorizontalTextJustification.Center) // //{ // // return new Vector2(x1.Value, y1.Value); // //} // // Bottom Left // return new Vector2(x1.Value + width * 0.5, y1.Value + height * 0.5); //} // Bottom Left return(new Vector2(xLeft + width * 0.5f, yBottom + height * 0.5f)); }
public static Bounds CalculateBounds(float xLeft, float yBottom, bool isMText, string text, float?textHeightCache = null, float?textWidthCache = null, float?textWidth = null, float?fontHeight = null, MTextAttachmentPoint attachmentPoint = MTextAttachmentPoint.TopLeft) { var width = CalculateWidth(text, textWidthCache, textWidth == 0 ? null : textWidth, fontHeight); var height = CalculateHeight(isMText, text, textHeightCache, textWidthCache, width, fontHeight); var center = CalculateCenter(xLeft, yBottom, width, height, isMText, attachmentPoint); return(Bounds.FromCenterSize(center, new Vector2(width, height))); }
/// <summary> /// Initializes a new instance of the <c>MText</c> class. /// </summary> /// <param name="text">Text string.</param> /// <param name="position">Text <see cref="Vector2">position</see> in world coordinates.</param> /// <param name="height">Text height.</param> /// <param name="rectangleWidth">Reference rectangle width.</param> /// <param name="style">Text <see cref="TextStyle">style</see>.</param> public MText(string text, Vector3 position, double height, double rectangleWidth, TextStyle style) : base(EntityType.MText, DxfObjectCode.MText) { this.value = text; this.position = position; this.attachmentPoint = MTextAttachmentPoint.TopLeft; if (style == null) throw new ArgumentNullException(nameof(style), "The Text style cannot be null."); this.style = style; this.rectangleWidth = rectangleWidth; if (height <= 0.0) throw new ArgumentOutOfRangeException(nameof(height), this.value, "The MText height must be greater than zero."); this.height = height; this.lineSpacing = 1.0; this.paragraphHeightFactor = 1.0; this.lineSpacingStyle = MTextLineSpacingStyle.AtLeast; this.rotation = 0.0; }