Replace magic Ghostscript raster device strings with StrEnum

This commit is contained in:
James R. Barlow
2026-01-20 10:44:25 -08:00
parent c818ad5e75
commit bc745d4d81
7 changed files with 44 additions and 21 deletions
+14 -1
View File
@@ -8,6 +8,7 @@ from __future__ import annotations
from abc import ABC, abstractmethod
from argparse import ArgumentParser
from collections.abc import Sequence, Set
from enum import StrEnum
from logging import Handler
from pathlib import Path
from typing import TYPE_CHECKING, NamedTuple
@@ -30,6 +31,18 @@ if TYPE_CHECKING:
# pylint: enable=ungrouped-imports
class GhostscriptRasterDevice(StrEnum):
"""Possible raster devices for Ghostscript."""
JPEGGRAY = 'jpeggray'
JPEGCOLOR = 'jpeg'
PNGMONO = 'pngmono'
PNGGRAY = 'pnggray'
PNG256 = 'png256'
PNG16M = 'png16m'
hookspec = pluggy.HookspecMarker('ocrmypdf')
# pylint: disable=unused-argument
@@ -207,7 +220,7 @@ def validate(pdfinfo: PdfInfo, options: OcrOptions) -> None:
def rasterize_pdf_page(
input_file: Path,
output_file: Path,
raster_device: str,
raster_device: GhostscriptRasterDevice,
raster_dpi: Resolution,
pageno: int,
page_dpi: Resolution | None,