The main duty of :meth:`hpack` is to compute the dimensions of the resulting boxes, and to 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 i
(self, w=0., m='additional')
| 1640 | # return 0.0 |
| 1641 | |
| 1642 | def hpack(self, w=0., m='additional'): |
| 1643 | """ |
| 1644 | The main duty of :meth:`hpack` is to compute the dimensions of |
| 1645 | the resulting boxes, and to adjust the glue if one of those |
| 1646 | dimensions is pre-specified. The computed sizes normally |
| 1647 | enclose all of the material inside the new box; but some items |
| 1648 | may stick out if negative glue is used, if the box is |
| 1649 | overfull, or if a ``\\vbox`` includes other boxes that have |
| 1650 | been shifted left. |
| 1651 | |
| 1652 | - *w*: specifies a width |
| 1653 | |
| 1654 | - *m*: is either 'exactly' or 'additional'. |
| 1655 | |
| 1656 | Thus, ``hpack(w, 'exactly')`` produces a box whose width is |
| 1657 | exactly *w*, while ``hpack(w, 'additional')`` yields a box |
| 1658 | whose width is the natural width plus *w*. The default values |
| 1659 | produce a box with the natural width. |
| 1660 | """ |
| 1661 | # I don't know why these get reset in TeX. Shift_amount is pretty |
| 1662 | # much useless if we do. |
| 1663 | #self.shift_amount = 0. |
| 1664 | h = 0. |
| 1665 | d = 0. |
| 1666 | x = 0. |
| 1667 | total_stretch = [0.] * 4 |
| 1668 | total_shrink = [0.] * 4 |
| 1669 | for p in self.children: |
| 1670 | if isinstance(p, Char): |
| 1671 | x += p.width |
| 1672 | h = max(h, p.height) |
| 1673 | d = max(d, p.depth) |
| 1674 | elif isinstance(p, Box): |
| 1675 | x += p.width |
| 1676 | if not np.isinf(p.height) and not np.isinf(p.depth): |
| 1677 | s = getattr(p, 'shift_amount', 0.) |
| 1678 | h = max(h, p.height - s) |
| 1679 | d = max(d, p.depth + s) |
| 1680 | elif isinstance(p, Glue): |
| 1681 | glue_spec = p.glue_spec |
| 1682 | x += glue_spec.width |
| 1683 | total_stretch[glue_spec.stretch_order] += glue_spec.stretch |
| 1684 | total_shrink[glue_spec.shrink_order] += glue_spec.shrink |
| 1685 | elif isinstance(p, Kern): |
| 1686 | x += p.width |
| 1687 | self.height = h |
| 1688 | self.depth = d |
| 1689 | |
| 1690 | if m == 'additional': |
| 1691 | w += x |
| 1692 | self.width = w |
| 1693 | x = w - x |
| 1694 | |
| 1695 | if x == 0.: |
| 1696 | self.glue_sign = 0 |
| 1697 | self.glue_order = 0 |
| 1698 | self.glue_ratio = 0. |
| 1699 | return |