public final class FontSpec extends Object
Unlike Font
, this object:
alias
.
font
because
Java always uses 72DPI to interpret the font size expressed in points.
get(java.lang.String, int, int)
.
This class is thread-safe.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_FONT_SIZE
Default font size expressed in CSS points (pt).
|
String |
family
An alias (example: "sans-serif") or standard (example: "sans-serif")
font family.
|
Font |
font
The font corresponding to this specification.
|
static int |
MAX_FONT_SIZE
Maximal font size expressed in CSS points (pt).
|
static int |
MIN_FONT_SIZE
Minimal font size expressed in CSS points (pt).
|
int |
size
Font size in CSS points (pt).
|
int |
style
Font style; a combination of
Font.PLAIN ,
Font.BOLD and Font.ITALIC . |
Modifier and Type | Method and Description |
---|---|
static void |
alias(String aliasFamily,
int aliasStyle,
String standardFamily,
int standardStyle)
Maps specified fonts.
|
static void |
alias(String aliasFamily,
String standardFamily)
Maps specified font families.
|
static FontSpec |
create(String family,
int style,
int size,
int cssResolution)
Not part of the public, documented, API:
creates and returns specified font specification.
|
static FontSpec |
get(String family,
int style,
int size)
Returns specified font specification.
|
static int |
getCSSResolution()
Number of CSS pixels per inch is normally a fixed value, 96dpi.
|
static FontSpec |
getDefault()
Returns default font specification, a plain "sans-serif" font having
a
DEFAULT_FONT_SIZE size. |
static int |
getPreferredFontSize(Preferences prefs)
Returns user-preferred normal font size expressed in CSS points (pt).
|
String |
toString() |
public static final int MIN_FONT_SIZE
public static final int MAX_FONT_SIZE
public static final int DEFAULT_FONT_SIZE
public final String family
public final int style
Font.PLAIN
,
Font.BOLD
and Font.ITALIC
.public final int size
public final Font font
public static void alias(String aliasFamily, String standardFamily)
Initially font families "serif", "sans-serif", "monospace", "cursive" and "fantasy" are mapped respectively to "Serif", "SansSerif", "Monospaced", "Serif" and "Serif".
aliasFamily
- an alias for font family standardFamily.
Example: "monospace". Case-sensitive.standardFamily
- a font family supported by the Java runtime.
Examples: "Monospaced", "Courier New" (when this font has
been installed on the platform running Java). Case-sensitive.alias(String, int, String, int)
public static void alias(String aliasFamily, int aliasStyle, String standardFamily, int standardStyle)
aliasFamily
- an alias for font family standardFamily.
Example: "monospace". Case-sensitive.aliasStyle
- the style of the alias font.
A combination of Font.PLAIN
, Font.BOLD
and Font.ITALIC
.standardFamily
- a font family supported by the Java runtime.
Examples: "Monospaced", "Courier New" (when this font has
been installed on the platform running Java). Case-sensitive.standardStyle
- the style of the standard font.alias(String, String)
public static int getPreferredFontSize(Preferences prefs)
public static int getCSSResolution()
This fixed value, 96dpi, is automatically adjusted to take into
account the display scaling returned by
AWTUtil.getDisplayScaling()
. For example, for a display scaling
of 150%, the number of CSS pixels per inch is 144dpi.
CSS units and dots-per-inch
The unit "in" doesn't represent a physical inch on screen, but represents 96px. That means that whatever is the real screen pixel density, it is assumed to be 96dpi. On devices with a greater pixel density, "1in" will be smaller than 1 physical inch. Similarly "mm", "cm", and "pt" are not absolute length.
public static FontSpec getDefault()
DEFAULT_FONT_SIZE
size.public static FontSpec get(String family, int style, int size)
If needed font specification is created and cached.
family
- an alias (example: "sans-serif") or
standard (example: "SansSerif") font family. Case-sensitive.style
- font style; a combination of Font.PLAIN
,
Font.BOLD
and Font.ITALIC
size
- font size in points (pt)public static FontSpec create(String family, int style, int size, int cssResolution)