public void PageElementsDontOverlap_TwoFootnotes() { IScripture scr = Cache.LangProject.TranslatedScriptureOA; ScrBook genesis = (ScrBook)scr.ScriptureBooksOS[0]; // Add a footnote in the first book, first section, first paragraph IScrSection section = (IScrSection)genesis.SectionsOS[0]; StFootnote footnote = m_scrInMemoryCache.AddFootnote(genesis, (StTxtPara)section.ContentOA.ParagraphsOS[0], 2); StTxtPara para = m_scrInMemoryCache.AddParaToMockedText(footnote.Hvo, ScrStyleNames.NormalFootnoteParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "Another footnote", 0); // Add a footnote in the first book, last section, 6th paragraph section = (IScrSection)genesis.SectionsOS[genesis.SectionsOS.Count - 1]; footnote = m_scrInMemoryCache.AddFootnote(genesis, (StTxtPara)section.ContentOA.ParagraphsOS[5], 10); para = m_scrInMemoryCache.AddParaToMockedText(footnote.Hvo, ScrStyleNames.NormalFootnoteParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "This is the footnote", 0); m_pub.CreatePages(); m_pub.PrepareToDrawPages(0, m_pub.AutoScrollMinSize.Height * 2); Page firstPage = m_pub.Pages[0]; int cFoonotesOnThisPage = (int)m_division.m_testPageFootnoteInfo[firstPage.Handle]; Assert.AreEqual(2, cFoonotesOnThisPage, "Should display two footnotes on first page"); // None of the page elements on the first page should intersect CheckThatPageElementsDontOverlap(firstPage); }
public void AdjustScrollRange_GrowFootnoteStream() { DummyVwLayoutStream stream = new DummyVwLayoutStream(); DummyVwLayoutStream footnoteStream = new DummyVwLayoutStream(); using (GoofyDivision divMgr = new GoofyDivision(stream)) using (DummyPublication pubCtrl = new DummyPublication(null, divMgr, DateTime.Now)) { pubCtrl.PageHeight = 72000 * 6; divMgr.m_overrideHeight = divMgr.AvailablePageHeightInPrinterPixels; pubCtrl.CreatePages(); Assert.AreEqual(2, pubCtrl.PageCount); divMgr.CallAddElement(pubCtrl.Pages[0], divMgr.m_overrideHeight - 100, 1, 1, divMgr.InsideMarginInPrinterPixels, 20, divMgr.AvailablePageHeightInPrinterPixels); int origTopOfPageTwo = divMgr.m_overrideHeight - 100; ((DummyPage)pubCtrl.Pages[0]).CallAddPageElement(divMgr, footnoteStream, false, new Rectangle(divMgr.InsideMarginInPrinterPixels, divMgr.m_overrideHeight - 100, divMgr.AvailablePageWidthInPrinterPixels, 100), 0, false, 1, 1, 0, 100, false, true); divMgr.CallAddElement(pubCtrl.Pages[1], 100, 1, 1, divMgr.OutsideMarginInPrinterPixels, origTopOfPageTwo, divMgr.AvailablePageHeightInPrinterPixels); ((DummyPage)pubCtrl.Pages[1]).CallAddPageElement(divMgr, footnoteStream, false, new Rectangle(divMgr.InsideMarginInPrinterPixels, divMgr.m_overrideHeight - 100, divMgr.AvailablePageWidthInPrinterPixels, 100), 101, false, 1, 1, 0, 100, false, true); Point origScrollPos = pubCtrl.ScrollPosition; Size origScrollSize = pubCtrl.AutoScrollMinSize; pubCtrl.AdjustScrollRange(footnoteStream, 0, 0, 300, 95); Assert.AreEqual(2, pubCtrl.PageCount); Assert.AreEqual(origScrollPos, pubCtrl.ScrollPosition); Assert.AreEqual(origScrollSize, pubCtrl.AutoScrollMinSize); Assert.AreEqual(0, pubCtrl.Pages[0].PageElements[1].OffsetToTopPageBoundary); Assert.AreEqual(401, pubCtrl.Pages[1].PageElements[1].OffsetToTopPageBoundary); Assert.AreEqual(20, pubCtrl.Pages[0].OffsetFromTopOfDiv(divMgr)); Assert.AreEqual(origTopOfPageTwo, pubCtrl.Pages[1].OffsetFromTopOfDiv(divMgr)); } }
public void AdjustScrollRange_GrowFirstDivOnPage() { DummyVwLayoutStream stream = new DummyVwLayoutStream(); using (GoofyDivision divMgr = new GoofyDivision(stream)) using (DummyPublication pubCtrl = new DummyPublication(null, divMgr, DateTime.Now)) { pubCtrl.PageHeight = 72000 * 6; divMgr.m_overrideHeight = divMgr.AvailablePageHeightInPrinterPixels; pubCtrl.CreatePages(); Assert.AreEqual(2, pubCtrl.PageCount); divMgr.CallAddElement(pubCtrl.Pages[0], divMgr.m_overrideHeight - 20, 1, 1, divMgr.InsideMarginInPrinterPixels, 20, divMgr.AvailablePageHeightInPrinterPixels); int origTopOfPageTwo = divMgr.m_overrideHeight - 20; divMgr.CallAddElement(pubCtrl.Pages[1], 20, 1, 1, divMgr.OutsideMarginInPrinterPixels, origTopOfPageTwo, divMgr.AvailablePageHeightInPrinterPixels); Point origScrollPos = pubCtrl.ScrollPosition; Size origScrollSize = pubCtrl.AutoScrollMinSize; pubCtrl.AdjustScrollRange(stream, 0, 0, 300, origTopOfPageTwo - 2000); Assert.AreEqual(2, pubCtrl.PageCount); Assert.AreEqual(origScrollPos, pubCtrl.ScrollPosition); Assert.AreEqual(origScrollSize, pubCtrl.AutoScrollMinSize); Assert.AreEqual(20, pubCtrl.Pages[0].PageElements[0].OffsetToTopPageBoundary); Assert.AreEqual(origTopOfPageTwo + 300, pubCtrl.Pages[1].PageElements[0].OffsetToTopPageBoundary); Assert.IsFalse(pubCtrl.Pages[0].NeedsLayout); Assert.IsTrue(pubCtrl.Pages[1].NeedsLayout); } }
public void AdjustScrollRange_GrowFirstDivOnPage_NoElements() { DummyVwLayoutStream stream = new DummyVwLayoutStream(); using (GoofyDivision divMgr = new GoofyDivision(stream)) using (DummyPublication pubCtrl = new DummyPublication(null, divMgr, DateTime.Now)) { pubCtrl.PageHeight = 72000 * 6; divMgr.m_overrideHeight = divMgr.AvailablePageHeightInPrinterPixels; pubCtrl.CreatePages(); Assert.AreEqual(2, pubCtrl.PageCount); Assert.AreEqual(0, pubCtrl.Pages[0].PageElements.Count); Assert.AreEqual(0, pubCtrl.Pages[1].PageElements.Count); Point origScrollPos = pubCtrl.ScrollPosition; Size origScrollSize = pubCtrl.AutoScrollMinSize; pubCtrl.AdjustScrollRange(stream, 0, 0, 300, 0); Assert.AreEqual(2, pubCtrl.PageCount); Assert.AreEqual(origScrollPos, pubCtrl.ScrollPosition); Assert.AreEqual(origScrollSize, pubCtrl.AutoScrollMinSize); Assert.AreEqual(0, pubCtrl.Pages[0].PageElements.Count); Assert.AreEqual(0, pubCtrl.Pages[1].PageElements.Count); Assert.IsTrue(pubCtrl.Pages[0].NeedsLayout); Assert.IsTrue(pubCtrl.Pages[1].NeedsLayout); } }
public void AdjustScrollRange_GrowSecondDivOnPageTwo() { DummyVwLayoutStream stream1 = new DummyVwLayoutStream(); DummyVwLayoutStream stream2 = new DummyVwLayoutStream(); using (GoofyDivision divMgr1 = new GoofyDivision(stream1)) using (GoofyDivision divMgr2 = new GoofyDivision(stream2)) using (DummyPublication pubCtrl = new DummyPublication(null, divMgr1, DateTime.Now)) { pubCtrl.PageHeight = 72000 * 6; pubCtrl.AddDivision(divMgr2); divMgr1.m_overrideHeight = divMgr1.AvailablePageHeightInPrinterPixels; divMgr2.m_overrideHeight = divMgr2.AvailablePageHeightInPrinterPixels; divMgr2.StartAt = DivisionStartOption.Continuous; pubCtrl.CreatePages(); Assert.AreEqual(3, pubCtrl.PageCount); divMgr1.CallAddElement(pubCtrl.Pages[0], divMgr1.m_overrideHeight - 20, 1, 1, divMgr1.InsideMarginInPrinterPixels, 20, divMgr1.AvailablePageHeightInPrinterPixels); int origTopOfPageTwoDiv1 = divMgr1.m_overrideHeight - 20; divMgr1.CallAddElement(pubCtrl.Pages[1], 20, 1, 1, divMgr1.OutsideMarginInPrinterPixels, origTopOfPageTwoDiv1, divMgr1.AvailablePageHeightInPrinterPixels); Page origPg3 = pubCtrl.Pages[2]; int origTopOfPageThreeDiv2 = origPg3.OffsetFromTopOfDiv(divMgr2); Point origScrollPos = pubCtrl.ScrollPosition; Size origScrollSize = pubCtrl.AutoScrollMinSize; pubCtrl.AdjustScrollRange(stream2, 0, 0, divMgr2.AvailablePageHeightInPrinterPixels, 0); Assert.AreEqual(4, pubCtrl.PageCount); Assert.IsFalse(pubCtrl.Pages[0].NeedsLayout); Assert.IsFalse(pubCtrl.Pages[1].NeedsLayout, "This test simulates a call to AdjustScrollRange that happens in the middle of laying out this page, so it should not get flagged as needing layout."); Assert.IsTrue(pubCtrl.Pages[2].NeedsLayout); Assert.IsTrue(pubCtrl.Pages[3].NeedsLayout); Assert.AreEqual(origScrollPos, pubCtrl.ScrollPosition); Assert.AreEqual(origScrollSize.Height * 4 / 3, pubCtrl.AutoScrollMinSize.Height); Assert.AreEqual(1, pubCtrl.Pages[0].PageElements.Count); Assert.AreEqual(20, pubCtrl.Pages[0].PageElements[0].OffsetToTopPageBoundary); Assert.AreEqual(1, pubCtrl.Pages[1].PageElements.Count); Assert.AreEqual(origTopOfPageTwoDiv1, pubCtrl.Pages[1].OffsetFromTopOfDiv(divMgr1)); Assert.AreEqual(0, pubCtrl.Pages[1].OffsetFromTopOfDiv(divMgr2)); Assert.AreEqual(origPg3, pubCtrl.Pages[3], "A page should have been inserted between the original page 2 and page 3."); Assert.AreEqual(0, pubCtrl.Pages[2].PageElements.Count); Assert.AreEqual(divMgr2.AvailablePageHeightInPrinterPixels, pubCtrl.Pages[2].OffsetFromTopOfDiv(divMgr2), "Inserted page's offset from top of division 2 should be one ideal page from the top."); Assert.AreEqual(0, pubCtrl.Pages[3].PageElements.Count); Assert.AreEqual(origTopOfPageThreeDiv2 + divMgr2.AvailablePageHeightInPrinterPixels, pubCtrl.Pages[3].OffsetFromTopOfDiv(divMgr2)); } }
public void AdjustScrollRange_ShrinkFirstDivOnPage() { DummyVwLayoutStream stream = new DummyVwLayoutStream(); GoofyDivision divMgr = new GoofyDivision(stream); DummyPublication pubCtrl = new DummyPublication(null, divMgr, DateTime.Now); pubCtrl.PageHeight = 72000 * 6; divMgr.m_overrideHeight = divMgr.AvailablePageHeightInPrinterPixels * 2; pubCtrl.CreatePages(); Assert.AreEqual(3, pubCtrl.PageCount); Page pg1 = pubCtrl.Pages[0]; Page pg2 = pubCtrl.Pages[1]; Page pg3 = pubCtrl.Pages[2]; divMgr.CallAddElement(pg1, divMgr.AvailablePageHeightInPrinterPixels - 20, 1, 1, divMgr.InsideMarginInPrinterPixels, 20, divMgr.AvailablePageHeightInPrinterPixels); int origTopOfPageTwo = divMgr.AvailablePageHeightInPrinterPixels - 40; divMgr.CallAddElement(pg2, divMgr.AvailablePageHeightInPrinterPixels - 20, 1, 1, divMgr.OutsideMarginInPrinterPixels, origTopOfPageTwo, divMgr.AvailablePageHeightInPrinterPixels); int origTopOfPageThree = divMgr.m_overrideHeight - 60; divMgr.CallAddElement(pg3, 40, 1, 1, divMgr.InsideMarginInPrinterPixels, origTopOfPageThree, divMgr.AvailablePageHeightInPrinterPixels); foreach (Page pg in pubCtrl.Pages) { Assert.AreEqual(pg.PageElements[0].OffsetToTopPageBoundary, pg.OffsetFromTopOfDiv(divMgr)); } Point origScrollPos = pubCtrl.ScrollPosition; Size origScrollSize = pubCtrl.AutoScrollMinSize; // The following should cause the original page 2 to be deleted and adjust the top of // the original page 3 (now page 2) to be the same as the original top of page 2. pubCtrl.AdjustScrollRange(stream, 0, 0, -divMgr.AvailablePageHeightInPrinterPixels, origTopOfPageTwo - 2000); Assert.AreEqual(2, pubCtrl.PageCount); Assert.AreEqual(origScrollPos, pubCtrl.ScrollPosition); Assert.AreEqual(origScrollSize.Height * 2 / 3, pubCtrl.AutoScrollMinSize.Height); Assert.AreEqual(20, pg1.PageElements[0].OffsetToTopPageBoundary); Assert.AreEqual(pg3, pubCtrl.Pages[1]); Assert.AreEqual(origTopOfPageThree - divMgr.AvailablePageHeightInPrinterPixels, pg3.PageElements[0].OffsetToTopPageBoundary); Assert.AreEqual(40, pg3.PageElements[0].LocationOnPage.Height); Assert.IsFalse(pg1.NeedsLayout); Assert.IsTrue(pg3.NeedsLayout); }
public void HeaderFooterLayout() { m_pub.PageHeight = 72000 * 6; // 6 inches m_pub.PageWidth = 72000 * 6; // 6 inches m_division.TopMargin = 72000; // inch m_division.BottomMargin = 72000; // inch m_division.InsideMargin = 9000; // 1/8 inch m_division.OutsideMargin = 4500; // 1/16 inch m_division.HeaderPosition = 72000 * 3 / 4; m_division.FooterPosition = 72000 * 3 / 4; m_pub.Width = 6 * 96; // represents a window that is 6" wide at 96 DPI m_pub.CreatePages(); Assert.IsTrue(m_pub.Pages.Count >= 2, "For this test, we want to check at least two pages."); Page firstPage = ((Page)m_pub.Pages[0]); Assert.AreEqual(0, firstPage.PageElements.Count, "Nothing should be laid out on page yet."); // Lay out all the pages List <Page> pagesToBeDrawn = m_pub.PrepareToDrawPages(0, m_pub.Pages.Count * 6 * 96); Assert.AreEqual(m_pub.Pages.Count, pagesToBeDrawn.Count, "All pages should be ready to be drawn"); foreach (Page page in pagesToBeDrawn) { Assert.AreEqual(3, page.PageElements.Count, "Header/Footer elements should be included on page " + page.PageNumber); PageElement peMain = page.GetFirstElementForStream(m_division.MainLayoutStream); Assert.IsNotNull(peMain); bool fFoundHeaderElement = false; bool fFoundFooterElement = false; foreach (PageElement pe in page.PageElements) { if (pe != peMain) { Assert.AreEqual(0, pe.OffsetToTopPageBoundary); if (page.PageNumber % 2 == 1) { Assert.AreEqual(m_pub.DpiXPrinter / 8, pe.LocationOnPage.X, "Odd page should have 1/8 inch left margin"); } else { Assert.AreEqual(m_pub.DpiXPrinter / 16, pe.LocationOnPage.X, "Even page should have 1/16 inch left margin"); } if (pe.LocationOnPage.Y == m_pub.DpiYPrinter / 2) { Assert.AreEqual(m_pub.DpiYPrinter / 4, pe.LocationOnPage.Height, "Header element should be a 1/4-inch rectangle"); Assert.IsFalse(fFoundHeaderElement); fFoundHeaderElement = true; } else { Assert.AreEqual(Math.Round(m_pub.DpiYPrinter * 5.25, MidpointRounding.AwayFromZero), pe.LocationOnPage.Y, "Found element that isn't in the correct header or footer position"); Assert.AreEqual(m_pub.DpiYPrinter * 3 / 4, pe.LocationOnPage.Height, "Footer element height should have been limited to 3/4 inch"); Assert.IsFalse(fFoundFooterElement); fFoundFooterElement = true; } } } Assert.IsTrue(fFoundFooterElement); Assert.IsTrue(fFoundHeaderElement); } }
public void SmallEstimates() { CheckDisposed(); m_pub.PageHeight = 72000 * 5; // 5 inches m_pub.PageWidth = 72000 * 3; // 3 inches m_division.TopMargin = 36000; // Half inch m_division.BottomMargin = 18000; // Quarter inch m_division.InsideMargin = 9000; // 1/8 inch m_division.OutsideMargin = 4500; // 1/16 inch DummyMainLazyViewVc vc = m_division.MainVc as DummyMainLazyViewVc; vc.m_estBookHeight = 100; vc.m_estSectionHeight = 50; m_pub.Width = 3 * 96; // represents a window that is 3" wide at 96 DPI m_pub.CreatePages(); Assert.AreEqual(2, m_pub.Pages.Count, "Our estimate of book size is low, so it should try to fit all of Scripture on 2 pages."); Page firstPage = ((Page)m_pub.Pages[0]); Assert.AreEqual(0, firstPage.FirstDivOnPage); Assert.AreEqual(0, firstPage.OffsetFromTopOfDiv(m_division)); // UNTIL we prepare to draw pages, the three books of Scripture are represented by // a lazy box that is three times the estimated height of a scripture book. // Compute the height of the first line BEFORE we layout any pages. int numberOfBooksInTestLangProj = m_scr.ScriptureBooksOS.Count; int dysHeightOfLiteralLineOfText = m_division.MainRootBox.Height - vc.m_estBookHeight * m_pub.DpiYPrinter / 72 * numberOfBooksInTestLangProj; List <Page> pagesToBeDrawn = m_pub.PrepareToDrawPages(0, 400); Assert.AreEqual(1, pagesToBeDrawn.Count, "First page should be ready to be drawn"); // Tests for TE-1413: As lazy boxes are expanded, add additional pages if necessary Assert.IsTrue(m_pub.Pages.Count > 2, "Expanding lazy boxes for page 1 should increase the estimated number of pages"); // Technically it is possible that the division comes out exactly and we don't need to add 1, // but it's too unlikely to bother with in a test. Assert.AreEqual(m_division.MainRootBox.Height / m_division.AvailablePageHeightInPrinterPixels + 1, m_pub.Pages.Count, "document should fill pages exactly"); // Each paragraph should take exactly one inch. we should be able to fit the one // line of literal text, plus 4 paragraphs on the first page (4.25" high). int dysExpectedP1DataHeight = m_pub.DpiYPrinter * 4 + dysHeightOfLiteralLineOfText; PageElement peMain = firstPage.GetFirstElementForStream(m_division.MainLayoutStream); int dysHeightOfDataOnPage1 = peMain.LocationOnPage.Height; Assert.AreEqual(dysExpectedP1DataHeight, dysHeightOfDataOnPage1, "Wrong amount of data on page 1."); // We should have added enough pages for anything that was expanded pagesToBeDrawn = m_pub.PrepareToDrawPages(401, 801); int dysNewEstHeight = m_division.MainRootBox.Height; int dysAvailPageHeight = m_pub.PageHeightInPrinterPixels - m_division.TopMarginInPrinterPixels - m_division.BottomMarginInPrinterPixels; Assert.IsTrue(dysNewEstHeight <= m_pub.Pages.Count * dysAvailPageHeight, "The page count should be increased to cover new estimated document height"); Assert.IsTrue(dysNewEstHeight > (m_pub.Pages.Count - 1) * dysAvailPageHeight, "The page count should not be increased too much"); }