class_docstr: A class for converting documents from the hOCR format.
  
  For details of the hOCR format, see:
  http://kba.cloud/hocr-spec/.
class_docstr_tok: ["A","class","for","converting","documents","from","the","hOCR","format",".","For","details","of","the","hOCR","format",",","see",":","http",":","\/\/kba.cloud\/hocr-spec\/","."]
docstr: Initialize the HocrTransform object.
docstr_tok: ["Initialize","the","HocrTransform","object","."]
code: def __init__(
      self,
      *,
      hocr_filename: str | Path,
      dpi: float,
      debug: bool = False,
      fontname: Name = Name("/f-0-0"),
      font: Font = GlyphlessFont(),
      debug_render_options: DebugRenderOptions | None = None,
  ):
      """Initialize the HocrTransform object."""
  
      if debug:
          log.warning(
              "Use debug_render_options instead", DeprecationWarning
          )
          self.render_options = DebugRenderOptions(
              render_baseline=debug,
              render_triangle=debug,
              render_line_bbox=False,
              render_word_bbox=debug,
              render_paragraph_bbox=False,
              render_space_bbox=False,
          )
      else:
          self.render_options = (
              debug_render_options or DebugRenderOptions()
          )
      self.dpi = dpi
      self.hocr = ElementTree.parse(os.fspath(hocr_filename))
      self._fontname = fontname
      self._font = font
  
      # if the hOCR file has a namespace, ElementTree requires its use to
      # find elements
      matches = re.match(r"({.*})html", self.hocr.getroot().tag)
      self.xmlns = ""
      if matches:
          self.xmlns = matches.group(1)
  
      for div in self.hocr.findall(
          self._child_xpath("div", "ocr_page")
      ):
          coords = self.element_coordinates(div)
          if not coords:
              raise HocrTransformError(
                  "hocr file is missing page dimensions"
              )
          self.width = (coords.urx - coords.llx) / (self.dpi / INCH)
          self.height = (coords.ury - coords.lly) / (self.dpi / INCH)
          # Stop after first div that has page coordinates
          break
  
imports: from __future__ import annotations
  import logging
  import os
  import re
  import unicodedata
  from dataclasses import dataclass
  from itertools import pairwise
  from math import atan, cos, pi
  from pathlib import Path
  from xml.etree import ElementTree
  from pikepdf import Matrix, Name, Rectangle
  from pikepdf.canvas import BLACK, BLUE, CYAN, DARKGREEN, GREEN, MAGENTA, RED, Canvas, Text, TextDirection
  from ocrmypdf.hocrtransform._font import EncodableFont
  from ocrmypdf.hocrtransform._font import GlyphlessFont
label_desc: Use image node_id 1 to create a new HocrTransform object  with example: obj = HocrTransform()