MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / subset

Method subset

lib/matplotlib/_type1font.py:840–895  ·  view source on GitHub ↗

Return a new font that only defines the given characters. Parameters ---------- characters : sequence of bytes The subset of characters to include. These are indices into the font's encoding array. The encoding array of a Type-1 font can

(self, characters, name_prefix)

Source from the content-addressed store, hash-verified

838 return bytes(data[:len0]), bytes(data[len0:])
839
840 def subset(self, characters, name_prefix):
841 """
842 Return a new font that only defines the given characters.
843
844 Parameters
845 ----------
846 characters : sequence of bytes
847 The subset of characters to include. These are indices into the
848 font's encoding array. The encoding array of a Type-1 font can
849 only include 256 characters, but other glyphs may be accessed
850 via the seac operator.
851 name_prefix : str
852 Prefix to prepend to the font name.
853
854 Returns
855 -------
856 `Type1Font`
857 """
858 characters = frozenset(characters)
859 if _log.isEnabledFor(logging.DEBUG):
860 _log.debug(
861 "Subsetting font %s to characters %s = %s",
862 self.prop['FontName'],
863 sorted(characters),
864 [self.prop['Encoding'].get(code) for code in sorted(characters)],
865 )
866 encoding = {code: glyph
867 for code, glyph in self.prop['Encoding'].items()
868 if code in characters}
869 encoding[0] = '.notdef'
870 # todo and done include strings (glyph names)
871 todo = set(encoding.values())
872 done = set()
873 seen_subrs = {0, 1, 2, 3}
874 while todo:
875 glyph = todo.pop()
876 called_glyphs, called_subrs = _CharstringSimulator(self).run(glyph)
877 todo.update(called_glyphs - done)
878 seen_subrs.update(called_subrs)
879 done.add(glyph)
880
881 charstrings = self._subset_charstrings(done)
882 subrs = self._subset_subrs(seen_subrs)
883 newparts = self._replace(
884 [(x, f'/FontName /{name_prefix}{self.prop["FontName"]} def')
885 for x in self._pos['FontName']]
886 + [(self._pos['CharStrings'][0], charstrings),
887 (self._pos['Subrs'][0], subrs),
888 (self._pos['Encoding'][0], self._postscript_encoding(encoding))
889 ] + [(x, '') for x in self._pos.get('UniqueID', [])]
890 )
891 return type(self)((
892 newparts[0],
893 self._encrypt(newparts[1], 'eexec'),
894 self.parts[2]
895 ))
896
897 @staticmethod

Callers 2

_embedTeXFontMethod · 0.95
get_glyphs_subsetFunction · 0.80

Calls 12

_subset_charstringsMethod · 0.95
_subset_subrsMethod · 0.95
_replaceMethod · 0.95
_postscript_encodingMethod · 0.95
_encryptMethod · 0.95
valuesMethod · 0.80
getMethod · 0.45
popMethod · 0.45
runMethod · 0.45
updateMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected