class_docstr: Manages grafting text-only PDFs onto regular PDFs.
class_docstr_tok: ["Manages","grafting","text-only","PDFs","onto","regular","PDFs","."]
docstr: Copy a font from the filename text into pdf_base.
docstr_tok: ["Copy","a","font","from","the","filename","text","into","pdf_base","."]
code: def _find_font(
      self, text: Path
  ) -> tuple[Dictionary | None, Name | None]:
      """Copy a font from the filename text into pdf_base."""
      font, font_key = None, None
      possible_font_names = ("/f-0-0", "/F1")
      try:
          with Pdf.open(text) as pdf_text:
              try:
                  pdf_text_fonts = pdf_text.pages[0].Resources.get(
                      Name.Font, Dictionary()
                  )
              except (AttributeError, IndexError, KeyError):
                  return None, None
              if not isinstance(pdf_text_fonts, Dictionary):
                  log.warning(
                      "Page fonts are not stored in a dictionary"
                  )
                  return None, None
              pdf_text_font = None
              for f in possible_font_names:
                  pdf_text_font = pdf_text_fonts.get(f, None)
                  if pdf_text_font is not None:
                      font_key = Name(f)
                      break
              if pdf_text_font:
                  font = self.pdf_base.copy_foreign(pdf_text_font)
              if not isinstance(font, Dictionary):
                  log.warning("Font is not a dictionary")
                  font, font_key = None, None
              return font, font_key
      except (FileNotFoundError, PdfError):
          # PdfError occurs if a 0-length file is written e.g. due to OCR timeout
          return None, None
  
file_path: OCRmyPDF/src/ocrmypdf/_graft.py
imports: from __future__ import annotations
  import logging
  from contextlib import suppress
  from enum import Enum
  from pathlib import Path
  from pikepdf import Dictionary, Matrix, Name, Operator, Page, Pdf, PdfError, Stream, parse_content_stream, unparse_content_stream
  from ocrmypdf._jobcontext import PdfContext
label_desc: Use image node_id 5 for calling the OcrGrafter obj's underlying member method code with example usage: obj._find_font(text) and returns: font,  font_key, None,  None, None,  None, None,  None