View Javadoc
1   /*
2    * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.  Oracle designates this
8    * particular file as subject to the "Classpath" exception as provided
9    * by Oracle in the LICENSE file that accompanied this code.
10   *
11   * This code is distributed in the hope that it will be useful, but WITHOUT
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   * version 2 for more details (a copy is included in the LICENSE file that
15   * accompanied this code).
16   *
17   * You should have received a copy of the GNU General Public License version
18   * 2 along with this work; if not, write to the Free Software Foundation,
19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20   *
21   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22   * or visit www.oracle.com if you need additional information or have any
23   * questions.
24   */
25  
26  package java.awt.font;
27  
28  /**
29  * The <code>LineMetrics</code> class allows access to the
30  * metrics needed to layout characters along a line
31  * and to layout of a set of lines.  A <code>LineMetrics</code>
32  * object encapsulates the measurement information associated
33  * with a run of text.
34  * <p>
35  * Fonts can have different metrics for different ranges of
36  * characters.  The <code>getLineMetrics</code> methods of
37  * {@link java.awt.Font Font} take some text as an argument
38  * and return a <code>LineMetrics</code> object describing the
39  * metrics of the initial number of characters in that text, as
40  * returned by {@link #getNumChars}.
41  */
42  
43  
44  public abstract class LineMetrics {
45  
46  
47      /**
48       * Returns the number of characters (<code>char</code> values) in the text whose
49       * metrics are encapsulated by this <code>LineMetrics</code>
50       * object.
51       * @return the number of characters (<code>char</code> values) in the text with which
52       *         this <code>LineMetrics</code> was created.
53       */
54      public abstract int getNumChars();
55  
56      /**
57       * Returns the ascent of the text.  The ascent
58       * is the distance from the baseline
59       * to the ascender line.  The ascent usually represents the
60       * the height of the capital letters of the text.  Some characters
61       * can extend above the ascender line.
62       * @return the ascent of the text.
63       */
64      public abstract float getAscent();
65  
66      /**
67       * Returns the descent of the text.  The descent
68       * is the distance from the baseline
69       * to the descender line.  The descent usually represents
70       * the distance to the bottom of lower case letters like
71       * 'p'.  Some characters can extend below the descender
72       * line.
73       * @return the descent of the text.
74       */
75      public abstract float getDescent();
76  
77      /**
78       * Returns the leading of the text. The
79       * leading is the recommended
80       * distance from the bottom of the descender line to the
81       * top of the next line.
82       * @return the leading of the text.
83       */
84      public abstract float getLeading();
85  
86      /**
87       * Returns the height of the text.  The
88       * height is equal to the sum of the ascent, the
89       * descent and the leading.
90       * @return the height of the text.
91       */
92      public abstract float getHeight();
93  
94      /**
95       * Returns the baseline index of the text.
96       * The index is one of
97       * {@link java.awt.Font#ROMAN_BASELINE ROMAN_BASELINE},
98       * {@link java.awt.Font#CENTER_BASELINE CENTER_BASELINE},
99       * {@link java.awt.Font#HANGING_BASELINE HANGING_BASELINE}.
100      * @return the baseline of the text.
101      */
102     public abstract int getBaselineIndex();
103 
104     /**
105      * Returns the baseline offsets of the text,
106      * relative to the baseline of the text.  The
107      * offsets are indexed by baseline index.  For
108      * example, if the baseline index is
109      * <code>CENTER_BASELINE</code> then
110      * <code>offsets[HANGING_BASELINE]</code> is usually
111      * negative, <code>offsets[CENTER_BASELINE]</code>
112      * is zero, and <code>offsets[ROMAN_BASELINE]</code>
113      * is usually positive.
114      * @return the baseline offsets of the text.
115      */
116     public abstract float[] getBaselineOffsets();
117 
118     /**
119      * Returns the position of the strike-through line
120      * relative to the baseline.
121      * @return the position of the strike-through line.
122      */
123     public abstract float getStrikethroughOffset();
124 
125     /**
126      * Returns the thickness of the strike-through line.
127      * @return the thickness of the strike-through line.
128      */
129     public abstract float getStrikethroughThickness();
130 
131     /**
132      * Returns the position of the underline relative to
133      * the baseline.
134      * @return the position of the underline.
135      */
136     public abstract float getUnderlineOffset();
137 
138     /**
139      * Returns the thickness of the underline.
140      * @return the thickness of the underline.
141      */
142     public abstract float getUnderlineThickness();
143 }