001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Oleg V. Khaschansky
019: * @version $Revision$
020: *
021: */package org.apache.harmony.awt.gl.font;
022:
023: import java.awt.font.LineMetrics;
024: import java.awt.font.GraphicAttribute;
025: import java.awt.*;
026:
027: /**
028: * Date: May 14, 2005
029: * Time: 7:44:13 PM
030: *
031: * This class incapsulates text metrics specific for the text layout or
032: * for the separate text segment. Text segment is a text run with the constant direction
033: * and attributes like font, decorations, etc. BasicMetrics is also used to store
034: * calculated text metrics like advance, ascent or descent. this class is very similar to
035: * LineMetrics, but provides some additional info, constructors and is more transparent.
036: */
037: public class BasicMetrics {
038: int baseLineIndex;
039:
040: float ascent; // Ascent of the font
041: float descent; // Descent of the font
042: float leading; // External leading
043: float advance;
044:
045: float italicAngle;
046: float super ScriptOffset;
047:
048: float underlineOffset;
049: float underlineThickness;
050:
051: float strikethroughOffset;
052: float strikethroughThickness;
053:
054: /**
055: * Constructs BasicMetrics from LineMetrics and font
056: * @param lm
057: * @param font
058: */
059: BasicMetrics(LineMetrics lm, Font font) {
060: ascent = lm.getAscent();
061: descent = lm.getDescent();
062: leading = lm.getLeading();
063:
064: underlineOffset = lm.getUnderlineOffset();
065: underlineThickness = lm.getUnderlineThickness();
066:
067: strikethroughOffset = lm.getStrikethroughOffset();
068: strikethroughThickness = lm.getStrikethroughThickness();
069:
070: baseLineIndex = lm.getBaselineIndex();
071:
072: italicAngle = font.getItalicAngle();
073: super ScriptOffset = (float) font.getTransform().getTranslateY();
074: }
075:
076: /**
077: * Constructs BasicMetrics from GraphicAttribute.
078: * It gets ascent and descent from the graphic attribute and
079: * computes reasonable defaults for other metrics.
080: * @param ga - graphic attribute
081: */
082: BasicMetrics(GraphicAttribute ga) {
083: ascent = ga.getAscent();
084: descent = ga.getDescent();
085: leading = 2;
086:
087: baseLineIndex = ga.getAlignment();
088:
089: italicAngle = 0;
090: super ScriptOffset = 0;
091:
092: underlineOffset = Math.max(descent / 2, 1);
093:
094: // Just suggested, should be cap_stem_width or something like that
095: underlineThickness = Math.max(ascent / 13, 1);
096:
097: strikethroughOffset = -ascent / 2; // Something like middle of the line
098: strikethroughThickness = underlineThickness;
099: }
100:
101: /**
102: * Copies metrics from the TextMetricsCalculator object.
103: * @param tmc - TextMetricsCalculator object
104: */
105: BasicMetrics(TextMetricsCalculator tmc) {
106: ascent = tmc.ascent;
107: descent = tmc.descent;
108: leading = tmc.leading;
109: advance = tmc.advance;
110: baseLineIndex = tmc.baselineIndex;
111: }
112:
113: public float getAscent() {
114: return ascent;
115: }
116:
117: public float getDescent() {
118: return descent;
119: }
120:
121: public float getLeading() {
122: return leading;
123: }
124:
125: public float getAdvance() {
126: return advance;
127: }
128:
129: public int getBaseLineIndex() {
130: return baseLineIndex;
131: }
132: }
|