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

Method hpack

lib/matplotlib/_mathtext.py:1357–1420  ·  view source on GitHub ↗

r""" Compute the dimensions of the resulting boxes, and adjust the glue if one of those dimensions is pre-specified. The computed sizes normally enclose all of the material inside the new box; but some items may stick out if negative glue is used, if the box is overf

(self, w: float = 0.0,
              m: T.Literal['additional', 'exactly'] = 'additional')

Source from the content-addressed store, hash-verified

1355 self.children = new_children
1356
1357 def hpack(self, w: float = 0.0,
1358 m: T.Literal['additional', 'exactly'] = 'additional') -> None:
1359 r"""
1360 Compute the dimensions of the resulting boxes, and adjust the glue if
1361 one of those dimensions is pre-specified. The computed sizes normally
1362 enclose all of the material inside the new box; but some items may
1363 stick out if negative glue is used, if the box is overfull, or if a
1364 ``\vbox`` includes other boxes that have been shifted left.
1365
1366 Parameters
1367 ----------
1368 w : float, default: 0
1369 A width.
1370 m : {'exactly', 'additional'}, default: 'additional'
1371 Whether to produce a box whose width is 'exactly' *w*; or a box
1372 with the natural width of the contents, plus *w* ('additional').
1373
1374 Notes
1375 -----
1376 The defaults produce a box with the natural width of the contents.
1377 """
1378 # I don't know why these get reset in TeX. Shift_amount is pretty
1379 # much useless if we do.
1380 # self.shift_amount = 0.
1381 h = 0.
1382 d = 0.
1383 x = 0.
1384 total_stretch = [0.] * 4
1385 total_shrink = [0.] * 4
1386 for p in self.children:
1387 if isinstance(p, Char):
1388 x += p.width
1389 h = max(h, p.height)
1390 d = max(d, p.depth)
1391 elif isinstance(p, Box):
1392 x += p.width
1393 if not np.isinf(p.height) and not np.isinf(p.depth):
1394 s = getattr(p, 'shift_amount', 0.)
1395 h = max(h, p.height - s)
1396 d = max(d, p.depth + s)
1397 elif isinstance(p, Glue):
1398 glue_spec = p.glue_spec
1399 x += glue_spec.width
1400 total_stretch[glue_spec.stretch_order] += glue_spec.stretch
1401 total_shrink[glue_spec.shrink_order] += glue_spec.shrink
1402 elif isinstance(p, Kern):
1403 x += p.width
1404 self.height = h
1405 self.depth = d
1406
1407 if m == 'additional':
1408 w += x
1409 self.width = w
1410 x = w - x
1411
1412 if x == 0.:
1413 self.glue_sign = 0
1414 self.glue_order = 0

Callers 6

__init__Method · 0.95
subsuperMethod · 0.95
accentMethod · 0.80
_genfracMethod · 0.80
_gensetMethod · 0.80
substackMethod · 0.80

Calls 1

_set_glueMethod · 0.80

Tested by

no test coverage detected