signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
def __sub__(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:m127
def interpolate(self, factor, minGlyph, maxGlyph,<EOL>round=True, suppressError=True):
factor = normalizers.normalizeInterpolationFactor(factor)<EOL>if not isinstance(minGlyph, BaseGlyph):<EOL><INDENT>raise TypeError(("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>% (self.__class__.__name__,<EOL>minGlyph.__class__.__name__))<EOL><DEDENT>if not isinstance(maxGlyph, BaseGlyph):<EOL><INDENT>raise TypeError(("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>% (self.__class__.__name__,<EOL>maxGlyph.__class__.__name__))<EOL><DEDENT>round = normalizers.normalizeBoolean(round)<EOL>suppressError = normalizers.normalizeBoolean(suppressError)<EOL>self._interpolate(factor, minGlyph, maxGlyph,<EOL>round=round, suppressError=suppressError)<EOL>
Interpolate the contents of this glyph at location ``factor`` in a linear interpolation between ``minGlyph`` and ``maxGlyph``. >>> glyph.interpolate(0.5, otherGlyph1, otherGlyph2) ``factor`` may be a :ref:`type-int-float` or a tuple containing two :ref:`type-int-float` values representing x and y factors. >>> glyph.interpolate((0.5, 1.0), otherGlyph1, otherGlyph2) ``minGlyph`` must be a :class:`BaseGlyph` and will be located at 0.0 in the interpolation range. ``maxGlyph`` must be a :class:`BaseGlyph` and will be located at 1.0 in the interpolation range. If ``round`` is ``True``, the contents of the glyph will be rounded to integers after the interpolation is performed. >>> glyph.interpolate(0.5, otherGlyph1, otherGlyph2, round=True) This method assumes that ``minGlyph`` and ``maxGlyph`` are completely compatible with each other for interpolation. If not, any errors encountered will raise a :class:`FontPartsError`. If ``suppressError`` is ``True``, no exception will be raised and errors will be silently ignored.
f10840:c0:m128
def _interpolate(self, factor, minGlyph, maxGlyph,<EOL>round=True, suppressError=True):
minGlyph = minGlyph._toMathGlyph()<EOL>maxGlyph = maxGlyph._toMathGlyph()<EOL>try:<EOL><INDENT>result = interpolate(minGlyph, maxGlyph, factor)<EOL><DEDENT>except IndexError:<EOL><INDENT>result = None<EOL><DEDENT>if result is None and not suppressError:<EOL><INDENT>raise FontPartsError(("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>% (minGlyph.name, maxGlyph.name))<EOL><DEDENT>if result is not None:<EOL><INDENT>if round:<EOL><INDENT>result = result.round()<EOL><DEDENT>self._fromMathGlyph(result, toThisGlyph=True)<EOL><DEDENT>
Subclasses may override this method.
f10840:c0:m129
def isCompatible(self, other):
return super(BaseGlyph, self).isCompatible(other, BaseGlyph)<EOL>
Evaluate the interpolation compatibility of this glyph and ``other``. >>> compatible, report = self.isCompatible(otherGlyph) >>> compatible False This will return a :ref:`type-bool` indicating if this glyph is compatible with ``other`` and a :class:`GlyphCompatibilityReporter` containing a detailed report about compatibility errors.
f10840:c0:m131
def _isCompatible(self, other, reporter):
glyph1 = self<EOL>glyph2 = other<EOL>if len(self.contours) != len(glyph2.contours):<EOL><INDENT>reporter.fatal = True<EOL>reporter.contourCountDifference = True<EOL><DEDENT>for i in range(min(len(glyph1), len(glyph2))):<EOL><INDENT>contour1 = glyph1[i]<EOL>contour2 = glyph2[i]<EOL>self._checkPairs(contour1, contour2, reporter, reporter.contours)<EOL><DEDENT>if len(glyph1.components) != len(glyph2.components):<EOL><INDENT>reporter.fatal = True<EOL>reporter.componentCountDifference = True<EOL><DEDENT>component_diff = []<EOL>selfComponents = [component.baseGlyph for component in glyph1.components]<EOL>otherComponents = [component.baseGlyph for component in glyph2.components]<EOL>for index, (left, right) in enumerate(<EOL>zip_longest(selfComponents, otherComponents)<EOL>):<EOL><INDENT>if left != right:<EOL><INDENT>component_diff.append((index, left, right))<EOL><DEDENT><DEDENT>if component_diff:<EOL><INDENT>reporter.warning = True<EOL>reporter.componentDifferences = component_diff<EOL>if not reporter.componentCountDifference and set(selfComponents) == set(<EOL>otherComponents<EOL>):<EOL><INDENT>reporter.componentOrderDifference = True<EOL><DEDENT>selfComponents_counted_set = collections.Counter(selfComponents)<EOL>otherComponents_counted_set = collections.Counter(otherComponents)<EOL>missing_from_glyph1 = (<EOL>otherComponents_counted_set - selfComponents_counted_set<EOL>)<EOL>if missing_from_glyph1:<EOL><INDENT>reporter.fatal = True<EOL>reporter.componentsMissingFromGlyph1 = sorted(<EOL>missing_from_glyph1.elements()<EOL>)<EOL><DEDENT>missing_from_glyph2 = (<EOL>selfComponents_counted_set - otherComponents_counted_set<EOL>)<EOL>if missing_from_glyph2:<EOL><INDENT>reporter.fatal = True<EOL>reporter.componentsMissingFromGlyph2 = sorted(<EOL>missing_from_glyph2.elements()<EOL>)<EOL><DEDENT><DEDENT>if len(self.guidelines) != len(glyph2.guidelines):<EOL><INDENT>reporter.warning = True<EOL>reporter.guidelineCountDifference = True<EOL><DEDENT>selfGuidelines = []<EOL>otherGuidelines = []<EOL>for source, names in ((self, selfGuidelines),<EOL>(other, otherGuidelines)):<EOL><INDENT>for i, guideline in enumerate(source.guidelines):<EOL><INDENT>names.append((guideline.name, i))<EOL><DEDENT><DEDENT>guidelines1 = set(selfGuidelines)<EOL>guidelines2 = set(otherGuidelines)<EOL>if len(guidelines1.difference(guidelines2)) != <NUM_LIT:0>:<EOL><INDENT>reporter.warning = True<EOL>reporter.guidelinesMissingFromGlyph2 = list(<EOL>guidelines1.difference(guidelines2))<EOL><DEDENT>if len(guidelines2.difference(guidelines1)) != <NUM_LIT:0>:<EOL><INDENT>reporter.warning = True<EOL>reporter.guidelinesMissingFromGlyph1 = list(<EOL>guidelines2.difference(guidelines1))<EOL><DEDENT>if len(self.anchors) != len(glyph2.anchors):<EOL><INDENT>reporter.warning = True<EOL>reporter.anchorCountDifference = True<EOL><DEDENT>anchor_diff = []<EOL>selfAnchors = [anchor.name for anchor in glyph1.anchors]<EOL>otherAnchors = [anchor.name for anchor in glyph2.anchors]<EOL>for index, (left, right) in enumerate(zip_longest(selfAnchors, otherAnchors)):<EOL><INDENT>if left != right:<EOL><INDENT>anchor_diff.append((index, left, right))<EOL><DEDENT><DEDENT>if anchor_diff:<EOL><INDENT>reporter.warning = True<EOL>reporter.anchorDifferences = anchor_diff<EOL>if not reporter.anchorCountDifference and set(selfAnchors) == set(<EOL>otherAnchors<EOL>):<EOL><INDENT>reporter.anchorOrderDifference = True<EOL><DEDENT>selfAnchors_counted_set = collections.Counter(selfAnchors)<EOL>otherAnchors_counted_set = collections.Counter(otherAnchors)<EOL>missing_from_glyph1 = otherAnchors_counted_set - selfAnchors_counted_set<EOL>if missing_from_glyph1:<EOL><INDENT>reporter.anchorsMissingFromGlyph1 = sorted(<EOL>missing_from_glyph1.elements()<EOL>)<EOL><DEDENT>missing_from_glyph2 = selfAnchors_counted_set - otherAnchors_counted_set<EOL>if missing_from_glyph2:<EOL><INDENT>reporter.anchorsMissingFromGlyph2 = sorted(<EOL>missing_from_glyph2.elements()<EOL>)<EOL><DEDENT><DEDENT>
This is the environment implementation of :meth:`BaseGlyph.isCompatible`. Subclasses may override this method.
f10840:c0:m132
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 glyph. >>> glyph.pointInside((40, 65)) True ``point`` must be a :ref:`type-coordinate`.
f10840:c0:m133
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.
f10840:c0:m134
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.
f10840:c0:m136
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.
f10840:c0:m138
def getLayer(self, name):
name = normalizers.normalizeLayerName(name)<EOL>return self._getLayer(name)<EOL>
Get the :ref:`type-glyph-layer` with ``name`` in this glyph. >>> glyphLayer = glyph.getLayer("foreground")
f10840:c0:m140
def _getLayer(self, name, **kwargs):
for glyph in self.layers:<EOL><INDENT>if glyph.layer.name == name:<EOL><INDENT>return glyph<EOL><DEDENT><DEDENT>raise ValueError("<STR_LIT>"<EOL>% (name, self.name))<EOL>
name will be a string, but there may not be a layer with a name matching the string. If not, a ``ValueError`` must be raised. Subclasses may override this method.
f10840:c0:m141
def newLayer(self, name):
layerName = name<EOL>glyphName = self.name<EOL>layerName = normalizers.normalizeLayerName(layerName)<EOL>for glyph in self.layers:<EOL><INDENT>if glyph.layer.name == layerName:<EOL><INDENT>layer = glyph.layer<EOL>layer.removeGlyph(glyphName)<EOL>break<EOL><DEDENT><DEDENT>glyph = self._newLayer(name=layerName)<EOL>layer = self.font.getLayer(layerName)<EOL>return glyph<EOL>
Make a new layer with ``name`` in this glyph. >>> glyphLayer = glyph.newLayer("background") This will return the new :ref:`type-glyph-layer`. If the layer already exists in this glyph, it will be cleared.
f10840:c0:m142
def _newLayer(self, name, **kwargs):
self.raiseNotImplementedError()<EOL>
name will be a string representing a valid layer name. The name will have been tested to make sure that no layer in the glyph already has the name. This must returned the new glyph. Subclasses must override this method.
f10840:c0:m143
def removeLayer(self, layer):
if isinstance(layer, BaseGlyph):<EOL><INDENT>layer = layer.layer.name<EOL><DEDENT>layerName = layer<EOL>layerName = normalizers.normalizeLayerName(layerName)<EOL>if self._getLayer(layerName).layer.name == layerName:<EOL><INDENT>self._removeLayer(layerName)<EOL><DEDENT>
Remove ``layer`` from this glyph. >>> glyph.removeLayer("background") Layer can be a :ref:`type-glyph-layer` or a :ref:`type-string` representing a layer name.
f10840:c0:m144
def _removeLayer(self, name, **kwargs):
self.raiseNotImplementedError()<EOL>
name will be a valid layer name. It will represent an existing layer in the font. Subclasses may override this method.
f10840:c0:m145
def _get_image(self):
self.raiseNotImplementedError()<EOL>
Subclasses must override this method.
f10840:c0:m147
def addImage(self, path=None, data=None, scale=None,<EOL>position=None, color=None):
if path is not None and data is not None:<EOL><INDENT>raise FontPartsError("<STR_LIT>")<EOL><DEDENT>if scale is None:<EOL><INDENT>scale = (<NUM_LIT:1>, <NUM_LIT:1>)<EOL><DEDENT>if position is None:<EOL><INDENT>position = (<NUM_LIT:0>, <NUM_LIT:0>)<EOL><DEDENT>scale = normalizers.normalizeTransformationScale(scale)<EOL>position = normalizers.normalizeTransformationOffset(position)<EOL>if color is not None:<EOL><INDENT>color = normalizers.normalizeColor(color)<EOL><DEDENT>sx, sy = scale<EOL>ox, oy = position<EOL>transformation = (sx, <NUM_LIT:0>, <NUM_LIT:0>, sy, ox, oy)<EOL>if path is not None:<EOL><INDENT>if not os.path.exists(path):<EOL><INDENT>raise IOError("<STR_LIT>" % path)<EOL><DEDENT>f = open(path, "<STR_LIT:rb>")<EOL>data = f.read()<EOL>f.close()<EOL><DEDENT>self._addImage(data=data, transformation=transformation, color=color)<EOL>return self.image<EOL>
Set the image in the glyph. This will return the assigned :class:`BaseImage`. The image data can be defined via ``path`` to an image file: >>> image = glyph.addImage(path="/path/to/my/image.png") The image data can be defined with raw image data via ``data``. >>> image = glyph.addImage(data=someImageData) If ``path`` and ``data`` are both provided, a :class:`FontPartsError` will be raised. The supported image formats will vary across environments. Refer to :class:`BaseImage` for complete details. ``scale`` indicates the x and y scale values that should be applied to the image. It must be a :ref:`type-scale` value or ``None``. >>> image = glyph.addImage(path="/p/t/image.png", scale=(0.5, 1.0)) ``position`` indicates the x and y location of the lower left point of the image. >>> image = glyph.addImage(path="/p/t/image.png", position=(10, 20)) ``color`` indicates the color to be applied to the image. It must be a :ref:`type-color` or ``None``. >>> image = glyph.addImage(path="/p/t/image.png", color=(1, 0, 0, 0.5))
f10840:c0:m148
def _addImage(self, data, transformation=None, color=None):
self.raiseNotImplementedError()<EOL>
data will be raw, unnormalized image data. Each environment may have different possible formats, so this is unspecified. transformation will be a valid transformation matrix. color will be a color tuple or None. This must return an Image object. Assigning it to the glyph will be handled by the base class. Subclasses must override this method.
f10840:c0:m149
def clearImage(self):
if self.image is not None:<EOL><INDENT>self._clearImage()<EOL><DEDENT>
Remove the image from the glyph. >>> glyph.clearImage()
f10840:c0:m150
def _clearImage(self, **kwargs):
self.raiseNotImplementedError()<EOL>
Subclasses must override this method.
f10840:c0:m151
def _get_markColor(self):
self.raiseNotImplementedError()<EOL>
Return the mark color value as a color tuple or None. Subclasses must override this method.
f10840:c0:m154
def _set_markColor(self, value):
self.raiseNotImplementedError()<EOL>
value will be a color tuple or None. Subclasses must override this method.
f10840:c0:m155
def _get_note(self):
self.raiseNotImplementedError()<EOL>
Subclasses must override this method.
f10840:c0:m158
def _set_note(self, value):
self.raiseNotImplementedError()<EOL>
Subclasses must override this method.
f10840:c0:m159
def _get_lib(self):
self.raiseNotImplementedError()<EOL>
Subclasses must override this method.
f10840:c0:m161
def isEmpty(self):
if self.contours:<EOL><INDENT>return False<EOL><DEDENT>if self.components:<EOL><INDENT>return False<EOL><DEDENT>return True<EOL>
This will return :ref:`type-bool` indicating if there are contours and/or components in the glyph. >>> glyph.isEmpty() Note: This method only checks for the presence of contours and components. Other attributes (guidelines, anchors, a lib, etc.) will not affect what this method returns.
f10840:c0:m162
def loadFromGLIF(self, glifData):
self._loadFromGLIF(glifData)<EOL>
Reads ``glifData``, in `GLIF format <http://unifiedfontobject.org/versions/ufo3/glyphs/glif/>`_, into this glyph. >>> glyph.readGlyphFromString(xmlData)
f10840:c0:m163
def _loadFromGLIF(self, glifData):
self.raiseNotImplementedError()<EOL>
Subclasses must override this method.
f10840:c0:m164
def dumpToGLIF(self, glyphFormatVersion=<NUM_LIT:2>):
glyphFormatVersion = normalizers.normalizeGlyphFormatVersion(<EOL>glyphFormatVersion)<EOL>return self._dumpToGLIF(glyphFormatVersion)<EOL>
This will return the glyph's contents as a string in `GLIF format <http://unifiedfontobject.org/versions/ufo3/glyphs/glif/>`_. >>> xml = glyph.writeGlyphToString() ``glyphFormatVersion`` must be a :ref:`type-int` that defines the preferred GLIF format version.
f10840:c0:m165
def _dumpToGLIF(self, glyphFormatVersion):
self.raiseNotImplementedError()<EOL>
Subclasses must override this method.
f10840:c0:m166
def _get_selectedContours(self):
return self._getSelectedSubObjects(self.contours)<EOL>
Subclasses may override this method.
f10840:c0:m168
def _set_selectedContours(self, value):
return self._setSelectedSubObjects(self.contours, value)<EOL>
Subclasses may override this method.
f10840:c0:m170
def _get_selectedComponents(self):
return self._getSelectedSubObjects(self.components)<EOL>
Subclasses may override this method.
f10840:c0:m172
def _set_selectedComponents(self, value):
return self._setSelectedSubObjects(self.components, value)<EOL>
Subclasses may override this method.
f10840:c0:m174
def _get_selectedAnchors(self):
return self._getSelectedSubObjects(self.anchors)<EOL>
Subclasses may override this method.
f10840:c0:m176
def _set_selectedAnchors(self, value):
return self._setSelectedSubObjects(self.anchors, value)<EOL>
Subclasses may override this method.
f10840:c0:m178
def _get_selectedGuidelines(self):
return self._getSelectedSubObjects(self.guidelines)<EOL>
Subclasses may override this method.
f10840:c0:m180
def _set_selectedGuidelines(self, value):
return self._setSelectedSubObjects(self.guidelines, value)<EOL>
Subclasses may override this method.
f10840:c0:m182
def normalizeFileFormatVersion(value):
if not isinstance(value, int):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>return value<EOL>
Normalizes a font's file format version. * **value** must be a :ref:`type-int`. * Returned value will be a ``int``.
f10841:m0
def normalizeLayerOrder(value, font):
if not isinstance(value, (tuple, list)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>for v in value:<EOL><INDENT>normalizeLayerName(v)<EOL><DEDENT>fontLayers = [layer.name for layer in font.layers]<EOL>for name in value:<EOL><INDENT>if name not in fontLayers:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % name)<EOL><DEDENT><DEDENT>duplicates = [v for v, count in Counter(value).items() if count > <NUM_LIT:1>]<EOL>if len(duplicates) != <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % "<STR_LIT:U+002CU+0020>".join(duplicates))<EOL><DEDENT>return tuple([unicode(v) for v in value])<EOL>
Normalizes layer order. ** **value** must be a ``tuple`` or ``list``. * **value** items must normalize as layer names with :func:`normalizeLayerName`. * **value** must contain layers that exist in **font**. * **value** must not contain duplicate layers. * Returned ``tuple`` will be unencoded ``unicode`` strings for each layer name.
f10841:m1
def normalizeDefaultLayerName(value, font):
value = normalizeLayerName(value)<EOL>if value not in font.layerOrder:<EOL><INDENT>raise ValueError("<STR_LIT>" % value)<EOL><DEDENT>return unicode(value)<EOL>
Normalizes default layer name. * **value** must normalize as layer name with :func:`normalizeLayerName`. * **value** must be a layer in **font**. * Returned value will be an unencoded ``unicode`` string.
f10841:m2
def normalizeGlyphOrder(value):
if not isinstance(value, (tuple, list)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>for v in value:<EOL><INDENT>normalizeGlyphName(v)<EOL><DEDENT>duplicates = sorted(v for v, count in Counter(value).items() if count > <NUM_LIT:1>)<EOL>if len(duplicates) != <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % "<STR_LIT:U+002CU+0020>".join(duplicates))<EOL><DEDENT>return tuple([unicode(v) for v in value])<EOL>
Normalizes glyph order. ** **value** must be a ``tuple`` or ``list``. * **value** items must normalize as glyph names with :func:`normalizeGlyphName`. * **value** must not repeat glyph names. * Returned value will be a ``tuple`` of unencoded ``unicode`` strings.
f10841:m3
def normalizeKerningKey(value):
if not isinstance(value, (tuple, list)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if len(value) != <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % len(value))<EOL><DEDENT>for v in value:<EOL><INDENT>if not isinstance(v, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(v).__name__)<EOL><DEDENT>if len(v) < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>if value[<NUM_LIT:0>].startswith("<STR_LIT>") and not value[<NUM_LIT:0>].startswith(<EOL>"<STR_LIT>"):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if value[<NUM_LIT:1>].startswith("<STR_LIT>") and not value[<NUM_LIT:1>].startswith(<EOL>"<STR_LIT>"):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>return tuple([unicode(v) for v in value])<EOL>
Normalizes kerning key. * **value** must be a ``tuple`` or ``list``. * **value** must contain only two members. * **value** items must be :ref:`type-string`. * **value** items must be at least one character long. * Returned value will be a two member ``tuple`` of unencoded ``unicode`` strings.
f10841:m4
def normalizeKerningValue(value):
if not isinstance(value, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>return value<EOL>
Normalizes kerning value. * **value** must be an :ref:`type-int-float`. * Returned value is the same type as input value.
f10841:m5
def normalizeGroupKey(value):
if not isinstance(value, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if len(value) < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return unicode(value)<EOL>
Normalizes group key. * **value** must be a :ref:`type-string`. * **value** must be least one character long. * Returned value will be an unencoded ``unicode`` string.
f10841:m6
def normalizeGroupValue(value):
if not isinstance(value, (tuple, list)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>value = [normalizeGlyphName(v) for v in value]<EOL>return tuple([unicode(v) for v in value])<EOL>
Normalizes group value. * **value** must be a ``list``. * **value** items must normalize as glyph names with :func:`normalizeGlyphName`. * Returned value will be a ``tuple`` of unencoded ``unicode`` strings.
f10841:m7
def normalizeFeatureText(value):
if not isinstance(value, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>return unicode(value)<EOL>
Normalizes feature text. * **value** must be a :ref:`type-string`. * Returned value will be an unencoded ``unicode`` string.
f10841:m8
def normalizeLibKey(value):
if not isinstance(value, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if len(value) < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return unicode(value)<EOL>
Normalizes lib key. * **value** must be a :ref:`type-string`. * **value** must be at least one character long. * Returned value will be an unencoded ``unicode`` string.
f10841:m9
def normalizeLibValue(value):
if value is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if isinstance(value, (list, tuple)):<EOL><INDENT>for v in value:<EOL><INDENT>normalizeLibValue(v)<EOL><DEDENT><DEDENT>elif isinstance(value, dict):<EOL><INDENT>for k, v in value.items():<EOL><INDENT>normalizeLibKey(k)<EOL>normalizeLibValue(v)<EOL><DEDENT><DEDENT>elif isinstance(value, basestring):<EOL><INDENT>value = unicode(value)<EOL><DEDENT>return value<EOL>
Normalizes lib value. * **value** must not be ``None``. * Returned value is the same type as the input value.
f10841:m10
def normalizeLayer(value):
from fontParts.base.layer import BaseLayer<EOL>return normalizeInternalObjectType(value, BaseLayer, "<STR_LIT>")<EOL>
Normalizes layer. * **value** must be a instance of :class:`BaseLayer` * Returned value is the same type as the input value.
f10841:m11
def normalizeLayerName(value):
if not isinstance(value, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if len(value) < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return unicode(value)<EOL>
Normalizes layer name. * **value** must be a :ref:`type-string`. * **value** must be at least one character long. * Returned value will be an unencoded ``unicode`` string.
f10841:m12
def normalizeGlyph(value):
from fontParts.base.glyph import BaseGlyph<EOL>return normalizeInternalObjectType(value, BaseGlyph, "<STR_LIT>")<EOL>
Normalizes glyph. * **value** must be a instance of :class:`BaseGlyph` * Returned value is the same type as the input value.
f10841:m13
def normalizeGlyphName(value):
if not isinstance(value, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if len(value) < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return unicode(value)<EOL>
Normalizes glyph name. * **value** must be a :ref:`type-string`. * **value** must be at least one character long. * Returned value will be an unencoded ``unicode`` string.
f10841:m14
def normalizeGlyphUnicodes(value):
if not isinstance(value, (tuple, list)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>values = [normalizeGlyphUnicode(v) for v in value]<EOL>duplicates = [v for v, count in Counter(value).items() if count > <NUM_LIT:1>]<EOL>if len(duplicates) != <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return tuple(values)<EOL>
Normalizes glyph unicodes. * **value** must be a ``list``. * **value** items must normalize as glyph unicodes with :func:`normalizeGlyphUnicode`. * **value** must not repeat unicode values. * Returned value will be a ``tuple`` of ints.
f10841:m15
def normalizeGlyphUnicode(value):
if not isinstance(value, (int, basestring)) or isinstance(value, bool):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if isinstance(value, basestring):<EOL><INDENT>try:<EOL><INDENT>value = int(value, <NUM_LIT:16>)<EOL><DEDENT>except ValueError:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>if value < <NUM_LIT:0> or value > <NUM_LIT>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return value<EOL>
Normalizes glyph unicode. * **value** must be an int or hex (represented as a string). * **value** must be in a unicode range. * Returned value will be an ``int``.
f10841:m16
def normalizeGlyphWidth(value):
if not isinstance(value, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>return value<EOL>
Normalizes glyph width. * **value** must be a :ref:`type-int-float`. * Returned value is the same type as the input value.
f10841:m17
def normalizeGlyphLeftMargin(value):
if not isinstance(value, (int, float)) and value is not None:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>" % type(value).__name__)<EOL><DEDENT>return value<EOL>
Normalizes glyph left margin. * **value** must be a :ref:`type-int-float` or `None`. * Returned value is the same type as the input value.
f10841:m18
def normalizeGlyphRightMargin(value):
if not isinstance(value, (int, float)) and value is not None:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>" % type(value).__name__)<EOL><DEDENT>return value<EOL>
Normalizes glyph right margin. * **value** must be a :ref:`type-int-float` or `None`. * Returned value is the same type as the input value.
f10841:m19
def normalizeGlyphHeight(value):
if not isinstance(value, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>" % type(value).__name__)<EOL><DEDENT>return value<EOL>
Normalizes glyph height. * **value** must be a :ref:`type-int-float`. * Returned value is the same type as the input value.
f10841:m20
def normalizeGlyphBottomMargin(value):
if not isinstance(value, (int, float)) and value is not None:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>return value<EOL>
Normalizes glyph bottom margin. * **value** must be a :ref:`type-int-float` or `None`. * Returned value is the same type as the input value.
f10841:m21
def normalizeGlyphTopMargin(value):
if not isinstance(value, (int, float)) and value is not None:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>" % type(value).__name__)<EOL><DEDENT>return value<EOL>
Normalizes glyph top margin. * **value** must be a :ref:`type-int-float` or `None`. * Returned value is the same type as the input value.
f10841:m22
def normalizeGlyphFormatVersion(value):
if not isinstance(value, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>value = int(value)<EOL>if value not in (<NUM_LIT:1>, <NUM_LIT:2>):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>% value)<EOL><DEDENT>return value<EOL>
Normalizes glyph format version for saving to XML string. * **value** must be a :ref:`type-int-float` of either 1 or 2. * Returned value will be an int.
f10841:m23
def normalizeContour(value):
from fontParts.base.contour import BaseContour<EOL>return normalizeInternalObjectType(value, BaseContour, "<STR_LIT>")<EOL>
Normalizes contour. * **value** must be a instance of :class:`BaseContour` * Returned value is the same type as the input value.
f10841:m24
def normalizePointType(value):
allowedTypes = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>if not isinstance(value, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if value not in allowedTypes:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>% ("<STR_LIT>".join(allowedTypes), value))<EOL><DEDENT>return unicode(value)<EOL>
Normalizes point type. * **value** must be an string. * **value** must be one of the following: +----------+ | move | +----------+ | line | +----------+ | offcurve | +----------+ | curve | +----------+ | qcurve | +----------+ * Returned value will be an unencoded ``unicode`` string.
f10841:m25
def normalizePointName(value):
if not isinstance(value, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if len(value) < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return unicode(value)<EOL>
Normalizes point name. * **value** must be a :ref:`type-string`. * **value** must be at least one character long. * Returned value will be an unencoded ``unicode`` string.
f10841:m26
def normalizePoint(value):
from fontParts.base.point import BasePoint<EOL>return normalizeInternalObjectType(value, BasePoint, "<STR_LIT>")<EOL>
Normalizes point. * **value** must be a instance of :class:`BasePoint` * Returned value is the same type as the input value.
f10841:m27
def normalizeSegment(value):
from fontParts.base.segment import BaseSegment<EOL>return normalizeInternalObjectType(value, BaseSegment, "<STR_LIT>")<EOL>
Normalizes segment. * **value** must be a instance of :class:`BaseSegment` * Returned value is the same type as the input value.
f10841:m28
def normalizeSegmentType(value):
allowedTypes = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>if not isinstance(value, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if value not in allowedTypes:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>% ("<STR_LIT>".join(allowedTypes), value))<EOL><DEDENT>return unicode(value)<EOL>
Normalizes segment type. * **value** must be a :ref:`type-string`. * **value** must be one of the following: +--------+ | move | +--------+ | line | +--------+ | curve | +--------+ | qcurve | +--------+ * Returned value will be an unencoded ``unicode`` string.
f10841:m29
def normalizeBPoint(value):
from fontParts.base.bPoint import BaseBPoint<EOL>return normalizeInternalObjectType(value, BaseBPoint, "<STR_LIT>")<EOL>
Normalizes bPoint. * **value** must be a instance of :class:`BaseBPoint` * Returned value is the same type as the input value.
f10841:m30
def normalizeBPointType(value):
allowedTypes = ['<STR_LIT>', '<STR_LIT>']<EOL>if not isinstance(value, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if value not in allowedTypes:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>% value)<EOL><DEDENT>return unicode(value)<EOL>
Normalizes bPoint type. * **value** must be an string. * **value** must be one of the following: +--------+ | corner | +--------+ | curve | +--------+ * Returned value will be an unencoded ``unicode`` string.
f10841:m31
def normalizeComponent(value):
from fontParts.base.component import BaseComponent<EOL>return normalizeInternalObjectType(value, BaseComponent, "<STR_LIT>")<EOL>
Normalizes component. * **value** must be a instance of :class:`BaseComponent` * Returned value is the same type as the input value.
f10841:m32
def normalizeComponentScale(value):
if not isinstance(value, (list, tuple)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>" % type(value).__name__)<EOL><DEDENT>else:<EOL><INDENT>if not len(value) == <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % len(value))<EOL><DEDENT>for v in value:<EOL><INDENT>if not isinstance(v, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT><DEDENT>value = tuple([float(v) for v in value])<EOL><DEDENT>return value<EOL>
Normalizes component scale. * **value** must be a `tuple`` or ``list``. * **value** must have exactly two items. These items must be instances of :ref:`type-int-float`. * Returned value is a ``tuple`` of two ``float``\s.
f10841:m33
def normalizeAnchor(value):
from fontParts.base.anchor import BaseAnchor<EOL>return normalizeInternalObjectType(value, BaseAnchor, "<STR_LIT>")<EOL>
Normalizes anchor. * **value** must be a instance of :class:`BaseAnchor` * Returned value is the same type as the input value.
f10841:m34
def normalizeAnchorName(value):
if value is None:<EOL><INDENT>return None<EOL><DEDENT>if not isinstance(value, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if len(value) < <NUM_LIT:1>:<EOL><INDENT>raise ValueError(("<STR_LIT>"<EOL>"<STR_LIT>"))<EOL><DEDENT>return unicode(value)<EOL>
Normalizes anchor name. * **value** must be a :ref:`type-string` or ``None``. * **value** must be at least one character long if :ref:`type-string`. * Returned value will be an unencoded ``unicode`` string or ``None``.
f10841:m35
def normalizeGuideline(value):
from fontParts.base.guideline import BaseGuideline<EOL>return normalizeInternalObjectType(value, BaseGuideline, "<STR_LIT>")<EOL>
Normalizes guideline. * **value** must be a instance of :class:`BaseGuideline` * Returned value is the same type as the input value.
f10841:m36
def normalizeGuidelineName(value):
if not isinstance(value, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if len(value) < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>return unicode(value)<EOL>
Normalizes guideline name. * **value** must be a :ref:`type-string`. * **value** must be at least one character long. * Returned value will be an unencoded ``unicode`` string.
f10841:m37
def normalizeInternalObjectType(value, cls, name):
if not isinstance(value, cls):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% (name, name, type(value).__name__))<EOL><DEDENT>return value<EOL>
Normalizes an internal object type. * **value** must be a instance of **cls**. * Returned value is the same type as the input value.
f10841:m38
def normalizeBoolean(value):
if isinstance(value, int) and value in (<NUM_LIT:0>, <NUM_LIT:1>):<EOL><INDENT>value = bool(value)<EOL><DEDENT>if not isinstance(value, bool):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>% value)<EOL><DEDENT>return value<EOL>
Normalizes a boolean. * **value** must be an ``int`` with value of 0 or 1, or a ``bool``. * Returned value will be a boolean.
f10841:m39
def normalizeIndex(value):
if value is not None:<EOL><INDENT>if not isinstance(value, int):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT><DEDENT>return value<EOL>
Normalizes index. * **value** must be an ``int`` or ``None``. * Returned value is the same type as the input value.
f10841:m40
def normalizeIdentifier(value):
if value is None:<EOL><INDENT>return value<EOL><DEDENT>if not isinstance(value, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if len(value) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if len(value) > <NUM_LIT:100>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % len(value))<EOL><DEDENT>for c in value:<EOL><INDENT>v = ord(c)<EOL>if v < <NUM_LIT> or v > <NUM_LIT>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% value)<EOL><DEDENT><DEDENT>return unicode(value)<EOL>
Normalizes identifier. * **value** must be an :ref:`type-string` or `None`. * **value** must not be longer than 100 characters. * **value** must not contain a character out the range of 0x20 - 0x7E. * Returned value is an unencoded ``unicode`` string.
f10841:m41
def normalizeX(value):
if not isinstance(value, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>return value<EOL>
Normalizes x coordinate. * **value** must be an :ref:`type-int-float`. * Returned value is the same type as the input value.
f10841:m42
def normalizeY(value):
if not isinstance(value, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>return value<EOL>
Normalizes y coordinate. * **value** must be an :ref:`type-int-float`. * Returned value is the same type as the input value.
f10841:m43
def normalizeCoordinateTuple(value):
if not isinstance(value, (tuple, list)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if len(value) != <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % len(value))<EOL><DEDENT>x, y = value<EOL>x = normalizeX(x)<EOL>y = normalizeY(y)<EOL>return (x, y)<EOL>
Normalizes coordinate tuple. * **value** must be a ``tuple`` or ``list``. * **value** must have exactly two items. * **value** items must be an :ref:`type-int-float`. * Returned value is a ``tuple`` of two values of the same type as the input values.
f10841:m44
def normalizeBoundingBox(value):
if not isinstance(value, (tuple, list)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if len(value) != <NUM_LIT:4>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % len(value))<EOL><DEDENT>for v in value:<EOL><INDENT>if not isinstance(v, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT><DEDENT>if value[<NUM_LIT:0>] > value[<NUM_LIT:2>]:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if value[<NUM_LIT:1>] > value[<NUM_LIT:3>]:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>return tuple([float(v) for v in value])<EOL>
Normalizes bounding box. * **value** must be an ``tuple`` or ``list``. * **value** must have exactly four items. * **value** items must be :ref:`type-int-float`. * xMin and yMin must be less than or equal to the corresponding xMax, yMax. * Returned value will be a tuple of four ``float``.
f10841:m45
def normalizeArea(value):
if not isinstance(value, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>" % type(value).__name__)<EOL><DEDENT>if value < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % repr(value))<EOL><DEDENT>return float(value)<EOL>
Normalizes area. * **value** must be a positive :ref:`type-int-float`.
f10841:m46
def normalizeRotationAngle(value):
if not isinstance(value, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if abs(value) > <NUM_LIT>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if value < <NUM_LIT:0>:<EOL><INDENT>value = value + <NUM_LIT><EOL><DEDENT>return float(value)<EOL>
Normalizes an angle. * Value must be a :ref:`type-int-float`. * Value must be between -360 and 360. * If the value is negative, it is normalized by adding it to 360 * Returned value is a ``float`` between 0 and 360.
f10841:m47
def normalizeColor(value):
from fontParts.base.color import Color<EOL>if not isinstance(value, (tuple, list, Color)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>if not len(value) == <NUM_LIT:4>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>% len(value))<EOL><DEDENT>for component, v in zip("<STR_LIT>", value):<EOL><INDENT>if not isinstance(v, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>" % (component, v))<EOL><DEDENT>if v < <NUM_LIT:0> or v > <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % (component, v))<EOL><DEDENT><DEDENT>return tuple([float(v) for v in value])<EOL>
Normalizes :ref:`type-color`. * **value** must be an ``tuple`` or ``list``. * **value** must have exactly four items. * **value** color components must be between 0 and 1. * Returned value is a ``tuple`` containing four ``float`` values.
f10841:m48
def normalizeGlyphNote(value):
if not isinstance(value, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>return unicode(value)<EOL>
Normalizes Glyph Note. * **value** must be a :ref:`type-string`. * Returned value is an unencoded ``unicode`` string
f10841:m49
def normalizeFilePath(value):
if not isinstance(value, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>return unicode(value)<EOL>
Normalizes file path. * **value** must be a :ref:`type-string`. * Returned value is an unencoded ``unicode`` string
f10841:m50
def normalizeInterpolationFactor(value):
if not isinstance(value, (int, float, list, tuple)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>" % type(value).__name__)<EOL><DEDENT>if isinstance(value, (int, float)):<EOL><INDENT>value = (float(value), float(value))<EOL><DEDENT>else:<EOL><INDENT>if not len(value) == <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % len(value))<EOL><DEDENT>for v in value:<EOL><INDENT>if not isinstance(v, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT><DEDENT>value = tuple([float(v) for v in value])<EOL><DEDENT>return value<EOL>
Normalizes interpolation factor. * **value** must be an :ref:`type-int-float`, ``tuple`` or ``list``. * If **value** is a ``tuple`` or ``list``, it must have exactly two items. These items must be instances of :ref:`type-int-float`. * Returned value is a ``tuple`` of two ``float``.
f10841:m51
def normalizeTransformationMatrix(value):
if not isinstance(value, (tuple, list)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>" % type(value).__name__)<EOL><DEDENT>if not len(value) == <NUM_LIT:6>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % len(value))<EOL><DEDENT>for v in value:<EOL><INDENT>if not isinstance(v, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% type(v).__name__)<EOL><DEDENT><DEDENT>return tuple([float(v) for v in value])<EOL>
Normalizes transformation matrix. * **value** must be an ``tuple`` or ``list``. * **value** must have exactly six items. Each of these items must be an instance of :ref:`type-int-float`. * Returned value is a ``tuple`` of six ``float``.
f10841:m52
def normalizeTransformationOffset(value):
return normalizeCoordinateTuple(value)<EOL>
Normalizes transformation offset. * **value** must be an ``tuple``. * **value** must have exactly two items. Each item must be an instance of :ref:`type-int-float`. * Returned value is a ``tuple`` of two ``float``.
f10841:m53
def normalizeTransformationSkewAngle(value):
if not isinstance(value, (int, float, list, tuple)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>" % type(value).__name__)<EOL><DEDENT>if isinstance(value, (int, float)):<EOL><INDENT>value = (float(value), <NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>if not len(value) == <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % len(value))<EOL><DEDENT>for v in value:<EOL><INDENT>if not isinstance(v, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT><DEDENT>value = tuple([float(v) for v in value])<EOL><DEDENT>for v in value:<EOL><INDENT>if abs(v) > <NUM_LIT>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>return tuple([float(v + <NUM_LIT>) if v < <NUM_LIT:0> else float(v) for v in value])<EOL>
Normalizes transformation skew angle. * **value** must be an :ref:`type-int-float`, ``tuple`` or ``list``. * If **value** is a ``tuple`` or ``list``, it must have exactly two items. These items must be instances of :ref:`type-int-float`. * **value** items must be between -360 and 360. * If the value is negative, it is normalized by adding it to 360 * Returned value is a ``tuple`` of two ``float`` between 0 and 360.
f10841:m54
def normalizeTransformationScale(value):
if not isinstance(value, (int, float, list, tuple)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>" % type(value).__name__)<EOL><DEDENT>if isinstance(value, (int, float)):<EOL><INDENT>value = (float(value), float(value))<EOL><DEDENT>else:<EOL><INDENT>if not len(value) == <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % len(value))<EOL><DEDENT>for v in value:<EOL><INDENT>if not isinstance(v, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT><DEDENT>value = tuple([float(v) for v in value])<EOL><DEDENT>return value<EOL>
Normalizes transformation scale. * **value** must be an :ref:`type-int-float`, ``tuple`` or ``list``. * If **value** is a ``tuple`` or ``list``, it must have exactly two items. These items must be instances of :ref:`type-int-float`. * Returned value is a ``tuple`` of two ``float``\s.
f10841:m55
def normalizeRounding(value):
if not isinstance(value, (int, float)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% type(value).__name__)<EOL><DEDENT>return round3(value)<EOL>
Normalizes rounding. Python 2 and Python 3 handing the rounding of halves (0.5, 1.5, etc) differently. This normalizes rounding to be the same (Python 3 style) in both environments. * **value** must be an :ref:`type-int-float` * Returned value is a ``int``
f10841:m56
def _get_transformation(self):
self.raiseNotImplementedError()<EOL>
Subclasses must override this method.
f10842:c0:m8
def _set_transformation(self, value):
self.raiseNotImplementedError()<EOL>
Subclasses must override this method.
f10842:c0:m9
def _get_offset(self):
sx, sxy, syx, sy, ox, oy = self.transformation<EOL>return (ox, oy)<EOL>
Subclasses may override this method.
f10842:c0:m12
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.
f10842:c0:m13
def _get_scale(self):
sx, sxy, syx, sy, ox, oy = self.transformation<EOL>return (sx, sy)<EOL>
Subclasses may override this method.
f10842:c0:m16