?? fontdata.java
字號:
/******************************************************************************* * Copyright (c) 2000, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/package org.eclipse.swt.graphics;import org.eclipse.swt.internal.*;import org.eclipse.swt.internal.win32.*;import org.eclipse.swt.*;/** * Instances of this class describe operating system fonts. * <p> * For platform-independent behaviour, use the get and set methods * corresponding to the following properties: * <dl> * <dt>height</dt><dd>the height of the font in points</dd> * <dt>name</dt><dd>the face name of the font, which may include the foundry</dd> * <dt>style</dt><dd>A bitwise combination of NORMAL, ITALIC and BOLD</dd> * </dl> * If extra, platform-dependent functionality is required: * <ul> * <li>On <em>Windows</em>, the data member of the <code>FontData</code> * corresponds to a Windows <code>LOGFONT</code> structure whose fields * may be retrieved and modified.</li> * <li>On <em>X</em>, the fields of the <code>FontData</code> correspond * to the entries in the font's XLFD name and may be retrieved and modified. * </ul> * Application code does <em>not</em> need to explicitly release the * resources managed by each instance when those instances are no longer * required, and thus no <code>dispose()</code> method is provided. * * @see Font */public final class FontData { /** * A Win32 LOGFONT struct * (Warning: This field is platform dependent) */ public LOGFONT data; /** * The height of the font data in points * (Warning: This field is platform dependent) */ public int height; /** * The locales of the font * (Warning: These fields are platform dependent) */ String lang, country, variant; /** * Constructs a new un-initialized font data. */public FontData() { data = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA(); // We set the charset field so that // wildcard searching will work properly // out of the box data.lfCharSet = (byte)OS.DEFAULT_CHARSET; height = 12;}/** * Constructs a new font data given the Windows <code>LOGFONT</code> * that it should represent. * * @param data the <code>LOGFONT</code> for the result */FontData(LOGFONT data, int height) { this.data = data; this.height = height;}/** * Constructs a new FontData given a string representation * in the form generated by the <code>FontData.toString</code> * method. * <p> * Note that the representation varies between platforms, * and a FontData can only be created from a string that was * generated on the same platform. * </p> * * @param string the string representation of a <code>FontData</code> (must not be null) * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li> * </ul> * * @see #toString */public FontData(String string) { if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); int start = 0; int end = string.indexOf('|'); if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); String version1 = string.substring(start, end); try { if (Integer.parseInt(version1) != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); } catch (NumberFormatException e) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } start = end + 1; end = string.indexOf('|', start); if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); String name = string.substring(start, end); start = end + 1; end = string.indexOf('|', start); if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); int height = 0; try { height = Integer.parseInt(string.substring(start, end)); } catch (NumberFormatException e) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } start = end + 1; end = string.indexOf('|', start); if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); int style = 0; try { style = Integer.parseInt(string.substring(start, end)); } catch (NumberFormatException e) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } start = end + 1; end = string.indexOf('|', start); data = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA(); data.lfCharSet = (byte)OS.DEFAULT_CHARSET; setName(name); setHeight(height); setStyle(style); if (end == -1) return; String platform = string.substring(start, end); start = end + 1; end = string.indexOf('|', start); if (end == -1) return; String version2 = string.substring(start, end); if (platform.equals("WINDOWS") && version2.equals("1")) { LOGFONT newData = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA(); try { start = end + 1; end = string.indexOf('|', start); if (end == -1) return; newData.lfHeight = Integer.parseInt(string.substring(start, end)); start = end + 1; end = string.indexOf('|', start); if (end == -1) return; newData.lfWidth = Integer.parseInt(string.substring(start, end)); start = end + 1; end = string.indexOf('|', start); if (end == -1) return; newData.lfEscapement = Integer.parseInt(string.substring(start, end)); start = end + 1; end = string.indexOf('|', start); if (end == -1) return; newData.lfOrientation = Integer.parseInt(string.substring(start, end)); start = end + 1; end = string.indexOf('|', start); if (end == -1) return; newData.lfWeight = Integer.parseInt(string.substring(start, end)); start = end + 1; end = string.indexOf('|', start); if (end == -1) return; newData.lfItalic = Byte.parseByte(string.substring(start, end)); start = end + 1; end = string.indexOf('|', start); if (end == -1) return; newData.lfUnderline = Byte.parseByte(string.substring(start, end)); start = end + 1; end = string.indexOf('|', start); if (end == -1) return; newData.lfStrikeOut = Byte.parseByte(string.substring(start, end)); start = end + 1; end = string.indexOf('|', start); if (end == -1) return; newData.lfCharSet = Byte.parseByte(string.substring(start, end)); start = end + 1; end = string.indexOf('|', start); if (end == -1) return; newData.lfOutPrecision = Byte.parseByte(string.substring(start, end)); start = end + 1; end = string.indexOf('|', start); if (end == -1) return; newData.lfClipPrecision = Byte.parseByte(string.substring(start, end)); start = end + 1; end = string.indexOf('|', start); if (end == -1) return; newData.lfQuality = Byte.parseByte(string.substring(start, end)); start = end + 1; end = string.indexOf('|', start); if (end == -1) return; newData.lfPitchAndFamily = Byte.parseByte(string.substring(start, end)); start = end + 1; } catch (NumberFormatException e) { setName(name); setHeight(height); setStyle(style); return; } TCHAR buffer = new TCHAR(0, string.substring(start), false); int length = Math.min(OS.LF_FACESIZE - 1, buffer.length()); if (OS.IsUnicode) { char[] lfFaceName = ((LOGFONTW)newData).lfFaceName; System.arraycopy(buffer.chars, 0, lfFaceName, 0, length); } else { byte[] lfFaceName = ((LOGFONTA)newData).lfFaceName; System.arraycopy(buffer.bytes, 0, lfFaceName, 0, length); } data = newData; }}/** * Constructs a new font data given a font name, * the height of the desired font in points, * and a font style. * * @param name the name of the font (must not be null) * @param height the font height in points * @param style a bit or combination of NORMAL, BOLD, ITALIC * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> * </ul> */public FontData(String name, int height, int style) { if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); data = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA(); setName(name); setHeight(height); setStyle(style); // We set the charset field so that // wildcard searching will work properly // out of the box data.lfCharSet = (byte)OS.DEFAULT_CHARSET;}/** * Compares the argument to the receiver, and returns true * if they represent the <em>same</em> object using a class * specific comparison. * * @param object the object to compare with this object * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise * * @see #hashCode */public boolean equals (Object object) { if (object == this) return true; if (!(object instanceof FontData)) return false; FontData fd = (FontData)object; LOGFONT lf = fd.data; return data.lfCharSet == lf.lfCharSet && /* * This code is intentionally commented. When creating * a FontData, lfHeight is not necessarily set. Instead * we check the height field which is always set. */ // data.lfHeight == lf.lfHeight && height == fd.height && data.lfWidth == lf.lfWidth && data.lfEscapement == lf.lfEscapement && data.lfOrientation == lf.lfOrientation && data.lfWeight == lf.lfWeight && data.lfItalic == lf.lfItalic && data.lfUnderline == lf.lfUnderline && data.lfStrikeOut == lf.lfStrikeOut && data.lfCharSet == lf.lfCharSet && data.lfOutPrecision == lf.lfOutPrecision && data.lfClipPrecision == lf.lfClipPrecision && data.lfQuality == lf.lfQuality && data.lfPitchAndFamily == lf.lfPitchAndFamily && getName().equals(fd.getName());}int EnumLocalesProc(int lpLocaleString) { /* Get the locale ID */ int length = 8; TCHAR buffer = new TCHAR(0, length); int byteCount = length * TCHAR.sizeof; OS.MoveMemory(buffer, lpLocaleString, byteCount); int lcid = Integer.parseInt(buffer.toString(0, buffer.strlen ()), 16); /* Check the language */ int size = OS.GetLocaleInfo(lcid, OS.LOCALE_SISO639LANGNAME, buffer, length); if (size <= 0 || !lang.equals(buffer.toString(0, size - 1))) return 1; /* Check the country */ if (country != null) { size = OS.GetLocaleInfo(lcid, OS.LOCALE_SISO3166CTRYNAME, buffer, length); if (size <= 0 || !country.equals(buffer.toString(0, size - 1))) return 1; } /* Get the charset */ size = OS.GetLocaleInfo(lcid, OS.LOCALE_IDEFAULTANSICODEPAGE, buffer, length); if (size <= 0) return 1;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -