Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: make mcstack immutable to avoid surprises #57

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions playa/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ class ContentObject:

gstate: GraphicState
ctm: Matrix
mcstack: List[MarkedContent]
mcstack: Tuple[MarkedContent, ...]

def __iter__(self) -> Iterator["ContentObject"]:
yield from ()
Expand Down Expand Up @@ -1021,7 +1021,7 @@ def init_state(self, ctm: Matrix) -> None:
# argstack: stack for command arguments.
self.argstack: List[PDFObject] = []
# mcstack: stack for marked content sections.
self.mcstack: List[MarkedContent] = []
self.mcstack: Tuple[MarkedContent, ...] = ()

def push(self, obj: PDFObject) -> None:
self.argstack.append(obj)
Expand Down Expand Up @@ -1676,7 +1676,8 @@ def do_BDC(self, tag: PDFObject, props: PDFObject) -> None:

def do_EMC(self) -> None:
"""End marked-content sequence"""
self.mcstack.pop()
if self.mcstack:
self.mcstack = self.mcstack[:-1]

def begin_tag(self, tag: PDFObject, props: Dict[str, PDFObject]) -> None:
"""Handle beginning of tag, setting current MCID if any."""
Expand All @@ -1686,4 +1687,4 @@ def begin_tag(self, tag: PDFObject, props: Dict[str, PDFObject]) -> None:
mcid = int_value(props["MCID"])
else:
mcid = None
self.mcstack.append(MarkedContent(mcid=mcid, tag=tag, props=props))
self.mcstack = (*self.mcstack, MarkedContent(mcid=mcid, tag=tag, props=props))
Loading