FILE COMPARISON
Produced: 2/18/2011 1:27:21 AM
   
Mode:  All Lines  
Left base folder: C:\Documents and Settings\krollins\My Documents\Admin\OpenSource\eRCP\eSWT\eSWT-1.2.orig  
Right base folder: C:\Documents and Settings\krollins\My Documents\Admin\OpenSource\eRCP\eSWT\eSWT-1.2.today  
   
File: org.eclipse.ercp.swt.core.win\src-platform\org\eclipse\swt\graphics\FontData.java  
1 /******************************************************************************* = 1 /*******************************************************************************
2 * Copyright (c) 2000, 2005 IBM Corporation and others.   2 * Copyright (c) 2000, 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials   3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0   4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at   5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html   6 * http://www.eclipse.org/legal/epl-v10.html
7 *   7 *
8 * Contributors:   8 * Contributors:
9 *     IBM Corporation - initial API and implementation   9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/   10 *******************************************************************************/
    <> 11  
      12 /*******************************************************************************
      13 * Additions/modifications to this source file by Oracle America, Inc. 2011
      14 *******************************************************************************/
      15  
11 package org.eclipse.swt.graphics; = 16 package org.eclipse.swt.graphics;
12     17  
13     18  
14 import org.eclipse.swt.SWT;   19 import org.eclipse.swt.SWT;
15     20  
16 import com.ibm.ugl.eswt.OS;   21 import com.ibm.ugl.eswt.OS;
17   22
18 /**   23 /**
19 * Instances of this class describe operating system fonts.   24 * Instances of this class describe operating system fonts.
20 * Only the public API of this type is platform independent.   25 * Only the public API of this type is platform independent.
21 * <p>   26 * <p>
22 * For platform-independent behaviour, use the get and set methods   27 * For platform-independent behaviour, use the get and set methods
23 * corresponding to the following properties:   28 * corresponding to the following properties:
24 * <dl>   29 * <dl>
25 * <dt>height</dt><dd>the height of the font in points</dd>   30 * <dt>height</dt><dd>the height of the font in points</dd>
26 * <dt>name</dt><dd>the face name of the font, which may include the foundry</dd>   31 * <dt>name</dt><dd>the face name of the font, which may include the foundry</dd>
27 * <dt>style</dt><dd>A bitwise combination of NORMAL, ITALIC and BOLD</dd> <> 32 * <dt>style</dt><dd>A bitwise combination of NORMAL, ITALIC, BOLD and UNDERLINE</dd>
28 * </dl> = 33 * </dl>
29 * If extra, platform-dependent functionality is required:   34 * If extra, platform-dependent functionality is required:
30 * <ul>   35 * <ul>
31 * <li>On <em>Windows</em>, the data member of the <code>FontData</code>   36 * <li>On <em>Windows</em>, the data member of the <code>FontData</code>
32 * corresponds to a Windows <code>LOGFONT</code> structure whose fields   37 * corresponds to a Windows <code>LOGFONT</code> structure whose fields
33 * may be retrieved and modified.</li>   38 * may be retrieved and modified.</li>
34 * <li>On <em>X</em>, the fields of the <code>FontData</code> correspond   39 * <li>On <em>X</em>, the fields of the <code>FontData</code> correspond
35 * to the entries in the font's XLFD name and may be retrieved and modified.   40 * to the entries in the font's XLFD name and may be retrieved and modified.
36 * </ul>   41 * </ul>
37 * Application code does <em>not</em> need to explicitly release the   42 * Application code does <em>not</em> need to explicitly release the
38 * resources managed by each instance when those instances are no longer   43 * resources managed by each instance when those instances are no longer
39 * required, and thus no <code>dispose()</code> method is provided.   44 * required, and thus no <code>dispose()</code> method is provided.
40 *   45 *
41 * @see Font   46 * @see Font
42 */   47 */
43 public final class FontData {   48 public final class FontData {
44         /**   49         /**
45          * The height of the font data in points   50          * The height of the font data in points
46          * (Warning: This field is platform dependent)   51          * (Warning: This field is platform dependent)
47          */   52          */
48         int height;   53         int height;
49         int style;   54         int style;
50         String name;   55         String name;
51         String locale;   56         String locale;
52           57        
53 /**        58 /**     
54 * Constructs a new un-initialized font data.   59 * Constructs a new un-initialized font data.
55 */   60 */
56 public FontData() {   61 public FontData() {
57         this("", 12, SWT.NORMAL);   62         this("", 12, SWT.NORMAL);
58 }   63 }
59     64  
60 /**   65 /**
61 * Constructs a new FontData given a string representation   66 * Constructs a new FontData given a string representation
62 * in the form generated by the <code>FontData.toString</code>   67 * in the form generated by the <code>FontData.toString</code>
63 * method.   68 * method.
64 * <p>   69 * <p>
65 * Note that the representation varies between platforms,   70 * Note that the representation varies between platforms,
66 * and a FontData can only be created from a string that was   71 * and a FontData can only be created from a string that was
67 * generated on the same platform.   72 * generated on the same platform.
68 * </p>   73 * </p>
69 *   74 *
70 * @param string the string representation of a <code>FontData</code> (must not be null)   75 * @param string the string representation of a <code>FontData</code> (must not be null)
71 *   76 *
72 * @exception IllegalArgumentException <ul>   77 * @exception IllegalArgumentException <ul>
73 *    <li>ERROR_NULL_ARGUMENT - if the argument is null</li>   78 *    <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
74 *    <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li>   79 *    <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li>
75 * </ul>   80 * </ul>
76 *   81 *
77 * @see #toString   82 * @see #toString
78 */   83 */
79 public FontData(String string) {   84 public FontData(String string) {
80         if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);   85         if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
81           86        
82         int start = 0;   87         int start = 0;
83         int end = string.indexOf('|');   88         int end = string.indexOf('|');
84         if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);   89         if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
85         String version1 = string.substring(start, end);   90         String version1 = string.substring(start, end);
86         try {   91         try {
87                 if (Integer.parseInt(version1) != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);   92                 if (Integer.parseInt(version1) != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
88         } catch (NumberFormatException e) {   93         } catch (NumberFormatException e) {
89                 SWT.error(SWT.ERROR_INVALID_ARGUMENT);   94                 SWT.error(SWT.ERROR_INVALID_ARGUMENT);
90         }   95         }
91           96        
92         start = end + 1;   97         start = end + 1;
93         end = string.indexOf('|', start);   98         end = string.indexOf('|', start);
94         if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);   99         if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
95         String name = string.substring(start, end);   100         String name = string.substring(start, end);
96     101  
97         start = end + 1;   102         start = end + 1;
98         end = string.indexOf('|', start);   103         end = string.indexOf('|', start);
99         if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);   104         if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
100         int height = 0;   105         int height = 0;
101         try {   106         try {
102                 height = Integer.parseInt(string.substring(start, end));   107                 height = Integer.parseInt(string.substring(start, end));
103         } catch (NumberFormatException e) {   108         } catch (NumberFormatException e) {
104                 SWT.error(SWT.ERROR_INVALID_ARGUMENT);   109                 SWT.error(SWT.ERROR_INVALID_ARGUMENT);
105         }   110         }
106     111  
107         start = end + 1;   112         start = end + 1;
108         end = string.indexOf('|', start);   113         end = string.indexOf('|', start);
109         if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);   114         if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
110         int style = 0;   115         int style = 0;
111         try {   116         try {
112                 style = Integer.parseInt(string.substring(start, end));   117                 style = Integer.parseInt(string.substring(start, end));
113         } catch (NumberFormatException e) {   118         } catch (NumberFormatException e) {
114                 SWT.error(SWT.ERROR_INVALID_ARGUMENT);   119                 SWT.error(SWT.ERROR_INVALID_ARGUMENT);
115         }   120         }
116     121  
117         setName(name);   122         setName(name);
118         setHeight(height);   123         setHeight(height);
119         setStyle(internal_convertToSWTStyle(style));   124         setStyle(internal_convertToSWTStyle(style));
120 }   125 }
121     126  
122 public static int internal_convertToSWTStyle(int style) {   127 public static int internal_convertToSWTStyle(int style) {
123         int swtStyle = SWT.NORMAL;   128         int swtStyle = SWT.NORMAL;
124           129        
125         if ((style & OS.FONT_STYLE_BOLD) == OS.FONT_STYLE_BOLD) {   130         if ((style & OS.FONT_STYLE_BOLD) == OS.FONT_STYLE_BOLD) {
126                 swtStyle |= SWT.BOLD;   131                 swtStyle |= SWT.BOLD;
127         }   132         }
128         if ((style & OS.FONT_STYLE_ITALIC) == OS.FONT_STYLE_ITALIC) {   133         if ((style & OS.FONT_STYLE_ITALIC) == OS.FONT_STYLE_ITALIC) {
129                 swtStyle |= SWT.ITALIC;   134                 swtStyle |= SWT.ITALIC;
130         }   135         }
    -+ 136         if ((style & OS.FONT_STYLE_UNDERLINED) == OS.FONT_STYLE_UNDERLINED) {
      137                 swtStyle |= SWT.UNDERLINE;
      138         }
131         = 139        
132         return swtStyle;   140         return swtStyle;
133 }   141 }
134     142  
135 public static int internal_convertToNativeStyle(int style) {   143 public static int internal_convertToNativeStyle(int style) {
136         int nativeStyle = 0;   144         int nativeStyle = 0;
137           145        
138         if ((style & SWT.BOLD) == SWT.BOLD) {   146         if ((style & SWT.BOLD) == SWT.BOLD) {
139                 nativeStyle |= OS.FONT_STYLE_BOLD;   147                 nativeStyle |= OS.FONT_STYLE_BOLD;
140         }   148         }
141         if ((style & SWT.ITALIC) == SWT.ITALIC) {   149         if ((style & SWT.ITALIC) == SWT.ITALIC) {
142                 nativeStyle |= OS.FONT_STYLE_ITALIC;   150                 nativeStyle |= OS.FONT_STYLE_ITALIC;
143         }   151         }
    -+ 152         if ((style & SWT.UNDERLINE) == SWT.UNDERLINE) {
      153                 nativeStyle |= OS.FONT_STYLE_UNDERLINED;
      154         }
144         = 155        
145         return nativeStyle;   156         return nativeStyle;
146 }   157 }
147     158  
148 /**        159 /**     
149 * Constructs a new font data given a font name,   160 * Constructs a new font data given a font name,
150 * the height of the desired font in points,   161 * the height of the desired font in points,
151 * and a font style.   162 * and a font style.
152 *   163 *
153 * @param name the name of the font (must not be null)   164 * @param name the name of the font (must not be null)
154 * @param height the font height in points   165 * @param height the font height in points
155 * @param style a bit or combination of NORMAL, BOLD, ITALIC <> 166 * @param style a bit or combination of NORMAL, BOLD, ITALIC, UNDERLINE
156 * = 167 *
157 * @exception IllegalArgumentException <ul>   168 * @exception IllegalArgumentException <ul>
158 *    <li>ERROR_NULL_ARGUMENT - when the font name is null</li>   169 *    <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
159 *    <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>   170 *    <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
160 * </ul>   171 * </ul>
161 */   172 */
162 public FontData(String name, int height, int style) {   173 public FontData(String name, int height, int style) {
163         if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);   174         if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
164         if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);   175         if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
165         this.name = name;   176         this.name = name;
166         this.height = height;   177         this.height = height;
167         this.style = style;   178         this.style = style;
168 }   179 }
169 /**   180 /**
170 * Compares the argument to the receiver, and returns true   181 * Compares the argument to the receiver, and returns true
171 * if they represent the <em>same</em> object using a class   182 * if they represent the <em>same</em> object using a class
172 * specific comparison.   183 * specific comparison.
173 *   184 *
174 * @param object the object to compare with this object   185 * @param object the object to compare with this object
175 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise   186 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
176 *   187 *
177 * @see #hashCode   188 * @see #hashCode
178 */   189 */
179 public boolean equals(Object object) {   190 public boolean equals(Object object) {
180         if (object == this) return true;   191         if (object == this) return true;
181         if (!(object instanceof FontData)) return false;   192         if (!(object instanceof FontData)) return false;
182         FontData data = (FontData) object;   193         FontData data = (FontData) object;
183         return name.equals(data.name) && height == data.height && style == data.style;   194         return name.equals(data.name) && height == data.height && style == data.style;
184 }   195 }
185 /**   196 /**
186 * Returns the height of the receiver in points.   197 * Returns the height of the receiver in points.
187 *   198 *
188 * @return the height of this FontData   199 * @return the height of this FontData
189 *   200 *
190 * @see #setHeight   201 * @see #setHeight
191 */   202 */
192 public int getHeight() {   203 public int getHeight() {
193         return height;   204         return height;
194 }   205 }
195 /**   206 /**
196 * Returns the locale of the receiver.   207 * Returns the locale of the receiver.
197 * <p>   208 * <p>
198 * The locale determines which platform character set this   209 * The locale determines which platform character set this
199 * font is going to use. Widgets and graphics operations that   210 * font is going to use. Widgets and graphics operations that
200 * use this font will convert UNICODE strings to the platform   211 * use this font will convert UNICODE strings to the platform
201 * character set of the specified locale.   212 * character set of the specified locale.
202 * </p>   213 * </p>
203 * <p>   214 * <p>
204 * On platforms where there are multiple character sets for a   215 * On platforms where there are multiple character sets for a
205 * given language/country locale, the variant portion of the   216 * given language/country locale, the variant portion of the
206 * locale will determine the character set.   217 * locale will determine the character set.
207 * </p>   218 * </p>
208 *   219 *
209 * @return the <code>String</code> representing a Locale object   220 * @return the <code>String</code> representing a Locale object
210 * @since 3.0   221 * @since 3.0
211 */   222 */
212 public String getLocale () {   223 public String getLocale () {
213         return (locale != null ? locale : "");   224         return (locale != null ? locale : "");
214 }   225 }
215 /**   226 /**
216 * Returns the name of the receiver.   227 * Returns the name of the receiver.
217 * On platforms that support font foundries, the return value will   228 * On platforms that support font foundries, the return value will
218 * be the foundry followed by a dash ("-") followed by the face name.   229 * be the foundry followed by a dash ("-") followed by the face name.
219 *   230 *
220 * @return the name of this <code>FontData</code>   231 * @return the name of this <code>FontData</code>
221 *   232 *
222 * @see #setName   233 * @see #setName
223 */   234 */
224 public String getName() {   235 public String getName() {
225         return name;   236         return name;
226 }   237 }
227 /**   238 /**
228 * Returns the style of the receiver which is a bitwise OR of   239 * Returns the style of the receiver which is a bitwise OR of
229 * one or more of the <code>SWT</code> constants NORMAL, BOLD <> 240 * one or more of the <code>SWT</code> constants NORMAL, BOLD,
230 * and ITALIC.   241 * ITALIC and UNDERLINE.
231 * = 242 *
232 * @return the style of this <code>FontData</code>   243 * @return the style of this <code>FontData</code>
233 *   244 *
234 * @see #setStyle   245 * @see #setStyle
235 */   246 */
236 public int getStyle() {   247 public int getStyle() {
237         return style;   248         return style;
238 }   249 }
239 /**   250 /**
240 * Returns an integer hash code for the receiver. Any two   251 * Returns an integer hash code for the receiver. Any two
241 * objects that return <code>true</code> when passed to   252 * objects that return <code>true</code> when passed to
242 * <code>equals</code> must return the same value for this   253 * <code>equals</code> must return the same value for this
243 * method.   254 * method.
244 *   255 *
245 * @return the receiver's hash   256 * @return the receiver's hash
246 *   257 *
247 * @see #equals   258 * @see #equals
248 */   259 */
249 public int hashCode() {   260 public int hashCode() {
250         return name.hashCode() ^ height ^ style;   261         return name.hashCode() ^ height ^ style;
251 }   262 }
252 /**   263 /**
253 * Sets the height of the receiver. The parameter is   264 * Sets the height of the receiver. The parameter is
254 * specified in terms of points, where a point is one   265 * specified in terms of points, where a point is one
255 * seventy-second of an inch.   266 * seventy-second of an inch.
256 *   267 *
257 * @param height the height of the <code>FontData</code>   268 * @param height the height of the <code>FontData</code>
258 *   269 *
259 * @exception IllegalArgumentException <ul>   270 * @exception IllegalArgumentException <ul>
260 *    <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>   271 *    <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
261 * </ul>   272 * </ul>
262 *   273 *
263 * @see #getHeight   274 * @see #getHeight
264 */   275 */
265 public void setHeight(int height) {   276 public void setHeight(int height) {
266         this.height = height;   277         this.height = height;
267 }   278 }
268 /**   279 /**
269 * Sets the locale of the receiver.   280 * Sets the locale of the receiver.
270 * <p>   281 * <p>
271 * The locale determines which platform character set this   282 * The locale determines which platform character set this
272 * font is going to use. Widgets and graphics operations that   283 * font is going to use. Widgets and graphics operations that
273 * use this font will convert UNICODE strings to the platform   284 * use this font will convert UNICODE strings to the platform
274 * character set of the specified locale.   285 * character set of the specified locale.
275 * </p>   286 * </p>
276 * <p>   287 * <p>
277 * On platforms where there are multiple character sets for a   288 * On platforms where there are multiple character sets for a
278 * given language/country locale, the variant portion of the   289 * given language/country locale, the variant portion of the
279 * locale will determine the character set.   290 * locale will determine the character set.
280 * </p>   291 * </p>
281 *   292 *
282 * @param locale the <code>String</code> representing a Locale object   293 * @param locale the <code>String</code> representing a Locale object
283 * @see java.util.Locale#toString   294 * @see java.util.Locale#toString
284 */   295 */
285 public void setLocale(String localeString) {   296 public void setLocale(String localeString) {
286         locale = localeString;   297         locale = localeString;
287 }   298 }
288 /**   299 /**
289 * Sets the name of the receiver.   300 * Sets the name of the receiver.
290 * <p>   301 * <p>
291 * Some platforms support font foundries. On these platforms, the name   302 * Some platforms support font foundries. On these platforms, the name
292 * of the font specified in setName() may have one of the following forms:   303 * of the font specified in setName() may have one of the following forms:
293 * <ol>   304 * <ol>
294 * <li>a face name (for example, "courier")</li>   305 * <li>a face name (for example, "courier")</li>
295 * <li>a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")</li>   306 * <li>a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")</li>
296 * </ol>   307 * </ol>
297 * In either case, the name returned from getName() will include the   308 * In either case, the name returned from getName() will include the
298 * foundry.   309 * foundry.
299 * </p>   310 * </p>
300 * <p>   311 * <p>
301 * On platforms that do not support font foundries, only the face name   312 * On platforms that do not support font foundries, only the face name
302 * (for example, "courier") is used in <code>setName()</code> and   313 * (for example, "courier") is used in <code>setName()</code> and
303 * <code>getName()</code>.   314 * <code>getName()</code>.
304 * </p>   315 * </p>
305 *   316 *
306 * @param name the name of the font data (must not be null)   317 * @param name the name of the font data (must not be null)
307 * @exception IllegalArgumentException <ul>   318 * @exception IllegalArgumentException <ul>
308 *    <li>ERROR_NULL_ARGUMENT - when the font name is null</li>   319 *    <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
309 * </ul>   320 * </ul>
310 *   321 *
311 * @see #getName   322 * @see #getName
312 */   323 */
313 public void setName(String name) {   324 public void setName(String name) {
314         if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);   325         if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
315         this.name = name;   326         this.name = name;
316 }   327 }
317 /**   328 /**
318 * Sets the style of the receiver to the argument which must   329 * Sets the style of the receiver to the argument which must
319 * be a bitwise OR of one or more of the <code>SWT</code>   330 * be a bitwise OR of one or more of the <code>SWT</code>
320 * constants NORMAL, BOLD and ITALIC.  All other style bits are <> 331 * constants NORMAL, BOLD, ITALIC and UNDERLINE.  All other style bits are
321 * ignored. = 332 * ignored.
322 *   333 *
323 * @param style the new style for this <code>FontData</code>   334 * @param style the new style for this <code>FontData</code>
324 *   335 *
325 * @see #getStyle   336 * @see #getStyle
326 */   337 */
327 public void setStyle(int style) {   338 public void setStyle(int style) {
328         this.style = style;   339         this.style = style;
329 }   340 }
330 /**   341 /**
331 * Returns a string representation of the receiver which is suitable   342 * Returns a string representation of the receiver which is suitable
332 * for constructing an equivalent instance using the   343 * for constructing an equivalent instance using the
333 * <code>FontData(String)</code> constructor.   344 * <code>FontData(String)</code> constructor.
334 *   345 *
335 * @return a string representation of the FontData   346 * @return a string representation of the FontData
336 *   347 *
337 * @see FontData   348 * @see FontData
338 */   349 */
339 public String toString() {   350 public String toString() {
340         StringBuffer buffer = new StringBuffer();   351         StringBuffer buffer = new StringBuffer();
341         buffer.append("1|");   352         buffer.append("1|");
342         buffer.append(getName());   353         buffer.append(getName());
343         buffer.append("|");   354         buffer.append("|");
344         buffer.append(getHeight());   355         buffer.append(getHeight());
345         buffer.append("|");   356         buffer.append("|");
346         buffer.append(internal_convertToNativeStyle(getStyle()));   357         buffer.append(internal_convertToNativeStyle(getStyle()));
347         buffer.append("|");   358         buffer.append("|");
348         return buffer.toString();   359         return buffer.toString();
349 }   360 }
350     361  
351 }   362 }