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 Ilya S. Okomin
019: * @version $Revision$
020: */package org.apache.harmony.awt.gl.font;
021:
022: import java.awt.font.FontRenderContext;
023:
024: import org.apache.harmony.awt.gl.font.LineMetricsImpl;
025:
026: /**
027: *
028: * Linux implementation of LineMetrics class
029: */
030: public class LinuxLineMetrics extends LineMetricsImpl {
031:
032: // LinuxFont corresponding to this LineMetrics object
033: private LinuxFont font = null;
034:
035: /**
036: * Constructor
037: */
038: public LinuxLineMetrics(LinuxFont fnt, String str) {
039:
040: float[] metrics = LinuxNativeFont.getNativeLineMetrics(fnt
041: .getFontHandle(), fnt.getSize(), false, false,
042: fnt.fontType);
043:
044: if (metrics == null) {
045: metrics = new float[17];
046: }
047:
048: font = fnt;
049: numChars = str.length();
050: baseLineIndex = 0;
051:
052: ascent = metrics[0]; // Ascent of the font
053: descent = -metrics[1]; // Descent of the font
054: leading = metrics[2]; // External leading
055:
056: height = ascent + descent + leading; // Height of the font ( == (ascent + descent + leading))
057: underlineThickness = metrics[3];
058: underlineOffset = -metrics[4];
059: strikethroughThickness = metrics[5];
060: strikethroughOffset = -metrics[6];
061: maxCharWidth = metrics[7];
062:
063: // TODO: Find out pixel metrics
064: /*
065: * positive metrics rounded to the smallest int that is bigger than value
066: * negative metrics rounded to the smallest int that is lesser than value
067: * thicknesses rounded to int ((int)round(value + 0.5))
068: *
069: */
070:
071: lAscent = (int) metrics[8];//(int)Math.ceil(ascent);// // Ascent of the font
072: lDescent = -(int) metrics[9]; //(int)Math.ceil(descent);// Descent of the font
073: lLeading = (int) metrics[10];//(int)Math.ceil(leading); // External leading
074:
075: lHeight = lAscent + lDescent + lLeading; // Height of the font ( == (ascent + descent + leading))
076:
077: lUnderlineThickness = Math.round(underlineThickness);//(int)metrics[11];
078:
079: if (underlineOffset >= 0) {
080: lUnderlineOffset = (int) Math.ceil(underlineOffset);
081: } else {
082: lUnderlineOffset = (int) Math.floor(underlineOffset);
083: }
084:
085: lStrikethroughThickness = Math.round(strikethroughThickness); //(int)metrics[13];
086:
087: if (strikethroughOffset >= 0) {
088: lStrikethroughOffset = (int) Math.ceil(strikethroughOffset);
089: } else {
090: lStrikethroughOffset = (int) Math
091: .floor(strikethroughOffset);
092: }
093:
094: lMaxCharWidth = (int) Math.ceil(maxCharWidth); //(int)metrics[15];
095: units_per_EM = (int) metrics[16];
096:
097: }
098:
099: public float[] getBaselineOffsets() {
100: // TODO: implement baseline offsets for TrueType fonts
101: if (baselineOffsets == null) {
102: float[] baselineData = null;
103:
104: // Temporary workaround:
105: // Commented out native data initialization, since it can
106: // cause failures with opening files in multithreaded applications.
107: //
108: // TODO: support work with truetype data in multithreaded
109: // applications.
110:
111: // If font TrueType data is taken from BASE table
112: // if ((this.font.getFontHandle() != 0) && (font.getFontType() == FontManager.FONT_TYPE_TT)){
113: // baselineData = LinuxNativeFont.getBaselineOffsetsNative(font.getFontHandle(), font.getSize(), ascent, descent, units_per_EM);
114: // }
115: //
116: // if (baselineData == null){
117: baseLineIndex = 0;
118: baselineOffsets = new float[] { 0, (-ascent + descent) / 2,
119: -ascent };
120: // } else {
121: // baseLineIndex = (int)baselineData[3];
122: // baselineOffsets = new float[3];
123: // System.arraycopy(baselineData, 0, baselineOffsets, 0, 3);
124: // }
125:
126: }
127:
128: return baselineOffsets;
129: }
130:
131: public int getBaselineIndex() {
132: if (baselineOffsets == null) {
133: // get offsets and set correct index
134: getBaselineOffsets();
135: }
136: return baseLineIndex;
137: }
138:
139: }
|