Esempio n. 1
0
  public static void setDefaults(Figure f) {
    // Set SVG default values

    FILL_COLOR.set(f, Color.black);
    STROKE_COLOR.set(f, null);
    STROKE_DASH_FACTOR.set(f, 1d);
  }
Esempio n. 2
0
 /**
  * Gets the fill paint for the specified figure based on the attributes FILL_GRADIENT,
  * FILL_OPACITY, FILL_PAINT and the bounds of the figure. Returns null if the figure is not
  * filled.
  */
 public static Paint getFillPaint(Figure f) {
   double opacity = FILL_OPACITY.get(f);
   if (FILL_GRADIENT.get(f) != null) {
     return FILL_GRADIENT.get(f).getPaint(f, opacity);
   }
   Color color = FILL_COLOR.get(f);
   if (color != null) {
     if (opacity != 1) {
       color = new Color((color.getRGB() & 0xffffff) | (int) (opacity * 255) << 24, true);
     }
   }
   return color;
 }
Esempio n. 3
0
  /** Writes the attributes of the figure into the specified DOMOutput. */
  public static void writeAttributes(Figure f, DOMOutput out) throws IOException {
    Color color;
    Double dbl;
    String value;

    // Fill attributes
    color = FILL_COLOR.get(f);
    if (color == null) {
      value = "none";
    } else {
      value = "000000" + Integer.toHexString(color.getRGB());
      value = "#" + value.substring(value.length() - 6);
    }
    out.addAttribute("fill", value);
    if (WINDING_RULE.get(f) != WindingRule.NON_ZERO) {
      out.addAttribute("fill-rule", "evenodd");
    }

    // Stroke attributes
    color = STROKE_COLOR.get(f);
    if (color == null) {
      value = "none";
    } else {
      value = "000000" + Integer.toHexString(color.getRGB());
      value = "#" + value.substring(value.length() - 6);
    }
    out.addAttribute("stroke", value);
    out.addAttribute("stroke-width", STROKE_WIDTH.get(f), 1d);
    out.addAttribute(
        "stroke-miterlimit", STROKE_MITER_LIMIT_FACTOR.get(f) / STROKE_WIDTH.get(f), 4d);
    double[] dashes = STROKE_DASHES.get(f);
    dbl = (STROKE_DASH_FACTOR.get(f) == null) ? STROKE_WIDTH.get(f) : STROKE_DASH_FACTOR.get(f);
    if (dashes != null) {
      StringBuilder buf = new StringBuilder();
      for (int i = 0; i < dashes.length; i++) {
        if (i != 0) {
          buf.append(',');
          buf.append(dashes[i] * dbl);
        }
        out.addAttribute("stroke-dasharray", buf.toString());
      }
    }
    out.addAttribute("stroke-dashoffset", STROKE_DASH_PHASE.get(f), 0d);

    // Text attributes
    out.addAttribute("font-size", FONT_SIZE.get(f));
    // out.addAttribute("text-anchor", "start");
  }
Esempio n. 4
0
  /** Sets SVG default values. */
  public static void setDefaults(Figure f) {
    // Fill properties
    // http://www.w3.org/TR/SVGMobile12/painting.html#FillProperties
    FILL_COLOR.basicSet(f, Color.black);
    WINDING_RULE.basicSet(f, WindingRule.NON_ZERO);

    // Stroke properties
    // http://www.w3.org/TR/SVGMobile12/painting.html#StrokeProperties
    STROKE_COLOR.basicSet(f, null);
    STROKE_WIDTH.basicSet(f, 1d);
    STROKE_CAP.basicSet(f, BasicStroke.CAP_BUTT);
    STROKE_JOIN.basicSet(f, BasicStroke.JOIN_MITER);
    STROKE_MITER_LIMIT.basicSet(f, 4d);
    IS_STROKE_MITER_LIMIT_FACTOR.basicSet(f, false);
    STROKE_DASHES.basicSet(f, null);
    STROKE_DASH_PHASE.basicSet(f, 0d);
    IS_STROKE_DASH_FACTOR.basicSet(f, false);
  }
Esempio n. 5
0
  /** Reads the attributes from the specified DOMInput and assigns them to the figure. */
  public static void readAttributes(Figure f, DOMInput in) throws IOException {
    // FIXME - This method is not working, when "style" and individual attributes
    // are both used in an SVG document.
    List<Map<String, String>> styles = new ArrayList<Map<String, String>>();
    List<String> values = in.getInheritedAttribute("style");
    for (String v : values) {
      styles.add(getStyles(v));
    }
    String value;

    // Fill color
    value = getInheritedAttribute("fill", in, styles);
    if (value != null) {
      Color color = getColor(value);
      if (color != INHERIT_COLOR && color != CURRENT_COLOR) {
        FILL_COLOR.set(f, color);
      }
    }
    value = getInheritedAttribute("fill-rule", in, styles);
    if (value != null) {
      WINDING_RULE.set(
          f, value.toUpperCase().equals("NONZERO") ? WindingRule.NON_ZERO : WindingRule.EVEN_ODD);
    } else {
      WINDING_RULE.set(f, WindingRule.NON_ZERO);
    }

    // Stroke color
    value = getInheritedAttribute("stroke", in, styles);
    if (value != null) {
      Color color = getColor(value);
      if (color != INHERIT_COLOR && color != CURRENT_COLOR) {
        STROKE_COLOR.set(f, color);
      }
    }

    value = getInheritedAttribute("stroke-width", in, styles);
    if (value != null) {
      STROKE_WIDTH.set(f, Double.valueOf(value));
    }
    value = getInheritedAttribute("stroke-miterlimit", in, styles);
    if (value != null) {
      STROKE_MITER_LIMIT_FACTOR.set(f, Double.valueOf(value));
    }
    value = getInheritedAttribute("stroke-dasharray", in, styles);
    if (value != null) {
      StringTokenizer tt = new StringTokenizer(value, " ,");
      double[] dashes = new double[tt.countTokens()];
      for (int i = 0, n = dashes.length; i < n; i++) {
        dashes[i] = Double.valueOf(tt.nextToken());
      }
      STROKE_DASHES.set(f, dashes);
    }
    value = getInheritedAttribute("stroke-dashoffset", in, styles);
    if (value != null) {
      STROKE_DASH_PHASE.set(f, Math.abs(Double.valueOf(value)));
    }
    value = getInheritedAttribute("font-size", in, styles);
    if (value != null) {
      FONT_SIZE.set(f, getDimensionValue(in, value));
    }
    value = getInheritedAttribute("text-anchor", in, styles);
    if (value != null) {
      SVGText.TEXT_ANCHOR.set(f, Enum.valueOf(SVGText.TextAnchor.class, value.toUpperCase()));
    }
  }
Esempio n. 6
0
 public Color getFillColor() {
   return FILL_COLOR.get(this) == null || FILL_COLOR.get(this).equals(Color.white)
       ? Color.black
       : Color.WHITE;
   //  return FILL_COLOR.get(this);
 }
Esempio n. 7
0
 public Color getTextColor() {
   return FILL_COLOR.get(this);
   //   return TEXT_COLOR.get(this);
 }