code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def _categorizeVector(v): """ Takes X,Y vector v and returns one of r, h, v, or 0 depending on which of X and/or Y are zero, plus tuple of nonzero ones. If both are zero, it returns a single zero still. >>> _categorizeVector((0,0)) ('0', (0,)) >>> _categorizeVector((1,0)) ('h', (1,)) ...
Takes X,Y vector v and returns one of r, h, v, or 0 depending on which of X and/or Y are zero, plus tuple of nonzero ones. If both are zero, it returns a single zero still. >>> _categorizeVector((0,0)) ('0', (0,)) >>> _categorizeVector((1,0)) ('h', (1,)) >>> _categorizeVector((0,2)) ...
_categorizeVector
python
fonttools/fonttools
Lib/fontTools/cffLib/specializer.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cffLib/specializer.py
MIT
def optimizeWidthsBruteforce(widths): """Bruteforce version. Veeeeeeeeeeeeeeeeery slow. Only works for smallests of fonts.""" d = defaultdict(int) for w in widths: d[w] += 1 # Maximum number of bytes using default can possibly save maxDefaultAdvantage = 5 * max(d.values()) minw, max...
Bruteforce version. Veeeeeeeeeeeeeeeeery slow. Only works for smallests of fonts.
optimizeWidthsBruteforce
python
fonttools/fonttools
Lib/fontTools/cffLib/width.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cffLib/width.py
MIT
def optimizeWidths(widths): """Given a list of glyph widths, or dictionary mapping glyph width to number of glyphs having that, returns a tuple of best CFF default and nominal glyph widths. This algorithm is linear in UPEM+numGlyphs.""" if not hasattr(widths, "items"): d = defaultdict(int) ...
Given a list of glyph widths, or dictionary mapping glyph width to number of glyphs having that, returns a tuple of best CFF default and nominal glyph widths. This algorithm is linear in UPEM+numGlyphs.
optimizeWidths
python
fonttools/fonttools
Lib/fontTools/cffLib/width.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cffLib/width.py
MIT
def decompile(self, file, otFont, isCFF2=None): """Parse a binary CFF file into an internal representation. ``file`` should be a file handle object. ``otFont`` is the top-level :py:class:`fontTools.ttLib.ttFont.TTFont` object containing this CFF file. If ``isCFF2`` is passed and set to ...
Parse a binary CFF file into an internal representation. ``file`` should be a file handle object. ``otFont`` is the top-level :py:class:`fontTools.ttLib.ttFont.TTFont` object containing this CFF file. If ``isCFF2`` is passed and set to ``True`` or ``False``, then the library makes an as...
decompile
python
fonttools/fonttools
Lib/fontTools/cffLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cffLib/__init__.py
MIT
def __getitem__(self, nameOrIndex): """Return TopDict instance identified by name (str) or index (int or any object that implements `__index__`). """ if hasattr(nameOrIndex, "__index__"): index = nameOrIndex.__index__() elif isinstance(nameOrIndex, str): n...
Return TopDict instance identified by name (str) or index (int or any object that implements `__index__`).
__getitem__
python
fonttools/fonttools
Lib/fontTools/cffLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cffLib/__init__.py
MIT
def compile(self, file, otFont, isCFF2=None): """Write the object back into binary representation onto the given file. ``file`` should be a file handle object. ``otFont`` is the top-level :py:class:`fontTools.ttLib.ttFont.TTFont` object containing this CFF file. If ``isCFF2`` is passed ...
Write the object back into binary representation onto the given file. ``file`` should be a file handle object. ``otFont`` is the top-level :py:class:`fontTools.ttLib.ttFont.TTFont` object containing this CFF file. If ``isCFF2`` is passed and set to ``True`` or ``False``, then the librar...
compile
python
fonttools/fonttools
Lib/fontTools/cffLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cffLib/__init__.py
MIT
def toXML(self, xmlWriter): """Write the object into XML representation onto the given :class:`fontTools.misc.xmlWriter.XMLWriter`. .. code:: python writer = xmlWriter.XMLWriter(sys.stdout) tt["CFF "].cff.toXML(writer) """ xmlWriter.simpletag("...
Write the object into XML representation onto the given :class:`fontTools.misc.xmlWriter.XMLWriter`. .. code:: python writer = xmlWriter.XMLWriter(sys.stdout) tt["CFF "].cff.toXML(writer)
toXML
python
fonttools/fonttools
Lib/fontTools/cffLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cffLib/__init__.py
MIT
def fromXML(self, name, attrs, content, otFont=None): """Reads data from the XML element into the ``CFFFontSet`` object.""" self.otFont = otFont # set defaults. These will be replaced if there are entries for them # in the XML file. if not hasattr(self, "major"): sel...
Reads data from the XML element into the ``CFFFontSet`` object.
fromXML
python
fonttools/fonttools
Lib/fontTools/cffLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cffLib/__init__.py
MIT
def toXML(self, xmlWriter): """Write the subroutines index into XML representation onto the given :class:`fontTools.misc.xmlWriter.XMLWriter`. .. code:: python writer = xmlWriter.XMLWriter(sys.stdout) tt["CFF "].cff[0].GlobalSubrs.toXML(writer) """ ...
Write the subroutines index into XML representation onto the given :class:`fontTools.misc.xmlWriter.XMLWriter`. .. code:: python writer = xmlWriter.XMLWriter(sys.stdout) tt["CFF "].cff[0].GlobalSubrs.toXML(writer)
toXML
python
fonttools/fonttools
Lib/fontTools/cffLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cffLib/__init__.py
MIT
def parseEncodingSupplement(file, encoding, strings): """ Parse the CFF Encoding supplement data: - nSups: number of supplementary mappings - each mapping: (code, SID) pair and apply them to the `encoding` list in place. """ nSups = readCard8(file) for _ in range(nSups): code...
Parse the CFF Encoding supplement data: - nSups: number of supplementary mappings - each mapping: (code, SID) pair and apply them to the `encoding` list in place.
parseEncodingSupplement
python
fonttools/fonttools
Lib/fontTools/cffLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cffLib/__init__.py
MIT
def parseEncoding0(charset, file): """ Format 0: simple list of codes. After reading the base table, optionally parse the supplement. """ nCodes = readCard8(file) encoding = [".notdef"] * 256 for glyphID in range(1, nCodes + 1): code = readCard8(file) if code != 0: ...
Format 0: simple list of codes. After reading the base table, optionally parse the supplement.
parseEncoding0
python
fonttools/fonttools
Lib/fontTools/cffLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cffLib/__init__.py
MIT
def arg_delta_blend(self, value): """A delta list with blend lists has to be *all* blend lists. The value is a list is arranged as follows:: [ [V0, d0..dn] [V1, d0..dn] ... [Vm, d0..dn] ...
A delta list with blend lists has to be *all* blend lists. The value is a list is arranged as follows:: [ [V0, d0..dn] [V1, d0..dn] ... [Vm, d0..dn] ] ``V`` is the absolute ...
arg_delta_blend
python
fonttools/fonttools
Lib/fontTools/cffLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cffLib/__init__.py
MIT
def populateCOLRv0( table: ot.COLR, colorGlyphsV0: _ColorGlyphsV0Dict, glyphMap: Optional[Mapping[str, int]] = None, ): """Build v0 color layers and add to existing COLR table. Args: table: a raw ``otTables.COLR()`` object (not ttLib's ``table_C_O_L_R_``). colorGlyphsV0: map of base...
Build v0 color layers and add to existing COLR table. Args: table: a raw ``otTables.COLR()`` object (not ttLib's ``table_C_O_L_R_``). colorGlyphsV0: map of base glyph names to lists of (layer glyph names, color palette index) tuples. Can be empty. glyphMap: a map from glyph name...
populateCOLRv0
python
fonttools/fonttools
Lib/fontTools/colorLib/builder.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/colorLib/builder.py
MIT
def buildCOLR( colorGlyphs: _ColorGlyphsDict, version: Optional[int] = None, *, glyphMap: Optional[Mapping[str, int]] = None, varStore: Optional[ot.VarStore] = None, varIndexMap: Optional[ot.DeltaSetIndexMap] = None, clipBoxes: Optional[Dict[str, _ClipBoxInput]] = None, allowLayerReuse: ...
Build COLR table from color layers mapping. Args: colorGlyphs: map of base glyph name to, either list of (layer glyph name, color palette index) tuples for COLRv0; or a single ``Paint`` (dict) or list of ``Paint`` for COLRv1. version: the version of COLR table. If None, the...
buildCOLR
python
fonttools/fonttools
Lib/fontTools/colorLib/builder.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/colorLib/builder.py
MIT
def buildCPAL( palettes: Sequence[Sequence[Tuple[float, float, float, float]]], paletteTypes: Optional[Sequence[ColorPaletteType]] = None, paletteLabels: Optional[Sequence[_OptionalLocalizedString]] = None, paletteEntryLabels: Optional[Sequence[_OptionalLocalizedString]] = None, nameTable: Optional[...
Build CPAL table from list of color palettes. Args: palettes: list of lists of colors encoded as tuples of (R, G, B, A) floats in the range [0..1]. paletteTypes: optional list of ColorPaletteType, one for each palette. paletteLabels: optional list of palette labels. Each lable c...
buildCPAL
python
fonttools/fonttools
Lib/fontTools/colorLib/builder.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/colorLib/builder.py
MIT
def _main(args=None): """Convert a UFO font from cubic to quadratic curves""" parser = argparse.ArgumentParser(prog="cu2qu") parser.add_argument("--version", action="version", version=fontTools.__version__) parser.add_argument( "infiles", nargs="+", metavar="INPUT", help=...
Convert a UFO font from cubic to quadratic curves
_main
python
fonttools/fonttools
Lib/fontTools/cu2qu/cli.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/cli.py
MIT
def split_cubic_into_n_iter(p0, p1, p2, p3, n): """Split a cubic Bezier into n equal parts. Splits the curve into `n` equal parts by curve time. (t=0..1/n, t=1/n..2/n, ...) Args: p0 (complex): Start point of curve. p1 (complex): First handle of curve. p2 (complex): Second handl...
Split a cubic Bezier into n equal parts. Splits the curve into `n` equal parts by curve time. (t=0..1/n, t=1/n..2/n, ...) Args: p0 (complex): Start point of curve. p1 (complex): First handle of curve. p2 (complex): Second handle of curve. p3 (complex): End point of curve. ...
split_cubic_into_n_iter
python
fonttools/fonttools
Lib/fontTools/cu2qu/cu2qu.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/cu2qu.py
MIT
def split_cubic_into_two(p0, p1, p2, p3): """Split a cubic Bezier into two equal parts. Splits the curve into two equal parts at t = 0.5 Args: p0 (complex): Start point of curve. p1 (complex): First handle of curve. p2 (complex): Second handle of curve. p3 (complex): End po...
Split a cubic Bezier into two equal parts. Splits the curve into two equal parts at t = 0.5 Args: p0 (complex): Start point of curve. p1 (complex): First handle of curve. p2 (complex): Second handle of curve. p3 (complex): End point of curve. Returns: tuple: Two cu...
split_cubic_into_two
python
fonttools/fonttools
Lib/fontTools/cu2qu/cu2qu.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/cu2qu.py
MIT
def split_cubic_into_three(p0, p1, p2, p3): """Split a cubic Bezier into three equal parts. Splits the curve into three equal parts at t = 1/3 and t = 2/3 Args: p0 (complex): Start point of curve. p1 (complex): First handle of curve. p2 (complex): Second handle of curve. p3...
Split a cubic Bezier into three equal parts. Splits the curve into three equal parts at t = 1/3 and t = 2/3 Args: p0 (complex): Start point of curve. p1 (complex): First handle of curve. p2 (complex): Second handle of curve. p3 (complex): End point of curve. Returns: ...
split_cubic_into_three
python
fonttools/fonttools
Lib/fontTools/cu2qu/cu2qu.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/cu2qu.py
MIT
def cubic_approx_control(t, p0, p1, p2, p3): """Approximate a cubic Bezier using a quadratic one. Args: t (double): Position of control point. p0 (complex): Start point of curve. p1 (complex): First handle of curve. p2 (complex): Second handle of curve. p3 (complex): End...
Approximate a cubic Bezier using a quadratic one. Args: t (double): Position of control point. p0 (complex): Start point of curve. p1 (complex): First handle of curve. p2 (complex): Second handle of curve. p3 (complex): End point of curve. Returns: complex: Loca...
cubic_approx_control
python
fonttools/fonttools
Lib/fontTools/cu2qu/cu2qu.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/cu2qu.py
MIT
def calc_intersect(a, b, c, d): """Calculate the intersection of two lines. Args: a (complex): Start point of first line. b (complex): End point of first line. c (complex): Start point of second line. d (complex): End point of second line. Returns: complex: Location...
Calculate the intersection of two lines. Args: a (complex): Start point of first line. b (complex): End point of first line. c (complex): Start point of second line. d (complex): End point of second line. Returns: complex: Location of intersection if one present, ``comp...
calc_intersect
python
fonttools/fonttools
Lib/fontTools/cu2qu/cu2qu.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/cu2qu.py
MIT
def cubic_farthest_fit_inside(p0, p1, p2, p3, tolerance): """Check if a cubic Bezier lies within a given distance of the origin. "Origin" means *the* origin (0,0), not the start of the curve. Note that no checks are made on the start and end positions of the curve; this function only checks the inside ...
Check if a cubic Bezier lies within a given distance of the origin. "Origin" means *the* origin (0,0), not the start of the curve. Note that no checks are made on the start and end positions of the curve; this function only checks the inside of the curve. Args: p0 (complex): Start point of cur...
cubic_farthest_fit_inside
python
fonttools/fonttools
Lib/fontTools/cu2qu/cu2qu.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/cu2qu.py
MIT
def curves_to_quadratic(curves, max_errors, all_quadratic=True): """Return quadratic Bezier splines approximating the input cubic Beziers. Args: curves: A sequence of *n* curves, each curve being a sequence of four 2D tuples. max_errors: A sequence of *n* floats representing the max...
Return quadratic Bezier splines approximating the input cubic Beziers. Args: curves: A sequence of *n* curves, each curve being a sequence of four 2D tuples. max_errors: A sequence of *n* floats representing the maximum permissible deviation from each of the cubic Bezier cur...
curves_to_quadratic
python
fonttools/fonttools
Lib/fontTools/cu2qu/cu2qu.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/cu2qu.py
MIT
def zip(*args): """Ensure each argument to zip has the same length. Also make sure a list is returned for python 2/3 compatibility. """ if len(set(len(a) for a in args)) != 1: raise UnequalZipLengthsError(*args) return list(_zip(*args))
Ensure each argument to zip has the same length. Also make sure a list is returned for python 2/3 compatibility.
zip
python
fonttools/fonttools
Lib/fontTools/cu2qu/ufo.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/ufo.py
MIT
def _get_segments(glyph): """Get a glyph's segments as extracted by GetSegmentsPen.""" pen = GetSegmentsPen() # glyph.draw(pen) # We can't simply draw the glyph with the pen, but we must initialize the # PointToSegmentPen explicitly with outputImpliedClosingLine=True. # By default PointToSegmen...
Get a glyph's segments as extracted by GetSegmentsPen.
_get_segments
python
fonttools/fonttools
Lib/fontTools/cu2qu/ufo.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/ufo.py
MIT
def _set_segments(glyph, segments, reverse_direction): """Draw segments as extracted by GetSegmentsPen back to a glyph.""" glyph.clearContours() pen = glyph.getPen() if reverse_direction: pen = ReverseContourPen(pen) for tag, args in segments: if tag == "move": pen.moveT...
Draw segments as extracted by GetSegmentsPen back to a glyph.
_set_segments
python
fonttools/fonttools
Lib/fontTools/cu2qu/ufo.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/ufo.py
MIT
def _segments_to_quadratic(segments, max_err, stats, all_quadratic=True): """Return quadratic approximations of cubic segments.""" assert all(s[0] == "curve" for s in segments), "Non-cubic given to convert" new_points = curves_to_quadratic([s[1] for s in segments], max_err, all_quadratic) n = len(new_...
Return quadratic approximations of cubic segments.
_segments_to_quadratic
python
fonttools/fonttools
Lib/fontTools/cu2qu/ufo.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/ufo.py
MIT
def _glyphs_to_quadratic(glyphs, max_err, reverse_direction, stats, all_quadratic=True): """Do the actual conversion of a set of compatible glyphs, after arguments have been set up. Return True if the glyphs were modified, else return False. """ try: segments_by_location = zip(*[_get_segme...
Do the actual conversion of a set of compatible glyphs, after arguments have been set up. Return True if the glyphs were modified, else return False.
_glyphs_to_quadratic
python
fonttools/fonttools
Lib/fontTools/cu2qu/ufo.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/ufo.py
MIT
def glyphs_to_quadratic( glyphs, max_err=None, reverse_direction=False, stats=None, all_quadratic=True ): """Convert the curves of a set of compatible of glyphs to quadratic. All curves will be converted to quadratic at once, ensuring interpolation compatibility. If this is not required, calling glyphs...
Convert the curves of a set of compatible of glyphs to quadratic. All curves will be converted to quadratic at once, ensuring interpolation compatibility. If this is not required, calling glyphs_to_quadratic with one glyph at a time may yield slightly more optimized results. Return True if glyphs were...
glyphs_to_quadratic
python
fonttools/fonttools
Lib/fontTools/cu2qu/ufo.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/ufo.py
MIT
def fonts_to_quadratic( fonts, max_err_em=None, max_err=None, reverse_direction=False, stats=None, dump_stats=False, remember_curve_type=True, all_quadratic=True, ): """Convert the curves of a collection of fonts to quadratic. All curves will be converted to quadratic at once, e...
Convert the curves of a collection of fonts to quadratic. All curves will be converted to quadratic at once, ensuring interpolation compatibility. If this is not required, calling fonts_to_quadratic with one font at a time may yield slightly more optimized results. Return the set of modified glyph nam...
fonts_to_quadratic
python
fonttools/fonttools
Lib/fontTools/cu2qu/ufo.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/cu2qu/ufo.py
MIT
def defaultMakeInstanceFilename( doc: DesignSpaceDocument, instance: InstanceDescriptor, statNames: StatNames ) -> str: """Default callable to synthesize an instance filename when makeNames=True, for instances that don't specify an instance name in the designspace. This part of the name generation can b...
Default callable to synthesize an instance filename when makeNames=True, for instances that don't specify an instance name in the designspace. This part of the name generation can be overriden because it's not specified by the STAT table.
defaultMakeInstanceFilename
python
fonttools/fonttools
Lib/fontTools/designspaceLib/split.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/split.py
MIT
def splitInterpolable( doc: DesignSpaceDocument, makeNames: bool = True, expandLocations: bool = True, makeInstanceFilename: MakeInstanceFilenameCallable = defaultMakeInstanceFilename, ) -> Iterator[Tuple[SimpleLocationDict, DesignSpaceDocument]]: """Split the given DS5 into several interpolable sub...
Split the given DS5 into several interpolable sub-designspaces. There are as many interpolable sub-spaces as there are combinations of discrete axis values. E.g. with axes: - italic (discrete) Upright or Italic - style (discrete) Sans or Serif - weight (continuous) 100 to 900 T...
splitInterpolable
python
fonttools/fonttools
Lib/fontTools/designspaceLib/split.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/split.py
MIT
def splitVariableFonts( doc: DesignSpaceDocument, makeNames: bool = False, expandLocations: bool = False, makeInstanceFilename: MakeInstanceFilenameCallable = defaultMakeInstanceFilename, ) -> Iterator[Tuple[str, DesignSpaceDocument]]: """Convert each variable font listed in this document into a sta...
Convert each variable font listed in this document into a standalone designspace. This can be used to compile all the variable fonts from a format 5 designspace using tools that can only deal with 1 VF at a time. Args: - ``makeNames``: Whether to compute the instance family and style names us...
splitVariableFonts
python
fonttools/fonttools
Lib/fontTools/designspaceLib/split.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/split.py
MIT
def convert5to4( doc: DesignSpaceDocument, ) -> Dict[str, DesignSpaceDocument]: """Convert each variable font listed in this document into a standalone format 4 designspace. This can be used to compile all the variable fonts from a format 5 designspace using tools that only know about format 4. .. ...
Convert each variable font listed in this document into a standalone format 4 designspace. This can be used to compile all the variable fonts from a format 5 designspace using tools that only know about format 4. .. versionadded:: 5.0
convert5to4
python
fonttools/fonttools
Lib/fontTools/designspaceLib/split.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/split.py
MIT
def getStatNames( doc: DesignSpaceDocument, userLocation: SimpleLocationDict ) -> StatNames: """Compute the family, style, PostScript names of the given ``userLocation`` using the document's STAT information. Also computes localizations. If not enough STAT data is available for a given name, eithe...
Compute the family, style, PostScript names of the given ``userLocation`` using the document's STAT information. Also computes localizations. If not enough STAT data is available for a given name, either its dict of localized names will be empty (family and style names), or the name will be None (...
getStatNames
python
fonttools/fonttools
Lib/fontTools/designspaceLib/statNames.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/statNames.py
MIT
def _getSortedAxisLabels( axes: list[Union[AxisDescriptor, DiscreteAxisDescriptor]], ) -> Dict[str, list[AxisLabelDescriptor]]: """Returns axis labels sorted by their ordering, with unordered ones appended as they are listed.""" # First, get the axis labels with explicit ordering... sortedAxes = so...
Returns axis labels sorted by their ordering, with unordered ones appended as they are listed.
_getSortedAxisLabels
python
fonttools/fonttools
Lib/fontTools/designspaceLib/statNames.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/statNames.py
MIT
def _getRibbiStyle( self: DesignSpaceDocument, userLocation: SimpleLocationDict ) -> Tuple[RibbiStyleName, SimpleLocationDict]: """Compute the RIBBI style name of the given user location, return the location of the matching Regular in the RIBBI group. .. versionadded:: 5.0 """ regularUserLocati...
Compute the RIBBI style name of the given user location, return the location of the matching Regular in the RIBBI group. .. versionadded:: 5.0
_getRibbiStyle
python
fonttools/fonttools
Lib/fontTools/designspaceLib/statNames.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/statNames.py
MIT
def posix(path): """Normalize paths using forward slash to work also on Windows.""" new_path = posixpath.join(*path.split(os.path.sep)) if path.startswith("/"): # The above transformation loses absolute paths new_path = "/" + new_path elif path.startswith(r"\\"): # The above tran...
Normalize paths using forward slash to work also on Windows.
posix
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def posixpath_property(private_name): """Generate a propery that holds a path always using forward slashes.""" def getter(self): # Normal getter return getattr(self, private_name) def setter(self, value): # The setter rewrites paths using forward slashes if value is not Non...
Generate a propery that holds a path always using forward slashes.
posixpath_property
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def getFullDesignLocation(self, doc: "DesignSpaceDocument") -> SimpleLocationDict: """Get the complete design location of this source, from its :attr:`designLocation` and the document's axis defaults. .. versionadded:: 5.0 """ result: SimpleLocationDict = {} for axis in ...
Get the complete design location of this source, from its :attr:`designLocation` and the document's axis defaults. .. versionadded:: 5.0
getFullDesignLocation
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def evaluateConditions(conditions, location): """Return True if all the conditions matches the given location. - If a condition has no minimum, check for < maximum. - If a condition has no maximum, check for > minimum. """ for cd in conditions: value = location[cd["name"]] if cd.get...
Return True if all the conditions matches the given location. - If a condition has no minimum, check for < maximum. - If a condition has no maximum, check for > minimum.
evaluateConditions
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def processRules(rules, location, glyphNames): """Apply these rules at this location to these glyphnames. Return a new list of glyphNames with substitutions applied. - rule order matters """ newNames = [] for rule in rules: if evaluateRule(rule, location): for name in glyph...
Apply these rules at this location to these glyphnames. Return a new list of glyphNames with substitutions applied. - rule order matters
processRules
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def clearLocation(self, axisName: Optional[str] = None): """Clear all location-related fields. Ensures that :attr:``designLocation`` and :attr:``userLocation`` are dictionaries (possibly empty if clearing everything). In order to update the location of this instance wholesale, a user ...
Clear all location-related fields. Ensures that :attr:``designLocation`` and :attr:``userLocation`` are dictionaries (possibly empty if clearing everything). In order to update the location of this instance wholesale, a user should first clear all the fields, then change the field(s) fo...
clearLocation
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def getLocationLabelDescriptor( self, doc: "DesignSpaceDocument" ) -> Optional[LocationLabelDescriptor]: """Get the :class:`LocationLabelDescriptor` instance that matches this instances's :attr:`locationLabel`. Raises if the named label can't be found. .. versionadded:: 5.0...
Get the :class:`LocationLabelDescriptor` instance that matches this instances's :attr:`locationLabel`. Raises if the named label can't be found. .. versionadded:: 5.0
getLocationLabelDescriptor
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def getFullDesignLocation( self, doc: "DesignSpaceDocument" ) -> AnisotropicLocationDict: """Get the complete design location of this instance, by combining data from the various location fields, default axis values and mappings, and top-level location labels. The source of ...
Get the complete design location of this instance, by combining data from the various location fields, default axis values and mappings, and top-level location labels. The source of truth for this instance's location is determined for each axis independently by taking the first not-None...
getFullDesignLocation
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def map_forward(self, v): """Maps value from axis mapping's input (user) to output (design).""" from fontTools.varLib.models import piecewiseLinearMap if not self.map: return v return piecewiseLinearMap(v, {k: v for k, v in self.map})
Maps value from axis mapping's input (user) to output (design).
map_forward
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def map_backward(self, v): """Maps value from axis mapping's output (design) to input (user).""" from fontTools.varLib.models import piecewiseLinearMap if isinstance(v, tuple): v = v[0] if not self.map: return v return piecewiseLinearMap(v, {v: k for k, v...
Maps value from axis mapping's output (design) to input (user).
map_backward
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def map_backward(self, value): """Maps value from axis mapping's output to input. Returns value unchanged if no mapping entry is found. Note: for discrete axes, each value must have its mapping entry, if you intend that value to be mapped. """ if isinstance(value, tuple...
Maps value from axis mapping's output to input. Returns value unchanged if no mapping entry is found. Note: for discrete axes, each value must have its mapping entry, if you intend that value to be mapped.
map_backward
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def getFullUserLocation(self, doc: "DesignSpaceDocument") -> SimpleLocationDict: """Get the complete user location of this label, by combining data from the explicit user location and default axis values. .. versionadded:: 5.0 """ return { axis.name: self.userLocatio...
Get the complete user location of this label, by combining data from the explicit user location and default axis values. .. versionadded:: 5.0
getFullUserLocation
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def _getEffectiveFormatTuple(self): """Try to use the version specified in the document, or a sufficiently recent version to be able to encode what the document contains. """ minVersion = self.documentObject.formatTuple if ( any( hasattr(axis, "values"...
Try to use the version specified in the document, or a sufficiently recent version to be able to encode what the document contains.
_getEffectiveFormatTuple
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def locationFromElement(self, element): """Read a nested ``<location>`` element inside the given ``element``. .. versionchanged:: 5.0 Return a tuple of (designLocation, userLocation) """ elementLocation = (None, None) for locationElement in element.findall(".location"...
Read a nested ``<location>`` element inside the given ``element``. .. versionchanged:: 5.0 Return a tuple of (designLocation, userLocation)
locationFromElement
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def readLocationElement(self, locationElement): """Read a ``<location>`` element. .. versionchanged:: 5.0 Return a tuple of (designLocation, userLocation) """ if self._strictAxisNames and not self.documentObject.axes: raise DesignSpaceDocumentError("No axes define...
Read a ``<location>`` element. .. versionchanged:: 5.0 Return a tuple of (designLocation, userLocation)
readLocationElement
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def readGlyphElement(self, glyphElement, instanceObject): """ Read the glyph element, which could look like either one of these: .. code-block:: xml <glyph name="b" unicode="0x62"/> <glyph name="b"/> <glyph name="b"> <master location="locat...
Read the glyph element, which could look like either one of these: .. code-block:: xml <glyph name="b" unicode="0x62"/> <glyph name="b"/> <glyph name="b"> <master location="location-token-bbb" source="master-token-aaa2"/> <master g...
readGlyphElement
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def readLib(self): """Read the lib element for the whole document.""" for libElement in self.root.findall(".lib"): self.documentObject.lib = plistlib.fromtree(libElement[0])
Read the lib element for the whole document.
readLib
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def fromfile(cls, path, readerClass=None, writerClass=None): """Read a designspace file from ``path`` and return a new instance of :class:. """ self = cls(readerClass=readerClass, writerClass=writerClass) self.read(path) return self
Read a designspace file from ``path`` and return a new instance of :class:.
fromfile
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def tostring(self, encoding=None): """Returns the designspace as a string. Default encoding ``utf-8``.""" if encoding is str or (encoding is not None and encoding.lower() == "unicode"): f = StringIO() xml_declaration = False elif encoding is None or encoding == "utf-8": ...
Returns the designspace as a string. Default encoding ``utf-8``.
tostring
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def read(self, path): """Read a designspace file from ``path`` and populates the fields of ``self`` with the data. """ if hasattr(path, "__fspath__"): # support os.PathLike objects path = path.__fspath__() self.path = path self.filename = os.path.basename(pat...
Read a designspace file from ``path`` and populates the fields of ``self`` with the data.
read
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def updatePaths(self): """ Right before we save we need to identify and respond to the following situations: In each descriptor, we have to do the right thing for the filename attribute. :: case 1. descriptor.filename == None descriptor.path == None ...
Right before we save we need to identify and respond to the following situations: In each descriptor, we have to do the right thing for the filename attribute. :: case 1. descriptor.filename == None descriptor.path == None -- action: ...
updatePaths
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def addSourceDescriptor(self, **kwargs): """Instantiate a new :class:`SourceDescriptor` using the given ``kwargs`` and add it to ``doc.sources``. """ source = self.writerClass.sourceDescriptorClass(**kwargs) self.addSource(source) return source
Instantiate a new :class:`SourceDescriptor` using the given ``kwargs`` and add it to ``doc.sources``.
addSourceDescriptor
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def addInstanceDescriptor(self, **kwargs): """Instantiate a new :class:`InstanceDescriptor` using the given ``kwargs`` and add it to :attr:`instances`. """ instance = self.writerClass.instanceDescriptorClass(**kwargs) self.addInstance(instance) return instance
Instantiate a new :class:`InstanceDescriptor` using the given ``kwargs`` and add it to :attr:`instances`.
addInstanceDescriptor
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def addAxisDescriptor(self, **kwargs): """Instantiate a new :class:`AxisDescriptor` using the given ``kwargs`` and add it to :attr:`axes`. The axis will be and instance of :class:`DiscreteAxisDescriptor` if the ``kwargs`` provide a ``value``, or a :class:`AxisDescriptor` otherwise. ...
Instantiate a new :class:`AxisDescriptor` using the given ``kwargs`` and add it to :attr:`axes`. The axis will be and instance of :class:`DiscreteAxisDescriptor` if the ``kwargs`` provide a ``value``, or a :class:`AxisDescriptor` otherwise.
addAxisDescriptor
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def addAxisMappingDescriptor(self, **kwargs): """Instantiate a new :class:`AxisMappingDescriptor` using the given ``kwargs`` and add it to :attr:`rules`. """ axisMapping = self.writerClass.axisMappingDescriptorClass(**kwargs) self.addAxisMapping(axisMapping) return axisMa...
Instantiate a new :class:`AxisMappingDescriptor` using the given ``kwargs`` and add it to :attr:`rules`.
addAxisMappingDescriptor
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def addRuleDescriptor(self, **kwargs): """Instantiate a new :class:`RuleDescriptor` using the given ``kwargs`` and add it to :attr:`rules`. """ rule = self.writerClass.ruleDescriptorClass(**kwargs) self.addRule(rule) return rule
Instantiate a new :class:`RuleDescriptor` using the given ``kwargs`` and add it to :attr:`rules`.
addRuleDescriptor
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def addVariableFontDescriptor(self, **kwargs): """Instantiate a new :class:`VariableFontDescriptor` using the given ``kwargs`` and add it to :attr:`variableFonts`. .. versionadded:: 5.0 """ variableFont = self.writerClass.variableFontDescriptorClass(**kwargs) self.addVar...
Instantiate a new :class:`VariableFontDescriptor` using the given ``kwargs`` and add it to :attr:`variableFonts`. .. versionadded:: 5.0
addVariableFontDescriptor
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def addLocationLabelDescriptor(self, **kwargs): """Instantiate a new :class:`LocationLabelDescriptor` using the given ``kwargs`` and add it to :attr:`locationLabels`. .. versionadded:: 5.0 """ locationLabel = self.writerClass.locationLabelDescriptorClass(**kwargs) self.a...
Instantiate a new :class:`LocationLabelDescriptor` using the given ``kwargs`` and add it to :attr:`locationLabels`. .. versionadded:: 5.0
addLocationLabelDescriptor
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def newDefaultLocation(self): """Return a dict with the default location in design space coordinates.""" # Without OrderedDict, output XML would be non-deterministic. # https://github.com/LettError/designSpaceDocument/issues/10 loc = collections.OrderedDict() for axisDescriptor i...
Return a dict with the default location in design space coordinates.
newDefaultLocation
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def labelForUserLocation( self, userLocation: SimpleLocationDict ) -> Optional[LocationLabelDescriptor]: """Return the :class:`LocationLabel` that matches the given ``userLocation``, or ``None`` if no such label exists. .. versionadded:: 5.0 """ return next( ...
Return the :class:`LocationLabel` that matches the given ``userLocation``, or ``None`` if no such label exists. .. versionadded:: 5.0
labelForUserLocation
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def updateFilenameFromPath(self, masters=True, instances=True, force=False): """Set a descriptor filename attr from the path and this document path. If the filename attribute is not None: skip it. """ if masters: for descriptor in self.sources: if descriptor....
Set a descriptor filename attr from the path and this document path. If the filename attribute is not None: skip it.
updateFilenameFromPath
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def getAxisOrder(self): """Return a list of axis names, in the same order as defined in the document.""" names = [] for axisDescriptor in self.axes: names.append(axisDescriptor.name) return names
Return a list of axis names, in the same order as defined in the document.
getAxisOrder
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def getLocationLabel(self, name: str) -> Optional[LocationLabelDescriptor]: """Return the top-level location label with the given ``name``, or ``None`` if no such label exists. .. versionadded:: 5.0 """ for label in self.locationLabels: if label.name == name: ...
Return the top-level location label with the given ``name``, or ``None`` if no such label exists. .. versionadded:: 5.0
getLocationLabel
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def map_forward(self, userLocation: SimpleLocationDict) -> SimpleLocationDict: """Map a user location to a design location. Assume that missing coordinates are at the default location for that axis. Note: the output won't be anisotropic, only the xvalue is set. .. versionadded:: 5.0 ...
Map a user location to a design location. Assume that missing coordinates are at the default location for that axis. Note: the output won't be anisotropic, only the xvalue is set. .. versionadded:: 5.0
map_forward
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def map_backward( self, designLocation: AnisotropicLocationDict ) -> SimpleLocationDict: """Map a design location to a user location. Assume that missing coordinates are at the default location for that axis. When the input has anisotropic locations, only the xvalue is used. ...
Map a design location to a user location. Assume that missing coordinates are at the default location for that axis. When the input has anisotropic locations, only the xvalue is used. .. versionadded:: 5.0
map_backward
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def findDefault(self): """Set and return SourceDescriptor at the default location or None. The default location is the set of all `default` values in user space of all axes. This function updates the document's :attr:`default` value. .. versionchanged:: 5.0 Allow th...
Set and return SourceDescriptor at the default location or None. The default location is the set of all `default` values in user space of all axes. This function updates the document's :attr:`default` value. .. versionchanged:: 5.0 Allow the default source to not specify so...
findDefault
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def normalizeLocation(self, location): """Return a dict with normalized axis values.""" from fontTools.varLib.models import normalizeValue new = {} for axis in self.axes: if axis.name not in location: # skipping this dimension it seems continu...
Return a dict with normalized axis values.
normalizeLocation
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def normalize(self): """ Normalise the geometry of this designspace: - scale all the locations of all masters and instances to the -1 - 0 - 1 value. - we need the axis data to do the scaling, so we do those last. """ # masters for item in self.sources: ...
Normalise the geometry of this designspace: - scale all the locations of all masters and instances to the -1 - 0 - 1 value. - we need the axis data to do the scaling, so we do those last.
normalize
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def loadSourceFonts(self, opener, **kwargs): """Ensure SourceDescriptor.font attributes are loaded, and return list of fonts. Takes a callable which initializes a new font object (e.g. TTFont, or defcon.Font, etc.) from the SourceDescriptor.path, and sets the SourceDescriptor.font attri...
Ensure SourceDescriptor.font attributes are loaded, and return list of fonts. Takes a callable which initializes a new font object (e.g. TTFont, or defcon.Font, etc.) from the SourceDescriptor.path, and sets the SourceDescriptor.font attribute. If the font attribute is already not None,...
loadSourceFonts
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def formatTuple(self): """Return the formatVersion as a tuple of (major, minor). .. versionadded:: 5.0 """ if self.formatVersion is None: return (5, 0) numbers = (int(i) for i in self.formatVersion.split(".")) major = next(numbers) minor = next(number...
Return the formatVersion as a tuple of (major, minor). .. versionadded:: 5.0
formatTuple
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def getVariableFonts(self) -> List[VariableFontDescriptor]: """Return all variable fonts defined in this document, or implicit variable fonts that can be built from the document's continuous axes. In the case of Designspace documents before version 5, the whole document was implicitly d...
Return all variable fonts defined in this document, or implicit variable fonts that can be built from the document's continuous axes. In the case of Designspace documents before version 5, the whole document was implicitly describing a variable font that covers the whole space. ...
getVariableFonts
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def deepcopyExceptFonts(self): """Allow deep-copying a DesignSpace document without deep-copying attached UFO fonts or TTFont objects. The :attr:`font` attribute is shared by reference between the original and the copy. .. versionadded:: 5.0 """ fonts = [source.font for ...
Allow deep-copying a DesignSpace document without deep-copying attached UFO fonts or TTFont objects. The :attr:`font` attribute is shared by reference between the original and the copy. .. versionadded:: 5.0
deepcopyExceptFonts
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def main(args=None): """Roundtrip .designspace file through the DesignSpaceDocument class""" if args is None: import sys args = sys.argv[1:] from argparse import ArgumentParser parser = ArgumentParser(prog="designspaceLib", description=main.__doc__) parser.add_argument("input") ...
Roundtrip .designspace file through the DesignSpaceDocument class
main
python
fonttools/fonttools
Lib/fontTools/designspaceLib/__init__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/designspaceLib/__init__.py
MIT
def add_range(self, start, end, glyphs): """Add a range (e.g. ``A-Z``) to the class. ``start`` and ``end`` are either :class:`GlyphName` objects or strings representing the start and end glyphs in the class, and ``glyphs`` is the full list of :class:`GlyphName` objects in the range.""" ...
Add a range (e.g. ``A-Z``) to the class. ``start`` and ``end`` are either :class:`GlyphName` objects or strings representing the start and end glyphs in the class, and ``glyphs`` is the full list of :class:`GlyphName` objects in the range.
add_range
python
fonttools/fonttools
Lib/fontTools/feaLib/ast.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py
MIT
def add_cid_range(self, start, end, glyphs): """Add a range to the class by glyph ID. ``start`` and ``end`` are the initial and final IDs, and ``glyphs`` is the full list of :class:`GlyphName` objects in the range.""" if self.curr < len(self.glyphs): self.original.extend(self...
Add a range to the class by glyph ID. ``start`` and ``end`` are the initial and final IDs, and ``glyphs`` is the full list of :class:`GlyphName` objects in the range.
add_cid_range
python
fonttools/fonttools
Lib/fontTools/feaLib/ast.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py
MIT
def add_class(self, gc): """Add glyphs from the given :class:`GlyphClassName` object to the class.""" if self.curr < len(self.glyphs): self.original.extend(self.glyphs[self.curr :]) self.original.append(gc) self.glyphs.extend(gc.glyphSet()) self.curr = len(sel...
Add glyphs from the given :class:`GlyphClassName` object to the class.
add_class
python
fonttools/fonttools
Lib/fontTools/feaLib/ast.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py
MIT
def build(self, builder): """Call the ``start_feature`` callback on the builder object, visit all the statements in this feature, and then call ``end_feature``.""" builder.start_feature(self.location, self.name, self.use_extension) # language exclude_dflt statements modify builder.featur...
Call the ``start_feature`` callback on the builder object, visit all the statements in this feature, and then call ``end_feature``.
build
python
fonttools/fonttools
Lib/fontTools/feaLib/ast.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py
MIT
def addDefinition(self, definition): """Add a :class:`MarkClassDefinition` statement to this mark class.""" assert isinstance(definition, MarkClassDefinition) self.definitions.append(definition) for glyph in definition.glyphSet(): if glyph in self.glyphs: othe...
Add a :class:`MarkClassDefinition` statement to this mark class.
addDefinition
python
fonttools/fonttools
Lib/fontTools/feaLib/ast.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py
MIT
def build(self, builder): """Calls the builder object's ``add_chain_context_pos`` callback on each rule context.""" for prefix, glyphs, suffix in self.chainContexts: prefix = [p.glyphSet() for p in prefix] glyphs = [g.glyphSet() for g in glyphs] suffix = [s.gl...
Calls the builder object's ``add_chain_context_pos`` callback on each rule context.
build
python
fonttools/fonttools
Lib/fontTools/feaLib/ast.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py
MIT
def build(self, builder): """Calls the builder object's ``add_chain_context_subst`` callback on each rule context.""" for prefix, glyphs, suffix in self.chainContexts: prefix = [p.glyphSet() for p in prefix] glyphs = [g.glyphSet() for g in glyphs] suffix = [s....
Calls the builder object's ``add_chain_context_subst`` callback on each rule context.
build
python
fonttools/fonttools
Lib/fontTools/feaLib/ast.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py
MIT
def build(self, builder): """Calls a callback on the builder object: * If the rule is enumerated, calls ``add_specific_pair_pos`` on each combination of first and second glyphs. * If the glyphs are both single :class:`GlyphName` objects, calls ``add_specific_pair_pos``. ...
Calls a callback on the builder object: * If the rule is enumerated, calls ``add_specific_pair_pos`` on each combination of first and second glyphs. * If the glyphs are both single :class:`GlyphName` objects, calls ``add_specific_pair_pos``. * Else, calls ``add_class_pair_po...
build
python
fonttools/fonttools
Lib/fontTools/feaLib/ast.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/ast.py
MIT
def addOpenTypeFeaturesFromString( font, features, filename=None, tables=None, debug=False ): """Add features from a string to a font. Note that this replaces any features currently present. Args: font (feaLib.ttLib.TTFont): The font object. features: A string containing feature code. ...
Add features from a string to a font. Note that this replaces any features currently present. Args: font (feaLib.ttLib.TTFont): The font object. features: A string containing feature code. filename: The directory containing ``filename`` is used as the root of relative ``incl...
addOpenTypeFeaturesFromString
python
fonttools/fonttools
Lib/fontTools/feaLib/builder.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/builder.py
MIT
def find_lookup_builders_(self, lookups): """Helper for building chain contextual substitutions Given a list of lookup names, finds the LookupBuilder for each name. If an input name is None, it gets mapped to a None LookupBuilder. """ lookup_builders = [] for lookuplist ...
Helper for building chain contextual substitutions Given a list of lookup names, finds the LookupBuilder for each name. If an input name is None, it gets mapped to a None LookupBuilder.
find_lookup_builders_
python
fonttools/fonttools
Lib/fontTools/feaLib/builder.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/builder.py
MIT
def add_to_cv_num_named_params(self, tag): """Adds new items to ``self.cv_num_named_params_`` or increments the count of existing items.""" if tag in self.cv_num_named_params_: self.cv_num_named_params_[tag] += 1 else: self.cv_num_named_params_[tag] = 1
Adds new items to ``self.cv_num_named_params_`` or increments the count of existing items.
add_to_cv_num_named_params
python
fonttools/fonttools
Lib/fontTools/feaLib/builder.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/builder.py
MIT
def __init__(self, featurefile, *, includeDir=None): """Initializes an IncludingLexer. Behavior: If includeDir is passed, it will be used to determine the top-level include directory to use for all encountered include statements. If it is not passed, ``os.path.dirnam...
Initializes an IncludingLexer. Behavior: If includeDir is passed, it will be used to determine the top-level include directory to use for all encountered include statements. If it is not passed, ``os.path.dirname(featurefile)`` will be considered the include dire...
__init__
python
fonttools/fonttools
Lib/fontTools/feaLib/lexer.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/lexer.py
MIT
def parse(self): """Parse the file, and return a :class:`fontTools.feaLib.ast.FeatureFile` object representing the root of the abstract syntax tree containing the parsed contents of the file.""" statements = self.doc_.statements while self.next_token_type_ is not None or self.cur...
Parse the file, and return a :class:`fontTools.feaLib.ast.FeatureFile` object representing the root of the abstract syntax tree containing the parsed contents of the file.
parse
python
fonttools/fonttools
Lib/fontTools/feaLib/parser.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/parser.py
MIT
def parse_name_(self): """Parses a name record. See `section 9.e <https://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html#9.e>`_.""" platEncID = None langID = None if self.next_token_type_ in Lexer.NUMBERS: platformID = self.expect_any_number_() ...
Parses a name record. See `section 9.e <https://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html#9.e>`_.
parse_name_
python
fonttools/fonttools
Lib/fontTools/feaLib/parser.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/parser.py
MIT
def parse_featureNames_(self, tag): """Parses a ``featureNames`` statement found in stylistic set features. See section `8.c <https://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html#8.c>`_. """ assert self.cur_token_ == "featureNames", self.cur_token_ block...
Parses a ``featureNames`` statement found in stylistic set features. See section `8.c <https://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html#8.c>`_.
parse_featureNames_
python
fonttools/fonttools
Lib/fontTools/feaLib/parser.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/parser.py
MIT
def check_glyph_name_in_glyph_set(self, *names): """Adds a glyph name (just `start`) or glyph names of a range (`start` and `end`) which are not in the glyph set to the "missing list" for future error reporting. If no glyph set is present, does nothing. """ if self.glyph...
Adds a glyph name (just `start`) or glyph names of a range (`start` and `end`) which are not in the glyph set to the "missing list" for future error reporting. If no glyph set is present, does nothing.
check_glyph_name_in_glyph_set
python
fonttools/fonttools
Lib/fontTools/feaLib/parser.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/parser.py
MIT
def make_glyph_range_(self, location, start, limit): """(location, "a.sc", "d.sc") --> ["a.sc", "b.sc", "c.sc", "d.sc"]""" result = list() if len(start) != len(limit): raise FeatureLibError( 'Bad range: "%s" and "%s" should have the same length' % (start, limit), ...
(location, "a.sc", "d.sc") --> ["a.sc", "b.sc", "c.sc", "d.sc"]
make_glyph_range_
python
fonttools/fonttools
Lib/fontTools/feaLib/parser.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/parser.py
MIT
def main(args=None): """Add features from a feature file (.fea) into an OTF font""" parser = argparse.ArgumentParser( description="Use fontTools to compile OpenType feature files (*.fea)." ) parser.add_argument( "input_fea", metavar="FEATURES", help="Path to the feature file" ) p...
Add features from a feature file (.fea) into an OTF font
main
python
fonttools/fonttools
Lib/fontTools/feaLib/__main__.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/feaLib/__main__.py
MIT
def add_method(*clazzes, **kwargs): """Returns a decorator function that adds a new method to one or more classes.""" allowDefault = kwargs.get("allowDefaultTable", False) def wrapper(method): done = [] for clazz in clazzes: if clazz in done: continue # Supp...
Returns a decorator function that adds a new method to one or more classes.
add_method
python
fonttools/fonttools
Lib/fontTools/merge/base.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/merge/base.py
MIT
def computeMegaGlyphOrder(merger, glyphOrders): """Modifies passed-in glyphOrders to reflect new glyph names. Stores merger.glyphOrder.""" megaOrder = {} for glyphOrder in glyphOrders: for i, glyphName in enumerate(glyphOrder): if glyphName in megaOrder: n = megaOrder...
Modifies passed-in glyphOrders to reflect new glyph names. Stores merger.glyphOrder.
computeMegaGlyphOrder
python
fonttools/fonttools
Lib/fontTools/merge/cmap.py
https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/merge/cmap.py
MIT