/// ------------------------------------------------------------------------------------ /// <summary> /// Update the properties of a CmPicture with the given file, caption, and folder. /// </summary> /// <param name="srcFilename">The full path to the original filename (an internal copy /// will be made in this method)</param> /// <param name="captionTss">The caption</param> /// <param name="sFolder">The name of the CmFolder where picture should be stored</param> /// <param name="ws">The WS for the location in the caption MultiUnicode to put the /// caption</param> /// ------------------------------------------------------------------------------------ public void UpdatePicture(string srcFilename, ITsString captionTss, string sFolder, int ws) { // Locate CmFolder with given name or create it, if neccessary ICmFolder folder = CmFolder.FindOrCreateFolder(m_cache, (int)LangProject.LangProjectTags.kflidPictures, sFolder); ICmFile file = PictureFileRA; if (file == null) { file = folder.FilesOC.Add(new CmFile()); PictureFileRA = file; } // (The case-independent comparison is valid only for Microsoft Windows.) string sInternalAbsPath = file.AbsoluteInternalPath; if (srcFilename != null && !srcFilename.Equals(sInternalAbsPath, StringComparison.InvariantCultureIgnoreCase)) { ((CmFile)file).SetInternalPath(srcFilename); } Caption.SetAlternative(captionTss, ws); m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, Hvo, (int)CmPicture.CmPictureTags.kflidCaption, ws, 0, 0); m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, file.Hvo, (int)CmFile.CmFileTags.kflidInternalPath, 0, 1, 1); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize a new CmPicture by creating a copy of the file in the given folder and /// hooking everything up. /// </summary> /// <param name="srcFilename">The path to the original filename (an internal copy will /// be made in this method)</param> /// <param name="captionTss">The caption (in the given Writing System)</param> /// <param name="description">Illustration description in English. This is not /// published.</param> /// <param name="layoutPos">Indication of where in the column/page the picture is to be /// laid out.</param> /// <param name="scaleFactor">Integral percentage by which picture is grown or shrunk.</param> /// <param name="locationRangeType">Indicates the type of data contained in LocationMin /// and LocationMax.</param> /// <param name="locationMin">The minimum Scripture reference at which this picture can /// be laid out.</param> /// <param name="locationMax">The maximum Scripture reference at which this picture can /// be laid out.</param> /// <param name="copyright">Publishable information about the copyright that should /// appear on the copyright page of the publication.</param> /// <param name="sFolder">The name of the CmFolder where picture should be stored /// </param> /// <param name="ws">The WS of the caption and copyright</param> /// ------------------------------------------------------------------------------------ public void InitializeNewPicture(string srcFilename, ITsString captionTss, string description, PictureLayoutPosition layoutPos, int scaleFactor, PictureLocationRangeType locationRangeType, int locationMin, int locationMax, string copyright, string sFolder, int ws) { // Set the caption first since creating the CmFile will throw if srcFilename is empty. if (captionTss != null) { Caption.SetAlternative(captionTss, ws); } // Locate CmFolder with given name or create it, if neccessary ICmFolder folder = CmFolder.FindOrCreateFolder(m_cache, (int)LangProject.LangProjectTags.kflidPictures, sFolder); PictureFileRA = CmFile.FindOrCreateFile(folder, srcFilename); int wsEn = Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("en"); if (!String.IsNullOrEmpty(description) && wsEn > 0) { Description.SetAlternative(description, wsEn); } LayoutPos = layoutPos; ScaleFactor = scaleFactor; LocationRangeType = locationRangeType; LocationMin = locationMin; LocationMax = locationMax; if (!string.IsNullOrEmpty(copyright)) { string sExistingCopyright = PictureFileRA.Copyright.GetAlternative(ws).Text; if (sExistingCopyright != null && sExistingCopyright != copyright) { Logger.WriteEvent("Could not update copyright for picture " + PictureFileRA.AbsoluteInternalPath + " to '" + copyright + "'"); return; } PictureFileRA.Copyright.SetAlternative(copyright, ws); } }