Python Scripting Guru?

PabloImpallari's picture

Hello there:

As there is nothing like Prepolator for PC....
I'm thinking of some kind of basic script to help PC users to prepare fonts for "mask to master" interpolation.

Nothing too complex, maybe something simple like this:

For each glyph in the current open font:
- Count number of points
- Count number of contours
- Save list as .txt file, or just output somewhere that can be copied and pasted.

So, we can run the script in 2 fonts, open the list in excel & quickly find the glyphs that needs more tunning to be compatible.
Can this be done? Where do I star looking for info to code this?

Thanks in advance.

blank's picture

Superpolator comes with a Fontlab/robofab script that does this. Superpolator does not deign to run on PCs, but you might be able to get Erik to license the script.

eigi's picture

You can use the robofab framework. A robofab glyph has a "isCompatible" method:


isCompatible(self, otherGlyph, report=True):
"""Return a bool value if the glyph is compatible with otherGlyph.With report = True, isCompatible will return a report of what's wrong. The interpolate method requires absolute equality between contour data. Absolute equality is preferred among component and anchor data, but it is NOT required. Interpolation between components and anchors will only deal with compatible data and incompatible data will be ignored. This method reflects this system."""

... and it works on PC

Eigi

PabloImpallari's picture

Thanks Andreas, that's great!

Ramiro Espinoza's picture

from robofab.world import CurrentFont,CurrentGlyph
font = CurrentFont()

# make a list to collect your data
stuff = []

# naming attributes
stuff.append(font.info.fullName)
stuff.append('---------------------------------------------------------')

for glyph in font:
stuff.append(' ')
stuff.append(glyph.name)
stuff.append("(glyph has %d contour)" % len(glyph))
stuff.append('-------------------------------')

for contour in glyph:

#stuff.append(`contour`)

stuff.append(" This contour has %d segments" % len(contour.segments))

# make up a path where you want to save
# if you run this script in fontlab
# you need to provide a full path

import os.path
path = os.path.join( os.path.split(fl.font.file_name)[0] , "segmentos.txt")
f = open(path, 'w')
f.write("\r".join(stuff))
f.close

Ramiro Espinoza's picture

IMPORTANTE: cortar y pegar en FL y poner las indentaciones tal como muestra la imagen que adjunto (sino no anda).

PabloImpallari's picture

Thanks Ramiro!
Works great

Syndicate content Syndicate content