Ejemplo n.º 1
0
 public PublishModel(BookSelection bookSelection, PdfMaker pdfMaker, CurrentEditableCollectionSelection currentBookCollectionSelection, CollectionSettings collectionSettings, BookServer bookServer)
 {
     BookSelection = bookSelection;
     _pdfMaker = pdfMaker;
     //_pdfMaker.EngineChoice = collectionSettings.PdfEngineChoice;
     _currentBookCollectionSelection = currentBookCollectionSelection;
     ShowCropMarks=false;
     _collectionSettings = collectionSettings;
     _bookServer = bookServer;
     bookSelection.SelectionChanged += new EventHandler(OnBookSelectionChanged);
     BookletPortion = BookletPortions.BookletPages;
 }
Ejemplo n.º 2
0
        public static void CompressBookForDevice(string outputPath, Book book, BookServer bookServer, Color backColor, IWebSocketProgress progress)
        {
            using (var temp = new TemporaryFolder())
            {
                var modifiedBook = BloomReaderFileMaker.PrepareBookForBloomReader(book, bookServer, temp, backColor, progress);
                // We want at least 256 for Bloom Reader, because the screens have a high pixel density. And (at the moment) we are asking for
                // 64dp in Bloom Reader.

                MakeSizedThumbnail(modifiedBook, backColor, temp.FolderPath, 256);

                CompressDirectory(outputPath, modifiedBook.FolderPath, "", reduceImages: true, omitMetaJson: false, wrapWithFolder: false,
                                  pathToFileForSha: BookStorage.FindBookHtmlInFolder(book.FolderPath));
            }
        }
Ejemplo n.º 3
0
        public PublishModel(BookSelection bookSelection, PdfMaker pdfMaker, CurrentEditableCollectionSelection currentBookCollectionSelection, CollectionSettings collectionSettings,
			BookServer bookServer, BookThumbNailer thumbNailer, NavigationIsolator isolator)
        {
            BookSelection = bookSelection;
            _pdfMaker = pdfMaker;
            //_pdfMaker.EngineChoice = collectionSettings.PdfEngineChoice;
            _currentBookCollectionSelection = currentBookCollectionSelection;
            ShowCropMarks=false;
            _collectionSettings = collectionSettings;
            _bookServer = bookServer;
            _thumbNailer = thumbNailer;
            bookSelection.SelectionChanged += new EventHandler(OnBookSelectionChanged);
            _isoloator = isolator;
            //we don't want to default anymore: BookletPortion = BookletPortions.BookletPages;
        }
Ejemplo n.º 4
0
        public static Book MakeDeviceXmatterTempBook(Book book, BookServer bookServer, string tempFolderPath)
        {
            BookStorage.CopyDirectory(book.FolderPath, tempFolderPath);
            var bookInfo = new BookInfo(tempFolderPath, true);

            bookInfo.XMatterNameOverride = "Device";
            var modifiedBook = bookServer.GetBookFromBookInfo(bookInfo);

            modifiedBook.BringBookUpToDate(new NullProgress());
            modifiedBook.AdjustCollectionStylesToBookFolder();
            modifiedBook.Save();
            modifiedBook.Storage.UpdateSupportFiles();
            // Copy the possibly modified stylesheets after UpdateSupportFiles so that they don't
            // get replaced by the factory versions.
            BookStorage.CopyCollectionStyles(book.FolderPath, tempFolderPath);
            return(modifiedBook);
        }
Ejemplo n.º 5
0
        public static Book PrepareBookForBloomReader(Book book, BookServer bookServer, TemporaryFolder temp, Color backColor,
                                                     IWebSocketProgress progress)
        {
            var modifiedBook = BookCompressor.MakeDeviceXmatterTempBook(book, bookServer, temp.FolderPath);

            var jsonPath      = Path.Combine(temp.FolderPath, QuestionFileName);
            var questionPages = modifiedBook.RawDom.SafeSelectNodes(
                "//html/body/div[contains(@class, 'bloom-page') and contains(@class, 'questions')]");
            var questions = new List <QuestionGroup>();

            foreach (var page in questionPages.Cast <XmlElement>().ToArray())
            {
                MakeQuestion(page, questions);
                page.ParentNode.RemoveChild(page);
            }
            var builder = new StringBuilder("[");

            foreach (var question in questions)
            {
                if (builder.Length > 1)
                {
                    builder.Append(",\n");
                }
                builder.Append(question.GetJson());
            }
            builder.Append("]");
            File.WriteAllText(jsonPath, builder.ToString());

            // Do this after making questions, as they satisfy the criteria for being 'blank'
            modifiedBook.RemoveBlankPages();

            modifiedBook.SetAnimationDurationsFromAudioDurations();

            modifiedBook.OurHtmlDom.SetMedia("bloomReader");
            EmbedFonts(modifiedBook, progress, new FontFileFinder());

            modifiedBook.Save();

            return(modifiedBook);
        }
Ejemplo n.º 6
0
        public LibraryModel(string pathToLibrary, CollectionSettings collectionSettings,
			SendReceiver sendReceiver,
			BookSelection bookSelection,
			SourceCollectionsList sourceCollectionsList,
			BookCollection.Factory bookCollectionFactory,
			EditBookCommand editBookCommand,
			CreateFromSourceBookCommand createFromSourceBookCommand,
			BookServer bookServer,
			CurrentEditableCollectionSelection currentEditableCollectionSelection)
        {
            _bookSelection = bookSelection;
            _pathToLibrary = pathToLibrary;
            _collectionSettings = collectionSettings;
            _sendReceiver = sendReceiver;
            _sourceCollectionsList = sourceCollectionsList;
            _bookCollectionFactory = bookCollectionFactory;
            _editBookCommand = editBookCommand;
            _bookServer = bookServer;
            _currentEditableCollectionSelection = currentEditableCollectionSelection;

            createFromSourceBookCommand.Subscribe(CreateFromSourceBook);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// used when this book is a "master"/"folio" book that is used to bring together a number of other books in the collection
        /// </summary>
        /// <param name="printingDom"></param>
        /// <param name="currentBookCollection"></param>
        /// <param name="bookServer"></param>
        private void AddChildBookContentsToFolio(HtmlDom printingDom, BookCollection currentBookCollection, BookServer bookServer)
        {
            XmlNode currentLastContentPage = GetLastPageForInsertingNewContent(printingDom);

            //currently we have no way of filtering them, we just take them all
            foreach (var bookInfo in currentBookCollection.GetBookInfos())
            {
                if (bookInfo.IsFolio)
                    continue;
                var childBook =bookServer.GetBookFromBookInfo(bookInfo);

                //this will set the class bloom-content1 on the correct language
                //this happens anyhow if the page was ever looked at in the Edti Tab
                //But if we are testing a collection's folio pdf'ing ability on a newly-generated
                //SHRP collection, and we don't do this, we see lots of sample text because every
                //bloom-editable has "bloom-content1", even the "Z" language ones.
                childBook.UpdateEditableAreasOfElement(childBook.OurHtmlDom);

                //add links to the template css needed by the children.

                HtmlDom.AddStylesheetFromAnotherBook(childBook.OurHtmlDom, printingDom);
                printingDom.SortStyleSheetLinks();

                foreach (XmlElement pageDiv in childBook.OurHtmlDom.RawDom.SafeSelectNodes("/html/body//div[contains(@class, 'bloom-page') and not(contains(@class,'bloom-frontMatter')) and not(contains(@class,'bloom-backMatter'))]"))
                {
                    XmlElement importedPage = (XmlElement) printingDom.RawDom.ImportNode(pageDiv, true);
                    currentLastContentPage.ParentNode.InsertAfter(importedPage, currentLastContentPage);
                    currentLastContentPage = importedPage;

                    foreach(XmlElement img in HtmlDom.SelectChildImgAndBackgroundImageElements(importedPage))
                    {
                        var bookFolderName = Path.GetFileName(bookInfo.FolderPath);
                        var path = HtmlDom.GetImageElementUrl(img);
                        var pathRelativeToFolioFolder = ".../" + bookFolderName + "/" + path.NotEncoded;
                        //NB: URLEncode would replace spaces with '+', which is ok in the parameter section, but not the URL
                        //So we are using UrlPathEncode

                        HtmlDom.SetImageElementUrl(new ElementProxy(img), UrlPathString.CreateFromUnencodedString(pathRelativeToFolioFolder));

                    }
                }
            }
        }
Ejemplo n.º 8
0
        public HtmlDom GetDomForPrinting(PublishModel.BookletPortions bookletPortion, BookCollection currentBookCollection, BookServer bookServer)
        {
            var printingDom = GetBookDomWithStyleSheets("previewMode.css", "origami.css");
            AddCreationTypeAttribute(printingDom);

            if (IsFolio)
            {
                AddChildBookContentsToFolio(printingDom, currentBookCollection, bookServer);
                printingDom.SortStyleSheetLinks();
            }

            //whereas the base is to our embedded server during editing, it's to the file folder
            //when we make a PDF, because we wan the PDF to use the original hi-res versions

            var pathSafeForWkHtml2Pdf = FileUtils.MakePathSafeFromEncodingProblems(FolderPath);
            BookStorage.SetBaseForRelativePaths(printingDom, pathSafeForWkHtml2Pdf);

            switch (bookletPortion)
            {
                case PublishModel.BookletPortions.AllPagesNoBooklet:
                    break;
                case PublishModel.BookletPortions.BookletCover:
                    DeletePages(printingDom.RawDom, p => !p.GetAttribute("class").ToLowerInvariant().Contains("cover"));
                    break;
                 case PublishModel.BookletPortions.BookletPages:
                    DeletePages(printingDom.RawDom, p => p.GetAttribute("class").ToLowerInvariant().Contains("cover"));
                    break;
                 default:
                    throw new ArgumentOutOfRangeException("bookletPortion");
            }
            AddCoverColor(printingDom, Color.White);
            AddPreviewJavascript(printingDom);
            return printingDom;
        }
Ejemplo n.º 9
0
        public XmlDocument GetDomForPrinting(PublishModel.BookletPortions bookletPortion, BookCollection currentBookCollection, BookServer bookServer)
        {
            var printingDom = GetBookDomWithStyleSheets("previewMode.css");
            //dom.LoadXml(OurHtmlDom.OuterXml);

            if (IsFolio)
            {
                AddChildBookContentsToFolio(printingDom, currentBookCollection, bookServer);
            }

            //whereas the base is to our embedded server during editing, it's to the file folder
            //when we make a PDF, because we wan the PDF to use the original hi-res versions
            BookStorage.SetBaseForRelativePaths(printingDom, FolderPath, false);

            switch (bookletPortion)
            {
                case PublishModel.BookletPortions.AllPagesNoBooklet:
                    break;
                case PublishModel.BookletPortions.BookletCover:
                    HidePages(printingDom.RawDom, p=>!p.GetAttribute("class").ToLower().Contains("cover"));
                    break;
                 case PublishModel.BookletPortions.BookletPages:
                    HidePages(printingDom.RawDom, p => p.GetAttribute("class").ToLower().Contains("cover"));
                    break;
                 default:
                    throw new ArgumentOutOfRangeException("bookletPortion");
            }
            AddCoverColor(printingDom, Color.White);
            AddPreviewJScript(printingDom);
            return printingDom.RawDom;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// used when this book is a "master"/"folio" book that is used to bring together a number of other books in the collection
        /// </summary>
        /// <param name="printingDom"></param>
        /// <param name="currentBookCollection"></param>
        /// <param name="bookServer"></param>
        private void AddChildBookContentsToFolio(HtmlDom printingDom, BookCollection currentBookCollection, BookServer bookServer)
        {
            XmlNode currentLastContentPage = GetLastPageForInsertingNewContent(printingDom);

            //currently we have no way of filtering them, we just take them all
            foreach (var bookInfo in currentBookCollection.GetBookInfos())
            {
                if (bookInfo.IsFolio)
                    continue;
                var childBook =bookServer.GetBookFromBookInfo(bookInfo);

                //add links to the template css needed by the children.
                //NB: at this point this code can't hand the "customBookStyles" from children, it'll ignore them (they woul conflict with each other)
                //NB: at this point custom styles (e.g. larger/smaller font rules) from children will be lost.
                var customStyleSheets = new List<string>();
                foreach (string sheetName in childBook.OurHtmlDom.GetTemplateStyleSheets())
                {
                    if (!customStyleSheets.Contains(sheetName)) //nb: if two books have stylesheets with the same name, we'll only be grabbing the 1st one.
                    {
                        customStyleSheets.Add(sheetName);
                        printingDom.AddStyleSheetIfMissing("file://"+Path.Combine(childBook.FolderPath,sheetName));
                    }
                }
                printingDom.SortStyleSheetLinks();

                foreach (XmlElement pageDiv in childBook.OurHtmlDom.RawDom.SafeSelectNodes("/html/body/div[contains(@class, 'bloom-page') and not(contains(@class,'bloom-frontMatter')) and not(contains(@class,'bloom-backMatter'))]"))
                {
                    XmlElement importedPage = (XmlElement) printingDom.RawDom.ImportNode(pageDiv, true);
                    currentLastContentPage.ParentNode.InsertAfter(importedPage, currentLastContentPage);
                    currentLastContentPage = importedPage;

                    ImageUpdater.MakeImagePathsOfImportedPagePointToOriginalLocations(importedPage, bookInfo.FolderPath);
                }
            }
        }
Ejemplo n.º 11
0
 private BookServer CreateBookServer()
 {
     var collectionSettings =
         new CollectionSettings(new NewCollectionSettings()
         {
             PathToSettingsFile = CollectionSettings.GetPathForNewSettings(_projectFolder.Path, "test"),
             Language1Iso639Code = "xyz"
         });
     var server = new BookServer((bookInfo, storage) =>
     {
         return new Bloom.Book.Book(bookInfo, storage, null, collectionSettings,
             new PageSelection(),
             new PageListChangedEvent(), new BookRefreshEvent());
     }, path => new BookStorage(path, _fileLocator, null, collectionSettings), () => _starter, null);
     return server;
 }