⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 font.java

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *    * * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER *  * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. *  * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). *  * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA *  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */package javax.microedition.lcdui;import com.sun.me.gci.renderer.GCIFontEnvironment;import com.sun.me.gci.renderer.GCIFont;/** * 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 &quot;small&quot; 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 &quot;medium&quot; 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 &quot;large&quot; 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 &quot;system&quot; font face.     *     * <P>Value <code>0</code> is assigned to <code>FACE_SYSTEM</code>.</P>     */    public static final int FACE_SYSTEM = 0;      /**     * The &quot;monospace&quot; font face.     *     * <P>Value <code>32</code> is assigned to <code>FACE_MONOSPACE</code>.</P>     */    public static final int FACE_MONOSPACE = 32;      /**     * The &quot;proportional&quot; 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)     */    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)     */    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     */    public static Font getFont(int fontSpecifier) {        Font font;        switch (fontSpecifier) {        case FONT_STATIC_TEXT:         case FONT_INPUT_TEXT:            font = getDefaultFont();            break;        default:            throw new IllegalArgumentException();        }        return font;    }    /**     * Construct a new Font object     *     * @param inp_face The face to use to construct the Font     * @param inp_style The style to use to construct the Font     * @param inp_size The point size to use to construct the Font     */    private Font(int inp_face, int inp_style, int inp_size) {        face  = inp_face;        style = inp_style;        size  = inp_size;        gciFont = 	    GCIFontEnvironment.getInstance().getFont(getGCIFontFace(inp_face), 						     getGCIFontStyle(inp_style),						     getGCIFontSize(inp_size),						     isUnderlined(),						     false);        baseline = gciFont.getMaxAscent();        glyphHeight = baseline + gciFont.getMaxDescent();        height = glyphHeight + gciFont.getLeading();    }    /**     * Gets the default font of the system.     * @return the default font     */    public static Font getDefaultFont() {        synchronized (Display.LCDUILock) {            if (DEFAULT_FONT == null)                DEFAULT_FONT = new Font(FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM);            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 inp_face one of <code>FACE_SYSTEM</code>,     * <code>FACE_MONOSPACE</code>, or <code>FACE_PROPORTIONAL</code>     * @param inp_style <code>STYLE_PLAIN</code>, or a combination of     * <code>STYLE_BOLD</code>,     * <code>STYLE_ITALIC</code>, and <code>STYLE_UNDERLINED</code>     * @param inp_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 inp_face, int inp_style, int inp_size) {        if ((inp_face != FACE_SYSTEM)             && (inp_face != FACE_MONOSPACE)            && (inp_face != FACE_PROPORTIONAL)) {            throw new IllegalArgumentException("Unsupported face");        }        if ((inp_style & ((STYLE_UNDERLINED << 1) - 1)) != inp_style) {            throw new IllegalArgumentException("Illegal style");        }        if ((inp_size != SIZE_SMALL)             && (inp_size != SIZE_MEDIUM)            && (inp_size != SIZE_LARGE)) {            throw new IllegalArgumentException("Unsupported size");        }        synchronized (Display.LCDUILock) {            /* IMPL_NOTE: this makes garbage.               * But hashtables need Object keys. */            Integer key = new Integer(inp_face | inp_style | inp_size);            Font f = (Font)table.get(key);            if (f == null) {                f = new Font(inp_face, inp_style, inp_size);                table.put(key, f);            }            return f;        }    }    /**     * Gets the style of the font. The value is an <code>OR'ed</code>     * combination of     * <code>STYLE_BOLD</code>, <code>STYLE_ITALIC</code>, and     * <code>STYLE_UNDERLINED</code>; or the value is     * zero (<code>STYLE_PLAIN</code>).     * @return style of the current font

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -