public void IsLandscape_landscapeCSS_true()
        {
            var dom = new XmlDocument();

            dom.LoadXml(@"<html ><body><div id='foo'></div><div class='blah bloom-page A5Landscape'></div></body></html>");
            Assert.IsTrue(SizeAndOrientation.GetSizeAndOrientation(dom, "A5Portrait").IsLandScape);
        }
        public void PageSizeName_USLetter()
        {
            var dom = new XmlDocument();

            dom.LoadXml(@"<html ><body><div id='foo'></div><div class='blah bloom-page LetterPortrait'></div></body></html>");
            Assert.AreEqual("Letter", SizeAndOrientation.GetSizeAndOrientation(dom, "A5Portrait").PageSizeName);
        }
        public void PageSizeName_A5LANDSCAPE()
        {
            var dom = new XmlDocument();

            dom.LoadXml(@"<html ><body><div id='foo'></div><div class='blah bloom-page A5Landscape'></div></body></html>");
            Assert.AreEqual("A5", SizeAndOrientation.GetSizeAndOrientation(dom, "A5Portrait").PageSizeName);
        }
Ejemplo n.º 4
0
        public void GetEditableHtmlDomForPage_BasicBook_HasA5PortraitClass()
        {
            var book = CreateBook();

            book.SetLayout(new Layout()
            {
                SizeAndOrientation = SizeAndOrientation.FromString("A5Portrait")
            });
            var dom = book.GetEditableHtmlDomForPage(book.GetPages().ToArray()[2]);

            AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[contains(@class,'A5Portrait') and contains(@class,'bloom-page')]", 1);
        }
Ejemplo n.º 5
0
        // Insert a clone of templatePage into the document before _currentPage (or after _lastContentPage, if _currentPage is null),
        // and make _currentPage point to the new page.
        private void ImportPage(XmlElement templatePage)
        {
            var newPage = _pages[0].OwnerDocument.ImportNode(templatePage, true) as XmlElement;

            BookStarter.SetupIdAndLineage(templatePage, newPage);
            _pages.Insert(_currentPageIndex, newPage);
            SizeAndOrientation.UpdatePageSizeAndOrientationClasses(newPage, _destLayout);
            // Correctly inserts at end if _currentPage is null, though this will hardly ever
            // be true because we normally have at least backmatter page to insert before.
            _pages[0].ParentNode.InsertBefore(newPage, _currentPage);

            // clear everything: this is useful in case it has slots we won't use.
            // They might have content either from the original last page, or from the
            // modifications we already made to it.
            var editables = newPage.SelectNodes(".//div[contains(@class, 'bloom-editable') and @lang != 'z']").Cast <XmlElement>().ToArray();

            foreach (var e in editables)
            {
                e.ParentNode.RemoveChild(e);
            }

            var imageContainers = GetImageContainers(newPage);

            foreach (var c in imageContainers)
            {
                var img = GetImgFromContainer(c);
                img?.SetAttribute("src", "placeHolder.png");
                foreach (var attr in new[] { "alt", "data-copyright", "data-creator", "data-license" })
                {
                    img?.RemoveAttribute(attr);
                }
                c.RemoveAttribute("title");
            }

            // This is not tested yet, but we want to remove video content if any from whatever last page we're copying.
            foreach (var v in newPage.SelectNodes(".//div[contains(@class, 'bloom-videoContainer')]/video")
                     .Cast <XmlElement>().ToList())
            {
                HtmlDom.AddClass(v.ParentNode as XmlElement, "bloom-noVideoSelected");
                v.ParentNode.RemoveChild(v);
            }

            // and widgets (also not tested)
            foreach (var w in newPage.SelectNodes(".//div[contains(@class, 'bloom-widgetContainer')]/iframe")
                     .Cast <XmlElement>().ToList())
            {
                HtmlDom.AddClass(w.ParentNode as XmlElement, "bloom-noWidgetSelected");
                w.ParentNode.RemoveChild(w);
            }

            _currentPage = newPage;
        }
