1:
37:
38: package ;
39:
40: import ;
41:
42: import ;
43: import ;
44: import ;
45:
46:
47:
50: public final class Zone
51: {
52: private Point[] points;
53: private int numPoints;
54:
55: public double scaleX, scaleY, shearX, shearY;
56:
57: public Zone(int maxNumPoints)
58: {
59: points = new Point[maxNumPoints];
60: }
61:
62: public int getCapacity()
63: {
64: return points.length;
65: }
66:
67:
68: public int getSize()
69: {
70: return numPoints;
71: }
72:
73:
74: public int getX(int point)
75: {
76: return getX(point, FontDelegate.FLAG_FITTED);
77: }
78:
79: public int getX(int point, int flags)
80: {
81: int x;
82: if ((flags & FontDelegate.FLAG_FITTED) != 0)
83: x = points[point].x;
84: else
85: x = points[point].scaledX;
86: return x;
87: }
88:
89:
90: public void setX(int point, int value, boolean touch)
91: {
92: points[point].scaledX = value;
93: points[point].x = value;
94: if (touch)
95: points[point].flags |= Point.FLAG_TOUCHED_X;
96: }
97:
98:
99: public void setY(int point, int value, boolean touch)
100: {
101: points[point].scaledY = value;
102: points[point].y = value;
103: if (touch)
104: points[point].flags |= Point.FLAG_TOUCHED_Y;
105: }
106:
107: public int getY(int point)
108: {
109: return getY(point, FontDelegate.FLAG_FITTED);
110: }
111:
112: public int getY(int point, int flags)
113: {
114: int y;
115: if ((flags & FontDelegate.FLAG_FITTED) != 0)
116: y = points[point].y;
117: else
118: y = points[point].scaledY;
119: return y;
120: }
121:
122:
123: public int getOriginalX(int point)
124: {
125: return points[point].origX;
126: }
127:
128:
129: public int getOriginalY(int point)
130: {
131: return points[point].origY;
132: }
133:
134:
135: public void setOriginalX(int point, int x)
136: {
137: points[point].origX = x;
138: }
139:
140: public void setOriginalY(int point, int y)
141: {
142: points[point].origY = y;
143: }
144:
145: public void setNumPoints(int numPoints)
146: {
147: for (int i = 0; i < numPoints; i++)
148: points[i] = new Point();
149: this.numPoints = numPoints;
150: }
151:
152:
153: public boolean isOnCurve(int point)
154: {
155: return (points[point].flags & Point.FLAG_ON_CURVE) != 0;
156: }
157:
158:
159: public void setOnCurve(int point, boolean onCurve)
160: {
161: if (onCurve)
162: points[point].flags |= Point.FLAG_ON_CURVE;
163: else
164: points[point].flags &= ~Point.FLAG_ON_CURVE;
165: }
166:
167:
168: public boolean isContourEnd(int point)
169: {
170: return (points[point].flags & Point.FLAG_CONTOUR_END) != 0;
171: }
172:
173:
174: public void setContourEnd(int point, boolean segEnd)
175: {
176: if (segEnd)
177: points[point].flags |= Point.FLAG_CONTOUR_END;
178: else
179: points[point].flags &= ~Point.FLAG_CONTOUR_END;
180: }
181:
182:
183:
184:
185: void transform(double pointSize, AffineTransform deviceTransform,
186: int unitsPerEm, int preTranslateX, int preTranslateY)
187: {
188: double factor;
189:
190: factor = pointSize / (double) unitsPerEm;
191: scaleX = deviceTransform.getScaleX() * factor;
192: scaleY = deviceTransform.getScaleY() * factor;
193: shearX = deviceTransform.getShearX() * factor;
194: shearY = deviceTransform.getShearY() * factor;
195:
196: for (int i = 0; i < numPoints; i++)
197: {
198: int x = points[i].origX + preTranslateX;
199: int y = points[i].origY + preTranslateY;
200:
201: points[i].scaledX = points[i].x = Fixed.valueOf(scaleX * x
202: + shearX * y);
203: points[i].scaledY = points[i].y = Fixed.valueOf(shearY * x
204: + scaleY * y);
205: }
206: }
207:
208:
209:
210: void combineWithSubGlyph(Zone zone, int numPhantomPoints)
211: {
212: int offset = this.numPoints - numPhantomPoints;
213: int count = zone.numPoints;
214: System.arraycopy(zone.points, 0, this.points, offset, count);
215: this.numPoints += count - numPhantomPoints;
216: }
217:
218:
219: private void dump()
220: {
221: for (int i = 0; i < numPoints; i++)
222: {
223: System.out.print(" " + i + ": ");
224: System.out.print(Fixed.toString(points[i].scaledX, points[i].scaledY));
225: System.out.print(' ');
226: System.out.print(Fixed.toString(points[i].origX, points[i].origY));
227: System.out.print(' ');
228: if (isOnCurve(i))
229: System.out.print('.');
230: else
231: System.out.print('c');
232: if (isContourEnd(i))
233: System.out.print('E');
234: System.out.println();
235: if (isContourEnd(i))
236: System.out.println();
237: }
238: }
239:
240:
241: public PathIterator getPathIterator(int type)
242: {
243: return new ZonePathIterator(this, type);
244: }
245:
246:
247: public GeneralPath getPath(int type)
248: {
249: GeneralPath p = new GeneralPath(GeneralPath.WIND_NON_ZERO, numPoints);
250: p.append(getPathIterator(type), false);
251: return p;
252: }
253:
254:
259: public int getNumContours()
260: {
261: int num = 0;
262: for (int i = 0; i < numPoints; i++)
263: {
264: if (isContourEnd(i))
265: num++;
266: }
267: return num;
268: }
269:
270: public int getContourEnd(int n)
271: {
272: int idx = -1;
273: int num = 0;
274: for (int i = 0; i < numPoints; i++)
275: {
276: if (isContourEnd(i))
277: {
278: idx = i;
279: if (num == n)
280: break;
281: num++;
282: }
283: }
284: return idx;
285: }
286:
287: public Point[] getPoints()
288: {
289: return points;
290: }
291: }