DroidFish: SVG, added support for gradients on strokes.

This commit is contained in:
Peter Osterlund 2012-06-09 15:32:15 +00:00
parent b1df438d06
commit 64d0048222

View File

@ -852,7 +852,7 @@ public class SVGParser {
return false; return false;
} }
private boolean doStroke(Properties atts) { private boolean doStroke(Properties atts, HashMap<String, Shader> gradients) {
if (whiteMode) { if (whiteMode) {
// Never stroke in white mode // Never stroke in white mode
return false; return false;
@ -860,9 +860,23 @@ public class SVGParser {
if ("none".equals(atts.getString("display"))) { if ("none".equals(atts.getString("display"))) {
return false; 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"); Integer color = atts.getHex("stroke");
if (color != null) { if (color == null)
return false;
paint.setShader(null);
doColor(atts, color, false); doColor(atts, color, false);
}
// Check for other stroke attributes // Check for other stroke attributes
Float width = atts.getFloat("stroke-width", true); Float width = atts.getFloat("stroke-width", true);
// Set defaults // Set defaults
@ -889,8 +903,6 @@ public class SVGParser {
paint.setStyle(Paint.Style.STROKE); paint.setStyle(Paint.Style.STROKE);
return true; return true;
} }
return false;
}
private Gradient doGradient(boolean isLinear, Attributes atts) { private Gradient doGradient(boolean isLinear, Attributes atts) {
Gradient gradient = new Gradient(); Gradient gradient = new Gradient();
@ -1087,7 +1099,7 @@ public class SVGParser {
else else
canvas.drawRect(x, y, x + width, y + height, paint); canvas.drawRect(x, y, x + width, y + height, paint);
} }
if (doStroke(props)) { if (doStroke(props, gradientMap)) {
if (rx > 0 && ry > 0) if (rx > 0 && ry > 0)
canvas.drawRoundRect(new RectF(x, y, x + width, y + height), rx, ry, paint); canvas.drawRoundRect(new RectF(x, y, x + width, y + height), rx, ry, paint);
else else
@ -1100,7 +1112,7 @@ public class SVGParser {
Float y1 = getFloatAttr("y1", atts); Float y1 = getFloatAttr("y1", atts);
Float y2 = getFloatAttr("y2", atts); Float y2 = getFloatAttr("y2", atts);
Properties props = new Properties(atts); Properties props = new Properties(atts);
if (doStroke(props)) { if (doStroke(props, gradientMap)) {
pushTransform(atts); pushTransform(atts);
doLimits(x1, y1); doLimits(x1, y1);
doLimits(x2, y2); doLimits(x2, y2);
@ -1119,7 +1131,7 @@ public class SVGParser {
doLimits(centerX + radius, centerY + radius); doLimits(centerX + radius, centerY + radius);
canvas.drawCircle(centerX, centerY, radius, paint); canvas.drawCircle(centerX, centerY, radius, paint);
} }
if (doStroke(props)) { if (doStroke(props, gradientMap)) {
canvas.drawCircle(centerX, centerY, radius, paint); canvas.drawCircle(centerX, centerY, radius, paint);
} }
popTransform(); popTransform();
@ -1138,7 +1150,7 @@ public class SVGParser {
doLimits(centerX + radiusX, centerY + radiusY); doLimits(centerX + radiusX, centerY + radiusY);
canvas.drawOval(rect, paint); canvas.drawOval(rect, paint);
} }
if (doStroke(props)) { if (doStroke(props, gradientMap)) {
canvas.drawOval(rect, paint); canvas.drawOval(rect, paint);
} }
popTransform(); popTransform();
@ -1165,7 +1177,7 @@ public class SVGParser {
doLimits(p); doLimits(p);
canvas.drawPath(p, paint); canvas.drawPath(p, paint);
} }
if (doStroke(props)) { if (doStroke(props, gradientMap)) {
canvas.drawPath(p, paint); canvas.drawPath(p, paint);
} }
popTransform(); popTransform();
@ -1179,7 +1191,7 @@ public class SVGParser {
doLimits(p); doLimits(p);
canvas.drawPath(p, paint); canvas.drawPath(p, paint);
} }
if (doStroke(props)) { if (doStroke(props, gradientMap)) {
canvas.drawPath(p, paint); canvas.drawPath(p, paint);
} }
popTransform(); popTransform();