ShapeBaseAdjustWithEffects Method

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

Namespace:  Aspose.Words.Drawing
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0


public RectangleF AdjustWithEffects(
	RectangleF source


Type: System.DrawingRectangleF

Return Value

Type: RectangleF


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
Document doc = new Document(MyDir + "Shape shadow effect.docx");
List<Shape> shapes = doc.GetChildNodes(NodeType.Shape, true).Cast<Shape>().ToList();
Assert.AreEqual(2, shapes.Count);

// The two shapes are identical in terms of dimensions and shape type
Assert.AreEqual(shapes[0].Width, shapes[1].Width);
Assert.AreEqual(shapes[0].Height, shapes[1].Height);
Assert.AreEqual(shapes[0].ShapeType, shapes[1].ShapeType);

// However, the first shape has no effects, while the second one has a shadow and thick outline
Assert.AreEqual(0.0, shapes[0].StrokeWeight);
Assert.AreEqual(20.0, shapes[1].StrokeWeight);

// 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
Shape shape = shapes[0];

// Create a RectangleF object, which represents a rectangle, which we could potentially use as the coordinates and bounds for a shape
RectangleF rectangleF = new RectangleF(200, 200, 1000, 1000);

// Run this method to get the size of the rectangle adjusted for all of our shape's effects
RectangleF rectangleFOut = shape.AdjustWithEffects(rectangleF);

// Since the shape has no border-changing effects, its boundary dimensions are unaffected
Assert.AreEqual(200, rectangleFOut.X);
Assert.AreEqual(200, rectangleFOut.Y);
Assert.AreEqual(1000, rectangleFOut.Width);
Assert.AreEqual(1000, rectangleFOut.Height);

// The final extent of the first shape, in points
Assert.AreEqual(0, shape.BoundsWithEffects.X);
Assert.AreEqual(0, shape.BoundsWithEffects.Y);
Assert.AreEqual(147, shape.BoundsWithEffects.Width);
Assert.AreEqual(147, shape.BoundsWithEffects.Height);

// Do the same with the second shape
shape = shapes[1];
rectangleF = new RectangleF(200, 200, 1000, 1000);
rectangleFOut = shape.AdjustWithEffects(rectangleF);

// The shape's x/y coordinates (top left corner location) have been pushed back by the thick outline
Assert.AreEqual(171.5, rectangleFOut.X);
Assert.AreEqual(167, rectangleFOut.Y);

// The width and height were also affected by the outline and shadow
Assert.AreEqual(1045, rectangleFOut.Width);
Assert.AreEqual(1132, rectangleFOut.Height);

// These values are also affected by effects
Assert.AreEqual(-28.5, shape.BoundsWithEffects.X);
Assert.AreEqual(-33, shape.BoundsWithEffects.Y);
Assert.AreEqual(192, shape.BoundsWithEffects.Width);
Assert.AreEqual(279, shape.BoundsWithEffects.Height);

See Also