Aspose::Words::Drawing::Shape class
Shape class
Represents an object in the drawing layer, such as an AutoShape, textbox, freeform, OLE object, ActiveX control, or picture. To learn more, visit the Working with Shapes documentation article.
class Shape : public ShapeBase,
public Core::ITextBox,
public Core::IStrokable
Methods
| Method | Description |
|---|---|
| Accept(System::SharedPtr<Aspose::Words::DocumentVisitor>) override | Accepts a visitor. |
| AcceptEnd(System::SharedPtr<Aspose::Words::DocumentVisitor>) override | Accepts a visitor for visiting the end of the shape. |
| AcceptStart(System::SharedPtr<Aspose::Words::DocumentVisitor>) override | Accepts a visitor for visiting the start of the shape. |
| Shape(const System::SharedPtr<Aspose::Words::DocumentBase> &, Aspose::Words::Drawing::ShapeType) | Creates a new shape object. |
| UpdateSmartArtDrawing() | Updates SmartArt pre-rendered drawing by using Aspose.Words’s SmartArt cold rendering engine. |
| get_Adjustments() | Provides access to the adjustment raw values of a shape. For a shape that does not contain any adjustment raw values, it returns an empty collection. |
| get_Chart() | Provides access to the chart properties if this shape has a Chart. |
| get_ExtrusionEnabled() | Returns true if an extrusion effect is enabled. |
| get_FillColor() | Defines the brush color that fills the closed path of the shape. |
| get_Filled() | Determines whether the closed path of the shape will be filled. |
| get_FirstParagraph() | Gets the first paragraph in the shape. |
| get_HasChart() | Returns true if this Shape has a Chart. |
| get_HasImage() | Returns true if the shape has image bytes or links an image. |
| get_HasSmartArt() | Returns true if this Shape has a SmartArt object. |
| get_HorizontalRuleFormat() | Provides access to the properties of the horizontal rule shape. For a shape that is not a horizontal rule, returns null. |
| get_ImageData() | Provides access to the image of the shape. Returns null if the shape cannot have an image. |
| get_LastParagraph() | Gets the last paragraph in the shape. |
| get_NodeType() const override | Returns 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. |
| get_ShadowEnabled() | Returns true if a shadow effect is enabled. |
| get_SignatureLine() | Gets SignatureLine object if the shape is a signature line. Returns null otherwise. |
| get_StoryType() | Returns Textbox. |
| get_Stroke() | Defines a stroke for a shape. |
| get_StrokeColor() | Defines the color of a stroke. |
| get_StrokeWeight() | Defines the brush thickness that strokes the path of a shape in points. |
| get_Stroked() | Defines whether the path will be stroked. |
| get_TextBox() | Defines attributes that specify how text is displayed in a shape. |
| get_TextPath() | Defines the text of the text path (of a WordArt object). |
| set_FillColor(System::Drawing::Color) | Defines the brush color that fills the closed path of the shape. |
| set_Filled(bool) | Determines whether the closed path of the shape will be filled. |
| set_StrokeColor(System::Drawing::Color) | Defines the color of a stroke. |
| set_StrokeWeight(double) | Defines the brush thickness that strokes the path of a shape in points. |
| set_Stroked(bool) | Defines whether the path will be stroked. |
| AdjustWithEffects(System::Drawing::RectangleF) | Adds to the source rectangle values of the effect extent and returns the final rectangle. |
| GetShapeRenderer() | Creates and returns an object that can be used to render this shape into an image. |
| LocalToParent(System::Drawing::PointF) | Converts a value from the local coordinate space into the coordinate space of the parent shape. |
| get_AllowOverlap() | Gets or sets a value that specifies whether this shape can overlap other shapes. |
| get_AlternativeText() | Defines alternative text to be displayed instead of a graphic. |
| get_AnchorLocked() | Specifies whether the shape’s anchor is locked. |
| get_AspectRatioLocked() | Specifies whether the shape’s aspect ratio is locked. |
| get_BehindText() | Specifies whether the shape is below or above text. |
| get_Bottom() | Gets the position of the bottom edge of the containing block of the shape. |
| get_Bounds() | Gets or sets the location and size of the containing block of the shape. |
| get_BoundsInPoints() | Gets the location and size of the containing block of the shape in points, relative to the anchor of the topmost shape. |
| get_BoundsWithEffects() | Gets final extent that this shape object has after applying drawing effects. Value is measured in points. |
| get_CanHaveImage() | Returns true if the shape type allows the shape to have an image. |
| get_CoordOrigin() | The coordinates at the top-left corner of the containing block of this shape. |
| get_CoordSize() | The width and height of the coordinate space inside the containing block of this shape. |
| get_DistanceBottom() | Returns or sets the distance (in points) between the document text and the bottom edge of the shape. |
| get_DistanceLeft() | Returns or sets the distance (in points) between the document text and the left edge of the shape. |
| get_DistanceRight() | Returns or sets the distance (in points) between the document text and the right edge of the shape. |
| get_DistanceTop() | Returns or sets the distance (in points) between the document text and the top edge of the shape. |
| get_Fill() | Gets fill formatting for the shape. |
| get_FlipOrientation() | Switches the orientation of a shape. |
| get_Font() | Provides access to the font formatting of this object. |
| get_Glow() | Gets glow formatting for the shape. |
| get_HRef() | Gets or sets the full hyperlink address for a shape. |
| get_Height() | Gets or sets the height of the containing block of the shape. |
| get_HeightRelative() | Gets or sets the value that represents the percentage of shape’s relative height. |
| get_Hidden() | Gets or sets a boolean value indicating whether the shape is visible. |
| get_HorizontalAlignment() | Specifies how the shape is positioned horizontally. |
| get_IsDecorative() | Gets or sets the flag that specifies whether the shape is decorative in the document. |
| get_IsDeleteRevision() | Returns true if this object was deleted in Microsoft Word while change tracking was enabled. |
| get_IsGroup() | Returns true if this is a group shape. |
| get_IsHorizontalRule() | Returns true if this shape is a horizontal rule. |
| get_IsImage() | Returns true if this shape is an image shape. |
| get_IsInline() | A quick way to determine if this shape is positioned inline with text. |
| get_IsInsertRevision() | Returns true if this object was inserted in Microsoft Word while change tracking was enabled. |
| get_IsLayoutInCell() | Gets or sets a flag indicating whether the shape is displayed inside a table or outside of it. |
| get_IsMoveFromRevision() | Returns true if this object was moved (deleted) in Microsoft Word while change tracking was enabled. |
| get_IsMoveToRevision() | Returns true if this object was moved (inserted) in Microsoft Word while change tracking was enabled. |
| get_IsSignatureLine() | Indicates that shape is a SignatureLine. |
| get_IsTopLevel() | Returns true if this shape is not a child of a group shape. |
| get_IsWordArt() | Returns true if this shape is a WordArt object. |
| get_Left() | Gets or sets the position of the left edge of the containing block of the shape. |
| get_LeftRelative() | Gets or sets the value that represents shape’s relative left position in percent. |
| get_MarkupLanguage() const | Gets MarkupLanguage used for this graphic object. |
| get_Name() | Gets or sets the optional shape name. |
| get_ParentParagraph() | Returns the immediate parent paragraph. |
| get_Reflection() | Gets reflection formatting for the shape. |
| get_RelativeHorizontalPosition() | Specifies relative to what the shape is positioned horizontally. |
| get_RelativeHorizontalSize() | Gets or sets the value of shape’s relative size in horizontal direction. |
| get_RelativeVerticalPosition() | Specifies relative to what the shape is positioned vertically. |
| get_RelativeVerticalSize() | Gets or sets the value of shape’s relative size in vertical direction. |
| get_Right() | Gets the position of the right edge of the containing block of the shape. |
| get_Rotation() | Defines the angle (in degrees) that a shape is rotated. Positive value corresponds to clockwise rotation angle. |
| get_ScreenTip() | Defines the text displayed when the mouse pointer moves over the shape. |
| get_ShadowFormat() | Gets shadow formatting for the shape. |
| get_ShapeType() | Gets the shape type. |
| get_SizeInPoints() | Gets the size of the shape in points. |
| get_SoftEdge() | Gets soft edge formatting for the shape. |
| get_Target() | Gets or sets the target frame for the shape hyperlink. |
| get_Title() | Gets or sets the title (caption) of the current shape object. |
| get_Top() | Gets or sets the position of the top edge of the containing block of the shape. |
| get_TopRelative() | Gets or sets the value that represents shape’s relative top position in percent. |
| get_VerticalAlignment() | Specifies how the shape is positioned vertically. |
| get_Width() | Gets or sets the width of the containing block of the shape. |
| get_WidthRelative() | Gets or sets the value that represents the percentage of shape’s relative width. |
| get_WrapSide() | Specifies how the text is wrapped around the shape. |
| get_WrapType() | Defines whether the shape is inline or floating. For floating shapes defines the wrapping mode for text around the shape. |
| get_ZOrder() | Determines the display order of overlapping shapes. |
| set_AllowOverlap(bool) | Sets a value that specifies whether this shape can overlap other shapes. |
| set_AlternativeText(const System::String &) | Defines alternative text to be displayed instead of a graphic. |
| set_AnchorLocked(bool) | Specifies whether the shape’s anchor is locked. |
| set_AspectRatioLocked(bool) | Specifies whether the shape’s aspect ratio is locked. |
| set_BehindText(bool) | Specifies whether the shape is below or above text. |
| set_Bounds(System::Drawing::RectangleF) | Sets the location and size of the containing block of the shape. |
| set_CoordOrigin(System::Drawing::Point) | The coordinates at the top-left corner of the containing block of this shape. |
| set_CoordSize(System::Drawing::Size) | The width and height of the coordinate space inside the containing block of this shape. |
| set_DistanceBottom(double) | Sets the distance (in points) between the document text and the bottom edge of the shape. |
| set_DistanceLeft(double) | Sets the distance (in points) between the document text and the left edge of the shape. |
| set_DistanceRight(double) | Sets the distance (in points) between the document text and the right edge of the shape. |
| set_DistanceTop(double) | Sets the distance (in points) between the document text and the top edge of the shape. |
| set_FlipOrientation(Aspose::Words::Drawing::FlipOrientation) | Switches the orientation of a shape. |
| set_HRef(const System::String &) | Sets the full hyperlink address for a shape. |
| set_Height(double) | Sets the height of the containing block of the shape. |
| set_HeightRelative(float) | Sets the value that represents the percentage of shape’s relative height. |
| set_Hidden(bool) | Sets a boolean value indicating whether the shape is visible. |
| set_HorizontalAlignment(Aspose::Words::Drawing::HorizontalAlignment) | Specifies how the shape is positioned horizontally. |
| set_IsDecorative(bool) | Sets the flag that specifies whether the shape is decorative in the document. |
| set_IsLayoutInCell(bool) | Sets a flag indicating whether the shape is displayed inside a table or outside of it. |
| set_Left(double) | Sets the position of the left edge of the containing block of the shape. |
| set_LeftRelative(float) | Sets the value that represents shape’s relative left position in percent. |
| set_Name(const System::String &) | Sets the optional shape name. |
| set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition) | Specifies relative to what the shape is positioned horizontally. |
| set_RelativeHorizontalSize(Aspose::Words::Drawing::RelativeHorizontalSize) | Sets the value of shape’s relative size in horizontal direction. |
| set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition) | Specifies relative to what the shape is positioned vertically. |
| set_RelativeVerticalSize(Aspose::Words::Drawing::RelativeVerticalSize) | Sets the value of shape’s relative size in vertical direction. |
| set_Rotation(double) | Defines the angle (in degrees) that a shape is rotated. Positive value corresponds to clockwise rotation angle. |
| set_ScreenTip(const System::String &) | Defines the text displayed when the mouse pointer moves over the shape. |
| set_Target(const System::String &) | Sets the target frame for the shape hyperlink. |
| set_Title(const System::String &) | Sets the title (caption) of the current shape object. |
| set_Top(double) | Sets the position of the top edge of the containing block of the shape. |
| set_TopRelative(float) | Sets the value that represents shape’s relative top position in percent. |
| set_VerticalAlignment(Aspose::Words::Drawing::VerticalAlignment) | Specifies how the shape is positioned vertically. |
| set_Width(double) | Sets the width of the containing block of the shape. |
| set_WidthRelative(float) | Sets the value that represents the percentage of shape’s relative width. |
| set_WrapSide(Aspose::Words::Drawing::WrapSide) | Specifies how the text is wrapped around the shape. |
| set_WrapType(Aspose::Words::Drawing::WrapType) | Defines whether the shape is inline or floating. For floating shapes defines the wrapping mode for text around the shape. |
| set_ZOrder(int32_t) | Determines the display order of overlapping shapes. |
| virtual AcceptEnd(System::SharedPtr<Aspose::Words::DocumentVisitor>) | When implemented in a derived class, calls the VisitXXXEnd method of the specified document visitor. |
| virtual AcceptStart(System::SharedPtr<Aspose::Words::DocumentVisitor>) | When implemented in a derived class, calls the VisitXXXStart method of the specified document visitor. |
| AppendChild(T) | Adds the specified node to the end of the list of child nodes for this node. |
| GetChild(Aspose::Words::NodeType, int32_t, bool) | Returns an Nth child node that matches the specified type. |
| GetChildNodes(Aspose::Words::NodeType, bool) | Returns a live collection of child nodes that match the specified type. |
| GetEnumerator() override | Provides support for the for each style iteration over the child nodes of this node. |
| GetText() override | Gets the text of this node and of all its children. |
| IndexOf(const System::SharedPtr<Aspose::Words::Node> &) | Returns the index of the specified child node in the child node array. |
| InsertAfter(T, const System::SharedPtr<Aspose::Words::Node> &) | Inserts the specified node immediately after the specified reference node. |
| InsertBefore(T, const System::SharedPtr<Aspose::Words::Node> &) | Inserts the specified node immediately before the specified reference node. |
| PrependChild(T) | Adds the specified node to the beginning of the list of child nodes for this node. |
| RemoveAllChildren() | Removes all the child nodes of the current node. |
| RemoveChild(T) | Removes the specified child node. |
| RemoveSmartTags() | Removes all SmartTag descendant nodes of the current node. |
| SelectNodes(const System::String &) | Selects a list of nodes matching the XPath expression. |
| SelectSingleNode(const System::String &) | Selects the first Node that matches the XPath expression. |
| get_Count() | Gets the number of immediate children of this node. |
| get_FirstChild() const | Gets the first child of the node. |
| get_HasChildNodes() | Returns true if this node has any child nodes. |
| get_IsComposite() override | Returns true as this node can have child nodes. |
| get_LastChild() const | Gets the last child of the node. |
| virtual Accept(System::SharedPtr<Aspose::Words::DocumentVisitor>) | Accepts a visitor. |
| Clone(bool) | Creates a duplicate of the node. |
| GetAncestor(Aspose::Words::NodeType) | Gets the first ancestor of the specified NodeType. |
| virtual GetText() | Gets the text of this node and of all its children. |
| NextPreOrder(const System::SharedPtr<Aspose::Words::Node> &) | Gets next node according to the pre-order tree traversal algorithm. |
| static NodeTypeToString(Aspose::Words::NodeType) | A utility method that converts a node type enum value into a user friendly string. |
| PreviousPreOrder(const System::SharedPtr<Aspose::Words::Node> &) | Gets the previous node according to the pre-order tree traversal algorithm. |
| Remove() | Removes itself from the parent. |
| ToString(Aspose::Words::SaveFormat) | Exports the content of the node into a string in the specified format. |
| ToString(const System::SharedPtr<Aspose::Words::Saving::SaveOptions> &) | Exports the content of the node into a string using the specified save options. |
| get_CustomNodeId() const | Specifies custom node identifier. |
| virtual get_Document() const | Gets the document to which this node belongs. |
| virtual get_IsComposite() | Returns true if this node can contain other nodes. |
| get_NextSibling() | Gets the node immediately following this node. |
| virtual get_NodeType() const | Gets the type of this node. |
| get_ParentNode() | Gets the immediate parent of this node. |
| get_PreviousSibling() | Gets the node immediately preceding this node. |
| get_Range() | Returns a Range object that represents the portion of a document that is contained in this node. |
| set_CustomNodeId(int32_t) | Specifies custom node identifier. |
Remarks
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.
Examples
Shows how to extract images from a document, and save them to the local file system as individual files.
auto doc = System::MakeObject<Aspose::Words::Document>(System::String(get_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.
System::SharedPtr<Aspose::Words::NodeCollection> shapes = doc->GetChildNodes(NodeType::Shape, true);
ASSERT_EQ(shapes->LINQ_Count(static_cast<System::Func<System::SharedPtr<Aspose::Words::Node>, bool>>(static_cast<std::function<bool(System::SharedPtr<Aspose::Words::Node> s)>>([](System::SharedPtr<Aspose::Words::Node> s) -> bool
{
return (System::ExplicitCast<Aspose::Words::Drawing::Shape>(s))->get_HasImage();
}))), 9);
int32_t imageIndex = 0;
for (auto&& shape : System::IterateOver(shapes->LINQ_OfType<System::SharedPtr<Aspose::Words::Drawing::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.
System::String imageFileName = System::String::Format(u"File.ExtractImages.{0}{1}", imageIndex, FileFormatUtil::ImageTypeToExtension(shape->get_ImageData()->get_ImageType()));
shape->get_ImageData()->Save(get_ArtifactsDir() + imageFileName);
imageIndex++;
}
}
Shows how to insert a floating image to the center of a page.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
// Insert a floating image that will appear behind the overlapping text and align it to the page's center.
System::SharedPtr<Aspose::Words::Drawing::Shape> shape = builder->InsertImage(get_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(get_ArtifactsDir() + u"Image.CreateFloatingPageCenter.docx");
Shows how to delete all shapes from a document.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
// Insert two shapes along with a group shape with another shape inside it.
builder->InsertShape(ShapeType::Rectangle, static_cast<double>(400), static_cast<double>(200));
builder->InsertShape(ShapeType::Star, static_cast<double>(300), static_cast<double>(300));
auto group = System::MakeObject<Aspose::Words::Drawing::GroupShape>(doc);
group->set_Bounds(System::Drawing::RectangleF(static_cast<float>(100.0f), static_cast<float>(50.0f), static_cast<float>(200.0f), static_cast<float>(100.0f)));
group->set_CoordOrigin(System::Drawing::Point(-1000, -500));
auto subShape = System::MakeObject<Aspose::Words::Drawing::Shape>(doc, ShapeType::Cube);
subShape->set_Width(500);
subShape->set_Height(700);
subShape->set_Left(0);
subShape->set_Top(0);
group->AppendChild<System::SharedPtr<Aspose::Words::Drawing::Shape>>(subShape);
builder->InsertNode(group);
ASSERT_EQ(doc->GetChildNodes(NodeType::Shape, true)->get_Count(), 3);
ASSERT_EQ(doc->GetChildNodes(NodeType::GroupShape, true)->get_Count(), 1);
// Remove all Shape nodes from the document.
System::SharedPtr<Aspose::Words::NodeCollection> shapes = doc->GetChildNodes(NodeType::Shape, true);
shapes->Clear();
// All shapes are gone, but the group shape is still in the document.
ASSERT_EQ(doc->GetChildNodes(NodeType::GroupShape, true)->get_Count(), 1);
ASSERT_EQ(doc->GetChildNodes(NodeType::Shape, true)->get_Count(), 0);
// Remove all group shapes separately.
System::SharedPtr<Aspose::Words::NodeCollection> groupShapes = doc->GetChildNodes(NodeType::GroupShape, true);
groupShapes->Clear();
ASSERT_EQ(doc->GetChildNodes(NodeType::GroupShape, true)->get_Count(), 0);
ASSERT_EQ(doc->GetChildNodes(NodeType::Shape, true)->get_Count(), 0);
See Also
- Class ShapeBase
- Namespace Aspose::Words::Drawing
- Library Aspose.Words for C++