1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.apache.harmony.awt.gl.font;
18
19import com.android.internal.awt.AndroidGraphics2D;
20
21import java.awt.Font;
22import java.awt.Shape;
23import java.awt.font.FontRenderContext;
24import java.awt.font.GlyphJustificationInfo;
25import java.awt.font.GlyphMetrics;
26import java.awt.font.GlyphVector;
27import java.awt.geom.AffineTransform;
28import java.awt.geom.Point2D;
29import java.awt.geom.Rectangle2D;
30
31import android.util.Log;
32import android.graphics.Path;
33
34public class AndroidGlyphVector extends GlyphVector {
35
36    // array of chars defined in constructor
37    public char[] charVector;
38
39    // array of Glyph objects, that describe information about glyphs
40    public Glyph[] vector;
41
42    // array of default positions of glyphs in GlyphVector
43    // without applying GlyphVector's transform
44    float[] defaultPositions;
45
46    // array of logical positions of glyphs in GlyphVector
47
48    float[] logicalPositions;
49
50    // array of visual (real) positions of glyphs in GlyphVector
51    public float[] visualPositions;
52
53    // FontRenderContext for this vector.
54    protected FontRenderContext vectorFRC;
55
56    // layout flags mask
57    protected int layoutFlags = 0;
58
59    // array of cached glyph outlines
60    protected Shape[] gvShapes;
61
62    FontPeerImpl peer;
63
64    // font corresponding to the GlyphVector
65    Font font;
66
67    // ascent of the font
68    float ascent;
69
70    // height of the font
71    float height;
72
73    // leading of the font
74    float leading;
75
76    // descent of the font
77    float descent;
78
79    // transform of the GlyphVector
80    AffineTransform transform;
81
82    @SuppressWarnings("deprecation")
83    public AndroidGlyphVector(char[] chars, FontRenderContext frc, Font fnt,
84            int flags) {
85        int len = chars.length;
86        this.font = fnt;
87        LineMetricsImpl lmImpl = (LineMetricsImpl)fnt.getLineMetrics(String.valueOf(chars), frc);
88        this.ascent = lmImpl.getAscent();
89        this.height = lmImpl.getHeight();
90        this.leading = lmImpl.getLeading();
91        this.descent = lmImpl.getDescent();
92        this.charVector = chars;
93        this.vectorFRC = frc;
94    }
95
96    public AndroidGlyphVector(char[] chars, FontRenderContext frc, Font fnt) {
97        this(chars, frc, fnt, 0);
98    }
99
100    public AndroidGlyphVector(String str, FontRenderContext frc, Font fnt) {
101        this(str.toCharArray(), frc, fnt, 0);
102    }
103
104    public AndroidGlyphVector(String str, FontRenderContext frc, Font fnt, int flags) {
105        this(str.toCharArray(), frc, fnt, flags);
106    }
107
108	@Override
109	public boolean equals(GlyphVector glyphVector) {
110		return false;
111	}
112
113	public char[] getGlyphs() {
114		return this.charVector;
115	}
116
117	@Override
118	public Font getFont() {
119		return this.font;
120	}
121
122	@Override
123	public FontRenderContext getFontRenderContext() {
124		return this.vectorFRC;
125	}
126
127	@Override
128	public int getGlyphCode(int glyphIndex) {
129		return charVector[glyphIndex];
130	}
131
132	@Override
133	public int[] getGlyphCodes(int beginGlyphIndex, int numEntries,
134			int[] codeReturn) {
135		throw new RuntimeException("Not implemented!");
136	}
137
138	@Override
139	public GlyphJustificationInfo getGlyphJustificationInfo(int glyphIndex) {
140		throw new RuntimeException("Not implemented!");
141	}
142
143	@Override
144	public Shape getGlyphLogicalBounds(int glyphIndex) {
145		throw new RuntimeException("Not implemented!");
146	}
147
148	@Override
149	public GlyphMetrics getGlyphMetrics(int glyphIndex) {
150		throw new RuntimeException("Not implemented!");
151	}
152
153	public Path getAndroidGlyphOutline(int glyphIndex) {
154		AndroidGraphics2D g = AndroidGraphics2D.getInstance();
155        Path path = new Path();
156        char tmp[] = new char[1];
157        tmp[0] = charVector[glyphIndex];
158        ((AndroidGraphics2D)g).getAndroidPaint().getTextPath(new String(tmp), 0, 1, 0, 0, path);
159        return path;
160	}
161
162	@Override
163	public Shape getGlyphOutline(int glyphIndex) {
164		throw new RuntimeException("Not implemented!");
165	}
166
167	@Override
168	public Point2D getGlyphPosition(int glyphIndex) {
169		throw new RuntimeException("Not implemented!");
170	}
171
172	@Override
173	public float[] getGlyphPositions(int beginGlyphIndex, int numEntries,
174			float[] positionReturn) {
175		throw new RuntimeException("Not implemented!");
176	}
177
178	@Override
179	public AffineTransform getGlyphTransform(int glyphIndex) {
180		throw new RuntimeException("Not implemented!");
181	}
182
183	@Override
184	public Shape getGlyphVisualBounds(int glyphIndex) {
185		throw new RuntimeException("Not implemented!");
186	}
187
188	@Override
189	public Rectangle2D getLogicalBounds() {
190		throw new RuntimeException("Not implemented!");
191	}
192
193	@Override
194	public int getNumGlyphs() {
195		return charVector.length;
196	}
197
198	@Override
199	public Shape getOutline(float x, float y) {
200		throw new RuntimeException("Not implemented!");
201	}
202
203	@Override
204	public Shape getOutline() {
205		throw new RuntimeException("Not implemented!");
206	}
207
208	public Path getAndroidOutline() {
209		AndroidGraphics2D g = AndroidGraphics2D.getInstance();
210        Path path = new Path();
211        ((AndroidGraphics2D)g).getAndroidPaint().getTextPath(new String(charVector), 0, charVector.length, 0, 0, path);
212        return path;
213	}
214
215	@Override
216	public Rectangle2D getVisualBounds() {
217		throw new RuntimeException("Not implemented!");
218	}
219
220	@Override
221	public void performDefaultLayout() {
222		throw new RuntimeException("Not implemented!");
223	}
224
225	@Override
226	public void setGlyphPosition(int glyphIndex, Point2D newPos) {
227		throw new RuntimeException("Not implemented!");
228	}
229
230	@Override
231	public void setGlyphTransform(int glyphIndex, AffineTransform trans) {
232		throw new RuntimeException("Not implemented!");
233	}
234
235}
236