Class DefaultFontRegistry

java.lang.Object
dev.jcputney.mjml.render.DefaultFontRegistry

public final class DefaultFontRegistry extends Object
Registry of well-known web fonts that MJML auto-imports when used in font-family. When a component uses one of these fonts, it is automatically registered in the GlobalContext even without an explicit <mj-font> tag.
  • Method Details

    • registerUsedFonts

      public static void registerUsedFonts(String fontFamily, GlobalContext ctx)
      Checks the given font-family string against known default fonts and registers any matches in the GlobalContext (unless already registered by an explicit mj-font).
      Parameters:
      fontFamily - the CSS font-family string to check for known fonts
      ctx - the global context to register discovered fonts in
    • registerUsedFonts

      public static void registerUsedFonts(String fontFamily, GlobalContext ctx, Set<String> registeredNames)
      Checks the given font-family string against known default fonts and registers any matches in the GlobalContext (unless already registered by an explicit mj-font). This overload accepts a pre-built set of registered font names, avoiding the overhead of rebuilding it on every call. The caller is responsible for keeping the set in sync (the set is mutated in place when fonts are added).
      Parameters:
      fontFamily - the CSS font-family string to check for known fonts
      ctx - the global context to register discovered fonts in
      registeredNames - mutable set of already-registered font names for O(1) lookup
    • buildRegisteredNameSet

      public static Set<String> buildRegisteredNameSet(GlobalContext ctx)
      Builds a mutable set of currently registered font names from the given context.
      Parameters:
      ctx - the global context to read font registrations from
      Returns:
      a mutable set of registered font names