Example #1
0
 public CssBoxSvgRoot(Css.BoxSpec spec, RootGraphic rootgfx, SvgElement svgElem)
     : base(spec, rootgfx, Css.CssDisplay.Block)
 {
     SetAsCustomCssBox(this);
     //create svg node 
     this.SvgSpec = svgElem;
     ChangeDisplayType(this, Css.CssDisplay.Block);
 }
Example #2
0
 public void AddChild(SvgElement child)
 {
     if (this.children == null)
     {
         this.children = new LinkedList<SvgElement>();
     }
     child.linkedNode = this.children.AddLast(child);
     child.parent = this;
 }
 public static void HitTestCore(SvgElement root, SvgHitChain chain, float x, float y)
 {
     //1. 
     chain.AddHit(root, x, y);
     //2. find hit child
     var child = root.GetFirstNode();
     while (child != null)
     {
         var node = child.Value;
         if (node.HitTestCore(chain, x, y))
         {
             break;
         }
         child = child.Next;
     }
 }
Example #4
0
 public void AddHit(SvgElement svg, float x, float y)
 {
     svgList.Add(new SvgHitInfo(svg, x, y));
 }
Example #5
0
 public SvgHitInfo(SvgElement svg, float x, float y)
 {
     this.svg = svg;
     this.x   = x;
     this.y   = y;
 }
Example #6
0
 public void AddHit(SvgElement svg, float x, float y)
 {
     svgList.Add(new SvgHitInfo(svg, x, y));
 }
