1 /* 2 * Copyright (c) 1998, 2020, 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} 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} 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} methods of 37 * {@link java.awt.Font Font} take some text as an argument 38 * and return a {@code LineMetrics} 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 * Constructor for subclasses to call. 48 */ LineMetrics()49 protected LineMetrics() {} 50 51 /** 52 * Returns the number of characters ({@code char} values) in the text whose 53 * metrics are encapsulated by this {@code LineMetrics} 54 * object. 55 * @return the number of characters ({@code char} values) in the text with which 56 * this {@code LineMetrics} was created. 57 */ getNumChars()58 public abstract int getNumChars(); 59 60 /** 61 * Returns the ascent of the text. The ascent 62 * is the distance from the baseline 63 * to the ascender line. The ascent usually represents the 64 * the height of the capital letters of the text. Some characters 65 * can extend above the ascender line. 66 * @return the ascent of the text. 67 */ getAscent()68 public abstract float getAscent(); 69 70 /** 71 * Returns the descent of the text. The descent 72 * is the distance from the baseline 73 * to the descender line. The descent usually represents 74 * the distance to the bottom of lower case letters like 75 * 'p'. Some characters can extend below the descender 76 * line. 77 * @return the descent of the text. 78 */ getDescent()79 public abstract float getDescent(); 80 81 /** 82 * Returns the leading of the text. The 83 * leading is the recommended 84 * distance from the bottom of the descender line to the 85 * top of the next line. 86 * @return the leading of the text. 87 */ getLeading()88 public abstract float getLeading(); 89 90 /** 91 * Returns the height of the text. The 92 * height is equal to the sum of the ascent, the 93 * descent and the leading. 94 * @return the height of the text. 95 */ getHeight()96 public abstract float getHeight(); 97 98 /** 99 * Returns the baseline index of the text. 100 * The index is one of 101 * {@link java.awt.Font#ROMAN_BASELINE ROMAN_BASELINE}, 102 * {@link java.awt.Font#CENTER_BASELINE CENTER_BASELINE}, 103 * {@link java.awt.Font#HANGING_BASELINE HANGING_BASELINE}. 104 * @return the baseline of the text. 105 */ getBaselineIndex()106 public abstract int getBaselineIndex(); 107 108 /** 109 * Returns the baseline offsets of the text, 110 * relative to the baseline of the text. The 111 * offsets are indexed by baseline index. For 112 * example, if the baseline index is 113 * {@code CENTER_BASELINE} then 114 * {@code offsets[HANGING_BASELINE]} is usually 115 * negative, {@code offsets[CENTER_BASELINE]} 116 * is zero, and {@code offsets[ROMAN_BASELINE]} 117 * is usually positive. 118 * @return the baseline offsets of the text. 119 */ getBaselineOffsets()120 public abstract float[] getBaselineOffsets(); 121 122 /** 123 * Returns the position of the strike-through line 124 * relative to the baseline. 125 * @return the position of the strike-through line. 126 */ getStrikethroughOffset()127 public abstract float getStrikethroughOffset(); 128 129 /** 130 * Returns the thickness of the strike-through line. 131 * @return the thickness of the strike-through line. 132 */ getStrikethroughThickness()133 public abstract float getStrikethroughThickness(); 134 135 /** 136 * Returns the position of the underline relative to 137 * the baseline. 138 * @return the position of the underline. 139 */ getUnderlineOffset()140 public abstract float getUnderlineOffset(); 141 142 /** 143 * Returns the thickness of the underline. 144 * @return the thickness of the underline. 145 */ getUnderlineThickness()146 public abstract float getUnderlineThickness(); 147 } 148