Sizing and positioning page elements

There are two different ways you can get and change the size and position of
a page element:

Using its getter and setter functions for size and position.

Manipulating its affine transform, using its getTransform() and setTransform() functions while preserving the inherent size.

Reading page element properties

As shown in the figure, size and position are measured with respect to the
bounding box of a rendered page element when it has no rotation:

Left and Top: measured from the upper left corner of the page to the
upper left corner of the unrotated bounding box. Use getLeft() and getTop() to
read the values.

Width and Height: the width and height of the unrotated bounding box.
Use getWidth() and getHeight() to read the values.

Rotation: the clockwise rotation with respect to the vertical line around
the center of the bounding box. Use getRotation() to read the value.

All lengths are measured in points (pt). The rotation is measured in degrees
(°).

Setting page element properties

You can set the size and position of a page element when you create it using
an insert method such as insertShape(). For an existing shape, you can set
the size, position, and rotation; you can also set an element's scaling to
resize or to reflect it along one of its edges.

At creation

You can provide position and size information when creating a page element.

Scaling

Instead of using setWidth() and setHeight() above to set the size of the shape
to an absolute value, scaleWidth() and scaleHeight() can be used to stretch or
squeeze a page element with a relative scaling factor.

shape.scaleHeight(0.5).scaleWidth(2);

The figure below depicts how above code works on a 45°-rotated square shape.
Note that the upper left corner of the bounding box is fixed during scaling.

Reflection along edge

The argument in scaleWidth() and scaleHeight() can be negative so that they can
be used to flip a page element horizontally or vertically.

shape.scaleWidth(-1); // Flip horizontally along the left edge of the bounding box.
shape.scaleHeight(-1); // Flip vertically along the top edge of the bounding box.

The figure below depicts how above code works on a 45°-rotated shape. Note that
the page element is flipped along one of the edges of its bounding box but not
its center.

Line rotation

Like other page elements, a line's rotation isn't the vertical angle of
the line, but the rotation of its bounding box. When you create a line with
specified start and end points, its rotation is always 0°. Dragging
the endpoints of the line in Google Slides UI changes its vertical angle as well
as the size and position of its bounding box, but doesn't change
its rotation. Using setRotation() rotates the bounding box of the line, which
effectively changes its vertical angle. So two lines can
have the same visual vertical angle, but different bounding boxes and therefore
different size, position, and rotation values.

Limitations

Some sizing and positioning methods are incompatible with some types of page
elements. The table below summarizes the methods which are not compatible with
certain types of page elements.

Methods

Shape

Video

Table

getHeight(), getWidth()

✔

✔

NO (returns null)

setHeight(), setWidth()

✔

✔

NO

setRotation()

✔

NO

NO

scaleHeight(), scaleWidth()

✔

✔

NO

All sizing and positioning methods may give unexpected results if the page
element has shearing. All limitations are subject to change. Check reference for
up-to-date information.

Using affine transforms

For advanced control, the size and position of a page element can also be
calculated and adjusted through its inherent (native) size and affine transform.