title: How to get my custom font in Apache FOP in Kotlin?
body: <p>i am generating a PDF with Apache FOP.</p>
  <p>i want to load my custom font &quot;Interstate&quot; in kotlin, so i can calculate the width of a text by using the font metrics.</p>
  <p>However i can't seem to get my custom font.</p>
  <p>I tried using the FontListGenerator but that only lists the default fonts like &quot;Helvetica&quot;, even though the FopFactory got my configuration that contains the custom fonts.</p>
  <p>here is my kotlin function to get a font:</p>
  <pre><code>private fun getFopFont(configFile: String, fontFamily: String, triplet: FontTriplet, fontSize: Int): Font? {
    // create empty FontEventListener just to satisfy FontListGenerator
    val listener: FontEventListener = object : FontEventListener {
      override fun fontLoadingErrorAtAutoDetection(source: Any, fontURL: String, e: Exception) {}
      override fun fontSubstituted(source: Any, requested: FontTriplet, effective: FontTriplet) {}
      override fun glyphNotAvailable(source: Any, ch: Char, fontName: String) {}
      override fun fontDirectoryNotFound(source: Any, msg: String) {}
      override fun svgTextStrokedAsShapes(source: Any, fontFamily: String) {}
    }
  
    val listGenerator = FontListGenerator()
    val fopFactory = FopFactory.newInstance(File(configFile).toURI())
  
    @Suppress(&quot;UNCHECKED_CAST&quot;)
    val fontFamilies = listGenerator.listFonts(fopFactory, MimeConstants.MIME_PDF, listener) as SortedMap&lt;String, List&lt;FontSpec&gt;&gt;
    val fontSpec = fontFamilies[fontFamily] as ArrayList&lt;FontSpec&gt;? ?: return null
  
    return fontSpec.filter {spec -&gt; spec.triplets.contains(triplet)}
      .map {Font(fontFamily, triplet, it.fontMetrics, fontSize)}
      .firstOrNull()
  }
  </code></pre>