/// <summary> /// This setup method for para builder is also useful for testing stuff related to the paragraph itself. /// For example, we take advantage of it for testing backspace at start of client run. /// </summary> internal static RootBox MakeTestParaThreeStrings(IVwGraphics vg, MockBreakOption breakOption, out ParaBox para) { var styles = new AssembledStyles().WithWs(s_simpleStringWs); var styles2 = new AssembledStyles().WithWs(s_secondGroupWs); string contents1 = AssembleStrings(s_firstGroupWords); string contents2 = AssembleStrings(s_secondGroupWords); string contents3 = AssembleStrings(s_thirdGroupWords); var clientRuns = new List<IClientRun>(); clientRuns.Add(new StringClientRun(contents1, styles)); clientRuns.Add(new StringClientRun(contents2, styles2)); clientRuns.Add(new StringClientRun(contents3, styles)); var source = new TextSource(clientRuns, null); para = new ParaBox(styles, source); var root = new RootBox(styles); root.AddBox(para); var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, vg); int totalLength = contents1.Length + contents2.Length + contents3.Length; // Arrange the following line breaks. // First the builder will ask to break the whole string, it puts the first three words on a line and indicates it is full. SetupMockEngineForThreeStringsPara(s_firstGroupWords, s_secondGroupWords, s_thirdGroupWords, layoutArgs); root.Layout(layoutArgs); return root; }
/// <summary> /// The setup method for para builder is also useful for testing stuff related to the paragraph itself. /// </summary> /// <param name="vg"></param> /// <param name="para"></param> /// <returns></returns> internal static RootBox MakeTestParaSimpleString(IVwGraphics vg, MockBreakOption breakOption, out ParaBox para) { var styles = new AssembledStyles().WithWs(s_simpleStringWs); string contents = AssembleStrings(s_simpleStringWords); var clientRuns = new List<IClientRun>(); clientRuns.Add(new StringClientRun(contents, styles)); var source = new TextSource(clientRuns, null); para = new ParaBox(styles, source); var root = new RootBox(styles); root.AddBox(para); var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, vg); var engine = layoutArgs.GetRenderer(1) as MockRenderEngine; switch (breakOption) { case MockBreakOption.ThreeOkayBreaks: // This option generates three lines as long as the width is sufficient because // Asked to break the whole string we answer a segment that has the first three words. engine.AddMockSeg(0, contents.Length, SumStringLengths(s_simpleStringWords, 0, 3), s_widthFirstMockSeg, s_simpleStringWs, LgEndSegmentType.kestOkayBreak); // Asked to break the rest of the line we answer a segment with the next three. engine.AddMockSeg(SumStringLengths(s_simpleStringWords, 0, 3), contents.Length, SumStringLengths(s_simpleStringWords, 3, 6), s_widthSecondMockSeg, s_simpleStringWs, LgEndSegmentType.kestOkayBreak); // Asked to break the rest of the line we answer a segment with the last three. engine.AddMockSeg(SumStringLengths(s_simpleStringWords, 0, 6), contents.Length, SumStringLengths(s_simpleStringWords, 6, 9), s_widthThirdMockSeg, s_simpleStringWs, LgEndSegmentType.kestNoMore); break; case MockBreakOption.FourSegsThreeLines: // Asked to break the whole string we answer a segment that has the first two words but allows more. engine.AddMockSeg(0, contents.Length, SumStringLengths(s_simpleStringWords, 0, 2), 50, s_simpleStringWs, LgEndSegmentType.kestOkayBreak); // Asked to break the rest of the line we give one more word and say it fills the line. engine.AddMockSeg(SumStringLengths(s_simpleStringWords, 0, 2), contents.Length, SumStringLengths(s_simpleStringWords, 0, 3), 20, s_simpleStringWs, LgEndSegmentType.kestMoreLines); // Asked to break the rest of the line we answer a segment with the next three and say it fills the line. engine.AddMockSeg(SumStringLengths(s_simpleStringWords, 0, 3), contents.Length, SumStringLengths(s_simpleStringWords, 3, 6), s_widthSecondMockSeg, s_simpleStringWs, LgEndSegmentType.kestMoreLines); // Asked to break the rest of the line we answer a segment with the last three. engine.AddMockSeg(SumStringLengths(s_simpleStringWords, 0, 6), contents.Length, SumStringLengths(s_simpleStringWords, 6, 9), s_widthThirdMockSeg, s_simpleStringWs, LgEndSegmentType.kestNoMore); // Asked to do anything else engine.OtherSegPolicy = UnexpectedSegments.MakeOneCharSeg; break; case MockBreakOption.ThreeFullLines: // Asked to break the whole string we answer a segment that has the first three words. SetupMockEngineForThreeLines(contents, engine, s_simpleStringWords); break; } root.Layout(layoutArgs); return root; }