private void InitLongText() { var stylesheet = SetupStyles(); var styles = new AssembledStyles(stylesheet); RootBox root = new RootBoxFdo(styles.WithLineHeight(12500)); var owner = new ParagraphOwnerDemo(); var words = "This is a bit of text from which we can extract substrings of increasing length to populate various paragraphs in different ways" .Split(' '); string sb = ""; int ws = 1; // arbitrary with default renderer factory. for (int i = 0; i < 20; i++) { if (i < words.Length) { sb += (words[i]); } if (i < words.Length) { sb += (" "); } var para = ApplyTsStringStyle(sb, "Normal", ws); owner.InsertParagraph(0, para); } root.Builder.Show(Div.Containing(Div.Containing(Display.Of(() => owner.Paragraphs).Using( (builder, para) => builder.Show(Paragraph.Containing(Display.Of(() => para.TsContents)).Style(para.ParaStyle))) .EditParagraphsUsing(new ParagraphOpsDemo(owner))).Border(1500).Pads(3000, 3000, 3000, 3000)).Border(2500).Pads(1000, 1000, 1000, 1000)); styleChooser.Visible = true; theSharpView.Root = root; root.SelectAtStart().Install(); theSharpView.Focus(); }
public void PileAndBlock() { var root = new RootBoxFdo(new AssembledStyles()); SetupFakeRootSite(root); var layoutInfo = HookupTests.MakeLayoutInfo(int.MaxValue / 2, m_gm.VwGraphics, 55); root.RendererFactory = layoutInfo.RendererFactory; var mock1 = new MockData1() { SimpleThree = "This is the first paragraph." }; // The length of the second paragraph is found by experiment to be enough so that // despite its lacking borders it also breaks into 2 lines in the second step. var mock2 = new MockData1() { SimpleThree = "Here is another paragraph. It needs to be a bit longer." }; root.Builder.Show( Div.Containing( Display.Block(Color.Red, 25000, 18000).BackColor(Color.Purple) .Margins(3000, 3000, 3000, 3000) .Border(5000, Color.Blue) .Pads(4000, 4000, 4000, 4000), Display.Block(Color.Green, 25000, 18000) ).BackColor(Color.Pink) // these apply to div. .Margins(1000, 1000, 1000, 1000) .Border(2000, Color.Gold) .Pads(6000, 6000, 6000, 6000)); root.Layout(layoutInfo); // We want to keep track of the sequence of paint operations in all three segments. var drawActions = new List <object>(); var vg = new MockGraphics(); vg.DrawActions = drawActions; var site = (MockSite)root.Site; root.Paint(vg, site.m_transform); var paintTrans = site.m_transform; int position = 0; int xOffset = 2 - 100; // how far it is pushed over by the offsets of the layoutInfo int yOffset = 2 - 200; // how far it is pushed down by the offsets of the layoutInfo int red = (int)ColorUtil.ConvertColorToBGR(Color.Red); int pink = (int)ColorUtil.ConvertColorToBGR(Color.Pink); int purple = (int)ColorUtil.ConvertColorToBGR(Color.Purple); int blue = (int)ColorUtil.ConvertColorToBGR(Color.Blue); int green = (int)ColorUtil.ConvertColorToBGR(Color.Green); int gold = (int)ColorUtil.ConvertColorToBGR(Color.Gold); // Technically we could do different conversions in the two directions, but for this test both dpi are the same. int margPile = layoutInfo.MpToPixelsX(1000); int bordPile = layoutInfo.MpToPixelsX(2000); int padPile = layoutInfo.MpToPixelsX(6000); int blockWidth = layoutInfo.MpToPixelsX(25000); int blockHeight = layoutInfo.MpToPixelsX(18000); int margBlock = layoutInfo.MpToPixelsX(3000); int bordBlock = layoutInfo.MpToPixelsX(5000); int padBlock = layoutInfo.MpToPixelsX(4000); // First a background rectangle for the whole pile. var leftPilePad = margPile + bordPile + xOffset; var topPilePad = margPile + bordPile + yOffset; var rightPilePad = margPile + bordPile + 2 * padPile + blockWidth + 2 * margBlock + 2 * bordBlock + 2 * padBlock + xOffset; var bottomPilePad = margPile + bordPile + 2 * padPile + 2 * blockHeight + 2 * margBlock + 2 * bordBlock + 2 * padBlock + yOffset; VerifyRect(drawActions, ref position, leftPilePad, topPilePad, rightPilePad, bottomPilePad, pink); // Left border, whole pile VerifyRect(drawActions, ref position, leftPilePad - bordPile, topPilePad - bordPile, leftPilePad, bottomPilePad + bordPile, gold); // top border, whole pile VerifyRect(drawActions, ref position, leftPilePad - bordPile, topPilePad - bordPile, rightPilePad + bordPile, topPilePad, gold); // right border, whole pile VerifyRect(drawActions, ref position, rightPilePad, topPilePad - bordPile, rightPilePad + bordPile, bottomPilePad + bordPile, gold); // bottom border, whole pile VerifyRect(drawActions, ref position, leftPilePad - bordPile, bottomPilePad, rightPilePad + bordPile, bottomPilePad + bordPile, gold); // background and border for first block. var leftBlockPad = margPile + bordPile + padPile + margBlock + bordBlock + xOffset; var topBlockPad = margPile + bordPile + padPile + margBlock + bordBlock + yOffset; var rightBlockPad = margPile + bordPile + padPile + margBlock + bordBlock + 2 * padBlock + blockWidth + xOffset; var bottomBlockPad = margPile + bordPile + padPile + margBlock + bordBlock + 2 * padBlock + blockHeight + yOffset; VerifyRect(drawActions, ref position, leftBlockPad, topBlockPad, rightBlockPad, bottomBlockPad, purple); // Left border, whole pile VerifyRect(drawActions, ref position, leftBlockPad - bordBlock, topBlockPad - bordBlock, leftBlockPad, bottomBlockPad + bordBlock, blue); // top border, whole pile VerifyRect(drawActions, ref position, leftBlockPad - bordBlock, topBlockPad - bordBlock, rightBlockPad + bordBlock, topBlockPad, blue); // right border, whole pile VerifyRect(drawActions, ref position, rightBlockPad, topBlockPad - bordBlock, rightBlockPad + bordBlock, bottomBlockPad + bordBlock, blue); // bottom border, whole pile VerifyRect(drawActions, ref position, leftBlockPad - bordBlock, bottomBlockPad, rightBlockPad + bordBlock, bottomBlockPad + bordBlock, blue); // The first block itself. VerifyRect(drawActions, ref position, leftBlockPad + padBlock, topBlockPad + padBlock, leftBlockPad + padBlock + blockWidth, topBlockPad + padBlock + blockHeight, red); // The second block itself. var topBlock2 = bottomBlockPad + bordBlock + margBlock; VerifyRect(drawActions, ref position, leftPilePad + padPile, topBlock2, leftPilePad + padPile + blockWidth, topBlock2 + blockHeight, green); // And that should be all! Assert.That(position, Is.EqualTo(drawActions.Count)); // A quick check that Relayout puts things in the same places. drawActions.Clear(); var fixupMap = new Dictionary <Box, Rectangle>(); var div1 = (DivBox)root.FirstBox; var block1 = div1.FirstBox; fixupMap[div1] = new Rectangle(0, 0, 10, 10); fixupMap[block1] = new Rectangle(0, 0, 10, 10); var oldblock1Left = block1.Left; var oldblock1bTop = block1.Top; using (var lcb = new LayoutCallbacks(root)) root.Relayout(layoutInfo, fixupMap, lcb); Assert.That(drawActions.Count, Is.EqualTo(0)); Assert.That(div1.FirstBox.Left, Is.EqualTo(oldblock1Left)); Assert.That(div1.FirstBox.Top, Is.EqualTo(oldblock1bTop)); }