Help for adapting a FL script

Hi there,

I would like to make this script I use to detect all kind of overlaps in FL to work also in Glyphs. Can you help me to make it work on Glyphs?

Thanks in advance.

f = Font(fl.font)

for glyphIndex in range(len(f.glyphs)):
	g = f[glyphIndex]
	if (len(g.components) > 1) or (len(g) > 0 and len(g.components) > 0):
		# only decompose composites made up of more than one component
	if len(g) > 0:
		# glyph has outlines
		g2 = Glyph(g)
		if len(g) != len(g2):
			# different number of nodes
			fl.font[glyphIndex].mark = 10
			# check nodes
			for nodeIndex in range(len(g.nodes)):
				n = g.nodes[nodeIndex]
				n2 = g2.nodes[nodeIndex]
				if len(n) != len(n2):
					# nodes don't have the same number of points
					fl.font[glyphIndex].mark = 20
					# check points
					for pointIndex in range(len(n.points)):
						if n[pointIndex].x != n2[pointIndex].x or n[pointIndex].y != n2[pointIndex].y:
							fl.font[glyphIndex].mark = 30

What do you need the script for? Why decompose components?

I only decompose overlapping components. It’s because I like to check for tiny problems in the contours, like cusps and superfluous points. This script check for all kind of overlaps: components / components, contour / contour and components / contour.
I think people who works with Glyphs frequently trust too much on automated interpolated weights and remove overlaps on font export. I prefer to generate instances and then carefully check the contours and correct mistakes when necessary. I like it this way.

You decompose all glyphs that have more than one component. There is no check if they are overlapping.

If I where you, I would export as TrueType and open the .ttf and do the checking there.

No thanks, I prefer to decompose overlapping composites and then improve the contours manually. Can be the script be adapted or not?

It can be adapted, of course. I just like to check that it is doing what you actually need. I’ll have a look.

This script does not necessarily help you with that. It decomposes all glyphs that have two components or a path and a component. The script proceeds to remove all overlaps and then checks if the node count has changed. I believe this says not much about overlapping components. In most setups it will create a lot of false positives.

#MenuTitle: Find Overlaps
# -*- coding: utf-8 -*-
Find Overlaps.

master = Font.masters[Font.masterIndex]

def findOverlaps(layer):
	AllPaths = []
	for component in layer.components:
	for path in layer.paths:
	for path in AllPaths:
		for otherPath in AllPaths:
			if path != otherPath:
				if path.intersectWithPath_(otherPath):
					layer.color = 2

for glyph in Font.glyphs:
	layer = glyph.layers[]

This script will not decompose anything. I just marks all glyphs where it found an overlap.

The FL script only highlight the slots when there is any kind of overlap. Then I decompose them and improve the contours when necessary.
The Glyphs version works very well, many thanks!