Spec-Zone .ru
спецификации, руководства, описания, API
|
public final class Font
extends java.lang.Object
The Font
class represents fonts, which are used to render text on
screen.
The size of a Font
is described as being specified in points
which are a real world measurement of approximately 1/72 inch.
Given that fonts scale with the rendering transform as determined
by the transform attributes of a Node
using the Font
and its ancestors, the size will actually be relative to the local
coordinate space of the node, which should provide coordinates
similar to the size of a point if no scaling transforms are present
in the environment of the node.
Note that the real world distances specified by the default coordinate
system only approximate point sizes as a rule of thumb and are typically
defaulted to screen pixels for most displays.
For more information see Node
for more information
on the default coordinate system
Constructor and Description |
---|
Font(double size)
Constructs a font using the default face "System".
|
Font(java.lang.String name,
double size)
Constructs a font using the specified full face name and size
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one.
|
static Font |
font(java.lang.String family,
double size)
Searches for an appropriate font based on the font family name and size.
|
static Font |
font(java.lang.String family,
FontPosture posture,
double size)
Searches for an appropriate font based on the font family name and posture
style.
|
static Font |
font(java.lang.String family,
FontWeight weight,
double size)
Searches for an appropriate font based on the font family name and weight
style.
|
static Font |
font(java.lang.String family,
FontWeight weight,
FontPosture posture,
double size)
Searches for an appropriate font based on the font family name and
weight and posture style.
|
static Font |
getDefault()
Gets the default font which will be from the family "System",
and typically the style "Regular", and be of a size consistent
with the user's desktop environment, to the extent that can
be determined.
|
static java.util.List<java.lang.String> |
getFamilies()
Gets all the font families installed on the user's system, including any
application fonts or SDK fonts.
|
java.lang.String |
getFamily()
Returns the family of this font.
|
static java.util.List<java.lang.String> |
getFontNames()
Gets the names of all fonts that are installed on the users system,
including any application fonts and SDK fonts.
|
static java.util.List<java.lang.String> |
getFontNames(java.lang.String family)
Gets the names of all fonts in the specified font family that are
installed on the users system, including any application fonts
and SDK fonts.
|
java.lang.String |
getName()
The full font name.
|
double |
getSize()
The point size for this font.
|
java.lang.String |
getStyle()
The font specified string describing the style within the font family.
|
int |
hashCode()
Returns a hash code for this
Font object. |
static Font |
loadFont(java.io.InputStream in,
double size)
Loads a font resource from the specified input stream.
|
static Font |
loadFont(java.lang.String urlStr,
double size)
Loads a font resource from the specified URL.
|
java.lang.String |
toString()
Converts this
Font object to a String representation. |
public Font(double size)
size
- the font size to usepublic Font(java.lang.String name, double size)
name
- full name of the font.size
- the font size to usepublic static Font getDefault()
public static java.util.List<java.lang.String> getFamilies()
public static java.util.List<java.lang.String> getFontNames()
public static java.util.List<java.lang.String> getFontNames(java.lang.String family)
public static Font font(java.lang.String family, FontWeight weight, FontPosture posture, double size)
A null or empty value for family allows the implementation to select any suitable font.
family
- The family of the fontweight
- The weight of the fontposture
- The posture or posture of the fontsize
- The point size of the font. This can be a fractional value,
but must not be negative. If the size is < 0 the default size will be
used.public static Font font(java.lang.String family, FontWeight weight, double size)
family
- The family of the fontweight
- The weight of the fontsize
- The point size of the font. This can be a fractional value,
but must not be negative. If the size is < 0 the default size will be
used.public static Font font(java.lang.String family, FontPosture posture, double size)
family
- The family of the fontposture
- The posture or posture of the fontsize
- The point size of the font. This can be a fractional value,
but must not be negative. If the size is < 0 the default size will be
used.public static Font font(java.lang.String family, double size)
family
- The family of the fontsize
- The point size of the font. This can be a fractional value,
but must not be negative. If the size is < 0 the default size will be
used.public final java.lang.String getName()
There is a single unified way to load all of application supplied
(via Font.loadFont()
, JavaFX runtime delivered fonts,
and system installed fonts. Simply create the font by specifying
the full name of the font you want to load.
If the specific font cannot be located, then a fallback or default
font will be used. The "name" will be updated to reflect the actual name
of the font being used. A load failure condition can be discovered by
checking the name of the Font with the name you tried to load.
Note that if you wish to locate a font by font family and style
then you can use one of the font(java.lang.String, javafx.scene.text.FontWeight, javafx.scene.text.FontPosture, double)
factory methods defined in
this class.
public final java.lang.String getFamily()
public final java.lang.String getStyle()
public final double getSize()
11.5
. If the specified value is < 0 the default size will be
used.public static Font loadFont(java.lang.String urlStr, double size)
Font
object will be returned.
Any failure such as a malformed URL being unable to locate or read
from the resource, or if it doesn't represent a font, will result in
a null
return. It is the application's responsibility
to check this before use.
On a successful (non-null) return the font will be registered with the FX graphics system for creation by available constructors and factory methods, and the application should use it in this manner rather than calling this method again, which would repeat the overhead of downloading and installing the font.
The font size
parameter is a convenience so that in
typical usage the application can directly use the returned (non-null)
font rather than needing to create one via a constructor. Invalid sizes
are those <=0 and will result in a default size.
If the URL represents a local disk file, then no copying is performed and the font file is required to persist for the lifetime of the application. Updating the file in any manner will result in unspecified and likely undesired behaviours.
urlStr
- from which to load the font, specified as a String.size
- of the returned font.public static Font loadFont(java.io.InputStream in, double size)
Font
object will be returned.
Any failure such as abbreviated input, or an unsupported font format
will result in a null
return. It is the application's
responsibility to check this before use.
On a successful (non-null) return the font will be registered with the FX graphics system for creation by available constructors and factory methods, and the application should use it in this manner rather than calling this method again, which would repeat the overhead of re-reading and installing the font.
The font size
parameter is a convenience so that in
typical usage the application can directly use the returned (non-null)
font rather than needing to create one via a constructor. Invalid sizes
are those <=0 and will result in a default size.
This method does not close the input stream.
in
- stream from which to load the font.size
- of the returned font.public java.lang.String toString()
Font
object to a String
representation.
The String representation is for informational use only and will change.
Do not use this string representation for any programmatic purpose.toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the reference object with which to compare.true
if this object is equal to the obj
argument; false
otherwise.public int hashCode()
Font
object.hashCode
in class java.lang.Object
Font
object.Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. Use is subject to