powerpoint-squircles 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- powerpoint_squircles-0.1.0/.gitignore +19 -0
- powerpoint_squircles-0.1.0/CHANGELOG.md +34 -0
- powerpoint_squircles-0.1.0/LICENSE +21 -0
- powerpoint_squircles-0.1.0/PKG-INFO +243 -0
- powerpoint_squircles-0.1.0/README.md +213 -0
- powerpoint_squircles-0.1.0/pyproject.toml +83 -0
- powerpoint_squircles-0.1.0/src/powerpoint_squircles/__init__.py +15 -0
- powerpoint_squircles-0.1.0/src/powerpoint_squircles/cli.py +150 -0
- powerpoint_squircles-0.1.0/src/powerpoint_squircles/convert.py +163 -0
- powerpoint_squircles-0.1.0/src/powerpoint_squircles/geometry.py +102 -0
- powerpoint_squircles-0.1.0/src/powerpoint_squircles/py.typed +0 -0
- powerpoint_squircles-0.1.0/tests/test_cli.py +203 -0
- powerpoint_squircles-0.1.0/tests/test_convert_scopes.py +199 -0
- powerpoint_squircles-0.1.0/tests/test_geometry_numeric.py +126 -0
- powerpoint_squircles-0.1.0/tests/test_squircle.py +192 -0
- powerpoint_squircles-0.1.0/tests/test_web_generator.py +310 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
build/
|
|
6
|
+
dist/
|
|
7
|
+
|
|
8
|
+
# Tooling
|
|
9
|
+
.venv/
|
|
10
|
+
.pytest_cache/
|
|
11
|
+
.ruff_cache/
|
|
12
|
+
|
|
13
|
+
# Editor / OS
|
|
14
|
+
.DS_Store
|
|
15
|
+
.claude/settings.local.json
|
|
16
|
+
|
|
17
|
+
# Sample decks for manual conversion checks
|
|
18
|
+
*.pptx
|
|
19
|
+
!assets/*.pptx
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project. The geometry constants are part of the
|
|
4
|
+
public interface: a change to them changes every shape drawn from a new version,
|
|
5
|
+
so they get their own heading.
|
|
6
|
+
|
|
7
|
+
The format is [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this
|
|
8
|
+
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-11-29
|
|
11
|
+
|
|
12
|
+
First public release: the geometry, the web generator, the library deck, and the
|
|
13
|
+
converter.
|
|
14
|
+
|
|
15
|
+
### Geometry
|
|
16
|
+
|
|
17
|
+
- The `custGeom` carries a text rect inset at the corners by `0.29289·R`,
|
|
18
|
+
`roundRect`'s own `1 − cos 45°`, rather than using the full bounding box.
|
|
19
|
+
Replacing a rounded rectangle therefore does not reflow the text inside it,
|
|
20
|
+
and text cannot run into the curve at large corner sizes. The inset stays
|
|
21
|
+
clear of the outline, since the squircle's 45° point sits nearer the corner
|
|
22
|
+
(`0.15910·R`) than the circle's.
|
|
23
|
+
|
|
24
|
+
### Notes
|
|
25
|
+
|
|
26
|
+
- `squircle-ify --corner` takes a percentage of the shorter side (`--corner
|
|
27
|
+
40`), not DrawingML's 1/1000-of-a-percent value. The library's `adj=` keeps
|
|
28
|
+
PowerPoint's convention (`adj=40000`).
|
|
29
|
+
- Writes go through a temporary file and an atomic rename, so an interrupted
|
|
30
|
+
save cannot leave a truncated deck, which matters most under `--in-place`,
|
|
31
|
+
where the input is the user's only copy.
|
|
32
|
+
- Requires Python 3.10 or newer.
|
|
33
|
+
|
|
34
|
+
[0.1.0]: https://github.com/WeinbergMalte/powerpoint-squircles/releases/tag/v0.1.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Malte Weinberg
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: powerpoint-squircles
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Curvature-continuous (G2) squircles for PowerPoint - the corner geometry roundRect should have had.
|
|
5
|
+
Project-URL: Homepage, https://github.com/WeinbergMalte/powerpoint-squircles
|
|
6
|
+
Project-URL: Issues, https://github.com/WeinbergMalte/powerpoint-squircles/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/WeinbergMalte/powerpoint-squircles/blob/main/CHANGELOG.md
|
|
8
|
+
Author: Malte Weinberg
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: design,drawingml,ooxml,powerpoint,pptx,squircle,superellipse
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
24
|
+
Classifier: Topic :: Office/Business :: Office Suites
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Requires-Dist: lxml>=4.9
|
|
28
|
+
Requires-Dist: python-pptx>=0.6.21
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# powerpoint-squircles
|
|
32
|
+
|
|
33
|
+
A squircle for PowerPoint, as a native shape you can edit like any other.
|
|
34
|
+
|
|
35
|
+
<p align="center"><img src="https://raw.githubusercontent.com/WeinbergMalte/powerpoint-squircles/main/assets/hero.png" height="300" alt="PowerPoint's rounded rectangle next to a squircle, both drawn by PowerPoint"></p>
|
|
36
|
+
|
|
37
|
+
PowerPoint's rounded rectangle has quarter circles for corners. A circle turns
|
|
38
|
+
at a constant rate and a straight edge doesn't turn at all, so where the two
|
|
39
|
+
meet the outline goes from no turning to full turning with nothing in between.
|
|
40
|
+
Few people notice this consciously. Put the two shapes side by side, though,
|
|
41
|
+
and the rounded rectangle looks slightly as if its corners had been attached
|
|
42
|
+
afterwards.
|
|
43
|
+
|
|
44
|
+
A **superellipse** corner (|x|⁴ + |y|⁴ = 1) begins to turn gradually and stops
|
|
45
|
+
gradually. This repo ships that corner as geometry which PowerPoint computes
|
|
46
|
+
itself, and that has a few practical consequences:
|
|
47
|
+
|
|
48
|
+
- **It is an ordinary shape.** Plain OOXML `custGeom`. No macro, no add-in, no
|
|
49
|
+
security prompt, and nothing the recipient of your deck has to install.
|
|
50
|
+
- **The yellow handle works.** It sets the corner size from 0 to 50% of the
|
|
51
|
+
shorter side, as it does on a rounded rectangle.
|
|
52
|
+
- **It can be stretched.** The corner size is a formula over the shorter side,
|
|
53
|
+
so a wide box keeps properly shaped corners instead of smeared ones.
|
|
54
|
+
- **There are no arcs in it.** Each corner is two cubic Béziers fitted to a
|
|
55
|
+
true superellipse (maximum deviation 0.00085·R), and they meet the straight
|
|
56
|
+
edges at exactly zero curvature.
|
|
57
|
+
|
|
58
|
+
PowerPoint has no squircle among its presets and offers no way of adding one:
|
|
59
|
+
the list of preset shapes is fixed, both in the file format and in the
|
|
60
|
+
application. Custom geometry is the one route left. That is less of a
|
|
61
|
+
compromise than it sounds, because custom geometry is written in the same
|
|
62
|
+
formula language as the built-in presets, and PowerPoint re-evaluates it at
|
|
63
|
+
every size.
|
|
64
|
+
|
|
65
|
+
## Get it
|
|
66
|
+
|
|
67
|
+
### Web generator: one shape to copy
|
|
68
|
+
|
|
69
|
+
**[weinbergmalte.github.io/powerpoint-squircles](https://weinbergmalte.github.io/powerpoint-squircles)**
|
|
70
|
+
|
|
71
|
+
Pick a corner size and download a `.pptx`. The file holds a comparison slide:
|
|
72
|
+
each squircle sits next to PowerPoint's own `roundRect` at the *same*
|
|
73
|
+
adjustment value, at two aspect ratios, with a short explanation on the slide.
|
|
74
|
+
Both are drawn by your copy of PowerPoint, so you don't have to take a
|
|
75
|
+
screenshot's word for the difference. Copy a squircle into your own deck and
|
|
76
|
+
the handle comes along.
|
|
77
|
+
|
|
78
|
+
There is also a **Copy as SVG** button, in case you would rather not open a
|
|
79
|
+
downloaded file. It has a cost: PowerPoint's *Convert to Shape* turns an SVG
|
|
80
|
+
into a fixed freeform. The curve is the same, but the handle is gone and the
|
|
81
|
+
corners distort when you resize.
|
|
82
|
+
|
|
83
|
+
The page is a single static HTML file with no dependencies and no build step.
|
|
84
|
+
It doesn't even need a zip library, because an OPC package may store its
|
|
85
|
+
entries uncompressed. View source if you are curious.
|
|
86
|
+
|
|
87
|
+
The same deck is checked in as
|
|
88
|
+
[`assets/squircle_library.pptx`](https://github.com/WeinbergMalte/powerpoint-squircles/blob/main/assets/squircle_library.pptx), for offline use
|
|
89
|
+
or for keeping in a template.
|
|
90
|
+
|
|
91
|
+
### Python converter: decks you already have
|
|
92
|
+
|
|
93
|
+
To run it once, without installing anything:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
uvx --from powerpoint-squircles squircle-ify deck.pptx
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
To install `squircle-ify` and use the other flags:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
uv tool install powerpoint-squircles
|
|
103
|
+
squircle-ify deck.pptx # every rounded rectangle -> squircle (radius preserved)
|
|
104
|
+
squircle-ify deck.pptx --corner 42 --all-rects # everything, uniform 42% corners
|
|
105
|
+
squircle-ify deck.pptx --layouts --masters # reach into layouts and masters too
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Shapes inside groups are converted at any depth. Layouts and masters are only
|
|
109
|
+
touched on request, since the placeholder frames on a master are usually plain
|
|
110
|
+
rectangles that should stay that way. They are always counted in the report,
|
|
111
|
+
though: when a conversion seems to have done nothing, the rounded rectangles
|
|
112
|
+
are usually sitting in the layouts.
|
|
113
|
+
|
|
114
|
+
One thing to expect: a converted corner looks a little tighter than the one it
|
|
115
|
+
replaces. At the same corner size a superellipse reaches further into the
|
|
116
|
+
corner than a circle does (the overlay further down shows by how much). The
|
|
117
|
+
converter keeps each shape's value and doesn't try to compensate. Pass
|
|
118
|
+
`--corner` if you want them rounder.
|
|
119
|
+
|
|
120
|
+
As a library (`uv add powerpoint-squircles`, or `pip install powerpoint-squircles`)
|
|
121
|
+
it works on top of [python-pptx](https://github.com/scanny/python-pptx):
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from pptx import Presentation
|
|
125
|
+
from pptx.util import Inches
|
|
126
|
+
from pptx.enum.shapes import MSO_SHAPE
|
|
127
|
+
from powerpoint_squircles import set_squircle, squircle_ify
|
|
128
|
+
|
|
129
|
+
prs = Presentation()
|
|
130
|
+
slide = prs.slides.add_slide(prs.slide_layouts[6])
|
|
131
|
+
box = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(1), Inches(1), Inches(3), Inches(2))
|
|
132
|
+
set_squircle(box, adj=42000) # one shape...
|
|
133
|
+
squircle_ify(prs) # ...or every roundRect in the deck
|
|
134
|
+
prs.save("out.pptx")
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Why the corner looks different
|
|
138
|
+
|
|
139
|
+
Curvature measures how sharply a curve is turning: zero on a straight edge,
|
|
140
|
+
1/r everywhere on a circle of radius r. A quarter-circle corner therefore has
|
|
141
|
+
to jump from zero to 1/r at the join. Edge and arc agree on direction there,
|
|
142
|
+
but not on the rate of turning. In the jargon that is a **G1** join.
|
|
143
|
+
|
|
144
|
+
A superellipse has zero curvature where it crosses the axes, so it joins the
|
|
145
|
+
straight edge without a step: **G2**. The curvature rises, peaks in the middle
|
|
146
|
+
of the corner and falls again.
|
|
147
|
+
|
|
148
|
+
<p align="center"><picture>
|
|
149
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/WeinbergMalte/powerpoint-squircles/main/assets/curvature-dark.png">
|
|
150
|
+
<img src="https://raw.githubusercontent.com/WeinbergMalte/powerpoint-squircles/main/assets/curvature.png" width="820" alt="Curvature combs: PowerPoint's circular arc vs an n=4 superellipse">
|
|
151
|
+
</picture></p>
|
|
152
|
+
|
|
153
|
+
*Curvature combs for both corners, each taking up the same length of straight
|
|
154
|
+
edge. **Left:** the circular arc. The teeth are at full length from the first
|
|
155
|
+
point of the corner. **Right:** the superellipse. The teeth grow from nothing
|
|
156
|
+
and shrink back. The bottom panel shows the same thing as a graph of curvature
|
|
157
|
+
against arc length. Regenerate with* `task figures`.
|
|
158
|
+
|
|
159
|
+
How much this matters depends on the corner. On a box with slightly softened
|
|
160
|
+
corners you will struggle to see it. On large, deliberately round shapes such
|
|
161
|
+
as cards, callouts and buttons it is visible, and that is where the shape is
|
|
162
|
+
worth using.
|
|
163
|
+
|
|
164
|
+
## The geometry
|
|
165
|
+
|
|
166
|
+
A quadrant of `x⁴ + y⁴ = 1` is approximated by two cubic Béziers that meet at
|
|
167
|
+
the 45° point. The constraints settle nearly everything. The curve has to pass
|
|
168
|
+
through the endpoints and the 45° point, leave the edges in exactly the edge
|
|
169
|
+
direction, have **zero curvature at the edge joins** (done by placing each
|
|
170
|
+
cubic's first three control points on the edge line), and have matching
|
|
171
|
+
tangents at the seam, which follows from symmetry. That leaves one free
|
|
172
|
+
parameter, fitted by least squares against the algebraic residual
|
|
173
|
+
`x⁴ + y⁴ − 1`.
|
|
174
|
+
|
|
175
|
+
Of the three control offsets, then, only the first is a fitted number, and the
|
|
176
|
+
result is not sensitive to it. The other two follow from the construction:
|
|
177
|
+
|
|
178
|
+
| offset | value | how it's determined |
|
|
179
|
+
|---|---|---|
|
|
180
|
+
| first control | 0.43593 | the single free parameter, least-squares fit |
|
|
181
|
+
| second control | 0.68179 | **forced**: 2·cos(π/4)^½ − 1, the only value putting the seam tangent on (1,−1) |
|
|
182
|
+
| 45° seam point | 0.84090 | **forced**: cos(π/4)^½, the exact 45° point of x⁴+y⁴=1 |
|
|
183
|
+
|
|
184
|
+
<p align="center"><picture>
|
|
185
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/WeinbergMalte/powerpoint-squircles/main/assets/corner-overlay-dark.png">
|
|
186
|
+
<img src="https://raw.githubusercontent.com/WeinbergMalte/powerpoint-squircles/main/assets/corner-overlay.png" width="440" alt="The same corner drawn four ways">
|
|
187
|
+
</picture></p>
|
|
188
|
+
|
|
189
|
+
*Could a circle have done the job? At the same corner size (grey) it is clearly
|
|
190
|
+
a different shape. A fairer comparison is the circle whose outline differs
|
|
191
|
+
least from the superellipse, `r = 0.56·R` (red), and that one follows the curve
|
|
192
|
+
closely. It still cannot reach the straight edge without a step in curvature.*
|
|
193
|
+
|
|
194
|
+
In DrawingML these become guide formulas over `ss`, the shorter side, so the
|
|
195
|
+
construction is re-evaluated by PowerPoint at every size. See
|
|
196
|
+
[`assets/squircle_custgeom.xml`](https://github.com/WeinbergMalte/powerpoint-squircles/blob/main/assets/squircle_custgeom.xml), the primitive
|
|
197
|
+
that everything else here wraps.
|
|
198
|
+
|
|
199
|
+
A caveat: the fit is G2 but not G3. At the 45° seam the curvature has a shallow
|
|
200
|
+
local minimum, 4.7% below its peak, where the true superellipse has a single
|
|
201
|
+
maximum. The curvature stays continuous, so there is no step, but a curvature
|
|
202
|
+
comb will show the dip, and I would rather mention it here than have someone
|
|
203
|
+
else find it.
|
|
204
|
+
|
|
205
|
+
## Working on it
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
task check # lint + tests, the same thing CI runs
|
|
209
|
+
task figures # regenerate everything in assets/
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
The geometry exists in four places on purpose: Python, the JS in `index.html`,
|
|
213
|
+
the XML asset and the library deck. A test pins each copy, and the numbers
|
|
214
|
+
quoted above, against `src/powerpoint_squircles/geometry.py`, so changing a
|
|
215
|
+
constant in one place fails the suite until the others follow. Details in
|
|
216
|
+
[`AGENTS.md`](https://github.com/WeinbergMalte/powerpoint-squircles/blob/main/AGENTS.md).
|
|
217
|
+
|
|
218
|
+
### Publishing
|
|
219
|
+
|
|
220
|
+
Releases go out on a tag (`git tag v0.1.0 && git push origin v0.1.0`) via
|
|
221
|
+
[`.github/workflows/release.yml`](https://github.com/WeinbergMalte/powerpoint-squircles/blob/main/.github/workflows/release.yml), which checks
|
|
222
|
+
the tag against `__version__`, re-runs the suite, builds, publishes, and cuts a
|
|
223
|
+
GitHub release. Authentication is PyPI Trusted Publishing, so there is no API
|
|
224
|
+
token in this repo; it needs a publisher registered on PyPI once, under
|
|
225
|
+
*Your projects → Publishing*, with these values:
|
|
226
|
+
|
|
227
|
+
| field | value |
|
|
228
|
+
|---|---|
|
|
229
|
+
| PyPI project name | `powerpoint-squircles` |
|
|
230
|
+
| owner | `WeinbergMalte` |
|
|
231
|
+
| repository | `powerpoint-squircles` |
|
|
232
|
+
| workflow | `release.yml` |
|
|
233
|
+
| environment | `pypi` |
|
|
234
|
+
|
|
235
|
+
## Roadmap
|
|
236
|
+
|
|
237
|
+
- [x] Publish to PyPI (`pip install powerpoint-squircles`)
|
|
238
|
+
- [ ] SVG/Figma export of the identical geometry, for cross-tool consistency
|
|
239
|
+
|
|
240
|
+
## License
|
|
241
|
+
|
|
242
|
+
MIT. The constants and the XML are small enough to embed in your own project.
|
|
243
|
+
Please do. A credit is appreciated.
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# powerpoint-squircles
|
|
2
|
+
|
|
3
|
+
A squircle for PowerPoint, as a native shape you can edit like any other.
|
|
4
|
+
|
|
5
|
+
<p align="center"><img src="assets/hero.png" height="300" alt="PowerPoint's rounded rectangle next to a squircle, both drawn by PowerPoint"></p>
|
|
6
|
+
|
|
7
|
+
PowerPoint's rounded rectangle has quarter circles for corners. A circle turns
|
|
8
|
+
at a constant rate and a straight edge doesn't turn at all, so where the two
|
|
9
|
+
meet the outline goes from no turning to full turning with nothing in between.
|
|
10
|
+
Few people notice this consciously. Put the two shapes side by side, though,
|
|
11
|
+
and the rounded rectangle looks slightly as if its corners had been attached
|
|
12
|
+
afterwards.
|
|
13
|
+
|
|
14
|
+
A **superellipse** corner (|x|⁴ + |y|⁴ = 1) begins to turn gradually and stops
|
|
15
|
+
gradually. This repo ships that corner as geometry which PowerPoint computes
|
|
16
|
+
itself, and that has a few practical consequences:
|
|
17
|
+
|
|
18
|
+
- **It is an ordinary shape.** Plain OOXML `custGeom`. No macro, no add-in, no
|
|
19
|
+
security prompt, and nothing the recipient of your deck has to install.
|
|
20
|
+
- **The yellow handle works.** It sets the corner size from 0 to 50% of the
|
|
21
|
+
shorter side, as it does on a rounded rectangle.
|
|
22
|
+
- **It can be stretched.** The corner size is a formula over the shorter side,
|
|
23
|
+
so a wide box keeps properly shaped corners instead of smeared ones.
|
|
24
|
+
- **There are no arcs in it.** Each corner is two cubic Béziers fitted to a
|
|
25
|
+
true superellipse (maximum deviation 0.00085·R), and they meet the straight
|
|
26
|
+
edges at exactly zero curvature.
|
|
27
|
+
|
|
28
|
+
PowerPoint has no squircle among its presets and offers no way of adding one:
|
|
29
|
+
the list of preset shapes is fixed, both in the file format and in the
|
|
30
|
+
application. Custom geometry is the one route left. That is less of a
|
|
31
|
+
compromise than it sounds, because custom geometry is written in the same
|
|
32
|
+
formula language as the built-in presets, and PowerPoint re-evaluates it at
|
|
33
|
+
every size.
|
|
34
|
+
|
|
35
|
+
## Get it
|
|
36
|
+
|
|
37
|
+
### Web generator: one shape to copy
|
|
38
|
+
|
|
39
|
+
**[weinbergmalte.github.io/powerpoint-squircles](https://weinbergmalte.github.io/powerpoint-squircles)**
|
|
40
|
+
|
|
41
|
+
Pick a corner size and download a `.pptx`. The file holds a comparison slide:
|
|
42
|
+
each squircle sits next to PowerPoint's own `roundRect` at the *same*
|
|
43
|
+
adjustment value, at two aspect ratios, with a short explanation on the slide.
|
|
44
|
+
Both are drawn by your copy of PowerPoint, so you don't have to take a
|
|
45
|
+
screenshot's word for the difference. Copy a squircle into your own deck and
|
|
46
|
+
the handle comes along.
|
|
47
|
+
|
|
48
|
+
There is also a **Copy as SVG** button, in case you would rather not open a
|
|
49
|
+
downloaded file. It has a cost: PowerPoint's *Convert to Shape* turns an SVG
|
|
50
|
+
into a fixed freeform. The curve is the same, but the handle is gone and the
|
|
51
|
+
corners distort when you resize.
|
|
52
|
+
|
|
53
|
+
The page is a single static HTML file with no dependencies and no build step.
|
|
54
|
+
It doesn't even need a zip library, because an OPC package may store its
|
|
55
|
+
entries uncompressed. View source if you are curious.
|
|
56
|
+
|
|
57
|
+
The same deck is checked in as
|
|
58
|
+
[`assets/squircle_library.pptx`](assets/squircle_library.pptx), for offline use
|
|
59
|
+
or for keeping in a template.
|
|
60
|
+
|
|
61
|
+
### Python converter: decks you already have
|
|
62
|
+
|
|
63
|
+
To run it once, without installing anything:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
uvx --from powerpoint-squircles squircle-ify deck.pptx
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
To install `squircle-ify` and use the other flags:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
uv tool install powerpoint-squircles
|
|
73
|
+
squircle-ify deck.pptx # every rounded rectangle -> squircle (radius preserved)
|
|
74
|
+
squircle-ify deck.pptx --corner 42 --all-rects # everything, uniform 42% corners
|
|
75
|
+
squircle-ify deck.pptx --layouts --masters # reach into layouts and masters too
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Shapes inside groups are converted at any depth. Layouts and masters are only
|
|
79
|
+
touched on request, since the placeholder frames on a master are usually plain
|
|
80
|
+
rectangles that should stay that way. They are always counted in the report,
|
|
81
|
+
though: when a conversion seems to have done nothing, the rounded rectangles
|
|
82
|
+
are usually sitting in the layouts.
|
|
83
|
+
|
|
84
|
+
One thing to expect: a converted corner looks a little tighter than the one it
|
|
85
|
+
replaces. At the same corner size a superellipse reaches further into the
|
|
86
|
+
corner than a circle does (the overlay further down shows by how much). The
|
|
87
|
+
converter keeps each shape's value and doesn't try to compensate. Pass
|
|
88
|
+
`--corner` if you want them rounder.
|
|
89
|
+
|
|
90
|
+
As a library (`uv add powerpoint-squircles`, or `pip install powerpoint-squircles`)
|
|
91
|
+
it works on top of [python-pptx](https://github.com/scanny/python-pptx):
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from pptx import Presentation
|
|
95
|
+
from pptx.util import Inches
|
|
96
|
+
from pptx.enum.shapes import MSO_SHAPE
|
|
97
|
+
from powerpoint_squircles import set_squircle, squircle_ify
|
|
98
|
+
|
|
99
|
+
prs = Presentation()
|
|
100
|
+
slide = prs.slides.add_slide(prs.slide_layouts[6])
|
|
101
|
+
box = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(1), Inches(1), Inches(3), Inches(2))
|
|
102
|
+
set_squircle(box, adj=42000) # one shape...
|
|
103
|
+
squircle_ify(prs) # ...or every roundRect in the deck
|
|
104
|
+
prs.save("out.pptx")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Why the corner looks different
|
|
108
|
+
|
|
109
|
+
Curvature measures how sharply a curve is turning: zero on a straight edge,
|
|
110
|
+
1/r everywhere on a circle of radius r. A quarter-circle corner therefore has
|
|
111
|
+
to jump from zero to 1/r at the join. Edge and arc agree on direction there,
|
|
112
|
+
but not on the rate of turning. In the jargon that is a **G1** join.
|
|
113
|
+
|
|
114
|
+
A superellipse has zero curvature where it crosses the axes, so it joins the
|
|
115
|
+
straight edge without a step: **G2**. The curvature rises, peaks in the middle
|
|
116
|
+
of the corner and falls again.
|
|
117
|
+
|
|
118
|
+
<p align="center"><picture>
|
|
119
|
+
<source media="(prefers-color-scheme: dark)" srcset="assets/curvature-dark.png">
|
|
120
|
+
<img src="assets/curvature.png" width="820" alt="Curvature combs: PowerPoint's circular arc vs an n=4 superellipse">
|
|
121
|
+
</picture></p>
|
|
122
|
+
|
|
123
|
+
*Curvature combs for both corners, each taking up the same length of straight
|
|
124
|
+
edge. **Left:** the circular arc. The teeth are at full length from the first
|
|
125
|
+
point of the corner. **Right:** the superellipse. The teeth grow from nothing
|
|
126
|
+
and shrink back. The bottom panel shows the same thing as a graph of curvature
|
|
127
|
+
against arc length. Regenerate with* `task figures`.
|
|
128
|
+
|
|
129
|
+
How much this matters depends on the corner. On a box with slightly softened
|
|
130
|
+
corners you will struggle to see it. On large, deliberately round shapes such
|
|
131
|
+
as cards, callouts and buttons it is visible, and that is where the shape is
|
|
132
|
+
worth using.
|
|
133
|
+
|
|
134
|
+
## The geometry
|
|
135
|
+
|
|
136
|
+
A quadrant of `x⁴ + y⁴ = 1` is approximated by two cubic Béziers that meet at
|
|
137
|
+
the 45° point. The constraints settle nearly everything. The curve has to pass
|
|
138
|
+
through the endpoints and the 45° point, leave the edges in exactly the edge
|
|
139
|
+
direction, have **zero curvature at the edge joins** (done by placing each
|
|
140
|
+
cubic's first three control points on the edge line), and have matching
|
|
141
|
+
tangents at the seam, which follows from symmetry. That leaves one free
|
|
142
|
+
parameter, fitted by least squares against the algebraic residual
|
|
143
|
+
`x⁴ + y⁴ − 1`.
|
|
144
|
+
|
|
145
|
+
Of the three control offsets, then, only the first is a fitted number, and the
|
|
146
|
+
result is not sensitive to it. The other two follow from the construction:
|
|
147
|
+
|
|
148
|
+
| offset | value | how it's determined |
|
|
149
|
+
|---|---|---|
|
|
150
|
+
| first control | 0.43593 | the single free parameter, least-squares fit |
|
|
151
|
+
| second control | 0.68179 | **forced**: 2·cos(π/4)^½ − 1, the only value putting the seam tangent on (1,−1) |
|
|
152
|
+
| 45° seam point | 0.84090 | **forced**: cos(π/4)^½, the exact 45° point of x⁴+y⁴=1 |
|
|
153
|
+
|
|
154
|
+
<p align="center"><picture>
|
|
155
|
+
<source media="(prefers-color-scheme: dark)" srcset="assets/corner-overlay-dark.png">
|
|
156
|
+
<img src="assets/corner-overlay.png" width="440" alt="The same corner drawn four ways">
|
|
157
|
+
</picture></p>
|
|
158
|
+
|
|
159
|
+
*Could a circle have done the job? At the same corner size (grey) it is clearly
|
|
160
|
+
a different shape. A fairer comparison is the circle whose outline differs
|
|
161
|
+
least from the superellipse, `r = 0.56·R` (red), and that one follows the curve
|
|
162
|
+
closely. It still cannot reach the straight edge without a step in curvature.*
|
|
163
|
+
|
|
164
|
+
In DrawingML these become guide formulas over `ss`, the shorter side, so the
|
|
165
|
+
construction is re-evaluated by PowerPoint at every size. See
|
|
166
|
+
[`assets/squircle_custgeom.xml`](assets/squircle_custgeom.xml), the primitive
|
|
167
|
+
that everything else here wraps.
|
|
168
|
+
|
|
169
|
+
A caveat: the fit is G2 but not G3. At the 45° seam the curvature has a shallow
|
|
170
|
+
local minimum, 4.7% below its peak, where the true superellipse has a single
|
|
171
|
+
maximum. The curvature stays continuous, so there is no step, but a curvature
|
|
172
|
+
comb will show the dip, and I would rather mention it here than have someone
|
|
173
|
+
else find it.
|
|
174
|
+
|
|
175
|
+
## Working on it
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
task check # lint + tests, the same thing CI runs
|
|
179
|
+
task figures # regenerate everything in assets/
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
The geometry exists in four places on purpose: Python, the JS in `index.html`,
|
|
183
|
+
the XML asset and the library deck. A test pins each copy, and the numbers
|
|
184
|
+
quoted above, against `src/powerpoint_squircles/geometry.py`, so changing a
|
|
185
|
+
constant in one place fails the suite until the others follow. Details in
|
|
186
|
+
[`AGENTS.md`](AGENTS.md).
|
|
187
|
+
|
|
188
|
+
### Publishing
|
|
189
|
+
|
|
190
|
+
Releases go out on a tag (`git tag v0.1.0 && git push origin v0.1.0`) via
|
|
191
|
+
[`.github/workflows/release.yml`](.github/workflows/release.yml), which checks
|
|
192
|
+
the tag against `__version__`, re-runs the suite, builds, publishes, and cuts a
|
|
193
|
+
GitHub release. Authentication is PyPI Trusted Publishing, so there is no API
|
|
194
|
+
token in this repo; it needs a publisher registered on PyPI once, under
|
|
195
|
+
*Your projects → Publishing*, with these values:
|
|
196
|
+
|
|
197
|
+
| field | value |
|
|
198
|
+
|---|---|
|
|
199
|
+
| PyPI project name | `powerpoint-squircles` |
|
|
200
|
+
| owner | `WeinbergMalte` |
|
|
201
|
+
| repository | `powerpoint-squircles` |
|
|
202
|
+
| workflow | `release.yml` |
|
|
203
|
+
| environment | `pypi` |
|
|
204
|
+
|
|
205
|
+
## Roadmap
|
|
206
|
+
|
|
207
|
+
- [x] Publish to PyPI (`pip install powerpoint-squircles`)
|
|
208
|
+
- [ ] SVG/Figma export of the identical geometry, for cross-tool consistency
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
MIT. The constants and the XML are small enough to embed in your own project.
|
|
213
|
+
Please do. A credit is appreciated.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling", "hatch-fancy-pypi-readme"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "powerpoint-squircles"
|
|
7
|
+
dynamic = ["version", "readme"]
|
|
8
|
+
description = "Curvature-continuous (G2) squircles for PowerPoint - the corner geometry roundRect should have had."
|
|
9
|
+
license = "MIT"
|
|
10
|
+
license-files = ["LICENSE"]
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{ name = "Malte Weinberg" }]
|
|
13
|
+
keywords = ["powerpoint", "pptx", "squircle", "superellipse", "design", "ooxml", "drawingml"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Intended Audience :: End Users/Desktop",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Programming Language :: Python :: 3.14",
|
|
26
|
+
"Topic :: Office/Business :: Office Suites",
|
|
27
|
+
"Topic :: Multimedia :: Graphics",
|
|
28
|
+
"Typing :: Typed",
|
|
29
|
+
]
|
|
30
|
+
dependencies = ["python-pptx>=0.6.21", "lxml>=4.9"]
|
|
31
|
+
|
|
32
|
+
[dependency-groups]
|
|
33
|
+
dev = ["pytest>=7", "ruff>=0.6"]
|
|
34
|
+
plot = ["matplotlib>=3.7", "numpy>=1.24"]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Homepage = "https://github.com/WeinbergMalte/powerpoint-squircles"
|
|
38
|
+
Issues = "https://github.com/WeinbergMalte/powerpoint-squircles/issues"
|
|
39
|
+
Changelog = "https://github.com/WeinbergMalte/powerpoint-squircles/blob/main/CHANGELOG.md"
|
|
40
|
+
|
|
41
|
+
[project.scripts]
|
|
42
|
+
squircle-ify = "powerpoint_squircles.cli:main"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.version]
|
|
45
|
+
path = "src/powerpoint_squircles/__init__.py"
|
|
46
|
+
|
|
47
|
+
# README.md keeps relative links so it renders on GitHub whatever the repo is
|
|
48
|
+
# called. PyPI renders it standalone, where a relative path is a broken image,
|
|
49
|
+
# so the copy that goes into the package metadata gets absolute URLs at build
|
|
50
|
+
# time. tests/test_squircle.py::test_pypi_readme_has_no_relative_links applies
|
|
51
|
+
# the same substitutions and checks nothing relative is left.
|
|
52
|
+
[tool.hatch.metadata.hooks.fancy-pypi-readme]
|
|
53
|
+
content-type = "text/markdown"
|
|
54
|
+
|
|
55
|
+
[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
|
|
56
|
+
path = "README.md"
|
|
57
|
+
|
|
58
|
+
[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
|
|
59
|
+
pattern = '(src|srcset)="(?!https?://)'
|
|
60
|
+
replacement = '\1="https://raw.githubusercontent.com/WeinbergMalte/powerpoint-squircles/main/'
|
|
61
|
+
|
|
62
|
+
[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
|
|
63
|
+
pattern = '\]\((?!https?://|#)'
|
|
64
|
+
replacement = '](https://github.com/WeinbergMalte/powerpoint-squircles/blob/main/'
|
|
65
|
+
|
|
66
|
+
[tool.hatch.build.targets.wheel]
|
|
67
|
+
packages = ["src/powerpoint_squircles"]
|
|
68
|
+
|
|
69
|
+
# The figures and the library deck are the README's, not the package's: they are
|
|
70
|
+
# ~700 kB that nobody pip-installing needs, and the README links them by URL.
|
|
71
|
+
[tool.hatch.build.targets.sdist]
|
|
72
|
+
include = ["src", "tests", "README.md", "CHANGELOG.md", "LICENSE", "pyproject.toml"]
|
|
73
|
+
|
|
74
|
+
[tool.ruff]
|
|
75
|
+
line-length = 100
|
|
76
|
+
target-version = "py310"
|
|
77
|
+
|
|
78
|
+
[tool.ruff.lint]
|
|
79
|
+
extend-select = ["I"]
|
|
80
|
+
|
|
81
|
+
[tool.pytest.ini_options]
|
|
82
|
+
testpaths = ["tests"]
|
|
83
|
+
pythonpath = ["src", "scripts"]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""powerpoint-squircles: curvature-continuous (G2) squircles for PowerPoint."""
|
|
2
|
+
|
|
3
|
+
from .convert import count_candidates, set_squircle, squircle_ify, squircle_ify_report
|
|
4
|
+
from .geometry import DEFAULT_ADJ, MAX_ADJ, custgeom
|
|
5
|
+
|
|
6
|
+
__version__ = "0.1.0"
|
|
7
|
+
__all__ = [
|
|
8
|
+
"custgeom",
|
|
9
|
+
"set_squircle",
|
|
10
|
+
"squircle_ify",
|
|
11
|
+
"squircle_ify_report",
|
|
12
|
+
"count_candidates",
|
|
13
|
+
"DEFAULT_ADJ",
|
|
14
|
+
"MAX_ADJ",
|
|
15
|
+
]
|