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

Function _parse_composites

lib/matplotlib/_afm.py:300–345  ·  view source on GitHub ↗

Parse the given filehandle for composites information. It is assumed that the file cursor is on the line behind 'StartComposites'. Returns ------- dict A dict mapping composite character names to a parts list. The parts list is a list of `.CompositePart` entrie

(fh: BinaryIO)

Source from the content-addressed store, hash-verified

298
299
300def _parse_composites(fh: BinaryIO) -> dict[bytes, list[CompositePart]]:
301 """
302 Parse the given filehandle for composites information.
303
304 It is assumed that the file cursor is on the line behind 'StartComposites'.
305
306 Returns
307 -------
308 dict
309 A dict mapping composite character names to a parts list. The parts
310 list is a list of `.CompositePart` entries describing the parts of
311 the composite.
312
313 Examples
314 --------
315 A composite definition line::
316
317 CC Aacute 2 ; PCC A 0 0 ; PCC acute 160 170 ;
318
319 will be represented as::
320
321 composites[b'Aacute'] = [CompositePart(name=b'A', dx=0, dy=0),
322 CompositePart(name=b'acute', dx=160, dy=170)]
323
324 """
325 composites: dict[bytes, list[CompositePart]] = {}
326 for line in fh:
327 line = line.rstrip()
328 if not line:
329 continue
330 if line.startswith(b'EndComposites'):
331 return composites
332 vals = line.split(b';')
333 cc = vals[0].split()
334 name, _num_parts = cc[1], _to_int(cc[2])
335 if len(vals) != _num_parts + 2: # First element is 'CC', last is empty.
336 raise RuntimeError(f'Bad composites parse: expected {_num_parts} parts, '
337 f'but got {len(vals) - 2}')
338 pccParts = []
339 for s in vals[1:-1]:
340 pcc = s.split()
341 part = CompositePart(pcc[1], _to_float(pcc[2]), _to_float(pcc[3]))
342 pccParts.append(part)
343 composites[name] = pccParts
344
345 raise RuntimeError('Bad composites parse')
346
347
348def _parse_optional(fh: BinaryIO) -> tuple[dict[tuple[str, str], float],

Callers 1

_parse_optionalFunction · 0.85

Calls 3

_to_intFunction · 0.85
CompositePartClass · 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…