Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Kerning Pairs.py not working with groups #3

Closed
gorjious opened this issue Apr 3, 2020 · 5 comments
Closed

Show Kerning Pairs.py not working with groups #3

gorjious opened this issue Apr 3, 2020 · 5 comments

Comments

@gorjious
Copy link

gorjious commented Apr 3, 2020

I've noticed an issue with Show Kerning Pairs.py. Kerning pairs which have a group name, other than its glyph name, are shown blank.

From what I can tell the if statement of the nameMaker() function returns the names of the kerning groups, and those names are then added into the kernPair string kernPair = "/%s/%s " % (thisGlyphName, nameMaker(R)) Does there have to be an additional loop of listing what at the members of each kerning group?

I've tried modifying the code by adding a loop that checks which glyphs are members of the returned kerning groups and inserting those into the string. I've got it working somewhat but have a feeling that there are things it may be missing. In any case, I've included the code below.

The issue is also posted in the Glyphs forum: https://forum.glyphsapp.com/t/show-kerning-pairs/10729/5

#MenuTitle: Show Kerning Pairs
# -*- coding: utf-8 -*-
__doc__="""
Show Kerning Pairs for this glyph in a new tab.
"""
import GlyphsApp


thisFont = Glyphs.font
Doc = Glyphs.currentDocument
selectedLayers = thisFont.selectedLayers
selectedMaster = thisFont.selectedFontMaster
masterID = selectedMaster.id

editStringLeft = ""
editStringRight = ""

def nameMaker(kernGlyph):
	if kernGlyph[0] == "@":
		return kernGlyph[7:]
	else:
		return thisFont.glyphForId_(kernGlyph).name	

	
	
for thisLayer in selectedLayers:
	thisGlyph = thisLayer.parent
	thisGlyphName = thisGlyph.name
	rGroupName = str(thisGlyph.rightKerningGroup)
	lGroupName = str(thisGlyph.leftKerningGroup)

	for L in thisFont.kerning[ masterID ]:
		try:
			# if the this kerning-pair's left glyph matches rGroupName (right side kerning group of thisGlyph)
			if L[0] == "@" and rGroupName == L[7:] or rGroupName == thisFont.glyphForId_(L).name or thisFont.glyphForId_(L).name == thisGlyph.name:
				# for every R counterpart to L in the kerning pairs of rGroupName
			
				for R in thisFont.kerning[masterID][L]:
					editStringLeft += '\n'
					for g in thisFont.glyphs:
						groupMembers = g.name
						if g.leftKerningGroup == nameMaker(R):
							kernPair = "/%s/%s  " % (thisGlyphName, groupMembers)
							editStringLeft += kernPair 		
					
		except:
			pass

		for R in thisFont.kerning[masterID][L]:
			
			try:
				# if the R counterpart (class glyph) of L glyph is the selectedGlyph
				if R[0] == "@" and lGroupName == R[7:] or lGroupName == thisFont.glyphForId_(R).name or thisFont.glyphForId_(R).name == thisGlyph.name:
					editStringRight += '\n'
					for g in thisFont.glyphs:
						groupMembers = g.name
						if g.rightKerningGroup == nameMaker(L):
							kernPair = "/%s/%s  " % (groupMembers, thisGlyphName)
# 							
							editStringRight += kernPair 
							print editStringRight
					
						
							
			except:
				pass

thisFont.newTab("/%s/%s " % (editStringLeft, editStringRight))

@weiweihuanghuang
Copy link
Owner

Ah yep this is out of date I since made a version with a kerning group dictionary... will upload eventually

@gorjious
Copy link
Author

gorjious commented Jul 7, 2021

Trying these scripts again for G3 – 3.0.3 (3091)
First ran into this error:
AttributeError: 'NSKVONotifying_GSFont' object has no attribute 'kerningDict'
Adding this code removed the error:

if Glyphs.versionNumber >= 3.0:
	kernDict = thisFont.kerning
else:
	kernDict = thisFont.kerningDict()

However, now I am getting this:

File "objc/_convenience_mapping.pyc", line 19, in __getitem__objectForKey_
File "objc/_convenience.pyc", line 118, in container_unwrap

The related Show Kerning Pairs as Left/Right Glyphs are also not working. They run but the result is an empty tab.

Would it be possible to update these scripts? Or, any suggestions on how to solve these errors?

@weiweihuanghuang
Copy link
Owner

Ok interesting, do you get the same error when you run "Show Kerning Pairs Context.py" ? Because I don't get the error. BUT if I copy the same code to another file with a different menu title, I do... strange. Going to look into it.

@weiweihuanghuang
Copy link
Owner

Ok these should work! Try these...

@gorjious
Copy link
Author

gorjious commented Jul 8, 2021

The "Show Kerning Pairs" seems to be semi-working now. For some reason, it is working for Latin but when I try it for Armenian the right pair is blank.

I was fiddling around with this more yesterday. Using Toshi's "New Tab with Unlocked Kerning Pairs" as a reference...I got something working. Haven't had ample time to test it or clean up but the code but feel free to check it out.

Show Kerning Pairs – GJ (draft).py.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants