diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/FontData.java')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/FontData.java | 198 |
1 files changed, 121 insertions, 77 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/FontData.java index 67de546b13..11425279f3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/FontData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/graphics/FontData.java @@ -8,7 +8,7 @@ package org.eclipse.swt.graphics; */ import org.eclipse.swt.*; - + /** * Instances of this class describe operating system fonts. * Only the public API of this type is platform independent. @@ -36,38 +36,36 @@ import org.eclipse.swt.*; */ public final class FontData { /** - * The font foundry. - * Warning: This field is platform dependent. - */ - public String foundry; - /** - * The font family. - * Warning: This field is platform dependent. + * the font name + * (Warning: This field is platform dependent) */ - public String fontFamily; + public String name; + /** * The height of the font data in points * (Warning: This field is platform dependent) */ public int height; + /** - * The font style. - * Warning: This field is platform dependent. + * the font style + * (Warning: This field is platform dependent) */ public int style; - - // AW for FontDialog - public String addStyle= "FontData.addStyle"; - public String weight= "FontData.weight"; - public String characterSetRegistry= "FontData.characterSetRegistry"; - public String characterSetName= "characterSetName"; - // AW end + + /** + * The locales of the font + * (Warning: These fields are platform dependent) + */ + String lang, country, variant; /** * Constructs a new un-initialized font data. */ public FontData () { + this("", 12, SWT.NORMAL); } + /** * Constructs a new FontData given a string representation * in the form generated by the <code>FontData.toString</code> @@ -89,31 +87,54 @@ public FontData () { */ public FontData(String string) { if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - //System.out.println("new FontData: " + string); + int start = 0; + int end = string.indexOf('|'); + if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + String version1 = string.substring(start, end); + + start = end + 1; + end = string.indexOf('|', start); + if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + String name = string.substring(start, end); - int start= 0; - int stop= string.indexOf("|"); - String name= string.substring(start, stop); - start= stop+1; - stop= string.indexOf("|", start); - int height= 0; + 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, stop)); - } catch (NumberFormatException ex) { + height = Integer.parseInt(string.substring(start, end)); + } catch (NumberFormatException e) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); } - start= stop+1; - int style= 0; + + 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)); - } catch (NumberFormatException ex) { + style = Integer.parseInt(string.substring(start, end)); + } catch (NumberFormatException e) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); } - - //System.out.println("**** <"+name+"><"+size+"><"+face+">"); - + + start = end + 1; + end = string.indexOf('|', start); 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("CARBON") && version2.equals("1")) { + return; + } } + /** * Constructs a new font data given a font name, * the height of the desired font in points, @@ -128,12 +149,12 @@ public FontData(String string) { * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> * </ul> */ -public FontData (String name, int height, int style) { - //System.out.println("new FontData: " + name + " " + height + " " + style); +public FontData(String name, int height, int style) { setName(name); setHeight(height); setStyle(style); } + /** * Compares the argument to the receiver, and returns true * if they represent the <em>same</em> object using a class @@ -145,8 +166,12 @@ public FontData (String name, int height, int style) { * @see #hashCode */ public boolean equals (Object object) { - return (object == this) || ((object instanceof FontData) && toString().equals(((FontData)object).toString())); + if (object == this) return true; + if (!(object instanceof FontData)) return false; + FontData data = (FontData)object; + return name.equals(data.name) && height == data.height && style == data.style; } + /** * Returns the height of the receiver in points. * @@ -157,6 +182,7 @@ public boolean equals (Object object) { public int getHeight() { return height; } + /** * Returns the name of the receiver. * On platforms that support font foundries, the return value will @@ -167,15 +193,9 @@ public int getHeight() { * @see #setName */ public String getName() { - StringBuffer buffer = new StringBuffer(); - if (foundry != null) { - buffer.append(foundry); - buffer.append("-"); - } - if (fontFamily != null) - buffer.append(fontFamily); - return buffer.toString(); + return name; } + /** * Returns the style of the receiver which is a bitwise OR of * one or more of the <code>SWT</code> constants NORMAL, BOLD @@ -188,6 +208,7 @@ public String getName() { public int getStyle() { return style; } + /** * Returns an integer hash code for the receiver. Any two * objects which return <code>true</code> when passed to @@ -199,11 +220,9 @@ public int getStyle() { * @see #equals */ public int hashCode () { - return toString().hashCode(); -} -public static FontData carbon_new(String xlfd) { - return new FontData(xlfd); + return name.hashCode() ^ height ^ style; } + /** * Sets the height of the receiver. The parameter is * specified in terms of points, where a point is one @@ -221,6 +240,44 @@ 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 which 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); + } +} + /** * Sets the name of the receiver. * <p> @@ -248,33 +305,9 @@ public void setHeight(int height) { */ public void setName(String name) { if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int dash = name.indexOf('-'); - if (dash != -1) { - foundry = name.substring(0, dash); - fontFamily = name.substring(dash + 1); - } else { - fontFamily = name; - } -} -/** - * 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 which 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) { + this.name = name; } + /** * Sets the style of the receiver to the argument which must * be a bitwise OR of one or more of the <code>SWT</code> @@ -285,8 +318,9 @@ public void setLocale(String locale) { * @see #getStyle */ public void setStyle(int style) { - this.style= style; + this.style = style; } + /** * Returns a string representation of the receiver which is suitable * for constructing an equivalent instance using the @@ -297,6 +331,16 @@ public void setStyle(int style) { * @see FontData */ public String toString() { - return getName() + "|" + getHeight() + "|" + getStyle(); + StringBuffer buffer = new StringBuffer(); + buffer.append("1|"); + buffer.append(getName()); + buffer.append("|"); + buffer.append(getHeight()); + buffer.append("|"); + buffer.append(getStyle()); + buffer.append("|"); + buffer.append("CARBON|1|"); + return buffer.toString(); } + } |