Aspose::Words::Drawing::ShapeBase::get_BoundsInPoints method

ShapeBase::get_BoundsInPoints method

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

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

Remarks

The returned bounds do not include the rotation of this shape or the rotation of the parent group shape, if any.

Examples

Shows how to verify shape containing block boundaries.

auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);

System::SharedPtr<Aspose::Words::Drawing::Shape> shape = builder->InsertShape(ShapeType::Line, RelativeHorizontalPosition::LeftMargin, static_cast<double>(50), RelativeVerticalPosition::TopMargin, static_cast<double>(50), static_cast<double>(100), static_cast<double>(100), WrapType::None);
shape->set_StrokeColor(System::Drawing::Color::get_Orange());

// Even though the line itself takes up little space on the document page,
// it occupies a rectangular containing block, the size of which we can determine using the "Bounds" properties.
ASPOSE_ASSERT_EQ(shape->get_Bounds(), System::Drawing::RectangleF(static_cast<float>(50.0f), static_cast<float>(50.0f), static_cast<float>(100.0f), static_cast<float>(100.0f)));
ASPOSE_ASSERT_EQ(shape->get_BoundsInPoints(), System::Drawing::RectangleF(static_cast<float>(50.0f), static_cast<float>(50.0f), static_cast<float>(100.0f), static_cast<float>(100.0f)));

// Create a group shape, and then set the size of its containing block using the "Bounds" property.
auto group = System::MakeObject<Aspose::Words::Drawing::GroupShape>(doc);
group->set_Bounds(System::Drawing::RectangleF(static_cast<float>(0.0f), static_cast<float>(100.0f), static_cast<float>(250.0f), static_cast<float>(250.0f)));

ASPOSE_ASSERT_EQ(group->get_BoundsInPoints(), System::Drawing::RectangleF(static_cast<float>(0.0f), static_cast<float>(100.0f), static_cast<float>(250.0f), static_cast<float>(250.0f)));

// Create a rectangle, verify the size of its bounding block, and then add it to the group shape.
shape = System::MakeObject<Aspose::Words::Drawing::Shape>(doc, ShapeType::Rectangle);
shape->set_Width(100);
shape->set_Height(100);
shape->set_Left(700);
shape->set_Top(700);

ASPOSE_ASSERT_EQ(shape->get_BoundsInPoints(), System::Drawing::RectangleF(static_cast<float>(700.0f), static_cast<float>(700.0f), static_cast<float>(100.0f), static_cast<float>(100.0f)));

group->AppendChild<System::SharedPtr<Aspose::Words::Drawing::Shape>>(shape);

// The group shape's coordinate plane has its origin on the top left-hand side corner of its containing block,
// and the x and y coordinates of (1000, 1000) on the bottom right-hand side corner.
// Our group shape is 250x250pt in size, so every 4pt on the group shape's coordinate plane
// translates to 1pt in the document body's coordinate plane.
// Every shape that we insert will also shrink in size by a factor of 4.
// The change in the shape's "BoundsInPoints" property will reflect this.
ASPOSE_ASSERT_EQ(shape->get_BoundsInPoints(), System::Drawing::RectangleF(static_cast<float>(175.0f), static_cast<float>(275.0f), static_cast<float>(25.0f), static_cast<float>(25.0f)));

doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild<System::SharedPtr<Aspose::Words::Drawing::GroupShape>>(group);

// Insert a shape and place it outside of the bounds of the group shape's containing block.
shape = System::MakeObject<Aspose::Words::Drawing::Shape>(doc, ShapeType::Rectangle);
shape->set_Width(100);
shape->set_Height(100);
shape->set_Left(1000);
shape->set_Top(1000);

group->AppendChild<System::SharedPtr<Aspose::Words::Drawing::Shape>>(shape);

// The group shape's footprint in the document body has increased, but the containing block remains the same.
ASPOSE_ASSERT_EQ(group->get_BoundsInPoints(), System::Drawing::RectangleF(static_cast<float>(0.0f), static_cast<float>(100.0f), static_cast<float>(250.0f), static_cast<float>(250.0f)));
ASPOSE_ASSERT_EQ(shape->get_BoundsInPoints(), System::Drawing::RectangleF(static_cast<float>(250.0f), static_cast<float>(350.0f), static_cast<float>(25.0f), static_cast<float>(25.0f)));

doc->Save(get_ArtifactsDir() + u"Shape.Bounds.docx");

See Also