Package org.eclipse.jface.resource
Class FontDescriptor
Lightweight descriptor for a font. Creates the described font on demand.
Subclasses can implement different ways of describing a font. These objects
will be compared, so hashCode(...) and equals(...) must return something
meaningful.
- Since:
- 3.1
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic FontData
Returns a copy of the original FontDatastatic FontData[]
Returns an array of FontData containing copies of the FontData from the original.abstract Font
createFont
(Device device) Creates the Font described by this descriptor.static FontDescriptor
createFrom
(String name, int height, int style) Creates a new FontDescriptor given an OS-specific font name, height, and style.static FontDescriptor
createFrom
(Font font) Creates a FontDescriptor that describes an existing font.static FontDescriptor
createFrom
(FontData data) Creates a new FontDescriptor given the associated FontDatastatic FontDescriptor
createFrom
(FontData[] data) Creates a new FontDescriptor given the an array of FontData that describes the font.static FontDescriptor
createFrom
(Font font, Device originalDevice) Deprecated.final Object
createResource
(Device device) Creates the resource described by this descriptorabstract void
destroyFont
(Font previouslyCreatedFont) Deallocates anything that was allocated by createFont, given a font that was allocated by an equal FontDescriptor.final void
destroyResource
(Object previouslyCreatedObject) Undoes everything that was done by a previous call to create(...), given the object that was returned by create(...).FontData[]
Returns the set of FontData associated with this font.final FontDescriptor
increaseHeight
(int heightDelta) Returns a FontDescriptor that is equivalent to the receiver, but whose height is larger by the given number of points.final FontDescriptor
setHeight
(int height) Returns a new FontDescriptor that is equivalent to the receiver, but has the given height.final FontDescriptor
setStyle
(int style) Returns a FontDescriptor that is equivalent to the receiver, but uses the given style bits.final FontDescriptor
withStyle
(int style) Returns a FontDescriptor that is equivalent to the receiver, but has the given style bits, in addition to any styles the receiver already has.
-
Constructor Details
-
FontDescriptor
public FontDescriptor()
-
-
Method Details
-
createFrom
Deprecated.usecreateFrom(Font)
Creates a FontDescriptor that describes an existing font. The resulting descriptor depends on the Font. Disposing the Font while the descriptor is still in use may throw a graphic disposed exception.- Parameters:
font
- a font to describeoriginalDevice
- must be the same Device that was passed into the font's constructor when it was first created.- Returns:
- a newly created FontDescriptor.
- Since:
- 3.1
-
createFrom
Creates a FontDescriptor that describes an existing font. The resulting descriptor depends on the original Font, and disposing the original Font while the descriptor is still in use may cause SWT to throw a graphic disposed exception.- Parameters:
font
- font to create- Returns:
- a newly created FontDescriptor that describes the given font
- Since:
- 3.1
-
createFrom
Creates a new FontDescriptor given the an array of FontData that describes the font.- Parameters:
data
- an array of FontData that describes the font (will be passed into the Font's constructor)- Returns:
- a FontDescriptor that describes the given font
- Since:
- 3.1
-
createFrom
Creates a new FontDescriptor given the associated FontData- Parameters:
data
- FontData describing the font to create- Returns:
- a newly created FontDescriptor
-
createFrom
Creates a new FontDescriptor given an OS-specific font name, height, and style.- Parameters:
name
- os-specific font nameheight
- height (pixels)style
- a bitwise combination of NORMAL, BOLD, ITALIC- Returns:
- a new FontDescriptor
- See Also:
-
Font(org.eclipse.swt.graphics.Device, java.lang.String, int, int)
-
getFontData
Returns the set of FontData associated with this font. Modifying the elements in the returned array has no effect on the original FontDescriptor.- Returns:
- the set of FontData associated with this font
- Since:
- 3.3
-
copy
Returns an array of FontData containing copies of the FontData from the original.- Parameters:
original
- array to copy- Returns:
- a deep copy of the original array
- Since:
- 3.3
-
copy
Returns a copy of the original FontData- Parameters:
next
- FontData to copy- Returns:
- a copy of the given FontData
- Since:
- 3.3
-
setStyle
Returns a FontDescriptor that is equivalent to the receiver, but uses the given style bits.Does not modify the receiver.
- Parameters:
style
- a bitwise combination of SWT.NORMAL, SWT.ITALIC and SWT.BOLD- Returns:
- a new FontDescriptor with the given style
- Since:
- 3.3
-
withStyle
Returns a FontDescriptor that is equivalent to the receiver, but has the given style bits, in addition to any styles the receiver already has.
Does not modify the receiver.
- Parameters:
style
- a bitwise combination of SWT.NORMAL, SWT.ITALIC and SWT.BOLD- Returns:
- a new FontDescriptor with the given additional style bits
- Since:
- 3.3
-
setHeight
Returns a new FontDescriptor that is equivalent to the receiver, but has the given height.
Does not modify the receiver.
- Parameters:
height
- a height, in points- Returns:
- a new FontDescriptor with the height, in points
- Since:
- 3.3
-
increaseHeight
Returns a FontDescriptor that is equivalent to the receiver, but whose height is larger by the given number of points.
Does not modify the receiver.
- Parameters:
heightDelta
- a change in height, in points. Negative values will return smaller fonts.- Returns:
- a FontDescriptor whose height differs from the receiver by the given number of points.
- Since:
- 3.3
-
createFont
Creates the Font described by this descriptor.- Parameters:
device
- device on which to allocate the font- Returns:
- a newly allocated Font (never null)
- Throws:
DeviceResourceException
- if unable to allocate the Font- Since:
- 3.1
-
destroyFont
Deallocates anything that was allocated by createFont, given a font that was allocated by an equal FontDescriptor.- Parameters:
previouslyCreatedFont
- previously allocated font- Since:
- 3.1
-
createResource
Description copied from class:DeviceResourceDescriptor
Creates the resource described by this descriptor- Specified by:
createResource
in classDeviceResourceDescriptor<Font>
- Parameters:
device
- the Device on which to allocate the resource- Returns:
- the newly allocated resource (not null)
- Throws:
DeviceResourceException
- if unable to allocate the resource
-
destroyResource
Description copied from class:DeviceResourceDescriptor
Undoes everything that was done by a previous call to create(...), given the object that was returned by create(...).- Specified by:
destroyResource
in classDeviceResourceDescriptor<Font>
- Parameters:
previouslyCreatedObject
- an object that was returned by an equal descriptor in a previous call to createResource(...).
-
createFrom(Font)