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 compatible for interpolation with **other** and a :ref:`type-string` of compatibility notes.
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_LIT>"<EOL>"<STR_LIT>") % (<EOL>self.__class__.__name__, maxKerning.__class__.__name__))<EOL><DEDENT>round = normalizers.normalizeBoolean(round)<EOL>suppressError = normalizers.normalizeBoolean(suppressError)<EOL>self._interpolate(factor, minKerning, maxKerning,<EOL>round=round, suppressError=suppressError)<EOL>
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. It may be less than 0 and greater than 1.0. It may be an :ref:`type-int-float`, ``tuple`` or ``list``. If it is a ``tuple`` or ``list``, the first number indicates the x factor and the second number indicates the y factor. * **round** is a ``bool`` indicating if the result should be rounded to ``int``\s. The default behavior is to round interpolated kerning. * **suppressError** is a ``bool`` indicating if incompatible data should be ignored or if an error should be raised when such incompatibilities are found. The default behavior is to ignore incompatible data. >>> myKerning.interpolate(kerningOne, kerningTwo)
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=minKerning.font.groups)<EOL>maxKerning = fontMath.MathKerning(<EOL>kerning=maxKerning, groups=maxKerning.font.groups)<EOL>result = interpolate(minKerning, maxKerning, factor)<EOL>if round:<EOL><INDENT>result.round()<EOL><DEDENT>self.clear()<EOL>result.extractKerning(self.font)<EOL><DEDENT>
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 kerning should be rounded. * **suppressError** will be a ``bool`` indicating if incompatible data should be ignored. Subclasses may override this method.
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 make a change to the value, one should do the following:: >>> value = font.kerning[("A", "V")] >>> value += 10 >>> font.kerning[("A", "V")] = value
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 reflected in the Kerning object. If one wants to make a change to the value, one should do the following:: >>> value = font.kerning[("A", "V")] >>> value += 10 >>> font.kerning[("A", "V")] = value
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")) -10.5
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 pair that is not in **otherKerning**, it is not changed. >>> font.kerning.update(newKerning)
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 object, wrap it with FontParts. If **pathOrObject** is None, create a new, empty font. If **showInterface** is ``False``, the font should be created without graphical interface. The default for **showInterface** is ``True``.
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.appendGuideline(guideline)<EOL><DEDENT>super(BaseFont, self).copyData(source)<EOL>
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. | +--------------------+---------------------------------------------------+ | string | Open the font file located at the given location. | +--------------------+---------------------------------------------------+ | native font object | Wrap the given object. | +--------------------+---------------------------------------------------+ If **showInterface** is ``False``, the font should be created without graphical interface. Subclasses must override this method.
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`. Subclasses must override this method.
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.normalizeFileFormatVersion(<EOL>formatVersion)<EOL><DEDENT>self._save(path=path, showProgress=showProgress,<EOL>formatVersion=formatVersion)<EOL>
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. **showProgress** indicates if a progress indicator should be displayed during the operation. Environments may or may not implement this behavior. **formatVersion** indicates the format version that should be used for writing the given file type. For example, if 2 is given for formatVersion and the file type being written if UFO, the file is to be written in UFO 2 format. This value is not limited to UFO format versions. If no format version is given, the original format version of the file should be preserved. If there is no original format version it is implied that the format version is the latest version for the file type as supported by the environment. .. note:: Environments may define their own rules governing when a file should be saved into its original location and when it should not. For example, a font opened from a compiled OpenType font may not be written back into the original OpenType font.
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 during the operation. Environments are not *required* to display a progress bar even if **showProgess** is ``True``. **formatVersion** will be :ref:`type-int-float` or ``None`` indicating the file format version to write the data into. It will have been normalized with :func:`normalizers.normalizeFileFormatVersion`. Subclasses must override this method.
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) | +--------------+--------------------------------------------------------------------+ | macttdfont | Mac TrueType font (generates suitcase with resources in data fork) | +--------------+--------------------------------------------------------------------+ | otfcff | PS OpenType (CFF-based) font (OTF) | +--------------+--------------------------------------------------------------------+ | otfttf | PC TrueType/TT OpenType font (TTF) | +--------------+--------------------------------------------------------------------+ | pctype1 | PC Type 1 font (binary/PFB) | +--------------+--------------------------------------------------------------------+ | pcmm | PC MultipleMaster font (PFB) | +--------------+--------------------------------------------------------------------+ | pctype1ascii | PC Type 1 font (ASCII/PFA) | +--------------+--------------------------------------------------------------------+ | pcmmascii | PC MultipleMaster font (ASCII/PFA) | +--------------+--------------------------------------------------------------------+ | ufo1 | UFO format version 1 | +--------------+--------------------------------------------------------------------+ | ufo2 | UFO format version 2 | +--------------+--------------------------------------------------------------------+ | ufo3 | UFO format version 3 | +--------------+--------------------------------------------------------------------+ | unixascii | UNIX ASCII font (ASCII/PFA) | +--------------+--------------------------------------------------------------------+
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 valid:<EOL><INDENT>warnings.warn("<STR_LIT>"<EOL>"<STR_LIT>" % key, UserWarning)<EOL><DEDENT>env[key] = value<EOL><DEDENT>environmentOptions = env<EOL>ext = self.generateFormatToExtension(format, "<STR_LIT:.>" + format)<EOL>if path is None and self.path is None:<EOL><INDENT>raise IOError(("<STR_LIT>"<EOL>"<STR_LIT>"))<EOL><DEDENT>elif path is None:<EOL><INDENT>path = os.path.splitext(self.path)[<NUM_LIT:0>]<EOL>path += ext<EOL><DEDENT>elif os.path.isdir(path):<EOL><INDENT>if self.path is None:<EOL><INDENT>raise IOError(("<STR_LIT>"<EOL>"<STR_LIT>"))<EOL><DEDENT>fileName = os.path.basename(self.path)<EOL>fileName += ext<EOL>path = os.path.join(path, fileName)<EOL><DEDENT>path = normalizers.normalizeFilePath(path)<EOL>return self._generate(<EOL>format=format,<EOL>path=path,<EOL>environmentOptions=environmentOptions<EOL>)<EOL>
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 environments may define their own format types. **path** defines the location where the new file should be created. If a file already exists at that location, it will be overwritten by the new file. If **path** defines a directory, the file will be output as the current file name, with the appropriate suffix for the format, into the given directory. If no **path** is given, the file will be output into the same directory as the source font with the file named with the current file name, with the appropriate suffix for the format. Environments may allow unique keyword arguments in this method. For example, if a tool allows decomposing components during a generate routine it may allow this: >>> font.generate("otfcff", "/p/f.otf", decompose=True)
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 raise :exc:`FontPartsError`. **path** will be a :ref:`type-string` defining the location where the file should be created. It will have been normalized with :func:`normalizers.normalizeFilePath`. **environmentOptions** will be a dictionary of names validated with :meth:`BaseFont._isValidGenerateEnvironmentOption` nd the given values. These values will not have been passed through any normalization functions. Subclasses must override this method.
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[g1grp, g2grp], pair)<EOL><DEDENT>flatKerning = dict()<EOL>kerning = self.kerning<EOL>groups = self.groups<EOL>for pair in sorted(self.kerning.keys(), key=kerningSortKeyFunc):<EOL><INDENT>kern = kerning[pair]<EOL>(left, right) = pair<EOL>if left.startswith("<STR_LIT>"):<EOL><INDENT>left = groups.get(left, [])<EOL><DEDENT>else:<EOL><INDENT>left = [left]<EOL><DEDENT>if right.startswith("<STR_LIT>"):<EOL><INDENT>right = groups.get(right, [])<EOL><DEDENT>else:<EOL><INDENT>right = [right]<EOL><DEDENT>for r in right:<EOL><INDENT>for l in left:<EOL><INDENT>flatKerning[(l, r)] = kern<EOL><DEDENT><DEDENT><DEDENT>return flatKerning<EOL>
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 must override this method.
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 method.
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._newLayer(name=name, color=color)<EOL>self._setFontInLayer(layer)<EOL>return layer<EOL>
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-color` or ``None``. If the value is not ``None`` the value will have been normalized with :func:`normalizers.normalizeColor`. This must return an instance of a :class:`BaseLayer` subclass that represents the new layer. Subclasses must override this method.
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. If **name** is not given, the layer's original name must be used. If the layer does not have a name, an error must be raised. The data that will be inserted from **layer** is the same data as documented in :meth:`BaseLayer.copy`.
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 **layer** should be copied to a new layer. **name** will be a :ref:`type-string` representing a glyph layer. It will have been normalized with :func:`normalizers.normalizeLayerName`. **name** will have been tested to make sure that no layer with the same name exists in the font. Subclasses may override this method.
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_LIT>" % newLayerName)<EOL><DEDENT>newLayer = self._duplicateLayer(layerName, newLayerName)<EOL>newLayer = normalizers.normalizeLayer(newLayer)<EOL>return newLayer<EOL>
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 :ref:`type-string` representing a valid layer name. The value will have been normalized with :func:`normalizers.normalizeLayerName` and **newLayerName** will have been tested to make sure that no layer with the same name exists in the font. This must return an instance of a :class:`BaseLayer` subclass. Subclasses may override this method.
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 ValueError("<STR_LIT>" % otherLayerName)<EOL><DEDENT>self._swapLayers(layerName, otherLayerName)<EOL>
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 tempLayerName in layerOrder:<EOL><INDENT>raise FontPartsError(("<STR_LIT>"<EOL>"<STR_LIT>"))<EOL><DEDENT>layer1.name = tempLayerName<EOL>layer2.name = layerName<EOL>layer1.name = otherLayerName<EOL>
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 :ref:`type-string` representing a valid layer name. The value will have been normalized with :func:`normalizers.normalizeLayerName` and **otherLayerName** will be a layer that exists in the font. Subclasses may override this method.
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:`normalizers.normalizeGlyphName`. This must return an instance of :class:`BaseGlyph` representing the new glyph. Subclasses may override this method.
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 inserted from **glyph** is the same data as documented in :meth:`BaseGlyph.copy`. On a font level **font.glyphOrder** will be preserved if the **name** is already present.
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><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.font = self<EOL>return guideline<EOL>
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-angle` of the guideline. **name** indicates the name for the guideline. This must be a :ref:`type-string` or ``None``. **color** indicates the color for the guideline. This must be a :ref:`type-color` or ``None``. This will return the newly created :class:`BaseGuidline` object. ``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.
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:`BaseGuideline` object. Subclasses may override this method.
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)<EOL>
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_LIT>")<EOL>% (self.__class__.__name__, maxFont.__class__.__name__))<EOL><DEDENT>round = normalizers.normalizeBoolean(round)<EOL>suppressError = normalizers.normalizeBoolean(suppressError)<EOL>self._interpolate(factor, minFont, maxFont,<EOL>round=round, suppressError=suppressError)<EOL>
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 value. It may be less than 0 and greater than 1.0. It may be a :ref:`type-int-float` or a tuple of two :ref:`type-int-float`. If it is a tuple, the first number indicates the x factor and the second number indicates the y factor. **round** indicates if the result should be rounded to integers. **suppressError** indicates if incompatible data should be ignored or if an error should be raised when such incompatibilities are found.
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.newLayer(layerName)<EOL>dstLayer.interpolate(factor, minLayer, maxLayer,<EOL>round=round, suppressError=suppressError)<EOL><DEDENT>if self.layerOrder:<EOL><INDENT>self.defaultLayer = self.getLayer(self.layerOrder[<NUM_LIT:0>])<EOL><DEDENT>self.kerning.interpolate(factor, minFont.kerning, maxFont.kerning,<EOL>round=round, suppressError=suppressError)<EOL>self.info.interpolate(factor, minFont.info, maxFont.info,<EOL>round=round, suppressError=suppressError)<EOL>
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 font is compatible for interpolation with **other** and a :ref:`type-string` of compatibility notes.
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>reporter.warning = True<EOL>reporter.guidelinesMissingFromFont2 = list(<EOL>guidelines1.difference(guidelines2))<EOL><DEDENT>if len(guidelines2.difference(guidelines1)) != <NUM_LIT:0>:<EOL><INDENT>reporter.warning = True<EOL>reporter.guidelinesMissingInFont1 = list(<EOL>guidelines2.difference(guidelines1))<EOL><DEDENT>layers1 = set(font1.layerOrder)<EOL>layers2 = set(font2.layerOrder)<EOL>if len(layers1) != len(layers2):<EOL><INDENT>reporter.warning = True<EOL>reporter.layerCountDifference = True<EOL><DEDENT>if len(layers1.difference(layers2)) != <NUM_LIT:0>:<EOL><INDENT>reporter.warning = True<EOL>reporter.layersMissingFromFont2 = list(layers1.difference(layers2))<EOL><DEDENT>if len(layers2.difference(layers1)) != <NUM_LIT:0>:<EOL><INDENT>reporter.warning = True<EOL>reporter.layersMissingInFont1 = list(layers2.difference(layers1))<EOL><DEDENT>for layerName in sorted(layers1.intersection(layers2)):<EOL><INDENT>layer1 = font1.getLayer(layerName)<EOL>layer2 = font2.getLayer(layerName)<EOL>layerCompatibility = layer1.isCompatible(layer2)[<NUM_LIT:1>]<EOL>if layerCompatibility.fatal or layerCompatibility.warning:<EOL><INDENT>if layerCompatibility.fatal:<EOL><INDENT>reporter.fatal = True<EOL><DEDENT>if layerCompatibility.warning:<EOL><INDENT>reporter.warning = True<EOL><DEDENT>reporter.layers.append(layerCompatibility)<EOL><DEDENT><DEDENT>
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