예제 #1
0
파일: Drawing.cs 프로젝트: yard/NGraphics
 private void DrawGraphic()
 {
     var c = new GraphicCanvas(size);
     if (func != null)
         func(c);
     graphic = c.Graphic;
 }
예제 #2
0
        public void Ellipse()
        {
            var d = new GraphicCanvas(new Size(50, 50), Platform);

            d.DrawEllipse(new Point(10, 20), new Size(30, 40), Pens.Black);
            Assert.AreEqual(1, d.Graphic.Children.Count);
        }
예제 #3
0
        string DrawBadge(PackageData package)
        {
            var k = "fuget";
            var v = "v" + package.Version.ShortVersionString;

            var font = new Font("DejaVu Sans,Verdana,Geneva,sans-serif", 11);
            var kw   = (int)Math.Round(NullPlatform.GlobalMeasureText(k, font).Width * 1.15);
            var vw   = (int)Math.Round(NullPlatform.GlobalMeasureText(v, font).Width * 1.15);

            var hpad = 8;
            var w    = kw + vw + 4 * hpad;
            var h    = 20;
            var c    = new GraphicCanvas(new Size(w, h));

            c.FillRectangle(new Rect(0, 0, w, h), new Size(3, 3), "#555");
            c.FillRectangle(new Rect(kw + 2 * hpad, 0, w - 2 * hpad - kw, h), new Size(3, 3), "#5cb85c");
            c.FillRectangle(new Rect(kw + 2 * hpad, 0, 6, h), "#5cb85c");

            var scolor = new Color(1.0 / 255.0, 0.3);

            // c.FillRectangle(new Rect(hpad, 5, kw, font.Size), "#F00");
            c.DrawText(k, new Point(hpad, 15), font, scolor);
            c.DrawText(k, new Point(hpad, 14), font, Colors.White);

            // c.FillRectangle(new Rect(w - vw - hpad, 5, vw, font.Size), "#FF0");
            c.DrawText(v, new Point(w - vw - hpad, 15), font, scolor);
            c.DrawText(v, new Point(w - vw - hpad, 14), font, Colors.White);

            using (var tw = new System.IO.StringWriter()) {
                c.Graphic.WriteSvg(tw);
                return(tw.ToString());
            }
        }
예제 #4
0
        //[Test]
        public void AutoSize()
        {
            var c = new GraphicCanvas();

            c.DrawRectangle(new Rect(0, 0, 40, 20), new Size(3, 3), null, new SolidBrush("#333"));
            var svg = c.Graphic.GetSvg();

            Assert.IsTrue(svg.Contains("svg width=\"40\""));
        }
예제 #5
0
        private void DrawGraphic()
        {
            var c = new GraphicCanvas(size);

            if (func != null)
            {
                func(c);
            }
            graphic = c.Graphic;
        }
예제 #6
0
        public void RoundedRect()
        {
            var c = new GraphicCanvas();

            c.DrawRectangle(new Rect(0, 0, 40, 20), new Size(3, 3), null, new SolidBrush("#333"));
            var svg = c.Graphic.GetSvg();

            Assert.IsTrue(svg.Contains("rx=\"3\""));
            Assert.IsTrue(svg.Contains("ry=\"3\""));
        }
예제 #7
0
        public void NoTitle()
        {
            var c = new GraphicCanvas();

            c.DrawRectangle(new Rect(0, 0, 40, 20), new Size(3, 3), null, new SolidBrush("#333"));
            var svg = c.Graphic.GetSvg();

            Assert.IsTrue(!svg.Contains("<title>"));
            Assert.IsTrue(!svg.Contains("<description>"));
        }
예제 #8
0
        public void NormalRect()
        {
            var c = new GraphicCanvas();

            c.DrawRectangle(new Rect(0, 0, 40, 20), new Size(0, 0), null, new SolidBrush("#333"));
            var svg = c.Graphic.GetSvg();

            Assert.IsTrue(!svg.Contains("rx="));
            Assert.IsTrue(!svg.Contains("ry="));
        }
예제 #9
0
        async Task Draw(Graphic g, string path)
        {
            //
            // Draw Image
            //
            var c = Platform.CreateImageCanvas(g.Size);

            g.Draw(c);
            await SaveImage(c, path);

            var c2 = new GraphicCanvas(g.Size, Platform);

            g.Draw(c2);
            await SaveSvg(c2, path);
        }
