CanScan
Loading...
Searching...
No Matches
fr.softsf.canscan.util.FontManager Enum Reference

Singleton responsible for loading, applying, and scaling custom fonts in the Swing UI. More...

Collaboration diagram for fr.softsf.canscan.util.FontManager:

Public Member Functions

int getCharWidth ()
 Returns the width of a reference character ('W') for grid alignments.
int getLineHeight ()
 Returns the total line height based on current UI font metrics.
int getScaledDimension (int basePx)
 Calculates a scaled dimension based on the current font's line height.
void initialize ()
 Entry point to load resources and refresh the Look and Feel.

Public Attributes

 INSTANCE

Static Public Attributes

static final double BASE_LINE_HEIGHT_REFERENCE = 16.0
static final double BASELINE_CORRECTION_FACTOR = 0.11

Private Member Functions

double calculateVerticalOffset (Font font)
 Calculates the vertical offset required to center the font baseline.
FontMetrics getCurrentFontMetrics ()
 Retrieves the current font metrics from UIManager or provides a JRE fallback.
void loadLucioleFontAsDefaultFont ()
 Loads the Luciole TTF, registers it in the environment, and applies it to UIManager.
void loadMaterialIconsFont ()
 Loads Material Icons font into the Graphics Environment for icon rendering.

Static Private Attributes

static final String DEFAULT_FONT = "defaultFont"
static final JLabel DUMMY_JLABEL = new JLabel()
static final String FONT_LUCIOLE_PATH = "/font/Luciole-Regular.ttf"
static final String FONT_MATERIAL_ICONS_PATH = "/font/MaterialIcons-Regular.ttf"
static final Font JRE_GUARANTEED_FONT_FALLBACK_FOR_UNIT_TESTS

Detailed Description

Singleton responsible for loading, applying, and scaling custom fonts in the Swing UI.

This manager handles the Luciole and Material Icons fonts. It automatically calculates vertical offsets and scaling ratios to ensure consistent rendering across different operating systems (Windows, Linux) and High-DPI displays.

Member Function Documentation

◆ calculateVerticalOffset()

double fr.softsf.canscan.util.FontManager.calculateVerticalOffset ( Font font)
private

Calculates the vertical offset required to center the font baseline.

*

Parameters
fontThe font to measure.
Returns
The calculated Y-axis translation.

◆ getCharWidth()

int fr.softsf.canscan.util.FontManager.getCharWidth ( )

Returns the width of a reference character ('W') for grid alignments.

  • Returns
    Width in pixels.
Here is the call graph for this function:

◆ getCurrentFontMetrics()

FontMetrics fr.softsf.canscan.util.FontManager.getCurrentFontMetrics ( )
private

Retrieves the current font metrics from UIManager or provides a JRE fallback.

  • Returns
    Valid FontMetrics object.

◆ getLineHeight()

int fr.softsf.canscan.util.FontManager.getLineHeight ( )

Returns the total line height based on current UI font metrics.

  • Returns
    Height in pixels (ascent + descent + leading).
Here is the call graph for this function:

◆ getScaledDimension()

int fr.softsf.canscan.util.FontManager.getScaledDimension ( int basePx)

Calculates a scaled dimension based on the current font's line height.

This ensures graphical elements (like QR Codes) maintain visual consistency between Windows (HiDPI) and Linux environments.

Parameters
basePxThe reference dimension in pixels (e.g., 50px).
Returns
The scaled dimension adjusted for the current OS scaling factor.
Here is the call graph for this function:

◆ initialize()

void fr.softsf.canscan.util.FontManager.initialize ( )

Entry point to load resources and refresh the Look and Feel.

Here is the call graph for this function:

◆ loadLucioleFontAsDefaultFont()

void fr.softsf.canscan.util.FontManager.loadLucioleFontAsDefaultFont ( )
private

Loads the Luciole TTF, registers it in the environment, and applies it to UIManager.

Includes automated baseline correction via AffineTransform.

Here is the call graph for this function:

◆ loadMaterialIconsFont()

void fr.softsf.canscan.util.FontManager.loadMaterialIconsFont ( )
private

Loads Material Icons font into the Graphics Environment for icon rendering.

Member Data Documentation

◆ BASE_LINE_HEIGHT_REFERENCE

final double fr.softsf.canscan.util.FontManager.BASE_LINE_HEIGHT_REFERENCE = 16.0
static

◆ BASELINE_CORRECTION_FACTOR

final double fr.softsf.canscan.util.FontManager.BASELINE_CORRECTION_FACTOR = 0.11
static

◆ DEFAULT_FONT

final String fr.softsf.canscan.util.FontManager.DEFAULT_FONT = "defaultFont"
staticprivate

◆ DUMMY_JLABEL

final JLabel fr.softsf.canscan.util.FontManager.DUMMY_JLABEL = new JLabel()
staticprivate

◆ FONT_LUCIOLE_PATH

final String fr.softsf.canscan.util.FontManager.FONT_LUCIOLE_PATH = "/font/Luciole-Regular.ttf"
staticprivate

◆ FONT_MATERIAL_ICONS_PATH

final String fr.softsf.canscan.util.FontManager.FONT_MATERIAL_ICONS_PATH = "/font/MaterialIcons-Regular.ttf"
staticprivate

◆ INSTANCE

fr.softsf.canscan.util.FontManager.INSTANCE

◆ JRE_GUARANTEED_FONT_FALLBACK_FOR_UNIT_TESTS

final Font fr.softsf.canscan.util.FontManager.JRE_GUARANTEED_FONT_FALLBACK_FOR_UNIT_TESTS
staticprivate
Initial value:
=
new Font("Dialog", Font.PLAIN, 12)

The documentation for this enum was generated from the following file: