@@ -717,8 +717,8 @@ class StixSansFonts(StixFonts):
717
717
#
718
718
# The most relevant "chapters" are:
719
719
# Data structures for boxes and their friends
720
- # Shipping pages out (Ship class )
721
- # Packaging (hpack and vpack)
720
+ # Shipping pages out (ship() )
721
+ # Packaging (hpack() and vpack() )
722
722
# Data structures for math mode
723
723
# Subroutines for math mode
724
724
# Typesetting math formulas
@@ -1421,81 +1421,70 @@ def __init__(self, c, width, state, always=False, char_class=Char):
1421
1421
self .width = char .width
1422
1422
1423
1423
1424
- class Ship :
1424
+ def ship ( ox , oy , box ) :
1425
1425
"""
1426
1426
Ship boxes to output once they have been set up, this sends them to output.
1427
1427
1428
- Since boxes can be inside of boxes inside of boxes, the main work of `Ship `
1428
+ Since boxes can be inside of boxes inside of boxes, the main work of `ship `
1429
1429
is done by two mutually recursive routines, `hlist_out` and `vlist_out`,
1430
1430
which traverse the `Hlist` nodes and `Vlist` nodes inside of horizontal
1431
1431
and vertical boxes. The global variables used in TeX to store state as it
1432
- processes have become member variables here.
1432
+ processes have become local variables here.
1433
1433
"""
1434
1434
1435
- def __call__ (self , ox , oy , box ):
1436
- self .max_push = 0 # Deepest nesting of push commands so far
1437
- self .cur_s = 0
1438
- self .cur_v = 0.
1439
- self .cur_h = 0.
1440
- self .off_h = ox
1441
- self .off_v = oy + box .height
1442
- self .hlist_out (box )
1435
+ cur_v = 0.
1436
+ cur_h = 0.
1437
+ off_h = ox
1438
+ off_v = oy + box .height
1443
1439
1444
- @staticmethod
1445
1440
def clamp (value ):
1446
- if value < - 1000000000. :
1447
- return - 1000000000.
1448
- if value > 1000000000. :
1449
- return 1000000000.
1450
- return value
1451
-
1452
- def hlist_out (self , box ):
1453
- cur_g = 0
1454
- cur_glue = 0.
1455
- glue_order = box .glue_order
1456
- glue_sign = box .glue_sign
1457
- base_line = self .cur_v
1458
- left_edge = self .cur_h
1459
- self .cur_s += 1
1460
- self .max_push = max (self .cur_s , self .max_push )
1461
- clamp = self .clamp
1441
+ return - 1e9 if value < - 1e9 else + 1e9 if value > + 1e9 else value
1442
+
1443
+ def hlist_out (box ):
1444
+ nonlocal cur_v , cur_h , off_h , off_v
1445
+
1446
+ cur_g = 0
1447
+ cur_glue = 0.
1448
+ glue_order = box .glue_order
1449
+ glue_sign = box .glue_sign
1450
+ base_line = cur_v
1451
+ left_edge = cur_h
1462
1452
1463
1453
for p in box .children :
1464
1454
if isinstance (p , Char ):
1465
- p .render (self . cur_h + self . off_h , self . cur_v + self . off_v )
1466
- self . cur_h += p .width
1455
+ p .render (cur_h + off_h , cur_v + off_v )
1456
+ cur_h += p .width
1467
1457
elif isinstance (p , Kern ):
1468
- self . cur_h += p .width
1458
+ cur_h += p .width
1469
1459
elif isinstance (p , List ):
1470
1460
# node623
1471
1461
if len (p .children ) == 0 :
1472
- self . cur_h += p .width
1462
+ cur_h += p .width
1473
1463
else :
1474
- edge = self . cur_h
1475
- self . cur_v = base_line + p .shift_amount
1464
+ edge = cur_h
1465
+ cur_v = base_line + p .shift_amount
1476
1466
if isinstance (p , Hlist ):
1477
- self . hlist_out (p )
1467
+ hlist_out (p )
1478
1468
else :
1479
1469
# p.vpack(box.height + box.depth, 'exactly')
1480
- self . vlist_out (p )
1481
- self . cur_h = edge + p .width
1482
- self . cur_v = base_line
1470
+ vlist_out (p )
1471
+ cur_h = edge + p .width
1472
+ cur_v = base_line
1483
1473
elif isinstance (p , Box ):
1484
1474
# node624
1485
1475
rule_height = p .height
1486
- rule_depth = p .depth
1487
- rule_width = p .width
1476
+ rule_depth = p .depth
1477
+ rule_width = p .width
1488
1478
if np .isinf (rule_height ):
1489
1479
rule_height = box .height
1490
1480
if np .isinf (rule_depth ):
1491
1481
rule_depth = box .depth
1492
1482
if rule_height > 0 and rule_width > 0 :
1493
- self .cur_v = base_line + rule_depth
1494
- p .render (self .cur_h + self .off_h ,
1495
- self .cur_v + self .off_v ,
1483
+ cur_v = base_line + rule_depth
1484
+ p .render (cur_h + off_h , cur_v + off_v ,
1496
1485
rule_width , rule_height )
1497
- self . cur_v = base_line
1498
- self . cur_h += rule_width
1486
+ cur_v = base_line
1487
+ cur_h += rule_width
1499
1488
elif isinstance (p , Glue ):
1500
1489
# node625
1501
1490
glue_spec = p .glue_spec
@@ -1509,38 +1498,36 @@ def hlist_out(self, box):
1509
1498
cur_glue += glue_spec .shrink
1510
1499
cur_g = round (clamp (box .glue_set * cur_glue ))
1511
1500
rule_width += cur_g
1512
- self .cur_h += rule_width
1513
- self .cur_s -= 1
1514
-
1515
- def vlist_out (self , box ):
1516
- cur_g = 0
1517
- cur_glue = 0.
1518
- glue_order = box .glue_order
1519
- glue_sign = box .glue_sign
1520
- self .cur_s += 1
1521
- self .max_push = max (self .max_push , self .cur_s )
1522
- left_edge = self .cur_h
1523
- self .cur_v -= box .height
1524
- top_edge = self .cur_v
1525
- clamp = self .clamp
1501
+ cur_h += rule_width
1502
+
1503
+ def vlist_out (box ):
1504
+ nonlocal cur_v , cur_h , off_h , off_v
1505
+
1506
+ cur_g = 0
1507
+ cur_glue = 0.
1508
+ glue_order = box .glue_order
1509
+ glue_sign = box .glue_sign
1510
+ left_edge = cur_h
1511
+ cur_v -= box .height
1512
+ top_edge = cur_v
1526
1513
1527
1514
for p in box .children :
1528
1515
if isinstance (p , Kern ):
1529
- self . cur_v += p .width
1516
+ cur_v += p .width
1530
1517
elif isinstance (p , List ):
1531
1518
if len (p .children ) == 0 :
1532
- self . cur_v += p .height + p .depth
1519
+ cur_v += p .height + p .depth
1533
1520
else :
1534
- self . cur_v += p .height
1535
- self . cur_h = left_edge + p .shift_amount
1536
- save_v = self . cur_v
1521
+ cur_v += p .height
1522
+ cur_h = left_edge + p .shift_amount
1523
+ save_v = cur_v
1537
1524
p .width = box .width
1538
1525
if isinstance (p , Hlist ):
1539
- self . hlist_out (p )
1526
+ hlist_out (p )
1540
1527
else :
1541
- self . vlist_out (p )
1542
- self . cur_v = save_v + p .depth
1543
- self . cur_h = left_edge
1528
+ vlist_out (p )
1529
+ cur_v = save_v + p .depth
1530
+ cur_h = left_edge
1544
1531
elif isinstance (p , Box ):
1545
1532
rule_height = p .height
1546
1533
rule_depth = p .depth
@@ -1549,9 +1536,8 @@ def vlist_out(self, box):
1549
1536
rule_width = box .width
1550
1537
rule_height += rule_depth
1551
1538
if rule_height > 0 and rule_depth > 0 :
1552
- self .cur_v += rule_height
1553
- p .render (self .cur_h + self .off_h ,
1554
- self .cur_v + self .off_v ,
1539
+ cur_v += rule_height
1540
+ p .render (cur_h + off_h , cur_v + off_v ,
1555
1541
rule_width , rule_height )
1556
1542
elif isinstance (p , Glue ):
1557
1543
glue_spec = p .glue_spec
@@ -1565,14 +1551,12 @@ def vlist_out(self, box):
1565
1551
cur_glue += glue_spec .shrink
1566
1552
cur_g = round (clamp (box .glue_set * cur_glue ))
1567
1553
rule_height += cur_g
1568
- self . cur_v += rule_height
1554
+ cur_v += rule_height
1569
1555
elif isinstance (p , Char ):
1570
1556
raise RuntimeError (
1571
1557
"Internal mathtext error: Char node found in vlist" )
1572
- self .cur_s -= 1
1573
-
1574
1558
1575
- ship = Ship ( )
1559
+ hlist_out ( box )
1576
1560
1577
1561
1578
1562
##############################################################################
0 commit comments