public ChangePicture ( string bookFolderPath, ElementProxy imgOrDivWithBackgroundImage, SIL.Windows.Forms.ImageToolbox.PalasoImage imageInfo, IProgress progress ) : void | ||
bookFolderPath | string | |
imgOrDivWithBackgroundImage | ElementProxy | Can be an XmlElement (during testing) |
imageInfo | SIL.Windows.Forms.ImageToolbox.PalasoImage | |
progress | IProgress | |
Результат | void |
public void ChangePicture_PictureIsFromOutsideProject_PictureCopiedAndAttributeChanged() { var dom = new XmlDocument(); dom.LoadXml("<html><body><div/><div><img id='one'/><img id='two' src='old.png'/></div></body></html>"); var model = new PageEditingModel(); using (var src = new TemporaryFolder("bloom pictures test source")) using (var dest = new TemporaryFolder("bloom picture tests dest")) { var newImagePath = src.Combine("new.png"); using (var original = MakeSamplePngImage(newImagePath)) { model.ChangePicture(dest.Path, dom, "two", original); Assert.IsTrue(File.Exists(dest.Combine("new.png"))); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath(@"//img[@id='two' and @src='new.png']", 1); } } }
public void ChangePicture_PictureIsJpg_StaysJpg() { var dom = new XmlDocument(); dom.LoadXml("<html><body><div/><div><img id='one'/><img id='two' src='old.png'/></div></body></html>"); var model = new PageEditingModel(); using (var src = new TemporaryFolder("bloom pictures test source")) using (var dest = new TemporaryFolder("bloom picture tests dest")) using (var original = MakeSampleJpegImage(src.Combine("new.jpg"))) { model.ChangePicture(dest.Path, dom, "two", original); Assert.IsTrue(File.Exists(dest.Combine("new.jpg"))); AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath(@"//img[@id='two' and @src='new.jpg']", 1); using (var converted = Image.FromFile(dest.Combine("new.jpg"))) { Assert.AreEqual(ImageFormat.Jpeg.Guid, converted.RawFormat.Guid); } } }
public void ChangePicture_AlreadyHaveACopyInPublicationFolder_PictureUpdated() { var dom = new XmlDocument(); dom.LoadXml("<html><body><div/><div><img id='one'/><img id='two' src='old.png'/></div></body></html>"); var model = new PageEditingModel(); using (var src = new TemporaryFolder("bloom pictures test source")) using (var dest = new TemporaryFolder("bloom picture tests dest")) { var dogImagePath = src.Combine("dog.png"); using (var original = MakeSamplePngImage(dogImagePath)) { var destDogImagePath = dest.Combine("dog.png"); File.WriteAllText(destDogImagePath, "old dog"); model.ChangePicture(dest.Path, dom, "two", original); Assert.IsTrue(Image.FromFile(destDogImagePath).Width == kSampleImageDimension); } } }
public void ChangePicture(GeckoHtmlElement img, PalasoImage imageInfo, IProgress progress) { try { Logger.WriteMinorEvent("Starting ChangePicture {0}...", imageInfo.FileName); var editor = new PageEditingModel(); editor.ChangePicture(_bookSelection.CurrentSelection.FolderPath, img, imageInfo, progress); //we have to save so that when asked by the thumbnailer, the book will give the proper image SaveNow(); //but then, we need the non-cleaned version back there _view.UpdateSingleDisplayedPage(_pageSelection.CurrentSelection); _view.UpdateThumbnailAsync(_pageSelection.CurrentSelection); Logger.WriteMinorEvent("Finished ChangePicture {0} (except for async thumbnail) ...", imageInfo.FileName); Analytics.Track("Change Picture"); Logger.WriteEvent("ChangePicture {0}...", imageInfo.FileName); } catch (Exception e) { ErrorReport.NotifyUserOfProblem(e, "Could not change the picture"); } }
public void ChangePicture(GeckoElement img, PalasoImage imageInfo, IProgress progress) { try { Logger.WriteMinorEvent("Starting ChangePicture {0}...", imageInfo.FileName); var editor = new PageEditingModel(); editor.ChangePicture(_bookSelection.CurrentSelection.FolderPath, img, imageInfo, progress); //we have to save so that when asked by the thumbnailer, the book will give the proper image SaveNow(); //but then, we need the non-cleaned version back there _view.UpdateSingleDisplayedPage(_pageSelection.CurrentSelection); _view.UpdateThumbnailAsync(_pageSelection.CurrentSelection); Logger.WriteMinorEvent("Finished ChangePicture {0} (except for async thumbnail) ...", imageInfo.FileName); Analytics.Track("Change Picture"); Logger.WriteEvent("ChangePicture {0}...", imageInfo.FileName); } catch (Exception e) { ErrorReport.NotifyUserOfProblem(e, "Could not change the picture"); } }
public void ChangePicture(GeckoHtmlElement img, PalasoImage imageInfo, IProgress progress) { try { Logger.WriteMinorEvent("Starting ChangePicture {0}...", imageInfo.FileName); var editor = new PageEditingModel(); editor.ChangePicture(CurrentBook.FolderPath, new ElementProxy(img), imageInfo, progress); // We need to save so that when asked by the thumbnailer, the book will give the proper image SaveNow(); // BL-3717: if we cleanup unused image files whenever we change a picture then Cut can lose // all of an image's metadata (because the actual file is missing from the book folder when we go to // paste in the image that was copied onto the clipboard, which doesn't have metadata.) // Let's only do this on ExpensiveIntialization() when loading a book. //CurrentBook.Storage.CleanupUnusedImageFiles(); // But after saving, we need the non-cleaned version back there _view.UpdateSingleDisplayedPage(_pageSelection.CurrentSelection); _view.UpdateThumbnailAsync(_pageSelection.CurrentSelection); Logger.WriteMinorEvent("Finished ChangePicture {0} (except for async thumbnail) ...", imageInfo.FileName); Analytics.Track("Change Picture"); Logger.WriteEvent("ChangePicture {0}...", imageInfo.FileName); } catch (Exception e) { var msg = LocalizationManager.GetString("Errors.ProblemImportingPicture","Bloom had a problem importing this picture."); ErrorReport.NotifyUserOfProblem(e, msg+Environment.NewLine+e.Message); } }