OrderedBoxes() private method

Return the boxes in the order they should be laid out across the line.
private OrderedBoxes ( int topDepth ) : IEnumerable
topDepth int
return IEnumerable
Ejemplo n.º 1
0
		public void OrderedBoxes()
		{
			var styles = new AssembledStyles();

			// Nothing is reversed when everything is at level 0.
			var line = new ParaLine();
			line.Add(MakeStringBox(styles, 0, false));
			line.Add(MakeStringBox(styles, 0, false));
			line.Add(MakeStringBox(styles, 0, false));
			var boxes = new List<Box>(line.OrderedBoxes(0));
			VerifyBoxOrder(line, boxes, new[] { 0, 1, 2 });

			// Also, three adjacent LTRs in an RTL paragraph are not reversed.
			boxes = new List<Box>(line.OrderedBoxes(1));
			VerifyBoxOrder(line, boxes, new[] { 0, 1, 2 });

			// Everything is reversed when everything is at level 1 (ordinary RTL text).
			line = new ParaLine();
			line.Add(MakeStringBox(styles, 1, false));
			line.Add(MakeStringBox(styles, 1, false));
			line.Add(MakeStringBox(styles, 1, false));
			boxes = new List<Box>(line.OrderedBoxes(0));
			VerifyBoxOrder(line, boxes, new[] { 2, 1, 0 });

			// Also, three adjacent RTL boxes in an LTR paragraph are reversed.
			boxes = new List<Box>(line.OrderedBoxes(1));
			VerifyBoxOrder(line, boxes, new[] { 2, 1, 0 });

			// In an RTL paragraph with two adjacent upstream boxes, they preserve their order.
			line = new ParaLine();
			line.Add(MakeStringBox(styles, 1, false));
			line.Add(MakeStringBox(styles, 2, false));
			line.Add(MakeStringBox(styles, 2, false));
			line.Add(MakeStringBox(styles, 1, false));
			boxes = new List<Box>(line.OrderedBoxes(0));
			VerifyBoxOrder(line, boxes, new[] { 3, 1, 2, 0 });

			// In an RTL paragraph with two adjacent upstream boxes, where one is weak, it goes downstream.
			line = new ParaLine();
			line.Add(MakeStringBox(styles, 1, false));
			line.Add(MakeStringBox(styles, 2, false));
			line.Add(MakeStringBox(styles, 2, true));
			line.Add(MakeStringBox(styles, 1, false));
			boxes = new List<Box>(line.OrderedBoxes(0));
			VerifyBoxOrder(line, boxes, new[] { 3, 2, 1, 0 });

			// In an RTL paragraph with three adjacent upstream boxes, where the middle one is weak, it goes upstream.
			line = new ParaLine();
			line.Add(MakeStringBox(styles, 1, false));
			line.Add(MakeStringBox(styles, 2, false));
			line.Add(MakeStringBox(styles, 2, true));
			line.Add(MakeStringBox(styles, 2, false));
			line.Add(MakeStringBox(styles, 1, false));
			boxes = new List<Box>(line.OrderedBoxes(0));
			VerifyBoxOrder(line, boxes, new[] { 4, 1, 2, 3, 0 });
		}
