Skip to content

Instantly share code, notes, and snippets.

@typemytype
Created January 27, 2023 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typemytype/9782256a570b3f52f32343cad72ede1e to your computer and use it in GitHub Desktop.
Save typemytype/9782256a570b3f52f32343cad72ede1e to your computer and use it in GitHub Desktop.
Glyph to css clippath polygon
"""
draw a shape
useage in clip-path: polygon(...);
"""
glyph = CurrentGlyph()
for contour in glyph:
bounds = contour.bounds
if bounds:
minx, miny, maxx, maxy = bounds
w = maxx - minx
h = maxy - miny
relativePoints = []
for point in contour.points:
x = (point.x - minx) / w
y = (point.y - miny) / h
relativePoints.append(f"{x * 100}% {y * 100}%")
print(f"polygon({', '.join(relativePoints)});")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment