SOLVED Can I apply a "smart sort" for Glyph Order via script?



  • I appreciate the "Smart Sort" feature of robofont ... is it possible to trigger this from a script? For instance, when I insert a new glyph via script, I would likely to immediate smart-sort the UFO, rather than having to do it manually.

    0_1526045122779_098bcbb1-6c03-4032-a5fd-bcc5c8fa44e2-image.png

    Short of accessing the actual smart sort feature from script, is the only alternative using something like the following?

    font.glyphOrder = ["a", "agrave", "b", "c"]  # etc
    

    ..and if so, is there a good default order I could import, so a user doesn't have to manage their list manually?

    Thanks for any pointers!



  • Thanks, @gferreira!

    That was a super helpful suggestion, including the link to the defcon docs.

    I find that for me, the cannedDesign sort type is seemingly identical to the "Smart Sort" option in Robofont, aside from deleting template glyphs.

    Still, those are easy enough to re-add manually, and something I don't need to do every time (Add Glyphs -> Import from my "Latin 1" character set... -> then select to "add as template glyphs").

    So, the script I'll use is very close to your suggestion, but I prefer this sort type:

    font = CurrentFont()
    newGlyphOrder = font.naked().unicodeData.sortGlyphNames(font.glyphOrder, sortDescriptors=[dict(type="cannedDesign", ascending=True, allowPseudoUnicode=True)])
    font.glyphOrder = newGlyphOrder
    


  • hello @StephenNixon,

    I don’t know exactly how Smart Sort works internally. but the options under the Custom sorting mode are available from defcon’s UnicodeData object, which you can access with font.naked(). here’s an example:

    font = CurrentFont()
    newGlyphOrder = font.naked().unicodeData.sortGlyphNames(font.glyphOrder, sortDescriptors=[dict(type="unicode", ascending=True, allowPseudoUnicode=True)])
    font.glyphOrder = newGlyphOrder
    

    have a look at the different sorting options in the UnicodeData.sortGlyphNames documentation linked above, see if you can get the results you are looking for.

    hope this helps. maybe @frederik has a better answer…