Aspose::Words::Drawing::ShapeBase::get_BoundsInPoints method
Contents
[
Hide
]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()
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(System::Drawing::RectangleF(static_cast<float>(50.0f), static_cast<float>(50.0f), static_cast<float>(100.0f), static_cast<float>(100.0f)), shape->get_Bounds());
ASPOSE_ASSERT_EQ(System::Drawing::RectangleF(static_cast<float>(50.0f), static_cast<float>(50.0f), static_cast<float>(100.0f), static_cast<float>(100.0f)), shape->get_BoundsInPoints());
// 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(System::Drawing::RectangleF(static_cast<float>(0.0f), static_cast<float>(100.0f), static_cast<float>(250.0f), static_cast<float>(250.0f)), group->get_BoundsInPoints());
// 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(System::Drawing::RectangleF(static_cast<float>(700.0f), static_cast<float>(700.0f), static_cast<float>(100.0f), static_cast<float>(100.0f)), shape->get_BoundsInPoints());
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(System::Drawing::RectangleF(static_cast<float>(175.0f), static_cast<float>(275.0f), static_cast<float>(25.0f), static_cast<float>(25.0f)), shape->get_BoundsInPoints());
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(System::Drawing::RectangleF(static_cast<float>(0.0f), static_cast<float>(100.0f), static_cast<float>(250.0f), static_cast<float>(250.0f)), group->get_BoundsInPoints());
ASPOSE_ASSERT_EQ(System::Drawing::RectangleF(static_cast<float>(250.0f), static_cast<float>(350.0f), static_cast<float>(25.0f), static_cast<float>(25.0f)), shape->get_BoundsInPoints());
doc->Save(get_ArtifactsDir() + u"Shape.Bounds.docx");
See Also
- Class ShapeBase
- Namespace Aspose::Words::Drawing
- Library Aspose.Words for C++