private void doColor(Properties atts, Integer color, boolean fillMode) {
   int c = (0xFFFFFF & color) | 0xFF000000;
   if (searchColor != null && searchColor.intValue() == c) {
     c = replaceColor;
   }
   paint.setColor(c);
   Float opacity = atts.getFloat("opacity", false);
   if (opacity == null) {
     opacity = atts.getFloat(fillMode ? "fill-opacity" : "stroke-opacity", false);
   }
   if (opacity == null) {
     paint.setAlpha(255);
   } else {
     paint.setAlpha((int) (255 * opacity));
   }
 }
    private boolean doStroke(Properties atts, HashMap<String, Shader> gradients) {
      if (whiteMode) {
        // Never stroke in white mode
        return false;
      }
      if ("none".equals(atts.getString("display"))) {
        return false;
      }
      String strokeString = atts.getString("stroke");
      if (strokeString == null) return false;
      if (strokeString.startsWith("url(#")) {
        String id = strokeString.substring("url(#".length(), strokeString.length() - 1);
        Shader shader = gradients.get(id);
        if (shader == null) return false;
        paint.setShader(shader);
      } else {
        Integer color = atts.getHex("stroke");
        if (color == null) return false;
        paint.setShader(null);
        doColor(atts, color, false);
      }

      // Check for other stroke attributes
      Float width = atts.getFloat("stroke-width", true);
      // Set defaults

      if (width != null) {
        paint.setStrokeWidth(width);
      }
      String linecap = atts.getString("stroke-linecap");
      if ("round".equals(linecap)) {
        paint.setStrokeCap(Paint.Cap.ROUND);
      } else if ("square".equals(linecap)) {
        paint.setStrokeCap(Paint.Cap.SQUARE);
      } else if ("butt".equals(linecap)) {
        paint.setStrokeCap(Paint.Cap.BUTT);
      }
      String linejoin = atts.getString("stroke-linejoin");
      if ("miter".equals(linejoin)) {
        paint.setStrokeJoin(Paint.Join.MITER);
      } else if ("round".equals(linejoin)) {
        paint.setStrokeJoin(Paint.Join.ROUND);
      } else if ("bevel".equals(linejoin)) {
        paint.setStrokeJoin(Paint.Join.BEVEL);
      }
      paint.setStyle(Paint.Style.STROKE);
      return true;
    }
Пример #3
0
    private boolean doStroke(Properties atts) {
      if (whiteMode) {
        // Never stroke in white mode
        return false;
      }
      if ("none".equals(atts.getString("display"))) {
        return false;
      }
      Integer color = atts.getHex("stroke");
      if (color != null) {
        doColor(atts, color, false);
        // Check for other stroke attributes
        Float width = atts.getFloat("stroke-width");
        // Set defaults

        if (width != null) {
          paint.setStrokeWidth(width);
        }
        String linecap = atts.getString("stroke-linecap");
        if ("round".equals(linecap)) {
          paint.setStrokeCap(Paint.Cap.ROUND);
        } else if ("square".equals(linecap)) {
          paint.setStrokeCap(Paint.Cap.SQUARE);
        } else if ("butt".equals(linecap)) {
          paint.setStrokeCap(Paint.Cap.BUTT);
        }
        String linejoin = atts.getString("stroke-linejoin");
        if ("miter".equals(linejoin)) {
          paint.setStrokeJoin(Paint.Join.MITER);
        } else if ("round".equals(linejoin)) {
          paint.setStrokeJoin(Paint.Join.ROUND);
        } else if ("bevel".equals(linejoin)) {
          paint.setStrokeJoin(Paint.Join.BEVEL);
        }
        paint.setStyle(Paint.Style.STROKE);
        return true;
      }
      return false;
    }