/**
   * Gets the FontMetrics object for the supplied font. This method caches font metrics to ensure
   * native fonts are not loaded twice for the same font.
   */
  static synchronized QtFontMetrics getFontMetrics(Font font, boolean backwardCompat) {

    /* See if metrics has been stored in font already. */

    QtFontMetrics fm = (QtFontMetrics) font.metrics;

    if (fm == null) {
      boolean strikethrough = false, underline = false;

      /* See if a font metrics of the same native name and size has already been loaded.
      If it has then we use that one. */

      String nativeName = (String) fontNameMap.get(font.name.toLowerCase());

      if (nativeName == null) nativeName = (String) fontNameMap.get("default");

      String key = nativeName + "." + font.style + "." + font.size;

      if (!backwardCompat) {
        Map fa = font.getAttributes();
        Object obj;

        if ((obj = fa.get(TextAttribute.STRIKETHROUGH)) != null) {
          if (obj.equals(TextAttribute.STRIKETHROUGH_ON)) {
            key += ".s";
            strikethrough = true;
          }
        }

        if ((obj = fa.get(TextAttribute.UNDERLINE)) != null) {
          if (obj.equals(TextAttribute.UNDERLINE_ON)) {
            key += ".u";
            underline = true;
          }
        }
      }

      fm = (QtFontMetrics) fontMetricsMap.get(key);

      if (fm == null) {
        fontMetricsMap.put(
            key, fm = new QtFontMetrics(font, nativeName, font.style, strikethrough, underline));
      }

      font.metrics = fm;
    }

    return fm;
  }