コード例 #1
0
		public void BidiLayout()
		{
			string content1 = "This is the ";
			string contentRtl = "day ";
			string content3 = "that ";

			// Two writing systems
			int wsLtr = 5;
			int wsRtl = 6;

			// Two corresponding renderers
			var factory = new FakeRendererFactory();
			var engineLtr = new FakeRenderEngine() { Ws = wsLtr, SegmentHeight = 13 };
			factory.SetRenderer(wsLtr, engineLtr);
			var engineRtl = new FakeRenderEngine() {Ws = wsRtl, SegmentHeight = 13 };
			engineRtl.RightToLeft = true;
			factory.SetRenderer(wsRtl, engineRtl);

			// Two corresponding styles (and a vanilla one)
			var styles = new AssembledStyles();
			var stylesLtr = new AssembledStyles().WithWs(wsLtr);
			var stylesRtl = new AssembledStyles().WithWs(wsRtl);

			var clientRuns = new List<IClientRun>();
			var run1 = new StringClientRun(content1, stylesLtr);
			clientRuns.Add(run1);
			var runRtl = new StringClientRun(contentRtl, stylesRtl);
			clientRuns.Add(runRtl);
			var run3 = new StringClientRun(content3, stylesLtr);
			clientRuns.Add(run3);

			var root = new RootBoxFdo(styles);

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

			var stylesParaRtl = styles.WithRightToLeft(true);
			var sourceRtl = new TextSource(clientRuns, null);
			var paraRtl = new ParaBox(stylesParaRtl, sourceRtl);
			root.AddBox(paraRtl);

			var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory);
			root.Layout(layoutArgs);

			// "day " being upstream should make two distinct boxes.
			// We should get something like
			// "This is the yad that ", where the space between "yad" and "that" is the one that
			// follows the 'y' in "day".
			var box1 = para.FirstBox as StringBox;
			var box2 = box1.Next as StringBox;
			var box3 = box2.Next as StringBox;
			var box4 = box3.Next as StringBox;
			Assert.That(box4, Is.Not.Null);
			Assert.That(box1.Segment.get_Lim(box1.IchMin) == content1.Length);
			Assert.That(box2.Segment.get_Lim(box2.IchMin) == contentRtl.Length - 1);
			Assert.That(box3.Segment.get_Lim(box3.IchMin) == 1);
			Assert.That(box4.Segment.get_Lim(box4.IchMin) == content3.Length);
			Assert.That(box1.Left, Is.LessThan(box2.Left));
			Assert.That(box2.Left, Is.LessThan(box3.Left));
			Assert.That(box3.Left, Is.LessThan(box4.Left));

			// In the second paragraph, the two LRT runs are upstream. We should get boxes
			// "This is the", " ", "day ", "that" and " " (but the final space will have zero width at end of line)
			// The effect should be something like
			// that yad This is the", where the space between "yad" and "This" is the one following "the",
			// and the one between "that" and "yad" is the one following "day", and the space following "that"
			// is invisible at the end of the line to the left of 'that'.
			var boxR1 = paraRtl.FirstBox as StringBox;
			var boxR2 = boxR1.Next as StringBox;
			var boxR3 = boxR2.Next as StringBox;
			var boxR4 = boxR3.Next as StringBox;
			var boxR5 = boxR4.Next as StringBox;
			Assert.That(boxR5, Is.Not.Null);
			Assert.That(boxR1.Segment.get_Lim(boxR1.IchMin) == content1.Length - 1);
			Assert.That(boxR2.Segment.get_Lim(boxR2.IchMin) == 1);
			Assert.That(boxR3.Segment.get_Lim(boxR3.IchMin) == contentRtl.Length);
			Assert.That(boxR4.Segment.get_Lim(boxR4.IchMin) == content3.Length - 1);
			Assert.That(boxR5.Segment.get_Lim(boxR5.IchMin) == 1);
		}