Aspose::Words::Drawing::ShapeBase Class Referenceabstract

Detailed Description

Base class for objects in the drawing layer, such as an AutoShape, freeform, OLE object, ActiveX control, or picture.

This is an abstract class. The two derived classes that you can instantiate are Shape and GroupShape.

A shape is a node in the document tree.

If the shape is a child of a Paragraph object, then the shape is said to be "top-level". Top-level shapes are measured and positioned in points.

A shape can also occur as a child of a GroupShape object when several shapes are grouped. Child shapes of a group shape are positioned in the coordinate space and units defined by the CoordSize and CoordOrigin properties of the parent group shape.

A shape can be positioned inline with text or floating. The positioning method is controlled using the WrapType property.

When a shape is floating, it is positioned relative to something (e.g the current paragraph, the margin or the page). The relative positioning of the shape is specified using the RelativeHorizontalPosition and RelativeVerticalPosition properties.

A floating shape be positioned explicitly using the Left and Top properties or aligned relative to some other object using the HorizontalAlignment and VerticalAlignment properties.

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

Shows how to insert a floating image in the middle of a page.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inline
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Make the image float, put it behind text and center on the page
shape->set_BehindText(true);
shape->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
doc->Save(ArtifactsDir + u"Image.CreateFloatingPageCenter.docx");

#include <Aspose.Words.Cpp/Model/Drawing/ShapeBase.h>

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

Public Member Functions

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...
 
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_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...
 
int32_t get_ZOrder_IShape () override
 
SharedPtr< ShapeRendererGetShapeRenderer ()
 Creates and returns an object that can be used to render this shape into an image. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
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 (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 (String value)
 Setter for get_HRef. More...
 
void set_IsLayoutInCell (bool value)
 Setter for get_IsLayoutInCell. More...
 
void set_Left (double value)
 Setter for get_Left. More...
 
void set_Name (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 (String value)
 Setter for get_ScreenTip. More...
 
void set_Target (String value)
 Setter for get_Target. More...
 
void set_Title (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...
 
void set_ZOrder_IShape (int32_t value) override
 
- Public Member Functions inherited from CompositeNode
SharedPtr< NodeAppendChild (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...
 
SharedPtr< CompositeNodeget_Container () override
 
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< NodeGetCurrentNode () override
 
SharedPtr< IEnumerator< SharedPtr< Node > > > GetEnumerator () override
 Provides support for the for each style iteration over the child nodes of this node. More...
 
SharedPtr< NodeGetNextMatchingNode (SharedPtr< Node > curNode) override
 
String GetText () override
 Gets the text of this node and of all its children. More...
 
int32_t IndexOf (SharedPtr< Node > child)
 Returns the index of the specified child node in the child node array. More...
 
SharedPtr< NodeInsertAfter (SharedPtr< Node > newChild, SharedPtr< Node > refChild)
 Inserts the specified node immediately after the specified reference node. More...
 
SharedPtr< NodeInsertBefore (SharedPtr< Node > newChild, SharedPtr< Node > refChild)
 Inserts the specified node immediately before the specified reference node. More...
 
SharedPtr< NodePrependChild (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 (SharedPtr< Node > oldChild)
 Removes the specified child node. More...
 
void RemoveSmartTags ()
 Removes all SmartTag descendant nodes of the current node. More...
 
SharedPtr< NodeListSelectNodes (String xpath)
 Selects a list of nodes matching the XPath expression. More...
 
SharedPtr< NodeSelectSingleNode (String xpath)
 Selects the first Node that matches the XPath expression. More...
 
- Public Member Functions inherited from Node
virtual bool Accept (SharedPtr< DocumentVisitor > visitor)=0
 Accepts a visitor. More...
 
SharedPtr< NodeClone (bool isCloneChildren)
 
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...
 
virtual NodeType get_NodeType () const =0
 Gets the type of 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 (SharedPtr< Node > rootNode)
 Gets next node according to the pre-order tree traversal algorithm. More...
 
SharedPtr< NodePreviousPreOrder (SharedPtr< Node > rootNode)
 Gets the previous node according to the pre-order tree traversal algorithm. More...
 
void Remove ()
 Removes itself from the parent. More...
 
String ToString (SaveFormat saveFormat)
 Exports the content of the node into a string in the specified format. More...
 
String ToString (SharedPtr< SaveOptions > saveOptions)
 Exports the content of the node into a string using the specified save options. More...
 
- Public Member Functions inherited from Object
ASPOSECPP_SHARED_API Object ()
 
ASPOSECPP_SHARED_API Object (Object const &x)
 
virtual ASPOSECPP_SHARED_API ~Object ()
 
virtual ASPOSECPP_SHARED_API bool Equals (ptr obj)
 
Detail::SmartPtrCounter * GetCounter ()
 
virtual ASPOSECPP_SHARED_API int GetHashCode () const
 
ASPOSECPP_SHARED_API void Lock ()
 
virtual ASPOSECPP_SHARED_API ptr MemberwiseClone () const
 
Objectoperator= (Object const &x)
 
bool ReferenceEquals (String const &str, std::nullptr_t)
 
bool ReferenceEquals (String const &str1, String const &str2)
 
int RemovedSharedRefs (int count)
 
virtual ASPOSECPP_SHARED_API void SetTemplateWeakPtr (unsigned int argument)
 
int SharedCount () const
 
ObjectSharedRefAdded ()
 
int SharedRefRemovedSafe ()
 
virtual ASPOSECPP_SHARED_API String ToString () const
 
ASPOSECPP_SHARED_API void Unlock ()
 
Detail::SmartPtrCounter * WeakRefAdded ()
 
void WeakRefRemoved ()
 
- Public Member Functions inherited from System::Collections::Generic::IEnumerable< System::SharedPtr< Aspose::Words::Node > >
EnumeratorBasedIterator< T, IEnumerator< T > > begin () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > cbegin () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > cend () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > end () noexcept
 
bool LINQ_All (std::function< bool(T)> predicate)
 
bool LINQ_Any ()
 
bool LINQ_Any (std::function< bool(T)> predicate)
 
SharedPtr< IEnumerable< ResultType > > LINQ_Cast ()
 
SharedPtr< IEnumerable< Result > > LINQ_Cast ()
 
bool LINQ_Contains (T value)
 
int LINQ_Count ()
 
int LINQ_Count (const Func< T, bool > &predicate)
 
LINQ_ElementAt (int index)
 
LINQ_First ()
 
LINQ_First (const Func< T, bool > &predicate)
 
LINQ_FirstOrDefault ()
 
LINQ_FirstOrDefault (std::function< bool(T)> predicate)
 
LINQ_Last ()
 
LINQ_LastOrDefault ()
 
SharedPtr< IEnumerable< ResultType > > LINQ_OfType ()
 
SharedPtr< IEnumerable< Result > > LINQ_OfType ()
 
SharedPtr< IEnumerable< Source > > LINQ_OrderBy (const Func< Source, Key > &keySelector)
 
SharedPtr< IEnumerable< T > > LINQ_OrderBy (const Func< T, Key > &keySelector)
 
SharedPtr< IEnumerable< Result > > LINQ_Select (const Func< Source, Result > &selector)
 
SharedPtr< IEnumerable< ResultType > > LINQ_Select (const Func< T, ResultType > &selector)
 
ArrayPtr< T > LINQ_ToArray ()
 
SharedPtr< List< T > > LINQ_ToList ()
 
SharedPtr< IEnumerable< T > > LINQ_Where (std::function< bool(T)> predicate)
 

Static Public Member Functions

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 ()
 
- Static Public Member Functions inherited from Object
bool Equals (double const &objA, double const &objB)
 
bool Equals (float const &objA, float const &objB)
 
static std::enable_if<!IsSmartPtr< T1 >::value &&!IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 
static std::enable_if< IsSmartPtr< T1 >::value &&IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 
static bool ReferenceEquals (ptr const &objA, ptr const &objB)
 
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, std::nullptr_t)
 
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, T const &objB)
 
static const TypeInfoType ()
 

Additional Inherited Members

- Public Types inherited from Object
typedef SmartPtr< Objectptr
 
typedef System::Details::SharedMembersType shared_members_type
 
- Public Types inherited from System::Collections::Generic::IEnumerable< System::SharedPtr< Aspose::Words::Node > >
typedef IEnumerator< T > IEnumeratorType
 
typedef T ValueType
 

Member Function Documentation

◆ AdjustWithEffects()

System::Drawing::RectangleF Aspose::Words::Drawing::ShapeBase::AdjustWithEffects ( System::Drawing::RectangleF  source)

Adds to the source rectangle values of the effect extent and returns the final rectangle.

Examples

Shows how to check how a shape's bounds are affected by shape effects.

// Open a document that contains two shapes and get its shape collection
auto doc = MakeObject<Document>(MyDir + u"Shape shadow effect.docx");
SharedPtr<System::Collections::Generic::List<SharedPtr<Shape>>> shapes = doc->GetChildNodes(Aspose::Words::NodeType::Shape, true)->LINQ_Cast<SharedPtr<Shape> >()->LINQ_ToList();
ASSERT_EQ(2, shapes->get_Count());
// The two shapes are identical in terms of dimensions and shape type
ASPOSE_ASSERT_EQ(shapes->idx_get(0)->get_Width(), shapes->idx_get(1)->get_Width());
ASPOSE_ASSERT_EQ(shapes->idx_get(0)->get_Height(), shapes->idx_get(1)->get_Height());
ASSERT_EQ(shapes->idx_get(0)->get_ShapeType(), shapes->idx_get(1)->get_ShapeType());
// However, the first shape has no effects, while the second one has a shadow and thick outline
ASPOSE_ASSERT_EQ(0.0, shapes->idx_get(0)->get_StrokeWeight());
ASPOSE_ASSERT_EQ(20.0, shapes->idx_get(1)->get_StrokeWeight());
ASSERT_FALSE(shapes->idx_get(0)->get_ShadowEnabled());
ASSERT_TRUE(shapes->idx_get(1)->get_ShadowEnabled());
// These effects make the size of the second shape's silhouette bigger than that of the first
// Even though the size of the rectangle that shows up when we click on these shapes in Microsoft Word is the same,
// the practical outer bounds of the second shape are affected by the shadow and outline and are bigger
// We can use the AdjustWithEffects method to see exactly how much bigger they are
// The first shape has no outline or effects
SharedPtr<Shape> shape = shapes->idx_get(0);
// Create a RectangleF object, which represents a rectangle, which we could potentially use as the coordinates and bounds for a shape
System::Drawing::RectangleF rectangleF(200.0f, 200.0f, 1000.0f, 1000.0f);
// Run this method to get the size of the rectangle adjusted for all of our shape's effects
System::Drawing::RectangleF rectangleFOut = shape->AdjustWithEffects(rectangleF);
// Since the shape has no border-changing effects, its boundary dimensions are unaffected
ASPOSE_ASSERT_EQ(200, rectangleFOut.get_X());
ASPOSE_ASSERT_EQ(200, rectangleFOut.get_Y());
ASPOSE_ASSERT_EQ(1000, rectangleFOut.get_Width());
ASPOSE_ASSERT_EQ(1000, rectangleFOut.get_Height());
// The final extent of the first shape, in points
ASPOSE_ASSERT_EQ(0, shape->get_BoundsWithEffects().get_X());
ASPOSE_ASSERT_EQ(0, shape->get_BoundsWithEffects().get_Y());
ASPOSE_ASSERT_EQ(147, shape->get_BoundsWithEffects().get_Width());
ASPOSE_ASSERT_EQ(147, shape->get_BoundsWithEffects().get_Height());
// Do the same with the second shape
shape = shapes->idx_get(1);
rectangleF = System::Drawing::RectangleF(200.0f, 200.0f, 1000.0f, 1000.0f);
rectangleFOut = shape->AdjustWithEffects(rectangleF);
// The shape's x/y coordinates (top left corner location) have been pushed back by the thick outline
ASPOSE_ASSERT_EQ(171.5, rectangleFOut.get_X());
ASPOSE_ASSERT_EQ(167, rectangleFOut.get_Y());
// The width and height were also affected by the outline and shadow
ASPOSE_ASSERT_EQ(1045, rectangleFOut.get_Width());
ASPOSE_ASSERT_EQ(1132, rectangleFOut.get_Height());
// These values are also affected by effects
ASPOSE_ASSERT_EQ(-28.5, shape->get_BoundsWithEffects().get_X());
ASPOSE_ASSERT_EQ(-33, shape->get_BoundsWithEffects().get_Y());
ASPOSE_ASSERT_EQ(192, shape->get_BoundsWithEffects().get_Width());
ASPOSE_ASSERT_EQ(279, shape->get_BoundsWithEffects().get_Height());

◆ get_AllowOverlap()

bool Aspose::Words::Drawing::ShapeBase::get_AllowOverlap ( )

Gets or sets a value that specifies whether this shape can overlap other shapes.

This property affects behavior of the shape in Microsoft Word. Aspose.Words ignores the value of this property.

This property is applicable only to top level shapes.

The default value is true.

Examples

Shows how get properties for floating tables

auto doc = MakeObject<Document>(MyDir + u"Table wrapped by text.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
ASSERT_EQ(Aspose::Words::Tables::TextWrapping::Around, table->get_TextWrapping());
ASSERT_EQ(Aspose::Words::Drawing::RelativeHorizontalPosition::Margin, table->get_HorizontalAnchor());
ASSERT_EQ(Aspose::Words::Drawing::RelativeVerticalPosition::Paragraph, table->get_VerticalAnchor());
ASPOSE_ASSERT_EQ(false, table->get_AllowOverlap());

◆ get_AlternativeText()

System::String Aspose::Words::Drawing::ShapeBase::get_AlternativeText ( )

Defines alternative text to be displayed instead of a graphic.

The default value is an empty string.

Examples

Shows how to insert shapes.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a cube and set its name
SharedPtr<Shape> shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::Cube, 150, 150);
shape->set_Name(u"MyCube");
// We can also set the alt text like this
// This text will be found in Format AutoShape > Alt Text
shape->set_AlternativeText(u"Alt text for MyCube.");
// Insert a text box
shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::TextBox, 300, 50);
shape->get_Font()->set_Name(u"Times New Roman");
// Move the builder into the text box and write text
builder->MoveTo(shape->get_LastParagraph());
builder->Write(u"Hello world!");
// Move the builder out of the text box back into the main document
builder->MoveTo(shape->get_ParentParagraph());
// Insert a shape with an image
shape = builder->InsertImage(System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg"));
ASSERT_TRUE(shape->get_CanHaveImage());
ASSERT_TRUE(shape->get_HasImage());
// Rotate the image
shape->set_Rotation(45.0);
doc->Save(ArtifactsDir + u"Shape.Insert.docx");

◆ get_AnchorLocked()

bool Aspose::Words::Drawing::ShapeBase::get_AnchorLocked ( )

Specifies whether the shape's anchor is locked.

The default value is false.

Has effect only for top level shapes.

This property affects behavior of the shape's anchor in Microsoft Word. When the anchor is not locked, moving the shape in Microsoft Word can move the shape's anchor too.

Examples

Shows how to create and work with a group of shapes.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto group = MakeObject<GroupShape>(doc);
// Every GroupShape by default is a top level floating shape
ASSERT_TRUE(group->get_IsGroup());
ASSERT_TRUE(group->get_IsTopLevel());
ASSERT_EQ(Aspose::Words::Drawing::WrapType::None, group->get_WrapType());
// Top level shapes can have this property changed
group->set_AnchorLocked(true);
// Set the XY coordinates of the shape group and the size of its containing block, as it appears on the page
group->set_Bounds(System::Drawing::RectangleF(100.0f, 50.0f, 200.0f, 100.0f));
// Set the scale of the inner coordinates of the shape group
// These values mean that the bottom right corner of the 200x100 outer block we set before
// will be at x = 2000 and y = 1000, or 2000 units from the left and 1000 units from the top
group->set_CoordSize(System::Drawing::Size(2000, 1000));
// The coordinate origin of a shape group is x = 0, y = 0 by default, which is the top left corner
// If we insert a child shape and set its distance from the left to 2000 and the distance from the top to 1000,
// its origin will be at the bottom right corner of the shape group
// We can offset the coordinate origin by setting the CoordOrigin attribute
// In this instance, we move the origin to the centre of the shape group
group->set_CoordOrigin(System::Drawing::Point(-1000, -500));
// Populate the shape group with child shapes
// First, insert a rectangle
auto subShape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Rectangle);
subShape->set_Width(500);
subShape->set_Height(700);
// Place its top left corner at the parent group's coordinate origin, which is currently at its centre
subShape->set_Left(0);
subShape->set_Top(0);
// Add the rectangle to the group
group->AppendChild(subShape);
// Insert a triangle
subShape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Triangle);
subShape->set_Width(400);
subShape->set_Height(400);
// Place its origin at the bottom right corner of the group
subShape->set_Left(1000);
subShape->set_Top(500);
// The offset between this child shape and parent group can be seen here
ASPOSE_ASSERT_EQ(System::Drawing::PointF(1000.0f, 500.0f), subShape->LocalToParent(System::Drawing::PointF(0.0f, 0.0f)));
// Add the triangle to the group
group->AppendChild(subShape);
// Child shapes of a group shape are not top level
ASSERT_FALSE(subShape->get_IsTopLevel());
// Finally, insert the group into the document and save
builder->InsertNode(group);
doc->Save(ArtifactsDir + u"Shape.InsertGroupShape.docx");

◆ get_AspectRatioLocked()

bool Aspose::Words::Drawing::ShapeBase::get_AspectRatioLocked ( )

Specifies whether the shape's aspect ratio is locked.

The default value depends on the ShapeType, for the ShapeType.Image it is true but for the other shape types it is false.

Has effect for top level shapes only.

Examples

Shows how to set "AspectRatioLocked" for the shape object.

auto doc = MakeObject<Document>(MyDir + u"ActiveX controls.docx");
// Get shape object from the document and set AspectRatioLocked(it is possible to get/set AspectRatioLocked for child shapes (mimic MS Word behavior),
// but AspectRatioLocked has effect only for top level shapes!)
auto shape = System::DynamicCast<Aspose::Words::Drawing::Shape>(doc->GetChild(Aspose::Words::NodeType::Shape, 0, true));
shape->set_AspectRatioLocked(isLocked);

◆ get_BehindText()

bool Aspose::Words::Drawing::ShapeBase::get_BehindText ( )

Specifies whether the shape is below or above text.

Has effect only for top level shapes.

The default value is false.

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

Shows how to insert a floating image in the middle of a page.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inline
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Make the image float, put it behind text and center on the page
shape->set_BehindText(true);
shape->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
doc->Save(ArtifactsDir + u"Image.CreateFloatingPageCenter.docx");

◆ get_Bottom()

double Aspose::Words::Drawing::ShapeBase::get_Bottom ( )

Gets the position of the bottom edge of the containing block of the shape.

For a top-level shape, the value is in points and relative to the shape anchor.

For shapes in a group, the value is in the coordinate space and units of the parent group.

Examples

Shows how to insert a floating image and specify its position and size.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inline
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Make the image float, put it behind text and center on the page
// Make position relative to the page
shape->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
// Set the shape's coordinates, from the top left corner of the page
shape->set_Left(100);
shape->set_Top(80);
// Set the shape's height
shape->set_Height(125.0);
// The width will be scaled to the height and the dimensions of the real image
ASPOSE_ASSERT_EQ(125.0, shape->get_Width());
// The Bottom and Right members contain the locations of the bottom and right edges of the image
ASPOSE_ASSERT_EQ(shape->get_Top() + shape->get_Height(), shape->get_Bottom());
ASPOSE_ASSERT_EQ(shape->get_Left() + shape->get_Width(), shape->get_Right());
doc->Save(ArtifactsDir + u"Image.CreateFloatingPositionSize.docx");

◆ get_Bounds()

System::Drawing::RectangleF Aspose::Words::Drawing::ShapeBase::get_Bounds ( )

Gets or sets the location and size of the containing block of the shape.

Ignores aspect ratio lock upon setting.

For a top-level shape, the value is in points and relative to the shape anchor.

For shapes in a group, the value is in the coordinate space and units of the parent group.

Examples

Shows how to create line shapes and set specific location and size.

auto doc = MakeObject<Document>();
// The lines will cross the whole page
float pageWidth = (float)doc->get_FirstSection()->get_PageSetup()->get_PageWidth();
float pageHeight = (float)doc->get_FirstSection()->get_PageSetup()->get_PageHeight();
// This line goes from top left to bottom right by default
auto lineA = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Line);
lineA->set_Bounds(System::Drawing::RectangleF(0.0f, 0.0f, pageWidth, pageHeight));
lineA->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
lineA->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
ASPOSE_ASSERT_EQ(System::Drawing::RectangleF(0.0f, 0.0f, pageWidth, pageHeight), lineA->get_BoundsInPoints());
// This line goes from bottom left to top right because we flipped it
auto lineB = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Line);
lineB->set_Bounds(System::Drawing::RectangleF(0.0f, 0.0f, pageWidth, pageHeight));
lineB->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
lineB->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
ASPOSE_ASSERT_EQ(System::Drawing::RectangleF(0.0f, 0.0f, pageWidth, pageHeight), lineB->get_BoundsInPoints());
// Add lines to the document
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(lineA);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(lineB);
doc->Save(ArtifactsDir + u"Shape.LineFlipOrientation.docx");

◆ get_BoundsInPoints()

System::Drawing::RectangleF Aspose::Words::Drawing::ShapeBase::get_BoundsInPoints ( )

Gets the location and size of the containing block of the shape in points, relative to the anchor of the topmost shape.

Examples

Shows how to create line shapes and set specific location and size.

auto doc = MakeObject<Document>();
// The lines will cross the whole page
float pageWidth = (float)doc->get_FirstSection()->get_PageSetup()->get_PageWidth();
float pageHeight = (float)doc->get_FirstSection()->get_PageSetup()->get_PageHeight();
// This line goes from top left to bottom right by default
auto lineA = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Line);
lineA->set_Bounds(System::Drawing::RectangleF(0.0f, 0.0f, pageWidth, pageHeight));
lineA->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
lineA->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
ASPOSE_ASSERT_EQ(System::Drawing::RectangleF(0.0f, 0.0f, pageWidth, pageHeight), lineA->get_BoundsInPoints());
// This line goes from bottom left to top right because we flipped it
auto lineB = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Line);
lineB->set_Bounds(System::Drawing::RectangleF(0.0f, 0.0f, pageWidth, pageHeight));
lineB->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
lineB->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
ASPOSE_ASSERT_EQ(System::Drawing::RectangleF(0.0f, 0.0f, pageWidth, pageHeight), lineB->get_BoundsInPoints());
// Add lines to the document
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(lineA);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(lineB);
doc->Save(ArtifactsDir + u"Shape.LineFlipOrientation.docx");

◆ get_BoundsWithEffects()

System::Drawing::RectangleF Aspose::Words::Drawing::ShapeBase::get_BoundsWithEffects ( )

Gets final extent that this shape object has after applying drawing effects. Value is measured in points.

Examples

Shows how to check how a shape's bounds are affected by shape effects.

// Open a document that contains two shapes and get its shape collection
auto doc = MakeObject<Document>(MyDir + u"Shape shadow effect.docx");
SharedPtr<System::Collections::Generic::List<SharedPtr<Shape>>> shapes = doc->GetChildNodes(Aspose::Words::NodeType::Shape, true)->LINQ_Cast<SharedPtr<Shape> >()->LINQ_ToList();
ASSERT_EQ(2, shapes->get_Count());
// The two shapes are identical in terms of dimensions and shape type
ASPOSE_ASSERT_EQ(shapes->idx_get(0)->get_Width(), shapes->idx_get(1)->get_Width());
ASPOSE_ASSERT_EQ(shapes->idx_get(0)->get_Height(), shapes->idx_get(1)->get_Height());
ASSERT_EQ(shapes->idx_get(0)->get_ShapeType(), shapes->idx_get(1)->get_ShapeType());
// However, the first shape has no effects, while the second one has a shadow and thick outline
ASPOSE_ASSERT_EQ(0.0, shapes->idx_get(0)->get_StrokeWeight());
ASPOSE_ASSERT_EQ(20.0, shapes->idx_get(1)->get_StrokeWeight());
ASSERT_FALSE(shapes->idx_get(0)->get_ShadowEnabled());
ASSERT_TRUE(shapes->idx_get(1)->get_ShadowEnabled());
// These effects make the size of the second shape's silhouette bigger than that of the first
// Even though the size of the rectangle that shows up when we click on these shapes in Microsoft Word is the same,
// the practical outer bounds of the second shape are affected by the shadow and outline and are bigger
// We can use the AdjustWithEffects method to see exactly how much bigger they are
// The first shape has no outline or effects
SharedPtr<Shape> shape = shapes->idx_get(0);
// Create a RectangleF object, which represents a rectangle, which we could potentially use as the coordinates and bounds for a shape
System::Drawing::RectangleF rectangleF(200.0f, 200.0f, 1000.0f, 1000.0f);
// Run this method to get the size of the rectangle adjusted for all of our shape's effects
System::Drawing::RectangleF rectangleFOut = shape->AdjustWithEffects(rectangleF);
// Since the shape has no border-changing effects, its boundary dimensions are unaffected
ASPOSE_ASSERT_EQ(200, rectangleFOut.get_X());
ASPOSE_ASSERT_EQ(200, rectangleFOut.get_Y());
ASPOSE_ASSERT_EQ(1000, rectangleFOut.get_Width());
ASPOSE_ASSERT_EQ(1000, rectangleFOut.get_Height());
// The final extent of the first shape, in points
ASPOSE_ASSERT_EQ(0, shape->get_BoundsWithEffects().get_X());
ASPOSE_ASSERT_EQ(0, shape->get_BoundsWithEffects().get_Y());
ASPOSE_ASSERT_EQ(147, shape->get_BoundsWithEffects().get_Width());
ASPOSE_ASSERT_EQ(147, shape->get_BoundsWithEffects().get_Height());
// Do the same with the second shape
shape = shapes->idx_get(1);
rectangleF = System::Drawing::RectangleF(200.0f, 200.0f, 1000.0f, 1000.0f);
rectangleFOut = shape->AdjustWithEffects(rectangleF);
// The shape's x/y coordinates (top left corner location) have been pushed back by the thick outline
ASPOSE_ASSERT_EQ(171.5, rectangleFOut.get_X());
ASPOSE_ASSERT_EQ(167, rectangleFOut.get_Y());
// The width and height were also affected by the outline and shadow
ASPOSE_ASSERT_EQ(1045, rectangleFOut.get_Width());
ASPOSE_ASSERT_EQ(1132, rectangleFOut.get_Height());
// These values are also affected by effects
ASPOSE_ASSERT_EQ(-28.5, shape->get_BoundsWithEffects().get_X());
ASPOSE_ASSERT_EQ(-33, shape->get_BoundsWithEffects().get_Y());
ASPOSE_ASSERT_EQ(192, shape->get_BoundsWithEffects().get_Width());
ASPOSE_ASSERT_EQ(279, shape->get_BoundsWithEffects().get_Height());

◆ get_CanHaveImage()

bool Aspose::Words::Drawing::ShapeBase::get_CanHaveImage ( )

Returns true if the shape type allows the shape to have an image.

Although Microsoft Word has a special shape type for images, it appears that in Microsoft Word documents any shape except a group shape can have an image, therefore this property returns true for all shapes except GroupShape.

Examples

Shows how to insert shapes.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a cube and set its name
SharedPtr<Shape> shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::Cube, 150, 150);
shape->set_Name(u"MyCube");
// We can also set the alt text like this
// This text will be found in Format AutoShape > Alt Text
shape->set_AlternativeText(u"Alt text for MyCube.");
// Insert a text box
shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::TextBox, 300, 50);
shape->get_Font()->set_Name(u"Times New Roman");
// Move the builder into the text box and write text
builder->MoveTo(shape->get_LastParagraph());
builder->Write(u"Hello world!");
// Move the builder out of the text box back into the main document
builder->MoveTo(shape->get_ParentParagraph());
// Insert a shape with an image
shape = builder->InsertImage(System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg"));
ASSERT_TRUE(shape->get_CanHaveImage());
ASSERT_TRUE(shape->get_HasImage());
// Rotate the image
shape->set_Rotation(45.0);
doc->Save(ArtifactsDir + u"Shape.Insert.docx");

◆ get_CoordOrigin()

System::Drawing::Point Aspose::Words::Drawing::ShapeBase::get_CoordOrigin ( )

The coordinates at the top-left corner of the containing block of this shape.

The default value is (0,0).

Examples

Shows how to create and work with a group of shapes.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto group = MakeObject<GroupShape>(doc);
// Every GroupShape by default is a top level floating shape
ASSERT_TRUE(group->get_IsGroup());
ASSERT_TRUE(group->get_IsTopLevel());
ASSERT_EQ(Aspose::Words::Drawing::WrapType::None, group->get_WrapType());
// Top level shapes can have this property changed
group->set_AnchorLocked(true);
// Set the XY coordinates of the shape group and the size of its containing block, as it appears on the page
group->set_Bounds(System::Drawing::RectangleF(100.0f, 50.0f, 200.0f, 100.0f));
// Set the scale of the inner coordinates of the shape group
// These values mean that the bottom right corner of the 200x100 outer block we set before
// will be at x = 2000 and y = 1000, or 2000 units from the left and 1000 units from the top
group->set_CoordSize(System::Drawing::Size(2000, 1000));
// The coordinate origin of a shape group is x = 0, y = 0 by default, which is the top left corner
// If we insert a child shape and set its distance from the left to 2000 and the distance from the top to 1000,
// its origin will be at the bottom right corner of the shape group
// We can offset the coordinate origin by setting the CoordOrigin attribute
// In this instance, we move the origin to the centre of the shape group
group->set_CoordOrigin(System::Drawing::Point(-1000, -500));
// Populate the shape group with child shapes
// First, insert a rectangle
auto subShape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Rectangle);
subShape->set_Width(500);
subShape->set_Height(700);
// Place its top left corner at the parent group's coordinate origin, which is currently at its centre
subShape->set_Left(0);
subShape->set_Top(0);
// Add the rectangle to the group
group->AppendChild(subShape);
// Insert a triangle
subShape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Triangle);
subShape->set_Width(400);
subShape->set_Height(400);
// Place its origin at the bottom right corner of the group
subShape->set_Left(1000);
subShape->set_Top(500);
// The offset between this child shape and parent group can be seen here
ASPOSE_ASSERT_EQ(System::Drawing::PointF(1000.0f, 500.0f), subShape->LocalToParent(System::Drawing::PointF(0.0f, 0.0f)));
// Add the triangle to the group
group->AppendChild(subShape);
// Child shapes of a group shape are not top level
ASSERT_FALSE(subShape->get_IsTopLevel());
// Finally, insert the group into the document and save
builder->InsertNode(group);
doc->Save(ArtifactsDir + u"Shape.InsertGroupShape.docx");

◆ get_CoordSize()

System::Drawing::Size Aspose::Words::Drawing::ShapeBase::get_CoordSize ( )

The width and height of the coordinate space inside the containing block of this shape.

The default value is (1000, 1000).

Examples

Shows how to create and work with a group of shapes.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto group = MakeObject<GroupShape>(doc);
// Every GroupShape by default is a top level floating shape
ASSERT_TRUE(group->get_IsGroup());
ASSERT_TRUE(group->get_IsTopLevel());
ASSERT_EQ(Aspose::Words::Drawing::WrapType::None, group->get_WrapType());
// Top level shapes can have this property changed
group->set_AnchorLocked(true);
// Set the XY coordinates of the shape group and the size of its containing block, as it appears on the page
group->set_Bounds(System::Drawing::RectangleF(100.0f, 50.0f, 200.0f, 100.0f));
// Set the scale of the inner coordinates of the shape group
// These values mean that the bottom right corner of the 200x100 outer block we set before
// will be at x = 2000 and y = 1000, or 2000 units from the left and 1000 units from the top
group->set_CoordSize(System::Drawing::Size(2000, 1000));
// The coordinate origin of a shape group is x = 0, y = 0 by default, which is the top left corner
// If we insert a child shape and set its distance from the left to 2000 and the distance from the top to 1000,
// its origin will be at the bottom right corner of the shape group
// We can offset the coordinate origin by setting the CoordOrigin attribute
// In this instance, we move the origin to the centre of the shape group
group->set_CoordOrigin(System::Drawing::Point(-1000, -500));
// Populate the shape group with child shapes
// First, insert a rectangle
auto subShape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Rectangle);
subShape->set_Width(500);
subShape->set_Height(700);
// Place its top left corner at the parent group's coordinate origin, which is currently at its centre
subShape->set_Left(0);
subShape->set_Top(0);
// Add the rectangle to the group
group->AppendChild(subShape);
// Insert a triangle
subShape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Triangle);
subShape->set_Width(400);
subShape->set_Height(400);
// Place its origin at the bottom right corner of the group
subShape->set_Left(1000);
subShape->set_Top(500);
// The offset between this child shape and parent group can be seen here
ASPOSE_ASSERT_EQ(System::Drawing::PointF(1000.0f, 500.0f), subShape->LocalToParent(System::Drawing::PointF(0.0f, 0.0f)));
// Add the triangle to the group
group->AppendChild(subShape);
// Child shapes of a group shape are not top level
ASSERT_FALSE(subShape->get_IsTopLevel());
// Finally, insert the group into the document and save
builder->InsertNode(group);
doc->Save(ArtifactsDir + u"Shape.InsertGroupShape.docx");

◆ get_DistanceBottom()

double Aspose::Words::Drawing::ShapeBase::get_DistanceBottom ( )

Returns or sets the distance (in points) between the document text and the bottom edge of the shape.

The default value is 0.

Has effect only for top level shapes.

Examples

Shows how to set the wrapping distance for text that surrounds a shape.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a rectangle and get the text to wrap tightly around its bounds
SharedPtr<Shape> shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::Rectangle, 150, 150);
// Set the minimum distance between the shape and surrounding text
shape->set_DistanceTop(40.0);
shape->set_DistanceBottom(40.0);
shape->set_DistanceLeft(40.0);
shape->set_DistanceRight(40.0);
// Move the shape closer to the centre of the page
shape->set_Top(75.0);
shape->set_Left(150.0);
// Rotate the shape
shape->set_Rotation(60.0);
// Add text that will wrap around the shape
builder->get_Font()->set_Size(24.0);
builder->Write(String(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ") + u"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.");
doc->Save(ArtifactsDir + u"Shape.Coordinates.docx");

◆ get_DistanceLeft()

double Aspose::Words::Drawing::ShapeBase::get_DistanceLeft ( )

Returns or sets the distance (in points) between the document text and the left edge of the shape.

The default value is 1/8 inch.

Has effect only for top level shapes.

Examples

Shows how to set the wrapping distance for text that surrounds a shape.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a rectangle and get the text to wrap tightly around its bounds
SharedPtr<Shape> shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::Rectangle, 150, 150);
// Set the minimum distance between the shape and surrounding text
shape->set_DistanceTop(40.0);
shape->set_DistanceBottom(40.0);
shape->set_DistanceLeft(40.0);
shape->set_DistanceRight(40.0);
// Move the shape closer to the centre of the page
shape->set_Top(75.0);
shape->set_Left(150.0);
// Rotate the shape
shape->set_Rotation(60.0);
// Add text that will wrap around the shape
builder->get_Font()->set_Size(24.0);
builder->Write(String(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ") + u"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.");
doc->Save(ArtifactsDir + u"Shape.Coordinates.docx");

◆ get_DistanceRight()

double Aspose::Words::Drawing::ShapeBase::get_DistanceRight ( )

Returns or sets the distance (in points) between the document text and the right edge of the shape.

The default value is 1/8 inch.

Has effect only for top level shapes.

Examples

Shows how to set the wrapping distance for text that surrounds a shape.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a rectangle and get the text to wrap tightly around its bounds
SharedPtr<Shape> shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::Rectangle, 150, 150);
// Set the minimum distance between the shape and surrounding text
shape->set_DistanceTop(40.0);
shape->set_DistanceBottom(40.0);
shape->set_DistanceLeft(40.0);
shape->set_DistanceRight(40.0);
// Move the shape closer to the centre of the page
shape->set_Top(75.0);
shape->set_Left(150.0);
// Rotate the shape
shape->set_Rotation(60.0);
// Add text that will wrap around the shape
builder->get_Font()->set_Size(24.0);
builder->Write(String(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ") + u"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.");
doc->Save(ArtifactsDir + u"Shape.Coordinates.docx");

◆ get_DistanceTop()

double Aspose::Words::Drawing::ShapeBase::get_DistanceTop ( )

Returns or sets the distance (in points) between the document text and the top edge of the shape.

The default value is 0.

Has effect only for top level shapes.

Examples

Shows how to set the wrapping distance for text that surrounds a shape.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a rectangle and get the text to wrap tightly around its bounds
SharedPtr<Shape> shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::Rectangle, 150, 150);
// Set the minimum distance between the shape and surrounding text
shape->set_DistanceTop(40.0);
shape->set_DistanceBottom(40.0);
shape->set_DistanceLeft(40.0);
shape->set_DistanceRight(40.0);
// Move the shape closer to the centre of the page
shape->set_Top(75.0);
shape->set_Left(150.0);
// Rotate the shape
shape->set_Rotation(60.0);
// Add text that will wrap around the shape
builder->get_Font()->set_Size(24.0);
builder->Write(String(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ") + u"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.");
doc->Save(ArtifactsDir + u"Shape.Coordinates.docx");

◆ get_FlipOrientation()

Aspose::Words::Drawing::FlipOrientation Aspose::Words::Drawing::ShapeBase::get_FlipOrientation ( )

Switches the orientation of a shape.

The default value is None.

Examples

Shows how to create line shapes and set specific location and size.

auto doc = MakeObject<Document>();
// The lines will cross the whole page
float pageWidth = (float)doc->get_FirstSection()->get_PageSetup()->get_PageWidth();
float pageHeight = (float)doc->get_FirstSection()->get_PageSetup()->get_PageHeight();
// This line goes from top left to bottom right by default
auto lineA = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Line);
lineA->set_Bounds(System::Drawing::RectangleF(0.0f, 0.0f, pageWidth, pageHeight));
lineA->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
lineA->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
ASPOSE_ASSERT_EQ(System::Drawing::RectangleF(0.0f, 0.0f, pageWidth, pageHeight), lineA->get_BoundsInPoints());
// This line goes from bottom left to top right because we flipped it
auto lineB = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Line);
lineB->set_Bounds(System::Drawing::RectangleF(0.0f, 0.0f, pageWidth, pageHeight));
lineB->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
lineB->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
ASPOSE_ASSERT_EQ(System::Drawing::RectangleF(0.0f, 0.0f, pageWidth, pageHeight), lineB->get_BoundsInPoints());
// Add lines to the document
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(lineA);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(lineB);
doc->Save(ArtifactsDir + u"Shape.LineFlipOrientation.docx");

◆ get_Font()

System::SharedPtr<Aspose::Words::Font> Aspose::Words::Drawing::ShapeBase::get_Font ( )

Provides access to the font formatting of this object.

Examples

Shows how to insert shapes.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a cube and set its name
SharedPtr<Shape> shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::Cube, 150, 150);
shape->set_Name(u"MyCube");
// We can also set the alt text like this
// This text will be found in Format AutoShape > Alt Text
shape->set_AlternativeText(u"Alt text for MyCube.");
// Insert a text box
shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::TextBox, 300, 50);
shape->get_Font()->set_Name(u"Times New Roman");
// Move the builder into the text box and write text
builder->MoveTo(shape->get_LastParagraph());
builder->Write(u"Hello world!");
// Move the builder out of the text box back into the main document
builder->MoveTo(shape->get_ParentParagraph());
// Insert a shape with an image
shape = builder->InsertImage(System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg"));
ASSERT_TRUE(shape->get_CanHaveImage());
ASSERT_TRUE(shape->get_HasImage());
// Rotate the image
shape->set_Rotation(45.0);
doc->Save(ArtifactsDir + u"Shape.Insert.docx");

◆ get_Height()

double Aspose::Words::Drawing::ShapeBase::get_Height ( )

Gets or sets the height of the containing block of the shape.

For a top-level shape, the value is in points.

For shapes in a group, the value is in the coordinate space and units of the parent group.

The default value is 0.

Examples

Shows how to insert a floating image and specify its position and size.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inline
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Make the image float, put it behind text and center on the page
// Make position relative to the page
shape->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
// Set the shape's coordinates, from the top left corner of the page
shape->set_Left(100);
shape->set_Top(80);
// Set the shape's height
shape->set_Height(125.0);
// The width will be scaled to the height and the dimensions of the real image
ASPOSE_ASSERT_EQ(125.0, shape->get_Width());
// The Bottom and Right members contain the locations of the bottom and right edges of the image
ASPOSE_ASSERT_EQ(shape->get_Top() + shape->get_Height(), shape->get_Bottom());
ASPOSE_ASSERT_EQ(shape->get_Left() + shape->get_Width(), shape->get_Right());
doc->Save(ArtifactsDir + u"Image.CreateFloatingPositionSize.docx");

Shows how to resize a shape with an image.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inserted at 100% scale
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Reduce the overall size of the shape by 50%
shape->set_Width(shape->get_Width() * 0.5);
shape->set_Height(shape->get_Height() * 0.5);
ASPOSE_ASSERT_EQ(75.0, shape->get_Width());
ASPOSE_ASSERT_EQ(75.0, shape->get_Height());
// However, we can also go back to the original image size and scale from there, for example, to 110%
SharedPtr<ImageSize> imageSize = shape->get_ImageData()->get_ImageSize();
shape->set_Width(imageSize->get_WidthPoints() * 1.1);
shape->set_Height(imageSize->get_HeightPoints() * 1.1);
ASPOSE_ASSERT_EQ(330.0, shape->get_Width());
ASPOSE_ASSERT_EQ(330.0, shape->get_Height());
doc->Save(ArtifactsDir + u"Image.ScaleImage.docx");

◆ get_HorizontalAlignment()

Aspose::Words::Drawing::HorizontalAlignment Aspose::Words::Drawing::ShapeBase::get_HorizontalAlignment ( )

Specifies how the shape is positioned horizontally.

The default value is None.

Has effect only for top level floating shapes.

Examples

Shows how to insert a floating image in the middle of a page.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inline
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Make the image float, put it behind text and center on the page
shape->set_BehindText(true);
shape->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
doc->Save(ArtifactsDir + u"Image.CreateFloatingPageCenter.docx");

◆ get_HRef()

System::String Aspose::Words::Drawing::ShapeBase::get_HRef ( )

Gets or sets the full hyperlink address for a shape.

The default value is an empty string.

Below are examples of valid values for this property:

Full URI: https://www.aspose.com/.

Full file name: C:\\My Documents\\SalesReport.doc.

Relative URI: ../../../resource.txt

Relative file name: ..\\My Documents\\SalesReport.doc.

Bookmark within another document: https://www.aspose.com/Products/Default.aspx#Suites

Bookmark within this document: #BookmakName.

Examples

Shows how to insert an image with a hyperlink.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Windows MetaFile.wmf");
shape->set_HRef(u"https://forum.aspose.com/");
shape->set_Target(u"New Window");
shape->set_ScreenTip(u"Aspose.Words Support Forums");
doc->Save(ArtifactsDir + u"Image.InsertImageWithHyperlink.docx");

◆ get_IsDeleteRevision()

bool Aspose::Words::Drawing::ShapeBase::get_IsDeleteRevision ( )

Returns true if this object was deleted in Microsoft Word while change tracking was enabled.

Examples

Shows how to work with revision shapes.

// Open a blank document
auto doc = MakeObject<Document>();
// Insert an inline shape without tracking revisions
ASSERT_FALSE(doc->get_TrackRevisions());
auto shape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Cube);
shape->set_Width(100.0);
shape->set_Height(100.0);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(shape);
// Start tracking revisions and then insert another shape
doc->StartTrackRevisions(u"John Doe");
shape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Sun);
shape->set_Width(100.0);
shape->set_Height(100.0);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(shape);
// Get the document's shape collection which includes just the two shapes we added
SharedPtr<System::Collections::Generic::List<SharedPtr<Shape>>> shapes = doc->GetChildNodes(Aspose::Words::NodeType::Shape, true)->LINQ_Cast<SharedPtr<Shape> >()->LINQ_ToList();
ASSERT_EQ(2, shapes->get_Count());
// Remove the first shape
shapes->idx_get(0)->Remove();
// Because we removed that shape while changes were being tracked, the shape counts as a delete revision
ASSERT_EQ(Aspose::Words::Drawing::ShapeType::Cube, shapes->idx_get(0)->get_ShapeType());
ASSERT_TRUE(shapes->idx_get(0)->get_IsDeleteRevision());
// And we inserted another shape while tracking changes, so that shape will count as an insert revision
ASSERT_EQ(Aspose::Words::Drawing::ShapeType::Sun, shapes->idx_get(1)->get_ShapeType());
ASSERT_TRUE(shapes->idx_get(1)->get_IsInsertRevision());

◆ get_IsGroup()

bool Aspose::Words::Drawing::ShapeBase::get_IsGroup ( )

Returns true if this is a group shape.

◆ get_IsHorizontalRule()

bool Aspose::Words::Drawing::ShapeBase::get_IsHorizontalRule ( )

Returns true if this shape is a horizontal rule.

Examples

Shows how to insert horizontal rule shape in a document and customize the formatting.

// Use a document builder to insert a horizontal rule
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Shape> shape = builder->InsertHorizontalRule();
SharedPtr<HorizontalRuleFormat> horizontalRuleFormat = shape->get_HorizontalRuleFormat();
horizontalRuleFormat->set_Alignment(Aspose::Words::Drawing::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_IsImage()

bool Aspose::Words::Drawing::ShapeBase::get_IsImage ( )

Returns true if this shape is an image shape.

◆ get_IsInline()

bool Aspose::Words::Drawing::ShapeBase::get_IsInline ( )

A quick way to determine if this shape is positioned inline with text.

Has effect only for top level shapes.

Examples

Shows how to test if a shape in the document is inline or floating.

auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
for (auto shape : System::IterateOver(doc->GetChildNodes(Aspose::Words::NodeType::Shape, true)->LINQ_OfType<SharedPtr<Shape> >()))
{
System::Console::WriteLine(shape->get_IsInline() ? String(u"Shape is inline.") : String(u"Shape is floating."));
}

◆ get_IsInsertRevision()

bool Aspose::Words::Drawing::ShapeBase::get_IsInsertRevision ( )

Returns true if this object was inserted in Microsoft Word while change tracking was enabled.

Examples

Shows how to work with revision shapes.

// Open a blank document
auto doc = MakeObject<Document>();
// Insert an inline shape without tracking revisions
ASSERT_FALSE(doc->get_TrackRevisions());
auto shape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Cube);
shape->set_Width(100.0);
shape->set_Height(100.0);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(shape);
// Start tracking revisions and then insert another shape
doc->StartTrackRevisions(u"John Doe");
shape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Sun);
shape->set_Width(100.0);
shape->set_Height(100.0);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(shape);
// Get the document's shape collection which includes just the two shapes we added
SharedPtr<System::Collections::Generic::List<SharedPtr<Shape>>> shapes = doc->GetChildNodes(Aspose::Words::NodeType::Shape, true)->LINQ_Cast<SharedPtr<Shape> >()->LINQ_ToList();
ASSERT_EQ(2, shapes->get_Count());
// Remove the first shape
shapes->idx_get(0)->Remove();
// Because we removed that shape while changes were being tracked, the shape counts as a delete revision
ASSERT_EQ(Aspose::Words::Drawing::ShapeType::Cube, shapes->idx_get(0)->get_ShapeType());
ASSERT_TRUE(shapes->idx_get(0)->get_IsDeleteRevision());
// And we inserted another shape while tracking changes, so that shape will count as an insert revision
ASSERT_EQ(Aspose::Words::Drawing::ShapeType::Sun, shapes->idx_get(1)->get_ShapeType());
ASSERT_TRUE(shapes->idx_get(1)->get_IsInsertRevision());

◆ get_IsLayoutInCell()

bool Aspose::Words::Drawing::ShapeBase::get_IsLayoutInCell ( )

Gets or sets a flag indicating whether the shape is displayed inside a table or outside of it.

The default value is true.

Has effect only for top level shapes, the property WrapType of which is set to value other than Inline.

Examples

Shows how to display the shape, inside a table or outside of it.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->StartTable();
builder->get_RowFormat()->set_Height(100);
builder->get_RowFormat()->set_HeightRule(Aspose::Words::HeightRule::Exactly);
for (int i = 0; i < 31; i++)
{
if (i != 0 && i % 7 == 0)
{
builder->EndRow();
}
builder->InsertCell();
builder->Write(u"Cell contents");
}
builder->EndTable();
SharedPtr<NodeCollection> runs = doc->GetChildNodes(Aspose::Words::NodeType::Run, true);
int num = 1;
for (auto run : System::IterateOver(runs->LINQ_OfType<SharedPtr<Run> >()))
{
auto watermark = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::TextPlainText);
watermark->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
watermark->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
// False - display the shape outside of table cell, True - display the shape outside of table cell
watermark->set_IsLayoutInCell(true);
watermark->set_Width(30);
watermark->set_Height(30);
watermark->set_HorizontalAlignment(Aspose::Words::Drawing::HorizontalAlignment::Center);
watermark->set_VerticalAlignment(Aspose::Words::Drawing::VerticalAlignment::Center);
watermark->set_Rotation(-40);
watermark->get_Fill()->set_Color(System::Drawing::Color::get_Gainsboro());
watermark->set_StrokeColor(System::Drawing::Color::get_Gainsboro());
watermark->get_TextPath()->set_Text(String::Format(u"{0}",num));
watermark->get_TextPath()->set_FontFamily(u"Arial");
watermark->set_Name(String::Format(u"Watermark_{0}",num++));
// Property will take effect only if the WrapType property is set to something other than WrapType.Inline
watermark->set_WrapType(Aspose::Words::Drawing::WrapType::None);
watermark->set_BehindText(true);
builder->MoveTo(run);
builder->InsertNode(watermark);
}
// Behaviour of MS Word on working with shapes in table cells is changed in the last versions
// Adding the following line is needed to make the shape displayed in center of a page
doc->get_CompatibilityOptions()->OptimizeFor(Aspose::Words::Settings::MsWordVersion::Word2010);
doc->Save(ArtifactsDir + u"Shape.LayoutInTableCell.docx");

◆ get_IsMoveFromRevision()

bool Aspose::Words::Drawing::ShapeBase::get_IsMoveFromRevision ( )

Returns true if this object was moved (deleted) in Microsoft Word while change tracking was enabled.

Examples

Shows how to identify move revision shapes.

// Open a document that contains a move revision
// A move revision is when we, while changes are tracked, cut(not copy)-and-paste or highlight and drag text from one place to another
// If inline shapes are caught up in the text movement, they will count as move revisions as well
// Moving a floating shape will not count as a move revision
auto doc = MakeObject<Document>(MyDir + u"Revision shape.docx");
// The document has one shape that was moved, but shape move revisions will have two instances of that shape
// One will be the shape at its arrival destination and the other will be the shape at its original location
SharedPtr<System::Collections::Generic::List<SharedPtr<Shape>>> nc = doc->GetChildNodes(Aspose::Words::NodeType::Shape, true)->LINQ_Cast<SharedPtr<Shape> >()->LINQ_ToList();
ASSERT_EQ(2, nc->get_Count());
// This is the move to revision, also the shape at its arrival destination
ASSERT_FALSE(nc->idx_get(0)->get_IsMoveFromRevision());
ASSERT_TRUE(nc->idx_get(0)->get_IsMoveToRevision());
// This is the move from revision, which is the shape at its original location
ASSERT_TRUE(nc->idx_get(1)->get_IsMoveFromRevision());
ASSERT_FALSE(nc->idx_get(1)->get_IsMoveToRevision());

◆ get_IsMoveToRevision()

bool Aspose::Words::Drawing::ShapeBase::get_IsMoveToRevision ( )

Returns true if this object was moved (inserted) in Microsoft Word while change tracking was enabled.

Examples

Shows how to identify move revision shapes.

// Open a document that contains a move revision
// A move revision is when we, while changes are tracked, cut(not copy)-and-paste or highlight and drag text from one place to another
// If inline shapes are caught up in the text movement, they will count as move revisions as well
// Moving a floating shape will not count as a move revision
auto doc = MakeObject<Document>(MyDir + u"Revision shape.docx");
// The document has one shape that was moved, but shape move revisions will have two instances of that shape
// One will be the shape at its arrival destination and the other will be the shape at its original location
SharedPtr<System::Collections::Generic::List<SharedPtr<Shape>>> nc = doc->GetChildNodes(Aspose::Words::NodeType::Shape, true)->LINQ_Cast<SharedPtr<Shape> >()->LINQ_ToList();
ASSERT_EQ(2, nc->get_Count());
// This is the move to revision, also the shape at its arrival destination
ASSERT_FALSE(nc->idx_get(0)->get_IsMoveFromRevision());
ASSERT_TRUE(nc->idx_get(0)->get_IsMoveToRevision());
// This is the move from revision, which is the shape at its original location
ASSERT_TRUE(nc->idx_get(1)->get_IsMoveFromRevision());
ASSERT_FALSE(nc->idx_get(1)->get_IsMoveToRevision());

◆ get_IsSignatureLine()

bool Aspose::Words::Drawing::ShapeBase::get_IsSignatureLine ( )

Indicates that shape is a SignatureLine.

Examples

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

// Create a blank document and its DocumentBuilder
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// The SignatureLineOptions will contain all the data that the signature line will display
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 the signature line, applying our SignatureLineOptions
// We can control where the signature line will appear on the page using a combination of left/top indents and margin-relative positions
// Since we're placing the signature line at the bottom right of the page, we will need to use negative indents to move it into view
ASSERT_TRUE(shape->get_IsSignatureLine());
// The SignatureLine object is a member of the shape that contains it
SharedPtr<Aspose::Words::Drawing::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());
// We will be prompted to sign it when we open the document
ASSERT_FALSE(signatureLine->get_IsSigned());
// The object may be valid, but the signature itself isn't until it is signed
ASSERT_FALSE(signatureLine->get_IsValid());
doc->Save(ArtifactsDir + u"Shape.SignatureLine.docx");

◆ get_IsTopLevel()

bool Aspose::Words::Drawing::ShapeBase::get_IsTopLevel ( )

Returns true if this shape is not a child of a group shape.

Examples

Shows how to create and work with a group of shapes.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto group = MakeObject<GroupShape>(doc);
// Every GroupShape by default is a top level floating shape
ASSERT_TRUE(group->get_IsGroup());
ASSERT_TRUE(group->get_IsTopLevel());
ASSERT_EQ(Aspose::Words::Drawing::WrapType::None, group->get_WrapType());
// Top level shapes can have this property changed
group->set_AnchorLocked(true);
// Set the XY coordinates of the shape group and the size of its containing block, as it appears on the page
group->set_Bounds(System::Drawing::RectangleF(100.0f, 50.0f, 200.0f, 100.0f));
// Set the scale of the inner coordinates of the shape group
// These values mean that the bottom right corner of the 200x100 outer block we set before
// will be at x = 2000 and y = 1000, or 2000 units from the left and 1000 units from the top
group->set_CoordSize(System::Drawing::Size(2000, 1000));
// The coordinate origin of a shape group is x = 0, y = 0 by default, which is the top left corner
// If we insert a child shape and set its distance from the left to 2000 and the distance from the top to 1000,
// its origin will be at the bottom right corner of the shape group
// We can offset the coordinate origin by setting the CoordOrigin attribute
// In this instance, we move the origin to the centre of the shape group
group->set_CoordOrigin(System::Drawing::Point(-1000, -500));
// Populate the shape group with child shapes
// First, insert a rectangle
auto subShape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Rectangle);
subShape->set_Width(500);
subShape->set_Height(700);
// Place its top left corner at the parent group's coordinate origin, which is currently at its centre
subShape->set_Left(0);
subShape->set_Top(0);
// Add the rectangle to the group
group->AppendChild(subShape);
// Insert a triangle
subShape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Triangle);
subShape->set_Width(400);
subShape->set_Height(400);
// Place its origin at the bottom right corner of the group
subShape->set_Left(1000);
subShape->set_Top(500);
// The offset between this child shape and parent group can be seen here
ASPOSE_ASSERT_EQ(System::Drawing::PointF(1000.0f, 500.0f), subShape->LocalToParent(System::Drawing::PointF(0.0f, 0.0f)));
// Add the triangle to the group
group->AppendChild(subShape);
// Child shapes of a group shape are not top level
ASSERT_FALSE(subShape->get_IsTopLevel());
// Finally, insert the group into the document and save
builder->InsertNode(group);
doc->Save(ArtifactsDir + u"Shape.InsertGroupShape.docx");

◆ get_IsWordArt()

bool Aspose::Words::Drawing::ShapeBase::get_IsWordArt ( )

Returns true if this shape is a WordArt object.

◆ get_Left()

double Aspose::Words::Drawing::ShapeBase::get_Left ( )

Gets or sets the position of the left edge of the containing block of the shape.

For a top-level shape, the value is in points and relative to the shape anchor.

For shapes in a group, the value is in the coordinate space and units of the parent group.

The default value is 0.

Has effect only for floating shapes.

Examples

Shows how to insert a floating image and specify its position and size.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inline
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Make the image float, put it behind text and center on the page
// Make position relative to the page
shape->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
// Set the shape's coordinates, from the top left corner of the page
shape->set_Left(100);
shape->set_Top(80);
// Set the shape's height
shape->set_Height(125.0);
// The width will be scaled to the height and the dimensions of the real image
ASPOSE_ASSERT_EQ(125.0, shape->get_Width());
// The Bottom and Right members contain the locations of the bottom and right edges of the image
ASPOSE_ASSERT_EQ(shape->get_Top() + shape->get_Height(), shape->get_Bottom());
ASPOSE_ASSERT_EQ(shape->get_Left() + shape->get_Width(), shape->get_Right());
doc->Save(ArtifactsDir + u"Image.CreateFloatingPositionSize.docx");

◆ get_MarkupLanguage()

Aspose::Words::Drawing::ShapeMarkupLanguage Aspose::Words::Drawing::ShapeBase::get_MarkupLanguage ( ) const

Gets MarkupLanguage used for this graphic object.

Examples

Shows how get markup language for shape object in document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->InsertImage(ImageDir + u"Transparent background logo.png");
// Loop through all single shapes inside document
for (auto shape : System::IterateOver(doc->GetChildNodes(Aspose::Words::NodeType::Shape, true)->LINQ_OfType<SharedPtr<Shape> >()))
{
System::Console::WriteLine(String(u"Shape: ") + System::ObjectExt::ToString(shape->get_MarkupLanguage()));
System::Console::WriteLine(String(u"ShapeSize: ") + shape->get_SizeInPoints());
}

◆ get_Name()

System::String Aspose::Words::Drawing::ShapeBase::get_Name ( )

Gets or sets the optional shape name.

Default is empty string.

Cannot be null, but can be an empty string.

Examples

Shows how to insert shapes.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a cube and set its name
SharedPtr<Shape> shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::Cube, 150, 150);
shape->set_Name(u"MyCube");
// We can also set the alt text like this
// This text will be found in Format AutoShape > Alt Text
shape->set_AlternativeText(u"Alt text for MyCube.");
// Insert a text box
shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::TextBox, 300, 50);
shape->get_Font()->set_Name(u"Times New Roman");
// Move the builder into the text box and write text
builder->MoveTo(shape->get_LastParagraph());
builder->Write(u"Hello world!");
// Move the builder out of the text box back into the main document
builder->MoveTo(shape->get_ParentParagraph());
// Insert a shape with an image
shape = builder->InsertImage(System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg"));
ASSERT_TRUE(shape->get_CanHaveImage());
ASSERT_TRUE(shape->get_HasImage());
// Rotate the image
shape->set_Rotation(45.0);
doc->Save(ArtifactsDir + u"Shape.Insert.docx");

◆ get_ParentParagraph()

System::SharedPtr<Aspose::Words::Paragraph> Aspose::Words::Drawing::ShapeBase::get_ParentParagraph ( )

Returns the immediate parent paragraph.

Examples

Shows how to insert shapes.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a cube and set its name
SharedPtr<Shape> shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::Cube, 150, 150);
shape->set_Name(u"MyCube");
// We can also set the alt text like this
// This text will be found in Format AutoShape > Alt Text
shape->set_AlternativeText(u"Alt text for MyCube.");
// Insert a text box
shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::TextBox, 300, 50);
shape->get_Font()->set_Name(u"Times New Roman");
// Move the builder into the text box and write text
builder->MoveTo(shape->get_LastParagraph());
builder->Write(u"Hello world!");
// Move the builder out of the text box back into the main document
builder->MoveTo(shape->get_ParentParagraph());
// Insert a shape with an image
shape = builder->InsertImage(System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg"));
ASSERT_TRUE(shape->get_CanHaveImage());
ASSERT_TRUE(shape->get_HasImage());
// Rotate the image
shape->set_Rotation(45.0);
doc->Save(ArtifactsDir + u"Shape.Insert.docx");

◆ get_RelativeHorizontalPosition()

Aspose::Words::Drawing::RelativeHorizontalPosition Aspose::Words::Drawing::ShapeBase::get_RelativeHorizontalPosition ( )

Specifies relative to what the shape is positioned horizontally.

The default value is Column.

Has effect only for top level floating shapes.

Examples

Shows how to insert a floating image in the middle of a page.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inline
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Make the image float, put it behind text and center on the page
shape->set_BehindText(true);
shape->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
doc->Save(ArtifactsDir + u"Image.CreateFloatingPageCenter.docx");

◆ get_RelativeVerticalPosition()

Aspose::Words::Drawing::RelativeVerticalPosition Aspose::Words::Drawing::ShapeBase::get_RelativeVerticalPosition ( )

Specifies relative to what the shape is positioned vertically.

The default value is Paragraph.

Has effect only for top level floating shapes.

Examples

Shows how to insert a floating image in the middle of a page.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inline
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Make the image float, put it behind text and center on the page
shape->set_BehindText(true);
shape->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
doc->Save(ArtifactsDir + u"Image.CreateFloatingPageCenter.docx");

◆ get_Right()

double Aspose::Words::Drawing::ShapeBase::get_Right ( )

Gets the position of the right edge of the containing block of the shape.

For a top-level shape, the value is in points and relative to the shape anchor.

For shapes in a group, the value is in the coordinate space and units of the parent group.

Examples

Shows how to insert a floating image and specify its position and size.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inline
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Make the image float, put it behind text and center on the page
// Make position relative to the page
shape->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
// Set the shape's coordinates, from the top left corner of the page
shape->set_Left(100);
shape->set_Top(80);
// Set the shape's height
shape->set_Height(125.0);
// The width will be scaled to the height and the dimensions of the real image
ASPOSE_ASSERT_EQ(125.0, shape->get_Width());
// The Bottom and Right members contain the locations of the bottom and right edges of the image
ASPOSE_ASSERT_EQ(shape->get_Top() + shape->get_Height(), shape->get_Bottom());
ASPOSE_ASSERT_EQ(shape->get_Left() + shape->get_Width(), shape->get_Right());
doc->Save(ArtifactsDir + u"Image.CreateFloatingPositionSize.docx");

◆ get_Rotation()

double Aspose::Words::Drawing::ShapeBase::get_Rotation ( )

Defines the angle (in degrees) that a shape is rotated. Positive value corresponds to clockwise rotation angle.

The default value is 0.

Examples

Shows how to insert shapes.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a cube and set its name
SharedPtr<Shape> shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::Cube, 150, 150);
shape->set_Name(u"MyCube");
// We can also set the alt text like this
// This text will be found in Format AutoShape > Alt Text
shape->set_AlternativeText(u"Alt text for MyCube.");
// Insert a text box
shape = builder->InsertShape(Aspose::Words::Drawing::ShapeType::TextBox, 300, 50);
shape->get_Font()->set_Name(u"Times New Roman");
// Move the builder into the text box and write text
builder->MoveTo(shape->get_LastParagraph());
builder->Write(u"Hello world!");
// Move the builder out of the text box back into the main document
builder->MoveTo(shape->get_ParentParagraph());
// Insert a shape with an image
shape = builder->InsertImage(System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg"));
ASSERT_TRUE(shape->get_CanHaveImage());
ASSERT_TRUE(shape->get_HasImage());
// Rotate the image
shape->set_Rotation(45.0);
doc->Save(ArtifactsDir + u"Shape.Insert.docx");

◆ get_ScreenTip()

System::String Aspose::Words::Drawing::ShapeBase::get_ScreenTip ( )

Defines the text displayed when the mouse pointer moves over the shape.

The default value is an empty string.

Examples

Shows how to insert an image with a hyperlink.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Windows MetaFile.wmf");
shape->set_HRef(u"https://forum.aspose.com/");
shape->set_Target(u"New Window");
shape->set_ScreenTip(u"Aspose.Words Support Forums");
doc->Save(ArtifactsDir + u"Image.InsertImageWithHyperlink.docx");

◆ get_ShapeType()

Aspose::Words::Drawing::ShapeType Aspose::Words::Drawing::ShapeBase::get_ShapeType ( )

Gets the shape type.

◆ get_SizeInPoints()

System::Drawing::SizeF Aspose::Words::Drawing::ShapeBase::get_SizeInPoints ( )

Gets the size of the shape in points.

Examples

Shows how get markup language for shape object in document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->InsertImage(ImageDir + u"Transparent background logo.png");
// Loop through all single shapes inside document
for (auto shape : System::IterateOver(doc->GetChildNodes(Aspose::Words::NodeType::Shape, true)->LINQ_OfType<SharedPtr<Shape> >()))
{
System::Console::WriteLine(String(u"Shape: ") + System::ObjectExt::ToString(shape->get_MarkupLanguage()));
System::Console::WriteLine(String(u"ShapeSize: ") + shape->get_SizeInPoints());
}

◆ get_Target()

System::String Aspose::Words::Drawing::ShapeBase::get_Target ( )

Gets or sets the target frame for the shape hyperlink.

The default value is an empty string.

Examples

Shows how to insert an image with a hyperlink.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Windows MetaFile.wmf");
shape->set_HRef(u"https://forum.aspose.com/");
shape->set_Target(u"New Window");
shape->set_ScreenTip(u"Aspose.Words Support Forums");
doc->Save(ArtifactsDir + u"Image.InsertImageWithHyperlink.docx");

◆ get_Title()

System::String Aspose::Words::Drawing::ShapeBase::get_Title ( )

Gets or sets the title (caption) of the current shape object.

Default is empty string.

Cannot be null, but can be an empty string.

Examples

Shows how to get or set title of shape object.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Create test shape
auto shape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Cube);
shape->set_Width(200);
shape->set_Height(200);
shape->set_Title(u"My cube");
builder->InsertNode(shape);

