Skip to content

Commit

Permalink
MText dxf writer
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Nov 14, 2023
1 parent 96af2ce commit 4277147
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 deletions.
11 changes: 1 addition & 10 deletions ACadSharp/Entities/MText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,11 @@ public double Height
public DrawingDirectionType DrawingDirection { get; set; }

/// <summary>
/// Specifies the text string for the entity.
/// Specifies the text string for the entity
/// </summary>
/// <value>
/// The maximum length is 256 characters.
/// </value>
[DxfCodeValue(1)]
public string Value { get; set; } = string.Empty;

/// <summary>
/// Additional text (always in 250-character chunks)
/// </summary>
[DxfCodeValue(DxfReferenceType.Optional, 3)]
public string AdditionalText { get; set; } = string.Empty;

/// <summary>
/// Style of this text entity.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ private bool readTextEntity(CadEntityTemplate template, DxfMap map, string subcl
switch (this._reader.Code)
{
//TODO: Implement multiline text def codes
case 3 when tmp.CadObject is MText mtext:
mtext.AdditionalText.Concat(this._reader.ValueAsString);
case 1 or 3 when tmp.CadObject is MText mtext:
mtext.Value += this._reader.ValueAsString;
return true;
case 70:
case 74:
Expand Down
30 changes: 10 additions & 20 deletions ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -616,37 +616,27 @@ private void writeMText(MText mtext)
this._writer.Write(71, (short)mtext.AttachmentPoint, map);
this._writer.Write(72, (short)mtext.DrawingDirection, map);

this._writer.Write(1, mtext.Value.Replace("\n", "^J"), map);

if (!string.IsNullOrEmpty(mtext.AdditionalText))
{
for (int i = 0; i < mtext.AdditionalText.Length; i += 250)
this._writer.Write(3, mtext.AdditionalText.Substring(i, 250), map);
}
this.writeMTextValue(mtext.Value);

this._writer.WriteName(7, mtext.Style);

this._writer.Write(73, (short)mtext.LineSpacingStyle, map);

this._writer.Write(11, mtext.AlignmentPoint, map);

return;
this._writer.Write(210, mtext.Normal, map);
}

if (this.Version >= ACadVersion.AC1018)
private void writeMTextValue(string text)
{
string encoded = text?.Replace("\n", "^J");

for (int i = 0; i < encoded.Length - 250; i += 250)
{
this._writer.Write(90, (int)mtext.BackgroundFillFlags, map);
if (mtext.BackgroundFillFlags.HasFlag(BackgroundFillFlags.UseBackgroundFillColor))
{
//this._writer.Write(63, mtext.BackgroundColor, map);
this._writer.Write(45, mtext.BackgroundScale, map);
//Transparency of background fill color (not implemented)
//this._writer.Write(441, mtext.BackgroundTransparency, map);
}
this._writer.Write(3, encoded.Substring(i, 250));
}

this._writer.Write(45, mtext.BackgroundScale, map);

this._writer.Write(210, mtext.Normal, map);
this._writer.Write(1, encoded);
}

private void writePoint(Point line)
Expand Down

0 comments on commit 4277147

Please sign in to comment.