예제 #1
0
파일: Gradient.java 프로젝트: wjase/cntools
  //    @Override
  //    protected void build() throws SVGException
  //    {
  //        super.build();
  //
  //        StyleAttribute sty = new StyleAttribute();
  //        String strn;
  //
  //        if (getPres(sty.setName("spreadMethod")))
  //        {
  //            strn = sty.getStringValue().toLowerCase();
  //            if (strn.equals("repeat")) spreadMethod = SM_REPEAT;
  //            else if (strn.equals("reflect")) spreadMethod = SM_REFLECT;
  //            else spreadMethod = SM_PAD;
  //        }
  //
  //        if (getPres(sty.setName("gradientUnits")))
  //        {
  //            strn = sty.getStringValue().toLowerCase();
  //            if (strn.equals("userspaceonuse")) gradientUnits = GU_USER_SPACE_ON_USE;
  //            else gradientUnits = GU_OBJECT_BOUNDING_BOX;
  //        }
  //
  //        if (getPres(sty.setName("gradientTransform"))) gradientTransform =
  // parseTransform(sty.getStringValue());
  //        //If we still don't have one, set it to identity
  //        if (gradientTransform == null) gradientTransform = new AffineTransform();
  //
  //
  //        //Check to see if we're using our own stops or referencing someone else's
  //        if (getPres(sty.setName("xlink:href")))
  //        {
  //            try {
  //                stopRef = sty.getURIValue(getXMLBase());
  //// System.err.println("Gradient: " + sty.getStringValue() + ", " + getXMLBase() + ", " + src);
  ////                URI src = getXMLBase().resolve(href);
  ////                stopRef = (Gradient)diagram.getUniverse().getElement(src);
  //            }
  //            catch (Exception e)
  //            {
  //                throw new SVGException("Could not resolve relative URL in Gradient: " +
  // sty.getStringValue() + ", " + getXMLBase(), e);
  //            }
  //        }
  //    }
  public float[] getStopFractions() {
    if (stopRef.isSet()) {
      Gradient grad = (Gradient) stopRef.getElement(); // diagram.getUniverse().getElement(stopRef);
      if (grad != null) {
        return grad.getStopFractions();
      }
    }

    if (stopFractions != null) {
      return stopFractions;
    }

    stopFractions = new float[stops.size()];
    int idx = 0;
    for (Iterator it = stops.iterator(); it.hasNext(); ) {
      Stop stop = (Stop) it.next();
      float val = stop.offset.getNormalisedValue();
      if (idx != 0 && val < stopFractions[idx - 1]) {
        val = stopFractions[idx - 1];
      }
      stopFractions[idx++] = val;
    }

    return stopFractions;
  }
예제 #2
0
파일: Gradient.java 프로젝트: wjase/cntools
  public Color[] getStopColors() {
    if (stopRef.isSet()) {
      Gradient grad = (Gradient) stopRef.getElement(); // diagram.getUniverse().getElement(stopRef);
      if (grad != null) {
        return grad.getStopColors();
      }
    }

    if (stops.isEmpty()) {
      throw new IllegalArgumentException("no stops for " + getId());
    }
    if (stopColors != null) {
      return stopColors;
    }

    stopColors = new Color[stops.size()];
    int idx = 0;
    for (Iterator it = stops.iterator(); it.hasNext(); ) {
      Stop stop = (Stop) it.next();
      int stopColorVal = stop.color.getColorValue().getRGB();
      Color stopColor =
          new Color(
              (stopColorVal >> 16) & 0xff,
              (stopColorVal >> 8) & 0xff,
              stopColorVal & 0xff,
              clamp((int) (stop.opacity.getNormalisedValue() * 255), 0, 255));
      stopColors[idx++] = stopColor;
    }

    return stopColors;
  }
예제 #3
0
파일: Gradient.java 프로젝트: wjase/cntools
 public AffineTransform getTransform() {
   if (stopRef.isSet()) {
     Gradient grad = (Gradient) stopRef.getElement(); // diagram.getUniverse().getElement(stopRef);
     return grad.getTransform();
   }
   return gradientTransform.getXform();
 }
예제 #4
0
파일: Gradient.java 프로젝트: wjase/cntools
 public void setStopRef(URI grad) {
   stopRef.setValue(grad);
 }