Ejemplo n.º 2
0
		public void ReverseUpstreamBoxes()
		{
			var line = new ParaLine();
			var styles = new AssembledStyles();

			// no  boxes (pathological)
			line.ReverseUpstreamBoxes(0, new List<Box>(), 0);

			// one box
			line = new ParaLine();
			line.Add(MakeStringBox(styles, 3, false));
			var boxes = new List<Box>(line.Boxes);
			line.ReverseUpstreamBoxes(0, boxes, 0);
			VerifyBoxOrder(line, boxes, new [] {0});

			//  two boxes: should re-order only if depth is small enough.
			line = new ParaLine();
			line.Add(MakeStringBox(styles, 2, false));
			line.Add(MakeStringBox(styles, 1, false));
			boxes = new List<Box>(line.Boxes);
			line.ReverseUpstreamBoxes(3, boxes, 0);
			VerifyBoxOrder(line, boxes, new[] { 0, 1 }); // not re-ordered, all depths too small
			line.ReverseUpstreamBoxes(2, boxes, 0);
			VerifyBoxOrder(line, boxes, new[] { 0, 1 }); // not re-ordered, just one that could be
			line.ReverseUpstreamBoxes(1, boxes, 0);
			VerifyBoxOrder(line, boxes, new[] { 1, 0 }); // re-ordered, all <= depth
			line.ReverseUpstreamBoxes(0, boxes, 0);
			VerifyBoxOrder(line, boxes, new[] { 0, 1 }); // re-ordered again, all < depth

			// quite a mixture!
			line = new ParaLine();
			MockDirectionSegment.NextIndex = 0;
			line.Add(MakeStringBox(styles, 2, false));
			line.Add(MakeStringBox(styles, 3, false));
			line.Add(MakeStringBox(styles, 1, false));
			line.Add(MakeStringBox(styles, 2, false));
			line.Add(MakeStringBox(styles, 4, false));
			line.Add(MakeStringBox(styles, 4, false));
			line.Add(MakeStringBox(styles, 4, false));
			line.Add(MakeStringBox(styles, 4, false));
			line.Add(MakeStringBox(styles, 3, false));
			line.Add(MakeStringBox(styles, 4, false));
			line.Add(MakeStringBox(styles, 5, false));
			line.Add(MakeStringBox(styles, 5, false));
			boxes = new List<Box>(line.Boxes);
			line.ReverseUpstreamBoxes(0, boxes, 0);
			VerifyBoxOrder(line, boxes, new[] { 11,10,9,8,7,6,5,4,3,2,1,0 }); // reverse everything
			line.ReverseUpstreamBoxes(1, boxes, 0);
			VerifyBoxOrder(line, boxes, new[] { 0,1,2,3,4,5,6,7,8,9,10,11 }); // back again
			// now the level 1 box at index 2 does not move
			line.ReverseUpstreamBoxes(2, boxes, 0);
			VerifyBoxOrder(line, boxes, new[] { 1, 0, 2, 11, 10, 9, 8, 7, 6, 5, 4, 3 });
			line.ReverseUpstreamBoxes(2, boxes, 0); // put them back!
			VerifyBoxOrder(line, boxes, new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }); // back again
			line.ReverseUpstreamBoxes(4, boxes, 0); // only the groups with more 4 or more reverse
			VerifyBoxOrder(line, boxes, new[] { 0, 1, 2, 3, 7, 6, 5, 4, 8, 11, 10, 9 }); // back again

			boxes = new List<Box>(line.Boxes);
			line.ReverseUpstreamBoxes(1, boxes, 0);
			VerifyBoxOrder(line, boxes, new[] { 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });
			line.ReverseUpstreamBoxes(2, boxes, 0);
			VerifyBoxOrder(line, boxes, new[] { 3, 4, 5, 6, 7, 8, 9, 10, 11, 2, 0, 1 });
			line.ReverseUpstreamBoxes(3, boxes, 0);
			VerifyBoxOrder(line, boxes, new[] { 3, 11, 10, 9, 8, 7, 6, 5, 4, 2, 0, 1 });
			line.ReverseUpstreamBoxes(4, boxes, 0);
			VerifyBoxOrder(line, boxes, new[] { 3, 9, 10, 11, 8, 4, 5, 6, 7, 2, 0, 1 });
			line.ReverseUpstreamBoxes(5, boxes, 0);
			VerifyBoxOrder(line, boxes, new[] { 3, 9, 11, 10, 8, 4, 5, 6, 7, 2, 0, 1 });

			boxes = new List<Box>(line.OrderedBoxes(0));
			// This should do all in one step the reversals indicated in the previous test
			// sequence. The results above indicate how the final sequence is arrived at.
			VerifyBoxOrder(line, boxes, new[] { 3, 9, 11, 10, 8, 4, 5, 6, 7, 2, 0, 1 });

			line = new ParaLine();
			line.Add(new BlockBox(styles, Color.Red, 200, 300));
			line.Add(MakeStringBox(styles, 2, true));
			line.Add(MakeStringBox(styles, 2, true));
			line.Add(new BlockBox(styles, Color.Red, 200, 300));
			boxes = new List<Box>(line.Boxes);
			line.ReverseUpstreamBoxes(2, boxes, 1);
			VerifyBoxOrder(line, boxes, new[] { 0,  2, 1, 3}); // reverse just the string boxes
		}