/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) { return; } if (disposing) { // Dispose managed resources here. if (m_internalFilesToDelete != null) { foreach (string sFile in m_internalFilesToDelete) { File.Delete(Path.Combine(DirectoryFinder.FWDataDirectory, sFile)); } m_internalFilesToDelete.Clear(); } } // Dispose unmanaged resources here, whether disposing is true or false. m_pict = null; m_factory = null; m_internalPath = null; m_internalFilesToDelete = null; base.Dispose(disposing); }
public void CmPictureConstructor_FullParamsMultipleDescriptionVariants() { Dictionary <int, string> descriptions = new Dictionary <int, string>(); descriptions[Cache.DefaultAnalWs] = "My picture."; descriptions[Cache.DefaultVernWs] = "Mi foto."; ICmPicture pictNew = m_pictureFactory.Create(CmFolderTags.LocalPictures, 0, null, descriptions, m_internalPath, "left", "1-2", "Don't use this picture in your book!", m_pict.Caption.VernacularDefaultWritingSystem, PictureLocationRangeType.ParagraphRange, "62"); Assert.AreNotEqual(pictNew, m_pict); string internalPathNew = pictNew.PictureFileRA.InternalPath; Assert.AreEqual(m_internalPath, internalPathNew); Assert.AreEqual(m_internalPath, pictNew.PictureFileRA.AbsoluteInternalPath, "Files outside LangProject.LinkedFilesRootDir are stored as absolute paths"); AssertEx.AreTsStringsEqual(m_pict.Caption.VernacularDefaultWritingSystem, pictNew.Caption.VernacularDefaultWritingSystem); Assert.AreEqual(m_pict.PictureFileRA.Owner, pictNew.PictureFileRA.Owner); Assert.AreEqual("My picture.", pictNew.Description.AnalysisDefaultWritingSystem.Text); Assert.AreEqual("Mi foto.", pictNew.Description.VernacularDefaultWritingSystem.Text); Assert.AreEqual(PictureLayoutPosition.LeftAlignInColumn, pictNew.LayoutPos); Assert.AreEqual(62, pictNew.ScaleFactor); Assert.AreEqual(PictureLocationRangeType.ParagraphRange, pictNew.LocationRangeType); Assert.AreEqual(1, pictNew.LocationMin); Assert.AreEqual(2, pictNew.LocationMax); Assert.AreEqual("Don't use this picture in your book!", pictNew.PictureFileRA.Copyright.VernacularDefaultWritingSystem.Text); }
public override void Initialize() { CheckDisposed(); base.Initialize(); // This is a bit odd, but because of the unpredictable timing of garbage collection, // it's possible for the junk file to be deleted by the GC from a previous test, // resulting in a FileNotFoundException in the CmPicture constructor. So we // just give it a few shots at it to make it more reliable. bool fSucceeded = false; for (int i = 0; i < 5 && !fSucceeded; i++) { try { using (DummyFileMaker filemaker = new DummyFileMaker("junk.jpg", true)) { m_pict = new CmPicture(Cache, filemaker.Filename, m_factory.MakeString("Test picture", Cache.DefaultVernWs), StringUtils.LocalPictures); fSucceeded = true; } } catch (FileNotFoundException) { } } Assert.IsNotNull(m_pict); m_internalPath = m_pict.PictureFileRA.InternalPath; Assert.IsNotNull(m_internalPath, "Internal path not set correctly"); Assert.IsTrue(m_pict.PictureFileRA.AbsoluteInternalPath == m_internalPath, "Files outside LangProject.ExtLinkRootDir are stored as absolute paths"); m_internalFilesToDelete.Add(m_pict.PictureFileRA.AbsoluteInternalPath); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Write out the picture as a <figure> element. /// </summary> /// <param name="pict"></param> /// ------------------------------------------------------------------------------------ private void ExportPicture(ICmPicture pict) { int wsCaption; ITsString tssCaption = pict.Caption.GetAlternativeOrBestTss(m_cache.DefaultVernWs, out wsCaption); string sCaption; if (tssCaption.Length > 0 && !tssCaption.Equals(pict.Caption.NotFoundTss)) { sCaption = tssCaption.Text.Normalize(); } else { sCaption = null; } m_writer.WriteLine("<div class=\"pictureCenter\">"); m_xhtml.MapCssToLang("pictureCenter", LanguageCode(wsCaption)); m_writer.WriteLine("<img class=\"picture\" src=\"{0}\" alt=\"{0}\"/>", XmlUtils.MakeSafeXmlAttribute(pict.PictureFileRA.InternalPath).Replace('\\', '/')); m_xhtml.MapCssToLang("picture", LanguageCode(wsCaption)); if (sCaption != null) { m_writer.WriteLine("<div class=\"pictureCaption\">"); m_xhtml.MapCssToLang("pictureCaption", LanguageCode(wsCaption)); WriteTsStringAsXml(tssCaption, 4); m_writer.WriteLine("</div>"); } m_writer.WriteLine("</div>"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:PicturePropertiesDialog"/> class. /// </summary> /// <param name="cache">The FdoCache to use</param> /// <param name="initialPicture">The CmPicture object to set all of the dialog /// properties to, or null to edit a new picture</param> /// <param name="helpTopicProvider">typically IHelpTopicProvider.App</param> /// <param name="app">The application</param> /// <param name="fAnalysis">true to use analysis writign system for caption</param> /// ------------------------------------------------------------------------------------ public PicturePropertiesDialog(FdoCache cache, ICmPicture initialPicture, IHelpTopicProvider helpTopicProvider, IApp app, bool fAnalysis) { // ReSharper disable LocalizableElement if (cache == null) { throw(new ArgumentNullException("cache", "The FdoCache cannot be null")); } // ReSharper restore LocalizableElement Logger.WriteEvent("Opening 'Picture Properties' dialog"); m_cache = cache; m_initialPicture = initialPicture; m_helpTopicProvider = helpTopicProvider; m_app = app; m_captionWs = fAnalysis ? m_cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.Handle : m_cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.Handle; InitializeComponent(); AccessibleName = GetType().Name; if (m_helpTopicProvider != null) // Could be null during tests { m_helpProvider = new HelpProvider(); m_helpProvider.HelpNamespace = FwDirectoryFinder.CodeDirectory + m_helpTopicProvider.GetHelpString("UserHelpFile"); m_helpProvider.SetHelpKeyword(this, m_helpTopicProvider.GetHelpString(s_helpTopic)); m_helpProvider.SetHelpNavigator(this, HelpNavigator.Topic); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Tests that a picture has been created in the DB with a single default run having /// the specified text. /// </summary> /// <param name="para">paragraph that owns the picture</param> /// <param name="iPictureIndex">zero-based picture index</param> /// <param name="sPictureCaption">Expected picture caption</param> /// <param name="sPictureTransCaption">Expected picture caption translation</param> /// ------------------------------------------------------------------------------------ public void VerifyPictureWithTranslation(IStTxtPara para, int iPictureIndex, string sPictureCaption, string sPictureTransCaption) { List <ICmPicture> pictures = para.GetPictures(); ICmPicture picture = pictures[iPictureIndex]; Assert.AreEqual(sPictureCaption, picture.Caption.VernacularDefaultWritingSystem.Text); Assert.AreEqual(sPictureTransCaption, picture.Caption.AnalysisDefaultWritingSystem.Text); }
/// ------------------------------------------------------------------------------------ /// <summary> /// This method is broken out so TeEditingHelper can override and adjust annotations. /// Probably anything else that does it will need to adjust annotations, too, but nothing /// else yet uses this kind of picture in an StText. /// </summary> /// <param name="pict">The picture to insert an ORC for</param> /// <param name="tss">The initial value of the TsString into which the ORC is to be /// inserted.</param> /// <param name="ich">The character offset into the string.</param> /// <param name="hvoObj">The hvo of the object that owns the string property that will /// receive the tss after the ORC is inserted (typically a paragraph).</param> /// <param name="propTag">The property that holds the string.</param> /// <param name="ws">The writing system ID if the property is a multi-string.</param> /// ------------------------------------------------------------------------------------ protected virtual void InsertPictureOrc(ICmPicture pict, ITsString tss, int ich, int hvoObj, int propTag, int ws) { ITsString newTss = pict.InsertORCAt(tss, ich); if (ws == 0) { m_cache.DomainDataByFlid.SetString(hvoObj, propTag, newTss); } else { m_cache.DomainDataByFlid.SetMultiStringAlt(hvoObj, propTag, ws, newTss); } }
public PictureSlice(ICmPicture picture) { m_picBox = new PictureBox(); m_picBox.Click += new EventHandler(pb_Click); m_picBox.Location = new Point(0,0); // not docked, because width may not be whole width m_picBox.SizeMode = PictureBoxSizeMode.Zoom; m_picture = picture; InstallPicture(m_picBox); // We need an extra layer of panel because the slice's control is always docked, // and we don't want that for the picture box. Panel panel = new Panel(); panel.Controls.Add(m_picBox); panel.SizeChanged += new EventHandler(panel_SizeChanged); this.Control = panel; }
bool m_fThumbnail; // true to force smaller size. /// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ public PictureSlice(ICmPicture picture) { m_picBox = new PictureBox(); m_picBox.Click += new EventHandler(pb_Click); m_picBox.Location = new Point(0, 0); // not docked, because width may not be whole width m_picBox.SizeMode = PictureBoxSizeMode.Zoom; m_picture = picture; InstallPicture(m_picBox); // We need an extra layer of panel because the slice's control is always docked, // and we don't want that for the picture box. Panel panel = new Panel(); panel.Controls.Add(m_picBox); panel.SizeChanged += new EventHandler(panel_SizeChanged); this.Control = panel; }
public void TestTextRepOfObj_CmPicture() { string internalPathOrig = null; string internalPathNew = null; try { using (DummyFileMaker filemaker = new DummyFileMaker("junk.jpg", true)) { ITsStrFactory factory = TsStrFactoryClass.Create(); using (var editHelper = new RootSiteEditingHelper(Cache, null)) { ICmPicture pict = Cache.ServiceLocator.GetInstance <ICmPictureFactory>().Create( filemaker.Filename, factory.MakeString("Test picture", Cache.DefaultVernWs), CmFolderTags.LocalPictures); Assert.IsNotNull(pict); Assert.IsTrue(pict.PictureFileRA.AbsoluteInternalPath == pict.PictureFileRA.InternalPath); string sTextRepOfObject = editHelper.TextRepOfObj(Cache, pict.Guid); int objectDataType; Guid guid = editHelper.MakeObjFromText(Cache, sTextRepOfObject, null, out objectDataType); ICmPicture pictNew = Cache.ServiceLocator.GetInstance <ICmPictureRepository>().GetObject(guid); Assert.IsTrue(pict != pictNew); internalPathOrig = pict.PictureFileRA.AbsoluteInternalPath; internalPathNew = pictNew.PictureFileRA.AbsoluteInternalPath; Assert.AreEqual(internalPathOrig, internalPathNew); Assert.AreEqual(internalPathOrig.IndexOf("junk"), internalPathNew.IndexOf("junk")); Assert.IsTrue(internalPathNew.EndsWith(".jpg")); AssertEx.AreTsStringsEqual(pict.Caption.VernacularDefaultWritingSystem, pictNew.Caption.VernacularDefaultWritingSystem); Assert.AreEqual(pict.PictureFileRA.Owner, pictNew.PictureFileRA.Owner); } } } finally { // TODO: When Undo works right, these should get cleaned up automatically if (internalPathOrig != null) { File.Delete(internalPathOrig); } if (internalPathNew != null) { File.Delete(internalPathNew); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Inserts an ORC pointing to hvoObjToInsert at the current selection location. /// Enhance JohnT: should move this to RootSite or similar location where all clients /// can readily use it. /// </summary> /// <param name="pict">The picture to insert</param> /// ------------------------------------------------------------------------------------ public void InsertPicture(ICmPicture pict) { // get selection information ITsString tss; int ich; bool fAssocPrev; int hvoObj; int ws; int propTag; SelectionHelper helper = CurrentSelection; IVwSelection sel = helper.Selection; sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out propTag, out ws); // If inserting a picture over a user prompt, need to set up info for a proper insertion // in the empty paragraph. if (propTag == SimpleRootSite.kTagUserPrompt) { ich = 0; ITsStrFactory factory = m_cache.TsStrFactory; tss = factory.MakeString(string.Empty, m_cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.Handle); propTag = StTxtParaTags.kflidContents; helper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, StTxtParaTags.kflidContents); helper.SetTextPropId(SelectionHelper.SelLimitType.End, StTxtParaTags.kflidContents); } else if (tss == null) { helper = GetSelectionReducedToIp(SelectionHelper.SelLimitType.Top); if (helper != null) { helper.Selection.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out propTag, out ws); } } if (tss == null) { throw new InvalidOperationException("Attempt to insert a picture in an invalid location."); } InsertPictureOrc(pict, tss, ich, hvoObj, propTag, ws); helper.IchAnchor = helper.IchEnd = ich + 1; helper.SetIPAfterUOW(); }
public void FixOrcsWithoutProps_OrphanedFootnoteAndValidPicture() { IScrBook exodus = CreateExodusData(); IScrTxtPara para = AddParaToMockedSectionContent(exodus.SectionsOS[2], ScrStyleNames.NormalParagraph); AddVerse(para, 2, 3, "ORC is here, you see, my friend."); // Update section 2's paragraph contents to include the picture ITsStrBldr tsStrBldr = para.Contents.GetBldr(); ITsStrFactory factory = TsStrFactoryClass.Create(); string filename; if (MiscUtils.IsUnix) { filename = "/tmp/junk.jpg"; } else { filename = "c:\\junk.jpg"; } ICmPicture pict = Cache.ServiceLocator.GetInstance <ICmPictureFactory>().Create(filename, factory.MakeString("Test picture", Cache.DefaultVernWs), CmFolderTags.LocalPictures); Assert.IsNotNull(pict); pict.InsertORCAt(tsStrBldr, 11); para.Contents = tsStrBldr.GetString(); // We need a valid footnote after the picture ORC CreateFootnote(exodus, 2, para.IndexInOwner, 0, 15, ScrStyleNames.CrossRefFootnoteParagraph, false); // Update section 1's paragraph contents to include an orphaned footnote marker CreateFootnote(exodus, 1, 0, 0, 19, ScrStyleNames.CrossRefFootnoteParagraph, true); TeScrInitializer scrInit = new TestTeScrInitializer(Cache); List <string> report = (List <string>)ReflectionHelper.GetResult(scrInit, "FixOrcsWithoutProps"); VerifyNoOrphanedFootnotes(); VerifyResourceForFixedOrphans(); Assert.AreEqual(1, report.Count); Assert.AreEqual("EXO 1:2 - Deleted corrupted footnote marker or picture anchor", report[0]); Assert.AreEqual(1, exodus.FootnotesOS.Count); }
/// ------------------------------------------------------------------------------------- /// <summary> /// Create a CmPicture from a dummy file. /// </summary> /// ------------------------------------------------------------------------------------- protected override void CreateTestData() { base.CreateTestData(); m_fileOs = new MockFileOS(); FileUtils.Manager.SetFileAdapter(m_fileOs); m_fileOs.AddFile(m_internalPath, "123", Encoding.Default); m_pictureFactory = Cache.ServiceLocator.GetInstance<ICmPictureFactory>(); m_pict = m_pictureFactory.Create(m_internalPath, Cache.TsStrFactory.MakeString("Test picture", Cache.DefaultVernWs), CmFolderTags.LocalPictures); Assert.IsNotNull(m_pict); Assert.AreEqual("Test picture", m_pict.Caption.VernacularDefaultWritingSystem.Text); Assert.AreEqual(m_internalPath, m_pict.PictureFileRA.InternalPath, "Internal path not set correctly"); Assert.AreEqual(m_internalPath, m_pict.PictureFileRA.AbsoluteInternalPath, "Files outside LangProject.LinkedFilesRootDir are stored as absolute paths"); }
/// ------------------------------------------------------------------------------------- /// <summary> /// Create a CmPicture from a dummy file. /// </summary> /// ------------------------------------------------------------------------------------- protected override void CreateTestData() { base.CreateTestData(); m_fileOs = new MockFileOS(); FileUtils.Manager.SetFileAdapter(m_fileOs); m_fileOs.AddFile(m_internalPath, "123", Encoding.Default); m_pictureFactory = Cache.ServiceLocator.GetInstance <ICmPictureFactory>(); m_pict = m_pictureFactory.Create(m_internalPath, Cache.TsStrFactory.MakeString("Test picture", Cache.DefaultVernWs), CmFolderTags.LocalPictures); Assert.IsNotNull(m_pict); Assert.AreEqual("Test picture", m_pict.Caption.VernacularDefaultWritingSystem.Text); Assert.AreEqual(m_internalPath, m_pict.PictureFileRA.InternalPath, "Internal path not set correctly"); Assert.AreEqual(m_internalPath, m_pict.PictureFileRA.AbsoluteInternalPath, "Files outside LangProject.LinkedFilesRootDir are stored as absolute paths"); }
private LfPicture FdoPictureToLfPicture(ICmPicture fdoPicture) { var result = new LfPicture(); result.Caption = ToMultiText(fdoPicture.Caption); if ((fdoPicture.PictureFileRA != null) && (!string.IsNullOrEmpty(fdoPicture.PictureFileRA.InternalPath))) { result.FileName = FdoPictureFilenameToLfPictureFilename(fdoPicture.PictureFileRA.InternalPath); } result.Guid = fdoPicture.Guid; // Unmapped ICmPicture fields include: // fdoPicture.Description; // fdoPicture.LayoutPos; // fdoPicture.LocationMax; // fdoPicture.LocationMin; // fdoPicture.LocationRangeType; // fdoPicture.ScaleFactor; return(result); }
public void CmPictureConstructor_FromTextRep() { ICmPicture pictNew = m_pictureFactory.Create(m_pict.TextRepresentation, CmFolderTags.LocalPictures); Assert.AreNotEqual(pictNew, m_pict); string internalPathNew = pictNew.PictureFileRA.InternalPath; Assert.AreEqual(m_internalPath, internalPathNew); Assert.AreEqual(internalPathNew, pictNew.PictureFileRA.AbsoluteInternalPath, "Files outside LangProject.LinkedFilesRootDir are stored as absolute paths"); AssertEx.AreTsStringsEqual(m_pict.Caption.VernacularDefaultWritingSystem, pictNew.Caption.VernacularDefaultWritingSystem); Assert.AreEqual(m_pict.PictureFileRA.Owner, pictNew.PictureFileRA.Owner); Assert.IsNull(pictNew.Description.AnalysisDefaultWritingSystem.Text); // REVIEW (TE-7745): What should the default PictureLayoutPosition value be? Assert.AreEqual(PictureLayoutPosition.CenterInColumn, pictNew.LayoutPos); Assert.AreEqual(100, pictNew.ScaleFactor); Assert.AreEqual(PictureLocationRangeType.AfterAnchor, pictNew.LocationRangeType); Assert.AreEqual(0, pictNew.LocationMin); Assert.AreEqual(0, pictNew.LocationMax); Assert.IsNull(pictNew.PictureFileRA.Copyright.VernacularDefaultWritingSystem.Text); }
internal BackTranslationInfo(ICmPicture pict) { foreach (int ws in pict.Cache.LangProject.AnalysisWssRC.HvoArray) { ITsString tss = pict.Caption.GetAlternative(ws).UnderlyingTsString; if (tss.Length > 0 && tss != pict.Caption.NotFoundTss) m_mapWsTssTran.Add(ws, tss); } m_wsDefaultAnal = pict.Cache.DefaultAnalWs; m_hvo = pict.Hvo; }
/// ------------------------------------------------------------------------------------ /// <summary> /// This method is broken out so TeEditingHelper can override and adjust annotations. /// Probably anything else that does it will need to adjust annotations, too, but nothing /// else yet uses this kind of picture in an StText. /// </summary> /// <param name="pict">The picture to insert an ORC for</param> /// <param name="tss">The initial value of the TsString into which the ORC is to be /// inserted.</param> /// <param name="ich">The character offset into the string.</param> /// <param name="hvoObj">The hvo of the object that owns the string property that will /// receive the tss after the ORC is inserted (typically a paragraph).</param> /// <param name="propTag">The property that holds the string.</param> /// <param name="ws">The writing system ID if the property is a multi-string.</param> /// ------------------------------------------------------------------------------------ protected virtual void InsertPictureOrc(ICmPicture pict, ITsString tss, int ich, int hvoObj, int propTag, int ws) { ITsString newTss = pict.InsertORCAt(tss, ich); if (ws == 0) m_cache.DomainDataByFlid.SetString(hvoObj, propTag, newTss); else m_cache.DomainDataByFlid.SetMultiStringAlt(hvoObj, propTag, ws, newTss); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets a string representation of the picture location. /// </summary> /// <param name="picture">The picture.</param> /// ------------------------------------------------------------------------------------ public string GetPictureLocAsString(ICmPicture picture) { return(picture.LocationRangeType == PictureLocationRangeType.AfterAnchor ? null : picture.LocationMin + "-" + picture.LocationMax); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Exports the picture in Toolbox format. /// </summary> /// <param name="picture">The picture to export.</param> /// ------------------------------------------------------------------------------------ private void ExportToolboxPicture(ICmPicture picture) { if (!string.IsNullOrEmpty(picture.EnglishDescriptionAsString)) m_file.WriteLine(GetMarkerForStyle("Figure Description", @"\figdesc") + " " + picture.EnglishDescriptionAsString); if (!string.IsNullOrEmpty(picture.PictureFileRA.AbsoluteInternalPath)) m_file.WriteLine(GetMarkerForStyle("Figure Filename", @"\figcat") + " " + picture.PictureFileRA.AbsoluteInternalPath); if (!string.IsNullOrEmpty(picture.LayoutPosAsString)) m_file.WriteLine(GetMarkerForStyle("Figure Layout Position", @"\figlaypos") + " " + picture.LayoutPosAsString); string sPictureLocation = ((IPictureLocationBridge)m_scr).GetPictureLocAsString(picture); if (!string.IsNullOrEmpty(sPictureLocation)) m_file.WriteLine(GetMarkerForStyle("Figure Location", @"\figrefrng") + " " + sPictureLocation); string sCopyright = picture.PictureFileRA.Copyright.VernacularDefaultWritingSystem.Text; if (!string.IsNullOrEmpty(sCopyright)) m_file.WriteLine(GetMarkerForStyle("Figure Copyright", @"\figcopy") + " " + sCopyright); string sCaption = picture.Caption.VernacularDefaultWritingSystem.Text; if (!string.IsNullOrEmpty(sCaption)) m_file.WriteLine(GetMarkerForStyle(ScrStyleNames.Figure, @"\figcap") + " " + sCaption); if (picture.ScaleFactor > 0) m_file.WriteLine(GetMarkerForStyle("Figure Scale", @"\figscale") + " " + picture.ScaleFactor); // If there is a back translation of the caption and we are exporting back translations, // then export the back translation of the caption now. if (m_exportBackTrans) ExportPictureBT(picture.Caption); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Inserts the picture at the beginning of the specified paragraph. /// </summary> /// <param name="picture">The picture.</param> /// <param name="para">Paragraph into which the picture is inserted, heretofore, /// whereof.</param> /// ------------------------------------------------------------------------------------ private SelectionHelper PutPictureInParagraph(ICmPicture picture, IStTxtPara para) { int ichOrc = para.Contents.Length; // Create orc for picture in the paragraph ITsStrBldr bldr = para.Contents.GetBldr(); byte[] objData = TsStringUtils.GetObjData(picture.Guid, (byte)FwObjDataTypes.kodtGuidMoveableObjDisp); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData, objData, objData.Length); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, Cache.DefaultVernWs); bldr.Replace(0, 0, new string(StringUtils.kChObject, 1), propsBldr.GetTextProps()); para.Contents = bldr.GetString(); // set up a selection SelectionHelper helper = new SelectionHelper(); helper.NumberOfLevels = 5; helper.LevelInfo[4].hvo = para.Owner.Owner.Owner.Hvo; helper.LevelInfo[4].tag = ScriptureTags.kflidScriptureBooks; helper.LevelInfo[3].hvo = para.Owner.Owner.Hvo; helper.LevelInfo[3].tag = ScrBookTags.kflidSections; helper.LevelInfo[2].hvo = para.Owner.Hvo; helper.LevelInfo[2].tag = para.Owner.OwningFlid; helper.LevelInfo[1].hvo = para.Hvo; helper.LevelInfo[1].tag = StTextTags.kflidParagraphs; helper.LevelInfo[0].hvo = picture.Hvo; helper.LevelInfo[0].tag = StTxtParaTags.kflidContents; helper.LevelInfo[0].ich = ichOrc; return helper; }
internal BackTranslationInfo(ICmPicture pict) { foreach (IWritingSystem ws in pict.Cache.ServiceLocator.WritingSystems.AnalysisWritingSystems) { ITsString tss = pict.Caption.get_String(ws.Handle); if (tss.Length > 0 && tss != pict.Caption.NotFoundTss) m_mapWsTssTran.Add(ws.Handle, tss); } m_hvo = pict.Hvo; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:PicturePropertiesDialog"/> class. /// </summary> /// <param name="cache">The FdoCache to use</param> /// <param name="initialPicture">The CmPicture object to set all of the dialog /// properties to, or null to edit a new picture</param> /// <param name="helpTopicProvider">typically IHelpTopicProvider.App</param> /// <param name="app">The application</param> /// <param name="fAnalysis">true to use analysis writign system for caption</param> /// ------------------------------------------------------------------------------------ public PicturePropertiesDialog(FdoCache cache, ICmPicture initialPicture, IHelpTopicProvider helpTopicProvider, IApp app, bool fAnalysis) { // ReSharper disable LocalizableElement if (cache == null) throw(new ArgumentNullException("cache", "The FdoCache cannot be null")); // ReSharper restore LocalizableElement Logger.WriteEvent("Opening 'Picture Properties' dialog"); m_cache = cache; m_initialPicture = initialPicture; m_helpTopicProvider = helpTopicProvider; m_app = app; m_captionWs = fAnalysis ? m_cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.Handle : m_cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.Handle; InitializeComponent(); AccessibleName = GetType().Name; if (m_helpTopicProvider != null) // Could be null during tests { helpProvider = new HelpProvider(); helpProvider.HelpNamespace = FwDirectoryFinder.CodeDirectory + m_helpTopicProvider.GetHelpString("UserHelpFile"); helpProvider.SetHelpKeyword(this, m_helpTopicProvider.GetHelpString(s_helpTopic)); helpProvider.SetHelpNavigator(this, HelpNavigator.Topic); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Exports the picture in Paratext format. /// </summary> /// <param name="picture">The picture to export.</param> /// ------------------------------------------------------------------------------------ private void ExportParatextPicture(ICmPicture picture) { string pictureMarker = GetMarkerForStyle("Figure USFM Parameters", @"\fig"); if (m_exportBackTrans) { ExportPictureBT(picture.Caption); return; } else if (m_exportParatextProjectFiles) { string sFileToCopy = picture.PictureFileRA.AbsoluteInternalPath; if (!m_pictureFilesToCopy.Contains(sFileToCopy)) m_pictureFilesToCopy.Add(sFileToCopy); } m_file.Write(pictureMarker + " " + picture.GetTextRepOfPicture(true, CurrentPictureRef, m_scr as IPictureLocationBridge) + pictureMarker + "*"); return; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:PicturePropertiesDialog"/> class. /// </summary> /// <param name="cache">The FdoCache to use</param> /// <param name="initialPicture">The CmPicture object to set all of the dialog /// properties to, or null to edit a new picture</param> /// <param name="helpTopicProvider">typically IHelpTopicProvider.App</param> /// <param name="app">The application</param> /// ------------------------------------------------------------------------------------ public PicturePropertiesDialog(FdoCache cache, ICmPicture initialPicture, IHelpTopicProvider helpTopicProvider, IApp app) : this(cache, initialPicture, helpTopicProvider, app, false) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Write out the picture as a <figure> element. /// </summary> /// <param name="pict"></param> /// ------------------------------------------------------------------------------------ private void ExportPicture(ICmPicture pict) { int wsCaption; ITsString tssCaption = pict.Caption.GetAlternativeOrBestTss(m_cache.DefaultVernWs, out wsCaption); string sCaption; if (tssCaption.Length > 0 && !tssCaption.Equals(pict.Caption.NotFoundTss)) sCaption = tssCaption.Text.Normalize(); else sCaption = null; m_writer.WriteLine("<div class=\"pictureCenter\">"); m_xhtml.MapCssToLang("pictureCenter", LanguageCode(wsCaption)); m_writer.WriteLine("<img class=\"picture\" src=\"{0}\" alt=\"{0}\"/>", XmlUtils.MakeSafeXmlAttribute(pict.PictureFileRA.InternalPath).Replace('\\', '/')); m_xhtml.MapCssToLang("picture", LanguageCode(wsCaption)); if (sCaption != null) { m_writer.WriteLine("<div class=\"pictureCaption\">"); m_xhtml.MapCssToLang("pictureCaption", LanguageCode(wsCaption)); WriteTsStringAsXml(tssCaption, 4); m_writer.WriteLine("</div>"); } m_writer.WriteLine("</div>"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make sure picture exists and is referred to properly in the paragraph contents /// </summary> /// <param name="pictureOrig">The original picture</param> /// <param name="para"></param> /// <param name="ich">Character position where ORC should be</param> /// ------------------------------------------------------------------------------------ private void VerifyPicture(ICmPicture pictureOrig, IStTxtPara para, int ich) { ITsString tss = para.Contents; int iRun = tss.get_RunAt(ich); ITsTextProps orcPropsParaFootnote = tss.get_Properties(iRun); string objData = orcPropsParaFootnote.GetStrPropValue( (int)FwTextPropType.ktptObjData); Assert.AreEqual((char)(int)FwObjDataTypes.kodtGuidMoveableObjDisp, objData[0]); // Send the objData string without the first character because the first character // is the object replacement character and the rest of the string is the GUID. Guid newPicGuid = MiscUtils.GetGuidFromObjData(objData.Substring(1)); Assert.AreNotEqual(pictureOrig.Guid, newPicGuid); string sOrc = tss.get_RunText(iRun); Assert.AreEqual(StringUtils.kChObject, sOrc[0]); ICmPicture pictureNew = Cache.ServiceLocator.GetInstance<ICmPictureRepository>().GetObject(newPicGuid); Assert.AreEqual(pictureOrig.PictureFileRA, pictureNew.PictureFileRA); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Write out the picture as a <figure> element. /// </summary> /// ------------------------------------------------------------------------------------ private void ExportPicture(ICmPicture pict) { ITsString tssCaption = pict.Caption.BestVernacularAlternative; string sCaption; if (tssCaption.Length > 0 && !tssCaption.Equals(pict.Caption.NotFoundTss)) sCaption = tssCaption.Text.Normalize(); else sCaption = String.Empty; m_writer.WriteStartElement("figure"); m_fInFigure = true; try { string sPath = pict.PictureFileRA.AbsoluteInternalPath.Normalize(); string sFile = Path.GetFileName(sPath); WriteFigureAttributes(sCaption, sFile); m_writer.WriteComment(String.Format("path=\"{0}\"", sPath)); m_writer.WriteStartElement("caption"); List<BTSegment> rgbts = new List<BTSegment>(); BTSegment bts = new BTSegment(tssCaption, 0, sCaption.Normalize(NormalizationForm.FormD).Length, pict); foreach (int ws in m_dictAnalLangs.Keys) { ITsString tss = pict.Caption.get_String(ws); if (tss.Length > 0 && tss != pict.Caption.NotFoundTss) bts.SetTransForWs(ws, tss.get_NormalizedForm(FwNormalizationMode.knmNFC)); } rgbts.Add(bts); if (sCaption.Length > 0) // Don't export caption with "NotFoundTss" text ExportParagraphData(tssCaption, rgbts); m_writer.WriteEndElement(); //</caption> m_writer.WriteEndElement(); //</figure> } finally { m_fInFigure = false; } }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) return; if (disposing) { // Dispose managed resources here. if (m_internalFilesToDelete != null) { foreach (string sFile in m_internalFilesToDelete) { File.Delete(Path.Combine(DirectoryFinder.FWDataDirectory, sFile)); } m_internalFilesToDelete.Clear(); } } // Dispose unmanaged resources here, whether disposing is true or false. m_pict = null; m_factory = null; m_internalPath = null; m_internalFilesToDelete = null; base.Dispose(disposing); }
private void WriteCmPicture(TextWriter w, ICmPicture picture) { w.Write("<illustration href=\""); if (picture.PictureFileRA != null) { ExportFile(w, picture.PictureFileRA.InternalPath, picture.PictureFileRA.AbsoluteInternalPath, "pictures", FdoFileHelper.ksPicturesDir); } w.WriteLine("\">"); WriteAllForms(w, "label", null, "form", picture.Caption); w.Write("</illustration>"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Inserts the picture at the current selection (or updates the picture we are editing) /// </summary> /// <param name="initialPicture">picture to modify, or null to insert</param> /// <param name="dlg">the dialog we ran to get or modify the picture.</param> /// ------------------------------------------------------------------------------------ private void InsertThePicture(ICmPicture initialPicture, PicturePropertiesDialog dlg) { FwEditingHelper editHelper = ActiveEditingHelper; string undo; string redo; TeResourceHelper.MakeUndoRedoLabels(initialPicture == null ? "kstidInsertPicture" : "kstidUpdatePicture", out undo, out redo); using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(m_cache.ActionHandlerAccessor, editHelper.EditedRootBox.Site, undo, redo)) { string strLocalPictures = CmFolderTags.DefaultPictureFolder; if (initialPicture != null) initialPicture.UpdatePicture(dlg.CurrentFile, dlg.Caption, strLocalPictures, m_cache.DefaultVernWs); else editHelper.InsertPicture(dlg.CurrentFile, dlg.Caption, strLocalPictures); undoTaskHelper.RollBack = false; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:PicturePropertiesDialog"/> class. /// </summary> /// <param name="cache">The FdoCache to use</param> /// <param name="initialPicture">The CmPicture object to set all of the dialog /// properties to, or null to edit a new picture</param> /// <param name="helpTopicProvider">typically IHelpTopicProvider.App</param> /// <param name="app">The application</param> /// ------------------------------------------------------------------------------------ public PicturePropertiesDialog(FdoCache cache, ICmPicture initialPicture, IHelpTopicProvider helpTopicProvider, IApp app) : this(cache, initialPicture, helpTopicProvider, app, false) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Write out the picture with the caption as a <div> element. /// </summary> /// <param name="pict"></param> /// ------------------------------------------------------------------------------------ private void ExportPicture(ICmPicture pict) { ITsString tssCaption = pict.Caption.VernacularDefaultWritingSystem; string sCaption; if (tssCaption.Length > 0 && !tssCaption.Equals(pict.Caption.NotFoundTss)) sCaption = tssCaption.Text.Normalize(); else sCaption = null; m_writer.WriteLine("<div class=\"pictureCenter\">"); m_xhtml.MapCssToLang("pictureCenter", LanguageCode(m_cache.DefaultVernWs)); m_writer.WriteLine("<img id=\"{0}\" class=\"picture\" src=\"{1}\" alt=\"{1}\"/>", "P" + pict.Guid.ToString().ToUpperInvariant(), XmlUtils.MakeSafeXmlAttribute(pict.PictureFileRA.InternalPath).Replace('\\', '/')); m_xhtml.MapCssToLang("picture", LanguageCode(m_cache.DefaultVernWs)); if (sCaption != null) { m_writer.WriteLine("<div class=\"pictureCaption\">"); m_xhtml.MapCssToLang("pictureCaption", LanguageCode(m_cache.DefaultVernWs)); WriteTsStringAsXml(tssCaption, 4); m_writer.WriteLine("</div>"); } m_writer.WriteLine("</div>"); }
public override void Initialize() { CheckDisposed(); base.Initialize(); // This is a bit odd, but because of the unpredictable timing of garbage collection, // it's possible for the junk file to be deleted by the GC from a previous test, // resulting in a FileNotFoundException in the CmPicture constructor. So we // just give it a few shots at it to make it more reliable. bool fSucceeded = false; for (int i = 0; i < 5 && !fSucceeded; i++) { try { using (DummyFileMaker filemaker = new DummyFileMaker("junk.jpg", true)) { m_pict = new CmPicture(Cache, filemaker.Filename, m_factory.MakeString("Test picture", Cache.DefaultVernWs), StringUtils.LocalPictures); fSucceeded = true; } } catch (FileNotFoundException) { } } Assert.IsNotNull(m_pict); m_internalPath = m_pict.PictureFileRA.InternalPath; Assert.IsNotNull(m_internalPath, "Internal path not set correctly"); Assert.IsTrue(m_pict.PictureFileRA.AbsoluteInternalPath == m_internalPath, "Files outside LangProject.ExtLinkRootDir are stored as absolute paths"); m_internalFilesToDelete.Add(m_pict.PictureFileRA.AbsoluteInternalPath); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Write out the picture as a <figure> element. /// </summary> /// <param name="pict"></param> /// ------------------------------------------------------------------------------------ private void ExportPicture(ICmPicture pict) { ITsString tssCaption = pict.Caption.BestVernacularAlternative; string sCaption; if (tssCaption.Length > 0 && !tssCaption.Equals(pict.Caption.NotFoundTss)) sCaption = tssCaption.Text.Normalize(); else sCaption = String.Empty; m_writer.WriteStartElement("figure"); string sPath = pict.PictureFileRA.AbsoluteInternalPath.Normalize(); string sFile = Path.GetFileName(sPath); WriteFigureAttributes(sCaption, sFile); m_writer.WriteComment(String.Format("path=\"{0}\"", sPath)); m_writer.WriteStartElement("caption"); OpenTrGroupIfNeeded(); List<BTSegment> rgbts = null; BackTranslationInfo trans = null; if (Options.UseInterlinearBackTranslation) { rgbts = new List<BTSegment>(); BTSegment bts = new BTSegment(0, sCaption.Normalize(NormalizationForm.FormD).Length, pict); foreach (int ws in m_dictAnalLangs.Keys) { ITsString tss = pict.Caption.GetAlternative(ws).UnderlyingTsString; if (tss.Length > 0 && tss != pict.Caption.NotFoundTss) bts.SetTransForWs(ws, tss.get_NormalizedForm(FwNormalizationMode.knmNFC)); } rgbts.Add(bts); } else { trans = new BackTranslationInfo(pict); } if (tssCaption.Length > 0) ExportParagraphData(0, tssCaption, trans, rgbts); CloseTrGroupIfNeeded(); m_writer.WriteEndElement(); //</caption> m_writer.WriteEndElement(); //</figure> }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets a string representation of the picture location. /// </summary> /// <param name="picture">The picture.</param> /// ------------------------------------------------------------------------------------ public string GetPictureLocAsString(ICmPicture picture) { return picture.LocationRangeType == PictureLocationRangeType.AfterAnchor ? null : picture.LocationMin + "-" + picture.LocationMax; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Inserts an ORC pointing to hvoObjToInsert at the current selection location. /// Enhance JohnT: should move this to RootSite or similar location where all clients /// can readily use it. /// </summary> /// <param name="pict">The picture to insert</param> /// ------------------------------------------------------------------------------------ public void InsertPicture(ICmPicture pict) { // get selection information ITsString tss; int ich; bool fAssocPrev; int hvoObj; int ws; int propTag; SelectionHelper helper = CurrentSelection; IVwSelection sel = helper.Selection; sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out propTag, out ws); // If inserting a picture over a user prompt, need to set up info for a proper insertion // in the empty paragraph. if (propTag == SimpleRootSite.kTagUserPrompt) { ich = 0; ITsStrFactory factory = m_cache.TsStrFactory; tss = factory.MakeString(string.Empty, m_cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.Handle); propTag = StTxtParaTags.kflidContents; helper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, StTxtParaTags.kflidContents); helper.SetTextPropId(SelectionHelper.SelLimitType.End, StTxtParaTags.kflidContents); } else if (tss == null) { helper = GetSelectionReducedToIp(SelectionHelper.SelLimitType.Top); if (helper != null) helper.Selection.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out propTag, out ws); } if (tss == null) throw new InvalidOperationException("Attempt to insert a picture in an invalid location."); InsertPictureOrc(pict, tss, ich, hvoObj, propTag, ws); helper.IchAnchor = helper.IchEnd = ich + 1; helper.SetIPAfterUOW(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make sure picture exists and is referred to properly in the paragraph contents /// </summary> /// <param name="pictureOrig">The original picture</param> /// <param name="para"></param> /// <param name="ich">Character position where ORC should be</param> /// ------------------------------------------------------------------------------------ private void VerifyPicture(ICmPicture pictureOrig, IStTxtPara para, int ich) { ITsString tss = para.Contents.UnderlyingTsString; int iRun = tss.get_RunAt(ich); ITsTextProps orcPropsParaFootnote = tss.get_Properties(iRun); string objData = orcPropsParaFootnote.GetStrPropValue( (int)FwTextPropType.ktptObjData); Assert.AreEqual((char)(int)FwObjDataTypes.kodtGuidMoveableObjDisp, objData[0]); // Send the objData string without the first character because the first character // is the object replacement character and the rest of the string is the GUID. Guid newPicGuid = MiscUtils.GetGuidFromObjData(objData.Substring(1)); int newPicHvo = m_fdoCache.GetIdFromGuid(newPicGuid); Assert.IsTrue(pictureOrig.Guid != newPicGuid); Assert.IsTrue(pictureOrig.Hvo != newPicHvo); string sOrc = tss.get_RunText(iRun); Assert.AreEqual(StringUtils.kchObject, sOrc[0]); CmPicture pictureNew = new CmPicture(m_fdoCache, newPicHvo); Assert.IsTrue(pictureOrig.PictureFileRAHvo != pictureNew.PictureFileRAHvo); Assert.AreEqual(pictureOrig.PictureFileRA.InternalPath, pictureNew.PictureFileRA.InternalPath); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Advances the enumerator to the next element of the collection. /// </summary> /// <returns> /// true if the enumerator was successfully advanced to the next element; false if the /// enumerator has passed the end of the collection. /// </returns> /// <exception cref="T:System.InvalidOperationException">The collection was modified /// after the enumerator was created. </exception> /// ------------------------------------------------------------------------------------ public bool MoveNext() { if (m_currentScrText == null) { return(false); } while (++m_currentScrText.m_iRun < m_currentScrText.m_paraTss.RunCount) { m_internalToken.m_fParagraphStart = (m_currentScrText.m_iRun == 0); ITsTextProps runProps = m_currentScrText.m_paraTss.get_Properties(m_currentScrText.m_iRun); string charStyleName = runProps.GetStrPropValue((int)FwTextPropType.ktptNamedStyle); m_internalToken.m_sText = m_currentScrText.m_paraTss.get_RunText(m_currentScrText.m_iRun); m_internalToken.m_paraOffset = m_currentScrText.m_paraTss.get_MinOfRun(m_currentScrText.m_iRun); int var; int ws = runProps.GetIntPropValues((int)FwTextPropType.ktptWs, out var); m_internalToken.m_icuLocale = GetLocale(ws); m_internalToken.Ws = ws; switch (runProps.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)) { case ScrStyleNames.VerseNumber: if (!m_foundStart || string.IsNullOrEmpty(m_internalToken.m_sText)) { continue; } m_internalToken.m_textType = TextType.VerseNumber; int verse = ScrReference.VerseToIntStart(m_internalToken.m_sText); if (verse != 0) { m_internalToken.m_startRef.Verse = verse; } verse = ScrReference.VerseToIntEnd(m_internalToken.m_sText); if (verse != 0) { m_internalToken.m_endRef.Verse = verse; } break; case ScrStyleNames.ChapterNumber: if (string.IsNullOrEmpty(m_internalToken.m_sText)) { continue; } int chapter = 0; try { chapter = ScrReference.ChapterToInt(m_internalToken.m_sText); } catch { // Ignore exceptions. We'll flag them later as errors. } if (!m_foundStart) { if (m_chapterNum != chapter) { continue; } m_foundStart = true; } else if (m_chapterNum > 0 && m_chapterNum != chapter) { // Stop if we're only getting tokens for a single chapter (unless // this is an (erroneous) second occurrence of the same chapter) return(false); } m_internalToken.m_textType = TextType.ChapterNumber; m_internalToken.m_startRef.Chapter = m_internalToken.m_endRef.Chapter = chapter; m_internalToken.m_startRef.Verse = m_internalToken.m_endRef.Verse = 1; break; default: { if (!m_foundStart) { continue; } // Deal with footnotes and picture captions Guid guidObj = TsStringUtils.GetGuidFromRun(m_currentScrText.m_paraTss, m_currentScrText.m_iRun, runProps); if (guidObj == Guid.Empty) { m_internalToken.m_textType = m_currentScrText.DefaultTextType; } else if (m_outerText != null) { // It was possible through copy/paste to put ORCs into footnotes or pictures, but that is no // longer allowed. This tokenizing code won't handle the nesting correctly, so just ignore // the nested ORC. See TE-8609. continue; } else { m_fOrcWasStartOfPara = m_internalToken.m_fParagraphStart; ICmObject obj; m_book.Cache.ServiceLocator.GetInstance <ICmObjectRepository>().TryGetObject(guidObj, out obj); if (obj is IStFootnote) { m_outerText = m_currentScrText; // footnotes are StTexts m_currentScrText = new TokenizableText((IStText)obj, TextType.Note); return(MoveNext()); } if (obj is ICmPicture) { m_outerText = m_currentScrText; ICmPicture pict = (ICmPicture)obj; m_currentScrText = new TokenizableText( pict.Caption.VernacularDefaultWritingSystem, ScrStyleNames.Figure, TextType.PictureCaption, pict, CmPictureTags.kflidCaption); return(MoveNext()); } } } break; } m_internalToken.m_fNoteStart = (m_internalToken.m_textType == TextType.Note && m_internalToken.m_fParagraphStart && m_currentScrText.m_iPara == 0); m_internalToken.m_paraStyleName = m_currentScrText.ParaStyleName; m_internalToken.m_charStyleName = charStyleName != null ? charStyleName : string.Empty; m_internalToken.m_object = m_currentScrText.m_obj; m_internalToken.m_flid = m_currentScrText.m_flid; // We need the current token to be a copy of our internal token so we don't change the // internal variables of whatever was returned from the enumerator. m_currentToken = m_internalToken.Copy(); return(true); } // Finished that paragraph and didn't find any more runs; try next para in this text, // if any. if (!m_currentScrText.NextParagraph()) { if (!m_foundStart) { Debug.Fail("We should have found the desired chapter wtihin the section we were searching."); return(false); } // Finished that text and didn't find any more paragraphs. // If we have been processing an inner text (footnote or picture caption), pop back // out to the "outer" one. if (m_outerText != null) { m_currentScrText = m_outerText; m_outerText = null; bool result = MoveNext(); if (result) { m_currentToken.m_fParagraphStart |= m_fOrcWasStartOfPara; m_fOrcWasStartOfPara = false; } return(result); } // Otherwise, try next text, if any. if (m_currentScrText.m_text.OwningFlid == ScrBookTags.kflidTitle) { // Get first section head text. CurrentSectionIndex = 0; } else if (m_currentScrText.m_text.OwningFlid == ScrSectionTags.kflidHeading) { m_currentScrText = new TokenizableText(m_currentSection.ContentOA, m_currentSection.IsIntro ? TextType.Other : TextType.Verse); } else { Debug.Assert(m_currentScrText.m_text.OwningFlid == ScrSectionTags.kflidContent); if (m_iCurrentSection + 1 >= m_book.SectionsOS.Count) { return(false); } CurrentSectionIndex++; if (m_chapterNum > 0 && ScrReference.GetChapterFromBcv(m_currentSection.VerseRefStart) != m_chapterNum) { return(false); } } } return(MoveNext()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets a string representation of the picture location. /// </summary> /// <param name="picture">The picture.</param> /// ------------------------------------------------------------------------------------ public string GetPictureLocAsString(ICmPicture picture) { if (picture.LocationRangeType == PictureLocationRangeType.ReferenceRange) { return (new BCVRef(picture.LocationMin)).AsString + "-" + (new BCVRef(picture.LocationMax)).AsString; } return ((CmPicture)picture).PictureLocAsString; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Export a picture object. /// </summary> /// <param name="picture">the picture to export</param> /// ------------------------------------------------------------------------------------ private void ExportPicture(ICmPicture picture) { // If we are doing a paratext non-interleaved BT, then just export the BT of the picture if (m_markupSystem == MarkupType.Paratext) ExportParatextPicture(picture); else ExportToolboxPicture(picture); }