public BloomPage(BloomImage image, string text, BloomAudio audio) { Uuid = Guid.NewGuid().ToString(); BloomTags = "bloom-page numberedPage customPage Device16x9Portrait layout-style-Default bloom-monolingual"; PageLabel = ""; PageDescription = ""; Language = ""; ImageAndTextWithAudioSplitter = new BloomPageSplitter { Image = image, Text = text, Audio = audio }; }
public BloomDocument(PhotoStoryProject project, string bookName, string bookDirectoryPath, IList <string> narratedText) { _metadata = BloomMetadata.DefaultBloomMetadata(bookName); _bookData = BloomBookData.DefaultBloomBookData(bookName); //A little bit of book-keeping, we want to remove images that are cover or credit images from the final directory var imagePathsToRemove = new SortedSet <string>(); //For each visual unit create a bloom page //Instead of creating a page for cover and credits pages, put information into the book data (data-div) //The X-Matter pack will create more visually appealing cover pages for (var i = 0; i < project.VisualUnits.Length; i++) { var visualUnit = project.VisualUnits[i]; var psImage = visualUnit.Image; var backgroundAudioPath = GetBackgroundAudioPathForImage(psImage); var backgroundAudioVolume = (backgroundAudioPath == null)?0.00:GetBackgroundAudioVolumeForImage(psImage); var extractor = new CreditsAndCoverExtractor(); if (extractor.imageIsCreditsOrCover(Path.Combine(bookDirectoryPath, psImage.Path))) { //If it was a credits page, put credit information into the data divs if (extractor.extractedCreditString != null) { _bookData.LocalizedOriginalAcknowledgments.Add(extractor.extractedCreditString); if (extractor.extractedImageCopyright != null) { ImageCopyright = extractor.extractedImageCopyright; } if (extractor.extractedImageLicense != null) { ImageLicense = extractor.extractedImageLicense; } if (extractor.extractedImageCreator != null) { ImageCreator = extractor.extractedImageCreator; } } //If the image had narration and/or background audio, and was the front cover, we want to store the audio for the new cover page if (i == 0 && backgroundAudioPath != null) { _bookData.CoverBackgroundAudioPath = backgroundAudioPath; _bookData.CoverBackgroundAudioVolume = backgroundAudioVolume; } if (i == 0 && visualUnit.Narration != null) { _bookData.CoverNarrationPath = visualUnit.Narration.Path; } imagePathsToRemove.Add(Path.Combine(bookDirectoryPath, psImage.Path)); } else { var cropRectangle = new Rectangle(); //If the image photostory was using had a crop edit, we need to adjust the image displayed for bloom likewise if (psImage.Edits != null) { foreach (var edit in psImage.Edits) { if (edit.RotateAndCrop == null) { continue; } cropRectangle = edit.RotateAndCrop.CroppedRect.ToAnimationRectangle(); } } var bloomImage = new BloomImage { Src = psImage.Path, ImageSize = new Size { Height = psImage.AbsoluteMotion.BaseImageHeight, Width = psImage.AbsoluteMotion.BaseImageWidth }, ImageMotion = new BloomImageMotion { CropRectangle = cropRectangle, InitialImageRectangle = psImage.AbsoluteMotion.Rects[0].ToAnimationRectangle(), FinalImageRectangle = psImage.AbsoluteMotion.Rects[1].ToAnimationRectangle(), } }; var text = ""; if (narratedText != null && narratedText.Count > i) { text = narratedText[i]; } var narrationPath = ""; if (visualUnit.Narration != null) { narrationPath = visualUnit.Narration.Path; } var narrationFilePath = Path.Combine(bookDirectoryPath, BloomAudio.kAudioDirectory, narrationPath); var bloomAudio = new BloomAudio(narrationPath, backgroundAudioPath, backgroundAudioVolume, GetDuration(narrationFilePath)); _pages.Add(new BloomPage(bloomImage, text, bloomAudio)); } } if (ImageCopyright != null || ImageLicense != null || ImageCreator != null) { //Because credits may have been at end of book, go back through and set image credits if we extracted some. foreach (var page in _pages) { var imageLocation = Path.Combine(bookDirectoryPath, page.ImageAndTextWithAudioSplitter.Image.Src); using (var image = SIL.Windows.Forms.ImageToolbox.PalasoImage.FromFile(imageLocation)) { image.Metadata.CopyrightNotice = ImageCopyright; image.Metadata.License = new CreativeCommonsLicense(true, true, CreativeCommonsLicense.DerivativeRules.DerivativesWithShareAndShareAlike); image.Metadata.Creator = ImageCreator; image.SaveUpdatedMetadataIfItMakesSense(); } } } foreach (var imagePath in imagePathsToRemove) { File.Delete(imagePath); } }