Skip to content

Instantly share code, notes, and snippets.

@pkolchanov
Last active June 28, 2023 15:09
Show Gist options
  • Save pkolchanov/cddf2ce719968b9a198b9c03a01b61d0 to your computer and use it in GitHub Desktop.
Save pkolchanov/cddf2ce719968b9a198b9c03a01b61d0 to your computer and use it in GitHub Desktop.
Tim Ahrens scaling
from dataclasses import dataclass
@dataclass
class Factor:
x: int
y: int
def interpolatedPosition(foregroundPosition, backgroundPosition, foregroundFactor, backgroundFactor):
interpolatedX = foregroundPosition.x * foregroundFactor.x + backgroundPosition.x * backgroundFactor.x
interpolatedY = foregroundPosition.y * foregroundFactor.y + backgroundPosition.y * backgroundFactor.y
interpolatedPosition = NSPoint(interpolatedX, interpolatedY)
return interpolatedPosition
def interpolatePaths(thisLayer, foregroundFactorX, foregroundFactorY):
foregroundFactor = Factor(foregroundFactorX, foregroundFactorY)
backgroundFactor = Factor(1- foregroundFactorX, 1-foregroundFactorY)
for path_index, path in enumerate(thisLayer.paths):
for node_index, node in enumerate(path.nodes):
foregroundPosition = node.position
bPath = thisLayer.background.paths[path_index]
if bPath:
backgroundPosition = bPath.nodes[node_index].position
node.setPosition_(interpolatedPosition(
foregroundPosition,
backgroundPosition,
foregroundFactor,
backgroundFactor,
))
foregroundStem = 65
backgroundStem = 100
targetScale = 0.6
targetFactor = (foregroundStem - backgroundStem*targetScale)/(foregroundStem*targetScale-backgroundStem*targetScale)
layers = Glyphs.font.selectedLayers
layer = layers[0]
RSB = layer.RSB
interpolatePaths(layer,targetFactor,1)
layer.applyTransform([targetScale,0,0,1,1,1])
layer.RSB = RSB
layer.syncMetrics()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment