Aspose::Words::Drawing::Shape Class Referencefinal

Detailed Description

Represents an object in the drawing layer, such as an AutoShape, textbox, freeform, OLE object, ActiveX control, or picture.

Using the Shape class you can create or modify shapes in a Microsoft Word document.

An important property of a shape is its ShapeType. Shapes of different types can have different capabilities in a Word document. For example, only image and OLE shapes can have images inside them. Most of the shapes can have text, but not all.

Shapes that can have text, can contain Paragraph and Table nodes as children.

See also
Aspose::Words::Drawing::ShapeBase
Aspose::Words::Drawing::GroupShape
Examples

Shows how to extract images from a document, and save them to the local file system as individual files.

auto doc = MakeObject<Document>(MyDir + u"Images.docx");
// Get the collection of shapes from the document,
// and save the image data of every shape with an image as a file to the local file system.
SharedPtr<NodeCollection> shapes = doc->GetChildNodes(NodeType::Shape, true);
ASSERT_EQ(9, shapes->LINQ_Count([](SharedPtr<Node> s) { return (System::DynamicCast<Shape>(s))->get_HasImage(); }));
int imageIndex = 0;
for (const auto& shape : System::IterateOver(shapes->LINQ_OfType<SharedPtr<Shape>>()))
{
if (shape->get_HasImage())
{
// The image data of shapes may contain images of many possible image formats.
// We can determine a file extension for each image automatically, based on its format.
String imageFileName =
String::Format(u"File.ExtractImages.{0}{1}", imageIndex, FileFormatUtil::ImageTypeToExtension(shape->get_ImageData()->get_ImageType()));
shape->get_ImageData()->Save(ArtifactsDir + imageFileName);
imageIndex++;
}
}

Shows how to insert a floating image to the center of a page.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a floating image that will appear behind the overlapping text and align it to the page's center.
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
shape->set_WrapType(WrapType::None);
shape->set_BehindText(true);
shape->set_RelativeHorizontalPosition(RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(RelativeVerticalPosition::Page);
shape->set_HorizontalAlignment(HorizontalAlignment::Center);
shape->set_VerticalAlignment(VerticalAlignment::Center);
doc->Save(ArtifactsDir + u"Image.CreateFloatingPageCenter.docx");

Shows how to delete all shapes from a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert two shapes along with a group shape with another shape inside it.
builder->InsertShape(ShapeType::Rectangle, 400, 200);
builder->InsertShape(ShapeType::Star, 300, 300);
auto group = MakeObject<GroupShape>(doc);
group->set_Bounds(System::Drawing::RectangleF(100.0f, 50.0f, 200.0f, 100.0f));
group->set_CoordOrigin(System::Drawing::Point(-1000, -500));
auto subShape = MakeObject<Shape>(doc, ShapeType::Cube);
subShape->set_Width(500);
subShape->set_Height(700);
subShape->set_Left(0);
subShape->set_Top(0);
group->AppendChild(subShape);
builder->InsertNode(group);
ASSERT_EQ(3, doc->GetChildNodes(NodeType::Shape, true)->get_Count());
ASSERT_EQ(1, doc->GetChildNodes(NodeType::GroupShape, true)->get_Count());
// Remove all Shape nodes from the document.
SharedPtr<NodeCollection> shapes = doc->GetChildNodes(NodeType::Shape, true);
shapes->Clear();
// All shapes are gone, but the group shape is still in the document.
ASSERT_EQ(1, doc->GetChildNodes(NodeType::GroupShape, true)->get_Count());
ASSERT_EQ(0, doc->GetChildNodes(NodeType::Shape, true)->get_Count());
// Remove all group shapes separately.
SharedPtr<NodeCollection> groupShapes = doc->GetChildNodes(NodeType::GroupShape, true);
groupShapes->Clear();
ASSERT_EQ(0, doc->GetChildNodes(NodeType::GroupShape, true)->get_Count());
ASSERT_EQ(0, doc->GetChildNodes(NodeType::Shape, true)->get_Count());

#include <Aspose.Words.Cpp/Drawing/Shape.h>

+ Inheritance diagram for Aspose::Words::Drawing::Shape:

Public Member Functions

 Shape (const SharedPtr< DocumentBase > &doc, ShapeType shapeType)
 Creates a new shape object. More...
 
bool Accept (SharedPtr< DocumentVisitor > visitor) override
 Accepts a visitor. More...
 
SharedPtr< Chartget_Chart ()
 Provides access to the chart properties if this shape has a Chart. More...
 
bool get_ExtrusionEnabled ()
 Returns true if an extrusion effect is enabled. More...
 
Color get_FillColor ()
 Defines the brush color that fills the closed path of the shape. More...
 
bool get_Filled ()
 Determines whether the closed path of the shape will be filled. More...
 
SharedPtr< Paragraphget_FirstParagraph ()
 Gets the first paragraph in the shape. More...
 
bool get_HasChart ()
 Returns true if this Shape has a Chart. More...
 
bool get_HasImage ()
 Returns true if the shape has image bytes or links an image. More...
 
bool get_HasSmartArt ()
 Returns true if this Shape has a SmartArt object. More...
 
SharedPtr< HorizontalRuleFormatget_HorizontalRuleFormat ()
 Provides access to the properties of the horizontal rule shape. For a shape that is not a horizontal rule, returns null. More...
 
SharedPtr< ImageDataget_ImageData ()
 Provides access to the image of the shape. Returns null if the shape cannot have an image. More...
 
SharedPtr< Paragraphget_LastParagraph ()
 Gets the last paragraph in the shape. More...
 
NodeType get_NodeType () const override
 Returns Shape. More...
 
SharedPtr< OleFormatget_OleFormat ()
 Provides access to the OLE data of a shape. For a shape that is not an OLE object or ActiveX control, returns null. More...
 
bool get_ShadowEnabled ()
 Returns true if a shadow effect is enabled. More...
 
SharedPtr< SignatureLineget_SignatureLine ()
 Gets SignatureLine object if the shape is a signature line. Returns null otherwise. More...
 
StoryType get_StoryType ()
 Returns Textbox. More...
 
SharedPtr< Strokeget_Stroke ()
 Defines a stroke for a shape. More...
 
Color get_StrokeColor ()
 Defines the color of a stroke. More...
 
bool get_Stroked ()
 Defines whether the path will be stroked. More...
 
double get_StrokeWeight ()
 Defines the brush thickness that strokes the path of a shape in points. More...
 
SharedPtr< TextBoxget_TextBox ()
 Defines attributes that specify how text is displayed in a shape. More...
 
SharedPtr< TextPathget_TextPath ()
 Defines the text of the text path (of a WordArt object). More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_FillColor (Color value)
 Setter for get_FillColor. More...
 
void set_Filled (bool value)
 Setter for get_Filled. More...
 
void set_StrokeColor (Color value)
 Setter for get_StrokeColor. More...
 
void set_Stroked (bool value)
 Setter for get_Stroked. More...
 
void set_StrokeWeight (double value)
 Setter for get_StrokeWeight. More...
 
void UpdateSmartArtDrawing ()
 Updates SmartArt pre-rendered drawing by using Aspose.Words's SmartArt cold rendering engine. More...
 
- Public Member Functions inherited from ShapeBase
RectangleF AdjustWithEffects (RectangleF source)
 Adds to the source rectangle values of the effect extent and returns the final rectangle. More...
 
bool get_AllowOverlap ()
 Gets or sets a value that specifies whether this shape can overlap other shapes. More...
 
String get_AlternativeText ()
 Defines alternative text to be displayed instead of a graphic. More...
 
bool get_AnchorLocked ()
 Specifies whether the shape's anchor is locked. More...
 
bool get_AspectRatioLocked ()
 Specifies whether the shape's aspect ratio is locked. More...
 
bool get_BehindText ()
 Specifies whether the shape is below or above text. More...
 
double get_Bottom ()
 Gets the position of the bottom edge of the containing block of the shape. More...
 
RectangleF get_Bounds ()
 Gets or sets the location and size of the containing block of the shape. More...
 
RectangleF get_BoundsInPoints ()
 Gets the location and size of the containing block of the shape in points, relative to the anchor of the topmost shape. More...
 
RectangleF get_BoundsWithEffects ()
 Gets final extent that this shape object has after applying drawing effects. Value is measured in points. More...
 
bool get_CanHaveImage ()
 Returns true if the shape type allows the shape to have an image. More...
 
Point get_CoordOrigin ()
 The coordinates at the top-left corner of the containing block of this shape. More...
 
Size get_CoordSize ()
 The width and height of the coordinate space inside the containing block of this shape. More...
 
double get_DistanceBottom ()
 Returns or sets the distance (in points) between the document text and the bottom edge of the shape. More...
 
double get_DistanceLeft ()
 Returns or sets the distance (in points) between the document text and the left edge of the shape. More...
 
double get_DistanceRight ()
 Returns or sets the distance (in points) between the document text and the right edge of the shape. More...
 
double get_DistanceTop ()
 Returns or sets the distance (in points) between the document text and the top edge of the shape. More...
 
SharedPtr< Fillget_Fill ()
 Gets fill formatting for the shape. More...
 
FlipOrientation get_FlipOrientation ()
 Switches the orientation of a shape. More...
 
SharedPtr< Fontget_Font ()
 Provides access to the font formatting of this object. More...
 
double get_Height ()
 Gets or sets the height of the containing block of the shape. More...
 
HorizontalAlignment get_HorizontalAlignment ()
 Specifies how the shape is positioned horizontally. More...
 
String get_HRef ()
 Gets or sets the full hyperlink address for a shape. More...
 
bool get_IsDecorative ()
 Gets or sets the flag that specifies whether the shape is decorative in the document. More...
 
bool get_IsDeleteRevision ()
 Returns true if this object was deleted in Microsoft Word while change tracking was enabled. More...
 
bool get_IsGroup ()
 Returns true if this is a group shape. More...
 
bool get_IsHorizontalRule ()
 Returns true if this shape is a horizontal rule. More...
 
bool get_IsImage ()
 Returns true if this shape is an image shape. More...
 
bool get_IsInline ()
 A quick way to determine if this shape is positioned inline with text. More...
 
bool get_IsInsertRevision ()
 Returns true if this object was inserted in Microsoft Word while change tracking was enabled. More...
 
bool get_IsLayoutInCell ()
 Gets or sets a flag indicating whether the shape is displayed inside a table or outside of it. More...
 
bool get_IsMoveFromRevision ()
 Returns true if this object was moved (deleted) in Microsoft Word while change tracking was enabled. More...
 
bool get_IsMoveToRevision ()
 Returns true if this object was moved (inserted) in Microsoft Word while change tracking was enabled. More...
 
bool get_IsSignatureLine ()
 Indicates that shape is a SignatureLine. More...
 
bool get_IsTopLevel ()
 Returns true if this shape is not a child of a group shape. More...
 
bool get_IsWordArt ()
 Returns true if this shape is a WordArt object. More...
 
double get_Left ()
 Gets or sets the position of the left edge of the containing block of the shape. More...
 
ShapeMarkupLanguage get_MarkupLanguage () const
 Gets MarkupLanguage used for this graphic object. More...
 
String get_Name ()
 Gets or sets the optional shape name. More...
 
SharedPtr< Paragraphget_ParentParagraph ()
 Returns the immediate parent paragraph. More...
 
RelativeHorizontalPosition get_RelativeHorizontalPosition ()
 Specifies relative to what the shape is positioned horizontally. More...
 
RelativeVerticalPosition get_RelativeVerticalPosition ()
 Specifies relative to what the shape is positioned vertically. More...
 
double get_Right ()
 Gets the position of the right edge of the containing block of the shape. More...
 
double get_Rotation ()
 Defines the angle (in degrees) that a shape is rotated. Positive value corresponds to clockwise rotation angle. More...
 
String get_ScreenTip ()
 Defines the text displayed when the mouse pointer moves over the shape. More...
 
ShapeType get_ShapeType ()
 Gets the shape type. More...
 
SizeF get_SizeInPoints ()
 Gets the size of the shape in points. More...
 
String get_Target ()
 Gets or sets the target frame for the shape hyperlink. More...
 
String get_Title ()
 Gets or sets the title (caption) of the current shape object. More...
 
double get_Top ()
 Gets or sets the position of the top edge of the containing block of the shape. More...
 
VerticalAlignment get_VerticalAlignment ()
 Specifies how the shape is positioned vertically. More...
 
double get_Width ()
 Gets or sets the width of the containing block of the shape. More...
 
WrapSide get_WrapSide ()
 Specifies how the text is wrapped around the shape. More...
 
WrapType get_WrapType ()
 Defines whether the shape is inline or floating. For floating shapes defines the wrapping mode for text around the shape. More...
 
int32_t get_ZOrder ()
 Determines the display order of overlapping shapes. More...
 
SharedPtr< ShapeRendererGetShapeRenderer ()
 Creates and returns an object that can be used to render this shape into an image. More...
 
PointF LocalToParent (PointF value)
 Converts a value from the local coordinate space into the coordinate space of the parent shape. More...
 
void set_AllowOverlap (bool value)
 Setter for get_AllowOverlap. More...
 
void set_AlternativeText (const String &value)
 Setter for get_AlternativeText. More...
 
void set_AnchorLocked (bool value)
 Setter for get_AnchorLocked. More...
 
void set_AspectRatioLocked (bool value)
 Setter for get_AspectRatioLocked. More...
 
void set_BehindText (bool value)
 Setter for get_BehindText. More...
 
void set_Bounds (RectangleF value)
 Setter for get_Bounds. More...
 
void set_CoordOrigin (Point value)
 Setter for get_CoordOrigin. More...
 
void set_CoordSize (Size value)
 Setter for get_CoordSize. More...
 
void set_DistanceBottom (double value)
 Setter for get_DistanceBottom. More...
 
void set_DistanceLeft (double value)
 Setter for get_DistanceLeft. More...
 
void set_DistanceRight (double value)
 Setter for get_DistanceRight. More...
 
void set_DistanceTop (double value)
 Setter for get_DistanceTop. More...
 
void set_FlipOrientation (FlipOrientation value)
 Setter for get_FlipOrientation. More...
 
void set_Height (double value)
 Setter for get_Height. More...
 
void set_HorizontalAlignment (HorizontalAlignment value)
 Setter for get_HorizontalAlignment. More...
 
void set_HRef (const String &value)
 Setter for get_HRef. More...
 
void set_IsDecorative (bool value)
 Setter for get_IsDecorative. More...
 
void set_IsLayoutInCell (bool value)
 Setter for get_IsLayoutInCell. More...
 
void set_Left (double value)
 Setter for get_Left. More...
 
void set_Name (const String &value)
 Setter for get_Name. More...
 
void set_RelativeHorizontalPosition (RelativeHorizontalPosition value)
 Setter for get_RelativeHorizontalPosition. More...
 
void set_RelativeVerticalPosition (RelativeVerticalPosition value)
 Setter for get_RelativeVerticalPosition. More...
 
void set_Rotation (double value)
 Setter for get_Rotation. More...
 
void set_ScreenTip (const String &value)
 Setter for get_ScreenTip. More...
 
void set_Target (const String &value)
 Setter for get_Target. More...
 
void set_Title (const String &value)
 Setter for get_Title. More...
 
void set_Top (double value)
 Setter for get_Top. More...
 
void set_VerticalAlignment (VerticalAlignment value)
 Setter for get_VerticalAlignment. More...
 
void set_Width (double value)
 Setter for get_Width. More...
 
void set_WrapSide (WrapSide value)
 Setter for get_WrapSide. More...
 
void set_WrapType (WrapType value)
 Setter for get_WrapType. More...
 
void set_ZOrder (int32_t value)
 Setter for get_ZOrder. More...
 
- Public Member Functions inherited from CompositeNode
SharedPtr< NodeAppendChild (const SharedPtr< Node > &newChild)
 Adds the specified node to the end of the list of child nodes for this node. More...
 
SharedPtr< NodeCollectionget_ChildNodes ()
 Gets all immediate child nodes of this node. More...
 
int32_t get_Count ()
 Gets the number of immediate children of this node. More...
 
SharedPtr< Nodeget_FirstChild () const
 Gets the first child of the node. More...
 
bool get_HasChildNodes ()
 Returns true if this node has any child nodes. More...
 
bool get_IsComposite () override
 Returns true as this node can have child nodes. More...
 
SharedPtr< Nodeget_LastChild () const
 Gets the last child of the node. More...
 
SharedPtr< NodeGetChild (NodeType nodeType, int32_t index, bool isDeep)
 Returns an Nth child node that matches the specified type. More...
 
SharedPtr< NodeCollectionGetChildNodes (NodeType nodeType, bool isDeep)
 Returns a live collection of child nodes that match the specified type. More...
 
SharedPtr< IEnumerator< SharedPtr< Node > > > GetEnumerator () override
 Provides support for the for each style iteration over the child nodes of this node. More...
 
String GetText () override
 Gets the text of this node and of all its children. More...
 
int32_t IndexOf (const SharedPtr< Node > &child)
 Returns the index of the specified child node in the child node array. More...
 
SharedPtr< NodeInsertAfter (const SharedPtr< Node > &newChild, const SharedPtr< Node > &refChild)
 Inserts the specified node immediately after the specified reference node. More...
 
SharedPtr< NodeInsertBefore (const SharedPtr< Node > &newChild, const SharedPtr< Node > &refChild)
 Inserts the specified node immediately before the specified reference node. More...
 
SharedPtr< NodePrependChild (const SharedPtr< Node > &newChild)
 Adds the specified node to the beginning of the list of child nodes for this node. More...
 
void RemoveAllChildren ()
 Removes all the child nodes of the current node. More...
 
SharedPtr< NodeRemoveChild (const SharedPtr< Node > &oldChild)
 Removes the specified child node. More...
 
void RemoveSmartTags ()
 Removes all SmartTag descendant nodes of the current node. More...
 
SharedPtr< NodeListSelectNodes (const String &xpath)
 Selects a list of nodes matching the XPath expression. More...
 
SharedPtr< NodeSelectSingleNode (const String &xpath)
 Selects the first Node that matches the XPath expression. More...
 
void SetTemplateWeakPtr (uint32_t argument) override
 
- Public Member Functions inherited from Node
SharedPtr< NodeClone (bool isCloneChildren)
 Creates a duplicate of the node. More...
 
int32_t get_CustomNodeId () const
 Specifies custom node identifier. More...
 
virtual SharedPtr< DocumentBaseget_Document () const
 Gets the document to which this node belongs. More...
 
SharedPtr< Nodeget_NextSibling ()
 Gets the node immediately following this node. More...
 
SharedPtr< CompositeNodeget_ParentNode ()
 Gets the immediate parent of this node. More...
 
SharedPtr< Nodeget_PreviousSibling ()
 Gets the node immediately preceding this node. More...
 
SharedPtr< Rangeget_Range ()
 Returns a Range object that represents the portion of a document that is contained in this node. More...
 
SharedPtr< CompositeNodeGetAncestor (NodeType ancestorType)
 Gets the first ancestor of the specified NodeType. More...
 
template<typename T >
GetAncestorOf ()
 
SharedPtr< NodeNextPreOrder (const SharedPtr< Node > &rootNode)
 Gets next node according to the pre-order tree traversal algorithm. More...
 
SharedPtr< NodePreviousPreOrder (const SharedPtr< Node > &rootNode)
 Gets the previous node according to the pre-order tree traversal algorithm. More...
 
void Remove ()
 Removes itself from the parent. More...
 
void set_CustomNodeId (int32_t value)
 Setter for get_CustomNodeId. More...
 
String ToString (SaveFormat saveFormat)
 Exports the content of the node into a string in the specified format. More...
 
String ToString (const SharedPtr< SaveOptions > &saveOptions)
 Exports the content of the node into a string using the specified save options. More...
 

Static Public Member Functions

static const TypeInfoType ()
 
- Static Public Member Functions inherited from ShapeBase
static const TypeInfoType ()
 
- Static Public Member Functions inherited from CompositeNode
static const TypeInfoType ()
 
- Static Public Member Functions inherited from Node
static String NodeTypeToString (NodeType nodeType)
 A utility method that converts a node type enum value into a user friendly string. More...
 
static const TypeInfoType ()
 

Constructor & Destructor Documentation

◆ Shape()

Aspose::Words::Drawing::Shape::Shape ( const System::SharedPtr< Aspose::Words::DocumentBase > &  doc,
Aspose::Words::Drawing::ShapeType  shapeType 
)

Creates a new shape object.

You should specify desired shape properties after you created a shape.

Parameters
docThe owner document.
shapeTypeThe type of the shape to create.
Examples

Shows how to insert a shape with an image from the local file system into a document.

auto doc = MakeObject<Document>();
// The "Shape" class's public constructor will create a shape with "ShapeMarkupLanguage.Vml" markup type.
// If you need to create a shape of a non-primitive type, such as SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,
// TopCornersOneRoundedOneSnipped, SingleCornerRounded, TopCornersRounded, or DiagonalCornersRounded,
// please use DocumentBuilder.InsertShape.
auto shape = MakeObject<Shape>(doc, ShapeType::Image);
shape->get_ImageData()->SetImage(ImageDir + u"Windows MetaFile.wmf");
shape->set_Width(100);
shape->set_Height(100);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(shape);
doc->Save(ArtifactsDir + u"Image.FromFile.docx");

Shows how to create and format a text box.

auto doc = MakeObject<Document>();
// Create a floating text box.
auto textBox = MakeObject<Shape>(doc, ShapeType::TextBox);
textBox->set_WrapType(WrapType::None);
textBox->set_Height(50);
textBox->set_Width(200);
// Set the horizontal, and vertical alignment of the text inside the shape.
textBox->set_HorizontalAlignment(HorizontalAlignment::Center);
textBox->set_VerticalAlignment(VerticalAlignment::Top);
// Add a paragraph to the text box and add a run of text that the text box will display.
textBox->AppendChild(MakeObject<Paragraph>(doc));
SharedPtr<Paragraph> para = textBox->get_FirstParagraph();
para->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Center);
auto run = MakeObject<Run>(doc);
run->set_Text(u"Hello world!");
para->AppendChild(run);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(textBox);
doc->Save(ArtifactsDir + u"Shape.CreateTextBox.docx");

