0
votes

In my never-ending quest to make my life easier, I've encountered something to make it more difficult.

Has anyone had any experience with why creating or editing objects in a Google Slide with Google Apps Script results in an inaccurate floating point version that's kinda close?

Example, creating an object:

SlidesApp
.getActivePresentation()
.getSlides()[0]
.insertShape(SlidesApp.ShapeType.RECTANGLE, 20, 20, 200, 200);

But the resulting rectangle has these properties:

Top: 20
Left: 20
Width: 200.00787401574803
Height: 200.00787401574803

And what's just as bad is the top and left 1px borders aren't pixel perfect as you'd expect given the correct top and left whole number value.

I discovered this because my first attempt at all this was to round the x/y,w/h to get shapes to at least be clean on the page, and that resulted in the same issues.

1
Removed, this should be the answer...Arlo

1 Answers

1
votes

Some more digging shows 2 things.

1) These crazy floats (rounding errors) aren't the cause of the blurring of my objects on the slide. They can safely be ignored.

2) It seems the pixel values a slide has are a multiple of .375. So to move an object 1px to the right, you actually have to move it .375 to the right. If you want to round the values of a slide's objects, you need to round the result of the value * 2.66666, then multiply the result by .375.

Example:

pageElements[0].setTop(Math.round((pageElements[0].getTop() * 2.6666666666666))*.375);

So now the original goal of pixel-perfect editing of objects in a sidebar tool I create is now possible. Whew!