Esempio n. 1
0
        public void PaintPictureBox()
        {
            AssembledStyles styles = new AssembledStyles();
            Bitmap          bm     = new Bitmap(20, 30);
            ImageBox        box    = new ImageBox(styles.WithMargins(new Thickness(72.0 / 96.0 * 2.0))
                                                  .WithBorders(new Thickness(72.0 / 96.0 * 3.0))
                                                  .WithPads(new Thickness(72.0 / 96.0 * 7.0, 72.0 / 96.0 * 8.0, 72.0 / 96.0 * 11.0, 72.0 / 96.0 * 13.0)), bm);

            RootBox  root  = new RootBox(styles);
            BlockBox block = new BlockBox(styles, Color.Yellow, 2000, 4000);

            root.AddBox(block);
            root.AddBox(box);
            LayoutInfo transform = MakeLayoutInfo();

            root.Layout(transform);
            Assert.That(box.Height, Is.EqualTo(30 + 2 * 2 + 3 * 2 + 8 + 13));
            Assert.That(box.Width, Is.EqualTo(20 + 2 * 2 + 3 * 2 + 7 + 11));
            Assert.That(box.Ascent, Is.EqualTo(box.Height));

            PaintTransform ptrans   = new PaintTransform(2, 4, 96, 96, 10, 40, 96, 96);
            MockGraphics   graphics = new MockGraphics();

            root.Paint(graphics, ptrans);
            Assert.That(graphics.LastRenderPictureArgs, Is.Not.Null);
            Assert.That(graphics.LastRenderPictureArgs.Picture, Is.EqualTo(box.Picture));
            Assert.That(graphics.LastRenderPictureArgs.X, Is.EqualTo(2 - 10 + 2 + 3 + 7));
            Assert.That(graphics.LastRenderPictureArgs.Y, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8));
            Assert.That(graphics.LastRenderPictureArgs.Cx, Is.EqualTo(20));
            Assert.That(graphics.LastRenderPictureArgs.Cy, Is.EqualTo(30));
            int hmWidth  = box.Picture.Width;
            int hmHeight = box.Picture.Height;

            Assert.That(graphics.LastRenderPictureArgs.XSrc, Is.EqualTo(0));
            Assert.That(graphics.LastRenderPictureArgs.YSrc, Is.EqualTo(hmHeight));
            Assert.That(graphics.LastRenderPictureArgs.CxSrc, Is.EqualTo(hmWidth));
            Assert.That(graphics.LastRenderPictureArgs.CySrc, Is.EqualTo(-hmHeight));
            Assert.That(graphics.LastRenderPictureArgs.RcWBounds.left, Is.EqualTo(2 - 10 + 2 + 3 + 7));
            Assert.That(graphics.LastRenderPictureArgs.RcWBounds.top, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8));
            Assert.That(graphics.LastRenderPictureArgs.RcWBounds.right, Is.EqualTo(2 - 10 + 2 + 3 + 7 + 20));
            Assert.That(graphics.LastRenderPictureArgs.RcWBounds.bottom, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8 + 30));
        }
Esempio n. 2
0
		public void PaintPictureBox()
		{
			AssembledStyles styles = new AssembledStyles();
			Bitmap bm = new Bitmap(20, 30);
			ImageBox box = new ImageBox(styles.WithMargins(new Thickness(72.0 / 96.0 * 2.0))
				.WithBorders(new Thickness(72.0 / 96.0 * 3.0))
				.WithPads(new Thickness(72.0 / 96.0 * 7.0, 72.0 / 96.0 * 8.0, 72.0 / 96.0 * 11.0, 72.0 / 96.0 * 13.0)), bm);

			RootBox root = new RootBox(styles);
			BlockBox block = new BlockBox(styles, Color.Yellow, 2000, 4000);
			root.AddBox(block);
			root.AddBox(box);
			LayoutInfo transform = MakeLayoutInfo();
			root.Layout(transform);
			Assert.That(box.Height, Is.EqualTo(30 + 2*2+3*2+8+13));
			Assert.That(box.Width, Is.EqualTo(20 + 2*2 +3*2 + 7 + 11));
			Assert.That(box.Ascent, Is.EqualTo(box.Height));

			PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 10, 40, 96, 96);
			MockGraphics graphics = new MockGraphics();
			root.Paint(graphics, ptrans);
			Assert.That(graphics.LastRenderPictureArgs, Is.Not.Null);
			Assert.That(graphics.LastRenderPictureArgs.Picture, Is.EqualTo(box.Picture));
			Assert.That(graphics.LastRenderPictureArgs.X, Is.EqualTo(2-10 + 2 + 3 + 7));
			Assert.That(graphics.LastRenderPictureArgs.Y, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8));
			Assert.That(graphics.LastRenderPictureArgs.Cx, Is.EqualTo(20));
			Assert.That(graphics.LastRenderPictureArgs.Cy, Is.EqualTo(30));
			int hmWidth = box.Picture.Width;
			int hmHeight = box.Picture.Height;
			Assert.That(graphics.LastRenderPictureArgs.XSrc, Is.EqualTo(0));
			Assert.That(graphics.LastRenderPictureArgs.YSrc, Is.EqualTo(hmHeight));
			Assert.That(graphics.LastRenderPictureArgs.CxSrc, Is.EqualTo(hmWidth));
			Assert.That(graphics.LastRenderPictureArgs.CySrc, Is.EqualTo(-hmHeight));
			Assert.That(graphics.LastRenderPictureArgs.RcWBounds.left, Is.EqualTo(2 - 10 + 2 + 3 + 7));
			Assert.That(graphics.LastRenderPictureArgs.RcWBounds.top, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8));
			Assert.That(graphics.LastRenderPictureArgs.RcWBounds.right, Is.EqualTo(2 - 10 + 2 + 3 + 7 + 20));
			Assert.That(graphics.LastRenderPictureArgs.RcWBounds.bottom, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8 + 30));
		}