1 /*
2 * Copyright (c) 2011, 2012, 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
67 // create shape corresponding to this primitive
68 roundrectangle.setRoundRect(x, y, width, height, arcWidth, arcHeight);
69
70 draw(sg2d, roundrectangle);
71 }
72
73 public synchronized void drawOval(SunGraphics2D sg2d, int x, int y, int width, int height) {
74 // create shape corresponding to this primitive
75 ellipse.setFrame(x, y, width, height);
76
77 draw(sg2d, ellipse);
78 }
79
80 public synchronized void drawArc(SunGraphics2D sg2d, int x, int y, int width, int height, int startAngle, int arcAngle) {
81 // create shape corresponding to this primitive
82 arc.setArc(x, y, width, height, startAngle, arcAngle, Arc2D.OPEN);
83
84 draw(sg2d, arc);
85 }
86
87 public synchronized void drawPolyline(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
88 doPolygon(sg2d, xpoints, ypoints, npoints, false, false);
89 }
90
91 public synchronized void drawPolygon(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
92 doPolygon(sg2d, xpoints, ypoints, npoints, true, false);
93 }
94
95 public synchronized void fillRect(SunGraphics2D sg2d, int x, int y, int width, int height) {
96 // create shape corresponding to this primitive
97 rectangle.setRect(x, y, width, height);
98
99 fill(sg2d, rectangle);
100 }
101
102 public synchronized void fillRoundRect(SunGraphics2D sg2d, int x, int y, int width, int height, int arcWidth, int arcHeight) {
103 // create shape corresponding to this primitive
104 roundrectangle.setRoundRect(x, y, width, height, arcWidth, arcHeight);
105
106 fill(sg2d, roundrectangle);
107 }
108
109 public synchronized void fillOval(SunGraphics2D sg2d, int x, int y, int width, int height) {
110 // create shape corresponding to this primitive
111 ellipse.setFrame(x, y, width, height);
112
113 fill(sg2d, ellipse);
114 }
115
116 public synchronized void fillArc(SunGraphics2D sg2d, int x, int y, int width, int height, int startAngle, int arcAngle) {
117 // create shape corresponding to this primitive
118 arc.setArc(x, y, width, height, startAngle, arcAngle, Arc2D.PIE);
119
120 fill(sg2d, arc);
121 }
122
123 public synchronized void fillPolygon(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
124 doPolygon(sg2d, xpoints, ypoints, npoints, true, true);
125 }
126
127 public synchronized void doPolygon(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints, boolean ispolygon, boolean isfill) {
128 GeneralPath gp = new GeneralPath(Path2D.WIND_NON_ZERO, npoints);
129 gp.moveTo(xpoints[0], ypoints[0]);
130 for (int i = 1; i < npoints; i++) {
131 gp.lineTo(xpoints[i], ypoints[i]);
132 }
133 if (ispolygon) {
134 // according to the specs (only applies to polygons, not polylines)
135 if ((xpoints[0] != xpoints[npoints - 1]) || (ypoints[0] != ypoints[npoints - 1])) {
136 gp.lineTo(xpoints[0], ypoints[0]);
137 }
138 }
139
140 doShape(sg2d, (OSXSurfaceData) sg2d.getSurfaceData(), (Shape) gp, isfill);
141 }
142
143 public synchronized void draw(SunGraphics2D sg2d, Shape shape) {
144 doShape(sg2d, (OSXSurfaceData) sg2d.getSurfaceData(), shape, false);
145 }
146
147 public synchronized void fill(SunGraphics2D sg2d, Shape shape) {
179 g.setPaint(sg2d.getPaint());
180 g.setStroke(sg2d.getStroke());
181
182 // render the primitive to be composited
183 if (isfill) {
184 g.fill(shape);
185 } else {
186 g.draw(shape);
187 }
188
189 g.dispose();
190
191 composite(sg2d, surfaceData, srcPixels, compositingBounds);
192 }
193 }
194
195 public synchronized void drawString(SunGraphics2D sg2d, String str, double x, double y) {
196 drawGlyphVector(sg2d, sg2d.getFont().createGlyphVector(sg2d.getFontRenderContext(), str), x, y);
197 }
198
199 public synchronized void drawChars(SunGraphics2D sg2d, char data[], int offset, int length, int x, int y) {
200 drawString(sg2d, new String(data, offset, length), x, y);
201 }
202
203 public synchronized void drawGlyphVector(SunGraphics2D sg2d, GlyphVector glyphVector, double x, double y) {
204 drawGlyphVector(sg2d, glyphVector, (float) x, (float) y);
205 }
206
207 public synchronized void drawGlyphVector(SunGraphics2D sg2d, GlyphVector glyphVector, float x, float y) {
208 OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
209
210 Shape shape = glyphVector.getOutline(x, y);
211
212 // get final destination compositing bounds (after all transformations if needed)
213 Rectangle2D compositingBounds = padBounds(sg2d, shape);
214
215 // constrain the bounds to be within surface bounds
216 clipBounds(sg2d, compositingBounds);
217
218 // if the compositing region is empty we skip all remaining compositing work:
219 if (compositingBounds.isEmpty() == false) {
|
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
67 // create shape corresponding to this primitive
68 roundrectangle.setRoundRect(x, y, width, height, arcWidth, arcHeight);
69
70 draw(sg2d, roundrectangle);
71 }
72
73 public synchronized void drawOval(SunGraphics2D sg2d, int x, int y, int width, int height) {
74 // create shape corresponding to this primitive
75 ellipse.setFrame(x, y, width, height);
76
77 draw(sg2d, ellipse);
78 }
79
80 public synchronized void drawArc(SunGraphics2D sg2d, int x, int y, int width, int height, int startAngle, int arcAngle) {
81 // create shape corresponding to this primitive
82 arc.setArc(x, y, width, height, startAngle, arcAngle, Arc2D.OPEN);
83
84 draw(sg2d, arc);
85 }
86
87 public synchronized void drawPolyline(SunGraphics2D sg2d, int[] xpoints, int[] ypoints, int npoints) {
88 doPolygon(sg2d, xpoints, ypoints, npoints, false, false);
89 }
90
91 public synchronized void drawPolygon(SunGraphics2D sg2d, int[] xpoints, int[] ypoints, int npoints) {
92 doPolygon(sg2d, xpoints, ypoints, npoints, true, false);
93 }
94
95 public synchronized void fillRect(SunGraphics2D sg2d, int x, int y, int width, int height) {
96 // create shape corresponding to this primitive
97 rectangle.setRect(x, y, width, height);
98
99 fill(sg2d, rectangle);
100 }
101
102 public synchronized void fillRoundRect(SunGraphics2D sg2d, int x, int y, int width, int height, int arcWidth, int arcHeight) {
103 // create shape corresponding to this primitive
104 roundrectangle.setRoundRect(x, y, width, height, arcWidth, arcHeight);
105
106 fill(sg2d, roundrectangle);
107 }
108
109 public synchronized void fillOval(SunGraphics2D sg2d, int x, int y, int width, int height) {
110 // create shape corresponding to this primitive
111 ellipse.setFrame(x, y, width, height);
112
113 fill(sg2d, ellipse);
114 }
115
116 public synchronized void fillArc(SunGraphics2D sg2d, int x, int y, int width, int height, int startAngle, int arcAngle) {
117 // create shape corresponding to this primitive
118 arc.setArc(x, y, width, height, startAngle, arcAngle, Arc2D.PIE);
119
120 fill(sg2d, arc);
121 }
122
123 public synchronized void fillPolygon(SunGraphics2D sg2d, int[] xpoints, int[] ypoints, int npoints) {
124 doPolygon(sg2d, xpoints, ypoints, npoints, true, true);
125 }
126
127 public synchronized void doPolygon(SunGraphics2D sg2d, int[] xpoints, int[] ypoints, int npoints, boolean ispolygon, boolean isfill) {
128 GeneralPath gp = new GeneralPath(Path2D.WIND_NON_ZERO, npoints);
129 gp.moveTo(xpoints[0], ypoints[0]);
130 for (int i = 1; i < npoints; i++) {
131 gp.lineTo(xpoints[i], ypoints[i]);
132 }
133 if (ispolygon) {
134 // according to the specs (only applies to polygons, not polylines)
135 if ((xpoints[0] != xpoints[npoints - 1]) || (ypoints[0] != ypoints[npoints - 1])) {
136 gp.lineTo(xpoints[0], ypoints[0]);
137 }
138 }
139
140 doShape(sg2d, (OSXSurfaceData) sg2d.getSurfaceData(), (Shape) gp, isfill);
141 }
142
143 public synchronized void draw(SunGraphics2D sg2d, Shape shape) {
144 doShape(sg2d, (OSXSurfaceData) sg2d.getSurfaceData(), shape, false);
145 }
146
147 public synchronized void fill(SunGraphics2D sg2d, Shape shape) {
179 g.setPaint(sg2d.getPaint());
180 g.setStroke(sg2d.getStroke());
181
182 // render the primitive to be composited
183 if (isfill) {
184 g.fill(shape);
185 } else {
186 g.draw(shape);
187 }
188
189 g.dispose();
190
191 composite(sg2d, surfaceData, srcPixels, compositingBounds);
192 }
193 }
194
195 public synchronized void drawString(SunGraphics2D sg2d, String str, double x, double y) {
196 drawGlyphVector(sg2d, sg2d.getFont().createGlyphVector(sg2d.getFontRenderContext(), str), x, y);
197 }
198
199 public synchronized void drawChars(SunGraphics2D sg2d, char[] data, int offset, int length, int x, int y) {
200 drawString(sg2d, new String(data, offset, length), x, y);
201 }
202
203 public synchronized void drawGlyphVector(SunGraphics2D sg2d, GlyphVector glyphVector, double x, double y) {
204 drawGlyphVector(sg2d, glyphVector, (float) x, (float) y);
205 }
206
207 public synchronized void drawGlyphVector(SunGraphics2D sg2d, GlyphVector glyphVector, float x, float y) {
208 OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
209
210 Shape shape = glyphVector.getOutline(x, y);
211
212 // get final destination compositing bounds (after all transformations if needed)
213 Rectangle2D compositingBounds = padBounds(sg2d, shape);
214
215 // constrain the bounds to be within surface bounds
216 clipBounds(sg2d, compositingBounds);
217
218 // if the compositing region is empty we skip all remaining compositing work:
219 if (compositingBounds.isEmpty() == false) {
|