Abstract (Java font)In Java API,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 GlyphsA 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. An eample of listing All Available Font Families(Java font)GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String fontNames[] = ge.getAvailableFontFamilyNames(); // Iterate the font family names for (int i=0; i<fontNames.length; i++) { }
An eample of Drawing Text with Mixed Styles(Java font)AttributedString astr = new AttributedString("aString"); astr.addAttribute(TextAttribute.FONT, font, start, end); astr.addAttribute(TextAttribute.BACKGROUND, color, start, end); // Draw mixed-style text TextLayout tl = new TextLayout(astr.getIterator(), g2d.getFontRenderContext()); tl.draw(g2d, x, y);
Master Font Manipulation in Java (Java font) From devxAny application that uses text, uses fonts. And depending on how wisely you plan, your fonts can either enhance your application or work against it. To get started, you need to understand how Java handles font objects and learn how to predict what your font-altering decisions will look like, regardless of the client system. Before you know it, you'll be a master of Java font manipulation. Whether you think very much about fonts or not, as an application user, you are constantly interacting with and manipulating fonts. Particularly in word processing programs, where it's common to change typestyles and typefaces for different parts of your document. So too, the ability to change typestyles and typefaces is useful as an application programmer. As a simple example, think of the "About" screen, which most every program has. It is common to see the program name in large text, to help it stand out, and legal jargon and copyright notices in smaller sized text. You can see this in Microsoft Word's Help/About menu. When writing computer programs, you want your user interface to be as intuitive as possible. This means you will use radio buttons and checkboxes and other visual components that your end users already understand. However, it also means that you want written information to stand out as clearly as possible. As well as varying the size of text, you may want to enhance specific words—by rendering them in bold, perhaps, or italics—to draw readers' attention. Also, you might want to consider how the reader will use the textual information you have provided. For instance, for information displayed on the screen, you might wish to use a sans-serif font such as Arial. However, for information that the user will print out from your application onto paper, you might wish to use a serif font such as Times Roman. These simple changes can help your user read and digest the information you want to convey. So, with that in mind, let's see how you can manage your textual information in Java, to enhance your own applications.
Read More HP-UX fonts and the Java™ Runtime Environment(java font) From HP
This section gives you information on how HP-UX fonts are configured with your HP-UX Java™ runtime environment. Because the HP-UX SDK has built-in support for the Asian TrueType fonts, you will not normally need this information. However, if you want to change Java's font.properties files or if you have a font-related problem, this information is useful Read More from HP Java font Tutorial from SUN A font is a complete set of type in one point size and type face. For example, all English language characters and symbols in Helvetica 10 point bold face make up a font. The font defines the characteristic look, size, and style (bold, italics, or plain) of the text string that is drawn with the font. How does a font define the characteristic look? A font is created from glyphs, and a glyph is a bit-mapped image that defines the appearance of the characters or symbols in the font. All fonts within the same font family have a similar appearance because they are all made from the same glyph set. Likewise, different fonts families use different glyph sets to achieve their own distinguishing look. A font family not only consists of fonts with a similar appearance, but also different points sizes and styles. Helvetica 10 point bold and Helvetica 12 point italic are two fonts in the same family, and Times Roman 8 point bold and Times Roman 10 point regular are two fonts in a different font family. Find Available Fonts To use a font, you have to create a Font object, and to do that, you need to know what fonts are available on the system and their names. Fonts have logical, family and font names. The logical name is a name mapped onto one of the specific fonts available on the platform. To get the logical name for a Font object, call java.awt.Font.getName The family name is the name of the font family that determines the typographic design across several faces, such as Helvetica or Times Roman. To get the family name for a given Font object, call java.awt.Font.getFamily. The font name represents a specific font within a family such as Helvetica Bold. To get the font name, call java.awt.Font.getFontName, and to determine which font faces are available on a system, call java.awt.GraphicsEnvironment.getAllFonts. Creating and Deriving Fonts The easiest way to create a font is by specifying the font name, point size, and style. Once you have a Font object, you can derive any number of new Font objects by calling the Font.deriveFont method on the existing font and specifying a new point size, style, transform (position, slant, scale, or rotation), or attribute map. Font boldFont = new Font("Helvetica", Font.BOLD, 12); Font italicDerived = boldFont.deriveFont(Font.ITALIC, 12); Font plainDerived = boldFont.deriveFont(Font.PLAIN, 14); Java Fonts, Random Numbers and Timers
This applet demonstrates the use of True Type Fonts in Java. Basically you have only the choice between TimesRoman, Courier and Helvetica if you want your applet to run on all machines. Fonts are objects which have to be created with new. You can add the BOLD and ITALIC attributes seperately or in combination. The size can be set in the last parameter of the Font constructor. Sourcecode import java.awt.*; import java.applet.*; //demonstrates the use of fonts public class Project6 extends Applet { Font font1 = new Font("Helvetica", Font.PLAIN, 22); Font font2 = new Font("TimesRoman", Font.PLAIN, 20); Font font3 = new Font("Courier", Font.PLAIN, 18); Font font4 = new Font("Helvetica", Font.BOLD, 16); Font font5 = new Font("Helvetica", Font.ITALIC, 16); Font font6 = new Font("Helvetica", Font.BOLD + Font.ITALIC, 16); public void paint(Graphics g) { g.setFont(font1); g.drawString("This is Font 1 (Helvetica)", 30,30); g.setFont(font2); g.drawString("This is Font 2 (TimesRoman)", 30,80); g.setFont(font3); g.drawString("This is Font 3 (Courier)", 30,130); g.setFont(font4); g.drawString("This is Helvetica Bold", 30,180); g.setFont(font5); g.drawString("This is Helvetica Italic", 30,230); g.setFont(font6); g.drawString("This is Helvetica Bold and Italic", 30,280); } } |