Class ShapeContent
Represents a shape within the document, primarily defined using SVG format.
Implements
Inherited Members
Namespace: IronWord.Models
Assembly: IronWord.dll
Syntax
public class ShapeContent : ContentElement, IWordShapeObject
ShapeContent is the inline shape a developer adds inside a run so a figure flows with the surrounding text. It is the drawing that travels with the words, a rectangle, ellipse, or freeform path that sits in the text stream rather than being pinned to a fixed spot on the page. A developer reaches for it to embed a small graphic alongside content, and it is paired with Shape, the page-positioned drawing that does not flow with text.
A run owns its inline shapes: a Run accepts ShapeContent items in its constructor, AddShape inserts one, and ExtractShapes reads them back as a List<ShapeContent>. A developer creates a shape from a ShapeType and a bounding RectangleF, optionally passing fill and stroke Color values, or builds a freeform outline by passing a List<IPathSegment>. That places it in the content-building step, between the run and the path geometry it may carry.
The members group by job. Construction comes from the ShapeType plus RectangleF constructors or the path-based ones, and Points exposes the freeform geometry as a List<IPathSegment>. Appearance is set by FillColor, StrokeColor, StrokeWeight, and Type, with Name, Id, and Index identifying the shape. Sizing and placement use Height, Width, the distance-from-edge properties such as DistanceFromTop and DistanceFromLeft, HorizontalAlignment, and VerticalAlignment, all available as Get and Set method forms that take a MeasurementUnit, plus BoundingBox, ZOrder, and ZPosition for stacking and bounds. Transforms cover Angle, Rotate, FlipHorizontal, FlipVertical, and Resize, while TextWrapBehavior controls how text flows around it and ToJson serializes it. Prefer the Set methods over the raw properties whenever the unit matters.
using IronWord.Models;
using IronWord.Models.Enums;
var shape = new ShapeContent(ShapeType.Rectangle, new RectangleF(0, 0, 100, 50));
shape.FillColor = Color.LightBlue;
new Run(shape);The add image how-to covers placing visual content inline, the add text how-to shows building runs, and the document element tutorial explains the document model.
Constructors
ShapeContent(ShapeType, RectangleF)
Initialize a ShapeContent object.
Declaration
public ShapeContent(ShapeType shapeType, RectangleF boundingBox)
Parameters
| Type | Name | Description |
|---|---|---|
| IronSoftware.Abstractions.Word.ShapeType | shapeType | The type of shape. |
| System.Drawing.RectangleF | boundingBox | The bounding box of the shape. |
ShapeContent(ShapeType, RectangleF, Color, Color)
Initialize a ShapeContent object.
Declaration
public ShapeContent(ShapeType shapeType, RectangleF boundingBox, Color fillColor, Color strokeColor)
Parameters
| Type | Name | Description |
|---|---|---|
| IronSoftware.Abstractions.Word.ShapeType | shapeType | The type of shape. |
| System.Drawing.RectangleF | boundingBox | The bounding box of the shape. |
| Color | fillColor | The fill color. |
| Color | strokeColor | The stroke color. |
ShapeContent(List<IPathSegment>)
Initialize a ShapeContent object.
Declaration
public ShapeContent(List<IPathSegment> points)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.List<IronSoftware.Abstractions.IPathSegment> | points | The points of the shape. |
Remarks
Initializing with just points will set the ShapeType as "Custom".
ShapeContent(List<IPathSegment>, Color, Color)
Initialize a ShapeContent object.
Declaration
public ShapeContent(List<IPathSegment> points, Color fillColor, Color strokeColor)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.List<IronSoftware.Abstractions.IPathSegment> | points | The points of the shape. |
| Color | fillColor | The fill color. |
| Color | strokeColor | The stroke color. |
Properties
Angle
Gets or sets rotation Angle for the shape in the document.
Declaration
public double Angle { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double |
Remarks
Unit are 'degrees' with range of values between 0 and 360, any negative or larger values will be normalized to that range.
BoundingBox
The bounding box of the shape.
Declaration
public RectangleF BoundingBox { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Drawing.RectangleF |
Remarks
Position and dimensions are represented in pts.
DistanceFromBottom
Gets or sets the distance from the bottom edge of the document to the Shape measured in points (1 inch = 72 points).
Declaration
public double DistanceFromBottom { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double |
DistanceFromLeft
Gets or sets the distance from the left edge of the document to the Shape measured in points (1 inch = 72 points).
Declaration
public double DistanceFromLeft { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double |
DistanceFromRight
Gets or sets the distance from the right edge of the document to the Shape measured in points (1 inch = 72 points).
Declaration
public double DistanceFromRight { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double |
DistanceFromTop
Gets or sets the distance from the top edge of the document to the Shape measured in points (1 inch = 72 points).
Declaration
public double DistanceFromTop { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double |
FillColor
Gets or sets the fill color of the shape.
Declaration
public Color FillColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
FlipHorizontal
Flip the shape horizontally.
Declaration
public bool FlipHorizontal { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
FlipVertical
Flip the shape vertically.
Declaration
public bool FlipVertical { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Height
The height of the shape in pts.
Declaration
public double Height { get; }
Property Value
| Type | Description |
|---|---|
| System.Double |
HorizontalAlignment
Gets or sets the horizontal alignment of the shape within its containing element.
Declaration
public HorizontalAlignment HorizontalAlignment { get; set; }
Property Value
| Type | Description |
|---|---|
| IronSoftware.Abstractions.Word.HorizontalAlignment |
HorizontalRelativePositionOrigin
Declaration
public HorizontalRelativePositionOrigin HorizontalRelativePositionOrigin { get; set; }
Property Value
| Type | Description |
|---|---|
| IronSoftware.Abstractions.Word.HorizontalRelativePositionOrigin |
Id
Gets or sets a unique identifier for the shape in the document.
Declaration
public uint Id { get; set; }
Property Value
| Type | Description |
|---|---|
| System.UInt32 |
Index
The index of this ShapeContent in Children.
Declaration
public int Index { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Name
Gets or sets the Name of the shape in the document.
Declaration
public string Name { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
Points
The points that make up the shape.
Declaration
public List<IPathSegment> Points { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<IronSoftware.Abstractions.IPathSegment> |
StrokeColor
Gets or sets the Stroke Color of the shape.
Declaration
public Color StrokeColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
StrokeWeight
The stroke weight of the shape in points (1 inch = 72 points).
Declaration
public int StrokeWeight { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
TextWrapBehavior
Declaration
public ITextWrapBehavior TextWrapBehavior { get; set; }
Property Value
| Type | Description |
|---|---|
| IronSoftware.Abstractions.Word.ITextWrapBehavior |
Type
Declaration
public ShapeType Type { get; set; }
Property Value
| Type | Description |
|---|---|
| IronSoftware.Abstractions.Word.ShapeType |
VerticalAlignment
Gets or sets the vertical alignment of the shape within its containing element.
Declaration
public VerticalAlignment VerticalAlignment { get; set; }
Property Value
| Type | Description |
|---|---|
| IronSoftware.Abstractions.Word.VerticalAlignment |
VerticalRelativePositionOrigin
Declaration
public VerticalRelativePositionOrigin VerticalRelativePositionOrigin { get; set; }
Property Value
| Type | Description |
|---|---|
| IronSoftware.Abstractions.Word.VerticalRelativePositionOrigin |
Width
The width of the shape in pts.
Declaration
public double Width { get; }
Property Value
| Type | Description |
|---|---|
| System.Double |
ZOrder
Declaration
public RelativeZOrder ZOrder { get; set; }
Property Value
| Type | Description |
|---|---|
| IronSoftware.Abstractions.RelativeZOrder |
ZPosition
Declaration
public long ZPosition { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int64 |
Methods
GetDistanceFromBottom(MeasurementUnit)
Declaration
public double GetDistanceFromBottom(MeasurementUnit measurementUnit)
Parameters
| Type | Name | Description |
|---|---|---|
| MeasurementUnit | measurementUnit |
Returns
| Type | Description |
|---|---|
| System.Double |
GetDistanceFromLeft(MeasurementUnit)
Declaration
public double GetDistanceFromLeft(MeasurementUnit measurementUnit)
Parameters
| Type | Name | Description |
|---|---|---|
| MeasurementUnit | measurementUnit |
Returns
| Type | Description |
|---|---|
| System.Double |
GetDistanceFromRight(MeasurementUnit)
Declaration
public double GetDistanceFromRight(MeasurementUnit measurementUnit)
Parameters
| Type | Name | Description |
|---|---|---|
| MeasurementUnit | measurementUnit |
Returns
| Type | Description |
|---|---|
| System.Double |
GetDistanceFromTop(MeasurementUnit)
Declaration
public double GetDistanceFromTop(MeasurementUnit measurementUnit)
Parameters
| Type | Name | Description |
|---|---|---|
| MeasurementUnit | measurementUnit |
Returns
| Type | Description |
|---|---|
| System.Double |
GetHeight(MeasurementUnit)
Declaration
public double GetHeight(MeasurementUnit measurementUnit)
Parameters
| Type | Name | Description |
|---|---|---|
| MeasurementUnit | measurementUnit |
Returns
| Type | Description |
|---|---|
| System.Double |
GetWidth(MeasurementUnit)
Get the width of the shape in specified measurement unit.
Declaration
public double GetWidth(MeasurementUnit measurementUnit)
Parameters
| Type | Name | Description |
|---|---|---|
| MeasurementUnit | measurementUnit | Measurement unit. |
Returns
| Type | Description |
|---|---|
| System.Double |
Resize(Int32, Int32)
Resizes the shape.
Declaration
public void Resize(int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | width | New width in points (1 inch = 72 points). |
| System.Int32 | height | New height in points (1 inch = 72 points). |
Rotate(Double)
Rotates the shape by a specified angle.
Declaration
public void Rotate(double angle)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | angle | The angle in degrees. |
Remarks
Unit is 'degrees' with a range of values between 0 and 360, any negative or larger values will be normalized to that range.
SetDistanceFromBottom(Double, MeasurementUnit)
Declaration
public void SetDistanceFromBottom(double distanceFromBottom, MeasurementUnit measurementUnit)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | distanceFromBottom | |
| MeasurementUnit | measurementUnit |
SetDistanceFromLeft(Double, MeasurementUnit)
Declaration
public void SetDistanceFromLeft(double distanceFromLeft, MeasurementUnit measurementUnit)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | distanceFromLeft | |
| MeasurementUnit | measurementUnit |
SetDistanceFromRight(Double, MeasurementUnit)
Declaration
public void SetDistanceFromRight(double distanceFromRight, MeasurementUnit measurementUnit)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | distanceFromRight | |
| MeasurementUnit | measurementUnit |
SetDistanceFromTop(Double, MeasurementUnit)
Declaration
public void SetDistanceFromTop(double distanceFromTop, MeasurementUnit measurementUnit)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | distanceFromTop | |
| MeasurementUnit | measurementUnit |
SetHeight(Double, MeasurementUnit)
Declaration
public void SetHeight(double height, MeasurementUnit measurementUnit)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | height | |
| MeasurementUnit | measurementUnit |
SetWidth(Double, MeasurementUnit)
Declaration
public void SetWidth(double width, MeasurementUnit measurementUnit)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | width | |
| MeasurementUnit | measurementUnit |
ToJson()
Serialize this shape as a JSON object.
Declaration
public string ToJson()
Returns
| Type | Description |
|---|---|
| System.String |