コード例 #1
0
        public async Task It_should_allow_concurrent_processing()
        {
            var pdfs = await Task.WhenAll(Enumerable.Range(0, 100).Select(_ => Task.Run(Generate)));

            PdfImageComparer.ComparePdfs("form", pdfs.First());
            PdfImageComparer.ComparePdfs("form", pdfs.Last());
        }
コード例 #2
0
ファイル: ImageRenderingTests.cs プロジェクト: orb1t/LayItOut
        public void It_should_render_images()
        {
            var redBlue    = CreateBitmap(Brushes.Red, Brushes.Blue, 400, 400);
            var blueYellow = CreateBitmap(Brushes.Blue, Brushes.Yellow, 30, 30);

            var renderer = new PdfRenderer();
            var vBox     = new VBox();
            var hBox     = new HBox();

            AddComponent(hBox, new Image {
                Src = redBlue, Width = 40, Height = 40, Scaling = ImageScaling.Uniform
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 40, Height = 30, Scaling = ImageScaling.Uniform, Alignment = Alignment.Center
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 40, Height = 30, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("center left")
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 40, Height = 30, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("center right")
            });
            vBox.AddComponent(hBox);
            hBox = new HBox();
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 30, Height = 40, Scaling = ImageScaling.Uniform, Alignment = Alignment.Center
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 30, Height = 40, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("top center")
            });
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 30, Height = 40, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("bottom center")
            });
            vBox.AddComponent(hBox);
            hBox = new HBox();
            AddComponent(hBox, new Image {
                Src = redBlue, Width = 10, Height = 20, Scaling = ImageScaling.Fill
            });
            AddComponent(hBox, new Image {
                Src = blueYellow, Scaling = ImageScaling.None
            });
            AddComponent(hBox, new Image {
                Src = blueYellow, Width = 20, Height = 20, Alignment = Alignment.Center, Scaling = ImageScaling.None
            });
            AddComponent(hBox, new Image {
                Src = blueYellow, Width = 20, Height = 20, Alignment = Alignment.Parse("top left"), Scaling = ImageScaling.None
            });
            AddComponent(hBox, new Image {
                Src = blueYellow, Width = 20, Height = 20, Alignment = Alignment.Parse("bottom right"), Scaling = ImageScaling.None
            });
            vBox.AddComponent(hBox);
            var form = new Form(vBox);

            var doc  = new PdfDocument();
            var page = doc.AddPage();

            renderer.Render(form, page, new PdfRendererOptions {
                AdjustPageSize = true
            });
            PdfImageComparer.ComparePdfs("bitmaps", doc);
        }
コード例 #3
0
        public void It_should_render_panels_and_hboxes()
        {
            var renderer = new PdfRenderer();

            var hbox = new HBox {
                Alignment = Alignment.Center
            };

            hbox.AddComponent(new Panel
            {
                BackgroundColor = Color.Yellow,
                Padding         = new Spacer(5),
                Border          = new Border(3, Color.Red),
                Alignment       = new Alignment(VerticalAlignment.Bottom)
            });
            hbox.AddComponent(new Panel
            {
                BackgroundColor = Color.Green,
                Padding         = new Spacer(10, 5),
                Border          = new Border(2, Color.Red),
                Alignment       = new Alignment(VerticalAlignment.Center)
            });
            hbox.AddComponent(new Panel
            {
                BackgroundColor = Color.Blue,
                Padding         = new Spacer(15, 5),
                Border          = new Border(1, Color.Red)
            });
            var panel = new Panel
            {
                Width           = SizeUnit.Unlimited,
                Height          = SizeUnit.Unlimited,
                BackgroundColor = Color.LightSteelBlue,
                Padding         = new Spacer(2),
                Inner           = hbox
            };
            var form = new Form(panel);

            var doc  = new PdfDocument();
            var page = doc.AddPage();

            page.Width  = 50;
            page.Height = 40;
            renderer.Render(form, page);
            PdfImageComparer.ComparePdfs("panels_hbox", doc);
        }
