# Pregunta de que fuente quiero copiar las proporciones
orignalFont = OpenFont(None, "Which font's Proportions do you want?")
original = {}

# Rango de Glyphs que voy a medir
uppercase = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

# Leo las n y obtengo el Ratio
original_n = orignalFont['n'].width
myfont_n = myfont['n'].width

# Leo la fuente de origen
for item in uppercase:
	if myfont.has_key(item):
		
		# Calculo Anchos
		ancho_original = orignalFont[item].width
		ancho_myfont = myfont[item].width
		ratio = ancho_original * 100.00 / original_n
		ancho_nuevo = int( myfont_n * ratio / 100 )
		
		# Calculo Diferencia
		if ancho_myfont > ancho_nuevo :
			diferencia = ancho_nuevo - ancho_myfont
		if ancho_myfont < ancho_nuevo :
			diferencia = "+" + str(ancho_nuevo - ancho_myfont)
		if ancho_myfont == ancho_nuevo:
			diferencia = " - "
			bar.tick(tick)
			tick = tick+1
		bar.close()
		orignalMetricsFont.close()
	else:
		for glyph in orignalMetricsFont:
			orignalMetrics[glyph.name] = [glyph.leftMargin, glyph.rightMargin]
			bar.tick(tick)
			tick = tick+1
		bar.close()
		orignalMetricsFont.close()
	
	layer = getLayer(fontToChange.naked(), 'Which layer to change?')
	tickCount = len(fontToChange)
	bar = ProgressBar('Changing Metrics', tickCount)
	tick = 0	
	for name, metrics in orignalMetrics.iteritems():
		if fontToChange.has_key(name):
			glyphWidth = int(fontToChange[name].naked().GetBoundingRect(layer).width)
			oldLeft = int(fontToChange[name].naked().GetBoundingRect(layer).x)
			newAdvanceWidth = glyphWidth + metrics[0] + metrics[1]
			leftShift = metrics[0] - oldLeft
			shiftPoint = Point(leftShift, 0)
			widthPoint = Point(newAdvanceWidth, 0)
			fontToChange[name].naked().SetMetrics(widthPoint, layer)
			fontToChange[name].naked().Shift(shiftPoint, layer)
			bar.tick(tick)
			tick = tick+1
	bar.close()
	fontToChange.update()
	Message('Done changing sidebearings')
# 18 (MC)
# 36 (FB)

#Always add .0 - Ej 18.0 instead of 18
units = 36.0

#scope
lower = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
basic = lower

f = CurrentFont()
anchos = {}
wider = 0

for n in basic:
	if f.has_key(n):
		name = f[n].name
		width = f[n].width
		anchos[name] = width
		if wider < width:
			wider = width
		
unit = wider / units

print "%d Units of %d (%.2f) points each" % (units, round(unit), unit)

print ""
print "Unitized"
for key, value in sorted(anchos.iteritems(), key=lambda (k,v): (v,k)):
	unitized = value / unit
	print "%s: %s - %d units (%.2f)" % (key, value, round(unitized), unitized)
Exemple #4
0
from robofab.world import CurrentFont
# gString has lots of glyph lists, these two will be useful for this demo
from robofab.gString import uppercase_plain, lowercase_plain

# (you will need t have a font open in FontLab for this demo)
font = CurrentFont()

# First off, let's gather up some glyph names.
# gString's uppercase_plain and lowercase_plain
# lists will do for now. Let's go through these lists
# and see if they contain any glyphs that are in this font.
uppercase = []
lowercase = []
for glyphName in uppercase_plain:
	if font.has_key(glyphName):
		uppercase.append(glyphName)
for glyphName in lowercase_plain:
	if font.has_key(glyphName):
		lowercase.append(glyphName)
uppercase.sort()
lowercase.sort()

# And, we'll combine the uppercase glyph names and
# lowercase glyph names that we found into one list
both = uppercase + lowercase
both.sort()

# Just for kicks, let's get the list of glyphs
# that you have selected in the font window as well
selected = font.selection
#Always add .0 - Ej: 18.0 instead of 18
units = 36.0

#scope
upper = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
lower = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
numbers = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
punct = ["space", "period", "hyphen"]
basic = punct + lower + upper + numbers

f = CurrentFont()
wider = 0

for n in basic:
	if f.has_key(n):
		width = f[n].width
		if wider < width:
			wider = width
		
unit = wider / units

print str(f.info.familyName) + ' ' + str(f.info.styleName)
print "Fitted into a %d Units system (%d points per unit)" % (units, round(unit))
print ""

for u in range(1, int(units+1)):
	grupo = []
	for g in basic:
		if f.has_key(g):
			g_fitted = int(round(f[g].width / unit))
	j_right = ( j_right * global_spacing / 100 )
	l_right = ( l_right * global_spacing / 100 )
	p_left = ( p_left * global_spacing / 100 )
	q_right = ( q_right * global_spacing / 100 )

# --- Unmark all glyphs ---
glyphs = f.glyphs
for g in glyphs:
	g.mark = 0
f.update()

# --- Apply Spacing ---
print "Applying new spacing to the Lowercase..."
print "-------------------------------------------"

if f.has_key('space'):
	f['space'].width = space
	f['a'].mark = 80

if f.has_key('a'):
	if style == 1:
		if aConstruction == 1:
			setMargins(f['a'], a_x_height, n_right * 0.57 , None ) #------ Hardcoded, mejorable
			setMargins(f['a'], half_x_height, None, n_right)
			f['a'].mark = 80
		if aConstruction == 2:
			setMargins(f['a'], half_x_height, o_both, n_right)
			f['a'].mark = 80
	if style == 2:
		if aConstruction == 1:
			setMargins(f['a'], a_x_height, n_right * 0.57 , None ) #------ Hardcoded, mejorable
for g in font:
    if g.selected:
        g.clearAnchors()

for group in accentGroups:
    name = group[1]
    groupName = group[3]
    if group[2] == 1:
        y = getNumber('Vertical Position for ' + name + ' in ' + groupName, 1)
    else:
        y = group[2]
    for glyph in group[0]:
		print glyph
		if '.smcp' in glyph:
			glyph = glyph.lower()
		if font.has_key(glyph) and font[glyph].selected:
			x = int(getGlyphWidth(font[glyph]) / 2) + font[glyph].leftMargin
			font[glyph].mark = 100
			if checkAnchors(font[glyph],name)!=1:
				font[glyph].appendAnchor(name, (x, y))
#        else:
#            newGlyph = font[glyph]
#            newGlyph.autoUnicodes()
#            newGlyph.update()




font.update()
Message('All done!')