Class MText
Represents a multiline text EntityObject.
Inherited Members
Namespace: netDxf.Entities
Assembly: CADability.dll
Syntax
public class MText : EntityObject, IHasXData, ICloneable
Remarks
Formatting codes for MText, you can use them directly while setting the text value or use the Write() and EndParagraph() methods.
\L Start underline
\l Stop underline
\O Start overstrike
\o Stop overstrike
\K Start strike-through
\k Stop strike-through
\P New paragraph (new line)
\pxi Control codes for bullets, numbered paragraphs and columns
\X Paragraph wrap on the dimension line (only in dimensions)
\Q Slanting (obliquing) text by angle - e.g. \Q30;
\H Text height - e.g. \H3x;
\W Text width - e.g. \W0.8x;
\F Font selection
e.g. \Fgdt;o - GDT-tolerance
e.g. \Fkroeger|b0|i0|c238|p10; - font Kroeger, non-bold, non-italic, code page 238, pitch 10
\S Stacking, fractions
e.g. \SA^B;
A
B
e.g. \SX/Y
X
-
Y
e.g. \S1#4;
1/4
\A Alignment
\A0; = bottom
\A1; = center
\A2; = top
\C Color change
\C1; = red
\C2; = yellow
\C3; = green
\C4; = cyan
\C5; = blue
\C6; = magenta
\C7; = white
\T Tracking, char.spacing - e.g. \T2;
~ Non-wrapping space, hard space
{} Braces - define the text area influenced by the code
\ Escape character - e.g. \ = "", { = "{"
Codes and braces can be nested up to 8 levels deep.
Constructors
| Improve this Doc View SourceMText()
Initializes a new instance of the MText class.
Declaration
public MText()
MText(Vector2, Double)
Initializes a new instance of the MText class.
Declaration
public MText(Vector2 position, double height)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | position | Text Vector2 in world coordinates. |
| System.Double | height | Text height. |
MText(Vector2, Double, Double)
Initializes a new instance of the MText class.
Declaration
public MText(Vector2 position, double height, double rectangleWidth)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | position | Text Vector2 in world coordinates. |
| System.Double | height | Text height. |
| System.Double | rectangleWidth | Reference rectangle width. |
MText(Vector2, Double, Double, TextStyle)
Initializes a new instance of the MText class.
Declaration
public MText(Vector2 position, double height, double rectangleWidth, TextStyle style)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | position | Text Vector2 in world coordinates. |
| System.Double | height | Text height. |
| System.Double | rectangleWidth | Reference rectangle width. |
| TextStyle | style | Text TextStyle. |
MText(Vector3, Double)
Initializes a new instance of the MText class.
Declaration
public MText(Vector3 position, double height)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | position | Text Vector2 in world coordinates. |
| System.Double | height | Text height. |
MText(Vector3, Double, Double)
Initializes a new instance of the MText class.
Declaration
public MText(Vector3 position, double height, double rectangleWidth)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | position | Text Vector2 in world coordinates. |
| System.Double | height | Text height. |
| System.Double | rectangleWidth | Reference rectangle width. |
MText(Vector3, Double, Double, TextStyle)
Initializes a new instance of the MText class.
Declaration
public MText(Vector3 position, double height, double rectangleWidth, TextStyle style)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | position | Text Vector2 in world coordinates. |
| System.Double | height | Text height. |
| System.Double | rectangleWidth | Reference rectangle width. |
| TextStyle | style | Text TextStyle. |
MText(String)
Initializes a new instance of the MText class.
Declaration
public MText(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | text | Text string. |
MText(String, Vector2, Double)
Initializes a new instance of the MText class.
Declaration
public MText(string text, Vector2 position, double height)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | text | Text string. |
| Vector2 | position | Text Vector2 in world coordinates. |
| System.Double | height | Text height. |
MText(String, Vector2, Double, Double)
Initializes a new instance of the MText class.
Declaration
public MText(string text, Vector2 position, double height, double rectangleWidth)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | text | Text string. |
| Vector2 | position | Text Vector2 in world coordinates. |
| System.Double | height | Text height. |
| System.Double | rectangleWidth | Reference rectangle width. |
MText(String, Vector2, Double, Double, TextStyle)
Initializes a new instance of the MText class.
Declaration
public MText(string text, Vector2 position, double height, double rectangleWidth, TextStyle style)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | text | Text string. |
| Vector2 | position | Text Vector2 in world coordinates. |
| System.Double | height | Text height. |
| System.Double | rectangleWidth | Reference rectangle width. |
| TextStyle | style | Text TextStyle. |
MText(String, Vector3, Double)
Initializes a new instance of the MText class.
Declaration
public MText(string text, Vector3 position, double height)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | text | Text string. |
| Vector3 | position | Text Vector2 in world coordinates. |
| System.Double | height | Text height. |
MText(String, Vector3, Double, Double)
Initializes a new instance of the MText class.
Declaration
public MText(string text, Vector3 position, double height, double rectangleWidth)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | text | Text string. |
| Vector3 | position | Text Vector2 in world coordinates. |
| System.Double | height | Text height. |
| System.Double | rectangleWidth | Reference rectangle width. |
MText(String, Vector3, Double, Double, TextStyle)
Initializes a new instance of the MText class.
Declaration
public MText(string text, Vector3 position, double height, double rectangleWidth, TextStyle style)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | text | Text string. |
| Vector3 | position | Text Vector2 in world coordinates. |
| System.Double | height | Text height. |
| System.Double | rectangleWidth | Reference rectangle width. |
| TextStyle | style | Text TextStyle. |
Properties
| Improve this Doc View SourceAttachmentPoint
Gets or sets the text MTextAttachmentPoint.
Declaration
public MTextAttachmentPoint AttachmentPoint { get; set; }
Property Value
| Type | Description |
|---|---|
| MTextAttachmentPoint |
DefaultMirrText
Gets or sets if the text will be mirrored when a symmetry is performed, when the current MText entity does not belong to a DXF document.
Declaration
public static bool DefaultMirrText { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
DrawingDirection
Get or sets the MTextDrawingDirection.
Declaration
public MTextDrawingDirection DrawingDirection { get; set; }
Property Value
| Type | Description |
|---|---|
| MTextDrawingDirection |
Height
Gets or sets the text height.
Declaration
public double Height { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double |
LineSpacingFactor
Gets or sets the line spacing factor.
Declaration
public double LineSpacingFactor { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double |
Remarks
Percentage of default line spacing to be applied. Valid values range from 0.25 to 4.0, the default value 1.0.
LineSpacingStyle
Get or sets the MTextLineSpacingStyle.
Declaration
public MTextLineSpacingStyle LineSpacingStyle { get; set; }
Property Value
| Type | Description |
|---|---|
| MTextLineSpacingStyle |
Position
Gets or sets the Text Vector3 in world coordinates.
Declaration
public Vector3 Position { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector3 |
RectangleWidth
Gets or sets the text reference rectangle width.
Declaration
public double RectangleWidth { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double |
Remarks
This value defines the width of the box where the text will fit.
If a paragraph width is longer than the rectangle width it will be broken in several lines, using the word spaces as breaking points.
If you specify a width of 0, word wrap is turned off and the width of the multiline text object is as wide as the longest line of text.
Rotation
Gets or sets the text rotation in degrees.
Declaration
public double Rotation { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double |
Style
Gets or sets the TextStyle.
Declaration
public TextStyle Style { get; set; }
Property Value
| Type | Description |
|---|---|
| TextStyle |
Value
Gets or sets the raw text string.
Declaration
public string Value { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
Methods
| Improve this Doc View SourceClone()
Creates a new MText that is a copy of the current instance.
Declaration
public override object Clone()
Returns
| Type | Description |
|---|---|
| System.Object | A new MText that is a copy of this instance. |
Overrides
| Improve this Doc View SourceEndParagraph()
Ends the current paragraph.
Declaration
public void EndParagraph()
OnTextStyleChangedEvent(TextStyle, TextStyle)
Declaration
protected virtual TextStyle OnTextStyleChangedEvent(TextStyle oldTextStyle, TextStyle newTextStyle)
Parameters
| Type | Name | Description |
|---|---|---|
| TextStyle | oldTextStyle | |
| TextStyle | newTextStyle |
Returns
| Type | Description |
|---|---|
| TextStyle |
PlainText()
Obtains the MText text value without the formatting codes, control characters like tab '\t' will be preserved in the result, the new paragraph command "\P" will be converted to new line feed '\r\n'.
Declaration
public string PlainText()
Returns
| Type | Description |
|---|---|
| System.String | MText text value without the formatting codes. |
StartParagraph()
Starts a new paragraph.
Declaration
public void StartParagraph()
Remarks
When no paragraph options are used, strictly speaking, there is no need to call this method, the previous paragraph options will be inherited.
When there is no need to change the paragraph options from the previous, it is no necessary to pass again the same instance,
the paragraph characteristics are inherited from the previous one.
This way no codes needs to be written and it will save some characters in the final string.
StartParagraph(MTextParagraphOptions)
Starts a new paragraph.
Declaration
public void StartParagraph(MTextParagraphOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| MTextParagraphOptions | options | Paragraph options. |
Remarks
When no paragraph options are used, strictly speaking, there is no need to call this method, the previous paragraph options will be inherited.
When there is no need to change the paragraph options from the previous, it is no necessary to pass again the same instance,
the paragraph characteristics are inherited from the previous one.
This way no codes needs to be written and it will save some characters in the final string.
TransformBy(Matrix3, Vector3)
Moves, scales, and/or rotates the current entity given a 3x3 transformation matrix and a translation vector.
Declaration
public override void TransformBy(Matrix3 transformation, Vector3 translation)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix3 | transformation | Transformation matrix. |
| Vector3 | translation | Translation vector. |
Overrides
Remarks
Non-uniform scaling is not supported, it would require to decompose each line into independent Text entities.
When the current Text entity does not belong to a DXF document, the text will use the DefaultMirrText when a symmetry is performed;
otherwise, the drawing variable MirrText will be used.
Matrix3 adopts the convention of using column vectors to represent a transformation matrix.
Write(String)
Adds the text to the current paragraph.
Declaration
public void Write(string txt)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | txt | Text string. |
Write(String, MTextFormattingOptions)
Adds the text to the current paragraph.
Declaration
public void Write(string txt, MTextFormattingOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | txt | Text string. |
| MTextFormattingOptions | options | Text formatting options. |
WriteFraction(String, String, FractionFormatType)
Formats a text string to represent a fraction.
Declaration
public void WriteFraction(string numerator, string denominator, FractionFormatType fractionType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | numerator | Fraction numerator. |
| System.String | denominator | Fraction denominator. |
| FractionFormatType | fractionType | Style of the fraction. |
Remarks
In fractions the characters '/' and '#' are reserved if you need to write them you must write "/" and "#", respectively.
WriteFraction(String, String, FractionFormatType, MTextFormattingOptions)
Formats a text string to represent a fraction.
Declaration
public void WriteFraction(string numerator, string denominator, FractionFormatType fractionType, MTextFormattingOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | numerator | Fraction numerator. |
| System.String | denominator | Fraction denominator. |
| FractionFormatType | fractionType | Style of the fraction. |
| MTextFormattingOptions | options | Text formatting options. |
Remarks
In fractions the characters '/' and '#' are reserved if you need to write them you must write "/" and "#", respectively.
Do not combine fractions with super or subscript options, it is not supported (stacking commands cannot be nested).
Events
| Improve this Doc View SourceTextStyleChanged
Declaration
public event MText.TextStyleChangedEventHandler TextStyleChanged
Event Type
| Type | Description |
|---|---|
| MText.TextStyleChangedEventHandler |