コード例 #4
0
        public void It_should_render_rounded_panels_with_borders()
        {
            var renderer = new PdfRenderer();

            var vbox = new VBox();

            var borders = new[]
            {
                new [] { "10 0 0 0", "0 10 0 0", "0 0 10 0", "0 0 0 10" },
                new [] { "10 10 0 0", "10 0 10 0", "10 0 0 10", "0 0 10 10" },
                new [] { "10 10 10 0", "10 0 10 10", "10 10 0 10", "10 10 10 10" }
            };

            foreach (var boxLine in borders)
            {
                var hbox = new HBox();
                foreach (var border in boxLine)
                {
                    hbox.AddComponent(new Panel
                    {
                        Margin          = new Spacer(1),
                        BackgroundColor = Color.Orange,
                        Width           = 24,
                        Height          = 24,
                        Border          = Border.Parse("1 black"),
                        BorderRadius    = BorderRadius.Parse(border)
                    });
                }
                vbox.AddComponent(hbox);
            }

            var doc  = new PdfDocument();
            var page = doc.AddPage();

            renderer.Render(new Form(vbox), page, new PdfRendererOptions {
                AdjustPageSize = true
            });
            PdfImageComparer.ComparePdfs("panels_rounded_border", doc);
        }
コード例 #5
0
        public void It_should_render_viewports()
        {
            var renderer = new PdfRenderer();

            var stack = new Stack();

            stack.AddComponent(new Panel
            {
                Width           = 100,
                Height          = 100,
                Border          = Border.Parse("1 #808080"),
                BackgroundColor = Color.LightBlue,
                BorderRadius    = BorderRadius.Parse("25")
            });
            stack.AddComponent(new Viewport
            {
                Alignment = Alignment.Parse("center left"),
                Width     = 10,
                Inner     = new Panel
                {
                    Width           = 40,
                    Height          = 40,
                    Border          = Border.Parse("1 #808080"),
                    BackgroundColor = Color.White,
                    BorderRadius    = BorderRadius.Parse("20")
                },
                ContentAlignment = Alignment.Parse("center right")
            });
            stack.AddComponent(new Viewport
            {
                Alignment = Alignment.Parse("top center"),
                Height    = 10,
                Inner     = new Panel
                {
                    Width           = 40,
                    Height          = 40,
                    Border          = Border.Parse("1 #808080"),
                    BackgroundColor = Color.White,
                    BorderRadius    = BorderRadius.Parse("20")
                },
                ContentAlignment = Alignment.Parse("bottom center")
            });
            stack.AddComponent(new Viewport
            {
                Alignment = Alignment.Parse("center right"),
                Width     = 10,
                Inner     = new Panel
                {
                    Width           = 40,
                    Height          = 40,
                    Border          = Border.Parse("1 #808080"),
                    BackgroundColor = Color.White,
                    BorderRadius    = BorderRadius.Parse("20")
                },
                ContentAlignment = Alignment.Parse("center left")
            });
            stack.AddComponent(new Viewport
            {
                Alignment = Alignment.Parse("bottom center"),
                Height    = 10,
                Inner     = new Panel
                {
                    Width           = 40,
                    Height          = 40,
                    Border          = Border.Parse("1 #808080"),
                    BackgroundColor = Color.White,
                    BorderRadius    = BorderRadius.Parse("20")
                },
                ContentAlignment = Alignment.Parse("top center")
            });
            stack.AddComponent(new Viewport
            {
                Alignment  = Alignment.Parse("center center"),
                ClipMargin = Spacer.Parse("3 1"),
                Inner      = new Panel
                {
                    Width           = 40,
                    Height          = 40,
                    BackgroundColor = Color.White,
                    Border          = Border.Parse("1 #808080"),
                    BorderRadius    = BorderRadius.Parse("20")
                },
                ContentAlignment = Alignment.Parse("center center")
            });
            var form = new Form(stack);

            var doc = new PdfDocument();

            renderer.Render(form, doc.AddPage(), new PdfRendererOptions {
                AdjustPageSize = true
            });
            PdfImageComparer.ComparePdfs("viewport", doc);
        }
