public class Font
Codename One currently supports 3 font types:
System fonts - these are very simplistic builtin fonts. They work on all platforms and come in one of 3 sizes. However, they are ubiquitous and work in every platform in all languages. A system font can be created using
int, int).TTF files - you can just place a TTF file in the src directory of the project and it will appear in the Codename One Designer as an option. You can load such a font using
java.lang.String).Native fonts - these aren’t supported on all platforms but generally they allow you to use a set of platform native good looking fonts. E.g. on Android the devices Roboto font will be used and on iOS Helvetica Neue will be used. You can load such a font using
java.lang.String).
WARNING: If you use a TTF file MAKE SURE not to delete the file when there MIGHT be a reference to it. This can cause hard to track down issues!
IMPORTANT: due to copyright restrictions we cannot distribute Helvetica and thus can’t simulate it. In the simulator you will see Roboto as the fallback in some cases and not the device font unless you are running on a Mac. Notice that the Roboto font from Google doesn’t support all languages and thus special characters might not work on the simulator but would work on the device.
The sample code below demonstrates a catalog of available fonts, the scr
private Label createForFont(Font fnt, String s) {
Label l = new Label(s);
l.getUnselectedStyle().setFont(fnt);
return l;
}
public void showForm() {
GridLayout gr = new GridLayout(5);
gr.setAutoFit(true);
Form hi = new Form("Fonts", gr);
int fontSize = Display.getInstance().convertToPixels(3);
// requires Handlee-Regular.ttf in the src folder root!
Font ttfFont = Font.createTrueTypeFont("Handlee", "Handlee-Regular.ttf").
derive(fontSize, Font.STYLE_PLAIN);
Font smallPlainSystemFont = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
Font mediumPlainSystemFont = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
Font largePlainSystemFont = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE);
Font smallBoldSystemFont = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL);
Font mediumBoldSystemFont = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
Font largeBoldSystemFont = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
Font smallItalicSystemFont = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_ITALIC, Font.SIZE_SMALL);
Font mediumItalicSystemFont = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_ITALIC, Font.SIZE_MEDIUM);
Font largeItalicSystemFont = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_ITALIC, Font.SIZE_LARGE);
Font smallPlainMonospaceFont = Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL);
Font mediumPlainMonospaceFont = Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
Font largePlainMonospaceFont = Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_LARGE);
Font smallBoldMonospaceFont = Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_SMALL);
Font mediumBoldMonospaceFont = Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
Font largeBoldMonospaceFont = Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_LARGE);
Font smallItalicMonospaceFont = Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_ITALIC, Font.SIZE_SMALL);
Font mediumItalicMonospaceFont = Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_ITALIC, Font.SIZE_MEDIUM);
Font largeItalicMonospaceFont = Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_ITALIC, Font.SIZE_LARGE);
Font smallPlainProportionalFont = Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);
Font mediumPlainProportionalFont = Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
Font largePlainProportionalFont = Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_LARGE);
Font smallBoldProportionalFont = Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL);
Font mediumBoldProportionalFont = Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
Font largeBoldProportionalFont = Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_LARGE);
Font smallItalicProportionalFont = Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_ITALIC, Font.SIZE_SMALL);
Font mediumItalicProportionalFont = Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_ITALIC, Font.SIZE_MEDIUM);
Font largeItalicProportionalFont = Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_ITALIC, Font.SIZE_LARGE);
String[] nativeFontTypes = {
"native:MainThin", "native:MainLight", "native:MainRegular", "native:MainBold", "native:MainBlack",
"native:ItalicThin", "native:ItalicLight", "native:ItalicRegular", "native:ItalicBold", "native:ItalicBlack"};
for(String s : nativeFontTypes) {
Font tt = Font.createTrueTypeFont(s, s).derive(fontSize, Font.STYLE_PLAIN);
hi.add(createForFont(tt, s));
}
hi.add(createForFont(ttfFont, "Handlee TTF Font")).
add(createForFont(smallPlainSystemFont, "smallPlainSystemFont")).
add(createForFont(mediumPlainSystemFont, "mediumPlainSystemFont")).
add(createForFont(largePlainSystemFont, "largePlainSystemFont")).
add(createForFont(smallBoldSystemFont, "smallBoldSystemFont")).
add(createForFont(mediumBoldSystemFont, "mediumBoldSystemFont")).
add(createForFont(largeBoldSystemFont, "largeBoldSystemFont")).
add(createForFont(smallPlainSystemFont, "smallItalicSystemFont")).
add(createForFont(mediumItalicSystemFont, "mediumItalicSystemFont")).
add(createForFont(largeItalicSystemFont, "largeItalicSystemFont")).
add(createForFont(smallPlainMonospaceFont, "smallPlainMonospaceFont")).
add(createForFont(mediumPlainMonospaceFont, "mediumPlainMonospaceFont")).
add(createForFont(largePlainMonospaceFont, "largePlainMonospaceFont")).
add(createForFont(smallBoldMonospaceFont, "smallBoldMonospaceFont")).
add(createForFont(mediumBoldMonospaceFont, "mediumBoldMonospaceFont")).
add(createForFont(largeBoldMonospaceFont, "largeBoldMonospaceFont")).
add(createForFont(smallItalicMonospaceFont, "smallItalicMonospaceFont")).
add(createForFont(mediumItalicMonospaceFont, "mediumItalicMonospaceFont")).
add(createForFont(largeItalicMonospaceFont, "largeItalicMonospaceFont")).
add(createForFont(smallPlainProportionalFont, "smallPlainProportionalFont")).
add(createForFont(mediumPlainProportionalFont, "mediumPlainProportionalFont")).
add(createForFont(largePlainProportionalFont, "largePlainProportionalFont")).
add(createForFont(smallBoldProportionalFont, "smallBoldProportionalFont")).
add(createForFont(mediumBoldProportionalFont, "mediumBoldProportionalFont")).
add(createForFont(largeBoldProportionalFont, "largeBoldProportionalFont")).
add(createForFont(smallItalicProportionalFont, "smallItalicProportionalFont")).
add(createForFont(mediumItalicProportionalFont, "mediumItalicProportionalFont")).
add(createForFont(largeItalicProportionalFont, "largeItalicProportionalFont"));
hi.show();
}
The demo code on the iPad simulator on a Mac
The demo code on an Android 5.1 OPO device (OnePlus One)
The Font class also supports bitmap fonts but this support is strictly aimed at legacy applications. We no longer maintain that functionality.
Methods
public static void clearDerivedFontCache() | Clears the cache of derived TrueType fonts. |
public static Font getBitmapFont(String fontName) | Deprecated Returns a previously loaded bitmap font from cache |
public static void clearBitmapCache() | Deprecated Bitmap fonts are cached this method allows us to flush the cache thus allows us to reload a font |
public static boolean isTrueTypeFileSupported() | Returns true if the underlying platform supports loading truetype fonts from a file. |
public static boolean isCreationByStringSupported() | Returns true if the underlying platform allows creating a font based on a user submitted string. |
public static boolean isNativeFontSchemeSupported() | Indicates whether the implementation supports loading a font “natively” to handle one of the common native prefixes |
public static Font createTrueTypeFont(String fontName) | Shorthand for createTrueTypeFont(name, name) which is useful for cases such as native: fonts. |
public static Font createTrueTypeFont(String fontName, float sizeMm) | Shorthand for createTrueTypeFont(name, name) & derive(size) which is useful for cases such as native: fonts. |
public static Font createTrueTypeFont(String fontName, float size, byte sizeUnit) | Shorthand for createTrueTypeFont(name, name) & derive(size) which is useful for cases such as native: fonts. |
public static Font createTrueTypeFont(String fontName, String fileName) | Creates a true type font with the given name/filename (font name might be different from the file name and is required by some devices e.g. iOS). |
public static Font create(String lookup) | Creates a new font instance based on the platform specific string name of the font. |
public static Font createBitmapFont(String name, Image bitmap, int[] cutOffsets, int[] charWidth, String charsets) | Deprecated Creates a bitmap font with the given arguments and places said font in the cache |
public static Font createBitmapFont(Image bitmap, int[] cutOffsets, int[] charWidth, String charsets) | Deprecated Creates a bitmap font with the given arguments |
public static Font createSystemFont(int face, int style, int size) | Creates a system native font in a similar way to common MIDP fonts |
public static Font getDefaultFont() | Return the global default font instance |
public static void setDefaultFont(Font f) | Sets the global default font instance |
public static boolean isBitmapFontEnabled() | Indicates whether bitmap fonts should be enabled when loading or the fallback system font should be used instead. |
public static void setBitmapFontEnabled(boolean enabled) | Indicates whether bitmap fonts should be enabled by default when loading or the fallback system font should be used instead. |
public Font derive(float size, int weight, byte unitType) | Creates a font based on this truetype font with the given pixel, WARNING! This method will only work in the case of truetype fonts! |
public Font deriveLetterSpacing(float letterSpacing) | Returns a variant of this truetype font with the given letter spacing (EM units) applied to its glyph advances. |
public Font derive(float sizePixels, int weight) | Creates a font based on this truetype font with the given pixel, WARNING! This method will only work in the case of truetype fonts! |
public boolean isTTFNativeFont() | Indicates if this is a TTF native font that can be derived and manipulated. |
public void addContrast(byte value) | Deprecated Increase the contrast of the bitmap font for rendering on top of a surface whose color is darker. |
public int charsWidth(char[] ch, int offset, int length) | Return the width of the given characters in this font instance |
public int substringWidth(String str, int offset, int len) | Return the width of the given string subset in this font instance |
public int stringWidth(String str) | Return the width of the given string in this font instance |
public int charWidth(char ch) | Return the width of the specific character when rendered alone |
public int getHeight() | Return the total height of the font |
public int getFace() | Return Optional operation returning the font face for system fonts |
public int getSize() | Return Optional operation returning the font size for system fonts |
public int getStyle() | Return Optional operation returning the font style for system fonts |
public String getCharset() | Returns a string containing all the characters supported by this font. |
public Object getNativeFont() | Returns the internal implementation specific font object |
public boolean equals(Object o) | Indicates whether some other object is “equal to” this one. |
public int hashCode() | Returns a hash code value for the object. |
public int getAscent() | The ascent is the amount by which the character ascends above the baseline. |
public int getDescent() | The descent is the amount by which the character descends below the baseline |
public float getPixelSize() | Returns the size with which the font object was created in case of truetype fonts/derived fonts. |
Inherited fields
From CN
NATIVE_MAIN_THIN, NATIVE_MAIN_LIGHT, NATIVE_MAIN_REGULAR, NATIVE_MAIN_BOLD, NATIVE_MAIN_BLACK, NATIVE_ITALIC_THIN, NATIVE_ITALIC_LIGHT, NATIVE_ITALIC_REGULAR, NATIVE_ITALIC_BOLD, NATIVE_ITALIC_BLACK, FACE_MONOSPACE, FACE_PROPORTIONAL, FACE_SYSTEM, SIZE_LARGE, SIZE_MEDIUM, SIZE_SMALL, STYLE_BOLD, STYLE_ITALIC, STYLE_UNDERLINED, STYLE_PLAIN, NORTH, SOUTH, WEST, EAST, CENTER, TOP, LEFT, BOTTOM, RIGHT, BASELINE, CENTER_BEHAVIOR_SCALE, CENTER_BEHAVIOR_CENTER, CENTER_BEHAVIOR_CENTER_ABSOLUTE, CENTER_BEHAVIOR_TOTAL_BELOW
From CN1Constants
DENSITY_VERY_LOW, DENSITY_LOW, DENSITY_MEDIUM, DENSITY_HIGH, DENSITY_VERY_HIGH, DENSITY_HD, DENSITY_560, DENSITY_2HD, DENSITY_4K, PICKER_TYPE_DATE, PICKER_TYPE_TIME, PICKER_TYPE_DATE_AND_TIME, PICKER_TYPE_STRINGS, PICKER_TYPE_DURATION, PICKER_TYPE_DURATION_HOURS, PICKER_TYPE_DURATION_MINUTES, PICKER_TYPE_CALENDAR, SMS_NOT_SUPPORTED, SMS_SEAMLESS, SMS_INTERACTIVE, SMS_BOTH, GALLERY_IMAGE, GALLERY_VIDEO, GALLERY_ALL, GALLERY_IMAGE_MULTI, GALLERY_VIDEO_MULTI, GALLERY_ALL_MULTI
Inherited methods
From CN
setBookmark, restoreToBookmark, getDragStartPercentage, setDragStartPercentage, createSoftWeakRef, extractHardRef, isEnableAsyncStackTraces, setEnableAsyncStackTraces, vibrate, announceForAccessibility, announceForAccessibility, isEdt, callSerially, callSeriallyOnIdle, scheduleBackgroundTask, callSeriallyAndWait, callSeriallyAndWait, invokeAndBlock, invokeWithoutBlocking, invokeWithoutBlockingWithResultSync, minimizeApplication, isMinimized, restoreMinimizedApplication, getCurrentForm, getCurrentTopLevel, getDisplayWidth, getDisplayHeight, convertToPixels, convertToPixels, convertToPixels, convertToPixels, getResourceAsStream, addEdtErrorHandler, removeEdtErrorHandler, exitApplication, exitAndClearTask, isExitAndClearTaskSupported, getProperty, setProperty, canExecute, execute, downloadBytesAsFile, getDeviceDensity, isPortrait, requestFullScreen, exitFullScreen, isInFullScreenMode, isFullScreenSupported, canForceOrientation, lockOrientation, isLockOrientation, unlockOrientation, isTablet, isDesktop, isMultiWindowSupported, isWatch, isTV, isCarConnected, getCurrentPointerEvent, getPointerButton, getPressedButtonMask, getPointerType, getPointerPressure, getPointerTiltX, getPointerTiltY, getPointerContactSize, isStylusPointer, isFoldable, getDevicePosture, addPostureListener, removePostureListener, isDesktopMode, getDisplayCount, isExternalDisplayConnected, getDesktopSize, getWindowBounds, setWindowSize, getInitialWindowSizeHintPercent, setInitialWindowSizeHintPercent, addWindowListener, removeWindowListener, canDial, isDarkMode, isHighContrastEnabled, isDifferentiateWithoutColorEnabled, getColorVisionDeficiency, isReduceMotionEnabled, isReduceTransparencyEnabled, isBoldTextEnabled, isInvertColorsEnabled, isGrayscaleEnabled, isOnOffSwitchLabelsEnabled, isScreenReaderEnabled, setDarkMode, openGallery, openFileChooser, getPlatformName, getSimd, isGpuSupported, dial, getSMSSupport, sendSMS, sendSMS, share, isNativeShareSupported, isNativeInAppReviewSupported, requestNativeInAppReview, share, registerPush, deregisterPush, createThread, startThread, isScreenSaverDisableSupported, setScreenSaverEnabled, hasCamera, isNativePickerTypeSupported, showNativePicker, log, log, sendLog, sendMessage, isSimulator, addDefaultHeader, addToQueueAndWait, addToQueue, killAndWait, addNetworkErrorListener, removeNetworkErrorListener, addNetworkProgressListener, removeNetworkProgressListener, updateNetworkThreadCount, clearStorageCache, flushStorageCache, deleteStorageFile, clearStorage, createStorageOutputStream, createStorageInputStream, existsInStorage, listStorageEntries, storageEntrySize, writeObjectToStorage, readObjectFromStorage, getFileSystemRoots, getFileSystemRootType, listFiles, getFileSystemRootSizeBytes, getFileSystemRootAvailableSpace, mkdir, delete, existsInFileSystem, isHiddenFile, setHiddenFile, renameFile, getFileLength, getFileLastModifiedFile, isDirectory, openFileOutputStream, openFileInputStream, openFileOutputStream, getAppHomePath, hasCachesDir, getCachesDir, canInstallOnHomescreen, promptInstallOnHomescreen, onCanInstallOnHomescreen, captureScreen, addMessageListener, removeMessageListener, postMessage, setTimeout, setInterval, getSharedJavascriptContext, getPluginSupport
Method details
clearDerivedFontCache
public static void clearDerivedFontCache()getBitmapFont
public static Font getBitmapFont(String fontName)Parameters
fontNameString- the font name is the logical name of the font
Returns
See also
clearBitmapCache
public static void clearBitmapCache()isTrueTypeFileSupported
public static boolean isTrueTypeFileSupported()Returns
isCreationByStringSupported
public static boolean isCreationByStringSupported()Returns
isNativeFontSchemeSupported
public static boolean isNativeFontSchemeSupported()Returns
createTrueTypeFont
public static Font createTrueTypeFont(String fontName)createTrueTypeFont(name, name) which is useful
for cases such as native: fonts. If a TTF file is passed this method will throw an exception!Parameters
fontNameString- the native font name. Notice that TTF file names are prohibited
Returns
createTrueTypeFont
public static Font createTrueTypeFont(String fontName, float sizeMm)createTrueTypeFont(name, name) &
derive(size) which is useful for cases such as native: fonts.Parameters
fontNameString- the native font name
sizeMmfloat- the size in mm
Returns
createTrueTypeFont
public static Font createTrueTypeFont(String fontName, float size, byte sizeUnit)createTrueTypeFont(name, name) &
derive(size) which is useful for cases such as native: fonts.Parameters
fontNameString- the native font name
sizefloat- the size in the specified unit.
sizeUnitbyte- The unit type of the size. One of
com.codename1.ui.plaf.Style#UNIT_TYPE_DIPS,
Returns
createTrueTypeFont
public static Font createTrueTypeFont(String fontName, String fileName)Creates a true type font with the given name/filename (font name might be different from the file name and is required by some devices e.g. iOS). The font file must reside in the src root of the project in order to be detectable. The file name should contain no slashes or any such value.
Important some platforms e.g. iOS don’t support changing the weight of the font and require you to use the font name matching the weight, so the weight argument to derive will be ignored!
This system also supports a special “native:” prefix that uses system native fonts e.g. HelveticaNeue on iOS and Roboto on Android. It supports the following types: native:MainThin, native:MainLight, native:MainRegular, native:MainBold, native:MainBlack, native:ItalicThin, native:ItalicLight, native:ItalicRegular, native:ItalicBold, native:ItalicBlack. Important due to copyright restrictions we cannot distribute Helvetica and thus can’t simulate it. In the simulator you will see Roboto and not the device font unless you are running on a Mac
Parameters
fontNameString- the name of the font
fileNameString- the file name of the font as it appears in the src directory of the project, it MUST end with the .ttf or .otf extension!
Returns
create
public static Font create(String lookup)Parameters
lookupString- a set of platform specific names delimited by commas, the first succefully loaded font will be used
Returns
createBitmapFont
public static Font createBitmapFont(String name, Image bitmap, int[] cutOffsets, int[] charWidth, String charsets)Parameters
nameString- the name for the font in the cache
bitmapImage- a transparency map in red and black that indicates the characters
cutOffsetsint[]- character offsets matching the bitmap pixels and characters in the font
charWidthint[]- The width of the character when drawing… this should not be confused with
the number of
cutOffset[o + 1] - cutOffset[o]. They are completely different since a character can be “wider” and “seep” into the next region. This is especially true with italic characters all of which “lean” outside of their bounds. charsetsString- the set of characters in the font
Returns
createBitmapFont
public static Font createBitmapFont(Image bitmap, int[] cutOffsets, int[] charWidth, String charsets)Parameters
bitmapImage- a transparency map in red and black that indicates the characters
cutOffsetsint[]- character offsets matching the bitmap pixels and characters in the font
charWidthint[]- The width of the character when drawing… this should not be confused with
the number of
cutOffset[o + 1] - cutOffset[o]. They are completely different since a character can be “wider” and “seep” into the next region. This is especially true with italic characters all of which “lean” outside of their bounds. charsetsString- the set of characters in the font
Returns
createSystemFont
public static Font createSystemFont(int face, int style, int size)Parameters
faceint- One of FACE_SYSTEM, FACE_PROPORTIONAL, FACE_MONOSPACE
styleint- one of STYLE_PLAIN, STYLE_ITALIC, STYLE_BOLD
sizeint- One of SIZE_SMALL, SIZE_MEDIUM, SIZE_LARGE
Returns
getDefaultFont
public static Font getDefaultFont()Returns
setDefaultFont
public static void setDefaultFont(Font f)Parameters
fFont- the global default font instance
isBitmapFontEnabled
public static boolean isBitmapFontEnabled()Returns
setBitmapFontEnabled
public static void setBitmapFontEnabled(boolean enabled)Parameters
enabledboolean- true to enable bitmap font loading (if they exist in the resource)
derive
public Font derive(float size, int weight, byte unitType)Creates a font based on this truetype font with the given pixel, WARNING! This method will only work in the case of truetype fonts!
Important some platforms e.g. iOS don’t support changing the weight of the font and require you to use the font name matching the weight, so the weight argument to derive will be ignored!
Parameters
sizefloat- the size of the font in the specified unit type.
weightint- PLAIN, BOLD or ITALIC weight based on the constants in this class
unitTypebyte- The unit type of the size. One of
com.codename1.ui.plaf.Style#UNIT_TYPE_DIPS,com.codename1.ui.plaf.Style#UNIT_TYPE_PIXELS,com.codename1.ui.plaf.Style#UNIT_TYPE_REM,com.codename1.ui.plaf.Style#UNIT_TYPE_VW,com.codename1.ui.plaf.Style#UNIT_TYPE_VH,com.codename1.ui.plaf.Style#UNIT_TYPE_VMIN,com.codename1.ui.plaf.Style#UNIT_TYPE_VMAX.
Returns
deriveLetterSpacing
public Font deriveLetterSpacing(float letterSpacing)derive
public Font derive(float sizePixels, int weight)Creates a font based on this truetype font with the given pixel, WARNING! This method will only work in the case of truetype fonts!
Important some platforms e.g. iOS don’t support changing the weight of the font and require you to use the font name matching the weight, so the weight argument to derive will be ignored!
Parameters
sizePixelsfloat- the size of the font in pixels
weightint- PLAIN, BOLD or ITALIC weight based on the constants in this class
Returns
isTTFNativeFont
public boolean isTTFNativeFont()Returns
addContrast
public void addContrast(byte value)Increase the contrast of the bitmap font for rendering on top of a surface whose color is darker. This is useful when drawing anti-aliased bitmap fonts using a light color (e.g. white) on top of a dark surface (e.g. black), the font often breaks down if its contrast is not increased due to the way alpha blending appears to the eye.
Notice that this method only works in one way, contrast cannot be decreased properly in a font and it should be cleared and reloaed with a Look and Feel switch.
Parameters
valuebyte- the value to increase
charsWidth
public int charsWidth(char[] ch, int offset, int length)Parameters
chchar[]- array of characters
offsetint- characters offsets
lengthint- characters length
Returns
substringWidth
public int substringWidth(String str, int offset, int len)Parameters
strString- the given string
offsetint- the string offset
lenint- the len od string
Returns
stringWidth
public int stringWidth(String str)Parameters
strString- the given string *
Returns
charWidth
public int charWidth(char ch)Parameters
chchar- the specific character
Returns
getHeight
public int getHeight()Returns
getFace
public int getFace()Returns
getSize
public int getSize()Returns
getStyle
public int getStyle()Returns
getCharset
public String getCharset()Returns
getNativeFont
public Object getNativeFont()Returns
equals
public boolean equals(Object o)hashCode
public int hashCode()getAscent
public int getAscent()Returns
getDescent
public int getDescent()Returns
getPixelSize
public float getPixelSize()