📄 font.java
字号:
* * @see #isPlain() * @see #isBold() * @see #isItalic() */ public int getStyle() { // SYNC NOTE: return of atomic value, no locking necessary return style; }; /** * Gets the size of the font. * * @return one of <code>SIZE_SMALL</code>, <code>SIZE_MEDIUM</code>, * <code>SIZE_LARGE</code> */ public int getSize() { // SYNC NOTE: return of atomic value, no locking necessary return size; } /** * Gets the face of the font. * * @return one of <code>FACE_SYSTEM</code>, * <code>FACE_PROPORTIONAL</code>, <code>FACE_MONOSPACE</code> */ public int getFace() { // SYNC NOTE: return of atomic value, no locking necessary return face; } /** * Returns <code>true</code> if the font is plain. * @see #getStyle() * @return <code>true</code> if font is plain */ public boolean isPlain() { // SYNC NOTE: return of atomic value, no locking necessary return style == STYLE_PLAIN; } /** * Returns <code>true</code> if the font is bold. * @see #getStyle() * @return <code>true</code> if font is bold */ public boolean isBold() { // SYNC NOTE: return of atomic value, no locking necessary return (style & STYLE_BOLD) == STYLE_BOLD; } /** * Returns <code>true</code> if the font is italic. * @see #getStyle() * @return <code>true</code> if font is italic */ public boolean isItalic() { // SYNC NOTE: return of atomic value, no locking necessary return (style & STYLE_ITALIC) == STYLE_ITALIC; } /** * Returns <code>true</code> if the font is underlined. * @see #getStyle() * @return <code>true</code> if font is underlined */ public boolean isUnderlined() { // SYNC NOTE: return of atomic value, no locking necessary return (style & STYLE_UNDERLINED) == STYLE_UNDERLINED; } /** * 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() { // SYNC NOTE: return of atomic value, no locking necessary return height; } /** * Gets the distance in pixels from the top of the text to the text's * baseline. * @return the distance in pixels from the top of the text to the text's * baseline */ public int getBaselinePosition() { // SYNC NOTE: return of atomic value, no locking necessary return baseline; } /** * Gets the advance width of the specified character in this Font. * The advance width is the horizontal distance that would be occupied if * <code>ch</code> were to be drawn using this <code>Font</code>, * including inter-character spacing following * <code>ch</code> 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 gciFont.getStringWidth(new String(new char[]{ch})); } /** * Returns the advance width of the characters in <code>ch</code>, * starting at the specified offset and for the specified number of * characters (length). * The advance width is the horizontal distance that would be occupied if * the characters were to be drawn using this <code>Font</code>, * including inter-character spacing following * the characters necessary for proper positioning of subsequent text. * * <p>The <code>offset</code> and <code>length</code> parameters must * specify a valid range of characters * within the character array <code>ch</code>. The <code>offset</code> * parameter must be within the * range <code>[0..(ch.length)]</code>, inclusive. * The <code>length</code> parameter must be a non-negative * integer such that <code>(offset + length) <= ch.length</code>.</p> * * @param ch the array of characters * @param offset the index of the first character to measure * @param length the number of characters to measure * @return the width of the character range * @throws ArrayIndexOutOfBoundsException if <code>offset</code> and * <code>length</code> specify an * invalid range * @throws NullPointerException if <code>ch</code> is <code>null</code> */ public int charsWidth(char[] ch, int offset, int length) { if (ch == null) { throw new NullPointerException(); } try { String strToRender = new String(ch, offset, length); return gciFont.getStringWidth(strToRender); } catch (IndexOutOfBoundsException i) { throw new ArrayIndexOutOfBoundsException(); } } /** * Gets the total advance width for showing the specified * <code>String</code> * in this <code>Font</code>. * The advance width is the horizontal distance that would be occupied if * <code>str</code> were to be drawn using this <code>Font</code>, * including inter-character spacing following * <code>str</code> necessary for proper positioning of subsequent text. * * @param str the <code>String</code> to be measured * @return the total advance width * @throws NullPointerException if <code>str</code> is <code>null</code> */ public int stringWidth(java.lang.String str) { if (str == null) { throw new NullPointerException(); } return gciFont.getStringWidth(str); } /** * Gets the total advance width for showing the specified substring in this * <code>Font</code>. * The advance width is the horizontal distance that would be occupied if * the substring were to be drawn using this <code>Font</code>, * including inter-character spacing following * the substring necessary for proper positioning of subsequent text. * * <p> * The <code>offset</code> and <code>len</code> parameters must * specify a valid range of characters * within <code>str</code>. The <code>offset</code> parameter must * be within the * range <code>[0..(str.length())]</code>, inclusive. * The <code>len</code> parameter must be a non-negative * integer such that <code>(offset + len) <= str.length()</code>. * </p> * * @param str the <code>String</code> to be measured * @param offset zero-based index of first character in the substring * @param len length of the substring * @return the total advance width * @throws StringIndexOutOfBoundsException if <code>offset</code> and * <code>length</code> specify an * invalid range * @throws NullPointerException if <code>str</code> is <code>null</code> */ public int substringWidth(String str, int offset, int len) { try { // This will generate NullPointerException String strToRender = str.substring(offset, offset + len); return gciFont.getStringWidth(strToRender); } catch (IndexOutOfBoundsException i) { throw new StringIndexOutOfBoundsException(); } } /** * Gets the standard height of a line of text in this font. * This extra space (leading) occurs below the text is not included * in this value. * @return standard height of a line of text in this font (a * non-negative value) */ int getMaxGlyphHeight() { // SYNC NOTE: return of atomic value, no locking necessary return glyphHeight; } // private implementation // /** The face of this Font */ private int face; /** The style of this Font */ private int style; /** The point size of this Font */ private int size; /** The baseline of this Font */ private int baseline; /** The height of this Font */ private int height; /** The height without leading of this Font */ private int glyphHeight; /** GCI Font mapping */ GCIFont gciFont; /** * The "default" font, constructed from the 'system' face, * plain style, and 'medium' size point. */ private static Font DEFAULT_FONT; /** * A hashtable used to maintain a store of created Fonts * so they are not re-created in the future */ private static java.util.Hashtable table = new java.util.Hashtable(4); /** * Returns the mapping of lcdui Font face to * GCIFont face. * * @param style lcdui Font face that has to be mapped * @return the GCIFont face to which lcdui Font size has to be mapped */ private static String getGCIFontFace(int face) { return (face == FACE_MONOSPACE ? "Monospaced" : "SansSerif"); } /** * Returns the mapping of STYLE_ITALIC, SIZE_BOLD, SIZE_PLAIN to * GCIFont STYLE_ITALIC, STYLE_ITALIC, STYLE_PLAIN. * * @param style lcdui Font style that has to be mapped * @return the GCIFont style to which lcdui Font size has to be mapped */ private static int getGCIFontStyle(int style) { int gciStyle = GCIFont.STYLE_PLAIN; if ((style & STYLE_ITALIC) != 0) { gciStyle = GCIFont.STYLE_ITALIC; } if ((style & STYLE_BOLD) != 0) { gciStyle |= GCIFont.STYLE_BOLD; } return gciStyle; } /** * Returns the mapping of SIZE_SMALL, SIZE_MEDIUM, SIZE_LARGE to * GCIFont size. * * @param size lcdui Font size that has to be mapped * @return the GCIFont size to which lcdui Font size has to be mapped */ private static int getGCIFontSize(int size) { return ((size == SIZE_MEDIUM) ? 12 : (size == SIZE_SMALL ? 10 : 16)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -