signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def _drawPoints(self, pen, **kwargs): | <EOL>try:<EOL><INDENT>pen.addComponent(self.baseGlyph, self.transformation,<EOL>identifier=self.identifier, **kwargs)<EOL><DEDENT>except TypeError:<EOL><INDENT>pen.addComponent(self.baseGlyph, self.transformation, **kwargs)<EOL><DEDENT> | Subclasses may override this method. | f10851:c0:m28 |
def _transformBy(self, matrix, **kwargs): | t = transform.Transform(*matrix)<EOL>transformation = t.transform(self.transformation)<EOL>self.transformation = tuple(transformation)<EOL> | Subclasses may override this method. | f10851:c0:m29 |
def round(self): | self._round()<EOL> | Round offset coordinates. | f10851:c0:m30 |
def _round(self): | x, y = self.offset<EOL>x = normalizers.normalizeRounding(x)<EOL>y = normalizers.normalizeRounding(y)<EOL>self.offset = (x, y)<EOL> | Subclasses may override this method. | f10851:c0:m31 |
def decompose(self): | glyph = self.glyph<EOL>if glyph is None:<EOL><INDENT>raise FontPartsError("<STR_LIT>")<EOL><DEDENT>self._decompose()<EOL> | Decompose the component. | f10851:c0:m32 |
def _decompose(self): | self.raiseNotImplementedError()<EOL> | Subclasses must override this method. | f10851:c0:m33 |
def isCompatible(self, other): | return super(BaseComponent, self).isCompatible(other, BaseComponent)<EOL> | Evaluate interpolation compatibility with **other**. ::
>>> compatible, report = self.isCompatible(otherComponent)
>>> compatible
True
>>> compatible
[Warning] Component: "A" + "B"
[Warning] Component: "A" has name A | "B" has name B
This will return a ``bool`` indicating if the component is
c... | f10851:c0:m34 |
def _isCompatible(self, other, reporter): | component1 = self<EOL>component2 = other<EOL>if component1.baseName != component2.baseName:<EOL><INDENT>reporter.baseDifference = True<EOL>reporter.warning = True<EOL><DEDENT> | This is the environment implementation of
:meth:`BaseComponent.isCompatible`.
Subclasses may override this method. | f10851:c0:m35 |
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 component.
point must be an (x, y) tuple. | f10851:c0:m36 |
def _pointInside(self, point): | from fontTools.pens.pointInsidePen import PointInsidePen<EOL>pen = PointInsidePen(glyphSet=self.layer, testPoint=point, evenOdd=False)<EOL>self.draw(pen)<EOL>return pen.getResult()<EOL> | Subclasses may override this method. | f10851:c0:m37 |
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. | f10851:c0:m39 |
def scaleBy(self, factor): | factor = normalizers.normalizeTransformationScale(factor)<EOL>self._scale(factor)<EOL> | Scales all kerning values by **factor**. **factor** will be an
:ref:`type-int-float`, ``tuple`` or ``list``. The first value of the
**factor** will be used to scale the kerning values.
>>> myKerning.scaleBy(2)
>>> myKerning.scaleBy((2,3)) | f10853:c0:m3 |
def _scale(self, factor): | factor = factor[<NUM_LIT:0>]<EOL>for k, v in self.items():<EOL><INDENT>v *= factor<EOL>self[k] = v<EOL><DEDENT> | This is the environment implementation of :meth:`BaseKerning.scaleBy`.
**factor** will be a ``tuple``.
Subclasses may override this method. | f10853:c0:m4 |
def round(self, multiple=<NUM_LIT:1>): | if not isinstance(multiple, int):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% multiple.__class__.__name__)<EOL><DEDENT>self._round(multiple)<EOL> | Rounds the kerning values to increments of **multiple**,
which will be an ``int``.
The default behavior is to round to increments of 1. | f10853:c0:m5 |
def _round(self, multiple=<NUM_LIT:1>): | for pair, value in self.items():<EOL><INDENT>value = int(normalizers.normalizeRounding(<EOL>value / float(multiple))) * multiple<EOL>self[pair] = value<EOL><DEDENT> | This is the environment implementation of
:meth:`BaseKerning.round`. **multiple** will be an ``int``.
Subclasses may override this method. | f10853:c0:m6 |
def interpolate(self, factor, minKerning, maxKerning, round=True, suppressError=True): | factor = normalizers.normalizeInterpolationFactor(factor)<EOL>if not isinstance(minKerning, BaseKerning):<EOL><INDENT>raise TypeError(("<STR_LIT>"<EOL>"<STR_LIT>") % (<EOL>self.__class__.__name__, minKerning.__class__.__name__))<EOL><DEDENT>if not isinstance(maxKerning, BaseKerning):<EOL><INDENT>raise TypeError(("<STR_... | Interpolates all pairs between two :class:`BaseKerning` objects:
**minKerning** and **maxKerning**. The interpolation occurs on a
0 to 1.0 range where **minKerning** is located at 0 and
**maxKerning** is located at 1.0. The kerning data is replaced by
the interpolated kerning.
* **factor** is the interpolation value.... | f10853:c0:m7 |
def _interpolate(self, factor, minKerning, maxKerning,<EOL>round=True, suppressError=True): | import fontMath<EOL>kerningGroupCompatibility = self._testKerningGroupCompatibility(<EOL>minKerning,<EOL>maxKerning,<EOL>suppressError=suppressError<EOL>)<EOL>if not kerningGroupCompatibility:<EOL><INDENT>self.clear()<EOL><DEDENT>else:<EOL><INDENT>minKerning = fontMath.MathKerning(<EOL>kerning=minKerning, groups=minKer... | This is the environment implementation of :meth:`BaseKerning.interpolate`.
* **factor** will be an :ref:`type-int-float`, ``tuple`` or ``list``.
* **minKerning** will be a :class:`BaseKerning` object.
* **maxKerning** will be a :class:`BaseKerning` object.
* **round** will be a ``bool`` indicating if the interpolated ... | f10853:c0:m8 |
def remove(self, pair): | del self[pair]<EOL> | Removes a pair from the Kerning. **pair** will
be a ``tuple`` of two :ref:`type-string`\s.
This is a backwards compatibility method. | f10853:c0:m10 |
def asDict(self, returnIntegers=True): | d = {}<EOL>for k, v in self.items():<EOL><INDENT>d[k] = v if not returnIntegers else normalizers.normalizeRounding(v)<EOL><DEDENT>return d<EOL> | Return the Kerning as a ``dict``.
This is a backwards compatibility method. | f10853:c0:m11 |
def __contains__(self, pair): | return super(BaseKerning, self).__contains__(pair)<EOL> | Tests to see if a pair is in the Kerning.
**pair** will be a ``tuple`` of two :ref:`type-string`\s.
This returns a ``bool`` indicating if the **pair**
is in the Kerning. ::
>>> ("A", "V") in font.kerning
True | f10853:c0:m12 |
def __delitem__(self, pair): | super(BaseKerning, self).__delitem__(pair)<EOL> | Removes **pair** from the Kerning. **pair** is a ``tuple`` of two
:ref:`type-string`\s.::
>>> del font.kerning[("A","V")] | f10853:c0:m13 |
def __getitem__(self, pair): | return super(BaseKerning, self).__getitem__(pair)<EOL> | Returns the kerning value of the pair. **pair** is a ``tuple`` of
two :ref:`type-string`\s.
The returned value will be a :ref:`type-int-float`.::
>>> font.kerning[("A", "V")]
-15
It is important to understand that any changes to the returned value
will not be reflected in the Kerning object. If one wants to ... | f10853:c0:m14 |
def __iter__(self): | return super(BaseKerning, self).__iter__()<EOL> | Iterates through the Kerning, giving the pair for each iteration. The order that
the Kerning will iterate though is not fixed nor is it ordered.::
>>> for pair in font.kerning:
>>> print pair
("A", "Y")
("A", "V")
("A", "W") | f10853:c0:m15 |
def __len__(self): | return super(BaseKerning, self).__len__()<EOL> | Returns the number of pairs in Kerning as an ``int``.::
>>> len(font.kerning)
5 | f10853:c0:m16 |
def __setitem__(self, pair, value): | super(BaseKerning, self).__setitem__(pair, value)<EOL> | Sets the **pair** to the list of **value**. **pair** is the
pair as a ``tuple`` of two :ref:`type-string`\s and **value**
is a :ref:`type-int-float`.
>>> font.kerning[("A", "V")] = -20
>>> font.kerning[("A", "W")] = -10.5 | f10853:c0:m17 |
def clear(self): | super(BaseKerning, self).clear()<EOL> | Removes all information from Kerning,
resetting the Kerning to an empty dictionary. ::
>>> font.kerning.clear() | f10853:c0:m18 |
def get(self, pair, default=None): | return super(BaseKerning, self).get(pair, default)<EOL> | Returns the value for the kerning pair.
**pair** is a ``tuple`` of two :ref:`type-string`\s, and the returned
values will either be :ref:`type-int-float` or ``None``
if no pair was found. ::
>>> font.kerning[("A", "V")]
-25
It is important to understand that any changes to the returned value
will not be refle... | f10853:c0:m19 |
def find(self, pair, default=None): | pair = normalizers.normalizeKerningKey(pair)<EOL>value = self._find(pair, default)<EOL>if value != default:<EOL><INDENT>value = normalizers.normalizeKerningValue(value)<EOL><DEDENT>return value<EOL> | Returns the value for the kerning pair.
**pair** is a ``tuple`` of two :ref:`type-string`\s, and the returned
values will either be :ref:`type-int-float` or ``None``
if no pair was found. ::
>>> font.kerning[("A", "V")]
-25 | f10853:c0:m20 |
def _find(self, pair, default=None): | from fontTools.ufoLib.kerning import lookupKerningValue<EOL>font = self.font<EOL>groups = font.groups<EOL>return lookupKerningValue(pair, self, groups, fallback=default)<EOL> | This is the environment implementation of
:attr:`BaseKerning.find`. This must return an
:ref:`type-int-float` or `default`. | f10853:c0:m21 |
def items(self): | return super(BaseKerning, self).items()<EOL> | Returns a list of ``tuple``\s of each pair and value. Pairs are a
``tuple`` of two :ref:`type-string`\s and values are :ref:`type-int-float`.
The initial list will be unordered.
>>> font.kerning.items()
[(("A", "V"), -30), (("A", "W"), -10)] | f10853:c0:m22 |
def keys(self): | return super(BaseKerning, self).keys()<EOL> | Returns a ``list`` of all the pairs in Kerning. This list will be
unordered.::
>>> font.kerning.keys()
[("A", "Y"), ("A", "V"), ("A", "W")] | f10853:c0:m23 |
def pop(self, pair, default=None): | return super(BaseKerning, self).pop(pair, default)<EOL> | Removes the **pair** from the Kerning and returns the value as an ``int``.
If no pair is found, **default** is returned. **pair** is a
``tuple`` of two :ref:`type-string`\s. This must return either
**default** or a :ref:`type-int-float`.
>>> font.kerning.pop(("A", "V"))
-20
>>> font.kerning.pop(("A", "W")... | f10853:c0:m24 |
def update(self, otherKerning): | super(BaseKerning, self).update(otherKerning)<EOL> | Updates the Kerning based on **otherKerning**. **otherKerning** is a ``dict`` of
kerning information. If a pair from **otherKerning** is in Kerning, the pair
value will be replaced by the value from **otherKerning**. If a pair
from **otherKerning** is not in the Kerning, it is added to the pairs. If Kerning
contains a ... | f10853:c0:m25 |
def values(self): | return super(BaseKerning, self).values()<EOL> | Returns a ``list`` of each pair's values, the values will be
:ref:`type-int-float`\s.
The list will be unordered.
>>> font.kerning.items()
[-20, -15, 5, 3.5] | f10853:c0:m26 |
def __init__(self, pathOrObject=None, showInterface=True): | super(BaseFont, self).__init__(pathOrObject=pathOrObject,<EOL>showInterface=showInterface)<EOL> | When constructing a font, the object can be created
in a new file, from an existing file or from a native
object. This is defined with the **pathOrObjectArgument**.
If **pathOrObject** is a string, the string must represent
an existing file. If **pathOrObject** is an instance of the
environment's unwrapped native font ... | f10854:c0:m0 |
def copy(self): | return super(BaseFont, self).copy()<EOL> | Copy the font into a new font. ::
>>> copiedFont = font.copy()
This will copy:
* info
* groups
* kerning
* features
* lib
* layers
* layerOrder
* defaultLayerName
* glyphOrder
* guidelines | f10854:c0:m2 |
def copyData(self, source): | for layerName in source.layerOrder:<EOL><INDENT>if layerName in self.layerOrder:<EOL><INDENT>layer = self.getLayer(layerName)<EOL><DEDENT>else:<EOL><INDENT>layer = self.newLayer(layerName)<EOL><DEDENT>layer.copyData(source.getLayer(layerName))<EOL><DEDENT>for guideline in self.guidelines:<EOL><INDENT>self.appendGuideli... | Copy data from **source** into this font.
Refer to :meth:`BaseFont.copy` for a list
of values that will be copied. | f10854:c0:m3 |
def _init(self, pathOrObject=None, showInterface=True, **kwargs): | self.raiseNotImplementedError()<EOL> | Initialize this object. This should wrap a native font
object based on the values for **pathOrObject**:
+--------------------+---------------------------------------------------+
| None | Create a new font. |
+--------------------+-------------------------------------------... | f10854:c0:m4 |
def _get_path(self, **kwargs): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:attr:`BaseFont.path`.
This must return a :ref:`type-string` defining the
location of the file or ``None`` indicating that the
font does not have a file representation. If the
returned value is not ``None`` it will be normalized
with :func:`normalizers.normalizeFilePath`.
Sub... | f10854:c0:m6 |
def save(self, path=None, showProgress=False, formatVersion=None): | if path is None and self.path is None:<EOL><INDENT>raise IOError(("<STR_LIT>"<EOL>"<STR_LIT>"))<EOL><DEDENT>if path is not None:<EOL><INDENT>path = normalizers.normalizeFilePath(path)<EOL><DEDENT>showProgress = bool(showProgress)<EOL>if formatVersion is not None:<EOL><INDENT>formatVersion = normalizers.normalizeFileFor... | Save the font to **path**.
>>> font.save()
>>> font.save("/path/to/my/font-2.ufo")
If **path** is None, use the font's original location.
The file type must be inferred from the file extension
of the given path. If no file extension is given, the
environment may fall back to the format of its choice.
**showPr... | f10854:c0:m7 |
def _save(self, path=None, showProgress=False,<EOL>formatVersion=None, **kwargs): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:meth:`BaseFont.save`. **path** will be a
:ref:`type-string` or ``None``. If **path**
is not ``None``, the value will have been
normalized with :func:`normalizers.normalizeFilePath`.
**showProgress** will be a ``bool`` indicating if
the environment should display a progress bar... | f10854:c0:m8 |
def close(self, save=False): | if save:<EOL><INDENT>self.save()<EOL><DEDENT>self._close()<EOL> | Close the font.
>>> font.close()
**save** is a boolean indicating if the font
should be saved prior to closing. If **save**
is ``True``, the :meth:`BaseFont.save` method
will be called. The default is ``False``. | f10854:c0:m9 |
def _close(self, **kwargs): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:meth:`BaseFont.close`.
Subclasses must override this method. | f10854:c0:m10 |
@staticmethod<EOL><INDENT>def generateFormatToExtension(format, fallbackFormat):<DEDENT> | formatToExtension = dict(<EOL>macttf="<STR_LIT>",<EOL>macttdfont="<STR_LIT>",<EOL>otfcff="<STR_LIT>",<EOL>otfttf="<STR_LIT>",<EOL>ufo1="<STR_LIT>",<EOL>ufo2="<STR_LIT>",<EOL>ufo3="<STR_LIT>",<EOL>unixascii="<STR_LIT>",<EOL>)<EOL>return formatToExtension.get(format, fallbackFormat)<EOL> | +--------------+--------------------------------------------------------------------+
| mactype1 | Mac Type 1 font (generates suitcase and LWFN file) |
+--------------+--------------------------------------------------------------------+
| macttf | Mac TrueType font (generates suitcase) ... | f10854:c0:m11 |
def generate(self, format, path=None, **environmentOptions): | import warnings<EOL>if format is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>elif not isinstance(format, basestring):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>env = {}<EOL>for key, value in environmentOptions.items():<EOL><INDENT>valid = self._isValidGenerateEnvironmentOption(key)<EOL>if not... | Generate the font to another format.
>>> font.generate("otfcff")
>>> font.generate("otfcff", "/path/to/my/font.otf")
**format** defines the file format to output.
Standard format identifiers can be found in :attr:`BaseFont.generateFormatToExtension`:
Environments are not required to support all of these
and... | f10854:c0:m12 |
@staticmethod<EOL><INDENT>def _isValidGenerateEnvironmentOption(name):<DEDENT> | return False<EOL> | Any unknown keyword arguments given to :meth:`BaseFont.generate`
will be passed to this method. **name** will be the name
used for the argument. Environments may evaluate if **name**
is a supported option. If it is, they must return `True` if
it is not, they must return `False`.
Subclasses may override this method. | f10854:c0:m13 |
def _generate(self, format, path, environmentOptions, **kwargs): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:meth:`BaseFont.generate`. **format** will be a
:ref:`type-string` defining the output format.
Refer to the :meth:`BaseFont.generate` documentation
for the standard format identifiers. If the value
given for **format** is not supported by the environment,
the environment must r... | f10854:c0:m14 |
def _get_info(self): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:attr:`BaseFont.info`. This must return an
instance of a :class:`BaseInfo` subclass.
Subclasses must override this method. | f10854:c0:m16 |
def _get_groups(self): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:attr:`BaseFont.groups`. This must return
an instance of a :class:`BaseGroups` subclass.
Subclasses must override this method. | f10854:c0:m18 |
def _get_kerning(self): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:attr:`BaseFont.kerning`. This must return
an instance of a :class:`BaseKerning` subclass.
Subclasses must override this method. | f10854:c0:m20 |
def getFlatKerning(self): | return self._getFlatKerning()<EOL> | Get the font's kerning as a flat dictionary. | f10854:c0:m21 |
def _getFlatKerning(self): | kernOrder = {<EOL>(True, True): <NUM_LIT:0>, <EOL>(True, False): <NUM_LIT:1>, <EOL>(False, True): <NUM_LIT:2>, <EOL>(False, False): <NUM_LIT:3>, <EOL>}<EOL>def kerningSortKeyFunc(pair):<EOL><INDENT>g1, g2 = pair<EOL>g1grp = g1.startswith("<STR_LIT>")<EOL>g2grp = g2.startswith("<STR_LIT>")<EOL>return (kernOrder[g1gr... | This is the environment implementation of
:meth:`BaseFont.getFlatKerning`.
Subclasses may override this method. | f10854:c0:m22 |
def _get_features(self): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:attr:`BaseFont.features`. This must return
an instance of a :class:`BaseFeatures` subclass.
Subclasses must override this method. | f10854:c0:m24 |
def _get_lib(self): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:attr:`BaseFont.lib`. This must return an
instance of a :class:`BaseLib` subclass.
Subclasses must override this method. | f10854:c0:m26 |
def _get_layers(self, **kwargs): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:attr:`BaseFont.layers`. This must return an
:ref:`type-immutable-list` containing
instances of :class:`BaseLayer` subclasses.
The items in the list should be in the order
defined by :attr:`BaseFont.layerOrder`.
Subclasses must override this method. | f10854:c0:m28 |
def _get_layerOrder(self, **kwargs): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:attr:`BaseFont.layerOrder`. This must return an
:ref:`type-immutable-list` defining the order of
the layers in the font. The contents of the list
must be layer names as :ref:`type-string`. The
list will be normalized with :func:`normalizers.normalizeLayerOrder`.
Subclasses mu... | f10854:c0:m31 |
def _set_layerOrder(self, value, **kwargs): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:attr:`BaseFont.layerOrder`. **value** will
be a **list** of :ref:`type-string` representing
layer names. The list will have been normalized
with :func:`normalizers.normalizeLayerOrder`.
Subclasses must override this method. | f10854:c0:m32 |
def _get_defaultLayerName(self): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:attr:`BaseFont.defaultLayerName`. Return the
name of the default layer as a :ref:`type-string`.
The name will be normalized with
:func:`normalizers.normalizeDefaultLayerName`.
Subclasses must override this method. | f10854:c0:m36 |
def _set_defaultLayerName(self, value, **kwargs): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:attr:`BaseFont.defaultLayerName`. **value**
will be a :ref:`type-string`. It will have
been normalized with :func:`normalizers.normalizeDefaultLayerName`.
Subclasses must override this method. | f10854:c0:m37 |
def _get_base_defaultLayer(self): | name = self.defaultLayerName<EOL>layer = self.getLayer(name)<EOL>return layer<EOL> | This is the environment implementation of
:attr:`BaseFont.defaultLayer`. Return the
default layer as a :class:`BaseLayer` object.
The layer will be normalized with
:func:`normalizers.normalizeLayer`.
Subclasses must override this method. | f10854:c0:m40 |
def _set_base_defaultLayer(self, value): | self.defaultLayerName = value.name<EOL> | This is the environment implementation of
:attr:`BaseFont.defaultLayer`. **value**
will be a :class:`BaseLayer`. It will have
been normalized with :func:`normalizers.normalizeLayer`.
Subclasses must override this method. | f10854:c0:m41 |
def getLayer(self, name): | name = normalizers.normalizeLayerName(name)<EOL>if name not in self.layerOrder:<EOL><INDENT>raise ValueError("<STR_LIT>" % name)<EOL><DEDENT>layer = self._getLayer(name)<EOL>self._setFontInLayer(layer)<EOL>return layer<EOL> | Get the :class:`BaseLayer` with **name**.
>>> layer = font.getLayer("My Layer 2") | f10854:c0:m42 |
def _getLayer(self, name, **kwargs): | for layer in self.layers:<EOL><INDENT>if layer.name == name:<EOL><INDENT>return layer<EOL><DEDENT><DEDENT> | This is the environment implementation of
:meth:`BaseFont.getLayer`. **name** will
be a :ref:`type-string`. It will have been
normalized with :func:`normalizers.normalizeLayerName`
and it will have been verified as an existing layer.
This must return an instance of :class:`BaseLayer`.
Subclasses may override this meth... | f10854:c0:m43 |
def newLayer(self, name, color=None): | name = normalizers.normalizeLayerName(name)<EOL>if name in self.layerOrder:<EOL><INDENT>layer = self.getLayer(name)<EOL>if color is not None:<EOL><INDENT>layer.color = color<EOL><DEDENT>return layer<EOL><DEDENT>if color is not None:<EOL><INDENT>color = normalizers.normalizeColor(color)<EOL><DEDENT>layer = self._newLaye... | Make a new layer with **name** and **color**.
**name** must be a :ref:`type-string` and
**color** must be a :ref:`type-color` or ``None``.
>>> layer = font.newLayer("My Layer 3")
The will return the newly created
:class:`BaseLayer`. | f10854:c0:m44 |
def _newLayer(self, name, color, **kwargs): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:meth:`BaseFont.newLayer`. **name** will be
a :ref:`type-string` representing a valid
layer name. The value will have been normalized
with :func:`normalizers.normalizeLayerName` and
**name** will not be the same as the name of
an existing layer. **color** will be a
:ref:`type-c... | f10854:c0:m45 |
def removeLayer(self, name): | name = normalizers.normalizeLayerName(name)<EOL>if name not in self.layerOrder:<EOL><INDENT>raise ValueError("<STR_LIT>" % name)<EOL><DEDENT>self._removeLayer(name)<EOL> | Remove the layer with **name** from the font.
>>> font.removeLayer("My Layer 3") | f10854:c0:m46 |
def _removeLayer(self, name, **kwargs): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:meth:`BaseFont.removeLayer`. **name** will
be a :ref:`type-string` defining the name
of an existing layer. The value will have
been normalized with :func:`normalizers.normalizeLayerName`.
Subclasses must override this method. | f10854:c0:m47 |
def insertLayer(self, layer, name=None): | if name is None:<EOL><INDENT>name = layer.name<EOL><DEDENT>name = normalizers.normalizeLayerName(name)<EOL>if name in self:<EOL><INDENT>self.removeLayer(name)<EOL><DEDENT>return self._insertLayer(layer, name=name)<EOL> | Insert **layer** into the font. ::
>>> layer = font.insertLayer(otherLayer, name="layer 2")
This will not insert the layer directly.
Rather, a new layer will be created and the data from
**layer** will be copied to to the new layer. **name**
indicates the name that should be assigned to the layer
after insertion.... | f10854:c0:m48 |
def _insertLayer(self, layer, name, **kwargs): | if name != layer.name and layer.name in self.layerOrder:<EOL><INDENT>layer = layer.copy()<EOL>layer.name = name<EOL><DEDENT>dest = self.newLayer(name)<EOL>dest.copyData(layer)<EOL>return dest<EOL> | This is the environment implementation of :meth:`BaseFont.insertLayer`.
This must return an instance of a :class:`BaseLayer` subclass.
**layer** will be a layer object with the attributes necessary
for copying as defined in :meth:`BaseLayer.copy` An environment
must not insert **layer** directly. Instead the data from ... | f10854:c0:m49 |
def duplicateLayer(self, layerName, newLayerName): | layerOrder = self.layerOrder<EOL>layerName = normalizers.normalizeLayerName(layerName)<EOL>if layerName not in layerOrder:<EOL><INDENT>raise ValueError("<STR_LIT>" % layerName)<EOL><DEDENT>newLayerName = normalizers.normalizeLayerName(newLayerName)<EOL>if newLayerName in layerOrder:<EOL><INDENT>raise ValueError("<STR_L... | Duplicate the layer with **layerName**, assign
**newLayerName** to the new layer and insert the
new layer into the font. ::
>>> layer = font.duplicateLayer("layer 1", "layer 2") | f10854:c0:m50 |
def _duplicateLayer(self, layerName, newLayerName): | newLayer = self.getLayer(layerName).copy()<EOL>return self.insertLayer(newLayer, newLayerName)<EOL> | This is the environment implementation of :meth:`BaseFont.duplicateLayer`.
**layerName** will be a :ref:`type-string` representing a valid layer name.
The value will have been normalized with :func:`normalizers.normalizeLayerName`
and **layerName** will be a layer that exists in the font. **newLayerName**
will be a :re... | f10854:c0:m51 |
def swapLayerNames(self, layerName, otherLayerName): | layerOrder = self.layerOrder<EOL>layerName = normalizers.normalizeLayerName(layerName)<EOL>if layerName not in layerOrder:<EOL><INDENT>raise ValueError("<STR_LIT>" % layerName)<EOL><DEDENT>otherLayerName = normalizers.normalizeLayerName(otherLayerName)<EOL>if otherLayerName not in layerOrder:<EOL><INDENT>raise ValueErr... | Assign **layerName** to the layer currently named
**otherLayerName** and assign the name **otherLayerName**
to the layer currently named **layerName**.
>>> font.swapLayerNames("before drawing revisions", "after drawing revisions") | f10854:c0:m52 |
def _swapLayers(self, layerName, otherLayerName): | import random<EOL>layer1 = self.getLayer(layerName)<EOL>layer2 = self.getLayer(otherLayerName)<EOL>layerOrder = self.layerOrder<EOL>for _ in range(<NUM_LIT:50>):<EOL><INDENT>tempLayerName = str(random.randint(<NUM_LIT>, <NUM_LIT>))<EOL>if tempLayerName not in layerOrder:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if tempLay... | This is the environment implementation of :meth:`BaseFont.swapLayerNames`.
**layerName** will be a :ref:`type-string` representing a valid layer name.
The value will have been normalized with :func:`normalizers.normalizeLayerName`
and **layerName** will be a layer that exists in the font. **otherLayerName**
will be a :... | f10854:c0:m53 |
def _getItem(self, name, **kwargs): | layer = self.defaultLayer<EOL>return layer[name]<EOL> | This is the environment implementation of
:meth:`BaseFont.__getitem__`. **name** will
be a :ref:`type-string` defining an existing
glyph in the default layer. The value will
have been normalized with :func:`normalizers.normalizeGlyphName`.
Subclasses may override this method. | f10854:c0:m54 |
def _keys(self, **kwargs): | layer = self.defaultLayer<EOL>return layer.keys()<EOL> | This is the environment implementation of
:meth:`BaseFont.keys`. This must return an
:ref:`type-immutable-list` of all glyph names
in the default layer.
Subclasses may override this method. | f10854:c0:m55 |
def _newGlyph(self, name, **kwargs): | layer = self.defaultLayer<EOL>return layer.newGlyph(name, clear=False)<EOL> | This is the environment implementation of
:meth:`BaseFont.newGlyph`. **name** will be
a :ref:`type-string` representing a valid
glyph name. The value will have been tested
to make sure that an existing glyph in the
default layer does not have an identical name.
The value will have been normalized with
:func:`normalizer... | f10854:c0:m56 |
def _removeGlyph(self, name, **kwargs): | layer = self.defaultLayer<EOL>layer.removeGlyph(name)<EOL> | This is the environment implementation of
:meth:`BaseFont.removeGlyph`. **name** will
be a :ref:`type-string` representing an
existing glyph in the default layer. The
value will have been normalized with
:func:`normalizers.normalizeGlyphName`.
Subclasses may override this method. | f10854:c0:m57 |
def __setitem__(self, name, glyph): | name = normalizers.normalizeGlyphName(name)<EOL>if name in self:<EOL><INDENT>dest = self._getItem(name)<EOL>dest.clear()<EOL><DEDENT>return self._insertGlyph(glyph, name=name, clear=False)<EOL> | Insert **glyph** into the font. ::
>>> glyph = font["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. The data that will be in... | f10854:c0:m58 |
def _get_glyphOrder(self): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:attr:`BaseFont.glyphOrder`. This must return
an :ref:`type-immutable-list` containing glyph
names representing the glyph order in the font.
The value will be normalized with
:func:`normalizers.normalizeGlyphOrder`.
Subclasses must override this method. | f10854:c0:m61 |
def _set_glyphOrder(self, value): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:attr:`BaseFont.glyphOrder`. **value** will
be a list of :ref:`type-string`. It will
have been normalized with
:func:`normalizers.normalizeGlyphOrder`.
Subclasses must override this method. | f10854:c0:m62 |
def round(self): | self._round()<EOL> | Round all approriate data to integers.
>>> font.round()
This is the equivalent of calling the round method on:
* info
* kerning
* the default layer
* font-level guidelines
This applies only to the default layer. | f10854:c0:m63 |
def _round(self): | layer = self.defaultLayer<EOL>layer.round()<EOL>self.info.round()<EOL>self.kerning.round()<EOL>for guideline in self.guidelines:<EOL><INDENT>guideline.round()<EOL><DEDENT> | This is the environment implementation of
:meth:`BaseFont.round`.
Subclasses may override this method. | f10854:c0:m64 |
def autoUnicodes(self): | self._autoUnicodes()<EOL> | Use heuristics to set Unicode values in all glyphs.
>>> font.autoUnicodes()
Environments will define their own heuristics for
automatically determining values.
This applies only to the default layer. | f10854:c0:m65 |
def _autoUnicodes(self): | layer = self.defaultLayer<EOL>layer.autoUnicodes()<EOL> | This is the environment implementation of
:meth:`BaseFont.autoUnicodes`.
Subclasses may override this method. | f10854:c0:m66 |
def _get_guidelines(self): | return tuple([self._getitem__guidelines(i)<EOL>for i in range(self._len__guidelines())])<EOL> | This is the environment implementation of
:attr:`BaseFont.guidelines`. This must
return an :ref:`type-immutable-list` of
:class:`BaseGuideline` objects.
Subclasses may override this method. | f10854:c0:m68 |
def _lenGuidelines(self, **kwargs): | self.raiseNotImplementedError()<EOL> | This must return an integer indicating
the number of font-level guidelines
in the font.
Subclasses must override this method. | f10854:c0:m70 |
def _getGuideline(self, index, **kwargs): | self.raiseNotImplementedError()<EOL> | This must return a :class:`BaseGuideline` object.
**index** will be a valid **index**.
Subclasses must override this method. | f10854:c0:m72 |
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><DEDEN... | Append a new guideline to the font.
>>> guideline = font.appendGuideline((50, 0), 90)
>>> guideline = font.appendGuideline((0, 540), 0, name="overshoot",
>>> color=(0, 0, 0, 0.2))
**position** must be a :ref:`type-coordinate`
indicating the position of the guideline.
**angle** indicates the :ref:`type-ang... | f10854:c0:m74 |
def _appendGuideline(self, position, angle, name=None, color=None, identifier=None, **kwargs): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:meth:`BaseFont.appendGuideline`. **position**
will be a valid :ref:`type-coordinate`. **angle**
will be a valid angle. **name** will be a valid
:ref:`type-string` or ``None``. **color** will
be a valid :ref:`type-color` or ``None``.
This must return the newly created
:class:`B... | f10854:c0:m75 |
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)<... | Remove **guideline** from the font.
>>> font.removeGuideline(guideline)
>>> font.removeGuideline(2)
**guideline** can be a guideline object or
an integer representing the guideline index. | f10854:c0:m76 |
def _removeGuideline(self, index, **kwargs): | self.raiseNotImplementedError()<EOL> | This is the environment implementation of
:meth:`BaseFont.removeGuideline`. **index**
will be a valid index.
Subclasses must override this method. | f10854:c0:m77 |
def clearGuidelines(self): | self._clearGuidelines()<EOL> | Clear all guidelines.
>>> font.clearGuidelines() | f10854:c0:m78 |
def _clearGuidelines(self): | for _ in range(self._len__guidelines()):<EOL><INDENT>self.removeGuideline(-<NUM_LIT:1>)<EOL><DEDENT> | This is the environment implementation of
:meth:`BaseFont.clearGuidelines`.
Subclasses may override this method. | f10854:c0:m79 |
def interpolate(self, factor, minFont, maxFont,<EOL>round=True, suppressError=True): | factor = normalizers.normalizeInterpolationFactor(factor)<EOL>if not isinstance(minFont, BaseFont):<EOL><INDENT>raise TypeError(("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>% (self.__class__.__name__, minFont.__class__.__name__))<EOL><DEDENT>if not isinstance(maxFont, BaseFont):<EOL><INDENT>raise TypeError(("<STR_LIT>"<EOL>"<STR_... | Interpolate all possible data in the font.
>>> font.interpolate(0.5, otherFont1, otherFont2)
>>> font.interpolate((0.5, 2.0), otherFont1, otherFont2, round=False)
The interpolation occurs on a 0 to 1.0 range where **minFont**
is located at 0 and **maxFont** is located at 1.0. **factor**
is the interpolation v... | f10854:c0:m80 |
def _interpolate(self, factor, minFont, maxFont,<EOL>round=True, suppressError=True): | <EOL>for layerName in self.layerOrder:<EOL><INDENT>self.removeLayer(layerName)<EOL><DEDENT>for layerName in minFont.layerOrder:<EOL><INDENT>if layerName not in maxFont.layerOrder:<EOL><INDENT>continue<EOL><DEDENT>minLayer = minFont.getLayer(layerName)<EOL>maxLayer = maxFont.getLayer(layerName)<EOL>dstLayer = self.newLa... | This is the environment implementation of
:meth:`BaseFont.interpolate`.
Subclasses may override this method. | f10854:c0:m81 |
def isCompatible(self, other): | return super(BaseFont, self).isCompatible(other, BaseFont)<EOL> | Evaluate interpolation compatibility with **other**.
>>> compatible, report = self.isCompatible(otherFont)
>>> compatible
False
>>> report
[Fatal] Glyph: "test1" + "test2"
[Fatal] Glyph: "test1" contains 1 contours | "test2" contains 2 contours
This will return a ``bool`` indicating if the fon... | f10854:c0:m82 |
def _isCompatible(self, other, reporter): | font1 = self<EOL>font2 = other<EOL>guidelines1 = set(font1.guidelines)<EOL>guidelines2 = set(font2.guidelines)<EOL>if len(guidelines1) != len(guidelines2):<EOL><INDENT>reporter.warning = True<EOL>reporter.guidelineCountDifference = True<EOL><DEDENT>if len(guidelines1.difference(guidelines2)) != <NUM_LIT:0>:<EOL><INDENT... | This is the environment implementation of
:meth:`BaseFont.isCompatible`.
Subclasses may override this method. | f10854:c0:m83 |
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. | f10854:c0:m84 |
def _getReverseComponentMapping(self): | layer = self.defaultLayer<EOL>return layer.getReverseComponentMapping()<EOL> | This is the environment implementation of
:meth:`BaseFont.getReverseComponentMapping`.
Subclasses may override this method. | f10854:c0:m85 |
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.
} | f10854:c0:m86 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.