◆ get_Top()

double Aspose::Words::Drawing::ShapeBase::get_Top ( )

Gets or sets the position of the top edge of the containing block of the shape.

For a top-level shape, the value is in points and relative to the shape anchor.

For shapes in a group, the value is in the coordinate space and units of the parent group.

The default value is 0.

Has effect only for floating shapes.

Examples

Shows how to insert a floating image and specify its position and size.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inline
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Make the image float, put it behind text and center on the page
// Make position relative to the page
shape->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
// Set the shape's coordinates, from the top left corner of the page
shape->set_Left(100);
shape->set_Top(80);
// Set the shape's height
shape->set_Height(125.0);
// The width will be scaled to the height and the dimensions of the real image
ASPOSE_ASSERT_EQ(125.0, shape->get_Width());
// The Bottom and Right members contain the locations of the bottom and right edges of the image
ASPOSE_ASSERT_EQ(shape->get_Top() + shape->get_Height(), shape->get_Bottom());
ASPOSE_ASSERT_EQ(shape->get_Left() + shape->get_Width(), shape->get_Right());
doc->Save(ArtifactsDir + u"Image.CreateFloatingPositionSize.docx");

◆ get_VerticalAlignment()

Aspose::Words::Drawing::VerticalAlignment Aspose::Words::Drawing::ShapeBase::get_VerticalAlignment ( )

Specifies how the shape is positioned vertically.

The default value is None.

Has effect only for top level floating shapes.

Examples

Shows how to insert a floating image in the middle of a page.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inline
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Make the image float, put it behind text and center on the page
shape->set_BehindText(true);
shape->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
doc->Save(ArtifactsDir + u"Image.CreateFloatingPageCenter.docx");

◆ get_Width()

double Aspose::Words::Drawing::ShapeBase::get_Width ( )

Gets or sets the width of the containing block of the shape.

For a top-level shape, the value is in points.

For shapes in a group, the value is in the coordinate space and units of the parent group.

The default value is 0.

Examples

Shows how to insert a floating image and specify its position and size.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inline
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Make the image float, put it behind text and center on the page
// Make position relative to the page
shape->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
// Set the shape's coordinates, from the top left corner of the page
shape->set_Left(100);
shape->set_Top(80);
// Set the shape's height
shape->set_Height(125.0);
// The width will be scaled to the height and the dimensions of the real image
ASPOSE_ASSERT_EQ(125.0, shape->get_Width());
// The Bottom and Right members contain the locations of the bottom and right edges of the image
ASPOSE_ASSERT_EQ(shape->get_Top() + shape->get_Height(), shape->get_Bottom());
ASPOSE_ASSERT_EQ(shape->get_Left() + shape->get_Width(), shape->get_Right());
doc->Save(ArtifactsDir + u"Image.CreateFloatingPositionSize.docx");

Shows how to resize a shape with an image.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inserted at 100% scale
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Reduce the overall size of the shape by 50%
shape->set_Width(shape->get_Width() * 0.5);
shape->set_Height(shape->get_Height() * 0.5);
ASPOSE_ASSERT_EQ(75.0, shape->get_Width());
ASPOSE_ASSERT_EQ(75.0, shape->get_Height());
// However, we can also go back to the original image size and scale from there, for example, to 110%
SharedPtr<ImageSize> imageSize = shape->get_ImageData()->get_ImageSize();
shape->set_Width(imageSize->get_WidthPoints() * 1.1);
shape->set_Height(imageSize->get_HeightPoints() * 1.1);
ASPOSE_ASSERT_EQ(330.0, shape->get_Width());
ASPOSE_ASSERT_EQ(330.0, shape->get_Height());
doc->Save(ArtifactsDir + u"Image.ScaleImage.docx");

◆ get_WrapSide()

Aspose::Words::Drawing::WrapSide Aspose::Words::Drawing::ShapeBase::get_WrapSide ( )

Specifies how the text is wrapped around the shape.

The default value is Both.

Has effect only for top level shapes.

Examples

Shows how to replace all textboxes with images.

auto doc = MakeObject<Document>(MyDir + u"Textboxes in drawing canvas.docx");
// This gets a live collection of all shape nodes in the document
SharedPtr<NodeCollection> shapeCollection = doc->GetChildNodes(Aspose::Words::NodeType::Shape, true);
// Since we will be adding/removing nodes, it is better to copy all collection
// into a fixed size array, otherwise iterator will be invalidated
ArrayPtr<SharedPtr<Node>> shapes = shapeCollection->ToArray();
for (auto shape : System::IterateOver(shapes->LINQ_OfType<SharedPtr<Shape> >()))
{
// Filter out all shapes that we don't need
{
// Create a new shape that will replace the existing shape
auto image = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Image);
// Load the image into the new shape
image->get_ImageData()->SetImage(ImageDir + u"Windows MetaFile.wmf");
// Make new shape's position to match the old shape
image->set_Left(shape->get_Left());
image->set_Top(shape->get_Top());
image->set_Width(shape->get_Width());
image->set_Height(shape->get_Height());
image->set_RelativeHorizontalPosition(shape->get_RelativeHorizontalPosition());
image->set_RelativeVerticalPosition(shape->get_RelativeVerticalPosition());
image->set_HorizontalAlignment(shape->get_HorizontalAlignment());
image->set_VerticalAlignment(shape->get_VerticalAlignment());
image->set_WrapType(shape->get_WrapType());
image->set_WrapSide(shape->get_WrapSide());
// Insert new shape after the old shape and remove the old shape
shape->get_ParentNode()->InsertAfter(image, shape);
shape->Remove();
}
}
doc->Save(ArtifactsDir + u"Shape.ReplaceTextboxesWithImages.docx");

◆ get_WrapType()

Aspose::Words::Drawing::WrapType Aspose::Words::Drawing::ShapeBase::get_WrapType ( )

Defines whether the shape is inline or floating. For floating shapes defines the wrapping mode for text around the shape.

The default value is None.

Has effect only for top level shapes.

Examples

Shows how to insert a floating image in the middle of a page.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// By default, the image is inline
SharedPtr<Shape> shape = builder->InsertImage(ImageDir + u"Logo.jpg");
// Make the image float, put it behind text and center on the page
shape->set_BehindText(true);
shape->set_RelativeHorizontalPosition(Aspose::Words::Drawing::RelativeHorizontalPosition::Page);
shape->set_RelativeVerticalPosition(Aspose::Words::Drawing::RelativeVerticalPosition::Page);
doc->Save(ArtifactsDir + u"Image.CreateFloatingPageCenter.docx");

Shows how to create a textbox with some text and different formatting options in a new document.

auto doc = MakeObject<Document>();
// Create a new shape of type TextBox
auto textBox = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::TextBox);
// Set some settings of the textbox itself
// Set the wrap of the textbox to inline
// Set the horizontal and vertical alignment of the text inside the shape
textBox->set_HorizontalAlignment(Aspose::Words::Drawing::HorizontalAlignment::Center);
textBox->set_VerticalAlignment(Aspose::Words::Drawing::VerticalAlignment::Top);
// Set the textbox height and width
textBox->set_Height(50);
textBox->set_Width(200);
// Set the textbox in front of other shapes with a lower ZOrder
textBox->set_ZOrder(2);
// Let's create a new paragraph for the textbox manually and align it in the center
// Make sure we add the new nodes to the textbox as well
textBox->AppendChild(MakeObject<Paragraph>(doc));
SharedPtr<Paragraph> para = textBox->get_FirstParagraph();
para->get_ParagraphFormat()->set_Alignment(Aspose::Words::ParagraphAlignment::Center);
// Add some text to the paragraph
auto run = MakeObject<Run>(doc);
run->set_Text(u"Hello world!");
para->AppendChild(run);
// Append the textbox to the first paragraph in the body
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(textBox);
doc->Save(ArtifactsDir + u"Shape.CreateTextBox.docx");

◆ get_ZOrder()

int32_t Aspose::Words::Drawing::ShapeBase::get_ZOrder ( )

Determines the display order of overlapping shapes.

Has effect only for top level shapes.

The default value is 0.

The number represents the stacking precedence. A shape with a higher number will be displayed as if it were overlapping (in "front" of) a shape with a lower number.

The order of overlapping shapes is independent for shapes in the header and in the main text of the document.

The display order of child shapes in a group shape is determined by their order inside the group shape.

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

Shows how to create a textbox with some text and different formatting options in a new document.

auto doc = MakeObject<Document>();
// Create a new shape of type TextBox
auto textBox = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::TextBox);
// Set some settings of the textbox itself
// Set the wrap of the textbox to inline
// Set the horizontal and vertical alignment of the text inside the shape
textBox->set_HorizontalAlignment(Aspose::Words::Drawing::HorizontalAlignment::Center);
textBox->set_VerticalAlignment(Aspose::Words::Drawing::VerticalAlignment::Top);
// Set the textbox height and width
textBox->set_Height(50);
textBox->set_Width(200);
// Set the textbox in front of other shapes with a lower ZOrder
textBox->set_ZOrder(2);
// Let's create a new paragraph for the textbox manually and align it in the center
// Make sure we add the new nodes to the textbox as well
textBox->AppendChild(MakeObject<Paragraph>(doc));
SharedPtr<Paragraph> para = textBox->get_FirstParagraph();
para->get_ParagraphFormat()->set_Alignment(Aspose::Words::ParagraphAlignment::Center);
// Add some text to the paragraph
auto run = MakeObject<Run>(doc);
run->set_Text(u"Hello world!");
para->AppendChild(run);
// Append the textbox to the first paragraph in the body
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(textBox);
doc->Save(ArtifactsDir + u"Shape.CreateTextBox.docx");

◆ get_ZOrder_IShape()

int32_t Aspose::Words::Drawing::ShapeBase::get_ZOrder_IShape ( )
override

◆ GetShapeRenderer()

System::SharedPtr<Aspose::Words::Rendering::ShapeRenderer> Aspose::Words::Drawing::ShapeBase::GetShapeRenderer ( )