예제 #10
0
		async Task ReadAndDraw (string path)
		{
			var g = Read (path);

			//
			// Draw Image
			//
			var c = Platform.CreateImageCanvas (g.Size);
			g.Draw (c);
			await SaveImage (c, path);

			var c2 = new GraphicCanvas (g.Size, Platform);
			g.Draw (c2);
			await SaveSvg (c2, path);
		}
예제 #11
0
		async Task Draw (GraphicCanvas canvas, string path)
		{
			var g = canvas.Graphic;

			//
			// Draw Image
			//
			var c = Platform.CreateImageCanvas (g.Size);
			g.Draw (c);
			await SaveImage (c, path);

			var c2 = Platform.CreateGraphicCanvas (g.Size);
			g.Draw (c2);
			await SaveSvg (c2, path);
		}
예제 #12
0
        async Task ReadAndDraw(string path)
        {
            var g = Read(path);

            //
            // Draw Image
            //
            var c = Platform.CreateImageCanvas(g.Size);

            g.Draw(c);
            await SaveImage(c, path);

            var c2 = new GraphicCanvas(g.Size, Platform);

            g.Draw(c2);
            await SaveSvg(c2, path);
        }
예제 #13
0
        async Task Draw(GraphicCanvas canvas, string path)
        {
            var g = canvas.Graphic;

            //
            // Draw Image
            //
            var c = Platform.CreateImageCanvas(g.Size);

            g.Draw(c);
            await SaveImage(c, path);

            var c2 = Platform.CreateGraphicCanvas(g.Size);

            g.Draw(c2);
            await SaveSvg(c2, path);
        }
예제 #14
0
        private string DrawShield(Package package)
        {
            var k = _options.Shield.ServerName;
            var v = package is null ? "Package not found" : $"v{package.Version.OriginalVersion}";

            var font = new Font("DejaVu Sans,Verdana,Geneva,sans-serif", 11);
            var kw   = (int)Math.Round(NullPlatform.GlobalMeasureText(k, font).Width * 1.15);
            var vw   = (int)Math.Round(NullPlatform.GlobalMeasureText(v, font).Width * 1.15);

            var hpad = 8;
            var w    = kw + vw + 4 * hpad;
            var h    = 20;
            var c    = new GraphicCanvas(new Size(w, h));

            var badgeColor = package?.IsPrerelease switch
            {
                null => "#FFA500",
                true => "#BBB90F",
                false => "#00008B"
            };

            c.FillRectangle(new Rect(0, 0, w, h), new Size(3, 3), "#555");
            c.FillRectangle(new Rect(kw + 2 * hpad, 0, w - 2 * hpad - kw, h), new Size(3, 3), badgeColor);
            c.FillRectangle(new Rect(kw + 2 * hpad, 0, 6, h), badgeColor);

            var scolor = new Color(1.0 / 255.0, 0.3);

            // c.FillRectangle(new Rect(hpad, 5, kw, font.Size), "#F00");
            c.DrawText(k, new Point(hpad, 15), font, scolor);
            c.DrawText(k, new Point(hpad, 14), font, Colors.White);

            // c.FillRectangle(new Rect(w - vw - hpad, 5, vw, font.Size), "#FF0");
            c.DrawText(v, new Point(w - vw - hpad, 15), font, scolor);
            c.DrawText(v, new Point(w - vw - hpad, 14), font, Colors.White);

            using var tw = new StringWriter();
            c.Graphic.WriteSvg(tw);
            return(tw.ToString());
        }
    }
예제 #15
0
        public async Task SaveSvg(GraphicCanvas canvas, string name)
        {
            var path = GetPath(name, ".svg");

            using (var s = OpenStream(path)) {
                if (s == null)
                {
                    using (var ss = await Platforms.Current.OpenFileStreamForWritingAsync(path)) {
                        using (var w = new System.IO.StreamWriter(ss)) {
                            canvas.Graphic.WriteSvg(w);
                        }
                    }
                }
                else
                {
                    var w = new System.IO.StreamWriter(s);
                    canvas.Graphic.WriteSvg(w);
                    await w.FlushAsync();
                    await CloseStream(s);
                }
            }
        }
예제 #16
0
 public void Ellipse()
 {
     var d = new GraphicCanvas (new Size (50, 50));
     d.DrawEllipse (new Point (10, 20), new Size (30, 40), Pens.Black);
     Assert.AreEqual (1, d.Graphic.Children.Count);
 }
예제 #17
0
        public void GetUtf8()
        {
            var svg = new GraphicCanvas().Graphic.GetSvg();

            Assert.IsTrue(svg.Contains("encoding=\"UTF-8\""));
        }