Пример #1
0
        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);
        }
Пример #2
0
        public void Arrange_should_distribute_remaining_width_between_components_with_unlimited_width()
        {
            var area = new Rectangle(5, 5, 100, 100);

            var box = new VBox
            {
                Height = 100
            };
            var c1 = new FixedMeasureComponent(100, 20)
            {
                Height = SizeUnit.Unlimited
            };
            var c2 = new Component {
                Width = 100, Height = 25
            };
            var c3 = new FixedMeasureComponent(100, 30)
            {
                Height = SizeUnit.Unlimited
            };

            box.AddComponent(c1);
            box.AddComponent(c2);
            box.AddComponent(c3);

            box.Measure(area.Size, TestRendererContext.Instance);
            box.Arrange(area);

            c1.Layout.ShouldBe(new Rectangle(5, 5, 100, 20 + 12));
            c2.Layout.ShouldBe(new Rectangle(new Point(area.Left, c1.Layout.Bottom), new Size(100, 25)));
            c3.Layout.ShouldBe(new Rectangle(new Point(area.Left, c2.Layout.Bottom), new Size(100, 30 + 13)));
        }
Пример #3
0
        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 BitmapRenderer();
            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 bmp = renderer.Render(form);

            BitmapComparer.CompareBitmaps("bitmaps", bmp);
        }
Пример #4
0
        public void Measure_should_sum_height_and_take_biggest_width()
        {
            var box = new VBox();

            box.AddComponent(new FixedMeasureComponent(22, 22));
            box.AddComponent(new FixedMeasureComponent(11, 11));
            box.AddComponent(new FixedMeasureComponent(33, 33));
            box.Measure(new Size(100, 100), TestRendererContext.Instance);

            box.DesiredSize.ShouldBe(new Size(33, 66));
        }
Пример #5
0
        public void Measure_should_pass_size_to_the_component_with_height_decreased_by_the_height_of_previous_ones_but_not_smaller_than_0()
        {
            var box = new VBox();
            var c1  = new Mock <IComponent>().WithDesiredSize(new Size(10, 15));
            var c2  = new Mock <IComponent>().WithDesiredSize(new Size(20, 20));
            var c3  = new Mock <IComponent>().WithDesiredSize(new Size(20, 20));

            box.AddComponent(c1.Object);
            box.AddComponent(c2.Object);
            box.AddComponent(c3.Object);
            box.Measure(new Size(100, 30), TestRendererContext.Instance);

            c1.Verify(x => x.Measure(new Size(100, 30), TestRendererContext.Instance));
            c2.Verify(x => x.Measure(new Size(100, 15), TestRendererContext.Instance));
            c3.Verify(x => x.Measure(new Size(100, 0), TestRendererContext.Instance));
        }
Пример #6
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);
        }
Пример #7
0
        public void It_should_render_rounded_panels_with_borders()
        {
            var renderer = new BitmapRenderer();

            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 white"),
                        BorderRadius    = BorderRadius.Parse(border)
                    });
                }
                vbox.AddComponent(hbox);
            }


            var bmp = new Bitmap(100, 100);

            renderer.Render(new Form(vbox), bmp);
            BitmapComparer.CompareBitmaps("panels_rounded_border", bmp);
        }
Пример #8
0
        public void It_should_render_text_with_alignments()
        {
            var renderer = new BitmapRenderer();

            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.White),
                    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.White),
                    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 bmp = new Bitmap(400, 400);

            renderer.Render(form, bmp);
            BitmapComparer.CompareBitmaps("text_box_align", bmp);
        }
Пример #9
0
        public void Render_should_traverse_through_child_hierarchy_and_render_all_which_size_is_greater_than_0()
        {
            var panelRenderer     = CreateMockRenderer <Panel>();
            var hboxRenderer      = CreateMockRenderer <HBox>();
            var componentRenderer = CreateMockRenderer <Component>();
            var renderer          = new TestableRenderer();

            renderer.RegisterRenderer(panelRenderer.Object);
            renderer.RegisterRenderer(hboxRenderer.Object);
            renderer.RegisterRenderer(componentRenderer.Object);

            var hbox       = new HBox();
            var vbox       = new VBox();
            var component1 = new Component {
                Width = 1, Height = 1
            };
            var component2 = new Component {
                Width = 1, Height = 1
            };
            var component3 = new Component {
                Width = 1, Height = 1
            };
            var component4 = new Component {
                Width = 1, Height = 1
            };
            var panel1 = new Panel {
                Width = 10, Height = 10, Inner = component1
            };
            var panel2 = new Panel {
                Width = 0, Height = 10, Inner = component2
            };
            var panel3 = new Panel {
                Width = 10, Height = 0, Inner = component3
            };
            var panel4 = new Panel {
                Width = 2, Height = 2, Inner = component4
            };

            hbox.AddComponent(vbox);
            hbox.AddComponent(panel1);

            vbox.AddComponent(panel2);
            vbox.AddComponent(panel3);
            vbox.AddComponent(panel4);

            var form = new Form(hbox);

            form.LayOut(new Size(int.MaxValue, int.MaxValue), TestRendererContext.Instance);
            var g = new object();

            renderer.Render(g, form);

            hboxRenderer.Verify(x => x.Render(g, hbox, It.IsAny <Action <object, IComponent> >()), Times.Once);
            panelRenderer.Verify(x => x.Render(g, panel1, It.IsAny <Action <object, IComponent> >()), Times.Once);
            panelRenderer.Verify(x => x.Render(g, panel2, It.IsAny <Action <object, IComponent> >()), Times.Never);
            panelRenderer.Verify(x => x.Render(g, panel3, It.IsAny <Action <object, IComponent> >()), Times.Never);
            panelRenderer.Verify(x => x.Render(g, panel4, It.IsAny <Action <object, IComponent> >()), Times.Once);

            componentRenderer.Verify(x => x.Render(g, component1, It.IsAny <Action <object, IComponent> >()), Times.Once);
            componentRenderer.Verify(x => x.Render(g, component2, It.IsAny <Action <object, IComponent> >()), Times.Never);
            componentRenderer.Verify(x => x.Render(g, component3, It.IsAny <Action <object, IComponent> >()), Times.Never);
            componentRenderer.Verify(x => x.Render(g, component4, It.IsAny <Action <object, IComponent> >()), Times.Once);
        }