Class FontData
- java.lang.Object
-
- org.eclipse.swt.graphics.FontData
-
public final class FontData extends Object
Instances of this class describe operating system fonts.For platform-independent behaviour, use the get and set methods corresponding to the following properties:
- height
- the height of the font in points
- name
- the face name of the font, which may include the foundry
- style
- A bitwise combination of NORMAL, ITALIC and BOLD
- On Windows, the data member of the
FontDatacorresponds to a WindowsLOGFONTstructure whose fields may be retrieved and modified. - On X, the fields of the
FontDatacorrespond to the entries in the font's XLFD name and may be retrieved and modified.
dispose()method is provided.- See Also:
Font, Sample code and further information
-
-
Constructor Summary
Constructors Constructor Description FontData()Constructs a new uninitialized font data.FontData(String string)Constructs a new FontData given a string representation in the form generated by theFontData.toStringmethod.FontData(String name, int height, int style)Constructs a new font data given a font name, the height of the desired font in points, and a font style.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object object)Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.intgetHeight()Returns the height of the receiver in points.StringgetLocale()Returns the locale of the receiver.StringgetName()Returns the name of the receiver.intgetStyle()Returns the style of the receiver which is a bitwise OR of one or more of theSWTconstants NORMAL, BOLD and ITALIC.inthashCode()Returns an integer hash code for the receiver.voidsetHeight(int height)Sets the height of the receiver.voidsetLocale(String locale)Sets the locale of the receiver.voidsetName(String name)Sets the name of the receiver.voidsetStyle(int style)Sets the style of the receiver to the argument which must be a bitwise OR of one or more of theSWTconstants NORMAL, BOLD and ITALIC.StringtoString()Returns a string representation of the receiver which is suitable for constructing an equivalent instance using theFontData(String)constructor.static FontDatawin32_new(org.eclipse.swt.internal.win32.LOGFONT data, float height)Invokes platform specific functionality to allocate a new font data.
-
-
-
Field Detail
-
data
public org.eclipse.swt.internal.win32.LOGFONT data
A Win32 LOGFONT struct (Warning: This field is platform dependent)IMPORTANT: This field is not part of the SWT public API. 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 accessed from application code.
- Restriction:
- This field is not intended to be referenced by clients.
-
height
public float height
The height of the font data in points (Warning: This field is platform dependent)IMPORTANT: This field is not part of the SWT public API. 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 accessed from application code.
- Restriction:
- This field is not intended to be referenced by clients.
-
-
Constructor Detail
-
FontData
public FontData()
Constructs a new uninitialized font data.
-
FontData
public FontData(String string)
Constructs a new FontData given a string representation in the form generated by theFontData.toStringmethod.Note that the representation varies between platforms, and a FontData can only be created from a string that was generated on the same platform.
- Parameters:
string- the string representation of aFontData(must not be null)- Throws:
IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the argument is null
- ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description
- See Also:
toString()
-
FontData
public FontData(String name, int height, int style)
Constructs a new font data given a font name, the height of the desired font in points, and a font style.- Parameters:
name- the name of the font (must not be null)height- the font height in pointsstyle- a bit or combination of NORMAL, BOLD, ITALIC- Throws:
IllegalArgumentException-- ERROR_NULL_ARGUMENT - when the font name is null
- ERROR_INVALID_ARGUMENT - if the height is negative
-
-
Method Detail
-
equals
public boolean equals(Object object)
Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.- Overrides:
equalsin classObject- Parameters:
object- the object to compare with this object- Returns:
trueif the object is the same as this object andfalseotherwise- See Also:
hashCode()
-
getHeight
public int getHeight()
Returns the height of the receiver in points.- Returns:
- the height of this FontData
- See Also:
setHeight(int)
-
getLocale
public String getLocale()
Returns the locale of the receiver.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.
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.
- Returns:
- the
Stringrepresenting a Locale object - Since:
- 3.0
-
getName
public String getName()
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.- Returns:
- the name of this
FontData - See Also:
setName(java.lang.String)
-
getStyle
public int getStyle()
Returns the style of the receiver which is a bitwise OR of one or more of theSWTconstants NORMAL, BOLD and ITALIC.- Returns:
- the style of this
FontData - See Also:
setStyle(int)
-
hashCode
public int hashCode()
Returns an integer hash code for the receiver. Any two objects that returntruewhen passed toequalsmust return the same value for this method.- Overrides:
hashCodein classObject- Returns:
- the receiver's hash
- See Also:
equals(java.lang.Object)
-
setHeight
public void setHeight(int height)
Sets the height of the receiver. The parameter is specified in terms of points, where a point is one seventy-second of an inch.- Parameters:
height- the height of theFontData- Throws:
IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the height is negative
- See Also:
getHeight()
-
setLocale
public void setLocale(String locale)
Sets the locale of the receiver.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.
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.
- Parameters:
locale- theStringrepresenting a Locale object- See Also:
Locale.toString()
-
setName
public void setName(String name)
Sets the name of the receiver.Some platforms support font foundries. On these platforms, the name of the font specified in setName() may have one of the following forms:
- a face name (for example, "courier")
- a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")
In either case, the name returned from getName() will include the foundry.
On platforms that do not support font foundries, only the face name (for example, "courier") is used in
setName()andgetName().- Parameters:
name- the name of the font data (must not be null)- Throws:
IllegalArgumentException-- ERROR_NULL_ARGUMENT - when the font name is null
- See Also:
getName()
-
setStyle
public void setStyle(int style)
Sets the style of the receiver to the argument which must be a bitwise OR of one or more of theSWTconstants NORMAL, BOLD and ITALIC. All other style bits are ignored.- Parameters:
style- the new style for thisFontData- See Also:
getStyle()
-
toString
public String toString()
Returns a string representation of the receiver which is suitable for constructing an equivalent instance using theFontData(String)constructor.
-
win32_new
public static FontData win32_new(org.eclipse.swt.internal.win32.LOGFONT data, float height)
Invokes platform specific functionality to allocate a new font data.IMPORTANT: This method is not part of the public API for
FontData. 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.- Parameters:
data- theLOGFONTfor the font dataheight- the height of the font data- Returns:
- a new font data object containing the specified
LOGFONTand height - Restriction:
- This method is not intended to be referenced by clients.
-
-