Instantly share code, notes, and snippets.

# tanaikech/submit.md

Created December 15, 2017 08:07
Show Gist options
• Save tanaikech/953e630855e65de55d8e5bd448ad764f to your computer and use it in GitHub Desktop.
Difference Between Given Values and Retrieved Values for Shapes on Google Slides

# Difference Between Given Values and Retrieved Values for Shapes on Google Slides

This is a document for explaining the difference between given values and retrieved values for shapes on Google Slides. When a shape is created to a slide using Slides API, most users give the size of height and width as `pt`. When the size is retrieved from the created shape as `pt`, the size is often difference from the given size.

For example, when a square shape is created by giving the height and width of 100 pt, the size which is retrieved from the created square becomes 99.99212598425197 pt for the height and width.

In this document, this will be explained.

At Slides, EMU is used as the default base unit. Slides manages all objects in the Slides using EMU. When the square with 100 pt in size is created, Slides processes as follows.

1. `100 pt` is converted to EMU. 1 pt is 12,700 EMUs.
• `100 pt x 12700 EMU/pt = 1270000 EMUs`
2. EMUs for `100 pt` is converted to `scaleX` and `scaleY` which are are unitless multiplying factors. `3000000` is the base value. You can see it using `slides.presentations.get`.
• `1270000 EMUs / 3000000 EMUs = 0.4233`
• At Slides API, I seemed that this calculation is often rounded. I thought that this was strange.
3. When users retrieve the size of width and height, using `scaleX` and `scaleY` EMU is converted to pt.
• `0.4233 x 3000000 EMUs / 12700 EMU/pt = 99.99212598425197 pt`
• This was calculated by the default calculator of windows.

By these flow, the square which was created by giving 100 pt in size has 99.99212598425197 pt in size.

## Appendix :

### Create a square with 100 pt in size

```var presentationId = "### presentationId ###";
var pageObjectId = "### pageObjectId ###";
var resource = {"requests":[{
"createShape":{
"shapeType":"RECTANGLE",
"elementProperties":{
"size":{
"height":{"magnitude":100,"unit":"pt"},
"width":{"magnitude":100,"unit":"pt"}},
"pageObjectId":pageObjectId
}
}
}]};
Slides.Presentations.batchUpdate(resource, presentationId);```

### Retrieve the size of created square

```var presentationId = "### presentationId ###";
var pageObjectId = "### pageObjectId ###";
var res = Slides.Presentations.Pages.get(presentationId, pageObjectId);
Logger.log("size: %s, transform: %s", res.pageElements[0].size, res.pageElements[0].transform)```