From f6ed8d7519c3962f028143edf0cd9b7e7aba6d1c Mon Sep 17 00:00:00 2001 From: Jesse Mandel Date: Wed, 29 Nov 2023 11:29:05 -0800 Subject: [PATCH] Add TextWithShapeFormat to support `fBehindDocument` --- .../DocumentObjectModel.Shapes/Shape.cs | 19 +++++++ .../TextWithShapeFormat.cs | 52 +++++++++++++++++++ .../RtfRendering/ShapeRenderer.cs | 10 ++++ 3 files changed, 81 insertions(+) create mode 100644 src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/TextWithShapeFormat.cs diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/Shape.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/Shape.cs index e4a50e2d..1c7d7ea9 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/Shape.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/Shape.cs @@ -125,6 +125,19 @@ public FillFormat FillFormat } } + /// + /// Gets the text in front or behind format of the shape. + /// + public TextWithShapeFormat TextWithShapeFormat + { + get => Values.TextWithShapeFormat ??= new TextWithShapeFormat(this); + set + { + SetParent(value); + Values.TextWithShapeFormat = value; + } + } + /// /// Gets or sets the height of the shape. /// @@ -234,6 +247,12 @@ internal ShapeValues(DocumentObject owner) : base(owner) /// public FillFormat? FillFormat { get; set; } + /// + /// Gets or sets the internal nullable implementation value of the enclosing document object property. + /// See enclosing document object class for documentation of this property. + /// + public TextWithShapeFormat? TextWithShapeFormat { get; set; } + /// /// Gets or sets the internal nullable implementation value of the enclosing document object property. /// See enclosing document object class for documentation of this property. diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/TextWithShapeFormat.cs b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/TextWithShapeFormat.cs new file mode 100644 index 00000000..594ae615 --- /dev/null +++ b/src/foundation/src/MigraDoc/src/MigraDoc.DocumentObjectModel/DocumentObjectModel.Shapes/TextWithShapeFormat.cs @@ -0,0 +1,52 @@ +// MigraDoc - Creating Documents on the Fly +// See the LICENSE file in the solution root for more information. + +namespace MigraDoc.DocumentObjectModel.Shapes +{ + /// + /// A TextWithShapeFormat object + /// Defines the background filling of the shape. + /// + public class TextWithShapeFormat : DocumentObject + { + /// + /// Initializes a new instance of the FillFormat class. + /// + public TextWithShapeFormat() { } + + /// + /// Initializes a new instance of the FillFormat class with the specified parent. + /// + internal TextWithShapeFormat(DocumentObject parent) : base(parent) { } + + /// + /// Creates a deep copy of this object. + /// + public new TextWithShapeFormat Clone() + => (TextWithShapeFormat)DeepCopy(); + + /// + /// Gets or sets a value indicating whether the text should be in front of the shape. + /// + public bool? TextInFront { get; set; } + + /// + /// Converts FillFormat into DDL. + /// + internal override void Serialize(Serializer serializer) + { + int pos = serializer.BeginContent("TextWithShapeFormat"); + if (this.TextInFront.HasValue) + serializer.WriteSimpleAttribute("TextInFront", this.TextInFront.Value); + + serializer.EndContent(); + } + + /// + /// Returns the meta object of this instance. + /// + internal override Meta Meta => TheMeta; + + static readonly Meta TheMeta = new(typeof(TextWithShapeFormat)); + } +} diff --git a/src/foundation/src/MigraDoc/src/MigraDoc.RtfRendering/RtfRendering/ShapeRenderer.cs b/src/foundation/src/MigraDoc/src/MigraDoc.RtfRendering/RtfRendering/ShapeRenderer.cs index 111eb314..1ee9460e 100644 --- a/src/foundation/src/MigraDoc/src/MigraDoc.RtfRendering/RtfRendering/ShapeRenderer.cs +++ b/src/foundation/src/MigraDoc/src/MigraDoc.RtfRendering/RtfRendering/ShapeRenderer.cs @@ -57,6 +57,7 @@ void RenderShapeAttributes() } RenderLineFormat(); RenderFillFormat(); + RenderTextWithShapeFormat(); } /// @@ -74,6 +75,15 @@ protected void RenderFillFormat() RenderNameValuePair("fFilled", "0"); } + protected void RenderTextWithShapeFormat() + { + var tf = GetValueAsIntended("TextWithShapeFormat") as TextWithShapeFormat; + if (tf != null && tf.TextInFront.HasValue && tf.TextInFront.Value) + RenderNameValuePair("fBehindDocument", "0"); + else + RenderNameValuePair("fBehindDocument", "1"); + } + protected Unit GetLineWidth() { var lf = GetValueAsIntended("LineFormat") as LineFormat;