def apply_Callback(self, sender):
     f = CurrentFont()
     if f is not None:
         print 'processing selected glyphs...\n'
         # get options
         boolstring = [False, True]
         _points = self.w._points_checkBox.get()
         _sidebearings = self.w._sidebearings_checkBox.get()
         _anchors = self.w._anchors_checkBox.get()
         # get color
         _gridsize = int(self.w._gridsize_value.get())
         _mark = self.w._mark_checkBox.get()
         _mark_color = self.w._mark_color.get()
         _mark_color = (_mark_color.redComponent(),
             _mark_color.greenComponent(),
             _mark_color.blueComponent(),
             _mark_color.alphaComponent())
         print '\tgrid size: %s' % _gridsize
         print '\talign points to grid: %s' % boolstring[_points]
         print '\talign side-bearings: %s' % boolstring[_sidebearings]
         print '\talign anchors: %s' % boolstring[_anchors]
         print '\tmark glyphs: %s (%s)' % (boolstring[_mark], _mark_color)
         print
         print '\t', 
         # batch do stuff
         for gName in f.selection:
             print gName,
             f[gName].prepareUndo('align to grid')
             if _points:
                 roundPointsToGrid(f[gName], (_gridsize, _gridsize))
             if _anchors:
                 roundAnchorsToGrid(f[gName], (_gridsize, _gridsize))
             if _sidebearings:
                 roundMargins(f[gName], _gridsize, left=True, right=True)
             if _mark:
                 f[gName].mark = _mark_color
             f[gName].update()
             f[gName].performUndo()
         # done
         print
         f.update()
         print '\n...done.\n'
Example #2
0
# robothon06
# setting data in the info object

from robofab.world import CurrentFont

font = CurrentFont()

# naming attributes
font.info.familyName = "MyFamily"
print font.info.familyName
font.info.styleName = "Roman"
print font.info.styleName
font.info.fullName = font.info.familyName + '-' + font.info.styleName
print font.info.fullName

# dimension attributes
font.info.ascender = 600
print font.info.ascender
font.info.descender = -400
print font.info.descender

font.update()
#FLM: Add 1 Units to each side to current glyph

# Description:
# Increase current glyph sidebearings by 1 units on each side

# Credits:
# Pablo Impallari
# http://www.impallari.com

from robofab.world import CurrentFont,CurrentGlyph

f = CurrentFont()
g = CurrentGlyph()

OldLeft = g.leftMargin
OldRight = g.rightMargin 

g.leftMargin = OldLeft + 1
g.rightMargin = OldRight + 1

f.update()

modes[1]=Mode("sups",400,math.cos(fl.font.italic_angle) * 400 * -1)
modes[2]=Mode("subs",-140,math.cos(fl.font.italic_angle) * -140 * -1)

dnomGlyphs = []
	
for glyph in fl.font.glyphs:
	splitName = glyph.name.split('.')
	if len(splitName)>1 and splitName[1]=="dnom":
			dnomGlyphs.append(glyph)

print "\nWelcome to FontLab Studio 5.\n"
print "Fonts  open: ", len(fl)

for x in range (0, len(modes)):
	print "Adding", modes[x].kind, "glyphs"
	for sGlyph in dnomGlyphs:
		newGlyph = Glyph() ;
		comp = Component(sGlyph.index) ;
		newGlyphName = sGlyph.name.split('.')[0]+"."+modes[x].kind ;
		newGlyph.width = sGlyph.width ;
		f.newGlyph(newGlyphName) ;
		f[newGlyphName].width = sGlyph.width ;
		f[newGlyphName].appendComponent(sGlyph.name, (modes[x].xShift,modes[x].yShift)) ;
		f.update() ;

endCount = len(f.glyphs)

print "Starting glyph count was ", startCount
print "Final glyph count is ", endCount
print "Added ", (endCount - startCount), "glyphs"
Example #5
0
    buildAccents(font, item[0], 'Building ' + item[1], overwrite)

if buildSmallCap == 1:
    buildAccents(font, smallCapList, 'Building small cap accents', overwrite)

