A horizontal list of boxes.
| 1322 | |
| 1323 | |
| 1324 | class Hlist(List): |
| 1325 | """A horizontal list of boxes.""" |
| 1326 | |
| 1327 | def __init__(self, elements: T.Sequence[Node], w: float = 0.0, |
| 1328 | m: T.Literal['additional', 'exactly'] = 'additional', |
| 1329 | do_kern: bool = True): |
| 1330 | super().__init__(elements) |
| 1331 | if do_kern: |
| 1332 | self.kern() |
| 1333 | self.hpack(w=w, m=m) |
| 1334 | self.is_phantom = False |
| 1335 | |
| 1336 | def is_char_node(self) -> bool: |
| 1337 | # See description in Node.is_char_node. |
| 1338 | return all(map(lambda node: node.is_char_node(), self.children)) |
| 1339 | |
| 1340 | def kern(self) -> None: |
| 1341 | """ |
| 1342 | Insert `Kern` nodes between `Char` nodes to set kerning. |
| 1343 | |
| 1344 | The `Char` nodes themselves determine the amount of kerning they need |
| 1345 | (in `~Char.get_kerning`), and this function just creates the correct |
| 1346 | linked list. |
| 1347 | """ |
| 1348 | new_children = [] |
| 1349 | for elem0, elem1 in itertools.zip_longest(self.children, self.children[1:]): |
| 1350 | new_children.append(elem0) |
| 1351 | kerning_distance = elem0.get_kerning(elem1) |
| 1352 | if kerning_distance != 0.: |
| 1353 | kern = Kern(kerning_distance) |
| 1354 | new_children.append(kern) |
| 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. |
no outgoing calls
no test coverage detected
searching dependent graphs…