TextPath Class

Defines the text and formatting of the text path (of a WordArt object).
Inheritance Hierarchy
SystemObject
  Aspose.Words.DrawingTextPath

Namespace:  Aspose.Words.Drawing
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public class TextPath

The TextPath type exposes the following members.

Properties
  NameDescription
Public propertyCode exampleBold
True if the font is formatted as bold.
Public propertyCode exampleFitPath
Defines whether the text fits the path of a shape.
Public propertyCode exampleFitShape
Defines whether the text fits bounding box of a shape.
Public propertyCode exampleFontFamily
Defines the family of the textpath font.
Public propertyCode exampleItalic
True if the font is formatted as italic.
Public propertyCode exampleKerning
Determines whether kerning is turned on.
Public propertyCode exampleOn
Defines whether the text is displayed.
Public propertyCode exampleReverseRows
Determines whether the layout order of rows is reversed.
Public propertyCode exampleRotateLetters
Determines whether the letters of the text are rotated.
Public propertyCode exampleSameLetterHeights
Determines whether all letters will be the same height regardless of initial case.
Public propertyCode exampleShadow
Defines whether a shadow is applied to the text on a text path.
Public propertySize
Defines the size of the font in points.
Public propertyCode exampleSmallCaps
True if the font is formatted as small capital letters.
Public propertyCode exampleSpacing
Defines the amount of spacing for text. 1 means 100%.
Public propertyCode exampleStrikeThrough
True if the font is formatted as strikethrough text.
Public propertyCode exampleText
Defines the text of the text path.
Public propertyCode exampleTextPathAlignment
Defines the alignment of text.
Public propertyCode exampleTrim
Determines whether extra space is removed above and below the text.
Public propertyCode exampleUnderline
True if the font is underlined.
Public propertyCode exampleXScale
Determines whether a straight textpath will be used instead of the shape path.
Methods
  NameDescription
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)
Remarks

Use the TextPath property to access WordArt properties of a shape. You do not create instances of the TextPath class directly.

Examples
Shows how to work with WordArt.
public void InsertTextPaths()
{
    Document doc = new Document();

    // Insert a WordArt object and capture the shape that contains it in a variable
    Shape shape = AppendWordArt(doc, "Bold & Italic", "Arial", 240, 24, Color.White, Color.Black, ShapeType.TextPlainText);

    // View and verify various text formatting settings
    shape.TextPath.Bold = true;
    shape.TextPath.Italic = true;

    Assert.False(shape.TextPath.Underline);
    Assert.False(shape.TextPath.Shadow);
    Assert.False(shape.TextPath.StrikeThrough);
    Assert.False(shape.TextPath.ReverseRows);
    Assert.False(shape.TextPath.XScale);
    Assert.False(shape.TextPath.Trim);
    Assert.False(shape.TextPath.SmallCaps);

    Assert.AreEqual(36.0, shape.TextPath.Size);
    Assert.AreEqual("Bold & Italic", shape.TextPath.Text);
    Assert.AreEqual(ShapeType.TextPlainText, shape.ShapeType);

    // Toggle whether or not to display text
    shape = AppendWordArt(doc, "On set to true", "Calibri", 150, 24, Color.Yellow, Color.Red, ShapeType.TextPlainText);
    shape.TextPath.On = true;

    shape = AppendWordArt(doc, "On set to false", "Calibri", 150, 24, Color.Yellow, Color.Red, ShapeType.TextPlainText);
    shape.TextPath.On = false;

    // Apply kerning
    shape = AppendWordArt(doc, "Kerning: VAV", "Times New Roman", 90, 24, Color.Orange, Color.Red, ShapeType.TextPlainText);
    shape.TextPath.Kerning = true;

    shape = AppendWordArt(doc, "No kerning: VAV", "Times New Roman", 100, 24, Color.Orange, Color.Red, ShapeType.TextPlainText);
    shape.TextPath.Kerning = false;

    // Apply custom spacing, on a scale from 0.0 (none) to 1.0 (default)
    shape = AppendWordArt(doc, "Spacing set to 0.1", "Calibri", 120, 24, Color.BlueViolet, Color.Blue, ShapeType.TextCascadeDown);
    shape.TextPath.Spacing = 0.1;

    // Rotate letters 90 degrees to the left, text is still laid out horizontally
    shape = AppendWordArt(doc, "RotateLetters", "Calibri", 200, 36, Color.GreenYellow, Color.Green, ShapeType.TextWave);
    shape.TextPath.RotateLetters = true;

    // Set the x-height to equal the cap height
    shape = AppendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300, 24, Color.DeepSkyBlue, Color.DodgerBlue, ShapeType.TextSlantUp);
    shape.TextPath.SameLetterHeights = true;

    // By default, the size of the text will scale to always fit the size of the containing shape, overriding the text size setting
    shape = AppendWordArt(doc, "FitShape on", "Calibri", 160, 24, Color.LightBlue, Color.Blue, ShapeType.TextPlainText);
    Assert.True(shape.TextPath.FitShape);
    shape.TextPath.Size = 24.0;

    // If we set FitShape to false, the size of the text will defy the shape bounds and always keep the size value we set below
    // We can also set TextPathAlignment to align the text
    shape = AppendWordArt(doc, "FitShape off", "Calibri", 160, 24, Color.LightBlue, Color.Blue, ShapeType.TextPlainText);
    shape.TextPath.FitShape = false;
    shape.TextPath.Size = 24.0;
    shape.TextPath.TextPathAlignment = TextPathAlignment.Right;

    doc.Save(ArtifactsDir + "Shape.InsertTextPaths.docx");
}

/// <summary>
/// Insert a new paragraph with a WordArt shape inside it.
/// </summary>
private static Shape AppendWordArt(Document doc, string text, string textFontFamily, double shapeWidth, double shapeHeight, Color wordArtFill, Color line, ShapeType wordArtShapeType)
{
    // Insert a new paragraph
    Paragraph para = (Paragraph)doc.FirstSection.Body.AppendChild(new Paragraph(doc));

    // Create an inline Shape, which will serve as a container for our WordArt, and append it to the paragraph
    // The shape can only be a valid WordArt shape if the ShapeType assigned here is a WordArt-designated ShapeType
    // These types will have "WordArt object" in the description and their enumerator names will start with "Text..."
    Shape shape = new Shape(doc, wordArtShapeType);
    shape.WrapType = WrapType.Inline;
    para.AppendChild(shape);

    // Set the shape's width and height
    shape.Width = shapeWidth;
    shape.Height = shapeHeight;

    // These color settings will apply to the letters of the displayed WordArt text
    shape.FillColor = wordArtFill;
    shape.StrokeColor = line;

    // The WordArt object is accessed here, and we will set the text and font like this
    shape.TextPath.Text = text;
    shape.TextPath.FontFamily = textFontFamily;

    return shape;
}
See Also