Esempio n. 1
0
        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 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);
            }
        }
Esempio n. 3
0
        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");
        }