예제 #1
1
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and shape.
  *
  * @return Returns true, if the polygon is inside of the image bounds.
  */
 private boolean writePolyAttributes(IXMLElement elem, SVGFigure f, Shape shape) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     StringBuilder buf = new StringBuilder();
     float[] coords = new float[6];
     GeneralPath path = new GeneralPath();
     for (PathIterator i = shape.getPathIterator(t, 1.5f);
     ! i.isDone(); i.next()) {
         switch (i.currentSegment(coords)) {
             case PathIterator.SEG_MOVETO :
                 if (buf.length() != 0) {
                     throw new IllegalArgumentException("Illegal shape "+shape);
                 }
                 if (buf.length() != 0) {
                     buf.append(',');
                 }
                 buf.append((int) coords[0]);
                 buf.append(',');
                 buf.append((int) coords[1]);
                 path.moveTo(coords[0], coords[1]);
                 break;
             case PathIterator.SEG_LINETO :
                 if (buf.length() != 0) {
                     buf.append(',');
                 }
                 buf.append((int) coords[0]);
                 buf.append(',');
                 buf.append((int) coords[1]);
                 path.lineTo(coords[0], coords[1]);
                 break;
             case PathIterator.SEG_CLOSE :
                 path.closePath();
                 break;
             default :
                 throw new InternalError("Illegal segment type "+i.currentSegment(coords));
         }
     }
     elem.setAttribute("shape", "poly");
     elem.setAttribute("coords", buf.toString());
     writeHrefAttribute(elem, f);
     return path.intersects(new Rectangle2D.Float(bounds.x, bounds.y, bounds.width, bounds.height));
 }
예제 #2
0
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and ellipse.
  *
  * @return Returns true, if the circle is inside of the image bounds.
  */
 private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType() &&
             ellipse.width == ellipse.height
             ) {
         
         Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y);
         Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height);
         t.transform(start, start);
         t.transform(end, end);
         ellipse.x = Math.min(start.x, end.x);
         ellipse.y = Math.min(start.y, end.y);
         ellipse.width = Math.abs(start.x - end.x);
         ellipse.height = Math.abs(start.y - end.y);
         
         elem.setAttribute("shape", "circle");
         elem.setAttribute("coords",
                 (int) (ellipse.x + ellipse.width / 2d)+","+
                 (int) (ellipse.y + ellipse.height / 2d)+","+
                 (int) (ellipse.width / 2d)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(ellipse.getBounds());
     } else {
         return writePolyAttributes(elem, f, (Shape) ellipse);
     }
 }
예제 #3
0
 private void writePolygonElement(IXMLElement parent, SVGPathFigure f) throws IOException {
     IXMLElement elem = parent.createElement("area");
     if (writePolyAttributes(elem, f, new GrowStroke((float) (getStrokeTotalWidth(f) / 2d), (float) getStrokeTotalWidth(f)).
             createStrokedShape(f.getChild(0).getBezierPath())
             )) {
         parent.addChild(elem);
     }
 }
예제 #4
0
 private void writeEllipseElement(IXMLElement parent, SVGEllipseFigure f) throws IOException  {
     IXMLElement elem = parent.createElement("area");
     Rectangle2D.Double r = f.getBounds();
     double grow = getPerpendicularHitGrowth(f);
     Ellipse2D.Double ellipse = new Ellipse2D.Double(r.x - grow, r.y - grow, r.width + grow, r.height + grow);
     if (writeCircleAttributes(elem, f, ellipse)) {
         parent.addChild(elem);
     }
 }
예제 #5
0
 private void writeLineElement(IXMLElement parent, SVGPathFigure f) throws IOException {
     IXMLElement elem = parent.createElement("area");
     if (writePolyAttributes(elem, f, new GrowStroke((float) (getStrokeTotalWidth(f) / 2d), (float) getStrokeTotalWidth(f)).
             createStrokedShape(new Line2D.Double(
             f.getStartPoint(), f.getEndPoint()
             )))) {
         parent.addChild(elem);
     }
 }