Creates and returns an object that can be used to render this shape into an image.

This method just invokes the ShapeRenderer constructor and passes this object as a parameter.

Returns
The renderer object for this shape.
Examples

Shows how to export shapes to files in the local file system using a shape renderer.

// Open a document that contains shapes and get its shape collection
auto doc = MakeObject<Document>(MyDir + u"Various shapes.docx");
SharedPtr<System::Collections::Generic::List<SharedPtr<Shape>>> shapes = doc->GetChildNodes(Aspose::Words::NodeType::Shape, true)->LINQ_Cast<SharedPtr<Shape> >()->LINQ_ToList();
ASSERT_EQ(7, shapes->get_Count());
// There are 7 shapes in the document, with one group shape with 2 child shapes
// The child shapes will be rendered but their parent group shape will be skipped, so we will see 6 output files
for (auto shape : System::IterateOver(doc->GetChildNodes(Aspose::Words::NodeType::Shape, true)->LINQ_OfType<SharedPtr<Shape> >()))
{
SharedPtr<ShapeRenderer> renderer = shape->GetShapeRenderer();
auto options = MakeObject<ImageSaveOptions>(Aspose::Words::SaveFormat::Png);
renderer->Save(ArtifactsDir + String::Format(u"Shape.RenderAllShapes.{0}.png",shape->get_Name()), options);
}

◆ GetType()

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

◆ Is()

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

◆ LocalToParent()

System::Drawing::PointF Aspose::Words::Drawing::ShapeBase::LocalToParent ( System::Drawing::PointF  value)

Converts a value from the local coordinate space into the coordinate space of the parent shape.

Examples

Shows how to create and work with a group of shapes.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto group = MakeObject<GroupShape>(doc);
// Every GroupShape by default is a top level floating shape
ASSERT_TRUE(group->get_IsGroup());
ASSERT_TRUE(group->get_IsTopLevel());
ASSERT_EQ(Aspose::Words::Drawing::WrapType::None, group->get_WrapType());
// Top level shapes can have this property changed
group->set_AnchorLocked(true);
// Set the XY coordinates of the shape group and the size of its containing block, as it appears on the page
group->set_Bounds(System::Drawing::RectangleF(100.0f, 50.0f, 200.0f, 100.0f));
// Set the scale of the inner coordinates of the shape group
// These values mean that the bottom right corner of the 200x100 outer block we set before
// will be at x = 2000 and y = 1000, or 2000 units from the left and 1000 units from the top
group->set_CoordSize(System::Drawing::Size(2000, 1000));
// The coordinate origin of a shape group is x = 0, y = 0 by default, which is the top left corner
// If we insert a child shape and set its distance from the left to 2000 and the distance from the top to 1000,
// its origin will be at the bottom right corner of the shape group
// We can offset the coordinate origin by setting the CoordOrigin attribute
// In this instance, we move the origin to the centre of the shape group
group->set_CoordOrigin(System::Drawing::Point(-1000, -500));
// Populate the shape group with child shapes
// First, insert a rectangle
auto subShape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Rectangle);
subShape->set_Width(500);
subShape->set_Height(700);
// Place its top left corner at the parent group's coordinate origin, which is currently at its centre
subShape->set_Left(0);
subShape->set_Top(0);
// Add the rectangle to the group
group->AppendChild(subShape);
// Insert a triangle
subShape = MakeObject<Shape>(doc, Aspose::Words::Drawing::ShapeType::Triangle);
subShape->set_Width(400);
subShape->set_Height(400);
// Place its origin at the bottom right corner of the group
subShape->set_Left(1000);
subShape->set_Top(500);
// The offset between this child shape and parent group can be seen here
ASPOSE_ASSERT_EQ(System::Drawing::PointF(1000.0f, 500.0f), subShape->LocalToParent(System::Drawing::PointF(0.0f, 0.0f)));
// Add the triangle to the group
group->AppendChild(subShape);
// Child shapes of a group shape are not top level
ASSERT_FALSE(subShape->get_IsTopLevel());
// Finally, insert the group into the document and save
builder->InsertNode(group);
doc->Save(ArtifactsDir + u"Shape.InsertGroupShape.docx");

◆ set_AllowOverlap()

void Aspose::Words::Drawing::ShapeBase::set_AllowOverlap ( bool  value)

◆ set_AlternativeText()

void Aspose::Words::Drawing::ShapeBase::set_AlternativeText ( System::String  value)

◆ set_AnchorLocked()

void Aspose::Words::Drawing::ShapeBase::set_AnchorLocked ( bool  value)

◆ set_AspectRatioLocked()

void Aspose::Words::Drawing::ShapeBase::set_AspectRatioLocked ( bool  value)

◆ set_BehindText()

void Aspose::Words::Drawing::ShapeBase::set_BehindText ( bool  value)

◆ set_Bounds()

void Aspose::Words::Drawing::ShapeBase::set_Bounds ( System::Drawing::RectangleF  value)

◆ set_CoordOrigin()

void Aspose::Words::Drawing::ShapeBase::set_CoordOrigin ( System::Drawing::Point  value)

◆ set_CoordSize()

void Aspose::Words::Drawing::ShapeBase::set_CoordSize ( System::Drawing::Size  value)

◆ set_DistanceBottom()

void Aspose::Words::Drawing::ShapeBase::set_DistanceBottom ( double  value)

◆ set_DistanceLeft()

void Aspose::Words::Drawing::ShapeBase::set_DistanceLeft ( double  value)

◆ set_DistanceRight()

void Aspose::Words::Drawing::ShapeBase::set_DistanceRight ( double  value)

◆ set_DistanceTop()

void Aspose::Words::Drawing::ShapeBase::set_DistanceTop ( double  value)

◆ set_FlipOrientation()

void Aspose::Words::Drawing::ShapeBase::set_FlipOrientation ( Aspose::Words::Drawing::FlipOrientation  value)

◆ set_Height()

void Aspose::Words::Drawing::ShapeBase::set_Height ( double  value)

◆ set_HorizontalAlignment()

void Aspose::Words::Drawing::ShapeBase::set_HorizontalAlignment ( Aspose::Words::Drawing::HorizontalAlignment  value)

◆ set_HRef()

void Aspose::Words::Drawing::ShapeBase::set_HRef ( System::String  value)

◆ set_IsLayoutInCell()

void Aspose::Words::Drawing::ShapeBase::set_IsLayoutInCell ( bool  value)

◆ set_Left()

void Aspose::Words::Drawing::ShapeBase::set_Left ( double  value)

◆ set_Name()

void Aspose::Words::Drawing::ShapeBase::set_Name ( System::String  value)

◆ set_RelativeHorizontalPosition()

void Aspose::Words::Drawing::ShapeBase::set_RelativeHorizontalPosition ( Aspose::Words::Drawing::RelativeHorizontalPosition  value)

◆ set_RelativeVerticalPosition()

void Aspose::Words::Drawing::ShapeBase::set_RelativeVerticalPosition ( Aspose::Words::Drawing::RelativeVerticalPosition  value)

◆ set_Rotation()

void Aspose::Words::Drawing::ShapeBase::set_Rotation ( double  value)

◆ set_ScreenTip()

void Aspose::Words::Drawing::ShapeBase::set_ScreenTip ( System::String  value)

◆ set_Target()

void Aspose::Words::Drawing::ShapeBase::set_Target ( System::String  value)

◆ set_Title()

void Aspose::Words::Drawing::ShapeBase::set_Title ( System::String  value)

◆ set_Top()

void Aspose::Words::Drawing::ShapeBase::set_Top ( double  value)

◆ set_VerticalAlignment()

void Aspose::Words::Drawing::ShapeBase::set_VerticalAlignment ( Aspose::Words::Drawing::VerticalAlignment  value)

◆ set_Width()

void Aspose::Words::Drawing::ShapeBase::set_Width ( double  value)

◆ set_WrapSide()

void Aspose::Words::Drawing::ShapeBase::set_WrapSide ( Aspose::Words::Drawing::WrapSide  value)

◆ set_WrapType()

void Aspose::Words::Drawing::ShapeBase::set_WrapType ( Aspose::Words::Drawing::WrapType  value)

◆ set_ZOrder()

void Aspose::Words::Drawing::ShapeBase::set_ZOrder ( int32_t  value)

◆ set_ZOrder_IShape()

void Aspose::Words::Drawing::ShapeBase::set_ZOrder_IShape ( int32_t  value)
override

◆ Type()

static const System::TypeInfo& Aspose::Words::Drawing::ShapeBase::Type ( )
static
@ Tight
Wraps tightly around the edges of the shape, instead of wrapping around the bounding box.
@ Around
Text is wrapped around the table occupying available side space.
String
@ Rectangle
@ Shape
A drawing object, such as an OfficeArt shape, image or an OLE object. A Shape node can contain Paragr...
static String ToString(const char_t *obj)
@ Sun
@ Margin
Specifies that the horizontal positioning shall be relative to the page margins.
@ Cube
float get_Height() const
@ Inline
The shape remains on the same layer as text and treated as a character.
@ Image
The shape is an image.
@ Page
The object is positioned relative to the top edge of the page.
@ Triangle
@ Horizontal
Flip along the y-axis, reversing the x-coordinates.
@ None
No text wrapping around the shape. The shape is placed behind or in front of text.
@ Word2010
Optimize Aspose.Words behavior to match MS Word 2010 version.
@ Center
Aligned to the center.
static ASPOSECPP_SHARED_API void WriteLine()
static ASPOSECPP_SHARED_API SharedPtr< Image > FromFile(const String &filename, bool use_embedded_color_management=false)
std::enable_if_t<!Details::IsIterable< Enumerable >::value, Details::EnumeratorAdapter< Enumerable, T > > IterateOver(System::SmartPtr< Enumerable > enumerable)
@ Page
The object is positioned relative to the left edge of the page.
@ BottomMargin
Specifies that the vertical positioning shall be relative to the bottom margin of the current page.
float get_X() const
@ TextBox
The shape is a textbox. Note that shapes of many other types can also have text inside them too....
SharedPtr< List< T > > LINQ_ToList()
@ Line
@ RightMargin
Specifies that the horizontal positioning shall be relative to the right margin of the page.
float get_Y() const
float get_Width() const
@ Center
Specifies that the object shall be centered with respect to the horizontal alignment base.
static ASPOSECPP_SHARED_API Color get_Blue()
@ Exactly
The height is specified exactly in points. Please note that if the text cannot fit inside the object ...
@ Center
Specifies that the object shall be centered with respect to the vertical alignment base.
@ Paragraph
The object is positioned relative to the top of the paragraph that contains the anchor.
@ TextPlainText
WordArt object.
@ Run
A run of text.
@ Top
Specifies that the object shall be at the top of the vertical alignment base.
@ Png
Renders a page of the document and saves it as a PNG file.
@ Table
A Table object that represents a table in a Word document. A Table node can have Row nodes.
static ASPOSECPP_SHARED_API Color get_Gainsboro()
static std::enable_if< IsExceptionWrapper< T >::value, bool >::type Equals(const T &obj, const T2 &another)
@ Center
Text is centered horizontally.