a:txSp (Text Shape)
Represents a specialized shape designed primarily for text content, combining drawing properties with text body formatting.
Description
a:txSp is the DrawingML text shape element designed as a shape optimized for text content. It is defined in ECMA-376 Part 1 §20.1.2.6.1.
Text shapes are specialized shapes that prioritize text rendering over geometric complexity. Key features:
- Designed for text-heavy content with complex formatting
- Supports all text formatting options (paragraphs, runs, styles)
- Can have shape fills, outlines, and effects
- Auto-fit options for text sizing and layout
- Common in text boxes, callouts, and text-focused diagrams
Text shapes are useful for:
- Text boxes and callouts in diagrams
- Structured text containers with visual styling
- Title and heading shapes
- Comment and annotation shapes
- Complex text layouts with graphics
Attributes
| Attribute | Type | Possible Values | Description |
|---|---|---|---|
| (none) | - | - | All properties defined through child elements. |
Examples
Simple Text Box
<p:txSp xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<p:nvTxSpPr>
<p:cNvPr id="1" name="Text Box 1"/>
<p:cNvTxSpPr/>
<p:nvPr/>
</p:nvTxSpPr>
<p:txSpPr>
<a:xfrm>
<a:off x="1000" y="1000"/>
<a:ext cx="2000000" cy="1000000"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
<a:solidFill>
<a:srgbClr val="E7E6E6"/>
</a:solidFill>
<a:ln w="9525">
<a:solidFill>
<a:srgbClr val="595959"/>
</a:solidFill>
</a:ln>
</p:txSpPr>
<p:txBody>
<a:bodyPr/>
<a:lstStyle/>
<a:p>
<a:r>
<a:rPr lang="en-US" sz="2400" b="0"/>
<a:t>Sample Text</a:t>
</a:r>
</a:p>
</p:txBody>
</p:txSp>
using DocumentFormat.OpenXml.Presentation;
using DocumentFormat.OpenXml.Drawing;
var txSp = new Shape();
var nvTxSpPr = new NonVisualShapeProperties();
nvTxSpPr.Append(new NonVisualDrawingProperties { Id = 1, Name = "Text Box 1" });
nvTxSpPr.Append(new NonVisualShapeDrawingProperties());
nvTxSpPr.Append(new ShapeNonVisualProperties());
txSp.Append(nvTxSpPr);
var txSpPr = new ShapeProperties();
var xfrm = new Transform2D();
xfrm.Append(new Offset { X = 1000, Y = 1000 });
xfrm.Append(new Extents { Cx = 2000000, Cy = 1000000 });
txSpPr.Append(xfrm);
var prstGeom = new PresetGeometry { Preset = ShapeTypeValues.Rectangle };
prstGeom.Append(new AdjustmentValueList());
txSpPr.Append(prstGeom);
var solidFill = new SolidFill();
solidFill.Append(new RgbColorModelHex { Val = "E7E6E6" });
txSpPr.Append(solidFill);
var ln = new Outline { Width = 9525 };
var lineFill = new SolidFill();
lineFill.Append(new RgbColorModelHex { Val = "595959" });
ln.Append(lineFill);
txSpPr.Append(ln);
var txBody = new TextBody();
txBody.Append(new BodyProperties());
txBody.Append(new ListStyle());
var p = new Paragraph();
var r = new Run();
r.Append(new RunProperties { Language = "en-US", FontSize = 2400 });
r.Append(new Text { Text = "Sample Text" });
p.Append(r);
txBody.Append(p);
txSp.Append(txBody);
Styled Text Box with Formatting
<p:txSp xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<p:nvTxSpPr>
<p:cNvPr id="2" name="Formatted Text"/>
<p:cNvTxSpPr/>
<p:nvPr/>
</p:nvTxSpPr>
<p:txSpPr>
<a:xfrm>
<a:off x="2000000" y="2000000"/>
<a:ext cx="3000000" cy="1500000"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
<a:gradFill>
<a:gsLst>
<a:gs pos="0">
<a:srgbClr val="0070C0"/>
</a:gs>
<a:gs pos="100000">
<a:srgbClr val="002060"/>
</a:gs>
</a:gsLst>
<a:lin ang="5400000" scaled="1"/>
</a:gradFill>
</p:txSpPr>
<p:txBody>
<a:bodyPr/>
<a:lstStyle/>
<a:p>
<a:pPr algn="ctr"/>
<a:r>
<a:rPr lang="en-US" sz="3200" b="1" color="FFFFFF"/>
<a:t>Title Text</a:t>
</a:r>
</a:p>
</p:txBody>
</p:txSp>
var txSp = new Shape();
// Non-visual properties
var nvTxSpPr = new NonVisualShapeProperties();
nvTxSpPr.Append(new NonVisualDrawingProperties { Id = 2, Name = "Formatted Text" });
nvTxSpPr.Append(new NonVisualShapeDrawingProperties());
nvTxSpPr.Append(new ShapeNonVisualProperties());
txSp.Append(nvTxSpPr);
// Text shape properties with gradient
var txSpPr = new ShapeProperties();
var xfrm = new Transform2D();
xfrm.Append(new Offset { X = 2000000, Y = 2000000 });
xfrm.Append(new Extents { Cx = 3000000, Cy = 1500000 });
txSpPr.Append(xfrm);
var prstGeom = new PresetGeometry { Preset = ShapeTypeValues.Rectangle };
prstGeom.Append(new AdjustmentValueList());
txSpPr.Append(prstGeom);
var gradFill = new GradientFill();
var gsLst = new GradientStopList();
var gs1 = new GradientStop { Position = 0 };
gs1.Append(new RgbColorModelHex { Val = "0070C0" });
gsLst.Append(gs1);
var gs2 = new GradientStop { Position = 100000 };
gs2.Append(new RgbColorModelHex { Val = "002060" });
gsLst.Append(gs2);
gradFill.Append(gsLst);
gradFill.Append(new LinearGradientFillProperties { Angle = 5400000, Scaled = true });
txSpPr.Append(gradFill);
txSp.Append(txSpPr);
// Text body with formatted text
var txBody = new TextBody();
txBody.Append(new BodyProperties());
txBody.Append(new ListStyle());
var p = new Paragraph { ParagraphProperties = new ParagraphProperties { Alignment = TextAlignmentTypeValues.Center } };
var r = new Run();
r.Append(new RunProperties { Language = "en-US", FontSize = 3200, Bold = true, Color = "FFFFFF" });
r.Append(new Text { Text = "Title Text" });
p.Append(r);
txBody.Append(p);
txSp.Append(txBody);
Notes
- Text shapes combine properties of regular shapes with full text formatting capabilities
- Useful for text-heavy content that needs visual styling
- Support auto-fit options for text sizing and word-wrapping
- Text body can contain multiple paragraphs with complex formatting
- Can apply effects (glow, shadow, reflection) to text shapes
- Font sizes in hundredths of points (2400 = 12pt)
- Text alignment options: left, center, right, justify