public final class FontDescription extends Boxed
The most common use is to indicate the font you want to use when drawing text:
cr = new Context(surface); layout = new Layout(cr); desc = new FontDescription("Monospace, 12"); layout.setFontDescription(desc);The
constructor
has an extensive
discussion of the format of the textual descriptions you can use when
hunting for that perfect font to render with.Constructor and Description |
---|
FontDescription()
Create a blank FontDescription with all fields unset.
|
FontDescription(String str)
Create a FontDescription from a textual description.
|
Modifier and Type | Method and Description |
---|---|
FontDescription |
copy()
Make a deep copy of this FontDescription object.
|
boolean |
equals(Object obj) |
String |
getFamily()
The family the font that this FontDescription represents belongs to.
|
double |
getSize()
Get the size of this font, in device units.
|
Style |
getStyle()
Get the slant style of the font.
|
Variant |
getVariant()
Get the capitalization variant of the font.
|
Weight |
getWeight()
Get the weight of the font.
|
int |
hashCode() |
void |
setFamily(String family)
Specify the family (of related font styles) you wish to pick.
|
void |
setSize(double size)
Set the size of the font you are requesting.
|
void |
setSizeAbsolute(double size)
Set the size in raw device units (ie pixels if working on screen).
|
void |
setStyle(Style style)
Set the style of the font you're looking for.
|
void |
setVariant(Variant variant)
Set the capitalization variant of the Font.
|
void |
setWeight(Weight weight)
Indicate how bold or light the font should be.
|
String |
toString() |
public FontDescription()
FontDescription(String)
is usually a better way to initialize the FontDescription, specially if
you get the description from a FontSelection
Widget.
public FontDescription(String str)
"family[,] options size"where:
family
is a comma separated list of one or more font
families. The trailing ','
on the family list
is optional but a good idea when a font family you're targeting
includes a space in its name;options
is a whitespace separated list of words each
describing a style, variant, weight,
stretch, or gravity; andsize
is the vertical size of the font,
expressed in points You can use a suffix "px" to specify pixels
instead, although this is only applicable if you're drawing to the
screen or to an image backend.All three are optional when using FontDescription to request a font; if default values will be used for any parameters which are absent.
Font size is traditionally expressed in "points". Be aware, however,
that having a "10.5" point font doesn't actually mean that lines will
be precisely 10.5 points high. If you need to know their rendered size,
see a resultant LayoutLine's getExtentsLogical()
. You can instead follow the number with
"px"
to interpret the size argument as an absolute number
of pixels .
Examples include:
"Sans Bold 24"
Your system's sans-serif application font at a size that'll probably be
about right for a headline.
"Monospace 10"
Your system's terminal font. Note that it's Monospace
, not
Monospaced
!
"Liberation Serif 12"
These are an excellent series of fonts obtained for the global
community by Red Hat as libre replacements for the common, but
nevertheless encumbered non-free Arial, Courier, and Times fonts.
Liberation Serif in particular is ideal for output being sent to
printed paper.
"DejaVu Sans, Book 9"
An upgraded version of Bitstream Vera. DejaVu Sans is optimized as a
screen font (and hopefully is what you have set as your application
font in your gnome-appearance-properties
). "Book"
version is the term used in DejaVu for what other fonts call "Normal".
public FontDescription copy()
public boolean equals(Object obj)
equals
in class Object
public String getFamily()
null
if unset.public double getSize()
Note that this does not imply how high a line in this font will
be; that is up to the Layout doing the rendering. To find out the
height of a rendered line, use LayoutLine's
getExtentsLogical()
.
public Style getStyle()
public Variant getVariant()
public Weight getWeight()
public int hashCode()
hashCode
in class Object
public void setFamily(String family)
See the families
argument to the FontDescription
constructor
for details.
public void setSize(double size)
Since you can indicate the size you want when constructing with a textual description, you don't need this too often.
public void setSizeAbsolute(double size)
This corresponds to providing a size in a textual description such as
"Sans, 10px"
instead of "Sans, 10"
; since you
can specify it there you problably don't need this much.
public void setStyle(Style style)
ITALIC
and friends.
If you've worked with Textview then you might have seen this before as
TextTag's setStyle()
.
Same factor.
public void setVariant(Variant variant)
SMALL_CAPS
lives. Normally you'll leave it
alone; not surprisingly the default is NORMAL
.public void setWeight(Weight weight)
public String toString()
toString
in class org.freedesktop.bindings.Pointer