///|
/// Return a human-readable simple-font subtype label.
///
/// Type 3 labels include the declared CharProc names to make debugging parsed
/// glyph programs easier.
pub fn PdfSimpleFontType::debug_name(self : PdfSimpleFontType) -> String {
  match self {
    PdfType1 => "Type 1"
    PdfMMType1 => "MM Type 1"
    PdfType3(data) => {
      let mut text = "Type 3: charprocs for"
      for entry in data.charprocs {
        let (name, _) = entry
        text = text + pdf_text_string_of_name(name)
      }
      text
    }
    PdfTrueType => "Truetype"
  }
}

///|
/// Return a multi-line debug summary for this simple font.
pub fn PdfSimpleFont::debug_name(self : PdfSimpleFont) -> String {
  let basefont = match self.basefont {
    Some(name) => pdf_text_string_of_name(name)
    None => ""
  }
  "fonttype = " +
  self.fonttype.debug_name() +
  "\nbasefont " +
  basefont +
  "\nencoding is " +
  self.encoding.debug_name() +
  "\n"
}

///|
/// Return a human-readable label for a parsed font.
pub fn PdfFont::debug_name(self : PdfFont) -> String {
  match self {
    PdfFontStandard(font) => font.debug_name()
    PdfFontSimple(font) => "SimpleFont " + font.debug_name()
    PdfFontCIDKeyed(font) => font.debug_name()
  }
}

///|
/// Compatibility wrapper for `PdfFont::debug_name`.
pub fn pdf_string_of_font(font : PdfFont) -> String {
  font.debug_name()
}

///|
/// Test whether this font is a Type 0 font using `/Identity-H`.
pub fn PdfFont::is_identity_h(self : PdfFont) -> Bool {
  match self {
    PdfFontCIDKeyed(font) => font.is_identity_h()
    _ => false
  }
}

///|
/// Compatibility wrapper for `PdfFont::is_identity_h`.
pub fn pdf_is_identity_h(font : PdfFont) -> Bool {
  font.is_identity_h()
}

///|
/// Test whether this font is a Type 0 font using `/Identity-V`.
pub fn PdfFont::is_identity_v(self : PdfFont) -> Bool {
  match self {
    PdfFontCIDKeyed(font) => font.is_identity_v()
    _ => false
  }
}

///|
/// Return true when this font consumes fixed two-byte text character codes.
pub fn PdfFont::uses_two_byte_codes(self : PdfFont) -> Bool {
  match self {
    PdfFontCIDKeyed(font) => font.uses_two_byte_codes()
    _ => false
  }
}

///|
/// Build a text extractor for an already parsed font.
pub fn PdfFont::text_extractor(self : PdfFont) -> PdfTextExtractor {
  { font: self, }
}

///|
/// Compatibility wrapper for `PdfFont::text_extractor`.
pub fn pdf_text_extractor_of_font_real(font : PdfFont) -> PdfTextExtractor {
  font.text_extractor()
}

///|
/// Build a pure reverse lookup closure for an already parsed font.
///
/// The returned closure maps one Unicode codepoint to the first matching PDF
/// character code when the font can represent it. `debug` is accepted for
/// CamlPDF API compatibility; this implementation does not write diagnostics.
pub fn pdf_charcode_extractor_of_font_real(
  font : PdfFont,
  debug? : Bool = false,
) -> (Int) -> Int? {
  // CamlPDF reports missing glyphs to stderr when debug is true; this wrapper
  // keeps the lookup pure while preserving the API shape.
  ignore(debug)
  let extractor = font.text_extractor()
  fn(codepoint) { extractor.charcode_of_codepoint(codepoint) }
}