示例#1
0
        private void ParseTranslate(StringPtr ptr)
        {
            if (ptr.String.StartsWith("translate"))
            {
                ptr += 9;

                ptr.AdvanceWhiteSpace();
                if (ptr.Char == '(')
                {
                    ++ptr;
                    ptr.AdvanceWhiteSpace();

                    var tx = ParseNumber(ptr).Value;

                    var current = ptr.Index;
                    this.ParseCommaOrWhitespace(ptr);

                    var ty = ParseNumber(ptr);
                    if (ty.HasValue)
                    {
                        this.ParseCommaOrWhitespace(ptr);

                        ptr.AdvanceWhiteSpace();
                        if (ptr.Char == ')')
                        {
                            ++ptr;
                            this.Transforms.Add(SvgTransform.CreateTranslate(tx, ty.Value));
                            return;
                        }
                    }
                    else
                    {
                        ptr.Index = current;

                        ptr.AdvanceWhiteSpace();
                        if (ptr.Char == ')')
                        {
                            ++ptr;
                            this.Transforms.Add(SvgTransform.CreateTranslate(tx, 0.0F));
                            return;
                        }
                    }
                }
                throw new ArgumentException("transformData");
            }
        }
示例#2
0
        internal SvgUseElement(INode parent, XmlElement element)
            : base(parent, element)
        {
            this._stylableHelper      = new SvgStylableHelper(this, element);
            this._transformableHelper = new SvgTransformableHelper(element);

            var nan = new SvgLength(SvgLength.SvgLengthType.Unknown, float.NaN);

            this.X      = element.ParseCoordinate("x", nan);
            this.Y      = element.ParseCoordinate("y", nan);
            this.Width  = element.ParseLength("width", nan);
            this.Height = element.ParseLength("height", nan);
            this.Href   = element.GetAttribute("xlink:href").Substring(1);

            var child = (SvgElement)this.OwnerDocument.GetElementById(this.Href).CloneNode(true);

            if (child.GetType() == typeof(SvgSymbolElement))
            {
                throw new NotImplementedException();
            }
            else if (child.GetType() == typeof(SvgRectElement))
            {
                var casted = (SvgRectElement)child;
                if (this.Width.UnitType != SvgLength.SvgLengthType.Unknown)
                {
                    casted.Width = this.Width;
                }
                if (this.Height.UnitType != SvgLength.SvgLengthType.Unknown)
                {
                    casted.Height = this.Height;
                }
            }
            this.InstanceRoot = child;

            if (this.X.UnitType != SvgLength.SvgLengthType.Unknown && this.Y.UnitType != SvgLength.SvgLengthType.Unknown)
            {
                this.Transform.Add(SvgTransform.CreateTranslate(
                                       this.X.UnitType != SvgLength.SvgLengthType.Unknown ? this.X.ValueAsPixel : 0.0F,
                                       this.Y.UnitType != SvgLength.SvgLengthType.Unknown ? this.Y.ValueAsPixel : 0.0F));
            }
        }
示例#3
0
        internal SvgUseElement(INode parent, XmlElement element)
            : base(parent, element)
        {
            this._stylableHelper      = new SvgStylableHelper(this, element);
            this._transformableHelper = new SvgTransformableHelper(element);

            var nan = new SvgLength(SvgLength.SvgLengthType.Unknown, float.NaN);

            this.X             = element.ParseCoordinate("x", nan);
            this.Y             = element.ParseCoordinate("y", nan);
            this.Width         = element.ParseLength("width", nan);
            this.Height        = element.ParseLength("height", nan);
            this.Href          = element.GetAttributeNS("http://www.w3.org/1999/xlink", "href").Substring(1);
            this._instanceRoot = new Lazy <SvgElement>(this.CreateInstanceRoot, true);

            if (this.X.UnitType != SvgLength.SvgLengthType.Unknown && this.Y.UnitType != SvgLength.SvgLengthType.Unknown)
            {
                this.Transform.Add(SvgTransform.CreateTranslate(
                                       this.X.UnitType != SvgLength.SvgLengthType.Unknown ? this.X.ValueAsPixel : 0.0F,
                                       this.Y.UnitType != SvgLength.SvgLengthType.Unknown ? this.Y.ValueAsPixel : 0.0F));
            }
        }