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

📄 systemfont.java

📁 j2me设计的界面包
💻 JAVA
字号:
/*
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code 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.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the LICENSE file that accompanied this code.
 *
 * This code 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 in the LICENSE file that
 * accompanied this code).
 *
 * 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 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */
package com.sun.lwuit;

/**
 *
 * @author Chen Fishbein
 */
class SystemFont extends Font{
    
    private javax.microedition.lcdui.Font font;
    static Font defaultFont = new SystemFont(javax.microedition.lcdui.Font.getDefaultFont());
    
    /**
     * Creates a new instance of SystemFont
     * 
     * @param face the face of the font, can be one of FACE_SYSTEM, 
     * FACE_PROPORTIONAL, FACE_MONOSPACE.
     * @param style the style of the font. 
     * The value is an OR'ed  combination of STYLE_BOLD, STYLE_ITALIC, and 
     * STYLE_UNDERLINED; or the value is zero (STYLE_PLAIN).
     * @param size the size of the font, can be one of SIZE_SMALL, 
     * SIZE_MEDIUM, SIZE_LARGE
     */
    public SystemFont(int face, int style, int size) {
        font = javax.microedition.lcdui.Font.getFont(face, style, size);
    }
    
    /**
     * Creates a new instance of SystemFont using a MIDP Font object
     * @param font a MIDP javax.microedition.lcdui.Font object
     */
    public SystemFont(javax.microedition.lcdui.Font font) {
        this(font.getFace(), font.getStyle(), font.getSize());
    }
    
    /**
     * Gets the advance width of the specified character in this Font. 
     * The advance width is the horizontal distance that would be occupied 
     * if ch were to be drawn using this Font, including inter-character 
     * spacing following ch necessary for proper positioning of subsequent text.
     * 
     * @param ch the character to be measured
     * @return the total advance width (a non-negative value)
     */
    public int charWidth(char ch) {
        return font.charWidth(ch);
    }


    /**
     * @inheritDoc
     */
    public int charsWidth(char[] ch, int offset, int length){
        return font.charsWidth(ch, offset, length);
    }
    
    /**
     * @inheritDoc
     */
    public int substringWidth(String str, int offset, int len){
        return font.substringWidth(str, offset, len);
    }
    
    /**
     * @inheritDoc
     */
    public int stringWidth(String str){
        return font.stringWidth(str);
    }
    
    /**
     * Gets the standard height of a line of text in this font. 
     * This value includes sufficient spacing to ensure that lines of text 
     * painted this distance from anchor point to anchor point are spaced 
     * as intended by the font designer and the device. 
     * This extra space (leading) occurs below the text.
     * 
     * @return standard height of a line of text in this font (a non-negative value)
     */
    public int getHeight() {
        return font.getHeight();
    }

    /**
     * Draws a given character in X/Y coordinates
     * 
     * @param g the graphics object
     * @param character the given character
     * @param x the x coordinate
     * @param y the y coordinate
     */
    void drawChar(Graphics g, char character, int x, int y) {
        g.setFont(font);
        g.drawNativeChar(character, x, y);
    }

    /**
     * Draws a given characters array. Starting from offset location in array
     * and in a given lenght, at X/Y coordinates
     * 
     * @param g the graphics object
     * @param data a given characters array 
     * @param offset the offset location in array
     * @param length the number of characters to draw
     * @param x the x coordinate
     * @param y the y coordinate
     */
    void drawChars(Graphics g, char[] data, int offset, int length, int x, int y) {
        g.drawNativeChars(font, data, offset, length, x, y);
    }
    
    /**
     * Gets the face of the font.
     * 
     * @return one of FACE_SYSTEM, FACE_PROPORTIONAL, FACE_MONOSPACE
     */
    public int getFace(){
        return font.getFace();
    }
    
    /**
     * Gets the style of the font. The value is an OR'ed 
     * combination of STYLE_BOLD, STYLE_ITALIC, and STYLE_UNDERLINED; 
     * or the value is zero (STYLE_PLAIN).
     * 
     * @return style of the current font
     */
    public int getStyle(){
        return font.getStyle();
    }
    
    /**
     * Gets the size of the font.
     * 
     * @return one of SIZE_SMALL, SIZE_MEDIUM, SIZE_LARGE
     */
    public int getSize(){
        return font.getSize();
    }
}

⌨️ 快捷键说明

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