Class FontUtil

java.lang.Object
com.jalios.jcms.font.FontUtil

public class FontUtil extends Object
  • Method Details

    • getFontCssPath

      public static Path getFontCssPath()
      Returns the directory containing generated font CSS files.
      Returns:
      the font CSS directory path
    • getFontLibPath

      public static Path getFontLibPath()
      Returns the root directory containing local font files.
      Returns:
      the local font library directory path
    • getWeightLabel

      public static String getWeightLabel(int weight)
      Returns a human-readable weight label.
      Parameters:
      weight - the CSS font weight
      Returns:
      the corresponding display label
    • getFont

      public static FontFamily getFont(String fontId)
    • extractFamilyName

      protected static String extractFamilyName(String fileName)
      Extracts a readable font family name from a file name.
      Parameters:
      fileName - the original uploaded file name
      Returns:
      the detected readable family name
    • extractWebFontFamily

      protected static String extractWebFontFamily(String url)
    • escapeIdentifier

      protected static String escapeIdentifier(String value, String defaultValue)
      Converts a display name into a stable technical identifier.
      Parameters:
      value - the display name to convert
      defaultValue - Value return if value parameter is empty
      Returns:
      a lowercase slug suitable for properties, folders, and CSS class names
    • analyzeVariant

      protected static FontVariant analyzeVariant(File file, String originalFileName) throws FontImportException
      Analyzes one file and creates a single font variant.
      Parameters:
      file - the physical font file
      originalFileName - the original or meaningful file name
      Returns:
      detected font variant
      Throws:
      FontImportException - if the file cannot be analyzed
    • getVariantKey

      protected static String getVariantKey(FontVariant variant)
      Builds a unique key identifying a variant by weight and style.
      Parameters:
      variant - the font variant
      Returns:
      a key such as "400.normal" or "700.italic"
    • compareSources

      protected static int compareSources(FontSource a, FontSource b)
      Compares font sources according to their preferred CSS format order.
      Parameters:
      a - the first font source
      b - the second font source
      Returns:
      a negative, zero, or positive value according to source priority
    • isRemoteUrl

      protected static boolean isRemoteUrl(String url)
    • rebuildFamilyCss

      protected static void rebuildFamilyCss(FontFamily family, Path familyDir, Path cssFile) throws FontImportException
      Rebuilds the CSS file for a font family by scanning its storage directory.
      Parameters:
      family - the target font family
      familyDir - the directory containing stored font files
      cssFile - the generated CSS file
      Throws:
      FontImportException - if a font file cannot be analyzed
    • getExtension

      public static String getExtension(String fileName)
      Returns the lowercase extension of a file name.
      Parameters:
      fileName - the file name to inspect
      Returns:
      the lowercase extension without the dot, or an empty string if missing