📄 font.java
字号:
/* * @(#)Font.java 1.35 02/08/14 @(#) * * Copyright (c) 1999-2002 Sun Microsystems, Inc. All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms. */package javax.microedition.lcdui;/** * The <code>Font</code> class represents fonts and font * metrics. <code>Fonts</code> cannot be * created by applications. Instead, applications query for fonts * based on * font attributes and the system will attempt to provide a font that * matches * the requested attributes as closely as possible. * * <p> A <code>Font's</code> attributes are style, size, and face. Values for * attributes must be specified in terms of symbolic constants. Values for * the style attribute may be combined using the bit-wise * <code>OR</code> operator, * whereas values for the other attributes may not be combined. For example, * the value </p> * * <p> <code> * STYLE_BOLD | STYLE_ITALIC * </code> </p> * * <p> may be used to specify a bold-italic font; however </p> * * <p> <code> * SIZE_LARGE | SIZE_SMALL * </code> </p> * * <p> is illegal. </p> * * <p> The values of these constants are arranged so that zero is valid for * each attribute and can be used to specify a reasonable default font * for the system. For clarity of programming, the following symbolic * constants are provided and are defined to have values of zero: </p> * * <p> <ul> * <li> <code> STYLE_PLAIN </code> </li> * <li> <code> SIZE_MEDIUM </code> </li> * <li> <code> FACE_SYSTEM </code> </li> * </ul> </p> * * <p> Values for other attributes are arranged to have disjoint bit patterns * in order to raise errors if they are inadvertently misused (for example, * using <code>FACE_PROPORTIONAL</code> where a style is * required). However, the values * for the different attributes are not intended to be combined with each * other. </p> * @since MIDP 1.0 */public final class Font { /** * The plain style constant. This may be combined with the * other style constants for mixed styles. * * <P>Value <code>0</code> is assigned to <code>STYLE_PLAIN</code>.</P> */ public static final int STYLE_PLAIN = 0; /** * The bold style constant. This may be combined with the * other style constants for mixed styles. * * <P>Value <code>1</code> is assigned to <code>STYLE_BOLD</code>.</P> */ public static final int STYLE_BOLD = 1; /** * The italicized style constant. This may be combined with * the other style constants for mixed styles. * * <P>Value <code>2</code> is assigned to <code>STYLE_ITALIC</code>.</P> */ public static final int STYLE_ITALIC = 2; /** * The underlined style constant. This may be combined with * the other style constants for mixed styles. * * <P>Value <code>4</code> is assigned to <code>STYLE_UNDERLINED</code>.</P> */ public static final int STYLE_UNDERLINED = 4; /** * The "small" system-dependent font size. * * <P>Value <code>8</code> is assigned to <code>STYLE_SMALL</code>.</P> */ public static final int SIZE_SMALL = 8; /** * The "medium" system-dependent font size. * * <P>Value <code>0</code> is assigned to <code>STYLE_MEDIUM</code>.</P> */ public static final int SIZE_MEDIUM = 0; /** * The "large" system-dependent font size. * * <P>Value <code>16</code> is assigned to <code>SIZE_LARGE</code>.</P> */ public static final int SIZE_LARGE = 16; /** * The "system" font face. * * <P>Value <code>0</code> is assigned to <code>FACE_SYSTEM</code>.</P> */ public static final int FACE_SYSTEM = 0; /** * The "monospace" font face. * * <P>Value <code>32</code> is assigned to <code>FACE_MONOSPACE</code>.</P> */ public static final int FACE_MONOSPACE = 32; /** * The "proportional" font face. * * <P>Value <code>64</code> is assigned to * <code>FACE_PROPORTIONAL</code>.</P> */ public static final int FACE_PROPORTIONAL = 64; /** * Default font specifier used to draw Item and Screen contents. * * <code>FONT_STATIC_TEXT</code> has the value <code>0</code>. * * @see #getFont(int fontSpecifier) * @since MIDP 2.0 */ public static final int FONT_STATIC_TEXT = 0; /** * Font specifier used by the implementation to draw text input by * a user. * * <code>FONT_INPUT_TEXT</code> has the value <code>1</code>. * * @see #getFont(int fontSpecifier) * @since MIDP 2.0 */ public static final int FONT_INPUT_TEXT = 1; /** * Gets the <code>Font</code> used by the high level user interface * for the <code>fontSpecifier</code> passed in. It should be used * by subclasses of * <code>CustomItem</code> and <code>Canvas</code> to match user * interface on the device. * * @param fontSpecifier one of <code>FONT_INPUT_TEXT</code>, or * <code>FONT_STATIC_TEXT</code> * @return font that corresponds to the passed in font specifier * @throws IllegalArgumentException if <code>fontSpecifier</code> is not * a valid fontSpecifier * @since MIDP 2.0 */ public static Font getFont(int fontSpecifier) { Font font; switch (fontSpecifier) { case FONT_STATIC_TEXT: // has the UE team defined RI fonts case FONT_INPUT_TEXT: // for these two options? font = DEFAULT_FONT; break; default: throw new IllegalArgumentException(); } return font; } /** * Construct a new Font object * * @param face The face to use to construct the Font * @param style The style to use to construct the Font * @param size The point size to use to construct the Font */ private Font(int face, int style, int size) { this.face = face; this.style = style; this.size = size; init(face, style, size); } /** * Gets the default font of the system. * @return the default font */ public static Font getDefaultFont() { // SYNC NOTE: return of atomic value, no locking necessary return DEFAULT_FONT; } /** * Obtains an object representing a font having the specified face, style, * and size. If a matching font does not exist, the system will * attempt to provide the closest match. This method <em>always</em> * returns * a valid font object, even if it is not a close match to the request. * * @param face one of <code>FACE_SYSTEM</code>, * <code>FACE_MONOSPACE</code>, or <code>FACE_PROPORTIONAL</code> * @param style <code>STYLE_PLAIN</code>, or a combination of * <code>STYLE_BOLD</code>, * <code>STYLE_ITALIC</code>, and <code>STYLE_UNDERLINED</code> * @param size one of <code>SIZE_SMALL</code>, <code>SIZE_MEDIUM</code>, * or <code>SIZE_LARGE</code> * @return instance the nearest font found * @throws IllegalArgumentException if <code>face</code>, * <code>style</code>, or <code>size</code> are not * legal values */ public static Font getFont(int face, int style, int size) { if ((face != FACE_SYSTEM) && (face != FACE_MONOSPACE) && (face != FACE_PROPORTIONAL)) { throw new IllegalArgumentException("Unsupported face"); } if ((style & ((STYLE_UNDERLINED << 1) - 1)) != style) { throw new IllegalArgumentException("Illegal style"); } if ((size != SIZE_SMALL) && (size != SIZE_MEDIUM) && (size != SIZE_LARGE)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -