11"""manage the PDF transform stack during "layout" mode text extraction"""
22
33from collections import ChainMap , Counter
4- from typing import Any , Dict , List , MutableMapping , Union
4+ from typing import Any , Dict , List , MutableMapping , Tuple , Union
55from typing import ChainMap as ChainMapType
66from typing import Counter as CounterType
77
@@ -43,6 +43,7 @@ def __init__(self) -> None:
4343 self .Tz : float = 100.0
4444 self .TL : float = 0.0
4545 self .Ts : float = 0.0
46+ self .font_stack : List [Tuple [Union [Font , None ], Union [int , float ]]] = []
4647 self .font : Union [Font , None ] = None
4748 self .font_size : Union [int , float ] = 0
4849
@@ -167,6 +168,7 @@ def reset_trm(self) -> TextStateManagerChainMapType:
167168
168169 def remove_q (self ) -> TextStateManagerChainMapType :
169170 """Rewind to stack prior state after closing a 'q' with internal 'cm' ops"""
171+ self .font , self .font_size = self .font_stack .pop (- 1 )
170172 self .transform_stack = self .reset_tm ()
171173 self .transform_stack .maps = self .transform_stack .maps [
172174 self .q_queue .pop (self .q_depth .pop (), 0 ) :
@@ -175,6 +177,7 @@ def remove_q(self) -> TextStateManagerChainMapType:
175177
176178 def add_q (self ) -> None :
177179 """Add another level to q_queue"""
180+ self .font_stack .append ((self .font , self .font_size ))
178181 self .q_depth .append (len (self .q_depth ))
179182
180183 def add_cm (self , * args : Any ) -> TextStateManagerChainMapType :
0 commit comments