-
-
Save pkolchanov/cddf2ce719968b9a198b9c03a01b61d0 to your computer and use it in GitHub Desktop.
Tim Ahrens scaling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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