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

Function _parse_kern_pairs

lib/matplotlib/_afm.py:255–284  ·  view source on GitHub ↗

Return a kern pairs dictionary. Returns ------- dict Keys are (*char1*, *char2*) tuples and values are the kern pair value. For example, a kern pairs line like ``KPX A y -50`` will be represented as:: d['A', 'y'] = -50

(fh: BinaryIO)

Source from the content-addressed store, hash-verified

253
254
255def _parse_kern_pairs(fh: BinaryIO) -> dict[tuple[str, str], float]:
256 """
257 Return a kern pairs dictionary.
258
259 Returns
260 -------
261 dict
262 Keys are (*char1*, *char2*) tuples and values are the kern pair value. For
263 example, a kern pairs line like ``KPX A y -50`` will be represented as::
264
265 d['A', 'y'] = -50
266 """
267 line = next(fh)
268 if not line.startswith(b'StartKernPairs'):
269 raise RuntimeError(f'Bad start of kern pairs data: {line!r}')
270
271 d: dict[tuple[str, str], float] = {}
272 for line in fh:
273 line = line.rstrip()
274 if not line:
275 continue
276 if line.startswith(b'EndKernPairs'):
277 next(fh) # EndKernData
278 return d
279 vals = line.split()
280 if len(vals) != 4 or vals[0] != b'KPX':
281 raise RuntimeError(f'Bad kern pairs line: {line!r}')
282 c1, c2, val = _to_str(vals[1]), _to_str(vals[2]), _to_float(vals[3])
283 d[(c1, c2)] = val
284 raise RuntimeError('Bad kern pairs parse')
285
286
287class CompositePart(NamedTuple):

Callers 1

_parse_optionalFunction · 0.85

Calls 2

_to_strFunction · 0.85
_to_floatFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…