Ejemplo n.º 6
0
        public static int Handle(HydrateParameters options)
        {
            if (!Directory.Exists(options.Path))
            {
                if (options.Path.Contains(".htm"))
                {
                    Debug.WriteLine("Supply only the directory, not the path to the file.");
                    Console.Error.WriteLine("Supply only the directory, not the path to the file.");
                }
                else
                {
                    Debug.WriteLine("Could not find " + options.Path);
                    Console.Error.WriteLine("Could not find " + options.Path);
                }
                return(1);
            }
            Console.WriteLine("Starting Hydrating.");

            var layout = new Layout
            {
                SizeAndOrientation = SizeAndOrientation.FromString(options.SizeAndOrientation)
            };

            var collectionSettings = new CollectionSettings
            {
                XMatterPackName     = options.XMatter,
                Language1Iso639Code = options.VernacularIsoCode,
                Language2Iso639Code = string.IsNullOrWhiteSpace(options.NationalLanguage1IsoCode) ? options.VernacularIsoCode : options.NationalLanguage1IsoCode,
                Language3Iso639Code = options.NationalLanguage2IsoCode
            };

            XMatterPackFinder xmatterFinder = new XMatterPackFinder(new[] { BloomFileLocator.GetInstalledXMatterDirectory() });
            var locator = new BloomFileLocator(collectionSettings, xmatterFinder, ProjectContext.GetFactoryFileLocations(),
                                               ProjectContext.GetFoundFileLocations(), ProjectContext.GetAfterXMatterFileLocations());

            var bookInfo = new BookInfo(options.Path, true);
            var book     = new Book.Book(bookInfo, new BookStorage(options.Path, locator, new BookRenamedEvent(), collectionSettings),
                                         null, collectionSettings, null, null, new BookRefreshEvent(), new BookSavedEvent());

            //we might change this later, or make it optional, but for now, this will prevent surprises to processes
            //running this CLI... the folder name won't change out from under it.
            book.LockDownTheFileAndFolderName = true;

            book.SetLayout(layout);
            book.BringBookUpToDate(new NullProgress());
            Console.WriteLine("Finished Hydrating.");
            Debug.WriteLine("Finished Hydrating.");
            return(0);
        }
Ejemplo n.º 7
0
        private TempFile MakeFinalHtmlForPdfMaker()
        {
            PdfFilePath = GetPdfPath(Path.GetFileName(_currentlyLoadedBook.FolderPath));

            XmlDocument dom = BookSelection.CurrentSelection.GetDomForPrinting(BookletPortion, _currentBookCollectionSelection.CurrentSelection, _bookServer);

            HtmlDom.AddPublishClassToBody(dom);

            //we do this now becuase the publish ui allows the user to select a different layout for the pdf than what is in the book file
            SizeAndOrientation.UpdatePageSizeAndOrientationClasses(dom, PageLayout);
            PageLayout.UpdatePageSplitMode(dom);

            XmlHtmlConverter.MakeXmlishTagsSafeForInterpretationAsHtml(dom);
            return(BloomTemp.TempFileUtils.CreateHtm5FromXml(dom));
        }
Ejemplo n.º 8
0
        private SimulatedPageFile MakeFinalHtmlForPdfMaker()
        {
            PdfFilePath = GetPdfPath(Path.GetFileName(_currentlyLoadedBook.FolderPath));

            var dom = BookSelection.CurrentSelection.GetDomForPrinting(BookletPortion, _currentBookCollectionSelection.CurrentSelection, _bookServer);

            AddStylesheetClasses(dom.RawDom);

            //we do this now becuase the publish ui allows the user to select a different layout for the pdf than what is in the book file
            SizeAndOrientation.UpdatePageSizeAndOrientationClasses(dom.RawDom, PageLayout);
            PageLayout.UpdatePageSplitMode(dom.RawDom);

            XmlHtmlConverter.MakeXmlishTagsSafeForInterpretationAsHtml(dom.RawDom);
            dom.UseOriginalImages = true;             // don't want low-res images or transparency in PDF.
            return(EnhancedImageServer.MakeSimulatedPageFileInBookFolder(dom));
        }
