Refactor: move ocr_element to a better location

This commit is contained in:
James R. Barlow
2026-01-27 14:01:30 -08:00
parent de5f2b80f0
commit 6b37583674
7 changed files with 22 additions and 16 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ from ocrmypdf.exceptions import (
TesseractConfigError,
UnsupportedImageFormatError,
)
from ocrmypdf.hocrtransform import (
from ocrmypdf.models.ocr_element import (
Baseline,
BoundingBox,
FontInfo,
+1 -1
View File
@@ -20,7 +20,7 @@ from fpdf.enums import TextMode
from pikepdf import Matrix, Rectangle
from ocrmypdf.font import FontManager, MultiFontManager
from ocrmypdf.hocrtransform.ocr_element import OcrClass, OcrElement
from ocrmypdf.models.ocr_element import OcrClass, OcrElement
log = logging.getLogger(__name__)
+1 -1
View File
@@ -27,7 +27,7 @@ from ocrmypdf.hocrtransform.hocr_parser import (
HocrParseError,
HocrParser,
)
from ocrmypdf.hocrtransform.ocr_element import (
from ocrmypdf.models.ocr_element import (
Baseline,
BoundingBox,
FontInfo,
+5 -5
View File
@@ -20,9 +20,9 @@ import re
import unicodedata
from pathlib import Path
from typing import Literal, cast
from xml.etree import ElementTree
from xml.etree import ElementTree as ET
from ocrmypdf.hocrtransform.ocr_element import (
from ocrmypdf.models.ocr_element import (
Baseline,
BoundingBox,
FontInfo,
@@ -34,7 +34,7 @@ TextDirection = Literal["ltr", "rtl"]
log = logging.getLogger(__name__)
Element = ElementTree.Element
Element = ET.Element
class HocrParseError(Exception):
@@ -132,8 +132,8 @@ class HocrParser:
"""
self._hocr_path = Path(hocr_file)
try:
self._tree = ElementTree.parse(os.fspath(hocr_file))
except ElementTree.ParseError as e:
self._tree = ET.parse(os.fspath(hocr_file))
except ET.ParseError as e:
raise HocrParseError(f"Failed to parse hOCR file: {e}") from e
# Detect XML namespace
+6
View File
@@ -0,0 +1,6 @@
# SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""OCRmyPDF models for plugin options and cross-cutting concerns."""
from __future__ import annotations