/**
   * Installs the given font in the preference store and optionally the font registry.
   *
   * @param definition the font definition
   * @param registry the font registry
   * @param store the preference store from which to set and obtain font data
   * @param setInRegistry whether the color should be put into the registry as well as having its
   *     default preference set
   */
  private static void installFont(
      FontDefinition definition, ITheme theme, IPreferenceStore store, boolean setInRegistry) {
    FontRegistry registry = theme.getFontRegistry();

    String id = definition.getId();
    String key = createPreferenceKey(theme, id);
    FontData[] prefFont = store != null ? PreferenceConverter.getFontDataArray(store, key) : null;
    FontData[] defaultFont = null;
    if (definition.getValue() != null) {
      defaultFont = definition.getValue();
    } else if (definition.getDefaultsTo() != null) {
      defaultFont =
          registry.filterData(
              registry.getFontData(definition.getDefaultsTo()),
              Workbench.getInstance().getDisplay());
    } else {
      // values pushed in from jface property files.  Very ugly.
      Display display = Workbench.getInstance().getDisplay();

      // If in high contrast, ignore the defaults in jface and use the default (system) font.
      // This is a hack to address bug #205474. See bug #228207 for a future fix.
      FontData[] fontData =
          JFaceResources.getFontRegistry()
              .getFontData(display.getHighContrast() ? JFaceResources.DEFAULT_FONT : id);
      defaultFont = registry.bestDataArray(fontData, display);
    }

    if (setInRegistry) {
      if (prefFont == null || prefFont == PreferenceConverter.FONTDATA_ARRAY_DEFAULT_DEFAULT) {
        prefFont = defaultFont;
      }

      if (prefFont != null) {
        registry.put(id, prefFont);
      }
    }

    if (defaultFont != null && store != null) {
      PreferenceConverter.setDefault(store, key, defaultFont);
    }
  }