Ejemplo n.º 9
0
        public IEnumerable <HtmlDom> GetPageDoms()
        {
            if (BookSelection.CurrentSelection.IsFolio)
            {
                foreach (var bi in _currentBookCollectionSelection.CurrentSelection.GetBookInfos())
                {
                    var book = _bookServer.GetBookFromBookInfo(bi);
                    //need to hide the "notes for illustrators" on SHRP, which is controlled by the layout
                    book.SetLayout(new Layout()
                    {
                        SizeAndOrientation = SizeAndOrientation.FromString("B5Portrait"),
                        Style = "HideProductionNotes"
                    });
                    foreach (var page in  book.GetPages())
                    {
                        //yield return book.GetPreviewXmlDocumentForPage(page);

                        var previewXmlDocumentForPage = book.GetPreviewXmlDocumentForPage(page);
                        BookStorage.SetBaseForRelativePaths(previewXmlDocumentForPage, book.FolderPath);

                        AddStylesheetClasses(previewXmlDocumentForPage.RawDom);

                        yield return(previewXmlDocumentForPage);
                    }
                }
            }
            else             //this one is just for testing, it's not especially fruitful to export for a single book
            {
                //need to hide the "notes for illustrators" on SHRP, which is controlled by the layout
                BookSelection.CurrentSelection.SetLayout(new Layout()
                {
                    SizeAndOrientation = SizeAndOrientation.FromString("B5Portrait"),
                    Style = "HideProductionNotes"
                });

                foreach (var page in BookSelection.CurrentSelection.GetPages())
                {
                    var previewXmlDocumentForPage = BookSelection.CurrentSelection.GetPreviewXmlDocumentForPage(page);
                    //get the original images, not compressed ones (just in case the thumbnails are, like, full-size & they want quality)
                    BookStorage.SetBaseForRelativePaths(previewXmlDocumentForPage, BookSelection.CurrentSelection.FolderPath);
                    AddStylesheetClasses(previewXmlDocumentForPage.RawDom);
                    yield return(previewXmlDocumentForPage);
                }
            }
        }
Ejemplo n.º 10
0
                  new[] { "another-image.svg", "another-image.png" })]                                                               // use default svg if no landscape
        public void InjectXMatter_BrandingApi_SelectsRightOrientationImage(string orientation, string expectedFileName,
                                                                           string expectedImageContent, string[] imageFilesToCreate)
        {
            using (var tempFolder = new TemporaryFolder("InjectXMatter_Landscape_PrefersLandscapeImage" + new Random().Next()))
            {
                var bookFolder = Path.Combine(tempFolder.FolderPath, "book");
                Directory.CreateDirectory(bookFolder);
                var srcFolder = Path.Combine(tempFolder.FolderPath, "source");
                Directory.CreateDirectory(srcFolder);
                foreach (var fileName in imageFilesToCreate)
                {
                    var srcImagePath = Path.Combine(srcFolder, fileName);
                    // yes, write the file name as its content, so we can identify which file was copied.
                    File.WriteAllText(srcImagePath, fileName);
                }

                var frontMatterDom = new XmlDocument();
                frontMatterDom.LoadXml(@"<html><head> <link href='file://blahblah\\a5portrait.css' type='text/css' /></head><body>
						 <div class='bloom-page cover coverColor bloom-frontMatter' data-page='required'>
							<img class='branding' src='/bloom/api/branding/image?id="                             + Path.Combine(srcFolder, expectedFileName) +
                                       @"' type='image/svg'/>
						</div></body></html>"                        );
                var helper = CreatePaperSaverHelper();
                helper.XMatterDom = frontMatterDom;

                var layout = new Layout()
                {
                    SizeAndOrientation = SizeAndOrientation.FromString(orientation)
                };

                helper.InjectXMatter(_dataSet.WritingSystemAliases, layout, "Default", bookFolder);
                AssertThatXmlIn.Dom(_dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//img[@src='" + expectedFileName + "']", 1);
                var outputImagePath = Path.Combine(bookFolder, expectedFileName);
                Assert.That(File.Exists(outputImagePath));
                Assert.That(RobustFile.ReadAllText(outputImagePath), Is.EqualTo(expectedImageContent));
            }
        }
Ejemplo n.º 11
0
        private SimulatedPageFile MakeFinalHtmlForPdfMaker()
        {
            PdfFilePath = GetPdfPath(Path.GetFileName(_currentlyLoadedBook.FolderPath));

            var dom = BookSelection.CurrentSelection.GetDomForPrinting(BookletPortion, _currentBookCollectionSelection.CurrentSelection, _bookServer);

            AddStylesheetClasses(dom.RawDom);

            //we do this now becuase the publish ui allows the user to select a different layout for the pdf than what is in the book file
            SizeAndOrientation.UpdatePageSizeAndOrientationClasses(dom.RawDom, PageLayout);

            if (BookSelection.CurrentSelection.GetLayout().SizeAndOrientation.IsLandScape !=
                PageLayout.SizeAndOrientation.IsLandScape)
            {
                // Need to update the xmatter in the print dom...it may use different images.
                // Make sure we do this AFTER setting PageOrientation in Dom.
                BookSelection.CurrentSelection.UpdateBrandingForCurrentOrientation(dom);
            }
            PageLayout.UpdatePageSplitMode(dom.RawDom);

            XmlHtmlConverter.MakeXmlishTagsSafeForInterpretationAsHtml(dom.RawDom);
            dom.UseOriginalImages = true;             // don't want low-res images or transparency in PDF.
            return(EnhancedImageServer.MakeSimulatedPageFileInBookFolder(dom, source: "pub"));
        }
Ejemplo n.º 12
0
        public static int Handle(HydrateParameters options)
        {
            if (!Directory.Exists(options.Path))
            {
                if (options.Path.Contains(".htm"))
                {
                    Debug.WriteLine("Supply only the directory, not the path to the file.");
                    Console.Error.WriteLine("Supply only the directory, not the path to the file.");
                }
                else
                {
                    Debug.WriteLine("Could not find " + options.Path);
                    Console.Error.WriteLine("Could not find " + options.Path);
                }
                return(1);
            }
            Console.WriteLine("Starting Hydrating.");

            var layout = new Layout
            {
                SizeAndOrientation = SizeAndOrientation.FromString(options.SizeAndOrientation)
            };

            var collectionSettings = new CollectionSettings
            {
                XMatterPackName     = options.XMatter,
                Language1Iso639Code = options.VernacularIsoCode,
                Language2Iso639Code = options.NationalLanguage1IsoCode,
                Language3Iso639Code = options.NationalLanguage2IsoCode
            };

            XMatterPackFinder xmatterFinder = new XMatterPackFinder(new[] { BloomFileLocator.GetInstalledXMatterDirectory() });
            var locator = new BloomFileLocator(collectionSettings, xmatterFinder, ProjectContext.GetFactoryFileLocations(),
                                               ProjectContext.GetFoundFileLocations(), ProjectContext.GetAfterXMatterFileLocations());

            var bookInfo = new BookInfo(options.Path, true);
            var book     = new Book.Book(bookInfo, new BookStorage(options.Path, locator, new BookRenamedEvent(), collectionSettings),
                                         null, collectionSettings, null, null, new BookRefreshEvent());

            if (collectionSettings.XMatterPackName == "Video")
            {
                if (null == book.OurHtmlDom.SelectSingleNodeHonoringDefaultNS("//script[contains(text(),'bloomPlayer.js')]"))
                {
                    var element = book.OurHtmlDom.Head.AppendChild(book.OurHtmlDom.RawDom.CreateElement("script")) as XmlElement;
                    element.IsEmpty = false;
                    element.SetAttribute("type", "text/javascript");
                    element.SetAttribute("src", "bloomPlayer.js");
                }

                AddRequisiteJsFiles(options.Path);
            }

            //we might change this later, or make it optional, but for now, this will prevent surprises to processes
            //running this CLI... the folder name won't change out from under it.
            book.LockDownTheFileAndFolderName = true;

            book.SetLayout(layout);
            book.BringBookUpToDate(new NullProgress());
            Console.WriteLine("Finished Hydrating.");
            Debug.WriteLine("Finished Hydrating.");
            return(0);
        }
Ejemplo n.º 13
0
        private static string GetPaperSizeName(XmlDocument document)
        {
            string paperSizeName = SizeAndOrientation.GetSizeAndOrientation(document, "A5Portrait").ToString();

            return(paperSizeName);
        }
Ejemplo n.º 14
0
        public static int Handle(HydrateParameters options)
        {
            if (!Directory.Exists(options.Path))
            {
                if (options.Path.Contains(".htm"))
                {
                    Debug.WriteLine("Supply only the directory, not the path to the file.");
                    Console.Error.WriteLine("Supply only the directory, not the path to the file.");
                }
                else
                {
                    Debug.WriteLine("Could not find " + options.Path);
                    Console.Error.WriteLine("Could not find " + options.Path);
                }
                return(1);
            }
            Console.WriteLine("Starting Hydrating.");

            var layout = new Layout
            {
                SizeAndOrientation = SizeAndOrientation.FromString(options.SizeAndOrientation)
            };

            if (File.Exists(TeamCollectionManager.GetTcLinkPathFromLcPath(Path.GetDirectoryName(options.Path))))
            {
                throw new ApplicationException("Hydrate command cannot currently be used in Team Collections");
                // To make this possible, we'd need to spin up a TeamCollectionManager and TeamCollection and pass the latter
                // to the Book as its SaveContext and still changes would be forbidden unless the book was checked out.
            }

            var collectionSettings = new CollectionSettings
            {
                XMatterPackName     = options.XMatter,
                Language1Iso639Code = options.VernacularIsoCode,
                Language2Iso639Code = string.IsNullOrWhiteSpace(options.NationalLanguage1IsoCode) ? options.VernacularIsoCode : options.NationalLanguage1IsoCode,
                Language3Iso639Code = options.NationalLanguage2IsoCode
            };

            XMatterPackFinder xmatterFinder = new XMatterPackFinder(new[] { BloomFileLocator.GetFactoryXMatterDirectory(), });
            var locator = new BloomFileLocator(collectionSettings, xmatterFinder, ProjectContext.GetFactoryFileLocations(),
                                               ProjectContext.GetFoundFileLocations(), ProjectContext.GetAfterXMatterFileLocations());

            // alwaysSaveable is fine here, as we already checked it's not a TC.
            var bookInfo = new BookInfo(options.Path, true, new AlwaysEditSaveContext());
            var book     = new Book.Book(bookInfo, new BookStorage(options.Path, locator, new BookRenamedEvent(), collectionSettings),
                                         null, collectionSettings, null, null, new BookRefreshEvent(), new BookSavedEvent());
            // This was added as part of the phase 1 changes towards the new language system, where book languages
            // are more clearly distinct from collection languages, and there's no sense (except underlying storage) in which
            // a book has languages that are not selected for display. This made it necessary to decide explicitly
            // whether passing the national language options implies that a book is bi- or tri-lingual. Andrew and I (JohnT)
            // could not think of any reason to pass the arguments at all except to achieve that, so I made it so.
            var langs = new List <string>();

            langs.Add(options.VernacularIsoCode);
            if (!string.IsNullOrEmpty(options.NationalLanguage1IsoCode) && options.NationalLanguage1IsoCode != options.VernacularIsoCode)
            {
                langs.Add(options.NationalLanguage1IsoCode);
            }
            if (!string.IsNullOrEmpty(options.NationalLanguage2IsoCode))
            {
                langs.Add(options.NationalLanguage2IsoCode);
            }
            book.SetMultilingualContentLanguages(langs.ToArray());

            //we might change this later, or make it optional, but for now, this will prevent surprises to processes
            //running this CLI... the folder name won't change out from under it.
            book.LockDownTheFileAndFolderName = true;

            book.SetLayout(layout);
            book.BringBookUpToDate(new NullProgress());
            Console.WriteLine("Finished Hydrating.");
            Debug.WriteLine("Finished Hydrating.");
            return(0);
        }