/** * TODO Would it be better/cleaner to throw a SVGParseException when sth could not be parsed instead of simply returning false? */ public bool setFill(SVGProperties pSVGProperties) { if (this.isDisplayNone(pSVGProperties) || this.isFillNone(pSVGProperties)) { return(false); } this.resetPaint(Paint.Style.Fill); string fillProperty = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_FILL); if (fillProperty == null) { if (pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STROKE) == null) { /* Default is black fill. */ if (!isStancil) { this.mPaint.Color = Color.Black; // TODO Respect color mapping? } return(true); } else { return(false); } } else { return(this.applyPaintProperties(pSVGProperties, true)); } }
bool setColorProperties(SVGProperties pSVGProperties, bool pModeFill) // TODO throw SVGParseException { string colorProperty = pSVGProperties.getStringProperty(pModeFill ? SVGConstants.ATTRIBUTE_FILL : SVGConstants.ATTRIBUTE_STROKE); if (colorProperty == null) { return(false); } string filterProperty = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_FILTER); if (filterProperty != null) { if (SVGProperties.IsUrlProperty(filterProperty)) { string filterID = SVGParserUtils.extractIDFromURLProperty(filterProperty); this.getFilter(filterID).applyFilterElements(this.mPaint); } else { return(false); } } if (SVGProperties.IsUrlProperty(colorProperty)) { string gradientID = SVGParserUtils.extractIDFromURLProperty(colorProperty); this.mPaint.SetShader(this.getGradientShader(gradientID)); return(true); } else { int?color = this.parseColor(colorProperty); if (color != null) { if (!isStancil) { this.applyColor(pSVGProperties, color.Value, pModeFill); } return(true); } else { return(false); } } }
public SVGGradientStop parseGradientStop(SVGProperties pSVGProperties) { float offset = pSVGProperties.getFloatProperty(SVGConstants.ATTRIBUTE_OFFSET, 0f); string stopColor = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STOP_COLOR); int rgb = this.parseColor(stopColor.Trim(), Color.Black); int alpha = this.parseGradientStopAlpha(pSVGProperties); return(new SVGGradientStop(offset, alpha | rgb)); }
/** * TODO Would it be better/cleaner to throw a SVGParseException when sth could not be parsed instead of simply returning false? */ public bool setFill(SVGProperties pSVGProperties) { if(this.isDisplayNone(pSVGProperties) || this.isFillNone(pSVGProperties)) { return false; } this.resetPaint(Paint.Style.Fill); string fillProperty = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_FILL); if(fillProperty == null) { if(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STROKE) == null) { /* Default is black fill. */ this.mPaint.Color = Color.Black; // TODO Respect color mapping? return true; } else { return false; } } else { return this.applyPaintProperties(pSVGProperties, true); } }
bool applyStrokeProperties(SVGProperties pSVGProperties) { float?width = pSVGProperties.getFloatProperty(SVGConstants.ATTRIBUTE_STROKE_WIDTH); if (width != null) { this.mPaint.StrokeWidth = width.Value; } string linecap = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STROKE_LINECAP); if (SVGConstants.ATTRIBUTE_STROKE_LINECAP_VALUE_ROUND.Equals(linecap)) { this.mPaint.StrokeCap = Paint.Cap.Round; } else if (SVGConstants.ATTRIBUTE_STROKE_LINECAP_VALUE_SQUARE.Equals(linecap)) { this.mPaint.StrokeCap = Paint.Cap.Square; } else if (SVGConstants.ATTRIBUTE_STROKE_LINECAP_VALUE_BUTT.Equals(linecap)) { this.mPaint.StrokeCap = Paint.Cap.Butt; } string linejoin = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STROKE_LINEJOIN_VALUE_); if (SVGConstants.ATTRIBUTE_STROKE_LINEJOIN_VALUE_MITER.Equals(linejoin)) { this.mPaint.StrokeJoin = Paint.Join.Miter; } else if (SVGConstants.ATTRIBUTE_STROKE_LINEJOIN_VALUE_ROUND.Equals(linejoin)) { this.mPaint.StrokeJoin = Paint.Join.Round; } else if (SVGConstants.ATTRIBUTE_STROKE_LINEJOIN_VALUE_BEVEL.Equals(linejoin)) { this.mPaint.StrokeJoin = Paint.Join.Bevel; } return(true); }
int parseGradientStopAlpha(SVGProperties pSVGProperties) { string opacityStyle = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STOP_OPACITY); if (opacityStyle != null) { float alpha = opacityStyle.ToSafeFloat(); int alphaInt = (int)Math.Round(255 * alpha); return(alphaInt << 24); } else { unchecked { return((int)ColorUtils.COLOR_MASK_32BIT_ARGB_ALPHA); } } }
public string getStringProperty(string pPropertyName, bool pAllowParentSVGProperties) { string s = null; if (this.mSVGStyleSet != null) { s = mSVGStyleSet.GetStyle(pPropertyName); } if (s == null) { s = mAttributes.GetStringAttribute(pPropertyName); } if (s == null && pAllowParentSVGProperties) { return(mParentSVGProperties == null ? null : mParentSVGProperties.getStringProperty(pPropertyName)); } else { return(s); } }
bool setColorProperties(SVGProperties pSVGProperties, bool pModeFill) { // TODO throw SVGParseException string colorProperty = pSVGProperties.getStringProperty(pModeFill ? SVGConstants.ATTRIBUTE_FILL : SVGConstants.ATTRIBUTE_STROKE); if(colorProperty == null) { return false; } string filterProperty = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_FILTER); if(filterProperty != null) { if(SVGProperties.IsUrlProperty(filterProperty)) { string filterID = SVGParserUtils.extractIDFromURLProperty(filterProperty); this.getFilter(filterID).applyFilterElements(this.mPaint); } else { return false; } } if(SVGProperties.IsUrlProperty(colorProperty)) { string gradientID = SVGParserUtils.extractIDFromURLProperty(colorProperty); this.mPaint.SetShader(this.getGradientShader(gradientID)); return true; } else { int? color = this.parseColor(colorProperty); if(color != null) { this.applyColor(pSVGProperties, color.Value, pModeFill); return true; } else { return false; } } }
int parseGradientStopAlpha(SVGProperties pSVGProperties) { string opacityStyle = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STOP_OPACITY); if (opacityStyle != null) { float alpha = opacityStyle.ToSafeFloat (); int alphaInt = (int)Math.Round(255 * alpha); return (alphaInt << 24); } else { unchecked { return (int)ColorUtils.COLOR_MASK_32BIT_ARGB_ALPHA; } } }
public SVGGradientStop parseGradientStop(SVGProperties pSVGProperties) { float offset = pSVGProperties.getFloatProperty(SVGConstants.ATTRIBUTE_OFFSET, 0f); string stopColor = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STOP_COLOR); int rgb = this.parseColor(stopColor.Trim(), Color.Black); int alpha = this.parseGradientStopAlpha(pSVGProperties); return new SVGGradientStop(offset, alpha | rgb); }
bool isFillNone(SVGProperties pSVGProperties) { return SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_FILL)); }
bool isDisplayNone(SVGProperties pSVGProperties) { return SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_DISPLAY)); }
bool isStrokeNone(SVGProperties pSVGProperties) { return(SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STROKE))); }
bool isFillNone(SVGProperties pSVGProperties) { return(SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_FILL))); }
bool isDisplayNone(SVGProperties pSVGProperties) { return(SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_DISPLAY))); }
bool applyStrokeProperties(SVGProperties pSVGProperties) { float? width = pSVGProperties.getFloatProperty(SVGConstants.ATTRIBUTE_STROKE_WIDTH); if (width != null) { this.mPaint.StrokeWidth = width.Value; } string linecap = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STROKE_LINECAP); if (SVGConstants.ATTRIBUTE_STROKE_LINECAP_VALUE_ROUND.Equals(linecap)) { this.mPaint.StrokeCap = Paint.Cap.Round; } else if (SVGConstants.ATTRIBUTE_STROKE_LINECAP_VALUE_SQUARE.Equals(linecap)) { this.mPaint.StrokeCap = Paint.Cap.Square; } else if (SVGConstants.ATTRIBUTE_STROKE_LINECAP_VALUE_BUTT.Equals(linecap)) { this.mPaint.StrokeCap = Paint.Cap.Butt; } string linejoin = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STROKE_LINEJOIN_VALUE_); if (SVGConstants.ATTRIBUTE_STROKE_LINEJOIN_VALUE_MITER.Equals(linejoin)) { this.mPaint.StrokeJoin = Paint.Join.Miter; } else if (SVGConstants.ATTRIBUTE_STROKE_LINEJOIN_VALUE_ROUND.Equals(linejoin)) { this.mPaint.StrokeJoin = Paint.Join.Round; } else if (SVGConstants.ATTRIBUTE_STROKE_LINEJOIN_VALUE_BEVEL.Equals(linejoin)) { this.mPaint.StrokeJoin = Paint.Join.Bevel; } return true; }
bool isStrokeNone(SVGProperties pSVGProperties) { return SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STROKE)); }