#Build a couple of accents that would be missed
#font.newGlyph('uni021B', clear=True)
#font.newGlyph('uni021A', clear=True)
#font.newGlyph('Dotlessi.sc', clear=True)
#dotlessisc = font['I.sc'].copy()
#duplicatetcommaaccent = font['tcommaaccent'].copy()
#duplicateTcommaaccent = font['Tcommaaccent'].copy()
#font['Dotlessi.sc'].appendGlyph(dotlessisc)
#font['uni021B'].appendGlyph(duplicatetcommaaccent)
#font['uni021A'].appendGlyph(duplicateTcommaaccent)
#font['uni021B'].width = duplicatetcommaaccent.width
#font['uni021B'].leftMargin = duplicatetcommaaccent.leftMargin
#font['uni021B'].rightMargin = duplicatetcommaaccent.rightMargin
#font['uni021B'].mark = 200
#font['uni021A'].width = duplicateTcommaaccent.width
#font['uni021A'].leftMargin = duplicateTcommaaccent.leftMargin
#font['uni021A'].rightMargin = duplicateTcommaaccent.rightMargin
#font['uni021A'].mark = 200
#font['Dotlessi.sc'].width = dotlessisc.width
#font['Dotlessi.sc'].leftMargin = dotlessisc.leftMargin
#font['Dotlessi.sc'].rightMargin = dotlessisc.rightMargin
#font['Dotlessi.sc'].mark = 200

font.update()

Message('Listo!')
Example #6
0
# robothon06
# edit the nametable
# this seems to work in FontLab 5
# it is broken in FontLab 4.6

from robofab.world import CurrentFont
from robofab.tools.nameTable import NameTable
f = CurrentFont()
nt = NameTable(f)

# bluntly set all copyright records to a string
nt.copyright = "Copyright 2006 RoboFab"

# get a record
print nt.copyright

