Example #1
0
        public Symbol(SvgSymbol svgSymbol)
        {
            x      = 0f;
            y      = 0f;
            width  = svgSymbol.ViewBox.Width;
            height = svgSymbol.ViewBox.Height;

            if (svgSymbol.CustomAttributes.TryGetValue("width", out string _widthString))
            {
                if (new SvgUnitConverter().ConvertFrom(_widthString) is SvgUnit _width)
                {
                    width = _width.ToDeviceValue(null, UnitRenderingType.Horizontal, svgSymbol);
                }
            }

            if (svgSymbol.CustomAttributes.TryGetValue("height", out string heightString))
            {
                if (new SvgUnitConverter().ConvertFrom(heightString) is SvgUnit _height)
                {
                    height = _height.ToDeviceValue(null, UnitRenderingType.Vertical, svgSymbol);
                }
            }

            bounds = SKRect.Create(x, y, width, height);

            matrix = SvgHelper.GetSKMatrix(svgSymbol.Transforms);
            var viewBoxMatrix = SvgHelper.GetSvgViewBoxTransform(svgSymbol.ViewBox, svgSymbol.AspectRatio, x, y, width, height);

            SKMatrix.Concat(ref matrix, ref matrix, ref viewBoxMatrix);
        }
Example #2
0
        private static void Main(string[] args)
        {
            Options options = null;

            Parser.Default.ParseArguments <Options>(args)
            .WithParsed(res => options = res)
            .WithNotParsed(err => Environment.Exit(1));

            var stopWatch = Stopwatch.StartNew();

            if (!File.Exists(options.FileName))
            {
                Console.WriteLine($"File {options.FileName} doesn't exist.");
                return;
            }

            Console.WriteLine($"Start parsing file: {options.FileName}");

            City city = null;

            try
            {
                using (var reader = new StreamReader(options.FileName))
                {
                    city = (City) new XmlSerializer(typeof(City)).Deserialize(reader);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(
                    $"Unable to parse osm file: {e.Message}. See about downloading here: https://github.com/bruce-willis/City-Roads/blob/develop/docs/download.md");
            }

            Console.WriteLine($"End parsing file. Spent time: {stopWatch.Elapsed}");

            SvgHelper.GenerateSvg(city, options);

            if (options.GenerateNodesList)
            {
                CsvHelper.WriteNodesInfo(options.OutputDirectory);
            }

            if (options.GenerateAdjacencyList)
            {
                CsvHelper.WriteAdjacencyList(options.OutputDirectory);
            }

            if (options.GenerateAdjacencyMatrix)
            {
                CsvHelper.WriteAdjacencyMatrix(options.OutputDirectory);
            }


            Console.WriteLine($"\nJob done! Now it's time for tea. Total time elapsed: {stopWatch.Elapsed}");
            Console.WriteLine(new Random().Next(0, 2) == 1
                ? "Лучший в СПбГУ - Факультет ПМ-ПУ"
                : "Ответ на главный вопрос жизни, вселенной и всего такого - 42");
        }
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            ComponentSettings.radius_2_Times = WidthAndHeight;


            ComponentSettings.radius_Origin      = WidthAndHeight / 2;
            ComponentSettings.radius_BigCircle   = ComponentSettings.radius_Origin * 0.9;
            ComponentSettings.radius_SmallCircle = ComponentSettings.radius_Origin * 0.6;
            ComponentSettings.CircleWidth        = ComponentSettings.radius_BigCircle - ComponentSettings.radius_SmallCircle;


            Initialize_Gradient();

            Generate_SVG();


            SvgHelper.Cmd_Render(_Svg, 0, builder);


            base.BuildRenderTree(builder);
        }
Example #4
0
        public Use(SvgUse svgUse, SvgVisualElement svgVisualElement)
        {
            matrix = SvgHelper.GetSKMatrix(svgUse.Transforms);

            float x = svgUse.X.ToDeviceValue(null, UnitRenderingType.Horizontal, svgUse);
            float y = svgUse.Y.ToDeviceValue(null, UnitRenderingType.Vertical, svgUse);

            var skMatrixTranslateXY = SKMatrix.MakeTranslation(x, y);

            SKMatrix.Concat(ref matrix, ref matrix, ref skMatrixTranslateXY);

            var ew = svgUse.Width.ToDeviceValue(null, UnitRenderingType.Horizontal, svgUse);
            var eh = svgUse.Height.ToDeviceValue(null, UnitRenderingType.Vertical, svgUse);

            if (ew > 0 && eh > 0)
            {
                var _attributes = svgVisualElement.GetType().GetField("_attributes", BindingFlags.NonPublic | BindingFlags.Instance);
                if (_attributes != null)
                {
                    var attributes = _attributes.GetValue(svgVisualElement) as SvgAttributeCollection;
                    if (attributes != null)
                    {
                        var viewBox = attributes.GetAttribute <SvgViewBox>("viewBox");
                        //var viewBox = svgVisualElement.Attributes.GetAttribute<SvgViewBox>("viewBox");
                        if (viewBox != SvgViewBox.Empty && Math.Abs(ew - viewBox.Width) > float.Epsilon && Math.Abs(eh - viewBox.Height) > float.Epsilon)
                        {
                            var sw = ew / viewBox.Width;
                            var sh = eh / viewBox.Height;

                            var skMatrixTranslateSWSH = SKMatrix.MakeTranslation(sw, sh);
                            SKMatrix.Concat(ref matrix, ref matrix, ref skMatrixTranslateSWSH);
                        }
                    }
                }
                //else
                //{
                //    throw new Exception("Can not get 'use' referenced element transform.");
                //}
            }
        }