In the MIDP 2.0 specification, only three sizes can be used for fonts: small, medium, and large. The height of the created font depends on the screen resolution and cannot be changed. Custom font heights are supported on Symbian devices with Nokia UI API 1.2 or newer.
Note: The Series 40 platform provides a stub implementation of the custom font height feature. This means that you can call the associated interface in your MIDlet, but it provides no functionality on Series 40 devices. So, even though you cannot actually use this feature on Series 40 devices, you can compile the MIDlet with the interface calls in place. The stub implementation is supported from Series 40 6th Edition FP 1 onwards. Earlier Series 40 releases do not support this feature in any form.
To create fonts with a custom height, use the DirectUtils.getFont
method of the Nokia
UI API. The created font instance has the same characteristics as
a standard font except for the height. You can specify the font face
and style in the same way as with standard fonts.
To determine whether the device supports the DirectUtils.getFont
method, use the com.nokia.mid.ui.customfontsize
system
property.
Fonts created with DirectUtils.getFont
are
supported only for Graphics
instances in low-level LCDUI
components (Canvas
, CustomItem
, Image
). If a font with a custom height
is defined for a high-level LCDUI component, the font is replaced
by the default font.
The following code snippet shows you how to create a font with a custom height. The first font is a standard one with the size set to large, while the second font has a custom height of 50 pixels.
public void paint(javax.microedition.lcdui.Graphics g) { g.setColor(0xff000000); String text = "Text 123"; // create standard font Font font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_LARGE); g.setFont(font); g.drawString(text, x, y, Graphics.TOP | Graphics.LEFT); y += font.getHeight() + 10; // create font with custom height font = DirectUtils.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, 50); g.setFont(font); g.drawString(text, x, y, Graphics.TOP | Graphics.LEFT); }
The following figure shows the two fonts as they are displayed on the device screen.
Figure: Standard font with size set to large (upper string) and custom font with height set to 50 pixels (lower string)
The height of the fonts created with DirectUtils.getFont
includes extra space (leading) between lines of text. For example,
the custom font created in the above code snippet is 50 pixels in
height when both the leading and font are combined.