public void FindPictureInVerse_Found() { CheckDisposed(); CreateExodusData(); StTxtPara paraS1P0 = (StTxtPara)m_scr.ScriptureBooksOS[0].SectionsOS[1].ContentOA.ParagraphsOS[0]; ITsString tss = paraS1P0.Contents.UnderlyingTsString; ITsStrFactory factory = TsStrFactoryClass.Create(); using (DummyFileMaker fileMaker = new DummyFileMaker("junk.jpg", true)) { CmPicture pict = new CmPicture(Cache, fileMaker.Filename, factory.MakeString("Test picture picture", Cache.DefaultVernWs), StringUtils.LocalPictures); int positionToInsertOrc = tss.Length; pict.InsertORCAt(tss, positionToInsertOrc, paraS1P0.Hvo, (int)StTxtPara.StTxtParaTags.kflidContents, 0); int iSection, iPara, ichOrcPos; Assert.IsTrue(m_editingHelper.FindPictureInVerse(new ScrReference(02001002, m_scr.Versification), pict.Hvo, out iSection, out iPara, out ichOrcPos)); Assert.AreEqual(1, iSection); Assert.AreEqual(0, iPara); Assert.AreEqual(positionToInsertOrc, ichOrcPos); } }
/// <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> protected virtual void InsertPictureOrc(CmPicture pict, ITsString tss, int ich, int hvoObj, int propTag, int ws) { pict.InsertORCAt(tss, ich, hvoObj, propTag, ws); }
public void DeletePictureTwoInPara() { CheckDisposed(); // Create pictures. string fileName1, fileName2; CmPicture picture1; CmPicture picture2; string folder = String.Empty; int hvoPic1 = CreateAndInsertPicture(0, out fileName1); int hvoPic2 = CreateAndInsertPicture(1, out fileName2); try { // Create a book with one section and one paragraph with text. IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(3, "Leviticus"); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "This is the paragraph", null); section.AdjustReferences(); // Insert picture ORCs into paragraph, at the beginning. picture1 = new CmPicture(Cache, hvoPic1); picture1.InsertORCAt(para.Contents.UnderlyingTsString, 0, para.Hvo, (int)StTxtPara.StTxtParaTags.kflidContents, 0); int paraRunCountWithOnePict = para.Contents.UnderlyingTsString.RunCount; picture2 = new CmPicture(Cache, hvoPic2); picture2.InsertORCAt(para.Contents.UnderlyingTsString, 1, para.Hvo, (int)StTxtPara.StTxtParaTags.kflidContents, 0); string pic1Text1 = picture1.TextRepOfPicture; int startIndex = pic1Text1.IndexOf(@":") - 1; int stringLength = pic1Text1.LastIndexOf(@"\") - startIndex; folder = pic1Text1.Substring(startIndex, stringLength); m_draftView.RefreshDisplay(); // Select the second picture. We click where we expect the picture is in the // DummyDraftView form; half the picture height above the bottom seems to work // NOTE: It would be better to select the picture programmatically. However, // MakeSelInObj doesn't work; we probably need a new method to allow this. // Currently there seems to be no way to programmatically (or with the keyboard) // select a picture. m_draftView.ScrollToEnd(); m_draftView.CallMouseDown(new Point(m_draftView.ClientRectangle.Width / 2, m_draftView.ClientRectangle.Height - (TeResourceHelper.ImageNotFoundX.Height / 2))); // delete the second picture m_draftView.TeEditingHelper.DeletePicture(); m_draftView.RefreshDisplay(); // We expect that picture 1 will still be in the cache, but picture 2 will be deleted. Assert.AreNotEqual(0, Cache.GetClassOfObject(hvoPic1), "Picture object 1 is not in cache"); Assert.AreEqual(0, Cache.GetClassOfObject(hvoPic2), "Picture object 2 is still in cache"); Assert.AreEqual(paraRunCountWithOnePict, para.Contents.UnderlyingTsString.RunCount, "Paragraph's run count is invalid. Second picture might not have been deleted."); Assert.AreEqual(null, para.Contents.UnderlyingTsString.get_Properties(1).GetStrPropValue( (int)FwTextPropType.ktptObjData), "The second picture's ORC is still in the paragraph."); } finally { m_draftView.Dispose(); // Remove picture files that were created for this test in StringUtils.LocalPictures if (File.Exists(fileName1)) File.Delete(fileName1); if (File.Exists(fileName2)) File.Delete(fileName2); if (File.Exists(folder + @"\" + fileName1)) File.Delete(folder + @"\" + fileName1); if (File.Exists(folder + @"\" + fileName2)) File.Delete(folder + @"\" + fileName2); } }
public void DeletePictureInPara() { CheckDisposed(); // Create pictures. string fileName1; CmPicture picture1 = new CmPicture(); string folder = String.Empty; int hvoPic1 = CreateAndInsertPicture(0, out fileName1); try { // Create a book with one section and one paragraph with text. IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(3, "Leviticus"); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "This is the paragraph", null); section.AdjustReferences(); // Insert picture ORC into paragraph at the beginning. int paraRunCountWithNoPict = para.Contents.UnderlyingTsString.RunCount; picture1 = new CmPicture(Cache, hvoPic1); picture1.InsertORCAt(para.Contents.UnderlyingTsString, 0, para.Hvo, (int)StTxtPara.StTxtParaTags.kflidContents, 0); string pic1Text1 = picture1.TextRepOfPicture; int startIndex = pic1Text1.IndexOf(@":") - 1; int stringLength = pic1Text1.LastIndexOf(@"\") - startIndex; folder = pic1Text1.Substring(startIndex, stringLength); m_draftView.RefreshDisplay(); // select the picture // 1/3 worked on the overnight build machine while 1/2 fails, so it can't be chosen programmatically reliably. // we click where we expect the picture is in the DummyDraftView form; 1/2 from top seems to work m_draftView.ScrollToEnd(); m_draftView.CallMouseDown(new Point(m_draftView.ClientRectangle.Width / 2, m_draftView.ClientRectangle.Height / 2)); //Application.DoEvents(); // delete the picture m_draftView.TeEditingHelper.DeletePicture(); m_draftView.RefreshDisplay(); // We expect that picture 1 will be deleted. Assert.AreEqual(0, Cache.GetClassOfObject(hvoPic1), "Picture object 1 is still in cache"); Assert.AreEqual(paraRunCountWithNoPict, para.Contents.UnderlyingTsString.RunCount, "Paragraph's run count is invalid. Picture might not have been deleted."); Assert.AreEqual(null, para.Contents.UnderlyingTsString.get_Properties(0).GetStrPropValue( (int)FwTextPropType.ktptObjData), "The picture's ORC is still in the paragraph."); } finally { m_draftView.Dispose(); // Remove picture files that were created for this test in StringUtils.LocalPictures if (File.Exists(fileName1)) File.Delete(fileName1); if (File.Exists(folder + @"\" + fileName1)) File.Delete(folder + @"\" + fileName1); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets up current and revision paragraphs, inserting a picture in the specified /// paragraph. This returns the position where the picture was inserted. /// </summary> /// ------------------------------------------------------------------------------------ private int SetupPictureDiffTests(bool putPicInRev, out StTxtPara paraCur, out StTxtPara paraRev) { // create Current section IScrSection sectionCur = CreateSection(m_genesis, "My aching head!"); paraCur = m_scrInMemoryCache.AddParaToMockedSectionContent(sectionCur.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(paraCur, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(paraCur, "Hello.", Cache.DefaultVernWs); // create Revision section IScrSection sectionRev = CreateSection(m_genesisRevision, "My aching head!"); paraRev = m_scrInMemoryCache.AddParaToMockedSectionContent(sectionRev.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(paraRev, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(paraRev, "Hello.", Cache.DefaultVernWs); int picPos = 7; StTxtPara para = (putPicInRev ? paraRev : paraCur); ITsString tss = para.Contents.UnderlyingTsString; // Add picture to revision. ITsStrFactory factory = TsStrFactoryClass.Create(); using (DummyFileMaker fileMaker = new DummyFileMaker("junk.jpg", true)) { CmPicture pict = new CmPicture(Cache, fileMaker.Filename, factory.MakeString("Test picture", Cache.DefaultVernWs), StringUtils.LocalPictures); pict.InsertORCAt(tss, picPos, para.Hvo, (int)StTxtPara.StTxtParaTags.kflidContents, 0); } m_bookMerger.DetectDifferences(null); Assert.AreEqual(1, m_bookMerger.Differences.Count); return picPos; }
public void CreateOwnedObjects_Picture() { CheckDisposed(); StTxtPara para = (StTxtPara)m_currentText.ParagraphsOS[0]; ITsString tss = para.Contents.UnderlyingTsString; ITsStrFactory factory = TsStrFactoryClass.Create(); using (DummyFileMaker fileMaker = new DummyFileMaker("junk.jpg", true)) { CmPicture pict = new CmPicture(Cache, fileMaker.Filename, factory.MakeString("Test picture", Cache.DefaultVernWs), StringUtils.LocalPictures); pict.InsertORCAt(tss, 0, para.Hvo, (int)StTxtPara.StTxtParaTags.kflidContents, 0); tss = para.Contents.UnderlyingTsString; int cchOrigStringLength = tss.Length; NMock.DynamicMock mockIObjectMetaInfoProvider = new DynamicMock(typeof(IObjectMetaInfoProvider)); mockIObjectMetaInfoProvider.Strict = true; mockIObjectMetaInfoProvider.ExpectAndReturn(1, "PictureFolder", StringUtils.LocalPictures); para.CreateOwnedObjects(0, 1, (IObjectMetaInfoProvider)mockIObjectMetaInfoProvider.MockInstance); mockIObjectMetaInfoProvider.Verify(); tss = para.Contents.UnderlyingTsString; Assert.AreEqual(cchOrigStringLength, tss.Length); string sObjData = tss.get_Properties(0).GetStrPropValue((int)FwTextPropType.ktptObjData); Guid guid = MiscUtils.GetGuidFromObjData(sObjData.Substring(1)); byte odt = Convert.ToByte(sObjData[0]); Assert.AreEqual((byte)FwObjDataTypes.kodtGuidMoveableObjDisp, odt); Assert.IsTrue(Cache.GetGuidFromId(pict.Hvo) != guid, "New guid was not inserted"); } }