示例#1
0
 /**
  * Returns the distance, that a Rectangle needs to grow (or shrink) to make hit detections on a
  * shape as specified by the FILL_UNDER_STROKE and STROKE_POSITION attributes of a figure. The
  * value returned is the number of units that need to be grown (or shrunk) perpendicular to a
  * stroke on an outline of the shape.
  */
 public static double getPerpendicularHitGrowth(Figure f) {
   double grow;
   if (STROKE_COLOR.get(f) == null && STROKE_GRADIENT.get(f) == null) {
     grow = getPerpendicularFillGrowth(f);
   } else {
     double strokeWidth = AttributeKeys.getStrokeTotalWidth(f);
     grow = getPerpendicularDrawGrowth(f) + strokeWidth / 2d;
   }
   return grow;
 }
示例#2
0
 /**
  * Gets the stroke paint for the specified figure based on the attributes STROKE_GRADIENT,
  * STROKE_OPACITY, STROKE_PAINT and the bounds of the figure. Returns null if the figure is not
  * filled.
  */
 public static Paint getStrokePaint(Figure f) {
   double opacity = STROKE_OPACITY.get(f);
   if (STROKE_GRADIENT.get(f) != null) {
     return STROKE_GRADIENT.get(f).getPaint(f, opacity);
   }
   Color color = STROKE_COLOR.get(f);
   if (color != null) {
     if (opacity != 1) {
       color = new Color((color.getRGB() & 0xffffff) | (int) (opacity * 255) << 24, true);
     }
   }
   return color;
 }
示例#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");
  }