1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17/**
18 * @author Ilya S. Okomin
19 * @version $Revision$
20 */
21package org.apache.harmony.awt.gl.font;
22
23import java.awt.font.FontRenderContext;
24import org.apache.harmony.awt.gl.font.LineMetricsImpl;
25
26
27/**
28 *
29 * Linux implementation of LineMetrics class
30 */
31public class AndroidLineMetrics extends LineMetricsImpl {
32
33    /**
34     * Constructor
35     */
36    public AndroidLineMetrics(    AndroidFont fnt,
37                                FontRenderContext frc,
38                                String str){
39        numChars = str.length();
40        baseLineIndex = 0;
41
42        ascent = fnt.ascent;    // Ascent of the font
43        descent = -fnt.descent;  // Descent of the font
44        leading = fnt.leading;  // External leading
45
46        height = ascent + descent + leading;    // Height of the font ( == (ascent + descent + leading))
47        underlineThickness = 0.0f;
48        underlineOffset = 0.0f;
49        strikethroughThickness = 0.0f;
50        strikethroughOffset = 0.0f;
51        maxCharWidth = 0.0f;
52
53        //    TODO: Find out pixel metrics
54        /*
55         * positive metrics rounded to the smallest int that is bigger than value
56         * negative metrics rounded to the smallest int that is lesser than value
57         * thicknesses rounded to int ((int)round(value + 0.5))
58         *
59         */
60
61        lAscent = (int)Math.ceil(fnt.ascent);//   // Ascent of the font
62        lDescent = -(int)Math.ceil(fnt.descent);// Descent of the font
63        lLeading = (int)Math.ceil(leading);  // External leading
64
65        lHeight = lAscent + lDescent + lLeading;    // Height of the font ( == (ascent + descent + leading))
66
67        lUnderlineThickness = Math.round(underlineThickness);//(int)metrics[11];
68
69        if (underlineOffset >= 0){
70            lUnderlineOffset = (int)Math.ceil(underlineOffset);
71        } else {
72            lUnderlineOffset = (int)Math.floor(underlineOffset);
73        }
74
75        lStrikethroughThickness = Math.round(strikethroughThickness); //(int)metrics[13];
76
77        if (strikethroughOffset >= 0){
78            lStrikethroughOffset = (int)Math.ceil(strikethroughOffset);
79        } else {
80            lStrikethroughOffset = (int)Math.floor(strikethroughOffset);
81        }
82
83        lMaxCharWidth = (int)Math.ceil(maxCharWidth); //(int)metrics[15];
84        units_per_EM = 0;
85
86    }
87
88    public float[] getBaselineOffsets() {
89        // TODO: implement baseline offsets for TrueType fonts
90        if (baselineOffsets == null){
91            float[] baselineData = null;
92
93            // Temporary workaround:
94            // Commented out native data initialization, since it can
95            // cause failures with opening files in multithreaded applications.
96            //
97            // TODO: support work with truetype data in multithreaded
98            // applications.
99
100            // If font TrueType data is taken from BASE table
101//            if ((this.font.getFontHandle() != 0) && (font.getFontType() == FontManager.FONT_TYPE_TT)){
102//                baselineData = LinuxNativeFont.getBaselineOffsetsNative(font.getFontHandle(), font.getSize(), ascent, descent, units_per_EM);
103//            }
104//
105                baseLineIndex = 0;
106                baselineOffsets = new float[]{0, (-ascent+descent)/2, -ascent};
107        }
108
109        return baselineOffsets;
110    }
111
112    public int getBaselineIndex() {
113        if (baselineOffsets == null){
114            // get offsets and set correct index
115            getBaselineOffsets();
116        }
117        return baseLineIndex;
118    }
119
120}
121