コード例 #1
0
ファイル: SKSvg.cs プロジェクト: inforithmics/Svg.Skia
        public static SKPicture?ToPicture(SvgFragment svgFragment)
        {
            var picture = SvgModelExtensions.ToModel(svgFragment, _assetLoader);

            return(picture?.ToSKPicture());
        }
コード例 #2
0
        public void Execute(GeneratorExecutionContext context)
        {
            try
            {
                context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.NamespaceName", out var globalNamespaceName);

                var files = context.AdditionalFiles.Where(at => at.Path.EndsWith(".svg", StringComparison.InvariantCultureIgnoreCase));

                foreach (var file in files)
                {
                    string?namespaceName = null;

                    if (!string.IsNullOrWhiteSpace(globalNamespaceName))
                    {
                        namespaceName = globalNamespaceName;
                    }

                    if (context.AnalyzerConfigOptions.GetOptions(file).TryGetValue("build_metadata.AdditionalFiles.NamespaceName", out var perFilenamespaceName))
                    {
                        if (!string.IsNullOrWhiteSpace(perFilenamespaceName))
                        {
                            namespaceName = perFilenamespaceName;
                        }
                    }

                    if (string.IsNullOrWhiteSpace(namespaceName))
                    {
                        namespaceName = "Svg";
                    }

                    context.AnalyzerConfigOptions.GetOptions(file).TryGetValue("build_metadata.AdditionalFiles.ClassName", out var className);

                    if (string.IsNullOrWhiteSpace(className))
                    {
                        className = CreateClassName(file.Path);
                    }

                    if (string.IsNullOrWhiteSpace(namespaceName))
                    {
                        context.ReportDiagnostic(Diagnostic.Create(s_errorDescriptor, Location.None, "The specified namespace name is invalid."));
                        return;
                    }

                    if (string.IsNullOrWhiteSpace(className))
                    {
                        context.ReportDiagnostic(Diagnostic.Create(s_errorDescriptor, Location.None, "The specified class name is invalid."));
                        return;
                    }

                    var svg = file.GetText(context.CancellationToken)?.ToString();
                    if (string.IsNullOrWhiteSpace(svg))
                    {
                        context.ReportDiagnostic(Diagnostic.Create(s_errorDescriptor, Location.None, "Svg file is null or empty."));
                        return;
                    }

                    var svgDocument = SvgModelExtensions.FromSvg(svg !);
                    if (svgDocument is { })
                    {
                        var picture = SvgModelExtensions.ToModel(svgDocument, _assetLoader);
                        if (picture is { } && picture.Commands is { })