Все шрифты в java

Java: How to list of all the available Java/Swing fonts

Java Fonts FAQ: How do I create a list of all the fonts available on the current platform (MacOS, Linux, Windows)?

Answer: To list all the fonts available to you in a Java application (a Java Swing application), use the GraphicsEnvironment.getLocalGraphicsEnvironment().
getAvailableFontFamilyNames() method of the GraphicsEnvironment class, which technically returns an array of all the font family names it finds on the local system.

Here’s a small but complete sample Java program that prints out all the fonts (font family names):

package com.alvinalexander.javasamples; import java.awt.GraphicsEnvironment; public class ListJavaFonts < public static void main(String[] args) < String fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); for (int i = 0; i < fonts.length; i++) < System.out.println(fonts[i]); >> >

On my macOS version 10.4.10 system, this Java fonts program results in the following output:

#GungSeo #HeadLineA #PCMyungjo #PilGi Abadi MT Condensed Extra Bold Abadi MT Condensed Light Academy Engraved LET Al Bayan American Typewriter Andale Mono Apple Casual Apple Chancery Apple LiGothic Apple LiSung Apple Symbols AppleGothic AppleMyungjo Arial Arial Black Arial Hebrew Arial Narrow Arial Rounded MT Bold Ayuthaya Baghdad Bank Gothic Baskerville Baskerville Old Face Batang Bauhaus 93 Bell MT Bernard MT Condensed BiauKai Big Caslon Bitstream Vera Sans Bitstream Vera Sans Mono Bitstream Vera Serif Blackmoor LET BlairMdITC TT Bodoni Ornaments ITC TT Bodoni SvtyTwo ITC TT Bodoni SvtyTwo OS ITC TT Bodoni SvtyTwo SC ITC TT Book Antiqua Bookman Old Style Bordeaux Roman Bold LET Bradley Hand ITC TT Braggadocio Britannic Bold Brush Script MT Calisto MT Century Century Gothic Century Schoolbook Chalkboard Charcoal CY Cochin Colonna MT Comic Sans MS Cooper Black Copperplate Copperplate Gothic Bold Copperplate Gothic Light Corsiva Hebrew Courier Courier New Cracked Curlz MT DecoType Naskh Desdemona Devanagari MT Dialog DialogInput Didot Edwardian Script ITC Engravers MT Euphemia UCAS Eurostile Footlight MT Light Futura Garamond GB18030 Bitmap Geeza Pro Geneva Geneva CY Georgia Gill Sans Gill Sans Ultra Bold Gloucester MT Extra Condensed Goudy Old Style Gujarati MT Gulim Gurmukhi MT Haettenschweiler Handwriting - Dakota Harrington Hei Helvetica Helvetica CY Helvetica Neue Herculanum Hiragino Kaku Gothic Pro Hiragino Kaku Gothic Std Hiragino Maru Gothic Pro Hiragino Mincho Pro Hoefler Text Impact Imprint MT Shadow InaiMathi Jazz LET Kai Kino MT Krungthep KufiStandardGK LiHei Pro LiSong Pro Lucida Blackletter Lucida Bright Lucida Calligraphy Lucida Fax Lucida Grande Lucida Handwriting Lucida Sans Lucida Sans Typewriter Marker Felt Matura MT Script Capitals Mistral Modern No. 20 Mona Lisa Solid ITC TT Monaco Monospaced Monotype Corsiva Monotype Sorts MS Gothic MS Mincho MS PGothic MS PMincho Mshtakan MT Extra Nadeem New Peninim MT News Gothic MT Onyx OpenSymbol Optima Osaka Palatino Papyrus Party LET Perpetua Titling MT Plantagenet Cherokee Playbill PMingLiU PortagoITC TT Princetown LET Raanana Rockwell Rockwell Extra Bold SansSerif Santa Fe LET Sathu Savoye LET SchoolHouse Cursive B SchoolHouse Printed A Serif Silom SimSun Skia Snell Roundhand Stencil STFangsong STHeiti STKaiti Stone Sans ITC TT Stone Sans Sem ITC TT STSong Symbol Synchro LET Tahoma Thonburi Times Times New Roman Trebuchet MS Type Embellishments One LET Verdana Webdings Wide Latin Wingdings Wingdings 2 Wingdings 3 Zapf Dingbats Zapfino

