- java.lang.Object
-
- java.awt.Font
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
FontUIResource
public class Font extends Object implements Serializable
TheFontclass represents fonts, which are used to render text in a visible way. A font provides the information needed to map sequences of characters to sequences of glyphs and to render sequences of glyphs onGraphicsandComponentobjects.Characters and Glyphs
A character is a symbol that represents an item such as a letter, a digit, or punctuation in an abstract way. For example,'g', LATIN SMALL LETTER G, is a character.A glyph is a shape used to render a character or a sequence of characters. In simple writing systems, such as Latin, typically one glyph represents one character. In general, however, characters and glyphs do not have one-to-one correspondence. For example, the character 'á' LATIN SMALL LETTER A WITH ACUTE, can be represented by two glyphs: one for 'a' and one for '´'. On the other hand, the two-character string "fi" can be represented by a single glyph, an "fi" ligature. In complex writing systems, such as Arabic or the South and South-East Asian writing systems, the relationship between characters and glyphs can be more complicated and involve context-dependent selection of glyphs as well as glyph reordering. A font encapsulates the collection of glyphs needed to render a selected set of characters as well as the tables needed to map sequences of characters to corresponding sequences of glyphs.
Physical and Logical Fonts
The Java Platform distinguishes between two kinds of fonts: physical fonts and logical fonts.Physical fonts are the actual font libraries containing glyph data and tables to map from character sequences to glyph sequences, using a font technology such as TrueType or PostScript Type 1. All implementations of the Java Platform must support TrueType fonts; support for other font technologies is implementation dependent. Physical fonts may use names such as Helvetica, Palatino, HonMincho, or any number of other font names. Typically, each physical font supports only a limited set of writing systems, for example, only Latin characters or only Japanese and Basic Latin. The set of available physical fonts varies between configurations. Applications that require specific fonts can bundle them and instantiate them using the
createFontmethod.Logical fonts are the five font families defined by the Java platform which must be supported by any Java runtime environment: Serif, SansSerif, Monospaced, Dialog, and DialogInput. These logical fonts are not actual font libraries. Instead, the logical font names are mapped to physical fonts by the Java runtime environment. The mapping is implementation and usually locale dependent, so the look and the metrics provided by them vary. Typically, each logical font name maps to several physical fonts in order to cover a large range of characters.
Peered AWT components, such as
LabelandTextField, can only use logical fonts.For a discussion of the relative advantages and disadvantages of using physical or logical fonts, see the Physical and Logical Fonts in The Java Tutorials document.
Font Faces and Names
AFontcan have many faces, such as heavy, medium, oblique, gothic and regular. All of these faces have similar typographic design.There are three different names that you can get from a
Fontobject. The logical font name is simply the name that was used to construct the font. The font face name, or just font name for short, is the name of a particular font face, like Helvetica Bold. The family name is the name of the font family that determines the typographic design across several faces, like Helvetica.The
Fontclass represents an instance of a font face from a collection of font faces that are present in the system resources of the host system. As examples, Arial Bold and Courier Bold Italic are font faces. There can be severalFontobjects associated with a font face, each differing in size, style, transform and font features.Glyphs may not always be rendered with the requested properties (e.g, font and style) due to platform limitations such as the absence of suitable platform fonts to implement a logical font.
The
getAllFontsmethod of theGraphicsEnvironmentclass returns an array of all font faces available in the system. These font faces are returned asFontobjects with a size of 1, identity transform and default font features. These base fonts can then be used to derive newFontobjects with varying sizes, styles, transforms and font features via thederiveFontmethods in this class.Font and TextAttribute
Fontsupports mostTextAttributes. This makes some operations, such as rendering underlined text, convenient since it is not necessary to explicitly construct aTextLayoutobject. Attributes can be set on a Font by constructing or deriving it using aMapofTextAttributevalues.The values of some
TextAttributesare not serializable, and therefore attempting to serialize an instance ofFontthat has such values will not serialize them. This means a Font deserialized from such a stream will not compare equal to the original Font that contained the non-serializable attributes. This should very rarely pose a problem since these attributes are typically used only in special circumstances and are unlikely to be serialized.FOREGROUNDandBACKGROUNDusePaintvalues. The subclassColoris serializable, whileGradientPaintandTexturePaintare not.CHAR_REPLACEMENTusesGraphicAttributevalues. The subclassesShapeGraphicAttributeandImageGraphicAttributeare not serializable.INPUT_METHOD_HIGHLIGHTusesInputMethodHighlightvalues, which are not serializable. SeeInputMethodHighlight.
Clients who create custom subclasses of
PaintandGraphicAttributecan make them serializable and avoid this problem. Clients who use input method highlights can convert these to the platform-specific attributes for that highlight on the current platform and set them on the Font as a workaround.The
Map-based constructor andderiveFontAPIs ignore the FONT attribute, and it is not retained by the Font; the staticgetFont(java.util.Map<? extends java.text.AttributedCharacterIterator.Attribute, ?>)method should be used if the FONT attribute might be present. SeeTextAttribute.FONTfor more information.Several attributes will cause additional rendering overhead and potentially invoke layout. If a
Fonthas such attributes, themethod will return true.hasLayoutAttributes()Note: Font rotations can cause text baselines to be rotated. In order to account for this (rare) possibility, font APIs are specified to return metrics and take parameters 'in baseline-relative coordinates'. This maps the 'x' coordinate to the advance along the baseline, (positive x is forward along the baseline), and the 'y' coordinate to a distance along the perpendicular to the baseline at 'x' (positive y is 90 degrees clockwise from the baseline vector). APIs for which this is especially important are called out as having 'baseline-relative coordinates.'
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intBOLDThe bold style constant.static intCENTER_BASELINEThe baseline used in ideographic scripts like Chinese, Japanese, and Korean when laying out text.static StringDIALOGA String constant for the canonical family name of the logical font "Dialog".static StringDIALOG_INPUTA String constant for the canonical family name of the logical font "DialogInput".static intHANGING_BASELINEThe baseline used in Devanagari and similar scripts when laying out text.static intITALICThe italicized style constant.static intLAYOUT_LEFT_TO_RIGHTA flag to layoutGlyphVector indicating that text is left-to-right as determined by Bidi analysis.static intLAYOUT_NO_LIMIT_CONTEXTA flag to layoutGlyphVector indicating that text in the char array after the indicated limit should not be examined.static intLAYOUT_NO_START_CONTEXTA flag to layoutGlyphVector indicating that text in the char array before the indicated start should not be examined.static intLAYOUT_RIGHT_TO_LEFTA flag to layoutGlyphVector indicating that text is right-to-left as determined by Bidi analysis.static StringMONOSPACEDA String constant for the canonical family name of the logical font "Monospaced".protected StringnameThe logical name of thisFont, as passed to the constructor.static intPLAINThe plain style constant.protected floatpointSizeThe point size of thisFontinfloat.static intROMAN_BASELINEThe baseline used in most Roman scripts when laying out text.static StringSANS_SERIFA String constant for the canonical family name of the logical font "SansSerif".static StringSERIFA String constant for the canonical family name of the logical font "Serif".protected intsizeThe point size of thisFont, rounded to integer.protected intstyleThe style of thisFont, as passed to the constructor.static intTRUETYPE_FONTIdentify a font resource of type TRUETYPE.static intTYPE1_FONTIdentify a font resource of type TYPE1.
-
Constructor Summary
Constructors Modifier Constructor Description protectedFont(Font font)Creates a newFontfrom the specifiedfont.Font(String name, int style, int size)Creates a newFontfrom the specified name, style and point size.Font(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)Creates a newFontwith the specified attributes.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanDisplay(char c)Checks if thisFonthas a glyph for the specified character.booleancanDisplay(int codePoint)Checks if thisFonthas a glyph for the specified character.intcanDisplayUpTo(char[] text, int start, int limit)Indicates whether or not thisFontcan display the characters in the specifiedtextstarting atstartand ending atlimit.intcanDisplayUpTo(String str)Indicates whether or not thisFontcan display a specifiedString.intcanDisplayUpTo(CharacterIterator iter, int start, int limit)Indicates whether or not thisFontcan display the text specified by theiterstarting atstartand ending atlimit.static FontcreateFont(int fontFormat, File fontFile)Returns a newFontusing the specified font type and the specified font file.static FontcreateFont(int fontFormat, InputStream fontStream)Returns a newFontusing the specified font type and input data.static Font[]createFonts(File fontFile)Returns a new array ofFontdecoded from the specified file.static Font[]createFonts(InputStream fontStream)Returns a new array ofFontdecoded from the specified stream.GlyphVectorcreateGlyphVector(FontRenderContext frc, char[] chars)Creates aGlyphVectorby mapping characters to glyphs one-to-one based on the Unicode cmap in thisFont.GlyphVectorcreateGlyphVector(FontRenderContext frc, int[] glyphCodes)Creates aGlyphVectorby mapping characters to glyphs one-to-one based on the Unicode cmap in thisFont.GlyphVectorcreateGlyphVector(FontRenderContext frc, String str)Creates aGlyphVectorby mapping characters to glyphs one-to-one based on the Unicode cmap in thisFont.GlyphVectorcreateGlyphVector(FontRenderContext frc, CharacterIterator ci)Creates aGlyphVectorby mapping the specified characters to glyphs one-to-one based on the Unicode cmap in thisFont.static Fontdecode(String str)Returns theFontthat thestrargument describes.FontderiveFont(float size)Creates a newFontobject by replicating the currentFontobject and applying a new size to it.FontderiveFont(int style)Creates a newFontobject by replicating the currentFontobject and applying a new style to it.FontderiveFont(int style, float size)Creates a newFontobject by replicating thisFontobject and applying a new style and size.FontderiveFont(int style, AffineTransform trans)Creates a newFontobject by replicating thisFontobject and applying a new style and transform.FontderiveFont(AffineTransform trans)Creates a newFontobject by replicating the currentFontobject and applying a new transform to it.FontderiveFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)Creates a newFontobject by replicating the currentFontobject and applying a new set of font attributes to it.booleanequals(Object obj)Compares thisFontobject to the specifiedObject.Map<TextAttribute,?>getAttributes()Returns a map of font attributes available in thisFont.AttributedCharacterIterator.Attribute[]getAvailableAttributes()Returns the keys of all the attributes supported by thisFont.bytegetBaselineFor(char c)Returns the baseline appropriate for displaying this character.StringgetFamily()Returns the family name of thisFont.StringgetFamily(Locale l)Returns the family name of thisFont, localized for the specified locale.static FontgetFont(String nm)Returns aFontobject from the system properties list.static FontgetFont(String nm, Font font)Gets the specifiedFontfrom the system properties list.static FontgetFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)Returns aFontappropriate to the attributes.StringgetFontName()Returns the font face name of thisFont.StringgetFontName(Locale l)Returns the font face name of theFont, localized for the specified locale.floatgetItalicAngle()Returns the italic angle of thisFont.LineMetricsgetLineMetrics(char[] chars, int beginIndex, int limit, FontRenderContext frc)Returns aLineMetricsobject created with the specified arguments.LineMetricsgetLineMetrics(String str, int beginIndex, int limit, FontRenderContext frc)Returns aLineMetricsobject created with the specified arguments.LineMetricsgetLineMetrics(String str, FontRenderContext frc)LineMetricsgetLineMetrics(CharacterIterator ci, int beginIndex, int limit, FontRenderContext frc)Returns aLineMetricsobject created with the specified arguments.Rectangle2DgetMaxCharBounds(FontRenderContext frc)Returns the bounds for the character with the maximum bounds as defined in the specifiedFontRenderContext.intgetMissingGlyphCode()Returns the glyphCode which is used when thisFontdoes not have a glyph for a specified unicode code point.StringgetName()Returns the logical name of thisFont.intgetNumGlyphs()Returns the number of glyphs in thisFont.StringgetPSName()Returns the postscript name of thisFont.intgetSize()Returns the point size of thisFont, rounded to an integer.floatgetSize2D()Returns the point size of thisFontinfloatvalue.Rectangle2DgetStringBounds(char[] chars, int beginIndex, int limit, FontRenderContext frc)Returns the logical bounds of the specified array of characters in the specifiedFontRenderContext.Rectangle2DgetStringBounds(String str, int beginIndex, int limit, FontRenderContext frc)Returns the logical bounds of the specifiedStringin the specifiedFontRenderContext.Rectangle2DgetStringBounds(String str, FontRenderContext frc)Returns the logical bounds of the specifiedStringin the specifiedFontRenderContext.Rectangle2DgetStringBounds(CharacterIterator ci, int beginIndex, int limit, FontRenderContext frc)Returns the logical bounds of the characters indexed in the specifiedCharacterIteratorin the specifiedFontRenderContext.intgetStyle()Returns the style of thisFont.AffineTransformgetTransform()Returns a copy of the transform associated with thisFont.inthashCode()Returns a hashcode for thisFont.booleanhasLayoutAttributes()Return true if this Font contains attributes that require extra layout processing.booleanhasUniformLineMetrics()Checks whether or not thisFonthas uniform line metrics.booleanisBold()Indicates whether or not thisFontobject's style is BOLD.booleanisItalic()Indicates whether or not thisFontobject's style is ITALIC.booleanisPlain()Indicates whether or not thisFontobject's style is PLAIN.booleanisTransformed()Indicates whether or not thisFontobject has a transform that affects its size in addition to the Size attribute.GlyphVectorlayoutGlyphVector(FontRenderContext frc, char[] text, int start, int limit, int flags)Returns a newGlyphVectorobject, performing full layout of the text if possible.static booleantextRequiresLayout(char[] chars, int start, int end)Returns true if any part of the specified text is from a complex script for which the implementation will need to invoke layout processing in order to render correctly when usingdrawString(String,int,int)and other text rendering methods.StringtoString()Converts thisFontobject to aStringrepresentation.
-
-
-
Field Detail
-
DIALOG
public static final String DIALOG
A String constant for the canonical family name of the logical font "Dialog". It is useful in Font construction to provide compile-time verification of the name.- Since:
- 1.6
- See Also:
- Constant Field Values
-
DIALOG_INPUT
public static final String DIALOG_INPUT
A String constant for the canonical family name of the logical font "DialogInput". It is useful in Font construction to provide compile-time verification of the name.- Since:
- 1.6
- See Also:
- Constant Field Values
-
SANS_SERIF
public static final String SANS_SERIF
A String constant for the canonical family name of the logical font "SansSerif". It is useful in Font construction to provide compile-time verification of the name.- Since:
- 1.6
- See Also:
- Constant Field Values
-
SERIF
public static final String SERIF
A String constant for the canonical family name of the logical font "Serif". It is useful in Font construction to provide compile-time verification of the name.- Since:
- 1.6
- See Also:
- Constant Field Values
-
MONOSPACED
public static final String MONOSPACED
A String constant for the canonical family name of the logical font "Monospaced". It is useful in Font construction to provide compile-time verification of the name.- Since:
- 1.6
- See Also:
- Constant Field Values
-
PLAIN
public static final int PLAIN
The plain style constant.- See Also:
- Constant Field Values
-
BOLD
public static final int BOLD
The bold style constant. This can be combined with the other style constants (except PLAIN) for mixed styles.- See Also:
- Constant Field Values
-
ITALIC
public static final int ITALIC
The italicized style constant. This can be combined with the other style constants (except PLAIN) for mixed styles.- See Also:
- Constant Field Values
-
ROMAN_BASELINE
public static final int ROMAN_BASELINE
The baseline used in most Roman scripts when laying out text.- See Also:
- Constant Field Values
-
CENTER_BASELINE
public static final int CENTER_BASELINE
The baseline used in ideographic scripts like Chinese, Japanese, and Korean when laying out text.- See Also:
- Constant Field Values
-
HANGING_BASELINE
public static final int HANGING_BASELINE
The baseline used in Devanagari and similar scripts when laying out text.- See Also:
- Constant Field Values
-
TRUETYPE_FONT
public static final int TRUETYPE_FONT
Identify a font resource of type TRUETYPE. Used to specify a TrueType font resource to thecreateFont(int, java.io.InputStream)method. The TrueType format was extended to become the OpenType format, which adds support for fonts with Postscript outlines, this tag therefore references these fonts, as well as those with TrueType outlines.- Since:
- 1.3
- See Also:
- Constant Field Values
-
TYPE1_FONT
public static final int TYPE1_FONT
Identify a font resource of type TYPE1. Used to specify a Type1 font resource to thecreateFont(int, java.io.InputStream)method.- Since:
- 1.5
- See Also:
- Constant Field Values
-
name
protected String name
The logical name of thisFont, as passed to the constructor.- Since:
- 1.0
- See Also:
getName()
-
style
protected int style
The style of thisFont, as passed to the constructor. This style can be PLAIN, BOLD, ITALIC, or BOLD+ITALIC.- Since:
- 1.0
- See Also:
getStyle()
-
size
protected int size
The point size of thisFont, rounded to integer.- Since:
- 1.0
- See Also:
getSize()
-
pointSize
protected float pointSize
The point size of thisFontinfloat.- See Also:
getSize(),getSize2D()
-
LAYOUT_LEFT_TO_RIGHT
public static final int LAYOUT_LEFT_TO_RIGHT
A flag to layoutGlyphVector indicating that text is left-to-right as determined by Bidi analysis.- See Also:
- Constant Field Values
-
LAYOUT_RIGHT_TO_LEFT
public static final int LAYOUT_RIGHT_TO_LEFT
A flag to layoutGlyphVector indicating that text is right-to-left as determined by Bidi analysis.- See Also:
- Constant Field Values
-
LAYOUT_NO_START_CONTEXT
public static final int LAYOUT_NO_START_CONTEXT
A flag to layoutGlyphVector indicating that text in the char array before the indicated start should not be examined.- See Also:
- Constant Field Values
-
LAYOUT_NO_LIMIT_CONTEXT
public static final int LAYOUT_NO_LIMIT_CONTEXT
A flag to layoutGlyphVector indicating that text in the char array after the indicated limit should not be examined.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Font
public Font(String name, int style, int size)
Creates a newFontfrom the specified name, style and point size.The font name can be a font face name or a font family name. It is used together with the style to find an appropriate font face. When a font family name is specified, the style argument is used to select the most appropriate face from the family. When a font face name is specified, the face's style and the style argument are merged to locate the best matching font from the same family. For example if face name "Arial Bold" is specified with style
Font.ITALIC, the font system looks for a face in the "Arial" family that is bold and italic, and may associate the font instance with the physical font face "Arial Bold Italic". The style argument is merged with the specified face's style, not added or subtracted. This means, specifying a bold face and a bold style does not double-embolden the font, and specifying a bold face and a plain style does not lighten the font.If no face for the requested style can be found, the font system may apply algorithmic styling to achieve the desired style. For example, if
ITALICis requested, but no italic face is available, glyphs from the plain face may be algorithmically obliqued (slanted).Font name lookup is case insensitive, using the case folding rules of the US locale.
If the
nameparameter represents something other than a logical font, i.e. is interpreted as a physical font face or family, and this cannot be mapped by the implementation to a physical font or a compatible alternative, then the font system will map the Font instance to "Dialog", such that for example, the family as reported bygetFamilywill be "Dialog".- Parameters:
name- the font name. This can be a font face name or a font family name, and may represent either a logical font or a physical font found in thisGraphicsEnvironment. The family names for logical fonts are: Dialog, DialogInput, Monospaced, Serif, or SansSerif. Pre-defined String constants exist for all of these names, for example,DIALOG. Ifnameisnull, the logical font name of the newFontas returned bygetName()is set to the name "Default".style- the style constant for theFontThe style argument is an integer bitmask that may bePLAIN, or a bitwise union ofBOLDand/orITALIC(for example,ITALICorBOLD|ITALIC). If the style argument does not conform to one of the expected integer bitmasks then the style is set toPLAIN.size- the point size of theFont- Since:
- 1.0
- See Also:
GraphicsEnvironment.getAllFonts(),GraphicsEnvironment.getAvailableFontFamilyNames()
-
Font
public Font(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
Creates a newFontwith the specified attributes. Only keys defined inTextAttributeare recognized. In addition the FONT attribute is not recognized by this constructor (seegetAvailableAttributes()). Only attributes that have values of valid types will affect the newFont.If
attributesisnull, a newFontis initialized with default values.- Parameters:
attributes- the attributes to assign to the newFont, ornull- See Also:
TextAttribute
-
Font
protected Font(Font font)
Creates a newFontfrom the specifiedfont. This constructor is intended for use by subclasses.- Parameters:
font- from which to create thisFont.- Throws:
NullPointerException- iffontis null- Since:
- 1.6
-
-
Method Detail
-
textRequiresLayout
public static boolean textRequiresLayout(char[] chars, int start, int end)Returns true if any part of the specified text is from a complex script for which the implementation will need to invoke layout processing in order to render correctly when usingdrawString(String,int,int)and other text rendering methods. Measurement of the text may similarly need the same extra processing. Thestartandendindices are provided so that the application can request only a subset of the text be considered. The last char index examined is at"end-1", i.e a request to examine the entire array would be
An application may find this information helpful in performance sensitive code.Font.textRequiresLayout(chars, 0, chars.length);Note that even if this method returns
false, layout processing may still be invoked when used with anyFontfor whichhasLayoutAttributes()returnstrue, so that method will need to be consulted for the specific font, in order to obtain an answer which accounts for such font attributes.- Parameters:
chars- the text.start- the index of the first char to examine.end- the ending index, exclusive.- Returns:
trueif the specified text will need special layout.- Throws:
NullPointerException- ifcharsis null.ArrayIndexOutOfBoundsException- ifstartis negative orendis greater than the length of thecharsarray.- Since:
- 9
-
getFont
public static Font getFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
Returns aFontappropriate to the attributes. Ifattributescontains aFONTattribute with a validFontas its value, it will be merged with any remaining attributes. SeeTextAttribute.FONTfor more information.- Parameters:
attributes- the attributes to assign to the newFont- Returns:
- a new
Fontcreated with the specified attributes - Throws:
NullPointerException- ifattributesis null.- Since:
- 1.2
- See Also:
TextAttribute
-
createFonts
public static Font[] createFonts(InputStream fontStream) throws FontFormatException, IOException
Returns a new array ofFontdecoded from the specified stream. The returnedFont[]will have at least one element.The explicit purpose of this variation on the
createFont(int, InputStream)method is to support font sources which represent a TrueType/OpenType font collection and be able to return all individual fonts in that collection. Consequently this method will throwFontFormatExceptionif the data source does not contain at least one TrueType/OpenType font. The same exception will also be thrown if any of the fonts in the collection does not contain the required font tables.The condition "at least one", allows for the stream to represent a single OpenType/TrueType font. That is, it does not have to be a collection. Each
Fontelement of the returned array is created with a point size of 1 and stylePLAIN. This base font can then be used with thederiveFontmethods in this class to derive newFontobjects with varying sizes, styles, transforms and font features.This method does not close the
InputStream.To make each
Fontavailable to Font constructors it must be registered in theGraphicsEnvironmentby callingregisterFont(Font).- Parameters:
fontStream- anInputStreamobject representing the input data for the font or font collection.- Returns:
- a new
Font[]. - Throws:
FontFormatException- if thefontStreamdata does not contain the required font tables for any of the elements of the collection, or if it contains no fonts at all.IOException- if thefontStreamcannot be completely read.- Since:
- 9
- See Also:
GraphicsEnvironment.registerFont(Font)
-
createFonts
public static Font[] createFonts(File fontFile) throws FontFormatException, IOException
Returns a new array ofFontdecoded from the specified file. The returnedFont[]will have at least one element.The explicit purpose of this variation on the
createFont(int, File)method is to support font sources which represent a TrueType/OpenType font collection and be able to return all individual fonts in that collection. Consequently this method will throwFontFormatExceptionif the data source does not contain at least one TrueType/OpenType font. The same exception will also be thrown if any of the fonts in the collection does not contain the required font tables.The condition "at least one", allows for the stream to represent a single OpenType/TrueType font. That is, it does not have to be a collection. Each
Fontelement of the returned array is created with a point size of 1 and stylePLAIN. This base font can then be used with thederiveFontmethods in this class to derive newFontobjects with varying sizes, styles, transforms and font features.To make each
Fontavailable to Font constructors it must be registered in theGraphicsEnvironmentby callingregisterFont(Font).- Parameters:
fontFile- aFileobject containing the input data for the font or font collection.- Returns:
- a new
Font[]. - Throws:
FontFormatException- if theFiledoes not contain the required font tables for any of the elements of the collection, or if it contains no fonts at all.IOException- if thefontFilecannot be read.- Since:
- 9
- See Also:
GraphicsEnvironment.registerFont(Font)
-
createFont
public static Font createFont(int fontFormat, InputStream fontStream) throws FontFormatException, IOException
Returns a newFontusing the specified font type and input data. The newFontis created with a point size of 1 and stylePLAIN. This base font can then be used with thederiveFontmethods in this class to derive newFontobjects with varying sizes, styles, transforms and font features. This method does not close theInputStream.To make the
Fontavailable to Font constructors the returnedFontmust be registered in theGraphicsEnvironmentby callingregisterFont(Font).- Parameters:
fontFormat- the type of theFont, which isTRUETYPE_FONTif a TrueType resource is specified. orTYPE1_FONTif a Type 1 resource is specified.fontStream- anInputStreamobject representing the input data for the font.- Returns:
- a new
Fontcreated with the specified font type. - Throws:
IllegalArgumentException- iffontFormatis notTRUETYPE_FONTorTYPE1_FONT.FontFormatException- if thefontStreamdata does not contain the required font tables for the specified format.IOException- if thefontStreamcannot be completely read.- Since:
- 1.3
- See Also:
GraphicsEnvironment.registerFont(Font)
-
createFont
public static Font createFont(int fontFormat, File fontFile) throws FontFormatException, IOException
Returns a newFontusing the specified font type and the specified font file. The newFontis created with a point size of 1 and stylePLAIN. This base font can then be used with thederiveFontmethods in this class to derive newFontobjects with varying sizes, styles, transforms and font features.- Parameters:
fontFormat- the type of theFont, which isTRUETYPE_FONTif a TrueType resource is specified orTYPE1_FONTif a Type 1 resource is specified. So long as the returned font, or its derived fonts are referenced the implementation may continue to accessfontFileto retrieve font data. Thus the results are undefined if the file is changed, or becomes inaccessible.To make the
Fontavailable to Font constructors the returnedFontmust be registered in theGraphicsEnvironmentby callingregisterFont(Font).fontFile- aFileobject representing the input data for the font.- Returns:
- a new
Fontcreated with the specified font type. - Throws:
IllegalArgumentException- iffontFormatis notTRUETYPE_FONTorTYPE1_FONT.NullPointerException- iffontFileis null.IOException- if thefontFilecannot be read.FontFormatException- iffontFiledoes not contain the required font tables for the specified format.SecurityException- if the executing code does not have permission to read from the file.- Since:
- 1.5
- See Also:
GraphicsEnvironment.registerFont(Font)
-
getTransform
public AffineTransform getTransform()
Returns a copy of the transform associated with thisFont. This transform is not necessarily the one used to construct the font. If the font has algorithmic superscripting or width adjustment, this will be incorporated into the returnedAffineTransform.Typically, fonts will not be transformed. Clients generally should call
isTransformed()first, and only call this method ifisTransformedreturns true.- Returns:
- an
AffineTransformobject representing the transform attribute of thisFontobject.
-
getFamily
public String getFamily()
Returns the family name of thisFont.The family name of a font is font specific. Two fonts such as Helvetica Italic and Helvetica Bold have the same family name, Helvetica, whereas their font face names are Helvetica Bold and Helvetica Italic. The list of available family names may be obtained by using the
GraphicsEnvironment.getAvailableFontFamilyNames()method.Use
getNameto get the logical name of the font. UsegetFontNameto get the font face name of the font.- Returns:
- a
Stringthat is the family name of thisFont. - Since:
- 1.1
- See Also:
getName(),getFontName()
-
getFamily
public String getFamily(Locale l)
Returns the family name of thisFont, localized for the specified locale.The family name of a font is font specific. Two fonts such as Helvetica Italic and Helvetica Bold have the same family name, Helvetica, whereas their font face names are Helvetica Bold and Helvetica Italic. The list of available family names may be obtained by using the
GraphicsEnvironment.getAvailableFontFamilyNames()method.Use
getFontNameto get the font face name of the font.- Parameters:
l- locale for which to get the family name- Returns:
- a
Stringrepresenting the family name of the font, localized for the specified locale. - Since:
- 1.2
- See Also:
getFontName(),Locale
-
getPSName
public String getPSName()
Returns the postscript name of thisFont. UsegetFamilyto get the family name of the font. UsegetFontNameto get the font face name of the font.- Returns:
- a
Stringrepresenting the postscript name of thisFont. - Since:
- 1.2
-
getName
public String getName()
Returns the logical name of thisFont. UsegetFamilyto get the family name of the font. UsegetFontNameto get the font face name of the font.- Returns:
- a
Stringrepresenting the logical name of thisFont. - Since:
- 1.0
- See Also:
getFamily(),getFontName()
-
getFontName
public String getFontName()
Returns the font face name of thisFont. For example, Helvetica Bold could be returned as a font face name. UsegetFamilyto get the family name of the font. UsegetNameto get the logical name of the font.- Returns:
- a
Stringrepresenting the font face name of thisFont. - Since:
- 1.2
- See Also:
getFamily(),getName()
-
getFontName
public String getFontName(Locale l)
Returns the font face name of theFont, localized for the specified locale. For example, Helvetica Fett could be returned as the font face name. UsegetFamilyto get the family name of the font.- Parameters:
l- a locale for which to get the font face name- Returns:
- a
Stringrepresenting the font face name, localized for the specified locale. - See Also:
getFamily(),Locale
-
getStyle
public int getStyle()
Returns the style of thisFont. The style can be PLAIN, BOLD, ITALIC, or BOLD+ITALIC.- Returns:
- the style of this
Font - Since:
- 1.0
- See Also:
isPlain(),isBold(),isItalic()
-
getSize
public int getSize()
Returns the point size of thisFont, rounded to an integer. Most users are familiar with the idea of using point size to specify the size of glyphs in a font. This point size defines a measurement between the baseline of one line to the baseline of the following line in a single spaced text document. The point size is based on typographic points, approximately 1/72 of an inch.The Java(tm)2D API adopts the convention that one point is equivalent to one unit in user coordinates. When using a normalized transform for converting user space coordinates to device space coordinates 72 user space units equal 1 inch in device space. In this case one point is 1/72 of an inch.
- Returns:
- the point size of this
Fontin 1/72 of an inch units. - Since:
- 1.0
- See Also:
getSize2D(),GraphicsConfiguration.getDefaultTransform(),GraphicsConfiguration.getNormalizingTransform()
-
getSize2D
public float getSize2D()
Returns the point size of thisFontinfloatvalue.- Returns:
- the point size of this
Fontas afloatvalue. - Since:
- 1.2
- See Also:
getSize()
-
isPlain
public boolean isPlain()
Indicates whether or not thisFontobject's style is PLAIN.- Returns:
trueif thisFonthas a PLAIN style;falseotherwise.- Since:
- 1.0
- See Also:
getStyle()
-
isBold
public boolean isBold()
Indicates whether or not thisFontobject's style is BOLD.- Returns:
trueif thisFontobject's style is BOLD;falseotherwise.- Since:
- 1.0
- See Also:
getStyle()
-
isItalic
public boolean isItalic()
Indicates whether or not thisFontobject's style is ITALIC.- Returns:
trueif thisFontobject's style is ITALIC;falseotherwise.- Since:
- 1.0
- See Also:
getStyle()
-
isTransformed
public boolean isTransformed()
Indicates whether or not thisFontobject has a transform that affects its size in addition to the Size attribute.- Returns:
trueif thisFontobject has a non-identity AffineTransform attribute.falseotherwise.- Since:
- 1.4
- See Also:
getTransform()
-
hasLayoutAttributes
public boolean hasLayoutAttributes()
Return true if this Font contains attributes that require extra layout processing.- Returns:
- true if the font has layout attributes
- Since:
- 1.6
-
getFont
public static Font getFont(String nm)
Returns aFontobject from the system properties list.nmis treated as the name of a system property to be obtained. TheStringvalue of this property is then interpreted as aFontobject according to the specification ofFont.decode(String)If the specified property is not found, or the executing code does not have permission to read the property, null is returned instead.- Parameters:
nm- the property name- Returns:
- a
Fontobject that the property name describes, or null if no such property exists. - Throws:
NullPointerException- if nm is null.- Since:
- 1.2
- See Also:
decode(String)
-
decode
public static Font decode(String str)
Returns theFontthat thestrargument describes. To ensure that this method returns the desired Font, format thestrparameter in one of these ways- fontname-style-pointsize
- fontname-pointsize
- fontname-style
- fontname
- fontname style pointsize
- fontname pointsize
- fontname style
- fontname
"PLAIN","BOLD","BOLDITALIC", or"ITALIC", and pointsize is a positive decimal integer representation of the point size. For example, if you want a font that is Arial, bold, with a point size of 18, you would call this method with: "Arial-BOLD-18". This is equivalent to calling the Font constructor :new Font("Arial", Font.BOLD, 18);and the values are interpreted as specified by that constructor.A valid trailing decimal field is always interpreted as the pointsize. Therefore a fontname containing a trailing decimal value should not be used in the fontname only form.
If a style name field is not one of the valid style strings, it is interpreted as part of the font name, and the default style is used.
Only one of ' ' or '-' may be used to separate fields in the input. The identified separator is the one closest to the end of the string which separates a valid pointsize, or a valid style name from the rest of the string. Null (empty) pointsize and style fields are treated as valid fields with the default value for that field.
Some font names may include the separator characters ' ' or '-'. If
stris not formed with 3 components, e.g. such thatstyleorpointsizefields are not present instr, andfontnamealso contains a character determined to be the separator character then these characters where they appear as intended to be part offontnamemay instead be interpreted as separators so the font name may not be properly recognised.The default size is 12 and the default style is PLAIN. If
strdoes not specify a valid size, the returnedFonthas a size of 12. Ifstrdoes not specify a valid style, the returned Font has a style of PLAIN. If you do not specify a valid font name in thestrargument, this method will return a font with the family name "Dialog". To determine what font family names are available on your system, use theGraphicsEnvironment.getAvailableFontFamilyNames()method. Ifstrisnull, a newFontis returned with the family name "Dialog", a size of 12 and a PLAIN style.- Parameters:
str- the name of the font, ornull- Returns:
- the
Fontobject thatstrdescribes, or a new defaultFontifstrisnull. - Since:
- 1.1
- See Also:
getFamily()
-
getFont
public static Font getFont(String nm, Font font)
Gets the specifiedFontfrom the system properties list. As in thegetPropertymethod ofSystem, the first argument is treated as the name of a system property to be obtained. TheStringvalue of this property is then interpreted as aFontobject.The property value should be one of the forms accepted by
Font.decode(String)If the specified property is not found, or the executing code does not have permission to read the property, thefontargument is returned instead.- Parameters:
nm- the case-insensitive property namefont- a defaultFontto return if propertynmis not defined- Returns:
- the
Fontvalue of the property. - Throws:
NullPointerException- if nm is null.- See Also:
decode(String)
-
hashCode
public int hashCode()
Returns a hashcode for thisFont.- Overrides:
hashCodein classObject- Returns:
- a hashcode value for this
Font. - Since:
- 1.0
- See Also:
Object.equals(java.lang.Object)
-
equals
public boolean equals(Object obj)
Compares thisFontobject to the specifiedObject.- Overrides:
equalsin classObject- Parameters:
obj- theObjectto compare- Returns:
trueif the objects are the same or if the argument is aFontobject describing the same font as this object;falseotherwise.- Since:
- 1.0
- See Also:
Object.hashCode()
-
toString
public String toString()
Converts thisFontobject to aStringrepresentation.
-
getNumGlyphs
public int getNumGlyphs()
Returns the number of glyphs in thisFont. Glyph codes for thisFontrange from 0 togetNumGlyphs()- 1.- Returns:
- the number of glyphs in this
Font. - Since:
- 1.2
-
getMissingGlyphCode
public int getMissingGlyphCode()
Returns the glyphCode which is used when thisFontdoes not have a glyph for a specified unicode code point.- Returns:
- the glyphCode of this
Font. - Since:
- 1.2
-
getBaselineFor
public byte getBaselineFor(char c)
Returns the baseline appropriate for displaying this character.Large fonts can support different writing systems, and each system can use a different baseline. The character argument determines the writing system to use. Clients should not assume all characters use the same baseline.
- Parameters:
c- a character used to identify the writing system- Returns:
- the baseline appropriate for the specified character.
- Since:
- 1.2
- See Also:
LineMetrics.getBaselineOffsets(),ROMAN_BASELINE,CENTER_BASELINE,HANGING_BASELINE
-
getAttributes
public Map<TextAttribute,?> getAttributes()
Returns a map of font attributes available in thisFont. Attributes include things like ligatures and glyph substitution.- Returns:
- the attributes map of this
Font.
-
getAvailableAttributes
public AttributedCharacterIterator.Attribute[] getAvailableAttributes()
Returns the keys of all the attributes supported by thisFont. These attributes can be used to derive other fonts.- Returns:
- an array containing the keys of all the attributes
supported by this
Font. - Since:
- 1.2
-
deriveFont
public Font deriveFont(int style, float size)
Creates a newFontobject by replicating thisFontobject and applying a new style and size.- Parameters:
style- the style for the newFontsize- the size for the newFont- Returns:
- a new
Fontobject. - Since:
- 1.2
-
deriveFont
public Font deriveFont(int style, AffineTransform trans)
Creates a newFontobject by replicating thisFontobject and applying a new style and transform.- Parameters:
style- the style for the newFonttrans- theAffineTransformassociated with the newFont- Returns:
- a new
Fontobject. - Throws:
IllegalArgumentException- iftransisnull- Since:
- 1.2
-
deriveFont
public Font deriveFont(float size)
Creates a newFontobject by replicating the currentFontobject and applying a new size to it.- Parameters:
size- the size for the newFont.- Returns:
- a new
Fontobject. - Since:
- 1.2
-
deriveFont
public Font deriveFont(AffineTransform trans)
Creates a newFontobject by replicating the currentFontobject and applying a new transform to it.- Parameters:
trans- theAffineTransformassociated with the newFont- Returns:
- a new
Fontobject. - Throws:
IllegalArgumentException- iftransisnull- Since:
- 1.2
-
deriveFont
public Font deriveFont(int style)
Creates a newFontobject by replicating the currentFontobject and applying a new style to it.- Parameters:
style- the style for the newFont- Returns:
- a new
Fontobject. - Since:
- 1.2
-
deriveFont
public Font deriveFont(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
Creates a newFontobject by replicating the currentFontobject and applying a new set of font attributes to it.- Parameters:
attributes- a map of attributes enabled for the newFont- Returns:
- a new
Fontobject. - Since:
- 1.2
-
canDisplay
public boolean canDisplay(char c)
Checks if thisFonthas a glyph for the specified character.Note: This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the
canDisplay(int)method orcanDisplayUpTomethods.- Parameters:
c- the character for which a glyph is needed- Returns:
trueif thisFonthas a glyph for this character;falseotherwise.- Since:
- 1.2
-
canDisplay
public boolean canDisplay(int codePoint)
Checks if thisFonthas a glyph for the specified character.- Parameters:
codePoint- the character (Unicode code point) for which a glyph is needed.- Returns:
trueif thisFonthas a glyph for the character;falseotherwise.- Throws:
IllegalArgumentException- if the code point is not a valid Unicode code point.- Since:
- 1.5
- See Also:
Character.isValidCodePoint(int)
-
canDisplayUpTo
public int canDisplayUpTo(String str)
Indicates whether or not thisFontcan display a specifiedString. For strings with Unicode encoding, it is important to know if a particular font can display the string. This method returns an offset into theStringstrwhich is the first character thisFontcannot display without using the missing glyph code. If theFontcan display all characters, -1 is returned.- Parameters:
str- aStringobject- Returns:
- an offset into
strthat points to the first character instrthat thisFontcannot display; or-1if thisFontcan display all characters instr. - Since:
- 1.2
-
canDisplayUpTo
public int canDisplayUpTo(char[] text, int start, int limit)Indicates whether or not thisFontcan display the characters in the specifiedtextstarting atstartand ending atlimit. This method is a convenience overload.- Parameters:
text- the specified array ofcharvaluesstart- the specified starting offset (inchars) into the specified array ofcharvalueslimit- the specified ending offset (inchars) into the specified array ofcharvalues- Returns:
- an offset into
textthat points to the first character intextthat thisFontcannot display; or-1if thisFontcan display all characters intext. - Since:
- 1.2
-
canDisplayUpTo
public int canDisplayUpTo(CharacterIterator iter, int start, int limit)
Indicates whether or not thisFontcan display the text specified by theiterstarting atstartand ending atlimit.- Parameters:
iter- aCharacterIteratorobjectstart- the specified starting offset into the specifiedCharacterIterator.limit- the specified ending offset into the specifiedCharacterIterator.- Returns:
- an offset into
iterthat points to the first character initerthat thisFontcannot display; or-1if thisFontcan display all characters initer. - Since:
- 1.2
-
getItalicAngle
public float getItalicAngle()
Returns the italic angle of thisFont. The italic angle is the inverse slope of the caret which best matches the posture of thisFont.- Returns:
- the angle of the ITALIC style of this
Font. - See Also:
TextAttribute.POSTURE
-
hasUniformLineMetrics
public boolean hasUniformLineMetrics()
Checks whether or not thisFonthas uniform line metrics. A logicalFontmight be a composite font, which means that it is composed of different physical fonts to cover different code ranges. Each of these fonts might have differentLineMetrics. If the logicalFontis a single font then the metrics would be uniform.- Returns:
trueif thisFonthas uniform line metrics;falseotherwise.
-
getLineMetrics
public LineMetrics getLineMetrics(String str, FontRenderContext frc)
- Parameters:
str- the specifiedStringfrc- the specifiedFontRenderContext- Returns:
- a
LineMetricsobject created with the specifiedStringandFontRenderContext.
-
getLineMetrics
public LineMetrics getLineMetrics(String str, int beginIndex, int limit, FontRenderContext frc)
Returns aLineMetricsobject created with the specified arguments.- Parameters:
str- the specifiedStringbeginIndex- the initial offset ofstrlimit- the end offset ofstrfrc- the specifiedFontRenderContext- Returns:
- a
LineMetricsobject created with the specified arguments.
-
getLineMetrics
public LineMetrics getLineMetrics(char[] chars, int beginIndex, int limit, FontRenderContext frc)
Returns aLineMetricsobject created with the specified arguments.- Parameters:
chars- an array of charactersbeginIndex- the initial offset ofcharslimit- the end offset ofcharsfrc- the specifiedFontRenderContext- Returns:
- a
LineMetricsobject created with the specified arguments.
-
getLineMetrics
public LineMetrics getLineMetrics(CharacterIterator ci, int beginIndex, int limit, FontRenderContext frc)
Returns aLineMetricsobject created with the specified arguments.- Parameters:
ci- the specifiedCharacterIteratorbeginIndex- the initial offset incilimit- the end offset ofcifrc- the specifiedFontRenderContext- Returns:
- a
LineMetricsobject created with the specified arguments.
-
getStringBounds
public Rectangle2D getStringBounds(String str, FontRenderContext frc)
Returns the logical bounds of the specifiedStringin the specifiedFontRenderContext. The logical bounds contains the origin, ascent, advance, and height, which includes the leading. The logical bounds does not always enclose all the text. For example, in some languages and in some fonts, accent marks can be positioned above the ascent or below the descent. To obtain a visual bounding box, which encloses all the text, use thegetBoundsmethod ofTextLayout.Note: The returned bounds is in baseline-relative coordinates (see
class notes).- Parameters:
str- the specifiedStringfrc- the specifiedFontRenderContext- Returns:
- a
Rectangle2Dthat is the bounding box of the specifiedStringin the specifiedFontRenderContext. - Since:
- 1.2
- See Also:
FontRenderContext,createGlyphVector(java.awt.font.FontRenderContext, java.lang.String)
-
getStringBounds
public Rectangle2D getStringBounds(String str, int beginIndex, int limit, FontRenderContext frc)
Returns the logical bounds of the specifiedStringin the specifiedFontRenderContext. The logical bounds contains the origin, ascent, advance, and height, which includes the leading. The logical bounds does not always enclose all the text. For example, in some languages and in some fonts, accent marks can be positioned above the ascent or below the descent. To obtain a visual bounding box, which encloses all the text, use thegetBoundsmethod ofTextLayout.Note: The returned bounds is in baseline-relative coordinates (see
class notes).- Parameters:
str- the specifiedStringbeginIndex- the initial offset ofstrlimit- the end offset ofstrfrc- the specifiedFontRenderContext- Returns:
- a
Rectangle2Dthat is the bounding box of the specifiedStringin the specifiedFontRenderContext. - Throws:
IndexOutOfBoundsException- ifbeginIndexis less than zero, orlimitis greater than the length ofstr, orbeginIndexis greater thanlimit.- Since:
- 1.2
- See Also:
FontRenderContext,createGlyphVector(java.awt.font.FontRenderContext, java.lang.String)
-
getStringBounds
public Rectangle2D getStringBounds(char[] chars, int beginIndex, int limit, FontRenderContext frc)
Returns the logical bounds of the specified array of characters in the specifiedFontRenderContext. The logical bounds contains the origin, ascent, advance, and height, which includes the leading. The logical bounds does not always enclose all the text. For example, in some languages and in some fonts, accent marks can be positioned above the ascent or below the descent. To obtain a visual bounding box, which encloses all the text, use thegetBoundsmethod ofTextLayout.Note: The returned bounds is in baseline-relative coordinates (see
class notes).- Parameters:
chars- an array of charactersbeginIndex- the initial offset in the array of characterslimit- the end offset in the array of charactersfrc- the specifiedFontRenderContext- Returns:
- a
Rectangle2Dthat is the bounding box of the specified array of characters in the specifiedFontRenderContext. - Throws:
IndexOutOfBoundsException- ifbeginIndexis less than zero, orlimitis greater than the length ofchars, orbeginIndexis greater thanlimit.- Since:
- 1.2
- See Also:
FontRenderContext,createGlyphVector(java.awt.font.FontRenderContext, java.lang.String)
-
getStringBounds
public Rectangle2D getStringBounds(CharacterIterator ci, int beginIndex, int limit, FontRenderContext frc)
Returns the logical bounds of the characters indexed in the specifiedCharacterIteratorin the specifiedFontRenderContext. The logical bounds contains the origin, ascent, advance, and height, which includes the leading. The logical bounds does not always enclose all the text. For example, in some languages and in some fonts, accent marks can be positioned above the ascent or below the descent. To obtain a visual bounding box, which encloses all the text, use thegetBoundsmethod ofTextLayout.Note: The returned bounds is in baseline-relative coordinates (see
class notes).- Parameters:
ci- the specifiedCharacterIteratorbeginIndex- the initial offset incilimit- the end offset incifrc- the specifiedFontRenderContext- Returns:
- a
Rectangle2Dthat is the bounding box of the characters indexed in the specifiedCharacterIteratorin the specifiedFontRenderContext. - Throws:
IndexOutOfBoundsException- ifbeginIndexis less than the start index ofci, orlimitis greater than the end index ofci, orbeginIndexis greater thanlimit- Since:
- 1.2
- See Also:
FontRenderContext,createGlyphVector(java.awt.font.FontRenderContext, java.lang.String)
-
getMaxCharBounds
public Rectangle2D getMaxCharBounds(FontRenderContext frc)
Returns the bounds for the character with the maximum bounds as defined in the specifiedFontRenderContext.Note: The returned bounds is in baseline-relative coordinates (see
class notes).- Parameters:
frc- the specifiedFontRenderContext- Returns:
- a
Rectangle2Dthat is the bounding box for the character with the maximum bounds.
-
createGlyphVector
public GlyphVector createGlyphVector(FontRenderContext frc, String str)
Creates aGlyphVectorby mapping characters to glyphs one-to-one based on the Unicode cmap in thisFont. This method does no other processing besides the mapping of glyphs to characters. This means that this method is not useful for some scripts, such as Arabic, Hebrew, Thai, and Indic, that require reordering, shaping, or ligature substitution.- Parameters:
frc- the specifiedFontRenderContextstr- the specifiedString- Returns:
- a new
GlyphVectorcreated with the specifiedStringand the specifiedFontRenderContext.
-
createGlyphVector
public GlyphVector createGlyphVector(FontRenderContext frc, char[] chars)
Creates aGlyphVectorby mapping characters to glyphs one-to-one based on the Unicode cmap in thisFont. This method does no other processing besides the mapping of glyphs to characters. This means that this method is not useful for some scripts, such as Arabic, Hebrew, Thai, and Indic, that require reordering, shaping, or ligature substitution.- Parameters:
frc- the specifiedFontRenderContextchars- the specified array of characters- Returns:
- a new
GlyphVectorcreated with the specified array of characters and the specifiedFontRenderContext.
-
createGlyphVector
public GlyphVector createGlyphVector(FontRenderContext frc, CharacterIterator ci)
Creates aGlyphVectorby mapping the specified characters to glyphs one-to-one based on the Unicode cmap in thisFont. This method does no other processing besides the mapping of glyphs to characters. This means that this method is not useful for some scripts, such as Arabic, Hebrew, Thai, and Indic, that require reordering, shaping, or ligature substitution.- Parameters:
frc- the specifiedFontRenderContextci- the specifiedCharacterIterator- Returns:
- a new
GlyphVectorcreated with the specifiedCharacterIteratorand the specifiedFontRenderContext.
-
createGlyphVector
public GlyphVector createGlyphVector(FontRenderContext frc, int[] glyphCodes)
Creates aGlyphVectorby mapping characters to glyphs one-to-one based on the Unicode cmap in thisFont. This method does no other processing besides the mapping of glyphs to characters. This means that this method is not useful for some scripts, such as Arabic, Hebrew, Thai, and Indic, that require reordering, shaping, or ligature substitution.- Parameters:
frc- the specifiedFontRenderContextglyphCodes- the specified integer array- Returns:
- a new
GlyphVectorcreated with the specified integer array and the specifiedFontRenderContext.
-
layoutGlyphVector
public GlyphVector layoutGlyphVector(FontRenderContext frc, char[] text, int start, int limit, int flags)
Returns a newGlyphVectorobject, performing full layout of the text if possible. Full layout is required for complex text, such as Arabic or Hindi. Support for different scripts depends on the font and implementation.Layout requires bidi analysis, as performed by
Bidi, and should only be performed on text that has a uniform direction. The direction is indicated in the flags parameter,by using LAYOUT_RIGHT_TO_LEFT to indicate a right-to-left (Arabic and Hebrew) run direction, or LAYOUT_LEFT_TO_RIGHT to indicate a left-to-right (English) run direction.In addition, some operations, such as Arabic shaping, require context, so that the characters at the start and limit can have the proper shapes. Sometimes the data in the buffer outside the provided range does not have valid data. The values LAYOUT_NO_START_CONTEXT and LAYOUT_NO_LIMIT_CONTEXT can be added to the flags parameter to indicate that the text before start, or after limit, respectively, should not be examined for context.
All other values for the flags parameter are reserved.
- Parameters:
frc- the specifiedFontRenderContexttext- the text to layoutstart- the start of the text to use for theGlyphVectorlimit- the limit of the text to use for theGlyphVectorflags- control flags as described above- Returns:
- a new
GlyphVectorrepresenting the text between start and limit, with glyphs chosen and positioned so as to best represent the text - Throws:
ArrayIndexOutOfBoundsException- if start or limit is out of bounds- Since:
- 1.4
- See Also:
Bidi,LAYOUT_LEFT_TO_RIGHT,LAYOUT_RIGHT_TO_LEFT,LAYOUT_NO_START_CONTEXT,LAYOUT_NO_LIMIT_CONTEXT
-
-