1 /*
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3  *
4  * This code is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 only, as
6  * published by the Free Software Foundation.  Oracle designates this
7  * particular file as subject to the "Classpath" exception as provided
8  * by Oracle in the LICENSE file that accompanied this code.
9  *
10  * This code is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * version 2 for more details (a copy is included in the LICENSE file that
14  * accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License version
17  * 2 along with this work; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21  * or visit www.oracle.com if you need additional information or have any
22  * questions.
23  *
24  */
25 
26 /*
27  *
28  * (C) Copyright IBM Corp. 2003, All Rights Reserved
29  *
30  */
31 
32 package sun.font;
33 
34 import java.awt.font.LineMetrics;
35 import java.awt.font.GraphicAttribute;
36 
37 public final class CoreMetrics {
38 
CoreMetrics(float ascent, float descent, float leading, float height, int baselineIndex, float[] baselineOffsets, float strikethroughOffset, float strikethroughThickness, float underlineOffset, float underlineThickness, float ssOffset, float italicAngle)39     public CoreMetrics(float ascent,
40                        float descent,
41                        float leading,
42                        float height,
43                        int baselineIndex,
44                        float[] baselineOffsets,
45                        float strikethroughOffset,
46                        float strikethroughThickness,
47                        float underlineOffset,
48                        float underlineThickness,
49                        float ssOffset,
50                        float italicAngle) {
51         this.ascent = ascent;
52         this.descent = descent;
53         this.leading = leading;
54         this.height = height;
55         this.baselineIndex = baselineIndex;
56         this.baselineOffsets = baselineOffsets;
57         this.strikethroughOffset = strikethroughOffset;
58         this.strikethroughThickness = strikethroughThickness;
59         this.underlineOffset = underlineOffset;
60         this.underlineThickness = underlineThickness;
61         this.ssOffset = ssOffset;
62         this.italicAngle = italicAngle;
63     }
64 
get(LineMetrics lm)65     public static CoreMetrics get(LineMetrics lm) {
66         return ((FontLineMetrics)lm).cm;
67     }
68 
hashCode()69     public final int hashCode() {
70         return Float.floatToIntBits(ascent + ssOffset);
71     }
72 
equals(Object rhs)73     public final boolean equals(Object rhs) {
74         try {
75             return equals((CoreMetrics)rhs);
76         }
77         catch(ClassCastException e) {
78             return false;
79         }
80     }
81 
equals(CoreMetrics rhs)82     public final boolean equals(CoreMetrics rhs) {
83         if (rhs != null) {
84             if (this == rhs) {
85                 return true;
86             }
87 
88             return ascent == rhs.ascent
89                 && descent == rhs.descent
90                 && leading == rhs.leading
91                 && baselineIndex == rhs.baselineIndex
92                 && baselineOffsets[0] == rhs.baselineOffsets[0]
93                 && baselineOffsets[1] == rhs.baselineOffsets[1]
94                 && baselineOffsets[2] == rhs.baselineOffsets[2]
95                 && strikethroughOffset == rhs.strikethroughOffset
96                 && strikethroughThickness == rhs.strikethroughThickness
97                 && underlineOffset == rhs.underlineOffset
98                 && underlineThickness == rhs.underlineThickness
99                 && ssOffset == rhs.ssOffset
100                 && italicAngle == rhs.italicAngle;
101         }
102         return false;
103     }
104 
105     // fullOffsets is an array of 5 baseline offsets,
106     // roman, center, hanging, bottom, and top in that order
107     // this does NOT add the ssOffset
effectiveBaselineOffset(float[] fullOffsets)108     public final float effectiveBaselineOffset(float[] fullOffsets) {
109         switch (baselineIndex) {
110         case GraphicAttribute.TOP_ALIGNMENT:
111             return fullOffsets[4] + ascent;
112         case GraphicAttribute.BOTTOM_ALIGNMENT:
113             return fullOffsets[3] - descent;
114         default:
115             return fullOffsets[baselineIndex];
116         }
117     }
118 
119     public final float   ascent;
120     public final float   descent;
121     public final float   leading;
122     public final float   height;
123     public final int     baselineIndex;
124     public final float[] baselineOffsets; // !! this is a hole, don't expose this class
125     public final float   strikethroughOffset;
126     public final float   strikethroughThickness;
127     public final float   underlineOffset;
128     public final float   underlineThickness;
129     public final float   ssOffset;
130     public final float   italicAngle;
131 }
132