@@ -911,8 +911,8 @@ def get_underline_thickness(self, font, fontsize, dpi):
911
911
#
912
912
# The most relevant "chapters" are:
913
913
# Data structures for boxes and their friends
914
- # Shipping pages out (Ship class )
915
- # Packaging (hpack and vpack)
914
+ # Shipping pages out (ship() )
915
+ # Packaging (hpack() and vpack() )
916
916
# Data structures for math mode
917
917
# Subroutines for math mode
918
918
# Typesetting math formulas
@@ -1690,65 +1690,63 @@ def __init__(self, c, width, state, always=False, char_class=Char):
1690
1690
self .width = char .width
1691
1691
1692
1692
1693
- class Ship :
1693
+ def ship ( ox , oy , box ) :
1694
1694
"""
1695
1695
Ship boxes to output once they have been set up, this sends them to output.
1696
1696
1697
- Since boxes can be inside of boxes inside of boxes, the main work of `Ship `
1697
+ Since boxes can be inside of boxes inside of boxes, the main work of `ship `
1698
1698
is done by two mutually recursive routines, `hlist_out` and `vlist_out`,
1699
1699
which traverse the `Hlist` nodes and `Vlist` nodes inside of horizontal
1700
1700
and vertical boxes. The global variables used in TeX to store state as it
1701
- processes have become member variables here.
1701
+ processes have become local variables here.
1702
1702
"""
1703
1703
1704
- def __call__ (self , ox , oy , box ):
1705
- self .max_push = 0 # Deepest nesting of push commands so far
1706
- self .cur_s = 0
1707
- self .cur_v = 0.
1708
- self .cur_h = 0.
1709
- self .off_h = ox
1710
- self .off_v = oy + box .height
1711
- self .hlist_out (box )
1704
+ max_push = 0 # Deepest nesting of push commands so far
1705
+ cur_s = 0
1706
+ cur_v = 0.
1707
+ cur_h = 0.
1708
+ off_h = ox
1709
+ off_v = oy + box .height
1712
1710
1713
- @staticmethod
1714
1711
def clamp (value ):
1715
1712
if value < - 1000000000. :
1716
1713
return - 1000000000.
1717
1714
if value > 1000000000. :
1718
1715
return 1000000000.
1719
1716
return value
1720
1717
1721
- def hlist_out (self , box ):
1718
+ def hlist_out (box ):
1719
+ nonlocal max_push , cur_s , cur_v , cur_h , off_h , off_v
1720
+
1722
1721
cur_g = 0
1723
1722
cur_glue = 0.
1724
1723
glue_order = box .glue_order
1725
1724
glue_sign = box .glue_sign
1726
- base_line = self .cur_v
1727
- left_edge = self .cur_h
1728
- self .cur_s += 1
1729
- self .max_push = max (self .cur_s , self .max_push )
1730
- clamp = self .clamp
1725
+ base_line = cur_v
1726
+ left_edge = cur_h
1727
+ cur_s += 1
1728
+ max_push = max (cur_s , max_push )
1731
1729
1732
1730
for p in box .children :
1733
1731
if isinstance (p , Char ):
1734
- p .render (self . cur_h + self . off_h , self . cur_v + self . off_v )
1735
- self . cur_h += p .width
1732
+ p .render (cur_h + off_h , cur_v + off_v )
1733
+ cur_h += p .width
1736
1734
elif isinstance (p , Kern ):
1737
- self . cur_h += p .width
1735
+ cur_h += p .width
1738
1736
elif isinstance (p , List ):
1739
1737
# node623
1740
1738
if len (p .children ) == 0 :
1741
- self . cur_h += p .width
1739
+ cur_h += p .width
1742
1740
else :
1743
- edge = self . cur_h
1744
- self . cur_v = base_line + p .shift_amount
1741
+ edge = cur_h
1742
+ cur_v = base_line + p .shift_amount
1745
1743
if isinstance (p , Hlist ):
1746
- self . hlist_out (p )
1744
+ hlist_out (p )
1747
1745
else :
1748
1746
# p.vpack(box.height + box.depth, 'exactly')
1749
- self . vlist_out (p )
1750
- self . cur_h = edge + p .width
1751
- self . cur_v = base_line
1747
+ vlist_out (p )
1748
+ cur_h = edge + p .width
1749
+ cur_v = base_line
1752
1750
elif isinstance (p , Box ):
1753
1751
# node624
1754
1752
rule_height = p .height
@@ -1759,12 +1757,11 @@ def hlist_out(self, box):
1759
1757
if np .isinf (rule_depth ):
1760
1758
rule_depth = box .depth
1761
1759
if rule_height > 0 and rule_width > 0 :
1762
- self .cur_v = base_line + rule_depth
1763
- p .render (self .cur_h + self .off_h ,
1764
- self .cur_v + self .off_v ,
1760
+ cur_v = base_line + rule_depth
1761
+ p .render (cur_h + off_h , cur_v + off_v ,
1765
1762
rule_width , rule_height )
1766
- self . cur_v = base_line
1767
- self . cur_h += rule_width
1763
+ cur_v = base_line
1764
+ cur_h += rule_width
1768
1765
elif isinstance (p , Glue ):
1769
1766
# node625
1770
1767
glue_spec = p .glue_spec
@@ -1778,38 +1775,39 @@ def hlist_out(self, box):
1778
1775
cur_glue += glue_spec .shrink
1779
1776
cur_g = round (clamp (box .glue_set * cur_glue ))
1780
1777
rule_width += cur_g
1781
- self .cur_h += rule_width
1782
- self .cur_s -= 1
1778
+ cur_h += rule_width
1779
+ cur_s -= 1
1780
+
1781
+ def vlist_out (box ):
1782
+ nonlocal max_push , cur_s , cur_v , cur_h , off_h , off_v
1783
1783
1784
- def vlist_out (self , box ):
1785
1784
cur_g = 0
1786
1785
cur_glue = 0.
1787
1786
glue_order = box .glue_order
1788
1787
glue_sign = box .glue_sign
1789
- self .cur_s += 1
1790
- self .max_push = max (self .max_push , self .cur_s )
1791
- left_edge = self .cur_h
1792
- self .cur_v -= box .height
1793
- top_edge = self .cur_v
1794
- clamp = self .clamp
1788
+ cur_s += 1
1789
+ max_push = max (max_push , cur_s )
1790
+ left_edge = cur_h
1791
+ cur_v -= box .height
1792
+ top_edge = cur_v
1795
1793
1796
1794
for p in box .children :
1797
1795
if isinstance (p , Kern ):
1798
- self . cur_v += p .width
1796
+ cur_v += p .width
1799
1797
elif isinstance (p , List ):
1800
1798
if len (p .children ) == 0 :
1801
- self . cur_v += p .height + p .depth
1799
+ cur_v += p .height + p .depth
1802
1800
else :
1803
- self . cur_v += p .height
1804
- self . cur_h = left_edge + p .shift_amount
1805
- save_v = self . cur_v
1801
+ cur_v += p .height
1802
+ cur_h = left_edge + p .shift_amount
1803
+ save_v = cur_v
1806
1804
p .width = box .width
1807
1805
if isinstance (p , Hlist ):
1808
- self . hlist_out (p )
1806
+ hlist_out (p )
1809
1807
else :
1810
- self . vlist_out (p )
1811
- self . cur_v = save_v + p .depth
1812
- self . cur_h = left_edge
1808
+ vlist_out (p )
1809
+ cur_v = save_v + p .depth
1810
+ cur_h = left_edge
1813
1811
elif isinstance (p , Box ):
1814
1812
rule_height = p .height
1815
1813
rule_depth = p .depth
@@ -1818,9 +1816,8 @@ def vlist_out(self, box):
1818
1816
rule_width = box .width
1819
1817
rule_height += rule_depth
1820
1818
if rule_height > 0 and rule_depth > 0 :
1821
- self .cur_v += rule_height
1822
- p .render (self .cur_h + self .off_h ,
1823
- self .cur_v + self .off_v ,
1819
+ cur_v += rule_height
1820
+ p .render (cur_h + off_h , cur_v + off_v ,
1824
1821
rule_width , rule_height )
1825
1822
elif isinstance (p , Glue ):
1826
1823
glue_spec = p .glue_spec
@@ -1834,14 +1831,13 @@ def vlist_out(self, box):
1834
1831
cur_glue += glue_spec .shrink
1835
1832
cur_g = round (clamp (box .glue_set * cur_glue ))
1836
1833
rule_height += cur_g
1837
- self . cur_v += rule_height
1834
+ cur_v += rule_height
1838
1835
elif isinstance (p , Char ):
1839
1836
raise RuntimeError (
1840
1837
"Internal mathtext error: Char node found in vlist" )
1841
- self .cur_s -= 1
1842
-
1838
+ cur_s -= 1
1843
1839
1844
- ship = Ship ( )
1840
+ hlist_out ( box )
1845
1841
1846
1842
1847
1843
##############################################################################
0 commit comments