예제 #1
0
 public static object UnsafeGetController(SvgElement elem)
 {
     return(elem._controller);
 }
예제 #2
0
        VgVisualElement CreateTextElem(VgVisualElement parentNode, SvgElement elem, SvgTextSpec textspec)
        {
            //text render element
            VgVisualElement vgVisElem = new VgVisualElement(WellknownSvgElementName.Text, textspec, _vgVisualDoc);

            vgVisElem.DomElem = elem;
            //some att

            if (textspec.Class != null && _activeSheet1 != null)
            {
                //resolve style definition
                LayoutFarm.WebDom.CssRuleSetGroup ruleSetGroup = _activeSheet1.GetRuleSetForClassName(textspec.Class);
                if (ruleSetGroup != null)
                {
                    //assign
                    foreach (LayoutFarm.WebDom.CssPropertyDeclaration propDecl in ruleSetGroup.GetPropertyDeclIter())
                    {
                        switch (propDecl.WellknownPropertyName)
                        {
                        case LayoutFarm.WebDom.WellknownCssPropertyName.Font:
                            //set font detail
                            break;

                        case LayoutFarm.WebDom.WellknownCssPropertyName.FontStyle:
                            //convert font style
                            break;

                        case LayoutFarm.WebDom.WellknownCssPropertyName.FontSize:
                            textspec.FontSize = propDecl.GetPropertyValue(0).AsLength();
                            break;

                        case LayoutFarm.WebDom.WellknownCssPropertyName.FontFamily:
                            textspec.FontFace = propDecl.GetPropertyValue(0).ToString();
                            break;

                        case LayoutFarm.WebDom.WellknownCssPropertyName.Fill:
                            textspec.FillColor = LayoutFarm.WebDom.Parser.CssValueParser.ParseCssColor(propDecl.GetPropertyValue(0).ToString());
                            break;

                        case LayoutFarm.WebDom.WellknownCssPropertyName.Unknown:
                        {
                            switch (propDecl.UnknownRawName)
                            {
                            case "fill":
                                //svg
                                break;
                            }
                        }
                        break;
                        }
                    }
                }
            }


            ReEvaluateArgs a = new ReEvaluateArgs(_containerWidth, _containerHeight, _emHeight); //temp fix

            textspec.ActualX = ConvertToPx(textspec.X, ref a);
            textspec.ActualY = ConvertToPx(textspec.Y, ref a);


            AssignAttributes(textspec);

            //text x,y


            parentNode.AddChildElement(vgVisElem);
            return(vgVisElem);
        }
예제 #3
0
        VgVisualElement CreateSvgVisualElement(VgVisualElement parentNode, SvgElement elem)
        {
            VgVisualElement vgVisElem        = null;
            bool            skipChildrenNode = false;

            switch (elem.WellknowElemName)
            {
            default:
                throw new NotSupportedException();

            //-----------------
            case WellknownSvgElementName.Unknown:
                return(null);

            case WellknownSvgElementName.FeColorMatrix:
                vgVisElem = CreateFeColorMatrix(parentNode, elem, (SvgFeColorMatrixSpec)elem.ElemSpec);    //no more child
                parentNode.AddChildElement(vgVisElem);
                return(vgVisElem);

            case WellknownSvgElementName.Filter:
                vgVisElem = CreateFilterElem(parentNode, elem, (SvgFilterSpec)elem.ElemSpec);
                break;

            case WellknownSvgElementName.RadialGradient:
                //TODO: add radial grapdient support
                //this version not support linear gradient
                return(CreateRadialGradient(parentNode, elem, (SvgRadialGradientSpec)elem.ElemSpec));

            case WellknownSvgElementName.LinearGradient:
                //TODO: add linear grapdient support
                //this version not support linear gradient
                return(CreateLinearGradient(parentNode, elem, (SvgLinearGradientSpec)elem.ElemSpec));

            case WellknownSvgElementName.Defs:
                _defsList.Add(elem);
                return(null);

            case WellknownSvgElementName.Style:
                _styleList.Add(elem);
                return(null);

            case WellknownSvgElementName.Marker:
                vgVisElem = CreateMarker(parentNode, (SvgMarkerSpec)elem.ElemSpec);
                break;

            case WellknownSvgElementName.Mask:
                vgVisElem = CreateMask(parentNode, (SvgMaskSpec)elem.ElemSpec);
                break;

            case WellknownSvgElementName.Svg:
                vgVisElem = new VgVisualElement(WellknownSvgElementName.Svg, (SvgVisualSpec)elem.ElemSpec, _vgVisualDoc);
                break;

            case WellknownSvgElementName.Rect:
                vgVisElem = CreateRect(parentNode, (SvgRectSpec)elem.ElemSpec);
                break;

            case WellknownSvgElementName.Image:
                vgVisElem = CreateImage(parentNode, (SvgImageSpec)elem.ElemSpec);
                break;

            case WellknownSvgElementName.Polyline:
                vgVisElem = CreatePolyline(parentNode, (SvgPolylineSpec)elem.ElemSpec);
                break;

            case WellknownSvgElementName.Polygon:
                vgVisElem = CreatePolygon(parentNode, (SvgPolygonSpec)elem.ElemSpec);
                break;

            case WellknownSvgElementName.Ellipse:
                vgVisElem = CreateEllipse(parentNode, (SvgEllipseSpec)elem.ElemSpec);
                break;

            case WellknownSvgElementName.Circle:
                vgVisElem = CreateCircle(parentNode, (SvgCircleSpec)elem.ElemSpec);
                break;

            case WellknownSvgElementName.Line:
                vgVisElem = CreateLine(parentNode, (SvgLineSpec)elem.ElemSpec);
                break;

            case WellknownSvgElementName.ClipPath:
                vgVisElem = CreateClipPath(parentNode, (SvgVisualSpec)elem.ElemSpec);
                break;

            case WellknownSvgElementName.Group:
                vgVisElem = CreateGroup(parentNode, (SvgVisualSpec)elem.ElemSpec);
                break;

            //---------------------------------------------
            case WellknownSvgElementName.Path:
                vgVisElem        = CreatePath(parentNode, (SvgPathSpec)elem.ElemSpec, elem);
                skipChildrenNode = true;    //***
                break;

            case WellknownSvgElementName.Text:
                vgVisElem        = CreateTextElem(parentNode, elem, (SvgTextSpec)elem.ElemSpec);
                skipChildrenNode = true;    //***
                break;

            case WellknownSvgElementName.Use:
                vgVisElem        = CreateUseElement(parentNode, (SvgUseSpec)elem.ElemSpec);
                skipChildrenNode = true;
                break;
            }

            if (vgVisElem == null)
            {
                //TODO: review here
                return(null);
            }
            //-----------------------------------
            vgVisElem.DomElem = elem;
            if (elem.ElemId != null)
            {
                //replace duplicated item ???
                _registeredElemsById[elem.ElemId] = vgVisElem;
            }

            vgVisElem.SetController(elem);


#if DEBUG
            if (skipChildrenNode && !vgVisElem.dbugHasParent)
            {
            }
#endif
            //-----------------------------------
            if (!skipChildrenNode)
            {
                parentNode.AddChildElement(vgVisElem);
                int childCount = elem.ChildCount;
                for (int i = 0; i < childCount; ++i)
                {
                    CreateSvgVisualElement(vgVisElem, elem.GetChild(i));
                }
            }

            return(vgVisElem);
        }
예제 #4
0
        VgVisualElement CreateLinearGradient(VgVisualElement parentNode, SvgElement elem, SvgLinearGradientSpec spec)
        {
            //https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient

            //Categories Gradient element
            //Permitted content Any number of the following elements, in any order:
            //Descriptive elements
            //<animate>, <animateTransform>, <set>, <stop>

            //Attributes
            //Section
            //Global attributes
            //Section

            //    Core attributes
            //    Presentation attributes
            //    Xlink attributes
            //    class
            //    style
            //    externalResourcesRequired

            //Specific attributes
            //Section

            //    gradientUnits
            //    gradientTransform
            //    x1
            //    y1
            //    x2
            //    y2
            //    spreadMethod
            //    xlink:href



            VgVisualElement linearGrd = new VgVisualElement(WellknownSvgElementName.LinearGradient, spec, _vgVisualDoc);

            //read attribute
            RegisterElementById(elem, linearGrd);
            int childCount = elem.ChildCount;

            for (int i = 0; i < childCount; ++i)
            {
                SvgElement child = elem.GetChild(i);
                if (child.ElemName == "stop")
                {
                    //color stop
                    //TODO: implement this....
                    SvgColorStopSpec stopSpec = child.ElemSpec as SvgColorStopSpec;
                    if (stopSpec != null)
                    {
                        if (spec.StopList == null)
                        {
                            //TODO
                            spec.StopList = new List <SvgColorStopSpec>();
                        }
                        spec.StopList.Add(stopSpec);
                    }
                }
                else
                {
                }
            }

            return(linearGrd);
        }
예제 #5
0
 public static object UnsafeGetController(SvgElement elem) => elem._controller;