2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / awt / Font.java
blob809684311f08e7c0947ffa25635c1695833599f9
1 /* Font.java -- Font object
2 Copyright (C) 1999, 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.awt;
41 import java.awt.font.FontRenderContext;
42 import java.awt.font.GlyphVector;
43 import java.awt.font.LineMetrics;
44 import java.awt.font.TextAttribute;
45 import java.awt.geom.AffineTransform;
46 import java.awt.geom.Rectangle2D;
47 import java.awt.peer.FontPeer;
48 import java.io.InputStream;
49 import java.io.IOException;
50 import java.io.Serializable;
51 import java.util.Locale;
52 import java.util.Map;
53 import java.util.StringTokenizer;
54 import java.text.CharacterIterator;
55 import java.text.AttributedCharacterIterator;
57 /**
58 * This class represents a windowing system font.
60 * @author Aaron M. Renn (arenn@urbanophile.com)
61 * @author Warren Levy <warrenl@cygnus.com>
63 public class Font implements Serializable
67 * Static Variables
70 /**
71 * Constant indicating a "plain" font.
73 public static final int PLAIN = 0;
75 /**
76 * Constant indicating a "bold" font.
78 public static final int BOLD = 1;
80 /**
81 * Constant indicating an "italic" font.
83 public static final int ITALIC = 2;
85 /**
86 * Constant indicating the baseline mode characteristic of Roman.
88 public static final int ROMAN_BASELINE = 0;
90 /**
91 * Constant indicating the baseline mode characteristic of Chinese.
93 public static final int CENTER_BASELINE = 1;
95 /**
96 * Constant indicating the baseline mode characteristic of Devanigri.
98 public static final int HANGING_BASELINE = 2;
102 * Indicates to <code>createFont</code> that the supplied font data
103 * is in TrueType format.
105 * <p><em>Specification Note:</em> The Sun JavaDoc for J2SE 1.4 does
106 * not indicate whether this value also subsumes OpenType. OpenType
107 * is essentially the same format as TrueType, but allows to define
108 * glyph shapes in the same way as PostScript, using cubic bezier
109 * curves.
111 * @since 1.3
113 public static final int TRUETYPE_FONT = 0;
117 * A flag for <code>layoutGlyphVector</code>, indicating that the
118 * orientation of a text run is from left to right.
120 * @since 1.4
122 public static final int LAYOUT_LEFT_TO_RIGHT = 0;
126 * A flag for <code>layoutGlyphVector</code>, indicating that the
127 * orientation of a text run is from right to left.
129 * @since 1.4
131 public static final int LAYOUT_RIGHT_TO_LEFT = 1;
135 * A flag for <code>layoutGlyphVector</code>, indicating that the
136 * text does not contain valid characters before the
137 * <code>start</code> position. If this flag is set,
138 * <code>layoutGlyphVector</code> does not examine the text before
139 * <code>start</code>, even if this would be necessary to select the
140 * correct glyphs (e.g., for Arabic text).
142 * @since 1.4
144 public static final int LAYOUT_NO_START_CONTEXT = 2;
148 * A flag for <code>layoutGlyphVector</code>, indicating that the
149 * text does not contain valid characters after the
150 * <code>limit</code> position. If this flag is set,
151 * <code>layoutGlyphVector</code> does not examine the text after
152 * <code>limit</code>, even if this would be necessary to select the
153 * correct glyphs (e.g., for Arabic text).
155 * @since 1.4
157 public static final int LAYOUT_NO_LIMIT_CONTEXT = 4;
160 // Serialization constant
161 private static final long serialVersionUID = -4206021311591459213L;
163 /*************************************************************************/
166 * Instance Variables
170 * The name of this font
172 protected String name;
175 * The font style, which is a combination (by summing, not OR-ing) of
176 * the font style constants in this class.
178 protected int style;
181 * The font point size.
183 protected int size;
185 protected float pointSize;
187 // The native peer for this font
188 private FontPeer peer;
190 /*************************************************************************/
193 * Static Methods
197 * Creates a <code>Font</code> object from the specified string, which
198 * is in one of the following formats:
199 * <p>
200 * <ul>
201 * <li>fontname-style-pointsize
202 * <li>fontname-style
203 * <li>fontname-pointsize
204 * <li>fontname
205 * </ul>
206 * <p>
207 * The style should be one of BOLD, ITALIC, or BOLDITALIC. The default
208 * style if none is specified is PLAIN. The default size if none
209 * is specified is 12.
211 public static Font
212 decode(String fontspec)
214 String name = null;
215 int style = PLAIN;
216 int size = 12;
218 StringTokenizer st = new StringTokenizer(fontspec, "-");
219 while (st.hasMoreTokens())
221 String token = st.nextToken();
222 if (name == null)
224 name = token;
225 continue;
228 if (token.toUpperCase().equals("BOLD"))
230 style = BOLD;
231 continue;
233 if (token.toUpperCase().equals("ITALIC"))
235 style = ITALIC;
236 continue;
238 if (token.toUpperCase().equals("BOLDITALIC"))
240 style = BOLD + ITALIC;
241 continue;
244 int tokenval = 0;
247 tokenval = Integer.parseInt(token);
249 catch(NumberFormatException e) { ; }
251 if (tokenval != 0)
252 size = tokenval;
255 return(new Font(name, style, size));
258 /*************************************************************************/
261 * Returns a <code>Font</code> object from the passed property name.
263 * @param propname The name of the system property.
264 * @param default Value to use if the property is not found.
266 * @return The requested font, or <code>default</code> if the property
267 * not exist or is malformed.
269 public static Font
270 getFont(String propname, Font defval)
272 String propval = System.getProperty(propname);
273 if (propval != null)
274 return(decode(propval));
276 return(defval);
279 /*************************************************************************/
282 * Returns a <code>Font</code> object from the passed property name.
284 * @param propname The name of the system property.
286 * @return The requested font, or <code>null</code> if the property
287 * not exist or is malformed.
289 public static Font
290 getFont(String propname)
292 return(getFont(propname, null));
295 /*************************************************************************/
298 * Constructors
302 * Initializes a new instance of <code>Font</code> with the specified
303 * attributes.
305 * @param name The name of the font.
306 * @param style The font style.
307 * @param size The font point size.
309 public
310 Font(String name, int style, int size)
312 this.name = name;
313 this.style = style;
314 this.size = size;
315 this.pointSize = size;
318 public
319 Font(Map attributes)
321 throw new UnsupportedOperationException();
324 /*************************************************************************/
327 * Instance Methods
331 * Returns the logical name of the font. A logical name describes a very
332 * general typographic style (such as Sans Serif). It is less specific
333 * than both a font family name (such as Helvetica) and a font face name
334 * (such as Helvetica Bold).
336 * @return The logical name of the font.
338 * @see getFamily()
339 * @see getFontName()
341 public String
342 getName()
344 return(name);
347 /*************************************************************************/
350 * Returns the style of the font.
352 * @return The font style.
354 public int
355 getSize()
357 return(size);
360 public float
361 getSize2D()
363 return pointSize;
366 /*************************************************************************/
369 * Tests whether or not this is a plain font. This will be true if
370 * and only if neither the bold nor the italics style is set.
372 * @return <code>true</code> if this is a plain font, <code>false</code>
373 * otherwise.
375 public boolean
376 isPlain()
378 if (style == PLAIN)
379 return(true);
380 else
381 return(false);
384 /*************************************************************************/
387 * Tests whether or not this font is bold.
389 * @return <code>true</code> if this font is bold, <code>false</code>
390 * otherwise.
392 public boolean
393 isBold()
395 if ((style == BOLD) || (style == (BOLD+ITALIC)))
396 return(true);
397 else
398 return(false);
401 /*************************************************************************/
404 * Tests whether or not this font is italic.
406 * @return <code>true</code> if this font is italic, <code>false</code>
407 * otherwise.
409 public boolean
410 isItalic()
412 if ((style == ITALIC) || (style == (BOLD+ITALIC)))
413 return(true);
414 else
415 return(false);
418 /*************************************************************************/
421 * Returns the family name of this font. A family name describes a
422 * typographic style (such as Helvetica or Palatino). It is more specific
423 * than a logical font name (such as Sans Serif) but less specific than a
424 * font face name (such as Helvetica Bold).
426 * @return A string containing the font family name.
428 * @since 1.2
430 * @see getName()
431 * @see getFontName()
432 * @see GraphicsEnvironment.getAvailableFontFamilyNames()
434 public String
435 getFamily()
437 // FIXME: How do I implement this?
438 return(name);
442 * Returns integer code representing the sum of style flags of this font, a
443 * combination of either {@link PLAIN}, {@link BOLD}, or {@link ITALIC}.
445 * @return code representing the style of this font.
447 * @see isPlain()
448 * @see isBold()
449 * @see isItalic()
451 public int
452 getStyle()
454 return style;
458 * Checks if specified character maps to a glyph in this font.
460 * @param c The character to check.
462 * @return Whether the character has a corresponding glyph in this font.
464 * @since 1.2
466 public boolean
467 canDisplay(char c)
469 throw new UnsupportedOperationException ();
473 * Checks how much of a given string can be mapped to glyphs in
474 * this font.
476 * @param s The string to check.
478 * @return The index of the first character in <code>s</code> which cannot
479 * be converted to a glyph by this font, or <code>-1</code> if all
480 * characters can be mapped to glyphs.
482 * @since 1.2
484 public int
485 canDisplayUpTo(String s)
487 throw new UnsupportedOperationException ();
491 * Checks how much of a given sequence of text can be mapped to glyphs in
492 * this font.
494 * @param text Array containing the text to check.
495 * @param start Position of first character to check in <code>text</code>.
496 * @param limit Position of last character to check in <code>text</code>.
498 * @return The index of the first character in the indicated range which
499 * cannot be converted to a glyph by this font, or <code>-1</code> if all
500 * characters can be mapped to glyphs.
502 * @since 1.2
504 * @throws IndexOutOfBoundsException if the range [start, limit] is
505 * invalid in <code>text</code>.
507 public int
508 canDisplayUpTo(char[] text, int start, int limit)
510 throw new UnsupportedOperationException ();
514 * Checks how much of a given sequence of text can be mapped to glyphs in
515 * this font.
517 * @param i Iterator over the text to check.
518 * @param start Position of first character to check in <code>i</code>.
519 * @param limit Position of last character to check in <code>i</code>.
521 * @return The index of the first character in the indicated range which
522 * cannot be converted to a glyph by this font, or <code>-1</code> if all
523 * characters can be mapped to glyphs.
525 * @since 1.2
527 * @throws IndexOutOfBoundsException if the range [start, limit] is
528 * invalid in <code>i</code>.
530 public int
531 canDisplayUpTo(CharacterIterator i, int start, int limit)
533 throw new UnsupportedOperationException ();
537 * Creates a new font with point size 1 and {@link PLAIN} style,
538 * reading font data from the provided input stream. The resulting font
539 * can have further fonts derived from it using its
540 * <code>deriveFont</code> method.
542 * @param fontFormat Integer code indicating the format the font data is
543 * in.Currently this can only be {@link TRUETYPE_FONT}.
544 * @param is {@link InputStream} from which font data will be read. This
545 * stream is not closed after font data is extracted.
547 * @return A new {@link Font} of the format indicated.
549 * @throws IllegalArgumentException if <code>fontType</code> is not
550 * recognized.
551 * @throws FontFormatException if data in InputStream is not of format
552 * indicated.
553 * @throws IOException if insufficient data is present on InputStream.
555 * @since 1.3
557 public static Font
558 createFont(int fontFormat, InputStream is)
559 throws FontFormatException, IOException
561 throw new UnsupportedOperationException ();
565 * Maps characters to glyphs in a one-to-one relationship, returning a new
566 * {@link GlyphVector} with a mapped glyph for each input character. This
567 * sort of mapping is often sufficient for some scripts such as Roman, but
568 * is inappropriate for scripts with special shaping or contextual layout
569 * requirements such as Arabic, Indic, Hebrew or Thai.
571 * @param ctx The rendering context used for precise glyph placement.
572 * @param str The string to convert to Glyphs.
574 * @return A new {@link GlyphVector} containing glyphs mapped from str,
575 * through the font's cmap table.
577 * @see layoutGlyphVector()
579 public GlyphVector
580 createGlyphVector(FontRenderContext ctx, String str)
582 throw new UnsupportedOperationException ();
586 * Maps characters to glyphs in a one-to-one relationship, returning a new
587 * {@link GlyphVector} with a mapped glyph for each input character. This
588 * sort of mapping is often sufficient for some scripts such as Roman, but
589 * is inappropriate for scripts with special shaping or contextual layout
590 * requirements such as Arabic, Indic, Hebrew or Thai.
592 * @param ctx The rendering context used for precise glyph placement.
593 * @param i Iterator over the text to convert to glyphs.
595 * @return A new {@link GlyphVector} containing glyphs mapped from str,
596 * through the font's cmap table.
598 * @see layoutGlyphVector()
600 public GlyphVector
601 createGlyphVector(FontRenderContext ctx, CharacterIterator i)
603 throw new UnsupportedOperationException ();
607 * Maps characters to glyphs in a one-to-one relationship, returning a new
608 * {@link GlyphVector} with a mapped glyph for each input character. This
609 * sort of mapping is often sufficient for some scripts such as Roman, but
610 * is inappropriate for scripts with special shaping or contextual layout
611 * requirements such as Arabic, Indic, Hebrew or Thai.
613 * @param ctx The rendering context used for precise glyph placement.
614 * @param chars Array of characters to convert to glyphs.
616 * @return A new {@link GlyphVector} containing glyphs mapped from str,
617 * through the font's cmap table.
619 * @see layoutGlyphVector()
621 public GlyphVector
622 createGlyphVector(FontRenderContext ctx, char[] chars)
624 throw new UnsupportedOperationException ();
628 * Extracts a sequence of glyphs from a font, returning a new {@link
629 * GlyphVector} with a mapped glyph for each input glyph code.
631 * @param ctx The rendering context used for precise glyph placement.
632 * @param chars Array of characters to convert to glyphs.
634 * @return A new {@link GlyphVector} containing glyphs mapped from str,
635 * through the font's cmap table.
637 * @see layoutGlyphVector()
639 * @specnote This method is documented to perform character-to-glyph
640 * conversions, in the Sun documentation, but its second parameter name is
641 * "glyphCodes" and it is not clear to me why it would exist if its
642 * purpose was to transport character codes inside integers. I assume it
643 * is mis-documented in the Sun documentation.
645 public GlyphVector
646 createGlyphVector(FontRenderContext ctx, int[] glyphCodes)
648 throw new UnsupportedOperationException ();
652 * Produces a new {@link Font} based on the current font, adjusted to a
653 * new size.
655 * @param size The size of the newly created font.
657 * @return A clone of the current font, with the specified size.
659 * @since 1.2
661 public Font
662 deriveFont(float size)
664 throw new UnsupportedOperationException ();
668 * Produces a new {@link Font} based on the current font, adjusted to a
669 * new style.
671 * @param style The style of the newly created font.
673 * @return A clone of the current font, with the specified style.
675 * @since 1.2
677 public Font
678 deriveFont(int style)
680 throw new UnsupportedOperationException ();
684 * Produces a new {@link Font} based on the current font, adjusted to a
685 * new style and subjected to a new affine transformation.
687 * @param style The style of the newly created font.
688 * @param a The transformation to apply.
690 * @return A clone of the current font, with the specified style and
691 * transform.
693 * @throws IllegalArgumentException If transformation is
694 * <code>null</code>.
696 * @since 1.2
698 public Font
699 deriveFont(int style, AffineTransform a)
701 throw new UnsupportedOperationException ();
705 * Produces a new {@link Font} based on the current font, adjusted to a
706 * new set of attributes.
708 * @param attributes Attributes of the newly created font.
710 * @return A clone of the current font, with the specified attributes.
712 * @since 1.2
714 public Font
715 deriveFont(Map attributes)
717 throw new UnsupportedOperationException ();
721 * Returns a map of chracter attributes which this font currently has set.
723 * @return A map of chracter attributes which this font currently has set.
725 * @see getAvailableAttributes()
726 * @see java.text.AttributedCharacterIterator.Attribute
727 * @see java.awt.font.TextAttribute
729 public Map
730 getAttributes()
732 throw new UnsupportedOperationException ();
736 * Returns an array of chracter attribute keys which this font understands.
738 * @return An array of chracter attribute keys which this font understands.
740 * @see getAttributes()
741 * @see java.text.AttributedCharacterIterator.Attribute
742 * @see java.awt.font.TextAttribute
744 public AttributedCharacterIterator.Attribute[]
745 getAvailableAttributes()
747 throw new UnsupportedOperationException ();
751 * Returns a baseline code (one of {@link ROMAN_BASELINE}, {@link
752 * CENTER_BASELINE} or {@link HANGING_BASELINE}) indicating which baseline
753 * this font will measure baseline offsets for, when presenting glyph
754 * metrics for a given character.
756 * Baseline offsets describe the position of a glyph relative to an
757 * invisible line drawn under, through the center of, or over a line of
758 * rendered text, respectively. Different scripts use different baseline
759 * modes, so clients should not assume all baseline offsets in a glyph
760 * vector are from a common baseline.
762 * @param c The character code to select a baseline mode for.
764 * @return The baseline mode which would be used in a glyph associated
765 * with the provided character.
767 * @since 1.2
769 * @see LineMetrics.getBaselineOffsets()
771 public byte
772 getBaselineFor(char c)
774 throw new UnsupportedOperationException ();
778 * Returns the family name of this font. A family name describes a
779 * typographic style (such as Helvetica or Palatino). It is more specific
780 * than a logical font name (such as Sans Serif) but less specific than a
781 * font face name (such as Helvetica Bold).
783 * @param lc The locale in which to describe the name of the font family.
785 * @return A string containing the font family name, localized for the
786 * provided locale.
788 * @since 1.2
790 * @see getName()
791 * @see getFontName()
792 * @see GraphicsEnvironment.getAvailableFontFamilyNames()
793 * @see Locale
795 public String
796 getFamily(Locale lc)
798 throw new UnsupportedOperationException ();
802 * Returns a font appropriate for the given attribute set.
804 * @param attributes The attributes required for the new font.
806 * @return A new Font with the given attributes.
808 * @since 1.2
810 * @see TextAttribure
812 public static Font
813 getFont(Map attributes)
815 throw new UnsupportedOperationException ();
819 * Returns the font face name of the font. A font face name describes a
820 * specific variant of a font family (such as Helvetica Bold). It is more
821 * specific than both a font family name (such as Helvetica) and a logical
822 * font name (such as Sans Serif).
824 * @return The font face name of the font.
826 * @since 1.2
828 * @see getName()
829 * @see getFamily()
831 public String
832 getFontName()
834 throw new UnsupportedOperationException ();
838 * Returns the font face name of the font. A font face name describes a
839 * specific variant of a font family (such as Helvetica Bold). It is more
840 * specific than both a font family name (such as Helvetica) and a logical
841 * font name (such as Sans Serif).
843 * @param lc The locale in which to describe the name of the font face.
845 * @return A string containing the font face name, localized for the
846 * provided locale.
848 * @since 1.2
850 * @see getName()
851 * @see getFamily()
853 public String
854 getFontName(Locale lc)
856 throw new UnsupportedOperationException ();
860 * Returns the italic angle of this font, a measurement of its slant when
861 * style is {@link ITALIC}. The precise meaning is the inverse slope of a
862 * caret line which "best measures" the font's italic posture.
864 * @return The italic angle.
866 * @see TextAttribute.POSTURE
868 public float
869 getItalicAngle()
871 throw new UnsupportedOperationException ();
875 * Returns a {@link LineMetrics} object constructed with the specified
876 * text and {@link FontRenderContext}.
878 * @param text The string to calculate metrics from.
879 * @param begin Index of first character in <code>text</code> to measure.
880 * @param limit Index of last character in <code>text</code> to measure.
881 * @param rc Context for calculating precise glyph placement and hints.
883 * @return A new {@link LineMetrics} object.
885 * @throws IndexOutOfBoundsException if the range [begin, limit] is
886 * invalid in <code>text</code>.
888 public LineMetrics
889 getLineMetrics(String text, int begin, int limit, FontRenderContext rc)
891 throw new UnsupportedOperationException ();
895 * Returns a {@link LineMetrics} object constructed with the specified
896 * text and {@link FontRenderContext}.
898 * @param chars The string to calculate metrics from.
899 * @param begin Index of first character in <code>text</code> to measure.
900 * @param limit Index of last character in <code>text</code> to measure.
901 * @param rc Context for calculating precise glyph placement and hints.
903 * @return A new {@link LineMetrics} object.
905 * @throws IndexOutOfBoundsException if the range [begin, limit] is
906 * invalid in <code>chars</code>.
908 public LineMetrics
909 getLineMetrics(char[] chars, int begin, int limit, FontRenderContext rc)
911 throw new UnsupportedOperationException ();
915 * Returns a {@link LineMetrics} object constructed with the specified
916 * text and {@link FontRenderContext}.
918 * @param ci The string to calculate metrics from.
919 * @param begin Index of first character in <code>text</code> to measure.
920 * @param limit Index of last character in <code>text</code> to measure.
921 * @param rc Context for calculating precise glyph placement and hints.
923 * @return A new {@link LineMetrics} object.
925 * @throws IndexOutOfBoundsException if the range [begin, limit] is
926 * invalid in <code>ci</code>.
928 public LineMetrics
929 getLineMetrics(CharacterIterator ci, int begin, int limit, FontRenderContext rc)
931 throw new UnsupportedOperationException ();
935 * Returns the maximal bounding box of all the bounding boxes in this
936 * font, when the font's bounding boxes are evaluated in a given {@link
937 * FontRenderContext}
939 * @param rc Context in which to evaluate bounding boxes.
941 * @return The maximal bounding box.
943 public Rectangle2D
944 getMaxCharBounds(FontRenderContext rc)
946 throw new UnsupportedOperationException ();
950 * Returns the glyph code this font uses to represent missing glyphs. This
951 * code will be present in glyph vectors when the font was unable to
952 * locate a glyph to represent a particular character code.
954 * @return The missing glyph code.
956 * @since 1.2
958 public int
959 getMissingGlyphCode()
961 throw new UnsupportedOperationException ();
965 * Returns the overall number of glyphs in this font. This number is one
966 * more than the greatest glyph code used in any glyph vectors this font
967 * produces. In other words, glyph codes are taken from the range
968 * <code>[ 0, getNumGlyphs() - 1 ]</code>.
970 * @return The number of glyphs in this font.
972 * @since 1.2
974 public int
975 getNumGlyphs()
977 throw new UnsupportedOperationException ();
981 * Returns the PostScript Name of this font.
983 * @return The PostScript Name of this font.
985 * @since 1.2
987 * @see getName()
988 * @see getFamily()
989 * @see getFontName()
991 public String
992 getPSName()
994 throw new UnsupportedOperationException ();
998 * Returns the logical bounds of the specified string when rendered with this
999 * font in the specified {@link FontRenderContext}. This box will include the
1000 * glyph origin, ascent, advance, height, and leading, but may not include all
1001 * diacritics or accents. To get the complete visual bounding box of all the
1002 * glyphs in a run of text, use the {@link TextLayout#getBounds} method of
1003 * {@link TextLayout}.
1005 * @param str The string to measure.
1006 * @param frc The context in which to make the precise glyph measurements.
1008 * @return A bounding box covering the logical bounds of the specified text.
1010 * @see createGlyphVector()
1012 public Rectangle2D
1013 getStringBounds(String str, FontRenderContext frc)
1015 throw new UnsupportedOperationException ();
1019 * Returns the logical bounds of the specified string when rendered with this
1020 * font in the specified {@link FontRenderContext}. This box will include the
1021 * glyph origin, ascent, advance, height, and leading, but may not include all
1022 * diacritics or accents. To get the complete visual bounding box of all the
1023 * glyphs in a run of text, use the {@link TextLayout#getBounds} method of
1024 * {@link TextLayout}.
1026 * @param str The string to measure.
1027 * @param begin Index of the first character in <code>str</code> to measure.
1028 * @param limit Index of the last character in <code>str</code> to measure.
1029 * @param frc The context in which to make the precise glyph measurements.
1031 * @return A bounding box covering the logical bounds of the specified text.
1033 * @throws IndexOutOfBoundsException if the range [begin, limit] is
1034 * invalid in <code>str</code>.
1036 * @since 1.2
1038 * @see createGlyphVector()
1040 public Rectangle2D
1041 getStringBounds(String str, int begin, int limit, FontRenderContext frc)
1043 throw new UnsupportedOperationException ();
1047 * Returns the logical bounds of the specified string when rendered with this
1048 * font in the specified {@link FontRenderContext}. This box will include the
1049 * glyph origin, ascent, advance, height, and leading, but may not include all
1050 * diacritics or accents. To get the complete visual bounding box of all the
1051 * glyphs in a run of text, use the {@link TextLayout#getBounds} method of
1052 * {@link TextLayout}.
1054 * @param ci The text to measure.
1055 * @param begin Index of the first character in <code>ci</code> to measure.
1056 * @param limit Index of the last character in <code>ci</code> to measure.
1057 * @param frc The context in which to make the precise glyph measurements.
1059 * @return A bounding box covering the logical bounds of the specified text.
1061 * @throws IndexOutOfBoundsException if the range [begin, limit] is
1062 * invalid in <code>ci</code>.
1064 * @since 1.2
1066 * @see createGlyphVector()
1068 public Rectangle2D
1069 getStringBounds(CharacterIterator ci, int begin, int limit, FontRenderContext frc)
1071 throw new UnsupportedOperationException ();
1075 * Returns the logical bounds of the specified string when rendered with this
1076 * font in the specified {@link FontRenderContext}. This box will include the
1077 * glyph origin, ascent, advance, height, and leading, but may not include all
1078 * diacritics or accents. To get the complete visual bounding box of all the
1079 * glyphs in a run of text, use the {@link TextLayout#getBounds} method of
1080 * {@link TextLayout}.
1082 * @param chars The text to measure.
1083 * @param begin Index of the first character in <code>ci</code> to measure.
1084 * @param limit Index of the last character in <code>ci</code> to measure.
1085 * @param frc The context in which to make the precise glyph measurements.
1087 * @return A bounding box covering the logical bounds of the specified text.
1089 * @throws IndexOutOfBoundsException if the range [begin, limit] is
1090 * invalid in <code>chars</code>.
1092 * @since 1.2
1094 * @see createGlyphVector()
1096 public Rectangle2D
1097 getStringBounds(char[] chars, int begin, int limit, FontRenderContext frc)
1099 throw new UnsupportedOperationException ();
1103 * Returns a copy of the affine transformation this font is currently
1104 * subject to, if any.
1106 * @return The current transformation.
1108 public AffineTransform
1109 getTransform()
1111 throw new UnsupportedOperationException ();
1115 * Indicates whether this font's line metrics are uniform. A font may be
1116 * composed of several "subfonts", each covering a different code range,
1117 * and each with their own line metrics. A font with no subfonts, or
1118 * subfonts with identical line metrics, is said to have "uniform" line
1119 * metrics.
1121 * @return Whether this font has uniform line metrics.
1123 * @see LineMetrics
1124 * @see getLineMetrics()
1126 public boolean
1127 hasUniformLineMetrics()
1129 throw new UnsupportedOperationException ();
1133 * Indicates whether this font is subject to a non-identity affine
1134 * transformation.
1136 * @return <code>true</code> iff the font has a non-identity affine
1137 * transformation applied to it.
1139 public boolean
1140 isTransformed()
1142 throw new UnsupportedOperationException ();
1146 * Produces a glyph vector representing a full layout fo the specified
1147 * text in this font. Full layouts may include complex shaping and
1148 * reordering operations, for scripts such as Arabic or Hindi.
1150 * Bidirectional (bidi) layout is not performed in this method; text
1151 * should have its bidi direction specified with one of the flags {@link
1152 * LAYOUT_LEFT_TO_RIGHT} or {@link LAYOUT_RIGHT_TO_LEFT}.
1154 * Some types of layout (notably Arabic glyph shaping) may examine context
1155 * characters beyond the bounds of the indicated range, in order to select
1156 * an appropriate shape. The flags {@link LAYOUT_NO_START_CONTEXT} and
1157 * {@link LAYOUT_NO_LIMIT_CONTEXT} can be provided to prevent these extra
1158 * context areas from being examined, for instance if they contain invalid
1159 * characters.
1161 * @param frc Context in which to perform the layout.
1162 * @param chars Text to perform layout on.
1163 * @param start Index of first character to perform layout on.
1164 * @param limit Index of last character to perform layout on.
1165 * @param flags Combination of flags controlling layout.
1167 * @return A new {@link GlyphVector} representing the specified text.
1169 * @throws IndexOutOfBoundsException if the range [begin, limit] is
1170 * invalid in <code>chars</code>.
1172 public GlyphVector
1173 layoutGlyphVector(FontRenderContext frc, char[] chars, int start, int limit, int flags)
1175 throw new UnsupportedOperationException ();
1179 /*************************************************************************/
1182 * Returns a native peer object for this font.
1184 * @return A native peer object for this font.
1186 * @deprecated
1188 public FontPeer
1189 getPeer()
1191 if (peer != null)
1192 return(peer);
1194 peer = Toolkit.getDefaultToolkit().getFontPeer(name, style);
1195 return(peer);
1198 /*************************************************************************/
1201 * Returns a hash value for this font.
1203 * @return A hash for this font.
1205 public int
1206 hashCode()
1208 return((new String(name + size + style)).hashCode());
1211 /*************************************************************************/
1214 * Tests whether or not the specified object is equal to this font. This
1215 * will be true if and only if:
1216 * <P>
1217 * <ul>
1218 * <li>The object is not <code>null</code>.
1219 * <li>The object is an instance of <code>Font</code>.
1220 * <li>The object has the same name, style, and size as this object.
1221 * </ul>
1223 * @return <code>true</code> if the specified object is equal to this
1224 * object, <code>false</code> otherwise.
1226 public boolean
1227 equals(Object obj)
1229 if (!(obj instanceof Font))
1230 return(false);
1232 Font f = (Font)obj;
1234 if (!f.name.equals(name))
1235 return(false);
1237 if (f.size != size)
1238 return(false);
1240 if (f.style != style)
1241 return(false);
1243 return(true);
1246 /*************************************************************************/
1249 * Returns a string representation of this font.
1251 * @return A string representation of this font.
1253 public String
1254 toString()
1256 return(getClass().getName() + "(name=" + name + ",style=" + style +
1257 ",size=" + size + ")");
1262 * Determines the line metrics for a run of text.
1264 * @param str the text run to be measured.
1266 * @param frc the font rendering parameters that are used for the
1267 * measurement. The exact placement and size of text slightly
1268 * depends on device-specific characteristics, for instance
1269 * the device resolution or anti-aliasing. For this reason,
1270 * the returned measurement will only be accurate if the
1271 * passed <code>FontRenderContext</code> correctly reflects
1272 * the relevant parameters. Hence, <code>frc</code> should be
1273 * obtained from the same <code>Graphics2D</code> that will
1274 * be used for drawing, and any rendering hints should be set
1275 * to the desired values before obtaining <code>frc</code>.
1277 * @see java.awt.Graphics2D#getFontRenderContext()
1279 public LineMetrics getLineMetrics(String str, FontRenderContext frc)
1281 throw new UnsupportedOperationException(); // FIXME
1283 } // class Font