001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026: package com.sun.perseus.j2d;
027:
028: import com.sun.pisces.PathSink;
029: import com.sun.pisces.Transformer;
030:
031: /**
032: * @version $Id: TileSink.java,v 1.3 2006/04/21 06:35:41 st125089 Exp $
033: */
034: class TileSink extends PathSink {
035: /**
036: * The minimum x coordinate in S15.16 format.
037: */
038: protected int minX;
039:
040: /**
041: * The minimum y coordinate in S15.16 format.
042: */
043: protected int minY;
044:
045: /**
046: * The maximum x coordinate in S15.16 format.
047: */
048: protected int maxX;
049:
050: /**
051: * The maximum y coordinate in S15.16 format.
052: */
053: protected int maxY;
054:
055: /**
056: * Resets the bounds to their initial values.
057: */
058: public void reset() {
059: minX = Integer.MAX_VALUE;
060: minY = Integer.MAX_VALUE;
061: maxX = Integer.MIN_VALUE;
062: maxY = Integer.MIN_VALUE;
063: }
064:
065: /**
066: * Moves the current drawing position to the point <code>(x0,
067: * y0)</code>.
068: *
069: * @param x0 the X coordinate in S15.16 format
070: * @param y0 the Y coordinate in S15.16 format
071: */
072: public void moveTo(int x0, int y0) {
073: checkPoint(x0, y0);
074: }
075:
076: /**
077: * Checks whether this point falls within the current region. If not,
078: * adjusts minX, minY, maxX, maxY.
079: */
080: void checkPoint(final int x0, final int y0) {
081: if (x0 < minX) {
082: minX = x0;
083: } else if (x0 > maxX) {
084: maxX = x0;
085: }
086:
087: if (y0 < minY) {
088: minY = y0;
089: } else if (y0 > maxY) {
090: maxY = y0;
091: }
092: }
093:
094: /**
095: * Provides a hint that the current segment should be joined to
096: * the following segment using an explicit miter or round join if
097: * required.
098: *
099: * <p> An application-generated path will generally have no need
100: * to contain calls to this method; they are typically introduced
101: * by a <code>Flattener</code> to mark segment divisions that
102: * appear in its input, and consumed by a <code>Stroker</code>
103: * that is responsible for emitting the miter or round join
104: * segments.
105: *
106: * <p> Other <code>LineSink</code> classes should simply pass this
107: * hint to their output sink as needed.
108: */
109: public void lineJoin() {
110: }
111:
112: /**
113: * Draws a line from the current drawing position to the point
114: * <code>(x1, y1)</code> and sets the current drawing position to
115: * <code>(x1, y1)</code>.
116: *
117: * @param x1 the X coordinate in S15.16 format
118: * @param y1 the Y coordinate in S15.16 format
119: */
120: public void lineTo(int x1, int y1) {
121: checkPoint(x1, y1);
122: }
123:
124: /**
125: * Closes the current path by drawing a line from the current
126: * drawing position to the point specified by the moset recent
127: * <code>moveTo</code> command.
128: */
129: public void close() {
130: }
131:
132: /**
133: * Ends the current path. It may be necessary to end a path in
134: * order to allow end caps to be drawn.
135: */
136: public void end() {
137: }
138:
139: /**
140: * Draws a quadratic Bezier curve starting at the current drawing
141: * position and ending at the point <code>(x2, y2)</code>
142: * according to the formulas:
143: *
144: * <pre>
145: * x(t) = (1 - t)^2*x0 + 2*(1 - t)*t*x1 + t^2*x2
146: * y(t) = (1 - t)^2*y0 + 2*(1 - t)*t*y1 + t^2*x2
147: *
148: * 0 <= t <= 1
149: * </pre>
150: *
151: * where <code>(x0, y0)</code> is the current drawing position.
152: * Finally, the current drawing position is set to <code>(x2,
153: * y2)</code>.
154: *
155: * @param x1 the X coordinate of the control point in S15.16 format
156: * @param y1 the Y coordinate of the control point in S15.16 format
157: * @param x2 the final X coordinate in S15.16 format
158: * @param y2 the final Y coordinate in S15.16 format
159: */
160: public void quadTo(final int x1, final int y1, final int x2,
161: final int y2) {
162: checkPoint(x1, y1);
163: checkPoint(x2, y2);
164: }
165:
166: /**
167: * Draws a cubic Bezier curve starting at the current drawing
168: * position and ending at the point <code>(x3, y3)</code>
169: * according to the formulas:
170: *
171: * <pre>
172: * x(t) = (1 - t)^3*x0 + 3*(1 - t)^2*t*x1 + 3*(1 - t)*t^2*x2 + t^3*x3
173: * y(t) = (1 - t)^3*y0 + 3*(1 - t)^2*t*y1 + 3*(1 - t)*t^2*y2 + t^3*x3
174: *
175: * 0 <= t <= 1
176: * </pre>
177: *
178: * where <code>(x0, y0)</code> is the current drawing position.
179: * Finally, the current drawing position is set to <code>(x3,
180: * y3)</code>.
181: *
182: * @param x1 the X coordinate of the first control point in S15.16 format
183: * @param y1 the Y coordinate of the first control point in S15.16 format
184: * @param x2 the X coordinate of the second control point in S15.16 format
185: * @param y2 the Y coordinate of the second control point in S15.16 format
186: * @param x3 the final X coordinate in S15.16 format
187: * @param y3 the final Y coordinate in S15.16 format
188: */
189: public void cubicTo(final int x1, final int y1, final int x2,
190: final int y2, final int x3, final int y3) {
191: checkPoint(x1, y1);
192: checkPoint(x2, y2);
193: checkPoint(x3, y3);
194: }
195:
196: /**
197: * Sets the tile to the current values.
198: *
199: * @param tile the tile to set.
200: */
201: public void setTile(final Tile tile) {
202: tile.x = minX >> 16;
203: tile.y = minY >> 16;
204: tile.maxX = (maxX >> 16) - 1;
205: tile.maxY = (maxY >> 16) - 1;
206:
207: // Precision adjustments.
208:
209: // If x and y are positive, then, the int value for minX is
210: // smaller than or equal to the fixed point value, so there
211: // is no adjustment needed.
212:
213: // If x and y are netative, then, the int value for minX is
214: // greater than the fixed point value. We need to be at least
215: // as large as the bounds, so we decrease the value by one
216: // to encompass the origin.
217:
218: if (minX < 0 && (minX & 0xffff) != 0) {
219: tile.x -= 1;
220: }
221:
222: if (minY < 0 && (minX & 0xffff) != 0) {
223: tile.y -= 1;
224: }
225:
226: // If there is a fractional part in the maxX and maxY values,
227: // we adjust them to be at least as big as the rendering area.
228: if (maxX > 0 && (maxX & 0xffff) != 0) {
229: tile.maxX += 1;
230: }
231:
232: if (maxY > 0 && (maxY & 0xffff) != 0) {
233: tile.maxY += 1;
234: }
235:
236: }
237: }
|