Источник

Читайте также:  Python чем отличается append от add

Class Font

The Font class 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 on Graphics and Component objects.

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

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 createFont method.

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 Label and TextField , 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

A Font can have many faces, such as heavy, medium, oblique, gothic and regular. All of these faces have similar typographic design.

Читайте также:  Default web page index html

There are three different names that you can get from a Font object. 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 Font class 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 several Font objects 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 getAllFonts method of the GraphicsEnvironment class returns an array of all font faces available in the system. These font faces are returned as Font objects with a size of 1, identity transform and default font features. These base fonts can then be used to derive new Font objects with varying sizes, styles, transforms and font features via the deriveFont methods in this class.

Font and TextAttribute

Font supports most TextAttribute s. This makes some operations, such as rendering underlined text, convenient since it is not necessary to explicitly construct a TextLayout object. Attributes can be set on a Font by constructing or deriving it using a Map of TextAttribute values.

  • FOREGROUND and BACKGROUND use Paint values. The subclass Color is serializable, while GradientPaint and TexturePaint are not.
  • CHAR_REPLACEMENT uses GraphicAttribute values. The subclasses ShapeGraphicAttribute and ImageGraphicAttribute are not serializable.
  • INPUT_METHOD_HIGHLIGHT uses InputMethodHighlight values, which are not serializable. See InputMethodHighlight .

Clients who create custom subclasses of Paint and GraphicAttribute can 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 and deriveFont APIs ignore the FONT attribute, and it is not retained by the Font; the static getFont(java.util.Map) method should be used if the FONT attribute might be present. See TextAttribute.FONT for more information.

Several attributes will cause additional rendering overhead and potentially invoke layout. If a Font has such attributes, the hasLayoutAttributes() method will return true.

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.’

Читайте также:  Java http код ошибки

Источник

Supported Fonts

The set of supported fonts varies between different implementations of the Java platform. For the terminology used, see the Font class description.

Support for Physical Fonts

The JRE supports TrueType and PostScript Type 1 fonts.

Physical fonts need to be installed in locations known to the Java runtime environment. The JRE looks in two locations: the lib/fonts directory within the JRE itself, and the normal font location(s) defined by the host operating system. If fonts with the same name exist in both locations, the one in the lib/fonts directory is used.

Users can add physical fonts that use a supported font technology by installing them either in the lib/fonts directory within the JRE, or by installing them in a way supported by the host operating system. The recommended location to add per-user fonts on Solaris or Linux is the $HOME/.fonts directory which is searched by the platform’s libfontconfig, and which is in turn used by the JDK.

Support for Logical Fonts

Logical font names are mapped to physical fonts in implementation dependent ways. Typically one logical font name maps to several physical fonts in order to cover a large range of characters. The JRE uses font configuration files to define the mapping.

Users can add a limited number of supported TrueType and Type 1 physical fonts as fallback fonts for logical fonts used in Java 2D rendering by installing them in the lib/fonts/fallback directory within the JRE. However, this mechanism has the following restrictions:

  • The same fonts are used for all logical fonts.
  • The order in which the fonts are used cannot be defined.
  • AWT heavyweight components on Windows do not work.
  • The mechanism does not work on macOS.
  • The number of fonts that can be added is limited in a way that cannot be precisely specified. On Windows, no more than 200 fonts can be assumed to work, and on Linux and Solaris it could be considerably fewer, with no guaranteed minimum number.

The Lucida Fonts

The JDK and the JRE bundle several physical fonts of the «Lucida» design family. These fonts are also licensed for use in other implementations of the Java Platform. These fonts are physical fonts, but since they come with the Java SE Runtime, they don’t depend on the host operating system. Using them provides the benefit of a consistent look and feel across platforms and implementations for a large set of languages.

There are three different type families: «Lucida Sans» , «Lucida Sans Typewriter» , and «Lucida Bright» . Each family has plain, bold, italic, and bold-italic styles. Not all of these are present in all Java SE implementations. For example, the default download bundle of the JRE for Windows only contains the Lucida Sans plain font (but note that application developers can include all Lucida fonts with a Java runtime environment that they redistribute with an application).

The following table shows which Unicode character blocks are covered by each font family:

Источник

Оцените статью