objectsBase

Base classes for the Unified Font Objects (UFO), a series of classes that deal with fonts, glyphs, contours and related things.

Unified Font Objects are: - platform independent - application independent

About Object Inheritance: objectsFL and objectsRF objects inherit methods and attributes from these objects. In other words, if it is in here, you can do it with the objectsFL and objectsRF.

issequence(x)

Is x a sequence? We say it is if it has a __getitem__ method.

class BasePostScriptHintValues(data=None)

Base class for postscript hinting information.

getParent()

this method will be overwritten with a weakref if there is a parent.

isEmpty()

Check all attrs and decide if they’re all empty.

clear()

Set all attributes to default / empty

copy(aParent=None)

Duplicate this object. Pass an object for parenting if you want.

class BasePostScriptGlyphHintValues(data=None)

Base class for glyph-level postscript hinting information. vStems, hStems

round()

Round the values to reasonable values. - stems are rounded to int

class BasePostScriptFontHintValues(data=None)

Base class for font-level postscript hinting information. Blues values, stem values.

round()

Round the values to reasonable values. - blueScale is not rounded, it is a float - forceBold is set to False if -0.5 < value < 0.5. Otherwise it will be True. - blueShift, blueFuzz are rounded to int - stems are rounded to int - blues are rounded to int

roundPt()

Round a vector

addPt(ptA, ptB)

Add two vectors

subPt(ptA, ptB)

Substract two vectors

mulPt(ptA, scalar)

Multiply a vector with scalar

relativeBCPIn(anchor, BCPIn)

convert absolute incoming bcp value to a relative value

absoluteBCPIn(anchor, BCPIn)

convert relative incoming bcp value to an absolute value

relativeBCPOut(anchor, BCPOut)

convert absolute outgoing bcp value to a relative value

absoluteBCPOut(anchor, BCPOut)

convert relative outgoing bcp value to an absolute value

class RBaseObject

Base class for wrapper objects

copy(aParent=None)

Duplicate this object. Pass an object for parenting if you want.

isRobofab()

Presence of this method indicates a Robofab object

naked()

Return the wrapped object itself, in case it is needed for direct access.

getParent()

this method will be overwritten with a weakref if there is a parent.

dump(private=False)

Print a dump of this object to the std out.

class BaseFont

Base class for all font objects.

update()

update the font

close(save=1)

Close the font, saving is optional.

round()

round all of the points in all of the glyphs

autoUnicodes()

Using fontTools.agl, assign Unicode lists to all glyphs in the font

getCharacterMapping()

Create a dictionary of unicode -> [glyphname, ...] mappings. Note that this dict is created each time this method is called, which can make it expensive for larger fonts. All glyphs are loaded. Note that one glyph can have multiple unicode values, and a unicode value can have multiple glyphs pointing to it.

getReverseComponentMapping()

Get a reversed map of component references in the font. { ‘A’ : [‘Aacute’, ‘Aring’] ‘acute’ : [‘Aacute’] ‘ring’ : [‘Aring’] etc. }

compileGlyph(glyphName, baseName, accentNames, adjustWidth=False, preflight=False, printErrors=True)

Compile components into a new glyph using components and anchorpoints. glyphName: the name of the glyph where it all needs to go baseName: the name of the base glyph accentNames: a list of accentName, anchorName tuples, [(‘acute’, ‘top’), etc]

generateGlyph(glyphName, replace=1, preflight=False, printErrors=True)

Generate a glyph and return it. Assembled from GlyphConstruction.txt

interpolate(factor, minFont, maxFont, suppressError=True, analyzeOnly=False, doProgress=False)

Traditional interpolation method. Interpolates by factor between minFont and maxFont. suppressError will supress all tracebacks and analyze only will not perform the interpolation but it will analyze all glyphs and return a dict of problems.

class BaseGlyph

Base class for all glyph objects.

interpolate(factor, minGlyph, maxGlyph, suppressError=True, analyzeOnly=False)

Traditional interpolation method. Interpolates by factor between minGlyph and maxGlyph. suppressError will supress all tracebacks and analyze only will not perform the interpolation but it will analyze all glyphs and return a dict of problems.

