コード例 #1
0
ファイル: PaintServer.java プロジェクト: Squeegee/batik
  /**
   * Converts a Paint definition to a concrete <code>java.awt.Paint</code> instance according to the
   * specified parameters.
   *
   * @param paintedElement the element interested in a Paint
   * @param paintedNode the graphics node to paint (objectBoundingBox)
   * @param paintDef the paint definition
   * @param opacity the opacity to consider for the Paint
   * @param ctx the bridge context
   */
  public static Paint convertPaint(
      Element paintedElement,
      GraphicsNode paintedNode,
      Value paintDef,
      float opacity,
      BridgeContext ctx) {
    if (paintDef.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
      switch (paintDef.getPrimitiveType()) {
        case CSSPrimitiveValue.CSS_IDENT:
          return null; // none

        case CSSPrimitiveValue.CSS_RGBCOLOR:
          return convertColor(paintDef, opacity);

        case CSSPrimitiveValue.CSS_URI:
          return convertURIPaint(paintedElement, paintedNode, paintDef, opacity, ctx);

        default:
          throw new IllegalArgumentException("Paint argument is not an appropriate CSS value");
      }
    } else { // List
      Value v = paintDef.item(0);
      switch (v.getPrimitiveType()) {
        case CSSPrimitiveValue.CSS_RGBCOLOR:
          return convertRGBICCColor(paintedElement, v, (ICCColor) paintDef.item(1), opacity, ctx);

        case CSSPrimitiveValue.CSS_URI:
          {
            Paint result = silentConvertURIPaint(paintedElement, paintedNode, v, opacity, ctx);
            if (result != null) return result;

            v = paintDef.item(1);
            switch (v.getPrimitiveType()) {
              case CSSPrimitiveValue.CSS_IDENT:
                return null; // none

              case CSSPrimitiveValue.CSS_RGBCOLOR:
                if (paintDef.getLength() == 2) {
                  return convertColor(v, opacity);
                } else {
                  return convertRGBICCColor(
                      paintedElement, v, (ICCColor) paintDef.item(2), opacity, ctx);
                }
              default:
                throw new IllegalArgumentException(
                    "Paint argument is not an appropriate CSS value");
            }
          }
        default:
          // can't be reached
          throw new IllegalArgumentException("Paint argument is not an appropriate CSS value");
      }
    }
  }
コード例 #2
0
ファイル: PaintServer.java プロジェクト: Squeegee/batik
  /**
   * Returns a <code>Marker</code> defined on the specified element by the specified value, and for
   * the specified shape node.
   *
   * @param e the painted element
   * @param v the CSS value describing the marker to construct
   * @param ctx the bridge context
   */
  public static Marker convertMarker(Element e, Value v, BridgeContext ctx) {

    if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
      return null; // 'none'
    } else {
      String uri = v.getStringValue();
      Element markerElement = ctx.getReferencedElement(e, uri);
      Bridge bridge = ctx.getBridge(markerElement);
      if (bridge == null || !(bridge instanceof MarkerBridge)) {
        throw new BridgeException(ctx, e, ERR_CSS_URI_BAD_TARGET, new Object[] {uri});
      }
      return ((MarkerBridge) bridge).createMarker(ctx, markerElement, e);
    }
  }
コード例 #3
0
ファイル: PaintServer.java プロジェクト: Squeegee/batik
 /**
  * Returns the value of one color component (0 <= result <= 255).
  *
  * @param v the value that defines the color component
  */
 public static int resolveColorComponent(Value v) {
   float f;
   switch (v.getPrimitiveType()) {
     case CSSPrimitiveValue.CSS_PERCENTAGE:
       f = v.getFloatValue();
       f = (f > 100f) ? 100f : (f < 0f) ? 0f : f;
       return Math.round(255f * f / 100f);
     case CSSPrimitiveValue.CSS_NUMBER:
       f = v.getFloatValue();
       f = (f > 255f) ? 255f : (f < 0f) ? 0f : f;
       return Math.round(f);
     default:
       throw new IllegalArgumentException(
           "Color component argument is not an appropriate CSS value");
   }
 }
コード例 #4
0
  /**
   * Implements {@link
   * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
   */
  public Value computeValue(
      CSSStylableElement elt, String pseudo, CSSEngine engine, int idx, StyleMap sm, Value value) {
    if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_PERCENTAGE) {
      sm.putLineHeightRelative(idx, true);

      int fsi = engine.getLineHeightIndex();
      CSSStylableElement parent;
      parent = (CSSStylableElement) elt.getParentNode();
      if (parent == null) {
        // Hmmm somthing pretty odd - can't happen accordint to spec,
        // should always have text parent.
        // http://www.w3.org/TR/SVG11/text.html#BaselineShiftProperty
        parent = elt;
      }
      Value fs = engine.getComputedStyle(parent, pseudo, fsi);
      float fsv = fs.getFloatValue();
      float v = value.getFloatValue();
      return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, (fsv * v) / 100f);
    }
    return super.computeValue(elt, pseudo, engine, idx, sm, value);
  }