Beispiel #1
0
        public void DeletePages()
        {
            CheckDisposed();

            m_pub.PageHeight = 72000 * 11;           // 11 inches
            m_pub.PageWidth  = 72000 * 9;            // 9 inches
            // No page margins
            m_division.TopMargin     = 0;
            m_division.BottomMargin  = 0;
            m_division.InsideMargin  = 0;
            m_division.OutsideMargin = 0;
            m_pub.Width = 9 * 96;             // represents a window that is 9" wide at 96 DPI
            DummyMainLazyViewVc vc = m_division.MainVc as DummyMainLazyViewVc;
            // We want estimates so that our 5 books fit on 12 pages plus a little bit on the
            // 13th page.
            int dypBookHeightEst = m_pub.PageHeightPlusGapInScreenPixels * 12 / 5;

            vc.m_estBookHeight    = dypBookHeightEst * 72 / 96;
            vc.m_estSectionHeight = vc.m_estBookHeight / 2;
            m_pub.CreatePages();
            Assert.AreEqual(13, m_pub.Pages.Count, "The expectations of this test don't fit reality");

            // This expands the first two books and should result in fewer pages
            m_pub.PrepareToDrawPages(0, dypBookHeightEst * 2);

            Assert.LessOrEqual(m_pub.Pages.Count, 10, "Should reduce number of pages");
        }
Beispiel #2
0
        public void OutsideOfBounds()
        {
            CheckDisposed();

            m_pub.PageHeight         = 720000 * 5;    // 5 inches
            m_pub.PageWidth          = 720000 * 3;    // 3 inches
            m_division.TopMargin     = 360000;        // Half inch
            m_division.BottomMargin  = 180000;        // Quarter inch
            m_division.InsideMargin  = 90000;         // 1/8 inch
            m_division.OutsideMargin = 45000;         // 1/16 inch
            DummyMainLazyViewVc vc = m_division.MainVc as DummyMainLazyViewVc;

            vc.m_estBookHeight    = 10;
            vc.m_estSectionHeight = 5;
            m_pub.Width           = 30 * 96;   // represents a window that is 3" wide at 96 DPI
            m_pub.CreatePages();

            // 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;

            // this test makes sure that trying to lay a page that can't exsist won't crash.
            List <Page> pagesToBeDrawn = m_pub.PrepareToDrawPages(300000, 400000);
        }
Beispiel #3
0
        public void SomethingElse()
        {
            m_pub.PageHeight = 72000 * 11;           // 11 inches
            m_pub.PageWidth  = 72000 * 9;            // 9 inches
            // No page margins
            m_division.TopMargin     = 0;
            m_division.BottomMargin  = 0;
            m_division.InsideMargin  = 0;
            m_division.OutsideMargin = 0;
            m_pub.Width = 9 * 96;             // represents a window that is 9" wide at 96 DPI
            DummyMainLazyViewVc vc = m_division.MainVc as DummyMainLazyViewVc;
            int dypEstBookHeight   = 30 * 96;

            vc.m_estBookHeight    = dypEstBookHeight * 72 / 96;
            vc.m_estSectionHeight = vc.m_estBookHeight / 2;
            m_pub.CreatePages();
            int cOriginalEstimateOfPages = m_pub.Pages.Count;

            int dypScrollPos = (cOriginalEstimateOfPages - 1) * m_pub.PageHeightPlusGapInScreenPixels + 5;

            m_pub.ScrollPosition = new Point(0, dypScrollPos);
            m_pub.PrepareToDrawPages(dypScrollPos, dypScrollPos + 40);
            //List<Page> pagesToBeDrawn = m_pub.PrepareToDrawPages(dypEstBookHeight * 4 + 20, dypEstBookHeight * 5);
            //int cActualPageCount = pagesToBeDrawn.Count;

            //Assert.IsTrue(m_pub.Pages.Count > cActualPageCount, "All pages should be real drawable pages now");
            //Assert.IsTrue(cActualPageCount < cOriginalEstimateOfPages,
            //    "Our estimate of book size should have been high for this test to be meaningful.");

            //Page pgLast = m_pub.Pages[cActualPageCount - 1] as Page;
            //Page pgSecondToLast = m_pub.Pages[cActualPageCount - 2] as Page;
            //Assert.IsTrue(pgLast.OffsetFromTopOfDiv(m_division) > pgSecondToLast.OffsetFromTopOfDiv(m_division), "last page should be real and in order");
            //Assert.IsTrue(pgLast.PageElements.Count > 0, "last page should have an element");
        }
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Configure a PublicationControl
		/// </summary>
		/// <param name="fAddSubStream">if set to <c>true</c> add subordinate stream.</param>
		/// <param name="fAddContent">if set to <c>true</c> add real content, otherwise add
		/// rectangle for paragraph.</param>
		/// ------------------------------------------------------------------------------------
		private void ConfigurePublication(bool fAddSubStream, bool fAddContent)
		{
			// When called for test setup, they will be null.
			// When called from within as test
			if (m_pub != null)
				m_pub.Dispose();
			if (m_division != null)
				m_division.Dispose();
			m_division = new DummyDivision(new DummyLazyPrintConfigurer(Cache, fAddSubStream,
				fAddContent), 2);
			IPublication pub =
				Cache.LangProject.TranslatedScriptureOA.PublicationsOC.ToArray()[0];
			m_pub = new DummyPublication(pub, m_division, DateTime.Now);
			m_pub.Configure();

			// Check initial state
			Assert.AreEqual(m_division, m_pub.Divisions[0]);
			Assert.IsNotNull(m_division.MainVc as DummyMainLazyViewVc);
			IVwLayoutStream layoutStream = m_division.MainLayoutStream;
			Assert.IsNotNull(layoutStream);
			m_pub.IsLeftBound = true;

			// Set up the publication
			m_pub.PageHeight = 72000 * 11; // 11 inches
			m_pub.PageWidth = (int)(72000 * 8.5); // 8.5 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 = 2000;
			vc.m_estSectionHeight = 2000;
			m_pub.Width = 3 * 96; // represents a window that is 3" wide at 96 DPI
		}
Beispiel #5
0
        public void PagesWithFootnotes()
        {
            CheckDisposed();

            // Need VC with footnotes for this test, so we recreate one
            ConfigurePublication(true);

            // Add a footnote in the last book, last section, last paragraph
            IScripture  scr      = Cache.LangProject.TranslatedScriptureOA;
            ScrBook     deut     = (ScrBook)scr.ScriptureBooksOS[scr.ScriptureBooksOS.Count - 1];
            IScrSection section  = (IScrSection)deut.SectionsOS[deut.SectionsOS.Count - 1];
            StFootnote  footnote = m_scrInMemoryCache.AddFootnote(deut,
                                                                  (StTxtPara)section.ContentOA.ParagraphsOS[section.ContentOA.ParagraphsOS.Count - 1], 10);
            StTxtPara para = m_scrInMemoryCache.AddParaToMockedText(footnote.Hvo,
                                                                    ScrStyleNames.NormalFootnoteParagraph);

            m_scrInMemoryCache.AddRunToMockedPara(para, "This is the footnote", 0);

            // Set up the publication
            m_pub.PageHeight         = 72000 * 11;         // 11 inches
            m_pub.PageWidth          = (int)(72000 * 8.5); // 8.5 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    = 2000;
            vc.m_estSectionHeight = 2000;
            m_pub.Width           = 3 * 96;   // represents a window that is 3" wide at 96 DPI
            m_pub.CreatePages();
            Assert.AreEqual(14, m_pub.Pages.Count,
                            "Our estimate of book should try to fit all of Scripture on 14 pages.");

            // expand the last page
            m_pub.ScrollPosition = new Point(-m_pub.ScrollPosition.X,
                                             m_pub.AutoScrollMinSize.Height - 10);
            m_pub.PrepareToDrawPages(0, 100);

            // now expand all of the pages
            m_pub.ScrollPosition = new Point(0, 0);
            m_pub.PrepareToDrawPages(0, m_pub.AutoScrollMinSize.Height * 2);

            Page        lastPage = (Page)m_pub.Pages[m_pub.Pages.Count - 1];
            PageElement peMain   = lastPage.GetFirstElementForStream(m_division.MainLayoutStream);

            Assert.IsTrue(m_division.m_testPageFootnoteInfo.ContainsKey(lastPage.Handle));
            Assert.AreEqual(2, lastPage.PageElements.Count,
                            "Main and footnote streams should be laid out on page " + lastPage.PageNumber);
            int cFoonotesOnThisPage = (int)m_division.m_testPageFootnoteInfo[lastPage.Handle];

            Assert.Greater(cFoonotesOnThisPage, 0, "Should display at least one footnote on last page");
        }
Beispiel #6
0
        public void LargeEstimates()
        {
            CheckDisposed();

            m_pub.PageHeight = 72000 * 11;           // 11 inches
            m_pub.PageWidth  = 72000 * 9;            // 9 inches
            // No page margins
            m_division.TopMargin     = 0;
            m_division.BottomMargin  = 0;
            m_division.InsideMargin  = 0;
            m_division.OutsideMargin = 0;
            m_pub.Width = 9 * 96;             // represents a window that is 9" wide at 96 DPI
            DummyMainLazyViewVc vc = m_division.MainVc as DummyMainLazyViewVc;

            vc.m_estBookHeight    = 20000;
            vc.m_estSectionHeight = 10000;
            m_pub.CreatePages();
            int cOriginalEstimateOfPages = m_pub.Pages.Count;

            // 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 cPagesOriginal = m_pub.Pages.Count;
//			// Expand first page of stuff...it turns out to be smaller than our outrageously large estimate.
//			m_pub.PrepareToDrawPages(0, 400);
//			// Tests for TE-1413: As lazy boxes are expanded, delete additional pages if necessary
//			Assert.IsTrue(m_pub.Pages.Count < cPagesOriginal,
//				"Expanding lazy boxes for page 1 should decrease 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");

            List <Page> pagesToBeDrawn   = m_pub.PrepareToDrawPages(0, 40000);
            int         cActualPageCount = pagesToBeDrawn.Count;

            Assert.AreEqual(m_pub.Pages.Count, cActualPageCount, "All pages should be real drawable pages now");
            Assert.IsTrue(cActualPageCount < cOriginalEstimateOfPages,
                          "Our estimate of book size should have been high for this test to be meaningful.");

            Page pgLast         = m_pub.Pages[cActualPageCount - 1] as Page;
            Page pgSecondToLast = m_pub.Pages[cActualPageCount - 2] as Page;

            Assert.IsTrue(pgLast.OffsetFromTopOfDiv(m_division) > pgSecondToLast.OffsetFromTopOfDiv(m_division), "last page should be real and in order");
            Assert.IsTrue(pgLast.PageElements.Count > 0, "last page should have an element");
        }
Beispiel #7
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");
        }