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.geom.GeneralPath;
021: import java.awt.geom.PathIterator;
022: import java.util.NoSuchElementException;
023:
024: import org.apache.harmony.awt.internal.nls.Messages;
025:
026: final public class FLPath implements PathIterator {
027:
028: /**
029: * The space amount in points buffer for different segmenet's types
030: */
031: /*private static int pointShift[] = {
032: 0, // CLOSE
033: 2, // LINETO
034: 2, // MOVETO
035: 6, // CUBICTO
036: 4}; // QUADTO*/
037:
038: //General path
039: static int pointShift[] = { 2, // MOVETO
040: 2, // LINETO
041: 4, // QUADTO
042: 6, // CUBICTO
043: 0 }; // CLOSE
044:
045: /**
046: * The current cursor position in types buffer
047: */
048: int commandsIndex;
049:
050: /**
051: * The current cursor position in points buffer
052: */
053: int pointIndex = 0;
054:
055: private int size;
056:
057: private final FLOutline outline = new FLOutline();
058:
059: FLPath(long glyphPointer) {
060: getShape(outline, glyphPointer);
061:
062: size = outline.commands.length;
063: }
064:
065: public int getWindingRule() {
066: return PathIterator.WIND_EVEN_ODD;
067: }
068:
069: public boolean isDone() {
070: return commandsIndex >= size;
071: }
072:
073: public void next() {
074: commandsIndex++;
075: }
076:
077: public int currentSegment(double[] coords) {
078: if (isDone()) {
079: // awt.4B=Iterator out of bounds
080: throw new NoSuchElementException(Messages
081: .getString("awt.4B")); //$NON-NLS-1$
082: }
083: int type = outline.commands[commandsIndex];
084: int count = pointShift[type];
085: for (int i = 0; i < count; i++) {
086: coords[i] = outline.points[pointIndex + i];
087: }
088: pointIndex += count;
089: return type;
090: }
091:
092: public int currentSegment(float[] coords) {
093: if (isDone()) {
094: // awt.4B=Iterator out of bounds
095: throw new NoSuchElementException(Messages
096: .getString("awt.4B")); //$NON-NLS-1$
097: }
098:
099: int type = outline.commands[commandsIndex];
100: int count = pointShift[type];
101:
102: System.arraycopy(outline.points, pointIndex, coords, 0, count);
103: pointIndex += count;
104: return type;
105: }
106:
107: Shape getShape() {
108: GeneralPath gp = new GeneralPath();
109:
110: gp.append(this , false);
111:
112: return gp;
113: }
114:
115: private native void getShape(FLOutline outline, long glyphPointer);
116: }
|