Skip to content

Instantly share code, notes, and snippets.

@kateliev
Last active May 10, 2022 21:13
Show Gist options
  • Save kateliev/d82695c93cd03acd2605d6512d3aed15 to your computer and use it in GitHub Desktop.
Save kateliev/d82695c93cd03acd2605d6512d3aed15 to your computer and use it in GitHub Desktop.
TypeRig: Reset Component
#FLM: Reset Components
#Note: Resets component whitout affecting its combinations
#-----------------------------------------------------------
# (C) Vassil Kateliev, 2022 (http://www.kateliev.com)
#------------------------------------------------------------
# No warranties. By using this you agree
# that you use it at your own risk!
# - Dependencies -----------------
# - Dependancies
from __future__ import absolute_import, print_function
import fontlab as fl6
import fontgate as fgt
import PythonQt as pqt
from typerig.proxy.fl.objects.font import pFont
from typerig.proxy.fl.objects.glyph import eGlyph
# - Config
process_layer = None # Could be any valid layer name. Use None for current layer!
target_LSB = 0 # X direction: 0 - Equals reset (but could be any value); None - skips.
target_VSB = None # Y direction: 0 - Equals reset (but could be any value); None - skips.
# - Init
current_font = pFont()
current_glyph = eGlyph()
current_LSB = current_glyph.getLSB(process_layer)
current_VSB = current_glyph.getVSB(process_layer)
delta_shift_X = 0 if target_LSB is None else -(target_LSB - current_LSB)
delta_shift_Y = 0 if target_VSB is None else -(target_VSB - current_VSB)
# - Process
# -- Set target
if target_LSB is not None: current_glyph.setLSB(target_LSB)
if target_VSB is not None: current_glyph.setVSB(target_VSB)
# -- Process combinations
for glyph in current_font.glyphs(extend=eGlyph):
try:
glyph_components = glyph.components(process_layer)
if len(glyph_components):
for component in glyph_components:
if component.shapeData.componentGlyph == current_glyph.name:
new_transform = component.transform.translate(delta_shift_X, delta_shift_Y)
component.transform = new_transform
glyph.updateObject(glyph.fl, 'Preserving transformation: %s' %glyph.name)
except AttributeError:
pass
# - Done
print('DONE:\tResetting component: %s\tLayer: %s' %(current_glyph.name, glyph.layer(process_layer).name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment