コード例 #1
0
ファイル: Use.java プロジェクト: uazure/josm
  public Rectangle2D getBoundingBox() throws SVGException {
    SVGElement ref = diagram.getUniverse().getElement(href);
    if (ref instanceof ShapeElement) {
      ShapeElement shapeEle = (ShapeElement) ref;
      shapeEle.pushParentContext(this);
      Rectangle2D bounds = shapeEle.getBoundingBox();
      shapeEle.popParentContext();

      bounds = refXform.createTransformedShape(bounds).getBounds2D();
      bounds = boundsToParent(bounds);

      return bounds;
    }

    return null;
  }
コード例 #2
0
ファイル: Use.java プロジェクト: uazure/josm
  protected void build() throws SVGException {
    super.build();

    StyleAttribute sty = new StyleAttribute();

    if (getPres(sty.setName("x"))) {
      x = sty.getFloatValueWithUnits();
    }

    if (getPres(sty.setName("y"))) {
      y = sty.getFloatValueWithUnits();
    }

    if (getPres(sty.setName("width"))) {
      width = sty.getFloatValueWithUnits();
    }

    if (getPres(sty.setName("height"))) {
      height = sty.getFloatValueWithUnits();
    }

    if (getPres(sty.setName("xlink:href"))) {
      URI src = sty.getURIValue(getXMLBase());
      href = src;
      //            href = diagram.getUniverse().getElement(src);
    }

    // Determine use offset/scale
    refXform = new AffineTransform();
    refXform.translate(this.x, this.y);
  }
コード例 #3
0
ファイル: Rect.java プロジェクト: huokedu/josm
  /*
  public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
  {
  //Load style string
  super.loaderStartElement(helper, attrs, parent);

  String x = attrs.getValue("x");
  String y = attrs.getValue("y");
  String width = attrs.getValue("width");
  String height = attrs.getValue("height");
  String rx = attrs.getValue("rx");
  String ry = attrs.getValue("ry");

  if (rx == null) rx = ry;
  if (ry == null) ry = rx;

  this.x = XMLParseUtil.parseFloat(x);
  this.y = XMLParseUtil.parseFloat(y);
  this.width = XMLParseUtil.parseFloat(width);
  this.height = XMLParseUtil.parseFloat(height);
  if (rx != null)
  {
  this.rx = XMLParseUtil.parseFloat(rx);
  this.ry = XMLParseUtil.parseFloat(ry);
  }

  build();
  //        setBounds(this.x, this.y, this.width, this.height);
  }
  */
  protected void build() throws SVGException {
    super.build();

    StyleAttribute sty = new StyleAttribute();

    //        SVGElement parent = this.getParent();
    //        if (parent instanceof RenderableElement)
    //        {
    //            RenderableElement re = (RenderableElement)parent;
    //            Rectangle2D bounds = re.getBoundingBox();
    //            bounds = null;
    //        }

    if (getPres(sty.setName("x"))) {
      x = sty.getFloatValueWithUnits();
    }

    if (getPres(sty.setName("y"))) {
      y = sty.getFloatValueWithUnits();
    }

    if (getPres(sty.setName("width"))) {
      width = sty.getFloatValueWithUnits();
    }

    if (getPres(sty.setName("height"))) {
      height = sty.getFloatValueWithUnits();
    }

    boolean rxSet = false;
    if (getPres(sty.setName("rx"))) {
      rx = sty.getFloatValueWithUnits();
      rxSet = true;
    }

    boolean rySet = false;
    if (getPres(sty.setName("ry"))) {
      ry = sty.getFloatValueWithUnits();
      rySet = true;
    }

    if (!rxSet) {
      rx = ry;
    }
    if (!rySet) {
      ry = rx;
    }

    if (rx == 0f && ry == 0f) {
      rect = new Rectangle2D.Float(x, y, width, height);
    } else {
      rect = new RoundRectangle2D.Float(x, y, width, height, rx * 2, ry * 2);
    }
  }
コード例 #4
0
 @Override
 protected void realRun() throws IOException, OsmTransferException {
   LatLon center = Main.getProjection().eastNorth2latlon(Main.map.mapView.getCenter());
   scale =
       Settings.getScaleNumerator()
           / Settings.getScaleDivisor()
           / Math.cos(Math.toRadians(center.lat()));
   this.center = projection.latlon2eastNorth(center);
   try {
     SVGUniverse universe = new SVGUniverse();
     universe.setVerbose(Main.pref.getBoolean("importvec.verbose", false));
     for (File f : files) {
       if (f.isDirectory()) continue;
       if (canceled) {
         return;
       }
       SVGDiagram diagram = universe.getDiagram(f.toURI());
       ShapeElement root = diagram.getRoot();
       if (root == null) {
         throw new IOException("Can't find root SVG element");
       }
       Rectangle2D bbox = root.getBoundingBox();
       this.center = this.center.add(-bbox.getCenterX() * scale, bbox.getCenterY() * scale);
       processElement(root, null);
     }
   } catch (IOException e) {
     throw e;
   } catch (Exception e) {
     throw new IOException(e);
   }
   LinkedList<Command> cmds = new LinkedList<>();
   for (Node n : nodes) {
     cmds.add(new AddCommand(n));
   }
   for (Way w : ways) {
     cmds.add(new AddCommand(w));
   }
   Main.main.undoRedo.add(new SequenceCommand("Import primitives", cmds));
 }