Member Function Documentation

◆ Accept()

bool Aspose::Words::Drawing::Shape::Accept ( System::SharedPtr< Aspose::Words::DocumentVisitor visitor)
overridevirtual

Accepts a visitor.

Enumerates over this node and all of its children. Each node calls a corresponding method on DocumentVisitor.

For more info see the Visitor design pattern.

Parameters
visitorThe visitor that will visit the nodes.
Returns
True if all nodes were visited; false if DocumentVisitor stopped the operation before visiting all nodes.
Examples

Shows how to iterate over all the shapes in a document.

void VisitShapes()
{
auto doc = MakeObject<Document>(MyDir + u"Revision shape.docx");
auto visitor = MakeObject<ExShape::ShapeAppearancePrinter>();
doc->Accept(visitor);
std::cout << visitor->GetText() << std::endl;
}
class ShapeAppearancePrinter : public DocumentVisitor
{
public:
ShapeAppearancePrinter() : mShapesVisited(0), mTextIndentLevel(0)
{
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = MakeObject<System::Text::StringBuilder>();
}
String GetText()
{
return String::Format(u"Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
VisitorAction VisitShapeStart(SharedPtr<Shape> shape) override
{
AppendLine(String::Format(u"Shape found: {0}", shape->get_ShapeType()));
mTextIndentLevel++;
if (shape->get_HasChart())
{
AppendLine(String::Format(u"Has chart: {0}", shape->get_Chart()->get_Title()->get_Text()));
}
AppendLine(String::Format(u"Extrusion enabled: {0}", shape->get_ExtrusionEnabled()));
AppendLine(String::Format(u"Shadow enabled: {0}", shape->get_ShadowEnabled()));
AppendLine(String::Format(u"StoryType: {0}", shape->get_StoryType()));
if (shape->get_Stroked())
{
ASPOSE_EXPECT_EQ(shape->get_Stroke()->get_Color(), shape->get_StrokeColor());
AppendLine(String::Format(u"Stroke colors: {0}, {1}", shape->get_Stroke()->get_Color(), shape->get_Stroke()->get_Color2()));
AppendLine(String::Format(u"Stroke weight: {0}", shape->get_StrokeWeight()));
}
if (shape->get_Filled())
{
AppendLine(String::Format(u"Filled: {0}", shape->get_FillColor()));
}
if (shape->get_OleFormat() != nullptr)
{
AppendLine(String::Format(u"Ole found of type: {0}", shape->get_OleFormat()->get_ProgId()));
}
if (shape->get_SignatureLine() != nullptr)
{
AppendLine(String::Format(u"Found signature line for: {0}, {1}", shape->get_SignatureLine()->get_Signer(),
shape->get_SignatureLine()->get_SignerTitle()));
}
}
VisitorAction VisitShapeEnd(SharedPtr<Shape> shape) override
{
mTextIndentLevel--;
mShapesVisited++;
AppendLine(String::Format(u"End of {0}", shape->get_ShapeType()));
}
VisitorAction VisitGroupShapeStart(SharedPtr<GroupShape> groupShape) override
{
AppendLine(String::Format(u"Shape group found: {0}", groupShape->get_ShapeType()));
mTextIndentLevel++;
}
VisitorAction VisitGroupShapeEnd(SharedPtr<GroupShape> groupShape) override
{
mTextIndentLevel--;
AppendLine(String::Format(u"End of {0}", groupShape->get_ShapeType()));
}
private:
int mShapesVisited;
int mTextIndentLevel;
SharedPtr<System::Text::StringBuilder> mStringBuilder;
void AppendLine(String text)
{
for (int i = 0; i < mTextIndentLevel; i++)
{
mStringBuilder->Append(u'\t');
}
mStringBuilder->AppendLine(text);
}
};

Implements Aspose::Words::Node.

◆ get_Chart()

System::SharedPtr<Aspose::Words::Drawing::Charts::Chart> Aspose::Words::Drawing::Shape::get_Chart ( )

Provides access to the chart properties if this shape has a Chart.

Examples

Shows how to iterate over all the shapes in a document.

void VisitShapes()
{
auto doc = MakeObject<Document>(MyDir + u"Revision shape.docx");
auto visitor = MakeObject<ExShape::ShapeAppearancePrinter>();
doc->Accept(visitor);
std::cout << visitor->GetText() << std::endl;
}
class ShapeAppearancePrinter : public DocumentVisitor
{
public:
ShapeAppearancePrinter() : mShapesVisited(0), mTextIndentLevel(0)
{
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = MakeObject<System::Text::StringBuilder>();
}
String GetText()
{
return String::Format(u"Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
VisitorAction VisitShapeStart(SharedPtr<Shape> shape) override
{
AppendLine(String::Format(u"Shape found: {0}", shape->get_ShapeType()));
mTextIndentLevel++;
if (shape->get_HasChart())
{
AppendLine(String::Format(u"Has chart: {0}", shape->get_Chart()->get_Title()->get_Text()));
}
AppendLine(String::Format(u"Extrusion enabled: {0}", shape->get_ExtrusionEnabled()));
AppendLine(String::Format(u"Shadow enabled: {0}", shape->get_ShadowEnabled()));
AppendLine(String::Format(u"StoryType: {0}", shape->get_StoryType()));
if (shape->get_Stroked())
{
ASPOSE_EXPECT_EQ(shape->get_Stroke()->get_Color(), shape->get_StrokeColor());
AppendLine(String::Format(u"Stroke colors: {0}, {1}", shape->get_Stroke()->get_Color(), shape->get_Stroke()->get_Color2()));
AppendLine(String::Format(u"Stroke weight: {0}", shape->get_StrokeWeight()));
}
if (shape->get_Filled())
{
AppendLine(String::Format(u"Filled: {0}", shape->get_FillColor()));
}
if (shape->get_OleFormat() != nullptr)
{
AppendLine(String::Format(u"Ole found of type: {0}", shape->get_OleFormat()->get_ProgId()));
}
if (shape->get_SignatureLine() != nullptr)
{
AppendLine(String::Format(u"Found signature line for: {0}, {1}", shape->get_SignatureLine()->get_Signer(),
shape->get_SignatureLine()->get_SignerTitle()));
}
}
VisitorAction VisitShapeEnd(SharedPtr<Shape> shape) override
{
mTextIndentLevel--;
mShapesVisited++;
AppendLine(String::Format(u"End of {0}", shape->get_ShapeType()));
}
VisitorAction VisitGroupShapeStart(SharedPtr<GroupShape> groupShape) override
{
AppendLine(String::Format(u"Shape group found: {0}", groupShape->get_ShapeType()));
mTextIndentLevel++;
}
VisitorAction VisitGroupShapeEnd(SharedPtr<GroupShape> groupShape) override
{
mTextIndentLevel--;
AppendLine(String::Format(u"End of {0}", groupShape->get_ShapeType()));
}
private:
int mShapesVisited;
int mTextIndentLevel;
SharedPtr<System::Text::StringBuilder> mStringBuilder;
void AppendLine(String text)
{
for (int i = 0; i < mTextIndentLevel; i++)
{
mStringBuilder->Append(u'\t');
}
mStringBuilder->AppendLine(text);
}
};

◆ get_ExtrusionEnabled()

bool Aspose::Words::Drawing::Shape::get_ExtrusionEnabled ( )

Returns true if an extrusion effect is enabled.

Examples

Shows how to iterate over all the shapes in a document.

void VisitShapes()
{
auto doc = MakeObject<Document>(MyDir + u"Revision shape.docx");
auto visitor = MakeObject<ExShape::ShapeAppearancePrinter>();
doc->Accept(visitor);
std::cout << visitor->GetText() << std::endl;
}
class ShapeAppearancePrinter : public DocumentVisitor
{
public:
ShapeAppearancePrinter() : mShapesVisited(0), mTextIndentLevel(0)
{
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = MakeObject<System::Text::StringBuilder>();
}
String GetText()
{
return String::Format(u"Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
VisitorAction VisitShapeStart(SharedPtr<Shape> shape) override
{
AppendLine(String::Format(u"Shape found: {0}", shape->get_ShapeType()));
mTextIndentLevel++;
if (shape->get_HasChart())
{
AppendLine(String::Format(u"Has chart: {0}", shape->get_Chart()->get_Title()->get_Text()));
}
AppendLine(String::Format(u"Extrusion enabled: {0}", shape->get_ExtrusionEnabled()));
AppendLine(String::Format(u"Shadow enabled: {0}", shape->get_ShadowEnabled()));
AppendLine(String::Format(u"StoryType: {0}", shape->get_StoryType()));
if (shape->get_Stroked())
{
ASPOSE_EXPECT_EQ(shape->get_Stroke()->get_Color(), shape->get_StrokeColor());
AppendLine(String::Format(u"Stroke colors: {0}, {1}", shape->get_Stroke()->get_Color(), shape->get_Stroke()->get_Color2()));
AppendLine(String::Format(u"Stroke weight: {0}", shape->get_StrokeWeight()));
}
if (shape->get_Filled())
{
AppendLine(String::Format(u"Filled: {0}", shape->get_FillColor()));
}
if (shape->get_OleFormat() != nullptr)
{
AppendLine(String::Format(u"Ole found of type: {0}", shape->get_OleFormat()->get_ProgId()));
}
if (shape->get_SignatureLine() != nullptr)
{
AppendLine(String::Format(u"Found signature line for: {0}, {1}", shape->get_SignatureLine()->get_Signer(),
shape->get_SignatureLine()->get_SignerTitle()));
}
}
VisitorAction VisitShapeEnd(SharedPtr<Shape> shape) override
{
mTextIndentLevel--;
mShapesVisited++;
AppendLine(String::Format(u"End of {0}", shape->get_ShapeType()));
}
VisitorAction VisitGroupShapeStart(SharedPtr<GroupShape> groupShape) override
{
AppendLine(String::Format(u"Shape group found: {0}", groupShape->get_ShapeType()));
mTextIndentLevel++;
}
VisitorAction VisitGroupShapeEnd(SharedPtr<GroupShape> groupShape) override
{
mTextIndentLevel--;
AppendLine(String::Format(u"End of {0}", groupShape->get_ShapeType()));
}
private:
int mShapesVisited;
int mTextIndentLevel;
SharedPtr<System::Text::StringBuilder> mStringBuilder;
void AppendLine(String text)
{
for (int i = 0; i < mTextIndentLevel; i++)
{
mStringBuilder->Append(u'\t');
}
mStringBuilder->AppendLine(text);
}
};

◆ get_FillColor()

System::Drawing::Color Aspose::Words::Drawing::Shape::get_FillColor ( )

Defines the brush color that fills the closed path of the shape.

This is a shortcut to the Color property.

The default value is White.

Examples

Shows how to fill a shape with a solid color.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Write some text, and then cover it with a floating shape.
builder->get_Font()->set_Size(32);
builder->Writeln(u"Hello world!");
25, 250, 150, WrapType::None);
// Use the "StrokeColor" property to set the color of the outline of the shape.
shape->set_StrokeColor(System::Drawing::Color::get_CadetBlue());
// Use the "FillColor" property to set the color of the inside area of the shape.
shape->set_FillColor(System::Drawing::Color::get_LightBlue());
// The "Opacity" property determines how transparent the color is on a 0-1 scale,
// with 1 being fully opaque, and 0 being invisible.
// The shape fill by default is fully opaque, so we cannot see the text that this shape is on top of.
ASPOSE_ASSERT_EQ(1.0, shape->get_Fill()->get_Opacity());
// Set the shape fill color's opacity to a lower value so that we can see the text underneath it.
shape->get_Fill()->set_Opacity(0.3);
doc->Save(ArtifactsDir + u"Shape.Fill.docx");

◆ get_Filled()

bool Aspose::Words::Drawing::Shape::get_Filled ( )

Determines whether the closed path of the shape will be filled.

This is a shortcut to the On property.

The default value is true.

Examples

Shows how to iterate over all the shapes in a document.

void VisitShapes()
{
auto doc = MakeObject<Document>(MyDir + u"Revision shape.docx");
auto visitor = MakeObject<ExShape::ShapeAppearancePrinter>();
doc->Accept(visitor);
std::cout << visitor->GetText() << std::endl;
}
class ShapeAppearancePrinter : public DocumentVisitor
{
public:
ShapeAppearancePrinter() : mShapesVisited(0), mTextIndentLevel(0)
{
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = MakeObject<System::Text::StringBuilder>();
}
String GetText()
{
return String::Format(u"Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
VisitorAction VisitShapeStart(SharedPtr<Shape> shape) override
{
AppendLine(String::Format(u"Shape found: {0}", shape->get_ShapeType()));
mTextIndentLevel++;
if (shape->get_HasChart())
{
AppendLine(String::Format(u"Has chart: {0}", shape->get_Chart()->get_Title()->get_Text()));
}
AppendLine(String::Format(u"Extrusion enabled: {0}", shape->get_ExtrusionEnabled()));
AppendLine(String::Format(u"Shadow enabled: {0}", shape->get_ShadowEnabled()));
AppendLine(String::Format(u"StoryType: {0}", shape->get_StoryType()));
if (shape->get_Stroked())
{
ASPOSE_EXPECT_EQ(shape->get_Stroke()->get_Color(), shape->get_StrokeColor());
AppendLine(String::Format(u"Stroke colors: {0}, {1}", shape->get_Stroke()->get_Color(), shape->get_Stroke()->get_Color2()));
AppendLine(String::Format(u"Stroke weight: {0}", shape->get_StrokeWeight()));
}
if (shape->get_Filled())
{
AppendLine(String::Format(u"Filled: {0}", shape->get_FillColor()));
}
if (shape->get_OleFormat() != nullptr)
{
AppendLine(String::Format(u"Ole found of type: {0}", shape->get_OleFormat()->get_ProgId()));
}
if (shape->get_SignatureLine() != nullptr)
{
AppendLine(String::Format(u"Found signature line for: {0}, {1}", shape->get_SignatureLine()->get_Signer(),
shape->get_SignatureLine()->get_SignerTitle()));
}
}
VisitorAction VisitShapeEnd(SharedPtr<Shape> shape) override
{
mTextIndentLevel--;
mShapesVisited++;
AppendLine(String::Format(u"End of {0}", shape->get_ShapeType()));
}
VisitorAction VisitGroupShapeStart(SharedPtr<GroupShape> groupShape) override
{
AppendLine(String::Format(u"Shape group found: {0}", groupShape->get_ShapeType()));
mTextIndentLevel++;
}
VisitorAction VisitGroupShapeEnd(SharedPtr<GroupShape> groupShape) override
{
mTextIndentLevel--;
AppendLine(String::Format(u"End of {0}", groupShape->get_ShapeType()));
}
private:
int mShapesVisited;
int mTextIndentLevel;
SharedPtr<System::Text::StringBuilder> mStringBuilder;
void AppendLine(String text)
{
for (int i = 0; i < mTextIndentLevel; i++)
{
mStringBuilder->Append(u'\t');
}
mStringBuilder->AppendLine(text);
}
};

◆ get_FirstParagraph()

System::SharedPtr<Aspose::Words::Paragraph> Aspose::Words::Drawing::Shape::get_FirstParagraph ( )

Gets the first paragraph in the shape.

Examples

Shows how to create and format a text box.

auto doc = MakeObject<Document>();
// Create a floating text box.
auto textBox = MakeObject<Shape>(doc, ShapeType::TextBox);
textBox->set_WrapType(WrapType::None);
textBox->set_Height(50);
textBox->set_Width(200);
// Set the horizontal, and vertical alignment of the text inside the shape.
textBox->set_HorizontalAlignment(HorizontalAlignment::Center);
textBox->set_VerticalAlignment(VerticalAlignment::Top);
// Add a paragraph to the text box and add a run of text that the text box will display.
textBox->AppendChild(MakeObject<Paragraph>(doc));
SharedPtr<Paragraph> para = textBox->get_FirstParagraph();
para->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Center);
auto run = MakeObject<Run>(doc);
run->set_Text(u"Hello world!");
para->AppendChild(run);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(textBox);
doc->Save(ArtifactsDir + u"Shape.CreateTextBox.docx");

◆ get_HasChart()

bool Aspose::Words::Drawing::Shape::get_HasChart ( )

Returns true if this Shape has a Chart.

Examples

Shows how to iterate over all the shapes in a document.

void VisitShapes()
{
auto doc = MakeObject<Document>(MyDir + u"Revision shape.docx");
auto visitor = MakeObject<ExShape::ShapeAppearancePrinter>();
doc->Accept(visitor);
std::cout << visitor->GetText() << std::endl;
}
class ShapeAppearancePrinter : public DocumentVisitor
{
public:
ShapeAppearancePrinter() : mShapesVisited(0), mTextIndentLevel(0)
{
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = MakeObject<System::Text::StringBuilder>();
}
String GetText()
{
return String::Format(u"Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
VisitorAction VisitShapeStart(SharedPtr<Shape> shape) override
{
AppendLine(String::Format(u"Shape found: {0}", shape->get_ShapeType()));
mTextIndentLevel++;
if (shape->get_HasChart())
{
AppendLine(String::Format(u"Has chart: {0}", shape->get_Chart()->get_Title()->get_Text()));
}
AppendLine(String::Format(u"Extrusion enabled: {0}", shape->get_ExtrusionEnabled()));
AppendLine(String::Format(u"Shadow enabled: {0}", shape->get_ShadowEnabled()));
AppendLine(String::Format(u"StoryType: {0}", shape->get_StoryType()));
if (shape->get_Stroked())
{
ASPOSE_EXPECT_EQ(shape->get_Stroke()->get_Color(), shape->get_StrokeColor());
AppendLine(String::Format(u"Stroke colors: {0}, {1}", shape->get_Stroke()->get_Color(), shape->get_Stroke()->get_Color2()));
AppendLine(String::Format(u"Stroke weight: {0}", shape->get_StrokeWeight()));
}
if (shape->get_Filled())
{
AppendLine(String::Format(u"Filled: {0}", shape->get_FillColor()));
}
if (shape->get_OleFormat() != nullptr)
{
AppendLine(String::Format(u"Ole found of type: {0}", shape->get_OleFormat()->get_ProgId()));
}
if (shape->get_SignatureLine() != nullptr)
{
AppendLine(String::Format(u"Found signature line for: {0}, {1}", shape->get_SignatureLine()->get_Signer(),
shape->get_SignatureLine()->get_SignerTitle()));
}
}
VisitorAction VisitShapeEnd(SharedPtr<Shape> shape) override
{
mTextIndentLevel--;
mShapesVisited++;
AppendLine(String::Format(u"End of {0}", shape->get_ShapeType()));
}
VisitorAction VisitGroupShapeStart(SharedPtr<GroupShape> groupShape) override
{
AppendLine(String::Format(u"Shape group found: {0}", groupShape->get_ShapeType()));
mTextIndentLevel++;
}
VisitorAction VisitGroupShapeEnd(SharedPtr<GroupShape> groupShape) override
{
mTextIndentLevel--;
AppendLine(String::Format(u"End of {0}", groupShape->get_ShapeType()));
}
private:
int mShapesVisited;
int mTextIndentLevel;
SharedPtr<System::Text::StringBuilder> mStringBuilder;
void AppendLine(String text)
{
for (int i = 0; i < mTextIndentLevel; i++)
{
mStringBuilder->Append(u'\t');
}
mStringBuilder->AppendLine(text);
}
};

◆ get_HasImage()

bool Aspose::Words::Drawing::Shape::get_HasImage ( )

Returns true if the shape has image bytes or links an image.

Examples

Shows how to extract images from a document, and save them to the local file system as individual files.

auto doc = MakeObject<Document>(MyDir + u"Images.docx");
// Get the collection of shapes from the document,
// and save the image data of every shape with an image as a file to the local file system.
SharedPtr<NodeCollection> shapes = doc->GetChildNodes(NodeType::Shape, true);
ASSERT_EQ(9, shapes->LINQ_Count([](SharedPtr<Node> s) { return (System::DynamicCast<Shape>(s))->get_HasImage(); }));
int imageIndex = 0;
for (const auto& shape : System::IterateOver(shapes->LINQ_OfType<SharedPtr<Shape>>()))
{
if (shape->get_HasImage())
{
// The image data of shapes may contain images of many possible image formats.
// We can determine a file extension for each image automatically, based on its format.
String imageFileName =
String::Format(u"File.ExtractImages.{0}{1}", imageIndex, FileFormatUtil::ImageTypeToExtension(shape->get_ImageData()->get_ImageType()));
shape->get_ImageData()->Save(ArtifactsDir + imageFileName);
imageIndex++;
}
}

Shows how to delete all shapes with images from a document.

auto doc = MakeObject<Document>(MyDir + u"Images.docx");
SharedPtr<NodeCollection> shapes = doc->GetChildNodes(NodeType::Shape, true);
ASSERT_EQ(9, shapes->LINQ_OfType<SharedPtr<Shape>>()->LINQ_Count([](SharedPtr<Shape> s) { return s->get_HasImage(); }));
for (const auto& shape : System::IterateOver(shapes->LINQ_OfType<SharedPtr<Shape>>()))
{
if (shape->get_HasImage())
{
shape->Remove();
}
}
ASSERT_EQ(0, shapes->LINQ_OfType<SharedPtr<Shape>>()->LINQ_Count([](SharedPtr<Shape> s) { return s->get_HasImage(); }));

◆ get_HasSmartArt()

bool Aspose::Words::Drawing::Shape::get_HasSmartArt ( )

Returns true if this Shape has a SmartArt object.

Examples

Shows how to count the number of shapes in a document with SmartArt objects.

auto doc = MakeObject<Document>(MyDir + u"SmartArt.docx");
int numberOfSmartArtShapes = doc->GetChildNodes(NodeType::Shape, true)
->LINQ_Cast<SharedPtr<Shape>>()
->LINQ_Count([](SharedPtr<Shape> shape) { return shape->get_HasSmartArt(); });
ASSERT_EQ(2, numberOfSmartArtShapes);

◆ get_HorizontalRuleFormat()

System::SharedPtr<Aspose::Words::Drawing::HorizontalRuleFormat> Aspose::Words::Drawing::Shape::get_HorizontalRuleFormat ( )

Provides access to the properties of the horizontal rule shape. For a shape that is not a horizontal rule, returns null.

Examples

Shows how to insert a horizontal rule shape, and customize its formatting.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Shape> shape = builder->InsertHorizontalRule();
SharedPtr<HorizontalRuleFormat> horizontalRuleFormat = shape->get_HorizontalRuleFormat();
horizontalRuleFormat->set_Alignment(HorizontalRuleAlignment::Center);
horizontalRuleFormat->set_WidthPercent(70);
horizontalRuleFormat->set_Height(3);
horizontalRuleFormat->set_Color(System::Drawing::Color::get_Blue());
horizontalRuleFormat->set_NoShade(true);
ASSERT_TRUE(shape->get_IsHorizontalRule());
ASSERT_TRUE(shape->get_HorizontalRuleFormat()->get_NoShade());

◆ get_ImageData()

System::SharedPtr<Aspose::Words::Drawing::ImageData> Aspose::Words::Drawing::Shape::get_ImageData ( )

Provides access to the image of the shape. Returns null if the shape cannot have an image.

Examples

Shows how to extract images from a document, and save them to the local file system as individual files.

auto doc = MakeObject<Document>(MyDir + u"Images.docx");
// Get the collection of shapes from the document,
// and save the image data of every shape with an image as a file to the local file system.
SharedPtr<NodeCollection> shapes = doc->GetChildNodes(NodeType::Shape, true);
ASSERT_EQ(9, shapes->LINQ_Count([](SharedPtr<Node> s) { return (System::DynamicCast<Shape>(s))->get_HasImage(); }));
int imageIndex = 0;
for (const auto& shape : System::IterateOver(shapes->LINQ_OfType<SharedPtr<Shape>>()))
{
if (shape->get_HasImage())
{
// The image data of shapes may contain images of many possible image formats.
// We can determine a file extension for each image automatically, based on its format.
String imageFileName =
String::Format(u"File.ExtractImages.{0}{1}", imageIndex, FileFormatUtil::ImageTypeToExtension(shape->get_ImageData()->get_ImageType()));
shape->get_ImageData()->Save(ArtifactsDir + imageFileName);
imageIndex++;
}
}

Shows how to insert a linked image into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
String imageFileName = ImageDir + u"Windows MetaFile.wmf";
// Below are two ways of applying an image to a shape so that it can display it.
// 1 - Set the shape to contain the image.
auto shape = MakeObject<Shape>(builder->get_Document(), ShapeType::Image);
shape->set_WrapType(WrapType::Inline);
shape->get_ImageData()->SetImage(imageFileName);
builder->InsertNode(shape);
doc->Save(ArtifactsDir + u"Image.CreateLinkedImage.Embedded.docx");
// Every image that we store in shape will increase the size of our document.
ASSERT_TRUE(70000 < MakeObject<System::IO::FileInfo>(ArtifactsDir + u"Image.CreateLinkedImage.Embedded.docx")->get_Length());
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->RemoveAllChildren();
// 2 - Set the shape to link to an image file in the local file system.
shape = MakeObject<Shape>(builder->get_Document(), ShapeType::Image);
shape->set_WrapType(WrapType::Inline);
shape->get_ImageData()->set_SourceFullName(imageFileName);
builder->InsertNode(shape);
doc->Save(ArtifactsDir + u"Image.CreateLinkedImage.Linked.docx");
// Linking to images will save space and result in a smaller document.
// However, the document can only display the image correctly while
// the image file is present at the location that the shape's "SourceFullName" property points to.
ASSERT_TRUE(10000 > MakeObject<System::IO::FileInfo>(ArtifactsDir + u"Image.CreateLinkedImage.Linked.docx")->get_Length());

◆ get_LastParagraph()

System::SharedPtr<Aspose::Words::Paragraph> Aspose::Words::Drawing::Shape::get_LastParagraph ( )

Gets the last paragraph in the shape.

Examples

Shows how to set the orientation of text inside a text box.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Shape> textBoxShape = builder->InsertShape(ShapeType::TextBox, 150, 100);
SharedPtr<TextBox> textBox = textBoxShape->get_TextBox();
// Move the document builder to inside the TextBox and add text.
builder->MoveTo(textBoxShape->get_LastParagraph());
builder->Writeln(u"Hello world!");
builder->Write(u"Hello again!");
// Set the "LayoutFlow" property to set an orientation for the text contents of this text box.
textBox->set_LayoutFlow(layoutFlow);
doc->Save(ArtifactsDir + u"Shape.TextBoxLayoutFlow.docx");

◆ get_NodeType()

Aspose::Words::NodeType Aspose::Words::Drawing::Shape::get_NodeType ( ) const
overridevirtual

Returns Shape.

Examples

Shows how to traverse a composite node's tree of child nodes.

void RecurseChildren()
{
auto doc = MakeObject<Document>(MyDir + u"Paragraphs.docx");
// Any node that can contain child nodes, such as the document itself, is composite.
ASSERT_TRUE(doc->get_IsComposite());
// Invoke the recursive function that will go through and print all the child nodes of a composite node.
TraverseAllNodes(doc, 0);
}
void TraverseAllNodes(SharedPtr<CompositeNode> parentNode, int depth)
{
for (SharedPtr<Node> childNode = parentNode->get_FirstChild(); childNode != nullptr; childNode = childNode->get_NextSibling())
{
std::cout << (String(u'\t', depth)) << Node::NodeTypeToString(childNode->get_NodeType());
// Recurse into the node if it is a composite node. Otherwise, print its contents if it is an inline node.
if (childNode->get_IsComposite())
{
std::cout << std::endl;
TraverseAllNodes(System::DynamicCast<CompositeNode>(childNode), depth + 1);
}
else if (System::ObjectExt::Is<Inline>(childNode))
{
std::cout << " - \"" << childNode->GetText().Trim() << "\"" << std::endl;
}
else
{
std::cout << std::endl;
}
}
}

Implements Aspose::Words::Node.

◆ get_OleFormat()

System::SharedPtr<Aspose::Words::Drawing::OleFormat> Aspose::Words::Drawing::Shape::get_OleFormat ( )

Provides access to the OLE data of a shape. For a shape that is not an OLE object or ActiveX control, returns null.

Examples

Shows how to iterate over all the shapes in a document.

void VisitShapes()
{
auto doc = MakeObject<Document>(MyDir + u"Revision shape.docx");
auto visitor = MakeObject<ExShape::ShapeAppearancePrinter>();
doc->Accept(visitor);
std::cout << visitor->GetText() << std::endl;
}
class ShapeAppearancePrinter : public DocumentVisitor
{
public:
ShapeAppearancePrinter() : mShapesVisited(0), mTextIndentLevel(0)
{
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = MakeObject<System::Text::StringBuilder>();
}
String GetText()
{
return String::Format(u"Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
VisitorAction VisitShapeStart(SharedPtr<Shape> shape) override
{
AppendLine(String::Format(u"Shape found: {0}", shape->get_ShapeType()));
mTextIndentLevel++;
if (shape->get_HasChart())
{
AppendLine(String::Format(u"Has chart: {0}", shape->get_Chart()->get_Title()->get_Text()));
}
AppendLine(String::Format(u"Extrusion enabled: {0}", shape->get_ExtrusionEnabled()));
AppendLine(String::Format(u"Shadow enabled: {0}", shape->get_ShadowEnabled()));
AppendLine(String::Format(u"StoryType: {0}", shape->get_StoryType()));
if (shape->get_Stroked())
{
ASPOSE_EXPECT_EQ(shape->get_Stroke()->get_Color(), shape->get_StrokeColor());
AppendLine(String::Format(u"Stroke colors: {0}, {1}", shape->get_Stroke()->get_Color(), shape->get_Stroke()->get_Color2()));
AppendLine(String::Format(u"Stroke weight: {0}", shape->get_StrokeWeight()));
}
if (shape->get_Filled())
{
AppendLine(String::Format(u"Filled: {0}", shape->get_FillColor()));
}
if (shape->get_OleFormat() != nullptr)
{
AppendLine(String::Format(u"Ole found of type: {0}", shape->get_OleFormat()->get_ProgId()));
}
if (shape->get_SignatureLine() != nullptr)
{
AppendLine(String::Format(u"Found signature line for: {0}, {1}", shape->get_SignatureLine()->get_Signer(),
shape->get_SignatureLine()->get_SignerTitle()));
}
}
VisitorAction VisitShapeEnd(SharedPtr<Shape> shape) override
{
mTextIndentLevel--;
mShapesVisited++;
AppendLine(String::Format(u"End of {0}", shape->get_ShapeType()));
}
VisitorAction VisitGroupShapeStart(SharedPtr<GroupShape> groupShape) override
{
AppendLine(String::Format(u"Shape group found: {0}", groupShape->get_ShapeType()));
mTextIndentLevel++;
}
VisitorAction VisitGroupShapeEnd(SharedPtr<GroupShape> groupShape) override
{
mTextIndentLevel--;
AppendLine(String::Format(u"End of {0}", groupShape->get_ShapeType()));
}
private:
int mShapesVisited;
int mTextIndentLevel;
SharedPtr<System::Text::StringBuilder> mStringBuilder;
void AppendLine(String text)
{
for (int i = 0; i < mTextIndentLevel; i++)
{
mStringBuilder->Append(u'\t');
}
mStringBuilder->AppendLine(text);
}
};

◆ get_ShadowEnabled()

bool Aspose::Words::Drawing::Shape::get_ShadowEnabled ( )

Returns true if a shadow effect is enabled.

Examples

Shows how to iterate over all the shapes in a document.

void VisitShapes()
{
auto doc = MakeObject<Document>(MyDir + u"Revision shape.docx");
auto visitor = MakeObject<ExShape::ShapeAppearancePrinter>();
doc->Accept(visitor);
std::cout << visitor->GetText() << std::endl;
}
class ShapeAppearancePrinter : public DocumentVisitor
{
public:
ShapeAppearancePrinter() : mShapesVisited(0), mTextIndentLevel(0)
{
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = MakeObject<System::Text::StringBuilder>();
}
String GetText()
{
return String::Format(u"Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
VisitorAction VisitShapeStart(SharedPtr<Shape> shape) override
{
AppendLine(String::Format(u"Shape found: {0}", shape->get_ShapeType()));
mTextIndentLevel++;
if (shape->get_HasChart())
{
AppendLine(String::Format(u"Has chart: {0}", shape->get_Chart()->get_Title()->get_Text()));
}
AppendLine(String::Format(u"Extrusion enabled: {0}", shape->get_ExtrusionEnabled()));
AppendLine(String::Format(u"Shadow enabled: {0}", shape->get_ShadowEnabled()));
AppendLine(String::Format(u"StoryType: {0}", shape->get_StoryType()));
if (shape->get_Stroked())
{
ASPOSE_EXPECT_EQ(shape->get_Stroke()->get_Color(), shape->get_StrokeColor());
AppendLine(String::Format(u"Stroke colors: {0}, {1}", shape->get_Stroke()->get_Color(), shape->get_Stroke()->get_Color2()));
AppendLine(String::Format(u"Stroke weight: {0}", shape->get_StrokeWeight()));
}
if (shape->get_Filled())
{
AppendLine(String::Format(u"Filled: {0}", shape->get_FillColor()));
}
if (shape->get_OleFormat() != nullptr)
{
AppendLine(String::Format(u"Ole found of type: {0}", shape->get_OleFormat()->get_ProgId()));
}
if (shape->get_SignatureLine() != nullptr)
{
AppendLine(String::Format(u"Found signature line for: {0}, {1}", shape->get_SignatureLine()->get_Signer(),
shape->get_SignatureLine()->get_SignerTitle()));
}
}
VisitorAction VisitShapeEnd(SharedPtr<Shape> shape) override
{
mTextIndentLevel--;
mShapesVisited++;
AppendLine(String::Format(u"End of {0}", shape->get_ShapeType()));
}
VisitorAction VisitGroupShapeStart(SharedPtr<GroupShape> groupShape) override
{
AppendLine(String::Format(u"Shape group found: {0}", groupShape->get_ShapeType()));
mTextIndentLevel++;
}
VisitorAction VisitGroupShapeEnd(SharedPtr<GroupShape> groupShape) override
{
mTextIndentLevel--;
AppendLine(String::Format(u"End of {0}", groupShape->get_ShapeType()));
}
private:
int mShapesVisited;
int mTextIndentLevel;
SharedPtr<System::Text::StringBuilder> mStringBuilder;
void AppendLine(String text)
{
for (int i = 0; i < mTextIndentLevel; i++)
{
mStringBuilder->Append(u'\t');
}
mStringBuilder->AppendLine(text);
}
};

◆ get_SignatureLine()

System::SharedPtr<Aspose::Words::Drawing::SignatureLine> Aspose::Words::Drawing::Shape::get_SignatureLine ( )

Gets SignatureLine object if the shape is a signature line. Returns null otherwise.

See also
Aspose::Words::DocumentBuilder::InsertSignatureLine(System::SharedPtr<Aspose::Words::SignatureLineOptions>, Aspose::Words::Drawing::RelativeHorizontalPosition, double, Aspose::Words::Drawing::RelativeVerticalPosition, double, Aspose::Words::Drawing::WrapType)
Examples

Shows how to create a line for a signature and insert it into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto options = MakeObject<SignatureLineOptions>();
options->set_AllowComments(true);
options->set_DefaultInstructions(true);
options->set_Email(u"john.doe@management.com");
options->set_Instructions(u"Please sign here");
options->set_ShowDate(true);
options->set_Signer(u"John Doe");
options->set_SignerTitle(u"Senior Manager");
// Insert a shape that will contain a signature line, whose appearance we will
// customize using the "SignatureLineOptions" object we have created above.
// If we insert a shape whose coordinates originate at the bottom right hand corner of the page,
// we will need to supply negative x and y coordinates to bring the shape into view.
SharedPtr<Shape> shape = builder->InsertSignatureLine(options, RelativeHorizontalPosition::RightMargin, -170.0, RelativeVerticalPosition::BottomMargin,
-60.0, WrapType::None);
ASSERT_TRUE(shape->get_IsSignatureLine());
// Verify the properties of our signature line via its Shape object.
SharedPtr<SignatureLine> signatureLine = shape->get_SignatureLine();
ASSERT_EQ(u"john.doe@management.com", signatureLine->get_Email());
ASSERT_EQ(u"John Doe", signatureLine->get_Signer());
ASSERT_EQ(u"Senior Manager", signatureLine->get_SignerTitle());
ASSERT_EQ(u"Please sign here", signatureLine->get_Instructions());
ASSERT_TRUE(signatureLine->get_ShowDate());
ASSERT_TRUE(signatureLine->get_AllowComments());
ASSERT_TRUE(signatureLine->get_DefaultInstructions());
doc->Save(ArtifactsDir + u"Shape.SignatureLine.docx");

◆ get_StoryType()

Aspose::Words::StoryType Aspose::Words::Drawing::Shape::get_StoryType ( )

Returns Textbox.

Examples

Shows how to iterate over all the shapes in a document.

void VisitShapes()
{
auto doc = MakeObject<Document>(MyDir + u"Revision shape.docx");
auto visitor = MakeObject<ExShape::ShapeAppearancePrinter>();
doc->Accept(visitor);
std::cout << visitor->GetText() << std::endl;
}
class ShapeAppearancePrinter : public DocumentVisitor
{
public:
ShapeAppearancePrinter() : mShapesVisited(0), mTextIndentLevel(0)
{
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = MakeObject<System::Text::StringBuilder>();
}
String GetText()
{
return String::Format(u"Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
VisitorAction VisitShapeStart(SharedPtr<Shape> shape) override
{
AppendLine(String::Format(u"Shape found: {0}", shape->get_ShapeType()));
mTextIndentLevel++;
if (shape->get_HasChart())
{
AppendLine(String::Format(u"Has chart: {0}", shape->get_Chart()->get_Title()->get_Text()));
}
AppendLine(String::Format(u"Extrusion enabled: {0}", shape->get_ExtrusionEnabled()));
AppendLine(String::Format(u"Shadow enabled: {0}", shape->get_ShadowEnabled()));
AppendLine(String::Format(u"StoryType: {0}", shape->get_StoryType()));
if (shape->get_Stroked())
{
ASPOSE_EXPECT_EQ(shape->get_Stroke()->get_Color(), shape->get_StrokeColor());
AppendLine(String::Format(u"Stroke colors: {0}, {1}", shape->get_Stroke()->get_Color(), shape->get_Stroke()->get_Color2()));
AppendLine(String::Format(u"Stroke weight: {0}", shape->get_StrokeWeight()));
}
if (shape->get_Filled())
{
AppendLine(String::Format(u"Filled: {0}", shape->get_FillColor()));
}
if (shape->get_OleFormat() != nullptr)
{
AppendLine(String::Format(u"Ole found of type: {0}", shape->get_OleFormat()->get_ProgId()));
}
if (shape->get_SignatureLine() != nullptr)
{
AppendLine(String::Format(u"Found signature line for: {0}, {1}", shape->get_SignatureLine()->get_Signer(),
shape->get_SignatureLine()->get_SignerTitle()));
}
}
VisitorAction VisitShapeEnd(SharedPtr<Shape> shape) override
{
mTextIndentLevel--;
mShapesVisited++;
AppendLine(String::Format(u"End of {0}", shape->get_ShapeType()));
}
VisitorAction VisitGroupShapeStart(SharedPtr<GroupShape> groupShape) override
{
AppendLine(String::Format(u"Shape group found: {0}", groupShape->get_ShapeType()));
mTextIndentLevel++;
}
VisitorAction VisitGroupShapeEnd(SharedPtr<GroupShape> groupShape) override
{
mTextIndentLevel--;
AppendLine(String::Format(u"End of {0}", groupShape->get_ShapeType()));
}
private:
int mShapesVisited;
int mTextIndentLevel;
SharedPtr<System::Text::StringBuilder> mStringBuilder;
void AppendLine(String text)
{
for (int i = 0; i < mTextIndentLevel; i++)
{
mStringBuilder->Append(u'\t');
}
mStringBuilder->AppendLine(text);
}
};

◆ get_Stroke()

System::SharedPtr<Aspose::Words::Drawing::Stroke> Aspose::Words::Drawing::Shape::get_Stroke ( )

Defines a stroke for a shape.

Examples

Shows to create a variety of shapes.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Below are four examples of shapes that we can insert into our documents.
// 1 - Dotted, horizontal, half-transparent red line
// with an arrow on the left end and a diamond on the right end:
auto arrow = MakeObject<Shape>(doc, ShapeType::Line);
arrow->set_Width(200);
arrow->get_Stroke()->set_Color(System::Drawing::Color::get_Red());
arrow->get_Stroke()->set_StartArrowType(ArrowType::Arrow);
arrow->get_Stroke()->set_StartArrowLength(ArrowLength::Long);
arrow->get_Stroke()->set_StartArrowWidth(ArrowWidth::Wide);
arrow->get_Stroke()->set_EndArrowType(ArrowType::Diamond);
arrow->get_Stroke()->set_EndArrowLength(ArrowLength::Long);
arrow->get_Stroke()->set_EndArrowWidth(ArrowWidth::Wide);
arrow->get_Stroke()->set_DashStyle(DashStyle::Dash);
arrow->get_Stroke()->set_Opacity(0.5);
ASSERT_EQ(JoinStyle::Miter, arrow->get_Stroke()->get_JoinStyle());
builder->InsertNode(arrow);
// 2 - Thick black diagonal line with rounded ends:
auto line = MakeObject<Shape>(doc, ShapeType::Line);
line->set_Top(40);
line->set_Width(200);
line->set_Height(20);
line->set_StrokeWeight(5.0);
line->get_Stroke()->set_EndCap(EndCap::Round);
builder->InsertNode(line);
// 3 - Arrow with a green fill:
auto filledInArrow = MakeObject<Shape>(doc, ShapeType::Arrow);
filledInArrow->set_Width(200);
filledInArrow->set_Height(40);
filledInArrow->set_Top(100);
filledInArrow->get_Fill()->set_ForeColor(System::Drawing::Color::get_Green());
filledInArrow->get_Fill()->set_Visible(true);
builder->InsertNode(filledInArrow);
// 4 - Arrow with a flipped orientation filled in with the Aspose logo:
auto filledInArrowImg = MakeObject<Shape>(doc, ShapeType::Arrow);
filledInArrowImg->set_Width(200);
filledInArrowImg->set_Height(40);
filledInArrowImg->set_Top(160);
filledInArrowImg->set_FlipOrientation(FlipOrientation::Both);
ArrayPtr<uint8_t> imageBytes = System::IO::File::ReadAllBytes(ImageDir + u"Logo.jpg");
{
auto stream = MakeObject<System::IO::MemoryStream>(imageBytes);
SharedPtr<System::Drawing::Image> image = System::Drawing::Image::FromStream(stream);
// When we flip the orientation of our arrow, we also flip the image that the arrow contains.
// Flip the image the other way to cancel this out before getting the shape to display it.
image->RotateFlip(System::Drawing::RotateFlipType::RotateNoneFlipXY);
filledInArrowImg->get_ImageData()->SetImage(image);
filledInArrowImg->get_Stroke()->set_JoinStyle(JoinStyle::Round);
builder->InsertNode(filledInArrowImg);
}
doc->Save(ArtifactsDir + u"Drawing.VariousShapes.docx");

◆ get_StrokeColor()

System::Drawing::Color Aspose::Words::Drawing::Shape::get_StrokeColor ( )

Defines the color of a stroke.

This is a shortcut to the Color property.

The default value is Black.

Examples

Shows how to fill a shape with a solid color.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Write some text, and then cover it with a floating shape.
builder->get_Font()->set_Size(32);
builder->Writeln(u"Hello world!");
25, 250, 150, WrapType::None);
// Use the "StrokeColor" property to set the color of the outline of the shape.
shape->set_StrokeColor(System::Drawing::Color::get_CadetBlue());
// Use the "FillColor" property to set the color of the inside area of the shape.
shape->set_FillColor(System::Drawing::Color::get_LightBlue());
// The "Opacity" property determines how transparent the color is on a 0-1 scale,
// with 1 being fully opaque, and 0 being invisible.
// The shape fill by default is fully opaque, so we cannot see the text that this shape is on top of.
ASPOSE_ASSERT_EQ(1.0, shape->get_Fill()->get_Opacity());
// Set the shape fill color's opacity to a lower value so that we can see the text underneath it.
shape->get_Fill()->set_Opacity(0.3);
doc->Save(ArtifactsDir + u"Shape.Fill.docx");

Shows how to iterate over all the shapes in a document.

void VisitShapes()
{
auto doc = MakeObject<Document>(MyDir + u"Revision shape.docx");
auto visitor = MakeObject<ExShape::ShapeAppearancePrinter>();
doc->Accept(visitor);
std::cout << visitor->GetText() << std::endl;
}
class ShapeAppearancePrinter : public DocumentVisitor
{
public:
ShapeAppearancePrinter() : mShapesVisited(0), mTextIndentLevel(0)
{
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = MakeObject<System::Text::StringBuilder>();
}
String GetText()
{
return String::Format(u"Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
VisitorAction VisitShapeStart(SharedPtr<Shape> shape) override
{
AppendLine(String::Format(u"Shape found: {0}", shape->get_ShapeType()));
mTextIndentLevel++;
if (shape->get_HasChart())
{
AppendLine(String::Format(u"Has chart: {0}", shape->get_Chart()->get_Title()->get_Text()));
}
AppendLine(String::Format(u"Extrusion enabled: {0}", shape->get_ExtrusionEnabled()));
AppendLine(String::Format(u"Shadow enabled: {0}", shape->get_ShadowEnabled()));
AppendLine(String::Format(u"StoryType: {0}", shape->get_StoryType()));
if (shape->get_Stroked())
{
ASPOSE_EXPECT_EQ(shape->get_Stroke()->get_Color(), shape->get_StrokeColor());
AppendLine(String::Format(u"Stroke colors: {0}, {1}", shape->get_Stroke()->get_Color(), shape->get_Stroke()->get_Color2()));
AppendLine(String::Format(u"Stroke weight: {0}", shape->get_StrokeWeight()));
}
if (shape->get_Filled())
{
AppendLine(String::Format(u"Filled: {0}", shape->get_FillColor()));
}
if (shape->get_OleFormat() != nullptr)
{
AppendLine(String::Format(u"Ole found of type: {0}", shape->get_OleFormat()->get_ProgId()));
}
if (shape->get_SignatureLine() != nullptr)
{
AppendLine(String::Format(u"Found signature line for: {0}, {1}", shape->get_SignatureLine()->get_Signer(),
shape->get_SignatureLine()->get_SignerTitle()));
}
}
VisitorAction VisitShapeEnd(SharedPtr<Shape> shape) override
{
mTextIndentLevel--;
mShapesVisited++;
AppendLine(String::Format(u"End of {0}", shape->get_ShapeType()));
}
VisitorAction VisitGroupShapeStart(SharedPtr<GroupShape> groupShape) override
{
AppendLine(String::Format(u"Shape group found: {0}", groupShape->get_ShapeType()));
mTextIndentLevel++;
}
VisitorAction VisitGroupShapeEnd(SharedPtr<GroupShape> groupShape) override
{
mTextIndentLevel--;
AppendLine(String::Format(u"End of {0}", groupShape->get_ShapeType()));
}
private:
int mShapesVisited;
int mTextIndentLevel;
SharedPtr<System::Text::StringBuilder> mStringBuilder;
void AppendLine(String text)
{
for (int i = 0; i < mTextIndentLevel; i++)
{
mStringBuilder->Append(u'\t');
}
mStringBuilder->AppendLine(text);
}
};

◆ get_Stroked()

bool Aspose::Words::Drawing::Shape::get_Stroked ( )

Defines whether the path will be stroked.

This is a shortcut to the On property.

The default value is true.

Examples

Shows how to iterate over all the shapes in a document.

void VisitShapes()
{
auto doc = MakeObject<Document>(MyDir + u"Revision shape.docx");
auto visitor = MakeObject<ExShape::ShapeAppearancePrinter>();
doc->Accept(visitor);
std::cout << visitor->GetText() << std::endl;
}
class ShapeAppearancePrinter : public DocumentVisitor
{
public:
ShapeAppearancePrinter() : mShapesVisited(0), mTextIndentLevel(0)
{
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = MakeObject<System::Text::StringBuilder>();
}
String GetText()
{
return String::Format(u"Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
VisitorAction VisitShapeStart(SharedPtr<Shape> shape) override
{
AppendLine(String::Format(u"Shape found: {0}", shape->get_ShapeType()));
mTextIndentLevel++;
if (shape->get_HasChart())
{
AppendLine(String::Format(u"Has chart: {0}", shape->get_Chart()->get_Title()->get_Text()));
}
AppendLine(String::Format(u"Extrusion enabled: {0}", shape->get_ExtrusionEnabled()));
AppendLine(String::Format(u"Shadow enabled: {0}", shape->get_ShadowEnabled()));
AppendLine(String::Format(u"StoryType: {0}", shape->get_StoryType()));
if (shape->get_Stroked())
{
ASPOSE_EXPECT_EQ(shape->get_Stroke()->get_Color(), shape->get_StrokeColor());
AppendLine(String::Format(u"Stroke colors: {0}, {1}", shape->get_Stroke()->get_Color(), shape->get_Stroke()->get_Color2()));
AppendLine(String::Format(u"Stroke weight: {0}", shape->get_StrokeWeight()));
}
if (shape->get_Filled())
{
AppendLine(String::Format(u"Filled: {0}", shape->get_FillColor()));
}
if (shape->get_OleFormat() != nullptr)
{
AppendLine(String::Format(u"Ole found of type: {0}", shape->get_OleFormat()->get_ProgId()));
}
if (shape->get_SignatureLine() != nullptr)
{
AppendLine(String::Format(u"Found signature line for: {0}, {1}", shape->get_SignatureLine()->get_Signer(),
shape->get_SignatureLine()->get_SignerTitle()));
}
}
VisitorAction VisitShapeEnd(SharedPtr<Shape> shape) override
{
mTextIndentLevel--;
mShapesVisited++;
AppendLine(String::Format(u"End of {0}", shape->get_ShapeType()));
}
VisitorAction VisitGroupShapeStart(SharedPtr<GroupShape> groupShape) override
{
AppendLine(String::Format(u"Shape group found: {0}", groupShape->get_ShapeType()));
mTextIndentLevel++;
}
VisitorAction VisitGroupShapeEnd(SharedPtr<GroupShape> groupShape) override
{
mTextIndentLevel--;
AppendLine(String::Format(u"End of {0}", groupShape->get_ShapeType()));
}
private:
int mShapesVisited;
int mTextIndentLevel;
SharedPtr<System::Text::StringBuilder> mStringBuilder;
void AppendLine(String text)
{
for (int i = 0; i < mTextIndentLevel; i++)
{
mStringBuilder->Append(u'\t');
}
mStringBuilder->AppendLine(text);
}
};

◆ get_StrokeWeight()

double Aspose::Words::Drawing::Shape::get_StrokeWeight ( )

Defines the brush thickness that strokes the path of a shape in points.

This is a shortcut to the Weight property.

The default value is 0.75.

Examples

Shows how to iterate over all the shapes in a document.

void VisitShapes()
{
auto doc = MakeObject<Document>(MyDir + u"Revision shape.docx");
auto visitor = MakeObject<ExShape::ShapeAppearancePrinter>();
doc->Accept(visitor);
std::cout << visitor->GetText() << std::endl;
}
class ShapeAppearancePrinter : public DocumentVisitor
{
public:
ShapeAppearancePrinter() : mShapesVisited(0), mTextIndentLevel(0)
{
mShapesVisited = 0;
mTextIndentLevel = 0;
mStringBuilder = MakeObject<System::Text::StringBuilder>();
}
String GetText()
{
return String::Format(u"Shapes visited: {0}\n{1}", mShapesVisited, mStringBuilder);
}
VisitorAction VisitShapeStart(SharedPtr<Shape> shape) override
{
AppendLine(String::Format(u"Shape found: {0}", shape->get_ShapeType()));
mTextIndentLevel++;
if (shape->get_HasChart())
{
AppendLine(String::Format(u"Has chart: {0}", shape->get_Chart()->get_Title()->get_Text()));
}
AppendLine(String::Format(u"Extrusion enabled: {0}", shape->get_ExtrusionEnabled()));
AppendLine(String::Format(u"Shadow enabled: {0}", shape->get_ShadowEnabled()));
AppendLine(String::Format(u"StoryType: {0}", shape->get_StoryType()));
if (shape->get_Stroked())
{
ASPOSE_EXPECT_EQ(shape->get_Stroke()->get_Color(), shape->get_StrokeColor());
AppendLine(String::Format(u"Stroke colors: {0}, {1}", shape->get_Stroke()->get_Color(), shape->get_Stroke()->get_Color2()));
AppendLine(String::Format(u"Stroke weight: {0}", shape->get_StrokeWeight()));
}
if (shape->get_Filled())
{
AppendLine(String::Format(u"Filled: {0}", shape->get_FillColor()));
}
if (shape->get_OleFormat() != nullptr)
{
AppendLine(String::Format(u"Ole found of type: {0}", shape->get_OleFormat()->get_ProgId()));
}
if (shape->get_SignatureLine() != nullptr)
{
AppendLine(String::Format(u"Found signature line for: {0}, {1}", shape->get_SignatureLine()->get_Signer(),
shape->get_SignatureLine()->get_SignerTitle()));
}
}
VisitorAction VisitShapeEnd(SharedPtr<Shape> shape) override
{
mTextIndentLevel--;
mShapesVisited++;
AppendLine(String::Format(u"End of {0}", shape->get_ShapeType()));
}
VisitorAction VisitGroupShapeStart(SharedPtr<GroupShape> groupShape) override
{
AppendLine(String::Format(u"Shape group found: {0}", groupShape->get_ShapeType()));
mTextIndentLevel++;
}
VisitorAction VisitGroupShapeEnd(SharedPtr<GroupShape> groupShape) override
{
mTextIndentLevel--;
AppendLine(String::Format(u"End of {0}", groupShape->get_ShapeType()));
}
private:
int mShapesVisited;
int mTextIndentLevel;
SharedPtr<System::Text::StringBuilder> mStringBuilder;
void AppendLine(String text)
{
for (int i = 0; i < mTextIndentLevel; i++)
{
mStringBuilder->Append(u'\t');
}
mStringBuilder->AppendLine(text);
}
};

◆ get_TextBox()

System::SharedPtr<Aspose::Words::Drawing::TextBox> Aspose::Words::Drawing::Shape::get_TextBox ( )

Defines attributes that specify how text is displayed in a shape.

Examples

Shows how to set the orientation of text inside a text box.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Shape> textBoxShape = builder->InsertShape(ShapeType::TextBox, 150, 100);
SharedPtr<TextBox> textBox = textBoxShape->get_TextBox();
// Move the document builder to inside the TextBox and add text.
builder->MoveTo(textBoxShape->get_LastParagraph());
builder->Writeln(u"Hello world!");
builder->Write(u"Hello again!");
// Set the "LayoutFlow" property to set an orientation for the text contents of this text box.
textBox->set_LayoutFlow(layoutFlow);
doc->Save(ArtifactsDir + u"Shape.TextBoxLayoutFlow.docx");

◆ get_TextPath()

System::SharedPtr<Aspose::Words::Drawing::TextPath> Aspose::Words::Drawing::Shape::get_TextPath ( )

Defines the text of the text path (of a WordArt object).

Examples

Shows how to work with WordArt.

void InsertTextPaths()
{
auto doc = MakeObject<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.
SharedPtr<Shape> shape = AppendWordArt(doc, u"Hello World! This text is bold, and italic.", u"Arial", 480, 24, System::Drawing::Color::get_White(),
// Apply the "Bold' and "Italic" formatting settings to the text using the respective properties.
shape->get_TextPath()->set_Bold(true);
shape->get_TextPath()->set_Italic(true);
// Below are various other text formatting-related properties.
ASSERT_FALSE(shape->get_TextPath()->get_Underline());
ASSERT_FALSE(shape->get_TextPath()->get_Shadow());
ASSERT_FALSE(shape->get_TextPath()->get_StrikeThrough());
ASSERT_FALSE(shape->get_TextPath()->get_ReverseRows());
ASSERT_FALSE(shape->get_TextPath()->get_XScale());
ASSERT_FALSE(shape->get_TextPath()->get_Trim());
ASSERT_FALSE(shape->get_TextPath()->get_SmallCaps());
ASPOSE_ASSERT_EQ(36.0, shape->get_TextPath()->get_Size());
ASSERT_EQ(u"Hello World! This text is bold, and italic.", shape->get_TextPath()->get_Text());
ASSERT_EQ(ShapeType::TextPlainText, shape->get_ShapeType());
// Use the "On" property to show/hide the text.
shape = AppendWordArt(doc, u"On set to \"true\"", u"Calibri", 150, 24, System::Drawing::Color::get_Yellow(), System::Drawing::Color::get_Red(),
shape->get_TextPath()->set_On(true);
shape = AppendWordArt(doc, u"On set to \"false\"", u"Calibri", 150, 24, System::Drawing::Color::get_Yellow(), System::Drawing::Color::get_Purple(),
shape->get_TextPath()->set_On(false);
// Use the "Kerning" property to enable/disable kerning spacing between certain characters.
shape = AppendWordArt(doc, u"Kerning: VAV", u"Times New Roman", 90, 24, System::Drawing::Color::get_Orange(), System::Drawing::Color::get_Red(),
shape->get_TextPath()->set_Kerning(true);
shape = AppendWordArt(doc, u"No kerning: VAV", u"Times New Roman", 100, 24, System::Drawing::Color::get_Orange(), System::Drawing::Color::get_Red(),
shape->get_TextPath()->set_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 = AppendWordArt(doc, u"Spacing set to 0.1", u"Calibri", 120, 24, System::Drawing::Color::get_BlueViolet(), System::Drawing::Color::get_Blue(),
shape->get_TextPath()->set_Spacing(0.1);
// Set the "RotateLetters" property to "true" to rotate each character 90 degrees counterclockwise.
shape = AppendWordArt(doc, u"RotateLetters", u"Calibri", 200, 36, System::Drawing::Color::get_GreenYellow(), System::Drawing::Color::get_Green(),
shape->get_TextPath()->set_RotateLetters(true);
// Set the "SameLetterHeights" property to "true" to get the x-height of each character to equal the cap height.
shape = AppendWordArt(doc, u"Same character height for lower and UPPER case", u"Calibri", 300, 24, System::Drawing::Color::get_DeepSkyBlue(),
shape->get_TextPath()->set_SameLetterHeights(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, u"FitShape on", u"Calibri", 160, 24, System::Drawing::Color::get_LightBlue(), System::Drawing::Color::get_Blue(),
ASSERT_TRUE(shape->get_TextPath()->get_FitShape());
shape->get_TextPath()->set_Size(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, u"FitShape off", u"Calibri", 160, 24, System::Drawing::Color::get_LightBlue(), System::Drawing::Color::get_Blue(),
shape->get_TextPath()->set_FitShape(false);
shape->get_TextPath()->set_Size(24.0);
shape->get_TextPath()->set_TextPathAlignment(TextPathAlignment::Right);
doc->Save(ArtifactsDir + u"Shape.InsertTextPaths.docx");
}
static SharedPtr<Shape> AppendWordArt(SharedPtr<Document> doc, String text, String textFontFamily, double shapeWidth, double shapeHeight,
System::Drawing::Color wordArtFill, System::Drawing::Color line, ShapeType wordArtShapeType)
{
// 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".
auto shape = MakeObject<Shape>(doc, wordArtShapeType);
shape->set_WrapType(WrapType::Inline);
shape->set_Width(shapeWidth);
shape->set_Height(shapeHeight);
shape->set_FillColor(wordArtFill);
shape->set_StrokeColor(line);
shape->get_TextPath()->set_Text(text);
shape->get_TextPath()->set_FontFamily(textFontFamily);
auto para = System::DynamicCast<Paragraph>(doc->get_FirstSection()->get_Body()->AppendChild(MakeObject<Paragraph>(doc)));
para->AppendChild(shape);
return shape;
}

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Drawing::Shape::GetType ( ) const
overridevirtual

Reimplemented from Aspose::Words::Drawing::ShapeBase.

◆ Is()

virtual bool Aspose::Words::Drawing::Shape::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from Aspose::Words::Drawing::ShapeBase.

◆ set_FillColor()

void Aspose::Words::Drawing::Shape::set_FillColor ( System::Drawing::Color  value)

◆ set_Filled()

void Aspose::Words::Drawing::Shape::set_Filled ( bool  value)

◆ set_StrokeColor()

void Aspose::Words::Drawing::Shape::set_StrokeColor ( System::Drawing::Color  value)

◆ set_Stroked()

void Aspose::Words::Drawing::Shape::set_Stroked ( bool  value)

◆ set_StrokeWeight()

void Aspose::Words::Drawing::Shape::set_StrokeWeight ( double  value)

◆ Type()

static const System::TypeInfo& Aspose::Words::Drawing::Shape::Type ( )
static

◆ UpdateSmartArtDrawing()

void Aspose::Words::Drawing::Shape::UpdateSmartArtDrawing ( )

Updates SmartArt pre-rendered drawing by using Aspose.Words's SmartArt cold rendering engine.