Skip to content

Instantly share code, notes, and snippets.

@mjlagattuta
Last active February 12, 2019 01:29
Show Gist options
  • Save mjlagattuta/fd6b4d0c822e4fac02b7b5e841a2bb75 to your computer and use it in GitHub Desktop.
Save mjlagattuta/fd6b4d0c822e4fac02b7b5e841a2bb75 to your computer and use it in GitHub Desktop.
# Copyright 2019 Michael LaGattuta
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Checks if there are optional anchors (i.e. multiple attachment points between two components)
import re
font = Glyphs.font
font.newTab().text = ""
def checkActualComponents(components ,glyph, glyphNames):
baseAnchors = {}
attachAnchors = {}
conflictingAnchors = []
for i in range(len(actualComponents) - 1):
for anchor in font.glyphs[components[i]].layers[0].anchors:
if re.match('^_.*', anchor.name) == None:
baseAnchors.update({anchor.name : components[i]})
for anchor in font.glyphs[components[i + 1]].layers[0].anchors:
if re.match('^_.*', anchor.name) != None:
attachAnchors.update({anchor.name : components[i + 1]})
count = 0
for item in attachAnchors.keys():
if baseAnchors.get(re.sub('^_', '', item)) != None:
count = count + 1
conflictingAnchors.append(str(re.sub('^_', '', item)))
addGlyph = True
else:
pass
if count > 1:
glyphNames = glyphNames + "/" + glyph.name
print "%s has %d conflicting anchors:" % (glyph.name, count)
print "%s" % re.sub('\[', '', re.sub('\]', '', str(conflictingAnchors)))
print "\n"
return glyphNames
glyphNames = ""
for glyph in font.glyphs:
actualComponents = [component.name for component in glyph.layers[0].components]
glyphNames = checkActualComponents(actualComponents, glyph, glyphNames)
font.tabs[-1].text = glyphNames
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment