private void selectProjectXmlButton_Click(object sender, EventArgs e)
        {
            var fileDialog = new OpenFileDialog
            {
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                Filter           = "xml files (*.xml)|*.xml",
                RestoreDirectory = true
            };

            if (fileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var projectPath = fileDialog.FileName;

            photoStoryProject = Ps3AndBloomSerializer.DeserializePhotoStoryXml(projectPath);

            photoStoryProjectTextBox.Text = projectPath;

            var bookName = photoStoryProject.GetProjectName();

            if (projectNameTextBox.Text.Length == 0 && bookName.Length > 0)
            {
                projectNameTextBox.Text = bookName;
            }
        }
        private void convertProjectButton_Click(object sender, EventArgs e)
        {
            var projectXmlPath      = photoStoryProjectTextBox.Text;
            var bloomCollectionPath = bloomCollectionTextBox.Text;
            var projectName         = projectNameTextBox.Text.Trim();
            var textPath            = wordDocTextBox.Text;
            var bloomExePath        = bloomCollectionTextBox.Text;

            Program.Convert(projectXmlPath, Path.GetDirectoryName(bloomCollectionPath), projectName, textPath, bloomExePath, photoStoryProject, extractedText);

            var result = MessageBox.Show("Success! Convert another project?", "Photo Story to Bloom Converter", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                photoStoryProject             = null;
                photoStoryProjectTextBox.Text = "";
                projectNameTextBox.Text       = "";
            }
            else
            {
                Close();
            }
        }
Exemple #3
0
        //Pulls in all the gathered information for the poject and creates a single bloom book html file at destinationFile
        public static void ConvertToBloom(PhotoStoryProject project, string destinationFile, string bookName, IList <string> text)
        {
            var document = new BloomDocument(project, bookName, Path.GetDirectoryName(destinationFile), text);

            Ps3AndBloomSerializer.SerializeBloomHtml(document.ConvertToHtml(), destinationFile);
        }
        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);
            }
        }
Exemple #5
0
        public static void Convert(string projectXmlPath, string destinationFolder, string projectName, string docxPath, string bloomPath, PhotoStoryProject photoStoryProject = null, IList <string> extractedText = null)
        {
            if (photoStoryProject == null)
            {
                photoStoryProject = Ps3AndBloomSerializer.DeserializePhotoStoryXml(projectXmlPath);
                if (string.IsNullOrEmpty(projectName))
                {
                    projectName = photoStoryProject.GetProjectName();
                }
            }

            var convertedProjectDirectory = Path.Combine(destinationFolder, projectName);

            if (Directory.Exists(convertedProjectDirectory) && !overwrite)
            {
                Console.WriteLine(string.Format("Error: A book already exists with the name {0}.", projectName), "projectName");
                return;
            }
            else if (Directory.Exists(convertedProjectDirectory) && overwrite)
            {
                DeleteAllFilesAndFoldersInDirectory(convertedProjectDirectory);
            }
            else
            {
                Directory.CreateDirectory(convertedProjectDirectory);
            }

            if (extractedText == null && docxPath != null)
            {
                TextExtractor.TryExtractText(docxPath, out extractedText);
                if (extractedText == null)
                {
                    Console.WriteLine("Unable to extract text from {0}", docxPath);
                }
            }

            //Three things needed for a bloom book:
            //  book assets (images, narration audio, background audio)
            //  bloom book css and images
            //  the actual book, a generated html file built from the photostory project
            CopyAssetsAndResources(Path.GetDirectoryName(projectXmlPath), convertedProjectDirectory);
            ConvertToBloom(photoStoryProject, Path.Combine(convertedProjectDirectory, string.Format("{0}.htm", projectName)), projectName, extractedText);

            var  hydrationArguments = string.Format("hydrate --preset app --bookpath \"{0}\" --VernacularIsoCode en", convertedProjectDirectory);
            bool hydrateSuccessful;

            try
            {
                using (var process = Process.Start(bloomPath, hydrationArguments))
                {
                    process.WaitForExit();
                    hydrateSuccessful = process.ExitCode == 0;
                }
            }
            catch
            {
                hydrateSuccessful = false;
            }
            if (!hydrateSuccessful)
            {
                Console.WriteLine("Unable to hydrate {0}", projectName);
            }
            else if (!batch)
            {
                Console.WriteLine("Successfully converted {0}", projectName);
            }
        }