Refactor: move ocr_element to a better location
This commit is contained in:
@@ -35,7 +35,7 @@ from ocrmypdf.exceptions import (
|
||||
TesseractConfigError,
|
||||
UnsupportedImageFormatError,
|
||||
)
|
||||
from ocrmypdf.hocrtransform import (
|
||||
from ocrmypdf.models.ocr_element import (
|
||||
Baseline,
|
||||
BoundingBox,
|
||||
FontInfo,
|
||||
|
||||
@@ -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__)
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user