on property
TextPath.on property
Defines whether the text is displayed.
@property
def on(self) -> bool:
...
@on.setter
def on(self, value: bool):
...
Remarks
The default value is False.
Examples
Shows how to work with WordArt.
doc = aw.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 = ExShape._append_word_art(doc, 'Hello World! This text is bold, and italic.', 'Arial', 480, 24, aspose.pydrawing.Color.white, aspose.pydrawing.Color.black, aw.drawing.ShapeType.TEXT_PLAIN_TEXT)
# Apply the "Bold" and "Italic" formatting settings to the text using the respective properties.
shape.text_path.bold = True
shape.text_path.italic = True
# Below are various other text formatting-related properties.
self.assertFalse(shape.text_path.underline)
self.assertFalse(shape.text_path.shadow)
self.assertFalse(shape.text_path.strike_through)
self.assertFalse(shape.text_path.reverse_rows)
self.assertFalse(shape.text_path.x_scale)
self.assertFalse(shape.text_path.trim)
self.assertFalse(shape.text_path.small_caps)
self.assertEqual(36, shape.text_path.size)
self.assertEqual('Hello World! This text is bold, and italic.', shape.text_path.text)
self.assertEqual(aw.drawing.ShapeType.TEXT_PLAIN_TEXT, shape.shape_type)
# Use the "On" property to show/hide the text.
shape = ExShape._append_word_art(doc, 'On set to "true"', 'Calibri', 150, 24, aspose.pydrawing.Color.yellow, aspose.pydrawing.Color.red, aw.drawing.ShapeType.TEXT_PLAIN_TEXT)
shape.text_path.on = True
shape = ExShape._append_word_art(doc, 'On set to "false"', 'Calibri', 150, 24, aspose.pydrawing.Color.yellow, aspose.pydrawing.Color.purple, aw.drawing.ShapeType.TEXT_PLAIN_TEXT)
shape.text_path.on = False
# Use the "Kerning" property to enable/disable kerning spacing between certain characters.
shape = ExShape._append_word_art(doc, 'Kerning: VAV', 'Times New Roman', 90, 24, aspose.pydrawing.Color.orange, aspose.pydrawing.Color.red, aw.drawing.ShapeType.TEXT_PLAIN_TEXT)
shape.text_path.kerning = True
shape = ExShape._append_word_art(doc, 'No kerning: VAV', 'Times New Roman', 100, 24, aspose.pydrawing.Color.orange, aspose.pydrawing.Color.red, aw.drawing.ShapeType.TEXT_PLAIN_TEXT)
shape.text_path.kerning = False
# Use the "Spacing" property to set the custom spacing between characters on a scale from 0.0 (none) to 1.0 (default).
shape = ExShape._append_word_art(doc, 'Spacing set to 0.1', 'Calibri', 120, 24, aspose.pydrawing.Color.blue_violet, aspose.pydrawing.Color.blue, aw.drawing.ShapeType.TEXT_CASCADE_DOWN)
shape.text_path.spacing = 0.1
# Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise.
shape = ExShape._append_word_art(doc, 'RotateLetters', 'Calibri', 200, 36, aspose.pydrawing.Color.green_yellow, aspose.pydrawing.Color.green, aw.drawing.ShapeType.TEXT_WAVE)
shape.text_path.rotate_letters = True
# Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height.
shape = ExShape._append_word_art(doc, 'Same character height for lower and UPPER case', 'Calibri', 300, 24, aspose.pydrawing.Color.deep_sky_blue, aspose.pydrawing.Color.dodger_blue, aw.drawing.ShapeType.TEXT_SLANT_UP)
shape.text_path.same_letter_heights = True
# By default, the text's size will always scale to fit the containing shape's size, overriding the text size setting.
shape = ExShape._append_word_art(doc, 'FitShape on', 'Calibri', 160, 24, aspose.pydrawing.Color.light_blue, aspose.pydrawing.Color.blue, aw.drawing.ShapeType.TEXT_PLAIN_TEXT)
self.assertTrue(shape.text_path.fit_shape)
shape.text_path.size = 24
# 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 = ExShape._append_word_art(doc, 'FitShape off', 'Calibri', 160, 24, aspose.pydrawing.Color.light_blue, aspose.pydrawing.Color.blue, aw.drawing.ShapeType.TEXT_PLAIN_TEXT)
shape.text_path.fit_shape = False
shape.text_path.size = 24
shape.text_path.text_path_alignment = aw.drawing.TextPathAlignment.RIGHT
doc.save(file_name=ARTIFACTS_DIR + 'Shape.InsertTextPaths.docx')
Shows how to work with WordArt (AppendWordArt).
@staticmethod
def _append_word_art(doc, text, text_font_family, shape_width, shape_height, word_art_fill, line, word_art_shape_type):
# 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 = aw.drawing.Shape(doc, word_art_shape_type)
shape.wrap_type = aw.drawing.WrapType.INLINE
shape.width = shape_width
shape.height = shape_height
shape.fill_color = word_art_fill
shape.stroke_color = line
shape.text_path.text = text
shape.text_path.font_family = text_font_family
para = doc.first_section.body.append_child(aw.Paragraph(doc)).as_paragraph()
para.append_child(shape)
return shape
See Also
- module aspose.words.drawing
- class TextPath