Example #7
0
        static void CreateSvgPath(SvgElement parentNode, HtmlElement elem)
        {
            SvgPathSpec spec    = new SvgPathSpec();
            SvgPath     svgPath = new SvgPath(spec, elem);

            parentNode.AddChild(svgPath);
            foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward())
            {
                WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex;
                switch (wellknownName)
                {
                case WebDom.WellknownName.Svg_X:
                {
                    spec.X = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Y:
                {
                    spec.Y = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WebDom.WellknownName.Width:
                {
                    spec.Width = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WebDom.WellknownName.Height:
                {
                    spec.Height = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Fill:
                {
                    spec.ActualColor = CssValueParser.GetActualColor(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Stroke:
                {
                    spec.StrokeColor = CssValueParser.GetActualColor(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Stroke_Width:
                {
                    spec.StrokeWidth = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Transform:
                {
                    //TODO: parse svg transform function
                }
                break;

                default:
                {
                    //other attrs
                    switch (attr.Name)
                    {
                    case "d":
                    {
                        //parse vertex commands
                        Svg.Pathing.SvgPathDataParser parser = new Svg.Pathing.SvgPathDataParser();
                        svgPath.Segments = parser.Parse(attr.Value.ToCharArray());
                    }
                    break;
                    }
                }
                break;
                }
            }
        }
Example #8
0
        static void CreateSvgBoxContent(
            SvgElement parentElement,
            HtmlElement elementNode)
        {
            int j = elementNode.ChildrenCount;

            for (int i = 0; i < j; ++i)
            {
                HtmlElement node = elementNode.GetChildNode(i) as HtmlElement;
                if (node == null)
                {
                    continue;
                }
                switch (node.WellknownElementName)
                {
                case WellKnownDomNodeName.svg_rect:
                {
                    CreateSvgRect(parentElement, node);
                }
                break;

                case WellKnownDomNodeName.svg_circle:
                {
                    //sample circle from
                    //www.svgbasics.com/shapes.html
                    CreateSvgCircle(parentElement, node);
                }
                break;

                case WellKnownDomNodeName.svg_ellipse:
                {
                    CreateSvgEllipse(parentElement, node);
                }
                break;

                case WellKnownDomNodeName.svg_polygon:
                {
                    CreateSvgPolygon(parentElement, node);
                }
                break;

                case WellKnownDomNodeName.svg_polyline:
                {
                    CreateSvgPolyline(parentElement, node);
                }
                break;

                case WellKnownDomNodeName.svg_defs:
                {
                    CreateSvgDefs(parentElement, node);
                }
                break;

                case WellKnownDomNodeName.svg_linearGradient:
                {
                    CreateSvgLinearGradient(parentElement, node);
                }
                break;

                case WellKnownDomNodeName.svg_path:
                {
                    CreateSvgPath(parentElement, node);
                }
                break;

                case WellKnownDomNodeName.svg_image:
                {
                    CreateSvgImage(parentElement, node);
                }
                break;

                case WellKnownDomNodeName.svg_g:
                {
                    CreateSvgGroupElement(parentElement, node);
                }
                break;

                default:
                {
                }
                break;
                }
            }
        }
Example #9
0
 static void CreateSvgPolyline(SvgElement parentNode, HtmlElement elem)
 {
     SvgPolylineSpec spec = new SvgPolylineSpec();
     SvgPolyline shape = new SvgPolyline(spec, elem);
     parentNode.AddChild(shape);
     foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward())
     {
         WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex;
         switch (wellknownName)
         {
             case WebDom.WellknownName.Svg_Points:
                 {
                     //parse points
                     spec.Points = ParsePointList(attr.Value);
                 }
                 break;
             case WebDom.WellknownName.Svg_Fill:
                 {
                     spec.ActualColor = CssValueParser.GetActualColor(attr.Value);
                 }
                 break;
             case WebDom.WellknownName.Svg_Stroke:
                 {
                     spec.StrokeColor = CssValueParser.GetActualColor(attr.Value);
                 }
                 break;
             case WebDom.WellknownName.Svg_Stroke_Width:
                 {
                     spec.StrokeWidth = UserMapUtil.ParseGenericLength(attr.Value);
                 }
                 break;
             case WebDom.WellknownName.Svg_Transform:
                 {
                     //TODO: parse svg transform function  
                 }
                 break;
             default:
                 {
                     //other attrs
                 }
                 break;
         }
     }
 }
Example #10
0
 static void CreateSvgBoxContent(
   SvgElement parentElement,
   HtmlElement elementNode)
 {
     int j = elementNode.ChildrenCount;
     for (int i = 0; i < j; ++i)
     {
         HtmlElement node = elementNode.GetChildNode(i) as HtmlElement;
         if (node == null)
         {
             continue;
         }
         switch (node.WellknownElementName)
         {
             case WellKnownDomNodeName.svg_rect:
                 {
                     CreateSvgRect(parentElement, node);
                 }
                 break;
             case WellKnownDomNodeName.svg_circle:
                 {
                     //sample circle from 
                     //www.svgbasics.com/shapes.html
                     CreateSvgCircle(parentElement, node);
                 }
                 break;
             case WellKnownDomNodeName.svg_ellipse:
                 {
                     CreateSvgEllipse(parentElement, node);
                 }
                 break;
             case WellKnownDomNodeName.svg_polygon:
                 {
                     CreateSvgPolygon(parentElement, node);
                 }
                 break;
             case WellKnownDomNodeName.svg_polyline:
                 {
                     CreateSvgPolyline(parentElement, node);
                 }
                 break;
             case WellKnownDomNodeName.svg_defs:
                 {
                     CreateSvgDefs(parentElement, node);
                 }
                 break;
             case WellKnownDomNodeName.svg_linearGradient:
                 {
                     CreateSvgLinearGradient(parentElement, node);
                 }
                 break;
             case WellKnownDomNodeName.svg_path:
                 {
                     CreateSvgPath(parentElement, node);
                 }
                 break;
             case WellKnownDomNodeName.svg_image:
                 {
                     CreateSvgImage(parentElement, node);
                 }
                 break;
             case WellKnownDomNodeName.svg_g:
                 {
                     CreateSvgGroupElement(parentElement, node);
                 }
                 break;
             default:
                 {
                 }
                 break;
         }
     }
 }
Example #11
0
        static void CreateSvgLinearGradient(SvgElement parentNode, HtmlElement elem)
        {
            //linear gradient definition

            SvgLinearGradient linearGradient = new SvgLinearGradient(elem);
            foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward())
            {
                WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex;
                switch (wellknownName)
                {
                    case WellknownName.Svg_X1:
                        {
                            linearGradient.X1 = UserMapUtil.ParseGenericLength(attr.Value);
                        }
                        break;
                    case WellknownName.Svg_X2:
                        {
                            linearGradient.X2 = UserMapUtil.ParseGenericLength(attr.Value);
                        }
                        break;
                    case WellknownName.Svg_Y1:
                        {
                            linearGradient.Y1 = UserMapUtil.ParseGenericLength(attr.Value);
                        }
                        break;
                    case WellknownName.Svg_Y2:
                        {
                            linearGradient.Y2 = UserMapUtil.ParseGenericLength(attr.Value);
                        }
                        break;
                }
            }
            //------------------------------------------------------------
            int j = elem.ChildrenCount;
            List<StopColorPoint> stopColorPoints = new List<StopColorPoint>(j);
            for (int i = 0; i < j; ++i)
            {
                HtmlElement node = elem.GetChildNode(i) as HtmlElement;
                if (node == null)
                {
                    continue;
                }
                switch (node.WellknownElementName)
                {
                    case WellKnownDomNodeName.svg_stop:
                        {
                            //stop point
                            StopColorPoint stopPoint = new StopColorPoint();
                            foreach (WebDom.DomAttribute attr in node.GetAttributeIterForward())
                            {
                                WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex;
                                switch (wellknownName)
                                {
                                    case WellknownName.Svg_StopColor:
                                        {
                                            stopPoint.StopColor = CssValueParser.GetActualColor(attr.Value);
                                        }
                                        break;
                                    case WellknownName.Svg_Offset:
                                        {
                                            stopPoint.Offset = UserMapUtil.ParseGenericLength(attr.Value);
                                        }
                                        break;
                                }
                            }
                            stopColorPoints.Add(stopPoint);
                        }
                        break;
                }
            }
        }
Example #12
0
 static void CreateSvgDefs(SvgElement parentNode, HtmlElement elem)
 {
     //inside single definition
     SvgDefinitionList svgDefList = new SvgDefinitionList(elem);
     parentNode.AddChild(svgDefList);
     CreateSvgBoxContent(svgDefList, elem);
 }
Example #13
0
        static void CreateSvgGroupElement(SvgElement parentNode, HtmlElement elem)
        {
            SvgVisualSpec spec = new SvgVisualSpec();
            SvgGroupElement svgGroupElement = new SvgGroupElement(spec, elem);
            parentNode.AddChild(svgGroupElement);
            foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward())
            {
                WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex;
                switch (wellknownName)
                {
                    case WebDom.WellknownName.Svg_Fill:
                        {
                            spec.ActualColor = CssValueParser.GetActualColor(attr.Value);
                        }
                        break;
                    case WebDom.WellknownName.Svg_Stroke:
                        {
                            spec.StrokeColor = CssValueParser.GetActualColor(attr.Value);
                        }
                        break;
                    case WebDom.WellknownName.Svg_Stroke_Width:
                        {
                            spec.StrokeWidth = UserMapUtil.ParseGenericLength(attr.Value);
                        }
                        break;
                    default:
                        {
                            //other attrs
                        }
                        break;
                }
            }

            CreateSvgBoxContent(svgGroupElement, elem);
        }
Example #14
0
 public SvgHitInfo(SvgElement svg, float x, float y)
 {
     this.svg = svg;
     this.x = x;
     this.y = y;
 }
Example #15
0
        static void CreateSvgPath(SvgElement parentNode, HtmlElement elem)
        {
            SvgPathSpec spec = new SvgPathSpec();
            SvgPath svgPath = new SvgPath(spec, elem);
            parentNode.AddChild(svgPath);
            foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward())
            {
                WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex;
                switch (wellknownName)
                {
                    case WebDom.WellknownName.Svg_X:
                        {
                            spec.X = UserMapUtil.ParseGenericLength(attr.Value);
                        }
                        break;
                    case WebDom.WellknownName.Svg_Y:
                        {
                            spec.Y = UserMapUtil.ParseGenericLength(attr.Value);
                        }
                        break;
                    case WebDom.WellknownName.Width:
                        {
                            spec.Width = UserMapUtil.ParseGenericLength(attr.Value);
                        }
                        break;
                    case WebDom.WellknownName.Height:
                        {
                            spec.Height = UserMapUtil.ParseGenericLength(attr.Value);
                        }
                        break;
                    case WebDom.WellknownName.Svg_Fill:
                        {
                            spec.ActualColor = CssValueParser.GetActualColor(attr.Value);
                        }
                        break;
                    case WebDom.WellknownName.Svg_Stroke:
                        {
                            spec.StrokeColor = CssValueParser.GetActualColor(attr.Value);
                        }
                        break;
                    case WebDom.WellknownName.Svg_Stroke_Width:
                        {
                            spec.StrokeWidth = UserMapUtil.ParseGenericLength(attr.Value);
                        }
                        break;
                    case WebDom.WellknownName.Svg_Transform:
                        {
                            //TODO: parse svg transform function   


                        }
                        break;
                    default:
                        {
                            //other attrs
                            switch (attr.Name)
                            {
                                case "d":
                                    {
                                        //parse vertex commands 
                                        Svg.Pathing.SvgPathDataParser parser = new Svg.Pathing.SvgPathDataParser();
                                        svgPath.Segments = parser.Parse(attr.Value.ToCharArray());
                                    }
                                    break;
                            }
                        }
                        break;
                }
            }
        }
Example #16
0
        static void CreateSvgLinearGradient(SvgElement parentNode, HtmlElement elem)
        {
            //linear gradient definition

            SvgLinearGradient linearGradient = new SvgLinearGradient(elem);

            foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward())
            {
                WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex;
                switch (wellknownName)
                {
                case WellknownName.Svg_X1:
                {
                    linearGradient.X1 = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WellknownName.Svg_X2:
                {
                    linearGradient.X2 = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WellknownName.Svg_Y1:
                {
                    linearGradient.Y1 = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WellknownName.Svg_Y2:
                {
                    linearGradient.Y2 = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;
                }
            }
            //------------------------------------------------------------
            int j = elem.ChildrenCount;
            List <StopColorPoint> stopColorPoints = new List <StopColorPoint>(j);

            for (int i = 0; i < j; ++i)
            {
                HtmlElement node = elem.GetChildNode(i) as HtmlElement;
                if (node == null)
                {
                    continue;
                }
                switch (node.WellknownElementName)
                {
                case WellKnownDomNodeName.svg_stop:
                {
                    //stop point
                    StopColorPoint stopPoint = new StopColorPoint();
                    foreach (WebDom.DomAttribute attr in node.GetAttributeIterForward())
                    {
                        WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex;
                        switch (wellknownName)
                        {
                        case WellknownName.Svg_StopColor:
                        {
                            stopPoint.StopColor = CssValueParser.GetActualColor(attr.Value);
                        }
                        break;

                        case WellknownName.Svg_Offset:
                        {
                            stopPoint.Offset = UserMapUtil.ParseGenericLength(attr.Value);
                        }
                        break;
                        }
                    }
                    stopColorPoints.Add(stopPoint);
                }
                break;
                }
            }
        }
Example #17
0
 static void CreateSvgImage(SvgElement parentNode, HtmlElement elem)
 {
     SvgImageSpec spec = new SvgImageSpec();
     SvgImage svgImage = new SvgImage(spec, elem);
     parentNode.AddChild(svgImage);
     foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward())
     {
         WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex;
         switch (wellknownName)
         {
             case WebDom.WellknownName.Svg_X:
                 {
                     spec.X = UserMapUtil.ParseGenericLength(attr.Value);
                 }
                 break;
             case WebDom.WellknownName.Svg_Y:
                 {
                     spec.Y = UserMapUtil.ParseGenericLength(attr.Value);
                 }
                 break;
             case WebDom.WellknownName.Width:
                 {
                     spec.Width = UserMapUtil.ParseGenericLength(attr.Value);
                 }
                 break;
             case WebDom.WellknownName.Height:
                 {
                     spec.Height = UserMapUtil.ParseGenericLength(attr.Value);
                 }
                 break;
             case WebDom.WellknownName.Svg_Fill:
                 {
                     spec.ActualColor = CssValueParser.GetActualColor(attr.Value);
                 }
                 break;
             case WebDom.WellknownName.Svg_Stroke:
                 {
                     spec.StrokeColor = CssValueParser.GetActualColor(attr.Value);
                 }
                 break;
             case WebDom.WellknownName.Svg_Stroke_Width:
                 {
                     spec.StrokeWidth = UserMapUtil.ParseGenericLength(attr.Value);
                 }
                 break;
             case WebDom.WellknownName.Svg_Transform:
                 {
                     //TODO: parse svg transform function    
                 }
                 break;
             case WellknownName.Href:
                 {
                     //image src***
                     spec.ImageSrc = attr.Value;
                 }
                 break;
             default:
                 {
                 }
                 break;
         }
     }
 }
Example #18
0
        static void CreateSvgEllipse(SvgElement parentNode, HtmlElement elem)
        {
            SvgEllipseSpec spec  = new SvgEllipseSpec();
            SvgEllipse     shape = new SvgEllipse(spec, elem);

            parentNode.AddChild(shape);
            foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward())
            {
                WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex;
                switch (wellknownName)
                {
                case WebDom.WellknownName.Svg_Cx:
                {
                    spec.X = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Cy:
                {
                    spec.Y = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WellknownName.Svg_Rx:
                {
                    spec.RadiusX = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WellknownName.Svg_Ry:
                {
                    spec.RadiusY = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Fill:
                {
                    spec.ActualColor = CssValueParser.GetActualColor(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Stroke:
                {
                    spec.StrokeColor = CssValueParser.GetActualColor(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Stroke_Width:
                {
                    spec.StrokeWidth = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Transform:
                {
                    //TODO: parse svg transform function
                }
                break;

                default:
                {
                    //other attrs
                }
                break;
                }
            }
        }
Example #19
0
 //--------------------------------
 public static object UnsafeGetController(SvgElement elem)
 {
     return(elem.controller);
 }
Example #20
0
        static void CreateSvgImage(SvgElement parentNode, HtmlElement elem)
        {
            SvgImageSpec spec     = new SvgImageSpec();
            SvgImage     svgImage = new SvgImage(spec, elem);

            parentNode.AddChild(svgImage);
            foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward())
            {
                WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex;
                switch (wellknownName)
                {
                case WebDom.WellknownName.Svg_X:
                {
                    spec.X = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Y:
                {
                    spec.Y = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WebDom.WellknownName.Width:
                {
                    spec.Width = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WebDom.WellknownName.Height:
                {
                    spec.Height = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Fill:
                {
                    spec.ActualColor = CssValueParser.GetActualColor(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Stroke:
                {
                    spec.StrokeColor = CssValueParser.GetActualColor(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Stroke_Width:
                {
                    spec.StrokeWidth = UserMapUtil.ParseGenericLength(attr.Value);
                }
                break;

                case WebDom.WellknownName.Svg_Transform:
                {
                    //TODO: parse svg transform function
                }
                break;

                case WellknownName.Href:
                {
                    //image src***
                    spec.ImageSrc = attr.Value;
                }
                break;

                default:
                {
                }
                break;
                }
            }
        }
Example #21
0
 //--------------------------------
 public static object UnsafeGetController(SvgElement elem)
 {
     return elem.controller;
 }