Add() private method

private Add ( Box box ) : void
box Box
return void
Esempio 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 });
		}
Esempio 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
		}
Esempio n. 3
0
		public void ArrangeBoxes()
		{
			var styles = new AssembledStyles();

			// Ordinary layout
			var line = new ParaLine();
			line.Add(MakeStringBox(styles, 0, false));
			var box2 = MakeStringBox(styles, 0, false);
			line.Add(box2);
			line.Add(MakeStringBox(styles, 0, false));
			((MockDirectionSegment) box2.Segment).SimulatedWidth = 20;
			var layoutInfo = MakeLayoutInfo();
			foreach (var box in line.Boxes)
				box.Layout(layoutInfo);
			line.ArrangeBoxes(FwTextAlign.ktalLeft, 7, 0, 0, 100, 0);
			Assert.That(line.Boxes.First().Left, Is.EqualTo(7));
			Assert.That(line.Boxes.Skip(1).First().Left, Is.EqualTo(17)); // past first default(10)-width box
			Assert.That(line.Boxes.Skip(2).First().Left, Is.EqualTo(37)); // past second, 20-pixel box.

			// Still LTR, but aligned right
			line.ArrangeBoxes(FwTextAlign.ktalRight, 7, 3, 10, 100, 0);
			Assert.That(line.Boxes.Skip(2).First().Left, Is.EqualTo(100 - 3 - 10)); // from maxwidth, minus gapright, minus 10 pix width.
			Assert.That(line.Boxes.Skip(1).First().Left, Is.EqualTo(100 - 3 - 10 - 20)); // further left by 20 pix width of middle default-width box
			Assert.That(line.Boxes.First().Left, Is.EqualTo(100 -3 - 10 - 20 - 10)); // still further by 10 pix width of first box

			// Still LTR, but aligned center
			line.ArrangeBoxes(FwTextAlign.ktalCenter, 7, 3, 10, 100, 0);
			int sumBoxWidth = 40;
			int available = 100 - 7 - 3 - 10; // the width in which we can center
			int start = 7 + 10 + (available - sumBoxWidth)/2;
			Assert.That(line.Boxes.First().Left, Is.EqualTo(start));
			Assert.That(line.Boxes.Skip(1).First().Left, Is.EqualTo(start + 10)); // past first default(10)-width box
			Assert.That(line.Boxes.Skip(2).First().Left, Is.EqualTo(start + 30)); // past second, 20-pixel box.

			// Enhance: add test for justified.

			// Now simulate RTL paragraph with similar contents. Boxes are in opposite order.
			line = new ParaLine();
			line.Add(MakeStringBox(styles, 1, false));
			box2 = MakeStringBox(styles, 1, false);
			line.Add(box2);
			line.Add(MakeStringBox(styles, 1, false));
			((MockDirectionSegment)box2.Segment).SimulatedWidth = 30;
			foreach (var box in line.Boxes)
				box.Layout(layoutInfo);
			line.ArrangeBoxes(FwTextAlign.ktalLeft, 7, 0, 0, 100, 1);
			Assert.That(line.Boxes.Skip(2).First().Left, Is.EqualTo(7)); // last box is now leftmost.
			Assert.That(line.Boxes.Skip(1).First().Left, Is.EqualTo(17)); // second is left of first by width of first
			Assert.That(line.Boxes.First().Left, Is.EqualTo(47)); // first is now on the right.

			// Verify that it works correctly for align right (obey firstLineIndent!) and center.
			line.ArrangeBoxes(FwTextAlign.ktalRight, 7, 3, 15, 100, 1);
			var rightOfFirstBox = 100 - 3 - 15;
			Assert.That(line.Boxes.First().Right, Is.EqualTo(rightOfFirstBox));
			Assert.That(line.Boxes.Skip(1).First().Right, Is.EqualTo(rightOfFirstBox - 10)); // past first default-width box
			Assert.That(line.Boxes.Skip(2).First().Right, Is.EqualTo(rightOfFirstBox - 10 - 30)); // past second, 30-pixel box.
		}
Esempio n. 4
0
		public void SetWeakDirections()
		{
			var line = new ParaLine();
			var styles = new AssembledStyles();

			// no  boxes (pathological)
			line.SetWeakDirections(0);

			// no weak boxes
			line = new ParaLine();
			line.Add(MakeStringBox(styles, 3, false));
			line.SetWeakDirections(0);
			VerifyDepth(line, 0, 3);

			// one weak box alone: no change
			line = new ParaLine();
			line.Add(MakeStringBox(styles, 3, true));
			line.SetWeakDirections(1);
			VerifyDepth(line, 0, 1);

			//  one at start, followed by a non-weak
			line = new ParaLine();
			line.Add(MakeStringBox(styles, 2, true));
			line.Add(MakeStringBox(styles, 1, false));
			line.SetWeakDirections(0);
			VerifyDepth(line, 0, 0); // adjacent to paragraph boundary, topDepth wins
			line.SetWeakDirections(2);
			VerifyDepth(line, 0, 1); // adjacent box has lower depth.

			// two at start, followed by non-weak; also two at end and four in middle.
			line = new ParaLine();
			line.Add(MakeStringBox(styles, 2, true));
			line.Add(MakeStringBox(styles, 3, true));
			line.Add(MakeStringBox(styles, 1, false));
			line.Add(MakeStringBox(styles, 2, false));
			line.Add(MakeStringBox(styles, 4, true));
			line.Add(MakeStringBox(styles, 4, true));
			line.Add(MakeStringBox(styles, 4, true));
			line.Add(MakeStringBox(styles, 4, true));
			line.Add(MakeStringBox(styles, 3, false));
			line.Add(MakeStringBox(styles, 4, false));
			line.Add(MakeStringBox(styles, 5, true));
			line.Add(MakeStringBox(styles, 5, true));
			line.SetWeakDirections(6); // let the adjacent boxes rather than the paragraph depth win.
			VerifyDepth(line, 0, 1); // first two set to depth of following box
			VerifyDepth(line, 1, 1);
			VerifyDepth(line, 4, 2); // middle four set to depth of preceding box
			VerifyDepth(line, 5, 2);
			VerifyDepth(line, 6, 2);
			VerifyDepth(line, 7, 2);
			VerifyDepth(line, 10, 4); // last two set to depth of preceding
			VerifyDepth(line, 11, 4);
			line.SetWeakDirections(0); // let the adjacent boxes rather than the paragraph depth win.
			VerifyDepth(line, 0, 0); // topdepth from para boundary
			VerifyDepth(line, 1, 0);
			VerifyDepth(line, 4, 2); // middle four set to depth of preceding box
			VerifyDepth(line, 5, 2);
			VerifyDepth(line, 6, 2);
			VerifyDepth(line, 7, 2);
			VerifyDepth(line, 10, 0); // topdepth from para boundary
			VerifyDepth(line, 11, 0);

			line= new ParaLine();
			line.Add(MakeStringBox(styles, 2, false));
			line.Add(MakeStringBox(styles, 3, true));
			line.Add(new BlockBox(styles, Color.Red, 200, 300));
			line.SetWeakDirections(1); // The block box is considered to have depth 1 and wins
			VerifyDepth(line, 1, 1);
		}
Esempio n. 5
0
 private void AddBoxToLine(Box boxToAdd, LgEndSegmentType est)
 {
     m_currentLine.Add(boxToAdd);
     m_lineSegTypes.Add(est);
 }