示例#1
0
        protected virtual SvgBuilder FillSvg(bool[,] sprite, Color background, Color foreground)
        {
            int     side     = sprite.GetLength(0);
            decimal offset   = Options.Border / (decimal)Options.Scale;
            decimal fullSide = side + 2m * offset;

            SvgBuilder svg = new SvgBuilder()
                             .SetViewBox(0, 0, fullSide, fullSide)
                             .Append(new SvgRect {
                PercentageWidth  = 100,
                PercentageHeight = 100,
                Color            = background
            });

            SvgPathBuilder path = new SvgPathBuilder {
                Color = foreground
            };

            for (int y = 0; y < side; ++y)
            {
                for (int x = 0; x < side; ++x)
                {
                    if (sprite[y, x])
                    {
                        path.AppendPoint(x + offset, y + offset)
                        .AppendRelativeHorizontalLine(1)
                        .AppendRelativeVerticalLine(1)
                        .AppendRelativeHorizontalLine(-1)
                        .AppendClosePath();
                    }
                }
            }

            return(svg.Append(path));
        }