예제 #6
0
 private void writeHrefAttribute(IXMLElement elem, SVGFigure f) {
     if (LINK.get(f) != null && LINK.get(f).trim().length() > 0) {
         elem.setAttribute("href", LINK.get(f));
         elem.setAttribute("title", LINK.get(f));
         elem.setAttribute("alt", LINK.get(f));
     } else {
         elem.setAttribute("nohref", "true");
     }
 }
예제 #7
0
 private void writeTextAreaElement(IXMLElement parent, SVGTextAreaFigure f) throws IOException {
     IXMLElement elem = parent.createElement("AREA");
     Rectangle2D.Double rect = f.getBounds();
     double grow = getPerpendicularHitGrowth(f);
     rect.x -= grow;
     rect.y -= grow;
     rect.width += grow;
     rect.height += grow;
     if (writeRectAttributes(elem, f, rect)) {
         parent.addChild(elem);
     }
 }
예제 #8
0
 private void writePathElement(IXMLElement parent, SVGPathFigure f) throws IOException {
     GrowStroke growStroke = new GrowStroke((float) (getStrokeTotalWidth(f) / 2d), (float) getStrokeTotalWidth(f));
     BasicStroke basicStroke = new BasicStroke((float) getStrokeTotalWidth(f));
     for (Figure child : f.getChildren()) {
         SVGBezierFigure bezier = (SVGBezierFigure) child;
         IXMLElement elem = parent.createElement("area");
         if (bezier.isClosed()) {
             writePolyAttributes(elem, f, growStroke.
                     createStrokedShape(bezier.getBezierPath())
                     );
         } else {
             writePolyAttributes(elem, f, basicStroke.
                     createStrokedShape(bezier.getBezierPath())
                     );
         }
         parent.addChild(elem);
     }
 }
예제 #9
0
 private void writeRectElement(IXMLElement parent, SVGRectFigure f) throws IOException {
     IXMLElement elem = parent.createElement("AREA");
     boolean isContained;
     if (f.getArcHeight() == 0 && f.getArcWidth() == 0) {
         Rectangle2D.Double rect = f.getBounds();
         double grow = getPerpendicularHitGrowth(f);
         rect.x -= grow;
         rect.y -= grow;
         rect.width += grow;
         rect.height += grow;
         isContained = writeRectAttributes(elem, f, rect);
     } else {
         isContained = writePolyAttributes(elem, f,
                 new GrowStroke((float) (getStrokeTotalWidth(f) / 2d), (float) getStrokeTotalWidth(f)).
                 createStrokedShape(new RoundRectangle2D.Double(
                 f.getX(), f.getY(), f.getWidth(), f.getHeight(),
                 f.getArcWidth(), f.getArcHeight()
                 )));
     }
     if (isContained) {
         parent.addChild(elem);
     }
 }
예제 #10
0
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and rectangle.
  *
  * @return Returns true, if the rect is inside of the image bounds.
  */
 private boolean writeRectAttributes(IXMLElement elem, SVGFigure f, Rectangle2D.Double rect) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType()
             ) {
         
         Point2D.Double start = new Point2D.Double(rect.x, rect.y);
         Point2D.Double end = new Point2D.Double(rect.x + rect.width, rect.y + rect.height);
         t.transform(start, start);
         t.transform(end, end);
         Rectangle r = new Rectangle(
                 (int) Math.min(start.x, end.x),
                 (int) Math.min(start.y, end.y),
                 (int) Math.abs(start.x - end.x),
                 (int) Math.abs(start.y - end.y)
                 );
         
         elem.setAttribute("shape", "rect");
         elem.setAttribute("coords",
                 r.x + ","+
                 r.y + ","+
                 (r.x + r.width) + ","+
                 (r.y + r.height)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(r);
     } else {
         return writePolyAttributes(elem, f, (Shape) rect);
     }
 }
예제 #11
0
 private void writeImageElement(IXMLElement parent, SVGImageFigure f) {
     IXMLElement elem = parent.createElement("area");
     Rectangle2D.Double rect = f.getBounds();
     writeRectAttributes(elem, f, rect);
     parent.addChild(elem);
 }