1 /*
2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
213 synchronized (arcToShape) {
214 arcToShape.setArc(x, y, width, height, startAngle, arcAngle, type);
215 drawfillShape(sg2d, sg2d.stroke.createStrokedShape(arcToShape), true, true);
216 }
217 }
218 }
219
220 public void fillArc(SunGraphics2D sg2d, int x, int y, int width, int height, int startAngle, int arcAngle) {
221 fillArc(sg2d, x, y, width, height, startAngle, arcAngle, Arc2D.PIE);
222 }
223
224 public void fillArc(SunGraphics2D sg2d, float x, float y, float width, float height, float startAngle, float arcAngle, int type) {
225 if ((width < 0) || (height < 0)) return;
226
227 OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
228 surfaceData.doArc(this, sg2d, x, y, width, height, startAngle, arcAngle, type, true);
229 }
230
231 native void doPoly(SurfaceData sData, int[] xpoints, int[] ypoints, int npoints, boolean ispolygon, boolean isfill);
232
233 public void drawPolyline(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
234 OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
235 if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
236 surfaceData.doPolygon(this, sg2d, xpoints, ypoints, npoints, false, false);
237 } else {
238 GeneralPath polyToShape = new GeneralPath();
239 polyToShape.moveTo(xpoints[0], ypoints[0]);
240 for (int i = 1; i < npoints; i++) {
241 polyToShape.lineTo(xpoints[i], ypoints[i]);
242 }
243 drawfillShape(sg2d, sg2d.stroke.createStrokedShape(polyToShape), true, true);
244 }
245 }
246
247 public void drawPolygon(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
248 OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
249 if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
250 surfaceData.doPolygon(this, sg2d, xpoints, ypoints, npoints, true, false);
251 } else {
252 GeneralPath polyToShape = new GeneralPath();
253 polyToShape.moveTo(xpoints[0], ypoints[0]);
254 for (int i = 1; i < npoints; i++) {
255 polyToShape.lineTo(xpoints[i], ypoints[i]);
256 }
257 polyToShape.lineTo(xpoints[0], ypoints[0]);
258 drawfillShape(sg2d, sg2d.stroke.createStrokedShape(polyToShape), true, true);
259 }
260 }
261
262 public void fillPolygon(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
263 OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
264 surfaceData.doPolygon(this, sg2d, xpoints, ypoints, npoints, true, true);
265 }
266
267 native void doShape(SurfaceData sData, int length, FloatBuffer coordinates, IntBuffer types, int windingRule, boolean isfill, boolean shouldApplyOffset);
268
269 void drawfillShape(SunGraphics2D sg2d, Shape s, boolean isfill, boolean shouldApplyOffset) {
270 if (s == null) { throw new NullPointerException(); }
271
272 OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
273 // TODO:
274 boolean sOptimizeShapes = true;
275 if (sOptimizeShapes && OSXSurfaceData.IsSimpleColor(sg2d.paint)) {
276 if (s instanceof Rectangle2D) {
277 Rectangle2D rectangle = (Rectangle2D) s;
278
279 float x = (float) rectangle.getX();
280 float y = (float) rectangle.getY();
281 float w = (float) rectangle.getWidth();
282 float h = (float) rectangle.getHeight();
|
1 /*
2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
213 synchronized (arcToShape) {
214 arcToShape.setArc(x, y, width, height, startAngle, arcAngle, type);
215 drawfillShape(sg2d, sg2d.stroke.createStrokedShape(arcToShape), true, true);
216 }
217 }
218 }
219
220 public void fillArc(SunGraphics2D sg2d, int x, int y, int width, int height, int startAngle, int arcAngle) {
221 fillArc(sg2d, x, y, width, height, startAngle, arcAngle, Arc2D.PIE);
222 }
223
224 public void fillArc(SunGraphics2D sg2d, float x, float y, float width, float height, float startAngle, float arcAngle, int type) {
225 if ((width < 0) || (height < 0)) return;
226
227 OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
228 surfaceData.doArc(this, sg2d, x, y, width, height, startAngle, arcAngle, type, true);
229 }
230
231 native void doPoly(SurfaceData sData, int[] xpoints, int[] ypoints, int npoints, boolean ispolygon, boolean isfill);
232
233 public void drawPolyline(SunGraphics2D sg2d, int[] xpoints, int[] ypoints, int npoints) {
234 OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
235 if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
236 surfaceData.doPolygon(this, sg2d, xpoints, ypoints, npoints, false, false);
237 } else {
238 GeneralPath polyToShape = new GeneralPath();
239 polyToShape.moveTo(xpoints[0], ypoints[0]);
240 for (int i = 1; i < npoints; i++) {
241 polyToShape.lineTo(xpoints[i], ypoints[i]);
242 }
243 drawfillShape(sg2d, sg2d.stroke.createStrokedShape(polyToShape), true, true);
244 }
245 }
246
247 public void drawPolygon(SunGraphics2D sg2d, int[] xpoints, int[] ypoints, int npoints) {
248 OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
249 if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
250 surfaceData.doPolygon(this, sg2d, xpoints, ypoints, npoints, true, false);
251 } else {
252 GeneralPath polyToShape = new GeneralPath();
253 polyToShape.moveTo(xpoints[0], ypoints[0]);
254 for (int i = 1; i < npoints; i++) {
255 polyToShape.lineTo(xpoints[i], ypoints[i]);
256 }
257 polyToShape.lineTo(xpoints[0], ypoints[0]);
258 drawfillShape(sg2d, sg2d.stroke.createStrokedShape(polyToShape), true, true);
259 }
260 }
261
262 public void fillPolygon(SunGraphics2D sg2d, int[] xpoints, int[] ypoints, int npoints) {
263 OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
264 surfaceData.doPolygon(this, sg2d, xpoints, ypoints, npoints, true, true);
265 }
266
267 native void doShape(SurfaceData sData, int length, FloatBuffer coordinates, IntBuffer types, int windingRule, boolean isfill, boolean shouldApplyOffset);
268
269 void drawfillShape(SunGraphics2D sg2d, Shape s, boolean isfill, boolean shouldApplyOffset) {
270 if (s == null) { throw new NullPointerException(); }
271
272 OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
273 // TODO:
274 boolean sOptimizeShapes = true;
275 if (sOptimizeShapes && OSXSurfaceData.IsSimpleColor(sg2d.paint)) {
276 if (s instanceof Rectangle2D) {
277 Rectangle2D rectangle = (Rectangle2D) s;
278
279 float x = (float) rectangle.getX();
280 float y = (float) rectangle.getY();
281 float w = (float) rectangle.getWidth();
282 float h = (float) rectangle.getHeight();
|