コード例 #6
0
        public void It_should_render_text_with_different_line_heights()
        {
            var renderer = new PdfRenderer();
            var content  = new HBox {
                Width = SizeUnit.Unlimited
            };

            content.AddComponent(new Panel
            {
                Width           = 100,
                Height          = SizeUnit.Unlimited,
                BackgroundColor = Color.Yellow,
                Margin          = new Spacer(1),
                Inner           = new Label
                {
                    TextColor  = Color.Red,
                    Font       = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic),
                    Text       = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?",
                    LineHeight = 1.2f
                }
            });

            content.AddComponent(new Panel
            {
                Width           = 100,
                Height          = SizeUnit.Unlimited,
                BackgroundColor = Color.Yellow,
                Margin          = new Spacer(1),
                Inner           = new Label
                {
                    TextColor  = Color.Red,
                    Font       = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic),
                    Text       = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?",
                    LineHeight = 2f
                }
            });

            content.AddComponent(new Panel
            {
                Width           = 100,
                Height          = SizeUnit.Unlimited,
                BackgroundColor = Color.Yellow,
                Margin          = new Spacer(1),
                Inner           = new Label
                {
                    TextColor  = Color.Red,
                    Font       = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic),
                    Text       = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?",
                    LineHeight = 0.8f
                }
            });

            var form = new Form(content);

            var doc  = new PdfDocument();
            var page = doc.AddPage();

            page.Width  = 300;
            page.Height = 400;
            renderer.Render(form, page);
            PdfImageComparer.ComparePdfs("text_box_line_height", doc);
        }
コード例 #7
0
        public void It_should_render_text_with_alignments()
        {
            var renderer = new PdfRenderer();

            var labelBox = new HBox {
                Width = SizeUnit.Unlimited
            };

            foreach (var align in new[] { TextAlignment.Left, TextAlignment.Right, TextAlignment.Center, TextAlignment.Justify })
            {
                labelBox.AddComponent(new Panel
                {
                    Width           = 100,
                    Height          = SizeUnit.Unlimited,
                    BackgroundColor = Color.Yellow,
                    Margin          = new Spacer(1),
                    Border          = new Border(1, Color.Black),
                    Padding         = new Spacer(2),
                    Inner           = new Label
                    {
                        Width         = SizeUnit.Unlimited,
                        TextColor     = Color.Red,
                        TextAlignment = align,
                        Font          = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic),
                        Text          = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?"
                    }
                });
            }

            var areaBox = new HBox {
                Width = SizeUnit.Unlimited
            };

            foreach (var align in new[] { TextAlignment.Left, TextAlignment.Right, TextAlignment.Center, TextAlignment.Justify })
            {
                var textBox = new TextBox
                {
                    Width         = SizeUnit.Unlimited,
                    TextAlignment = align
                };
                textBox.AddComponent(new Label
                {
                    TextColor = Color.Red,
                    Text      = "Hi Bob!",
                    Font      = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic)
                });

                textBox.AddComponent(new Link
                {
                    TextColor = Color.Black,
                    Text      = "Check out this: ",
                    Font      = new FontInfo(TestFontFamily.Serif, 12, FontInfoStyle.Regular)
                });
                textBox.AddComponent(new Link
                {
                    TextColor = Color.Purple,
                    Text      = "great link!!!",
                    Font      = new FontInfo(TestFontFamily.Serif, 8, FontInfoStyle.Underline),
                    Uri       = "http://google.com"
                });
                areaBox.AddComponent(new Panel
                {
                    Width           = 100,
                    Height          = SizeUnit.Unlimited,
                    BackgroundColor = Color.Green,
                    Margin          = new Spacer(1),
                    Border          = new Border(1, Color.Black),
                    Padding         = new Spacer(2),
                    Inner           = textBox
                });
            }

            var content = new VBox {
                Width = SizeUnit.Unlimited
            };

            content.AddComponent(labelBox);
            content.AddComponent(areaBox);

            var form = new Form(content);

            var doc  = new PdfDocument();
            var page = doc.AddPage();

            page.Width  = 400;
            page.Height = 400;
            renderer.Render(form, page);
            PdfImageComparer.ComparePdfs("text_box_align", doc);
        }
