Module com.googlecode.lanterna
Class AWTTerminalFontConfiguration
- java.lang.Object
-
- com.googlecode.lanterna.terminal.swing.AWTTerminalFontConfiguration
-
- Direct Known Subclasses:
SwingTerminalFontConfiguration
public class AWTTerminalFontConfiguration extends java.lang.Object
This class encapsulates the font information used by anAWTTerminal
. By customizing this class, you can choose which fonts are going to be used by anAWTTerminal
component and some other related settings.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AWTTerminalFontConfiguration.BoldMode
Controls how the SGR bold will take effect when enabled on a character.
-
Field Summary
Fields Modifier and Type Field Description private AWTTerminalFontConfiguration.BoldMode
boldMode
static int
DEFAULT_FONT_SIZE
The default font size used unless overriddenprivate int
fontHeight
private java.util.List<java.awt.Font>
fontPriority
private int
fontWidth
private static java.util.Set<java.lang.String>
MONOSPACE_CHECK_OVERRIDE
private static java.util.Set<java.lang.Character>
SYMBOLS_CACHE
private boolean
useAntiAliasing
-
Constructor Summary
Constructors Modifier Constructor Description protected
AWTTerminalFontConfiguration(boolean useAntiAliasing, AWTTerminalFontConfiguration.BoldMode boldMode, java.awt.Font... fontsInOrderOfPriority)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.awt.Font[]
filterMonospaced(java.awt.Font... fonts)
Given an array of fonts, returns another array with only the ones that are monospaced.private static int
getAdjustedFontSize(int fontSize)
static AWTTerminalFontConfiguration
getDefault()
This is the default font settings that will be used if you don't specify anythingprivate static java.util.List<java.awt.Font>
getDefaultFonts(int fontSize)
private static java.util.List<java.awt.Font>
getDefaultLinuxFonts(int fontSize)
static AWTTerminalFontConfiguration
getDefaultOfSize(int fontSize)
Returns the default font settings except for a custom font size to use.private static java.util.List<java.awt.Font>
getDefaultWindowsFonts(int fontSize)
(package private) java.awt.Font
getFontForCharacter(TextCharacter character)
Given a certain character, return the font to use for drawing it.private java.awt.Font
getFontForCharacter(java.lang.String string)
int
getFontHeight()
Returns the vertical size in pixels of the fonts configuredprivate int
getFontHeight(java.awt.Font font)
private java.awt.font.FontRenderContext
getFontRenderContext()
int
getFontWidth()
Returns the horizontal size in pixels of the fonts configuredprivate int
getFontWidth(java.awt.Font font)
private static int
getHPIAdjustedFontSize(int baseFontSize)
boolean
isAntiAliased()
Returnstrue
if anti-aliasing has been enabled,false
otherwiseprivate static boolean
isFontMonospaced(java.awt.Font font)
private boolean
isNotASymbol(char character)
static AWTTerminalFontConfiguration
newInstance(java.awt.Font... fontsInOrderOfPriority)
Creates a new font configuration from a list of fonts in order of priority.protected static java.awt.Font[]
selectDefaultFont()
Returns the default font to use depending on the platformprotected static java.awt.Font[]
selectDefaultFont(int fontSize)
Returns the default font to use depending on the platform
-
-
-
Field Detail
-
DEFAULT_FONT_SIZE
public static final int DEFAULT_FONT_SIZE
The default font size used unless overridden- See Also:
- Constant Field Values
-
MONOSPACE_CHECK_OVERRIDE
private static final java.util.Set<java.lang.String> MONOSPACE_CHECK_OVERRIDE
-
fontPriority
private final java.util.List<java.awt.Font> fontPriority
-
fontWidth
private final int fontWidth
-
fontHeight
private final int fontHeight
-
useAntiAliasing
private final boolean useAntiAliasing
-
boldMode
private final AWTTerminalFontConfiguration.BoldMode boldMode
-
SYMBOLS_CACHE
private static final java.util.Set<java.lang.Character> SYMBOLS_CACHE
-
-
Constructor Detail
-
AWTTerminalFontConfiguration
protected AWTTerminalFontConfiguration(boolean useAntiAliasing, AWTTerminalFontConfiguration.BoldMode boldMode, java.awt.Font... fontsInOrderOfPriority)
-
-
Method Detail
-
getDefaultWindowsFonts
private static java.util.List<java.awt.Font> getDefaultWindowsFonts(int fontSize)
-
getDefaultLinuxFonts
private static java.util.List<java.awt.Font> getDefaultLinuxFonts(int fontSize)
-
getDefaultFonts
private static java.util.List<java.awt.Font> getDefaultFonts(int fontSize)
-
getAdjustedFontSize
private static int getAdjustedFontSize(int fontSize)
-
getHPIAdjustedFontSize
private static int getHPIAdjustedFontSize(int baseFontSize)
-
selectDefaultFont
protected static java.awt.Font[] selectDefaultFont()
Returns the default font to use depending on the platform- Returns:
- Default font to use, system-dependent
-
selectDefaultFont
protected static java.awt.Font[] selectDefaultFont(int fontSize)
Returns the default font to use depending on the platform- Parameters:
fontSize
- The size of the fonts to use- Returns:
- Default font to use, system-dependent
-
getDefault
public static AWTTerminalFontConfiguration getDefault()
This is the default font settings that will be used if you don't specify anything- Returns:
- An
AWTTerminal
font configuration object with default values set up
-
getDefaultOfSize
public static AWTTerminalFontConfiguration getDefaultOfSize(int fontSize)
Returns the default font settings except for a custom font size to use.- Parameters:
fontSize
- Size of the font- Returns:
- An
AWTTerminal
font configuration object with default values set up
-
filterMonospaced
public static java.awt.Font[] filterMonospaced(java.awt.Font... fonts)
Given an array of fonts, returns another array with only the ones that are monospaced. The fonts in the result will have the same order as in which they came in. A font is considered monospaced if the width of 'i' and 'W' is the same.- Parameters:
fonts
- Fonts to filter monospaced fonts from- Returns:
- Array with the fonts from the input parameter that were monospaced
-
newInstance
public static AWTTerminalFontConfiguration newInstance(java.awt.Font... fontsInOrderOfPriority)
Creates a new font configuration from a list of fonts in order of priority. This works by having the terminal attempt to draw each character with the fonts in the order they are specified in and stop once we find a font that can actually draw the character. For ASCII characters, it's very likely that the first font will always be used.- Parameters:
fontsInOrderOfPriority
- Fonts to use when drawing text, in order of priority- Returns:
- Font configuration built from the font list
-
getFontForCharacter
java.awt.Font getFontForCharacter(TextCharacter character)
Given a certain character, return the font to use for drawing it. The method will go through all fonts passed in to thisAWTTerminalFontConfiguration
in the order of priority specified and chose the first font which is capable of drawingcharacter
. If no such font is found, the normal fonts is returned (and probably won't be able to draw the character).- Parameters:
character
- Character to find a font for- Returns:
- Font which the
character
should be drawn using
-
getFontForCharacter
private java.awt.Font getFontForCharacter(java.lang.String string)
-
getFontWidth
public int getFontWidth()
Returns the horizontal size in pixels of the fonts configured- Returns:
- Horizontal size in pixels of the fonts configured
-
getFontHeight
public int getFontHeight()
Returns the vertical size in pixels of the fonts configured- Returns:
- Vertical size in pixels of the fonts configured
-
isAntiAliased
public boolean isAntiAliased()
Returnstrue
if anti-aliasing has been enabled,false
otherwise- Returns:
true
if anti-aliasing has been enabled,false
otherwise
-
isFontMonospaced
private static boolean isFontMonospaced(java.awt.Font font)
-
getFontWidth
private int getFontWidth(java.awt.Font font)
-
getFontHeight
private int getFontHeight(java.awt.Font font)
-
getFontRenderContext
private java.awt.font.FontRenderContext getFontRenderContext()
-
isNotASymbol
private boolean isNotASymbol(char character)
-
-