scanny / python-pptx

Create Open XML PowerPoint documents in Python
MIT License
2.26k stars 498 forks source link

Pixel Unit of Measurement #943

Open hendursaga opened 5 months ago

hendursaga commented 5 months ago

I was reading through the documentation, and spotted this:

https://github.com/scanny/python-pptx/blob/d043334b984736a7a2ade3fb6f9adcdd97b3e8f5/pptx/util.py#L10-L23

It still implies that there is a Px class, but there is no _EMUS_PER_PX constant or anything related to pixels.

hendursaga commented 5 months ago

I am assuming that a pixel, in the context of a PowerPoint, would be 914,400 / 96 = 9,525 EMUs, or perhaps 914,400 / 72 = 12,700 EMUs.

scanny commented 5 months ago

Yeah, there's no universal agreement on the size of a pixel. Px was probably included in the docstring before I worked out there was no agree-upon definition there.

As I recall, on Mac it's 72 px/inch and in the PC world it's 100 px/inch (maybe Linux is 96). So you have to make your choice for your particular use case. It's easy enough to add a private subclass of Length or even to monkey-patch it if you like, so that might be an option for you.

But I don't think we're going to be adding Px to the library since you'd have to make it something like Px_72, Px_96, and Px_100 which doesn't pass the elegance test for me :)

scanny commented 5 months ago

Wouldn't hurt to fix that in the docs though, I'll leave this open for that purpose, thanks for reporting :)