isCompatible(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.

box

the bounding box of the glyph: (xMin, yMin, xMax, yMax)

leftMargin

the left margin

rightMargin

the right margin

copy(aParent=None)

Duplicate this glyph

getGlyph(glyphName)

Provided there is a font parent for this glyph, return a sibling glyph.

getPen()

Return a Pen object for creating an outline in this glyph.

getPointPen()

Return a PointPen object for creating an outline in this glyph.

deSelect()

Set all selected attrs in glyph to False: for the glyph, components, anchors, points.

isEmpty()

return true if the glyph has no contours or components

update()

update the glyph

draw(pen)

draw the object with a RoboFab segment pen

drawPoints(pen)

draw the object with a point pen

appendContour(aContour, offset=(0, 0))

append a contour to the glyph

appendGlyph(aGlyph, offset=(0, 0))

append another glyph to the glyph

round()

round all coordinates in all contours, components and anchors

autoUnicodes()

Using fontTools.agl, assign Unicode list to the glyph

pointInside()

determine if the point is in the black or white of the glyph

correctDirection(trueType=False)

corect the direction of the contours in the glyph.

autoContourOrder()

attempt to sort the contours based on their centers

rasterize(cellSize=50, xMin=None, yMin=None, xMax=None, yMax=None)

Slice the glyph into a grid based on the cell size. It returns a list of lists containing bool values that indicate the black (True) or white (False) value of that particular cell. These lists are arranged from top to bottom of the glyph and proceed from left to right. This is an expensive operation!

move()

Move a glyph’s items that are flagged as True

scale()

scale the glyph

transform(matrix)

Transform this glyph. Use a Transform matrix object from robofab.transform

rotate(angle, offset=None)

rotate the glyph

skew(angle, offset=None)

skew the glyph

class BaseContour

Base class for all contour objects.

box

the bounding box for the contour

clockwise

direction of contour: positive=counterclockwise negative=clockwise

copy(aParent=None)

Duplicate this contour

round()

round the value of all points in the contour

draw(pen)

draw the object with a fontTools pen

drawPoints(pen)

draw the object with a point pen

move()

move the contour

scale()

scale the contour

transform(matrix)

Transform this contour. Use a Transform matrix object from robofab.transform

rotate(angle, offset=None)

rotate the contour

skew(angle, offset=None)

skew the contour

pointInside()

determine if the point is inside or ouside of the contour

autoStartSegment()

automatically set the lower left point of the contour as the first point.

appendBPoint(pointType, anchor, bcpIn=(0, 0), bcpOut=(0, 0))

append a bPoint to the contour

insertBPoint(index, pointType, anchor, bcpIn=(0, 0), bcpOut=(0, 0))

insert a bPoint at index on the contour

class BaseSegment

Base class for all segment objects

copy(aParent=None)

Duplicate this segment

round()

round all points in the segment

move()

move the segment

scale()

scale the segment

transform(matrix)

Transform this segment. Use a Transform matrix object from robofab.transform

offCurve

on curve point for the segment

onCurve

list of off curve points for the segment

class BasePoint

Base class for point objects.

copy(aParent=None)

Duplicate this point

select(state=True)

Set the selection of this point. XXXX This method should be a lot more versatile, dealing with different kinds of selection, select the bcp’s seperately etc. But that’s for later when we need it more. For now it’s just one flag for the entire thing.

round()

round the values in the point

move()

Move the point

scale()

scale the point

transform(matrix)

Transform this point. Use a Transform matrix object from fontTools.misc.transform

class BaseBPoint

Base class for bPoints objects.

select(state=True)

Set the selection of this point. XXXX This method should be a lot more versatile, dealing with different kinds of selection, select the bcp’s seperately etc. But that’s for later when we need it more. For now it’s just one flag for the entire thing.

round()

Round the coordinates to integers

move()

move the bPoint

scale()

scale the bPoint

transform(matrix)

Transform this point. Use a Transform matrix object from fontTools.misc.transform

anchor

the position of the anchor

bcpIn

the (x,y) for the incoming bcp

bcpOut

the (x,y) for the outgoing bcp

type

the type of bPoint, either ‘corner’ or ‘curve’

class BaseComponent

Base class for all component objects.

copy(aParent=None)

Duplicate this component.

box

the bounding box of the component: (xMin, yMin, xMax, yMax)

round()

round the offset values

draw(pen)

Segment pen drawing method.

drawPoints(pen)

draw the object with a point pen

class BaseAnchor

Base class for all anchor point objects.

copy(aParent=None)

Duplicate this anchor.

round()

round the values in the anchor

draw(pen)

Draw the object onto a segment pen

drawPoints(pen)

draw the object with a point pen

move()

Move the anchor

scale()

scale the anchor

transform(matrix)

Transform this anchor. Use a Transform matrix object from fontTools.misc.transform

class BaseGuide

Base class for all guide objects.

class BaseGroups

Base class for all RFont.groups objects

getParent()

this method will be overwritten with a weakref if there is a parent.

findGlyph(glyphName)

return a list of all groups contianing glyphName

class BaseLib

Base class for all lib objects

getParent()

this method will be overwritten with a weakref if there is a parent.

copy(aParent=None)

Duplicate this lib.

class BaseKerning(kerningDict=None)

Base class for all kerning objects. Object behaves like a dict but has some special kerning specific tricks.

keys()

return list of kerning pairs

values()

return a list of kerning values

items()

return a list of kerning items

get(pair, default=None)

get a value. return None if the pair does not exist

remove(pair)

remove a kerning pair

getAverage()

return average of all kerning pairs

getExtremes()

return the lowest and highest kerning values

update(kerningDict)

replace kerning data with the data in the given kerningDict

clear()

clear all kerning

add(value)

add value to all kerning pairs

scale(value)

scale all kernng pairs by value

minimize(minimum=10)

eliminate pairs with value less than minimum

eliminate(leftGlyphsToEliminate=None, rightGlyphsToEliminate=None, analyzeOnly=False)

eliminate pairs containing a left glyph that is in the leftGlyphsToEliminate list or a right glyph that is in the rightGlyphsToELiminate list. sideGlyphsToEliminate can be a string: ‘a’ or list: [‘a’, ‘b’]. analyzeOnly will not remove pairs. it will return a count of all pairs that would be removed.

interpolate(sourceDictOne, sourceDictTwo, value, clearExisting=True)

interpolate the kerning between sourceDictOne and sourceDictTwo. clearExisting will clear existing kerning first.

round(multiple=10)

round the kerning pair values to increments of multiple

occurrenceCount(glyphsToCount)

return a dict with glyphs as keys and the number of occurances of that glyph in the kerning pairs as the value glyphsToCount can be a string: ‘a’ or list: [‘a’, ‘b’]

getLeft(glyphName)

Return a list of kerns with glyphName as left character.

getRight(glyphName)

Return a list of kerns with glyphName as left character.

combine(kerningDicts, overwriteExisting=True)

combine two or more kerning dictionaries. overwrite exsisting duplicate pairs if overwriteExisting=True

swapNames(swapTable)

change glyph names in all kerning pairs based on swapTable. swapTable = {‘BeforeName’:’AfterName’, ...}

explodeClasses(leftClassDict=None, rightClassDict=None, analyzeOnly=False)

turn class kerns into real kerning pairs. classes should be defined in dicts: {‘O’:[‘C’, ‘G’, ‘Q’], ‘H’:[‘B’, ‘D’, ‘E’, ‘F’, ‘I’]}. analyzeOnly will not remove pairs. it will return a count of all pairs that would be added

implodeClasses(leftClassDict=None, rightClassDict=None, analyzeOnly=False)

condense the number of kerning pairs by applying classes. this will eliminate all pairs containg the classed glyphs leaving pairs that contain the key glyphs behind. analyzeOnly will not remove pairs. it will return a count of all pairs that would be removed.

importAFM(path, clearExisting=True)

Import kerning pairs from an AFM file. clearExisting=True will clear all exising kerning

asDict(returnIntegers=True)

return the object as a dictionary

links