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.
100 pt
is converted to EMU. 1 pt is 12,700 EMUs.100 pt x 12700 EMU/pt = 1270000 EMUs
- EMUs for
100 pt
is converted toscaleX
andscaleY
which are are unitless multiplying factors.3000000
is the base value. You can see it usingslides.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.
- When users retrieve the size of width and height, using
scaleX
andscaleY
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.
References :
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)