Пример #1
0
  /**
   * Converts for the specified element, its fill paint properties to a Paint object.
   *
   * @param filledElement the element interested in a Paint
   * @param filledNode the graphics node to fill
   * @param ctx the bridge context
   */
  public static Paint convertFillPaint(
      Element filledElement, GraphicsNode filledNode, BridgeContext ctx) {
    Value v = CSSUtilities.getComputedStyle(filledElement, SVGCSSEngine.FILL_OPACITY_INDEX);
    float opacity = convertOpacity(v);
    v = CSSUtilities.getComputedStyle(filledElement, SVGCSSEngine.FILL_INDEX);

    return convertPaint(filledElement, filledNode, v, opacity, ctx);
  }
Пример #2
0
  /**
   * Converts for the specified element, its stroke paint properties to a Paint object.
   *
   * @param strokedElement the element interested in a Paint
   * @param strokedNode the graphics node to stroke
   * @param ctx the bridge context
   */
  public static Paint convertStrokePaint(
      Element strokedElement, GraphicsNode strokedNode, BridgeContext ctx) {
    Value v = CSSUtilities.getComputedStyle(strokedElement, SVGCSSEngine.STROKE_OPACITY_INDEX);
    float opacity = convertOpacity(v);
    v = CSSUtilities.getComputedStyle(strokedElement, SVGCSSEngine.STROKE_INDEX);

    return convertPaint(strokedElement, strokedNode, v, opacity, ctx);
  }
Пример #3
0
  /**
   * Returns a <code>ShapePainter</code> defined on the specified element and for the specified
   * shape node.
   *
   * @param e the element with the marker CSS properties
   * @param node the shape node
   * @param ctx the bridge context
   */
  public static ShapePainter convertMarkers(Element e, ShapeNode node, BridgeContext ctx) {
    Value v;
    v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.MARKER_START_INDEX);
    Marker startMarker = convertMarker(e, v, ctx);
    v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.MARKER_MID_INDEX);
    Marker midMarker = convertMarker(e, v, ctx);
    v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.MARKER_END_INDEX);
    Marker endMarker = convertMarker(e, v, ctx);

    if (startMarker != null || midMarker != null || endMarker != null) {
      MarkerShapePainter p = new MarkerShapePainter(node.getShape());
      p.setStartMarker(startMarker);
      p.setMiddleMarker(midMarker);
      p.setEndMarker(endMarker);
      return p;
    } else {
      return null;
    }
  }
Пример #4
0
  /**
   * Converts a <code>Stroke</code> object defined on the specified element.
   *
   * @param e the element on which the stroke is specified
   */
  public static Stroke convertStroke(Element e) {
    Value v;
    v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.STROKE_WIDTH_INDEX);
    float width = v.getFloatValue();
    if (width == 0.0f) return null; // Stop here no stroke should be painted.

    v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.STROKE_LINECAP_INDEX);
    int linecap = convertStrokeLinecap(v);
    v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.STROKE_LINEJOIN_INDEX);
    int linejoin = convertStrokeLinejoin(v);
    v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.STROKE_MITERLIMIT_INDEX);
    float miterlimit = convertStrokeMiterlimit(v);
    v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.STROKE_DASHARRAY_INDEX);
    float[] dasharray = convertStrokeDasharray(v);

    float dashoffset = 0;
    if (dasharray != null) {
      v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.STROKE_DASHOFFSET_INDEX);
      dashoffset = v.getFloatValue();

      // make the dashoffset positive since BasicStroke cannot handle
      // negative values
      if (dashoffset < 0) {
        float dashpatternlength = 0;
        for (int i = 0; i < dasharray.length; i++) {
          dashpatternlength += dasharray[i];
        }
        // if the dash pattern consists of an odd number of elements,
        // the pattern length must be doubled
        if ((dasharray.length % 2) != 0) dashpatternlength *= 2;

        if (dashpatternlength == 0) {
          dashoffset = 0;
        } else {
          while (dashoffset < 0) dashoffset += dashpatternlength;
        }
      }
    }
    return new BasicStroke(width, linecap, linejoin, miterlimit, dasharray, dashoffset);
  }