コード例 #8
0
        public void It_should_render_text()
        {
            var renderer = new PdfRenderer();
            var content  = new HBox {
                Width = SizeUnit.Unlimited
            };

            content.AddComponent(new Panel
            {
                Width           = 100,
                Height          = SizeUnit.Unlimited,
                BackgroundColor = Color.Yellow,
                Margin          = new Spacer(1),
                Border          = new Border(1, Color.Black),
                Padding         = new Spacer(2),
                Inner           = new Label
                {
                    TextColor = Color.Red,
                    Font      = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic),
                    Text      = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?"
                }
            });

            content.AddComponent(new Panel
            {
                Width           = 100,
                Height          = SizeUnit.Unlimited,
                BackgroundColor = Color.DarkSeaGreen,
                Margin          = new Spacer(1),
                Border          = new Border(1, Color.Black),
                Padding         = new Spacer(2),
                Inner           = new Link
                {
                    TextColor = Color.Blue,
                    Font      = new FontInfo(TestFontFamily.Serif, 14, FontInfoStyle.Bold),
                    Text      = "How are you doing today?",
                    Uri       = "http://google.com"
                }
            });

            var textBox = new TextBox();

            textBox.AddComponent(new Label {
                Text = "Hello!\n", TextColor = Color.Green, Font = new FontInfo(TestFontFamily.Monospace, 20, FontInfoStyle.Underline)
            });
            textBox.AddComponent(new Label {
                Text = "Hi Bob, nice to see you after", TextColor = Color.Black, Font = new FontInfo(TestFontFamily.SansSerif, 10)
            });
            textBox.AddComponent(new Label {
                Text = "20", TextColor = Color.Red, Font = new FontInfo(TestFontFamily.SansSerif, 10, FontInfoStyle.Bold)
            });
            textBox.AddComponent(new Label {
                Text = "years!\n", TextColor = Color.Black, Font = new FontInfo(TestFontFamily.SansSerif, 10)
            });
            textBox.AddComponent(new Label {
                Text = "I'm sure you'd love to see my new", TextColor = Color.Black, Font = new FontInfo(TestFontFamily.SansSerif, 10)
            });
            textBox.AddComponent(new Link {
                Text = "web", TextColor = Color.Blue, Font = new FontInfo(TestFontFamily.SansSerif, 12, FontInfoStyle.Italic), Uri = "http://google.com"
            });
            textBox.AddComponent(new Link {
                Text = "site", TextColor = Color.Green, TextContinuation = true, Font = new FontInfo(TestFontFamily.SansSerif, 12, FontInfoStyle.Italic), Uri = "http://google.com"
            });
            content.AddComponent(new Panel
            {
                Width           = SizeUnit.Unlimited,
                Height          = SizeUnit.Unlimited,
                BackgroundColor = Color.LightYellow,
                Margin          = new Spacer(1),
                Border          = new Border(1, Color.Black),
                Padding         = new Spacer(2),
                Inner           = textBox
            });

            var form = new Form(content);

            var doc  = new PdfDocument();
            var page = doc.AddPage();

            page.Width  = 320;
            page.Height = 400;
            renderer.Render(form, page);
            PdfImageComparer.ComparePdfs("text_box", doc);
        }