Tosche / Glyphs-Scripts

Tosche's Python scripts for glyphs
Apache License 2.0
77 stars 24 forks source link

Using 'Copy Kerning Pairs.py' to copy Kerning Pair Exceptions #13

Open weiweihuanghuang opened 6 years ago

weiweihuanghuang commented 6 years ago

I wanted to copy any kerning pair exceptions that oslash had over to oslashacute (which has @o for both sides kerning groups in both glyphs), but it didn't run as expected, is there a way to restrict it to only kerning pair exceptions somewhere?

Tosche commented 6 years ago

What happened when you tried it?

weiweihuanghuang commented 6 years ago

It seemed to just re-copy all @o kerning, so not changing the file in anyway

Tosche commented 6 years ago

That is expected. What you need is to type oslash or ø as source glyph, and oslashacute as target. Blank field is treated as "anything involving the other glyph". And you may need to do it to both sides.

weiweihuanghuang commented 6 years ago

Oh I should've been clearer, I mean I entered oslash as source, and oslashacute as target, and it doesn't copy the exceptions.

ethancohen commented 3 years ago

Hi Tosche! I'm having an error that sounds similar to this. I'm copying kerning from @O to @Oslash and getting this:

Black10
    @MMK_L_Oslash,  @MMK_R_A,  -32.0
    @MMK_L_Oslash,  @MMK_R_AE,  -31.0
    @MMK_L_Oslash,  @MMK_R_C,  1.0
    @MMK_L_Oslash,  @MMK_R_Eth,  10.0
    @MMK_L_Oslash,  @MMK_R_G,  1.0
    @MMK_L_Oslash,  @MMK_R_J,  -28.0
    @MMK_L_Oslash,  @MMK_R_O,  1.0
    @MMK_L_Oslash,  @MMK_R_T,  -31.0
    @MMK_L_Oslash,  @MMK_R_V,  -26.0
    @MMK_L_Oslash,  @MMK_R_W,  -18.0
    @MMK_L_Oslash,  @MMK_R_X,  -52.0
    @MMK_L_Oslash,  @MMK_R_Y,  -44.0
    @MMK_L_Oslash,  @MMK_R_Z,  -23.0
    @MMK_L_Oslash,  @MMK_R_f,  11.0
    @MMK_L_Oslash,  @MMK_R_parenright,  -21.0
    @MMK_L_Oslash,  @MMK_R_period,  -26.0
    @MMK_L_Oslash,  @MMK_R_slash,  -31.0
    @MMK_L_Oslash,  @MMK_R_x,  -10.0
    @MMK_L_Oslash,  A648FAE1-FF4C-4CC9-9272-0FAC2F8F849E,  25.0
Copy kerning Pairs Error (dupliKernPair): 'Glyphs with name: A648FAE1-FF4C-4CC9-9272-0FAC2F8F849E not found'

A648FAE1-FF4C-4CC9-9272-0FAC2F8F849E is the glyph id of the first glyph for which there is an exception to @Oslash.

Tosche commented 3 years ago

Thanks! This is a G3-related issue in which the kerning structure has changed a bit. I'll update it soon.

Tosche commented 3 years ago

@ethancohen Sorry, could you actually specify which versions of Glyphs and Python you use?

ethancohen commented 3 years ago

Yessir! Python 3.7.4, Glyphs 3.0.4 (3092). Also Glyphs crashes when I run it with "All masters" checked.

schriftgestalt commented 3 years ago

Please update to python 3.9. Either use the glyph python or update the one you installed.

ethancohen commented 3 years ago

I'm on Python 3.9.1 now and I get these errors:

When I run the script on @Oslash_1st:

Following pairs have been added.

Copy kerning Pairs Error (dupliKernPair): applyKern2() takes 7 positional arguments but 8 were given

When I run the script on @Oslash_2nd:

...
    @MMK_L_quotedblleft,  @MMK_R_Oslash,  -20.0
    @MMK_L_quotedblright,  @MMK_R_Oslash,  -36.0
    @MMK_L_slash,  @MMK_R_Oslash,  -1.0
    9701A7CD-72D3-4A63-AB4B-559D3CA04FC7,  @MMK_R_Oslash,  14.0
Copy kerning Pairs Error (dupliKernPair): 'Glyphs with name: 9701A7CD-72D3-4A63-AB4B-559D3CA04FC7 not found'
Tosche commented 3 years ago

@ethancohen I've updated the script. I'd love to know if it works for you this time.

ethancohen commented 3 years ago

Thanks, Tosche! Unfortunately I still get the same error for @Oslash_1st. But no more Glyphs with name: {glyph id} not found!

Oslash_1st:

Following pairs have been added.

Copy kerning Pairs Error (dupliKernPair): applyKern2() takes 7 positional arguments but 8 were given

Also exceptions don't get copied... is that intentional?

Tosche commented 3 years ago

Sorry about that. It's Glyphs 3's change in the internals of how single glyph entries are treated (it was all glyph names before, now mixed with glyph IDs depending on the function). Whenever you see an error relating to glyph ID, this is the reason. I haven't successfully got rid of those yet, and will give it another shot later today.

ethancohen commented 3 years ago

Thank you, Tosche! You are awesome.

And if there's any chance you would add functionality to copy exceptions you would be my hero.

Tosche commented 3 years ago

Huh, I don't quite get how applyKern2() can receive extra arguments. I guess I need your file and to know exactly what you tried. Could you provide me with the data please? The outlines can be totally empty if you're concerned (but the glyphs need to exist). You can email me the file at tosche@mac.com

schriftgestalt commented 3 years ago

Tosche, can you send me some code samples where Glyphs 2 would return/expect names and Glyphs 3 is using IDs?

Tosche commented 3 years ago

I have mentioned it before in the forum, it's GSFont.kerningDict() in G2 (at least earlier version of it) and GSFont.kerning in G3. The former reported single glyph in glyph name, and the latter reports in ID. To my knowledge, setKerningForPair() behave the same (accepts the name).

When I moved to G3, GSFont.kerning was recommended as the substitute for kerningDict(). When I changed it, things started to break around single glyphs because I couldn't simply apply what I read in the kerning dictionary anymore.

schriftgestalt commented 3 years ago

Now I see. The kerningDict method is used internally when serialization of the data. It is still availably in G3: kerningDictForDirection_(direction) (direction: LTR = 0, RTL = 2, Vertical = 4)

You should use those methods cautiously. It returns a copy of the kerning querying too often might be slow.

What API did you use to set the kerning?

And it is now difficult to convert IDs into names and back:

ID = Font.glyphs[name].id
name = Font.glyphForId_(ID).name
Tosche commented 3 years ago

I've been using setKerningForPair() in both G2 and G3, which seems to accept glyph names. I honestly don't like dealing with glyph IDs in kerning though, it's also inconvenient when I need to print them out and need to convert to ID. What was wrong with glyph names? Kerning window displays single glyphs in names anyway.

schriftgestalt commented 3 years ago

As I wrote before, the only thing that has changed in G3 is that the .kerningDict is .kerningDictForDirection_(direction) now. Feel free to use it in place of .kerningDict. All my other comments apply equally to G2 and G3.

weiweihuanghuang commented 1 year ago

I just tried to run this for this purpose and came back to the same problem of kerning exceptions not included when copying 😅