Skip to content

Commit

Permalink
ghostscript: better comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarlow83 committed Nov 10, 2023
1 parent 52fd9a6 commit 4a9a575
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/ocrmypdf/_exec/ghostscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@


class DuplicateFilter(logging.Filter):
"""Filter out duplicate log messages."""
"""Filter out duplicate log messages.
def __init__(self, logger: logging.Logger):
self.window: deque[str] = deque([], maxlen=5)
A context window of default 5 messages is used to determine if a message is a
duplicate. This is because some Ghostscript messages are word wrapped.
"""

def __init__(self, logger: logging.Logger, context_window=5):
self.window: deque[str] = deque([], maxlen=context_window)
self.logger = logger
self.levelno = logging.DEBUG
self.count = 0
Expand Down Expand Up @@ -74,6 +78,11 @@ def _gs_error_reported(stream) -> bool:


def _gs_devicen_reported(stream) -> bool:
"""Did Ghostscript warn about a DeviceN with inappropriate alternate?
If so, we need the user to select a color conversion, or the resulting PDF will
not present correctly in some PDF viewers.
"""
match = re.search(
r'DeviceN.*inappropriate alternate',
stream,
Expand Down

0 comments on commit 4a9a575

Please sign in to comment.