Typophile

Check glyph compatibility script ?

Smitchell

I'm trying to write a script that checks the compatibility of glyphs before generating a MM font.

I wrote this which works for single glyphs


========================
from robofab.world import OpenFont
lightFont = OpenFont(None)
boldFont = OpenFont(None)
#
#
print lightFont.info.fullName,"/",boldFont.info.fullName

print lightFont["A"].isCompatible(boldFont["A"], True)
========================

I really wanted to do it with a loop, and loop through the whole font.

I tired this, but it gives me a list saying all the glyphs are compatible but I know they are not.


========================
from robofab.world import OpenFont
lightFont = OpenFont(None)
boldFont = OpenFont(None)
#
#
print lightFont.info.fullName,"/",boldFont.info.fullName

for glyph in lightFont:
print lightFont["glyph"].isCompatible(boldFont["glyph"], True)

print lightFont["B"].isCompatible(boldFont["B"], True)

========================

I changed the outline of the "B" and tested the compatibility after the loop and it tells me they are not compatible but the loops tells me they are

How can I loop through both fonts and test there compatibility ?

I would suggest to loop through the *glyph names* instead of the *glyph objects*:

from robofab.world import OpenFont
lightFont = OpenFont()
boldFont = OpenFont()

print lightFont.info.fullName, "/", boldFont.info.fullName

for glyphName in lightFont.keys():
> lightGlyph = lightFont['glyphName']
> boldGlyph = boldFont['glyphName']
> print lightGlyph.isCompatible(boldGlyph, True)

-Paul van der Laan
www.type-invaders.com

PvdL

Thank you for the code

How reliable is the isCompatible() method in RoboFab ?

To test it I put in some extra points so they the outlines would be incompatible, but the script still says they are compatible.

PvdL

Thank you for the code

How reliable is the isCompatible() method in RoboFab ?

To test it I put in some extra points so they the outlines would be incompatible, but the script still says they are compatible.

Unless you have a glyph named "glyphName" the script above should toss you an error:

for glyphName in lightFont.keys():
> lightGlyph = lightFont[glyphName]
> boldGlyph = boldFont[glyphName]
> print lightGlyph.isCompatible(boldGlyph, True)

I don't know if it's working as I aspected it to, but I'm not getting an error.

The only difference between the chunk of script I posted and Paul's is that you don't have to call a particular glyph called glyphName each time but you just have to refer to the item in the font.keys() iterable. So no '' in the square brackets.

That should teach me never to post code without testing it... :)

Indeed folengo is right, there should be no quotes:

> lightGlyph = lightFont[glyphName]
> boldGlyph = boldFont[glyphName]

I just tested the script with two of my own files and it works fine here - it happily reports any incompatibility errors.

-Paul van der Laan
www.type-invaders.com

Thank you forlengo and PvdL

I didn't notice the quotes where removed from forlengo's code - Yes it does now work

Captured from web.archive.org on 11 Jan 2012. view this capture