?? fontdata.java
字號:
int cp = Integer.parseInt(buffer.toString(0, size - 1)); int [] lpCs = new int[8]; OS.TranslateCharsetInfo(cp, lpCs, OS.TCI_SRCCODEPAGE); data.lfCharSet = (byte)lpCs[0]; return 0;}/** * Returns the height of the receiver in points. * * @return the height of this FontData * * @see #setHeight */public int getHeight() { return height;}/** * Returns the locale of the receiver. * <p> * The locale determines which platform character set this * font is going to use. Widgets and graphics operations that * use this font will convert UNICODE strings to the platform * character set of the specified locale. * </p> * <p> * On platforms where there are multiple character sets for a * given language/country locale, the variant portion of the * locale will determine the character set. * </p> * * @return the <code>String</code> representing a Locale object * @since 3.0 */public String getLocale () { StringBuffer buffer = new StringBuffer (); char sep = '_'; if (lang != null) { buffer.append (lang); buffer.append (sep); } if (country != null) { buffer.append (country); buffer.append (sep); } if (variant != null) { buffer.append (variant); } String result = buffer.toString (); int length = result.length (); if (length > 0) { if (result.charAt (length - 1) == sep) { result = result.substring (0, length - 1); } } return result;}/** * Returns the name of the receiver. * On platforms that support font foundries, the return value will * be the foundry followed by a dash ("-") followed by the face name. * * @return the name of this <code>FontData</code> * * @see #setName */public String getName() { char[] chars; if (OS.IsUnicode) { chars = ((LOGFONTW)data).lfFaceName; } else { chars = new char[OS.LF_FACESIZE]; byte[] bytes = ((LOGFONTA)data).lfFaceName; OS.MultiByteToWideChar (OS.CP_ACP, OS.MB_PRECOMPOSED, bytes, bytes.length, chars, chars.length); } int index = 0; while (index < chars.length) { if (chars [index] == 0) break; index++; } return new String (chars, 0, index);}/** * Returns the style of the receiver which is a bitwise OR of * one or more of the <code>SWT</code> constants NORMAL, BOLD * and ITALIC. * * @return the style of this <code>FontData</code> * * @see #setStyle */public int getStyle() { int style = SWT.NORMAL; if (data.lfWeight == 700) style |= SWT.BOLD; if (data.lfItalic != 0) style |= SWT.ITALIC; return style;}/** * Returns an integer hash code for the receiver. Any two * objects which return <code>true</code> when passed to * <code>equals</code> must return the same value for this * method. * * @return the receiver's hash * * @see #equals */public int hashCode () { return data.lfCharSet ^ height ^ data.lfWidth ^ data.lfEscapement ^ data.lfOrientation ^ data.lfWeight ^ data.lfItalic ^data.lfUnderline ^ data.lfStrikeOut ^ data.lfCharSet ^ data.lfOutPrecision ^ data.lfClipPrecision ^ data.lfQuality ^ data.lfPitchAndFamily ^ getName().hashCode();}/** * Sets the height of the receiver. The parameter is * specified in terms of points, where a point is one * seventy-second of an inch. * * @param height the height of the <code>FontData</code> * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> * </ul> * * @see #getHeight */public void setHeight(int height) { if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); this.height = height;}/** * Sets the locale of the receiver. * <p> * The locale determines which platform character set this * font is going to use. Widgets and graphics operations that * use this font will convert UNICODE strings to the platform * character set of the specified locale. * </p> * <p> * On platforms where there are multiple character sets for a * given language/country locale, the variant portion of the * locale will determine the character set. * </p> * * @param locale the <code>String</code> representing a Locale object * @see java.util.Locale#toString */public void setLocale(String locale) { lang = country = variant = null; if (locale != null) { char sep = '_'; int length = locale.length(); int firstSep, secondSep; firstSep = locale.indexOf(sep); if (firstSep == -1) { firstSep = secondSep = length; } else { secondSep = locale.indexOf(sep, firstSep + 1); if (secondSep == -1) secondSep = length; } if (firstSep > 0) lang = locale.substring(0, firstSep); if (secondSep > firstSep + 1) country = locale.substring(firstSep + 1, secondSep); if (length > secondSep + 1) variant = locale.substring(secondSep + 1); } if (lang == null) { data.lfCharSet = (byte)OS.DEFAULT_CHARSET; } else { Callback callback = new Callback (this, "EnumLocalesProc", 1); int lpEnumLocalesProc = callback.getAddress (); OS.EnumSystemLocales(lpEnumLocalesProc, OS.LCID_SUPPORTED); callback.dispose (); }}/** * Sets the name of the receiver. * <p> * Some platforms support font foundries. On these platforms, the name * of the font specified in setName() may have one of the following forms: * <ol> * <li>a face name (for example, "courier")</li> * <li>a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")</li> * </ol> * In either case, the name returned from getName() will include the * foundry. * </p> * <p> * On platforms that do not support font foundries, only the face name * (for example, "courier") is used in <code>setName()</code> and * <code>getName()</code>. * </p> * * @param name the name of the font data (must not be null) * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> * </ul> * * @see #getName */public void setName(String name) { if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); /* The field lfFaceName must be NULL terminated */ TCHAR buffer = new TCHAR(0, name, true); int length = Math.min(OS.LF_FACESIZE - 1, buffer.length()); if (OS.IsUnicode) { char[] lfFaceName = ((LOGFONTW)data).lfFaceName; for (int i = 0; i < lfFaceName.length; i++) lfFaceName[i] = 0; System.arraycopy(buffer.chars, 0, lfFaceName, 0, length); } else { byte[] lfFaceName = ((LOGFONTA)data).lfFaceName; for (int i = 0; i < lfFaceName.length; i++) lfFaceName[i] = 0; System.arraycopy(buffer.bytes, 0, lfFaceName, 0, length); }}/** * Sets the style of the receiver to the argument which must * be a bitwise OR of one or more of the <code>SWT</code> * constants NORMAL, BOLD and ITALIC. * * @param style the new style for this <code>FontData</code> * * @see #getStyle */public void setStyle(int style) { if ((style & SWT.BOLD) == SWT.BOLD) { data.lfWeight = 700; } else { data.lfWeight = 0; } if ((style & SWT.ITALIC) == SWT.ITALIC) { data.lfItalic = 1; } else { data.lfItalic = 0; }}/** * Returns a string representation of the receiver which is suitable * for constructing an equivalent instance using the * <code>FontData(String)</code> constructor. * * @return a string representation of the FontData * * @see FontData */public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("1|"); buffer.append(getName()); buffer.append("|"); buffer.append(getHeight()); buffer.append("|"); buffer.append(getStyle()); buffer.append("|"); buffer.append("WINDOWS|1|"); buffer.append(data.lfHeight); buffer.append("|"); buffer.append(data.lfWidth); buffer.append("|"); buffer.append(data.lfEscapement); buffer.append("|"); buffer.append(data.lfOrientation); buffer.append("|"); buffer.append(data.lfWeight); buffer.append("|"); buffer.append(data.lfItalic); buffer.append("|"); buffer.append(data.lfUnderline); buffer.append("|"); buffer.append(data.lfStrikeOut); buffer.append("|"); buffer.append(data.lfCharSet); buffer.append("|"); buffer.append(data.lfOutPrecision); buffer.append("|"); buffer.append(data.lfClipPrecision); buffer.append("|"); buffer.append(data.lfQuality); buffer.append("|"); buffer.append(data.lfPitchAndFamily); buffer.append("|"); buffer.append(getName()); return buffer.toString();}/** * Invokes platform specific functionality to allocate a new font data. * <p> * <b>IMPORTANT:</b> This method is <em>not</em> part of the public * API for <code>FontData</code>. It is marked public only so that * it can be shared within the packages provided by SWT. It is not * available on all platforms, and should never be called from * application code. * </p> * * @param data the <code>LOGFONT</code> for the font data * @param height the height of the font data * @return a new font data object containing the specified <code>LOGFONT</code> and height */public static FontData win32_new(LOGFONT data, int height) { return new FontData(data, height);}}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -