Skip to content

Instantly share code, notes, and snippets.

@connordavenport
Last active July 21, 2026 22:13
Show Gist options
  • Select an option

  • Save connordavenport/c04fd3b5fd6bcebcad683390437151bc to your computer and use it in GitHub Desktop.

Select an option

Save connordavenport/c04fd3b5fd6bcebcad683390437151bc to your computer and use it in GitHub Desktop.
a hack to add italic constraint to the fontparts' base object
import math
import mojo.roboFont as rf
from fontParts.fontshell import RBPoint
from fontParts.base import normalizers
IntFloatType = int | float
Coordinate = tuple[IntFloatType, IntFloatType]
CoordinateLike = list[IntFloatType] | Coordinate
### thanks tal for the x and y idea!
def moveBy_(
self,
value: CoordinateLike | IntFloatType,
xConstraintAngle: IntFloatType | None = None,
yConstraintAngle: IntFloatType | None = None,
) -> None:
assert not (xConstraintAngle and yConstraintAngle)
if xConstraintAngle:
if isinstance(value, tuple):
deltaX = value[0]
elif isinstance(value, (int, float)):
deltaX = value
deltaY = deltaX * math.tan(math.radians(xConstraintAngle))
value = deltaX, deltaY
#self.moveBy((deltaX, deltaY))
if yConstraintAngle:
if isinstance(value, tuple):
deltaY = value[1]
elif isinstance(value, (int, float)):
deltaY = value
deltaX = -deltaY * math.tan(math.radians(yConstraintAngle))
value = deltaX, deltaY
#self.moveBy((deltaX, deltaY))
value = normalizers.normalizeTransformationOffset(value)
self.moveBy(value)
for obj in (dir(rf)):
if obj.startswith("R") and obj[1].isupper():
attr = getattr(rf, obj)
if hasattr(attr, "moveBy"):
setattr(attr, "moveBy_", moveBy_)
RBPoint.moveBy_ = moveBy_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment