1
1
"""manage the PDF transform stack during "layout" mode text extraction"""
2
2
3
3
from collections import ChainMap , Counter
4
- from typing import Any , Dict , List , MutableMapping , Union
4
+ from typing import Any , Dict , List , MutableMapping , Tuple , Union
5
5
from typing import ChainMap as ChainMapType
6
6
from typing import Counter as CounterType
7
7
@@ -43,6 +43,7 @@ def __init__(self) -> None:
43
43
self .Tz : float = 100.0
44
44
self .TL : float = 0.0
45
45
self .Ts : float = 0.0
46
+ self .font_stack : List [Tuple [Union [Font , None ], Union [int , float ]]] = []
46
47
self .font : Union [Font , None ] = None
47
48
self .font_size : Union [int , float ] = 0
48
49
@@ -167,6 +168,7 @@ def reset_trm(self) -> TextStateManagerChainMapType:
167
168
168
169
def remove_q (self ) -> TextStateManagerChainMapType :
169
170
"""Rewind to stack prior state after closing a 'q' with internal 'cm' ops"""
171
+ self .font , self .font_size = self .font_stack .pop (- 1 )
170
172
self .transform_stack = self .reset_tm ()
171
173
self .transform_stack .maps = self .transform_stack .maps [
172
174
self .q_queue .pop (self .q_depth .pop (), 0 ) :
@@ -175,6 +177,7 @@ def remove_q(self) -> TextStateManagerChainMapType:
175
177
176
178
def add_q (self ) -> None :
177
179
"""Add another level to q_queue"""
180
+ self .font_stack .append ((self .font , self .font_size ))
178
181
self .q_depth .append (len (self .q_depth ))
179
182
180
183
def add_cm (self , * args : Any ) -> TextStateManagerChainMapType :
0 commit comments