public class TextPath
Use the Example:
Document doc = new Document();
// Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word.
// Provide a "ShapeType" as an argument to set a shape for the WordArt.
Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.",
"Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT);
// Apply the "Bold' and "Italic" formatting settings to the text using the respective properties.
shape.getTextPath().setBold(true);
shape.getTextPath().setItalic(true);
// Below are various other text formatting-related properties.
Assert.assertFalse(shape.getTextPath().getUnderline());
Assert.assertFalse(shape.getTextPath().getShadow());
Assert.assertFalse(shape.getTextPath().getStrikeThrough());
Assert.assertFalse(shape.getTextPath().getReverseRows());
Assert.assertFalse(shape.getTextPath().getXScale());
Assert.assertFalse(shape.getTextPath().getTrim());
Assert.assertFalse(shape.getTextPath().getSmallCaps());
Assert.assertEquals(36.0, shape.getTextPath().getSize());
Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText());
Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType());
// Use the "On" property to show/hide the text.
shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT);
shape.getTextPath().setOn(true);
shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT);
shape.getTextPath().setOn(false);
// Use the "Kerning" property to enable/disable kerning spacing between certain characters.
shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT);
shape.getTextPath().setKerning(true);
shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT);
shape.getTextPath().setKerning(false);
// Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default).
shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN);
shape.getTextPath().setSpacing(0.1);
// Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise.
shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE);
shape.getTextPath().setRotateLetters(true);
// Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height.
shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP);
shape.getTextPath().setSameLetterHeights(true);
// By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting.
shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT);
Assert.assertTrue(shape.getTextPath().getFitShape());
shape.getTextPath().setSize(24.0);
// If we set the "FitShape: property to "false", the text will keep the size
// which the "Size" property specifies regardless of the size of the shape.
// Use the "TextPathAlignment" property also to align the text to a side of the shape.
shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT);
shape.getTextPath().setFitShape(false);
shape.getTextPath().setSize(24.0);
shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT);
doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception {
// Create an inline Shape, which will serve as a container for our WordArt.
// The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it.
// These types will have "WordArt object" in the description,
// and their enumerator constant names will all start with "Text".
Shape shape = new Shape(doc, wordArtShapeType);
{
shape.setWrapType(WrapType.INLINE);
shape.setWidth(shapeWidth);
shape.setHeight(shapeHeight);
shape.setFillColor(wordArtFill);
shape.setStrokeColor(line);
}
shape.getTextPath().setText(text);
shape.getTextPath().setFontFamily(textFontFamily);
Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc));
para.appendChild(shape);
return shape;
}
Property Getters/Setters Summary | ||
---|---|---|
boolean | getBold() | |
void | setBold(booleanvalue) | |
True if the font is formatted as bold. | ||
boolean | getFitPath() | |
void | setFitPath(booleanvalue) | |
Defines whether the text fits the path of a shape. | ||
boolean | getFitShape() | |
void | setFitShape(booleanvalue) | |
Defines whether the text fits bounding box of a shape. | ||
java.lang.String | getFontFamily() | |
void | setFontFamily(java.lang.Stringvalue) | |
Defines the family of the textpath font. | ||
boolean | getItalic() | |
void | setItalic(booleanvalue) | |
True if the font is formatted as italic. | ||
boolean | getKerning() | |
void | setKerning(booleanvalue) | |
Determines whether kerning is turned on. | ||
boolean | getOn() | |
void | setOn(booleanvalue) | |
Defines whether the text is displayed. | ||
boolean | getReverseRows() | |
void | setReverseRows(booleanvalue) | |
Determines whether the layout order of rows is reversed. | ||
boolean | getRotateLetters() | |
void | setRotateLetters(booleanvalue) | |
Determines whether the letters of the text are rotated. | ||
boolean | getSameLetterHeights() | |
void | setSameLetterHeights(booleanvalue) | |
Determines whether all letters will be the same height regardless of initial case. | ||
boolean | getShadow() | |
void | setShadow(booleanvalue) | |
Defines whether a shadow is applied to the text on a text path. | ||
double | getSize() | |
void | setSize(doublevalue) | |
Defines the size of the font in points. | ||
boolean | getSmallCaps() | |
void | setSmallCaps(booleanvalue) | |
True if the font is formatted as small capital letters. | ||
double | getSpacing() | |
void | setSpacing(doublevalue) | |
Defines the amount of spacing for text. 1 means 100%. | ||
boolean | getStrikeThrough() | |
void | setStrikeThrough(booleanvalue) | |
True if the font is formatted as strikethrough text. | ||
java.lang.String | getText() | |
void | setText(java.lang.Stringvalue) | |
Defines the text of the text path. | ||
int | getTextPathAlignment() | |
void | setTextPathAlignment(intvalue) | |
Defines the alignment of text. The value of the property is TextPathAlignment integer constant. | ||
boolean | getTrim() | |
void | setTrim(booleanvalue) | |
Determines whether extra space is removed above and below the text. | ||
boolean | getUnderline() | |
void | setUnderline(booleanvalue) | |
True if the font is underlined. | ||
boolean | getXScale() | |
void | setXScale(booleanvalue) | |
Determines whether a straight textpath will be used instead of the shape path. |
public boolean getBold() / public void setBold(boolean value)
The default value is false.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public boolean getFitPath() / public void setFitPath(boolean value)
The default value is false.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public boolean getFitShape() / public void setFitShape(boolean value)
The default value is false.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public java.lang.String getFontFamily() / public void setFontFamily(java.lang.String value)
The default value is Arial.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public boolean getItalic() / public void setItalic(boolean value)
The default value is false.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public boolean getKerning() / public void setKerning(boolean value)
The default value is false.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public boolean getOn() / public void setOn(boolean value)
The default value is false.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public boolean getReverseRows() / public void setReverseRows(boolean value)
The default value is false.
If true, the layout order of rows is reversed. This attribute is used for vertical text layout.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public boolean getRotateLetters() / public void setRotateLetters(boolean value)
The default value is false.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public boolean getSameLetterHeights() / public void setSameLetterHeights(boolean value)
The default value is false.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public boolean getShadow() / public void setShadow(boolean value)
The default value is false.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public double getSize() / public void setSize(double value)
The default value is 36.
public boolean getSmallCaps() / public void setSmallCaps(boolean value)
The default value is false.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public double getSpacing() / public void setSpacing(double value)
The default value is 1.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public boolean getStrikeThrough() / public void setStrikeThrough(boolean value)
The default value is false.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public java.lang.String getText() / public void setText(java.lang.String value)
The default value is an empty string.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public int getTextPathAlignment() / public void setTextPathAlignment(int value)
The default value is
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public boolean getTrim() / public void setTrim(boolean value)
The default value is false.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public boolean getUnderline() / public void setUnderline(boolean value)
The default value is false.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }
public boolean getXScale() / public void setXScale(boolean value)
The default value is false.
If true, the text runs along a path from left to right along the x value of the lower boundary of the shape.
Example:
Shows how to work with WordArt.Document doc = new Document(); // Insert a WordArt object to display text in a shape that we can re-size and move by using the mouse in Microsoft Word. // Provide a "ShapeType" as an argument to set a shape for the WordArt. Shape shape = appendWordArt(doc, "Hello World! This text is bold, and italic.", "Arial", 480.0, 24.0, Color.WHITE, Color.BLACK, ShapeType.TEXT_PLAIN_TEXT); // Apply the "Bold' and "Italic" formatting settings to the text using the respective properties. shape.getTextPath().setBold(true); shape.getTextPath().setItalic(true); // Below are various other text formatting-related properties. Assert.assertFalse(shape.getTextPath().getUnderline()); Assert.assertFalse(shape.getTextPath().getShadow()); Assert.assertFalse(shape.getTextPath().getStrikeThrough()); Assert.assertFalse(shape.getTextPath().getReverseRows()); Assert.assertFalse(shape.getTextPath().getXScale()); Assert.assertFalse(shape.getTextPath().getTrim()); Assert.assertFalse(shape.getTextPath().getSmallCaps()); Assert.assertEquals(36.0, shape.getTextPath().getSize()); Assert.assertEquals("Hello World! This text is bold, and italic.", shape.getTextPath().getText()); Assert.assertEquals(ShapeType.TEXT_PLAIN_TEXT, shape.getShapeType()); // Use the "On" property to show/hide the text. shape = appendWordArt(doc, "On set to \"true\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(true); shape = appendWordArt(doc, "On set to \"false\"", "Calibri", 150.0, 24.0, Color.YELLOW, Color.pink, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setOn(false); // Use the "Kerning" property to enable/disable kerning spacing between certain characters. shape = appendWordArt(doc, "Kerning: VAV", "Times New Roman", 90.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(true); shape = appendWordArt(doc, "No kerning: VAV", "Times New Roman", 100.0, 24.0, Color.ORANGE, Color.RED, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setKerning(false); // Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default). shape = appendWordArt(doc, "Spacing set to 0.1", "Calibri", 120.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_CASCADE_DOWN); shape.getTextPath().setSpacing(0.1); // Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise. shape = appendWordArt(doc, "RotateLetters", "Calibri", 200.0, 36.0, Color.YELLOW, Color.GREEN, ShapeType.TEXT_WAVE); shape.getTextPath().setRotateLetters(true); // Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height. shape = appendWordArt(doc, "Same character height for lower and UPPER case", "Calibri", 300.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_SLANT_UP); shape.getTextPath().setSameLetterHeights(true); // By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting. shape = appendWordArt(doc, "FitShape on", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); Assert.assertTrue(shape.getTextPath().getFitShape()); shape.getTextPath().setSize(24.0); // If we set the "FitShape: property to "false", the text will keep the size // which the "Size" property specifies regardless of the size of the shape. // Use the "TextPathAlignment" property also to align the text to a side of the shape. shape = appendWordArt(doc, "FitShape off", "Calibri", 160.0, 24.0, Color.BLUE, Color.BLUE, ShapeType.TEXT_PLAIN_TEXT); shape.getTextPath().setFitShape(false); shape.getTextPath().setSize(24.0); shape.getTextPath().setTextPathAlignment(TextPathAlignment.RIGHT); doc.save(getArtifactsDir() + "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*/int wordArtShapeType) throws Exception { // Create an inline Shape, which will serve as a container for our WordArt. // The shape can only be a valid WordArt shape if we assign a WordArt-designated ShapeType to it. // These types will have "WordArt object" in the description, // and their enumerator constant names will all start with "Text". Shape shape = new Shape(doc, wordArtShapeType); { shape.setWrapType(WrapType.INLINE); shape.setWidth(shapeWidth); shape.setHeight(shapeHeight); shape.setFillColor(wordArtFill); shape.setStrokeColor(line); } shape.getTextPath().setText(text); shape.getTextPath().setFontFamily(textFontFamily); Paragraph para = (Paragraph) doc.getFirstSection().getBody().appendChild(new Paragraph(doc)); para.appendChild(shape); return shape; }