From 4277147d0cee1439dea2cac2a87ec7bcb03d9488 Mon Sep 17 00:00:00 2001 From: DomCR Date: Tue, 14 Nov 2023 11:54:45 +0100 Subject: [PATCH] MText dxf writer --- ACadSharp/Entities/MText.cs | 11 +------ .../DxfStreamReader/DxfSectionReaderBase.cs | 4 +-- .../DxfSectionWriterBase.Entities.cs | 30 +++++++------------ 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/ACadSharp/Entities/MText.cs b/ACadSharp/Entities/MText.cs index 77a95482..424c5a79 100644 --- a/ACadSharp/Entities/MText.cs +++ b/ACadSharp/Entities/MText.cs @@ -81,20 +81,11 @@ public double Height public DrawingDirectionType DrawingDirection { get; set; } /// - /// Specifies the text string for the entity. + /// Specifies the text string for the entity /// - /// - /// The maximum length is 256 characters. - /// [DxfCodeValue(1)] public string Value { get; set; } = string.Empty; - /// - /// Additional text (always in 250-character chunks) - /// - [DxfCodeValue(DxfReferenceType.Optional, 3)] - public string AdditionalText { get; set; } = string.Empty; - /// /// Style of this text entity. /// diff --git a/ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs b/ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs index f0c37f5a..6b1b0e3b 100644 --- a/ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs +++ b/ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs @@ -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: diff --git a/ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.Entities.cs b/ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.Entities.cs index 0dade031..506c3d70 100644 --- a/ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.Entities.cs +++ b/ACadSharp/IO/DXF/DxfStreamWriter/DxfSectionWriterBase.Entities.cs @@ -616,13 +616,7 @@ 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); @@ -630,23 +624,19 @@ private void writeMText(MText mtext) 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)