signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
def __getitem__(self, groupName):
return super(BaseGroups, self).__getitem__(groupName)<EOL>
Returns the contents of the named group. **groupName** is a :ref:`type-string`. The returned value will be a :ref:`type-immutable-list` of the group contents.:: >>> font.groups["myGroup"] ("A", "B", "C") It is important to understand that any changes to the returned group contents will not be reflected in the Groups object. If one wants to make a change to the group contents, one should do the following:: >>> group = font.groups["myGroup"] >>> group.remove("A") >>> font.groups["myGroup"] = group
f10839:c0:m13
def __iter__(self):
return super(BaseGroups, self).__iter__()<EOL>
Iterates through the Groups, giving the key for each iteration. The order that the Groups will iterate though is not fixed nor is it ordered.:: >>> for groupName in font.groups: >>> print groupName "myGroup" "myGroup3" "myGroup2"
f10839:c0:m14
def __len__(self):
return super(BaseGroups, self).__len__()<EOL>
Returns the number of groups in Groups as an ``int``.:: >>> len(font.groups) 5
f10839:c0:m15
def __setitem__(self, groupName, glyphNames):
super(BaseGroups, self).__setitem__(groupName, glyphNames)<EOL>
Sets the **groupName** to the list of **glyphNames**. **groupName** is the group name as a :ref:`type-string` and **glyphNames** is a ``list`` of glyph names as :ref:`type-string`. >>> font.groups["myGroup"] = ["A", "B", "C"]
f10839:c0:m16
def clear(self):
super(BaseGroups, self).clear()<EOL>
Removes all group information from Groups, resetting the Groups to an empty dictionary. :: >>> font.groups.clear()
f10839:c0:m17
def get(self, groupName, default=None):
return super(BaseGroups, self).get(groupName, default)<EOL>
Returns the contents of the named group. **groupName** is a :ref:`type-string`, and the returned values will either be :ref:`type-immutable-list` of group contents or ``None`` if no group was found. :: >>> font.groups["myGroup"] ("A", "B", "C") It is important to understand that any changes to the returned group contents will not be reflected in the Groups object. If one wants to make a change to the group contents, one should do the following:: >>> group = font.groups["myGroup"] >>> group.remove("A") >>> font.groups["myGroup"] = group
f10839:c0:m18
def items(self):
return super(BaseGroups, self).items()<EOL>
Returns a list of ``tuple`` of each group name and group members. Group names are :ref:`type-string` and group members are a :ref:`type-immutable-list` of :ref:`type-string`. The initial list will be unordered. >>> font.groups.items() [("myGroup", ("A", "B", "C"), ("myGroup2", ("D", "E", "F"))]
f10839:c0:m19
def keys(self):
return super(BaseGroups, self).keys()<EOL>
Returns a ``list`` of all the group names in Groups. This list will be unordered.:: >>> font.groups.keys() ["myGroup4", "myGroup1", "myGroup5"]
f10839:c0:m20
def pop(self, groupName, default=None):
return super(BaseGroups, self).pop(groupName, default)<EOL>
Removes the **groupName** from the Groups and returns the list of group members. If no group is found, **default** is returned. **groupName** is a :ref:`type-string`. This must return either **default** or a :ref:`type-immutable-list` of glyph names as :ref:`type-string`. >>> font.groups.pop("myGroup") ("A", "B", "C")
f10839:c0:m21
def update(self, otherGroups):
super(BaseGroups, self).update(otherGroups)<EOL>
Updates the Groups based on **otherGroups**. *otherGroups** is a ``dict`` of groups information. If a group from **otherGroups** is in Groups, the group members will be replaced by the group members from **otherGroups**. If a group from **otherGroups** is not in the Groups, it is added to the Groups. If Groups contain a group name that is not in *otherGroups**, it is not changed. >>> font.groups.update(newGroups)
f10839:c0:m22
def values(self):
return super(BaseGroups, self).values()<EOL>
Returns a ``list`` of each named group's members. This will be a list of lists, the group members will be a :ref:`type-immutable-list` of :ref:`type-string`. The initial list will be unordered. >>> font.groups.items() [("A", "B", "C"), ("D", "E", "F")]
f10839:c0:m23
def copy(self):
return super(BaseGlyph, self).copy()<EOL>
Copy this glyph's data into a new glyph object. This new glyph object will not belong to a font. >>> copiedGlyph = glyph.copy() This will copy: - name - unicodes - width - height - note - markColor - lib - contours - components - anchors - guidelines - image
f10840:c0:m1
def _get_name(self):
self.raiseNotImplementedError()<EOL>
Get the name of the glyph. This must return a unicode string. Subclasses must override this method.
f10840:c0:m8
def _set_name(self, value):
self.raiseNotImplementedError()<EOL>
Set the name of the glyph. This will be a unicode string. Subclasses must override this method.
f10840:c0:m9
def _get_unicodes(self):
self.raiseNotImplementedError()<EOL>
Get the unicodes assigned to the glyph. This must return a tuple of zero or more integers. Subclasses must override this method.
f10840:c0:m12
def _set_unicodes(self, value):
self.raiseNotImplementedError()<EOL>
Assign the unicodes to the glyph. This will be a list of zero or more integers. Subclasses must override this method.
f10840:c0:m13
def _get_unicode(self):
values = self.unicodes<EOL>if values:<EOL><INDENT>return values[<NUM_LIT:0>]<EOL><DEDENT>return None<EOL>
Get the primary unicode assigned to the glyph. This must return an integer or None. Subclasses may override this method.
f10840:c0:m16
def _set_unicode(self, value):
values = list(self.unicodes)<EOL>if value in values:<EOL><INDENT>values.remove(value)<EOL><DEDENT>values.insert(<NUM_LIT:0>, value)<EOL>self.unicodes = values<EOL>
Assign the primary unicode to the glyph. This will be an integer or None. Subclasses may override this method.
f10840:c0:m17
def autoUnicodes(self):
self._autoUnicodes()<EOL>
Use heuristics to set the Unicode values in the glyph. >>> glyph.autoUnicodes() Environments will define their own heuristics for automatically determining values.
f10840:c0:m18
def _autoUnicodes(self):
self.raiseNotImplementedError()<EOL>
Subclasses must override this method.
f10840:c0:m19
def _get_width(self):
self.raiseNotImplementedError()<EOL>
This must return an int or float. Subclasses must override this method.
f10840:c0:m22
def _set_width(self, value):
self.raiseNotImplementedError()<EOL>
value will be an int or float. Subclasses must override this method.
f10840:c0:m23
def _get_leftMargin(self):
bounds = self.bounds<EOL>if bounds is None:<EOL><INDENT>return None<EOL><DEDENT>xMin, yMin, xMax, yMax = bounds<EOL>return xMin<EOL>
This must return an int or float. If the glyph has no outlines, this must return `None`. Subclasses may override this method.
f10840:c0:m26
def _set_leftMargin(self, value):
diff = value - self.leftMargin<EOL>self.moveBy((diff, <NUM_LIT:0>))<EOL>self.width += diff<EOL>
value will be an int or float. Subclasses may override this method.
f10840:c0:m27
def _get_rightMargin(self):
bounds = self.bounds<EOL>if bounds is None:<EOL><INDENT>return None<EOL><DEDENT>xMin, yMin, xMax, yMax = bounds<EOL>return self.width - xMax<EOL>
This must return an int or float. If the glyph has no outlines, this must return `None`. Subclasses may override this method.
f10840:c0:m30
def _set_rightMargin(self, value):
bounds = self.bounds<EOL>if bounds is None:<EOL><INDENT>self.width = value<EOL><DEDENT>else:<EOL><INDENT>xMin, yMin, xMax, yMax = bounds<EOL>self.width = xMax + value<EOL><DEDENT>
value will be an int or float. Subclasses may override this method.
f10840:c0:m31
def _get_height(self):
self.raiseNotImplementedError()<EOL>
This must return an int or float. Subclasses must override this method.
f10840:c0:m34
def _set_height(self, value):
self.raiseNotImplementedError()<EOL>
value will be an int or float. Subclasses must override this method.
f10840:c0:m35
def _get_bottomMargin(self):
bounds = self.bounds<EOL>if bounds is None:<EOL><INDENT>return None<EOL><DEDENT>xMin, yMin, xMax, yMax = bounds<EOL>return yMin<EOL>
This must return an int or float. If the glyph has no outlines, this must return `None`. Subclasses may override this method.
f10840:c0:m38
def _set_bottomMargin(self, value):
diff = value - self.bottomMargin<EOL>self.moveBy((<NUM_LIT:0>, diff))<EOL>self.height += diff<EOL>
value will be an int or float. Subclasses may override this method.
f10840:c0:m39
def _get_topMargin(self):
bounds = self.bounds<EOL>if bounds is None:<EOL><INDENT>return None<EOL><DEDENT>xMin, yMin, xMax, yMax = bounds<EOL>return self.height - yMax<EOL>
This must return an int or float. If the glyph has no outlines, this must return `None`. Subclasses may override this method.
f10840:c0:m42
def _set_topMargin(self, value):
bounds = self.bounds<EOL>if bounds is None:<EOL><INDENT>self.height = value<EOL><DEDENT>else:<EOL><INDENT>xMin, yMin, xMax, yMax = bounds<EOL>self.height = yMax + value<EOL><DEDENT>
value will be an int or float. Subclasses may override this method.
f10840:c0:m43
def getPen(self):
self.raiseNotImplementedError()<EOL>
Return a :ref:`type-pen` object for adding outline data to the glyph. >>> pen = glyph.getPen()
f10840:c0:m44
def getPointPen(self):
self.raiseNotImplementedError()<EOL>
Return a :ref:`type-pointpen` object for adding outline data to the glyph. >>> pointPen = glyph.getPointPen()
f10840:c0:m45
def draw(self, pen, contours=True, components=True):
if contours:<EOL><INDENT>for contour in self:<EOL><INDENT>contour.draw(pen)<EOL><DEDENT><DEDENT>if components:<EOL><INDENT>for component in self.components:<EOL><INDENT>component.draw(pen)<EOL><DEDENT><DEDENT>
Draw the glyph's outline data (contours and components) to the given :ref:`type-pen`. >>> glyph.draw(pen) If ``contours`` is set to ``False``, the glyph's contours will not be drawn. >>> glyph.draw(pen, contours=False) If ``components`` is set to ``False``, the glyph's components will not be drawn. >>> glyph.draw(pen, components=False)
f10840:c0:m46
def drawPoints(self, pen, contours=True, components=True):
if contours:<EOL><INDENT>for contour in self:<EOL><INDENT>contour.drawPoints(pen)<EOL><DEDENT><DEDENT>if components:<EOL><INDENT>for component in self.components:<EOL><INDENT>component.drawPoints(pen)<EOL><DEDENT><DEDENT>
Draw the glyph's outline data (contours and components) to the given :ref:`type-pointpen`. >>> glyph.drawPoints(pointPen) If ``contours`` is set to ``False``, the glyph's contours will not be drawn. >>> glyph.drawPoints(pointPen, contours=False) If ``components`` is set to ``False``, the glyph's components will not be drawn. >>> glyph.drawPoints(pointPen, components=False)
f10840:c0:m47
def clear(self, contours=True, components=True, anchors=True,<EOL>guidelines=True, image=True):
self._clear(contours=contours, components=components,<EOL>anchors=anchors, guidelines=guidelines, image=image)<EOL>
Clear the glyph. >>> glyph.clear() This clears: - contours - components - anchors - guidelines - image It's possible to turn off the clearing of portions of the glyph with the listed arguments. >>> glyph.clear(guidelines=False)
f10840:c0:m48
def _clear(self, contours=True, components=True, anchors=True,<EOL>guidelines=True, image=True):
if contours:<EOL><INDENT>self.clearContours()<EOL><DEDENT>if components:<EOL><INDENT>self.clearComponents()<EOL><DEDENT>if anchors:<EOL><INDENT>self.clearAnchors()<EOL><DEDENT>if guidelines:<EOL><INDENT>self.clearGuidelines()<EOL><DEDENT>if image:<EOL><INDENT>self.clearImage()<EOL><DEDENT>
Subclasses may override this method.
f10840:c0:m49
def appendGlyph(self, other, offset=None):
if offset is None:<EOL><INDENT>offset = (<NUM_LIT:0>, <NUM_LIT:0>)<EOL><DEDENT>offset = normalizers.normalizeTransformationOffset(offset)<EOL>self._appendGlyph(other, offset)<EOL>
Append the data from ``other`` to new objects in this glyph. This will append: - contours - components - anchors - guidelines >>> glyph.appendGlyph(otherGlyph) ``offset`` indicates the x and y shift values that should be applied to the appended data. It must be a :ref:`type-coordinate` value or ``None``. If ``None`` is given, the offset will be ``(0, 0)``. >>> glyph.appendGlyph(otherGlyph, (100, 0))
f10840:c0:m50
def _appendGlyph(self, other, offset=None):
other = other.copy()<EOL>if offset != (<NUM_LIT:0>, <NUM_LIT:0>):<EOL><INDENT>other.moveBy(offset)<EOL><DEDENT>for contour in other.contours:<EOL><INDENT>self.appendContour(contour)<EOL><DEDENT>for component in other.components:<EOL><INDENT>self.appendComponent(component=component)<EOL><DEDENT>for anchor in other.anchors:<EOL><INDENT>self.appendAnchor(anchor=anchor)<EOL><DEDENT>for guideline in other.guidelines:<EOL><INDENT>self.appendGuideline(guideline=guideline)<EOL><DEDENT>
Subclasses may override this method.
f10840:c0:m51
def _get_contours(self):
return tuple([self[i] for i in range(len(self))])<EOL>
Subclasses may override this method.
f10840:c0:m53
def __len__(self):
return self._lenContours()<EOL>
The number of contours in the glyph. >>> len(glyph) 2
f10840:c0:m54
def _lenContours(self, **kwargs):
self.raiseNotImplementedError()<EOL>
This must return an integer. Subclasses must override this method.
f10840:c0:m55
def __iter__(self):
return self._iterContours()<EOL>
Iterate through all contours in the glyph. >>> for contour in glyph: ... contour.reverse()
f10840:c0:m56
def _iterContours(self, **kwargs):
count = len(self)<EOL>index = <NUM_LIT:0><EOL>while count:<EOL><INDENT>yield self[index]<EOL>count -= <NUM_LIT:1><EOL>index += <NUM_LIT:1><EOL><DEDENT>
This must return an iterator that returns wrapped contours. Subclasses may override this method.
f10840:c0:m57
def __getitem__(self, index):
index = normalizers.normalizeIndex(index)<EOL>if index >= len(self):<EOL><INDENT>raise ValueError("<STR_LIT>" % index)<EOL><DEDENT>contour = self._getContour(index)<EOL>self._setGlyphInContour(contour)<EOL>return contour<EOL>
Get the contour located at ``index`` from the glyph. >>> contour = glyph[0] The returned value will be a :class:`BaseContour` object.
f10840:c0:m58
def _getContour(self, index, **kwargs):
self.raiseNotImplementedError()<EOL>
This must return a wrapped contour. index will be a valid index. Subclasses must override this method.
f10840:c0:m59
def appendContour(self, contour, offset=None):
contour = normalizers.normalizeContour(contour)<EOL>if offset is None:<EOL><INDENT>offset = (<NUM_LIT:0>, <NUM_LIT:0>)<EOL><DEDENT>offset = normalizers.normalizeTransformationOffset(offset)<EOL>return self._appendContour(contour, offset)<EOL>
Append a contour containing the same data as ``contour`` to this glyph. >>> contour = glyph.appendContour(contour) This will return a :class:`BaseContour` object representing the new contour in the glyph. ``offset`` indicates the x and y shift values that should be applied to the appended data. It must be a :ref:`type-coordinate` value or ``None``. If ``None`` is given, the offset will be ``(0, 0)``. >>> contour = glyph.appendContour(contour, (100, 0))
f10840:c0:m61
def _appendContour(self, contour, offset=None, **kwargs):
copy = contour.copy()<EOL>if offset != (<NUM_LIT:0>, <NUM_LIT:0>):<EOL><INDENT>copy.moveBy(offset)<EOL><DEDENT>pointPen = self.getPointPen()<EOL>contour.drawPoints(pointPen)<EOL>return self[-<NUM_LIT:1>]<EOL>
contour will be an object with a drawPoints method. offset will be a valid offset (x, y). This must return the new contour. Subclasses may override this method.
f10840:c0:m62
def removeContour(self, contour):
if isinstance(contour, int):<EOL><INDENT>index = contour<EOL><DEDENT>else:<EOL><INDENT>index = self._getContourIndex(contour)<EOL><DEDENT>index = normalizers.normalizeIndex(index)<EOL>if index >= len(self):<EOL><INDENT>raise ValueError("<STR_LIT>" % index)<EOL><DEDENT>self._removeContour(index)<EOL>
Remove ``contour`` from the glyph. >>> glyph.removeContour(contour) ``contour`` may be a :ref:`BaseContour` or an :ref:`type-int` representing a contour index.
f10840:c0:m63
def _removeContour(self, index, **kwargs):
self.raiseNotImplementedError()<EOL>
index will be a valid index. Subclasses must override this method.
f10840:c0:m64
def clearContours(self):
self._clearContours()<EOL>
Clear all contours in the glyph. >>> glyph.clearContours()
f10840:c0:m65
def _clearContours(self):
for _ in range(len(self)):<EOL><INDENT>self.removeContour(-<NUM_LIT:1>)<EOL><DEDENT>
Subclasses may override this method.
f10840:c0:m66
def removeOverlap(self):
Perform a remove overlap operation on the contours. >>> glyph.removeOverlap() The behavior of this may vary across environments.
f10840:c0:m67
def _removeOverlap(self):
self.raiseNotImplementedError()<EOL>
Subclasses must implement this method.
f10840:c0:m68
def _get_components(self):
return tuple([self._getitem__components(i) for<EOL>i in range(self._len__components())])<EOL>
Subclasses may override this method.
f10840:c0:m70
def _lenComponents(self, **kwargs):
self.raiseNotImplementedError()<EOL>
This must return an integer indicating the number of components in the glyph. Subclasses must override this method.
f10840:c0:m72
def _getComponent(self, index, **kwargs):
self.raiseNotImplementedError()<EOL>
This must return a wrapped component. index will be a valid index. Subclasses must override this method.
f10840:c0:m74
def appendComponent(self, baseGlyph=None, offset=None, scale=None, component=None):
identifier = None<EOL>sxy = <NUM_LIT:0><EOL>syx = <NUM_LIT:0><EOL>if component is not None:<EOL><INDENT>component = normalizers.normalizeComponent(component)<EOL>if baseGlyph is None:<EOL><INDENT>baseGlyph = component.baseGlyph<EOL><DEDENT>sx, sxy, syx, sy, ox, oy = component.transformation<EOL>if offset is None:<EOL><INDENT>offset = (ox, oy)<EOL><DEDENT>if scale is None:<EOL><INDENT>scale = (sx, sy)<EOL><DEDENT>if baseGlyph is None:<EOL><INDENT>baseGlyph = component.baseGlyph<EOL><DEDENT>if component.identifier is not None:<EOL><INDENT>existing = set([c.identifier for c in self.components if c.identifier is not None])<EOL>if component.identifier not in existing:<EOL><INDENT>identifier = component.identifier<EOL><DEDENT><DEDENT><DEDENT>baseGlyph = normalizers.normalizeGlyphName(baseGlyph)<EOL>if self.name == baseGlyph:<EOL><INDENT>raise FontPartsError(("<STR_LIT>"))<EOL><DEDENT>if offset is None:<EOL><INDENT>offset = (<NUM_LIT:0>, <NUM_LIT:0>)<EOL><DEDENT>if scale is None:<EOL><INDENT>scale = (<NUM_LIT:1>, <NUM_LIT:1>)<EOL><DEDENT>offset = normalizers.normalizeTransformationOffset(offset)<EOL>scale = normalizers.normalizeTransformationScale(scale)<EOL>ox, oy = offset<EOL>sx, sy = scale<EOL>transformation = (sx, sxy, syx, sy, ox, oy)<EOL>identifier = normalizers.normalizeIdentifier(identifier)<EOL>return self._appendComponent(baseGlyph, transformation=transformation, identifier=identifier)<EOL>
Append a component to this glyph. >>> component = glyph.appendComponent("A") This will return a :class:`BaseComponent` object representing the new component in the glyph. ``offset`` indicates the x and y shift values that should be applied to the appended component. It must be a :ref:`type-coordinate` value or ``None``. If ``None`` is given, the offset will be ``(0, 0)``. >>> component = glyph.appendComponent("A", offset=(10, 20)) ``scale`` indicates the x and y scale values that should be applied to the appended component. It must be a :ref:`type-scale` value or ``None``. If ``None`` is given, the scale will be ``(1.0, 1.0)``. >>> component = glyph.appendComponent("A", scale=(1.0, 2.0)) ``component`` may be a :class:`BaseComponent` object from which attribute values will be copied. If ``baseGlyph``, ``offset`` or ``scale`` are specified as arguments, those values will be used instead of the values in the given component object.
f10840:c0:m76
def _appendComponent(self, baseGlyph, transformation=None, identifier=None, **kwargs):
pointPen = self.getPointPen()<EOL>pointPen.addComponent(baseGlyph, transformation=transformation, identifier=identifier)<EOL>return self.components[-<NUM_LIT:1>]<EOL>
baseGlyph will be a valid glyph name. The baseGlyph may or may not be in the layer. offset will be a valid offset (x, y). scale will be a valid scale (x, y). identifier will be a valid, nonconflicting identifier. This must return the new component. Subclasses may override this method.
f10840:c0:m77
def removeComponent(self, component):
if isinstance(component, int):<EOL><INDENT>index = component<EOL><DEDENT>else:<EOL><INDENT>index = self._getComponentIndex(component)<EOL><DEDENT>index = normalizers.normalizeIndex(index)<EOL>if index >= self._len__components():<EOL><INDENT>raise ValueError("<STR_LIT>" % index)<EOL><DEDENT>self._removeComponent(index)<EOL>
Remove ``component`` from the glyph. >>> glyph.removeComponent(component) ``component`` may be a :ref:`BaseComponent` or an :ref:`type-int` representing a component index.
f10840:c0:m78
def _removeComponent(self, index, **kwargs):
self.raiseNotImplementedError()<EOL>
index will be a valid index. Subclasses must override this method.
f10840:c0:m79
def clearComponents(self):
self._clearComponents()<EOL>
Clear all components in the glyph. >>> glyph.clearComponents()
f10840:c0:m80
def _clearComponents(self):
for _ in range(self._len__components()):<EOL><INDENT>self.removeComponent(-<NUM_LIT:1>)<EOL><DEDENT>
Subclasses may override this method.
f10840:c0:m81
def decompose(self):
self._decompose()<EOL>
Decompose all components in the glyph to contours. >>> glyph.decompose()
f10840:c0:m82
def _decompose(self):
for component in self.components:<EOL><INDENT>component.decompose()<EOL><DEDENT>
Subclasses may override this method.
f10840:c0:m83
def _get_anchors(self):
return tuple([self._getitem__anchors(i) for<EOL>i in range(self._len__anchors())])<EOL>
Subclasses may override this method.
f10840:c0:m85
def _lenAnchors(self, **kwargs):
self.raiseNotImplementedError()<EOL>
This must return an integer indicating the number of anchors in the glyph. Subclasses must override this method.
f10840:c0:m87
def _getAnchor(self, index, **kwargs):
self.raiseNotImplementedError()<EOL>
This must return a wrapped anchor. index will be a valid index. Subclasses must override this method.
f10840:c0:m89
def appendAnchor(self, name=None, position=None, color=None, anchor=None):
identifier = None<EOL>if anchor is not None:<EOL><INDENT>anchor = normalizers.normalizeAnchor(anchor)<EOL>if name is None:<EOL><INDENT>name = anchor.name<EOL><DEDENT>if position is None:<EOL><INDENT>position = anchor.position<EOL><DEDENT>if color is None:<EOL><INDENT>color = anchor.color<EOL><DEDENT>if anchor.identifier is not None:<EOL><INDENT>existing = set([a.identifier for a in self.anchors if a.identifier is not None])<EOL>if anchor.identifier not in existing:<EOL><INDENT>identifier = anchor.identifier<EOL><DEDENT><DEDENT><DEDENT>name = normalizers.normalizeAnchorName(name)<EOL>position = normalizers.normalizeCoordinateTuple(position)<EOL>if color is not None:<EOL><INDENT>color = normalizers.normalizeColor(color)<EOL><DEDENT>identifier = normalizers.normalizeIdentifier(identifier)<EOL>return self._appendAnchor(name, position=position, color=color, identifier=identifier)<EOL>
Append an anchor to this glyph. >>> anchor = glyph.appendAnchor("top", (10, 20)) This will return a :class:`BaseAnchor` object representing the new anchor in the glyph. ``name`` indicated the name to be assigned to the anchor. It must be a :ref:`type-string` or ``None``. ``position`` indicates the x and y location to be applied to the anchor. It must be a :ref:`type-coordinate` value. ``color`` indicates the color to be applied to the anchor. It must be a :ref:`type-color` or ``None``. >>> anchor = glyph.appendAnchor("top", (10, 20), color=(1, 0, 0, 1)) ``anchor`` may be a :class:`BaseAnchor` object from which attribute values will be copied. If ``name``, ``position`` or ``color`` are specified as arguments, those values will be used instead of the values in the given anchor object.
f10840:c0:m91
def _appendAnchor(self, name, position=None, color=None, identifier=None, **kwargs):
self.raiseNotImplementedError()<EOL>
name will be a valid anchor name. position will be a valid position (x, y). color will be None or a valid color. identifier will be a valid, nonconflicting identifier. This must return the new anchor. Subclasses may override this method.
f10840:c0:m92
def removeAnchor(self, anchor):
if isinstance(anchor, int):<EOL><INDENT>index = anchor<EOL><DEDENT>else:<EOL><INDENT>index = self._getAnchorIndex(anchor)<EOL><DEDENT>index = normalizers.normalizeIndex(index)<EOL>if index >= self._len__anchors():<EOL><INDENT>raise ValueError("<STR_LIT>" % index)<EOL><DEDENT>self._removeAnchor(index)<EOL>
Remove ``anchor`` from the glyph. >>> glyph.removeAnchor(anchor) ``anchor`` may be an :ref:`BaseAnchor` or an :ref:`type-int` representing an anchor index.
f10840:c0:m93
def _removeAnchor(self, index, **kwargs):
self.raiseNotImplementedError()<EOL>
index will be a valid index. Subclasses must override this method.
f10840:c0:m94
def clearAnchors(self):
self._clearAnchors()<EOL>
Clear all anchors in the glyph. >>> glyph.clearAnchors()
f10840:c0:m95
def _clearAnchors(self):
for _ in range(self._len__anchors()):<EOL><INDENT>self.removeAnchor(-<NUM_LIT:1>)<EOL><DEDENT>
Subclasses may override this method.
f10840:c0:m96
def _get_guidelines(self):
return tuple([self._getitem__guidelines(i) for<EOL>i in range(self._len__guidelines())])<EOL>
Subclasses may override this method.
f10840:c0:m98
def _lenGuidelines(self, **kwargs):
self.raiseNotImplementedError()<EOL>
This must return an integer indicating the number of guidelines in the glyph. Subclasses must override this method.
f10840:c0:m100
def _getGuideline(self, index, **kwargs):
self.raiseNotImplementedError()<EOL>
This must return a wrapped guideline. index will be a valid index. Subclasses must override this method.
f10840:c0:m102
def appendGuideline(self, position=None, angle=None, name=None, color=None, guideline=None):
identifier = None<EOL>if guideline is not None:<EOL><INDENT>guideline = normalizers.normalizeGuideline(guideline)<EOL>if position is None:<EOL><INDENT>position = guideline.position<EOL><DEDENT>if angle is None:<EOL><INDENT>angle = guideline.angle<EOL><DEDENT>if name is None:<EOL><INDENT>name = guideline.name<EOL><DEDENT>if color is None:<EOL><INDENT>color = guideline.color<EOL><DEDENT>if guideline.identifier is not None:<EOL><INDENT>existing = set([g.identifier for g in self.guidelines if g.identifier is not None])<EOL>if guideline.identifier not in existing:<EOL><INDENT>identifier = guideline.identifier<EOL><DEDENT><DEDENT><DEDENT>position = normalizers.normalizeCoordinateTuple(position)<EOL>angle = normalizers.normalizeRotationAngle(angle)<EOL>if name is not None:<EOL><INDENT>name = normalizers.normalizeGuidelineName(name)<EOL><DEDENT>if color is not None:<EOL><INDENT>color = normalizers.normalizeColor(color)<EOL><DEDENT>identifier = normalizers.normalizeIdentifier(identifier)<EOL>guideline = self._appendGuideline(position, angle, name=name, color=color, identifier=identifier)<EOL>guideline.glyph = self<EOL>return guideline<EOL>
Append a guideline to this glyph. >>> guideline = glyph.appendGuideline((100, 0), 90) This will return a :class:`BaseGuideline` object representing the new guideline in the glyph. ``position`` indicates the x and y location to be used as the center point of the anchor. It must be a :ref:`type-coordinate` value. ``angle`` indicates the angle of the guideline, in degrees. This must be a :ref:`type-int-float` between 0 and 360. ``name`` indicates an name to be assigned to the guideline. It must be a :ref:`type-string` or ``None``. >>> guideline = glyph.appendGuideline((100, 0), 90, name="left") ``color`` indicates the color to be applied to the guideline. It must be a :ref:`type-color` or ``None``. >>> guideline = glyph.appendGuideline((100, 0), 90, color=(1, 0, 0, 1)) ``guideline`` may be a :class:`BaseGuideline` object from which attribute values will be copied. If ``position``, ``angle``, ``name`` or ``color`` are specified as arguments, those values will be used instead of the values in the given guideline object.
f10840:c0:m104
def _appendGuideline(self, position, angle, name=None, color=None, identifier=None, **kwargs):
self.raiseNotImplementedError()<EOL>
position will be a valid position (x, y). angle will be a valid angle. name will be a valid guideline name or None. color will be a valid color or None . identifier will be a valid, nonconflicting identifier. This must return the new guideline. Subclasses may override this method.
f10840:c0:m105
def removeGuideline(self, guideline):
if isinstance(guideline, int):<EOL><INDENT>index = guideline<EOL><DEDENT>else:<EOL><INDENT>index = self._getGuidelineIndex(guideline)<EOL><DEDENT>index = normalizers.normalizeIndex(index)<EOL>if index >= self._len__guidelines():<EOL><INDENT>raise ValueError("<STR_LIT>" % index)<EOL><DEDENT>self._removeGuideline(index)<EOL>
Remove ``guideline`` from the glyph. >>> glyph.removeGuideline(guideline) ``guideline`` may be a :ref:`BaseGuideline` or an :ref:`type-int` representing an guideline index.
f10840:c0:m106
def _removeGuideline(self, index, **kwargs):
self.raiseNotImplementedError()<EOL>
index will be a valid index. Subclasses must override this method.
f10840:c0:m107
def clearGuidelines(self):
self._clearGuidelines()<EOL>
Clear all guidelines in the glyph. >>> glyph.clearGuidelines()
f10840:c0:m108
def _clearGuidelines(self):
for _ in range(self._len__guidelines()):<EOL><INDENT>self.removeGuideline(-<NUM_LIT:1>)<EOL><DEDENT>
Subclasses may override this method.
f10840:c0:m109
def round(self):
self._round()<EOL>
Round coordinates to the nearest integer. >>> glyph.round() This applies to the following: - width - height - contours - components - anchors - guidelines
f10840:c0:m110
def _round(self):
for contour in self.contours:<EOL><INDENT>contour.round()<EOL><DEDENT>for component in self.components:<EOL><INDENT>component.round()<EOL><DEDENT>for anchor in self.anchors:<EOL><INDENT>anchor.round()<EOL><DEDENT>for guideline in self.guidelines:<EOL><INDENT>guideline.round()<EOL><DEDENT>self.width = normalizers.normalizeRounding(self.width)<EOL>self.height = normalizers.normalizeRounding(self.height)<EOL>
Subclasses may override this method.
f10840:c0:m111
def correctDirection(self, trueType=False):
self._correctDirection(trueType=trueType)<EOL>
Correct the winding direction of the contours following the PostScript recommendations. >>> glyph.correctDirection() If ``trueType`` is ``True`` the TrueType recommendations will be followed.
f10840:c0:m112
def _correctDirection(self, trueType=False, **kwargs):
self.raiseNotImplementedError()<EOL>
Subclasses may override this method.
f10840:c0:m113
def autoContourOrder(self):
self._autoContourOrder()<EOL>
Automatically order the contours based on heuristics. >>> glyph.autoContourOrder() The results of this may vary across environments.
f10840:c0:m114
def _autoContourOrder(self, **kwargs):
self.raiseNotImplementedError()<EOL>
XXX This can be ported from RoboFab. XXX
f10840:c0:m115
def _transformBy(self, matrix, **kwargs):
for contour in self.contours:<EOL><INDENT>contour.transformBy(matrix)<EOL><DEDENT>for component in self.components:<EOL><INDENT>component.transformBy(matrix)<EOL><DEDENT>for anchor in self.anchors:<EOL><INDENT>anchor.transformBy(matrix)<EOL><DEDENT>for guideline in self.guidelines:<EOL><INDENT>guideline.transformBy(matrix)<EOL><DEDENT>
Subclasses may override this method.
f10840:c0:m116
def scaleBy(self, value, origin=None, width=False, height=False):
value = normalizers.normalizeTransformationScale(value)<EOL>if origin is None:<EOL><INDENT>origin = (<NUM_LIT:0>, <NUM_LIT:0>)<EOL><DEDENT>origin = normalizers.normalizeCoordinateTuple(origin)<EOL>if origin != (<NUM_LIT:0>, <NUM_LIT:0>) and (width or height):<EOL><INDENT>raise FontPartsError(("<STR_LIT>"<EOL>"<STR_LIT>"))<EOL><DEDENT>super(BaseGlyph, self).scaleBy(value, origin=origin)<EOL>sX, sY = value<EOL>if width:<EOL><INDENT>self._scaleWidthBy(sX)<EOL><DEDENT>if height:<EOL><INDENT>self._scaleHeightBy(sY)<EOL><DEDENT>
%s **width** indicates if the glyph's width should be scaled. **height** indicates if the glyph's height should be scaled. The origin must not be specified when scaling the width or height.
f10840:c0:m117
def _scaleWidthBy(self, value):
self.width *= value<EOL>
Subclasses may override this method.
f10840:c0:m118
def _scaleHeightBy(self, value):
self.height *= value<EOL>
Subclasses may override this method.
f10840:c0:m119
def toMathGlyph(self):
return self._toMathGlyph()<EOL>
Returns the glyph as an object that follows the `MathGlyph protocol <https://github.com/typesupply/fontMath>`_. >>> mg = glyph.toMathGlyph()
f10840:c0:m120
def _toMathGlyph(self):
import fontMath<EOL>mathGlyph = fontMath.MathGlyph(None)<EOL>pen = mathGlyph.getPointPen()<EOL>self.drawPoints(pen)<EOL>for anchor in self.anchors:<EOL><INDENT>d = dict(<EOL>x=anchor.x,<EOL>y=anchor.y,<EOL>name=anchor.name,<EOL>identifier=anchor.identifier,<EOL>color=anchor.color<EOL>)<EOL>mathGlyph.anchors.append(d)<EOL><DEDENT>for guideline in self.guidelines:<EOL><INDENT>d = dict(<EOL>x=guideline.x,<EOL>y=guideline.y,<EOL>angle=guideline.angle,<EOL>name=guideline.name,<EOL>identifier=guideline.identifier,<EOL>color=guideline.color<EOL>)<EOL>mathGlyph.guidelines.append(d)<EOL><DEDENT>image = self.image<EOL>mathGlyph.image = dict(<EOL>fileName=image.data,<EOL>transformation=image.transformation,<EOL>color=image.color<EOL>)<EOL>mathGlyph.lib = deepcopy(self.lib)<EOL>mathGlyph.name = self.name<EOL>mathGlyph.unicodes = self.unicodes<EOL>mathGlyph.width = self.width<EOL>mathGlyph.height = self.height<EOL>mathGlyph.note = self.note<EOL>return mathGlyph<EOL>
Subclasses may override this method.
f10840:c0:m121
def fromMathGlyph(self, mathGlyph):
return self._fromMathGlyph(mathGlyph, toThisGlyph=True)<EOL>
Replaces the contents of this glyph with the contents of ``mathGlyph``. >>> glyph.fromMathGlyph(mg) ``mathGlyph`` must be an object following the `MathGlyph protocol <https://github.com/typesupply/fontMath>`_.
f10840:c0:m122
def __mul__(self, factor):
mathGlyph = self._toMathGlyph()<EOL>result = mathGlyph * factor<EOL>copied = self._fromMathGlyph(result)<EOL>return copied<EOL>
Subclasses may override this method.
f10840:c0:m124
def __truediv__(self, factor):
mathGlyph = self._toMathGlyph()<EOL>result = mathGlyph / factor<EOL>copied = self._fromMathGlyph(result)<EOL>return copied<EOL>
Subclasses may override this method.
f10840:c0:m125
def __add__(self, other):
selfMathGlyph = self._toMathGlyph()<EOL>otherMathGlyph = other._toMathGlyph()<EOL>result = selfMathGlyph + otherMathGlyph<EOL>copied = self._fromMathGlyph(result)<EOL>return copied<EOL>
Subclasses may override this method.
f10840:c0:m126