Skip to content

Instantly share code, notes, and snippets.

@weiweihuanghuang
Last active September 2, 2018 02:59
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 weiweihuanghuang/b0266db3aa7a1fe91a2d9c636c1b1d19 to your computer and use it in GitHub Desktop.
Save weiweihuanghuang/b0266db3aa7a1fe91a2d9c636c1b1d19 to your computer and use it in GitHub Desktop.
Skew only Paths and Anchors
#MenuTitle: Skew only Paths and Anchors
# -*- coding: utf-8 -*-
__doc__="""
"""
import GlyphsApp
import math
Font = Glyphs.font
Doc = Glyphs.currentDocument
selectedLayers = Font.selectedLayers
def italicSkew( x, y, angle=10.0 ):
"""Skews x/y along the x axis and returns skewed x value."""
new_angle = ( angle / 180.0 ) * math.pi
return x + y * math.tan( new_angle )
# thisMasterItalicAngle = Font.masters[thisLayer.associatedMasterId].italicAngle
skewAngle = 13
skewRadians = round(math.radians(skewAngle),2)
thisMasterXHeight = Font.masters[selectedLayers[0].associatedMasterId].xHeight
italicCorrection = italicSkew( 0.0, thisMasterXHeight/2.0, skewAngle )
for thisLayer in selectedLayers:
componentTransformDict = {}
for thisComponent in thisLayer.components:
componentTransformDict[thisComponent.componentName] = thisComponent.transform
Font.disableUpdateInterface()
thisLayer.applyTransform([
1, # x scale factor
0, # x skew factor
skewRadians, # y skew factor
1, # y scale factor
-italicCorrection, # x position
0 # y position
])
# shift component back to original position
for eachComponent in thisLayer.components:
thisComponent.transform = componentTransformDict[thisComponent.componentName]
Font.enableUpdateInterface()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment