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: package org.apache.harmony.awt.gl.font.fontlib;
018:
019: import java.awt.Shape;
020: import java.awt.font.GlyphMetrics;
021:
022: import org.apache.harmony.awt.gl.font.Glyph;
023:
024: final public class FLGlyph extends Glyph {
025:
026: private long glyphPointer;
027:
028: // private static final JavaShapeRasterizer jsr = new JavaShapeRasterizer();
029:
030: //this.glMetrics = new GlyphMetrics((float)Math.ceil(metrics[2]), rect, (byte)0);
031: /*
032: values[0] = - extents.x ; // Glyph Pixels Bounds : X
033: values[1] = extents.y ; // Glyph Pixels Bounds : Y
034: values[2] = extents.xOff; // Pixels AdvanceX
035: values[3] = extents.yOff; // Pixels AdvanceY ?= Ascent+Descent
036: values[4] = acbox.xMax-acbox.xMin; // Glyph Pixels Bounds : width
037: values[5] = acbox.yMax-acbox.yMin; // Glyph Pixels Bounds : height
038: */
039:
040: FLGlyph(char c, long fontPeerPointer, int size) {
041: // System.out.println("create glyph char " + (new Integer(c)).intValue() + " " + c + " size " + size + " pfont " + fontPeerPointer);
042:
043: glChar = c;
044: glyphPointer = initGlyph(c, size, fontPeerPointer);
045: }
046:
047: @Override
048: public byte[] getBitmap() {
049: /*MultiRectArea mra = jsr.rasterize(initOutline(), 0.5);
050:
051: Rectangle rec = mra.getBounds();
052: int w = rec.width;
053: int h = rec.height;
054:
055: System.out.println(" " + w + " " + h);
056: if(w <= 0 || h <= 0) {
057: return null;
058: }
059:
060: BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
061:
062: ((Graphics2D)bim.getGraphics()).draw(mra);
063:
064: // bim.getRaster().
065:
066:
067: int dbufferLength = w * h;
068:
069: DataBufferByte dbuffer = new DataBufferByte(dbufferLength);
070:
071: WritableRaster scanRaster = Raster.createInterleavedRaster(dbuffer, w, h, w, 1,new int[]{0}, null);
072:
073: /*WritableRaster scanRaster = Raster.createPackedRaster(
074: dbuffer,
075: (dbufferLength / h) << 3,
076: h,
077: 1,
078: null
079: );*
080:
081: scanRaster.setRect(bim.getRaster());*/
082:
083: // return dbuffer.getData();
084: return null;
085: }
086:
087: public Shape initOutline() {
088: if (glOutline == null) {
089: FLPath path = new FLPath(glyphPointer);
090: glOutline = path.getShape();
091: }
092:
093: return glOutline;
094: }
095:
096: @Override
097: public Shape initOutline(char arg0) {
098: return initOutline();
099: }
100:
101: public GlyphMetrics getGlyphMetrics() {
102: if (glMetrics == null) {
103: //System.out.println("getGlyphMetrics");
104: float[] metrics = getGlyphMetrics(glyphPointer);
105:
106: // System.out.println("x = " + metrics[0] + ", y = " + metrics[1]);
107: // System.out.println("after x = " + Math.round(metrics[0]) + ", y = " + Math.round(metrics[1]));
108:
109: this .glMetrics = new GlyphMetrics(true, Math
110: .round(metrics[0]),//metrics[0],
111: Math.round(metrics[1]),//metrics[1],
112: //new Rectangle2D.Double(initOutline().getBounds2D().getMinX(), initOutline().getBounds2D().getMinY(), initOutline().getBounds2D().getMaxX() + 5, initOutline().getBounds2D().getMaxY()),
113: initOutline().getBounds2D(),//new Rectangle2D.Float(metrics[2], -metrics[5]-1,metrics[4]- metrics[2] + 1, metrics[5] - metrics[3] + 1),
114: GlyphMetrics.STANDARD);
115:
116: /*System.out.println("GlyphMetrics length " + metrics.length + " glyph " + new Integer(glChar));
117: for (int i = 0; i < metrics.length; i ++) {
118: System.out.println(metrics[i]);
119: }*/
120: }
121:
122: return glMetrics;
123: }
124:
125: public GlyphMetrics getGlyphPointMetrics() {
126: //System.out.println("getGlyphPointMetrics");
127: return glPointMetrics = getGlyphMetrics();
128: }
129:
130: private native float[] getGlyphMetrics(long glyphPointer);
131:
132: private native long initGlyph(char c, int size, long fontPeerPointer);
133: }
|