signature
stringlengths 8
3.44k
| body
stringlengths 0
1.41M
| docstring
stringlengths 1
122k
| id
stringlengths 5
17
|
|---|---|---|---|
def round(self):
|
self._round()<EOL>
|
Round coordinates in all points to integers.
|
f10848:c0:m18
|
def _round(self, **kwargs):
|
for point in self.points:<EOL><INDENT>point.round()<EOL><DEDENT>
|
Subclasses may override this method.
|
f10848:c0:m19
|
def _transformBy(self, matrix, **kwargs):
|
for point in self.points:<EOL><INDENT>point.transformBy(matrix)<EOL><DEDENT>
|
Subclasses may override this method.
|
f10848:c0:m20
|
def isCompatible(self, other):
|
return super(BaseContour, self).isCompatible(other, BaseContour)<EOL>
|
Evaluate interpolation compatibility with **other**. ::
>>> compatible, report = self.isCompatible(otherContour)
>>> compatible
False
>>> compatible
[Fatal] Contour: [0] + [0]
[Fatal] Contour: [0] contains 4 segments | [0] contains 3 segments
[Fatal] Contour: [0] is closed | [0] is open
This will return a ``bool`` indicating if the contour is
compatible for interpolation with **other** and a
:ref:`type-string` of compatibility notes.
|
f10848:c0:m21
|
def _isCompatible(self, other, reporter):
|
contour1 = self<EOL>contour2 = other<EOL>if contour1.open != contour2.open:<EOL><INDENT>reporter.openDifference = True<EOL><DEDENT>if contour1.clockwise != contour2.clockwise:<EOL><INDENT>reporter.directionDifference = True<EOL><DEDENT>if len(contour1) != len(contour2.segments):<EOL><INDENT>reporter.segmentCountDifference = True<EOL>reporter.fatal = True<EOL><DEDENT>for i in range(min(len(contour1), len(contour2))):<EOL><INDENT>segment1 = contour1[i]<EOL>segment2 = contour2[i]<EOL>segmentCompatibility = segment1.isCompatible(segment2)[<NUM_LIT:1>]<EOL>if segmentCompatibility.fatal or segmentCompatibility.warning:<EOL><INDENT>if segmentCompatibility.fatal:<EOL><INDENT>reporter.fatal = True<EOL><DEDENT>if segmentCompatibility.warning:<EOL><INDENT>reporter.warning = True<EOL><DEDENT>reporter.segments.append(segmentCompatibility)<EOL><DEDENT><DEDENT>
|
This is the environment implementation of
:meth:`BaseContour.isCompatible`.
Subclasses may override this method.
|
f10848:c0:m22
|
def _get_open(self):
|
self.raiseNotImplementedError()<EOL>
|
Subclasses must override this method.
|
f10848:c0:m24
|
def _get_clockwise(self):
|
self.raiseNotImplementedError()<EOL>
|
Subclasses must override this method.
|
f10848:c0:m27
|
def _set_clockwise(self, value):
|
if self.clockwise != value:<EOL><INDENT>self.reverse()<EOL><DEDENT>
|
Subclasses may override this method.
|
f10848:c0:m28
|
def reverse(self):
|
self._reverseContour()<EOL>
|
Reverse the direction of the contour.
|
f10848:c0:m29
|
def _reverse(self, **kwargs):
|
self.raiseNotImplementedError()<EOL>
|
Subclasses may override this method.
|
f10848:c0:m30
|
def pointInside(self, point):
|
point = normalizers.normalizeCoordinateTuple(point)<EOL>return self._pointInside(point)<EOL>
|
Determine if ``point`` is in the black or white of the contour.
>>> contour.pointInside((40, 65))
True
``point`` must be a :ref:`type-coordinate`.
|
f10848:c0:m31
|
def _pointInside(self, point):
|
from fontTools.pens.pointInsidePen import PointInsidePen<EOL>pen = PointInsidePen(glyphSet=None, testPoint=point, evenOdd=False)<EOL>self.draw(pen)<EOL>return pen.getResult()<EOL>
|
Subclasses may override this method.
|
f10848:c0:m32
|
def contourInside(self, otherContour):
|
otherContour = normalizers.normalizeContour(otherContour)<EOL>return self._contourInside(otherContour)<EOL>
|
Determine if ``otherContour`` is in the black or white of this contour.
>>> contour.contourInside(otherContour)
True
``contour`` must be a :class:`BaseContour`.
|
f10848:c0:m33
|
def _contourInside(self, otherContour):
|
self.raiseNotImplementedError()<EOL>
|
Subclasses may override this method.
|
f10848:c0:m34
|
def _get_bounds(self):
|
from fontTools.pens.boundsPen import BoundsPen<EOL>pen = BoundsPen(self.layer)<EOL>self.draw(pen)<EOL>return pen.bounds<EOL>
|
Subclasses may override this method.
|
f10848:c0:m36
|
def _get_area(self):
|
from fontTools.pens.areaPen import AreaPen<EOL>pen = AreaPen(self.layer)<EOL>self.draw(pen)<EOL>return abs(pen.value)<EOL>
|
Subclasses may override this method.
|
f10848:c0:m38
|
def _get_segments(self):
|
points = list(self.points)<EOL>segments = [[]]<EOL>lastWasOffCurve = False<EOL>firstIsMove = points[<NUM_LIT:0>].type == "<STR_LIT>"<EOL>for point in points:<EOL><INDENT>segments[-<NUM_LIT:1>].append(point)<EOL>if point.type != "<STR_LIT>":<EOL><INDENT>segments.append([])<EOL><DEDENT>lastWasOffCurve = point.type == "<STR_LIT>"<EOL><DEDENT>if len(segments[-<NUM_LIT:1>]) == <NUM_LIT:0>:<EOL><INDENT>del segments[-<NUM_LIT:1>]<EOL><DEDENT>if lastWasOffCurve and firstIsMove:<EOL><INDENT>del segments[-<NUM_LIT:1>]<EOL><DEDENT>if lastWasOffCurve and not firstIsMove:<EOL><INDENT>segment = segments.pop(-<NUM_LIT:1>)<EOL>segment.extend(segments[<NUM_LIT:0>])<EOL>del segments[<NUM_LIT:0>]<EOL>segments.append(segment)<EOL><DEDENT>if not lastWasOffCurve and not firstIsMove:<EOL><INDENT>segment = segments.pop(<NUM_LIT:0>)<EOL>segments.append(segment)<EOL><DEDENT>wrapped = []<EOL>for points in segments:<EOL><INDENT>s = self.segmentClass()<EOL>s._setPoints(points)<EOL>self._setContourInSegment(s)<EOL>wrapped.append(s)<EOL><DEDENT>return wrapped<EOL>
|
Subclasses may override this method.
|
f10848:c0:m40
|
def _len__segments(self, **kwargs):
|
return len(self.segments)<EOL>
|
Subclasses may override this method.
|
f10848:c0:m45
|
def appendSegment(self, type=None, points=None, smooth=False, segment=None):
|
if segment is not None:<EOL><INDENT>if type is not None:<EOL><INDENT>type = segment.type<EOL><DEDENT>if points is None:<EOL><INDENT>points = [(point.x, point.y) for point in segment.points]<EOL><DEDENT>smooth = segment.smooth<EOL><DEDENT>type = normalizers.normalizeSegmentType(type)<EOL>pts = []<EOL>for pt in points:<EOL><INDENT>pt = normalizers.normalizeCoordinateTuple(pt)<EOL>pts.append(pt)<EOL><DEDENT>points = pts<EOL>smooth = normalizers.normalizeBoolean(smooth)<EOL>self._appendSegment(type=type, points=points, smooth=smooth)<EOL>
|
Append a segment to the contour.
|
f10848:c0:m46
|
def _appendSegment(self, type=None, points=None, smooth=False, **kwargs):
|
self._insertSegment(len(self), type=type, points=points,<EOL>smooth=smooth, **kwargs)<EOL>
|
Subclasses may override this method.
|
f10848:c0:m47
|
def insertSegment(self, index, type=None, points=None, smooth=False, segment=None):
|
if segment is not None:<EOL><INDENT>if type is not None:<EOL><INDENT>type = segment.type<EOL><DEDENT>if points is None:<EOL><INDENT>points = [(point.x, point.y) for point in segment.points]<EOL><DEDENT>smooth = segment.smooth<EOL><DEDENT>index = normalizers.normalizeIndex(index)<EOL>type = normalizers.normalizeSegmentType(type)<EOL>pts = []<EOL>for pt in points:<EOL><INDENT>pt = normalizers.normalizeCoordinateTuple(pt)<EOL>pts.append(pt)<EOL><DEDENT>points = pts<EOL>smooth = normalizers.normalizeBoolean(smooth)<EOL>self._insertSegment(index=index, type=type,<EOL>points=points, smooth=smooth)<EOL>
|
Insert a segment into the contour.
|
f10848:c0:m48
|
def _insertSegment(self, index=None, type=None, points=None,<EOL>smooth=False, **kwargs):
|
onCurve = points[-<NUM_LIT:1>]<EOL>offCurve = points[:-<NUM_LIT:1>]<EOL>segments = self.segments<EOL>ptCount = sum([len(segments[s].points) for s in range(index)]) + <NUM_LIT:1><EOL>self.insertPoint(ptCount, onCurve, type=type, smooth=smooth)<EOL>for offCurvePoint in reversed(offCurve):<EOL><INDENT>self.insertPoint(ptCount, offCurvePoint, type="<STR_LIT>")<EOL><DEDENT>
|
Subclasses may override this method.
|
f10848:c0:m49
|
def removeSegment(self, segment, preserveCurve=False):
|
if not isinstance(segment, int):<EOL><INDENT>segment = self.segments.index(segment)<EOL><DEDENT>segment = normalizers.normalizeIndex(segment)<EOL>if segment >= self._len__segments():<EOL><INDENT>raise ValueError("<STR_LIT>" % segment)<EOL><DEDENT>preserveCurve = normalizers.normalizeBoolean(preserveCurve)<EOL>self._removeSegment(segment, preserveCurve)<EOL>
|
Remove segment from the contour.
If ``preserveCurve`` is set to ``True`` an attempt
will be made to preserve the shape of the curve
if the environment supports that functionality.
|
f10848:c0:m50
|
def _removeSegment(self, segment, preserveCurve, **kwargs):
|
segment = self.segments[segment]<EOL>for point in segment.points:<EOL><INDENT>self.removePoint(point, preserveCurve)<EOL><DEDENT>
|
segment will be a valid segment index.
preserveCurve will be a boolean.
Subclasses may override this method.
|
f10848:c0:m51
|
def setStartSegment(self, segment):
|
segments = self.segments<EOL>if not isinstance(segment, int):<EOL><INDENT>segmentIndex = segments.index(segment)<EOL><DEDENT>else:<EOL><INDENT>segmentIndex = segment<EOL><DEDENT>if len(self.segments) < <NUM_LIT:2>:<EOL><INDENT>return<EOL><DEDENT>if segmentIndex == <NUM_LIT:0>:<EOL><INDENT>return<EOL><DEDENT>if segmentIndex >= len(segments):<EOL><INDENT>raise ValueError(("<STR_LIT>"<EOL>"<STR_LIT>" % segmentIndex))<EOL><DEDENT>self._setStartSegment(segmentIndex)<EOL>
|
Set the first segment on the contour.
segment can be a segment object or an index.
|
f10848:c0:m52
|
def _setStartSegment(self, segmentIndex, **kwargs):
|
segments = self.segments<EOL>oldStart = segments[-<NUM_LIT:1>]<EOL>oldLast = segments[<NUM_LIT:0>]<EOL>if oldLast.type == "<STR_LIT>" or oldLast.type == "<STR_LIT>":<EOL><INDENT>startOn = oldStart.onCurve<EOL>lastOn = oldLast.onCurve<EOL>if startOn.x == lastOn.x and startOn.y == lastOn.y:<EOL><INDENT>self.removeSegment(<NUM_LIT:0>)<EOL>segmentIndex = segmentIndex - <NUM_LIT:1><EOL>segments = self.segments<EOL><DEDENT><DEDENT>if segments[<NUM_LIT:0>].type == "<STR_LIT>":<EOL><INDENT>segments[<NUM_LIT:0>].type = "<STR_LIT>"<EOL><DEDENT>segments = segments[segmentIndex - <NUM_LIT:1>:] + segments[:segmentIndex - <NUM_LIT:1>]<EOL>points = []<EOL>for segment in segments:<EOL><INDENT>for point in segment:<EOL><INDENT>points.append(((point.x, point.y), point.type,<EOL>point.smooth, point.name, point.identifier))<EOL><DEDENT><DEDENT>for point in self.points:<EOL><INDENT>self.removePoint(point)<EOL><DEDENT>for point in points:<EOL><INDENT>position, type, smooth, name, identifier = point<EOL>self.appendPoint(<EOL>position,<EOL>type=type,<EOL>smooth=smooth,<EOL>name=name,<EOL>identifier=identifier<EOL>)<EOL><DEDENT>
|
Subclasses may override this method.
|
f10848:c0:m53
|
def appendBPoint(self, type=None, anchor=None, bcpIn=None, bcpOut=None, bPoint=None):
|
if bPoint is not None:<EOL><INDENT>if type is None:<EOL><INDENT>type = bPoint.type<EOL><DEDENT>if anchor is None:<EOL><INDENT>anchor = bPoint.anchor<EOL><DEDENT>if bcpIn is None:<EOL><INDENT>bcpIn = bPoint.bcpIn<EOL><DEDENT>if bcpOut is None:<EOL><INDENT>bcpOut = bPoint.bcpOut<EOL><DEDENT><DEDENT>type = normalizers.normalizeBPointType(type)<EOL>anchor = normalizers.normalizeCoordinateTuple(anchor)<EOL>if bcpIn is None:<EOL><INDENT>bcpIn = (<NUM_LIT:0>, <NUM_LIT:0>)<EOL><DEDENT>bcpIn = normalizers.normalizeCoordinateTuple(bcpIn)<EOL>if bcpOut is None:<EOL><INDENT>bcpOut = (<NUM_LIT:0>, <NUM_LIT:0>)<EOL><DEDENT>bcpOut = normalizers.normalizeCoordinateTuple(bcpOut)<EOL>self._appendBPoint(type, anchor, bcpIn=bcpIn, bcpOut=bcpOut)<EOL>
|
Append a bPoint to the contour.
|
f10848:c0:m55
|
def _appendBPoint(self, type, anchor, bcpIn=None, bcpOut=None, **kwargs):
|
self.insertBPoint(<EOL>len(self.bPoints),<EOL>type,<EOL>anchor,<EOL>bcpIn=bcpIn,<EOL>bcpOut=bcpOut<EOL>)<EOL>
|
Subclasses may override this method.
|
f10848:c0:m56
|
def insertBPoint(self, index, type=None, anchor=None, bcpIn=None, bcpOut=None, bPoint=None):
|
if bPoint is not None:<EOL><INDENT>if type is None:<EOL><INDENT>type = bPoint.type<EOL><DEDENT>if anchor is None:<EOL><INDENT>anchor = bPoint.anchor<EOL><DEDENT>if bcpIn is None:<EOL><INDENT>bcpIn = bPoint.bcpIn<EOL><DEDENT>if bcpOut is None:<EOL><INDENT>bcpOut = bPoint.bcpOut<EOL><DEDENT><DEDENT>index = normalizers.normalizeIndex(index)<EOL>type = normalizers.normalizeBPointType(type)<EOL>anchor = normalizers.normalizeCoordinateTuple(anchor)<EOL>if bcpIn is None:<EOL><INDENT>bcpIn = (<NUM_LIT:0>, <NUM_LIT:0>)<EOL><DEDENT>bcpIn = normalizers.normalizeCoordinateTuple(bcpIn)<EOL>if bcpOut is None:<EOL><INDENT>bcpOut = (<NUM_LIT:0>, <NUM_LIT:0>)<EOL><DEDENT>bcpOut = normalizers.normalizeCoordinateTuple(bcpOut)<EOL>self._insertBPoint(index=index, type=type, anchor=anchor,<EOL>bcpIn=bcpIn, bcpOut=bcpOut)<EOL>
|
Insert a bPoint at index in the contour.
|
f10848:c0:m57
|
def _insertBPoint(self, index, type, anchor, bcpIn, bcpOut, **kwargs):
|
<EOL>self._insertSegment(index=index, type="<STR_LIT>",<EOL>points=[anchor], smooth=False)<EOL>bPoints = self.bPoints<EOL>index += <NUM_LIT:1><EOL>if index >= len(bPoints):<EOL><INDENT>index = -<NUM_LIT:1><EOL><DEDENT>bPoint = bPoints[index]<EOL>bPoint.bcpIn = bcpIn<EOL>bPoint.bcpOut = bcpOut<EOL>bPoint.type = type<EOL>
|
Subclasses may override this method.
|
f10848:c0:m58
|
def removeBPoint(self, bPoint):
|
if not isinstance(bPoint, int):<EOL><INDENT>bPoint = bPoint.index<EOL><DEDENT>bPoint = normalizers.normalizeIndex(bPoint)<EOL>if bPoint >= self._len__points():<EOL><INDENT>raise ValueError("<STR_LIT>" % bPoint)<EOL><DEDENT>self._removeBPoint(bPoint)<EOL>
|
Remove the bpoint from the contour.
bpoint can be a point object or an index.
|
f10848:c0:m59
|
def _removeBPoint(self, index, **kwargs):
|
bPoint = self.bPoints[index]<EOL>nextSegment = bPoint._nextSegment<EOL>offCurves = nextSegment.offCurve<EOL>if offCurves:<EOL><INDENT>offCurve = offCurves[<NUM_LIT:0>]<EOL>self.removePoint(offCurve)<EOL><DEDENT>segment = bPoint._segment<EOL>offCurves = segment.offCurve<EOL>if offCurves:<EOL><INDENT>offCurve = offCurves[-<NUM_LIT:1>]<EOL>self.removePoint(offCurve)<EOL><DEDENT>self.removePoint(bPoint._point)<EOL>
|
index will be a valid index.
Subclasses may override this method.
|
f10848:c0:m60
|
def _get_points(self):
|
return tuple([self._getitem__points(i)<EOL>for i in range(self._len__points())])<EOL>
|
Subclasses may override this method.
|
f10848:c0:m62
|
def _lenPoints(self, **kwargs):
|
self.raiseNotImplementedError()<EOL>
|
This must return an integer indicating
the number of points in the contour.
Subclasses must override this method.
|
f10848:c0:m64
|
def _getPoint(self, index, **kwargs):
|
self.raiseNotImplementedError()<EOL>
|
This must return a wrapped point.
index will be a valid index.
Subclasses must override this method.
|
f10848:c0:m66
|
def appendPoint(self, position=None, type="<STR_LIT>", smooth=False, name=None, identifier=None, point=None):
|
if point is not None:<EOL><INDENT>if position is None:<EOL><INDENT>position = point.position<EOL><DEDENT>type = point.type<EOL>smooth = point.smooth<EOL>if name is None:<EOL><INDENT>name = point.name<EOL><DEDENT>if identifier is not None:<EOL><INDENT>identifier = point.identifier<EOL><DEDENT><DEDENT>self.insertPoint(<EOL>len(self.points),<EOL>position=position,<EOL>type=type,<EOL>smooth=smooth,<EOL>name=name,<EOL>identifier=identifier<EOL>)<EOL>
|
Append a point to the contour.
|
f10848:c0:m68
|
def insertPoint(self, index, position=None, type="<STR_LIT>", smooth=False, name=None, identifier=None, point=None):
|
if point is not None:<EOL><INDENT>if position is None:<EOL><INDENT>position = point.position<EOL><DEDENT>type = point.type<EOL>smooth = point.smooth<EOL>if name is None:<EOL><INDENT>name = point.name<EOL><DEDENT>if identifier is not None:<EOL><INDENT>identifier = point.identifier<EOL><DEDENT><DEDENT>index = normalizers.normalizeIndex(index)<EOL>position = normalizers.normalizeCoordinateTuple(position)<EOL>type = normalizers.normalizePointType(type)<EOL>smooth = normalizers.normalizeBoolean(smooth)<EOL>if name is not None:<EOL><INDENT>name = normalizers.normalizePointName(name)<EOL><DEDENT>if identifier is not None:<EOL><INDENT>identifier = normalizers.normalizeIdentifier(identifier)<EOL><DEDENT>self._insertPoint(<EOL>index,<EOL>position=position,<EOL>type=type,<EOL>smooth=smooth,<EOL>name=name,<EOL>identifier=identifier<EOL>)<EOL>
|
Insert a point into the contour.
|
f10848:c0:m69
|
def _insertPoint(self, index, position, type="<STR_LIT>",<EOL>smooth=False, name=None, identifier=None, **kwargs):
|
self.raiseNotImplementedError()<EOL>
|
position will be a valid position (x, y).
type will be a valid type.
smooth will be a valid boolean.
name will be a valid name or None.
identifier will be a valid identifier or None.
The identifier will not have been tested for uniqueness.
Subclasses must override this method.
|
f10848:c0:m70
|
def removePoint(self, point, preserveCurve=False):
|
if not isinstance(point, int):<EOL><INDENT>point = self.points.index(point)<EOL><DEDENT>point = normalizers.normalizeIndex(point)<EOL>if point >= self._len__points():<EOL><INDENT>raise ValueError("<STR_LIT>" % point)<EOL><DEDENT>preserveCurve = normalizers.normalizeBoolean(preserveCurve)<EOL>self._removePoint(point, preserveCurve)<EOL>
|
Remove the point from the contour.
point can be a point object or an index.
If ``preserveCurve`` is set to ``True`` an attempt
will be made to preserve the shape of the curve
if the environment supports that functionality.
|
f10848:c0:m71
|
def _removePoint(self, index, preserveCurve, **kwargs):
|
self.raiseNotImplementedError()<EOL>
|
index will be a valid index. preserveCurve will be a boolean.
Subclasses must override this method.
|
f10848:c0:m72
|
def _get_selectedSegments(self):
|
return self._getSelectedSubObjects(self.segments)<EOL>
|
Subclasses may override this method.
|
f10848:c0:m74
|
def _set_selectedSegments(self, value):
|
return self._setSelectedSubObjects(self.segments, value)<EOL>
|
Subclasses may override this method.
|
f10848:c0:m76
|
def _get_selectedPoints(self):
|
return self._getSelectedSubObjects(self.points)<EOL>
|
Subclasses may override this method.
|
f10848:c0:m78
|
def _set_selectedPoints(self, value):
|
return self._setSelectedSubObjects(self.points, value)<EOL>
|
Subclasses may override this method.
|
f10848:c0:m80
|
def _get_selectedBPoints(self):
|
return self._getSelectedSubObjects(self.bPoints)<EOL>
|
Subclasses may override this method.
|
f10848:c0:m82
|
def _set_selectedBPoints(self, value):
|
return self._setSelectedSubObjects(self.bPoints, value)<EOL>
|
Subclasses may override this method.
|
f10848:c0:m84
|
def __len__(self):
|
return self._len()<EOL>
|
An ``int`` representing number of glyphs in the layer. ::
>>> len(layer)
256
|
f10849:c0:m1
|
def _len(self, **kwargs):
|
return len(self.keys())<EOL>
|
This is the environment implementation of
:meth:`BaseLayer.__len__` and :meth:`BaseFont.__len__`
This must return an ``int`` indicating
the number of glyphs in the layer.
Subclasses may override this method.
|
f10849:c0:m2
|
def __iter__(self):
|
return self._iter()<EOL>
|
Iterate through the :class:`BaseGlyph` objects in the layer. ::
>>> for glyph in layer:
... glyph.name
"A"
"B"
"C"
|
f10849:c0:m3
|
def _iter(self, **kwargs):
|
for name in self.keys():<EOL><INDENT>yield self[name]<EOL><DEDENT>
|
This is the environment implementation of
:meth:`BaseLayer.__iter__` and :meth:`BaseFont.__iter__`
This must return an iterator that returns
instances of a :class:`BaseGlyph` subclass.
Subclasses may override this method.
|
f10849:c0:m4
|
def __getitem__(self, name):
|
name = normalizers.normalizeGlyphName(name)<EOL>if name not in self:<EOL><INDENT>raise KeyError("<STR_LIT>" % name)<EOL><DEDENT>glyph = self._getItem(name)<EOL>self._setLayerInGlyph(glyph)<EOL>return glyph<EOL>
|
Get the :class:`BaseGlyph` with name from the layer. ::
>>> glyph = layer["A"]
|
f10849:c0:m5
|
def _getItem(self, name, **kwargs):
|
self.raiseNotImplementedError()<EOL>
|
This is the environment implementation of
:meth:`BaseLayer.__getitem__` and :meth:`BaseFont.__getitem__`
This must return an instance of a :class:`BaseGlyph`
subclass. **name** will be a :ref:`type-string` representing
a name of a glyph that is in the layer. It will have been
normalized with :func:`normalizers.normalizeGlyphName`.
Subclasses must override this method.
|
f10849:c0:m6
|
def __setitem__(self, name, glyph):
|
name = normalizers.normalizeGlyphName(name)<EOL>if name in self:<EOL><INDENT>del self[name]<EOL><DEDENT>return self._insertGlyph(glyph, name=name)<EOL>
|
Insert **glyph** into the layer. ::
>>> glyph = layer["A"] = otherGlyph
This will not insert the glyph directly. Rather, a
new glyph will be created and the data from **glyph**
will be copied to the new glyph. **name** indicates
the name that should be assigned to the glyph after
insertion. If **name** is not given, the glyph's original
name must be used. If the glyph does not have a name,
an error must be raised. The data that will be inserted
from **glyph** is the same data as documented in
:meth:`BaseGlyph.copy`.
|
f10849:c0:m7
|
def __delitem__(self, name):
|
name = normalizers.normalizeGlyphName(name)<EOL>if name not in self:<EOL><INDENT>raise KeyError("<STR_LIT>" % name)<EOL><DEDENT>self._removeGlyph(name)<EOL>
|
Remove the glyph with name from the layer. ::
>>> del layer["A"]
|
f10849:c0:m8
|
def keys(self):
|
return self._keys()<EOL>
|
Get a list of all glyphs in the layer. ::
>>> layer.keys()
["B", "C", "A"]
The order of the glyphs is undefined.
|
f10849:c0:m9
|
def _keys(self, **kwargs):
|
self.raiseNotImplementedError()<EOL>
|
This is the environment implementation of
:meth:`BaseLayer.keys` and :meth:`BaseFont.keys`
This must return an :ref:`type-immutable-list`
of the names representing all glyphs in the layer.
The order is not defined.
Subclasses must override this method.
|
f10849:c0:m10
|
def __contains__(self, name):
|
name = normalizers.normalizeGlyphName(name)<EOL>return self._contains(name)<EOL>
|
Test if the layer contains a glyph with **name**. ::
>>> "A" in layer
True
|
f10849:c0:m11
|
def _contains(self, name, **kwargs):
|
return name in self.keys()<EOL>
|
This is the environment implementation of
:meth:`BaseLayer.__contains__` and :meth:`BaseFont.__contains__`
This must return ``bool`` indicating if the
layer has a glyph with the defined name.
**name** will be a :ref-type-string` representing
a glyph name. It will have been normalized with
:func:`normalizers.normalizeGlyphName`.
Subclasses may override this method.
|
f10849:c0:m12
|
def newGlyph(self, name, clear=True):
|
name = normalizers.normalizeGlyphName(name)<EOL>if name not in self:<EOL><INDENT>glyph = self._newGlyph(name)<EOL><DEDENT>elif clear:<EOL><INDENT>self.removeGlyph(name)<EOL>glyph = self._newGlyph(name)<EOL><DEDENT>else:<EOL><INDENT>glyph = self._getItem(name)<EOL><DEDENT>self._setLayerInGlyph(glyph)<EOL>return glyph<EOL>
|
Make a new glyph with **name** in the layer. ::
>>> glyph = layer.newGlyph("A")
The newly created :class:`BaseGlyph` will be returned.
If the glyph exists in the layer and clear is set to ``False``,
the existing glyph will be returned, otherwise the default
behavior is to clear the exisiting glyph.
|
f10849:c0:m13
|
def _newGlyph(self, name, **kwargs):
|
self.raiseNotImplementedError()<EOL>
|
This is the environment implementation of
:meth:`BaseLayer.newGlyph` and :meth:`BaseFont.newGlyph`
This must return an instance of a :class:`BaseGlyph` subclass.
**name** will be a :ref:`type-string` representing
a glyph name. It will have been normalized with
:func:`normalizers.normalizeGlyphName`. The
name will have been tested to make sure that
no glyph with the same name exists in the layer.
Subclasses must override this method.
|
f10849:c0:m14
|
def removeGlyph(self, name):
|
del self[name]<EOL>
|
Remove the glyph with name from the layer. ::
>>> layer.removeGlyph("A")
This method is deprecated. :meth:`BaseFont.__delitem__` instead.
|
f10849:c0:m15
|
def _removeGlyph(self, name, **kwargs):
|
self.raiseNotImplementedError()<EOL>
|
This is the environment implementation of
:meth:`BaseLayer.removeGlyph` and :meth:`BaseFont.removeGlyph`.
**name** will be a :ref:`type-string` representing a
glyph name of a glyph that is in the layer. It will
have been normalized with :func:`normalizers.normalizeGlyphName`.
The newly created :class:`BaseGlyph` must be returned.
Subclasses must override this method.
|
f10849:c0:m16
|
def insertGlyph(self, glyph, name=None):
|
if name is None:<EOL><INDENT>name = glyph.name<EOL><DEDENT>self[name] = glyph<EOL>
|
Insert **glyph** into the layer. ::
>>> glyph = layer.insertGlyph(otherGlyph, name="A")
This method is deprecated. :meth:`BaseFont.__setitem__` instead.
|
f10849:c0:m17
|
def _insertGlyph(self, glyph, name, **kwargs):
|
if glyph.name is None or (name != glyph.name and glyph.name in self):<EOL><INDENT>glyph = glyph.copy()<EOL>glyph.name = name<EOL><DEDENT>dest = self.newGlyph(name, clear=kwargs.get("<STR_LIT>", True))<EOL>dest.copyData(glyph)<EOL>return dest<EOL>
|
This is the environment implementation of
:meth:`BaseLayer.__setitem__` and :meth:`BaseFont.__setitem__`.
This must return an instance of a :class:`BaseGlyph` subclass.
**glyph** will be a glyph object with the attributes necessary
for copying as defined in :meth:`BaseGlyph.copy` An environment
must not insert **glyph** directly. Instead the data from
**glyph** should be copied to a new glyph instead. **name**
will be a :ref:`type-string` representing a glyph name. It
will have been normalized with :func:`normalizers.normalizeGlyphName`.
**name** will have been tested to make sure that no glyph with
the same name exists in the layer.
Subclasses may override this method.
|
f10849:c0:m18
|
def _get_selectedGlyphs(self):
|
return self._getSelectedSubObjects(self)<EOL>
|
Subclasses may override this method.
|
f10849:c0:m20
|
def _set_selectedGlyphs(self, value):
|
return self._setSelectedSubObjects(self, value)<EOL>
|
Subclasses may override this method.
|
f10849:c0:m22
|
def _get_selectedGlyphNames(self):
|
selected = [glyph.name for glyph in self.selectedGlyphs]<EOL>return selected<EOL>
|
Subclasses may override this method.
|
f10849:c0:m24
|
def _set_selectedGlyphNames(self, value):
|
select = [self[name] for name in value]<EOL>self.selectedGlyphs = select<EOL>
|
Subclasses may override this method.
|
f10849:c0:m26
|
def copy(self):
|
return super(BaseLayer, self).copy()<EOL>
|
Copy the layer into a new layer that does not
belong to a font. ::
>>> copiedLayer = layer.copy()
This will copy:
* name
* color
* lib
* glyphs
|
f10849:c1:m1
|
def copyData(self, source):
|
super(BaseLayer, self).copyData(source)<EOL>for name in source.keys():<EOL><INDENT>glyph = self.newGlyph(name)<EOL>glyph.copyData(source[name])<EOL><DEDENT>
|
Copy data from **source** into this layer.
Refer to :meth:`BaseLayer.copy` for a list
of values that will be copied.
|
f10849:c1:m2
|
def _get_name(self):
|
self.raiseNotImplementedError()<EOL>
|
This is the environment implementation of :attr:`BaseLayer.name`.
This must return a :ref:`type-string` defining the name of the
layer. If the layer is the default layer, the returned value
must be ``None``. It will be normalized with
:func:`normalizers.normalizeLayerName`.
Subclasses must override this method.
|
f10849:c1:m7
|
def _set_name(self, value, **kwargs):
|
self.raiseNotImplementedError()<EOL>
|
This is the environment implementation of :attr:`BaseLayer.name`.
**value** will be a :ref:`type-string` defining the name of the
layer. It will have been normalized with
:func:`normalizers.normalizeLayerName`.
No layer with the same name will exist.
Subclasses must override this method.
|
f10849:c1:m8
|
def _get_color(self):
|
self.raiseNotImplementedError()<EOL>
|
This is the environment implementation of :attr:`BaseLayer.color`.
This must return a :ref:`type-color` defining the
color assigned to the layer. If the layer does not
have an assigned color, the returned value must be
``None``. It will be normalized with
:func:`normalizers.normalizeColor`.
Subclasses must override this method.
|
f10849:c1:m11
|
def _set_color(self, value, **kwargs):
|
self.raiseNotImplementedError()<EOL>
|
This is the environment implementation of :attr:`BaseLayer.color`.
**value** will be a :ref:`type-color` or ``None`` defining the
color to assign to the layer. It will have been normalized with
:func:`normalizers.normalizeColor`.
Subclasses must override this method.
|
f10849:c1:m12
|
def _get_lib(self):
|
self.raiseNotImplementedError()<EOL>
|
This is the environment implementation of :attr:`BaseLayer.lib`.
This must return an instance of a :class:`BaseLib` subclass.
|
f10849:c1:m14
|
def round(self):
|
self._round()<EOL>
|
Round all approriate data to integers. ::
>>> layer.round()
This is the equivalent of calling the round method on:
* all glyphs in the layer
|
f10849:c1:m15
|
def _round(self):
|
for glyph in self:<EOL><INDENT>glyph.round()<EOL><DEDENT>
|
This is the environment implementation of :meth:`BaseLayer.round`.
Subclasses may override this method.
|
f10849:c1:m16
|
def autoUnicodes(self):
|
self._autoUnicodes()<EOL>
|
Use heuristics to set Unicode values in all glyphs. ::
>>> layer.autoUnicodes()
Environments will define their own heuristics for
automatically determining values.
|
f10849:c1:m17
|
def _autoUnicodes(self):
|
for glyph in self:<EOL><INDENT>glyph.autoUnicodes()<EOL><DEDENT>
|
This is the environment implementation of
:meth:`BaseLayer.autoUnicodes`.
Subclasses may override this method.
|
f10849:c1:m18
|
def interpolate(self, factor, minLayer, maxLayer, round=True,<EOL>suppressError=True):
|
factor = normalizers.normalizeInterpolationFactor(factor)<EOL>if not isinstance(minLayer, BaseLayer):<EOL><INDENT>raise TypeError(("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>% (self.__class__.__name__, minLayer.__class__.__name__))<EOL><DEDENT>if not isinstance(maxLayer, BaseLayer):<EOL><INDENT>raise TypeError(("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>% (self.__class__.__name__, maxLayer.__class__.__name__))<EOL><DEDENT>round = normalizers.normalizeBoolean(round)<EOL>suppressError = normalizers.normalizeBoolean(suppressError)<EOL>self._interpolate(factor, minLayer, maxLayer,<EOL>round=round, suppressError=suppressError)<EOL>
|
Interpolate all possible data in the layer. ::
>>> layer.interpolate(0.5, otherLayer1, otherLayer2)
>>> layer.interpolate((0.5, 2.0), otherLayer1, otherLayer2, round=False)
The interpolation occurs on a 0 to 1.0 range where **minLayer**
is located at 0 and **maxLayer** is located at 1.0. **factor**
is the interpolation value. It may be less than 0 and greater
than 1.0. It may be a :ref:`type-int-float` or a tuple of
two :ref:`type-int-float`. If it is a tuple, the first
number indicates the x factor and the second number indicates
the y factor. **round** indicates if the result should be
rounded to integers. **suppressError** indicates if incompatible
data should be ignored or if an error should be raised when
such incompatibilities are found.
|
f10849:c1:m19
|
def _interpolate(self, factor, minLayer, maxLayer, round=True,<EOL>suppressError=True):
|
for glyphName in self.keys():<EOL><INDENT>del self[glyphName]<EOL><DEDENT>for glyphName in minLayer.keys():<EOL><INDENT>if glyphName not in maxLayer:<EOL><INDENT>continue<EOL><DEDENT>minGlyph = minLayer[glyphName]<EOL>maxGlyph = maxLayer[glyphName]<EOL>dstGlyph = self.newGlyph(glyphName)<EOL>dstGlyph.interpolate(factor, minGlyph, maxGlyph,<EOL>round=round, suppressError=suppressError)<EOL><DEDENT>
|
This is the environment implementation of
:meth:`BaseLayer.interpolate`.
Subclasses may override this method.
|
f10849:c1:m20
|
def isCompatible(self, other):
|
return super(BaseLayer, self).isCompatible(other, BaseLayer)<EOL>
|
Evaluate interpolation compatibility with **other**. ::
>>> compat, report = self.isCompatible(otherLayer)
>>> compat
False
>>> report
A
-
[Fatal] The glyphs do not contain the same number of contours.
This will return a ``bool`` indicating if the layer is
compatible for interpolation with **other** and a
:ref:`type-string` of compatibility notes.
|
f10849:c1:m21
|
def _isCompatible(self, other, reporter):
|
layer1 = self<EOL>layer2 = other<EOL>glyphs1 = set(layer1.keys())<EOL>glyphs2 = set(layer2.keys())<EOL>if len(glyphs1) != len(glyphs2):<EOL><INDENT>reporter.glyphCountDifference = True<EOL>reporter.warning = True<EOL><DEDENT>if len(glyphs1.difference(glyphs2)) != <NUM_LIT:0>:<EOL><INDENT>reporter.warning = True<EOL>reporter.glyphsMissingFromLayer2 = list(glyphs1.difference(glyphs2))<EOL><DEDENT>if len(glyphs2.difference(glyphs1)) != <NUM_LIT:0>:<EOL><INDENT>reporter.warning = True<EOL>reporter.glyphsMissingInLayer1 = list(glyphs2.difference(glyphs1))<EOL><DEDENT>for glyphName in sorted(glyphs1.intersection(glyphs2)):<EOL><INDENT>glyph1 = layer1[glyphName]<EOL>glyph2 = layer2[glyphName]<EOL>glyphCompatibility = glyph1.isCompatible(glyph2)[<NUM_LIT:1>]<EOL>if glyphCompatibility.fatal or glyphCompatibility.warning:<EOL><INDENT>if glyphCompatibility.fatal:<EOL><INDENT>reporter.fatal = True<EOL><DEDENT>if glyphCompatibility.warning:<EOL><INDENT>reporter.warning = True<EOL><DEDENT>reporter.glyphs.append(glyphCompatibility)<EOL><DEDENT><DEDENT>
|
This is the environment implementation of
:meth:`BaseLayer.isCompatible`.
Subclasses may override this method.
|
f10849:c1:m22
|
def getReverseComponentMapping(self):
|
return self._getReverseComponentMapping()<EOL>
|
Create a dictionary of unicode -> [glyphname, ...] mappings.
All glyphs are loaded. Note that one glyph can have multiple
unicode values, and a unicode value can have multiple glyphs
pointing to it.
|
f10849:c1:m23
|
def _getReverseComponentMapping(self):
|
self.raiseNotImplementedError()<EOL>
|
This is the environment implementation of
:meth:`BaseFont.getReverseComponentMapping`.
Subclasses may override this method.
|
f10849:c1:m24
|
def getCharacterMapping(self):
|
return self._getCharacterMapping()<EOL>
|
Get a reversed map of component references in the font.
{
'A' : ['Aacute', 'Aring']
'acute' : ['Aacute']
'ring' : ['Aring']
etc.
}
|
f10849:c1:m25
|
def _getCharacterMapping(self):
|
self.raiseNotImplementedError()<EOL>
|
This is the environment implementation of
:meth:`BaseFont.getCharacterMapping`.
Subclasses may override this method.
|
f10849:c1:m26
|
def _get_baseGlyph(self):
|
self.raiseNotImplementedError()<EOL>
|
Subclasses must override this method.
|
f10851:c0:m7
|
def _set_baseGlyph(self, value):
|
self.raiseNotImplementedError()<EOL>
|
Subclasses must override this method.
|
f10851:c0:m8
|
def _get_transformation(self):
|
self.raiseNotImplementedError()<EOL>
|
Subclasses must override this method.
|
f10851:c0:m11
|
def _set_transformation(self, value):
|
self.raiseNotImplementedError()<EOL>
|
Subclasses must override this method.
|
f10851:c0:m12
|
def _get_offset(self):
|
sx, sxy, syx, sy, ox, oy = self.transformation<EOL>return ox, oy<EOL>
|
Subclasses may override this method.
|
f10851:c0:m15
|
def _set_offset(self, value):
|
sx, sxy, syx, sy, ox, oy = self.transformation<EOL>ox, oy = value<EOL>self.transformation = sx, sxy, syx, sy, ox, oy<EOL>
|
Subclasses may override this method.
|
f10851:c0:m16
|
def _get_scale(self):
|
sx, sxy, syx, sy, ox, oy = self.transformation<EOL>return sx, sy<EOL>
|
Subclasses may override this method.
|
f10851:c0:m19
|
def _set_scale(self, value):
|
sx, sxy, syx, sy, ox, oy = self.transformation<EOL>sx, sy = value<EOL>self.transformation = sx, sxy, syx, sy, ox, oy<EOL>
|
Subclasses may override this method.
|
f10851:c0:m20
|
def _get_index(self):
|
glyph = self.glyph<EOL>return glyph.components.index(self)<EOL>
|
Subclasses may override this method.
|
f10851:c0:m23
|
def _set_index(self, value):
|
self.raiseNotImplementedError()<EOL>
|
Subclasses must override this method.
|
f10851:c0:m24
|
def draw(self, pen):
|
self._draw(pen)<EOL>
|
Draw the component with the given Pen.
|
f10851:c0:m25
|
def _draw(self, pen, **kwargs):
|
from fontTools.ufoLib.pointPen import PointToSegmentPen<EOL>adapter = PointToSegmentPen(pen)<EOL>self.drawPoints(adapter)<EOL>
|
Subclasses may override this method.
|
f10851:c0:m26
|
def drawPoints(self, pen):
|
self._drawPoints(pen)<EOL>
|
Draw the contour with the given PointPen.
|
f10851:c0:m27
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.