# set a specific record to a string
nt.setSpecificRecord(pid=1, eid=0, lid=0, nid=0,
	value="You Mac-Roman-English folks should know\\
	that this is Copyright 2004 RoboFab.")

# get a record again to show what happens
# when the records for a NID are not the same
	
print nt.copyright
# look at the code to see what else is possible
f.update()
Example #7
0
# Mark in color glyphs that exceeds the BBox limits 
# defined in metricsMax and metricsMin variables

# Credits:
# Pablo Impallari
# http://www.impallari.com

# Variables
# Tweak to fit your font
metricsMax = 900
metricsMin = -300

# Dependencies
from robofab.world import CurrentFont, CurrentGlyph
f = CurrentFont()
glyphs = f.glyphs

for g in glyphs:
	bbox = g.box
	# print bbox
	if bbox[3] > int(metricsMax):
		# print g.name + " xMax: " + str(bbox[3])
		g.mark = 240
	if bbox[1] < int(metricsMin):
		# print g.name + " xMin: " + str(bbox[1])
		g.mark = 220
		
f.update()

print "Done!"
Example #8
0
for f in fonts:
    if f.info.postscriptFullName == fontCompare:
        f1 = f

f2 = CurrentFont()
glyph = CurrentGlyph()
fl.SetUndo()
error = 0
print f1, f2

if len(fonts) < 2:
    error = "Debe abrir dos fuentes para comparar"
elif f1.path == f2.path:
    error = "Origen y destino son la misma fuente."

if error == 0:
    tickCount = len(f2.selection)
    bar = ProgressBar('Chequeando...', tickCount)
    tick = 0

    for g in f2.keys():
        if f2[g].selected or g.index == fl.iglyph or g == glyph.name:
            chequear(f2[g], f2, f1)
            bar.tick(tick)
            tick = tick + 1
    bar.close()
    f1.update()
    f2.update()
else:
    print error
class RoundToGridDialog(object):

	_points = True
	_anchors = True
	_sidebearings = True
	_mark = True
	_mark_color = randomColor()
	_gridsize = 30
	_height = 235
	_column_1 = 120
	_title = 'round to grid'
	_padding_top = 10
	_padding = 10
	_bWidth = 80
	_row_height = 30
	_bSpacing = 0

	def __init__(self, verbose=True):
		self._verbose = verbose
		self._width = self._column_1 + self._bWidth + (self._padding_top * 3)
		self.w = ModalDialog(
				(self._width,
				self._height),
				self._title,
				okCallback=self.okCallback)
		# grid size
		self.w.gridsize_label = TextBox(
				(self._padding,
				self._padding_top + (self._row_height * 0),
				self._column_1,
				self._row_height),
				"grid size:")
		self.w.gridsize_value = EditText(
				(self._column_1,
				self._padding_top + (self._row_height * 0),
				self._bWidth,
				self._row_height),
				self._gridsize,
				callback=self.gridsize_callback)
		# points
		self.w.points_checkbox = CheckBox(
				(self._padding,
				self._padding_top + (self._row_height * 1),
				-0,
				self._row_height),
				"points",
				callback=self.points_callback,
				value=self._points)
		# anchors
		self.w.anchors_checkbox = CheckBox(
				(self._padding,
				self._padding_top + (self._row_height * 2),
				-0,
				self._row_height),
				"anchors",
				callback=self.anchors_callback,
				value=self._anchors)
		# side-bearings
		self.w.sidebearings_checkbox = CheckBox(
				(self._padding,
				self._padding_top + (self._row_height * 3),
				-0,
				self._row_height),
				"side-bearings",
				callback=self.sidebearings_callback,
				value=self._sidebearings)
		# mark
		self.w.mark_checkbox = CheckBox(
				(self._padding,
				self._padding_top + (self._row_height * 4),
				-0,
				self._row_height),
				"mark",
				callback=self.mark_callback,
				value=True)
		# apply
		self.w.apply_button = Button(
				(self._padding,
				(2 * self._padding) + ((self._row_height) * 4),
				self._width - (2 * self._padding_top),
				self._row_height),
				'apply',
				callback=self.apply_callback)
		# open window
		self.w.open()

	def gridsize_callback(self, sender):
		self._gridsize = sender.get()

	def points_callback(self, sender):
		self._points = sender.get()

	def anchors_callback(self, sender):
		self._anchors = sender.get()

	def sidebearings_callback(self, sender):
		self._sidebearings = sender.get()

	def mark_callback(self, sender):
		self._mark = sender.get()

	def apply_callback(self, sender):
		self.font = CurrentFont()
		if self.font is not None:
			gNames = getGlyphs(self.font)
			if len(gNames) > 0:
				# print info
				if self._verbose:
					print 'rounding glyphs to grid...\n'
					print '\tgrid size: %s' % self._gridsize
					print '\tpoints: %s' % self._points
					print '\tanchors: %s' % self._anchors
					print '\tside-bearings: %s' % self._sidebearings
					print '\tmark: %s' % self._mark
					print
					print '\t',
				# batch process glyphs
				for gName in gNames:
					print gName,
					if self._points:
						roundPointsToGrid(self.font[gName], (self._gridsize, self._gridsize))
					if self._anchors:
						roundAnchorsToGrid(self.font[gName], (self._gridsize, self._gridsize))
					if self._sidebearings:
						roundMargins(self.font[gName], self._gridsize, left=True, right=True)
					if self._mark:
						self.font[gName].mark = self._mark_color
					self.font[gName].update()
				# done
				print
				self.font.update()
				if self._verbose:
					print '\n...done.\n'
			# no glyphs selected
			else:
				print 'no glyph to process, please select one or more glyphs and try again.\n'
		# no font open
		else:
			print 'please open a font and try again.\n'
			
	def okCallback(self, sender):
		# print "...done.\n"
		pass
"""Import one glyph from a .ufo, 
	i.e. a single .glif file.
"""

from robofab.world import CurrentFont
from robofab.objects.objectsRF import OpenFont
from robofab.interface.all.dialogs import SelectGlyph, Message

flFont = CurrentFont()
if flFont is None:
	Message("Please have a FontLab destination font ready..")
else:
	# pick a .ufo
	rfFont = OpenFont()
	if rfFont is not None:
		# pick a glyph in the .ufo
		rfGlyph = SelectGlyph(rfFont)
		if rfGlyph is not None:
			# make a new glyph in the FL font
			flGlyph = flFont.newGlyph(rfGlyph.name, clear=True)
			# draw the glyph into the FL font
			pen = flGlyph.getPointPen()
			rfGlyph.drawPoints(pen)
			# set the width, unicodes and lib
			flGlyph.width = rfGlyph.width
			flGlyph.unicodes = rfGlyph.unicodes
			flGlyph.lib = rfGlyph.lib
			flGlyph.note = rfGlyph.note
			flGlyph.update()
			flFont.update()
from robofab.world import CurrentFont

font = CurrentFont()

for glyph in font:
    for contour in glyph:
        for point in contour.points:
            if point.type != "offCurve" and point.y == 689:
                point.y = point.y - 10

    font.update()

"""    old = font[g]
    print len(old)
    new = font.newGlyph("dummytmp", clear=True)
    
    pen = new.getPointPen()
    for contour in old:
        pen.beginPath()
        for point in contour.points:
            if point.type != "offCurve" and point.y == 0:
                pen.addPoint((point.x,point.y+10),point.type)
                print old.name, point.x, point.y , "modifiziert!"
            else:
                pen.addPoint((point.x,point.y), point.type)
        pen.endPath()
    
    font.newGlyph(g, clear=True)
    old.appendGlyph(new)

font.update()"""
Example #12
0
"""Import one glyph from a .ufo, 
	i.e. a single .glif file.
"""

from robofab.world import CurrentFont
from robofab.objects.objectsRF import OpenFont
from robofab.interface.all.dialogs import SelectGlyph, Message

flFont = CurrentFont()
if flFont is None:
    Message("Please have a FontLab destination font ready..")
else:
    # pick a .ufo
    rfFont = OpenFont()
    if rfFont is not None:
        # pick a glyph in the .ufo
        rfGlyph = SelectGlyph(rfFont)
        if rfGlyph is not None:
            # make a new glyph in the FL font
            flGlyph = flFont.newGlyph(rfGlyph.name, clear=True)
            # draw the glyph into the FL font
            pen = flGlyph.getPointPen()
            rfGlyph.drawPoints(pen)
            # set the width, unicodes and lib
            flGlyph.width = rfGlyph.width
            flGlyph.unicodes = rfGlyph.unicodes
            flGlyph.lib = rfGlyph.lib
            flGlyph.note = rfGlyph.note
            flGlyph.update()
            flFont.update()
Example #13
0
class RoundToGridDialog(object):

    _points = True
    _anchors = True
    _sidebearings = True
    _mark = True
    _mark_color = randomColor()
    _gridsize = 30
    _height = 235
    _column_1 = 120
    _title = 'round to grid'
    _padding_top = 10
    _padding = 10
    _bWidth = 80
    _row_height = 30
    _bSpacing = 0

    def __init__(self, verbose=True):
        self._verbose = verbose
        self._width = self._column_1 + self._bWidth + (self._padding_top * 3)
        self.w = ModalDialog((self._width, self._height),
                             self._title,
                             okCallback=self.okCallback)
        # grid size
        self.w.gridsize_label = TextBox(
            (self._padding, self._padding_top +
             (self._row_height * 0), self._column_1, self._row_height),
            "grid size:")
        self.w.gridsize_value = EditText(
            (self._column_1, self._padding_top +
             (self._row_height * 0), self._bWidth, self._row_height),
            self._gridsize,
            callback=self.gridsize_callback)
        # points
        self.w.points_checkbox = CheckBox(
            (self._padding, self._padding_top +
             (self._row_height * 1), -0, self._row_height),
            "points",
            callback=self.points_callback,
            value=self._points)
        # anchors
        self.w.anchors_checkbox = CheckBox(
            (self._padding, self._padding_top +
             (self._row_height * 2), -0, self._row_height),
            "anchors",
            callback=self.anchors_callback,
            value=self._anchors)
        # side-bearings
        self.w.sidebearings_checkbox = CheckBox(
            (self._padding, self._padding_top +
             (self._row_height * 3), -0, self._row_height),
            "side-bearings",
            callback=self.sidebearings_callback,
            value=self._sidebearings)
        # mark
        self.w.mark_checkbox = CheckBox(
            (self._padding, self._padding_top +
             (self._row_height * 4), -0, self._row_height),
            "mark",
            callback=self.mark_callback,
            value=True)
        # apply
        self.w.apply_button = Button(
            (self._padding,
             (2 * self._padding) + ((self._row_height) * 4), self._width -
             (2 * self._padding_top), self._row_height),
            'apply',
            callback=self.apply_callback)
        # open window
        self.w.open()

    def gridsize_callback(self, sender):
        self._gridsize = sender.get()

    def points_callback(self, sender):
        self._points = sender.get()

    def anchors_callback(self, sender):
        self._anchors = sender.get()

    def sidebearings_callback(self, sender):
        self._sidebearings = sender.get()

    def mark_callback(self, sender):
        self._mark = sender.get()

    def apply_callback(self, sender):
        self.font = CurrentFont()
        if self.font is not None:
            gNames = getGlyphs(self.font)
            if len(gNames) > 0:
                # print info
                if self._verbose:
                    print 'rounding glyphs to grid...\n'
                    print '\tgrid size: %s' % self._gridsize
                    print '\tpoints: %s' % self._points
                    print '\tanchors: %s' % self._anchors
                    print '\tside-bearings: %s' % self._sidebearings
                    print '\tmark: %s' % self._mark
                    print
                    print '\t',
                # batch process glyphs
                for gName in gNames:
                    print gName,
                    if self._points:
                        roundPointsToGrid(self.font[gName],
                                          (self._gridsize, self._gridsize))
                    if self._anchors:
                        roundAnchorsToGrid(self.font[gName],
                                           (self._gridsize, self._gridsize))
                    if self._sidebearings:
                        roundMargins(self.font[gName],
                                     self._gridsize,
                                     left=True,
                                     right=True)
                    if self._mark:
                        self.font[gName].mark = self._mark_color
                    self.font[gName].update()
                # done
                print
                self.font.update()
                if self._verbose:
                    print '\n...done.\n'
            # no glyphs selected
            else:
                print 'no glyph to process, please select one or more glyphs and try again.\n'
        # no font open
        else:
            print 'please open a font and try again.\n'

    def okCallback(self, sender):
        # print "...done.\n"
        pass
		if ancho_myfont < ancho_nuevo :
			diferencia = "+" + str(ancho_nuevo - ancho_myfont)
		if ancho_myfont == ancho_nuevo:
			diferencia = " - "

		# Imprimo
		print item + " " + str(ancho_nuevo) + " (" + str(diferencia) + ")"
		
		# Borro Lineas Guia Locales
		myfont[item].clearVGuides()
		myfont[item].clearHGuides()
		
		# Agrego Linea Guia en el nuevo Ancho
		myfont[item].appendVGuide(ancho_nuevo)
		
		# Pinto
		if ancho_myfont == ancho_nuevo:
			myfont[item].mark = 70
		if ancho_myfont < ancho_nuevo:
			myfont[item].mark = 130
		if ancho_myfont > ancho_nuevo:
			myfont[item].mark = 255						

# Cierro la fuente Original	
orignalFont.close()

#Updateo mi fuente		
myfont.update()

# Listo el pollo
print '------ Done ------';
Example #15
0
#FLM: AT Compatible through fonts
"""correctDirection(): correct the direction of all contours in this glyphs.
autoContourOrder(): automatically order the contours based on (in this order): the point count of the contours, the segment count of the contours, the x value of the center of the contours, the y value of the center of the contours and the surface of the bounding box of the contours.
"""
from robofab.world import CurrentFont, AllFonts

fonts = AllFonts()
current = CurrentFont()
currentFullName = current.info.fullName


def checkGlyph(g):
    for f in fonts:
        if f[g.name] and f.info.fullName != currentFullName:
            if g.isCompatible(f[g.name]):
                g.mark = 20


for g in current:
    checkGlyph(g)

current.update()
		if ancho_myfont < ancho_nuevo :
			diferencia = "+" + str(ancho_nuevo - ancho_myfont)
		if ancho_myfont == ancho_nuevo:
			diferencia = " - "

		# Imprimo
		print item + " " + str(ancho_nuevo) + " (" + str(diferencia) + ")"
		
		# Borro Lineas Guia Locales
		myfont[item].clearVGuides()
		myfont[item].clearHGuides()
		
		# Agrego Linea Guia en el nuevo Ancho
		myfont[item].appendVGuide(ancho_nuevo)
		
		# Pinto
		if ancho_myfont == ancho_nuevo:
			myfont[item].mark = 70
		if ancho_myfont < ancho_nuevo:
			myfont[item].mark = 130
		if ancho_myfont > ancho_nuevo:
			myfont[item].mark = 255					

# Cierro la fuente Original	
orignalFont.close()

#Updateo mi fuente		
myfont.update()

# Listo el pollo
print '------ Done ------';
			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')
Example #18
0
#FLM: Copy Font Sidebearing
# (c) Ben Kiel
#
# Copys one font's sidebearing values to another font

#Imports
from robofab.world import OpenFont, CurrentFont
from robofab.interface.all.dialogs import Message

fontToChange = CurrentFont()
orignalMetricsFont = OpenFont(None, "Which font's sidebearings do you want?")
orignalMetrics = {}

for glyph in orignalMetricsFont:
    orignalMetrics[glyph.name] = [glyph.leftMargin, glyph.rightMargin]
orignalMetricsFont.close()

for name, metrics in orignalMetrics.iteritems():
    if fontToChange.has_key(name):
        fontToChange[name].leftMargin = metrics[0]
        fontToChange[name].rightMargin = metrics[1]
fontToChange.update()
Message('Done changing sidebearings')