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