Example #1
0
        /**
         *  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));
            }
        }
Example #2
0
 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();
 }
Example #3
0
        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);
        }
Example #4
0
		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);
		}
Example #5
0
        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));
        }
Example #6
0
		public bool setStroke(SVGProperties pSVGProperties) {
			if(this.isDisplayNone(pSVGProperties) || this.isStrokeNone(pSVGProperties)) {
				return false;
			}

			this.resetPaint(Paint.Style.Stroke);

			return this.applyPaintProperties(pSVGProperties, false);
		}
Example #7
0
        public bool setStroke(SVGProperties pSVGProperties)
        {
            if (this.isDisplayNone(pSVGProperties) || this.isStrokeNone(pSVGProperties))
            {
                return(false);
            }

            this.resetPaint(Paint.Style.Stroke);

            return(this.applyPaintProperties(pSVGProperties, false));
        }
Example #8
0
        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();
            }
        }
Example #9
0
        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);
            }
        }
Example #10
0
        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);
                }
            }
        }
Example #11
0
        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();
            }
        }
Example #12
0
        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));
            }
        }
Example #13
0
        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);
                }
            }
        }
Example #14
0
 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);
     }
 }
Example #15
0
		/**
		 *  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);
			}
		}
Example #16
0
        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);
        }
Example #17
0
        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));
        }
Example #18
0
        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]);
            }
        }
Example #19
0
		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);
		}
Example #20
0
		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;
				}
			}
		}
Example #21
0
		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);
		}
Example #22
0
		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;
		}
Example #23
0
		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;
				}
			}
		}
Example #24
0
		bool isDisplayNone(SVGProperties pSVGProperties) {
			return SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_DISPLAY));
		}
Example #25
0
		bool applyFillProperties(SVGProperties pSVGProperties) {
			return true;
		}
Example #26
0
		bool isFillNone(SVGProperties pSVGProperties) {
			return SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_FILL));
		}
Example #27
0
 bool applyFillProperties(SVGProperties pSVGProperties)
 {
     return(true);
 }
Example #28
0
 bool isStrokeNone(SVGProperties pSVGProperties)
 {
     return(SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STROKE)));
 }
Example #29
0
		bool isStrokeNone(SVGProperties pSVGProperties) {
			return SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_STROKE));
		}
Example #30
0
 bool isFillNone(SVGProperties pSVGProperties)
 {
     return(SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_FILL)));
 }
Example #31
0
 bool isDisplayNone(SVGProperties pSVGProperties)
 {
     return(SVGConstants.VALUE_NONE.Equals(pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_DISPLAY)));
 }
Example #32
0
		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);
			}
		}
Example #33
0
		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;
			}
		}
Example #34
0
		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();
		}