Macro - Copy to Composites

RachelR
20.Dec.2007 3.20am
RachelR's picture

Hi all,

I’m to write a script to use with RoboFab that will work like the fontlab function “Copy to composites” from the preview window when a glyph is used in other composites.

This fiunction works fine but I was trying to produce something that would update all the metrics in composites in on go without having to go through each glyph.

I thought something like this might work,

#---------------------------
#UPDATE COMPONENT METRICS
#---------------------------
from robofab.world import CurrentFont
f = CurrentFont()

f['Itilde'].leftMargin = f['I'].leftMargin
f['Imacron'].leftMargin = f['I'].leftMargin
f['Ibreve'].leftMargin = f['I'].leftMargin
f['Iacute'].leftMargin = f['I'].leftMargin
f['Icircumflex'].leftMargin = f['I'].leftMargin
f['Idieresis'].leftMargin = f['I'].leftMargin
f['Igrave'].leftMargin = f['I'].leftMargin
f['Idotaccent'].leftMargin = f['I'].leftMargin
f['Itilde'].rightMargin = f['I'].rightMargin
f['Imacron'].rightMargin = f['I'].rightMargin
f['Ibreve'].rightMargin = f['I'].rightMargin
f['Iacute'].rightMargin = f['I'].rightMargin
f['Icircumflex'].rightMargin = f['I'].rightMargin
f['Idieresis'].rightMargin = f['I'].rightMargin
f['Igrave'].rightMargin = f['I'].rightMargin
f['Idotaccent'].rightMargin = f['I'].rightMargin

f.update()

This produces sidebearings including the added accents in the case of the Itilde, Imacron etc.

When using the Copy to Composites function in FL it produces the correct sidebearings with the accents, as can be seen with the measurement line.

What I wanted is someway of applying the copy to composites function to all composites.



PvdL
20.Dec.2007 4.14am
PvdL's picture

A quicker way is to rebuild your accented glyphs with the f.generateGlyph() method since it will copy the metrics of the baseglyph. Just select the glyphs you want to update and run this script:


#FLM: Build accents

from robofab.world import CurrentFont, CurrentGlyph
from robofab.interface.all.dialogs import ProgressBar

f = CurrentFont()

def buildAccents(f, g):
--> f.generateGlyph(g.name, replace=True, printErrors=True)
--> g.update()

if f:
--> if f.selection:
--> --> l = f.selection
--> else:
--> --> l = f.keys()
--> bar = ProgressBar('Building accents...', len(l))
--> for n in l:
--> --> g = f[n]
--> --> buildAccents(f, g)
--> --> bar.tick()
--> bar.close()
--> print "Accents for glyphs " + str(l) + " built"
--> f.update()
--> print ""

(replace the arrows with a tab to get proper Python syntax)

:)


gferreira
20.Dec.2007 8.11am
gferreira's picture

but robofab’s accent builder assumes the designer is using anchors, right?

;-)


PvdL
21.Dec.2007 4.32am
PvdL's picture

Yes, this RoboFab method requires the use of anchors. Which I think is almost vital if you’re dealing with many accented glyphs.