DEV Community

Cover image for How to understand and align shapes in powerpoint
Antoine
Antoine

Posted on

How to understand and align shapes in powerpoint

Photo by Eaters Collective on Unsplash

The issue is simple.
I have a powerpoint whith shapes.

Alt Text

Using Open Xml SDK, i need to analyze a powerpoint slide containing shapes, and align them in an json.

Each shape has an offset property which defines its position (from the top left corner), and an extent property which defines its size.
Alt Text

Alt Text

We will use a column object to keep track of which shapes belongs to which column.

So, by just ordering shapes by their Offset.X property, we can sort the shapes on the X axis.
The first shape will be the current shape.
Then, using a loop, we can define if the next item is inside the current shape, if projected on X axis. If it's inside, it will be in the same column. If not, we can create a new column, and set the item as the current one.

In the example, A1 will be the current item. Then, A4 is the next one.

A1.Offset.X + A1.Extent.X > A4.Offset.X

Then A1 and A4 belongs to the same column. Then, A2 is the next item.

A1.Offset.X + A1.Extent.X < A2.Offset.X

Thus, we create a new column, and A2 is the current item, etc ... .

At the end we should have Alt Text

If we want to solve issues, when shapes are not here (for example, what if A4 does not exist ?). We can fill the column with fake shapes, and remove them when adding a shape.

Hope this helps !

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay