示例#1
0
		public void PaintParaBox()
		{
			AssembledStyles styles = new AssembledStyles();
			var clientRuns = new List<IClientRun>();
			BlockBox box0 = new BlockBox(styles, Color.Red, 72000, 36000);
			clientRuns.Add(box0);
			BlockBox box1 = new BlockBox(styles, Color.Blue, 36000, 18000);
			clientRuns.Add(box1);
			BlockBox box2 = new BlockBox(styles, Color.Red, 24000, 18000);
			clientRuns.Add(box2);
			BlockBox box3 = new BlockBox(styles, Color.Red, 72000, 36000);
			clientRuns.Add(box3);
			BlockBox box4 = new BlockBox(styles, Color.Red, 36000, 36000);
			clientRuns.Add(box4);

			TextSource source = new TextSource(clientRuns, null);
			ParaBox para = new ParaBox(styles, source);
			RootBox root = new RootBox(styles);
			root.AddBox(para);

			MockGraphics graphics = new MockGraphics();
			LayoutInfo layoutArgs = ParaBuilderTests.MakeLayoutInfo(100, graphics);
			root.Layout(layoutArgs);

			PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
			root.Paint(graphics, ptrans);
			Assert.AreEqual(5, graphics.RectanglesDrawn.Count);
			VerifyRect(2, 2, 96, 48, graphics, 0, Color.Red);
			VerifyRect(2, 48+2, 48, 24, graphics, 1, Color.Blue);
			VerifyRect(2+48, 48 + 2, 32, 24, graphics, 2, Color.Red);
			VerifyRect(2, 24 + 48 + 2, 96, 48, graphics, 3, Color.Red);
			VerifyRect(2, 48 + 24 + 48 + 2, 48, 48, graphics, 4, Color.Red);
		}
示例#2
0
        private void VerifyPaint(RootBox root, Rectangle clipRect, int xScrollOffset, int yScrollOffset, Rectangle[] paintRects)
        {
            MockGraphics graphics = new MockGraphics();

            graphics.ClipRectangle = clipRect;
            PaintTransform ptrans = new PaintTransform(0, 0, 96, 96, xScrollOffset, yScrollOffset, 96, 96);

            root.Paint(graphics, ptrans);
            var drawActions = graphics.DrawActions;             // after the paint, it gets created when first rect added.

            if (paintRects == null || paintRects.Length == 0)
            {
                Assert.IsTrue(drawActions == null || drawActions.Count == 0);
                return;
            }
            Assert.That(drawActions, Has.Count.EqualTo(paintRects.Length * 2));
            int position = 0;

            // First all the blocks get drawn in their PaintBackground routine
            foreach (var rect in paintRects)
            {
                VerifyRect(drawActions, ref position, rect);
            }
            // Then we verify that the PaintForeground routines got called.
            for (; position < drawActions.Count; position++)
            {
                Assert.That(drawActions[position], Is.InstanceOf(typeof(FgBlockBox)));
            }
        }
示例#3
0
		public void PaintBarBox()
		{
			AssembledStyles styles = new AssembledStyles();
			BlockBox box = new BlockBox(styles, Color.Red, 72000, 36000);

			RootBox root = new RootBox(styles);
			root.AddBox(box);
			LayoutInfo transform = MakeLayoutInfo();
			root.Layout(transform);

			PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
			MockGraphics graphics = new MockGraphics();
			root.Paint(graphics, ptrans);
			Assert.AreEqual(1, graphics.RectanglesDrawn.Count);
			Assert.AreEqual(new Rectangle(2, 2, 96, 48), graphics.RectanglesDrawn[0]);
			Assert.AreEqual((int)ColorUtil.ConvertColorToBGR(Color.Red), graphics.BackColor);
		}
示例#4
0
        public void SimpleString()
        {
            ParaBox        para;
            RootBox        root   = ParaBuilderTests.MakeTestParaSimpleString(m_gm.VwGraphics, ParaBuilderTests.MockBreakOption.ThreeFullLines, out para);
            PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, -10, 120, 128);

            root.Paint(m_gm.VwGraphics, ptrans);

            ParaBox pb = root.FirstBox as ParaBox;

            Assert.IsNotNull(pb);
            StringBox first = pb.FirstBox as StringBox;

            Assert.IsNotNull(first);
            MockSegment seg1 = first.Segment as MockSegment;

            Assert.IsNotNull(seg1);
            Assert.AreEqual(m_gm.VwGraphics, seg1.LastDrawTextCall.vg);
            Assert.AreEqual(0, seg1.LastDrawTextCall.ichBase);
            VerifySimpleRect(seg1.LastDrawTextCall.rcSrc, -2, -4, 96, 100);
            VerifySimpleRect(seg1.LastDrawTextCall.rcDst, 0, 10, 120, 128);

            StringBox second = first.Next as StringBox;

            Assert.IsNotNull(second);
            MockSegment seg2 = second.Segment as MockSegment;

            Assert.IsNotNull(seg2);
            VerifySimpleRect(seg2.LastDrawTextCall.rcSrc, -2, -14, 96, 100);
            VerifySimpleRect(seg2.LastDrawTextCall.rcDst, 0, 10, 120, 128);

            StringBox third = second.Next as StringBox;

            Assert.IsNotNull(third);
            MockSegment seg3 = third.Segment as MockSegment;

            Assert.IsNotNull(seg3);
            VerifySimpleRect(seg3.LastDrawTextCall.rcSrc, -2, -24, 96, 100);
            VerifySimpleRect(seg3.LastDrawTextCall.rcDst, 0, 10, 120, 128);

            Assert.AreEqual(root, third.Root);
        }
示例#5
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));
        }
示例#6
0
        public void PaintBarBox()
        {
            AssembledStyles styles = new AssembledStyles();
            BlockBox        box    = new BlockBox(styles, Color.Red, 72000, 36000);

            RootBox root = new RootBox(styles);

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

            root.Layout(transform);

            PaintTransform ptrans   = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
            MockGraphics   graphics = new MockGraphics();

            root.Paint(graphics, ptrans);
            Assert.AreEqual(1, graphics.RectanglesDrawn.Count);
            Assert.AreEqual(new Rectangle(2, 2, 96, 48), graphics.RectanglesDrawn[0]);
            Assert.AreEqual((int)ColorUtil.ConvertColorToBGR(Color.Red), graphics.BackColor);
        }
示例#7
0
        public void PaintParaBox()
        {
            AssembledStyles styles     = new AssembledStyles();
            var             clientRuns = new List <IClientRun>();
            BlockBox        box0       = new BlockBox(styles, Color.Red, 72000, 36000);

            clientRuns.Add(box0);
            BlockBox box1 = new BlockBox(styles, Color.Blue, 36000, 18000);

            clientRuns.Add(box1);
            BlockBox box2 = new BlockBox(styles, Color.Red, 24000, 18000);

            clientRuns.Add(box2);
            BlockBox box3 = new BlockBox(styles, Color.Red, 72000, 36000);

            clientRuns.Add(box3);
            BlockBox box4 = new BlockBox(styles, Color.Red, 36000, 36000);

            clientRuns.Add(box4);

            TextSource source = new TextSource(clientRuns, null);
            ParaBox    para   = new ParaBox(styles, source);
            RootBox    root   = new RootBox(styles);

            root.AddBox(para);

            MockGraphics graphics   = new MockGraphics();
            LayoutInfo   layoutArgs = ParaBuilderTests.MakeLayoutInfo(100, graphics);

            root.Layout(layoutArgs);

            PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);

            root.Paint(graphics, ptrans);
            Assert.AreEqual(5, graphics.RectanglesDrawn.Count);
            VerifyRect(2, 2, 96, 48, graphics, 0, Color.Red);
            VerifyRect(2, 48 + 2, 48, 24, graphics, 1, Color.Blue);
            VerifyRect(2 + 48, 48 + 2, 32, 24, graphics, 2, Color.Red);
            VerifyRect(2, 24 + 48 + 2, 96, 48, graphics, 3, Color.Red);
            VerifyRect(2, 48 + 24 + 48 + 2, 48, 48, graphics, 4, Color.Red);
        }
示例#8
0
		private void VerifyPaint(RootBox root, Rectangle clipRect, int xScrollOffset, int yScrollOffset, Rectangle[] paintRects)
		{
			MockGraphics graphics = new MockGraphics();
			graphics.ClipRectangle = clipRect;
			PaintTransform ptrans = new PaintTransform(0, 0, 96, 96, xScrollOffset, yScrollOffset, 96, 96);
			root.Paint(graphics, ptrans);
			var drawActions = graphics.DrawActions; // after the paint, it gets created when first rect added.
			if (paintRects == null || paintRects.Length == 0)
			{
				Assert.IsTrue(drawActions == null || drawActions.Count == 0);
				return;
			}
			Assert.That(drawActions, Has.Count.EqualTo(paintRects.Length * 2));
			int position = 0;
			// First all the blocks get drawn in their PaintBackground routine
			foreach (var rect in paintRects)
			{
				VerifyRect(drawActions, ref position, rect);
			}
			// Then we verify that the PaintForeground routines got called.
			for (; position < drawActions.Count; position++)
				Assert.That(drawActions[position], Is.InstanceOf(typeof(FgBlockBox)));
		}
示例#9
0
        public void FlashInsertionPoint()
        {
            AssembledStyles styles     = new AssembledStyles();
            var             clientRuns = new List <IClientRun>();
            BlockBox        box0       = new BlockBox(styles, Color.Red, 72000, 36000);

            clientRuns.Add(box0);
            TextSource source = new TextSource(clientRuns, null);
            ParaBox    para   = new ParaBox(styles, source);
            RootBox    root   = new RootBox(styles);

            root.AddBox(para);
            MockGraphics graphics   = new MockGraphics();
            LayoutInfo   layoutArgs = ParaBuilderTests.MakeLayoutInfo(100, graphics);

            root.Layout(layoutArgs);

            var sel = new DummySelection();

            root.Selection = sel;

            PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);

            root.Paint(graphics, ptrans);

            Assert.AreEqual(graphics, sel.VgUsedToDraw);
            Assert.AreEqual(ptrans, sel.TransformUsedToDraw);

            sel.ClearResults();
            root.FlashInsertionPoint();

            Assert.IsFalse(sel.WasInvalidated, "flash IP should not cause range to be invalidated");

            var ip = new DummySelection();

            ip.SimulateIP  = true;
            root.Selection = ip;
            Assert.IsTrue(ip.WasInvalidated);

            // Initial paint after being installed should indeed paint the IP (so it appears at once)
            ip.ClearResults();
            root.Paint(graphics, ptrans);
            Assert.AreEqual(graphics, ip.VgUsedToDraw);
            Assert.AreEqual(ptrans, ip.TransformUsedToDraw);


            // Each flash should invalide it.
            sel.ClearResults();
            root.FlashInsertionPoint();
            Assert.IsTrue(ip.WasInvalidated);

            // The second paint should do nothing to the IP.
            ip.ClearResults();
            root.Paint(graphics, ptrans);
            Assert.AreEqual(null, ip.VgUsedToDraw);

            // One more flash
            ip.ClearResults();
            root.FlashInsertionPoint();
            Assert.IsTrue(ip.WasInvalidated);

            // And now back to drawing the IP.
            ip.ClearResults();
            root.Paint(graphics, ptrans);
            Assert.AreEqual(graphics, ip.VgUsedToDraw);
            Assert.AreEqual(ptrans, ip.TransformUsedToDraw);

            // range should get drawn even though IP was hidden.
            root.FlashInsertionPoint();       // back to hidden
            root.Selection = sel;             // back to range.
            sel.ClearResults();
            root.Paint(graphics, ptrans);
            Assert.AreEqual(graphics, sel.VgUsedToDraw);
            Assert.AreEqual(ptrans, sel.TransformUsedToDraw);
        }
示例#10
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));
		}
示例#11
0
		public void FlashInsertionPoint()
		{
			AssembledStyles styles = new AssembledStyles();
			var clientRuns = new List<IClientRun>();
			BlockBox box0 = new BlockBox(styles, Color.Red, 72000, 36000);
			clientRuns.Add(box0);
			TextSource source = new TextSource(clientRuns, null);
			ParaBox para = new ParaBox(styles, source);
			RootBox root = new RootBox(styles);
			root.AddBox(para);
			MockGraphics graphics = new MockGraphics();
			LayoutInfo layoutArgs = ParaBuilderTests.MakeLayoutInfo(100, graphics);
			root.Layout(layoutArgs);

			var sel = new DummySelection();
			root.Selection = sel;

			PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
			root.Paint(graphics, ptrans);

			Assert.AreEqual(graphics, sel.VgUsedToDraw);
			Assert.AreEqual(ptrans, sel.TransformUsedToDraw);

			sel.ClearResults();
			root.FlashInsertionPoint();

			Assert.IsFalse(sel.WasInvalidated, "flash IP should not cause range to be invalidated");

			var ip = new DummySelection();
			ip.SimulateIP = true;
			root.Selection = ip;
			Assert.IsTrue(ip.WasInvalidated);

			// Initial paint after being installed should indeed paint the IP (so it appears at once)
			ip.ClearResults();
			root.Paint(graphics, ptrans);
			Assert.AreEqual(graphics, ip.VgUsedToDraw);
			Assert.AreEqual(ptrans, ip.TransformUsedToDraw);


			// Each flash should invalide it.
			sel.ClearResults();
			root.FlashInsertionPoint();
			Assert.IsTrue(ip.WasInvalidated);

			// The second paint should do nothing to the IP.
			ip.ClearResults();
			root.Paint(graphics, ptrans);
			Assert.AreEqual(null, ip.VgUsedToDraw);

			// One more flash
			ip.ClearResults();
			root.FlashInsertionPoint();
			Assert.IsTrue(ip.WasInvalidated);

			// And now back to drawing the IP.
			ip.ClearResults();
			root.Paint(graphics, ptrans);
			Assert.AreEqual(graphics, ip.VgUsedToDraw);
			Assert.AreEqual(ptrans, ip.TransformUsedToDraw);

			// range should get drawn even though IP was hidden.
			root.FlashInsertionPoint(); // back to hidden
			root.Selection = sel; // back to range.
			sel.ClearResults();
			root.Paint(graphics, ptrans);
			Assert.AreEqual(graphics, sel.VgUsedToDraw);
			Assert.AreEqual(ptrans, sel.TransformUsedToDraw);
		}