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: Render the text for a single word.
docstr_tok: ["Render","the","text","for","a","single","word","."]
code: def _do_line_word(
      self,
      canvas: Canvas,
      line_matrix: Matrix,
      text: Text,
      fontsize: float,
      elem: Element,
      next_elem: Element | None,
      text_direction: TextDirection,
      inject_word_breaks: bool,
  ):
      """Render the text for a single word."""
      if elem is None:
          return
      elemtxt = self.normalize_text(
          self._get_element_text(elem).strip()
      )
      if elemtxt == "":
          return
  
      hocr_box = self.element_coordinates(elem)
      if hocr_box is None:
          return
      box = line_matrix.inverse().transform(hocr_box)
      font_width = self._font.text_width(elemtxt, fontsize)
  
      # Debug sketches
      self._debug_draw_word_triangle(canvas, box)
      self._debug_draw_word_bbox(canvas, box)
  
      # If this word is 0 units wide, our best bet seems to be to suppress this text
      if text_direction == TextDirection.RTL:
          log.info("RTL: %s", elemtxt)
      if font_width > 0:
          if text_direction == TextDirection.LTR:
              text.text_transform(Matrix(1, 0, 0, -1, box.llx, 0))
          elif text_direction == TextDirection.RTL:
              text.text_transform(
                  Matrix(-1, 0, 0, -1, box.llx + box.width, 0)
              )
          text.horiz_scale(100 * box.width / font_width)
          text.show(self._font.text_encode(elemtxt))
  
      # Get coordinates of the next word (if there is one)
      hocr_next_box = (
          self.element_coordinates(next_elem)
          if next_elem is not None
          else None
      )
      if hocr_next_box is None:
          return
      # Render a space this word and the next word. The explicit space helps
      # PDF viewers identify the word break, and horizontally scaling it to
      # occupy the space the between the words helps the PDF viewer
      # avoid combiningthewordstogether.
      if not inject_word_breaks:
          return
      next_box = line_matrix.inverse().transform(hocr_next_box)
      if text_direction == TextDirection.LTR:
          space_box = Rectangle(
              box.urx, box.lly, next_box.llx, next_box.ury
          )
      elif text_direction == TextDirection.RTL:
          space_box = Rectangle(
              next_box.urx, box.lly, box.llx, next_box.ury
          )
      self._debug_draw_space_bbox(canvas, space_box)
      space_width = self._font.text_width(" ", fontsize)
      if space_width > 0:
          if text_direction == TextDirection.LTR:
              text.text_transform(Matrix(1, 0, 0, -1, space_box.llx, 0))
          elif text_direction == TextDirection.RTL:
              text.text_transform(
                  Matrix(
                      -1, 0, 0, -1, space_box.llx + space_box.width, 0
                  )
              )
          text.horiz_scale(100 * space_box.width / space_width)
          text.show(self._font.text_encode(" "))
  
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 12 for calling the HocrTransform obj's underlying member method code with example usage: obj._do_line_word(canvas, line_matrix, text, fontsize, elem, next_elem, text_direction, inject_word_breaks) without return types