/** * 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)); } }
public SVGGroup(SVGGroup pSVGroupParent, SVGProperties pSVGProperties, bool pHasTransform) { this.mSVGroupParent = pSVGroupParent; this.mSVGProperties = pSVGProperties; this.mHasTransform = pHasTransform; this.mHidden = (this.mSVGroupParent != null && this.mSVGroupParent.isHidden()) || this.isDisplayNone(); }
void applyColor(SVGProperties pSVGProperties, int pColor, bool pModeFill) { int c = (int)((ColorUtils.COLOR_MASK_32BIT_ARGB_RGB & pColor) | ColorUtils.COLOR_MASK_32BIT_ARGB_ALPHA); this.mPaint.Color = new Color(c); this.mPaint.Alpha = SVGPaint.parseAlpha(pSVGProperties, pModeFill); }
public SVGProperties(SVGProperties pParentSVGProperties, Attributes pAttributes, bool pAttributesDeepCopy) { this.mAttributes = (pAttributesDeepCopy) ? new Attributes(pAttributes) : pAttributes; this.mAttributes = pAttributes; this.mParentSVGProperties = pParentSVGProperties; var styleAttr = pAttributes.GetStringAttribute (SVGConstants.ATTRIBUTE_STYLE); if (styleAttr != null) mSVGStyleSet = new SVGStyleSet (styleAttr); }
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)); }
public bool setStroke(SVGProperties pSVGProperties) { if(this.isDisplayNone(pSVGProperties) || this.isStrokeNone(pSVGProperties)) { return false; } this.resetPaint(Paint.Style.Stroke); return this.applyPaintProperties(pSVGProperties, false); }
public bool setStroke(SVGProperties pSVGProperties) { if (this.isDisplayNone(pSVGProperties) || this.isStrokeNone(pSVGProperties)) { return(false); } this.resetPaint(Paint.Style.Stroke); return(this.applyPaintProperties(pSVGProperties, false)); }
void parseRect(Attributes pAttributes) { SVGProperties svgProperties = this.getSVGPropertiesFromAttributes(pAttributes); bool pushed = this.pushTransform(pAttributes); SVGRectParser.parse(svgProperties, this.mCanvas, this.mSVGPaint, this.mRect); if (pushed) { this.popTransform(); } }
public SVGProperties(SVGProperties pParentSVGProperties, Attributes pAttributes, bool pAttributesDeepCopy) { this.mAttributes = (pAttributesDeepCopy) ? new Attributes(pAttributes) : pAttributes; this.mAttributes = pAttributes; this.mParentSVGProperties = pParentSVGProperties; var styleAttr = pAttributes.GetStringAttribute(SVGConstants.ATTRIBUTE_STYLE); if (styleAttr != null) { mSVGStyleSet = new SVGStyleSet(styleAttr); } }
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); } } }
void parseText(Attributes pAttributes, string text) { if (pAttributes == null) { return; } SVGProperties svgProperties = this.getSVGPropertiesFromAttributes(pAttributes); bool pushed = this.pushTransform(pAttributes); SVGTextParser.Parse(svgProperties, this.mCanvas, this.mSVGPaint, text); if (pushed) { this.popTransform(); } }
static int parseAlpha(SVGProperties pSVGProperties, bool pModeFill) { float?opacity = pSVGProperties.getFloatProperty(SVGConstants.ATTRIBUTE_OPACITY); if (opacity == null) { opacity = pSVGProperties.getFloatProperty(pModeFill ? SVGConstants.ATTRIBUTE_FILL_OPACITY : SVGConstants.ATTRIBUTE_STROKE_OPACITY); } if (opacity == null) { return(255); } else { return((int)(255 * opacity)); } }
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 bool applyPaintProperties(SVGProperties pSVGProperties, bool pModeFill) { if (this.setColorProperties(pSVGProperties, pModeFill)) { if (pModeFill) { return(this.applyFillProperties(pSVGProperties)); } else { return(this.applyStrokeProperties(pSVGProperties)); } } else { return(false); } }
/** * 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); }
Color?parseColor(string pString) { /* TODO Test if explicit pattern matching is faster: * * RGB: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/ * #RRGGBB: /^(\w{2})(\w{2})(\w{2})$/ * #RGB: /^(\w{1})(\w{1})(\w{1})$/ */ Color?parsedColor; if (pString == null) { parsedColor = null; } else if (SVGProperties.isHexProperty(pString)) { parsedColor = SVGParserUtils.extractColorFromHexProperty(pString); } else if (SVGProperties.isRgbProperty(pString)) { parsedColor = SVGParserUtils.extractColorFromRGBProperty(pString); } else { Color?colorByName = ColorUtils.GetColorByName(pString.Trim()); if (colorByName != null) { parsedColor = colorByName; } else { parsedColor = SVGParserUtils.extraColorIntegerProperty(pString); } } return(this.applySVGColorMapper(parsedColor.Value)); }
public SVGProperties(SVGProperties pParentSVGProperties, Attributes pAttributes, bool pAttributesDeepCopy) { this.mAttributes = (pAttributesDeepCopy) ? new Attributes(pAttributes) : pAttributes; this.mAttributes = pAttributes; this.mParentSVGProperties = pParentSVGProperties; var styleAttr = pAttributes.GetStringAttribute(SVGConstants.ATTRIBUTE_STYLE); if (styleAttr != null) { mSVGStyleSet = new SVGStyleSet(styleAttr); } foreach (string skey in styleattributes.Split(';')) { if (!pAttributes.ContainsKey(skey)) { continue; } if (styleAttr != null) { mSVGStyleSet = new SVGStyleSet(); } mSVGStyleSet.AddStyleAttribute(skey, pAttributes[skey]); } }
void applyColor(SVGProperties pSVGProperties, int pColor, bool pModeFill) { int c = (int)((ColorUtils.COLOR_MASK_32BIT_ARGB_RGB & pColor) | ColorUtils.COLOR_MASK_32BIT_ARGB_ALPHA); this.mPaint.Color = new Color (c); this.mPaint.Alpha = SVGPaint.parseAlpha(pSVGProperties, pModeFill); }
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; } } }
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 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; } } }
bool isDisplayNone(SVGProperties pSVGProperties) { return SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_DISPLAY)); }
bool applyFillProperties(SVGProperties pSVGProperties) { return true; }
bool isFillNone(SVGProperties pSVGProperties) { return SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_FILL)); }
bool applyFillProperties(SVGProperties pSVGProperties) { return(true); }
bool isStrokeNone(SVGProperties pSVGProperties) { return(SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STROKE))); }
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))); }
static int parseAlpha(SVGProperties pSVGProperties, bool pModeFill) { float? opacity = pSVGProperties.getFloatProperty(SVGConstants.ATTRIBUTE_OPACITY); if(opacity == null) { opacity = pSVGProperties.getFloatProperty(pModeFill ? SVGConstants.ATTRIBUTE_FILL_OPACITY : SVGConstants.ATTRIBUTE_STROKE_OPACITY); } if(opacity == null) { return 255; } else { return (int) (255 * opacity); } }
public bool applyPaintProperties(SVGProperties pSVGProperties, bool pModeFill) { if(this.setColorProperties(pSVGProperties, pModeFill)) { if(pModeFill) { return this.applyFillProperties(pSVGProperties); } else { return this.applyStrokeProperties(pSVGProperties); } } else { return false; } }
public SVGGroup(SVGGroup pSVGroupParent, SVGProperties pSVGProperties, bool pHasTransform) { this.mSVGroupParent = pSVGroupParent; this.mSVGProperties = pSVGProperties; this.mHasTransform = pHasTransform; this.mHidden = (this.mSVGroupParent != null && this.mSVGroupParent.isHidden()) || this.isDisplayNone(); }