Appends the commands required to draw a shape on the EPS document.
(Shape s, String action)
| 291 | * Appends the commands required to draw a shape on the EPS document. |
| 292 | */ |
| 293 | private void draw(Shape s, String action) { |
| 294 | if(s!=null) { |
| 295 | if(!_transform.isIdentity()) { |
| 296 | s = _transform.createTransformedShape(s); |
| 297 | } |
| 298 | // Update the bounds. |
| 299 | if(!action.equals("clip")) { //$NON-NLS-1$ |
| 300 | Rectangle2D shapeBounds = s.getBounds2D(); |
| 301 | Rectangle2D visibleBounds = shapeBounds; |
| 302 | if(_clip!=null) { |
| 303 | Rectangle2D clipBounds = _clip.getBounds2D(); |
| 304 | visibleBounds = shapeBounds.createIntersection(clipBounds); |
| 305 | } |
| 306 | float lineRadius = _stroke.getLineWidth()/2; |
| 307 | float minX = (float) visibleBounds.getMinX()-lineRadius; |
| 308 | float minY = (float) visibleBounds.getMinY()-lineRadius; |
| 309 | float maxX = (float) visibleBounds.getMaxX()+lineRadius; |
| 310 | float maxY = (float) visibleBounds.getMaxY()+lineRadius; |
| 311 | _document.updateBounds(minX, -minY); |
| 312 | _document.updateBounds(maxX, -maxY); |
| 313 | } |
| 314 | append("newpath"); //$NON-NLS-1$ |
| 315 | int type = 0; |
| 316 | float[] coords = new float[6]; |
| 317 | PathIterator it = s.getPathIterator(null); |
| 318 | float x0 = 0; |
| 319 | float y0 = 0; |
| 320 | while(!it.isDone()) { |
| 321 | type = it.currentSegment(coords); |
| 322 | float x1 = coords[0]; |
| 323 | float y1 = -coords[1]; |
| 324 | float x2 = coords[2]; |
| 325 | float y2 = -coords[3]; |
| 326 | float x3 = coords[4]; |
| 327 | float y3 = -coords[5]; |
| 328 | if(type==PathIterator.SEG_CLOSE) { |
| 329 | append("closepath"); //$NON-NLS-1$ |
| 330 | } else if(type==PathIterator.SEG_CUBICTO) { |
| 331 | append(x1+" "+y1+" "+x2+" "+y2+" "+x3+" "+y3+" curveto"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ |
| 332 | x0 = x3; |
| 333 | y0 = y3; |
| 334 | } else if(type==PathIterator.SEG_LINETO) { |
| 335 | append(x1+" "+y1+" lineto"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 336 | x0 = x1; |
| 337 | y0 = y1; |
| 338 | } else if(type==PathIterator.SEG_MOVETO) { |
| 339 | append(x1+" "+y1+" moveto"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 340 | x0 = x1; |
| 341 | y0 = y1; |
| 342 | } else if(type==PathIterator.SEG_QUADTO) { |
| 343 | // Convert the quad curve into a cubic. |
| 344 | float _x1 = x0+2/3f*(x1-x0); |
| 345 | float _y1 = y0+2/3f*(y1-y0); |
| 346 | float _x2 = x1+1/3f*(x2-x1); |
| 347 | float _y2 = y1+1/3f*(y2-y1); |
| 348 | float _x3 = x2; |
| 349 | float _y3 = y2; |
| 350 | append(_x1+" "+_y1+" "+_x2+" "+_y2+" "+_x3+" "+_y3+" curveto"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ |
no test coverage detected